ホテル管理システム
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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
using customTypes;
using HotelPms.Client.Blazor.Models;
using HotelPms.Client.Blazor.Pages.UseDetail;
using HotelPms.Client.Blazor.Shared;
using HotelPms.Client.Blazor.Util;
using HotelPms.Data.Common;
using HotelPms.Data.UseInfo;
using HotelPms.DataAccessGrpc.Client;
using HotelPms.Share.IO;
using HotelPms.Share.Util;
using Microsoft.JSInterop;
using System.ComponentModel;
using System.Text;
using System.Text.Json;
using static HotelPms.Client.Blazor.Util.SystemEnum;
 
namespace HotelPms.Client.Blazor.ViewModel;
 
/// <summary>
/// 利用情報詳細入力画面用
/// </summary>
public class UseInput : ValidModelEx
{
    public enum GroupKey : int
    {
        [Description("予約情報")]
        Resv = 0,
        [Description("個人情報")]
        Person,
        [Description("会社情報")]
        Company,
        [Description("その他")]
        Other,
        [Description("予約追加情報")]
        ResvAdd,
        [Description("個人追加情報")]
        PersonAdd,
        [Description("会社追加情報")]
        CompanyAdd,
        [Description("顧客追加情報")]
        CustomerAdd,
    }
 
    /// <summary>
    /// 利用情報
    /// </summary>
    public Data.UseInfo.Use Use { get; set; }
 
    /// <summary>
    /// 現在選択されている利用明細
    /// </summary>
    public Data.UseInfo.UseDetail UseDetail { get; set; }
 
    /// <summary>
    /// 現在の伝票表示区分
    /// </summary>
    public ESaleDispType SaleDispType { get; set; } = ESaleDispType.Normal;
 
    /// <summary>
    /// 現在選択されている利用日
    /// yyyy/MM/dd
    /// </summary>
    public string UseDate { get; set; } = string.Empty;
 
    /// <summary>
    /// 現在選択されている利用日の泊数
    /// </summary>
    public int CurrentStay { get; set; } = 1;
 
    /// <summary>
    /// 部屋タイプ情報入力
    /// </summary>
    public IEnumerable<RoomTypeInputRow> RoomTypeList { get; set; } = new List<RoomTypeInputRow>();
 
    private UseRoomRow m_SelUseRoomRow = null;
 
    /// <summary>
    /// 選択されている利用部屋
    /// </summary>
    public UseRoomRow SelUseRoomRow
    {
        get { return m_SelUseRoomRow; }
        set
        {
            m_SelUseRoomRow = value;
            EnvironmentSetting.Debug($"Change:{m_SelUseRoomRow.RoomID}");
        }
    }
 
    /// <summary>
    /// 利用部屋一覧
    /// </summary>
    public IEnumerable<UseRoomRow> UseRoomList { get; set; } = new List<UseRoomRow>();
 
    /// <summary>
    /// 伝票一覧
    /// </summary>
    public IEnumerable<SaleInputRow> SaleList { get; set; } = new List<SaleInputRow>();
 
    /// <summary>
    /// 入金一覧
    /// </summary>
    public IEnumerable<string> PayList { get; set; } = new List<string>();
 
    /// <summary>
    /// グループ毎返す
    /// </summary>
    /// <param name="key"></param>
    /// <returns></returns>
    public List<ValidField> GetGroup(GroupKey key)
    {
        List<ValidField> list = new List<ValidField>();
        if (key == GroupKey.Resv) { for (int i = 0; i <= 11; i++) { list.Add(Fields[i]); } }
        else if (key == GroupKey.Person) { for (int i = 12; i <= 19; i++) { list.Add(Fields[i]); } }
        else if (key == GroupKey.Company) { for (int i = 20; i <= 25; i++) { list.Add(Fields[i]); } }
        else if (key == GroupKey.Other) { for (int i = 26; i <= 32; i++) { list.Add(Fields[i]); } }
        return list;
    }
 
