黄学彪
2020-12-17 6c0c799c1f5da2d215ec8d9df9b92b3d1948dc14
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
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
using System;
using Shared;
using System.Collections.Generic;
 
 
namespace HDL_ON.UI.UI2.Intelligence.Automation
{
    public class AddLogic : FrameLayout
    {
        public AddLogic()
        {
            Tag = "Logic";
        }
 
        public void Show()
        {
            #region  界面布局
            this.BackgroundColor = CSS.CSS_Color.viewMiddle;
            LogicView.TopView topView = new LogicView.TopView();
            topView.setBtn.Visible = true;
            this.AddChidren(topView.FLayoutView());
            topView.clickBackBtn.MouseUpEventHandler += (e, sen) =>
             {
                 RemoveFromParent();
             };
            if (string.IsNullOrEmpty(Logic.currlogic.userLogicId))
            {
                topView.topNameBtn.TextID = StringId.newAutomation;
                topView.setBtn.Visible = false;
                topView.clickSetBtn.Visible = false;
            }
            else
            {
                topView.topNameBtn.TextID = StringId.editAutomation;
                topView.setBtn.Visible = true;
                topView.clickSetBtn.Visible = true;
            }
 
 
            VerticalScrolViewLayout viewLayout = new VerticalScrolViewLayout
            {
                Y = Application.GetRealHeight(64),
                Width = Application.GetRealWidth(LogicView.TextSize.view375),
                Height = Application.GetRealHeight(LogicView.TextSize.view667 - 64 - 76),
                BackgroundColor = CSS.CSS_Color.viewMiddle,
            };
            this.AddChidren(viewLayout);
            #region  条件
            ///如果的View
            LogicView.AddOutputInputTextView addInputTextView = new LogicView.AddOutputInputTextView();
            addInputTextView.btnIf.TextID = StringId.ifCondition;
            viewLayout.AddChidren(addInputTextView.FLayoutView(46, 12));
            ///满足以下条件的View
            LogicView.LogicTypeTitleView titleCondition = new LogicView.LogicTypeTitleView();
            titleCondition.frameLayout.SetCornerWithSameRadius(Application.GetRealHeight(12), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight);
            titleCondition.btnText.TextID = StringId.andCondition;
            viewLayout.AddChidren(titleCondition.FLayoutView());
 
            if (Logic.currlogic.relation == "and")
            {
                titleCondition.btnText.Text = Language.StringByID(StringId.andCondition);
            }
            else
            {
                titleCondition.btnText.Text = Language.StringByID(StringId.orCondition);
 
            }
 
            // 条件处理方法
            InpOrOutLogicMethod.InputCondition(this, viewLayout);
            ///添加图标的View
            LogicView.LogicAddView addInputIcon = new LogicView.LogicAddView();
            addInputIcon.frameLayout.SetCornerWithSameRadius(Application.GetRealHeight(12), HDLUtils.RectCornerBottomLeft | HDLUtils.RectCornerBottomRight);
            viewLayout.AddChidren(addInputIcon.FLayoutView());
            #endregion
 
            #region  目标
            ///就执行View
            LogicView.AddOutputInputTextView addOutpuTextView = new LogicView.AddOutputInputTextView();
            addOutpuTextView.btnIf.TextID = StringId.isExecuted;
            viewLayout.AddChidren(addOutpuTextView.FLayoutView(54, 20));
            ///以下动作View        
            LogicView.LogicTypeTitleView titleOutpu = new LogicView.LogicTypeTitleView();
            titleOutpu.frameLayout.SetCornerWithSameRadius(Application.GetRealHeight(12), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight);
            titleOutpu.btnText.TextID = StringId.theFollowingActions;
            titleOutpu.btnNextIcon.Visible = false;
            viewLayout.AddChidren(titleOutpu.FLayoutView());
            //目标处理方法
            InpOrOutLogicMethod.OutputTarget(this, viewLayout);
            ///添加图标的View
            LogicView.LogicAddView addOutputIcon = new LogicView.LogicAddView();
            addOutputIcon.frameLayout.SetCornerWithSameRadius(Application.GetRealHeight(12), HDLUtils.RectCornerBottomLeft | HDLUtils.RectCornerBottomRight);
            viewLayout.AddChidren(addOutputIcon.FLayoutView());
 
            #endregion
 
            #region  循环方式
            ///循环方式iew
            LogicView.AddOutputInputTextView cyclicTextView = new LogicView.AddOutputInputTextView();
            cyclicTextView.btnIf.TextID = StringId.cyclic;
            viewLayout.AddChidren(cyclicTextView.FLayoutView(54, 20));
            ///选择周期类型View        
            LogicView.LogicTypeTitleView cyclicTitle = new LogicView.LogicTypeTitleView();
            cyclicTitle.frameLayout.Height = Application.GetRealHeight(50);
            cyclicTitle.frameLayout.Radius = (uint)Application.GetRealHeight(12);
            cyclicTitle.btnText.Text = MainView.GetWeekText(Logic.currlogic);
            viewLayout.AddChidren(cyclicTitle.FLayoutView());
 
            #endregion
 
            #region  执行推送 发送通知
            ///上下间隔12像素
            viewLayout.AddChidren(new FrameLayout { Height = Application.GetRealHeight(12) });
            /////执行推送iew
            //LogicView.LogicTypeTitleView push = new LogicView.LogicTypeTitleView();
            //push.frameLayout.Height = Application.GetRealHeight(50);
            //push.frameLayout.SetCornerWithSameRadius(Application.GetRealHeight(12), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight);
            //push.btnText.TextID = StringId.push;
            //push.btnNextIcon.Width = Application.GetMinRealAverage(36);
            //push.btnNextIcon.Height = Application.GetMinRealAverage(36);
            //push.btnNextIcon.X = Application.GetRealWidth(305);
            //push.btnNextIcon.UnSelectedImagePath = "LogicIcon/off.png";
            //push.btnNextIcon.SelectedImagePath = "LogicIcon/on.png";
            //viewLayout.AddChidren(push.FLayoutView());
            /////发送通知View        
            //LogicView.LogicTypeTitleView notification = new LogicView.LogicTypeTitleView();
            //notification.frameLayout.SetCornerWithSameRadius(Application.GetRealHeight(12), HDLUtils.RectCornerBottomLeft | HDLUtils.RectCornerBottomRight);
            //notification.btnText.TextID = StringId.notification;
            //viewLayout.AddChidren(notification.FLayoutView());
            /////上下间隔62像素
            //viewLayout.AddChidren(new FrameLayout { Height = Application.GetRealHeight(62) });
            #endregion
 
            #region  保存
            ///保存View
            LogicView.SaveView saveView = new LogicView.SaveView();
            saveView.frameLayout.SetCornerWithSameRadius(Application.GetRealHeight(24), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight);
            this.AddChidren(saveView.FLayoutView());
 
            #endregion
            #endregion
 
            #region  界面各种点击事件
            ///设置图标点击事件
            topView.clickSetBtn.MouseUpEventHandler += (sender, e) =>
            {
                Set set = new Set();
                MainPage.BasePageView.AddChidren(set);
                set.Show();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
 
            };
            ///或和与点击事件
            titleCondition.btnClick.MouseUpEventHandler += (sender, e) =>
            {
                FrameLayout fLayout = new FrameLayout
                {
                    BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
                };
                this.AddChidren(fLayout);
                AndOrMethod(fLayout, titleCondition.btnText);
            };
            ///条件点击事件
            addInputIcon.btnClick.MouseUpEventHandler += (sen, e) =>
            {
                var addInputType = new AddInputType();
                MainPage.BasePageView.AddChidren(addInputType);
                addInputType.Show();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
            ///目标点击事件
            addOutputIcon.btnClick.MouseUpEventHandler += (sen, e) =>
            {
                var addTarget = new AddTarget();
                MainPage.BasePageView.AddChidren(addTarget);
                addTarget.Show();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
            ///循环方式点击事件
            cyclicTitle.btnClick.MouseUpEventHandler += (sender, e) =>
            {
                DateMethod(cyclicTitle.btnText);
            };
            ///保存点击事件
            saveView.btnClick.MouseUpEventHandler += (sender, e) =>
            {
                Loading loading = new Loading();
                this.AddChidren(loading);
                HDL_ON.DAL.Server.ResponsePackNew responsePackNew = null;
                if (string.IsNullOrEmpty(Logic.currlogic.userLogicId))
                {
                    List<string> list = new List<string>();
                    foreach (var logic in Logic.LogicList)
                    {
                        list.Add(logic.name);
                    }
                    new LogicView.TipPopView().InputBox(StringId.editName, Logic.currlogic.name, StringId.nameNull, StringId.NameAlreadyExists, list, (logicName) =>
                    {
                        Logic.currlogic.name = logicName;
                        Logic.currlogic.sid = LogicMethod.NewSid();
                        loading.Start();
                        new System.Threading.Thread(() =>
                        {
 
                            try
                            {
                                //发送新加逻辑命令;
                                responsePackNew = Send.AddLogic(Logic.currlogic);
 
                            }
                            catch { }
                            finally
                            {
                                Application.RunOnMainThread(() =>
                                {
                                    loading.Hide();
                                    if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                                    {
 
 
                                        //获取逻辑详细返回是一个数组(object类型转换为数组);
                                        var jArray = Newtonsoft.Json.Linq.JArray.Parse(responsePackNew.Data.ToString());
                                        for (int a = 0; a < jArray.Count; a++)
                                        {
                                            var jay = jArray[a];
                                            //数据返序列化为Logic对象
                                            var str = Newtonsoft.Json.JsonConvert.SerializeObject(jay);
                                            var logic = Newtonsoft.Json.JsonConvert.DeserializeObject<Logic>(str);
                                            if (logic.userLogicId!="")
                                            {
                                                //更新云端唯一自动化id;
                                                Logic.currlogic.userLogicId = logic.userLogicId;
                                            }
                                            else
                                            {
                                                //自己看的所以不需要支持中英文
                                                new LogicView.TipPopView().FlashingBox("没有返回云端唯一自动化id");
                                            }
 
                                        }
 
                                        Logic.LogicList.Add(Logic.currlogic);
                                        LogicMethod.RemoveAllView();
                                        MainView.MainShow();
                                    }
                                    else
                                    {
                                        new LogicView.TipPopView().FlashingBox(Language.StringByID(StringId.saveFail));
                                    }
                                });
                            }
 
                        })
                        { IsBackground = true }.Start();
 
                    });
 
                }
                else
                {
                    loading.Start();
                    new System.Threading.Thread(() =>
                    {
 
                        try
                        {
                            //发送修改逻辑命令;
                            responsePackNew = Send.updateLogic(Logic.currlogic);
 
                        }
                        catch { }
                        finally
                        {
                            Application.RunOnMainThread(() =>
                            {
                                loading.Hide();
                                if (responsePackNew != null && responsePackNew.Code == "0")
                                {
                                    LogicMethod.RemoveAllView();
                                    MainView.MainShow();
                                }
                                else
                                {
                                    new LogicView.TipPopView().FlashingBox(Language.StringByID(StringId.saveFail));
                                }
                            });
                        }
 
 
 
                    })
                    { IsBackground = true }.Start();
 
                }
 
            };
            #endregion
        }
        /// <summary>
        /// 循环方式(每天,每月。。)
        /// </summary>
        /// <param name="button">显示文本</param>
        public void DateMethod(Button button)
        {
            FrameLayout fLayout = new FrameLayout
            {
                BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
            };
            this.AddChidren(fLayout);
            LogicView.DateView dateView = new LogicView.DateView();
            dateView.btnTitle.TextID = StringId.cyclic;
            dateView.FLayoutView(fLayout, 4);
            dateView.btnCancel.MouseUpEventHandler += (sender2, e2) =>
            {
                //移除fLayout界面
                fLayout.RemoveFromParent();
            };
            //定义一个局部变量记录选中文本状态
            string weekName = "";
            //定义一个局部Btn用来记录选中Btn;
            var selecetdBtn = new Button() { Text = "" };
            for (int i = 0; i < 4; i++)
            {
                LogicView.SelectTypeView dateTypeView = new LogicView.SelectTypeView();
                dateTypeView.frameLayout.BackgroundColor = CSS.CSS_Color.viewTranslucence;
                dateTypeView.frameLayout.Y = Application.GetRealHeight(56 + 50 * i);
                dateTypeView.btnIcon.Visible = false;
                dateTypeView.btnText.X = Application.GetRealWidth(20);
                dateTypeView.btnNextIcon.X = Application.GetRealWidth(307);
                dateTypeView.btnLine.X = Application.GetRealWidth(20);
                dateTypeView.btnLine.Width = Application.GetRealWidth(303);
                dateView.frameLayout.AddChidren(dateTypeView.FLayoutView());
                dateTypeView.btnClick.Tag = i;//标记类型
 
                switch (i)
                {
                    case 0:
                        {
                            weekName = Language.StringByID(StringId.performA);
                            dateTypeView.btnNextIcon.Visible = false;
                        }
                        break;
                    case 1:
                        {
                            weekName = Language.StringByID(StringId.days);
                            dateTypeView.btnNextIcon.Visible = false;
                        }
                        break;
                    case 2:
                        {
                            weekName = Language.StringByID(StringId.weekly);
                        }
                        break;
                    case 3:
                        {
                            weekName = Language.StringByID(StringId.monthly);
                        }
                        break;
 
 
                }
                dateTypeView.btnText.Text = weekName;
                //循环类型(例如:每月,每天)点击事件
                dateTypeView.btnClick.MouseUpEventHandler += (sender, e) =>
                {
                    int clickIndex = int.Parse(dateTypeView.btnClick.Tag.ToString());
                    switch (clickIndex)
                    {
                        case 0:
                            {
                                weekName = Language.StringByID(StringId.performA);
                                selecetdBtn.TextColor = CSS.CSS_Color.textColor;
                                dateTypeView.btnText.TextColor = CSS.CSS_Color.textConfirmColor;
                                selecetdBtn = dateTypeView.btnText;
                            }
                            break;
                        case 1:
                            {
                                weekName = Language.StringByID(StringId.days);
                                selecetdBtn.TextColor = CSS.CSS_Color.textColor;
                                dateTypeView.btnText.TextColor = CSS.CSS_Color.textConfirmColor;
                                selecetdBtn = dateTypeView.btnText;
 
                            }
                            break;
                        case 2:
                            {
                                WeekMethod(fLayout, button);
                            }
                            break;
                        case 3:
                            {
                                MonMethod(fLayout, button);
                            }
                            break;
 
 
                    }
                };
 
 
                //显示之前的状态
                if (button.Text == weekName)
                {
                    dateTypeView.btnText.TextColor = CSS.CSS_Color.textConfirmColor;
                    selecetdBtn = dateTypeView.btnText;
 
                }
            }
            //确定保存
            dateView.btnConfirm.MouseUpEventHandler += (sender3, e3) =>
            {
                if (selecetdBtn.Text == Language.StringByID(StringId.performA))
                {
                    //执行一次
                    Logic.currlogic.cycle.type = "once";
                }
                else if (selecetdBtn.Text == Language.StringByID(StringId.days))
                {
                    //每天
                    Logic.currlogic.cycle.type = "day";
 
                }
                else
                {
                    //提示:还未选
                    return;
                }
                //选中保存之后显示文本
                button.Text = selecetdBtn.Text;
                //移除fLayout界面
                fLayout.RemoveFromParent();
            };
        }
        /// <summary>
        /// 选中星期几(周一,周二 。。。)
        /// </summary>
        /// <param name="fLayout">弹框主控件</param>
        /// <param name="button">显示文本</param>
        public void WeekMethod(FrameLayout fLayout, Button button)
        {
            List<string> weekStr = new List<string> {
             Language.StringByID(StringId.monday),
             Language.StringByID(StringId.tuesday),
             Language.StringByID(StringId.wednesday),
             Language.StringByID(StringId.thursday),
             Language.StringByID(StringId.friday),
             Language.StringByID(StringId.saturday),
             Language.StringByID(StringId.sunday),
            };
 
            //定义一个局部weekList列表用来记录选中数据;
            List<string> weekStateList = new List<string>();
            weekStateList.Clear();
            if (Logic.currlogic.cycle.type == "week")
            {
                var list = GetWeekString(Logic.currlogic.cycle.value, "int");
                //加载之前保存的数据
                weekStateList.AddRange(list);
            }
            PublicInterface weekView = new PublicInterface();
            weekView.MultiSelectShow(fLayout, weekStr, Language.StringByID(StringId.cyclic), weekStateList
               , (list) =>
               {
                   var statelist = GetWeekString(list, "str");
                   Logic.currlogic.cycle.type = "week";
                   Logic.currlogic.cycle.value = statelist;
                   button.Text = MainView.GetWeekString(statelist);
 
               });
        }
        /// <summary>
        /// 每月
        /// </summary>
        /// <param name="fLayout">弹框主控件</param>
        /// <param name="button">显示文本</param>
        public void MonMethod(FrameLayout fLayout, Button button)
        {
 
            PublicInterface weekView = new PublicInterface();
            weekView.MonSelectShow(fLayout, Logic.currlogic, (monList) =>
                {
                    Logic.currlogic.cycle.type = "mon";
                    Logic.currlogic.cycle.value = monList;
                    button.Text = MainView.GetMonString(monList);
                });
 
        }
        /// <summary>
        /// 满足条件
        /// </summary>
        /// <param name="fLayout">弹框主控件</param>
        /// <param name="button">显示文本</param>
        public void AndOrMethod(FrameLayout fLayout, Button button)
        {
            List<string> strList = new List<string> {
             Language.StringByID(StringId.andCondition),
             Language.StringByID(StringId.orCondition),
            };
            ///之前的状态文本
            string currCondition = button.Text;
 
            PublicInterface conditionView = new PublicInterface();
            conditionView.SingleSelectionShow(fLayout, strList, Language.StringByID(StringId.meetTheCondition), currCondition
               , (stateValue) =>
               {
                   if (stateValue == Language.StringByID(StringId.orCondition))
                   {
                       Logic.currlogic.relation = "or";
                   }
                   else
                   {
                       Logic.currlogic.relation = "and";
                   }
                   button.Text = stateValue;
 
               });
 
 
        }
        /// <summary>
        /// 星期周期转换值的方法
        /// </summary>
        /// <param name="list"></param>
        /// <param name="str_or_int"></param>
        /// <returns></returns>
        public List<string> GetWeekString(List<string> list, string str_or_int)
        {
            string weekTextName = "";
            List<string> stateList = new List<string>();
            for (int i = 0; i < list.Count; i++)
            {
                var s = list[i];
                if (str_or_int == "int")
                {
                    switch (s)
                    {
                        case "1":
                            {
                                weekTextName = Language.StringByID(StringId.monday);
                            }
                            break;
                        case "2":
                            {
                                weekTextName = Language.StringByID(StringId.tuesday);
                            }
                            break;
                        case "3":
                            {
                                weekTextName = Language.StringByID(StringId.wednesday);
                            }
                            break;
                        case "4":
                            {
                                weekTextName = Language.StringByID(StringId.thursday);
                            }
                            break;
                        case "5":
                            {
                                weekTextName = Language.StringByID(StringId.friday);
                            }
                            break;
                        case "6":
                            {
                                weekTextName = Language.StringByID(StringId.saturday);
                            }
                            break;
                        case "0":
                            {
                                weekTextName = Language.StringByID(StringId.sunday);
                            }
                            break;
                    }
 
                }
                else
                {
                    if (Language.StringByID(StringId.monday) == s)
                    {
                        weekTextName = "1";
                    }
                    else if (Language.StringByID(StringId.tuesday) == s)
                    {
                        weekTextName = "2";
                    }
                    else if (Language.StringByID(StringId.wednesday) == s)
                    {
                        weekTextName = "3";
                    }
                    else if (Language.StringByID(StringId.thursday) == s)
                    {
                        weekTextName = "4";
                    }
                    else if (Language.StringByID(StringId.friday) == s)
                    {
                        weekTextName = "5";
                    }
                    else if (Language.StringByID(StringId.saturday) == s)
                    {
                        weekTextName = "6";
                    }
                    else if (Language.StringByID(StringId.sunday) == s)
                    {
                        weekTextName = "0";
                    }
                }
                stateList.Add(weekTextName);
 
            }
 
            return stateList;
        }
 
    }
}