Example #1
0
        public EditRightForm(spAllowedRoleMenu right, string Conn)
        {
            InitializeComponent();
            if (string.IsNullOrEmpty(Conn))
            {
                throw new ArgumentNullException("connection");
            }
            connection = Conn;

            rep = new Repository(connection);
            db  = new SBPayrollDBEntities(connection);

            if (right == null)
            {
                throw new ArgumentNullException("right");
            }
            _right = right;
        }
 private void btnDelete_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     if (dataGridViewRights.SelectedRows.Count != 0)
     {
         try
         {
             spAllowedRoleMenu _right = (spAllowedRoleMenu)bindingSourceRights.Current;
             if (DialogResult.Yes == MessageBox.Show("Are you sure you want to delete Right", "Confirm Delete", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
             {
                 db.spAllowedRoleMenus.DeleteObject(_right);
                 db.SaveChanges();
                 RefreshGrid();
             }
         }
         catch (Exception ex)
         {
             Utils.ShowError(ex);
         }
     }
 }
 private void btnEdit_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     if (dataGridViewRights.SelectedRows.Count != 0)
     {
         try
         {
             spAllowedRoleMenu _right = (spAllowedRoleMenu)bindingSourceRights.Current;
             EditRightForm     eus    = new EditRightForm(_right, connection)
             {
                 Owner = this
             };
             eus.Text = "Edit Right";
             eus.ShowDialog();
         }
         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);
                }
            }
        }