ホテル管理システム
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
using HotelPms.Client.Blazor.Pages.UseDetail;
using HotelPms.Client.Blazor.Services;
using HotelPms.Client.Blazor.Util;
using HotelPms.Share.IO;
using HotelPms.Share.Util;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.JSInterop;
using System.Collections.Concurrent;
using System.Reflection.Metadata;
using System.Text;
 
namespace HotelPms.Client.Blazor.ViewModel
{
    /// <summary>
    /// ViewModelExとして使って、
    /// Windows Fromスタイルの入力チェック方式
    /// C# Call jsは遅いため、逆にjsよりCallBackと使用する
    /// ※@bind-value使わない
    /// </summary>
    public abstract class ValidModelEx : IDisposable
    {
        #region  ★★★★★ Declartions ★★★★★
 
        public delegate void ValidEventHandler(ValidField sender, ValidEventArgs e);
        public delegate Task<bool> ValidResultEventHandler(ValidField sender, ValidEventArgs e);
 
        public event ValidResultEventHandler BeforeAutoNextFocus;
        public event ValidEventHandler AfterAutoNextFocus;
        public event ValidEventHandler AfterEnter;
        public event ValidEventHandler AfterLeave;
        public event ValidResultEventHandler ValueChanged;
        public event ValidResultEventHandler ShowList;
        public event ValidResultEventHandler BusinessValid;
 
        public static string Chr_Num = "0123456789";
        public static string Chr_Alpha_S = "abcdefghijklmnopqrstuvwxyz ";
        public static string Chr_Alpha_C = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
        public static string Chr_Kana = "ヲァィゥェォャュョッーアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゙゚ ";
        public static string Chr_Alpha = Chr_Alpha_S + Chr_Alpha_C;
        public static string Chr_NumAlpha = Chr_Num + Chr_Alpha;
        public static string Chr_ANK = Chr_NumAlpha + Chr_Kana;
 
        #endregion
 
        #region  ★★★★★ Property ★★★★★
 
        /// <summary>
        /// ID毎のインスタンス格納
        /// </summary>
        public static ConcurrentDictionary<string, ValidModelEx> Storage { get; set; } = new ConcurrentDictionary<string, ValidModelEx>();
 
        public IJSRuntime JSRuntime { get; set; }
 
        public List<ValidField> Fields { get; set; } = new List<ValidField>();
        private Dictionary<string, ValidField> dict = new Dictionary<string, ValidField>();
 
        public Action ErrRefresh { get; set; }
 
        /// <summary>
        /// Enterキーを押したかどうか
        /// </summary>
        public bool EnterPush { get; set; }
 
        /// <summary>
        /// Upキー押したかどうか
        /// </summary>
        public bool ArrowUpPush { get; set; }
 
        /// <summary>
        /// 0.新規 1.編集 2.削除
        /// </summary>
        public int EditMode { get; set; }
 
        /// <summary>
        /// 全体のエラー
        /// </summary>
        public string ErrText { get; set; }
 
        /// <summary>
        /// 一覧表示の検索キー対象項目一覧
        /// </summary>
        public List<string> FilterFields { get; set; } = new List<string>();
 
        /// <summary>
        /// 一覧表示の順番対象項目一覧
        /// </summary>
        public SortedList<int, string> OrderFields { get; set; } = new SortedList<int, string>();
 
        /// <summary>
        /// Guid
        /// </summary>
        public string ID { get; set; } = string.Empty;
 
        public bool DisableKeyboard { get; set; } = false;
 
        #endregion
 
        #region  ★★★★★ Class Event ★★★★★
 
        public ValidModelEx(IJSRuntime js)
        {
            JSRuntime = js;
            ID = Guid.NewGuid().ToString();
            Storage[ID] = this;
        }
 
        public void Dispose()
        {
            Storage.TryRemove(ID, out ValidModelEx model);
        }
 
        #endregion
 
        #region  ★★★★★ Control Event ★★★★★
 
