Beispiel #1
0
        protected void btPhanQuyen_Click(object sender, EventArgs e)
        {
            if (!UserRightImpl.CheckRightAdminnistrator().UserEdit)
            {
                Response.Redirect(Utility.UrlRoot + Config.PathNotRight, false);
                return;
            }
            if (ddlUser.Text.Equals("0"))
            {
                lbMess.Text = "<p><font color='red'>Bạn phải chọn username phân quyền trước.</font></p>";
                return;
            }
            try
            {
                int           menuIndex = ddlMenu.SelectedIndex;
                int           i         = 0;
                UserRightImpl obj       = new UserRightImpl();
                foreach (GridViewRow row in grvView.Rows)
                {
                    var chkRead   = (CheckBox)row.FindControl("chkRead");
                    var chkEdit   = (CheckBox)row.FindControl("chkEdit");
                    var chkDelete = (CheckBox)row.FindControl("chkDelete");

                    UserRightInfo item = new UserRightInfo();

                    item.MenuID = int.Parse(grvView.DataKeys[row.RowIndex].Value.ToString());
                    if (_adminID == 0)
                    {
                        _adminID = int.Parse(ddlUser.Text.ToString());
                    }
                    item.AdminID = _adminID;

                    item.UserRead = chkRead.Checked;
                    if (menuIndex == 1)
                    {
                        item.UserEdit   = chkEdit.Checked;
                        item.UserDelete = chkDelete.Checked;
                    }
                    else
                    {
                        item.UserEdit   = true;
                        item.UserDelete = true;
                    }
                    UserRightInfo item2 = obj.GetRightByMenuAndAdmin(item.MenuID, item.AdminID);
                    if (item2 != null)
                    {
                        item.ID = item2.ID;
                        obj.Update(item);
                    }
                    else
                    {
                        obj.Insert(item);
                    }
                }
            }
            catch
            {
                Response.Redirect(Utility.UrlRoot + Config.PathError, false);
                return;
            }
        }