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.
170 lines
4.8 KiB
170 lines
4.8 KiB
3 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Text;
|
||
|
using System.IO;
|
||
|
using Stone.Common.Biz;
|
||
|
using System.Data;
|
||
|
|
||
|
namespace Stone.Common
|
||
|
{
|
||
|
public class MyAppconfig
|
||
|
{
|
||
|
//public static string ReadValue(string name)
|
||
|
//{
|
||
|
// IniClass ini = new IniClass(DllPath.GetDllPath() + "\\Stone.WinForm.ini");
|
||
|
// return ini.IniReadValue("系统配置", name);
|
||
|
//}
|
||
|
|
||
|
//public static void WriteValue(string name, string value)
|
||
|
//{
|
||
|
// IniClass ini = new IniClass(DllPath.GetDllPath() + "\\Stone.WinForm.ini");
|
||
|
// ini.IniWriteValue("系统配置", name, value);
|
||
|
//}
|
||
|
|
||
|
|
||
|
public static void Test()
|
||
|
{
|
||
|
DataSet dsAppconfig = new DataSet();
|
||
|
|
||
|
DataTable dt = new DataTable();
|
||
|
dt.TableName = "AppConfig";
|
||
|
|
||
|
dt.Columns.Add("Name");
|
||
|
dt.Columns.Add("Value");
|
||
|
|
||
|
dsAppconfig.Tables.Add(dt);
|
||
|
|
||
|
DataRow drData = dt.NewRow();
|
||
|
drData["Name"] = "配置一";
|
||
|
drData["Value"] = "OK1";
|
||
|
dsAppconfig.Tables[0].Rows.Add(drData);
|
||
|
|
||
|
drData = dt.NewRow();
|
||
|
drData["Name"] = "配置二";
|
||
|
drData["Value"] = "OK2";
|
||
|
dsAppconfig.Tables[0].Rows.Add(drData);
|
||
|
|
||
|
drData = dt.NewRow();
|
||
|
drData["Name"] = "配置三";
|
||
|
drData["Value"] = "OK3";
|
||
|
dsAppconfig.Tables[0].Rows.Add(drData);
|
||
|
|
||
|
dsAppconfig.Tables[0].WriteXml(MyIO.GetAppPath() + "\\Stone.WinForm.xml");
|
||
|
}
|
||
|
|
||
|
public static string ReadValue(string name)
|
||
|
{
|
||
|
string ret = "";
|
||
|
try
|
||
|
{
|
||
|
DataSet dsAppConfig = new DataSet();
|
||
|
dsAppConfig.ReadXml(MyIO.GetAppPath() + "\\Stone.WinForm.xml");
|
||
|
|
||
|
DataRow[] drs = dsAppConfig.Tables[0].Select("[Name]='" + name + "'");
|
||
|
if (drs.Length > 0)
|
||
|
{
|
||
|
ret = drs[0]["Value"].ToString();
|
||
|
}
|
||
|
}
|
||
|
catch
|
||
|
{
|
||
|
}
|
||
|
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
public static void WriteValue(string name, string value)
|
||
|
{
|
||
|
DataSet dsAppconfig = new DataSet();
|
||
|
string file = MyIO.GetAppPath() + "\\Stone.WinForm.xml";
|
||
|
if (!File.Exists(file))
|
||
|
{
|
||
|
DataTable dt = new DataTable();
|
||
|
dt.TableName = "AppConfig";
|
||
|
|
||
|
dt.Columns.Add("Name");
|
||
|
dt.Columns.Add("Value");
|
||
|
|
||
|
dsAppconfig.Tables.Add(dt);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
dsAppconfig.ReadXml(file);
|
||
|
}
|
||
|
|
||
|
DataRow[] drs = dsAppconfig.Tables[0].Select("[Name]='" + name + "'");
|
||
|
if (drs.Length == 0)
|
||
|
{
|
||
|
DataRow drData = dsAppconfig.Tables[0].NewRow();
|
||
|
drData["Name"] = name;
|
||
|
drData["Value"] = value;
|
||
|
dsAppconfig.Tables[0].Rows.Add(drData);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
drs[0]["Value"] = value;
|
||
|
}
|
||
|
|
||
|
dsAppconfig.Tables[0].WriteXml(file);
|
||
|
}
|
||
|
|
||
|
public static string ReadValue(string filename, string type, string name)
|
||
|
{
|
||
|
string ret = "";
|
||
|
try
|
||
|
{
|
||
|
DataSet dsAppConfig = new DataSet();
|
||
|
dsAppConfig.ReadXml(filename);
|
||
|
|
||
|
DataRow[] drs = dsAppConfig.Tables[0].Select("[Name]='" + name + "'");
|
||
|
if (drs.Length > 0)
|
||
|
{
|
||
|
ret = drs[0]["Value"].ToString();
|
||
|
}
|
||
|
}
|
||
|
catch
|
||
|
{
|
||
|
}
|
||
|
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
public static void WriteValue(string filename, string type, string name, string value)
|
||
|
{
|
||
|
DataSet dsAppconfig = new DataSet();
|
||
|
string file = filename;
|
||
|
if (!File.Exists(file))
|
||
|
{
|
||
|
DataTable dt = new DataTable();
|
||
|
dt.TableName = "AppConfig";
|
||
|
|
||
|
dt.Columns.Add("Type");
|
||
|
dt.Columns.Add("Name");
|
||
|
dt.Columns.Add("Value");
|
||
|
|
||
|
dsAppconfig.Tables.Add(dt);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
dsAppconfig.ReadXml(file);
|
||
|
}
|
||
|
|
||
|
DataRow[] drs = dsAppconfig.Tables[0].Select("[Type] = '" + type + "' and [Name]='" + name + "'");
|
||
|
if (drs.Length == 0)
|
||
|
{
|
||
|
DataRow drData = dsAppconfig.Tables[0].NewRow();
|
||
|
drData["Type"] = type;
|
||
|
drData["Name"] = name;
|
||
|
drData["Value"] = value;
|
||
|
dsAppconfig.Tables[0].Rows.Add(drData);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
drs[0]["Value"] = value;
|
||
|
}
|
||
|
|
||
|
dsAppconfig.Tables[0].WriteXml(file);
|
||
|
}
|
||
|
}
|
||
|
}
|