陈嘉乐
2020-12-01 e08a444a9d7acea0cf39f50d22d29179f6a59292
HDL_ON/UI/UI2/4-PersonalCenter/AccountBindInfo/NewBindVerificationCodePage.cs
copy from HDL_ON/UI/UI2/4-PersonalCenter/AccountBindInfo/VerificationCodePage.cs copy to HDL_ON/UI/UI2/4-PersonalCenter/AccountBindInfo/NewBindVerificationCodePage.cs
File was copied from HDL_ON/UI/UI2/4-PersonalCenter/AccountBindInfo/VerificationCodePage.cs
@@ -2,10 +2,14 @@
using Shared;
using HDL_ON.UI.CSS;
using System.Threading;
using HDL_ON.DAL.Server;
namespace HDL_ON.UI
{
    public partial class VerificationCodePage :FrameLayout
    /// <summary>
    /// 新绑定或者换绑--验证码验证并绑定
    /// </summary>
    public partial class NewBindVerificationCodePage : FrameLayout
    {
        FrameLayout bodyView;
@@ -31,41 +35,68 @@
        Button btnResend;
        Button btnTip;
        Action<string> action;
        int titleId;
        /// <summary>
        /// 操作目标类型 1:邮箱,2:手机
        /// </summary>
        int optionType;
        ///// <summary>
        ///// 操作目标类型 1:邮箱,2:手机
        ///// </summary>
        //int optionType;
        /// <summary>
        /// 倒计时时间
        /// </summary>
        int time = 0;
        public VerificationCodePage()
        /// <summary>
        /// 是否手机
        /// </summary>
        bool isPhone;
        /// <summary>
        /// 是否换绑
        /// </summary>
        bool isModifyBind;
        /// <summary>
        /// 新绑定的账号
        /// </summary>
        string verAccount;
        /// <summary>
        /// 手机区号
        /// </summary>
        public string PhoneZoneCode = "86";
        public NewBindVerificationCodePage()
        {
            bodyView = this;
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="act">回掉函数</param>
        /// <param name="tId">页面标题</param>
        /// <param name="ot">操作类型1:邮箱;2:手机</param>
        /// <param name="time">倒计时时间</param>
        public void LoadPage(Action<string> act,int tId,int ot,int t)
        /// <param name="account">账号</param>
        /// <param name="bPhone">是否手机</param>
        /// <param name="t">倒计时时间</param>
        /// <param name="isModifyBind">是否为修改绑定</param>
        public void LoadPage(Action<string> act, int tId, string account, bool bPhone, int t,  bool isModifyBind)
        {
            action = act;
            titleId = tId;
            bodyView.BackgroundColor = CSS_Color.BackgroundColor;
            optionType = ot;
            isPhone = bPhone;
            time = t;
            this.verAccount = account;
            this.isModifyBind = isModifyBind;
            Action backAction = () => {
                Application.HideSoftInput();
                BackConfirmAction();
            };
            new TopViewDiv(bodyView, Language.StringByID(tId)).LoadTopView(backAction);
            new TopViewDiv(bodyView, Language.StringByID(tId), false).LoadTopView(backAction);
            Button btnTip = new Button()
            btnTip = new Button()
            {
                Y = Application.GetRealHeight(64),
                Height = Application.GetRealHeight(84),
@@ -237,7 +268,7 @@
                Y = Application.GetRealHeight(276),
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(220),
                Height = Application.GetRealHeight(44),
                Height = Application.GetRealWidth(44),
                SelectedBackgroundColor = CSS_Color.MainColor,
                BackgroundColor = CSS_Color.PromptingColor1,
                TextAlignment = TextAlignment.Center,
@@ -259,7 +290,7 @@
    //---------------------------------------------
    public partial class VerificationCodePage
    public partial class NewBindVerificationCodePage
    {
        /// <summary>
        /// 验证码输入变化事件
@@ -489,36 +520,16 @@
                            {
                                act = new PublicAssmebly().TipLoadingMsgDialog(Language.StringByID(StringId.SavingPleaseWait));
                            });
                            var verAccount = optionType == 1 ? MainPage.LoginUser.userEmailInfo : MainPage.LoginUser.userMobileInfo;
                            var response = new DAL.Server.HttpServerRequest().ValidatorCode(verAccount, etCode, MainPage.LoginUser.areaCode);
                            if (response.StateCode.ToUpper() == "SUCCESS")
                            var resultObj = new HttpServerRequest().BindAccount(verAccount, etCode, isPhone);
                            if (resultObj == StateCode.SUCCESS)
                            {
                                result = true;
                            }
                            else
                            {
                                string erorrInfo = "";
                                switch (response.StateCode)
                                {
                                    case "ValidCodeAndPhoneNoEqual"://验证码错误
                                        erorrInfo = Language.StringByID(StringId.VerificationCodeWrong);
                                        break;
                                    case "NoRecord":
                                        erorrInfo = Language.StringByID(StringId.PlsGetTheVerificationCode);
                                        break;
                                    default:
                                        erorrInfo = "Server error";
                                        break;
                                }
                                Application.RunOnMainThread(() =>
                                {
                                    new Tip()
                                    {
                                        CloseTime = 1,
                                        Direction = AMPopTipDirection.None,
                                        Text = erorrInfo,
                                    }.Show(bodyView);
                                });
                                //失败提示
                                IMessageCommon.Current.ShowErrorInfoAlter(resultObj);
                            }
                            Application.RunOnMainThread(() =>
                            {
@@ -526,99 +537,9 @@
                            });
                            if (result)
                            {
                                //Application.RunOnMainThread(() =>
                                //{
                                //    new PublicAssmebly().TipMsgAutoClose(Language.StringByID(StringId.ValidationSuccessful), true);
                                //});
                                //Thread.Sleep(1600);
                                Application.RunOnMainThread(() =>
                                {
                                    MainPage.BasePageView.GetChildren(MainPage.BasePageView.ChildrenCount - 1).RemoveFromParent();
                                    //MainPage.BasePageView.RemoveAt(MainPage.BasePageView.ChildrenCount - 1);
                                    if (titleId == StringId.ModifyBindingEmail)
                                    {
                                        LoadEvent_SkipBindAccountInfoPage(StringId.BindEmail);
                                    }
                                    else if (titleId == StringId.ModifyBindingPhone)
                                    {
                                        LoadEvent_SkipBindAccountInfoPage(StringId.BindPhone);
                                    }
                                    else if (titleId == StringId.UnbindEmail)//解除绑定邮箱
                                    {
                                        var account = "";
                                        new Thread(() =>
                                        {
                                            var result2 = new DAL.Server.HttpServerRequest().BindAccount(account);
                                            if (result2 == "SUCCESS")
                                            {
                                                Application.RunOnMainThread(() =>
                                                {
                                                    MainPage.LoginUser.userEmailInfo = account;
                                                    var page = new OperationResultDisPalyPage();
                                                    page.Show();
                                                    page.LoadPage(true, Language.StringByID(StringId.UnbindEmail), Language.StringByID(StringId.UnbindEmailSuccess), "");
                                                    for (int i = 0; i < 2; i++)
                                                    {
                                                        MainPage.BasePageView.GetChildren(MainPage.BasePageView.ChildrenCount - 1).RemoveFromParent();
                                                    }
                                                    action(account);
                                                });
                                            }
                                            else
                                            {
                                                Application.RunOnMainThread(() =>
                                                {
                                                    new Tip()
                                                    {
                                                        CloseTime = 1,
                                                        Direction = AMPopTipDirection.None,
                                                        Text = Language.StringByID(StringId.OperationFailed),
                                                    }.Show(bodyView);
                                                });
                                            }
                                        })
                                        { IsBackground = true }.Start();
                                    }
                                    else if (titleId == StringId.UnbindPhone)
                                    {
                                        var account = "";
                                        new Thread(() =>
                                        {
                                            var result2 = new DAL.Server.HttpServerRequest().BindAccount(account);
                                            if (result2 == "SUCCESS")
                                            {
                                                Application.RunOnMainThread(() =>
                                                {
                                                    MainPage.LoginUser.userEmailInfo = account;
                                                    var page = new OperationResultDisPalyPage();
                                                    page.Show();
                                                    page.LoadPage(true, Language.StringByID(StringId.UnbindPhone), Language.StringByID(StringId.UnbindPhoneSuccess), "");
                                                    for (int i = 0; i < 2; i++)
                                                    {
                                                        MainPage.BasePageView.GetChildren(MainPage.BasePageView.ChildrenCount - 1).RemoveFromParent();
                                                    }
                                                    action(account);
                                                });
                                            }
                                            else
                                            {
                                                Application.RunOnMainThread(() =>
                                                {
                                                    new Tip()
                                                    {
                                                        CloseTime = 1,
                                                        Direction = AMPopTipDirection.None,
                                                        Text = Language.StringByID(StringId.OperationFailed),
                                                    }.Show(bodyView);
                                                });
                                            }
                                        })
                                        { IsBackground = true }.Start();
                                    }
                                });
                                //绑定成功
                                BindSuccess();
                            }
                        })
                        { IsBackground = true }.Start();
@@ -627,6 +548,80 @@
                }
            };
        }
        /// <summary>
        /// 绑定成功
        /// </summary>
        void BindSuccess()
        {
            Application.RunOnMainThread(() =>
            {
                var tipTitle = "";
                var tipMsg = "";
                if (isPhone)
                {
                     UserInfo.Current.userMobileInfo = verAccount;
                    //请使用新的手机账号登录APP
                    tipMsg = Language.StringByID(StringId.PleaseLoginWithNewMobileAccount);
                    if (isModifyBind)
                    {
                        //登录手机修改完成
                        tipTitle = Language.StringByID(StringId.LoginMobileAccountModificationCompleted);
                    }
                    else
                    {
                        //登录手机绑定完成
                        tipTitle = Language.StringByID(StringId.LoginMobileAccountBindCompleted);
                    }
                }
                else
                {
                     UserInfo.Current.userEmailInfo = verAccount;
                    //请使用新的邮箱账号登录APP
                    tipMsg = Language.StringByID(StringId.PleaseLoginWithNewEmailAccount);
                    if (isModifyBind)
                    {
                        //登录邮箱修改完成
                        tipTitle = Language.StringByID(StringId.LoginEmailAccountModificationCompleted);
                    }
                    else
                    {
                        //登录邮箱绑定完成
                        tipTitle = Language.StringByID(StringId.LoginEmailAccountBindCompleted);
                    }
                }
                var page = new OperationResultDisPalyPage();
                page.Show();
                page.LoadPage(true, Language.StringByID(titleId), tipTitle, tipMsg);
                if (isModifyBind)
                {
                    ClosePageWithCount(3);
                }
                else
                {
                    ClosePageWithCount(2);
                }
                action(verAccount);
            });
        }
        /// <summary>
        /// 指定关闭页面个数
        /// </summary>
        /// <param name="countPage"></param>
        void ClosePageWithCount(int countPage)
        {
            //关闭多少个页面
            for (int i = 0; i < countPage; i++)
            {
                MainPage.BasePageView.GetChildren(MainPage.BasePageView.ChildrenCount - 1).RemoveFromParent();
            }
        }
        /// <summary>
        /// 重发验证码等待线程
        /// </summary>
