黄学彪
2020-12-17 9f326f4000847e6167d8166fa2f6a66f53cb3734
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
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.DevicePanel
{
    /// <summary>
    /// 环境面板的目标界面
    /// </summary>
    public class PanelFangyueEnvironmentTargetForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalListControl listView = null;
        /// <summary>
        /// 目标设备
        /// </summary>
        private CommonDevice deviceTarget = null;
        /// <summary>
        /// 绑定的目标的主键(只能绑定一个)
        /// </summary>
        private string bindTargetKey = null;
        /// <summary>
        /// 当前选择的楼层ID
        /// </summary>
        private string nowSelectFloorId = string.Empty;
        /// <summary>
        /// 1:空调目标  2:地暖目标  3:新风目标
        /// </summary>
        private int deviceDiv = -1;
        /// <summary>
        /// 可以显示的设备对象 (Keys:房间ID)
        /// </summary>
        private Dictionary<string, List<CommonDevice>> dicShowDevice = new Dictionary<string, List<CommonDevice>>();
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_deviceTarget">目标设备</param>
        /// <param name="i_bindTargetKey">绑定的目标的主键(只能绑定一个)</param>
        /// <param name="i_div">1:空调目标  2:地暖目标  3:新风目标</param>
        public void ShowForm(CommonDevice i_deviceTarget, string i_bindTargetKey, int i_div)
        {
            this.deviceTarget = i_deviceTarget;
            this.bindTargetKey = i_bindTargetKey;
            this.deviceDiv = i_div;
 
            if (i_div == 1)
            {
                //设置头部信息
                base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAirConditionerTarget));
            }
            else if (i_div == 2)
            {
                //设置头部信息
                base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uFloorHeatingTarget));
            }
            else if (i_div == 3)
            {
                //设置头部信息
                base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uNewWindTarget));
            }
 
            //初始化右上角的控件
            this.InitTopRightMenuControl();
 
            //初始化中部信息
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                var listRoom = HdlRoomLogic.Current.GetFloorSortRoom(this.nowSelectFloorId, false);
                var listDataRoom = new List<Common.Room>();
                for (int i = 0; i < listRoom.Count; i++)
                {
                    //检测能否显示该房间
                    if (this.CheckCanShowRoom(listRoom[i]) == true)
                    {
                        listDataRoom.Add(listRoom[i]);
                    }
                }
 
                HdlThreadLogic.Current.RunMain(() =>
                {
                    if (listDataRoom.Count > 0)
                    {
                        //初始化房间和设备列表
                        this.InitRoomAndDeviceRow(listDataRoom);
                    }
                    else
                    {
                        //如果没有可以添加的目标
                        bodyFrameLayout.RemoveAll();
                        this.ShowNotDataImage(bodyFrameLayout, Language.StringByID(R.MyInternationalizationString.uNotHadAddTarget), "Item/NotShardPic.png", 383, 279);
                    }
                });
            });
        }
 
        /// <summary>
        /// 初始化右上角的控件
        /// </summary>
        private void InitTopRightMenuControl()
        {
            //获取楼层
            var dicFloor = HdlRoomLogic.Current.GetFloorSortList();
            if (dicFloor.Count == 0)
            {
                return;
            }
            var btnIconContr = new MostRightIconControl(69, 69);
            btnIconContr.UnSelectedImagePath = "Item/Drop_Down.png";
            topFrameLayout.AddChidren(btnIconContr);
            btnIconContr.InitControl();
 
            var btnFloor = new NormalViewControl(300, 69, true);
            btnFloor.Gravity = Gravity.CenterVertical;
            btnFloor.X = btnIconContr.X + btnIconContr.btnIcon.X - Application.GetRealWidth(300);
            btnFloor.TextAlignment = TextAlignment.CenterRight;
            topFrameLayout.AddChidren(btnFloor);
 
            foreach (var floorId in dicFloor.Keys)
            {
                //第一个楼层
                this.nowSelectFloorId = floorId;
                btnFloor.Text = dicFloor[floorId];
                break;
            }
 
            btnIconContr.ButtonClickEvent += (sender, e) =>
            {
                //楼层菜单
                var contr = new TopRightMenuControl(dicFloor.Count, 2, Language.StringByID(R.MyInternationalizationString.SelectFloor));
                foreach (var floorId in dicFloor.Keys)
                {
                    contr.AddRowMenu(dicFloor[floorId], "Floor/Floor.png", "Floor/FloorSelected.png", () =>
                    {
                        //记录起选择的ID
                        this.nowSelectFloorId = floorId;
                        this.bindTargetKey = string.Empty;
 
                        btnFloor.Text = dicFloor[this.nowSelectFloorId];
                        //初始化中部信息
                        this.InitMiddleFrame();
                    });
                }
            };
        }
 
        #endregion
 
        #region ■ 房间和设备列表_____________________
 
        /// <summary>
        /// 初始化房间和设备列表
        /// </summary>
        /// <param name="listRoom">可以显示的房间对象</param>
        private void InitRoomAndDeviceRow(List<Common.Room> listRoom)
        {
            //房间列表控件
            var roomContr = new RoomDeviceGroupMenuControl(listRoom);
            bodyFrameLayout.AddChidren(roomContr);
 
            //列表控件
            this.listView = new VerticalListControl(23);
            listView.BackgroundColor = UserCenterColor.Current.White;
            listView.Height = bodyFrameLayout.Height - roomContr.Height;
            listView.Y = roomContr.Bottom;
            bodyFrameLayout.AddChidren(listView);
 
            //保存
            var btnSave = new BottomClickButton();
            btnSave.TextID = R.MyInternationalizationString.uSave;
            bodyFrameLayout.AddChidren(btnSave);
            btnSave.ButtonClickEvent += (sender, e) =>
            {
                //保存目标设备
                this.SaveTargetDevice();
            };
 
            roomContr.SelectRoomEvent += (selectRoom) =>
            {
                HdlThreadLogic.Current.RunMainInThread(() =>
                {
                    //添加设备行
                    this.AddDeviceRow(selectRoom.Id);
                });
            };
            //执行初始化房间控件
            roomContr.InitControl();
        }
 
        /// <summary>
        /// 添加设备行
        /// </summary>
        /// <param name="roomId"></param>
        private void AddDeviceRow(string roomId)
        {
            //先清空
            this.listView.RemoveAll();
            listView.RecoverHeight();
 
            DeviceSimpleSelectControl oldSelectContr = null;
            var listDevice = this.dicShowDevice[roomId];
            for (int i = 0; i < listDevice.Count; i++)
            {
                string mainKey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(listDevice[i]);
                var contr = new DeviceSimpleSelectControl(listDevice[i], false, this.listView.rowSpace / 2);
                listView.AddChidren(contr);
                contr.InitControl();
                if (i != listDevice.Count - 1)
                {
                    //底线
                    contr.AddBottomLine();
                }
                contr.ButtonClickEvent += (sender, e) =>
                {
                    contr.IsSelected = !contr.IsSelected;
                    //选择了别的设备
                    if (contr.IsSelected == true)
                    {
                        if (oldSelectContr != null)
                        {
                            oldSelectContr.IsSelected = false;
                        }
                        oldSelectContr = contr;
                        this.bindTargetKey = mainKey;
                    }
                    //取消选择
                    else
                    {
                        oldSelectContr = null;
                        this.bindTargetKey = string.Empty;
                    }
                };
                if (this.bindTargetKey == mainKey)
                {
                    //这个是它之前绑定的设备
                    contr.ButtonClickEvent(null, null);
                }
            }
            //调整真实高度
            listView.AdjustRealHeightByBottomButton(Application.GetRealHeight(23));
        }
 
        #endregion
 
        #region ■ 保存数据___________________________
 
        /// <summary>
        /// 保存目标设备
        /// </summary>
        private void SaveTargetDevice()
        {
            this.CloseForm();
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 检测该房间能否显示
        /// </summary>
        /// <param name="room"></param>
        /// <param name="i_div"></param>
        /// <returns></returns>
        private bool CheckCanShowRoom(Common.Room room)
        {
            bool canShow = false;
            //先清空
            this.dicShowDevice[room.Id] = new List<CommonDevice>();
 
            foreach (var deviceKeys in room.ListDevice)
            {
                var device = HdlDeviceCommonLogic.Current.GetDevice(deviceKeys);
                if (device != null)
                {
                    canShow = true;
                    //收集可以显示的设备
                    this.dicShowDevice[room.Id].Add(device);
                }
            }
            return canShow;
        }
 
        #endregion
    }
}