黄学彪
2020-05-07 e2cd94abacc0101af8d0db7fed3a785c1a045b5d
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
using System;
using System.Collections.Generic;
using Shared.Common;
using Shared.R;
using Shared;
 
namespace Shared.Phone.Device.Logic
{
    public class SoneLogicList : FrameLayout
    {
        /// <summary>
        /// 给Sone门锁徐梅更新界面用的
        /// </summary>
        ///
        public SoneLogicList()
        {
            Tag = "SoneLogic";
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="action">给徐梅刷新界面用的</param>
        /// <param name="bool_If"></param>
        public Action<bool> action;
        public async void Show()
        {
         
            #region  界面的布局代码
            UserView.HomePage.Instance.ScrollEnabled = false;//锁住左滑
            TopView view = new TopView();
            this.AddChidren(view.TopRowView());
            view.toptitleNameBtn.TextID = MyInternationalizationString.selection;
            view.clickBtn.MouseDownEventHandler += (sender, e) =>
            {
                UserView.HomePage.Instance.ScrollEnabled = true;
                if (action != null)
                {
                    action(Send.CurrentDoorLock.IsDoorLockNormallyMode);
                }
 
                RemoveFromParent();
 
            };
 
            var middle = new FrameLayout
            {
                Y = view.topRowLayout.Bottom,
                Height = Application.GetRealHeight(Method.H - 184),
                BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor,
            };
            this.AddChidren(middle);
            #endregion
 
            #region  常开模式图标 时效性常开设置
            ///第二块第一级父控件
            var fLayout = new FrameLayout
            {
                Width = Application.GetRealWidth(1080),
                Height = Application.GetRealHeight(829 - 184),
                BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor,
            };
            middle.AddChidren(fLayout);
            ///常开模式图标
            var modeIconBtn = new Button
            {
                X = Application.GetRealWidth(395),
                Y = Application.GetRealHeight(92),
                Width = Application.GetMinRealAverage(294),
                Height = Application.GetMinRealAverage(294),
                UnSelectedImagePath = "ZigeeLogic/noMode.png",
                SelectedImagePath = "ZigeeLogic/openMode.png",
            };
            fLayout.AddChidren(modeIconBtn);
 
            if (Send.CurrentDoorLock.IsDoorLockNormallyMode)
            {
                /// 查找是否存在时效性自动化;有的话就返回自动化对象;
                var logic = await SkipView.GetLogicIfon();
 
                fLayout.Height = Application.GetRealHeight(780);//改变高度
                modeIconBtn.IsSelected = true;//改变图标状态
                ///第二级父控件
                var openModeFl = new FrameLayout
                {
                    Y = Application.GetRealHeight(455),
                    Height = Application.GetRealHeight(127 + 199),
                    Width = Application.GetRealWidth(1080),
                };
                fLayout.AddChidren(openModeFl);
                ///关闭时效性自动化
                Button closeBtn = new Button
                {
                    X = Application.GetRealWidth(86),
                    Height = Application.GetRealHeight(127),
                    Width = Application.GetRealWidth(907),
                    Radius = (uint)Application.GetRealHeight(58),
                    BackgroundColor = ZigbeeColor.Current.LogicBtnSaveBackgroundColor,
                    TextID = MyInternationalizationString.closeUp,
                    TextColor = ZigbeeColor.Current.LogicBtnSaveTextColor,
                    TextSize = 16,
                };
                openModeFl.AddChidren(closeBtn);
                closeBtn.MouseUpEventHandler += async (sender, e) =>
                {
                    var result = await UserCenter.DoorLock.DoorLockCommonInfo.DelNormallyOpenMode(Send.CurrentDoorLock);
                    if (result)
                    {
                        if (logic != null)
                        {
                            ///有可能只有常开模式,没有时效性自动化
                            ///没有判断的话,逻辑会为空,抛出异常;
                            Send.DelLogic(logic.LogicId);
                        }
                        Send.CurrentDoorLock.IsDoorLockNormallyMode = false;
                        this.RemoveFromParent();
                        var soneLogicList = new SoneLogicList();
                        UserView.HomePage.Instance.AddChidren(soneLogicList);
                        UserView.HomePage.Instance.PageIndex += 1;
                        soneLogicList.Show();
                    }
                    else
                    {
                        ///提示失败
                    }
 
                };
 
                ///显示失效设置时间文本控件
                var timeTextBtn = new Button
                {
                    Y = Application.GetRealHeight(127 + 69),
                    X = Application.GetRealWidth(225),
                    Width = Application.GetRealWidth(634),
                    Height = Application.GetRealHeight(60),
                    TextSize = 15,
                    TextColor = ZigbeeColor.Current.LogicTextBlackColor,
                    Text = "时效性常开设置12:20",
                };
                if (logic != null)
                {
                    ///有时效性常开才显示时间条件文本
                    openModeFl.AddChidren(timeTextBtn);
                }
                ///时效性常开只有一个条件;
                try
                {
                    var y = DateTime.Now.ToString("yy");//那一年
                    var m = DateTime.Now.ToString("mm");//那一月
                    var d = DateTime.Now.ToString("dd");//那一天
                    var h = int.Parse(DateTime.Now.ToString("HH"));//当前系统时间
                    var me = DateTime.Now.ToLongDateString();
                    var timeInt = int.Parse(logic.Conditions[0]["DoorLockOpenDelayTime"]);
                    int dayInt = (h + timeInt) / 24;//算出几天后执行
                    int hour = (h + timeInt) % 24;//算出几天后那个时间执行
                    timeTextBtn.Text = "时效性常开设置" + y + "年" + m + "月" + d + dayInt + "号" + timeInt + "时" + "执行";
                }
                catch { }
 
            }
            else
            {
                fLayout.Height = Application.GetRealHeight(645);//改变高度
                modeIconBtn.IsSelected = false;//改变图标状态
                ///第二级父控件
                var modeFl = new FrameLayout
                {
                    Y = Application.GetRealHeight(478),
                    X = Application.GetRealWidth(58),
                    Height = Application.GetRealHeight(138),
                    Width = Application.GetRealWidth(1022),
                    BackgroundColor = ZigbeeColor.Current.LogicBlankBackgroundColor,
                };
                fLayout.AddChidren(modeFl);
                modeFl.SetCornerWithSameRadius(Application.GetRealHeight(17), HDLUtils.RectCornerTopLeft);
                modeFl.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerBottomLeft);
                ///时效性常开设置显示文本控件
                var modeTextBtn = new Button
                {
 
                    Y = Application.GetRealHeight(40),
                    X = Application.GetRealWidth(58),
                    Width = Application.GetRealWidth(600),
                    Height = Application.GetRealHeight(60),
                    TextSize = 15,
                    TextColor = ZigbeeColor.Current.LogicTextBlackColor,
                    TextAlignment = TextAlignment.CenterLeft,
                    // Text = "时效性常开设置",
                    TextID = MyInternationalizationString.timeSetSone,
                };
                modeFl.AddChidren(modeTextBtn);
                ///下一级菜单图标控件
                var nextIconBtn = new Button
                {
                    Width = Application.GetMinRealAverage(104),
                    Height = Application.GetMinRealAverage(104),
                    X = Application.GetRealWidth(861),
                    Y = Application.GetRealHeight(17),
                    UnSelectedImagePath = "ZigeeLogic/next.png",
                };
                modeFl.AddChidren(nextIconBtn);
 
 
 
                nextIconBtn.MouseUpEventHandler += (sender, e) =>
                 {
                     LogicView.TipView.ShowConfrimTip(() =>
                     {///再次确认
                       LogicView.TipView.ShowInputTip(true, async (str) =>
                         {///确认发送命令
                           try
                             {
                               ///xm
                               var result = await UserCenter.DoorLock.DoorLockCommonInfo.SetNormallyOpenModeFuncAsync(Send.CurrentDoorLock);
                                 if (!result)
                                 {
                                     Application.RunOnMainThread(() =>
                                     {
                                       ///提示失败
                                   });
                                     return;
                                 }
                                 else
                                 {
                                   ///因为有常开模式下才可以创建失效逻辑;
                                   SkipView.GetLogicAll();//删除之前所有失效逻辑
                                   var addResult = await SkipView.LockAddModifyLogic(int.Parse(str), Send.CurrentDoorLock);//添加一条失效逻辑
                                   if (!addResult)
                                     {
                                       ///提示失败
                                       return;
                                     }
                                     Send.CurrentDoorLock.IsDoorLockNormallyMode = true;
                                     this.RemoveFromParent();
                                     var soneLogicList = new SoneLogicList();
                                     UserView.HomePage.Instance.AddChidren(soneLogicList);
                                     UserView.HomePage.Instance.PageIndex += 1;
                                     soneLogicList.Show();
 
                                 }
                             }
                             catch
                             {
 
                             }
                         });
 
                     });
 
                 };
            }
 
            #endregion
 
            #region 常开自动化
            ///第三块第一级父控件
            var listLogicFl = new FrameLayout
            {
                Y = fLayout.Bottom,
                X = Application.GetRealWidth(58),
                Height = middle.Height - fLayout.Height,
                Width = Application.GetRealWidth(1022),
                BackgroundColor = ZigbeeColor.Current.LogicBlankBackgroundColor,
            };
            middle.AddChidren(listLogicFl);
            listLogicFl.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerTopLeft);
 
            ///添加常开自动化的父控件
            var addLogicfL = new FrameLayout
            {
                Height = Application.GetRealHeight(187),
                Width = Application.GetRealWidth(1080 - 58),
            };
            listLogicFl.AddChidren(addLogicfL);
            ///常开自动化显示文本的控件
            var addTextBtn = new Button
            {
                Y = Application.GetRealHeight(46),
                X = Application.GetRealWidth(58),
                Width = Application.GetRealWidth(600),
                Height = Application.GetRealHeight(95),
                TextSize = 24,
                TextColor = ZigbeeColor.Current.LogicTextBlackColor,
                TextAlignment = TextAlignment.CenterLeft,
                //Text = "常开自动化",
                TextID = MyInternationalizationString.openAutomationSone,
            };
            addLogicfL.AddChidren(addTextBtn);
            ///添加自动化图标的控件
            var addIconBtn = new Button
            {
                Width = Application.GetMinRealAverage(69),
                Height = Application.GetMinRealAverage(69),
                X = Application.GetRealWidth(890),
                Y = Application.GetRealHeight(60),
                UnSelectedImagePath = "ZigeeLogic/add.png",
            };
            addLogicfL.AddChidren(addIconBtn);
            addIconBtn.MouseUpEventHandler += (sender, e) =>
            {
 
                //读取系统当前时间:时-分
                //读取系统当前时间:时-分
                var h = DateTime.Now.ToString("HH");
                var m = DateTime.Now.ToString("mm");
                Dictionary<string, string> timeConditionsInfo = new Dictionary<string, string>();
                timeConditionsInfo.Add("Type", "0");
                timeConditionsInfo.Add("IsValid", "1");
                timeConditionsInfo.Add("DateType", "0");
                timeConditionsInfo.Add("RemindTime", "0");
                timeConditionsInfo.Add("EnDelay", "0");
                timeConditionsInfo.Add("DelayTime", "0");
                timeConditionsInfo.Add("DoorLockOpenDelayTime", "0");
                timeConditionsInfo.Add("StartHour", h);
                timeConditionsInfo.Add("StartMin", m);
                Dictionary<string, object> actionsInfo = new Dictionary<string, object>();
                actionsInfo.Add("LinkType", 8);
                actionsInfo.Add("DeviceAddr", Send.CurrentDoorLock.DeviceAddr);
                actionsInfo.Add("Epoint", "200");
                actionsInfo.Add("PassData", "055704010113");//默认门锁常关
                //new一个新逻辑对象;
                //新增门锁常开模式自动化入口;
                Common.Logic.CurrentLogic = new Common.Logic();
                Common.Logic.CurrentLogic.IsEnable = 1;//默认为开
                Common.Logic.CurrentLogic.LogicType = 2;//标记逻辑类型
                Common.Logic.CurrentLogic.LogicName = Language.StringByID(MyInternationalizationString.openmode);
                Common.Logic.CurrentLogic.Conditions.Add(timeConditionsInfo);//添加条件
                Common.Logic.CurrentLogic.Actions.Add(actionsInfo);//添加目标
                var oneLogic = new OneLogic();
                UserView.HomePage.Instance.AddChidren(oneLogic);
                UserView.HomePage.Instance.PageIndex += 1;
                oneLogic.Show(false);
 
            };
 
            ///常开自动化列表上下滑动的控件
            var verticalRefresh = new VerticalRefreshLayout
            {
 
                Y = addLogicfL.Bottom,
                X = Application.GetRealWidth(46),
                Height = listLogicFl.Height - addLogicfL.Height,
                Width = listLogicFl.Width - Application.GetRealWidth(46),
            };
            listLogicFl.AddChidren(verticalRefresh);
            verticalRefresh.BeginHeaderRefreshingAction += () =>
            {
                Common.Logic.SoneLogicList.Clear();
                Read(verticalRefresh, false);
                verticalRefresh.EndHeaderRefreshing();
            };
            Read(verticalRefresh, true);
            #endregion
        }
        /// <summary>
        /// 读取自动化列表数据;
        /// </summary>
        /// <param name="verticalRefresh"></param>
        private async void Read(VerticalRefreshLayout verticalRefresh, bool yes)
        {
            if (yes)
            {
                CommonPage.Loading.Start();
            }
            try
            {
                if (Common.Logic.SoneLogicList.Count == 0)
                {
                    var Idlist = await Send.GetLogicId(2);//门锁常开模式
                    if (Idlist.Count != 0)
                    {
                        var listlogic = await Send.ReadList(Idlist.Count, 2);
                        for (int i = 0; i < listlogic.Count; i++)
                        {
                            var logic = listlogic[i];
                            if (logic.LogicType != 2)
                            {
                                continue;
                            }
                            Common.Logic.SoneLogicList.Add(logic);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                var dd = e.Message;
            }
            //自动化
            RefreshView(verticalRefresh);
            if (yes)
            {
                CommonPage.Loading.Hide();
 
            }
        }
        /// <summary>
        /// 加载自动化列表
        /// </summary>
        /// <param name="verticalRefresh"></param>
        private void RefreshView(VerticalRefreshLayout verticalRefresh)
        {
            verticalRefresh.RemoveAll();
           
            foreach (var logic in Common.Logic.SoneLogicList)
            {
                #region  自动化布局View
 
                ///自动化父控件
                var fLayout = new FrameLayout
                {
                    Height = Application.GetRealHeight(184),
                };
                verticalRefresh.AddChidren(fLayout);
                ///左右可滑动控件
                var logicRow = new RowLayout
                {
                    LineColor = ZigbeeColor.Current.LogicBackgroundColor,
                    BackgroundColor = ZigbeeColor.Current.LogicBackgroundColor,
                    SubViewWidth = Application.GetRealWidth(184),//改变编辑控件宽度多少;
                };
                fLayout.AddChidren(logicRow);
                //左滑菜单事件
                logicRow.OpenMenuAction += () =>
                {
                    //if (selectedRow.Tag.ToString() != logicRowlayout.Tag.ToString())
                    //{   //保留左滑只有一个;
                    //    selectedRow.HideMenu();//
                    //}
                    //selectedRow = logicRowlayout;
                };
                ///显示逻辑名称的控件
                var nameBtn = new Button
                {
                    Height = Application.GetRealHeight(58),
                    Width = Application.GetRealWidth(350),
                    Text = logic.LogicName,
                    X = Application.GetRealWidth(12),
                    Y = Application.GetRealHeight(3),
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = ZigbeeColor.Current.LogicTextBlackColor,
                    TextSize = 14,
                };
                logicRow.AddChidren(nameBtn);
                ///显示目标功能背景颜色的控件
                var typeBjBtn = new FrameLayout
                {
                    Width = Application.GetMinRealAverage(82),
                    Height = Application.GetMinRealAverage(82),
                    X = Application.GetRealWidth(17),
                    Y = Application.GetRealHeight(84),
                    Radius = (uint)Application.GetMinRealAverage(41),
                    BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor,
                };
                logicRow.AddChidren(typeBjBtn);
                ///显示目标功能图标的控件
                var typeIconBtn = new Button
                {
                    Width = Application.GetMinRealAverage(58),
                    Height = Application.GetMinRealAverage(58),
                    Gravity = Gravity.Center,
                };
                typeBjBtn.AddChidren(typeIconBtn);
                ///逻辑开关图标的控件
                var switchBtn = new Button
                {
                    Width = Application.GetMinRealAverage(104),
                    Height = Application.GetMinRealAverage(63),
                    UnSelectedImagePath = "ZigeeLogic/logicclose.png",
                    SelectedImagePath = "ZigeeLogic/logicopen.png",
                    X = Application.GetRealWidth(815),
                    Y = Application.GetRealHeight(92),
 
                };
                logicRow.AddChidren(switchBtn);
                if (logic.IsEnable == 1)
                {
                    switchBtn.IsSelected = true;
                    typeIconBtn.UnSelectedImagePath = "ZigeeLogic/function1.png";
                    typeBjBtn.BackgroundColor = ZigbeeColor.Current.LogicFunction1Color;
                }
                else if (logic.IsEnable == 0)
                {
                    switchBtn.IsSelected = false;
                    typeIconBtn.UnSelectedImagePath = "ZigeeLogic/nofunction.png";
                    typeBjBtn.BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor;
                }
                ///编辑
                var edit = new Button
                {
                    BackgroundColor = ZigbeeColor.Current.LogicEditBlackColor1,
                    Text = Language.StringByID(MyInternationalizationString.edit),
                    TextColor = ZigbeeColor.Current.LogicBtnSaveTextColor,
                };
                logicRow.AddRightView(edit);
                if (logic.LogicType == 2)
                {
                    edit.TextID = MyInternationalizationString.look;
                }
                ///删除
                var del = new Button
                {
                    BackgroundColor = ZigbeeColor.Current.LogicDelBlackColor1,
                    Text = Language.StringByID(MyInternationalizationString.del),
                    TextColor = ZigbeeColor.Current.LogicBtnSaveTextColor,
                };
                logicRow.AddRightView(del);
                ///线的控件
                var line = new Button
                {
                    Y = fLayout.Height - 1,
                    Height = 1,
                    Width = Application.GetRealWidth(976),
                    BackgroundColor = ZigbeeColor.Current.LogicRowLayoutLineColor,
                };
                fLayout.AddChidren(line);
                #endregion
                ///开关点击事件
                switchBtn.MouseUpEventHandler += (sender1, e1) =>
                {
                    switchBtn.IsSelected = !switchBtn.IsSelected;
                    if (switchBtn.IsSelected)
                    {
                        //逻辑开
                        logic.IsEnable = 1;
                        typeIconBtn.UnSelectedImagePath = "ZigeeLogic/function1.png";
                        typeBjBtn.BackgroundColor = ZigbeeColor.Current.LogicFunction1Color;
                    }
                    else
                    {
                        //逻辑关
                        typeIconBtn.UnSelectedImagePath = "ZigeeLogic/nofunction.png";
                        typeBjBtn.BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor;
                    }
                    Send.LogicControlSwitch(logic);
                    //Logic.Send.AddModifyLogic(logic);
                };
                ///编辑点击事件
                edit.MouseUpEventHandler += (sender, e) =>
                {
                    Common.Logic.CurrentLogic = logic;
                    var oneLogic = new OneLogic();
                    UserView.HomePage.Instance.AddChidren(oneLogic);
                    UserView.HomePage.Instance.PageIndex += 1;
                    oneLogic.Show(false);
                };
                ///删除点击事件
                del.MouseUpEventHandler += (sender, e) =>
                {
                    var alert = new UserCenter.ShowMsgControl(UserCenter.ShowMsgType.Confirm,
                    Language.StringByID(MyInternationalizationString.doyouwanttodelete),
                    Language.StringByID(MyInternationalizationString.confrim));
                    alert.Show();
                    alert.ConfirmClickEvent += () =>
                    {
                        Common.Logic.SoneLogicList.Remove(logic);
                        //logicRow.Parent.RemoveFromParent();
                        fLayout.RemoveFromParent();
                        Send.DelLogic(logic.LogicId);
                    };
 
                };
            }
 
 
        }
    }
}