|
|
@ -22,7 +22,8 @@ namespace EGFramework |
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<TData> GetPage<TData>(string dataKey, int pageIndex, int pageSize) where TData : new() |
|
|
|
public IEnumerable<TData> GetPage<TData>(string dataKey, int pageIndex, int pageSize) where TData : new() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if(pageIndex <= 0){ |
|
|
|
if (pageIndex <= 0) |
|
|
|
|
|
|
|
{ |
|
|
|
pageIndex = 1; |
|
|
|
pageIndex = 1; |
|
|
|
} |
|
|
|
} |
|
|
|
int startPointer = (pageIndex - 1) * pageSize; |
|
|
|
int startPointer = (pageIndex - 1) * pageSize; |
|
|
@ -47,10 +48,15 @@ namespace EGFramework |
|
|
|
if (data == null) |
|
|
|
if (data == null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
throw new ArgumentNullException(nameof(data)); |
|
|
|
throw new ArgumentNullException(nameof(data)); |
|
|
|
}else{ |
|
|
|
} |
|
|
|
if(this.ContainsData(dataKey,id)){ |
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (this.ContainsData(dataKey, id)) |
|
|
|
|
|
|
|
{ |
|
|
|
UpdateData(dataKey, data, id); |
|
|
|
UpdateData(dataKey, data, id); |
|
|
|
}else{ |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
AddData(dataKey, data); |
|
|
|
AddData(dataKey, data); |
|
|
|
} |
|
|
|
} |
|
|
|
//EG.Print("data:" + data); |
|
|
|
//EG.Print("data:" + data); |
|
|
@ -68,7 +74,8 @@ namespace EGFramework |
|
|
|
var properties = DataType.GetProperties(); |
|
|
|
var properties = DataType.GetProperties(); |
|
|
|
string keySet = ""; |
|
|
|
string keySet = ""; |
|
|
|
string keySetParam = ""; |
|
|
|
string keySetParam = ""; |
|
|
|
foreach(PropertyInfo key in properties){ |
|
|
|
foreach (PropertyInfo key in properties) |
|
|
|
|
|
|
|
{ |
|
|
|
keySet += key.Name + ","; |
|
|
|
keySet += key.Name + ","; |
|
|
|
keySetParam += "@" + key.Name + ","; |
|
|
|
keySetParam += "@" + key.Name + ","; |
|
|
|
} |
|
|
|
} |
|
|
@ -84,7 +91,8 @@ namespace EGFramework |
|
|
|
var properties = DataType.GetProperties(); |
|
|
|
var properties = DataType.GetProperties(); |
|
|
|
string keySet = ""; |
|
|
|
string keySet = ""; |
|
|
|
string keySetParam = ""; |
|
|
|
string keySetParam = ""; |
|
|
|
foreach(PropertyInfo key in properties){ |
|
|
|
foreach (PropertyInfo key in properties) |
|
|
|
|
|
|
|
{ |
|
|
|
keySet += key.Name + ","; |
|
|
|
keySet += key.Name + ","; |
|
|
|
keySetParam += "@" + key.Name + ","; |
|
|
|
keySetParam += "@" + key.Name + ","; |
|
|
|
} |
|
|
|
} |
|
|
@ -102,8 +110,10 @@ namespace EGFramework |
|
|
|
} |
|
|
|
} |
|
|
|
string keySet = ""; |
|
|
|
string keySet = ""; |
|
|
|
string keySetParam = ""; |
|
|
|
string keySetParam = ""; |
|
|
|
foreach(KeyValuePair<string,object> param in data){ |
|
|
|
foreach (KeyValuePair<string, object> param in data) |
|
|
|
if (param.Key == "ID" || param.Key == "Id" || param.Key == "id"){ |
|
|
|
{ |
|
|
|
|
|
|
|
if (param.Key == "ID" || param.Key == "Id" || param.Key == "id") |
|
|
|
|
|
|
|
{ |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
keySet += param.Key + ","; |
|
|
|
keySet += param.Key + ","; |
|
|
@ -138,8 +148,10 @@ namespace EGFramework |
|
|
|
Type DataType = typeof(TData); |
|
|
|
Type DataType = typeof(TData); |
|
|
|
var properties = DataType.GetProperties(); |
|
|
|
var properties = DataType.GetProperties(); |
|
|
|
string keyMap = ""; |
|
|
|
string keyMap = ""; |
|
|
|
foreach(PropertyInfo key in properties){ |
|
|
|
foreach (PropertyInfo key in properties) |
|
|
|
if(key.Name=="ID" || key.Name == "id" || key.Name == "Id"){ |
|
|
|
{ |
|
|
|
|
|
|
|
if (key.Name == "ID" || key.Name == "id" || key.Name == "Id") |
|
|
|
|
|
|
|
{ |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
keyMap += key.Name + " = @" + key.Name + ","; |
|
|
|
keyMap += key.Name + " = @" + key.Name + ","; |
|
|
@ -158,8 +170,10 @@ namespace EGFramework |
|
|
|
throw new ArgumentNullException(nameof(data)); |
|
|
|
throw new ArgumentNullException(nameof(data)); |
|
|
|
} |
|
|
|
} |
|
|
|
string keyMap = ""; |
|
|
|
string keyMap = ""; |
|
|
|
foreach (KeyValuePair<string, object> param in data) { |
|
|
|
foreach (KeyValuePair<string, object> param in data) |
|
|
|
if (param.Key == "ID" || param.Key == "Id" || param.Key == "id"){ |
|
|
|
{ |
|
|
|
|
|
|
|
if (param.Key == "ID" || param.Key == "Id" || param.Key == "id") |
|
|
|
|
|
|
|
{ |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
if (param.Value is string) |
|
|
|
if (param.Value is string) |
|
|
@ -197,9 +211,12 @@ namespace EGFramework |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
var result = Connection.QuerySingle("select * from " + dataKey + " where ID = @ID", new { ID = id }); |
|
|
|
var result = Connection.QuerySingle("select * from " + dataKey + " where ID = @ID", new { ID = id }); |
|
|
|
if(result == null){ |
|
|
|
if (result == null) |
|
|
|
|
|
|
|
{ |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
}else{ |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -225,8 +242,8 @@ namespace EGFramework |
|
|
|
// throw new System.NotImplementedException(); |
|
|
|
// throw new System.NotImplementedException(); |
|
|
|
if (this.ContainsKey(dataKey)) |
|
|
|
if (this.ContainsKey(dataKey)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
//Drop table if has. |
|
|
|
EG.Print("Table " + dataKey + " has been created!"); |
|
|
|
Connection.Execute(@"DROP TABLE IF EXISTS "+dataKey+""); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
string createSql = typeof(TData).ToCreateTableSQL(dataKey); |
|
|
|
string createSql = typeof(TData).ToCreateTableSQL(dataKey); |
|
|
|
int count = Connection.Execute(createSql); |
|
|
|
int count = Connection.Execute(createSql); |
|
|
@ -234,7 +251,26 @@ namespace EGFramework |
|
|
|
|
|
|
|
|
|
|
|
public void CreateTable(string dataKey, Dictionary<string, object> tableParam) |
|
|
|
public void CreateTable(string dataKey, Dictionary<string, object> tableParam) |
|
|
|
{ |
|
|
|
{ |
|
|
|
throw new NotImplementedException(); |
|
|
|
if (this.ContainsKey(dataKey)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
EG.Print("Table " + dataKey + " has been created!"); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Dictionary<string, Type> tableType = new Dictionary<string, Type>(); |
|
|
|
|
|
|
|
foreach (KeyValuePair<string, object> pair in tableParam) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
tableType.Add(pair.Key, pair.Value.GetType()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
string createSql = tableType.ToCreateTableSQL(dataKey); |
|
|
|
|
|
|
|
int count = Connection.Execute(createSql); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void DropTable(string dataKey) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (this.ContainsKey(dataKey)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Connection.Execute(@"DROP TABLE IF EXISTS "+dataKey+""); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |