using System; using System.Text; using Shared.Common; using Shared.Phone.UserView; namespace Shared.Phone.Login { public class AccountRegisterSuccess : FrameLayout { /// /// registerSuccess /// /// /// public void Show(string account, string password,string OpenID="") { var dialog = new FrameLayout() { BackgroundColor = ZigbeeColor.Current.GXCDailogBackGroundColor }; AddChidren(dialog); var blackBG = new FrameLayout() { Y = Application.GetRealHeight(527), Width = Application.GetRealWidth(688), Height = Application.GetRealHeight(274), Gravity = Gravity.CenterHorizontal, BackgroundColor = ZigbeeColor.Current.GXCBlackBackgroundColor }; AddChidren(blackBG); var whiteBG = new FrameLayout() { Y = blackBG.Bottom, Width = Application.GetRealWidth(688), Height = Application.GetRealHeight(579), Gravity = Gravity.CenterHorizontal, BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor }; AddChidren(whiteBG); var accountImg = new Button() { Y = Application.GetRealHeight(648), Width = Application.GetMinRealAverage(294), Height = Application.GetMinRealAverage(316), Gravity = Gravity.CenterHorizontal, UnSelectedImagePath = "Account/Cat.png" }; AddChidren(accountImg); var accountBtn = new Button() { Y = accountImg.Bottom, Width = Application.GetRealWidth(500), Height = Application.GetRealHeight(80), Gravity = Gravity.CenterHorizontal, Text = account, TextColor = ZigbeeColor.Current.GXCTextGrayColor2, TextSize = 14, }; AddChidren(accountBtn); var tip = new Button() { Y = Application.GetRealHeight(1143), Width = Application.GetRealWidth(500), Height = Application.GetRealHeight(80), Gravity = Gravity.CenterHorizontal, TextID = R.MyInternationalizationString.RegisterSuccessTip, TextColor = ZigbeeColor.Current.GXCTextBlackColor2, TextSize = 16, }; AddChidren(tip); var willLogin = new Button() { Y = tip.Bottom + Application.GetRealHeight(15), Width = Application.GetRealWidth(500), Height = Application.GetRealHeight(80), Gravity = Gravity.CenterHorizontal, TextID = R.MyInternationalizationString.WillAutoLogin, TextColor = ZigbeeColor.Current.GXCTextGrayColor, TextSize = 14, }; AddChidren(willLogin); AutoLogin(account, password,OpenID); } /// /// AutoLogin /// /// /// private void AutoLogin(string account, string password, string OpenID = "") { new System.Threading.Thread(() => { System.Threading.Thread.Sleep(1500); Application.RunOnMainThread(() => { try { HomePage.Instance.ShowLoginLoadView(); CommonPage.Loading.Start(Language.StringByID(R.MyInternationalizationString.Logining)); Action action = async () => { var loginSuccess = await HomePage.Instance.LoginByPWDAsync(account, password); if (loginSuccess==1) { new System.Threading.Thread(async () => { if (string.IsNullOrEmpty(OpenID)==false) { BindAuthUser(Config.Instance.Guid, OpenID); } //登录成功 var homes = await House.GetHomeLists(); //刷新个人中心的内存及线程 await UserCenter.UserCenterLogic.InitUserCenterMenmoryAndThread(); //启动ZigBee ZigBee.Common.Application.Init(); Application.RunOnMainThread(() => { CommonPage.Loading.Hide(); this.RemoveFromParent(); CommonPage.Instance.RemoveViewByTag("Register"); CommonPage.Instance.RemoveViewByTag("Login"); UserPage.Instance.Fresh(); }); }) { IsBackground = true }.Start(); } else { //未登录成功弹出登录界面 同时需要标记为未登录状态 Config.Instance.LoginDateTime = new DateTime(1970, 1, 1); Config.Instance.Save(); var login = new AccountLogin { }; CommonPage.Instance.AddChidren(login); login.ShowForm(account); } }; action(); } catch (Exception ex) { var errMsg = ex.Message; } finally { CommonPage.Loading.Hide(); } }); }) { IsBackground = true }.Start(); } /// /// 绑定 /// /// /// private void BindAuthUser(string guid, string openId) { new System.Threading.Thread(async () => { var auth = new SendDataToServer.BindAuthUser { AccountGuid = guid, OpenID = openId }; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(auth); var revert = await CommonPage.Instance.RequestHttpsZigbeeAsync("ZigbeeUsers/BindAuthUserToAccount", Encoding.UTF8.GetBytes(requestJson)); }) { IsBackground = true }.Start(); } } }