xm
2019-07-16 b910cb79c9b5bcc204022a3cf9e6950f0a64dfbd
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
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.Safety
{
    /// <summary>
    /// 已经设置了的传感器的一览画面
    /// </summary>
    public class SensorDeviceSettionListForm : UserCenterCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalScrolViewLayout 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 TopLayoutMostRightView();
            btnTopIcon.UnSelectedImagePath = "Item/Add.png";
            btnTopIcon.SelectedImagePath = "Item/AddSelected.png";
            topFrameLayout.AddChidren(btnTopIcon);
            btnTopIcon.MouseUpEventHandler += (sender, e) =>
            {
                //添加新的传感器
                this.AddNewSensorDevice();
            };
 
            listView = new VerticalScrolViewLayout();
            listView.Height = bodyFrameLayout.Height;
            bodyFrameLayout.AddChidren(listView);
 
            //初始化传感器列表信息
            this.InitSensorDevicesListInfo();
        }
 
        /// <summary>
        /// 初始化传感器列表信息
        /// </summary>
        private void InitSensorDevicesListInfo()
        {
            this.listView.RemoveAll();
 
            //获取指定防区全部的传感器设备的信息
            var listInfo = Common.LocalSafeguard.Current.GetSensorDevicesInfoByZoonID(this.zoonID);
            new System.Threading.Thread(() =>
            {
                foreach (var info in listInfo)
                {
                    Application.RunOnMainThread(() =>
                    {
                        this.AddRowLayout(info);
                    });
                }
            })
            { IsBackground = true }.Start();
        }
 
        #endregion
 
        #region ■ 添加传感器行_______________________
 
        /// <summary>
        /// 添加行
        /// </summary>
        /// <param name="sensorInfo">传感器信息</param>
        private void AddRowLayout(Safeguard.ZoneDeviceListData sensorInfo)
        {
            CommonDevice device = Common.LocalDevice.Current.GetDevice(sensorInfo.MacAddr, sensorInfo.Epoint);
            if (device == null)
            {
                return;
            }
 
            var rowLayout = new RowLayout();
            rowLayout.Height = ControlCommonResourse.ListViewRowHeight;
            listView.AddChidren(rowLayout);
 
            //图标
            var btnIcon = new RowLeftIconView();
            Common.LocalDevice.Current.SetDeviceIconToControl(btnIcon, device);
            rowLayout.AddChidren(btnIcon);
 
            //设备名
            var btnDevice = new RowTopBlackView();
            btnDevice.Text = Common.LocalDevice.Current.GetDeviceEpointName(device);
            rowLayout.AddChidren(btnDevice);
 
            //房间
            var btnRoom = new RowBottomGrayView();
            btnRoom.Text = Common.Room.CurrentRoom.GetRoomNameByDevice(device);
            rowLayout.AddChidren(btnRoom);
 
            //旁路状态
            var txtStatu = new RowMostRightTextView();
            txtStatu.TextColor = UserCenterColor.Current.Red;
            rowLayout.AddChidren(txtStatu);
 
            //旁路设置
            var btnBypass = new RowBypassButton();
            if (sensorInfo.IsBypass == 1)
            {
                //已设置旁路
                txtStatu.TextID = R.MyInternationalizationString.uHadSetBypass;
                //取消旁路
                btnBypass.TextID = R.MyInternationalizationString.uCancelBypass;
            }
            rowLayout.AddLeftView(btnBypass);
            btnBypass.MouseUpEventHandler += (sender, e) =>
            {
                //设置旁路状态
                this.SetBypassStatu(sensorInfo, device);
            };
 
            //删除
            var btnDelete = new RowDeleteButton();
            rowLayout.AddRightView(btnDelete);
            btnDelete.MouseUpEventHandler += (sender, e) =>
            {
                string msg = Language.StringByID(R.MyInternationalizationString.uShowDoDeleteMsg);
                this.ShowConfirmMsg(msg, "DeleteRow", rowLayout, device);
            };
        }
 
        #endregion
 
        #region ■ 删除传感器行_______________________
 
        /// <summary>
        /// 删除行
        /// </summary>
        /// <param name="rowLayout"></param>
        /// <param name="device"></param>
        public async void DeleteRow(RowLayout rowLayout, CommonDevice device)
        {
            //开启进度条
            this.ShowProgressBar();
 
            bool result = await Common.LocalSafeguard.Current.DeleteSensorDevice(this.zoonID, new List<CommonDevice>() { device });
 
            //关闭进度条
            this.CloseProgressBar();
            if (result == false)
            {
                return;
            }
            Application.RunOnMainThread(() =>
            {
                //从画面中移除
                rowLayout.RemoveFromParent();
            });
        }
 
        #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 Common.LocalSafeguard.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();
            this.AddForm(form, list, new List<string>(), true);
            form.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddSensor));
 
            //设备选择确定
            form.ActionSelectDeviceEx += (async (listDevice) =>
            {
                if (listDevice.Count == 0)
                {
                    Application.RunOnMainThread(() =>
                    {
                        //关闭界面
                        form.CloseForm();
                    });
                    return;
                }
                //开启进度条
                this.ShowProgressBar();
                //添加设备到安防
                bool success = await Common.LocalSafeguard.Current.AddSensorDevice(this.zoonID, listDevice);
                //关闭进度条
                this.CloseProgressBar();
 
                if (success == true)
                {
                    Application.RunOnMainThread(() =>
                    {
                        //关闭界面
                        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 (Common.LocalSafeguard.Current.IsSensorDeviceExist(device) == true)
                {
                    continue;
                }
                listNew.Add(device);
            }
            return listNew;
        }
 
        #endregion
    }
}