ホテル管理システム
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
using Grpc.Net.Client;
using HotelPms.Client.Blazor.Util;
using HotelPms.Data.Master;
using HotelPms.DataAccessGrpc.Client;
using HotelPms.Share.Util;
using Microsoft.VisualBasic;
using MudBlazor;
using System.Collections.Concurrent;
using System.Data;
using System.Text;
using System.Threading.Channels;
using static MudBlazor.CategoryTypes;
using static System.Net.Mime.MediaTypeNames;
 
namespace HotelPms.Client.Blazor.Models
{
    /// <summary>
    /// 客室状況を持つデータ
    /// </summary>
    public class RoomViewData
    {
        /// <summary>
        /// 現在選択されているTabのインデックス
        /// </summary>
        public int ActiveTabIndex { get; set; } = 0;
 
        /// <summary>
        /// 全部行数
        /// </summary>
        public int RowCount { get; set; } = 0;
 
        /// <summary>
        /// 全部列数
        /// </summary>
        public int ColCount { get; set; } = 0;
 
        /// <summary>
        /// 部屋タブ一覧
        /// </summary>
        public List<RoomViewTab> Tabs { get; set; } = new List<RoomViewTab>();
 
        /// <summary>
        /// 選択されているタブのレイアウトデータ
        /// 行⇒列
        /// </summary>
        public List<List<RoomViewLayout>> Data { get; set; } = new List<List<RoomViewLayout>>();
 
        /// <summary>
        /// 現在のセルレイアウト
        /// </summary>
        public List<RoomCell> Cells { get; set; } = new List<RoomCell>();
 
        /// <summary>
        /// Tab毎のレイアウトを持つ
        /// M_RoomCellを編集されたら、SignalRより受信し、更新される
        /// </summary>
        public ConcurrentDictionary<int, List<RoomCell>> CellsBuffer = new ConcurrentDictionary<int, List<RoomCell>>();
 
        /// <summary>
        /// 部屋ID, 部屋属性データ
        /// </summary>
        public Dictionary<int, RoomViewAtt> RoomData = new Dictionary<int, RoomViewAtt>();
 
        /// <summary>
        /// 部屋ID, [SortKey, 利用データ]
        /// </summary>
        public Dictionary<int, SortedDictionary<string, RoomViewUse>> UseData = new Dictionary<int, SortedDictionary<string, RoomViewUse>>();
 
        /// <summary>
        /// メニュー
        /// </summary>
        public RoomViewMenu Menu = new RoomViewMenu();
 
        /// <summary>
        /// 現在の利用日
        /// </summary>
        public DateTime UseDate { get; set; } = DateTime.Today;
 
        public RoomViewData()
        {
        }
 
        /// <summary>
        /// 表示Tabのデータクリア
        /// </summary>
        private void Clear()
        {
            Data.Clear();
            RoomData.Clear();
            UseData.Clear();
            RowCount = 0;
            ColCount = 0;
        }
 
        /// <summary>
        /// 客室状況画面初期化
        /// </summary>
        /// <returns></returns>
        public async Task Init()
        {
            using RoomViewLayoutAccess access = new RoomViewLayoutAccess(EnvironmentSetting.GrpcChannel);
            using DataSet ds = await access.GetRoomViewData($"NULL,0,1");
 
            //データを取得してから、クリア:データを取得時、画面再表示されないように
            Clear();
 
            //レイアウトデータ
            SetLayoutData(ds.Tables[0]);
 
            //部屋状態・属性
            SetRoomData(ds.Tables[1]);
 
            //部屋の利用データ
            SetUseData(ds.Tables[2]);
 
            //レイアウト
            SetRoomCell(ds.Tables[3]);
 
            //ホテル日
            UseDate = (DateTime)ds.Tables[4].Rows[0][0];
 
            //Tab一覧
            SetTabs(ds.Tables[5]);
        }
 
        /// <summary>
        /// 表示用データ
        /// </summary>
        /// <param name="channel"></param>
        /// <returns></returns>
        public async Task GetData(DateTime useDate, bool tabChanged)
        {
            Clear();
            int tabID = Tabs[ActiveTabIndex].ID;
            using RoomViewLayoutAccess access = new RoomViewLayoutAccess(EnvironmentSetting.GrpcChannel);
            using DataSet ds = await access.GetRoomViewData($"{CConvert.ToDateString(useDate)},{tabID},{(tabChanged ? 2 : 0)}");
 
            //レイアウトデータ
            SetLayoutData(ds.Tables[0]);
 
            //部屋状態・属性
            SetRoomData(ds.Tables[1]);
 
            //部屋の利用データ
            SetUseData(ds.Tables[2]);
 
            //レイアウト
            if (tabChanged) { SetRoomCell(ds.Tables[3]); }
        }
 
        /// <summary>
        /// セルのレイアウト情報取得
        /// </summary>
        /// <param name="table"></param>
        private void SetRoomCell(DataTable table)
        {
            List<RoomCell> list;    
            if (CellsBuffer.TryGetValue(ActiveTabIndex, out list)) 
            {
                Cells = list;
                return; 
            }
 
            list = new List<RoomCell>();
            foreach (DataRow row in table.Rows)
            {
                RoomCell item = new RoomCell();
                item.ConvertDataRow(row);
                list.Add(item);
            }
            CellsBuffer[ActiveTabIndex] = list;
            Cells = list;
        }
 
        /// <summary>
        /// Tabの情報
        /// </summary>
        /// <param name="table"></param>
        private void SetTabs(DataTable table)
        {
            Tabs.Clear();
            foreach (DataRow row in table.Rows)
            {
                RoomViewTab item = new RoomViewTab();
                item.ConvertDataRow(row);
                Tabs.Add(item);
            }
        }
 
