/// <summary> /// Role GridView CellContent Click Event. /// </summary> private void RoleGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { if (e.RowIndex == -1 || e.ColumnIndex == -1) { return; } var key = (Guid)RoleGridView.Rows[e.RowIndex].Cells["GuidColumn"].Value; var obj = GridRoles.Find(r => r.RoleID == key); if (obj == null) { MessageBox.Show("未找到相关数据项", "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } switch (RoleGridView.Columns[e.ColumnIndex].Name) { case "DeleteColumn": if (MemberShipEntity.RoleUserExists(obj.RoleID)) { MessageBox.Show(String.Format("角色[{0}]下存在用户,无法执行删除操作。", obj.RoleName), "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } var SubRoles = new List <RoleInfo>(); FindSubRolesRecursion(obj.RoleID, SubRoles); foreach (var sr in SubRoles) { if (MemberShipEntity.RoleUserExists(sr.RoleID)) { MessageBox.Show(String.Format("其子角色[{0}]下存在用户,无法执行删除操作。", sr.RoleName), "系统警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } if (MessageBox.Show(String.Format("角色[{0}]{1}将被删除,您确定要删除吗?", obj.RoleName, SubRoles.Count > 0 ? "及其子角色" : String.Empty), "确认对话框", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK) { var result = Common.ShowWait(() => { SubRoles.Add(obj); MemberShipEntity.DelRoles(SubRoles); }, default(String), "正在删除,请稍后...", default(int), default(int)); if (result == System.Windows.Forms.DialogResult.OK) { foreach (var sr in SubRoles) { Roles.Remove(sr); Common.WriteLog(DateTime.Now, EnmMsgType.Info, Common.CurUser.UserName, "Delta.MPS.AccessSystem.RoleManagerForm.RoleGridView.CellContentClick", String.Format("删除角色:[{0}]", sr.RoleName), null); } BindRolesToTreeView(); } } break; case "EditColumn": if (new SaveRoleForm(EnmSaveBehavior.Edit, obj).ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { BindRolesToTreeView(); } break; default: break; } } catch (Exception err) { Common.WriteLog(DateTime.Now, EnmMsgType.Error, "System", "Delta.MPS.AccessSystem.RoleManagerForm.RoleGridView.CellContentClick", err.Message, err.StackTrace); MessageBox.Show(err.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }