using Rs.DataAccess; using Rs.Framework; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Rs.Controls { public class SysParameter { public int ID { get; set; } public string FieldName { get; set; } public string FieldType { get; set; } public string FieldValue { get; set; } public string Desc { get; set; } public string Category { get; set; } } public static class SysConfigParam { static SqliteHelper db = new SqliteHelper(); static Dictionary sysParamDic = new Dictionary(); public static void Init() { sysParamDic.Clear(); string querySql = "select * from SysParameter"; DataTable dtParameters = db.GetDataTable(querySql); if (dtParameters != null && dtParameters.Rows.Count > 0) { foreach (DataRow row in dtParameters.Rows) { SysParameter parm = EntityHelper.ToEntity(row); if (parm != null) { if (!sysParamDic.ContainsKey(parm.FieldName)) { sysParamDic.Add(parm.FieldName, parm); } } } } } public static T GetValue(string key) { if (sysParamDic.ContainsKey(key)) { SysParameter parm = sysParamDic[key]; return (T)Convert.ChangeType(parm.FieldValue, typeof(T)); } return default(T); } public static int Update(string key,string value) { string updateSql = $"update SysParameter set FieldValue='{value}' where FieldName='{key}'"; int count = db.ExecuteNonQuery(updateSql); if (count>0) { Init(); return count; } return 0; } } }