黄学彪
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
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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
 
namespace Shared.Phone.UserCenter.Member
{
    /// <summary>
    /// 成员管理★
    /// </summary>
    public class MemberListForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalListControl listView = null;
        /// <summary>
        /// 成员头像控件
        /// </summary>
        private Dictionary<string, ImageView> dicIconControl = new Dictionary<string, ImageView>();
        /// <summary>
        /// 成员的账号(获取头像用)
        /// </summary>
        private Dictionary<string, string> dicMemberAccount = new Dictionary<string, string>();
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm()
        {
            //设置标题信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.MenberManagement));
 
            var titleIcon = new MostRightIconControl(69, 69);
            titleIcon.UnSelectedImagePath = "Item/Add.png";
            topFrameLayout.AddChidren(titleIcon);
            titleIcon.InitControl();
            titleIcon.ButtonClickEvent += (sender, e) =>
            {
                var menuContr = new TopRightMenuControl(2, 2);
                //扫描二维码
                string msg1 = Language.StringByID(R.MyInternationalizationString.uScanQRcode);
                menuContr.AddRowMenu(msg1, "Item/ScanQRcodeIcon.png", "Item/ScanQRcodeIconSelected.png", () =>
                {
                    QRCode.ScanQRcode((qrCode) =>
                    {
                        if (string.IsNullOrEmpty(qrCode) == true)
                        {
                            return;
                        }
                        //搜索ID
                        HdlThreadLogic.Current.RunThread(() =>
                        {
                            this.SearchMemberInfo(qrCode);
                        });
                    }, 
                    Language.StringByID(R.MyInternationalizationString.uCancel),
                    Language.StringByID(R.MyInternationalizationString.uFlashlamp),
                    msg1);
                });
                //输入账号
                string msg2 = Language.StringByID(R.MyInternationalizationString.uInputAccount);
                menuContr.AddRowMenu(msg2, "Item/InputAccountIcon.png", "Item/InputAccountIconSelected.png", () =>
                {
                    var form = new AddMemberByIdForm();
                    form.AddForm();
                });
            };
 
            //初始化中部控件
            this.InitMiddleFrame();
        }
 
 
        /// <summary>
        /// 初始化中部控件
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            //初始化用户图标
            this.InitUserIconControl();
 