    /// <summary>
    /// 初期化
    /// </summary>
    public UseInput(IJSRuntime js) : base(js)
    {
        // 0 ~ 10
        Add(new ValidField() { Name = "ResvNo", Caption = "予約番号", MaxLenth = 50, WidthUnit = 12 });
        Add(new ValidField() { Name = "ResvType", Caption = "予約区分", Required = true, MaxLenth = 2, InputChar = EInputChar.Num, DispNameEnabled = true, ShowStyle = EShowStyle.ShowList, DispWidthUnit = 6 });
        Add(new ValidField() { Name = "GroupType", Caption = "団体区分", Required = true, MaxLenth = 2, InputChar = EInputChar.Num, ShowStyle = EShowStyle.ShowList, DispNameEnabled = true, DispWidthUnit = 6 });
        Add(new ValidField() { Name = "RoomID", Caption = "部屋No", MaxLenth = 7, InputChar = EInputChar.Num, WidthUnit = 5 });
        Add(new ValidField() { Name = "SalesLoginID", Caption = "営業", MaxLenth = 7, InputChar = EInputChar.Num, ShowStyle = EShowStyle.ShowList, WidthUnit = 7, DispNameEnabled = true, DispWidthUnit = 8 });
        Add(new ValidField() { Name = "CinDate", Caption = "チェックイン日", MaxLenth = 10, InputChar = EInputChar.Num | EInputChar.Slash, InputStyle = EInputStyle.Date });
        Add(new ValidField() { Name = "CinTime", Caption = "到着時間", MaxLenth = 5, InputChar = EInputChar.Num | EInputChar.Colon, InputStyle = EInputStyle.Time });
        Add(new ValidField() { Name = "Stay", Caption = "泊数", MaxLenth = 3, InputChar = EInputChar.Num, WidthUnit = 6, NewLine = true });
        Add(new ValidField() { Name = "CoutDate", Caption = "チェックアウト日", MaxLenth = 10, InputChar = EInputChar.Num | EInputChar.Slash, InputStyle = EInputStyle.Date });
        Add(new ValidField() { Name = "CoutTime", Caption = "出発時間", MaxLenth = 5, InputChar = EInputChar.Num | EInputChar.Colon, InputStyle = EInputStyle.Time });
        Add(new ValidField() { Name = "GroupName", Caption = "団体名称", MaxLenth = 50 });
        Add(new ValidField() { Name = "GroupKana", Caption = "団体カナ", MaxLenth = 50 });
 
        // 11 ~ 18
        Add(new ValidField() { Name = "MemberNo", Caption = "会員番号", MaxLenth = 50, WidthUnit = 12 });
        Add(new ValidField() { Name = "Tel", Caption = "電話番号", MaxLenth = 50, InputChar = EInputChar.Num | EInputChar.Subtract, WidthUnit = 8 });
        Add(new ValidField() { Name = "TelKind", Caption = "区分", Required = true, MaxLenth = 50, ShowStyle = EShowStyle.ShowList, ReadOnly = true, WidthUnit = 4 });
        Add(new ValidField() { Name = "Name", Required = true, Caption = "氏名", MaxLenth = 50, WidthUnit = 12 });
        Add(new ValidField() { Name = "Kana", Required = true, Caption = "カナ", MaxLenth = 50, WidthUnit = 12 });
        Add(new ValidField() { Name = "ResvName", Caption = "予約者名", MaxLenth = 50, WidthUnit = 12 });
        Add(new ValidField() { Name = "ResvKana", Caption = "カナ", MaxLenth = 50, WidthUnit = 12 });
        Add(new ValidField() { Name = "ResvTel", Caption = "電話番号", InputChar = EInputChar.Num | EInputChar.Subtract, MaxLenth = 50, WidthUnit = 12 });
 
        // 19 ~ 24
        Add(new ValidField() { Name = "CorpID", Caption = "法人顧客", MaxLenth = 7, InputChar = EInputChar.Num, ShowStyle = EShowStyle.ShowList, WidthUnit = 12 });
        Add(new ValidField() { Name = "CorpName", Caption = "会社名", MaxLenth = 50, WidthUnit = 12 });
        Add(new ValidField() { Name = "CorpKana", Caption = "カナ", MaxLenth = 50, WidthUnit = 12 });
        Add(new ValidField() { Name = "CorpTel", Caption = "会社電話", MaxLenth = 50, WidthUnit = 12 });
        Add(new ValidField() { Name = "CorpFax", Caption = "会社FAX", MaxLenth = 50, WidthUnit = 12 });
        Add(new ValidField() { Name = "ReceiptName", Caption = "宛名", MaxLenth = 50, InputChar = EInputChar.None, WidthUnit = 12 });
 
        // 25 ~ 31
        Add(new ValidField() { Name = "AreaID", Caption = "地域", MaxLenth = 7, InputChar = EInputChar.Num, ShowStyle = EShowStyle.ShowList, DispWidthUnit = 8, DispNameEnabled = true, WidthUnit = 12 });
        Add(new ValidField() { Name = "CharacterType", Caption = "人物フラグ", MaxLenth = 7, InputChar = EInputChar.Num, ShowStyle = EShowStyle.ShowList, DispWidthUnit = 8, DispNameEnabled = true, WidthUnit = 12 });
        Add(new ValidField() { Name = "CustomerRig", Caption = "顧客登録", MaxLenth = 1, InputChar = EInputChar.Num, ShowStyle = EShowStyle.ShowList, DispWidthUnit = 8, DispNameEnabled = true, WidthUnit = 12 });
        Add(new ValidField() { Name = "AgentID", Caption = "エージェント", MaxLenth = 7, InputChar = EInputChar.Num, ShowStyle = EShowStyle.ShowList, DispWidthUnit = 8, DispNameEnabled = true, WidthUnit = 12 });
        Add(new ValidField() { Name = "AgentBranchID", Caption = "支店", MaxLenth = 7, InputChar = EInputChar.Num, ShowStyle = EShowStyle.ShowList, DispWidthUnit = 8, DispNameEnabled = true, WidthUnit = 12 });
        Add(new ValidField() { Name = "PlanID", Caption = "プラン", MaxLenth = 7, InputChar = EInputChar.Num, ShowStyle = EShowStyle.ShowList, DispWidthUnit = 8, DispNameEnabled = true, WidthUnit = 12 });
        Add(new ValidField() { Name = "RoomAssign", Caption = "部屋指定", MaxLenth = 1, InputChar = EInputChar.Num, ShowStyle = EShowStyle.ShowList, DispWidthUnit = 8, DispNameEnabled = true, WidthUnit = 12 });
 
        // 予約追加情報(自由集計)
 
        // 個人追加情報
        Add(new ValidField() { Name = "ZipCode", Caption = "郵便番号", MaxLenth = 50, InputChar = EInputChar.None });
        Add(new ValidField() { Name = "Prefecture", Caption = "都道府県", MaxLenth = 20, InputChar = EInputChar.None });
        Add(new ValidField() { Name = "Address2", Caption = "市区町村", MaxLenth = 50, InputChar = EInputChar.None });
        Add(new ValidField() { Name = "Address3", Caption = "町域", MaxLenth = 50, InputChar = EInputChar.None });
        Add(new ValidField() { Name = "Address4", Caption = "番地", MaxLenth = 100, InputChar = EInputChar.None });
        Add(new ValidField() { Name = "Mail", Caption = "メール", MaxLenth = 100, InputChar = EInputChar.None });
        Add(new ValidField() { Name = "PassportNo", Caption = "パスポート", MaxLenth = 50, InputChar = EInputChar.None });
        Add(new ValidField() { Name = "Sex", Caption = "性別", MaxLenth = 2, InputChar = EInputChar.Num });
        Add(new ValidField() { Name = "BirthDay", Caption = "誕生日", MaxLenth = 10, InputChar = EInputChar.Num | EInputChar.Slash, InputStyle = EInputStyle.Date });
        Add(new ValidField() { Name = "Anniversary", Caption = "記念日", MaxLenth = 10, InputChar = EInputChar.Num | EInputChar.Slash, InputStyle = EInputStyle.Date });
 
        // 会社追加情報
        //Add(new ValidField() { Name = "ResvTel", Caption = "所属", MaxLenth = 50 });
        //Add(new ValidField() { Name = "ResvTel", Caption = "役職", MaxLenth = 50 });
        Add(new ValidField() { Name = "CorpZipCode", Caption = "法人郵便番号", MaxLenth = 50, InputChar = EInputChar.None });
        Add(new ValidField() { Name = "CorpPrefecture", Caption = "都道府県", MaxLenth = 20, InputChar = EInputChar.None });
        Add(new ValidField() { Name = "CorpAddress2", Caption = "市区町村", MaxLenth = 50, InputChar = EInputChar.None });
        Add(new ValidField() { Name = "CorpAddress3", Caption = "町域", MaxLenth = 50, InputChar = EInputChar.None });
        Add(new ValidField() { Name = "CorpAddress4", Caption = "番地", MaxLenth = 100, InputChar = EInputChar.None });
        Add(new ValidField() { Name = "CorpMemo", Caption = "法人備考", MaxLenth = 500, InputChar = EInputChar.None });
 
        // 顧客追加情報 (顧客自由集計 GroupID使用)
 
 
        //追加電話番号はGridリストへ
 
        // 複数想定(リスト)
        Add(new ValidField() { Name = "Memo", Caption = "メモ", MaxLenth = 1000 });
        Add(new ValidField() { Name = "Remark", Caption = "備考", MaxLenth = 1000 });
    }
 
