void checkBox_CheckedChanged(object sender, EventArgs e) { if (!UsersRolesSetted) { return; } if (SelectedUsersRoles == null) { return; } CheckBox checkBox = sender as CheckBox; string message = string.Empty; if (checkBox != null) { Role role = checkBox.Tag as Role; if (checkBox.Checked) { //选中了 if (!SelectedUsersRoles.Any(ur => ur.RoleId == role.Id && ur.Id == SelectedUser.Id)) { //原来没有则添加 RoleWithUser rwu = new RoleWithUser(); rwu.Id = Guid.NewGuid(); rwu.RoleId = role.Id; rwu.UserId = SelectedUser.Id; PharmacyDatabaseService.AddRoleWithUser(out message, rwu); this.PharmacyDatabaseService.WriteLog(AppClientContext.CurrentUser.Id, "员工岗位信息设置成功!"); } } else { //没选 RoleWithUser rwu = SelectedUsersRoles.FirstOrDefault(ur => ur.RoleId == role.Id && ur.UserId == SelectedUser.Id); if (rwu != null) { PharmacyDatabaseService.DeleteRoleWithUser(out message, rwu.Id); } } LoadSelectedUsersRoles(); } }