黄学彪
2020-12-17 9f326f4000847e6167d8166fa2f6a66f53cb3734
ZigbeeApp/Shared/Phone/UserCenter/Member/MemberManagementForm.cs
@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
namespace Shared.Phone.UserCenter.Member
{
    /// <summary>
    /// 成员信息管理
    /// </summary>
    public class MemberManagementForm : UserCenterCommonForm
    public class MemberManagementForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
@@ -13,17 +15,13 @@
        /// </summary>
        private MemberInfoRes memberInfo = null;
        /// <summary>
        /// TopFrameLayout
        /// </summary>
        private SpecialFrameLayout specialTopFrame = null;
        /// <summary>
        /// 管理员权限图标控件
        /// </summary>
        private TopLayoutMostRightView btnTopIcon = null;
        private MostRightIconControl btnTopIcon = null;
        /// <summary>
        /// 权限的翻译名控件
        /// </summary>
        private ViewNormalControl btnAuthority = null;
        private NormalViewControl btnAuthority = null;
        #endregion
@@ -38,10 +36,7 @@
            this.memberInfo = info;
            //设置标题信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.MenberManagement));
            //为了能够显示模块图样
            bodyFrameLayout.BackgroundColor = UserCenterColor.Current.TopFrameLayout;
            base.SetTitleText(info.ShowName);
            //初始化右上角的图标
            this.InitTopRightIcon();
@@ -55,30 +50,40 @@
        /// </summary>
        private void InitTopRightIcon()
        {
            if (UserCenterResourse.UserInfo.AuthorityNo != 1)
            if (HdlUserCenterResourse.ResidenceOption.AuthorityNo != 1)
            {
                return;
            }
            //管理员权限图标
            btnTopIcon = new TopLayoutMostRightView();
            btnTopIcon = new MostRightIconControl(69, 69);
            if (memberInfo.AccountType == 1)
            {
                btnTopIcon.UnSelectedImagePath = "Account/HadAuthority.png";
                btnTopIcon.UnSelectedImagePath = "Item/HadAuthority.png";
            }
            else
            {
                btnTopIcon.UnSelectedImagePath = "Account/NotAuthority.png";
                btnTopIcon.UnSelectedImagePath = "Item/NotAuthority.png";
            }
            topFrameLayout.AddChidren(btnTopIcon);
            btnTopIcon.MouseUpEventHandler += (sender, e) =>
            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);
                }
                this.ShowConfirmMsg(msg, "UpOrDownSubAccountLevel");
                msg = msg.Replace("{0}", memberInfo.ShowName);
                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                 {
                     //二次安全验证,如果没有设置有,直接跳过验证
                     HdlCheckLogic.Current.CheckSecondarySecurity(
                         () => { this.UpOrDownSubAccountLevel(); },
                         () => { this.UpOrDownSubAccountLevel(); });
                 });
            };
        }
@@ -87,6 +92,9 @@
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
            //初始化用户图标
            this.InitMenberIconControl();