    /// <summary>
    /// 画面初期化
    /// </summary>
    public void InitGrid()
    {
        InitRoomTypeInput();
    }
 
    public async void InitRoomTypeInput()
    {
        List<RoomTypeInputRow> list = RoomTypeList as List<RoomTypeInputRow>;
        List<UseRoomRow> roomList = UseRoomList as  List<UseRoomRow>;
        
        SortedDictionary<int, RoomTypeInputRow> typeDt = new SortedDictionary<int, RoomTypeInputRow>();  //まとめる
        //UseRoomより取得する
        List<Data.UseInfo.UseRoom> useRoomList = Use.GetUseRoomList(UseDate);
        foreach (var item in useRoomList)
        {
            RoomTypeInputRow row;
            if (!typeDt.TryGetValue(item.RoomTypeID, out row))
            {
                row = new();
                row.SetCellText((int)RoomTypeInputRow.ColType.ID, item.RoomTypeID.ToString());
                row.SetCellText((int)RoomTypeInputRow.ColType.Name, await MasterCore.GetRoomTypeName(item.RoomTypeID));
                row.SetCellText((int)RoomTypeInputRow.ColType.Count, "0");
                typeDt.Add(item.RoomTypeID, row);
            }
            row.SetCellText((int)RoomTypeInputRow.ColType.Count, CConvert.ToString(CConvert.ToInt(row.GetCellText((int)RoomTypeInputRow.ColType.Count)) + 1));
            row.DataList.Add(item);
 
            //部屋一覧
            UseRoomRow roomRow = new UseRoomRow
            {
                RoomID = item.RoomID.ToString(),
                Name = item.UseAlloList.Count == 0 ? string.Empty : item.UseAlloList[0].Person?.Name,
                Representative = true,
                UseStatus = (item.Parent as Data.UseInfo.UseDetail).UseStatus.ToString(),
            };
            roomRow.UseRoom = item;
            roomList.Add(roomRow);
        }
 
        //常に空行追加
        list.Add(new());
 
        //部屋一覧初期選択データ
        if (roomList.Count > 0) 
        {
            if (roomList.Count > 1)
            {
                UseRoomRow roomRow = new UseRoomRow
                {
                    RoomID = "",
                    Name = "(一括)",
                    Representative = false,
                    UseStatus = "",
                };
                roomRow.UseRoom = roomList[0].UseRoom;
                roomList.Insert(0, roomRow);
            }
 
            SelUseRoomRow = roomList[0]; 
        }
    }
 
