wxr
2021-03-23 09bde2ffef953fa5e78a4320aa8bbe03276ed7c5
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
using System;
using System.Collections.Generic;
using HDL_ON.Entity;
using HDL_ON.UI.UI2.Intelligence.Automation.LogicView;
using Shared;
namespace HDL_ON.UI.UI2.PersonalCenter.PirDevice
{
    public class Matching : FrameLayout
    {
        public Matching()
        {
            Tag = "PirView";
        }
      
        public void Show(List<Brand> brandList, List<Library> libraryList,string spk) 
        {
           
            
            #region 界面布局
            this.BackgroundColor = CSS.CSS_Color.viewMiddle;
            PirDevice.View.TopView topView = new View.TopView();
            topView.topNameBtn.TextID = StringId.pipeiyaokongqi;
            this.AddChidren(topView.FLayoutView());
            topView.clickBackBtn.MouseUpEventHandler += (sender, e) =>
            {
                BrandList brandObj = new BrandList();
                brandObj.Show(brandList, spk);
                this.RemoveFromParent();
 
            };
 
            FrameLayout fLayout = new FrameLayout
            {
                Y = topView.frameLayout.Bottom,
                Height = Application.GetRealHeight(667 - 64),
                Width = Application.GetRealWidth(375),
            };
            this.AddChidren(fLayout);
            //请点击以下按钮
            Button text1Btn = new Button
            {
                Y = Application.GetRealHeight(60),
                X = Application.GetRealWidth(16),
                Width = Application.GetRealWidth(375 - 32),
                Height = Application.GetRealHeight(20),
                TextID = StringId.dianjianniu,
                TextSize = TextSize.text14,
                TextColor = CSS.CSS_Color.textColor,
                TextAlignment = TextAlignment.Center,
 
            };
            fLayout.AddChidren(text1Btn);
 
            //确认设备是否有响应
            Button text2Btn = new Button
            {
                Y = Application.GetRealHeight(60 + 24),
                X = Application.GetRealWidth(16),
                Width = Application.GetRealWidth(375 - 32),
                Height = Application.GetRealHeight(20),
                TextID = StringId.shifouyouxiangying,
                TextSize = TextSize.text14,
                TextColor = CSS.CSS_Color.textColor,
                TextAlignment = TextAlignment.Center,
            };
            fLayout.AddChidren(text2Btn);
            //左
            var leftIconBtn = new Button
            {
                Y = Application.GetRealHeight(203),
                X = Application.GetRealWidth(16),
                Width = Application.GetRealWidth(36),
                Height = Application.GetRealWidth(36),
                UnSelectedImagePath = "PirIcon/left.png",
            };
            fLayout.AddChidren(leftIconBtn);
            //右
            var rightIconBtn = new Button
            {
                Y = Application.GetRealHeight(203),
                X = Application.GetRealWidth(323),
                Width = Application.GetRealWidth(36),
                Height = Application.GetRealWidth(36),
                UnSelectedImagePath = "PirIcon/right.png",
            };
            fLayout.AddChidren(rightIconBtn);
            //测试功能
            var testBtn = new Button
            {
                Y = Application.GetRealHeight(199),
                X = Application.GetRealWidth(136),
                Width = Application.GetRealWidth(104),
                Height = Application.GetRealHeight(44),
                TextID=StringId.dianyuan,
                TextSize = TextSize.text16,
                TextColor = CSS.CSS_Color.textColor,
                TextAlignment = TextAlignment.Center,
                Radius = (uint)Application.GetRealHeight(18),
                BorderWidth = 1,
                BorderColor = CSS.CSS_Color.textCancelColor,
            };
            fLayout.AddChidren(testBtn);
 
            // 5/10
            Button sumBtn = new Button
            {
                Y = Application.GetRealHeight(267),
                X = Application.GetRealWidth(136),
                Width = Application.GetRealWidth(104),
                Height = Application.GetRealHeight(17),
                Text = $"(1/{libraryList.Count})",
                TextSize = TextSize.text12,
                TextColor = CSS.CSS_Color.textCancelColor,
            };
            fLayout.AddChidren(sumBtn);
 
            //控制失败
            var failedBtn = new Button
            {
                Y = Application.GetRealHeight(521),
                X = Application.GetRealWidth(52),
                Width = Application.GetRealWidth(124),
                Height = Application.GetRealHeight(44),
                TextID = StringId.kongzhishibai,
                TextSize = TextSize.text16,
                TextColor = CSS.CSS_Color.textConfirmColor,
                TextAlignment = TextAlignment.Center,
                Radius = (uint)Application.GetRealHeight(22),
                BorderWidth = 1,
                BorderColor = CSS.CSS_Color.textConfirmColor,
            };
            fLayout.AddChidren(failedBtn);
            //控制成功
            var succeedBtn = new Button
            {
                Y = Application.GetRealHeight(521),
                X = Application.GetRealWidth(196),
                Width = Application.GetRealWidth(124),
                Height = Application.GetRealHeight(44),
                TextID = StringId.kongzhichenggong,
                TextSize = TextSize.text16,
                TextColor = CSS.CSS_Color.textWhiteColor,
                TextAlignment = TextAlignment.Center,
                Radius = (uint)Application.GetRealHeight(22),
                //BorderWidth = 1,
                //BorderColor = CSS.CSS_Color.textConfirmColor,
                BackgroundColor = CSS.CSS_Color.textConfirmColor,
            };
            fLayout.AddChidren(succeedBtn);
            #endregion
            #region 点击事件
            //表示库列表索引值(目前只20个库)
            int index = 1; 
            //表示测试码索引值(目前只测试3个码)
            int code = 1;
            //表示测试最后一个码;
            bool if_bool = false;
            //左
            leftIconBtn.MouseUpEventHandler += (sender, e) =>
            {
                if (index>1) {
                    index--;
                    sumBtn.Text = $"({index.ToString()}/{libraryList.Count})";
                }
                code = 1;
                GetBtnText(testBtn, code, spk);
            };
            //右
            rightIconBtn.MouseUpEventHandler += (sender, e) =>
            {
                if (index < libraryList.Count)
                {
                    index++;
                    sumBtn.Text = $"({index.ToString()}/{libraryList.Count})";
                }
                code = 1;
                GetBtnText(testBtn, code, spk);
            };
           
            //测试Text
            testBtn.MouseUpEventHandler += (sender, e) =>
            {
                var library = libraryList[index-1];
                var control = GetControl(spk, testBtn.TextID, library);
                //发送测试码命令
                CodeTest(control);
                if (code == 3) {
                    //标记最后那个码
                    if_bool = true;
                }
            };
            //控制失败
            failedBtn.MouseUpEventHandler += (sender, e) =>
            {
                if (index < libraryList.Count)
                {
                    //先加
                    index++;
                    //更新文本
                    sumBtn.Text = $"({index.ToString()}/{libraryList.Count})";
                }
                code = 1;
                //更新状态
                GetBtnText(testBtn, code, spk);
            };
            //控制成功
            succeedBtn.MouseUpEventHandler += (sender, e) =>
            {
                if (code < 3)
                {
                    code++;
                }
                //更新状态
                GetBtnText(testBtn, code, spk);
                if (if_bool)
                {
                    var library = libraryList[index-1];
                    var control = GetControl(spk, testBtn.TextID, library);
                    Method method = new Method();
                    //发送库添加遥控器命令
                    method.ThreadAddControl(control, this, (cont) =>
                    {
                        MainPage.BasePageView.RemoveViewByTag("PirView");
                        AddControlComplete addControlComplete = new AddControlComplete();
                        MainPage.BasePageView.AddChidren(addControlComplete);
                        addControlComplete.Show(cont, true);
                        MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                    });
 
                }
            };
            #endregion
        }
 
