Browse Source

add primary key get method,and add default data

master
jkpete 2 months ago
parent
commit
6b67781961
  1. 4
      Example/SaveSystem/Script/ViewSaveSystem.cs
  2. 2
      addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotSaveTable.cs
  3. 33
      addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotTable.cs
  4. 66
      addons/EGFramework/Module/GenerateTools/Templete/Variant/EGVariantGenerator.cs

4
Example/SaveSystem/Script/ViewSaveSystem.cs

@ -23,11 +23,11 @@ namespace EGFramework.Examples.Test { @@ -23,11 +23,11 @@ namespace EGFramework.Examples.Test {
{
dataStudents.Add(new DataStudent("A" + stu, 20 + stu));
}
EGodotTable table = container.CreateNode<EGodotTable>("Teacher");
EGodotTable table = container.CreateNode<EGodotTable>("Default");
table.InitData<DataStudent>(dataStudents);
IEGSaveData SqliteTest = this.EGSave().LoadDataFile<EGSqliteSave>("SaveData/test.db");
EGodotSaveTable PersonTable = container.CreateNode<EGodotSaveTable>("Person");
EGodotSaveTable PersonTable = container.CreateNode<EGodotSaveTable>("SQLite");
PersonTable.InitSaveData<EGSqliteSave>(SqliteTest);
PersonTable.InitData<DataPerson>("person");

2
addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotSaveTable.cs

@ -36,8 +36,8 @@ namespace EGFramework.UI @@ -36,8 +36,8 @@ namespace EGFramework.UI
InitTitle(typeof(T).EGenerateDictiontaryByType());
InitRowData(null);
InitPageMenu();
}
public void QueryPageData<T>() where T : new()
{

33
addons/EGFramework/Module/GenerateTools/Templete/Godot/UI/EGodotTable.cs

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
@ -28,6 +29,10 @@ namespace EGFramework.UI @@ -28,6 +29,10 @@ namespace EGFramework.UI
protected List<Dictionary<string, object>> TableData { set; get; }
protected Dictionary<string,object> EmptyData { set; get; }
protected EasyEvent<Dictionary<string, object>> AddData { set; get; } = new EasyEvent<Dictionary<string, object>>();
/// <summary>
/// The max data count for one page.
/// </summary>
@ -47,12 +52,28 @@ namespace EGFramework.UI @@ -47,12 +52,28 @@ namespace EGFramework.UI
PageAdapter.Reload(count, PageLimit);
}
this.Vertical = true;
EmptyData = typeof(T).EGenerateEmptyDictiontaryByType();
InitFunctionMenu();
InitTitle(typeof(T).EGenerateDictiontaryByType());
InitRowData(tableData.EGenerateDictionaryByGroup());
InitPageMenu();
}
public virtual void OnAddData(Dictionary<string, object> data)
{
GD.Print("Add : " + data["Name"]);
string primaryKey = data.EGetDefaultPrimaryKey();
if (primaryKey != "")
{
data[primaryKey] = TableData.Count.ToString();
}
TableData.Add(new Dictionary<string, object>(data));
PageAdapter.DataLength++;
PageAdapter.Reload(PageAdapter.DataLength, PageLimit);
InitPageData();
OnPageChanged.Invoke();
}
public virtual void InitFunctionMenu()
{
@ -60,6 +81,16 @@ namespace EGFramework.UI @@ -60,6 +81,16 @@ namespace EGFramework.UI
{
FunctionContainer = this.CreateNode<BoxContainer>("FunctionContainer");
FunctionContainer.Vertical = false;
Button add = FunctionContainer.CreateNode<Button>("add");
add.Text = "Add";
add.Connect("pressed", Callable.From(()=>this.EGEditDialog(EmptyData, OnAddData, "Add")));
add.FocusMode = FocusModeEnum.None;
Button refresh = FunctionContainer.CreateNode<Button>("refresh");
refresh.Text = "Refresh";
refresh.Connect("pressed", Callable.From(InitPageData));
refresh.FocusMode = FocusModeEnum.None;
}
}
public void InitTitle(Dictionary<string, object> titleData)
@ -67,7 +98,7 @@ namespace EGFramework.UI @@ -67,7 +98,7 @@ namespace EGFramework.UI
if (Title == null)
{
Title = this.CreateNode<EGodotRowData>("TitleContainer");
titleData.Add("Operate", "");
titleData.Add("Operate", "Operate");
Title.Init(titleData);
}
else

