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
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
using Shared;
using HDL_ON.UI.CSS;
using HDL_ON.Stan;
using System;
using System.Collections.Generic;
using System.Text;
using HDL_ON.Entity;
 
namespace HDL_ON.UI
{
    /// <summary>
    /// 门锁常开自动化列表界面
    /// </summary>
    public class DoorLockAlwaysOnListPage : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 上部Frame的容器控件
        /// </summary>
        private FrameLayout frameTopBack = null;
        /// <summary>
        /// 下部Frame的容器控件
        /// </summary>
        private FrameLayout frameBottomBack = null;
        /// <summary>
        /// 自动化列表控件
        /// </summary>
        private VerticalListControl listView = null;
        /// <summary>
        /// 门锁信息
        /// </summary>
        private DoorLockAlwayOnInfo doorLockInfo = new DoorLockAlwayOnInfo();
        /// <summary>
        /// 门锁对象
        /// </summary>
        private Function doorDevice = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_doorDevice">门锁对象</param>
        public void ShowForm(Function i_doorDevice)
        {
            this.doorDevice = i_doorDevice;
 
            //常开
            base.SetTitleText(Language.StringByID(StringId.AlwaysOn));
 
            //初始化中部信息
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            //初始化上部控件
            this.InitTopTopBackControl();
 
            //初始化下部控件
            this.InitBottomBackControl();
        }
 
        #endregion
 
        #region ■ 初始化上部控件_____________________
 
        /// <summary>
        /// 初始化上部控件
        /// </summary>
        private void InitTopTopBackControl()
        {
            if (this.frameTopBack == null || this.frameTopBack.Parent == null)
            {
                this.frameTopBack = new FrameLayout();
                frameTopBack.BackgroundColor = CSS_Color.MainBackgroundColor;
                bodyFrameLayout.AddChidren(frameTopBack);
            }
            else
            {
                this.frameTopBack.RemoveAll();
            }
 
            //如果不处于常开模式
            if (this.doorLockInfo.IsAlwayOpen == false)
            {
                //锁的图片
                var btnPic = new PicViewControl(102, 102);
                btnPic.Y = Application.GetRealHeight(28);
                btnPic.Gravity = Gravity.CenterHorizontal;
                btnPic.UnSelectedImagePath = "FunctionIcon/DoorLock/UnLockPictrue2.png";
                this.frameTopBack.AddChidren(btnPic);
                btnPic.ButtonClickEvent += (sender, e) =>
                {
                    this.doorLockInfo.IsAlwayOpen = true;
                    //重新初始化上部控件
                    this.InitTopTopBackControl();
                };
 
                //时效性常开设置
                var rowSettion = new FrameRowControl();
                rowSettion.Y = btnPic.Bottom + Application.GetRealHeight(32);
                this.frameTopBack.AddChidren(rowSettion);
                rowSettion.AddLeftCaption(Language.StringByID(StringId.TimelyAlwaysOnSetting), 350);
                rowSettion.AddRightArrow();
                rowSettion.AddBottomLine();
                rowSettion.ButtonClickEvent += (sender, e) =>
                {
                    //设置常开模式后{0}您的门锁将处于打开状态{0}是否继续开启
                    HdlMessageLogic.Current.ShowMassage(ShowMsgType.Confirm, Language.StringByID(StringId.OpenAlwayOnConfirmMsg), () =>
                    {
                        var form = new DoorLockExpireTimeSettionPage();
                        form.ShowForm();
                        form.FinishEvent += (hour) =>
                        {
                            //已开启
                            //HdlMessageLogic.Current.ShowMassage(ShowMsgType.ConfirmSuccess, Language.StringByID(StringId.AlreadyOpened), () =>
                            //{
 
                            //});
                            //常开模式关闭设置失效,请重试
                            HdlMessageLogic.Current.ShowMassage(ShowMsgType.ConfirmFail, Language.StringByID(StringId.AlwayOnFailTimeSettionFailMsg), () =>
                            {
                            });
                        };
 
                    }, Language.StringByID(StringId.ConfirmOpen));
                };
 
                //变更容器高度
                this.frameTopBack.Height = rowSettion.Bottom + Application.GetRealHeight(12);
            }
            //如果处于常开模式
            else
            {
                //锁的图片
                var btnPic = new PicViewControl(102, 102);
                btnPic.Y = Application.GetRealHeight(28);
                btnPic.Gravity = Gravity.CenterHorizontal;
                btnPic.UnSelectedImagePath = "FunctionIcon/DoorLock/UnLockPictrue1.png";
                this.frameTopBack.AddChidren(btnPic);
 
                //关闭按钮
                var btnClose = new BottomClickButton(220);
                btnClose.Y = btnPic.Bottom + Application.GetRealHeight(28);
                btnClose.TextID = StringId.Close;
                this.frameTopBack.AddChidren(btnClose);
                btnClose.ButtonClickEvent += (sender, e) =>
                {
                    this.doorLockInfo.IsAlwayOpen = false;
                    //重新初始化上部控件
                    this.InitTopTopBackControl();
                };
 
                //常开模式将于{12.31 14:59}关闭
                var listMsg = Language.StringByID(StringId.AlwaysOnWillCloseOnTime).Split(new string[] { "{0}" }, StringSplitOptions.None);
                int widthCount = 0;
                //常开模式将于
                var btnMsg1 = new NormalViewControl(100, 20, true);
                btnMsg1.Y = btnClose.Bottom + Application.GetRealHeight(32);
                btnMsg1.TextColor = CSS_Color.FirstLevelTitleColor;
                btnMsg1.Text = listMsg[0];
                btnMsg1.Width = btnMsg1.GetRealWidthByText();
                this.frameTopBack.AddChidren(btnMsg1);
                widthCount += btnMsg1.Width;
                //时间(12.31 14:59)
                var startTime = this.doorLockInfo.StartTime.AddHours(this.doorLockInfo.AlwayOpenHour);
                var btnMsgTime = new NormalViewControl(100, 20, true);
                btnMsgTime.Y = btnMsg1.Y;
                btnMsgTime.TextColor = CSS_Color.AuxiliaryColor2;
                btnMsgTime.Text = HdlCommonLogic.Current.ConvertDayText(startTime.Month, startTime.Day, startTime.Year) + " " + startTime.ToString("HH:mm");
                btnMsgTime.Width = btnMsgTime.GetRealWidthByText();
                this.frameTopBack.AddChidren(btnMsgTime);
                widthCount += btnMsgTime.Width;
 
                NormalViewControl btnMsg2 = null;
                if (listMsg.Length > 1)
                {
                    //关闭
                    btnMsg2 = new NormalViewControl(100, 20, true);
                    btnMsg2.Y = btnMsg1.Y;
                    btnMsg2.TextColor = CSS_Color.FirstLevelTitleColor;
                    btnMsg2.Text = listMsg[1];
                    btnMsg2.Width = btnMsg2.GetRealWidthByText();
                    this.frameTopBack.AddChidren(btnMsg2);
                    widthCount += btnMsg2.Width;
                }
                //让这三个东西居中
                int defultXX = (this.frameTopBack.Width - widthCount) / 2;
                btnMsg1.X = defultXX;
                btnMsgTime.X = btnMsg1.Right;
                if (btnMsg2 != null)
                {
                    btnMsg2.X = btnMsgTime.Right;
                }
 
                //变更容器高度
                this.frameTopBack.Height = btnMsgTime.Bottom + Application.GetRealHeight(16);
            }
            //刷新下部Frame控件的坐标和高度
            this.RefreshBottomFrameHeightAndLocation();
        }
 
