protected void ddlRole_SelectedIndexChanged(object sender, EventArgs e) { try { RoleRightsBL objRoleRightsBL = new RoleRightsBL(); DataTable dtRoleRight = new DataTable(); ApplicationResult objApplicationResult = new ApplicationResult(); DataTable dt = new DataTable(); dt.Rows.Clear(); gvSelectRights.DataSource = dt; gvSelectRights.DataBind(); BindScreen(); objApplicationResult = objRoleRightsBL.RoleRights_T_Select(Convert.ToInt32(ddlRole.SelectedValue), Convert.ToInt32(Session[ApplicationSession.TRUSTID]), Convert.ToInt32(ViewState["SchoolMID"].ToString()), 0); dtRoleRight = objApplicationResult.resultDT; if (dtRoleRight.Rows.Count > 0) { int j = 0; foreach (GridViewRow rowItem in gvSelectRights.Rows) { for (int i = 0; i < dtRoleRight.Rows.Count; i++) { if (gvSelectRights.Rows[j].Cells[0].Text.ToString() == dtRoleRight.Rows[i]["ScreenID"].ToString()) { CheckBox chk = (CheckBox)gvSelectRights.Rows[j].FindControl("chkRights"); chk.Checked = true; if (ddlRole.SelectedValue == "1") { chk.Enabled = false; } else { chk.Enabled = true; } } } j++; } } } catch (Exception ex) { logger.Error("Error", ex); ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "<script>alert('Oops! There is some technical Problem. Contact to your Administrator.');</script>"); } }
protected void btnSave_Click(object sender, EventArgs e) { try { RoleRightsBO objRoleRightsBO = new RoleRightsBO(); RoleRightsBL objRoleRightsBL = new RoleRightsBL(); ApplicationResult objResultsInsert = new ApplicationResult(); ApplicationResult objResultsSelect = new ApplicationResult(); ApplicationResult objResultsDelete = new ApplicationResult(); DataTable dtRoleRights = new DataTable(); int j = 0; CheckBox chk; for (int i = 0; i < gvSelectRights.Rows.Count; i++) { objResultsSelect = objRoleRightsBL.RoleRights_T_Select(Convert.ToInt32(ddlRole.SelectedValue), Convert.ToInt32(Session[ApplicationSession.TRUSTID]), 0, Convert.ToInt32(gvSelectRights.Rows[i].Cells[0].Text)); chk = (CheckBox)gvSelectRights.Rows[i].Cells[2].FindControl("chkRights"); if (chk.Checked == true) { if (rblSelect.SelectedValue == "0") { if (objResultsSelect != null) { if (objResultsSelect.resultDT.Rows.Count > 0) { } else { objRoleRightsBO.RoleID = Convert.ToInt32(ddlRole.SelectedValue); objRoleRightsBO.TrustMID = Convert.ToInt32(Session[ApplicationSession.TRUSTID]); objRoleRightsBO.SchoolMID = 0; objRoleRightsBO.ScreenID = Convert.ToInt32(gvSelectRights.Rows[i].Cells[0].Text); objResultsInsert = objRoleRightsBL.RoleRights_Insert(objRoleRightsBO); if (Convert.ToInt32(gvSelectRights.Rows[i].Cells[1].Text) == 1) { ApplicationResult objResults = new ApplicationResult(); SchoolBL objSchool = new SchoolBL(); objResults = objSchool.School_SelectAll(Convert.ToInt32(Session[ApplicationSession.TRUSTID])); if (objResults != null) { if (objResults.resultDT.Rows.Count > 0) { foreach (DataRow dt in objResults.resultDT.Rows) { objRoleRightsBO.RoleID = Convert.ToInt32(ddlRole.SelectedValue); objRoleRightsBO.TrustMID = Convert.ToInt32(Session[ApplicationSession.TRUSTID]); objRoleRightsBO.SchoolMID = Convert.ToInt32(dt[0].ToString()); objRoleRightsBO.ScreenID = Convert.ToInt32(Convert.ToInt32(gvSelectRights.Rows[i].Cells[0].Text)); objResultsInsert = objRoleRightsBL.RoleRights_Insert(objRoleRightsBO); } } } } } } } else { objRoleRightsBO.RoleID = Convert.ToInt32(ddlRole.SelectedValue); objRoleRightsBO.TrustMID = Convert.ToInt32(Session[ApplicationSession.TRUSTID]); objRoleRightsBO.SchoolMID = Convert.ToInt32(ViewState["SchoolMID"].ToString()); objRoleRightsBO.ScreenID = Convert.ToInt32(Convert.ToInt32(gvSelectRights.Rows[i].Cells[0].Text)); objResultsInsert = objRoleRightsBL.RoleRights_Insert(objRoleRightsBO); } } else { if (rblSelect.SelectedValue == "0") { dtRoleRights = objResultsSelect.resultDT; if (objResultsSelect.resultDT.Rows.Count > 0) { objResultsDelete = objRoleRightsBL.RoleRights_Delete(Convert.ToInt32(ddlRole.SelectedValue), Convert.ToInt32(Session[ApplicationSession.TRUSTID]), 0, Convert.ToInt32(gvSelectRights.Rows[i].Cells[0].Text)); } } else { objResultsDelete = objRoleRightsBL.RoleRights_Delete(Convert.ToInt32(ddlRole.SelectedValue), Convert.ToInt32(Session[ApplicationSession.TRUSTID]), Convert.ToInt32(ViewState["SchoolMID"].ToString()), Convert.ToInt32(gvSelectRights.Rows[i].Cells[0].Text)); } } } if (objResultsInsert.status == ApplicationResult.CommonStatusType.SUCCESS) { ClearAll(); BindScreen(); lblMsg.Visible = true; lblMsg.Text = "Roles Applied Successfully"; } //objResultsSelect = objRoleRightsBL.RoleRights_Select(Convert.ToInt32(ddlRole.SelectedValue), Convert.ToInt32(Session[ApplicationSession.TRUSTID]), Convert.ToInt32(ViewState["SchoolMID"].ToString())); //if (objResultsSelect != null) //{ // dtRoleRights = objResultsSelect.resultDT; // if (dtRoleRights.Rows.Count > 0) // { // // objResultsDelete = objRoleRightsBL.RoleRights_Delete(Convert.ToInt32(ddlRole.SelectedValue), Convert.ToInt32(Session[ApplicationSession.TRUSTID]), Convert.ToInt32(ViewState["SchoolMID"].ToString())); // } //} //for (int i = 0; i < gvSelectRights.Rows.Count; i++) //{ // chk = (CheckBox)gvSelectRights.Rows[i].Cells[2].FindControl("chkRights"); // if (chk.Checked == true) // { // objRoleRightsBO.RoleID = Convert.ToInt32(ddlRole.SelectedValue); // objRoleRightsBO.TrustMID = Convert.ToInt32(Session[ApplicationSession.TRUSTID]); // objRoleRightsBO.SchoolMID = Convert.ToInt32(ViewState["SchoolMID"].ToString()); // objRoleRightsBO.ScreenID = Convert.ToInt32(gvSelectRights.Rows[i].Cells[1].Text); // objResultsInsert = objRoleRightsBL.RoleRights_Insert(objRoleRightsBO); // } //} // } catch (Exception ex) { logger.Error("Error", ex); ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "<script>alert('Oops! There is some technical Problem. Contact to your Administrator.');</script>"); } }