黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
using System;
using System.Collections.Generic;
 
namespace Shared.Phone.UserCenter.Member
{
    /// <summary>
    /// 成员信息管理
    /// </summary>
    public class MemberManagementForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 成员的信息
        /// </summary>
        private MemberInfoRes memberInfo = null;
        /// <summary>
        /// 管理员权限图标控件
        /// </summary>
        private MostRightIconControl btnTopIcon = null;
        /// <summary>
        /// 权限的翻译名控件
        /// </summary>
        private NormalViewControl btnAuthority = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="info">成员信息</param>
        public void ShowForm(MemberInfoRes info)
        {
            this.memberInfo = info;
 
            //设置标题信息
            base.SetTitleText(info.ShowName);
 
            //初始化右上角的图标
            this.InitTopRightIcon();
 
            //初始化中部控件
            this.InitMiddleFrame();
        }
 
        /// <summary>
        /// 初始化右上角的图标
        /// </summary>
        private void InitTopRightIcon()
        {
            if (HdlUserCenterResourse.ResidenceOption.AuthorityNo != 1)
            {
                return;
            }
            //管理员权限图标
            btnTopIcon = new MostRightIconControl(69, 69);
            if (memberInfo.AccountType == 1)
            {
                btnTopIcon.UnSelectedImagePath = "Item/HadAuthority.png";
            }
            else
            {
                btnTopIcon.UnSelectedImagePath = "Item/NotAuthority.png";
            }
            topFrameLayout.AddChidren(btnTopIcon);
            btnTopIcon.InitControl();
            btnTopIcon.ButtonClickEvent += (sender, e) =>
            {
                //确定取消「{0}」管理员权限?
                string msg = Language.StringByID(R.MyInternationalizationString.uDownSubAccountLevel);
                if (memberInfo.AccountType != 1)
                {
                    //确定授权「{0}」成为管理员?
                    msg = Language.StringByID(R.MyInternationalizationString.uUpSubAccountLevel);
                }
                msg = msg.Replace("{0}", memberInfo.ShowName);
 
                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                 {
                     //二次安全验证,如果没有设置有,直接跳过验证
                     HdlCheckLogic.Current.CheckSecondarySecurity(
                         () => { this.UpOrDownSubAccountLevel(); },
                         () => { this.UpOrDownSubAccountLevel(); });
                 });
            };
        }
 
        /// <summary>
        /// 初始化中部控件
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            //初始化用户图标
            this.InitMenberIconControl();
 
            //初始化信息列表
            this.InitInfoList();
        }
 
        /// <summary>
        /// 初始化用户图标
        /// </summary>
        private void InitMenberIconControl()
        {
            var frame = new FrameLayout();
            frame.Height = Application.GetRealHeight(372);
            frame.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frame);
 
            //用户图标
            string iconPath = System.IO.Path.Combine(HdlFileNameResourse.UserPictrueDirectory, memberInfo.ChildAccountId + ".png");
            var btnUserIcon = new ImageView();
            btnUserIcon.Height = this.GetPictrueRealSize(207);
            btnUserIcon.Width = this.GetPictrueRealSize(207);
            btnUserIcon.Radius = (uint)this.GetPictrueRealSize(207) / 2;
            if (System.IO.File.Exists(iconPath) == true)
            {
                btnUserIcon.ImageBytes = Shared.IO.FileUtils.ReadFile(iconPath);
            }
            else
            {
                btnUserIcon.ImagePath = "Center/Admin.png";
            }
            btnUserIcon.Y = Application.GetRealHeight(45);
            btnUserIcon.Gravity = Gravity.CenterHorizontal;
            frame.AddChidren(btnUserIcon);
            //获取成员头像
            this.GetMemberIcon(btnUserIcon);
 
            //权限
            btnAuthority = new NormalViewControl(800, 50, true);
            btnAuthority.TextAlignment = TextAlignment.Center;
            btnAuthority.TextSize = 12;
            btnAuthority.Y = btnUserIcon.Bottom + Application.GetRealHeight(23);
            btnAuthority.Gravity = Gravity.CenterHorizontal;
            btnAuthority.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnAuthority.TextID = R.MyInternationalizationString.uMember;
            if (memberInfo.AccountType == 1)
            {
                //拥有管理员权限
                btnAuthority.TextID = R.MyInternationalizationString.uMemberHadActionAuthority;
            }
            frame.AddChidren(btnAuthority);
        }
 
        #endregion
 
        #region ■ 初始化信息列表_____________________
 
        /// <summary>
        /// 初始化信息列表
        /// </summary>
        private void InitInfoList()
        {
            //标题:成员权限
            var btnMenberTile = new NormalViewControl(800, 60, true);
            btnMenberTile.X = HdlControlResourse.XXLeft;
            btnMenberTile.Y = Application.GetRealHeight(418);
            btnMenberTile.TextColor = UserCenterColor.Current.TextColor2;
            btnMenberTile.TextID = R.MyInternationalizationString.MenberAuthority;
            btnMenberTile.TextSize = 15;
            bodyFrameLayout.AddChidren(btnMenberTile);
 
            var frame = new FrameListControl();
            frame.Height = Application.GetRealHeight(311);
            frame.BackgroundColor = UserCenterColor.Current.White;
            frame.Y = Application.GetRealHeight(501);
            bodyFrameLayout.AddChidren(frame);
 
            //塞一个空白的进去占空间
            var rowTemp = new FrameRowControl();
            rowTemp.UseClickStatu = false;
            rowTemp.Height = Application.GetRealHeight(23) - frame.rowSpace;
            frame.AddChidren(rowTemp);
 
            //添加远程操作行
            var rowRemote = new FrameRowControl(frame.rowSpace / 2);
            rowRemote.UseClickStatu = false;
            frame.AddChidren(rowRemote);
            this.AddRemoteRow(rowRemote);
 
            //添加已共享内容行
            var rowShard = new FrameRowControl(frame.rowSpace / 2);
            frame.AddChidren(rowShard);
            this.AddShardContentRow(rowShard);
 
            //一旦移除该家庭成员,他/她将无法使用该网关下所绑定的设备
            var btnNote1 = new NormalViewControl(613, 100, true);
            btnNote1.X = Application.GetRealWidth(248);
            btnNote1.Y = Application.GetRealHeight(1327);
            btnNote1.TextSize = 12;
            btnNote1.TextID = R.MyInternationalizationString.RemoveMenberAndDonotUserBindGatewayDevice;
            btnNote1.IsMoreLines = true;
            btnNote1.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnNote1.TextAlignment = TextAlignment.Center;
            bodyFrameLayout.AddChidren(btnNote1);
 
            var btnIcon = new IconViewControl(58);
            btnIcon.X = Application.GetRealWidth(167);
            btnIcon.Y = btnNote1.Y;
            btnIcon.UnSelectedImagePath = "Item/Tips.png";
            bodyFrameLayout.AddChidren(btnIcon);
 
            //添加移除按钮
            var btnDelete = new BottomClickButton();
            btnDelete.TextID = R.MyInternationalizationString.RemoveBotton;
            btnDelete.BackgroundColor = 0xfff75858;
            bodyFrameLayout.AddChidren(btnDelete);
            btnDelete.ButtonClickEvent += (sender, e) =>
            {
                //确定要移除该家庭成员吗?
                string msg = Language.StringByID(R.MyInternationalizationString.uConfirmRemoveMember);
                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                {
                    this.DeleteSubAccount();
                });
            };
        }
 
        #endregion
 
        #region ■ 远程操作行_________________________
 
        /// <summary>
        /// 添加远程操作行
        /// </summary>
        /// <param name="row">Row.</param>
        private void AddRemoteRow(FrameRowControl row)
        {
            //图标
            var btnIcon = row.AddLeftIcon(81);
            btnIcon.UnSelectedImagePath = "Item/Remote.png";
 
            //文字:远程操作
            var btnName = row.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.RemoteManipulation), 500);
            btnName.TextID = R.MyInternationalizationString.RemoteManipulation;
            btnName.TextSize = 15;
 
            //开关
            var btnSwitch = row.AddMostRightSwitchIcon();
            if (this.memberInfo.IsRemoteControl == true)
            {
                btnSwitch.IsSelected = true;
            }
            btnSwitch.ButtonClickEvent += (sender, e) =>
            {
                btnSwitch.CanClick = false;
                bool statu = !btnSwitch.IsSelected;
                HdlThreadLogic.Current.RunThread(() =>
                {
                    //打开进度条
                    this.ShowProgressBar();
                    var result = HdlMemberLogic.Current.SetRemoteOperationPermissions(this.memberInfo.ChildAccountId, statu);
                    //关闭进度条
                    this.CloseProgressBar();
 
                    if (result == false)
                    {
                        return;
                    }
                    this.memberInfo.IsRemoteControl = statu;
 
                    HdlThreadLogic.Current.RunMain(() =>
                    {
                        btnSwitch.IsSelected = statu;
                        btnSwitch.CanClick = true;
                    });
                });
      
            };
            //底线
            row.AddBottomLine();
        }
 
        #endregion
 
        #region ■ 已共享内容行_______________________
 
        /// <summary>
        /// 添加已共享内容行
        /// </summary>
        /// <param name="row">Row.</param>
        private void AddShardContentRow(FrameRowControl row)
        {
            //图标
            var btnIcon = row.AddLeftIcon(81);
            btnIcon.UnSelectedImagePath = "Item/ShardMenu.png";
 
            //共享
            var btnName = row.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uShared2), 500);
            btnName.TextID = R.MyInternationalizationString.uShared2;
            btnName.TextSize = 15;
 
            //右图标
            row.AddRightArrow();
 
            row.ButtonClickEvent += (sender, e) =>
            {
                var form = new SharedContent.LookSharedListRoomForm();
                form.AddForm(memberInfo.ChildAccountId);
            };
        }
 
        #endregion
 
        #region ■ 升级或者降级子账号_________________
 
        /// <summary>
        /// 升级或者降级子账号
        /// </summary>
        private void UpOrDownSubAccountLevel()
        {
            //变更权限
            var result = HdlMemberLogic.Current.EditorMemberAuthority(this.memberInfo.ChildAccountId, memberInfo.AccountType == 1 ? 1 : 3);
            if (result == false)
            {
                return;
            }
 
            //变更权限
            memberInfo.AccountType = memberInfo.AccountType == 1 ? 0 : 1;
 
            //变更权限图标
            if (memberInfo.AccountType == 1)
            {
                btnTopIcon.UnSelectedImagePath = "Item/HadAuthority.png";
            }
            else
            {
                btnTopIcon.UnSelectedImagePath = "Item/NotAuthority.png";
            }
            //变更权限文字
            btnAuthority.TextID = memberInfo.AccountType == 1 ? R.MyInternationalizationString.uMemberHadActionAuthority : R.MyInternationalizationString.uMember;
 
            //打开显示成功的画面
            var form = new SubAccountLevelUpSuccessForm();
            form.AddForm(memberInfo);
        }
 
        #endregion
 
        #region ■ 删除子账号_________________________
 
        /// <summary>
        /// 删除子账号
        /// </summary>
        private void DeleteSubAccount()
        {
            bool result = HdlMemberLogic.Current.DeleteMember(this.memberInfo.ChildAccountId);
            if (result == false)
            {
                return;
            }
            //从成员一览画面移除
            this.LoadFormMethodByName("MemberListForm", "DeleteRowByAccount", memberInfo.Account);
            //自身关闭
            this.CloseForm();
        }
 
        #endregion
 
        #region ■ 获取成员头像_______________________
 
        /// <summary>
        /// 获取成员头像
        /// </summary>
        private void GetMemberIcon(ImageView btnUserIcon)
        {
            HdlThreadLogic.Current.RunThread(() =>
            {
                var imageData = HdlAccountLogic.Current.DownLoadAccountPictrue(memberInfo.Account);
                if (imageData != null && imageData.Length > 0)
                {
                    //写入头像内容
                    string iconPath = System.IO.Path.Combine(HdlFileNameResourse.UserPictrueDirectory, memberInfo.ChildAccountId + ".png");
                    Shared.IO.FileUtils.WriteFileByBytes(iconPath, imageData);
                    HdlThreadLogic.Current.RunMain(() =>
                    {
                        btnUserIcon.ImageBytes = Shared.IO.FileUtils.ReadFile(iconPath);
                    });
                }
            });
        }
 
        #endregion
    }
}