        /// <summary>
        /// 获取Control对象(存储发送数据的对象)
        /// </summary>
        /// <param name="spk"></param>
        /// <param name="textInt"></param>
        /// <param name="library"></param>
        /// <returns></returns>
        private Control GetControl(string spk, int textInt, Library library) {
 
            string key = "";
            string value = "";
            switch (spk)
            {
                case SPK.AcIr:
                    {
                        switch (textInt)
                        {
                            case StringId.dianyuan:
                                {
                                    key = "on_off";
                                    value = "on";
                                }
                                break;
                            case StringId.moshizhileng:
                                {
                                    key = "mode";
                                    value = "cool";
                                }
                                break;
                            case StringId.fengsuzhongfeng:
                                {
                                    key = "fan";
                                    value = "medium";
                                }
                                break;
                        }
                    }
                    break;
                case SPK.TvIr:
                    {
                        switch (textInt)
                        {
                            case StringId.dianyuan:
                                {
                                    key = "on_off";
                                    value = "on";
                                }
                                break;
                            case StringId.yinliangjia:
                                {
                                    key = "volume+";
                                    value = "50";
                                }
                                break;
                            case StringId.jingyin:
                                {
                                    key = "mute";
                                    value = "0";
                                }
                                break;
                        }
                    }
                    break;
            }
            AttributesStatus buttonObj = new AttributesStatus();
            buttonObj.key = key;
            buttonObj.value = value;
 
            Control control = new Control();
            control.spk = spk;
            control.name = spk;
            control.groupId = library.irIndex;
            control.type = "library";
            control.status.Add(buttonObj);
            control.deviceId = Pir.currPir.deviceId;
            control.sid = "";
            string[] strings = library.irCode.Split(',');
            for (int arrayStr = 0; arrayStr < strings.Length; arrayStr++) 
            {
                //var intValue = Convert.ToInt32(strings[arrayStr],16);
                control.library.Add(strings[arrayStr].Replace("0x",""));
            }
 
            return control;
        }
 
