wxr
2020-11-20 716d1b3b705e7d37e6edebd7f60b7613ab5aee87
HDL_ON/UI/UI2/4-PersonalCenter/AccountBindInfo/BindAccountPage.cs
@@ -1,206 +1,206 @@
using System;
using Shared;
using HDL_ON.UI.CSS;
using System.Text.RegularExpressions;
using HDL_ON.DAL.Server;
//using System;
//using Shared;
//using HDL_ON.UI.CSS;
//using System.Text.RegularExpressions;
//using HDL_ON.DAL.Server;
namespace HDL_ON.UI
{
    public partial class BindAccountPage : FrameLayout
    {
        FrameLayout bodyView;
        Button btnBind;
        EditText etContent;
        Action<string> action;
        /// <summary>
        /// 标题ID
        /// </summary>
        int titleId;
        public BindAccountPage()
        {
            bodyView = this;
        }
//namespace HDL_ON.UI
//{
//    public partial class BindAccountPage : FrameLayout
//    {
//        FrameLayout bodyView;
//        Button btnBind;
//        EditText etContent;
//        Action<string> action;
//        /// <summary>
//        /// 标题ID
//        /// </summary>
//        int titleId;
//        public BindAccountPage()
//        {
//            bodyView = this;
//        }
        public void LoadPage(Action<string> act,int tId)
        {
            action = act;
            titleId = tId;
            bodyView.BackgroundColor = CSS_Color.BackgroundColor;
            new TopViewDiv(bodyView, Language.StringByID(titleId)).LoadTopView();
//        public void LoadPage(Action<string> act,int tId)
//        {
//            action = act;
//            titleId = tId;
//            bodyView.BackgroundColor = CSS_Color.BackgroundColor;
//            new TopViewDiv(bodyView, Language.StringByID(titleId)).LoadTopView();
            FrameLayout rowView = new FrameLayout()
            {
                Y = Application.GetRealHeight(72),
                Height = Application.GetRealHeight(50),
                BackgroundColor = CSS_Color.MainBackgroundColor,
            };
            bodyView.AddChidren(rowView);
//            FrameLayout rowView = new FrameLayout()
//            {
//                Y = Application.GetRealHeight(72),
//                Height = Application.GetRealHeight(50),
//                BackgroundColor = CSS_Color.MainBackgroundColor,
//            };
//            bodyView.AddChidren(rowView);
            Button btnTitle = new Button()
            {
                X = Application.GetRealWidth(16),
                Width = Application.GetRealWidth(180),
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextAlignment = TextAlignment.CenterLeft,
                TextID = titleId == StringId.BindEmail ? StringId.EntryNewEmail : StringId.EntryNewPhone,
            };
            rowView.AddChidren(btnTitle);
//            Button btnTitle = new Button()
//            {
//                X = Application.GetRealWidth(16),
//                Width = Application.GetRealWidth(180),
//                TextColor = CSS_Color.FirstLevelTitleColor,
//                TextSize = CSS_FontSize.SubheadingFontSize,
//                TextAlignment = TextAlignment.CenterLeft,
//                TextID = titleId == StringId.BindEmail ? StringId.EntryNewEmail : StringId.EntryNewPhone,
//            };
//            rowView.AddChidren(btnTitle);
            etContent = new EditText()
            {
                Width = Application.GetRealWidth(359),
                TextColor = CSS_Color.PromptingColor1,
                TextSize = CSS_FontSize.TextFontSize,
                TextAlignment = TextAlignment.CenterRight,
                Foucs = true
            };
            rowView.AddChidren(etContent);
//            etContent = new EditText()
//            {
//                Width = Application.GetRealWidth(359),
//                TextColor = CSS_Color.PromptingColor1,
//                TextSize = CSS_FontSize.TextFontSize,
//                TextAlignment = TextAlignment.CenterRight,
//                Foucs = true
//            };
//            rowView.AddChidren(etContent);
            btnBind = new Button()
            {
                Y = Application.GetRealHeight(213),
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(220),
                Height = Application.GetRealHeight(44),
                BackgroundColor = CSS_Color.MainColor,
                TextAlignment = TextAlignment.Center,
                TextColor = CSS_Color.MainBackgroundColor,
                TextID = StringId.Confirm,
                TextSize = CSS_FontSize.SubheadingFontSize,
                IsBold = true,
                Radius = (uint)Application.GetRealWidth(22),
                BorderColor = 0x00000000,
                BorderWidth = 0,
            };
            bodyView.AddChidren(btnBind);
//            btnBind = new Button()
//            {
//                Y = Application.GetRealHeight(213),
//                Gravity = Gravity.CenterHorizontal,
//                Width = Application.GetRealWidth(220),
//                Height = Application.GetRealHeight(44),
//                BackgroundColor = CSS_Color.MainColor,
//                TextAlignment = TextAlignment.Center,
//                TextColor = CSS_Color.MainBackgroundColor,
//                TextID = StringId.Confirm,
//                TextSize = CSS_FontSize.SubheadingFontSize,
//                IsBold = true,
//                Radius = (uint)Application.GetRealWidth(22),
//                BorderColor = 0x00000000,
//                BorderWidth = 0,
//            };
//            bodyView.AddChidren(btnBind);
            LoadEvent_BindEmail();
//            LoadEvent_BindEmail();
           
        }
    }
//        }
//    }
    //--------------------------------------------
    public partial class BindAccountPage
    {
        void LoadEvent_BindEmail()
        {
            btnBind.MouseUpEventHandler = (sender, e) => {
                Application.HideSoftInput();
                var account = etContent.Text.Trim();
                if (titleId == StringId.BindEmail)
                {
                    if (account == MainPage.LoginUser.userEmailInfo)
                    {
                        var tip = new Tip()
                        {
                            Text = Language.StringByID(StringId.EmailIsSameNoNeedModfiy),
                            CloseTime = 1,
                            Direction = AMPopTipDirection.None
                        };
                        tip.Show(bodyView);
                        return;
                    }
                    if (!Regex.IsMatch(account, "([a-zA-Z0-9_\\.\\-])+\\@(([a-zA-Z0-9\\-])+\\.)+([a-zA-Z0-9]{2,5})+"))
                    {
                        var tip = new Tip()
                        {
                            Text = Language.StringByID(StringId.PlsEntryCorrectEmailAddress),
                            CloseTime = 1,
                            Direction = AMPopTipDirection.None
                        };
                        tip.Show(bodyView);
                        return;
                    }
                }
                else if (titleId == StringId.BindPhone)
                {
                    if(account == MainPage.LoginUser.userMobileInfo)
                    {
                        var tip = new Tip()
                        {
                            Text = Language.StringByID(StringId.PhoneNumberIsSameNoNeedModfiy),
                            CloseTime = 1,
                            Direction = AMPopTipDirection.None
                        };
                        tip.Show(bodyView);
                        return;
                    }
                    if (!Regex.IsMatch(account, @"^[1]+\d{10}") || (account.Length != 11))
                    {
                        var tip = new Tip()
                        {
                            Text = Language.StringByID(StringId.PlsEntryCorrectMobilNeumber),
                            CloseTime = 1,
                            Direction = AMPopTipDirection.None
                        };
                        tip.Show(bodyView);
                        return;
                    }
                }
                new System.Threading.Thread(() =>
                {
                    var result = new HttpServerRequest().BindAccount(account);
                    if (result.ToUpper() == StateCode.SUCCESS)
                    {
                        Application.RunOnMainThread(() =>
                        {
                            if (titleId == StringId.BindEmail)
                            {
                                MainPage.LoginUser.userEmailInfo = account;
                            }
                            else if (titleId == StringId.BindPhone)
                            {
                                MainPage.LoginUser.userMobileInfo = account;
                            }
                            var page = new OperationResultDisPalyPage();
                            page.Show();
                            if (titleId == StringId.BindEmail)
                            {
                                page.LoadPage(true, Language.StringByID(StringId.BindEmail), Language.StringByID(StringId.BindEmailSuccess), "");
                            }
                            else if (titleId == StringId.BindPhone)
                            {
                                page.LoadPage(true, Language.StringByID(StringId.BindPhone), Language.StringByID(StringId.BindPhoneSuccess), "");
                            }
//    //--------------------------------------------
//    public partial class BindAccountPage
//    {
//        void LoadEvent_BindEmail()
//        {
//            btnBind.MouseUpEventHandler = (sender, e) => {
//                Application.HideSoftInput();
//                var account = etContent.Text.Trim();
//                if (titleId == StringId.BindEmail)
//                {
//                    if (account ==  UserInfo.Current.userEmailInfo)
//                    {
//                        var tip = new Tip()
//                        {
//                            Text = Language.StringByID(StringId.EmailIsSameNoNeedModfiy),
//                            CloseTime = 1,
//                            Direction = AMPopTipDirection.None
//                        };
//                        tip.Show(bodyView);
//                        return;
//                    }
//                    if (!Regex.IsMatch(account, "([a-zA-Z0-9_\\.\\-])+\\@(([a-zA-Z0-9\\-])+\\.)+([a-zA-Z0-9]{2,5})+"))
//                    {
//                        var tip = new Tip()
//                        {
//                            Text = Language.StringByID(StringId.PlsEntryCorrectEmailAddress),
//                            CloseTime = 1,
//                            Direction = AMPopTipDirection.None
//                        };
//                        tip.Show(bodyView);
//                        return;
//                    }
//                }
//                else if (titleId == StringId.BindPhone)
//                {
//                    if(account ==  UserInfo.Current.userMobileInfo)
//                    {
//                        var tip = new Tip()
//                        {
//                            Text = Language.StringByID(StringId.PhoneNumberIsSameNoNeedModfiy),
//                            CloseTime = 1,
//                            Direction = AMPopTipDirection.None
//                        };
//                        tip.Show(bodyView);
//                        return;
//                    }
//                    if (!Regex.IsMatch(account, @"^[1]+\d{10}") || (account.Length != 11))
//                    {
//                        var tip = new Tip()
//                        {
//                            Text = Language.StringByID(StringId.PlsEntryCorrectMobilNeumber),
//                            CloseTime = 1,
//                            Direction = AMPopTipDirection.None
//                        };
//                        tip.Show(bodyView);
//                        return;
//                    }
//                }
//                new System.Threading.Thread(() =>
//                {
//                    var result = new HttpServerRequest().BindAccount(account);
//                    if (result.ToUpper() == StateCode.SUCCESS)
//                    {
//                        Application.RunOnMainThread(() =>
//                        {
//                            if (titleId == StringId.BindEmail)
//                            {
//                                 UserInfo.Current.userEmailInfo = account;
//                            }
//                            else if (titleId == StringId.BindPhone)
//                            {
//                                 UserInfo.Current.userMobileInfo = account;
//                            }
//                            var page = new OperationResultDisPalyPage();
//                            page.Show();
//                            if (titleId == StringId.BindEmail)
//                            {
//                                page.LoadPage(true, Language.StringByID(StringId.BindEmail), Language.StringByID(StringId.BindEmailSuccess), "");
//                            }
//                            else if (titleId == StringId.BindPhone)
//                            {
//                                page.LoadPage(true, Language.StringByID(StringId.BindPhone), Language.StringByID(StringId.BindPhoneSuccess), "");
//                            }
                            for (int i = 0; i < 3; i++)
                            {
                                MainPage.BasePageView.GetChildren(MainPage.BasePageView.ChildrenCount - 1).RemoveFromParent();
                            }
                            action(account);
                        });
                    }
                    else
                    {
                        var tipMsg = "";
//                            for (int i = 0; i < 3; i++)
//                            {
//                                MainPage.BasePageView.GetChildren(MainPage.BasePageView.ChildrenCount - 1).RemoveFromParent();
//                            }
//                            action(account);
//                        });
//                    }
//                    else
//                    {
//                        var tipMsg = "";
                       
                        Application.RunOnMainThread(() =>
                        {
                            var page = new OperationResultDisPalyPage();
                            page.Show();
                            if (titleId == StringId.BindEmail)
                            {
                                if (result == "Exist")
                                {
                                    tipMsg = Language.StringByID(StringId.EmailAlreadyUse);
                                }
                                page.LoadPage(false, Language.StringByID(StringId.BindEmail), Language.StringByID(StringId.BindEmailFail) + "," + tipMsg, "");
                            }
                            else
                            {
                                if (result == "Exist")
                                {
                                    tipMsg = Language.StringByID(StringId.PhoneNumberAlreadyUse);
                                }
                                page.LoadPage(false, Language.StringByID(StringId.BindPhone), Language.StringByID(StringId.BindPhoneFail) + "," + tipMsg, "");
                            }
                        });
                    }
                })
                { IsBackground = true }.Start();
            };
        }
    }
}
//                        Application.RunOnMainThread(() =>
//                        {
//                            var page = new OperationResultDisPalyPage();
//                            page.Show();
//                            if (titleId == StringId.BindEmail)
//                            {
//                                if (result == "Exist")
//                                {
//                                    tipMsg = Language.StringByID(StringId.EmailAlreadyUse);
//                                }
//                                page.LoadPage(false, Language.StringByID(StringId.BindEmail), Language.StringByID(StringId.BindEmailFail) + "," + tipMsg, "");
//                            }
//                            else
//                            {
//                                if (result == "Exist")
//                                {
//                                    tipMsg = Language.StringByID(StringId.PhoneNumberAlreadyUse);
//                                }
//                                page.LoadPage(false, Language.StringByID(StringId.BindPhone), Language.StringByID(StringId.BindPhoneFail) + "," + tipMsg, "");
//                            }
//                        });
//                    }
//                })
//                { IsBackground = true }.Start();
//            };
//        }
//    }
//}