天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

94 lines
2.9 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using QMFrameWork.Data;
namespace Common.Config
{
public static class ConfigSetting
{
private static Dictionary<string, string> SettingList = null;
/// <summary>
/// 初始化配置信息
/// </summary>
public static void InitSettings()
{
Data.SqlLite.SqlLiteHelper dal = new Data.SqlLite.SqlLiteHelper();
string sql = "SELECT * FROM T_QM_HISCONFIG";
DataTable dt = null;
try
{
using (IDataSession session = DataFactory.CreateSession())
{
dt = session.GetTable(sql,new List<DataParameter>().ToArray());
}
SettingList = new Dictionary<string, string>();
foreach (DataRow row in dt.Rows)
{
SettingList.Add(row["KEYCODE"].ToString(), row["CONFIGVALUE"].ToString());
}
}
catch (Exception ex)
{
throw new Exceptions.CannotInitConfigException();
}
}
/// <summary>
/// 修改配置信息
/// </summary>
/// <param name="key">配置项</param>
/// <param name="value">值</param>
public static void SetSetting(string key, string value)
{
Data.SqlLite.SqlLiteHelper dal = new Data.SqlLite.SqlLiteHelper();
try
{
using (System.Data.IDbConnection conn = dal.OpenConnection(GetConnectionString()))
{
dal.ExecuteSql(conn, "UPDATE T_CONFIG SET CONFIGVALUE='" + value + "' WHERE KEYCODE='" + key + "'");
}
SettingList[key] = value;
}
catch (Exception ex)
{
throw new Exceptions.ExcuteFailsException();
}
}
/// <summary>
/// 获取配置值
/// </summary>
/// <param name="key">配置项</param>
/// <returns></returns>
public static string GetSetting(string key)
{
return SettingList[key];
}
/// <summary>
/// 获取数据库连接字符串
/// </summary>
/// <param name="index">数据库编号</param>
/// <returns></returns>
public static string GetDBConnString(int index)
{
return IO.Security.DES.Decrypt(GetSetting("Z" + index.ToString().PadLeft(3, '0')));
}
/// <summary>
/// 获取配置数据库连接字符串
/// </summary>
/// <returns></returns>
public static string GetConnectionString()
{
return string.Format(@"Data Source={0}\bds.dsf;",
System.Windows.Forms.Application.StartupPath);
}
}
}