        /// <summary>
        /// ①フォーカス入る
        /// ※BlazorのBugでEnterのパラメータ変数できない
        /// </summary>
        /// <param name="index"></param>
        public void Enter(int index, JsInputCoreEventArgs e)
        {
            EnvironmentSetting.Debug($"Enter:{index}⇒OrgText={e.OrgText},Text={e.Text}");
 
            Fields[index].OrgText = e.OrgText;
            if ((Fields[index].ShowStyle & SystemEnum.EShowStyle.ThousandSeparator) == SystemEnum.EShowStyle.ThousandSeparator && Fields[index].Text.Length > 0)
            {
                Fields[index].Text = Fields[index].Text.Replace(",", string.Empty); //コントロールの値連動する                
            }
            e.ResultNo = 0;
 
            if (AfterEnter != null) { AfterEnter(Fields[index], new ValidEventArgs()); }
        }
 
        /// <summary>
        /// ※IMEでもここに通る
        /// 例:「おぎ」を打つ時、[O]⇒e.Key="Proess"、e.KeyCode="KeyO"、e.Type="KeyDown"
        /// ②Enter⇒KeyDown⇒KeyPress⇒Leave
        /// </summary>
        /// <param name="index"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public async Task KeyUp(int index, JsInputCoreEventArgs e)
        {
            if(DisableKeyboard) { return; }
 
            if (e.Key == "ArrowUp")
            {
                try
                {
                    EnvironmentSetting.Debug($"KeyUp⇒ArrowUp:{index}");
                    if (!await SetAutoNextFocus(index, false, e)) { return; }
                    e.ResultNo = 0;
                }
                catch { }
                finally
                {
                }
            }
            else if (e.Key == "End")
            {
                EnvironmentSetting.Debug($"KeyUp⇒End:{index}");
                if (ShowList != null) 
                {
                    DisableKeyboard = true;
                    ValidEventArgs eventArgs = new();
                    bool ret = await ShowList(Fields[index], eventArgs);
                    DisableKeyboard = false;
                    if (!eventArgs.Cancel) { await SetAutoNextFocus(index, true, e); }
                }
                e.Text = Fields[index].Text;
                e.ResultNo = 0;
            }
            else if (e.Key == "Enter")
            {
                await KeyEnter(index, e);
            }
        }
 
        /// <summary>
        /// ※注意:IMEモードではここに通らない
        /// e.Codeだと、二つEnterが違う
        /// ※※注意:ここで@bind-Valueを変更しても、直ぐにinputへ反映しない
        /// 必ずjs側で強制的にtextをセットする
        /// 整合性を保るため、@bind-Valueも同じでセットする
        /// </summary>
        /// <param name="index"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public async Task KeyEnter(int index, JsInputCoreEventArgs e)
        {
            try
            {
                FormatInput(index, e);
                string text = e.Text;
                EnvironmentSetting.Debug($"Return:{index}⇒{text}");
 
                //値変更したら、イベント発生
                if (await IsValueChanged(index, text, true, e))
                {
                    //通常チェックを行う
                    Fields[index].Error = false;
                    Fields[index].ErrorText = string.Empty;
                    if (!IsCorrectText(index, text, true)) { return; }
 
                    bool bvRet = true;
                    if (BusinessValid != null)
                    {
                        //業務チェックを行う
                        ValidEventArgs vea = new ValidEventArgs() { Text = text, EnterPush = true };
                        bvRet = await BusinessValid(Fields[index], vea);
                        EnvironmentSetting.Debug($"BusinessValid結果(Enter):{bvRet},Error:{Fields[index].Error},index={index}");
                    }
                    EnterPush = true;   //Enterを押した知らせ                     
                    if (bvRet) { SetOrgText(index, text); } else { return; } //BusinessValid結果:OK⇒OrgTextを反映する NG⇒前へ進まない 
                    Fields[index].Text = text;   //入力値確定
                    e.ResultNo = 0;
                }
                else
                {
                    //必須判断:初期表示時:OrgTextは空白のため、値変更しないまま
                    if (text.Trim().Length == 0 && Fields[index].Required)
                    {
                        Fields[index].Error = true;
                        Fields[index].ErrorText = "内容を入力してください。";
                        return;
                    }
                    e.ResultNo = 1;
                }
 
                if (!await SetAutoNextFocus(index, true, e)) { e.ResultNo = 9; return; }
            }
            catch { }
            finally
            {
                if (ErrRefresh != null && Fields[index].Error) 
                {
                    EnvironmentSetting.Debug($"Error:{Fields[index].Error},ErrorText={Fields[index].ErrorText}");
                    ErrRefresh(); 
                }   
            }
        }
 
