陈嘉乐
2020-12-01 307e554fb2ef6491d08afc58a6c0a852f44b4f46
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
using System;
using Shared;
using System.Collections.Generic;
namespace HDL_ON.UI.UI2.Intelligence.Automation
{
    public class InpOrOutLogicMethod
    {
        /// <summary>
        /// 输入条件处理方法
        /// </summary>
        /// <param name="thisView">当前界面</param>
        /// <param name="viewLayout">上下滑动控件</param>
        public static void InputCondition(FrameLayout thisView,VerticalScrolViewLayout viewLayout)
        {
            for (int i = 0; i < Logic.currlogic.input.Count; i++)
            {
                Input inputCondition = Logic.currlogic.input[i];
                ///各种条件的View
                LogicView.AddOutputInputView inputView = new LogicView.AddOutputInputView();
                viewLayout.AddChidren(inputView.FLayoutView());
                ///记录条件类型
                inputView.btnClick.Name = inputCondition.condition_type;
                ///记录条件索引
                inputView.btnClick.Tag = i;
                ///条件状态数组
                List<Dictionary<string, string>> dicList = inputCondition.condition as List<Dictionary<string, string>>;
                //显示条件各种类型状态
                switch (inputCondition.condition_type)
                {
                    case "1":
                        {
                            inputView.btnIcon.UnSelectedImagePath = "LogicIcon/timecondition.png";
                            foreach (var dic in dicList)
                            {
                                string value = dic["value"];
                                inputView.btnText.Text = Language.StringByID(StringId.hour) + ": " + value;
                                inputView.btnClick.AddTag("timepoint", value);
                            }
 
                        }
                        break;
                    case "2":
                        {
                            inputView.btnIcon.UnSelectedImagePath = "LogicIcon/timecondition.png";
                            foreach (var dic in dicList)
                            {
                                string value = dic["value"];
                                inputView.btnText.Text = Language.StringByID(StringId.timeHorizon) + ": " + value;
                                inputView.btnClick.AddTag("timeHorizon", value);
                            }
 
                        }
                        break;
                    case "3":
                        {
                            //用sid找到设备;
                            var device = LogicMethod.GetDevice(inputCondition.sid);
                            //用设备的functionType类型找到对应图标;
                            inputView.btnIcon.UnSelectedImagePath = LogicMethod.GetIconPath(device.functionType);
                            //显示设备名称
                            inputView.btnText.Text = device.name;
                            //改变设备名称显示控件宽度
                            inputView.btnText.Width = Application.GetRealWidth(80);
                            //区别不同设备,显示不同设备状态
                            switch (device.functionType)
                            {
                                case FunctionType.Relay:
                                    {//开关灯
                                        foreach (var dic in dicList)
                                        {
                                            
                                            string value = dic["value"];
                                            if (value == "on")
                                            {
                                                inputView.btnState.Text = Language.StringByID(StringId.onLogic);
 
                                            }
                                            else
                                            {
                                                inputView.btnState.Text = Language.StringByID(StringId.offLogic);
                                            }
                                        }
                                    }
                                    break;
                            }
                        }
                        break;
 
                }
                //再次编辑条件状态点击事件
                inputView.btnClick.MouseUpEventHandler += (sen, e) =>
                {
                    Button button = (Button)sen;
                    //找到当前编辑的索引
                    int indexVulae = int.Parse(inputView.btnClick.Tag.ToString());
                    //标记编辑状态
                    bool edit = true;
                    //表示是条件
                    string if_type = LogicMethod.condition_if;
                    switch (button.Name)
                    {
                        case "1":
                            {
                                FrameLayout fLayout = new FrameLayout
                                {
                                    BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
                                };
                                thisView.AddChidren(fLayout);
                                TimeTpye timeTpye = new TimeTpye();
                                timeTpye.TimePoint(fLayout, edit, indexVulae);
                            }
                            break;
                        case "2":
                            {
                                FrameLayout fLayout = new FrameLayout
                                {
                                    BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
                                };
                                thisView.AddChidren(fLayout);
                                TimeTpye timeTpye = new TimeTpye();
                                timeTpye.TimeHorizon(fLayout, edit, indexVulae);
                            }
                            break;
 
                        case "3":
                            {
                                //用sid找到设备;
                                var device = LogicMethod.GetDevice(inputCondition.sid);
                                DeviceFunList deviceFunList = new DeviceFunList();
                                MainPage.BasePageView.AddChidren(deviceFunList);
                                deviceFunList.Show(device, indexVulae,edit, if_type);
                                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                            }
                            break;
 
                        
                    }
                };
            }
 
        }
        /// <summary>
        /// 输出条件处理方法
        /// </summary>
        /// <param name="thisView">当前界面</param>
        /// <param name="viewLayout">上下滑动控件</param>
        public static void OutputTarget(FrameLayout thisView, VerticalScrolViewLayout viewLayout)
        {
 
            for (int i = 0; i < Logic.currlogic.output.Count; i++)  
            {
                Output outputTarget = Logic.currlogic.output[i];
                ///各种条件的View
                LogicView.AddOutputInputView targetView = new LogicView.AddOutputInputView();
                viewLayout.AddChidren(targetView.FLayoutView());
                ///记录条件类型
                targetView.btnClick.Name = outputTarget.target_type;
                ///记录条件索引
                targetView.btnClick.Tag = i;
                ///条件状态数组
                List<Dictionary<string, string>> dicList = outputTarget.status as List<Dictionary<string, string>>;
                //显示条件各种类型状态
                switch (outputTarget.target_type)
                {
                    case "1":
                        {
                            //用sid找到设备;
                            var device = LogicMethod.GetDevice(outputTarget.sid);
                            //用设备的functionType类型找到对应图标;
                            targetView.btnIcon.UnSelectedImagePath = LogicMethod.GetIconPath(device.functionType);
                            //显示设备名称
                            targetView.btnText.Text = device.name;
                            //改变设备名称显示控件宽度
                            targetView.btnText.Width = Application.GetRealWidth(80);
                            //区别不同设备,显示不同设备状态
                            switch (device.functionType)
                            {
                                case FunctionType.Relay:
                                    {//开关灯
                                        foreach (var dic in dicList)
                                        {
 
                                            string value = dic["value"];
                                            if (value == "on")
                                            {
                                                targetView.btnState.Text = Language.StringByID(StringId.onLogic);
 
                                            }
                                            else
                                            {
                                                targetView.btnState.Text = Language.StringByID(StringId.offLogic);
                                            }
                                        }
                                    }
                                    break;
                            }
                        }
                        break;
                    case "2":
                        {
                            //用sid找到场景;
                            var scene = LogicMethod.GetSecne(outputTarget.sid);
                            targetView.btnIcon.UnSelectedImagePath = "LogicIcon/scene.png";
                            targetView.btnNextIcon.Visible = false;
                            //显示场景名称
                            targetView.btnText.Text = scene.name;
                        }
                        break;
                    case "3":
                        {
                            targetView.btnIcon.UnSelectedImagePath = "LogicIcon/delayed.png";
                            foreach (var dic in dicList)
                            {
                                string value = dic["value"];
                                targetView.btnText.Text =value;
                            }
                        }
                        break;
                }
                //再次编辑条件状态点击事件
                targetView.btnClick.MouseUpEventHandler += (sen, e) =>
                {
                    Button button = (Button)sen;
                    //找到当前编辑的索引
                    int indexVulae = int.Parse(targetView.btnClick.Tag.ToString());
                    //标记编辑状态
                    bool edit = true;
                    //表示是目标
                    string if_type = LogicMethod.target_if;
                    switch (button.Name)
                    {
                        case "1":
                            {
                                //用sid找到设备;
                                var device = LogicMethod.GetDevice(outputTarget.sid);
                                DeviceFunList deviceFunList = new DeviceFunList();
                                MainPage.BasePageView.AddChidren(deviceFunList);
                                deviceFunList.Show(device, indexVulae, edit, if_type);
                                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                            }
                            break;
                        case "3":
                            {
 
                                FrameLayout fLayout = new FrameLayout
                                {
                                    BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
                                };
                                thisView.AddChidren(fLayout);
                                AddTarget addTarget = new AddTarget();
                                addTarget.Delayed(fLayout, edit, indexVulae);
 
                               
                            }
                            break;
                    }
                };
            }
        }
 
    }
}