黄学彪
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
using System;
using System.Collections.Generic;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.Safety
{
    /// <summary>
    /// 添加报警目标菜单列表的画面
    /// </summary>
    public class AddAlarmTargetTypeListForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 防区ID(这个东西似乎是唯一的)
        /// </summary>
        private int zoonID = 0;
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalListControl listView = null;
        /// <summary>
        /// 全部设备信息
        /// </summary>
        private List<uRowInformation> listAllDeviceInfo = new List<uRowInformation>();
 
        #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.uAddAlarmTarget));
 
            //初始化中部信息
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            //设置中间部分信息
            this.SetMiddleInfo();
        }
 
        /// <summary>
        /// 设置中间部分信息
        /// </summary>
        private void SetMiddleInfo()
        {
            HdlThreadLogic.Current.RunThread(() =>
            {
                //获取设备的所有类型,并整理成每一行的数据
                this.GetAllListData();
                if (listAllDeviceInfo.Count == 0)
                {
                    return;
                }
 
                Application.RunOnMainThread(() =>
                {
                    int realHeight = (ControlCommonResourse.ListViewRowHeight + Application.GetRealHeight(29)) * listAllDeviceInfo.Count + Application.GetRealHeight(23);
                    if (realHeight > bodyFrameLayout.Height + Application.GetRealHeight(6))
                    {
                        //计算真实高度
                        realHeight = bodyFrameLayout.Height + Application.GetRealHeight(6);
                    }
                    this.listView = new VerticalListControl(29);
                    listView.Y = Application.GetRealHeight(-6);
                    listView.Height = realHeight;
                    listView.BackgroundColor = UserCenterColor.Current.White;
                    bodyFrameLayout.AddChidren(this.listView);
 
                    //添加设备的行
                    int count = listAllDeviceInfo.Count - 1;
                    for (int i = 0; i < listAllDeviceInfo.Count; i++)
                    {
                        this.AddRowLaout(listAllDeviceInfo[i], i != count);
                    }
                });
            });
        }
 
        #endregion
 
        #region ■ 添加行_____________________________
 
        /// <summary>
        /// 添加行
        /// </summary>
        /// <param name="uRow"></param>
        /// <param name="addLine"></param>
        private void AddRowLaout(uRowInformation uRow, bool addLine)
        {
            var rowlayout = new FrameRowControl(listView.rowSpace / 2);
            listView.AddChidren(rowlayout);
            //图标
            var btnIcon = rowlayout.AddLeftIcon(81);
            btnIcon.UnSelectedImagePath = uRow.IconUnSelectPath;
 
            //设备名
            var txtDevice = rowlayout.AddLeftCaption(uRow.TextName, 750);
            txtDevice.Text = uRow.TextName;
            txtDevice.TextSize = 15;
            //向右图标
            rowlayout.AddRightArrow();
            if (addLine == true)
            {
                //底线
                rowlayout.AddBottomLine();
            }
 
            //单击事件
            rowlayout.ButtonClickEvent += (sender, e) =>
            {
                if (uRow.listScene == null)
                {
                    //设备的一览
                    var form = new AddDeviceAlarmTargetListForm();
                    form.AddForm(this.zoonID, uRow.TextName, uRow.listDevice);
                }
                else
                {
                    //场景的一览
                    var form = new AddSceneAlarmTargetListForm();
                    form.AddForm(this.zoonID, uRow.listScene);
                }
            };
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 获取设备的所有类型,并整理成每一行的数据
        /// </summary>
        private void GetAllListData()
        {
            Dictionary<string, uRowInformation> dic = new Dictionary<string, uRowInformation>();
            this.listAllDeviceInfo.Clear();
 
            var listDevice = Common.LocalDevice.Current.listAllDevice;
            foreach (CommonDevice device in listDevice)
            {
                //如果那个设备已经添加了,则不再显示
                if (HdlSafeguardLogic.Current.IsAlarmDeviceExist(this.zoonID, device) == true)
                {
                    continue;
                }
                if (device.Type == DeviceType.AirSwitch//空气开关
                    || device.Type == DeviceType.DimmableLight//调光器
                    || device.Type == DeviceType.ColorDimmableLight//彩灯
                    || device.Type == DeviceType.OnOffOutput//继电器
                    || device.Type == DeviceType.WindowCoveringDevice)//窗帘
                {
                    //显示文本
                    string KeysName = Common.LocalDevice.Current.GetDeviceObjectText(new List<CommonDevice>() { device });
 
                    uRowInformation infoRow = null;
                    if (dic.ContainsKey(KeysName) == false)
                    {
                        //图标地址:点亮
                        string IconSelect = string.Empty;
                        //图标地址:未点亮
                        string IconUnSelect = string.Empty;
                        Common.LocalDevice.Current.GetDeviceBeloneIcon(new List<CommonDevice>() { device }, ref IconUnSelect, ref IconSelect);
 
                        //第一次时,设置它的显示文本及设置它的图标
                        infoRow = new uRowInformation();
                        dic[KeysName] = infoRow;
                        infoRow.TextName = KeysName;
                        infoRow.IconSelectPath = IconSelect;
                        infoRow.IconUnSelectPath = IconUnSelect;
 
                        this.listAllDeviceInfo.Add(infoRow);
                    }
                    infoRow = dic[KeysName];
 
                    //设备收集
                    var info = new uDeviceInfo
                    {
                        RoomName = Shared.Common.Room.CurrentRoom.GetRoomNameByDevice(device),
                        Device = device,
                        MainKeys = device.DeviceAddr + device.DeviceEpoint.ToString()
                    };
                    infoRow.listDevice.Add(info);
                }
            }
 
            //获取场景
            Common.SceneRoomUI.GetAllSceneRoomUIList();
            List<Common.SceneRoomUI> listScene = Common.SceneRoomUI.AllSceneRoomUIList;
            if (listScene.Count == 0)
            {
                return;
            }
            //获取本地安防的场景
            Dictionary<int, string> dicScene = HdlSafeguardLogic.Current.GetLocalSceneByZoneID(this.zoonID);
 
            var SceneInfo = new uRowInformation();
            SceneInfo.listScene = new List<Common.SceneRoomUI>();
            foreach (var data in listScene)
            {
                //如果那个场景已经添加了,则不再显示
                if (dicScene.ContainsKey(data.sceneUI.Id) == true)
                {
                    continue;
                }
                SceneInfo.listScene.Add(data);
            }
            if (SceneInfo.listScene.Count > 0)
            {
                SceneInfo.TextName = Language.StringByID(R.MyInternationalizationString.uScence);
                SceneInfo.IconUnSelectPath = "Item/Scene.png";
                this.listAllDeviceInfo.Add(SceneInfo);
            }
        }
 
        #endregion
 
        #region ■ 界面重新激活事件___________________
 
        /// <summary>
        /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
        /// </summary>
        public override int FormActionAgainEvent()
        {
            //重新刷新界面
            this.InitMiddleFrame();
 
            return 1;
        }
 
        #endregion
 
        #region ■ 自定义结构体_______________________
 
        /// <summary>
        /// 每一行的行数据
        /// </summary>
        private class uRowInformation
        {
            /// <summary>
            /// 图标地址:未点亮
            /// </summary>
            public string IconUnSelectPath = string.Empty;
            /// <summary>
            /// 图标地址:点亮
            /// </summary>
            public string IconSelectPath = string.Empty;
            /// <summary>
            /// 显示的内容
            /// </summary>
            public string TextName = string.Empty;
            /// <summary>
            /// 设备列表信息
            /// </summary>
            public List<uDeviceInfo> listDevice = new List<uDeviceInfo>();
            /// <summary>
            /// 场景
            /// </summary>
            public List<Common.SceneRoomUI> listScene = null;
        }
        #endregion
    }
}