陈嘉乐
2020-11-25 1410e38e50687272a162123552de122661d981ee
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
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, int index, bool edit)
        {
            #region 界面布局
            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);
            #endregion
 
            //定义一个变量,记录选中状态
            string selectedState = "unknown";
 
            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;
                                selectedState = device.functionType + "_on";
                            };
                            btnOff.MouseUpEventHandler += (sender3, e3) =>
                            {
                                LogicMethod.dictionary(dic, "value", "off");
                                RemView(relayFunView);
                                relayView.btnState.TextID = StringId.offLogic;
                                selectedState = device.functionType + "_off";
                            };
 
                        };
                        if (edit)
                        {
                            Input inputs = Logic.currlogic.input[index];
                            if (inputs.condition_type == "3")
                            {
                                List<Dictionary<string, string>> dicList = inputs.condition as List<Dictionary<string, string>>;
                                foreach (var dic in dicList)
                                {
                                    string value = dic["value"];
                                    if (value == "on")
                                    {
                                        relayView.btnState.Text = Language.StringByID(StringId.onLogic);
 
                                    }
                                    else
                                    {
                                        relayView.btnState.Text = Language.StringByID(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 (selectedState != "unknown")
                {
                    if (edit)
                    {
                        //移除旧数据
                        Logic.currlogic.input.RemoveAt(index);
                        //新数据插入旧数据的位置;
                        Logic.currlogic.input.Insert(index, inputdevice);
                    }
                    else
                    {
                        //添加一个新的时间点条件
                        Logic.currlogic.input.Add(inputdevice);
                    }
                }
                else
                {
                    if (!edit)
                    {
                        //提示用户
                        return;
                    }
                    this.RemoveFromParent();
                    return;
                }
                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();
        }
 
        public void GetState(Entity.Function device, bool edit, int index,Button button1,Button button2,Button button3,Button button4)
        {
            if (edit)
            {
                Input inputs = Logic.currlogic.input[index];
                var dicList = inputs.condition as List<Dictionary<string, string>>;
                switch (device.functionType)
                {
                    //开关灯光
                    case FunctionType.Relay:
                        {
                            foreach (var dic in dicList)
                            {
                                string value = dic["value"];
                                //if (value == "on")
                                //{
                                //    relayView.btnState.Text = Language.StringByID(StringId.onLogic);
 
                                //}
                                //else
                                //{
                                //    relayView.btnState.Text = Language.StringByID(StringId.offLogic);
                                //}
                            }
                        }
                        break;
 
                }
            }
        }
    }
}