| | |
| | | using System; |
| | | using System.Text.RegularExpressions; |
| | | using System.Threading; |
| | | using HDL_ON.DAL.Server; |
| | | using System.Collections.Generic; |
| | | using HDL_ON.UI.CSS; |
| | | using Shared; |
| | | |
| | |
| | | LoadPage_SwitchLoginType(); |
| | | LoadMethod_VisiblePassword(); |
| | | LoadPage_SwitchLoginMode(); |
| | | LoadMethod_LoginMethod(); |
| | | LoadEvent_Login(); |
| | | LoadPage_SelectionEditText(); |
| | | LoadPage_RegisterPage(); |
| | | GetVerificationCode(); |
| | | |
| | | LoadMethod_ForgetPassword(); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | btnGetVerificationCode.MouseUpEventHandler += (sender, e) => |
| | | { |
| | | #if DEBUG |
| | | etAccount.Text = "17576024298"; |
| | | #endif |
| | | string phoneNumber = etAccount.Text.Trim(); |
| | | btnGetVerificationCode.Enable = false; |
| | | btnGetVerificationCode.TextColor = CSS_Color.PromptingColor1; |
| | | int time = 60; |
| | | new Thread(() => |
| | | if (btnGetVerificationCode.IsSelected) |
| | | { |
| | | while (time != 0) |
| | | string phoneNumber = etAccount.Text.Trim(); |
| | | btnGetVerificationCode.IsSelected = false; |
| | | btnGetVerificationCode.TextColor = CSS_Color.PromptingColor1; |
| | | int time = 60; |
| | | new Thread(() => |
| | | { |
| | | time--; |
| | | while (time < 0) |
| | | { |
| | | time--; |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | btnGetVerificationCode.Text = time.ToString() + "s"; |
| | | }); |
| | | Thread.Sleep(1000); |
| | | } |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | btnGetVerificationCode.Text = time.ToString() + "s"; |
| | | btnGetVerificationCode.IsSelected = true; |
| | | btnGetVerificationCode.TextID = InternationalizationString.GetVerificationCode; |
| | | }); |
| | | Thread.Sleep(1000); |
| | | } |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | //检查手机是否已经被注册 |
| | | var checkPhoneResult = pm.IsExistingAccount(etAccount.Text.Trim()); |
| | | //手机已经被注册 |
| | | if (checkPhoneResult.StateCode == HttpRequesResult.SUCCESS.ToString()) |
| | | { |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | //获取验证码 |
| | | pm.GetPhoneVerificationCode(phoneNumber,MainPage.Company); |
| | | pm.GetPhoneLoginVerCode(phoneNumber); |
| | | } |
| | | }; |
| | | } |
| | |
| | | /// <summary> |
| | | /// 登录按钮点击事件 |
| | | /// </summary> |
| | | void LoadMethod_LoginMethod() |
| | | void LoadEvent_Login() |
| | | { |
| | | btnLogin.MouseUpEventHandler += (sender, e) => |
| | | { |
| | |
| | | { |
| | | account = etAccount.Text.Trim(); |
| | | password = etPassword.Text.Trim(); |
| | | |
| | | if (logintType == 0) |
| | | { |
| | | if (!Regex.IsMatch(account, @"^[1]+\d{9}")) |
| | | { |
| | | var tip = new Tip() |
| | | { |
| | | Text = Language.StringByID(InternationalizationString.PlsEntryCorrectMobilNeumber), |
| | | CloseTime = 3, |
| | | Direction = AMPopTipDirection.None |
| | | }; |
| | | tip.Show(bodyView); |
| | | return; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if(! Regex.IsMatch(account, "^[\\w-]+@[\\w-]+\\.(com|net|org|edu|mil|tv|biz|info)$")) |
| | | { |
| | | var tip = new Tip() |
| | | { |
| | | Text = Language.StringByID(InternationalizationString.PlsEntryCorrectEmailAddress), |
| | | CloseTime = 3, |
| | | Direction = AMPopTipDirection.None |
| | | }; |
| | | tip.Show(bodyView); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | //创建登录线程 |
| | | var loginThread = LoadMethod_LoginThread(); |
| | | LoadPage_WaitPage(loginThread); |
| | | var loginThread = LoadThread_Login(); |
| | | waitPage = new Loading(); |
| | | new WaitPageMothed().LoadPage_WaitPage(loginThread, bodyView, waitPage); |
| | | |
| | | } |
| | | }; |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 加载等待界面 |
| | | /// </summary> |
| | | void LoadPage_WaitPage(Thread thread) |
| | | { |
| | | waitPage = new Loading(); |
| | | bodyView.AddChidren(waitPage); |
| | | waitPage.Start(Language.StringByID(InternationalizationString.PleaseWait)); |
| | | var showedTime = DateTime.Now; |
| | | //如果等待事件过长,可以允许用户取消当前操作 |
| | | waitPage.MouseUpEventHandler += (sender, e) => |
| | | { |
| | | if (showedTime.AddSeconds(30) > DateTime.Now) |
| | | { |
| | | waitPage.RemoveFromParent(); |
| | | waitPage = null; |
| | | thread.Abort(); |
| | | } |
| | | }; |
| | | thread.Start(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 加载登录线程 |
| | | /// </summary> |
| | | Thread LoadMethod_LoginThread() |
| | | Thread LoadThread_Login() |
| | | { |
| | | var loginThread = new Thread(() => |
| | | { |
| | | try |
| | | { |
| | | var loginResult = pm.LoginByPassword(account,password,MainPage.Company); |
| | | Application.RunOnMainThread(() => |
| | | //登录 |
| | | var loginResult = LoadMethod_Login(); |
| | | if (loginResult) |
| | | { |
| | | waitPage.RemoveFromParent(); |
| | | waitPage = null; |
| | | }); |
| | | //登录成功 |
| | | if (loginResult.StateCode == HttpRequesResult.SUCCESS.ToString()) |
| | | { |
| | | var loginResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<UserLoginRes>(loginResult.ResponseData.ToString()); |
| | | //记录用户数据 |
| | | MainPage.LoginUser = new UserInfo |
| | | //获取住宅信息 |
| | | var getResidencesResult = LoadMethod_GetResidences(); |
| | | if (getResidencesResult) |
| | | { |
| | | ID = loginResponseData.UserId, |
| | | MasterID = loginResponseData.MainUserId, |
| | | AccountType = loginResponseData.UserType, |
| | | AccountString = account, |
| | | Password = password, |
| | | LastTime = DateTime.Now, |
| | | SIP_Account = loginResponseData.AllVisionRegisterDevUserNameGuid, |
| | | }; |
| | | MainPage.LoginUser.SaveUserInfo(); |
| | | MainPage.Log("登录成功。"); |
| | | //跳转页面---- |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | var personalCenterPage = new UI2.PersonalCenterPage(); |
| | | personalCenterPage.BackgroundColor = CSS_Color.MainBackgroundColor; |
| | | MainPage.BaseView.AddChidren(personalCenterPage); |
| | | personalCenterPage.LoadView(); |
| | | }); |
| | | /* |
| | | * Wait : 推送注册 |
| | | */ |
| | | |
| | | /* |
| | | * Wait : 推送注册 |
| | | */ |
| | | } |
| | | //登录失败 |
| | | else |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | //提示原因 |
| | | var tip = new Tip() |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | Text = loginResult.ErrorInfo, |
| | | CloseTime = 3, |
| | | Direction = AMPopTipDirection.None |
| | | }; |
| | | tip.Show(bodyView); |
| | | //if (loginResult.StateCode == HttpRequesResult.LoginFailed_AccountErorr.ToString()) |
| | | { |
| | | btnAccountViewBottomLine.BackgroundColor = CSS_Color.AuxiliaryColor2; |
| | | btnAccountViewBottomLine.Height = Application.GetRealHeight(2); |
| | | //} |
| | | //else if (loginResult.StateCode == HttpRequesResult.LoginFailed_PasswordErorr.ToString()) |
| | | //{ |
| | | btnPasswordViewBottomLine.BackgroundColor = CSS_Color.AuxiliaryColor2; |
| | | btnPasswordViewBottomLine.Height = Application.GetRealHeight(2); |
| | | } |
| | | }); |
| | | waitPage.RemoveFromParent(); |
| | | waitPage = null; |
| | | |
| | | //跳转页面---- |
| | | var ss = new UserPage(); |
| | | MainPage.BaseView.AddChidren(ss); |
| | | ss.LoadPage(); |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | |
| | | }) |
| | | { IsBackground = true }; |
| | | return loginThread; |
| | | } |
| | | /// <summary> |
| | | /// 调用登录接口登录 |
| | | /// </summary> |
| | | bool LoadMethod_Login() |
| | | { |
| | | 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(), |
| | | }; |
| | | MainPage.LoginUser.SaveUserInfo(); |
| | | MainPage.Log("登录成功。"); |
| | | result = true; |
| | | } |
| | | //登录失败 |
| | | else |
| | | { |
| | | string tipStr = "Sever erorr"; |
| | | switch (loginResult.StateCode) |
| | | { |
| | | case "USERNAMEORPWDERROR": |
| | | tipStr = Language.StringByID(InternationalizationString.LoginFailed_AccountOrPasswordError); |
| | | break; |
| | | case "Self:Net_Error": |
| | | tipStr = Language.StringByID(InternationalizationString.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.HomeLists = 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.HomeLists.Add(home); |
| | | } |
| | | UserConfig.Instance.ChangeResidence(MainPage.LoginUser.HomeLists[0]); |
| | | UserConfig.Instance.SaveUserConfig(); |
| | | } |
| | | result = true; |
| | | } |
| | | else |
| | | { |
| | | var tipStr = "Server erorr"; |
| | | switch (responsePack.StateCode) |
| | | { |
| | | case "NoLogin": |
| | | tipStr = Language.StringByID(InternationalizationString.InvalidLoginCertificate); |
| | | break; |
| | | } |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | //提示原因 |
| | | var tip = new Tip() |
| | | { |
| | | Text = tipStr, |
| | | CloseTime = 3, |
| | | Direction = AMPopTipDirection.None |
| | | }; |
| | | tip.Show(bodyView); |
| | | }); |
| | | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | //回调事件 |
| | | Action<string> callBackAction = (callBackPar_Action) => |
| | | { |
| | | try |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | etAccount.Text = callBackPar_Action; |
| | | } |
| | | catch (Exception ex) { |
| | | MainPage.Log($"login callBackAction : {ex.Message}"); |
| | | } |
| | | try |
| | | { |
| | | etAccount.Text = callBackPar_Action; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"login callBackAction : {ex.Message}"); |
| | | } |
| | | }); |
| | | }; |
| | | |
| | | var registerPage = new RegisterPage(callBackAction); |
| | |
| | | registerPage.ShowDialog(); |
| | | }; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 忘记密码 |
| | | /// </summary> |
| | | void LoadMethod_ForgetPassword() |
| | | { |
| | | btnForgetPassword.MouseUpEventHandler += (sender, e) => |
| | | { |
| | | Action<string> callBackAction = (callBackPar_Action) => |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | try |
| | | { |
| | | etAccount.Text = callBackPar_Action; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MainPage.Log($"login callBackAction : {ex.Message}"); |
| | | } |
| | | }); |
| | | }; |
| | | var forgetPasswordDialog = new ForgetPasswordPage(callBackAction); |
| | | forgetPasswordDialog.Show(); |
| | | forgetPasswordDialog.ShowDialog(); |
| | | |
| | | }; |
| | | } |
| | | } |
| | | } |