HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2020-09-22 ade5917841b0fdcb1df7353ef7c56b1a1bdc9282
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
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 FormCloseEvent = null;
        /// <summary>
        /// 设备对象
        /// </summary>
        private CommonDevice device;
        /// <summary>
        /// 房间对象(这个房间有可能是喜爱,有可能是null)
        /// </summary>
        private Room room = null;
        /// <summary>
        /// 列表控件
        /// </summary>
        private FrameListControl 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 listBackControl = new VerticalFrameControl();
            listBackControl.Height = bodyFrameLayout.Height;
            bodyFrameLayout.AddChidren(listBackControl);
 
            //初始化桌布
            var tableContr = new InformationEditorControl();
            this.listview = tableContr.InitControl(listBackControl.frameTable, Language.StringByID(R.MyInternationalizationString.uInfoEditor), 1319);
 
            //图片
            var btnPic = new DeviceInfoIconControl();
            btnPic.Y = Application.GetRealHeight(46);
            btnPic.Gravity = Gravity.CenterHorizontal;
            listBackControl.frameTable.AddChidren(btnPic);
            btnPic.InitControl(device.DeviceAddr, device.DeviceEpoint);
            btnPic.ButtonClickEvent += (sender, e) =>
            {
                var form = new SelectLocalDeviceImageForm();
                form.AddForm();
                form.FinishSelectEvent = (unSelectedImagePath) =>
                {
                    //变更图片
                    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;
            listBackControl.frameTable.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 == null || 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.BelongDevice);
            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();
            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 listBackControl = new VerticalFrameControl();
            listBackControl.Height = bodyFrameLayout.Height;
            bodyFrameLayout.AddChidren(listBackControl);
 
            //初始化桌布
            var tableContr = new InformationEditorControl();
            this.listview = tableContr.InitControl(listBackControl.frameTable, Language.StringByID(R.MyInternationalizationString.uInfoEditor), 1319);
 
            //图片
            var btnPic = new DeviceInfoIconControl();
            btnPic.Y = Application.GetRealHeight(92);
            btnPic.Gravity = Gravity.CenterHorizontal;
            listBackControl.frameTable.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;
            listBackControl.frameTable.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 == null || 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.BelongDevice);
            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();
            tableContr = null;
        }
 
        #endregion
 
        #region ■ 功能类型___________________________
 
        /// <summary>
        /// 添加【功能类型】行(主人,管理员)
        /// </summary>
        private void AddFunctionTypeRowByAdmin(NormalViewControl btnBelongType)
        {
            //自定义功能类型控件
            var rowFunction = new DeviceFunctionTypeRowControl(device, listview.rowSpace / 2);
            if (rowFunction.CanShowRow == true)
            {
                listview.AddChidren(rowFunction);
                rowFunction.InitControl();
                //底线
                rowFunction.AddBottomLine();
                rowFunction.FinishSelectEvent += (index) =>
                {
                    //当类型变更时,头上的类型也一起变更
                    btnBelongType.Text = rowFunction.Text;
                };
            }
        }
 
        /// <summary>
        /// 添加【功能类型】行(成员)
        /// </summary>
        private void AddFunctionTypeRowByMember()
        {
            //自定义功能类型控件
            var rowFunction = new DeviceFunctionTypeRowControl(device, listview.rowSpace / 2);
            if (rowFunction.CanShowRow == true)
            {
                //强制干涉不能选择
                rowFunction.SetCanSelect = false;
                listview.AddChidren(rowFunction);
                rowFunction.InitControl();
                //底线
                rowFunction.AddBottomLine();
            }
        }
 
        #endregion
 
        #region ■ 修改名字___________________________
 
        /// <summary>
        /// 设备重命名
        /// </summary>
        /// <param name="i_deviceName">deviceName.</param>
        private void DeviceReName(string i_deviceName, bool closeForm)
        {
            //修改MAC名
            string deviceName = i_deviceName.Trim();
            var result = 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.FormCloseEvent = null;
 
            base.CloseFormBefore();
        }
 
        #endregion
    }
}