黄学彪
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
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.Safety
{
    /// <summary>
    /// 已经设置了的传感器的一览画面
    /// </summary>
    public class GarrisonAreaExistSensorForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalListControl listView = null;
        /// <summary>
        /// 防区ID
        /// </summary>
        private int zoonID = 0;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="SectorsName">防区名字</param>
        /// <param name="i_zoonID">防区ID</param>
        public void ShowForm(string SectorsName, int i_zoonID)
        {
            this.zoonID = i_zoonID;
 
            //设置头部信息
            base.SetTitleText(SectorsName + Language.StringByID(R.MyInternationalizationString.uSettion));
 
            //右上角的“+”图标
            var btnTopIcon = new MostRightIconControl(69, 69);
            btnTopIcon.UnSelectedImagePath = "Item/Add.png";
            topFrameLayout.AddChidren(btnTopIcon);
            btnTopIcon.InitControl();
            btnTopIcon.ButtonClickEvent += (sender, e) =>
            {
                //添加新的传感器
                this.AddNewSensorDevice();
            };
 
            //初始化传感器列表信息
            this.InitSensorDevicesListInfo();
        }
 
        /// <summary>
        /// 初始化传感器列表信息
        /// </summary>
        private void InitSensorDevicesListInfo()
        {
            //清空bodyFrameLayout
            this.ClearBodyFrame();
 
            //获取指定防区全部的传感器设备的信息
            var listInfo = HdlSafeguardLogic.Current.GetSensorDevicesInfoByZoonID(this.zoonID);
            if (listInfo.Count == 0)
            {
                //还没有设置传感器哦
                this.ShowNotDataImage(bodyFrameLayout, Language.StringByID(R.MyInternationalizationString.uDoNotHadSettionSensorMsg));
                this.listView = null;
                return;
            }
 
            listView = new VerticalListControl(29);
            listView.Y = Application.GetRealHeight(-6);
            listView.Height = bodyFrameLayout.Height + Application.GetRealHeight(6);
            listView.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(listView);
 
            HdlThreadLogic.Current.RunMainInThread(() =>
            {
                int count = listInfo.Count - 1;
                for (int i = 0; i < listInfo.Count; i++)
                {
                    this.AddRowLayout(listInfo[i], i != count);
                }
                //调整列表控件的高度
                this.listView.AdjustRealHeight(Application.GetRealHeight(23));
            });
        }
 
        #endregion
 
        #region ■ 添加传感器行_______________________
 
        /// <summary>
        /// 添加行
        /// </summary>
        /// <param name="sensorInfo">传感器信息</param>
        /// <param name="addLine">是否添加底线</param>
        private void AddRowLayout(Safeguard.ZoneDeviceListData sensorInfo, bool addLine)
        {
            CommonDevice device = Common.LocalDevice.Current.GetDevice(sensorInfo.MacAddr, sensorInfo.Epoint);
            if (device == null)
            {
                return;
            }
            //自定义控件
            var rowLayout = new DeviceRoomControl(device, listView.rowSpace / 2);
            listView.AddChidren(rowLayout);
            rowLayout.InitControl();
            rowLayout.frameTable.UseClickStatu = false;
            if (addLine == true)
            {
                //底线
                rowLayout.frameTable.AddBottomLine();
            }
            //旁路状态
            var txtStatu = rowLayout.frameTable.AddMostRightView("", 350);
            txtStatu.TextColor = UserCenterColor.Current.TextGrayColor1;
 
            //旁路设置
            var btnBypass = new NormalViewControl(Application.GetRealWidth(184), rowLayout.Height, false);
            btnBypass.TextID = R.MyInternationalizationString.uBypass;
            btnBypass.BackgroundColor = 0xff4a4a4a;
            btnBypass.TextColor = UserCenterColor.Current.TextColor3;
            btnBypass.TextAlignment = TextAlignment.Center;
            btnBypass.TextSize = 12;
            if (sensorInfo.IsBypass == 1)
            {
                //已设置旁路
                txtStatu.TextID = R.MyInternationalizationString.uHadSetBypass;
                //取消旁路
                btnBypass.TextID = R.MyInternationalizationString.uCancelBypass;
            }
            rowLayout.AddLeftView(btnBypass);
            btnBypass.ButtonClickEvent += (sender, e) =>
            {
                //设置旁路状态
                this.SetBypassStatu(sensorInfo, device);
            };
 
            //删除
            var btnDelete = new NormalViewControl(Application.GetRealWidth(184), rowLayout.Height, false);
            btnDelete.TextID = R.MyInternationalizationString.uDelete;
            btnDelete.BackgroundColor = 0xfff75858;
            btnDelete.TextColor = UserCenterColor.Current.TextColor3;
            btnDelete.TextAlignment = TextAlignment.Center;
            btnDelete.TextSize = 12;
            rowLayout.AddRightView(btnDelete);
            btnDelete.ButtonClickEvent += (sender, e) =>
            {
                //确认是否要删除?
                string msg = Language.StringByID(R.MyInternationalizationString.uShowDoDeleteMsg);
                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                {
                    //删除传感器行
                    this.DeleteRow(rowLayout, device);
                });
            };
        }
 
        #endregion
 
        #region ■ 删除传感器行_______________________
 
        /// <summary>
        /// 删除行
        /// </summary>
        /// <param name="rowLayout"></param>
        /// <param name="device"></param>
        private async void DeleteRow(DeviceRoomControl rowLayout, CommonDevice device)
        {
            bool result = await HdlSafeguardLogic.Current.DeleteSensorDevice(this.zoonID, new List<CommonDevice>() { device });
 
            if (result == false)
            {
                return;
            }
            //从画面中移除
            rowLayout?.RemoveFromParent();
            //调整列表控件的高度
            this.listView.AdjustRealHeight(Application.GetRealHeight(23));
            if (this.listView.ChildrenCount == 0)
            {
                //初始化传感器列表信息
                this.InitSensorDevicesListInfo();
            }
        }
 
        #endregion
 
        #region ■ 旁路设置___________________________
 
        /// <summary>
        /// 设置旁路状态
        /// </summary>
        /// <param name="sensorInfo">传感器信息</param>
        /// <param name="device">传感器设备</param>
        private async void SetBypassStatu(Safeguard.ZoneDeviceListData sensorInfo, CommonDevice device)
        {
            //变更状态
            int statu = sensorInfo.IsBypass == 1 ? 0 : 1;
 
            bool result = await HdlSafeguardLogic.Current.SetByPassStatuToSafety(this.zoonID, device, statu);
            if (result == false)
            {
                return;
            }
            //变更状态
            sensorInfo.IsBypass = statu;
 
            this.InitSensorDevicesListInfo();
        }
 
        #endregion
 
        #region ■ 添加新的传感器_____________________
 
        /// <summary>
        /// 添加新的传感器
        /// </summary>
        private void AddNewSensorDevice()
        {
            //获取能够添加的传感器
            var list = this.GetCanAddSensorDevice();
 
            //显示选择界面
            var form = new SelectDeviceForm();
            form.AddForm(list, new List<string>(), true, false);
            form.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddSensor));
 
            //设备选择确定
            form.ActionSelectDeviceEx += (async (listDevice) =>
            {
                if (listDevice.Count == 0)
                {
                    //关闭界面
                    form.CloseForm();
                    return;
                }
                //添加设备到安防
                bool success = await HdlSafeguardLogic.Current.AddSensorDevice(this.zoonID, listDevice);
                if (success == true)
                {
                    //关闭界面
                    form.CloseForm();
                    //刷新列表
                    this.InitSensorDevicesListInfo();
                }
            });
        }
 
        /// <summary>
        /// 获取能够添加的传感器
        /// </summary>
        /// <returns></returns>
        private List<CommonDevice> GetCanAddSensorDevice()
        {
            List<CommonDevice> listNew = new List<CommonDevice>();
            List<CommonDevice> listDevices = Common.LocalDevice.Current.listAllDevice;
            foreach (CommonDevice device in listDevices)
            {
                //只要传感器
                if (device.Type != DeviceType.IASZone)
                {
                    continue;
                }
                //如果那个设备已经添加了,则不再显示
                if (HdlSafeguardLogic.Current.IsSensorDeviceExist(device) == true)
                {
                    continue;
                }
                listNew.Add(device);
            }
            return listNew;
        }
 
        #endregion
    }
}