using System; using System.Collections.Generic; using System.Threading.Tasks; namespace Shared.Phone.UserCenter.Member { /// /// 成员管理★ /// public class MemberListForm : EditorCommonForm { #region ■ 变量声明___________________________ /// /// 列表控件 /// private VerticalListControl listView = null; /// /// 成员头像控件 /// private Dictionary dicIconControl = new Dictionary(); /// /// 成员的账号(获取头像用) /// private Dictionary dicMemberAccount = new Dictionary(); #endregion #region ■ 初始化_____________________________ /// /// 画面显示(底层会固定调用此方法,借以完成画面创建) /// 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(); } /// /// 初始化中部控件 /// private void InitMiddleFrame() { //清空bodyFrame this.ClearBodyFrame(); //初始化用户图标 this.InitUserIconControl(); //初始化列表控件 this.InitMemberListControl(); } #endregion #region ■ 初始化用户图标_____________________ /// /// 初始化用户图标 /// 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 = UserCenterResourse.UserInfo.UserIconFile; 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 = UserCenterResourse.UserInfo.UserName; ; 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 = UserCenterResourse.UserInfo.AuthorityText; frameBack.AddChidren(btnAuthority); } #endregion #region ■ 初始化成员列表_____________________ /// /// 初始化成员列表 /// private void InitMemberListControl() { //标题:成员列表 var btnMenberTile = new NormalViewControl(800, 60, true); btnMenberTile.X = ControlCommonResourse.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.ClearShardDirectory(); //初始化成员列表 this.InitMemberList(); }); } /// /// 初始化成员列表 /// private void InitMemberList() { //开启进度条 this.ShowProgressBar(); var pra = new MemberListInfoPra(); string result = UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeUsers/GetSubAccountByDistributedMark", false, pra); if (string.IsNullOrEmpty(result) == true) { //关闭进度条 this.CloseProgressBar(ShowReLoadMode.YES); return; } if (this.Parent == null) { //关闭进度条 this.CloseProgressBar(); return; } List listInfo = Newtonsoft.Json.JsonConvert.DeserializeObject>(result); if (listInfo == null) { //关闭进度条 this.CloseProgressBar(ShowReLoadMode.YES); return; } //关闭进度条 this.CloseProgressBar(); List listCheck = new List(); List listShowInfo = new List(); foreach (MemberInfoRes infoRes in listInfo) { if (listCheck.Contains(infoRes.DistributedMark) == true || infoRes.Account == UserCenterResourse.UserInfo.Phone || infoRes.Account == UserCenterResourse.UserInfo.Email) { //如果是它自己的话,不显示 continue; } if (UserCenterResourse.UserInfo.AuthorityNo != 1 && infoRes.AccountType != 0) { //不能够获取权限等级比他高的(主人自己可以无视这个判断) continue; } listCheck.Add(infoRes.DistributedMark); //添加成员信息的缓存 listShowInfo.Add(infoRes); } if (listShowInfo.Count == 0) { return; } HdlThreadLogic.Current.RunMain(() => { //添加成员列表 this.AddMemberListRowByData(listShowInfo); }); } /// /// 添加成员列表 /// private void AddMemberListRowByData(List 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 ■ 添加成员行_________________________ /// /// 添加成员行 /// /// Info. /// addLine 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(UserCenterResourse.AccountOption.UserPictruePath, info.DistributedMark + ".png"); var btnIcon = new ImageView(); btnIcon.X = ControlCommonResourse.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.DistributedMark] = btnIcon; this.dicMemberAccount[info.DistributedMark] = info.Account; } rowlayout.AddChidren(btnIcon); //成员昵称 string memberName = string.IsNullOrEmpty(info.UserName) == true ? info.Account : info.UserName; var btnName = rowlayout.AddLeftCaption(memberName, 600, true); btnName.X = ControlCommonResourse.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); }; } /// /// 添加成员行(外部调用) /// /// 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 ■ 获取成员头像_______________________ /// /// 获取成员头像 /// private void GetMemberIcon() { if (dicIconControl.Count == 0) { return; } HdlThreadLogic.Current.RunThread(() => { var pra = new AccountInfoPra(); foreach (var keys in dicMemberAccount.Keys) { if (this.Parent == null) { return; } pra.Account = dicMemberAccount[keys]; var result = UserCenterLogic.GetByteResponseDataByRequestHttps("ZigbeeUsers/GetSubAccountInfo", false, pra); if (result == null) { continue; } var revertObj = Newtonsoft.Json.JsonConvert.DeserializeObject(System.Text.Encoding.UTF8.GetString(result)); if (revertObj == null || revertObj.ResponseData == null) { continue; } var infoResult = Newtonsoft.Json.JsonConvert.DeserializeObject(revertObj.ResponseData.ToString()); if (infoResult.HeadImage != null) { //写入头像内容 string iconPath = System.IO.Path.Combine(UserCenterResourse.AccountOption.UserPictruePath, keys + ".png"); Shared.IO.FileUtils.WriteFileByBytes(iconPath, infoResult.HeadImage); HdlThreadLogic.Current.RunMain(() => { dicIconControl[keys].ImageBytes = Shared.IO.FileUtils.ReadFile(iconPath); }); } } }); } #endregion #region ■ 删除指定行_________________________ /// /// 删除指定行(外部调用) /// /// 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_____________________________ /// /// 搜索指定ID的信息 /// /// 成员ID /// 信息控件 private void SearchMemberInfo(string accountId) { var pra = new AccountInfoPra(); pra.Account = accountId; var byteData = UserCenterLogic.GetByteResponseDataByRequestHttps("ZigbeeUsers/GetSubAccountInfo", false, pra, new List() { "AccountNoExists" }); if (byteData == null) { //异常 return; } var revertObj = Newtonsoft.Json.JsonConvert.DeserializeObject(System.Text.Encoding.UTF8.GetString(byteData)); if (revertObj.StateCode == "AccountNoExists") { //成员不存在 var form = new MemberNotEsixtForm(); form.AddForm(); return; } var infoResult = Newtonsoft.Json.JsonConvert.DeserializeObject(revertObj.ResponseData.ToString()); infoResult.Account = accountId; HdlThreadLogic.Current.RunMain(() => { var form = new AddMemberInfoForm(); form.AddForm(infoResult); }); } #endregion #region ■ 界面重新激活事件___________________ /// /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件 /// public override int FormActionAgainEvent() { //清空共享文件夹 HdlShardLogic.Current.ClearShardDirectory(); return 1; } #endregion } }