ホテル管理システム
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
using HotelPms.Client.Blazor.Util;
using HotelPms.Data;
using HotelPms.Data.Common;
using Grpc.Net.Client;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Channels;
using System.Threading.Tasks;
using HotelPms.Data.Client;
 
namespace HotelPms.Client.Blazor.ViewModel
{
    public class ColSettingData
    {
        /// <summary>
        /// 帳票ID
        /// </summary>
        public int ReportID { get; set; } = 0;
 
        /// <summary>
        /// 帳票名
        /// </summary>
        public string ReportName { get; set; }
 
        /// <summary>
        /// 項目一覧(S_ReportCol)
        /// </summary>
        public List<string> OrgColList { get; set; }
 
        /// <summary>
        /// 出力パターンID
        /// </summary>
        public int OutputID { get; set; }
 
        /// <summary>
        ///  出力パターン名
        /// </summary>
        public string OutputName { get; set; }
 
        /// <summary>
        /// 出力パターン候補一覧
        /// </summary>
        internal List<HotelPms.Data.Master.Output> OutputList { get; set; }
 
        /// <summary>
        /// 第一ソート順
        /// </summary>
        public string Sort1 { get; set; }
 
        /// <summary>
        /// 第二ソート順
        /// </summary>
        public string Sort2 { get; set; }
 
        public List<ColSettingRow> Rows { get; set; }
 
 
        /// <summary>
        /// 帳票設定データの作成
        /// </summary>
        /// <param name="reportID"></param>
        /// <param name="channel"></param>
        /// <returns></returns>
        public static async Task<ColSettingData> Create(int reportID, GrpcChannel channel)
        {
            string name = string.Empty;
            GrpcSet grpcSet = await GrpcClient.GetDataSet(channel, (int)ESetActionType.ColSetting, $"{Environment.MachineName},{EnvironmentSetting.UserName},{reportID}");
            if (grpcSet.ErrNo != 0) { return null; }
 
            using (DataTable dataTable = grpcSet.Tables[0].ToDataTable())
            {
                if (dataTable.Rows.Count > 0)
                {
                    name = dataTable.Rows[0]["Name"].ToString();
                }
            }
 
            List<string> list = new List<string>();
            using (DataTable dataTable = grpcSet.Tables[3].ToDataTable())
            {
                foreach(DataColumn col in dataTable.Columns)
                {
                    list.Add(col.ColumnName);
                }
            }
 
            //取得する(列設定情報)
            ColSettingData data = new ColSettingData
            {
                ReportID = reportID,
                ReportName = name,
                OutputList = grpcSet.Tables[1].Convert<HotelPms.Data.Master.Output>(),
                OrgColList = list,
                Rows = new List<ColSettingRow>(),
            };
 
            //Dict化
            Dictionary<int, HotelPms.Data.Master.Output> dict = new Dictionary<int, HotelPms.Data.Master.Output>();
            foreach (HotelPms.Data.Master.Output item in data.OutputList) { dict.Add(item.ID, item); } 
 
            //明細
            using (DataTable detail = grpcSet.Tables[2].ToDataTable())
            {
                foreach (DataRow row in detail.Rows)
                {
                    Data.Master.OutputItem outputItem = new Data.Master.OutputItem();
                    outputItem.ConvertDataRow(row);
                    Data.Master.Output parent = null;
                    if (!dict.TryGetValue(outputItem.OutputID, out parent)) { continue; }
                    parent.Items.Add(outputItem);
                }
            }
 
            return data;
        }
    }
}