wxr
2020-12-18 5ea6aa8ea047d4d7b6137fa86c03109aeb1b67ff
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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
using System;
using HDL_ON.UI.CSS;
using Shared;
using HDL_ON.Entity;
using System.Collections.Generic;
using HDL_ON.DAL;
using HDL_ON.DAL.Server;
 
namespace HDL_ON.UI
{
    /// <summary>
    /// 成员权限管理页面
    /// </summary>
    public partial class MemberPermissionPage : FrameLayout
    {
        MemberPermissionPage bodyView;
        Button btnDelMember;
        VerticalScrolViewLayout roomListView;
 
        ResidenceMemberInfo memberInfo;
 
        Action backAction;
 
        public MemberPermissionPage(ResidenceMemberInfo mInfo,Action action)
        {
            bodyView = this;
            memberInfo = mInfo;
            backAction = action;
        }
 
        public void LoadPage()
        {
            bodyView.BackgroundColor = CSS_Color.BackgroundColor;
            new TopViewDiv(bodyView, Language.StringByID(StringId.MemberPermissionManagement)).LoadTopView();
 
            FrameLayout headPortraitView = new FrameLayout()
            {
                Y = Application.GetRealHeight(64),
                Height = Application.GetRealHeight(66),
                BackgroundColor = CSS_Color.MainBackgroundColor,
            };
            bodyView.AddChidren(headPortraitView);
 
            ImageView userHeadImageView = new ImageView()
            {
                X = Application.GetRealWidth(16),
                Gravity = Gravity.CenterVertical,
                Width = Application.GetRealWidth(42),
                Height = Application.GetRealWidth(42),
                Radius = (uint)Application.GetRealWidth(21),
                ImagePath = memberInfo.headImagePagePath
            };
            headPortraitView.AddChidren(userHeadImageView);
 
            Button btnMemberName = new Button()
            {
                X = Application.GetRealWidth(70),
                Width = Application.GetRealWidth(300),
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.TextFontSize,
                //Text = memberInfo.nickName + "(" + memberInfo.UserName + ")",
            };
            headPortraitView.AddChidren(btnMemberName);
            string username = HDLCommon.Current.GetUserName(memberInfo.memberName);
            btnMemberName.Text = memberInfo.nickName + "(" + username + ")";
 
            #region RoomList
            roomListView = new VerticalScrolViewLayout()
            {
                Y = Application.GetRealHeight(138),
                Height = Application.GetRealHeight(471),
                //BackgroundColor = CSS_Color.MainBackgroundColor,
            };
            bodyView.AddChidren(roomListView);
            #endregion
 
            btnDelMember = new Button()
            {
                Y = Application.GetRealHeight(617),
                //Height = MainPage.Increase ? Application.GetRealHeight(70) : Application.GetRealHeight(50),
                Height = Application.GetRealHeight(50),
                TextAlignment = TextAlignment.Center,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextColor = CSS_Color.WarningColor,
                TextID = StringId.RemoveTheMember,
                BackgroundColor = CSS_Color.MainBackgroundColor,
            };
            bodyView.AddChidren(btnDelMember);
 
            LoadEventList();
 
            GetShareDataByAccount();
        }
 
        /// <summary>
        /// 加载房间列表,统计分享的数据
        /// </summary>
        void ShowRoomListView()
        {
            roomListView.RemoveAll();
 
            var titleView = new FrameLayout()
            {
                BackgroundColor = CSS_Color.MainBackgroundColor,
                Height = Application.GetRealWidth(44),
            };
            roomListView.AddChidren(titleView);
 
            var btnTitle = new Button()
            {
                X = Application.GetRealWidth(16),
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextID = StringId.UseArea,
            };
            titleView.AddChidren(btnTitle);
 
            var btnLine = new Button()
            {
                X = Application.GetRealWidth(16),
                Y = titleView.Height - Application.GetRealHeight(2),
                Width = Application.GetRealWidth(360),
                Height = Application.GetRealHeight(1),
                BackgroundColor = CSS_Color.DividingLineColor,
            };
            titleView.AddChidren(btnLine);
 
            //---------------------------------------------
            //未分配区域的功能
            List<Function> allFunctionList = FunctionList.List.GetDeviceFunctionList();
            //未分配区域的功能
            List<Function> unallocatedList = new List<Function>();
            //
            foreach (var function in allFunctionList)
            {
                function.roomIds.Remove(null);
                if (function.roomIds.Count > 0)
                {
                    //allocatedList.Add(function);
                }
                else
                {
                    unallocatedList.Add(function);
                }
            }
 
            //移除当前住宅已经不存在的功能
            for (int i = 0; i < memberInfo.CurResidenceShareData.Count;)
            {
                var sd = memberInfo.CurResidenceShareData[i];
                if (allFunctionList.Find((obj) => obj.deviceId == sd.shareTypeId) == null)
                {
                    //new DAL.Server.HttpServerRequest().DeleteShareData(sd);
                    //待确认是否同步云端删除分享
                    memberInfo.CurResidenceShareData.Remove(sd);
                }
                else
                {
                    i++;
                }
            }
 
            try
            {
                //遍历加载房间分享个数统计状态RowLayout
                foreach (var room in SpatialInfo.CurrentSpatial.RoomList)
                {
                    AddRoomFunctionRowLayout(room);
                }
                //2020-12-16 加载未分配区域功能RowLayout
                AddNoAreaFunctionRowLayout(unallocatedList);
            }
            catch
            {
                Utlis.WriteLine("AddRoomFunctionRowLayout error");
            }
        }
 