@@ -639,14 +634,18 @@
                time = 60;
                new Thread(() =>
                {
                    if (optionType == 1)
                    //2.2  获取验证码
                    ResponsePackNew resultObj;
                    if (!isPhone)//邮箱
                    {
                        var result = new DAL.Server.HttpServerRequest().GetLoginVerCode(MainPage.LoginUser.userEmailInfo);
                        resultObj = new HttpServerRequest().VerificationCodeSend(VerifyType.REGISTER_USER_SYSTEM, verAccount);
                    }
                    else if (optionType == 2)
                    else
                    {
                        var result = new DAL.Server.HttpServerRequest().GetLoginVerCode(MainPage.LoginUser.userMobileInfo);
                        resultObj = new HttpServerRequest().VerificationCodeSend(VerifyType.REGISTER_USER_SYSTEM, verAccount, true, PhoneZoneCode);
                    }
                })
                { IsBackground = true }.Start();
            }
@@ -670,6 +669,7 @@
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// 重发验证码事件
        /// </summary>
@@ -679,15 +679,33 @@
                LoadThread_SendVerCode();
            };
        }
        /// <summary>
        /// 跳转绑定账号信息事件
        /// 返回二次确认事件
        /// </summary>
        void LoadEvent_SkipBindAccountInfoPage(int skipTid)
        void BackConfirmAction()
        {
            var vcp = new BindAccountPage();
            MainPage.BasePageView.AddChidren(vcp);
            vcp.LoadPage(action,skipTid);
            MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            //验证码发送成功,二次确认退出
            if (btnTip.TextID == StringId.VerificationCodePrompt)
            {
                Action cancelAction = () =>
                {
                    if (bodyView != null)
                    {
                        bodyView.RemoveFromParent();
                    }
                };
                new ConfirmDialog().ShowDialog(StringId.Tip, StringId.VerificationCodeMayBeDelayed, null, cancelAction, StringId.ReturnStr, StringId.WaitAMoment);
            }
            else
            {
                //直接关闭
                if (bodyView != null)
                {
                    bodyView.RemoveFromParent();
                }
            }
        }
    }
}