ホテル管理システム
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
using HotelPms.Share.Windows.Util;
using HotelPms.SourceFactory.Table;
using System.Text;
 
namespace HotelPms.SourceFactory.Util;
 
public class EnumFactory
{
    public static string Create(string path, int sheetIndex)
    {
        StringBuilder text = new();
        using NPOIExcel excel = new(path);
        excel.SetCurrentSheet(sheetIndex);
        bool start = false; 
        for (int i = 0; i < excel.Sheet.LastRowNum; i++)
        {
            string line = excel.GetCellString($"B{i+1}");
            if(line.Length > 0 && line.Substring(0,1) == "■")
            {
                int p1 = line.IndexOf('(');
                int p2 = line.IndexOf(')');
                string name = line.Substring(p1 + 1, p2 - p1 - 1);
                text.Append(Environment.NewLine);
                text.AppendLine($"public enum {name} : int");
                text.AppendLine("{");
                start = true;
            }
            else
            {                
                if (start) 
                {
                    string itemLine = excel.GetCellString($"C{i + 1}").Trim();
                    if (itemLine.Length == 0) { text.AppendLine("}"); start = false; }
                    else if (itemLine == "名称") { continue; }
                    else
                    {
                        text.AppendLine($"[Description(\"{excel.GetCellString($"R{i + 1}").Trim()}\")]");
                        text.AppendLine($"{itemLine} = {excel.GetCellInt($"O{i + 1}")},");
                    }                   
                }
 
            }
 
        }
 
        return text.ToString(); 
    }
 
}