ホテル管理システム
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
 
namespace HotelPms.Share.IO
{
    public class FileOperation
    {
        [System.Runtime.InteropServices.DllImport("shell32.dll")]
        private static extern int ExtractIconEx(string lpszFile, int niconIndex, ref IntPtr phiconLarge, ref IntPtr phiconSmall, int nIcons);
 
        /// <summary>Žw’èPATH‚ňꊇƒRƒs[‚·‚é</summary>
        /// <param name="hsSrcDir">Œ³ƒp[ƒX</param>
        /// <param name="hsDstDir">–Ú•Wƒp[ƒX</param>
        /// <returns>bool</returns>
        public static bool CopyTree(string hsSrcDir, string hsDstDir)
        {
            try
            {
                //–Ú•Wƒp[ƒX‚ª‚È‚¯‚ê‚΁Aì‚éB
                if (!Directory.Exists(hsDstDir))
                {
                    Directory.CreateDirectory(hsDstDir);
                }
 
                //ƒtƒ@ƒCƒ‹‚ðƒRƒs[
                string[] wvFileArray = Directory.GetFiles(hsSrcDir);
                if (wvFileArray.Length > 0)
                {
                    foreach (string wsCurfile in wvFileArray)
                    {
                        string dstFile = hsDstDir + Path.DirectorySeparatorChar + Path.GetFileName(wsCurfile);
                        Delete(dstFile);
                        File.Copy(wsCurfile, dstFile, true);
                    }
                }
 
                //ŽqƒtƒHƒ‹ƒ_‚ðƒRƒs[
                string wsCurSrcDir = null;
                string wsCurFullDstDir = null;
 
                string[] wvDirArray = Directory.GetDirectories(hsSrcDir);
 
                if (wvDirArray.Length > 0)
                {
                    foreach (string wsCurFullSrcDir in wvDirArray)
                    {
                        wsCurSrcDir = wsCurFullSrcDir.Substring(wsCurFullSrcDir.LastIndexOf(Path.DirectorySeparatorChar) + 1);
                        wsCurFullDstDir = hsDstDir + Path.DirectorySeparatorChar + wsCurSrcDir;
 
                        CopyTree(wsCurFullSrcDir, wsCurFullDstDir);
                    }
                }
 
                return true;
            }
            catch
            {
                return false;
            }
 
        }
 
        public static List<string> GetDirList(string rootDir)
        {
            List<string> retDir = new List<string>();
            string[] dirList = Directory.GetDirectories(rootDir);
            retDir.AddRange(dirList);
 
            foreach (string item in dirList)
            {
                retDir.AddRange(GetDirList(item));
            }
 
            return retDir;
        }
 
        /// <summary>Žw’èPATH‚Ńtƒ@ƒCƒ‹ˆê——‚ðŽæ“¾‚·‚é</summary>
        /// <param name="hsSrcDir">Œ³ƒp[ƒX</param>
        /// <param name="hoFileList">ƒtƒ@ƒCƒ‹ˆê——</param>
        /// <returns>bool</returns>
        public static bool GetFileList(string hsSrcDir, ref List<string> hoFileList)
        {
            return GetFileList(hsSrcDir, ref hoFileList, "*");
        }
 
        /// <summary>Žw’èPATH‚Ńtƒ@ƒCƒ‹ˆê——‚ðŽæ“¾‚·‚é</summary>
        /// <param name="hsSrcDir">Œ³ƒp[ƒX</param>
        /// <param name="hoFileList">ƒtƒ@ƒCƒ‹ˆê——</param>
        /// <param name="hsSearchPattern">ƒtƒ@ƒCƒ‹‚̃^ƒCƒv(—á *.txtA*.sql“™)</param>
        /// <returns>bool</returns>
        public static bool GetFileList(string hsSrcDir, ref List<string> hoFileList, string hsSearchPattern)
        {
            try
            {
                string[] wvFileArray = Directory.GetFiles(hsSrcDir, hsSearchPattern);
                if (wvFileArray.Length > 0)
                {
                    foreach (string wsCurfile in wvFileArray)
                    {
                        hoFileList.Add(wsCurfile);
                    }
                }
 
                string[] wvDirArray = Directory.GetDirectories(hsSrcDir);
 
                if (wvDirArray.Length > 0)
                {
                    foreach (string wsCurFullSrcDir in wvDirArray)
                    {
                        GetFileList(wsCurFullSrcDir, ref  hoFileList, hsSearchPattern);
                    }
                }
 
                return true;
            }
            catch
            {
                return false;
            }
        }
 
