www.pudn.com > startprepare.rar > ManageConfigs.cs
using System;
using System.Xml;
using System.IO;
namespace DS.EMIS.StartPrepare.Common
{
///
///
///
internal class ManageConfigs
{
public ManageConfigs()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
#region 标准配置文件的读写
/*
*
*
*
*
*
*
*
*/
public string GetConfig(string KeyValue,string FileName)
{
try
{
string reValue = "";
string currAppPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
if(System.IO.Path.IsPathRooted(FileName))
{
doc.Load(FileName);
}
else
{
doc.Load(currAppPath+".\\Configs\\"+FileName);
}
System.Xml.XmlNode node = doc.SelectSingleNode("//add[@key='"+KeyValue+"']");
System.Xml.XmlElement ele = (System.Xml.XmlElement)node;
reValue = ele.GetAttribute("value");
return reValue;
}
catch
{
return String.Empty;
}
}
public void UpdateConfig(string KeyValue,string Xvalue,string FileName)
{
string currAppPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(currAppPath+".\\Configs\\"+FileName);
System.Xml.XmlNode node = doc.SelectSingleNode(@"//add[@key='"+KeyValue+"']");
System.Xml.XmlElement ele = (System.Xml.XmlElement)node;
ele.SetAttribute("value",Xvalue);
doc.Save(currAppPath+".\\Configs\\"+FileName);
}
/*
*
*
* <接点名称 属性1="值" 属性2="值" 属性3="值" ...../>
*例:
*
*/
public System.Data.DataTable GetConfigs(string fileName,string nodeName)
{
System.Data.DataTable dataTable = new System.Data.DataTable("Configs");
XmlDocument doc = new XmlDocument();
if(System.IO.Path.IsPathRooted(fileName))
{
doc.Load(fileName);
}
else
{
doc.Load(".\\Configs\\"+fileName);
}
foreach(XmlNode node in doc.DocumentElement.ChildNodes)
{
if(node.Name.ToUpper() == nodeName.ToUpper())
{
if(dataTable.Columns.Count == 0)
{
for(int i=0;i