Exemplo n.º 1
0
        /// <summary>
        /// 登录操作
        /// </summary>
        public void DoLogin()
        {
            var account = etAccount.Text.Trim();

            if (string.IsNullOrEmpty(account))
            {
                ToastUtil.ShowWarningToast(this, "请输入您的手机号码或者邮箱");
                etAccount.RequestFocus();
                return;
            }
            if (!CheckUtil.IsValidEmail(account) && !CheckUtil.IsValidPhone(account))
            {
                ToastUtil.ShowWarningToast(this, "登录账号错误");
                etAccount.RequestFocus();
                return;
            }

            var passwrod = etPassword.Text.Trim();

            if (string.IsNullOrEmpty(passwrod))
            {
                ToastUtil.ShowWarningToast(this, "请输入您的登录密码");
                etPassword.RequestFocus();
                return;
            }

            if (!NetUtil.CheckNetWork(this))
            {
                ToastUtil.ShowWarningToast(this, "网络未连接!");
                return;
            }


            LoadingDialogUtil.ShowLoadingDialog(this, "登录中...");

            try
            {
                new Thread(new ThreadStart(() =>
                {
                    var result = DataService.UserService.GetUser(account, passwrod);
                    RunOnUiThread(() =>
                    {
                        LoadingDialogUtil.DismissLoadingDialog();
                        if (result.State == 1 && result.Data != null)
                        {
                            var loginUserJson = Helper.ToJsonItem(result.Data);
                            SharedPreferencesUtil.SetParam(this, AppConfig.SP_LAST_LOGIN_ACCOUNT, account);
                            SharedPreferencesUtil.SetParam(this, AppConfig.SP_USERINFO, loginUserJson);

                            Intent intent = new Intent(this, typeof(Main));
                            StartActivity(intent);
                            OverridePendingTransition(Android.Resource.Animation.FadeIn, Android.Resource.Animation.FadeOut);
                            this.Finish();
                        }
                        else
                        {
                            ToastUtil.ShowWarningToast(this, result.Error ?? "登录失败");
                        }
                    });
                })).Start();
            }
            catch (Exception ex)
            {
                var msg = ex.Message.ToString();
                LoadingDialogUtil.DismissLoadingDialog();
                ToastUtil.ShowWarningToast(this, msg);
            }
        }