        public static void DeleteFile(string fileName)
        {
            try
            {
                FileInfo fi = new FileInfo(fileName);
                if ((fi.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                {
                    fi.Attributes = FileAttributes.Normal;
                }
 
                File.Delete(fileName);
            }
            catch { }
        }
 
        /// <summary>ƒtƒ@ƒCƒ‹‚ðíœ‚·‚é</summary>
        /// <param name="fileName">ƒtƒ@ƒCƒ‹–¼</param>
        /// <returns>bool</returns>
        public static bool Delete(string fileName)
        {
            try
            {
                FileInfo fi = new FileInfo(fileName);
                if ((fi.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                {
                    fi.Attributes = FileAttributes.Normal;
                }
 
                File.Delete(fileName);
 
                return true;
            }
            catch
            {
                return false;
            }
        }
 
        /// <summary>ƒtƒ@ƒCƒ‹‚ÌŽí—ނō폜‚·‚é</summary>
        /// <param name="hsSrcDir">ƒp[ƒX</param>
        /// <param name="hsSearchPattern">ƒtƒ@ƒCƒ‹‚ÌŽí—Þ(—á *.txtA*.sql“™)</</param>
        /// <returns>bool</returns>
        public static bool Delete(string hsSrcDir, string[] hsSearchPattern)
        {
            try
            {
                List<string> hoList = new List<string>();
                for (int i = 0; i < hsSearchPattern.Length; i++)
                {
                    GetFileList(hsSrcDir, ref  hoList, hsSearchPattern[i]);
                }
 
                for (int i = 0; i < hoList.Count; i++)
                {
                    FileInfo fi = new FileInfo(hoList[i].ToString());
                    if ((fi.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                    {
                        fi.Attributes = FileAttributes.Normal;
                    }
 
                    File.Delete(hoList[i].ToString());
                }
 
                hoList.Clear();
 
                return true;
            }
            catch
            {
                return false;
            }
        }
 
        /// <summary>
        /// “ǂݎæ‚èê—p‚ðŠO‚·
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static bool UnReadOnly(string filePath)
        {
            try
            {
                FileInfo fi = new FileInfo(filePath);
                if ((fi.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                {
                    fi.Attributes = FileAttributes.Normal;
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
 
        /// <summary>‘SPathíœ‚·‚é</summary>
        /// <param name="aimpath">ƒp[ƒX</param>
        /// <returns>bool</returns>
        public static bool DeleteDir(string aimpath)
        {
            try
            {
                if (aimpath[aimpath.Length - 1] != Path.DirectorySeparatorChar)
                {
                    aimpath += Path.DirectorySeparatorChar;
                }
                string[] filelist = Directory.GetFileSystemEntries(aimpath);
                foreach (string file in filelist)
                {
                    if (Directory.Exists(file))
                    {
                        DeleteDir(aimpath + Path.GetFileName(file));
                    }
                    else
                    {
                        string filePath = aimpath + Path.GetFileName(file);
                        UnReadOnly(filePath);
                        File.Delete(filePath);
                    }
                }
                Directory.Delete(aimpath, true);
                return true;
            }
            catch
            {
                return false;
            }
        }
 
        ///// <summary>
        ///// ƒtƒ@ƒCƒ‹‚̃Rƒs[
        ///// </summary>
        ///// <param name="fileList"></param>
        //public static void CopyToClipboard(System.Collections.Specialized.StringCollection fileList)
        //{
        //    //System.Collections.Specialized.StringCollection strcoll = new System.Collections.Specialized.StringCollection();
        //    //strcoll.Add(System.Windows.Forms.Application.ExecutablePath);
        //    //strcoll.Add(Application.StartupPath + @"\GoogleJapaneseInputSetup.exe");
        //    Clipboard.SetFileDropList(fileList);
        //}
    }
}