    /// <summary>
    /// 入力項目→Data
    /// </summary>
    /// <param name="field"></param>
    public void SetDataField(ValidField field)
    {
        #region 利用情報
 
        if (field.Name == "ResvType")
        {
            Use.ResvType = CConvert.ToInt(field.Text);
        }
        else if (field.Name == "GroupType")
        {
            Use.GroupType = CConvert.ToInt(field.Text);
        }
        else if (field.Name == "GroupName")
        {
            Use.GroupName = field.Text;
        }
        else if (field.Name == "GroupKana")
        {
            Use.GroupKana = field.Text;
        }
 
        #endregion
 
        #region 利用明細情報
 
        if (UseDetail != null)
        {
            if (field.Name == "ResvNo")
            {
                UseDetail.ResvNo = field.Text;
            }
            else if (field.Name == "SalesLoginID")
            {
                UseDetail.SalesLoginID = CConvert.ToInt(field.Text);
            }
            else if (field.Name == "CinDate")
            {
                UseDetail.CinDate = new customTypes.Date(field.Text);
            }
            else if (field.Name == "CinTime")
            {
                UseDetail.CinTime = CConvert.ToInt(field.Text.Replace(":", string.Empty));
            }
            else if (field.Name == "Stay")
            {
                UseDetail.Stay = CConvert.ToInt(field.Text);
            }
            else if (field.Name == "CoutDate")
            {
                UseDetail.CoutDate = new customTypes.Date(field.Text);
            }
            else if (field.Name == "CoutTime")
            {
                UseDetail.CoutTime = CConvert.ToInt(field.Text.Replace(":", string.Empty));
            }
        }
 
        #endregion
 
        if (field.Name == "MemberNo")
        {
            //Use.MemberNo = field.Text;
        }
        else if (field.Name == "Tel")
        {
            //Use.Tel = field.Text;
        }
        else if (field.Name == "TelKind")
        {
            //Use.TelKind = field.Text;
        }
        else if (field.Name == "Name")
        {
            //Use.Name = field.Text;
        }
        else if (field.Name == "Kana")
        {
            //Use.Kana = field.Text;
        }
        else if (field.Name == "ResvName")
        {
            //Use.ResvName = field.Text;
        }
        else if (field.Name == "ResvKana")
        {
            //Use.ResvKana = field.Text;
        }
        else if (field.Name == "ResvTel")
        {
            //Use.ResvTel = field.Text;
        }
        else if (field.Name == "CorpID")
        {
            //Use.CorpID = CConvert.ToInt(field.Text);
        }
        else if (field.Name == "CorpName")
        {
            //Use.CorpName = field.Text;
        }
        else if (field.Name == "CorpKana")
        {
            //Use.CorpKana = field.Text;
        }
        else if (field.Name == "CorpTel")
        {
            //Use.CorpTel = field.Text;
        }
        else if (field.Name == "CorpFax")
        {
            //Use.CorpFax = field.Text;
        }
        else if (field.Name == "ReceiptName")
        {
            //Use.ReceiptName = field.Text;
        }
        else if (field.Name == "AreaID")
        {
            //Use.AreaID = CConvert.ToInt(field.Text);
        }
        else if (field.Name == "CharacterType")
        {
            //Use.CharacterType = CConvert.ToInt(field.Text);
        }
        else if (field.Name == "CustomerRig")
        {
            //Use.CustomerRig = CConvert.ToInt(field.Text);
        }
        else if (field.Name == "AgentID")
        {
            //Use.AgentID = CConvert.ToInt(field.Text);
        }
        else if (field.Name == "AgentBranchID")
        {
            //Use.AgentBranchID = CConvert.ToInt(field.Text);
        }
        else if (field.Name == "PlanID")
        {
            //Use.PlanID = CConvert.ToInt(field.Text);
        }
        else if (field.Name == "RoomAssign")
        {
            //Use.RoomAssign = CConvert.ToInt(field.Text);
        }
        else if (field.Name == "ZipCode")
        {
            //Use.ZipCode = field.Text;
        }
        else if (field.Name == "Prefecture")
        {
            //Use.Prefecture = field.Text;
        }
        else if (field.Name == "Address2")
        {
            //Use.Address2 = field.Text;
        }
        else if (field.Name == "Address3")
        {
            //Use.Address3 = field.Text;
        }
        else if (field.Name == "Address4")
        {
            //Use.Address4 = field.Text;
        }
        else if (field.Name == "Mail")
        {
            //Use.Mail = field.Text;
        }
        else if (field.Name == "PassportNo")
        {
            //Use.PassportNo = field.Text;
        }
        else if (field.Name == "Sex")
        {
            //Use.Sex = CConvert.ToInt(field.Text);
        }
        else if (field.Name == "BirthDay")
        {
            //Use.BirthDay = field.Text;
        }
        else if (field.Name == "Anniversary")
        {
            //Use.Anniversary = field.Text;
        }
        else if (field.Name == "CorpZipCode")
        {
            //Use.CorpZipCode = field.Text;
        }
        else if (field.Name == "CorpPrefecture")
        {
            //Use.CorpPrefecture = field.Text;
        }
        else if (field.Name == "CorpAddress2")
        {
            //Use.CorpAddress2 = field.Text;
        }
        else if (field.Name == "CorpAddress3")
        {
            //Use.CorpAddress3 = field.Text;
        }
        else if (field.Name == "CorpAddress4")
        {
            //Use.CorpAddress4 = field.Text;
        }
        else if (field.Name == "CorpMemo")
        {
            //Use.CorpMemo = field.Text;
        }
        else if (field.Name == "Memo")
        {
            //Use.Memo = field.Text;
        }
        else if (field.Name == "Remark")
        {
            //Use.Remark = field.Text;
        }
    }
 
