HDL Home App 第二版本 旧平台金堂用 正在使用
chenqiyang
2022-06-22 dc0309e64f02227d8e1468b7326c07955f804612
ZigbeeApp/Shared/Phone/UserCenter/Password/ResetAccountPasswordForm.cs
old mode 100755 new mode 100644
@@ -1,238 +1,238 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Shared.Phone.UserCenter.Password
{
    /// <summary>
    /// 重置账号密码的界面
    /// </summary>
    public class ResetAccountPasswordForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
        #endregion
        #region ■ 初始化_____________________________
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm()
        {
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uResetPassword));
            //初始化中部信息
            this.InitMiddleFrame();
        }
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
            var frameRow1 = new FrameLayout();
            frameRow1.Height = Application.GetRealHeight(23) + ControlCommonResourse.ListViewRowHeight;
            frameRow1.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameRow1);
            //请输入新密码
            var rowNewPsw = new FrameRowControl(Application.GetRealHeight(5) / 2);
            //关闭状态提示
            rowNewPsw.UseClickStatu = false;
            rowNewPsw.Y = Application.GetRealHeight(23);
            frameRow1.AddChidren(rowNewPsw);
            var txtNewPsw = rowNewPsw.AddLeftInput("", 800);
            txtNewPsw.SecureTextEntry = true;
            txtNewPsw.PlaceholderText = Language.StringByID(R.MyInternationalizationString.uPleaseInputNewPassword);
            //底线
            rowNewPsw.AddBottomLine();
            //图标
            var btnNewPswIcon = rowNewPsw.AddMostRightEmptyIcon(58, 58);
            btnNewPswIcon.UnSelectedImagePath = "Item/HidenPWD.png";
            btnNewPswIcon.SelectedImagePath = "Item/UnHidenPWD.png";
            btnNewPswIcon.ButtonClickEvent += (sender, e) =>
            {
                btnNewPswIcon.IsSelected = !btnNewPswIcon.IsSelected;
                txtNewPsw.SecureTextEntry = !txtNewPsw.SecureTextEntry;
            };
            //Row1的错误信息
            var btnErrorRow1 = new NormalViewControl(800, 58, true);
            btnErrorRow1.X = ControlCommonResourse.XXLeft;
            btnErrorRow1.Y = rowNewPsw.Bottom + Application.GetRealHeight(29);
            btnErrorRow1.TextColor = 0xfff75858;
            frameRow1.AddChidren(btnErrorRow1);
            var frameRow2 = new FrameLayout();
            frameRow2.Y = frameRow1.Bottom;
            frameRow2.Height = Application.GetRealHeight(150) + ControlCommonResourse.ListViewRowHeight;
            bodyFrameLayout.AddChidren(frameRow2);
            var frameTemp = new FrameLayout();
            frameTemp.Height = Application.GetRealHeight(161);
            frameTemp.BackgroundColor = UserCenterColor.Current.White;
            frameRow2.AddChidren(frameTemp);
            //请重复输入新密码
            var rowConfirmPsw = new FrameRowControl(Application.GetRealHeight(5) / 2);
            //关闭状态提示
            rowConfirmPsw.UseClickStatu = false;
            rowConfirmPsw.Y = Application.GetRealHeight(10);
            frameTemp.AddChidren(rowConfirmPsw);
            var txtConfirmPsw = rowConfirmPsw.AddLeftInput("", 800);
            txtConfirmPsw.SecureTextEntry = true;
            txtConfirmPsw.PlaceholderText = Language.StringByID(R.MyInternationalizationString.uPleaseRepeatInputNewPassword);
            //图标
            var btnConfirmPswIcon = rowConfirmPsw.AddMostRightEmptyIcon(58, 58);
            btnConfirmPswIcon.UnSelectedImagePath = "Item/HidenPWD.png";
            btnConfirmPswIcon.SelectedImagePath = "Item/UnHidenPWD.png";
            btnConfirmPswIcon.ButtonClickEvent += (sender, e) =>
            {
                btnConfirmPswIcon.IsSelected = !btnConfirmPswIcon.IsSelected;
                txtConfirmPsw.SecureTextEntry = !txtConfirmPsw.SecureTextEntry;
            };
            //Row2的错误信息
            var btnErrorRow2 = new NormalViewControl(800, 58, true);
            btnErrorRow2.X = ControlCommonResourse.XXLeft;
            btnErrorRow2.Y = frameTemp.Bottom + Application.GetRealHeight(29);
            btnErrorRow2.TextColor = 0xfff75858;
            frameRow2.AddChidren(btnErrorRow2);
            //重置密码
            var btnReset = new BottomClickButton(688);
            btnReset.TextID = R.MyInternationalizationString.uResetPassword;
            btnReset.Y = Application.GetRealHeight(706);
            bodyFrameLayout.AddChidren(btnReset);
            btnReset.ButtonClickEvent += (sender, e) =>
            {
                //密码检测
                var flage = this.CheckPassword(frameRow1, frameRow2, btnErrorRow1, btnErrorRow2, txtNewPsw.Text, txtConfirmPsw.Text);
                if (flage == false)
                {
                    return;
                }
                //重置密码
                this.ResetPassword(txtNewPsw.Text, txtConfirmPsw.Text);
            };
        }
        #endregion
        #region ■ 重置密码___________________________
        /// <summary>
        /// 重置密码
        /// </summary>
        /// <param name="newPsw">新密码</param>
        /// <param name="newPsw2">二次确认密码</param>
        private void ResetPassword(string newPsw, string newPsw2)
        {
            var pra = new ResetPswPra();
            pra.Password = newPsw;
            pra.AgainPassword = newPsw2;
            //更改密码
            bool flage = UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/ResetPassword", false, pra);
            if (flage == false)
            {
                return;
            }
            //密码已经修改,请重新登录
            string msg = Language.StringByID(R.MyInternationalizationString.uPasswordIsHadChangedAndLoginAgain);
            this.ShowMassage(ShowMsgType.Normal, msg, () =>
            {
                //从新登录
                UserCenterLogic.ReLoginAgain(Common.Config.Instance.Account);
            }, Language.StringByID(R.MyInternationalizationString.Login));
        }
        #endregion
        #region ■ 一般方法___________________________
        /// <summary>
        /// 密码检测
        /// </summary>
        /// <param name="frameRow1"></param>
        /// <param name="frameRow2"></param>
        /// <param name="btnError1"></param>
        /// <param name="btnError2"></param>
        /// <param name="newPsw">输入的新密码</param>
        /// <param name="newPsw2">输入的确认密码</param>
        /// <returns></returns>
        private bool CheckPassword(FrameLayout frameRow1,FrameLayout frameRow2,
            NormalViewControl btnError1, NormalViewControl btnError2,
            string newPsw, string newPsw2)
        {
            //还原
            frameRow1.Height = Application.GetRealHeight(23) + ControlCommonResourse.ListViewRowHeight;
            frameRow2.Y = frameRow1.Bottom;
            btnError2.Text = string.Empty;
            if (newPsw == string.Empty)
            {
                //请输入新密码
                btnError1.TextID = R.MyInternationalizationString.uPleaseInputNewPassword;
                frameRow1.Height += Application.GetRealHeight(133);
                frameRow2.Y = frameRow1.Bottom;
                return false;
            }
            if (newPsw2 == string.Empty)
            {
                //请重复输入新密码
                btnError2.TextID = R.MyInternationalizationString.uPleaseRepeatInputNewPassword;
                return false;
            }
            if (newPsw != newPsw2)
            {
                //确认密码不一致,请重新输入
                btnError2.TextID = R.MyInternationalizationString.SecondPswNotEqual1;
                return false;
            }
            if (newPsw.Length < 6 || newPsw.Length > 13)
            {
                //密码长度为6-13个字符
                string textValue = Language.StringByID(R.MyInternationalizationString.PswLengthMsg);
                if (textValue.Contains("{0}") == true)
                {
                    textValue = string.Format(textValue, "6-13");
                }
                btnError1.Text = textValue;
                frameRow1.Height += Application.GetRealHeight(133);
                frameRow2.Y = frameRow1.Bottom;
                return false;
            }
            return true;
        }
        #endregion
        #region ■ 结构体_____________________________
        /// <summary>
        /// 重置密码的启动参数
        /// </summary>
        private class ResetPswPra
        {
            /// <summary>
            /// 用户账号
            /// </summary>
            public string Account = UserCenterResourse.UserInfo.Account;
            /// <summary>
            /// 国家地区代码,手机号发送验证码时使用
            /// </summary>
            public int AreaCode = Convert.ToInt32(UserCenterResourse.UserInfo.AreaCode);
            /// <summary>
            /// 新密码
            /// </summary>
            public string Password = string.Empty;
            /// <summary>
            /// 二次确认密码
            /// </summary>
            public string AgainPassword = string.Empty;
        }
        #endregion
    }
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Shared.Phone.UserCenter.Password
{
    /// <summary>
    /// 重置账号密码的界面
    /// </summary>
    public class ResetAccountPasswordForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
        #endregion
        #region ■ 初始化_____________________________
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm()
        {
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uResetPassword));
            //初始化中部信息
            this.InitMiddleFrame();
        }
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
            var frameRow1 = new FrameLayout();
            frameRow1.Height = Application.GetRealHeight(23) + ControlCommonResourse.ListViewRowHeight;
            frameRow1.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameRow1);
            //请输入新密码
            var rowNewPsw = new FrameRowControl(Application.GetRealHeight(5) / 2);
            //关闭状态提示
            rowNewPsw.UseClickStatu = false;
            rowNewPsw.Y = Application.GetRealHeight(23);
            frameRow1.AddChidren(rowNewPsw);
            var txtNewPsw = rowNewPsw.AddLeftInput("", 800);
            txtNewPsw.SecureTextEntry = true;
            txtNewPsw.PlaceholderText = Language.StringByID(R.MyInternationalizationString.uPleaseInputNewPassword);
            //底线
            rowNewPsw.AddBottomLine();
            //图标
            var btnNewPswIcon = rowNewPsw.AddMostRightEmptyIcon(58, 58);
            btnNewPswIcon.UnSelectedImagePath = "Item/HidenPWD.png";
            btnNewPswIcon.SelectedImagePath = "Item/UnHidenPWD.png";
            btnNewPswIcon.ButtonClickEvent += (sender, e) =>
            {
                btnNewPswIcon.IsSelected = !btnNewPswIcon.IsSelected;
                txtNewPsw.SecureTextEntry = !txtNewPsw.SecureTextEntry;
            };
            //Row1的错误信息
            var btnErrorRow1 = new NormalViewControl(800, 58, true);
            btnErrorRow1.X = ControlCommonResourse.XXLeft;
            btnErrorRow1.Y = rowNewPsw.Bottom + Application.GetRealHeight(29);
            btnErrorRow1.TextColor = 0xfff75858;
            frameRow1.AddChidren(btnErrorRow1);
            var frameRow2 = new FrameLayout();
            frameRow2.Y = frameRow1.Bottom;
            frameRow2.Height = Application.GetRealHeight(150) + ControlCommonResourse.ListViewRowHeight;
            bodyFrameLayout.AddChidren(frameRow2);
            var frameTemp = new FrameLayout();
            frameTemp.Height = Application.GetRealHeight(161);
            frameTemp.BackgroundColor = UserCenterColor.Current.White;
            frameRow2.AddChidren(frameTemp);
            //请重复输入新密码
            var rowConfirmPsw = new FrameRowControl(Application.GetRealHeight(5) / 2);
            //关闭状态提示
            rowConfirmPsw.UseClickStatu = false;
            rowConfirmPsw.Y = Application.GetRealHeight(10);
            frameTemp.AddChidren(rowConfirmPsw);
            var txtConfirmPsw = rowConfirmPsw.AddLeftInput("", 800);
            txtConfirmPsw.SecureTextEntry = true;
            txtConfirmPsw.PlaceholderText = Language.StringByID(R.MyInternationalizationString.uPleaseRepeatInputNewPassword);
            //图标
            var btnConfirmPswIcon = rowConfirmPsw.AddMostRightEmptyIcon(58, 58);
            btnConfirmPswIcon.UnSelectedImagePath = "Item/HidenPWD.png";
            btnConfirmPswIcon.SelectedImagePath = "Item/UnHidenPWD.png";
            btnConfirmPswIcon.ButtonClickEvent += (sender, e) =>
            {
                btnConfirmPswIcon.IsSelected = !btnConfirmPswIcon.IsSelected;
                txtConfirmPsw.SecureTextEntry = !txtConfirmPsw.SecureTextEntry;
            };
            //Row2的错误信息
            var btnErrorRow2 = new NormalViewControl(800, 58, true);
            btnErrorRow2.X = ControlCommonResourse.XXLeft;
            btnErrorRow2.Y = frameTemp.Bottom + Application.GetRealHeight(29);
            btnErrorRow2.TextColor = 0xfff75858;
            frameRow2.AddChidren(btnErrorRow2);
            //重置密码
            var btnReset = new BottomClickButton(688);
            btnReset.TextID = R.MyInternationalizationString.uResetPassword;
            btnReset.Y = Application.GetRealHeight(706);
            bodyFrameLayout.AddChidren(btnReset);
            btnReset.ButtonClickEvent += (sender, e) =>
            {
                //密码检测
                var flage = this.CheckPassword(frameRow1, frameRow2, btnErrorRow1, btnErrorRow2, txtNewPsw.Text, txtConfirmPsw.Text);
                if (flage == false)
                {
                    return;
                }
                //重置密码
                this.ResetPassword(txtNewPsw.Text, txtConfirmPsw.Text);
            };
        }
        #endregion
        #region ■ 重置密码___________________________
        /// <summary>
        /// 重置密码
        /// </summary>
        /// <param name="newPsw">新密码</param>
        /// <param name="newPsw2">二次确认密码</param>
        private void ResetPassword(string newPsw, string newPsw2)
        {
            var pra = new ResetPswPra();
            pra.Password = newPsw;
            pra.AgainPassword = newPsw2;
            //更改密码
            bool flage = UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/ResetPassword", false, pra);
            if (flage == false)
            {
                return;
            }
            //密码已经修改,请重新登录
            string msg = Language.StringByID(R.MyInternationalizationString.uPasswordIsHadChangedAndLoginAgain);
            this.ShowMassage(ShowMsgType.Normal, msg, () =>
            {
                //从新登录
                UserCenterLogic.ReLoginAgain(Common.Config.Instance.Account);
            }, Language.StringByID(R.MyInternationalizationString.Login));
        }
        #endregion
        #region ■ 一般方法___________________________
        /// <summary>
        /// 密码检测
        /// </summary>
        /// <param name="frameRow1"></param>
        /// <param name="frameRow2"></param>
        /// <param name="btnError1"></param>
        /// <param name="btnError2"></param>
        /// <param name="newPsw">输入的新密码</param>
        /// <param name="newPsw2">输入的确认密码</param>
        /// <returns></returns>
        private bool CheckPassword(FrameLayout frameRow1,FrameLayout frameRow2,
            NormalViewControl btnError1, NormalViewControl btnError2,
            string newPsw, string newPsw2)
        {
            //还原
            frameRow1.Height = Application.GetRealHeight(23) + ControlCommonResourse.ListViewRowHeight;
            frameRow2.Y = frameRow1.Bottom;
            btnError2.Text = string.Empty;
            if (newPsw == string.Empty)
            {
                //请输入新密码
                btnError1.TextID = R.MyInternationalizationString.uPleaseInputNewPassword;
                frameRow1.Height += Application.GetRealHeight(133);
                frameRow2.Y = frameRow1.Bottom;
                return false;
            }
            if (newPsw2 == string.Empty)
            {
                //请重复输入新密码
                btnError2.TextID = R.MyInternationalizationString.uPleaseRepeatInputNewPassword;
                return false;
            }
            if (newPsw != newPsw2)
            {
                //确认密码不一致,请重新输入
                btnError2.TextID = R.MyInternationalizationString.SecondPswNotEqual1;
                return false;
            }
            if (newPsw.Length < 6 || newPsw.Length > 13)
            {
                //密码长度为6-13个字符
                string textValue = Language.StringByID(R.MyInternationalizationString.PswLengthMsg);
                if (textValue.Contains("{0}") == true)
                {
                    textValue = string.Format(textValue, "6-13");
                }
                btnError1.Text = textValue;
                frameRow1.Height += Application.GetRealHeight(133);
                frameRow2.Y = frameRow1.Bottom;
                return false;
            }
            return true;
        }
        #endregion
        #region ■ 结构体_____________________________
        /// <summary>
        /// 重置密码的启动参数
        /// </summary>
        private class ResetPswPra
        {
            /// <summary>
            /// 用户账号
            /// </summary>
            public string Account = UserCenterResourse.UserInfo.Account;
            /// <summary>
            /// 国家地区代码,手机号发送验证码时使用
            /// </summary>
            public int AreaCode = Convert.ToInt32(UserCenterResourse.UserInfo.AreaCode);
            /// <summary>
            /// 新密码
            /// </summary>
            public string Password = string.Empty;
            /// <summary>
            /// 二次确认密码
            /// </summary>
            public string AgainPassword = string.Empty;
        }
        #endregion
    }
}