Blame view

SunVoteARSPPT/Common/SunVoteLPT.cs 3.17 KB
20c0108c   wutaian   xx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
  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;
          }
  
      }
  }