/// <summary> /// 调用接口验证用户名和密码 /// </summary> /// <param name="loginUser"></param> async private void RemoteValidate() { try { MesService.LoginResult loginRes = await mesService.LoginAsync(tbx_username.Text, tbx_pwd.Text); //验证用户密码 switch (loginRes) { case MesService.LoginResult.SUCCESS: LogHelper.Log.Info("登录验证成功!"); //连接云服务 if (!ConnectCloudService()) { MessageBox.Show("连接服务失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } LogHelper.Log.Info("连接服务成功!"); //启动主界面 this.DialogResult = DialogResult.OK; loginResult = LoginResult.STATUS_OK; this.Close(); break; case MesService.LoginResult.FAIL_EXCEP: LogHelper.Log.Info("登录失败!"); loginResult = LoginResult.ERROR_EXCEPT; break; case MesService.LoginResult.USER_NAME_ERR: //该用户不存在 tbx_username.ForeColor = Color.Red; tbx_username.Focus(); loginResult = LoginResult.ERROR_USER_NAME; break; case MesService.LoginResult.USER_PWD_ERR: tbx_pwd.ForeColor = Color.Red; tbx_pwd.Focus(); loginResult = LoginResult.ERROR_PASSWORD; return; default: break; } tbx_pwd.ForeColor = Color.Black; } catch (Exception ex) { LogHelper.Log.Error(ex.Message); MessageBox.Show(ex.Message, "Err"); } }
async private void CommitUserModify() { var username = this.tb_user.Text.Trim(); var oldPwd = this.tb_oldPwd.Text.Trim(); var newPwd = this.tb_newPwd.Text.Trim(); var confirmPwd = this.tb_confirmPwd.Text.Trim(); if (string.IsNullOrEmpty(username)) { MessageBox.Show("用户名称不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(oldPwd)) { MessageBox.Show("旧密码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(newPwd)) { MessageBox.Show("新密码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(confirmPwd)) { MessageBox.Show("确认密码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } var dt = (await serviceClient.GetUserInfoAsync(username)).Tables[0]; if (dt.Rows.Count > 0) { //用户已存在 //用户不能是已经存在的其他用户名 if (username != userName) { MessageBox.Show("该用户名已存在,请重新输入用户名!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } //验证旧密码 MesService.LoginResult loginResult = await serviceClient.LoginAsync(userName, oldPwd); if (loginResult != MesService.LoginResult.SUCCESS) { MessageBox.Show("旧密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (newPwd != confirmPwd) { MessageBox.Show("新密码与确认密码不一致!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } var res = await serviceClient.ModifyUserPasswordAsync(userID, username, confirmPwd); if (res == 1) { MessageBox.Show("修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MessageBox.Show("修改失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }