HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2019-10-10 2ed75b8b337048e5d75e6d9ec8307633134f02fd
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
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.Safety
{
    /// <summary>
    /// 报警目标设置画面
    /// </summary>
    public class AlarmTargetSettionForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 防区ID(这个东西似乎是唯一的)
        /// </summary>
        private int zoonID = 0;
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalListControl listView = null;
        /// <summary>
        /// 底部的【添加目标】的行
        /// </summary>
        private FrameRowControl frameBottomAddRow = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_zoonID">防区ID</param>
        public void ShowForm(int i_zoonID)
        {
            this.zoonID = i_zoonID;
 
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAlarmTargetSettion));
 
            //初始化中部信息
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            //根据防区ID获取本地的报警目标列表
            var listData = HdlSafeguardLogic.Current.GetLocalAlarmTargetInfoByZoneId(this.zoonID);
            if (listData.Count == 0)
            {
                //特殊特效,如果没有报警目标的话,则显示的界面效果非常的大
                this.ShowNotAlarmTargetAppeal();
                frameBottomAddRow = null;
                return;
            }
 
            //当该防区报警时,以下目标将会响应
            var frameBack = new FrameLayout();
            frameBack.Height = Application.GetRealHeight(92);
            frameBack.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameBack);
 
            var btnTitle = new NormalViewControl(860, 49, true);
            btnTitle.X = ControlCommonResourse.XXLeft;
            btnTitle.Y = Application.GetRealHeight(35);
            btnTitle.TextSize = 12;
            btnTitle.TextColor = UserCenterColor.Current.TextGrayColor2;
            btnTitle.TextID = R.MyInternationalizationString.uTargetViewAlarmAfterZoonAlarm;
            frameBack.AddChidren(btnTitle);
 
            int maxRowCount = listData.Count;
            if (maxRowCount > 8)
            {
                //特效问题,它只能显示8个,超过8个只能用滑动
                maxRowCount = 8;
            }
            this.listView = new VerticalListControl(29);
            this.listView.Y = frameBack.Bottom;
            this.listView.BackgroundColor = UserCenterColor.Current.White;
            this.listView.Height = (ControlCommonResourse.ListViewRowHeight + Application.GetRealHeight(29)) * maxRowCount;
            bodyFrameLayout.AddChidren(this.listView);
 
            //添加底部 添加报警目标的菜单行
            this.AddBottomAlarmTargetMenu();
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                //设置中间部分信息
                this.SetMiddleInfo(listData);
            });
        }
 
        /// <summary>
        /// 设置中间部分信息
        /// </summary>
        public void SetMiddleInfo(List<Safeguard.CatActionResponseObj> listData)
        {
            if (this.Parent == null)
            {
                return;
            }
 
            //添加报警目标的明细行S
            Application.RunOnMainThread(() =>
            {
                foreach (var data in listData)
                {
                    //场景
                    if (data.Type == 1)
                    {
                        this.AddSceneRow(data);
                    }
                    //设备
                    if (data.Type == 0)
                    {
                        CommonDevice device = Common.LocalDevice.Current.GetDevice(data.DeviceAddr, data.Epoint);
                        if (device != null)
                        {
                            this.AddDeviceRow(data, device);
                        }
                    }
                }
            });
        }
 
        #endregion
 
        #region ■ 报警目标菜单行_____________________
 
        /// <summary>
        /// 显示无报警目标特效
        /// </summary>
        private void ShowNotAlarmTargetAppeal()
        {
            var frameTemp = new FrameRowControl();
            frameTemp.Height = Application.GetRealHeight(173);
            frameTemp.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameTemp);
 
            //添加目标
            var btnText = frameTemp.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uAddTarget), 400);
            btnText.TextSize = 15;
 
            //加号
            var btnAdd = frameTemp.AddMostRightEmptyIcon(58, 58);
            btnAdd.UnSelectedImagePath = "Item/Add.png";
 
            frameTemp.ButtonClickEvent += (sender, e) =>
            {
                var form = new AddAlarmTargetTypeListForm();
                form.AddForm(this.zoonID);
            };
        }
 
        /// <summary>
        /// 添加底部 添加报警目标的菜单行
        /// </summary>
        private void AddBottomAlarmTargetMenu()
        {
            //添加目标
            frameBottomAddRow = new FrameRowControl();
            frameBottomAddRow.Y = this.listView.Bottom;
            frameBottomAddRow.Height = ControlCommonResourse.ListViewRowHeight + Application.GetRealHeight(29 + 29);
            frameBottomAddRow.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameBottomAddRow);
 
            var frameTemp = new FrameRowControl();
            frameTemp.Gravity = Gravity.CenterVertical;
            frameBottomAddRow.AddChidren(frameTemp);
            var btnText = frameTemp.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uAddTarget), 400);
            btnText.TextSize = 15;
            //加号
            var btnAdd = frameTemp.AddMostRightEmptyIcon(58, 58);
            btnAdd.UnSelectedImagePath = "Item/Add.png";
            //底线
            frameTemp.AddBottomLine();
 
            frameTemp.ButtonClickEvent += (sender, e) =>
            {
                var form = new AddAlarmTargetTypeListForm();
                form.AddForm(this.zoonID);
            };
        }
 
        #endregion
 
        #region ■ 报警目标明细行_____________________
 
        /// <summary>
        /// 添加报警目标的明细行
        /// </summary>
        private void AddAlarmTargetList(List<Safeguard.CatActionResponseObj> listData)
        {
            foreach (var data in listData)
            {
                //场景
                if (data.Type == 1)
                {
                    Application.RunOnMainThread(() =>
                    {
                        if (this.Parent != null)
                        {
                            this.AddSceneRow(data);
                        }
                    });
                }
                //设备
                if (data.Type == 0)
                {
                    CommonDevice device = Common.LocalDevice.Current.GetDevice(data.DeviceAddr, data.Epoint);
                    if (device == null)
                    {
                        //本地没有这个设备的话
                        continue;
                    }
 
                    Application.RunOnMainThread(() =>
                    {
                        if (this.Parent != null)
                        {
                            this.AddDeviceRow(data, device);
                        }
                    });
                }
            }
        }
 
        /// <summary>
        /// 添加设备行
        /// </summary>
        /// <param name="data"></param>
        /// <param name="device"></param>
        private void AddDeviceRow(Safeguard.CatActionResponseObj data, CommonDevice device)
        {
            //行控件
            var row = new DeviceRoomControl(device, listView.rowSpace / 2);
            listView.AddChidren(row);
            row.InitControl();
            row.frameTable.UseClickStatu = false;
            //底线
            row.frameTable.AddBottomLine();
 
            //删除图标
            var btnDelete = row.frameTable.AddMostRightEmptyIcon(58, 58);
            btnDelete.UnSelectedImagePath = "Item/DeleteIcon1.png";
            row.frameTable.ChangedChidrenBindMode(btnDelete, ChidrenBindMode.NotBind);
            btnDelete.ButtonClickEvent += (sender, e) =>
            {
                //删除
                string msg = Language.StringByID(R.MyInternationalizationString.uShowDoDeleteMsg);
                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                {
                    //删除报警目标
                    this.DeleteAlarmTarget(row, data);
                });
            };
 
            //状态显示
            var btnStatu = row.frameTable.AddMostRightView("", 400);
            if (data.TaskList.Count > 0)
            {
                btnStatu.Text = HdlSafeguardLogic.Current.GetLightAlarmStatuText(data.TaskList);
            }
            else
            {
                //无动作
                btnStatu.TextID = R.MyInternationalizationString.uNotAction;
            }
        }
 
        /// <summary>
        /// 添加场景行
        /// </summary>
        /// <param name="data"></param>
        private void AddSceneRow(Safeguard.CatActionResponseObj data)
        {
            //行控件
            var row = new SceneRoomControl(data.ScenesId, data.ESName, listView.rowSpace / 2);
            listView.AddChidren(row);
            row.InitControl();
            row.frameTable.UseClickStatu = false;
            //底线
            row.frameTable.AddBottomLine();
 
            //删除图标
            var btnDelete = row.frameTable.AddMostRightEmptyIcon(58, 58);
            btnDelete.UnSelectedImagePath = "Item/DeleteIcon1.png";
            row.frameTable.ChangedChidrenBindMode(btnDelete, ChidrenBindMode.NotBind);
            btnDelete.ButtonClickEvent += (sender, e) =>
            {
                //删除
                string msg = Language.StringByID(R.MyInternationalizationString.uShowDoDeleteMsg);
                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                {
                    //删除报警目标
                    this.DeleteAlarmTarget(row, data);
                });
            };
        }
 
        #endregion
 
        #region ■ 删除指定报警目标___________________
 
        /// <summary>
        /// 删除指定报警目标
        /// </summary>
        /// <param name="row"></param>
        /// <param name="delObj"></param>
        private async void DeleteAlarmTarget(RowLayoutControl row, Safeguard.CatActionResponseObj delObj)
        {
            //参数
            var Pra = new List<Safeguard.DelAlarmActionObj>();
            var actionObj = new Safeguard.DelAlarmActionObj();
            actionObj.DeviceAddr = delObj.DeviceAddr;
            actionObj.Epoint = delObj.Epoint;
            actionObj.ScenesId = delObj.ScenesId;
            actionObj.Type = delObj.Type;
            Pra.Add(actionObj);
 
            //打开进度条
            this.ShowProgressBar();
 
            //执行删除
            bool result = await HdlSafeguardLogic.Current.DeleteAlarmTaget(this.zoonID, Pra);
 
            //关闭进度条
            this.CloseProgressBar();
 
            if (result == false)
            {
                return;
            }
 
            Application.RunOnMainThread(() =>
            {
                //行移除
                row?.RemoveFromParent();
                if (listView != null && listView.ChildrenCount == 0)
                {
                    //重新初始化中部信息
                    this.InitMiddleFrame();
                    return;
                }
                var realHeight = listView.ChildrenCount * listView.GetChildren(listView.ChildrenCount - 1).Height;
                if (realHeight < listView.Height)
                {
                    //缩小控件高度
                    listView.Height = realHeight;
                    //移动行控件
                    frameBottomAddRow.Y = this.listView.Bottom;
                }
            });
        }
        #endregion
 
        #region ■ 界面重新激活事件___________________
 
        /// <summary>
        /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
        /// </summary>
        public override int FormActionAgainEvent()
        {
            //重新刷新界面
            this.InitMiddleFrame();
 
            return 1;
        }
 
        #endregion
    }
}