        public void FormatInput(int index, JsInputCoreEventArgs e)
        { 
            try
            {
                if (Fields[index].InputStyle == SystemEnum.EInputStyle.Date)
                {
                    e.Text = CConvert.ParseDate(e.Text, Fields[index].OrgText);
                }
                else if (Fields[index].InputStyle == SystemEnum.EInputStyle.Time)
                {
                    e.Text = CConvert.ParseTime(e.Text, Fields[index].OrgText);
                }
            }
            catch { }
        }
 
        /// <summary>
        /// そのタイミングbind反映したはず
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        //private async Task LeaveMud(int index)
        public async Task Leave(int index, JsInputCoreEventArgs e)
        {
            string text = string.Empty;
            bool refresh = false;
            try
            {
                EnvironmentSetting.Debug($"Leave:{index}⇒OrgText={Fields[index].OrgText},Text={Fields[index].Text}");
                FormatInput(index, e);
                text = e.Text;
 
                if (EnterPush)
                {
                    //Enterキーを押した時にも既にチェック済
                    EnterPush = false;
                }
                else
                {
                    //値変更したら、イベント発生
                    if (!await IsValueChanged(index, text, false, e)) 
                    {
                        //必須判断:初期表示時:OrgTextは空白のため、値変更しないまま
                        Fields[index].Error = false;
                        Fields[index].ErrorText = string.Empty;
                        e.ResultNo = 1; 
                        return; 
                    }
 
                    //通常チェックを行う
                    Fields[index].Error = false;
                    Fields[index].ErrorText = string.Empty;
                    if (IsCorrectText(index, text, false))
                    {
                        if (BusinessValid != null)
                        {
                            //業務チェックを行う
                            ValidEventArgs vea = new ValidEventArgs() { Text = text };
                            bool bvRet = await BusinessValid(Fields[index], vea);
                            EnvironmentSetting.Debug($"BusinessValid結果:{bvRet},Error:{Fields[index].Error},index={index}");
                            if (!bvRet)
                            {
                                Fields[index].Error = true;
                            }
                        }
                    }
                }
 
                if (Fields[index].Error)
                {
                    EnvironmentSetting.Debug($"元値に復元する↓:Error={Fields[index].Error},index={index}");
                    //エラーの場合、元値に復元する
                    Fields[index].Text = Fields[index].OrgText;
                    e.Text = Fields[index].OrgText;
                    Fields[index].Error = false;
                    Fields[index].ErrorText = string.Empty;
                    EnvironmentSetting.Debug($"元値に復元する↑:Error={Fields[index].Error},ErrorText={Fields[index].ErrorText},Text={Fields[index].Text},index={index}");
                    refresh = true;
                    return;
                }
 
                Fields[index].Text = text;  //確定
                e.Text = text;
                SetOrgText(index, text);
                e.ResultNo = 0;
            }
            catch (Exception ex)
            {
                OperationLog.Instance.WriteLog(ex.Message);
            }
            finally
            {
                if ((Fields[index].ShowStyle & SystemEnum.EShowStyle.ThousandSeparator) == SystemEnum.EShowStyle.ThousandSeparator && text.Length > 0)
                {
                    text = CConvert.ToThousandSeparator(CConvert.ToDecimal(text), Fields[index].ThousandFormat); //コントロールの値連動する (小数点!!!!)
                    Fields[index].Text = text;
                    e.Text = text;
                }
                else if ((Fields[index].ShowStyle & SystemEnum.EShowStyle.ZeroPad) == SystemEnum.EShowStyle.ZeroPad && text.Length > 0)
                {
                    text = text.PadLeft(Fields[index].MaxLenth, '0');
                    Fields[index].Text = text;
                    e.Text = text;
                }
 
                if (AfterLeave != null) { AfterLeave(Fields[index], new ValidEventArgs()); }
                if (ArrowUpPush) { ArrowUpPush = false; }
                if (refresh && ErrRefresh != null) { ErrRefresh(); }
            }
        }
 
