Beispiel #1
0
        private void saveChildrenModules(SecRoleModule parentModule, GridView gvModulePermission)
        {
            SecRoleModule roleModule = null;

            foreach (GridViewRow row in gvModulePermission.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    CheckBox cbxViewPermission   = row.FindControl("cbxViewPermission") as CheckBox;
                    CheckBox cbxEditPermission   = row.FindControl("cbxEditPermission") as CheckBox;
                    CheckBox cbxAddPermission    = row.FindControl("cbxAddPermission") as CheckBox;
                    CheckBox cbxDeletePermission = row.FindControl("cbxDeletePermission") as CheckBox;

                    if (cbxViewPermission.Checked || cbxEditPermission.Checked || cbxEditPermission.Checked || cbxDeletePermission.Checked)
                    {
                        // save child
                        roleModule = new SecRoleModule();

                        roleModule.ClientID = parentModule.ClientID;
                        roleModule.RoleID   = parentModule.RoleID;

                        roleModule.ModuleID = (int)gvModulePermission.DataKeys[row.RowIndex].Value;
                        roleModule.Status   = 1;

                        roleModule.ViewPermission   = cbxViewPermission.Checked;
                        roleModule.AddPermssion     = cbxAddPermission != null ? cbxAddPermission.Checked : false;
                        roleModule.DeletePermission = cbxDeletePermission != null ? cbxDeletePermission.Checked : false;;
                        roleModule.EditPermission   = cbxEditPermission != null ? cbxEditPermission.Checked : false;

                        SecRoleModuleManager.SaveRoleModule(roleModule);
                    }
                }
            }
        }
Beispiel #2
0
        private void processTreeView(TreeNodeCollection parentNode)
        {
            SecRoleModule roleModule = null;

            if (parentNode != null && parentNode != null && parentNode.Count > 0)
            {
                foreach (TreeNode node in parentNode)
                {
                    if (node.Checked)
                    {
                        roleModule          = new SecRoleModule();
                        roleModule.ModuleID = Convert.ToInt32(node.Value);
                        roleModule.RoleID   = Convert.ToInt32(ViewState["RoleID"]);
                        roleModule.Status   = 1;

                        roleModule.ViewPermission   = true;
                        roleModule.AddPermssion     = false;
                        roleModule.DeletePermission = false;
                        roleModule.EditPermission   = false;

                        SecRoleModuleManager.SaveRoleModule(roleModule);
                    }
                    processTreeView(node.ChildNodes);
                }
            }
        }
