SunVoteLPT.cs 3.17 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using GeneralLib;

namespace SunVoteARSPPT
{
    public class SunVoteLPT
    {
        /// <summary>
        /// xml文档
        /// </summary>
        private XmlDocument xmlDoc;
        /// <summary>
        /// xml文档的路径
        /// </summary>
        public string xmlDocPath = "";

        /// <summary>
        /// xml默认语言文档。杨斌 2014-11-19
        /// </summary>
        private XmlDocument xmlDocDef;
        /// <summary>
        /// xml默认语言路径。杨斌 2014-11-19
        /// </summary>
        public string xmlDocPathDef = "";

        /// <summary>
        /// 构造函数
        /// </summary>
        public SunVoteLPT()
        {
            xmlDoc = new XmlDocument();
            xmlDocDef = new XmlDocument();//杨斌 2014-11-19
        }
        /// <summary>
        /// 初始化语言
        /// </summary>
        public void LoadLanguage(string xmlDocPath)
        {
            xmlDoc.Load(xmlDocPath);
        }

        /// <summary>
        /// 初始化语言-默认。杨斌 2014-11-19
        /// </summary>
        /// <param name="xmlDocPath"></param>
        public void LoadLanguageDef(string xmlDocPath)
        {
            xmlDocDef.Load(xmlDocPath);
        }

        /// <summary>
        /// 读xml文件
        /// </summary>
        /// <param name="root"></param>
        /// <param name="element"></param>
        /// <param name="attribute"></param>
        /// <param name="dValue">默认值</param>
        /// <returns></returns>
        public string ReadString(string element, string attribute, string dValue)
        {
            //string nodePath = "//Language//" + element + "//" + attribute;
            //XmlNode node = xmlDoc.SelectSingleNode(nodePath);
            //if (node != null)
            //{
            //    //杨斌 2013-09-02
            //    dValue = node.InnerText;
            //    dValue = dValue.Replace("\\r\\n", "\r\n");
            //    return dValue;
            //}
            //return dValue;

            try
            {
                string nodePath = "//Language//" + element + "//" + attribute;

                //杨斌 2014-11-19
                XmlNode node = null;
                try
                {
                    node = xmlDoc.SelectSingleNode(nodePath);
                }
                catch (Exception ex)
                {
                    SystemLog.WriterLog(ex, false);
                }

                if (node == null)//没有则从默认语言加载。杨斌 2014-11-19
                {
                    if (attribute == "lblGroupName")
                        attribute = attribute;
                    try
                    {
                        node = xmlDocDef.SelectSingleNode(nodePath);
                    }
                    catch { }
                }

                if (node != null)
                {
                    //杨斌 2013-09-02
                    dValue = node.InnerText;
                    dValue = dValue.Replace("\\r\\n", "\r\n");
                }
            }
            catch { }
            return dValue;
        }

    }
}