Browse Source

fixed row data

master
jkpete 3 months ago
parent
commit
47d2cbd668
  1. 15
      Example/SaveSystem/Script/ViewSaveSystem.cs
  2. 59
      addons/EGFramework/Module/GenerateTools/GodotUITemplete/EGodotTableRowData.cs
  3. 3
      addons/EGFramework/Module/GenerateTools/PlatformInterface/IGodotTable.cs
  4. 24
      addons/EGFramework/Module/NodeExtension/EGCreate.cs
  5. 32
      addons/EGFramework/Module/SaveTools/Data/EGCsvSave.cs
  6. 16
      addons/EGFramework/Module/SaveTools/Data/EGDapper.cs
  7. 16
      addons/EGFramework/Module/SaveTools/Data/EGLiteDBSave.cs
  8. 2
      addons/EGFramework/Module/SaveTools/SaveToolsInterface.cs

15
Example/SaveSystem/Script/ViewSaveSystem.cs

@ -26,18 +26,21 @@ namespace EGFramework.Examples.Test{
List<DataStudent> dataStudents = new List<DataStudent>(); List<DataStudent> dataStudents = new List<DataStudent>();
dataStudents.Add(dataStudent); dataStudents.Add(dataStudent);
dataStudents.Add(dataStudent2); dataStudents.Add(dataStudent2);
this.GetNode<TabContainer>("TabContainer").CreateTable<DataStudent>(dataStudents,"Teacher"); EGodotTable table = this.GetNode<TabContainer>("TabContainer").CreateTable<DataStudent>(dataStudents,"Teacher");
// Button btn = this.CreateNode<Button>("Test"); // Button btn = this.CreateNode<Button>("Test");
// btn.Text = "Test"; // btn.Text = "Test";
// btn.Position = new Vector2(100,100); // btn.Position = new Vector2(100,100);
// btn.Connect("pressed",Callable.From (() => { // btn.Connect("pressed",Callable.From (() => {
// this.Alert("Test"); // this.Alert("Test");
// })); // }));
EGodotEditDialog Edit = this.CreateNode<EGodotEditDialog>("Edit"); // EGodotEditDialog Edit = this.CreateNode<EGodotEditDialog>("Edit");
Edit.InitDialog(new Dictionary<string, object>() {{"Name","Tom"},{"Age",18}},(data) => { // Edit.InitDialog(new Dictionary<string, object>() {{"Name","Tom"},{"Age",18}},(data) => {
GD.Print(data["Name"]); // GD.Print(data["Name"]);
GD.Print(data["Age"]); // GD.Print(data["Age"]);
}); // });
EGodotTableRowData rowData = table.CreateNode<EGodotTableRowData>("RowData");
rowData.InitRowData(new Dictionary<string, object>() {{"Name","Tom"},{"Age",18}});
} }

59
addons/EGFramework/Module/GenerateTools/GodotUITemplete/EGodotTableRowData.cs

@ -3,7 +3,7 @@ using System.Collections.Generic;
using Godot; using Godot;
namespace EGFramework.UI{ namespace EGFramework.UI{
public partial class EGodotTableRowData : Control,IEGFramework public partial class EGodotTableRowData : VBoxContainer,IEGFramework
{ {
public Button ItemHover { get; set; } public Button ItemHover { get; set; }
public ColorRect Line { get; set; } public ColorRect Line { get; set; }
@ -13,14 +13,63 @@ namespace EGFramework.UI{
public Control Operate { get; set; } public Control Operate { get; set; }
public Button Modify { get; set; } public Button Modify { get; set; }
public Button Delete { get; set; } public Button Delete { get; set; }
public string[] Data { get; set; }
// private Action<Dictionary<string,string>> OnDataEdit; private Dictionary<string,object> Data { get; set; }
private Action<Dictionary<string,object>> OnDataEdit;
public void InitRowData(){ public void InitRowData(Dictionary<string,object> data){
this.Data = data;
List = new HBoxContainer();
List.Name = "TableRow_"+Resource.GenerateSceneUniqueId();
List.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
this.AddChild(List);
Line = new ColorRect();
Line.Name = "Line";
Line.Color = new Color(0.5f,0.5f,0.5f);
Line.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
Line.SizeFlagsVertical = Control.SizeFlags.ShrinkEnd;
Line.CustomMinimumSize = new Vector2(0,1);
this.AddChild(Line);
foreach(KeyValuePair<string,object> kv in data){
this.List.AddChild(new Label(){
Name = kv.Key,
Text = kv.Value.ToString(),
HorizontalAlignment = HorizontalAlignment.Center,
SizeFlagsHorizontal = Control.SizeFlags.ExpandFill
});
}
Operate = new HBoxContainer();
Operate.Name = "Operate";
Operate.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
List.AddChild(Operate);
Modify = new Button();
Modify.Name = "Modify";
Modify.Text = "Modify";
Modify.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
Operate.AddChild(Modify);
Delete = new Button();
Delete.Name = "Delete";
Delete.Text = "Delete";
Delete.SizeFlagsHorizontal = Control.SizeFlags.ExpandFill;
Operate.AddChild(Delete);
Modify.Connect("pressed",Callable.From(OnEdit));
Delete.Connect("pressed",Callable.From(OnDelete));
OnDataEdit = e => {
};
}
public void RefreshRowData(){
} }
public void RefreshRow(){
public void OnEdit(){
// if(Data == null){
// return ;
// }
// this.EditParams(Data.GetModifyParams(),OnDataEdit,"修改");
}
public void OnDelete(){
} }
} }

3
addons/EGFramework/Module/GenerateTools/PlatformInterface/IGodotTable.cs

@ -2,5 +2,8 @@ namespace EGFramework{
public interface IGodotTable public interface IGodotTable
{ {
}
public interface IGodotRowData{
} }
} }

24
addons/EGFramework/Module/NodeExtension/EGCreate.cs

@ -41,7 +41,7 @@ namespace EGFramework{
return nodeData; return nodeData;
} }
public static void Alert(this Node self,string alertMsg){ public static void Alert(this Node self,string alertMsg,string title = "Alert"){
AcceptDialog acceptDialog; AcceptDialog acceptDialog;
if(EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Get<AcceptDialog>()!=null){ if(EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Get<AcceptDialog>()!=null){
acceptDialog = EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Get<AcceptDialog>(); acceptDialog = EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Get<AcceptDialog>();
@ -50,10 +50,30 @@ namespace EGFramework{
} }
EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Register(acceptDialog); EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Register(acceptDialog);
acceptDialog.Name = "AlertDialog"; acceptDialog.Name = "AlertDialog";
acceptDialog.Title = "Alert"; acceptDialog.Title = title;
acceptDialog.DialogText = alertMsg; acceptDialog.DialogText = alertMsg;
acceptDialog.PopupCentered(); acceptDialog.PopupCentered();
} }
public static void Confirm(this Node self,string alertMsg,Action<bool> callback,string title = "Confirm"){
ConfirmationDialog confirmDialog;
if(EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Get<ConfirmationDialog>()!=null){
confirmDialog = EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Get<ConfirmationDialog>();
}else{
confirmDialog = self.CreateNode<ConfirmationDialog>();
}
EGArchitectureImplement.Interface.GetModule<EGSingletonNode>().NodeContainer.Register(confirmDialog);
confirmDialog.Name = "ConfirmDialog";
confirmDialog.Title = title;
confirmDialog.DialogText = alertMsg;
confirmDialog.PopupCentered();
confirmDialog.Connect("confirmed",Callable.From(() => {
callback(true);
}));
confirmDialog.Connect("canceled",Callable.From(() => {
callback(false);
}));
}
public static Tree CreateTree(this Node self,string treeName = "Tree"){ public static Tree CreateTree(this Node self,string treeName = "Tree"){
Tree tree = new Tree(); Tree tree = new Tree();
tree.Name = treeName; tree.Name = treeName;

32
addons/EGFramework/Module/SaveTools/Data/EGCsvSave.cs

@ -207,6 +207,33 @@ namespace EGFramework
return DataList; return DataList;
} }
public IEnumerable<TData> GetPage<TData>(string dataKey, int pageIndex, int pageSize) where TData : new()
{
if(pageIndex <= 0){
pageIndex = 1;
}
int startPointer = (pageIndex - 1) * pageSize;
List<TData> DataList = new List<TData>();
PropertyInfo[] properties = typeof(TData).GetProperties();
for (int dataID = startPointer; dataID < startPointer+pageSize; dataID++){
TData data = new TData();
foreach(PropertyInfo property in properties){
CsvParamAttribute csvParam = property.GetCustomAttribute<CsvParamAttribute>();
if(csvParam != null && CsvDataHeader.ContainsKey(csvParam._name)){
string valueStr = CsvDataBlock[dataID][CsvDataHeader[csvParam._name]];
if(property.PropertyType==typeof(string)){
property.SetValue(data,valueStr);
}else{
property.SetValue(data,Convert.ChangeType(valueStr,property.PropertyType));
}
}
}
DataList.Add(data);
}
TypeDataContainer.Register(DataList);
return DataList;
}
public IEnumerable<TData> FindData<TData>(string dataKey, Expression<Func<TData, bool>> expression) where TData : new() public IEnumerable<TData> FindData<TData>(string dataKey, Expression<Func<TData, bool>> expression) where TData : new()
{ {
List<TData> sourceList; List<TData> sourceList;
@ -319,6 +346,11 @@ namespace EGFramework
{ {
return CsvDataBlock.Count() > 0 && id.GetType() == typeof(int) && (int)id < CsvDataBlock.Count(); return CsvDataBlock.Count() > 0 && id.GetType() == typeof(int) && (int)id < CsvDataBlock.Count();
} }
public int GetDataCount(string dataKey)
{
return CsvDataBlock.Count();
}
} }
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]

16
addons/EGFramework/Module/SaveTools/Data/EGDapper.cs

@ -20,6 +20,16 @@ namespace EGFramework
return result; return result;
} }
public IEnumerable<TData> GetPage<TData>(string dataKey, int pageIndex, int pageSize) where TData : new()
{
if(pageIndex <= 0){
pageIndex = 1;
}
int startPointer = (pageIndex - 1) * pageSize;
IEnumerable<TData> result = Connection.Query<TData>("select * from "+dataKey+" limit "+startPointer+","+pageIndex);
return result;
}
public TData GetData<TData>(string dataKey, object id) where TData : new() public TData GetData<TData>(string dataKey, object id) where TData : new()
{ {
TData result = Connection.QuerySingle<TData>("select * from "+dataKey+" where ID = @ID",new {ID = id}); TData result = Connection.QuerySingle<TData>("select * from "+dataKey+" where ID = @ID",new {ID = id});
@ -142,6 +152,12 @@ namespace EGFramework
} }
} }
public int GetDataCount(string dataKey)
{
int count = Connection.QuerySingle<int>("select COUNT(*) from " + dataKey);
return count;
}
public DbConnection GetConnection() public DbConnection GetConnection()
{ {
return Connection; return Connection;

16
addons/EGFramework/Module/SaveTools/Data/EGLiteDBSave.cs

@ -54,6 +54,17 @@ namespace EGFramework
return collection.FindAll(); return collection.FindAll();
} }
public IEnumerable<TData> GetPage<TData>(string dataKey, int pageIndex, int pageSize) where TData : new()
{
if(pageIndex <= 0){
pageIndex = 1;
}
int startPointer = (pageIndex - 1) * pageSize;
LiteCollection<TData> collection = (LiteCollection<TData>)Database.GetCollection<TData>(dataKey);
IEnumerable<TData> result = collection.FindAll().Skip(startPointer).Take(pageSize);
return result;
}
public IEnumerable<TData> FindData<TData>(string dataKey, Expression<Func<TData, bool>> expression) where TData : new() public IEnumerable<TData> FindData<TData>(string dataKey, Expression<Func<TData, bool>> expression) where TData : new()
{ {
LiteCollection<TData> collection = (LiteCollection<TData>)Database.GetCollection<TData>(dataKey); LiteCollection<TData> collection = (LiteCollection<TData>)Database.GetCollection<TData>(dataKey);
@ -99,5 +110,10 @@ namespace EGFramework
{ {
return Database.GetCollection(dataKey).Exists((BsonValue)id); return Database.GetCollection(dataKey).Exists((BsonValue)id);
} }
public int GetDataCount(string dataKey)
{
return Database.GetCollection(dataKey).Count();
}
} }
} }

