ホテル管理システム
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;
using HotelPms.Share.IO;
using HotelPms.Share.Util;
 
namespace HotelPms.Share.Xml
{
    public class SysXmlMgr :IDisposable
    {
        /// ****************************** Description *******************************
        /// žƒVƒXƒeƒ€–¼Ì
        /// @”Ä—pƒNƒ‰ƒX
        /// žŠT—v
        /// @XML‚Ì‘€ìF’ljÁAC³AíœAŒŸõ‚È‚Ç
        /// <>Žg—p•û–@
        /// ž—š—ð
        /// @2007/11/10  ¬–؁@Ÿ—´    V‹Kì¬
        /// ****************************** Declarations ******************************
        #region  ššššš@Declartions@ššššš
 
        private string fileName;
        private Dictionary<string, string>? fileInfo;
 
        #endregion
 
        #region  ššššš@Property@ššššš
 
        public string FileName
        {
            get { return fileName; }
            set { fileName = value; }
        }
 
        public Dictionary<string, string> FileInfo
        {
            get { return fileInfo; }
            set { fileInfo = value; }
        }
            
        #endregion
 
        #region  ššššš@Class Event@ššššš
 
        public SysXmlMgr()
            : this("")
        {
        }
 
        public SysXmlMgr(string fileName)
        {
            if (!fileName.Equals(""))
            {
                this.fileName = fileName;
            }
            if (!File.Exists(this.fileName))
            {
                fileInfo = new Dictionary<string, string>();
            }
            else
            {
                fileInfo = GetNormalXml(this.fileName);
            }
            
        }
 
        #endregion
 
        #region  ššššš@Private Function@ššššš
        #endregion
 
        #region  ššššš@Public  Function@ššššš
 
        public static Dictionary<string, string> GetNormalXml(object hvConfigXml)
        {
            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);
                        }
                    }
                }
                return config;
            }
            catch
            {
                return null;
            }
        }
 
        public int GetInt(string name)
        {
            return CConvert.ToInt(GetItem(name));
        }
 
        public bool GetBool(string name)
        {
            return CConvert.ToBool(GetItem(name));
        }
 
        public string GetItem(string name)
        {
            if (fileInfo.ContainsKey(name))
            {
                return fileInfo[name];
            }
            else
            {
                return string.Empty;
            }
        }
 
        public bool SetItem(string name, string value)
        {
            return SetItem(name, value, false);
        }
 
        public bool SetItem(string name, string value, bool forceAdd)
        {
            if (fileInfo.ContainsKey(name))
            {
                fileInfo[name] = value;
                return true;
            }
            else
            {
                if (forceAdd)
                {
                    Add(name, value);
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
 
        public void Remove(string name)
        {
            fileInfo.Remove(name);
        }
 
        public void Add(string name,string value)
        {
            fileInfo.Add(name, value);
        }
 
        /// <summary>
        /// •Û‘¶‚·‚é
        /// </summary>
        /// <returns></returns>
        public bool Save()
        {
            try
            {             
                StringBuilder fileBuilder = new StringBuilder();
                fileBuilder.AppendLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
                fileBuilder.AppendLine("<environment>");
                foreach (string item in fileInfo.Keys)
                {
                    fileBuilder.AppendLine("  <param>");
                    fileBuilder.AppendLine("    <name>" + item + "</name>");
                    fileBuilder.AppendLine("    <value>" + fileInfo[item] + "</value>");
                    fileBuilder.AppendLine("  </param>");
                }
                fileBuilder.AppendLine("</environment>");
                FileOperation.Delete(fileName);
                File.WriteAllText(fileName, fileBuilder.ToString(), Encoding.UTF8);
                return true;
            }
            catch
            {
                return false;
            }
        }
 
        public void ReLoad()
        {
            this.fileInfo = GetNormalXml(this.fileName);
        }
 
        public void Dispose()
        {
        }
 
        #endregion
    }
}