public static UserLoginDto Login(UserLoginVo vo) { RestClient rc = new RestClient(); var request = new RestRequest(GlobalConfig.USER_LOGIN, Method.POST); //String json = JsonConvert.SerializeObject(vo); request.AddJsonBody(vo); try { var response = rc.Post(request); if (response.StatusCode == HttpStatusCode.OK) { var login = rc.Deserialize <UserLoginDto>(response); return(login.Data); } else if (response.StatusCode == 0) { throw new BusinessException("请检查网络"); } else { var x = rc.Deserialize <CustomException>(response); throw new BusinessException(x.Data.message); } } catch (BusinessException ex) { throw ex; } catch (Exception ex) { throw new BusinessException(ex.Message); } }
private void BtnLogin_Click(object sender, EventArgs e) { txtAccountNo.Text = txtAccountNo.Text.Trim(); txtPassword.Text = txtPassword.Text.Trim(); if (txtAccountNo.Text.Length < 1) { MessageBox.Show("请输入您的账号", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); txtAccountNo.Focus(); return; } if (txtPassword.Text == String.Empty) { MessageBox.Show("请输入密码", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); txtPassword.Focus(); return; } UserLoginVo vo = new UserLoginVo(); vo.password = txtPassword.Text; vo.principalName = txtAccountNo.Text; try { UserLoginDto login = LoginService.Login(vo); Global.USER_TOKEN = login.Token; Global.USER_ID = login.Id; Global.USER_NAME = login.Name; Global.ORGANIZAITON_NAME = login.organizationName; Global.ORGANIZATION_ID = login.organizationId; } catch (Exception ex) { MessageBox.Show("登录失败:" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } this.DialogResult = DialogResult.OK; }