2
addons/EGFramework/Module/SaveTools/SaveToolsInterface.cs

@ -65,10 +65,12 @@ namespace EGFramework
public interface IEGSaveDataReadOnly{ public interface IEGSaveDataReadOnly{
TData GetData<TData>(string dataKey,object id) where TData : new(); TData GetData<TData>(string dataKey,object id) where TData : new();
IEnumerable<TData> GetAll<TData>(string dataKey) where TData : new(); IEnumerable<TData> GetAll<TData>(string dataKey) where TData : new();
IEnumerable<TData> GetPage<TData>(string dataKey,int pageIndex,int pageSize) where TData : new();
IEnumerable<TData> FindData<TData>(string dataKey,Expression<Func<TData, bool>> expression) where TData : new(); IEnumerable<TData> FindData<TData>(string dataKey,Expression<Func<TData, bool>> expression) where TData : new();
IEnumerable<string> GetKeys(); IEnumerable<string> GetKeys();
bool ContainsKey(string dataKey); bool ContainsKey(string dataKey);
bool ContainsData(string dataKey,object id); bool ContainsData(string dataKey,object id);
int GetDataCount(string dataKey);
} }
public interface IEGSaveData : IEGSaveDataReadOnly{ public interface IEGSaveData : IEGSaveDataReadOnly{

Loading…
Cancel
Save