You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
3.5 KiB
C#
107 lines
3.5 KiB
C#
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<string, SysParameter> sysParamDic = new Dictionary<string, SysParameter>();
|
|
|
|
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<SysParameter>(row);
|
|
if (parm != null)
|
|
{
|
|
if (!sysParamDic.ContainsKey(parm.FieldName))
|
|
{
|
|
sysParamDic.Add(parm.FieldName, parm);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static T GetValue<T>(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 descAndCategory="")
|
|
{
|
|
if(!sysParamDic.ContainsKey(key))
|
|
{
|
|
string desc = "", category = "";
|
|
if(!string.IsNullOrEmpty(descAndCategory))
|
|
{
|
|
string[] items= descAndCategory.Split(',');
|
|
if(items.Length==2)
|
|
{
|
|
desc = items[0];
|
|
category = items[1];
|
|
}
|
|
}
|
|
string insertSql = $"insert into SysParameter(FieldName,FieldType,FieldValue,Desc,Category) values('{key}','string','{value}','{desc}','{category}')";
|
|
int count = db.ExecuteNonQuery(insertSql) ;
|
|
if (count > 0)
|
|
{
|
|
Init();
|
|
return count;
|
|
}
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
string updateSql = $"update SysParameter set FieldValue='{value}' where FieldName='{key}'";
|
|
int count = db.ExecuteNonQuery(updateSql);
|
|
if (count > 0)
|
|
{
|
|
//Init();
|
|
string querySql = $"select * from SysParameter where FieldName='{key}' ";
|
|
DataTable dtParameters = db.GetDataTable(querySql);
|
|
if (dtParameters != null && dtParameters.Rows.Count > 0)
|
|
{
|
|
SysParameter parm = EntityHelper.ToEntity<SysParameter>(dtParameters.Rows[0]);
|
|
sysParamDic.Remove(key);
|
|
sysParamDic.Add(key, parm);
|
|
}
|
|
return count;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|