@@ -99,42 +107,45 @@
        /// </summary>
        private void InitMenberIconControl()
        {
            this.specialTopFrame = new SpecialFrameLayout(400, 10);
            specialTopFrame.BackgroundColor = UserCenterColor.Current.BodyFrameLayout;
            bodyFrameLayout.AddChidren(specialTopFrame);
            var frame = new FrameLayout();
            frame.Height = Application.GetRealHeight(372);
            frame.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frame);
            //用户图标
            var btnUserIcon = new ProfilePhotoControl();
            btnUserIcon.Y = Application.GetRealHeight(40);
            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;
            btnUserIcon.UnSelectedImagePath = "Account/Admin.png";
            this.specialTopFrame.AddChidren(btnUserIcon);
            frame.AddChidren(btnUserIcon);
            //获取成员头像
            this.GetMemberIcon(btnUserIcon);
            //权限
            btnAuthority = new ViewNormalControl(800, true);
            btnAuthority = new NormalViewControl(800, 50, true);
            btnAuthority.TextAlignment = TextAlignment.Center;
            btnAuthority.Y = btnUserIcon.Bottom + Application.GetRealHeight(10);
            btnAuthority.TextSize = 12;
            btnAuthority.Y = btnUserIcon.Bottom + Application.GetRealHeight(23);
            btnAuthority.Gravity = Gravity.CenterHorizontal;
            btnAuthority.TextColor = UserCenterColor.Current.TextGrayColor;
            btnAuthority.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnAuthority.TextID = R.MyInternationalizationString.uMember;
            if (memberInfo.AccountType == 1)
            {
                //拥有管理员权限
                btnAuthority.TextID = R.MyInternationalizationString.uMemberHadActionAuthority;
            }
            this.specialTopFrame.AddChidren(btnAuthority);
            //昵称
            var btnName = new ViewNormalControl(800, true);
            btnName.TextAlignment = TextAlignment.Center;
            btnName.Y = btnAuthority.Bottom + Application.GetRealHeight(10);
            btnName.Text = memberInfo.UserName;
            btnName.Gravity = Gravity.CenterHorizontal;
            this.specialTopFrame.AddChidren(btnName, HeightAutoMode.IncreaseOnly);
            if (string.IsNullOrEmpty(memberInfo.UserName) == true)
            {
                btnName.Text = memberInfo.Account;
            }
            frame.AddChidren(btnAuthority);
        }
        #endregion
@@ -146,65 +157,68 @@
        /// </summary>
        private void InitInfoList()
        {
            //创建一个FrameLayout
            var frameLayout = new FrameLayout();
            frameLayout.Height = bodyFrameLayout.Height - specialTopFrame.Height - Application.GetRealHeight(50);
            frameLayout.BackgroundColor = UserCenterColor.Current.BodyFrameLayout;
            frameLayout.Y = specialTopFrame.Bottom + Application.GetRealHeight(50);
            bodyFrameLayout.AddChidren(frameLayout);
            //标题:成员权限
            var btnMenberTile = new ViewNormalControl(800, true);
            btnMenberTile.X = ControlCommonResourse.XXLeft;
            btnMenberTile.Y = Application.GetRealHeight(20);
            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;
            frameLayout.AddChidren(btnMenberTile);
            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 rowLayout = new RowLayout();
            rowLayout.Y = btnMenberTile.Bottom + Application.GetRealHeight(10);
            rowLayout.Height = ControlCommonResourse.ListViewRowHeight;
            frameLayout.AddChidren(rowLayout);
            this.AddRemoteRow(rowLayout);
            var rowRemote = new FrameRowControl(frame.rowSpace / 2);
            rowRemote.UseClickStatu = false;
            frame.AddChidren(rowRemote);
            this.AddRemoteRow(rowRemote);
            //添加已共享内容行
            var rowDevice = new StatuRowLayout();
            rowDevice.Y = rowLayout.Bottom;
            frameLayout.AddChidren(rowDevice);
            this.AddShardContentRow(rowDevice);
            //添加画面底部的说明
            var frameNote = new FrameLayout();
            frameNote.Height = ControlCommonResourse.NormalControlHeight * 2;
            frameNote.Y = Application.GetRealHeight(680);
            frameLayout.AddChidren(frameNote);
            var rowShard = new FrameRowControl(frame.rowSpace / 2);
            frame.AddChidren(rowShard);
            this.AddShardContentRow(rowShard);
            //一旦移除该家庭成员,他/她将无法使用该网关下所绑定的设备
            Button btnNote1 = new ViewNormalControl(Application.GetRealWidth(800), ControlCommonResourse.NormalControlHeight * 2, false);
            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.Gray;
            btnNote1.Gravity = Gravity.CenterHorizontal;
            btnNote1.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnNote1.TextAlignment = TextAlignment.Center;
            frameNote.AddChidren(btnNote1);
            bodyFrameLayout.AddChidren(btnNote1);
            var btnIcon = new IconViewControl(80);
            btnIcon.X = btnNote1.X - Application.GetRealWidth(80);
            var btnIcon = new IconViewControl(58);
            btnIcon.X = Application.GetRealWidth(167);
            btnIcon.Y = btnNote1.Y;
            btnIcon.UnSelectedImagePath = "Item/Tips.png";
            btnIcon.Gravity = Gravity.CenterVertical;
            frameNote.AddChidren(btnIcon);
            bodyFrameLayout.AddChidren(btnIcon);
            //添加移除按钮
            var btnDelete = new BottomClickButton();
            btnDelete.TextID = R.MyInternationalizationString.RemoveBotton;
            btnDelete.Y = frameNote.Bottom + Application.GetRealHeight(100);
            btnDelete.BackgroundColor = UserCenterColor.Current.Red;
            frameLayout.AddChidren(btnDelete);
            btnDelete.MouseUpEventHandler += (sender, e) =>
            btnDelete.BackgroundColor = 0xfff75858;
            bodyFrameLayout.AddChidren(btnDelete);
            btnDelete.ButtonClickEvent += (sender, e) =>
            {
                //确定要移除该家庭成员吗?
                string msg = Language.StringByID(R.MyInternationalizationString.uConfirmRemoveMember);
                this.ShowConfirmMsg(msg, "DeleteSubAccount");
                this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                {
                    this.DeleteSubAccount();
                });
            };
        }
