xm
2021-12-01 6d73bf6e816570291865674bef8bce8972e4de3f
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
using Shared;
using HDL_ON.UI.CSS;
using HDL_ON.Stan;
using System;
using System.Collections.Generic;
using System.Text;
 
namespace HDL_ON.UI
{
    /// <summary>
    /// 门锁常开模式失效时间设置界面(不需要添加到父控件)
    /// </summary>
    public class DoorLockExpireTimeSettionPage
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 结束事件(参数为,输入的小时)
        /// </summary>
        public Action<int> FinishEvent = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 界面显示
        /// </summary>
        public void ShowForm()
        {
            var dialogForm = new Dialog();
            dialogForm.BackgroundColor = CSS_Color.DialogTransparentColor1;
            //主控件
            var frameMain = new NormalFrameLayout();
            dialogForm.AddChidren(frameMain);
            dialogForm.Show();
            frameMain.ButtonClickEvent += (sender, e) =>
            {
                dialogForm.Close();
                this.FinishEvent = null;
            };
 
            //中间区域
            var frameCenter = new NormalFrameLayout();
            frameCenter.Y = Application.GetRealHeight(239);
            frameCenter.Gravity = Gravity.CenterHorizontal;
            frameCenter.Width = Application.GetRealWidth(270);
            frameCenter.Height = Application.GetRealHeight(172);
            frameCenter.BackgroundColor = CSS_Color.MainBackgroundColor;
            frameCenter.BorderColor = 0x00000000;
            frameCenter.BorderWidth = 0;
            frameCenter.Radius = (uint)Application.GetMinRealAverage(10);
            frameMain.AddChidren(frameCenter);
 
            //失效设置
            var btnTitle = new NormalViewControl(frameCenter.Width - HdlControlResourse.XXLeft * 2, Application.GetRealHeight(22), false);
            btnTitle.Y = Application.GetRealHeight(20);
            btnTitle.Gravity = Gravity.CenterHorizontal;
            btnTitle.TextColor = CSS_Color.MainColor;
            btnTitle.TextSize = CSS_FontSize.SubheadingFontSize;
            btnTitle.TextAlignment = TextAlignment.Center;
            btnTitle.IsBold = true;
            btnTitle.Text = Language.StringByID(StringId.FailTimeSeetion);
            frameCenter.AddChidren(btnTitle);
 
            //常开模式将于{0}小时后失效
            string[] strArryMsg = Language.StringByID(StringId.AlwayOnWillCloseAtTimeMsg).Split(new string[] { "{0}" }, StringSplitOptions.RemoveEmptyEntries);
 
            //常开模式将于
            var btnMsg1 = new NormalViewControl(Application.GetRealWidth(76), Application.GetRealHeight(32), false);
            btnMsg1.X = Application.GetRealWidth(20);
            btnMsg1.Y = btnTitle.Bottom + Application.GetRealHeight(20);
            btnMsg1.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
            btnMsg1.IsMoreLines = true;
            btnMsg1.Text = strArryMsg[0].Trim();
            frameCenter.AddChidren(btnMsg1);
 
            //失效时间的背景容器
            var frameTime = new FrameLayout();
            frameTime.X = btnMsg1.Right + Application.GetRealWidth(12);
            frameTime.Y = btnMsg1.Y;
            frameTime.Width = Application.GetRealWidth(62);
            frameTime.Height = Application.GetRealHeight(32);
            frameTime.Radius = (uint)Application.GetRealWidth(4);
            frameTime.BackgroundColor = CSS_Color.BackgroundColor;
            frameCenter.AddChidren(frameTime);
            //失效时间输入控件
            var txtInput = new TextInputControl(frameTime.Width - Application.GetRealWidth(10 * 2), frameTime.Height, false);
            txtInput.TextColor = CSS_Color.FirstLevelTitleColor;
            txtInput.Gravity = Gravity.CenterHorizontal;
            txtInput.TextAlignment = TextAlignment.Center;
            txtInput.Text = "12";
            txtInput.MaxByte = 2;
            txtInput.IsNumberKeyboardType = true;
            frameTime.AddChidren(txtInput);
 
            //小时后失效
            var btnMsg2 = new NormalViewControl(btnMsg1.Width, btnMsg1.Height, false);
            btnMsg2.X = frameTime.Right + Application.GetRealWidth(12);
            btnMsg2.Y = btnMsg1.Y;
            btnMsg2.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
            btnMsg2.IsMoreLines = true;
            btnMsg2.Text = strArryMsg.Length > 1 ? strArryMsg[1].Trim() : string.Empty;
            frameCenter.AddChidren(btnMsg2);
 
            //错误显示消息
            var btnErrorMsg = new NormalViewControl(frameCenter.Width - Application.GetRealWidth(20) * 2, Application.GetRealHeight(21), false);
            btnErrorMsg.Y = btnMsg1.Bottom;
            btnErrorMsg.Gravity = Gravity.CenterHorizontal;
            btnErrorMsg.TextColor = CSS_Color.WarningColor;
            btnErrorMsg.IsMoreLines = true;
            btnErrorMsg.TextAlignment = TextAlignment.TopLeft;
            //btnErrorMsg.Height = Application.GetRealHeight(21) * btnErrorMsg.GetRealRowCountByText();
            btnErrorMsg.Visible = false;
            frameCenter.AddChidren(btnErrorMsg);
 
            //确认
            var btnConfirm = new NormalViewControl(frameCenter.Width, Application.GetRealHeight(45), false);
            btnConfirm.Gravity = Gravity.BottomCenter;
            btnConfirm.TextAlignment = TextAlignment.Center;
            btnConfirm.TextSize = CSS_FontSize.SubheadingFontSize;
            btnConfirm.TextColor = CSS_Color.MainBackgroundColor;
            btnConfirm.BackgroundColor = CSS_Color.MainColor;
            btnConfirm.Text = Language.StringByID(StringId.Confirm);
            frameCenter.AddChidren(btnConfirm);
            btnConfirm.SetCornerWithSameRadius((uint)Application.GetMinRealAverage(10), HDLUtils.RectCornerBottomLeft | HDLUtils.RectCornerBottomRight);
            btnConfirm.ButtonClickEvent += (sender, e) =>
            {
                //检测输入的时间是否正确
                var errorMsg = this.CheckInputTime(txtInput.Text.Trim());
                if (errorMsg != string.Empty)
                {
                    //看看消息显示的控件有没有大于34,大于的话,则算出它增加的宽度(34是输入框到底部按钮Y轴的空白区域)
                    int value = 0;
                    if (btnErrorMsg.Height > Application.GetRealHeight(34))
                    {
                        //5是与底部按钮Y轴的间距
                        value = btnErrorMsg.Height - Application.GetRealHeight(34) + Application.GetRealHeight(5);
                    }
                    //调整白色桌布的高度和坐标
                    frameCenter.Height = frameTime.Bottom + Application.GetRealHeight(34) + btnConfirm.Height + value;
                    //白色背景在蓝湖上的坐标为239,高度为172  然后让它按这个比例置于桌布
                    frameCenter.Y = Application.GetRealHeight(239) - (frameCenter.Height - Application.GetRealHeight(172)) / 2;
                    btnConfirm.Gravity = Gravity.BottomCenter;
                    //按钮置底
                    return;
                }
                //关闭界面
                dialogForm.Close();
                //回调函数
                FinishEvent?.Invoke(Convert.ToInt32(txtInput.Text.Trim()));
                FinishEvent = null;
            };
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 检测输入的时间是否正确
        /// </summary>
        /// <param name="i_value">输入的时间</param>
        /// <returns></returns>
        private string CheckInputTime(string i_value)
        {
            if (i_value == string.Empty)
            {
                //请输入失效时间
                return Language.StringByID(StringId.PleaseInputFailTime);
            }
            int value = Convert.ToInt32(i_value);
            if (value < 1)
            {
                //失效时间不能小于1小时
                return Language.StringByID(StringId.InvalidTimeLessThan1);
            }
            if (value > 72)
            {
                //失效时间不能大于72小时
                return Language.StringByID(StringId.InvalidTimeMoreThan72);
            }
            return string.Empty;
        }
 
        #endregion
    }
}