        #endregion
 
        #region  ★★★★★ Private Function ★★★★★
 
        private async Task<bool> SetAutoNextFocus(int index, bool isEnter, JsInputCoreEventArgs e)
        {
            try
            {
                if (BeforeAutoNextFocus != null)
                {
                    ValidEventArgs args = new ValidEventArgs() { EnterPush = isEnter };
                    if (!await BeforeAutoNextFocus(Fields[index], args)) { return false; }
                }
 
                int hitIdx = -1;
                if (isEnter)
                {
                    for (int i = index + 1; i < Fields.Count; i++)
                    {
                        if (!Fields[i].Disabled)
                        {
                            hitIdx = i;
                            break;
                        }
                    }
 
                    if (hitIdx == -1) { return false; }
                }
                else
                {
                    if (index == 0) { return true; }
 
                    for (int i = index - 1; i >= 0; i--)
                    {
                        if (!Fields[i].Disabled)
                        {
                            hitIdx = i;
                            break;
                        }
                    }
 
                    if (hitIdx == -1) { return false; }
                }
                e.NextFocus = $"{e.ID}-{hitIdx}";
                return true;
            }
            catch
            {
                return false;
            }
            finally
            {
                if (AfterAutoNextFocus != null) { AfterAutoNextFocus(Fields[index], new ValidEventArgs() { EnterPush = isEnter }); }
            }
        }
 
        private async Task<bool> IsValueChanged(int index, string inputText, bool isEnter, JsInputCoreEventArgs e)
        {
            string newInputValue = string.Empty;
            if ((Fields[index].ShowStyle & SystemEnum.EShowStyle.ThousandSeparator) == SystemEnum.EShowStyle.ThousandSeparator && inputText.Length > 0)
            {
                newInputValue = CConvert.ToThousandSeparator(CConvert.ToDecimal(inputText), Fields[index].ThousandFormat);   //※OrgTextはカンマ区切りのまま
            }
            else
            {
                newInputValue = inputText;
            }
 
            EnvironmentSetting.Debug($"CheckValueChanged:{index}⇒inputText={newInputValue},OrgText={Fields[index].OrgText}");
            if (newInputValue.Equals(Fields[index].OrgText))
            {
                return false;
            }
 
            //値変更したかどうか
            if (ValueChanged != null)
            {
                ValidEventArgs vce = new ValidEventArgs() { Text = inputText, EnterPush = isEnter };
                if (!await ValueChanged(Fields[index], vce))
                {
                    //元の値に戻す
                    if (vce.ResetOrgValue)
                    {
                        //※元の値に戻す且つフォーカス移動必要
                        Fields[index].Text = Fields[index].OrgText;
                        e.Text = Fields[index].OrgText;
                    }
                    return false;  //外から強制的に値変らないようにする
                }
            }
            return true;
        }
 
        private void SetOrgText(int index, string inputText)
        {
            if ((Fields[index].ShowStyle & SystemEnum.EShowStyle.ThousandSeparator) == SystemEnum.EShowStyle.ThousandSeparator)
            {
                Fields[index].OrgText = CConvert.ToThousandSeparator(CConvert.ToDecimal(inputText), Fields[index].ThousandFormat);   //※OrgTextはカンマ区切りのまま
            }
            else
            {
                Fields[index].OrgText = inputText;
            }
        }
 