@@ -216,26 +230,51 @@
        /// 添加远程操作行
        /// </summary>
        /// <param name="row">Row.</param>
        private void AddRemoteRow(RowLayout row)
        private void AddRemoteRow(FrameRowControl row)
        {
            //图标
            var btnIcon = new RowLeftIconView();
            var btnIcon = row.AddLeftIcon(81);
            btnIcon.UnSelectedImagePath = "Item/Remote.png";
            btnIcon.SelectedImagePath = "Item/RemoteSelected.png";
            row.AddChidren(btnIcon);
            //文字:远程操作
            var btnName = new RowCenterView(true);
            var btnName = row.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.RemoteManipulation), 500);
            btnName.TextID = R.MyInternationalizationString.RemoteManipulation;
            row.AddChidren(btnName);
            btnName.TextSize = 15;
            //开关
            var btnSwitch = new SwichControl();
            row.AddChidren(btnSwitch);
            btnSwitch.MouseUpEventHandler += (sender, e) =>
            var btnSwitch = row.AddMostRightSwitchIcon();
            if (this.memberInfo.IsRemoteControl == true)
            {
                btnSwitch.IsSelected = !btnSwitch.IsSelected;
                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
@@ -246,27 +285,24 @@
        /// 添加已共享内容行
        /// </summary>
        /// <param name="row">Row.</param>
        private void AddShardContentRow(StatuRowLayout row)
        private void AddShardContentRow(FrameRowControl row)
        {
            //图标
            var btnIcon = new RowLeftIconView();
            btnIcon.UnSelectedImagePath = "Item/ShardDevice.png";
            btnIcon.SelectedImagePath = "Item/ShardDeviceSelected.png";
            row.AddChidren(btnIcon);
            var btnIcon = row.AddLeftIcon(81);
            btnIcon.UnSelectedImagePath = "Item/ShardMenu.png";
            //文字:已共享内容行
            var btnName = new RowCenterView(true);
            btnName.TextID = R.MyInternationalizationString.uHadSharedContent;
            row.AddChidren(btnName);
            //共享
            var btnName = row.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uShared2), 500);
            btnName.TextID = R.MyInternationalizationString.uShared2;
            btnName.TextSize = 15;
            //右图标
            row.AddRightIconControl();
            row.AddRightArrow();
            var memberShardInfo = new MemberShardInfoData();
            row.MouseUpEvent += (sender, e) =>
            row.ButtonClickEvent += (sender, e) =>
            {
                var form = new SharedContent.SearchConfigureSharedListRoomForm();
                this.AddForm(form, memberInfo, memberShardInfo);
                var form = new SharedContent.LookSharedListRoomForm();
                form.AddForm(memberInfo.ChildAccountId);
            };
        }
@@ -277,46 +313,33 @@
        /// <summary>
        /// 升级或者降级子账号
        /// </summary>
        public async void UpOrDownSubAccountLevel()
        private void UpOrDownSubAccountLevel()
        {
            //开启进度条
            this.ShowProgressBar();
            var pra = new UpOrDownLevelPra();
            pra.DistributedMark = memberInfo.DistributedMark;
            bool result = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/UpSubAccount", pra);
            //变更权限
            var result = HdlMemberLogic.Current.EditorMemberAuthority(this.memberInfo.ChildAccountId, memberInfo.AccountType == 1 ? 1 : 3);
            if (result == false)
            {
                this.CloseProgressBar();
                return;
            }
            this.CloseProgressBar();
            //变更权限
            memberInfo.AccountType = memberInfo.AccountType == 1 ? 0 : 1;
            Application.RunOnMainThread(() =>
            //变更权限图标
            if (memberInfo.AccountType == 1)
            {
                //变更权限图标
                if (memberInfo.AccountType == 1)
                {
                    btnTopIcon.UnSelectedImagePath = "Account/HadAuthority.png";
                }
                else
                {
                    btnTopIcon.UnSelectedImagePath = "Account/NotAuthority.png";
                }
                //变更权限文字
                btnAuthority.TextID = memberInfo.AccountType == 1 ? R.MyInternationalizationString.uMemberHadActionAuthority : R.MyInternationalizationString.uMember;
                btnTopIcon.UnSelectedImagePath = "Item/HadAuthority.png";
            }
            else
            {
                btnTopIcon.UnSelectedImagePath = "Item/NotAuthority.png";
            }
            //变更权限文字
            btnAuthority.TextID = memberInfo.AccountType == 1 ? R.MyInternationalizationString.uMemberHadActionAuthority : R.MyInternationalizationString.uMember;
                //打开显示成功的画面
                if (memberInfo.AccountType == 1)
                {
                    var form = new SubAccountLevelUpSuccessForm();
                    this.AddForm(form, memberInfo);
                }
            });
            //打开显示成功的画面
            var form = new SubAccountLevelUpSuccessForm();
            form.AddForm(memberInfo);
        }
        #endregion
@@ -326,61 +349,44 @@
        /// <summary>
        /// 删除子账号
        /// </summary>
        public async void DeleteSubAccount()
        private void DeleteSubAccount()
        {
            //开启进度条
            this.ShowProgressBar();
            var pra = new DeleteSubAccountPra();
            pra.SubAccount = memberInfo.SubAccountDistributedMark;
            bool result = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/DeletedSubAccount", pra);
            //关闭进度条
            this.CloseProgressBar();
            bool result = HdlMemberLogic.Current.DeleteMember(this.memberInfo.ChildAccountId);
            if (result == false)
            {
                return;
            }
            Application.RunOnMainThread(() =>
            {
                //从成员一览画面移除
                this.LoadFormMethodByName("MemberListForm", "DeleteRowByAccount", memberInfo.Account);
                //自身关闭
                this.CloseForm();
            });
            //从成员一览画面移除
            this.LoadFormMethodByName("MemberListForm", "DeleteRowByAccount", memberInfo.Account);
            //自身关闭
            this.CloseForm();
        }
        #endregion
        #region ■ 结构体_____________________________
        #region ■ 获取成员头像_______________________
        /// <summary>
        /// 升级或者降级子账号的启动参数
        /// 获取成员头像
        /// </summary>
        private class UpOrDownLevelPra : IfacePraCommon
        private void GetMemberIcon(ImageView btnUserIcon)
        {
            /// <summary>
            /// 通过《住宅的Guid查询住宅下面的子账号》接口时,返回的DistributedMark字段
            /// </summary>
            public string DistributedMark = string.Empty;
            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);
                    });
                }
            });
        }
        /// <summary>
        /// 删除子账号的启动参数
        /// </summary>
        private class DeleteSubAccountPra : IfacePraCommon
        {
            /// <summary>
            /// 通过《住宅的Guid查询住宅下面的子账号》接口时,返回的DistributedMark字段
            /// </summary>
            public string SubAccount = string.Empty;
            /// <summary>
            /// HouseDistributedMark
            /// </summary>
            public string HouseDistributedMark = Common.Config.Instance.HomeId;
        }
        #endregion
    }
}