        #endregion
 
        #region ■ 初始化下部控件_____________________
 
        /// <summary>
        /// 初始化下部控件
        /// </summary>
        private void InitBottomBackControl()
        {
            if (this.frameBottomBack == null || this.frameBottomBack.Parent == null)
            {
                this.frameBottomBack = new FrameLayout();
                frameBottomBack.BackgroundColor = CSS_Color.MainBackgroundColor;
                bodyFrameLayout.AddChidren(frameBottomBack);
                //常开自动化
                var rowSettion = new FrameRowControl();
                rowSettion.Y = Application.GetRealHeight(6);
                frameBottomBack.AddChidren(rowSettion);
                var btnCation = rowSettion.AddLeftCaption(Language.StringByID(StringId.AutomationAlwaysOn), 300);
                btnCation.TextSize = CSS_FontSize.SubheadingFontSize;
                btnCation.TextColor = CSS_Color.FirstLevelTitleColor;
                btnCation.IsBold = true;
                //添加图标
                var btnAddIcon = rowSettion.AddMostRightEmptyIcon(38, 38);
                btnAddIcon.UnSelectedImagePath = "Public/AddIcon.png";
                btnAddIcon.ButtonClickEvent += (sender, e) =>
                {
                    var form = new DoorLockAlwaysOnManagerPage();
                    form.AddForm(new object[] { null });
                };
 
                //列表控件
                this.listView = new VerticalListControl();
                frameBottomBack.AddChidren(listView);
            }
            else
            {
                this.frameBottomBack.RemoveAll();
                this.listView.RemoveAll();
            }
            //刷新下部Frame控件的坐标和高度
            this.RefreshBottomFrameHeightAndLocation();
 
            //测试
            for (int i = 0; i < 2; i++)
            {
                //添加自动化条件控件
                this.AddAutomationControl(new AlwayOnAutomationInfo());
            }
        }
 
        #endregion
 
        #region ■ 添加自动化条件控件_________________
 
        /// <summary>
        /// 添加自动化条件控件
        /// </summary>
        /// <param name="i_info">自动化信息</param>
        private void AddAutomationControl(AlwayOnAutomationInfo i_info)
        {
            //容器控件
            var rowBack = new RowLayout();
            rowBack.LineColor = CSS_Color.viewTranslucence;
            rowBack.SubViewWidth = Application.GetRealWidth(80);
            rowBack.Height = Application.GetRealHeight(100);
            this.listView.AddChidren(rowBack);
 
            //消息
            var btnMsg = new NormalViewControl(rowBack.Width - HdlControlResourse.XXLeft * 2, Application.GetRealHeight(20), false);
            btnMsg.X = HdlControlResourse.XXLeft;
            btnMsg.Y = Application.GetRealHeight(10);
            btnMsg.TextColor = CSS_Color.FirstLevelTitleColor;
            if (i_info.IsOpenAlwayOn == true)
            {
                //9:00 - 打开常开模式
                btnMsg.Text = i_info.Hour + ":" + i_info.Minute.ToString().PadLeft(2, '0') + " - " + Language.StringByID(StringId.OpenAlwaysOnModel);
            }
            else
            {
                //9:00 - 关闭常开模式
                btnMsg.Text = i_info.Hour + ":" + i_info.Minute.ToString().PadLeft(2, '0') + " - " + Language.StringByID(StringId.CloseAlwaysOnModel);
            }
            rowBack.AddChidren(btnMsg);
 
            //周期
            var btnTimeLoop = new NormalViewControl(rowBack.Width - HdlControlResourse.XXLeft * 2, Application.GetRealHeight(18), false);
            btnTimeLoop.X = btnMsg.X;
            btnTimeLoop.Y = btnMsg.Bottom + Application.GetRealHeight(4);
            btnTimeLoop.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
            btnTimeLoop.TextColor = CSS_Color.PromptingColor1;
            btnTimeLoop.Text = "周一 - 周五";
            rowBack.AddChidren(btnTimeLoop);
 
            //图标行控件
            var rowIcon = new FrameRowControl();
            rowIcon.Gravity = Gravity.BottomCenter;
            rowBack.AddChidren(rowIcon);
 
            //先画底线
            rowIcon.AddBottomLine();
 
            //固定的三个图标
            var btnIcon1 = rowIcon.AddLeftIcon(28, "Phone/LogicIcon/selectTheTime.png");
            var btnIcon2 = rowIcon.AddLeftIcon(20, "Phone/LogicIcon/link.png");
            btnIcon2.X = btnIcon1.Right + Application.GetRealWidth(8);
            var btnIcon3 = rowIcon.AddLeftIcon(28, "FunctionIcon/DoorLock/NormallyOpenIcon3.png");
            btnIcon3.X = btnIcon2.Right + Application.GetRealWidth(8);
 
            //开关
            var btnSwitch = rowIcon.AddMostRightSwitchIcon();
            btnSwitch.ButtonClickEvent += (sender, e) =>
            {
                btnSwitch.IsSelected = !btnSwitch.IsSelected;
            };
 
            //编辑
            var btnEditor = new NormalViewControl(rowBack.SubViewWidth, rowBack.Height, false);
            btnEditor.TextAlignment = TextAlignment.Center;
            btnEditor.TextSize = CSS_FontSize.SubheadingFontSize;
            btnEditor.TextColor = CSS_Color.MainBackgroundColor;
            btnEditor.BackgroundColor = CSS_Color.AuxiliaryColor1;
            btnEditor.TextID = StringId.Edit;
            rowBack.AddRightView(btnEditor);
            btnEditor.ButtonClickEvent += (sender, e) =>
            {
                //还原
                rowBack.HideRightMenu();
                var form = new DoorLockAlwaysOnManagerPage();
                form.AddForm(new object[] { i_info });
            };
            //删除
            var btnDelete = new NormalViewControl(rowBack.SubViewWidth, rowBack.Height, false);
            btnDelete.TextAlignment = TextAlignment.Center;
            btnDelete.TextSize = CSS_FontSize.SubheadingFontSize;
            btnDelete.TextColor = CSS_Color.MainBackgroundColor;
            btnDelete.BackgroundColor = CSS_Color.AuxiliaryColor2;
            btnDelete.TextID = StringId.Del;
            rowBack.AddRightView(btnDelete);
            btnDelete.ButtonClickEvent += (sender, e) =>
            {
                //是否要删除自动化?
                HdlMessageLogic.Current.ShowMassage(ShowMsgType.Confirm, Language.StringByID(StringId.delAutomation), () =>
                {
                    rowBack.RemoveFromParent();
                });
            };
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 刷新下部Frame控件的坐标和高度
        /// </summary>
        private void RefreshBottomFrameHeightAndLocation()
        {
            if (this.frameBottomBack != null)
            {
                this.frameBottomBack.Y = this.frameTopBack.Bottom + Application.GetRealHeight(8);
                this.frameBottomBack.Height = bodyFrameLayout.Height - this.frameBottomBack.Y;
            }
            if (this.listView != null)
            {
                //这个Y轴固定
                this.listView.Y = Application.GetRealHeight(58);
                this.listView.Height = this.frameBottomBack.Height - this.listView.Y;
            }
        }
 
        #endregion
 
        #region ■ 界面关闭___________________________
 
        /// <summary>
        /// 界面关闭
        /// </summary>
        public override void CloseFormBefore()
        {
            base.CloseFormBefore();
        }
 
        #endregion
    }
}