wxr
2023-06-06 592974441a4df95fffd9167c90192da1a390b1c2
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
using HDL_ON.Entity;
using Shared;
using System;
using System.Collections.Generic;
using System.Text;
 
namespace HDL_ON
{
    /// <summary>
    /// 楼层及房间的选择界面
    /// </summary>
    public class FloorRoomSelectPopupView
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 当前选择显示的UID(楼层,或者房间,或者全部)
        /// </summary>
        private string nowShowSelectId = DiySelectPopupDialog.ALLSELECT;
        /// <summary>
        /// 全部的功能(设备显示分支使用)
        /// </summary>
        private List<Function> listAllFun = null;
 
        #endregion
 
        #region ■ 场景显示___________________________
 
        /// <summary>
        /// 显示选择场景的界面
        /// </summary>
        /// <param name="btnFloor">楼层名字显示的控件,选择后,内部会自动变更显示文字,可以设置为null</param>
        /// <param name="SelectEvent">根据选择的条件,筛选之后的场景列表(第一个参数是选择的UID,不管有没有用,总之先返回)</param>
        /// <param name="i_defultSelectId">默认哪个为选择状态</param>
        public void ShowSceneView(Button btnFloor, Action<string, List<Scene>> SelectEvent, string i_defultSelectId = null)
        {
            //清缓存
            this.ClearMemory();
 
            if (string.IsNullOrEmpty(i_defultSelectId) == true)
            {
                i_defultSelectId = DiySelectPopupDialog.ALLSELECT;
            }
 
            //返回的id是UID
            new FloorSelectPopupDialog().ShowView((selectValue) =>
            {
                this.nowShowSelectId = selectValue;
                //刷新楼层的显示名字
                this.RefreshFloorShowName(btnFloor);
 
                //获取可以显示的场景列表
                var listScene = this.GetCanShowListScene();
                SelectEvent?.Invoke(this.nowShowSelectId, listScene);
                SelectEvent = null;
 
            }, i_defultSelectId);
        }
 
        /// <summary>
        /// 获取能够显示的场景
        /// </summary>
        /// <returns></returns>
        public List<Scene> GetCanShowListScene()
        {
            var listScene = new List<Scene>();
 
            //先看看当前选择的显示类型 1:全部 2:楼层 3:房间
            var selectType = this.CheckSelectFloorIdType();
            if (selectType == 1)
            {
                return FunctionList.List.scenes;
            }
 
            //房间的UID (key:uid value:roomId)
            var dicRoomUid = new Dictionary<string, string>();
            foreach (var roomInfo in SpatialInfo.CurrentSpatial.RoomList)
            {
                dicRoomUid[roomInfo.uid] = roomInfo.roomId;
            }
            //房间
            if (selectType == 3)
            {
                //用UID转换为roomId
                string roomId = dicRoomUid.ContainsKey(this.nowShowSelectId) == true ? dicRoomUid[this.nowShowSelectId] : string.Empty;
                foreach (var scene in FunctionList.List.scenes)
                {
                    //判断这个场景是否是这个房间的
                    if (scene.roomIds.Contains(roomId) == true)
                    {
                        listScene.Add(scene);
                    }
                }
            }
            //楼层
            else if (selectType == 2)
            {
                //获取这个楼层下面的全部房间ID
                var listRoomId = new List<string>();
                foreach (var roomInfo in SpatialInfo.CurrentSpatial.RoomList)
                {
                    //判断是不是这个楼层的
                    if (roomInfo.parentId == this.nowShowSelectId)
                    {
                        listRoomId.Add(roomInfo.roomId);
                    }
                }
                foreach (var scene in FunctionList.List.scenes)
                {
                    //判断这个场景是否是这个房间的
                    foreach (var roomid in listRoomId)
                    {
                        if (scene.roomIds.Contains(roomid) == true)
                        {
                            listScene.Add(scene);
                        }
                    }
                }
            }
            return listScene;
        }
 
        #endregion
 
        #region ■ 设备显示___________________________
 
        /// <summary>
        /// 显示选择场景的界面
        /// </summary>
        /// <param name="btnFloor">楼层名字显示的控件,选择后,内部会自动变更显示文字,可以设置为null</param>
        /// <param name="i_listAllFun">全部的设备列表,需要手动指定</param>
        /// <param name="SelectEvent">根据选择的条件,筛选之后的设备列表(第一个参数是选择的UID,不管有没有用,总之先返回)</param>
        /// <param name="i_defultSelectId">默认哪个为选择状态</param>
        public void ShowDeviceFunctionView(Button btnFloor, List<Function> i_listAllFun, Action<string, List<Function>> SelectEvent, string i_defultSelectId = null, int offsetY = 0)
        {
            //清缓存
            this.ClearMemory();
            this.listAllFun = new List<Function>();
            this.listAllFun.AddRange(i_listAllFun);
 
            if (string.IsNullOrEmpty(i_defultSelectId) == true)
            {
                i_defultSelectId = DiySelectPopupDialog.ALLSELECT;
            }
 
            //返回的id是UID
            new FloorSelectPopupDialog().ShowView((selectValue) =>
            {
                this.nowShowSelectId = selectValue;
                //刷新楼层的显示名字
                this.RefreshFloorShowName(btnFloor);
 
                //获取可以显示的设备列表
                var listDevice = this.GetCanShowListDevice();
                SelectEvent?.Invoke(this.nowShowSelectId, listDevice);
                SelectEvent = null;
 
            }, i_defultSelectId, offsetY);
        }
 
