ホテル管理システム
ogi
yesterday 1a1c8e71fcd14858f595029f089b2d4a00202b32
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
using System;
using System.Collections.Generic;
using System.Text;
using HotelPms.Share.Util;
using System.Xml;
using System.IO;
 
namespace HotelPms.Share.Xml
{
    /// ****************************** Description *******************************
    /// žƒVƒXƒeƒ€–¼Ì
    /// @”Ä—pƒNƒ‰ƒX
    /// žŠT—v
    /// @Config.xml‚ð“Ǎž
    /// ž—š—ð
    /// @20070803  ¬–؁@Ÿ—´    V‹Kì¬
    /// ****************************** 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€‚Ì‚w‚l‚k‚ð“Ç‚Þ
        /// </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;
            }
        } 
 
    }
}