/// <summary> /// 建構子 /// </summary> /// <param name="dbtyp">資料庫類別</param> /// <param name="connstr">連線字串</param> /// <param name="cmdtimeout">逾時設定</param> public DBEntity(DBType dbtyp, string connstr, int cmdtimeout = 30) { DBConnStr = connstr; DBTimeout = cmdtimeout; DBType = dbtyp; if (connstr.ToLower().StartsWith("server=")) { db = new DB(dbtyp, connstr, cmdtimeout); } else { db = new DB(dbtyp, ConnSecure.Decrypt(connstr), cmdtimeout); } _conn = db.CreateConnection(); }
private string getRedisData(IConfigurationSection section, string rediskey) { var redisconn = GetService <DBInfo>(section.Value); CSRedis.CSRedisClient csredis; try { csredis = new CSRedis.CSRedisClient(ConnSecure.Decrypt(redisconn.RedisConnStr)); RedisHelper.Initialization(csredis); } catch (Exception err) { NCLog.ExceptionLog(err, $"getRedisData error: {err.Message}"); throw new Exception($"getRedisData error: {err.Message}"); } var tokenstr = csredis.Get(rediskey); return(tokenstr); }
static void Main(string[] args) { DateTime dt = new DateTime(); var acc = NCUtility.AllowMonth(3, 4); /////////單一資料表操作///////// //宣告DB實體 DBEntity dBEntity = new DBEntity(DBType.MySql, "server=192.168.1.226;database=PMERP;Persist Security Info=False;uid=itlife;pwd=1qaz@WSX;ConnectionTimeout=300;DefaultCommandTimeout=300;Allow User Variables=True"); //Task.Run(()=> dBEntity.logHistory("a", "b", Guid.NewGuid())); TableEntity <NCModel.Org> userOrgTable = new TableEntity <NCModel.Org>(dBEntity); User_Company userOrgx = new User_Company { User_Id = Guid.Parse("1a7e021d-09ed-4d8c-adc7-39c5be0befd5") }; var userOrgs = userOrgTable.Select(new NCModel.Org()); //var userOrgs = userOrgTable.Select(new NCModel.Org { Code = "%0%"}); //宣告欲查詢資料表類 User u = new User() { //給定查詢key值,或給定其他欄位條件 Id = Guid.Parse("97d52e4c-8472-11ea-a6ce-1ab29814667c") }; //宣告資料表操作類 TableEntity <User> userTable = new TableEntity <User>(dBEntity); //查詢 List <User> result = userTable.Select(new User { Code = "%%" }); foreach (User _user in result) { //do job } var cnt = 190; List <string> ht = new List <string>(); Hashtable same = new Hashtable(); while (cnt > 0) { string _key = ConnSecure.GenerateUID(); if (ht.Contains(_key)) { same.Add(cnt, _key); } else { ht.Add(_key); Console.Write(_key); } cnt--; } foreach (var item in same.Keys) { Console.WriteLine($"SameKey:{item},{same[item]}"); } //更新單筆 result[0].Name = "NewName"; //userTable.Update(result[0]); //更新多筆 result[0].Name = "NewName"; //result[1].Name = "NewName"; //userTable.Update(result); //刪除單筆 //userTable.Delete(result[0]); //刪除多筆 // userTable.Delete(result); //自訂查詢; doQuery(); Console.Read(); }