        /// <summary>
        /// 获取能够显示的设备
        /// </summary>
        /// <returns></returns>
        public List<Function> GetCanShowListDevice()
        {
            var listFunction = new List<Function>();
 
            //先看看当前选择的显示类型 1:全部 2:楼层 3:房间
            var selectType = this.CheckSelectFloorIdType();
            if (selectType == 1)
            {
                return this.listAllFun;
            }
 
            //房间的UID (key:uid value:roomId)
            var dicRoomUid = new Dictionary<string, string>();
            foreach (var roomInfo in SpatialInfo.CurrentSpatial.RoomList)
            {
                dicRoomUid[roomInfo.uid] = roomInfo.roomId;
            }
            //房间
            if (selectType == 3)
            {
                //用UID转换为roomId
                string roomId = dicRoomUid.ContainsKey(this.nowShowSelectId) == true ? dicRoomUid[this.nowShowSelectId] : string.Empty;
                foreach (var func in this.listAllFun)
                {
                    //判断这个场景是否是这个房间的
                    if (func.roomIds.Contains(roomId) == true)
                    {
                        listFunction.Add(func);
                    }
                }
            }
            //楼层
            else if (selectType == 2)
            {
                //获取这个楼层下面的全部房间ID
                var listRoomId = new List<string>();
                foreach (var roomInfo in SpatialInfo.CurrentSpatial.RoomList)
                {
                    //判断是不是这个楼层的
                    if (roomInfo.parentId == this.nowShowSelectId)
                    {
                        listRoomId.Add(roomInfo.roomId);
                    }
                }
                foreach (var func in this.listAllFun)
                {
                    //判断这个场景是否是这个房间的
                    foreach (var roomid in listRoomId)
                    {
                        if (func.roomIds.Contains(roomid) == true)
                        {
                            listFunction.Add(func);
                        }
                    }
                }
            }
            return listFunction;
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 刷新楼层的显示名字
        /// </summary>
        /// <param name="btnFloorName"></param>
        private void RefreshFloorShowName(Button btnFloorName)
        {
            if (btnFloorName == null)
            {
                return;
            }
            //先看看当前选择的显示类型 1:全部 2:楼层 3:房间
            var selectType = this.CheckSelectFloorIdType();
            if (selectType == 1)
            {
                //全部
                btnFloorName.Text = Language.StringByID(StringId.All);
                //btnFloorName.Width = btnFloorName.GetTextWidth();
            }
            //房间
            else if (selectType == 3)
            {
                foreach (var roomInfo in SpatialInfo.CurrentSpatial.RoomList)
                {
                    if (roomInfo.uid == this.nowShowSelectId)
                    {
                        btnFloorName.Text = roomInfo.floorName + roomInfo.roomName;
                        //btnFloorName.Width = btnFloorName.GetTextWidth();
                        return;
                    }
                }
            }
            //楼层
            else if (selectType == 2)
            {
                foreach (var floorInfo in SpatialInfo.CurrentSpatial.FloorList)
                {
                    if (floorInfo.uid == this.nowShowSelectId)
                    {
                        btnFloorName.Text = floorInfo.roomName;
                        //btnFloorName.Width = btnFloorName.GetTextWidth();
                    }
                }
            }
        }
 
        /// <summary>
        /// 判断当前所选的ID的类型 1:全部 2:楼层 3:房间
        /// </summary>
        /// <returns></returns>
        private int CheckSelectFloorIdType()
        {
            if (this.nowShowSelectId == DiySelectPopupDialog.ALLSELECT)
            {
                //全部
                return 1;
            }
            foreach (var floorInfo in SpatialInfo.CurrentSpatial.FloorList)
            {
                if (floorInfo.uid == this.nowShowSelectId)
                {
                    //当前选择的是楼层ID
                    return 2;
                }
            }
            //不出意外,应该是房间了
            return 3;
        }
 
        /// <summary>
        /// 清除缓存
        /// </summary>
        public void ClearMemory()
        {
            //初始值
            this.nowShowSelectId = DiySelectPopupDialog.ALLSELECT;
            this.listAllFun = null;
        }
 
        #endregion
    }
}