using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using HotelPms.Share.Util;
|
using System.Xml;
|
using System.IO;
|
|
namespace HotelPms.Share.Xml
|
{
|
/// ****************************** Description *******************************
|
/// VXe¼Ì
|
/// @ÄpNX
|
/// Tv
|
/// @Config.xmlðÇ
|
/// ð
|
/// @20070803 ¬Ø@´ VKì¬
|
/// ****************************** Declarations ******************************
|
public class ConfigXml
|
{
|
private static string configXmlPath = System.AppDomain.CurrentDomain.BaseDirectory + @"Config.xml";
|
private static string dBServer = string.Empty;
|
private static string dBName = string.Empty;
|
private static string dBUser = string.Empty;
|
private static string dBPassWord = string.Empty;
|
|
public static string DBName
|
{
|
get { return dBName; }
|
set { dBName = value; }
|
}
|
|
public static string DBServer
|
{
|
get { return dBServer; }
|
set { dBServer = value; }
|
}
|
|
public static string DBUser
|
{
|
get { return dBUser; }
|
set { dBUser = value; }
|
}
|
|
public static string DBPassWord
|
{
|
get { return dBPassWord; }
|
set { dBPassWord = value; }
|
}
|
|
public static string ConfigXmlPath
|
{
|
get { return configXmlPath; }
|
set { configXmlPath = value; }
|
}
|
|
/// <summary>
|
/// [ÝèÌÇÝÝ
|
/// </summary>
|
public static void GetConfigXml()
|
{
|
try
|
{
|
if (!File.Exists(configXmlPath))
|
{
|
try
|
{
|
string[] connectInfo = new string[4];
|
//ȯêζ¬·é
|
StringBuilder fileBuilder = new StringBuilder();
|
fileBuilder.AppendLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
fileBuilder.AppendLine("<environment>");
|
fileBuilder.AppendLine(" <param>");
|
fileBuilder.AppendLine(" <name>DataSource</name>");
|
fileBuilder.AppendLine(string.Format(" <value>{0}</value>", connectInfo[0]));
|
fileBuilder.AppendLine(" </param>");
|
fileBuilder.AppendLine(" <param>");
|
fileBuilder.AppendLine(" <name>InitialCatalog</name>");
|
fileBuilder.AppendLine(string.Format(" <value>{0}</value>", connectInfo[1]));
|
fileBuilder.AppendLine(" </param>");
|
fileBuilder.AppendLine(" <param>");
|
fileBuilder.AppendLine(" <name>UserID</name>");
|
fileBuilder.AppendLine(string.Format(" <value>{0}</value>", connectInfo[2]));
|
fileBuilder.AppendLine(" </param>");
|
fileBuilder.AppendLine(" <param>");
|
fileBuilder.AppendLine(" <name>Password</name>");
|
fileBuilder.AppendLine(string.Format(" <value>{0}</value>", connectInfo[3]));
|
fileBuilder.AppendLine(" </param>");
|
fileBuilder.AppendLine("</environment>");
|
File.WriteAllText(configXmlPath, fileBuilder.ToString(), Encoding.UTF8);
|
}
|
catch
|
{
|
return;
|
}
|
}
|
|
Dictionary<string, string> dic = SysXmlMgr.GetNormalXml(configXmlPath);
|
dBServer = dic["DataSource"];
|
dBName = dic["InitialCatalog"];
|
dBUser = dic["UserID"];
|
dBPassWord = dic["Password"];
|
dic.Clear();
|
}
|
catch { }
|
}
|
|
/// <summary>
|
/// ¼½ÃÑWÌwlkðÇÞ
|
/// </summary>
|
/// <param name="hvConfigXml">̧²ÙÊß½</param>
|
/// <param name="hsKeyName">SystemStorageÌL[</param>
|
/// <returns>bool</returns>
|
public static bool GetNormalXml(object hvConfigXml, string hsKeyName)
|
{
|
Dictionary<string, string> config = new Dictionary<string, string>();
|
XmlDocument doc = new XmlDocument();
|
string itemName = string.Empty;
|
string itemValue = string.Empty;
|
try
|
{
|
if (hvConfigXml is Stream)
|
{
|
doc.Load((hvConfigXml as Stream));
|
}
|
else
|
{
|
doc.Load((hvConfigXml as string));
|
}
|
XmlNode rootnode = doc.DocumentElement;
|
foreach (XmlNode child in rootnode.ChildNodes)
|
{
|
if (child.NodeType == XmlNodeType.Element)
|
{
|
if (child.HasChildNodes)
|
{
|
foreach (XmlNode woItem in child.ChildNodes)
|
{
|
if (woItem.NodeType == XmlNodeType.Element)
|
{
|
if (woItem.Name == "name")
|
{
|
itemName = woItem.InnerText;
|
}
|
else if (woItem.Name == "value")
|
{
|
itemValue = woItem.InnerText;
|
}
|
}
|
}
|
config.Add(itemName, itemValue);
|
}
|
}
|
}
|
SystemStorage.Instance().SetItem(hsKeyName, config);
|
return true;
|
}
|
catch
|
{
|
return false;
|
}
|
}
|
|
}
|
}
|