Beispiel #3
0
        private void saveRoleModules(int clientID, int roleID)
        {
            SecRoleModule roleModule = null;

            foreach (GridViewRow row in gvModules.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    CheckBox cbxModule = row.FindControl("cbxModule") as CheckBox;

                    if (cbxModule.Checked)
                    {
                        roleModule = new SecRoleModule();

                        roleModule.ClientID = clientID;
                        roleModule.RoleID   = roleID;

                        roleModule.ModuleID = (int)gvModules.DataKeys[row.RowIndex].Value;
                        roleModule.Status   = 1;

                        roleModule.ViewPermission   = cbxModule.Checked;
                        roleModule.AddPermssion     = true;
                        roleModule.DeletePermission = false;
                        roleModule.EditPermission   = true;

                        SecRoleModuleManager.SaveRoleModule(roleModule);

                        GridView gvModulePermission = row.FindControl("gvModulePermission") as GridView;

                        // save
                        saveChildrenModules(roleModule, gvModulePermission);
                    }
                }
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            lblError.Text    = string.Empty;
            lblSave.Text     = string.Empty;
            lblSave.Visible  = false;
            lblError.Visible = false;
            try {
                using (TransactionScope scope = new TransactionScope()) {
                    SecRoleModuleManager.UpdateSecRoleModuleStatus(Convert.ToInt32(ddlRole.SelectedValue));

                    foreach (GridViewRow row in grdModule.Rows)
                    {
                        int         check          = 0;
                        int         checkParent    = 0;
                        GridView    gv             = (GridView)row.FindControl("gvSubModule");
                        HiddenField hfRoleModuleId = (HiddenField)row.FindControl("hfRoleModuleId");
                        HiddenField hfModuleId     = (HiddenField)row.FindControl("hfModuleId");

                        if (hfRoleModuleId.Value == string.Empty)
                        {
                            hfRoleModuleId.Value = "0";
                        }

                        CheckBox chkAllAdd  = (CheckBox)row.FindControl("chkAllAdd");
                        CheckBox chkAllEdit = (CheckBox)row.FindControl("chkAllEdit");
                        CheckBox chkAllDel  = (CheckBox)row.FindControl("chkAllDel");
                        CheckBox chkAllView = (CheckBox)row.FindControl("chkAllView");

                        SecRoleModule roleModuleMainGrid = SecRoleModuleManager.GetByRoleModuleId(Convert.ToInt32(hfRoleModuleId.Value));
                        if (chkAllView.Checked || chkAllAdd.Checked || chkAllEdit.Checked || chkAllEdit.Checked)
                        {
                            var secRoleModule = new CRM.Data.Entities.SecRoleModule {
                                ModuleID         = Convert.ToInt32(hfModuleId.Value),
                                RoleID           = Convert.ToInt32(ddlRole.SelectedValue),
                                AddPermssion     = chkAllAdd.Checked == true ? true : false,
                                EditPermission   = chkAllEdit.Checked == true ? true : false,
                                DeletePermission = chkAllDel.Checked == true ? true : false,
                                ViewPermission   = chkAllView.Checked == true ? true : false,
                                Status           = 1,
                                CreatedBy        = Convert.ToInt32(HttpContext.Current.User.Identity.Name),
                                CreatedOn        = DateTime.Now,
                                UpdatedBy        = Convert.ToInt32(HttpContext.Current.User.Identity.Name),
                                UpdatedOn        = DateTime.Now,
                                CreatedMachineIP = Request.ServerVariables["remote_addr"].ToString(),
                            };
                            SecRoleModuleManager.SaveRoleModule(secRoleModule);
                            checkParent = 1;
                        }


                        foreach (GridViewRow subGridRow in gv.Rows)
                        {
                            CheckBox      chkAdd          = (CheckBox)subGridRow.FindControl("chkAdd");
                            CheckBox      chkEdit         = (CheckBox)subGridRow.FindControl("chkEdit");
                            CheckBox      chkDelete       = (CheckBox)subGridRow.FindControl("chkDel");
                            CheckBox      chkView         = (CheckBox)subGridRow.FindControl("chkView");
                            HiddenField   hfModuleIdChild = (HiddenField)subGridRow.FindControl("hfModuleIdChild");
                            SecRoleModule roleModule      = SecRoleModuleManager.GetByRoleModuleId(Convert.ToInt32(hfRoleModuleId.Value));
                            if (chkAdd.Checked || chkEdit.Checked || chkDelete.Checked || chkView.Checked)
                            {
                                var secRoleModuleChild = new CRM.Data.Entities.SecRoleModule {
                                    ModuleID         = Convert.ToInt32(hfModuleIdChild.Value),
                                    RoleID           = Convert.ToInt32(ddlRole.SelectedValue),
                                    AddPermssion     = chkAdd.Checked == true ? true : false,
                                    EditPermission   = chkEdit.Checked == true ? true : false,
                                    DeletePermission = chkDelete.Checked == true ? true : false,
                                    ViewPermission   = chkView.Checked == true ? true : false,
                                    Status           = 1,
                                    CreatedBy        = Convert.ToInt32(HttpContext.Current.User.Identity.Name),
                                    CreatedOn        = DateTime.Now,
                                    UpdatedBy        = Convert.ToInt32(HttpContext.Current.User.Identity.Name),
                                    UpdatedOn        = DateTime.Now,
                                    CreatedMachineIP = Request.ServerVariables["remote_addr"].ToString(),
                                };
                                SecRoleModuleManager.SaveRoleModule(secRoleModuleChild);
                                check       = 1;
                                checkParent = 0;
                            }

                            GridView gvchild = (GridView)subGridRow.FindControl("gvSubModule1");
                            if (gvchild.Rows.Count > 0)
                            {
                                foreach (GridViewRow child in gvchild.Rows)
                                {
                                    CheckBox      chkAdd1          = (CheckBox)child.FindControl("chkAdd");
                                    CheckBox      chkEdit1         = (CheckBox)child.FindControl("chkEdit");
                                    CheckBox      chkDelete1       = (CheckBox)child.FindControl("chkDel");
                                    CheckBox      chkView1         = (CheckBox)child.FindControl("chkView");
                                    HiddenField   hfModuleIdChild1 = (HiddenField)child.FindControl("hfModuleIdChild1");
                                    SecRoleModule roleModule1      = SecRoleModuleManager.GetByRoleModuleId(Convert.ToInt32(hfRoleModuleId.Value));
                                    if (chkAdd1.Checked || chkEdit1.Checked || chkDelete1.Checked || chkView1.Checked)
                                    {
                                        var secRoleModuleChild = new CRM.Data.Entities.SecRoleModule {
                                            ModuleID         = Convert.ToInt32(hfModuleIdChild1.Value),
                                            RoleID           = Convert.ToInt32(ddlRole.SelectedValue),
                                            AddPermssion     = chkAdd.Checked == true ? true : false,
                                            EditPermission   = chkEdit.Checked == true ? true : false,
                                            DeletePermission = chkDelete.Checked == true ? true : false,
                                            ViewPermission   = chkView.Checked == true ? true : false,
                                            Status           = 1,
                                            CreatedBy        = Convert.ToInt32(HttpContext.Current.User.Identity.Name),
                                            CreatedOn        = DateTime.Now,
                                            UpdatedBy        = Convert.ToInt32(HttpContext.Current.User.Identity.Name),
                                            UpdatedOn        = DateTime.Now,
                                            CreatedMachineIP = Request.ServerVariables["remote_addr"].ToString(),
                                        };
                                        SecRoleModuleManager.SaveRoleModule(secRoleModuleChild);
                                        check       = 1;
                                        checkParent = 0;
                                    }
                                }
                            }
                        }
                    }

                    CRM.Data.Entities.SecUser user = SecUserManager.GetByUserId(Convert.ToInt32(HttpContext.Current.User.Identity.Name));
                    if (user.SecRole.RoleId == Convert.ToInt32(ddlRole.SelectedValue))
                    {
                        Session["rolePermission"] = refreshRolePermission = SecRoleModuleManager.getRolePermission(user.SecRole.RoleId).ToList();
                    }
                    bindGrid(Convert.ToInt32(ddlRole.SelectedValue));
                    lblSave.Text    = "Record Saved Sucessfully.";
                    lblSave.Visible = true;
                    scope.Complete();
                }
            }
            catch (Exception ex) {
                lblError.Text    = "Record Not Saved Sucessfully.";
                lblError.Visible = true;
            }
        }