gxc
2020-02-28 66a9965c44ecc32a6696abca876ab9d1cd091584
ZigbeeApp/Shared/Phone/UserCenter/UserMain/UserInformationForm.cs
@@ -8,6 +8,11 @@
    /// </summary>
    public class UserInformationForm : EditorCommonForm
    {
        /// <summary>
        /// 中部桌布控件
        /// </summary>
        private FrameLayout frameMiddleBack = null;
        #region ■ 初始化_____________________________
        /// <summary>
@@ -46,20 +51,18 @@
            bodyFrameLayout.AddChidren(specialTopFrame);
            //用户图标
            var btnUserIcon = new CutPictureControl(UserCenterResourse.UserInfo.UserIconFile, 251, 251, true);
            var btnUserIcon = new ImageView();
            btnUserIcon.Height = Application.GetMinRealAverage(251);
            btnUserIcon.Width = Application.GetMinRealAverage(251);
            btnUserIcon.Radius = (uint)Application.GetMinRealAverage(251) / 2;
            btnUserIcon.Y = Application.GetRealHeight(46);
            btnUserIcon.Gravity = Gravity.CenterHorizontal;
            btnUserIcon.ImagePath = UserCenterResourse.UserInfo.UserIconFile;
            btnUserIcon.ImageBytes = Shared.IO.FileUtils.ReadFile(UserCenterResourse.UserInfo.UserIconFile);
            specialTopFrame.AddChidren(btnUserIcon);
            btnUserIcon.SelectPictrueEvent += async (selectPic) =>
            btnUserIcon.MouseUpEventHandler += (sender, e) =>
            {
                var pra = new { HeadImage = Shared.IO.FileUtils.ReadFile(selectPic) };
                var result = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/UpdateHeadImage", false, pra);
                if (result == true)
                {
                    UserCenterResourse.UserInfo.UserIconFileChanged = true;
                }
                //显示获取图片来源菜单
                this.ShowUserIconMenu(btnUserIcon);
            };
        }
@@ -72,23 +75,30 @@
        /// </summary>
        private void InitMiddleBodyFrame()
        {
            var frameBack = new FrameLayout();
            frameBack.Y = Application.GetRealHeight(363);
            frameBack.Height = Application.GetRealHeight(1008);
            frameBack.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameBack);
            if (this.frameMiddleBack == null)
            {
                frameMiddleBack = new FrameLayout();
                frameMiddleBack.Y = Application.GetRealHeight(363);
                frameMiddleBack.Height = Application.GetRealHeight(1008);
                frameMiddleBack.BackgroundColor = UserCenterColor.Current.White;
                bodyFrameLayout.AddChidren(frameMiddleBack);
            }
            else
            {
                frameMiddleBack.RemoveAll();
            }
            var listMidFrame = new FrameListControl(12);
            listMidFrame.Y = Application.GetRealHeight(11);
            listMidFrame.Height = Application.GetRealHeight(1008 - 11);
            frameBack.AddChidren(listMidFrame);
            frameMiddleBack.AddChidren(listMidFrame);
            var rowName = new FrameRowControl(listMidFrame.rowSpace / 2);
            //关闭点击状态
            rowName.UseClickStatu = false;
            listMidFrame.AddChidren(rowName);
            //底线
            rowName.AddBottomLine();
            var btnNameLine = rowName.AddBottomLine();
            //名称View
            rowName.AddLeftCaption(Language.StringByID(R.MyInternationalizationString.uName), 350);
            //名称输入
@@ -111,6 +121,8 @@
                //更新用户名
                this.SaveUserName(txtName.Text.Trim());
            });
            //联动线的状态
            txtName.btnLine = btnNameLine;
            var rowQrCode = new FrameRowControl(listMidFrame.rowSpace / 2);
            listMidFrame.AddChidren(rowQrCode);
