private void BtnYes_Click(object sender, EventArgs e) { txtName.Text = txtName.Text.Trim(); txtMobile.Text = txtMobile.Text.Trim(); if (String.IsNullOrEmpty(txtName.Text)) { MessageBox.Show("必须输入姓名"); txtName.Focus(); return; } if (String.IsNullOrEmpty(txtMobile.Text)) { MessageBox.Show("必须输入手机号码"); txtMobile.Focus(); return; } if (String.IsNullOrEmpty(cmbGenders.Text)) { MessageBox.Show("必须指定性别"); cmbGenders.Focus(); return; } if (String.IsNullOrEmpty(cmbOrganizations.Text)) { MessageBox.Show("必须指定部门"); cmbOrganizations.Focus(); return; } AddUserVo vo = new AddUserVo(); vo.name = txtName.Text; vo.mobile = txtMobile.Text; vo.gender = Convert.ToInt32(cmbGenders.SelectedValue.ToString()); vo.organizationId = cmbOrganizations.SelectedValue.ToString(); vo.permissionIds = collectionUserAllPermissions(); vo.projectIds = CollectionAllProjects(); if (vo.projectIds.Count < 1 && MessageBox.Show("您确认该用户不关联任何一个项目?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } try { CurrentUser = UserService.UpdateUser(CurrentUser.id, vo, Global.USER_TOKEN); } catch (BusinessException ex) { MessageBox.Show("修改用户发生错误:" + ex.Message, "提醒"); txtName.Focus(); return; } MessageBox.Show("修改成功!", "提醒", MessageBoxButtons.YesNo, MessageBoxIcon.Information); DialogResult = DialogResult.OK; }
/// <summary> /// 跟新用户 /// </summary> /// <param name="vo"></param> /// <param name="token"></param> /// <returns></returns> public static UserDto UpdateUser(long userId, AddUserVo vo, String token) { RestClient rs = new RestClient(); var request = new RestRequest(GlobalConfig.USERS_SOMEONE); request.AddHeader(GlobalConfig.AUTHORIZATION, token); request.AddUrlSegment("userId", userId); request.AddJsonBody(vo); IRestResponse response; try { response = rs.Execute(request, Method.PUT); } catch (Exception ex) { throw new BusinessException(ex.Message); } if (response.StatusCode == 0) { throw new BusinessException("请检查网络"); } if (response.StatusCode != HttpStatusCode.OK) { var res = rs.Deserialize <CustomException>(response); var customException = res.Data; throw new BusinessException(customException.message); } try { var types = rs.Deserialize <UserDto>(response); return(types.Data); } catch (Exception ex) { throw new BusinessException(ex.Message); } }