黄学彪
2019-12-12 7e863a33397f317ffc3ffd9288496d0e4f16aa66
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
using System;
using System.Collections.Generic;
using Shared;
using Shared.Phone;
using Shared.R;
using ZigBee.Device;
 
namespace Shared.Phone.Device.Logic
{
    public class SelectedLogic : FrameLayout
    {
        public void Show (ZbGateway zbGateway)
        {
            UserView.HomePage.Instance.RemoveViewByTag ("Logic");
            Tag = "Logic";
 
 
            this.AddChidren (new Button {
                Height = Application.GetRealHeight (30),
                BackgroundColor = 0xFF1f1f1f,
            });
 
            var topFrameLayout = new FrameLayout {
                Height = Application.GetRealHeight (100),
                Y = Application.GetRealHeight (30),
                BackgroundColor = 0xFF1F1F1F,
            };
            AddChidren (topFrameLayout);
 
            var hdl = new Button {
                Width = Application.GetRealWidth (104),
                Height = Application.GetRealHeight (32),
                X = Application.GetRealWidth (530),
                Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = "Logo/Logo.png",
            };
            //if (superGateWay.Tag != "LogicEdit") {
            //    topFrameLayout.AddChidren (hdl);
            //}
 
            var titleName = new Button {
                //Text = "时间条件",
                TextID = MyInternationalizationString.Timecondition,
                TextSize = 17,
                IsBold = true,
            };
            topFrameLayout.AddChidren (titleName);
 
            var back = new Button {
                Width = Application.GetRealWidth (82),
                Height = Application.GetRealHeight (89),
                X = Application.GetRealWidth (10),
                Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = "MusicIcon/HomepageBack.png",
            };
            //if (logicedit.Tag == "true") {
            //    topFrameLayout.AddChidren (back);
            //}
            back.MouseDownEventHandler += (sender, e) => {
                RemoveFromParent ();
 
            };
 
            var middle = new VerticalScrolViewLayout ();
            middle.Y = topFrameLayout.Bottom;
            middle.Height = Application.GetRealHeight (1136 - 130 - 80);
            middle.BackgroundColor = 0xff2F2F2F;
            this.AddChidren (middle);
 
            var conditionRowLayout = new RowLayout {
                Height = Application.GetRealHeight (100),
                BackgroundColor = 0xff323232,
            };
            middle.AddChidren (conditionRowLayout);
            ///条件VerticalScrolViewLayout
            var inputVerticalScrolViewLayout = new VerticalScrolViewLayout {
                Height = 0,
                BackgroundColor = 0xffffffff,
            };
            middle.AddChidren (inputVerticalScrolViewLayout);
            conditionRowLayout.AddChidren (new Button {
                Width = Application.GetRealWidth (200),
                //Text = "条件",
                TextID = MyInternationalizationString.condition,
                TextSize = 16,
                TextAlignment = TextAlignment.CenterLeft,
                X = Application.GetRealWidth (40),
                Gravity = Gravity.CenterVertical,
            });
 
            var conditionadd = new Button {
                Width = Application.GetRealWidth (72),
                Height = Application.GetRealHeight (58),
                UnSelectedImagePath = "MusicIcon/add.png",
                X = Application.GetRealWidth (525),
                Gravity = Gravity.CenterVertical,
            };
            conditionRowLayout.AddChidren (conditionadd);
           
            #region -----显示逻辑条件-----
            //inputVerticalScrolViewLayout.Height = Application.GetRealHeight (100 * (logicedit.input.Count + logicedit.time.Count));
            //for (int i = 0; i < logicedit.time.Count; i++) {
            //    var s = logicedit.time [i];
            //    var timerowLayout = new RowLayout {
            //        Height = Application.GetRealHeight (100),
            //        BackgroundColor = 0xff505050,
            //    };
            //    inputVerticalScrolViewLayout.AddChidren (timerowLayout);
 
            //    ///显示时间
            //    var timevalue = new Button {
            //        X = Application.GetRealWidth (40),
            //        Width = Application.GetRealWidth (300),
            //        TextAlignment = TextAlignment.CenterLeft,
            //        Gravity = Gravity.CenterVertical,
            //        Text = s,
            //        //TextColor = 0xff121212,
            //    };
            //    timerowLayout.AddChidren (timevalue);
                               
            //}
 
            //foreach (var deviceinput in logicedit.input) {
            //    if (deviceinput.sid == null || deviceinput.sid == "") {
            //        continue;
            //    }
            //    var tempSid = deviceinput.sid;
            //    //判断SID是否有效的,如果不是有效的当前这个场景数据就不处理
            //    Convert.ToUInt64 (tempSid, 16);
            //    var sidUlong = Convert.ToUInt64 (tempSid, 16);
            //    ///1:设备;2:场景;3:逻辑;
            //    var type = (byte)((sidUlong >> 60) & 0xF);
            //    var statevalue = deviceinput.value.ToString ();
 
            //    var inputrowLayout = new RowLayout {
            //        Height = Application.GetRealHeight (100),
            //        BackgroundColor = 0xff505050,
            //    };
            //    inputVerticalScrolViewLayout.AddChidren (inputrowLayout);
 
            //    ///显示设备名称
            //    var devicename = new Button {
            //        X = Application.GetRealWidth (40),
            //        Width = Application.GetRealWidth (300),
            //        TextAlignment = TextAlignment.CenterLeft,
            //        Gravity = Gravity.CenterVertical,
            //        //TextColor = 0xff121212,
            //    };
            //    inputrowLayout.AddChidren (devicename);
 
            //    ///显示设备条件状态控件
            //    var devicestatus = new Button {
            //        Width = Application.GetRealWidth (130),
            //        Height = Application.GetRealHeight (100),
            //        Gravity = Gravity.CenterVertical,
            //        //TextColor = 0xff121212,
            //        X = Application.GetRealWidth (500),
            //    };
            //    inputrowLayout.AddChidren (devicestatus);
                              
            //    switch (type) {
            //    case 1: {
            //            var subnetId = (byte)((sidUlong >> 40) & 0xFF);
            //            var deviceId = (byte)((sidUlong >> 32) & 0xFF);
            //            var targetType = (byte)((sidUlong >> 24) & 0xFF);
            //            var property = (byte)((sidUlong >> 16) & 0xFF);
            //            var targetNumber = (uint)((sidUlong >> 0) & 0xFFFF);
            //            ///用来判断为条件,查找当前设备;
            //            var commonLoopID = subnetId + "_" + deviceId + "_" + targetNumber;
            //            var Type = Logic.devicetype (targetType, property);
 
            //            var commonDevice = superGateWay.Commons.Find ((obj) => obj.Type.ToString () == Type && obj.CommonLoopID == commonLoopID);
            //            if (commonDevice == null) {
            //                continue;
            //            }
            //            devicename.Text = commonDevice.Name;
 
            //            try {
            //                switch (commonDevice.Type) {
            //                case DeviceType.CurtainModel: {
            //                        if (statevalue == "1") {
            //                            devicestatus.Text = Language.StringByID (MyInternationalizationString.open);
            //                        } else {
            //                            devicestatus.Text = Language.StringByID (MyInternationalizationString.close);
            //                        }
            //                    }
            //                    break;
            //                case DeviceType.CurtainRoller: {
            //                        devicestatus.Text = statevalue + "%";
            //                    }
            //                    break;
            //                case DeviceType.LightDimming: {
            //                        devicestatus.Text = statevalue + "%";
            //                    }
            //                    break;
            //                case DeviceType.LightSwitch: {
            //                        if (statevalue == "1") {
            //                            devicestatus.Text = Language.StringByID (MyInternationalizationString.open);
            //                        } else {
            //                            devicestatus.Text = Language.StringByID (MyInternationalizationString.close);
            //                        }
 
            //                    }
            //                    break;
            //                case DeviceType.HVAC: {
 
            //                        if (property == 0) {
 
            //                            if (statevalue == "1") {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.open);
            //                            } else {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.close);
            //                            }
 
            //                        } else if (property == 1) {
            //                            if (statevalue == "0") {
            //                                //制冷
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.Cool);
            //                            } else if (statevalue == "1") {
            //                                //制热
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.Hot);
            //                            } else if (statevalue == "2") {
            //                                //通风
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.Ventila);
            //                            } else if (statevalue == "3") {
            //                                //自动
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.Auto);
            //                            } else if (statevalue == "4") {
            //                                //抽湿
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.Dehumidify);
            //                            }
            //                        } else if (property == 3) {
            //                            //空调温度
            //                            devicestatus.Text = statevalue + "%";
            //                        } else if (property == 5) {
            //                            //环境温度
            //                            devicestatus.Text = statevalue + "%";
            //                        }
            //                    }
            //                    break;
            //                case DeviceType.FoolHeat: {
            //                        if (property == 0) {
            //                            if (statevalue == "1") {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.open);
            //                            } else {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.close);
            //                            }
            //                        } else if (property == 2) {
            //                            devicestatus.Text = statevalue + "℃";
            //                        }
            //                    }
            //                    break;
            //                case DeviceType.FreshAir: {
            //                        if (property == 0) {
            //                            if (statevalue == "1") {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.open);
            //                            } else {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.close);
            //                            }
            //                        } else if (property == 1) {
            //                            if (statevalue == "0") {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.Smart);
            //                            } else if (statevalue == "1") {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.FreshAir);
            //                            } else if (statevalue == "2") {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.InternalCirculation);
            //                            } else if (statevalue == "3") {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.ConstantTemp);
            //                            }
            //                        }
            //                    }
            //                    break;
            //                case DeviceType.MechanicalSwitch: {
            //                        if (property == 0) {
            //                            if (statevalue == "1") {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.open);
            //                            } else {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.close);
            //                            }
            //                        }
            //                    }
            //                    break;
            //                case DeviceType.AutomaticSwitch: {
            //                        if (property == 1) {
            //                            if (statevalue == "1") {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.singleclick);
            //                            } else if (statevalue == "2") {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.longpress);
            //                            } else if (statevalue == "3") {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.longpressrelease);
            //                            } else if (statevalue == "4") {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.doubleclick);
            //                            }
            //                        }
            //                    }
            //                    break;
            //                case DeviceType.DryContact: {
            //                        if (property == 0) {
            //                            if (statevalue == "1") {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.open);
            //                            } else {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.close);
            //                            }
            //                        }
            //                    }
            //                    break;
            //                case DeviceType.MusicModel: {
            //                        if (property == 0) {
            //                            if (statevalue == "1") {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.play);
            //                            } else if (statevalue == "2") {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.pause);
            //                            }
            //                        } else if (property == 1) {
            //                            //devicestatus.Text = Language.StringByID (MyInternationalizationString.close);
            //                            devicestatus.Text = statevalue + "%";
            //                        }
            //                    }
            //                    break;
            //                case DeviceType.DoorLock: {
            //                        if (property == 0) {
            //                            if (statevalue == "1") {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.open);
            //                            } else {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.close);
            //                            }
            //                        } else if (property == 1) {
            //                            if (statevalue == "1") {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.low);
            //                            } else {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.normal);
            //                            }
            //                        } else if (property == 2) {
            //                            if (statevalue == "1") {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.trigger);
            //                            } else {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.nontrigger);
            //                            }
            //                        }
            //                    }
            //                    break;
            //                case DeviceType.DoorLockID: {
            //                        if (property == 0) {
            //                            if (statevalue == "1") {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.trigger);
            //                            } else {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.nontrigger);
            //                            }
            //                        }
            //                    }
            //                    break;
            //                case DeviceType.Sensor: {
            //                        if (property == 0) {
            //                            devicestatus.Text = statevalue + "℃";
            //                        } else if (property == 1) {
            //                            devicestatus.Text = statevalue + "%";
            //                        } else if (property == 5) {
            //                            int intvalue = 90;
            //                            intvalue = int.Parse (statevalue);
            //                            if (0 <= intvalue && intvalue < 60) {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.difference);
            //                            } else if (60 <= intvalue && intvalue < 75) {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.middle);
            //                            } else if (75 <= intvalue && intvalue <= 100) {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.excellent);
            //                            }
            //                        } else if (property == 10) {
            //                            int intvalue = 90;
            //                            intvalue = int.Parse (statevalue);
            //                            if (0 <= intvalue && intvalue < 60) {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.difference);
            //                            } else if (60 <= intvalue && intvalue < 75) {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.middle);
            //                            } else if (75 <= intvalue && intvalue <= 100) {
            //                                devicestatus.Text = Language.StringByID (MyInternationalizationString.excellent);
            //                            }
            //                        }
            //                    }
            //                    break;
            //                }
            //            } catch { }
                       
            //        }
            //        break;
            //    case 3: {
            //            var logic = superGateWay.Logics.Find ((obj) => obj.sid == tempSid);
            //            if (logic == null) {
            //                continue;
            //            }
            //            devicename.Text = logic.name;
            //            if (statevalue == "1") {
            //                devicestatus.Text = Language.StringByID (MyInternationalizationString.open1);
            //            } else {
            //                devicestatus.Text = Language.StringByID (MyInternationalizationString.disable);
            //            }
 
            //          }
            //        break;
 
            //    }
 
            //}
            #endregion
 
            var targetRowLayout = new RowLayout {
                Height = Application.GetRealHeight (100),
                BackgroundColor = 0xff323232,
            };
            middle.AddChidren (targetRowLayout);
            ///目标targetVerticalScrolViewLayout
            var targetVerticalScrolViewLayout = new VerticalScrolViewLayout {
                Height = 0,
                BackgroundColor = 0xffffffff,
            };
            middle.AddChidren (targetVerticalScrolViewLayout);
 
            var btntargettitle = new Button {
                // Text = "执行目标",
                TextSize = 16,
                TextAlignment = TextAlignment.CenterLeft,
                X = Application.GetRealWidth (40),
                Gravity = Gravity.CenterVertical,
                TextID = MyInternationalizationString.Implementationgoals,
            };
            targetRowLayout.AddChidren (btntargettitle);
 
            var btntargetadd = new Button {
                Width = Application.GetRealWidth (72),
                Height = Application.GetRealHeight (58),
                UnSelectedImagePath = "MusicIcon/add.png",
                X = Application.GetRealWidth (525),
                Gravity = Gravity.CenterVertical,
            };
            targetRowLayout.AddChidren (btntargetadd);
           
            #region  ----显示执行目标----
            //foreach (var deviceoutput in logicedit.output) {
            //    targetVerticalScrolViewLayout.Height = Application.GetRealHeight (100 * deviceoutput.objects.Count);
            //    foreach (var device in deviceoutput.objects) {
            //        if (!device.ContainsKey ("sid")) {
            //            continue;
            //        }
            //        var tempSid = device ["sid"]?.ToString ();
            //        if (tempSid == "") {
            //            continue;
            //        }
            //        //判断SID是否有效的,如果不是有效的当前这个场景数据就不处理
            //        Convert.ToUInt64 (tempSid, 16);
            //        var sidUlong = Convert.ToUInt64 (tempSid, 16);
            //        ///1:设备;2:场景;3:逻辑;
            //        var type = (byte)((sidUlong >> 60) & 0xF);
            //        string delay = "";
            //        string statevalue = "";
            //        if (device.ContainsKey ("value")) {
            //            statevalue = device ["value"]?.ToString ();
            //        }
            //        if (device.ContainsKey ("delay")) {
            //            delay = device ["delay"]?.ToString ();
            //        }
 
            //        var inputrowLayout = new RowLayout {
            //            Height = Application.GetRealHeight (100),
            //            BackgroundColor = 0xff505050,
            //        };
            //        targetVerticalScrolViewLayout.AddChidren (inputrowLayout);
 
            //        var devicename = new Button {
            //            // Text = device.Name,
            //            X = Application.GetRealWidth (40),
            //            Width = Application.GetRealWidth (300),
            //            TextAlignment = TextAlignment.CenterLeft,
            //            Gravity = Gravity.CenterVertical,
            //            //TextColor = 0xff121212,
            //        };
            //        inputrowLayout.AddChidren (devicename);
 
            //        var btndelay = new Button {
            //            Width = Application.GetRealWidth (150),
            //            Height = Application.GetRealHeight (50),
            //            X = Application.GetRealWidth (300),
            //            Y = Application.GetRealHeight (25),
            //            TextAlignment = TextAlignment.Center,
            //            TextColor = 0xffcccccc,
            //        };
            //        inputrowLayout.AddChidren (btndelay);
 
                   
 
 
            //        if (delay != "" && delay != "0") {
            //            var l = int.Parse (delay) / 10;
            //            btndelay.Text = l.ToString () + "s";
            //        }
 
            //        ///显示设备状态控件
            //        var devicestatus = new Button {
            //            Width = Application.GetRealWidth (130),
            //            Height = Application.GetRealHeight (100),
            //            Gravity = Gravity.CenterVertical,
            //            //TextColor = 0xff121212,
            //            X = Application.GetRealWidth (500),
            //        };
            //        inputrowLayout.AddChidren (devicestatus);
 
                  
            //    }
 
            //}
            #endregion
 
            var cyclerowlayout = new RowLayout {
                Height = Application.GetRealHeight (100),
                BackgroundColor = 0xff323232,
            };
            middle.AddChidren (cyclerowlayout);
            ///执行周期
            var btncycle = new Button {
                TextSize = 16,
                //Text = "执行周期",
                TextAlignment = TextAlignment.CenterLeft,
                X = Application.GetRealWidth (40),
                Width = Application.GetRealWidth (210),
                Gravity = Gravity.CenterVertical,
                TextID = MyInternationalizationString.cycle
            };
            cyclerowlayout.AddChidren (btncycle);
            ///显示周期时间
            var btndisplaycycle = new Button {
                TextAlignment = TextAlignment.CenterLeft,
                X = Application.GetRealWidth (250),
                Width = Application.GetRealWidth (300),
                Gravity = Gravity.CenterVertical,
            };
            cyclerowlayout.AddChidren (btndisplaycycle);
            ///更新周期的方法
 
            var btncycleback = new Button {
                Width = Application.GetRealWidth (87),
                Height = Application.GetRealHeight (100),
                UnSelectedImagePath = "MusicIcon/Next.png",
                SelectedImagePath = "MusicIcon/NextSelecte.png",
                X = Application.GetRealWidth (525),//550
            };
            cyclerowlayout.AddChidren (btncycleback);
 
            var btncomplete = new Button {
                Height = Application.GetRealHeight (80),
                Y = middle.Bottom,
                TextID = MyInternationalizationString.complete,
                TextSize = 16,
                BackgroundColor = 0xff1f1f1f,
            };
            AddChidren (btncomplete);
            btncomplete.MouseUpEventHandler += (sender, e) => {
                var logicCommunalPage = new LogicCommunalPage ();
                UserView.HomePage.Instance.AddChidren (logicCommunalPage);
                logicCommunalPage.Show (() => { });
 
            };
           
        }
 
       
    }
}