陈嘉乐
2020-11-25 1761bbd82d7c1251283e3baa9b519204e456b2f8
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
using System;
using Shared;
using System.Collections.Generic;
namespace HDL_ON.UI.UI2.Intelligence.Automation
{
    public class DeviceFunList : FrameLayout
    {
        public DeviceFunList()
        {
            Tag = "Logic";
        }
 
        public void Show(Entity.Function device)
        {
            this.BackgroundColor = CSS.CSS_Color.viewMiddle;
            LogicView.TopView topView = new LogicView.TopView();
            this.AddChidren(topView.FLayoutView());
            topView.clickBackBtn.MouseUpEventHandler += (e, sen) =>
            {
                RemoveFromParent();
            };
            topView.topNameBtn.Text = device.name;
 
            FrameLayout fLayout = new FrameLayout
            {
                Y = Application.GetRealHeight(64),
                Height = Application.GetRealHeight(667 - 64),
            };
            this.AddChidren(fLayout);
            
                Input inputdevice = new Input();
                inputdevice.condition_type = "3";
                inputdevice.sid = device.sid;
            
 
            switch (device.functionType)
            {
                //开关灯光
                case FunctionType.Relay:
                    {
                        //for (int i = 0; i < device.function.Count; i++)
                        //{
                        //}
                        LogicView.SelectTypeView relayView = new LogicView.SelectTypeView();
                        relayView.btnIcon.Visible = false;
                        relayView.btnState.Visible = true;
                        relayView.btnText.TextSize = LogicView.TextSize.text16;
                        relayView.btnText.Height = Application.GetRealHeight(22);
                        relayView.btnText.TextID =StringId.switchLogic;
                        relayView.btnText.X = Application.GetRealWidth(16);
                        relayView.btnText.Width= Application.GetRealWidth(130);
                        relayView.btnLine.X = Application.GetRealWidth(16);
                        relayView.btnLine.Width = Application.GetRealWidth(343);
                        fLayout.AddChidren(relayView.FLayoutView());
                        relayView.btnClick.MouseUpEventHandler += (sender, e) =>
                        {
                            FrameLayout relayFunView = new FrameLayout
                            {
                                BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
                            };
                            this.AddChidren(relayFunView);
                            LogicView.SwitchView switchView = new LogicView.SwitchView();
                            switchView.FLayoutView(relayFunView, 2);
                            
                            Button btnOn = new Button
                            {
                                TextAlignment = TextAlignment.Center,
                                TextSize = LogicView.TextSize.text16,
                                TextColor = CSS.CSS_Color.textCancelColor,
                                TextID = StringId.onLogic,
                                Height = Application.GetRealHeight(44),
                                Width = Application.GetRealWidth(343),
                            };
                            switchView.frameLayout.AddChidren(btnOn);
                            Button btnLine = new Button
                            {
                                Height = 1,
                                BackgroundColor = CSS.CSS_Color.viewLine,
                                Y = btnOn.Bottom,
                            };
                            switchView.frameLayout.AddChidren(btnLine);
                            Button btnOff = new Button
                            {
                                Y = btnLine.Bottom,
                                TextAlignment = TextAlignment.Center,
                                TextSize = LogicView.TextSize.text16,
                                TextColor = CSS.CSS_Color.textCancelColor,
                                TextID = StringId.offLogic,
                                Height = Application.GetRealHeight(44),
                                Width = Application.GetRealWidth(343),
                            };
                            switchView.frameLayout.AddChidren(btnOff);
 
                            Dictionary<string, string> dic = new Dictionary<string, string>();
                            LogicMethod.dictionary(dic, "key", "on_off");
                            LogicMethod.dictionary(dic, "comparator", "=");
                            LogicMethod.dictionary(dic, "data_type", "string");
                            inputdevice.condition.Add(dic);
                            btnOn.MouseUpEventHandler += (sender2, e2) => {
                                LogicMethod.dictionary(dic, "value", "on");
                                RemView(relayFunView);
                                relayView.btnState.TextID = StringId.onLogic;
                            };
                            btnOff.MouseUpEventHandler += (sender3, e3) => {
                                LogicMethod.dictionary(dic, "value", "off");
                                RemView(relayFunView);
                                relayView.btnState.TextID = StringId.offLogic;
                            };
 
                        };
 
                    }
                    break;
 
            }
 
 
 
            #region  保存
            ///保存View
            LogicView.SaveView saveView = new LogicView.SaveView();
            saveView.frameLayout.SetCornerWithSameRadius(Application.GetRealHeight(24), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight);
            saveView.btnSave.TextID = StringId.completeLogic;
            this.AddChidren(saveView.FLayoutView());
            saveView.btnClick.MouseUpEventHandler += (sen, e) =>
            {
                //if (edit)
                //{
                //    //移除旧数据
                //    Logic.currlogic.input.RemoveAt(index);
                //    //新数据插入旧数据的位置;
                //    Logic.currlogic.input.Insert(index, inputdevice);
                //}
                //else
                //{
                //    //添加一个新的时间点条件
                //    Logic.currlogic.input.Add(inputdevice);
                //}
 
                //添加一个新的时间点条件
                Logic.currlogic.input.Add(inputdevice);
                RemoveViewByTag("Logic");
                AddLogic addLogic = new AddLogic();
                MainPage.BasePageView.AddChidren(addLogic);
                addLogic.Show();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
 
            #endregion
 
        }
        /// <summary>
        /// 移除控件
        /// </summary>
        /// <param name="frame"></param>
        public void RemView(FrameLayout frame) {
            frame.RemoveFromParent();
        }
    }
}