        private bool IsCorrectValue(int index, string inputText)
        {
            string wsChkStr = "";
            SystemEnum.EInputChar wlErrFlg = 0;
            try
            {
                string text = (Fields[index].ShowStyle & SystemEnum.EShowStyle.ThousandSeparator) == SystemEnum.EShowStyle.ThousandSeparator ? inputText.Replace(",", string.Empty) : inputText;
 
                SystemEnum.EInputChar inputType = Fields[index].InputChar;
                //半角チェック
                if ((inputType & SystemEnum.EInputChar.Half) == SystemEnum.EInputChar.Half && !CConvert.IsHalf(text))
                {
                    Fields[index].Error = true;
                    Fields[index].ErrorText = "半角入力してください。";
                    return false;
                }
 
                //全角チェック
                if ((inputType & SystemEnum.EInputChar.Full) == SystemEnum.EInputChar.Full && !CConvert.IsFull(text))
                {
                    Fields[index].Error = true;
                    Fields[index].ErrorText = "全角入力してください。";
                    return false;
                }
 
                //数字
                if ((inputType & SystemEnum.EInputChar.Num) == SystemEnum.EInputChar.Num)
                {
                    wsChkStr = wsChkStr + Chr_Num;
                    wlErrFlg = wlErrFlg | SystemEnum.EInputChar.Num;
                }
 
                //.
                if ((inputType & SystemEnum.EInputChar.Dot) == SystemEnum.EInputChar.Dot)
                {
                    wsChkStr = wsChkStr + ".";
                    wlErrFlg = wlErrFlg | SystemEnum.EInputChar.Dot;
                }
 
                //[/]
                if ((inputType & SystemEnum.EInputChar.Slash) == SystemEnum.EInputChar.Slash)
                {
                    wsChkStr = wsChkStr + "/";
                    wlErrFlg = wlErrFlg | SystemEnum.EInputChar.Slash;
                }
 
                //Space
                if ((inputType & SystemEnum.EInputChar.Space) == SystemEnum.EInputChar.Space)
                {
                    wsChkStr = wsChkStr + " ";
                    wlErrFlg = wlErrFlg | SystemEnum.EInputChar.Space;
                }
 
                //-
                if ((inputType & SystemEnum.EInputChar.Subtract) == SystemEnum.EInputChar.Subtract)
                {
                    wsChkStr = wsChkStr + "-";
                    wlErrFlg = wlErrFlg | SystemEnum.EInputChar.Subtract;
                }
 
                //:
                if ((inputType & SystemEnum.EInputChar.Colon) == SystemEnum.EInputChar.Colon)
                {
                    wsChkStr = wsChkStr + ":";
                    wlErrFlg = wlErrFlg | SystemEnum.EInputChar.Colon;
                }
 
                //,
                if ((inputType & SystemEnum.EInputChar.Comma) == SystemEnum.EInputChar.Comma)
                {
                    wsChkStr = wsChkStr + ",";
                    wlErrFlg = wlErrFlg | SystemEnum.EInputChar.Colon;
                }
 
                //小英
                if ((inputType & SystemEnum.EInputChar.Alpha_C) == SystemEnum.EInputChar.Alpha_C)
                {
                    wsChkStr = wsChkStr + Chr_Alpha_C;
                    wlErrFlg = wlErrFlg | SystemEnum.EInputChar.Alpha_C;
                }
 
                //大英
                if ((inputType & SystemEnum.EInputChar.Alpha_S) == SystemEnum.EInputChar.Alpha_S)
                {
                    wsChkStr = wsChkStr + Chr_Alpha_S;
                    wlErrFlg = wlErrFlg | SystemEnum.EInputChar.Alpha_S;
                }
 
                //カナ
                if ((inputType & SystemEnum.EInputChar.Kana) == SystemEnum.EInputChar.Kana)
                {
                    wsChkStr = wsChkStr + Chr_Kana;
                    wlErrFlg = wlErrFlg | SystemEnum.EInputChar.Kana;
                }
                if (wsChkStr.Length > 0)
                {
                    if (CConvert.IsInOwnStr(text, wsChkStr) == false)
                    {
                        Fields[index].Error = true;
                        if (wlErrFlg == SystemEnum.EInputChar.Num)
                        {
                            Fields[index].ErrorText = "数字を入力してください。";
                        }
                        else if (wlErrFlg == SystemEnum.EInputChar.Kana)
                        {
                            Fields[index].ErrorText = "半角カナを入力してください。";
                        }
                        else if (wlErrFlg == SystemEnum.EInputChar.Alpha_S)
                        {
                            Fields[index].ErrorText = "小英文字を入力してください。";
                        }
                        else if (wlErrFlg == SystemEnum.EInputChar.Alpha_C)
                        {
                            Fields[index].ErrorText = "大英文字を入力してください。";
                        }
                        else
                        {
                            Fields[index].ErrorText = "正しい値を入力してください。";
                        }
                        return false;
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                OperationLog.Instance.WriteLog($"IsCorrectValue:{ex.Message}");
                return false;
            }
        }
 
        private bool IsCorrectText(int index, string inputText, bool isEnter)
        {
            //必須判断
            if (inputText.Trim().Length == 0 && Fields[index].Required)
            {
                Fields[index].Error = true;
                Fields[index].ErrorText = "内容を入力してください。";
                return false;
            }
 
            //入力文字判断
            if (!IsCorrectValue(index, inputText)) { return false; }
 
            //日付判断
            if (Fields[index].InputStyle == SystemEnum.EInputStyle.Date)
            {
                if (!CConvert.IsDate(CConvert.ToInt(inputText.Replace("/", string.Empty).Replace("-", string.Empty)).ToString().PadLeft(8, '0')))
                {
                    Fields[index].Error = true;
                    Fields[index].ErrorText = "正しい日付を入力してください。";
                    return false;
                }
            }
 
            //範囲判断
            if (Fields[index].Range.Length > 0)
            {
                if (CConvert.IsOutOfRange(inputText, Fields[index].Range))
                {
                    Fields[index].Error = true;
                    Fields[index].ErrorText = "入力範囲以外です。";
                    return false;
                }
            }
            return true;
        }
 
        #endregion
 
        #region  ★★★★★ Public  Function ★★★★★
 
        public void Add(ValidField field)
        {
            field.Index = Fields.Count;
            Fields.Add(field);
            dict.Add(field.Name, field);
            if (field.GridFilter) { FilterFields.Add(field.Name); }
            if (field.GridOrder > 0) { OrderFields.Add(field.GridOrder, field.Name); }
        }
 
        public void RemoveAt(int index)
        {
            string key = Fields[index].Name;
            if (Fields[index].GridFilter) { FilterFields.Remove(key); }
            if (Fields[index].GridOrder > 0) { OrderFields.Remove(Fields[index].GridOrder); }
            dict.Remove(key);
            Fields.RemoveAt(index);
            for (int i = index; i < Fields.Count; i++) { Fields[i].Index -= 1; }
        }
 
        public void Remove(ValidField field)
        {
            RemoveAt(field.Index);
        }
 
        public void Remove(string key)
        {
            ValidField field = dict[key];
            RemoveAt(field.Index);
        }
 
        public ValidField GetField(string key)
        {
            return dict[key];
        }
 
        public void SetField(string key, string value)
        {
            dict[key].Text = value;
        }
 
        public void SetField(string key, string value, string disp)
        {
            dict[key].Text = value;
            dict[key].DispText = disp;
        }
 
        public void Clear()
        {
            ErrText = string.Empty;
            EnterPush = false;
            ArrowUpPush = false;
 
            foreach (ValidField field in Fields)
            {
                field.Clear();
            }
        }
 
        public async Task<bool> IsValidAll()
        {
            try
            {
                ErrText = string.Empty;
                foreach (ValidField field in Fields)
                {
                    string text = field.Text;
                    if (!IsCorrectText(field.Index, text, false))
                    {
                        ErrText = field.ErrorText;
                        return false;
                    }
 
                    if (BusinessValid != null)
                    {
                        ValidEventArgs e = new ValidEventArgs() { Text = text, IsAll = true };
                        if (!await BusinessValid(field, e))
                        {
                            ErrText = field.ErrorText;
                            return false;
                        }
                    }
                }
 
                return true;
            }
            catch
            {
                return false;
            }
            finally
            {
                if (ErrText.Length > 0 && ErrRefresh != null) { ErrRefresh(); }
            }
        }
 
        #endregion
 
    }
}