        /// <summary>
        /// レイアウトデータ
        /// </summary>
        /// <param name="table"></param>
        private void SetLayoutData(DataTable table)
        {
            List<RoomViewLayout> rowData = new List<RoomViewLayout>();
            foreach (DataRow row in table.Rows)
            {
                RoomViewLayout item = new RoomViewLayout();
                item.Read(row);
 
                if (item.Row > RowCount) { RowCount = item.Row; }
                if (item.Col > ColCount) { ColCount = item.Col; }
                if (item.Col == 1)
                {
                    //改行
                    rowData = new List<RoomViewLayout>();
                    Data.Add(rowData);
                }
 
                //行毎の各列
                rowData.Add(item);
            }
        }
 
        /// <summary>
        /// 部屋状態・属性
        /// </summary>
        /// <param name="table"></param>
        private void SetRoomData(DataTable table)
        {
            foreach (DataRow row in table.Rows)
            {
                RoomViewAtt room = new RoomViewAtt();
                room.Read(row);
                RoomData.Add(room.RoomID, room);
            }
        }
 
        /// <summary>
        /// 部屋の利用データ
        /// </summary>
        /// <param name="table"></param>
        private void SetUseData(DataTable table)
        {
            foreach (DataRow row in table.Rows)
            {
                RoomViewUse use = new RoomViewUse();
                use.Read(row);
 
                SortedDictionary<string, RoomViewUse> dict;
                if (!UseData.TryGetValue(use.RoomID, out dict))
                {
                    dict = new SortedDictionary<string, RoomViewUse>();
                    UseData.Add(use.RoomID, dict);
                }
 
                dict.Add(use.SortKey, use);
            }
        }
 
        /// <summary>
        /// セルのアイテム毎の表示文言
        /// </summary>
        /// <param name="roomCell"></param>
        /// <param name="roomID"></param>
        /// <returns></returns>
        public string GetText(Data.Master.RoomCell roomCell, int roomID)
        {
            try
            {
                if (roomCell.ID == 0) { return roomCell.Content; }
                else if (roomCell.ID == 1) { return roomID.ToString(); }
                else if (roomCell.ID == 9) { return RoomData.ContainsKey(roomID) ? RoomData[roomID].RoomName : string.Empty; }
                else
                {
                    return UseData.ContainsKey(roomID) ? UseData[roomID].FirstOrDefault().Value.UseData[$"F{roomCell.ID}"] : string.Empty;
                }
            }
            catch
            {
                return $"error:{roomCell.ID}";
            }
        }
 
        /// <summary>
        /// セル色
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public string GetCellColor(Data.Master.RoomViewLayout item)
        {
            int roomID = item.RoomID;   
            StringBuilder text = new StringBuilder();
            //優先順位:部屋状態>利用状態>固定色
            string backColor = item.BackColor, foreColor = item.ForeColor;
            if (roomID > 0)
            {
                int maidType = RoomData.ContainsKey(roomID) ? RoomData[roomID].MaidType : 0;
                if (maidType > 0)
                {
                    foreColor = RoomData[roomID].ForeColor;
                    backColor = RoomData[roomID].BackColor;
                }
                else if (UseData.ContainsKey(roomID))
                {
                    var use = UseData[roomID].FirstOrDefault().Value;
                    foreColor = use.ForeColor;
                    backColor = use.BackColor;
                }
            }
            text.Append($"color:{CConvert.ToHtmlColor(foreColor)};");
            text.Append($"background:{CConvert.ToHtmlColor(backColor)};");
            return text.ToString();
        }
 
        /// <summary>
        /// セルのアイテム毎のスタイル
        /// </summary>
        /// <param name="roomCell"></param>
        /// <returns></returns>
        public string GetRoomCellStyle(Data.Master.RoomCell roomCell)
        {
            StringBuilder text = new StringBuilder();
            text.Append("position: absolute;");
            text.Append($"left: {roomCell.Left}px;");
            text.Append($"top: {roomCell.Top}px;");
            text.Append($"width:{roomCell.Width}px;");
            text.Append($"height:{roomCell.Heigh}px;");
            text.Append($"font-family:{roomCell.FontName};");
            text.Append($"font-size:{roomCell.FontSize}pt;");
            if (roomCell.FontItalic) { text.Append("font-style:italic;"); }
            if (roomCell.FontBold) { text.Append("font-weight:bold;"); }
            string backColor = roomCell.BackColor, foreColor = roomCell.ForeColor;
            text.Append($"color:{CConvert.ToHtmlColor(foreColor)};");
            if (!CConvert.IsTransparent(backColor)) { text.Append($"background:{CConvert.ToHtmlColor(backColor)};"); }
 
            if(roomCell.FontUnderline)
            {
                text.Append("text-decoration: underline;");
                text.Append("text-underline-offset: 0.2em;");
            }
 
            return text.ToString();
        }
 
        /// <summary>
        /// セルの文字寄せ
        /// </summary>
        /// <param name="roomCell"></param>
        /// <returns></returns>
        public Align ToTextAlignCSS(Data.Master.RoomCell roomCell)
        {
            //TopLeft = 1,
            //TopCenter = 2,
            //TopRight = 4,
            //MiddleLeft = 16,
            //MiddleCenter = 32,
            //MiddleRight = 64,
            //BottomLeft = 256,
            //BottomCenter = 512,
            //BottomRight = 1024,
 
            if (roomCell.TextAlign == 1 || roomCell.TextAlign == 16 || roomCell.TextAlign == 256)
            {
                return Align.Left;
            }
            else if (roomCell.TextAlign == 4 || roomCell.TextAlign == 64 || roomCell.TextAlign == 1024)
            {
                return Align.Right;
            }
            else
            {
                return Align.Center;
            }
        }
    }
}