?? dbconnectxml.cs
字號:
using System;
using System.Windows.Forms ;
using System.Text;
using System.Xml;
using System.Xml.XPath;
using System.IO;
namespace DataServer
{
/// <summary>
/// DBConnectXml 的摘要說明。
/// </summary>
public class DBConnectXml
{
private XmlElement xmlRoot ;
private XmlDocument xmlDoc ;
private static DBConnectXml _Instance = null ;
private string strRootName ;
private string FileName
{
get
{
return System.AppDomain.CurrentDomain.BaseDirectory+"DBConnect.xml" ;
}
}
public DBConnectXml()
{
Load() ;
}
public static DBConnectXml Instance()
{
if (_Instance == null)
_Instance = new DBConnectXml() ;
return _Instance ;
}
private bool Load()
{
if (!File.Exists(FileName))
CreateMaillinkFile(FileName);
if (xmlDoc == null)
xmlDoc = new XmlDocument() ;
try
{
xmlDoc.Load(FileName) ;
}
catch
{
return false ;
}
xmlRoot = xmlDoc.DocumentElement ;
if (xmlRoot != null)
strRootName = "/" + xmlRoot.Name + "/" ;
return true ;
}
public string GetNode(string strName)
{
XmlNode xNode = xmlRoot.SelectSingleNode(strRootName + strName) ;
if (xNode == null)
return null ;
else
return xNode.InnerText ;
}
private void CreateMaillinkFile(string strFileName)
{
StringBuilder sb = new StringBuilder() ;
sb.Append("<?xml version='1.0\' ?> ") ;
sb.Append("<dbconfig>") ;
sb.Append("<ServerName>fipamw</ServerName>") ;
sb.Append("<DataBase>kr_train</DataBase>") ;
sb.Append("<LogID>sa</LogID>") ;
sb.Append("<PWD></PWD>") ;
sb.Append("</dbconfig>") ;
XmlDocument xmlDoc = new XmlDocument() ;
xmlDoc.LoadXml(sb.ToString()) ;
xmlDoc.Save(strFileName) ;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -