黄学彪
2020-04-02 9904031f5291daaf56985146bb671f25e18ebbdf
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
425
426
427
428
429
430
431
432
433
434
435
436
437
using System;
using System.Collections.Generic;
using System.Text;
using Shared.Common;
using Shared.Phone.UserCenter;
using ZigBee.Device;
 
namespace Shared.Phone.MainPage
{
    /// <summary>
    /// 主页的设备信息界面
    /// </summary>
    public class DeviceDetailInfoForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 界面关闭事件(该事件目前给分类界面的自定义行控件使用)
        /// </summary>
        public Action<CommonDevice, Room> FormCloseEvent = null;
        /// <summary>
        /// 设备对象
        /// </summary>
        private CommonDevice device;
        /// <summary>
        /// 房间对象(这个房间有可能是喜爱)
        /// </summary>
        private Room room = null;
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalListControl listview = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_device">设备对象</param>
        /// <param name="i_room">房间对象(这个房间有可能是喜爱)</param>
        public void ShowForm(CommonDevice i_device, Room i_room)
        {
            this.device = i_device;
            this.room = i_room;
 
            //设置标题信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.FunctionSetting));
 
            //主人和管理员才能更改
            if (UserCenterResourse.UserInfo.AuthorityNo == 1 || UserCenterResourse.UserInfo.AuthorityNo == 2)
            {
                //初始化中部控件(主人,管理员)
                this.InitMiddleFrameByAdmin();
            }
            //成员不允许变更
            else
            {
                //初始化中部控件(成员)
                this.InitMiddleFrameByMember();
            }
        }
 
        /// <summary>
        /// 初始化中部控件(主人,管理员)
        /// </summary>
        private void InitMiddleFrameByAdmin()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            //初始化桌布
            var tableContr = new InformationEditorControl();
            this.listview = tableContr.InitControl(bodyFrameLayout, Language.StringByID(R.MyInternationalizationString.uInfoEditor), 418, 1319);
 
            //图片
            var btnPic = new DeviceInfoIconControl();
            btnPic.Y = Application.GetRealHeight(46);
            btnPic.Gravity = Gravity.CenterHorizontal;
            bodyFrameLayout.AddChidren(btnPic);
            btnPic.InitControl(device.DeviceAddr, device.DeviceEpoint);
            btnPic.ButtonClickEvent += (sender, e) =>
            {
                var localPic = new Device.CommonForm.DeviceIconSelectedIMGByLocal();
                UserView.HomePage.Instance.AddChidren(localPic);
                UserView.HomePage.Instance.PageIndex += 1;
                localPic.Show();
                localPic.action = (unSelectedImagePath, selectedImagePath) =>
                {
                    //变更图片
                    device.IconPath = unSelectedImagePath;
                    device.IsCustomizeImage = true;
                    device.ReSave();
                    //刷新控件
                    btnPic.RefreshControl();
                };
            };
 
            //设备所属类型
            var infoType = LocalDevice.Current.GetDeviceBelongEnumInfo(device);
            var btnBelongType = new NormalViewControl(700, 62, true);
            btnBelongType.Y = btnPic.Bottom + Application.GetRealHeight(35);
            btnBelongType.Gravity = Gravity.CenterHorizontal;
            btnBelongType.TextID = infoType.BeloneTextId;
            btnBelongType.TextSize = 15;
            btnBelongType.TextAlignment = TextAlignment.Center;
            bodyFrameLayout.AddChidren(btnBelongType);
 
            //功能名称
            string caption = Language.StringByID(R.MyInternationalizationString.FunctionName);
            string deviceName = LocalDevice.Current.GetDeviceEpointName(device);
            var btnNote = new FrameCaptionInputControl(caption, deviceName, listview.rowSpace / 2);
            listview.AddChidren(btnNote);
            btnNote.InitControl();
            //划线
            btnNote.AddBottomLine();
            btnNote.txtInput.FinishInputEvent += () =>
            {
                string oldName = LocalDevice.Current.GetDeviceEpointName(device);
                if (btnNote.Text == string.Empty)
                {
                    btnNote.Text = oldName;
                }
                if (oldName != btnNote.Text)
                {
                    //修改名字
                    this.DeviceReName(btnNote.Text, false);
                }
            };
 
            //喜爱房间不允许变更区域
            if (this.room.IsLove == false)
            {
                //所属区域
                var rowBeloneArea = new BelongAreaControl(listview.rowSpace / 2);
                listview.AddChidren(rowBeloneArea);
                rowBeloneArea.InitControl(Language.StringByID(R.MyInternationalizationString.uBelongArea), this.device);
                //底线
                rowBeloneArea.AddBottomLine();
                rowBeloneArea.SelectRoomEvent += (roomKeys) =>
                {
                    //房间重新获取
                    this.room = HdlRoomLogic.Current.GetRoomById(roomKeys);
                    HdlRoomLogic.Current.ChangedRoom(device, roomKeys);
                };
            }
 
            //所属模块
            caption = Language.StringByID(R.MyInternationalizationString.BelongModel);
            deviceName = Common.LocalDevice.Current.GetDeviceMacName(device);
            var rowBelongModul = new FrameCaptionViewControl(caption, deviceName, listview.rowSpace / 2);
            listview.AddChidren(rowBelongModul);
            rowBelongModul.InitControl();
            //划线
            rowBelongModul.AddBottomLine();
 
            //添加【功能类型】行(主人,管理员)
            this.AddFunctionTypeRowByAdmin(btnBelongType);
 
            //初始化桌布完成
            tableContr.FinishInitControl(bodyFrameLayout, this.listview);
            tableContr = null;
 
            //保存
            var btnFinish = new BottomClickButton();
            btnFinish.TextID = R.MyInternationalizationString.uSave;
            bodyFrameLayout.AddChidren(btnFinish);
            btnFinish.ButtonClickEvent += (sender, e) =>
            {
                string oldName = LocalDevice.Current.GetDeviceEpointName(device);
                if (btnNote.Text.Trim() == string.Empty)
                {
                    btnNote.Text = oldName;
                }
                if (oldName != btnNote.Text.Trim())
                {
                    //修改名字
                    this.DeviceReName(btnNote.Text.Trim(), true);
                }
                else
                {
                    //关闭自身
                    this.CloseForm();
                }
            };
        }
 
        /// <summary>
        /// 初始化中部控件(成员)
        /// </summary>
        private void InitMiddleFrameByMember()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            //初始化桌布
            var tableContr = new InformationEditorControl();
            this.listview = tableContr.InitControl(bodyFrameLayout, Language.StringByID(R.MyInternationalizationString.uInfoEditor), 418, 1319);
 
            //图片
            var btnPic = new DeviceInfoIconControl();
            btnPic.Y = Application.GetRealHeight(92);
            btnPic.Gravity = Gravity.CenterHorizontal;
            bodyFrameLayout.AddChidren(btnPic);
            btnPic.InitControl(device.DeviceAddr, device.DeviceEpoint);
 
            //设备所属类型
            var infoType = LocalDevice.Current.GetDeviceBelongEnumInfo(device);
            var btnBelongType = new NormalViewControl(700, 62, true);
            btnBelongType.Y = btnPic.Bottom + Application.GetRealHeight(35);
            btnBelongType.Gravity = Gravity.CenterHorizontal;
            btnBelongType.TextID = infoType.BeloneTextId;
            btnBelongType.TextSize = 15;
            btnBelongType.TextAlignment = TextAlignment.Center;
            bodyFrameLayout.AddChidren(btnBelongType);
 
            //功能名称
            string caption = Language.StringByID(R.MyInternationalizationString.FunctionName);
            string nameValue = LocalDevice.Current.GetDeviceEpointName(device);
            var btnNote = new FrameCaptionViewControl(caption, nameValue, listview.rowSpace / 2);
            btnNote.UseClickStatu = false;
            listview.AddChidren(btnNote);
            btnNote.InitControl();
            //划线
            btnNote.AddBottomLine();
 
            //喜爱房间不允许出现区域
            if (this.room.IsLove == false)
            {
                //所属区域
                caption = Language.StringByID(R.MyInternationalizationString.uBelongArea);
                nameValue = HdlRoomLogic.Current.GetRoomNameByDevice(device);
                var rowBeloneArea = new FrameCaptionViewControl(caption, nameValue, listview.rowSpace / 2);
                rowBeloneArea.UseClickStatu = false;
                listview.AddChidren(rowBeloneArea);
                rowBeloneArea.InitControl();
                //划线
                rowBeloneArea.AddBottomLine();
            }
 
            //所属模块
            caption = Language.StringByID(R.MyInternationalizationString.BelongModel);
            nameValue = Common.LocalDevice.Current.GetDeviceMacName(device);
            var rowBelongModul = new FrameCaptionViewControl(caption, nameValue, listview.rowSpace / 2);
            rowBelongModul.UseClickStatu = false;
            listview.AddChidren(rowBelongModul);
            rowBelongModul.InitControl();
            //划线
            rowBelongModul.AddBottomLine();
 
            //添加【功能类型】行(成员)
            this.AddFunctionTypeRowByMember();
 
            //初始化桌布完成
            tableContr.FinishInitControl(bodyFrameLayout, this.listview);
            tableContr = null;
        }
 
        #endregion
 
        #region ■ 功能类型___________________________
 
        /// <summary>
        /// 添加【功能类型】行(主人,管理员)
        /// </summary>
        private void AddFunctionTypeRowByAdmin(NormalViewControl btnBelongType)
        {
            //如果是继电器,空气开关,调光器的话
            if (device.Type == DeviceType.OnOffOutput || device.Type == DeviceType.DimmableLight
                || device.Type == DeviceType.ColorDimmableLight || device.Type == DeviceType.AirSwitch)
            {
                //功能类型的翻译名字
                int nowSelectNo = 1;
                string strType = string.Empty;
                if (this.device.DfunctionType == DeviceFunctionType.A灯光)
                {
                    strType = Language.StringByID(R.MyInternationalizationString.uLight);
                    nowSelectNo = 1;
                }
                else if (this.device.DfunctionType == DeviceFunctionType.A开关)
                {
                    strType = Language.StringByID(R.MyInternationalizationString.uSwitch);
                    nowSelectNo = 0;
                }
                else if (this.device.DfunctionType == DeviceFunctionType.A插座)
                {
                    strType = Language.StringByID(R.MyInternationalizationString.uSocket1);
                    nowSelectNo = 2;
                }
                //功能类型
                var btnFunction = new FrameCaptionViewControl(Language.StringByID(R.MyInternationalizationString.uFunctionType), strType, listview.rowSpace / 2);
                btnFunction.UseClickStatu = false;
                listview.AddChidren(btnFunction);
                btnFunction.InitControl();
                //底线
                btnFunction.AddBottomLine();
                //如果是空气开关和继电器,才能修改
                if (device.Type == DeviceType.OnOffOutput || device.Type == DeviceType.AirSwitch)
                {
                    //右箭头
                    btnFunction.AddRightArrow();
                    btnFunction.ButtonClickEvent += (sender, e) =>
                    {
                        //显示列表
                        var listText = new List<string>();
                        listText.Add(Language.StringByID(R.MyInternationalizationString.uSwitch));//开关
                        listText.Add(Language.StringByID(R.MyInternationalizationString.uLight));//灯光
                        listText.Add(Language.StringByID(R.MyInternationalizationString.uSocket1));//插座
                        //标题:选择功能类型
                        var title = Language.StringByID(R.MyInternationalizationString.uSelectFunctionType);
 
                        var form = new BottomItemSelectForm();
                        form.AddForm(title, listText, nowSelectNo);
                        form.FinishSelectEvent += (selectNo) =>
                        {
                            btnFunction.Text = listText[selectNo];
                            //当类型变更时,头上的类型也一起变更
                            btnBelongType.Text = listText[selectNo];
                            nowSelectNo = selectNo;
                            //记录起当前选择的功能类型
                            if (selectNo == 0)
                            {
                                this.device.DfunctionType = DeviceFunctionType.A开关;
                                if (this.device.IsCustomizeImage == false)
                                {
                                    //重新设置图片
                                    this.device.IconPath = "Device/Switch.png";
                                }
                            }
                            else if (selectNo == 1)
                            {
                                this.device.DfunctionType = DeviceFunctionType.A灯光;
                                if (this.device.IsCustomizeImage == false)
                                {
                                    //重新设置图片
                                    this.device.IconPath = "Device/Light.png";
                                }
                            }
                            else
                            {
                                this.device.DfunctionType = DeviceFunctionType.A插座;
                                if (this.device.IsCustomizeImage == false)
                                {
                                    //重新设置图片
                                    this.device.IconPath = "Device/Socket1.png";
                                }
                            }
                            this.device.ReSave();
                        };
                    };
                }
            }
        }
 
        /// <summary>
        /// 添加【功能类型】行(成员)
        /// </summary>
        private void AddFunctionTypeRowByMember()
        {
            //如果是继电器,空气开关,调光器的话
            if (device.Type == DeviceType.OnOffOutput || device.Type == DeviceType.DimmableLight
                || device.Type == DeviceType.ColorDimmableLight || device.Type == DeviceType.AirSwitch)
            {
                //功能类型的翻译名字
                string strType = string.Empty;
                if (this.device.DfunctionType == DeviceFunctionType.A灯光)
                {
                    strType = Language.StringByID(R.MyInternationalizationString.uLight);
                }
                else if (this.device.DfunctionType == DeviceFunctionType.A开关)
                {
                    strType = Language.StringByID(R.MyInternationalizationString.uSwitch);
                }
                else if (this.device.DfunctionType == DeviceFunctionType.A插座)
                {
                    strType = Language.StringByID(R.MyInternationalizationString.uSocket1);
                }
 
                //功能类型
                var btnFunction = new FrameCaptionViewControl(Language.StringByID(R.MyInternationalizationString.uFunctionType), strType, listview.rowSpace / 2);
                btnFunction.UseClickStatu = false;
                listview.AddChidren(btnFunction);
                btnFunction.InitControl();
                //底线
                btnFunction.AddBottomLine();
            }
        }
 
        #endregion
 
        #region ■ 修改名字___________________________
 
        /// <summary>
        /// 设备重命名
        /// </summary>
        /// <param name="i_deviceName">deviceName.</param>
        private async void DeviceReName(string i_deviceName, bool closeForm)
        {
            //修改MAC名
            string deviceName = i_deviceName.Trim();
            var result = await LocalDevice.Current.ReName(this.device, deviceName);
            if (result == false)
            {
                return;
            }
            if (closeForm == true)
            {
                //关闭界面
                this.CloseForm();
            }
            else
            {
                //设备备注修改成功!
                string msg = Language.StringByID(R.MyInternationalizationString.uDeviceReNoteSuccess);
                this.ShowMassage(ShowMsgType.Tip, msg);
            }
        }
 
        #endregion
 
        #region ■ 界面关闭___________________________
 
        /// <summary>
        /// 界面关闭
        /// </summary>
        public override void CloseFormBefore()
        {
            this.FormCloseEvent?.Invoke(this.device, this.room);
            this.FormCloseEvent = null;
 
            base.CloseFormBefore();
        }
 
        #endregion
    }
}