        /// <summary>
        /// 添加房间分享个数统计状态的RowLayout
        /// </summary>
        /// <param name="mRoom"></param>
        void AddRoomFunctionRowLayout(Room mRoom)
        {
            ShowBaseRoomFunOrNoAreaFunRowLayout(mRoom, null);
        }
 
        /// <summary>
        /// 添加未分配区域功能 的个数统计状态的RowLayout
        /// </summary>
        /// <param name="unallocatedList">未分配的所有功能列表</param>
        void AddNoAreaFunctionRowLayout(List<Function> unallocatedList)
        {
            ShowBaseRoomFunOrNoAreaFunRowLayout(null, unallocatedList);
        }
 
        /// <summary>
        /// 2020-12-17 重新调整
        /// 添加房间分享或者无区域分配 个数统计状态的RowLayout
        /// </summary>
        /// <param name="room">如果房间为空,代表管理无分配区域</param>
        /// <param name="unallocatedList">管理无分配区域才有效</param>
        void ShowBaseRoomFunOrNoAreaFunRowLayout(Room mRoom, List<Function> unallocatedList)
        {
            /// 当前房间或者无分配区域分享列表
            List<ShareData> funs_RoomAll = new List<ShareData>();
            /// <summary>
            /// 房间或者无分配区域所有功能列表
            /// </summary>
            List<Function> roomFunctionList = new List<Function>();
            /// 房间ID
            string roomId = "";
 
            var roomView = new RowLayout()
            {
                Height = Application.GetRealWidth(50),
                BackgroundColor = CSS_Color.MainBackgroundColor,
                LineColor = CSS_Color.MainBackgroundColor,
            };
            roomListView.AddChidren(roomView);
 
            var btnRoomName = new Button()
            {
                X = Application.GetRealWidth(16),
                Y = Application.GetRealWidth(4),
                Width = Application.GetRealWidth(330),
                Height = Application.GetRealWidth(24),
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.TextFontSize,
                //Text = room.roomName,
            };
            roomView.AddChidren(btnRoomName);
 
           
 
            var btnFunctionCount = new Button()
            {
                X = Application.GetRealWidth(16),
                Y = btnRoomName.Bottom,
                Width = Application.GetRealWidth(330),
                Height = Application.GetRealWidth(18),
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = CSS_Color.PromptingColor1,
                TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel,
                //Text = addCount + "/" + room.GetRoomFunctions(false).Count.ToString(),
            };
            roomView.AddChidren(btnFunctionCount);
 
            var btnRight = new Button()
            {
                X = Application.GetRealWidth(351),
                Gravity = Gravity.CenterVertical,
                Width = Application.GetMinRealAverage(16),
                Height = Application.GetMinRealAverage(16),
                UnSelectedImagePath = "Public/Right.png",
            };
            roomView.AddChidren(btnRight);
 
            //如果房间为空,代表管理无分配区域
            if (mRoom != null)
            {
                //显示房间名
                btnRoomName.Text = mRoom.roomName;
                roomFunctionList = mRoom.GetRoomFunctions(false);
                roomId = mRoom.roomId;
                //添加分割线
                var lineView = new LineView(roomView.Height - Application.GetRealHeight(1));
                roomView.AddChidren(lineView);
            }
            else
            {
                //显示无区域功能
                btnRoomName.TextID = StringId.NoAreaFunction;
                roomFunctionList = unallocatedList;
                roomId = null;
            }
 
            //删除按钮
            var deleteBtn = new Button()
            {
                TextID = StringId.Del,
                BackgroundColor = CSS_Color.AuxiliaryColor2,
                TextColor = CSS_Color.MainBackgroundColor,
                TextSize = CSS_FontSize.TextFontSize,
            };
            roomView.AddRightView(deleteBtn);
            deleteBtn.MouseUpEventHandler = (sender, e) =>
            {
                //一键删除所有分享
                DeleteRoomAllShare(funs_RoomAll, roomFunctionList, roomId, btnFunctionCount, roomView);
            };
 
            //计算已经加入房间的设备数量的Action事件
            Action RefreshAction = () => {
                funs_RoomAll = new List<ShareData>();
                int addCount = 0;
                foreach (var sd in memberInfo.CurResidenceShareData)
                {
                    if (roomFunctionList.Find((obj) => obj.deviceId == sd.shareTypeId) != null)
                    {
                        addCount++;
                        funs_RoomAll.Add(sd);
                    }
                }
                btnFunctionCount.Text = addCount + "/" + roomFunctionList.Count.ToString();
                //Utlis.WriteLine("刷新成功");
            };
            //点击调整事件
            EventHandler<MouseEventArgs> eHandler = (sender, e) =>
            {
                var mmp = new MemberFunctionPermissionPage(memberInfo, roomFunctionList, funs_RoomAll, roomId, RefreshAction);
                MainPage.BasePageView.AddChidren(mmp);
                mmp.LoadPage(StringId.MemberPermissionManagement);
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
            roomView.MouseUpEventHandler = eHandler;
            btnRoomName.MouseUpEventHandler = eHandler;
            btnRight.MouseUpEventHandler = eHandler;
            btnFunctionCount.MouseUpEventHandler = eHandler;
 
            RefreshAction?.Invoke();
        }
 
 
    }
}