    /// <summary>
    /// 現在表示されている利用明細を画面へ表示する
    /// </summary>
    public void SetUseDetailToForm()
    {
        //利用情報
        SetField("ResvType", Use.ResvType.ToString(), CConvert.GetEnumDescription<EResvType>(Use.ResvType));
        SetField("GroupType", Use.GroupType.ToString(), CConvert.GetEnumDescription<EGroupType>(Use.GroupType));
        SetField("GroupName", Use.GroupName);
        SetField("GroupKana", Use.GroupKana);
 
        //利用明細
        SetField("ResvNo", UseDetail.ResvNo.ToString());        
        SetField("SalesLoginID", UseDetail.SalesLoginID.ToString(), string.Empty);
        SetField("CinDate", UseDetail.CinDate.ToText());
        SetField("CinTime", CConvert.ToTime(UseDetail.CinTime));
        SetField("Stay", UseDetail.Stay.ToString());
        SetField("CoutDate", UseDetail.CoutDate.ToText());
        SetField("CoutTime", CConvert.ToTime(UseDetail.CoutTime));
 
        if (UseDetail.UseRoomList.Count > 0) 
        {
            HotelPms.Data.UseInfo.UseRoom useRoom = UseDetail.UseRoomList[0];
            SetField("RoomID", useRoom.RoomID.ToString());
 
            //利用者特定
            if (useRoom.UseAlloList.Count > 0 && useRoom.UseAlloList[0].Person != null)
            {
                HotelPms.Data.UseInfo.UsePerson usePerson = useRoom.UseAlloList[0].Person;
                SetField("MemberNo", usePerson.MemberNo);
                SetField("Name", usePerson.Name);
                SetField("Kana", usePerson.Kana);
                SetField("ReceiptName", usePerson.ReceiptName);
                SetField("CorpID", usePerson.CorpID.ToString());
                SetField("CorpName", usePerson.CorpName);
                SetField("CorpKana", usePerson.CorpKana);
 
                string tel = string.Empty;
                int telKind = 0;                
                string corpTel = string.Empty;
                string corpFax = string.Empty;
                if (usePerson.TelList.Count > 0)
                {
                    foreach (HotelPms.Data.UseInfo.UsePersonTel personTel in usePerson.TelList)
                    {
                        if ((personTel.Kind == (int)ETelKind.Tel || personTel.Kind == (int)ETelKind.Mobile) && tel.Length == 0)
                        {
                            tel = personTel.Tel;
                            telKind = personTel.Kind;   
                        }
                        else if (personTel.Kind == (int)ETelKind.CorpTel && corpTel.Length == 0)
                        {
                            corpTel = personTel.Tel;
                        }
                        else if (personTel.Kind == (int)ETelKind.CorpFax && corpFax.Length == 0)
                        {
                            corpFax = personTel.Tel;
                        }
                    }
                }
 
                SetField("Tel", tel);
                if (tel.Length == 0)
                {
                    SetField("TelKind", string.Empty, string.Empty);
                }
                else
                {
                    SetField("TelKind", telKind.ToString(), ((ETelKind)telKind).ToDescription());
                }
                SetField("CorpTel", corpTel);
                SetField("CorpFax", corpFax);
            }
        }
 
        //予約者情報
        if (UseDetail.ResvPerson != null)
        {
            SetField("ResvName", UseDetail.ResvPerson.Name.ToString());
            SetField("ResvKana", UseDetail.ResvPerson.Kana.ToString());
            if (UseDetail.ResvPerson.TelList.Count > 0)
            {
                SetField("ResvTel", UseDetail.ResvPerson.TelList[0].Tel.ToString());
            }
            else
            {
                SetField("ResvTel", string.Empty);
            }
        }
    }
 
