private void btnUpdate_Click(object sender, EventArgs e) { if (IsRightValid()) { try { if (cboRoles.SelectedIndex != -1) { _right.RoleId = int.Parse(cboRoles.SelectedValue.ToString()); } if (cboMenuItem.SelectedIndex != -1) { _right.MenuItemId = int.Parse(cboMenuItem.SelectedValue.ToString()); } _right.Allowed = chkAllowed.Checked; rep.UpdateRight(_right); RightsListForm f = (RightsListForm)this.Owner; f.RefreshGrid(); this.Close(); } catch (Exception ex) { Utils.ShowError(ex); } } }
private void btnAdd_Click(object sender, EventArgs e) { if (IsRightValid()) { try { spAllowedRoleMenu _right = new spAllowedRoleMenu(); if (cboRoles.SelectedIndex != -1) { _right.RoleId = int.Parse(cboRoles.SelectedValue.ToString()); } if (cboMenuItem.SelectedIndex != -1) { _right.MenuItemId = int.Parse(cboMenuItem.SelectedValue.ToString()); } _right.Allowed = chkAllowed.Checked; if (db.spAllowedRoleMenus.Any(i => i.RoleId == _right.RoleId && i.MenuItemId == _right.MenuItemId)) { MessageBox.Show("Right Exist!", "SB Payroll", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (!db.spAllowedRoleMenus.Any(i => i.RoleId == _right.RoleId && i.MenuItemId == _right.MenuItemId)) { db.spAllowedRoleMenus.AddObject(_right); db.SaveChanges(); RightsListForm f = (RightsListForm)this.Owner; f.RefreshGrid(); this.Close(); } } catch (Exception ex) { Utils.ShowError(ex); } } }