黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
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
using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using Shared;
using Shared.Common;
using Shared.Phone;
using Shared.Phone.Device.Logic.LogicView;
using Shared.R;
using ZigBee.Device;
 
namespace Shared.Phone.Device.Logic
{
    public class OneLogic : FrameLayout
    {
 
        public OneLogic()
        {
            UserView.HomePage.Instance.RemoveViewByTag("Logic");
            Tag = "Logic";
        }
        /// <summary>
        /// S-one门锁特殊界面
        /// </summary>
        /// <param name="Yes"></param>
        public  void Show(bool Yes)
        {
            #region  View布局代码
            UserView.HomePage.Instance.ScrollEnabled = false;
            TopView view = new TopView();
            this.AddChidren(view.TopRowView());
 
            if (Yes)
            {
                view.toptitleNameBtn.Text = Language.StringByID(MyInternationalizationString.look);
            }
            else
            {
                if (Common.Logic.CurrentLogic.LogicId != 0)
                {
                    view.toptitleNameBtn.Text = Language.StringByID(MyInternationalizationString.editautomation);
                }
                else
                {
                    view.toptitleNameBtn.Text = Language.StringByID(MyInternationalizationString.newautomation);
                }
            }
            
            view.clickBtn.MouseDownEventHandler += (sender, e) =>
            {
                UserView.HomePage.Instance.ScrollEnabled = true;//恢复左滑
                RemoveFromParent();
            };
            var middle = new VerticalScrolViewLayout
            {
                Y = view.topRowLayout.Bottom,
                Height = Application.GetRealHeight(Method.H - 184 - 180),
                BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor,
            };
            this.AddChidren(middle);
            var saveBtn = new SaveView();
            saveBtn.frameLayout.Y = middle.Bottom;
            saveBtn.frameLayout.Height = Application.GetRealHeight(180);
            this.AddChidren(saveBtn.Show());
            #endregion
 
            #region -----自动化名称 设置名称-----
            var logicnamefl = new FrameLayout
            {
                Height = Application.GetRealHeight(130),
                BackgroundColor = ZigbeeColor.Current.LogicBackgroundColor,
            };
            middle.AddChidren(logicnamefl);
 
            var text = new Button
            {
                Width = Application.GetRealWidth(300),
                Height = Application.GetRealHeight(60),
                X = Application.GetRealWidth(58),
                TextAlignment = TextAlignment.CenterLeft,
                //Text = "自动化名称",
                TextID = MyInternationalizationString.automationname,
                TextColor = ZigbeeColor.Current.LogicTextBlackColor,
                Y = Application.GetRealHeight(35),
                TextSize = 15,
            };
            logicnamefl.AddChidren(text);
 
            var logicTextBox = new EditText
            {
                Y = Application.GetRealHeight(35),
                Width = Application.GetRealWidth(1080 - 58 - 300),
                Height = Application.GetRealHeight(60),
                X = text.Right,
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = ZigbeeColor.Current.LogicBtnCancelColor,
                TextSize = 14,
                Text = Common.Logic.CurrentLogic.LogicName,
                //TextID=MyInternationalizationString.automation1,
            };
            logicnamefl.AddChidren(logicTextBox);
            if (Yes)
            {
                //S-one门锁特殊,不能再次编辑;
                logicTextBox.Enable = false;
            }
            var fraline = new FrameLayout
            {
                Height = Application.GetRealHeight(30),
            };
            middle.AddChidren(fraline);
            #endregion
 
            #region -----显示逻辑条件-----
            Addview addconditionview = new Addview();
            addconditionview.iconBtn.Visible = false;
            addconditionview.titleBtn.TextID = MyInternationalizationString.ifcondition;
            middle.AddChidren(addconditionview.AddDeviceView());
 
            ///添加条件的点击事件
            for (int i = 0; i < Common.Logic.CurrentLogic.Conditions.Count; i++)
            {
                SelectedDeviceView selecteddevice = new SelectedDeviceView();
                selecteddevice.Show(middle);
                if (!Yes)
                {
                    //S-one门锁特殊,不能再次编辑;
                    selecteddevice.stateRow.AddRightView(selecteddevice.edit);
                }
                var Type = int.Parse(Common.Logic.CurrentLogic.Conditions[i]["Type"]);
                var conditions = Common.Logic.CurrentLogic.Conditions[i];
                switch (Type)
                {
                    case 0:
                        {
 
                            //"0正常时间点","1日出时间","2日落时间","3正午时间"
                            switch (int.Parse(conditions["DateType"]))
                            {
                                case 0:
                                    {
                                        selecteddevice.ordinaryBtn.Text = Language.StringByID(MyInternationalizationString.immediateexecution);
                                        selecteddevice.iconBtn.UnSelectedImagePath = "ZigeeLogic/timepoint.png";
                                        string s = "";
                                        s = conditions["StartMin"].Length < 2 ? "0" + conditions["StartMin"] : conditions["StartMin"];
                                        selecteddevice.selecetddevicestateBtn.Text= conditions["StartHour"] + ":" + s;
                                    }
                                    break;
                            }
 
                        }
                        break;
                }
                if (Yes)
                {
                    //改变字体颜色;
                    selecteddevice.ordinaryBtn.TextColor = ZigbeeColor.Current.LogicBtnCancelColor;
                    selecteddevice.selecetddevicestateBtn.TextColor = ZigbeeColor.Current.LogicBtnCancelColor;
                }
                ///编辑
                selecteddevice.edit.MouseUpEventHandler += (sender, e) =>
                {
                    if (Type == 0)
                    {
                        var oneTimePoint = new OneTimePoint();
                        UserView.HomePage.Instance.AddChidren(oneTimePoint);
                        UserView.HomePage.Instance.PageIndex += 1;
                        oneTimePoint.Show((timeString) =>
                        {
                            if (!string.IsNullOrEmpty(timeString))
                            {
                                //编辑完回来先更新时间
                                selecteddevice.selecetddevicestateBtn.Text = timeString;
                            }
                        });
                    }
                };
 
            }
            #endregion
 
            #region  ----显示执行目标----
            Addview addactionview = new Addview();
            addactionview.iconBtn.Visible = false;
            addactionview.titleBtn.TextID = MyInternationalizationString.execute;
            middle.AddChidren(addactionview.AddDeviceView());
 
            for (int i = 0; i < Common.Logic.CurrentLogic.Actions.Count; i++)
            {
                SelectedDeviceView actiondevice = new SelectedDeviceView();
                actiondevice.Show(middle);
                if (!Yes)
                {
                    //S-one门锁特殊,不能再次编辑;
                    actiondevice.stateRow.AddRightView(actiondevice.edit);
                }
                var linkType = int.Parse(Common.Logic.CurrentLogic.Actions[i]["LinkType"].ToString());
                var actions = Common.Logic.CurrentLogic.Actions[i];
                switch (linkType)
                {
                    case 8:
                        {
                            //S-one门锁特殊(Mac是唯一的识别)
                            ///如果不这样查找,分类-自动化进来查看会存在问题
                            var deviceinof = Common.Logic.LogicDviceList.Find((obj) => { return  obj.DeviceAddr == actions["DeviceAddr"].ToString(); });
                            if (deviceinof == null)
                            {
                                deviceinof = new CommonDevice();
                            }
                            actiondevice.deviceNameBtn.Text = HdlDeviceCommonLogic.Current.GetDeviceEpointName(deviceinof);
                            actiondevice.deviceNameBtn.Visible = true;
                            actiondevice.regionNameBtn.Visible = true;
                            Method.RoomNmae(actiondevice.regionNameBtn, deviceinof);
 
                            if (Yes) {
                                //改变字体颜色;
                                actiondevice.deviceNameBtn.TextColor = ZigbeeColor.Current.LogicBtnCancelColor;
                                actiondevice.regionNameBtn.TextColor = ZigbeeColor.Current.LogicBtnCancelColor;
                                actiondevice.selecetddevicestateBtn.TextColor = ZigbeeColor.Current.LogicBtnCancelColor;
                            }
                            switch (deviceinof.Type)
                            {
                                case DeviceType.DoorLock:
                                    {
                                        //门锁特殊
                                        actiondevice.iconBtn.UnSelectedImagePath = "ZigeeLogic/doorlock.png";
                                        if (actions["PassData"].ToString() == "055704010112")
                                        {
                                            actiondevice.selecetddevicestateBtn.Text = Language.StringByID(MyInternationalizationString.logicopen);
                                        }
                                        else
                                        {
                                            actiondevice.selecetddevicestateBtn.Text = Language.StringByID(MyInternationalizationString.logicclose);
                                        }
                                    }
                                    break;
                            }
 
                        }
                        break;
 
                }
                ///编辑
                actiondevice.edit.MouseUpEventHandler += (sender, e) =>
                {
                    switch (linkType)
                    {
                        case 8:
                            {
                                //S-one门锁特殊(Mac是唯一的识别)
                                ///如果不这样查找,分类-自动化进来查看会存在问题
                                var deviceinof = Common.Logic.LogicDviceList.Find((obj) => { return obj.DeviceAddr == actions["DeviceAddr"].ToString(); });
                                if (deviceinof == null)
                                {
                                    deviceinof = new CommonDevice();
                                }
                                DevcieView(deviceinof, actiondevice.selecetddevicestateBtn);
                            };
                            break;
 
 
                    }
                };
 
            }
            #endregion
 
            #region -----每天 设置周期-----
 
            var fraline1 = new FrameLayout
            {
                Height = Application.GetRealHeight(30),
            };
            middle.AddChidren(fraline1);
 
            Addview weekview = new Addview();
            weekview.iconBtn.Visible = true;
            weekview.iconBtn.UnSelectedImagePath = "ZigeeLogic/next.png";
            weekview.titleBtn.TextID = MyInternationalizationString.setupcycle;
            middle.AddChidren(weekview.AddDeviceView());
            var weekBtn = new Button
            {
                Width = Application.GetRealWidth(595),
                Height = Application.GetRealHeight(60),
                TextAlignment = TextAlignment.CenterRight,
                //Text = "每天",
                TextColor = ZigbeeColor.Current.LogicBtnCancelColor,
                TextID = MyInternationalizationString.everyday,
                Y = Application.GetRealHeight(35 + 30),
                X = weekview.titleBtn.Right,
                TextSize = 14,
            };
            weekview.frameLayout.AddChidren(weekBtn);
            Method.UpdateWeek(weekBtn, Common.Logic.CurrentLogic);
            EventHandler<MouseEventArgs> cycleclick = (sender, e) =>
            {
                if (Yes) {
                    //S-one门锁特殊,不能再次编辑;
                    return;
                }
                var cycle = new Cycle(() => { Method.UpdateWeek(weekBtn, Common.Logic.CurrentLogic); });
                UserView.HomePage.Instance.AddChidren(cycle);
                UserView.HomePage.Instance.PageIndex += 1;
                cycle.Show();
            };
            weekBtn.MouseUpEventHandler += cycleclick;
            weekview.clickBtn.MouseUpEventHandler += cycleclick;
            if (Yes)
            {
                //改变字体颜色;
                weekBtn.TextColor = ZigbeeColor.Current.LogicBtnCancelColor;
                logicTextBox.TextColor = ZigbeeColor.Current.LogicBtnCancelColor;
            }
            #endregion
 
            #region  ----推送设置----
            Method.Push(middle);
            #endregion
 
            saveBtn.clickviewBtn.MouseUpEventHandler += (sender, e) =>
            {
                if (Yes)
                {
                    //S-one门锁特殊,不能再次编辑;
                    RemoveFromParent();
                    return;
                }
                var name = logicTextBox.Text.Trim();
                Method.SaveLogic(IfString._SoneLogic, name, IfString.Tag, Common.Logic.CurrentLogic);
            };
 
        }
        /// <summary>
        /// 选中该作为条件或者目标的视图方法
        /// </summary>
        /// <param name="common">Common.</param>
         void DevcieView( CommonDevice common,Button button)
        {
            #region  -------界面布局部分
            //不让当前界面滑动
            UserView.HomePage.Instance.ScrollEnabled = false;
            var flMain = new FrameLayout { BackgroundColor = ZigbeeColor.Current.LogicViewBackgroundColor };
            this.AddChidren(flMain);
            CompleteView completeView = new CompleteView();
            flMain.AddChidren(completeView.Show(1));
            // completeView.Btntitle.Text =HdlDeviceCommonLogic.Current.GetDeviceEpointName(common);
            completeView.Btntitle.TextID = MyInternationalizationString.openmode;
            EventHandler<MouseEventArgs> clickcancel = (sender, e) =>
            {
                flMain.RemoveFromParent();
            };
            flMain.MouseUpEventHandler += clickcancel;
            completeView.Btncancel.MouseUpEventHandler += clickcancel;
 
            mFunView openView = new mFunView();
            openView.frameLayout.Y = Application.GetRealHeight(140 + 20);
            completeView.Show(2).AddChidren(openView.Show());
            openView.titleBtn.TextID = MyInternationalizationString.logicopen;
 
            mFunView closeView = new mFunView();
            closeView.frameLayout.Y = Application.GetRealHeight(140 + 20 + 160);
             closeView.frameLayout.Y = openView.frameLayout.Bottom;
            completeView.Show(2).AddChidren(closeView.Show());
            closeView.titleBtn.TextID = MyInternationalizationString.logicclose;
            closeView.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicBackgroundColor;
            #endregion
 
 
            Dictionary<string, object> actionsInfo = new Dictionary<string, object>();
            actionsInfo.Add("LinkType", 8);
            actionsInfo.Add("DeviceAddr", common.DeviceAddr);
            actionsInfo.Add("Epoint","200");
            string SelectedDeviceStatus = "";
            switch (common.Type)
            {
                case DeviceType.DoorLock:
                    {
                        openView.clickviewBtn.MouseUpEventHandler += (sender, e) =>
                        {
                            openView.selectedIconBtn.Visible = true;
                            closeView.selectedIconBtn.Visible = false;
                            openView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnSelectedColor;
                            closeView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnNotSelectedColor;
                            SelectedDeviceStatus = Language.StringByID(MyInternationalizationString.logicopen);
                            if (actionsInfo.ContainsKey("PassData"))
                            {
                                actionsInfo.Remove("PassData");
                            }
                            actionsInfo.Add("PassData", "055704010112");//门锁常开
                        };
                        ///点击取消事件
                        closeView.clickviewBtn.MouseUpEventHandler += (sender, e) =>
                        {
                            openView.selectedIconBtn.Visible = false;
                            closeView.selectedIconBtn.Visible = true;
                            openView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnNotSelectedColor;
                            closeView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnSelectedColor;
                            SelectedDeviceStatus = Language.StringByID(MyInternationalizationString.logicclose);
                            if (actionsInfo.ContainsKey("PassData"))
                            {
                                actionsInfo.Remove("PassData");
                            }
                            actionsInfo.Add("PassData", "055704010113");//门锁常关
 
                        };
 
                        if (button.Text == Language.StringByID(MyInternationalizationString.logicopen))
                        {
                            //开启
                            SelectedDeviceStatus = Language.StringByID(MyInternationalizationString.logicopen);
                            openView.selectedIconBtn.Visible = true;
                            closeView.selectedIconBtn.Visible = false;
                            openView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnSelectedColor;
                            closeView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnNotSelectedColor;
 
                        }
                        else {
                            //关闭
                            SelectedDeviceStatus = Language.StringByID(MyInternationalizationString.logicclose);
                            openView.selectedIconBtn.Visible = false;
                            closeView.selectedIconBtn.Visible = true;
                            openView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnNotSelectedColor;
                            closeView.titleBtn.TextColor = ZigbeeColor.Current.LogicBtnSelectedColor;
                        }
 
                    }
                    break;
 
            }
             
            
            completeView.Btncomplete.MouseUpEventHandler += (sender, e) =>
            {
                if (!string.IsNullOrEmpty(SelectedDeviceStatus))
                {
                    LogicIfon.AddDoorLockActions(common, actionsInfo);
                    button.Text = SelectedDeviceStatus;
                }
            
                flMain.RemoveFromParent();
 
            };
        }
    }
}