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
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.Device
{
    /// <summary>
    /// 网关指定设备的信息画面(这个画面会修改设备的物理名字)★
    /// </summary>
    public class DeviceEpointInfoForm : UserCenterCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 设备名称变更的回调函数(设备名称,房间名)
        /// </summary>
        public Action<string, List<string>> ActionNameChangedEvent = null;
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalScrolViewLayout listview = null;
        /// <summary>
        /// 新上报的设备
        /// </summary>
        private CommonDevice newDevice = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="device">设备</param>
        public void ShowForm(CommonDevice device)
        {
            this.newDevice = device;
 
            //设置标题信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uDeviceSettingUp));
 
            //检测设备是否拥有测试的功能
            if (Common.LocalDevice.Current.DeviceIsCanTest(device) == true)
            {
                //初始化头部右边的测试图标
                this.InitTopLayoutRightIcon();
            }
 
            //初始化中部控件
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化头部右边的测试图标
        /// </summary>
        private void InitTopLayoutRightIcon()
        {
            var btnIcon = new TopLayoutMostRightView();
            btnIcon.UnSelectedImagePath = "Item/Test.png";
            btnIcon.SelectedImagePath = "Item/TestSelected.png";
            topFrameLayout.AddChidren(btnIcon);
 
            btnIcon.MouseUpEventHandler += (sender, e) =>
            {
                //测试
                Common.LocalDevice.Current.SetTestCommand(newDevice);
            };
        }
 
        /// <summary>
        /// 初始化中部控件
        /// </summary>
        public void InitMiddleFrame()
        {
            this.bodyFrameLayout.RemoveAll();
 
            //房间
            List<string> listRoomName = Common.Room.CurrentRoom.GetRoomListNameByDevice(this.newDevice);
 
            //图标
            var btnImage = new IconViewControl(332);
            btnImage.Y = Application.GetRealHeight(40);
            btnImage.Gravity = Gravity.CenterHorizontal;
            //设置大图
            Common.LocalDevice.Current.SetDeviceBigIconToControl(btnImage, this.newDevice);
            bodyFrameLayout.AddChidren(btnImage);
            btnImage.MouseUpEventHandler += (sender, e) =>
            {
                //显示变更设备图标的界面
                this.ShowChangedIconForm(btnImage);
            };
 
            listview = new VerticalScrolViewLayout();
            listview.Y = btnImage.Bottom + Application.GetRealHeight(50);
            listview.Height = bodyFrameLayout.Height - btnImage.Bottom - Application.GetRealHeight(50);
            bodyFrameLayout.AddChidren(listview);
 
            //设备名称
            string caption = Language.StringByID(R.MyInternationalizationString.uDeviceName);
            string nameValue = Common.LocalDevice.Current.GetDeviceEpointName(newDevice);
            var btnDeviceView = new EditorNameValueRow(caption, nameValue);
            listview.AddChidren(btnDeviceView);
            btnDeviceView.InitControl();
            //请输入设备名称
            btnDeviceView.SetEmptyNameTip(Language.StringByID(R.MyInternationalizationString.uDeviceNameMastInput));
            //编辑设备名称
            btnDeviceView.SetDialogTitle(Language.StringByID(R.MyInternationalizationString.uEditorDeviceName));
            btnDeviceView.ActionNameChangedEvent += (deviceName) =>
            {
                //设备重命名
                this.DeviceReName(deviceName, listRoomName);
            };
 
            var statuRow = new StatuRowLayout(listview);
            //所属区域
            var btnBelongAreaView = new RowTopGrayView(false);
            btnBelongAreaView.TextID = R.MyInternationalizationString.uBelongArea;
            statuRow.AddChidren(btnBelongAreaView);
 
            var btnBelongArea = new RowBottomBlackView(false);
            btnBelongArea.Text = Common.Room.CurrentRoom.GetRoomName(listRoomName);
            statuRow.AddChidren(btnBelongArea);
 
            //向右图标
            statuRow.AddRightIconControl();
 
            statuRow.MouseUpEvent += (sender, e) =>
            {
                var form = new SelectRoomForm();
                this.AddForm(form, listRoomName);
                form.ActionSelectRoom = (list) =>
                {
                    if (list != null)
                    {
                        //变更房间
                        Common.Room.CurrentRoom.ChangedRoom(newDevice, list);
 
                        btnBelongArea.Text = Common.Room.CurrentRoom.GetRoomName(list);
                        listRoomName = list;
 
                        if (this.ActionNameChangedEvent != null)
                        {
                            string name = Common.LocalDevice.Current.GetDeviceEpointName(this.newDevice);
                            this.ActionNameChangedEvent(name, listRoomName);
                        }
                    }
                };
            };
 
            //所属模块
            var row = new RowLayout();
            row.Height = ControlCommonResourse.ListViewRowHeight;
            listview.AddChidren(row);
 
            var btnBelongObjectView = new RowTopGrayView(false);
            btnBelongObjectView.TextID = R.MyInternationalizationString.uBelongObject;
            row.AddChidren(btnBelongObjectView);
 
            var btnBelongObject = new RowBottomBlackView(false);
            btnBelongObject.Text = Common.LocalDevice.Current.GetDeviceMacName(newDevice);
            row.AddChidren(btnBelongObject);
 
            //添加所有菜单
            this.AddAllMenu();
        }
 
        #endregion
 
        #region ■ 添加菜单___________________________
 
        /// <summary>
        /// 添加所有菜单
        /// </summary>
        private async void AddAllMenu()
        {
            //开启进度条
            this.ShowProgressBar();
 
            //添加按键面板的【指示灯设置】行  这个东西需要判断功能
            bool result = await this.AddPanelPilolightSettionRow();
            if (result == false)
            {
                //关闭进度条
                this.CloseProgressBar(ShowReLoadMode.YES);
                return;
            }
            //PIR传感器的信息
            IASZone.ConfigureParamates Pirconfigure = null;
            //如果是PIR传感器并且支持开关,只能河东的设备使用 (这里判断的是输出簇)
            if ((newDevice is IASZone) == true
                && Common.LocalDevice.Current.IsHdlDevice(newDevice) == true
                && Common.LocalDevice.Current.OutDeviceIsCanOnOff(newDevice) == true)
            {
                //获取PIR传感器的【灯光配置】,错误时返回null
                Pirconfigure = await Common.LocalDevice.Current.GetPirSensorLightSettion((IASZone)newDevice);
                if (Pirconfigure == null)
                {
                    //关闭进度条
                    this.CloseProgressBar(ShowReLoadMode.YES);
                    return;
                }
            }
 
            Application.RunOnMainThread(() =>
            {
                //添加按键面板的【绑定目标】行
                this.AddPanelBindTargetRow();
 
                //添加PIR传感器的【绑定目标】行
                this.AddPirSensorBindTargetRow(Pirconfigure);
 
                //关闭进度条
                this.CloseProgressBar();
            });
        }
 
        #endregion
 
        #region ■ 按键面板指示灯设置_________________
 
        /// <summary>
        /// 添加按键面板的【指示灯设置】行
        /// </summary>
        private async Task<bool> AddPanelPilolightSettionRow()
        {
            if (newDevice.Type != DeviceType.OnOffSwitch)
            {
                //如果是不是按键面板的话
                return true;
            }
            if (Common.LocalDevice.Current.IsHdlDevice(newDevice) == false)
            {
                //只有河东的设备能使用
                return true;
            }
 
            //检测控制面板(灯类)所拥有的功能:需要颜色调节功能
            Dictionary<string, bool> dicCheck = await Common.LocalDevice.Current.CheckPanelLightFunctionLevel2((Panel)newDevice);
            if (dicCheck == null)
            {
                return false;
            }
            if (dicCheck["颜色调节"] == false)
            {
                //这个面板没有颜色调节的功能
                return true;
            }
 
            Application.RunOnMainThread(() =>
            {
                //指示灯设置
                var staRow = new StatuRowLayout(listview);
                var btnPilolight = new RowCenterView(false);
                btnPilolight.TextID = R.MyInternationalizationString.uPilolightSettion;
                staRow.AddChidren(btnPilolight);
                //向右图标
                staRow.AddRightIconControl();
 
                staRow.MouseUpEvent += (sender, e) =>
                {
                    var form = new DevicePanel.PanelPilolightSettionMenuForm();
                    this.AddForm(form, (Panel)newDevice);
                };
            });
            return true;
        }
 
        #endregion
 
        #region ■ 按键面板绑定目标___________________
 
        /// <summary>
        /// 添加按键面板的【绑定目标】行
        /// </summary>
        private void AddPanelBindTargetRow()
        {
            if (newDevice.Type != DeviceType.OnOffSwitch)
            {
                //如果是不是按键面板的话
                return;
            }
 
            //绑定目标
            var staRow = new StatuRowLayout(listview);
            var btnBind = new RowCenterView(false);
            btnBind.TextID = R.MyInternationalizationString.uBindTargets;
            staRow.AddChidren(btnBind);
            //向右图标
            staRow.AddRightIconControl();
 
            staRow.MouseUpEvent += (sender, e) =>
            {
                var panel = newDevice as ZigBee.Device.Panel;
                var bindPage = new Shared.Phone.UserCenter.Bind.PanelBindPage();
                Shared.Phone.UserView.HomePage.Instance.AddChidren(bindPage);
                Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                bindPage.Show(panel.Gateway, panel);
            };
        }
 
        #endregion
 
        #region ■ PIR传感器绑定目标__________________
 
        /// <summary>
        /// 添加PIR传感器的【绑定目标】行
        /// </summary>
        /// <param name="configure">灯光配置</param>
        private void AddPirSensorBindTargetRow(IASZone.ConfigureParamates configure)
        {
            //如果是PIR传感器并且支持开关 (这里判断的是输出簇)
            if (configure == null || (newDevice is IASZone) == false || Common.LocalDevice.Current.OutDeviceIsCanOnOff(newDevice) == false)
            {
                return;
            }
 
            //绑定目标
            var staRow = new StatuRowLayout(listview);
            var btnBind = new RowCenterView(false);
            btnBind.TextID = R.MyInternationalizationString.uBindTargets;
            staRow.AddChidren(btnBind);
            //向右图标
            staRow.AddRightIconControl();
 
            staRow.MouseUpEvent += (sender, e) =>
            {
                var form = new DevicePir.PirSensorBindTargetForm();
                this.AddForm(form, (IASZone)newDevice);
            };
 
            //检测目标推送
            var SenRow = new RowLayout();
            SenRow.Height = ControlCommonResourse.ListViewRowHeight;
            listview.AddChidren(SenRow);
 
            var btnSend = new RowCenterView(false);
            btnSend.TextID = R.MyInternationalizationString.uTestTargetPush;
            SenRow.AddChidren(btnSend);
 
            var btnSendSwich = new SwichControl();
            SenRow.AddChidren(btnSendSwich);
            btnSendSwich.IsSelected = configure.controlDevEnable;
            btnSendSwich.MouseUpEventHandler += async (sender, e) =>
            {
                configure.controlDevEnable = !configure.controlDevEnable;
                //开启进度条
                this.ShowProgressBar();
                var result = await Common.LocalDevice.Current.SetPirSensorLightSettion((IASZone)newDevice, configure);
                //关闭进度条
                this.CloseProgressBar();
                if (result == false)
                {
                    //将缓存值改回来
                    configure.controlDevEnable = !configure.controlDevEnable;
                    return;
                }
                Application.RunOnMainThread(() =>
                {
                    btnSendSwich.IsSelected = !btnSendSwich.IsSelected;
                });
            };
        }
 
        #endregion
 
        #region ■ 修改名字___________________________
 
        /// <summary>
        /// 设备重命名
        /// </summary>
        /// <param name="name">Name.</param>
        /// <param name="listRoomName">Name.</param>
        private async void DeviceReName(string name, List<string> listRoomName)
        {
            //设备名称修改
            var result = await Common.LocalDevice.Current.ReName(this.newDevice, name);
            if (result == false)
            {
                return;
            }
            Application.RunOnMainThread(() =>
            {
                if (this.ActionNameChangedEvent != null)
                {
                    name = Common.LocalDevice.Current.GetDeviceEpointName(this.newDevice);
                    this.ActionNameChangedEvent(name, listRoomName);
                }
            });
        }
 
        #endregion
 
        #region ■ 变更图片___________________________
 
        /// <summary>
        /// 显示变更设备图标的界面
        /// </summary>
        /// <param name="btnIcon"></param>
        private void ShowChangedIconForm(IconViewControl btnIcon)
        {
            var form = new Phone.Device.CommonForm.DeviceIconSelectedIMGByLocal();
            UserView.HomePage.Instance.AddChidren(form);
            UserView.HomePage.Instance.PageIndex += 1;
            form.Show();
            form.action = (unSelectedImagePath, selectedImagePath) =>
            {
                btnIcon.UnSelectedImagePath = selectedImagePath;
 
                //变更图标
                Common.LocalDevice.Current.ChangedDeviceIcon(newDevice, unSelectedImagePath);
 
                if (this.ActionNameChangedEvent != null)
                {
                    List<string> listRoomName = Common.Room.CurrentRoom.GetRoomListNameByDevice(this.newDevice);
                    string name = Common.LocalDevice.Current.GetDeviceEpointName(this.newDevice);
                    this.ActionNameChangedEvent(name, listRoomName);
                }
            };
        }
 
        #endregion
    }
}