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.
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace ClientTest
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
*类名称:ConfigReader
|
|
|
|
|
*创建人:韩荣伟
|
|
|
|
|
*创建时间:2010-10-30
|
|
|
|
|
*功能描述:配置读取类,读取xml配置参数
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
class ConfigReader
|
|
|
|
|
{
|
|
|
|
|
public string sDatabase;
|
|
|
|
|
public string sServer;
|
|
|
|
|
public string sPWD;
|
|
|
|
|
public string sServerIP;
|
|
|
|
|
public string sServerPort;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*方法名称:Load
|
|
|
|
|
*创建人:韩荣伟
|
|
|
|
|
*创建时间:2010-10-30
|
|
|
|
|
*参数描述:string sConfigFile xml配置文件,含路径
|
|
|
|
|
*返回描述:bool true,加载成功,false 失败
|
|
|
|
|
*功能描述:参数读取
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public bool Load(string sConfigFile)
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists(sConfigFile) == false)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
XmlElement theConfig = null, theElem = null, root = null;
|
|
|
|
|
XmlDocument xmldoc = new XmlDocument();
|
|
|
|
|
xmldoc.Load(sConfigFile);
|
|
|
|
|
root = xmldoc.DocumentElement;
|
|
|
|
|
theConfig = (XmlElement)root.SelectSingleNode("/root/config");
|
|
|
|
|
//mycontrols.UserControl1 userControl;
|
|
|
|
|
if (theConfig != null)
|
|
|
|
|
{
|
|
|
|
|
theElem = (XmlElement)theConfig.FirstChild;
|
|
|
|
|
while (theElem != null)
|
|
|
|
|
{
|
|
|
|
|
if (theElem.Name == "Database")
|
|
|
|
|
{
|
|
|
|
|
sDatabase = theElem.InnerXml;
|
|
|
|
|
}
|
|
|
|
|
else if (theElem.Name == "Server")
|
|
|
|
|
{
|
|
|
|
|
sServer = theElem.InnerXml;
|
|
|
|
|
}
|
|
|
|
|
else if (theElem.Name == "PWD")
|
|
|
|
|
{
|
|
|
|
|
sPWD = theElem.InnerXml;
|
|
|
|
|
}
|
|
|
|
|
else if (theElem.Name == "ServerIP")
|
|
|
|
|
{
|
|
|
|
|
sServerIP = theElem.InnerXml;
|
|
|
|
|
}
|
|
|
|
|
else if (theElem.Name == "ServerPort")
|
|
|
|
|
{
|
|
|
|
|
sServerPort = theElem.InnerXml;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
theElem = (XmlElement)theElem.NextSibling;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|