        /// <summary>
        /// 发送库码测试命令
        /// </summary>
        /// <param name="control"></param>
        private void CodeTest(Control control)
        {
 
            //加载log
            Loading loading = new Loading();
            this.AddChidren(loading);
            HDL_ON.DAL.Server.ResponsePackNew responsePackNew = null;
            loading.Start();
            new System.Threading.Thread(() =>
            {
                try
                {
                    responsePackNew = PirSend.CodeTest(control);
                }
                catch { }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        loading.Hide();
                        if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                        {
 
                        }
                        else
                        {
                            //Method method = new Method();
                            //method.ErrorShow(responsePackNew);
                        }
 
                    });
                }
 
            })
            { IsBackground = true }.Start();
        }
 
        /// <summary>
        /// 显示测试文本
        /// </summary>
        /// <param name="testBtn">显示控件</param>
        /// <param name="code">测试码文本索引值</param>
        /// <param name="spk">云雀上定义spk</param>
        private  void GetBtnText(Button testBtn,int code,string spk) {
 
            int textValue = 0;
            switch (spk)
            {
                case SPK.AcIr:
                    {
                        switch (code)
                        {
                            case 1:
                                {
                                    textValue = StringId.dianyuan;
                                }
                                break;
                            case 2:
                                {
                                    textValue = StringId.moshizhileng;
                                }
                                break;
                            case 3:
                                {
                                    textValue = StringId.fengsuzhongfeng;
                                }
                                break;
                        }
                    }
                    break;
                case SPK.TvIr:
                    {
                        switch (code)
                        {
                            case 1:
                                {
                                    textValue = StringId.dianyuan;
                                }
                                break;
                            case 2:
                                {
                                    textValue = StringId.yinliangjia;
                                }
                                break;
                            case 3:
                                {
                                    textValue = StringId.jingyin;
                                }
                                break;
                        }
                    }
                    break;
            }
            testBtn.TextID = textValue;
        }
    }
}