            //初始化列表控件
            this.InitMemberListControl();
        }
 
        #endregion
 
        #region ■ 初始化用户图标_____________________
 
        /// <summary>
        /// 初始化用户图标
        /// </summary>
        private void InitUserIconControl()
        {
            var frameBack = new FrameLayout();
            frameBack.BackgroundColor = UserCenterColor.Current.White;
            frameBack.Height = Application.GetRealHeight(438);
            bodyFrameLayout.AddChidren(frameBack);
 
            //用户图标
            var btnUserIcon = new ImageView();
            btnUserIcon.Height = this.GetPictrueRealSize(207);
            btnUserIcon.Width = this.GetPictrueRealSize(207);
            btnUserIcon.Radius = (uint)this.GetPictrueRealSize(207) / 2;
            btnUserIcon.ImagePath = HdlFileNameResourse.UserHeadIconFile;
            btnUserIcon.Y = Application.GetRealHeight(46);
            btnUserIcon.Gravity = Gravity.CenterHorizontal;
            frameBack.AddChidren(btnUserIcon);
 
            //昵称
            var btnName = new NormalViewControl(frameBack.Width, Application.GetRealHeight(60), false);
            btnName.TextAlignment = TextAlignment.Center;
            btnName.Y = btnUserIcon.Bottom + Application.GetRealHeight(20);
            btnName.TextSize = 16;
            btnName.Text = HdlUserCenterResourse.UserInfo.NickName; ;
            frameBack.AddChidren(btnName);
 
            //身份
            var btnAuthority = new NormalViewControl(frameBack.Width, Application.GetRealHeight(55), false);
            btnAuthority.TextAlignment = TextAlignment.Center;
            btnAuthority.Y = btnName.Bottom + Application.GetRealHeight(10);
            btnAuthority.TextSize = 12;
            btnAuthority.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnAuthority.Text = HdlUserCenterResourse.ResidenceOption.AuthorityText;
            frameBack.AddChidren(btnAuthority);
        }
 
        #endregion
 
        #region ■ 初始化成员列表_____________________
 
        /// <summary>
        /// 初始化成员列表
        /// </summary>
        private void InitMemberListControl()
        {
            //标题:成员列表
            var btnMenberTile = new NormalViewControl(800, 60, true);
            btnMenberTile.X = HdlControlResourse.XXLeft;
            btnMenberTile.Y = Application.GetRealHeight(480);
            btnMenberTile.TextColor = UserCenterColor.Current.TextColor1;
            btnMenberTile.TextID = R.MyInternationalizationString.MenberList;
            btnMenberTile.TextSize = 15;
            bodyFrameLayout.AddChidren(btnMenberTile);
 
            var frameBack = new FrameLayout();
            frameBack.Y = btnMenberTile.Bottom + Application.GetRealHeight(23);
            frameBack.Height = Application.GetRealHeight(11);
            frameBack.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameBack);
 
            //添加可以向下滚动的控件
            listView = new VerticalListControl(12);
            listView.Height = bodyFrameLayout.Height - frameBack.Bottom;
            listView.BackgroundColor = UserCenterColor.Current.White;
            listView.Y = frameBack.Bottom;
            bodyFrameLayout.AddChidren(listView);
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                //总之先清空共享文件夹准没错
                HdlShardLogic.Current.Dispone();
                //初始化成员列表
                this.InitMemberList();
            });
        }
 
        /// <summary>
        /// 初始化成员列表
        /// </summary>
        private void InitMemberList()
        {
            //开启进度条
            this.ShowProgressBar();
 
            var listShowInfo = HdlMemberLogic.Current.GetMemberListInfo();
            if (listShowInfo == null)
            {
                //关闭进度条
                this.CloseProgressBar(ShowReLoadMode.YES);
                return;
            }
            //关闭进度条
            this.CloseProgressBar();
 
            if (listShowInfo.Count == 0)
            {
                return;
            }
            HdlThreadLogic.Current.RunMain(() =>
            {
                //添加成员列表
                this.AddMemberListRowByData(listShowInfo);
            });
        }
 
        /// <summary>
        /// 添加成员列表
        /// </summary>
        private void AddMemberListRowByData(List<MemberInfoRes> listNewInfo)
        {
            if (this.Parent == null)
            {
                return;
            }
 
            int count = listNewInfo.Count - 1;
            for (int i = 0; i < listNewInfo.Count; i++)
            {
                //添加成员行
                this.AddRowLayout(listNewInfo[i], i != count);
            }
            //调整列表控件的高度
            listView.AdjustRealHeight(Application.GetRealHeight(23));
            //获取成员头像
            this.GetMemberIcon();
        }
 
        #endregion
 
        #region ■ 添加成员行_________________________
 
        /// <summary>
        /// 添加成员行
        /// </summary>
        /// <param name="info">Info.</param>
        ///  <param name="addLine">addLine</param>
        private void AddRowLayout(MemberInfoRes info, bool addLine)
        {
            var rowlayout = new FrameRowControl(listView.rowSpace / 2);
            rowlayout.Height = Application.GetRealHeight(138);
            rowlayout.MainKeys = info.Account;
            listView.AddChidren(rowlayout);
 
            //成员头像图标
            string iconPath = System.IO.Path.Combine(HdlFileNameResourse.UserPictrueDirectory, info.ChildAccountId + ".png");
            var btnIcon = new ImageView();
            btnIcon.X = HdlControlResourse.XXLeft;
            btnIcon.Gravity = Gravity.CenterVertical;
            btnIcon.Height = this.GetPictrueRealSize(115);
            btnIcon.Width = this.GetPictrueRealSize(115);
            btnIcon.Radius = (uint)this.GetPictrueRealSize(115) / 2;
            if (System.IO.File.Exists(iconPath) == true)
            {
                btnIcon.ImagePath = iconPath;
            }
            else
            {
                btnIcon.ImagePath = "Center/Admin.png";
                this.dicIconControl[info.ChildAccountId] = btnIcon;
                this.dicMemberAccount[info.ChildAccountId] = info.Account;
            }
            rowlayout.AddChidren(btnIcon);
 
            //成员昵称
            string memberName = info.ShowName;
            var btnName = rowlayout.AddLeftCaption(memberName, 600, true);
            btnName.X = HdlControlResourse.XXLeft + btnIcon.Height + Application.GetRealWidth(35);
            btnName.TextSize = 15;
            rowlayout.AddChidren(btnName);
 
            if (addLine == true)
            {
                //底线
                rowlayout.AddBottomLine();
            }
            //右图标
            rowlayout.AddRightArrow();
            rowlayout.ButtonClickEvent += (sender, e) =>
            {
                var form = new MemberManagementForm();
                form.AddForm(info);
            };
        }
 
        /// <summary>
        /// 添加成员行(外部调用)
        /// </summary>
        /// <param name="info"></param>
        public void AddRowLayoutByOtherForm(MemberInfoRes info)
        {
            var myRow = listView.GetChildren(listView.ChildrenCount - 1);
            if (myRow != null)
            {
                //最后一行加底线
                ((FrameRowControl)myRow).AddBottomLine();
            }
            this.AddRowLayout(info, false);
            //调整列表控件的高度
            listView.AdjustRealHeight(Application.GetRealHeight(23));
        }
 
        #endregion
 
        #region ■ 获取成员头像_______________________
 
        /// <summary>
        /// 获取成员头像
        /// </summary>
        private void GetMemberIcon()
        {
            if (dicIconControl.Count == 0)
            {
                return;
            }
            HdlThreadLogic.Current.RunThread(() =>
            {
                foreach (var keys in dicMemberAccount.Keys)
                {
                    if (this.Parent == null)
                    {
                        return;
                    }
                    var imageData = HdlAccountLogic.Current.DownLoadAccountPictrue(dicMemberAccount[keys]);
                    if (imageData != null && imageData.Length > 0)
                    {
                        //写入头像内容
                        string iconPath = System.IO.Path.Combine(HdlFileNameResourse.UserPictrueDirectory, keys + ".png");
                        Shared.IO.FileUtils.WriteFileByBytes(iconPath, imageData);
                        HdlThreadLogic.Current.RunMain(() =>
                        {
                            dicIconControl[keys].ImageBytes = Shared.IO.FileUtils.ReadFile(iconPath);
                        });
                    }
                }
            });
        }
 
        #endregion
 
        #region ■ 删除指定行_________________________
 
        /// <summary>
        /// 删除指定行(外部调用)
        /// </summary>
        /// <param name="accountId"></param>
        public void DeleteRowByAccount(string accountId)
        {
            for (int i = 0; ; i++)
            {
                var row = (FrameRowControl)listView.GetChildren(i);
                if (row == null)
                {
                    break;
                }
                if (row.MainKeys == accountId)
                {
                    row.RemoveFromParent();
                    //调整列表控件的高度
                    listView.AdjustRealHeight(Application.GetRealHeight(23));
 
                    break;
                }
            }
        }
 
        #endregion
 
        #region ■ 搜索ID_____________________________
 
        /// <summary>
        /// 搜索指定ID的信息
        /// </summary>
        /// <param name="accountId">成员ID</param>
        /// <param name="txtMsg">信息控件</param>
        private void SearchMemberInfo(string accountId)
        {
            //开启进度条
            this.ShowProgressBar();
 
            var result = HdlMemberLogic.Current.SearchNormalInfoByAccount(accountId);
            //关闭进度条
            this.CloseProgressBar();
 
            if (result == null)
            {
                return;
            }
            if (result.Account == string.Empty)
            {
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //成员不存在
                    var form = new MemberNotEsixtForm();
                    form.AddForm(Language.StringByID(R.MyInternationalizationString.uMemberInformation));
                });
                return;
            }
 
            HdlThreadLogic.Current.RunMain(() =>
            {
                var form = new AddMemberInfoForm();
                form.AddForm(result);
            });
        }
 
        #endregion
 
        #region ■ 界面重新激活事件___________________
 
        /// <summary>
        /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
        /// </summary>
        public override int FormActionAgainEvent()
        {
            //清空共享文件夹
            HdlShardLogic.Current.Dispone();
 
            return 1;
        }
 
        #endregion
    }
}