@@ -172,7 +184,17 @@
            }
            else
            {
                btnPhone.Text = "+" + UserCenterResourse.UserInfo.AreaCode + " " + UserCenterResourse.UserInfo.Phone;
                string phoneNum = UserCenterResourse.UserInfo.Phone;
                if (phoneNum.Length >= 11)
                {
                    phoneNum = phoneNum.Substring(0, 3) + "".PadLeft(phoneNum.Length - 7, '*') + phoneNum.Substring(phoneNum.Length - 4, 4);
                }
                else if (phoneNum.Length >= 5)
                {
                    //或许这是国外的手机吧
                    phoneNum = phoneNum.Substring(0, 3) + "".PadLeft(phoneNum.Length - 5, '*') + phoneNum.Substring(phoneNum.Length - 2, 2);
                }
                btnPhone.Text = "+" + UserCenterResourse.UserInfo.AreaCode + " " + phoneNum;
            }
            rowPhone.ButtonClickEvent += (sender, e) =>
            {
@@ -198,7 +220,8 @@
            //添加向右图标
            rowOther.AddRightArrow();
            //微信、QQ
            rowOther.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uWebChatAndQQ), 500);
            //var btnQQ = rowOther.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uWebChatAndQQ), 500);
            var btnQQ = rowOther.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uWebChat), 500);
            rowOther.ButtonClickEvent += (sender, e) =>
            {
                var form = new OtherParty.OtherPartyAccountMenuForm();
@@ -214,7 +237,7 @@
            //添加向右图标
            rowSysPsw.AddRightArrow();
            //去修改
            rowSysPsw.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uGotoEditor), 350);
            var btnPsw = rowSysPsw.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uGotoEditor), 350);
            rowSysPsw.ButtonClickEvent += (sender, e) =>
            {
                var form = new Password.EditorAccountPasswordForm();
@@ -228,7 +251,7 @@
            //添加向右图标
            rowSecond.AddRightArrow();
            //密码、手势、指纹
            rowSecond.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uPasswordGestureFingerPrint), 400);
            var btnSecand = rowSecond.AddMostRightView(Language.StringByID(R.MyInternationalizationString.uPasswordGestureFingerPrint), 400);
            rowSecond.ButtonClickEvent += (sender, e) =>
            {
                var form = new SecondAuthenticationForm();
@@ -252,6 +275,7 @@
            //退出登陆
            var btnLogout = new NormalClickButton(specialFrame.Width, specialFrame.Height);
            btnLogout.clickStatuColor = 0xfffbfbfb;
            btnLogout.TextID = R.MyInternationalizationString.uLogoutAccount;
            btnLogout.TextColor = 0xff666666;
            btnLogout.BackgroundColor = UserCenterColor.Current.White;
@@ -306,6 +330,98 @@
        #endregion
        #region ■ 显示获取图片来源菜单_______________
        /// <summary>
        /// 显示获取图片来源菜单
        /// </summary>
        /// <param name="btnUser"></param>
        private void ShowUserIconMenu(ImageView btnUser)
        {
            var menuContr = new BottomMenuSelectForm();
            menuContr.AddForm(2);
            //拍照
            menuContr.AddMenu(Language.StringByID(R.MyInternationalizationString.uTakePictrue), () =>
            {
                //通过相机拍照裁剪
                CropImage.TakePicture((imagePath) =>
                {
                    if (string.IsNullOrEmpty(imagePath) == false)
                    {
                        //移动用户头像文件
                        if (this.MoveUserIconFile(imagePath) == true)
                        {
                            //上传用户头像文件
                            this.UpLoadUserIconFile(btnUser, UserCenterResourse.UserInfo.UserIconFile);
                        }
                    }
                }, "HdlPicture");
            });
            //从相册中选择
            menuContr.AddMenu(Language.StringByID(R.MyInternationalizationString.uGetPictrueFromAlbum), () =>
            {
                //从相册选择图片裁剪
                CropImage.SelectPicture((imagePath) =>
                {
                    if (string.IsNullOrEmpty(imagePath) == false)
                    {
                        //移动用户头像文件
                        if (this.MoveUserIconFile(imagePath) == true)
                        {
                            //上传用户头像文件
                            this.UpLoadUserIconFile(btnUser, UserCenterResourse.UserInfo.UserIconFile);
                        }
                    }
                }, "HdlPicture");
            });
        }
        /// <summary>
        /// 上传用户头像文件
        /// </summary>
        /// <param name="btnUser"></param>
        /// <param name="imagePath"></param>
        private async void UpLoadUserIconFile(ImageView btnUser, string imagePath)
        {
            var pra = new { HeadImage = Shared.IO.FileUtils.ReadFile(imagePath) };
            var result = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/UpdateHeadImage", false, pra);
            if (result == true)
            {
                UserCenterResourse.UserInfo.UserIconFileChanged = true;
                btnUser.ImageBytes = Shared.IO.FileUtils.ReadFile(imagePath);
            }
        }
        /// <summary>
        /// 移动用户头像文件
        /// </summary>
        /// <param name="imagePath"></param>
        /// <returns></returns>
        private bool MoveUserIconFile(string imagePath)
        {
            try
            {
                if (System.IO.File.Exists(UserCenterResourse.UserInfo.UserIconFile) == true)
                {
                    System.IO.File.Delete(UserCenterResourse.UserInfo.UserIconFile);
                }
                //移动文件
                System.IO.File.Move(imagePath, UserCenterResourse.UserInfo.UserIconFile);
                return true;
            }
            catch (Exception ex)
            {
                //出现未知错误
                var alert = new ShowMsgControl(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uUnKnownError));
                alert.Show();
                //Log
                HdlLogLogic.Current.WriteLog(ex);
                return false;
            }
        }
        #endregion
        #region ■ 界面重新激活事件___________________
        /// <summary>
@@ -313,8 +429,8 @@
        /// </summary>
        public override int FormActionAgainEvent()
        {
            //重新刷新界面
            this.ShowForm();
            //初始化中部的信息
            this.InitMiddleBodyFrame();
            return 1;
        }