66
addons/EGFramework/Module/GenerateTools/Templete/Variant/EGVariantGenerator.cs

@ -4,16 +4,35 @@ using System.Linq; @@ -4,16 +4,35 @@ using System.Linq;
using System.Reflection;
namespace EGFramework{
public static class EGenerateVariant{
public static Dictionary<string,object> EGenerateDictiontaryByType(this Type self){
public static class EGenerateVariant
{
public static Dictionary<string, object> EGenerateDictiontaryByType(this Type self)
{
PropertyInfo[] propertyNames = self.GetProperties();
FieldInfo[] fieldNames = self.GetFields();
Dictionary<string, object> result = new Dictionary<string, object>();
foreach (PropertyInfo pName in propertyNames)
{
result.Add(pName.Name, pName.Name);
}
foreach (FieldInfo fName in fieldNames)
{
result.Add(fName.Name, fName.Name);
}
return result;
}
public static Dictionary<string, object> EGenerateEmptyDictiontaryByType(this Type self)
{
PropertyInfo[] propertyNames = self.GetProperties();
FieldInfo[] fieldNames = self.GetFields();
Dictionary<string,object> result = new Dictionary<string, object>();
foreach(PropertyInfo pName in propertyNames){
result.Add(pName.Name,pName.Name);
Dictionary<string, object> result = new Dictionary<string, object>();
foreach (PropertyInfo pName in propertyNames)
{
result.Add(pName.Name, "");
}
foreach(FieldInfo fName in fieldNames){
result.Add(fName.Name,fName.Name);
foreach (FieldInfo fName in fieldNames)
{
result.Add(fName.Name, "");
}
return result;
}
@ -38,23 +57,40 @@ namespace EGFramework{ @@ -38,23 +57,40 @@ namespace EGFramework{
return result;
}
public static List<Dictionary<string,object>> EGenerateDictionaryByGroup<T>(this IEnumerable<T> self){
List<Dictionary<string,object>> result = new List<Dictionary<string, object>>();
public static List<Dictionary<string, object>> EGenerateDictionaryByGroup<T>(this IEnumerable<T> self)
{
List<Dictionary<string, object>> result = new List<Dictionary<string, object>>();
PropertyInfo[] propertyNames = typeof(T).GetProperties();
FieldInfo[] fieldNames = typeof(T).GetFields();
foreach(T member in self){
Dictionary<string,object> mResult = new Dictionary<string, object>();
foreach(PropertyInfo pName in propertyNames){
foreach (T member in self)
{
Dictionary<string, object> mResult = new Dictionary<string, object>();
foreach (PropertyInfo pName in propertyNames)
{
object p = pName.GetValue(member);
mResult.Add(pName.Name,p);
mResult.Add(pName.Name, p);
}
foreach(FieldInfo fName in fieldNames){
foreach (FieldInfo fName in fieldNames)
{
object p = fName.GetValue(member);
mResult.Add(fName.Name,p);
mResult.Add(fName.Name, p);
}
result.Add(mResult);
}
return result;
}
//Default primary key is id,Id,ID.
public static string EGetDefaultPrimaryKey(this Dictionary<string, object> self)
{
foreach (KeyValuePair<string, object> param in self)
{
if (param.Key == "ID" || param.Key == "Id" || param.Key == "id")
{
return param.Key;
}
}
return "";
}
}
}
Loading…
Cancel
Save