wxr
2020-04-14 06696e6f225733a60b03eea4a7c6374053d92c1d
HDL_ON/UI/UI1-Login/RegisterPage.cs
@@ -1,5 +1,8 @@
using System;
using System.Collections.Generic;
using System.Threading;
using HDL_ON.DAL.Server;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
@@ -47,7 +50,7 @@
        /// <summary>
        /// 账号子区域底部横线
        /// </summary>
        Button btnAccountViewBottomLine;
        Button btnVerificationCodeViewBottomLine;
        /// <summary>
        /// 密码子区域
        /// </summary>
@@ -120,7 +123,7 @@
        /// <summary>
        /// 验证码子区域底部分割线
        /// </summary>
        Button btnVerificationCodeViewBottomLine;
        Button btnAccountViewBottomLine;
        /// <summary>
        /// 注册按钮
        /// </summary>
@@ -150,7 +153,7 @@
        /// <summary>
        /// 回调事件
        /// </summary>
        Action<string> callbackAction;
        //Action callbackAction;
        /// <summary>
        /// 注册类型
        /// 0:手机
@@ -169,17 +172,16 @@
            pm = new HttpServerRequest();
        }
        public RegisterPage(Action<string> action)
        {
            bodyView = new FrameLayout()
            {
                BackgroundColor = CSS_Color.MainBackgroundColor,
            };
            AddChidren(bodyView);
            pm = new HttpServerRequest();
            callbackAction = action;
        }
        //public RegisterPage(Action action)
        //{
        //    bodyView = new FrameLayout()
        //    {
        //        BackgroundColor = CSS_Color.MainBackgroundColor,
        //    };
        //    AddChidren(bodyView);
        //    pm = new HttpServerRequest();
        //    callbackAction = action;
        //}
        public void ShowDialog()
        {
@@ -499,5 +501,256 @@
            LoadEventList();
        }
        /// <summary>
        /// 注册成功之后自动登录
        /// </summary>
        void LoadEvent_AutoLogin(string account, string password)
        {
            Dialog dialog = new Dialog();
            FrameLayout frame = new FrameLayout()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(198),
                Width = Application.GetRealWidth(288),
                Height = Application.GetRealHeight(206),
                BackgroundColor = CSS_Color.MainBackgroundColor,
                Radius = (uint)Application.GetRealWidth(12),
                BorderWidth = 0,
                BorderColor = 0x00000000,
            };
            dialog.AddChidren(frame);
            Button btnAccountText = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(40),
                Height = Application.GetRealHeight(17 + 14 + 14),
                IsMoreLines = true,
                TextAlignment = TextAlignment.Center,
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.TextFontSize,
                Text = account,
            };
            frame.AddChidren(btnAccountText);
            Button btnTipRegisterSuccess = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(123),
                Height = Application.GetRealHeight(30),
                TextAlignment = TextAlignment.Center,
                TextColor = CSS_Color.MainColor,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextID = StringId.CongratulationsRegistration,
            };
            frame.AddChidren(btnTipRegisterSuccess);
            Button btnAutoLoginTip = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = btnTipRegisterSuccess.Bottom,
                Height = Application.GetRealHeight(17 + 8),
                TextAlignment = TextAlignment.Center,
                TextColor = CSS_Color.PromptingColor1,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                TextID = StringId.AutomaticallyLogin,
            };
            frame.AddChidren(btnAutoLoginTip);
            Button btnHeadImage = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(150),
                Width = Application.GetRealWidth(84),
                Height = Application.GetRealWidth(84),
                Radius = (uint)Application.GetRealWidth(42),
                BorderColor = 0x00000000,
                BorderWidth = 0,
                UnSelectedImagePath = "LoginIcon/2.png",
            };
            dialog.AddChidren(btnHeadImage);
            dialog.Show();
            new Thread(() =>
            {
                Thread.Sleep(1500);
                Application.RunOnMainThread(() =>
                {
                    //创建登录线程
                    var loginThread = LoadThread_Login(account, password);
                    waitPage = new Loading();
                    new PublicAssmebly().LoadPage_WaitPage(loginThread, bodyView, waitPage);
                });
            })
            { IsBackground = true }.Start();
        }
        #region 登录线程部分
        /// <summary>
        /// 加载登录线程
        /// </summary>
        Thread LoadThread_Login(string account,string password)
        {
            var loginThread = new Thread(() =>
            {
                try
                {
                    //登录
                    var loginResult = LoadMethod_Login(account,password);
                    if (loginResult)
                    {
                        //获取住宅信息
                        var getResidencesResult = LoadMethod_GetResidences();
                        if (getResidencesResult)
                        {
                            /*
                             * Wait : 推送注册
                             */
                            Application.RunOnMainThread(() =>
                            {
                                waitPage.RemoveFromParent();
                                waitPage = null;
                                //跳转页面----
                                MainPage.GoUserPage();
                            });
                        }
                    }
                }
                catch (Exception ex)
                {
                    MainPage.Log($"LoginPage : {ex.Message}");
                }
            })
            { IsBackground = true };
            return loginThread;
        }
        /// <summary>
        /// 调用登录接口登录
        /// </summary>
        bool LoadMethod_Login(string account, string password)
        {
            var result = false;
            //调用登录接口
            var loginResult = pm.LoginByPassword(account, password);
            if (loginResult.StateCode == "SUCCESS")
            {
                var loginDataStr = Newtonsoft.Json.Linq.JObject.FromObject(loginResult.ResponseData);
                //记录用户数据
                MainPage.LoginUser = new UserInfo
                {
                    ID = (int)loginDataStr.GetValue("UserID"),
                    masterID = (int)loginDataStr.GetValue("MainUserID"),
                    accountType = (int)loginDataStr.GetValue("UserType"),
                    accountString = account,
                    password = password,
                    lastTime = DateTime.Now,
                    SIP_Account = loginDataStr.GetValue("AllVisionRegisterDevUserNameGuid").ToString(),
                    userName = loginDataStr.GetValue("Remark").ToString(),
                };
                MainPage.LoginUser.SaveUserInfo();
                MainPage.Log("登录成功。");
                result = true;
            }
            //登录失败
            else
            {
                string tipStr = "Sever erorr";
                switch (loginResult.StateCode)
                {
                    case "USERNAMEORPWDERROR":
                        tipStr = Language.StringByID(StringId.LoginFailed_AccountOrPasswordError);
                        break;
                    case "Self:Net_Error":
                        tipStr = Language.StringByID(StringId.NetworkAnomaly);
                        break;
                }
                //账号或者密码错误
                Application.RunOnMainThread(() =>
                {
                    //提示原因
                    var tip = new Tip()
                    {
                        Text = tipStr,
                        CloseTime = 3,
                        Direction = AMPopTipDirection.None
                    };
                    tip.Show(bodyView);
                    btnPasswordViewBottomLine.BackgroundColor = CSS_Color.AuxiliaryColor2;
                    btnPasswordViewBottomLine.Height = Application.GetRealHeight(2);
                });
            }
            return result;
        }
        /// <summary>
        /// 获取住宅列表
        /// </summary>
        bool LoadMethod_GetResidences()
        {
            var result = false;
            var responsePack = pm.GetHomePager();
            if (responsePack.StateCode == "Success")
            {
                var dataStr = Newtonsoft.Json.Linq.JObject.FromObject(responsePack.ResponseData);
                //没有住宅
                if (dataStr.GetValue("PageData").ToString() == "[]")
                {
                }
                else
                {
                    MainPage.LoginUser.regionList = new List<RegionInfoRes>();
                    foreach (var jsonData in dataStr.GetValue("PageData"))
                    {
                        var homeJsonStr = Newtonsoft.Json.Linq.JObject.FromObject(jsonData);
                        var home = new RegionInfoRes()
                        {
                            RegionID = homeJsonStr.GetValue("Id").ToString(),
                            RegionName = homeJsonStr.GetValue("RegionName").ToString(),
                            Name = homeJsonStr.GetValue("Name").ToString(),
                        };
                        MainPage.LoginUser.regionList.Add(home);
                    }
                    DB_ResidenceData.residenceData.residecenInfo = MainPage.LoginUser.regionList[0];
                    OnAppConfig.Instance.SaveUserConfig();
                    MainPage.LoginUser.SaveUserInfo();
                }
                result = true;
            }
            else
            {
                var tipStr = "Server erorr";
                switch (responsePack.StateCode)
                {
                    case "NoLogin":
                        tipStr = Language.StringByID(StringId.InvalidLoginCertificate);
                        break;
                }
                Application.RunOnMainThread(() =>
                {
                    //提示原因
                    var tip = new Tip()
                    {
                        Text = tipStr,
                        CloseTime = 3,
                        Direction = AMPopTipDirection.None
                    };
                    tip.Show(bodyView);
                });
            }
            return result;
        }
        #endregion
    }
}