    /// <summary>
    /// 自動ソースコード生成
    /// </summary>
    /// <returns></returns>
    public string GetAutoCode()
    {
        StringBuilder text = new StringBuilder();
        foreach (ViewModel.ValidField item in Fields)
        {
            if (item.Index > 0) { text.Append("else "); }
            text.AppendLine($"if (sender.Name == \"{item.Name}\")");
            text.AppendLine("{");
            if (item.InputChar == EInputChar.Num)
            {
                text.AppendLine($"   //Use.{item.Name} = CConvert.ToInt(sender.Text);");
            }
            else
            {
                text.AppendLine($"   //Use.{item.Name} = sender.Text;");
            }
            text.AppendLine("}");
        }
        return text.ToString();
    }
 
    /// <summary>
    /// 利用情報新規作成
    /// </summary>
    /// <returns></returns>
    public async Task<bool> CreateDefault(Date cinDate, int stay)
    {
        try
        {
            Use = new()
            {
                ID = await EnvironmentSetting.GetSeq(ESeqType.Use),
                ResvType = (int)EResvType.Reserve,
                GroupType = (int)EGroupType.Person,
                ReceiptPrtWay = 0,
                PayWay = 1,
                //CreateDate = CConvert.ToTimestamp(DateTime.Now.Date),
                //CreateLoginID = 1,
                //CreatePcName = Environment.MachineName,
                //CreateClass = 1,
                //UpdateDate = CConvert.ToTimestamp(DateTime.Now),
                //UpdateLoginID = 789,
                //UpdatePcName = Environment.MachineName,
                //UpdateClass = 2
            };
 
            #region 代表利用明細
 
            Data.UseInfo.UseDetail useDetail = new()
            {
                ID = Use.ID,
                DetailID = await EnvironmentSetting.GetSeq(ESeqType.UseDetail),
                UseStatus = (int)EUseStatus.Resv,
                SubStatus = 0,
                ExtenStatus = 0,
                CinDate = cinDate,
                CinTime = 1500,
                Stay = stay,
                CoutDate = cinDate.Add(stay),
                CoutTime = 1000,
                ResvType = Use.ResvType,
                //CreateDate = Use.CreateDate,
                //CreateLoginID = Use.CreateLoginID,
                //CreatePcName = Use.CreatePcName,
                //CreateClass = Use.CreateClass,
                //UpdateDate = Use.UpdateDate,
                //UpdateLoginID = Use.UpdateLoginID,
                //UpdatePcName = Use.UpdatePcName,
                //UpdateClass = Use.UpdateClass
            };
            Use.DetailList.Add(useDetail);
            UseDetail = useDetail;   //現在選択されている利用明細
 
            #endregion
 
            return true;
        }
        catch (Exception ex)
        {
            OperationLog.Instance.WriteLog($"CreateDefault:{ex.Message}");
            return false;
        }
    }
 
