wxr
2023-06-06 592974441a4df95fffd9167c90192da1a390b1c2
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
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 DoorLockSelectTimePage : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 选择结束的事件
        /// </summary>
        public Action<DateTime> SelectFinshEvent = null;
        /// <summary>
        /// 选择的时间
        /// </summary>
        private DateTime selectDateTime;
        /// <summary>
        /// 时间校验
        /// 是否需要校验时间大于当前时间
        /// </summary>
        public bool TimeCheck = false;
 
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_dateTime">一个时间</param>
        public void ShowForm(DateTime i_dateTime)
        {
            this.selectDateTime = i_dateTime;
 
            //选择时间
            base.SetTitleText(Language.StringByID(StringId.SelectTime));
 
            //初始化中部信息
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            //选择日期
            var rowDate = new FrameLayout() {
                Height = Application.GetRealHeight(50),
            };
            rowDate.BackgroundColor = CSS_Color.MainBackgroundColor;
            bodyFrameLayout.AddChidren(rowDate);
            var btnDateLeft = new Button()
            {
                TextID = StringId.SelectDate,
                TextAlignment = TextAlignment.CenterLeft,
                Width = Application.GetRealWidth(300),
                X = Application.GetRealWidth(16),
                TextColor = CSS_Color.FirstLevelTitleColor,
            };
            rowDate.AddChidren(btnDateLeft);
            var btnDateRight = new Button()
            {
                X = Application.GetRealWidth(339),
                Gravity = Gravity.CenterVertical,
                Width = Application.GetMinRealAverage(16),
                Height = Application.GetMinRealAverage(16),
                UnSelectedImagePath = "Public/Right.png",
            };
            rowDate.AddChidren(btnDateRight);
            rowDate.AddChidren(new Button() { X = Application.GetRealWidth(16),Y = Application.GetRealHeight(49), Height = Application.GetRealHeight(1), Width = Application.GetRealWidth(343), BackgroundColor = CSS_Color.DividingLineColor });
 
            var btnDay = new Button()
            {
                Width = Application.GetRealWidth(327),
                TextAlignment = TextAlignment.CenterRight,
                Text = selectDateTime.ToString("yyyy.MM.dd"),
                TextColor = CSS_Color.FirstLevelTitleColor,
            };
            rowDate.AddChidren(btnDay);
            EventHandler<MouseEventArgs> dateEvent = (sender, e) =>
            {
                //显示日期选择的底部弹窗
                var contr = new BottomDateSelectControl();
                contr.InitControl(this.selectDateTime.Year, this.selectDateTime.Month, this.selectDateTime.Day, 0, 1);
                contr.FinishEvent += (div, year, month, day) =>
                {
                    //覆盖时间
                    if (div == 1)
                    {
                        this.selectDateTime = new DateTime(year, month, day, this.selectDateTime.Hour, this.selectDateTime.Minute, 0);
                        btnDay.Text = this.selectDateTime.ToString("yyyy.MM.dd");
                    }
                };
            };
            btnDateLeft.MouseUpEventHandler = dateEvent;
            btnDateRight.MouseUpEventHandler = dateEvent;
            btnDay.MouseUpEventHandler = dateEvent;
 
            //选择时间
            var rowTime = new FrameLayout() {
                Y = rowDate.Bottom,
                Height = Application.GetRealHeight(50),
                BackgroundColor = CSS_Color.MainBackgroundColor,
            };
            bodyFrameLayout.AddChidren(rowTime);
            rowTime.AddChidren(new Button() { X = Application.GetRealWidth(16),Y = Application.GetRealHeight(49), Height = Application.GetRealHeight(1), Width = Application.GetRealWidth(343), BackgroundColor = CSS_Color.DividingLineColor });
            var btnTimeLeft = new Button()
            {
                TextID = StringId.SelectTime,
                TextAlignment = TextAlignment.CenterLeft,
                Width = Application.GetRealWidth(300),
                X = Application.GetRealWidth(16),
                TextColor = CSS_Color.FirstLevelTitleColor,
            };
            rowTime.AddChidren(btnTimeLeft);
            var btnTimeRight = new Button()
            {
                X = Application.GetRealWidth(339),
                Gravity = Gravity.CenterVertical,
                Width = Application.GetMinRealAverage(16),
                Height = Application.GetMinRealAverage(16),
                UnSelectedImagePath = "Public/Right.png",
            };
            rowTime.AddChidren(btnTimeRight);
            var btnTime = new Button()
            {
                Width = Application.GetRealWidth(327),
                TextAlignment = TextAlignment.CenterRight,
                Text = selectDateTime.ToString("HH:mm"),
                TextColor = CSS_Color.FirstLevelTitleColor,
            };
            rowTime.AddChidren(btnTime);
            EventHandler<MouseEventArgs> timeEvent = (sender, e) =>
            {
                //显示日期选择的底部弹窗
                var contr = new BottomTimeSelectControl();
                contr.RowCount = 4;
                contr.InitControl(this.selectDateTime.Hour, this.selectDateTime.Minute,250);
                contr.FinishEvent += (div, hour, minute) =>
                {
                    //覆盖时间
                    if (div == 1)
                    {
                        this.selectDateTime = new DateTime(this.selectDateTime.Year, this.selectDateTime.Month, this.selectDateTime.Day, hour, minute, 0);
                        btnTime.Text = this.selectDateTime.ToString("HH:mm");
                    }
                };
            };
            btnTimeLeft.MouseUpEventHandler = timeEvent;
            btnTimeRight.MouseUpEventHandler = timeEvent;
            btnTime.MouseUpEventHandler = timeEvent;
        }
 
        #endregion
 
        #region ■ 界面关闭___________________________
 
        /// <summary>
        /// 界面关闭
        /// </summary>
        public override void CloseFormBefore()
        {
            if (TimeCheck)
            {
                if (DateTime.Now > this.selectDateTime.AddMinutes(1))
                {
                    new PublicAssmebly().TipMsg(StringId.Tip, StringId.TempPwdSettingTip);
                    throw new Exception("stop");
                }
            }
            base.CloseFormBefore();
            //调用回调事件
            this.SelectFinshEvent?.Invoke(this.selectDateTime);
            this.SelectFinshEvent = null;
        }
 
        #endregion
    }
}