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.
108 lines
2.5 KiB
108 lines
2.5 KiB
3 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Text;
|
||
|
using System.Data;
|
||
|
|
||
|
using System.Windows.Forms;
|
||
|
using System.IO;
|
||
|
|
||
|
namespace PDAForm.Comm
|
||
|
{
|
||
|
public class MyAppconfig
|
||
|
{
|
||
|
private static DataSet dsData = null;
|
||
|
private static string patch = string.Empty;
|
||
|
static MyAppconfig()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
patch = MyFileManager.GetApplicationPath() + @"PDAForm.xml";
|
||
|
dsData = new DataSet();
|
||
|
|
||
|
if (!File.Exists(patch))
|
||
|
{
|
||
|
dsData = new DataSet();
|
||
|
|
||
|
DataTable dtConfig = new DataTable("ConfigList");
|
||
|
dtConfig.Columns.Add("Name");
|
||
|
dtConfig.Columns.Add("Value");
|
||
|
|
||
|
dsData.Tables.Add(dtConfig);
|
||
|
dsData.WriteXml(patch);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
dsData.ReadXml(patch);
|
||
|
}
|
||
|
}
|
||
|
catch { }
|
||
|
}
|
||
|
|
||
|
public static string GetValue(string name)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
DataRow[] drs = dsData.Tables[0].Select("Name='" + name.Trim() + "'");
|
||
|
if (drs.Length > 0)
|
||
|
{
|
||
|
return drs[0]["Value"].ToString().Trim();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return "";
|
||
|
}
|
||
|
}
|
||
|
catch
|
||
|
{
|
||
|
return "";
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
public static void SetValue(string name, string configvalue)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
DataRow[] drs = dsData.Tables[0].Select("Name='" + name.Trim() + "'");
|
||
|
|
||
|
if (drs.Length == 0)
|
||
|
{
|
||
|
DataRow dr = dsData.Tables[0].NewRow();
|
||
|
dr["Name"] = name;
|
||
|
dr["Value"] = configvalue;
|
||
|
dsData.Tables[0].Rows.Add(dr);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
drs[0]["Value"] = configvalue;
|
||
|
}
|
||
|
|
||
|
dsData.WriteXml(patch);
|
||
|
}
|
||
|
catch { }
|
||
|
}
|
||
|
|
||
|
private static DataTable GetTable()
|
||
|
{
|
||
|
if (dsData != null)
|
||
|
{
|
||
|
return dsData.Tables[0];
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private static void Save()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
dsData.WriteXml(patch);
|
||
|
}
|
||
|
catch { }
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|