    public void RemoveUseRoom(List<Data.UseInfo.UseRoom> list, int count)
    {
        try
        {
            //Parentが必要!!
            int i = 0;
            List<Data.UseInfo.UseRoom> delList = new List<Data.UseInfo.UseRoom>();
            foreach(var item in list)
            {                
                delList.Add(item);
                i++;
                if (i == count) { break; }
            }
 
            foreach(var item in delList) 
            {
                (item.Parent as Data.UseInfo.UseDetail).UseRoomList.Remove(item);
                list.Remove(item);
            }
        }
        catch (Exception ex)
        {
            OperationLog.Instance.WriteLog($"RemoveUseRoom:{ex.Message}");
        }
    }
 
    /// <summary>
    /// 部屋を作成する
    /// </summary>
    /// <param name="typeID"></param>
    /// <param name="kind"></param>
    /// <returns></returns>
    public async Task<Data.UseInfo.UseRoom> CreateUseRoom(int typeID, int kind)
    {
        try
        {
            Data.UseInfo.UseDetail detail = Use.GetDetailWithoutUseRoom(UseDate);
            if (detail == null) 
            {
                detail = new()
                {
                    ID = Use.ID,
                    DetailID = await EnvironmentSetting.GetSeq(ESeqType.UseDetail),
                    UseStatus = (int)EUseStatus.Resv,
                    SubStatus = 0,
                    ExtenStatus = 0,
                    CinDate = new(UseDate),
                    CinTime = 1500,
                    Stay = 1,
                    CoutDate = new customTypes.Date(UseDate).Add(1),
                    CoutTime = 1000,
                    ResvType = Use.ResvType,
                };
                Use.DetailList.Add(detail);
            }
            else
            {                
                detail.SetUseRange(UseDate);  // 利用期間以外だったら、伸びる
            }
 
            //UseRoom作成
            Data.UseInfo.UseRoom useRoom = new()
            {
                ID = Use.ID,
                DetailID = detail.DetailID,
                UseDate = new(UseDate),
                RoomTypeID = typeID,
                RoomKind = kind,
            };
            detail.UseRoomList.Add(useRoom);
            useRoom.Parent = detail;
 
            //基本伝票(部屋料金)作成
            HotelPms.Data.Master.Item item = await MasterCore.GetBaseItem(useRoom.RoomTypeID, 0, UseDate);
            int saleID = await EnvironmentSetting.GetSeq(ESeqType.Sale);
            int taxRate = await EnvironmentSetting.GetTaxRate(useRoom.UseDate.ToText(), item.TaxType);
            var saleItem = useRoom.AddSaleByItem(saleID, taxRate, item);
 
            //料金の画面表示
            SaleInputRow saleRow = new();
            await saleRow.Add(saleItem);
            (SaleList as List<SaleInputRow>).Add(saleRow);
            return useRoom;
        }
        catch (Exception ex)
        {
            OperationLog.Instance.WriteLog($"CreateUseRoom:{ex.Message}");
            return null;
        }
    }
}