/// <summary> /// Set Grid Data source /// </summary> /// <param name="addRow"></param> /// <param name="deleteRow"></param>e private void GenerateMenuItems() { RolePrivilegesLst = new RolePrivilegesList(); RolePrivilegesBLL objRolePrivBLL = new RolePrivilegesBLL(); DataTable mainMenuTable = objRolePrivBLL.GetRolePrivileges(); subMenuTable = mainMenuTable.Copy(); DataView MainMenuView = mainMenuTable.AsDataView(); DataView SubMenuView = subMenuTable.AsDataView(); MainMenuView.RowFilter = "PARENTMENUID=0"; for (int i = 0; i < MainMenuView.Count; i++) { objPriv = new RolePrivilegesBO(); objPriv.MenuID = Convert.ToInt32(MainMenuView[i]["CHILDMENUID"]); objPriv.MenuDescription = MainMenuView[i]["MENUDESCRIPTION"].ToString(); objPriv.ChildMenuCount = Convert.ToInt32(MainMenuView[i]["CHILDMENUCOUNT"]); objPriv.MenuLevel = Convert.ToInt32(MainMenuView[i]["CHILDLEVEL"]); objPriv.ParentMenuID = Convert.ToInt32(MainMenuView[i]["PARENTMENUID"]); RolePrivilegesLst.Add(objPriv); GenerateChildMenu(MainMenuView[i]["CHILDMENUID"].ToString()); } mainMenuTable = null; rptRolePrivileges.DataSource = RolePrivilegesLst; rptRolePrivileges.DataBind(); }
/// <summary> /// Chek User permitions and set his menu controls /// </summary> private void CheckPrivilege() { RolePrivilegesBLL privBLL = new RolePrivilegesBLL(); PrivilegeList = privBLL.GetROLEPRIId(Convert.ToInt32(Session["USER_ID"])); MenuItem navMenuItem = null; for (int mnuItmIDX = NavigationMenu.Items.Count - 1; mnuItmIDX > 0; mnuItmIDX--) { navMenuItem = NavigationMenu.Items[mnuItmIDX]; CheckChildNavigationMenus(navMenuItem); if (navMenuItem.Value.ToUpper() != "Help".ToUpper() && navMenuItem.Value.ToUpper() != "AboutUs".ToUpper() && navMenuItem.Value.ToUpper() != "onlinehelp".ToUpper()) { result = HasViewPermission(navMenuItem.Value); if ((result != null && result.CanView == "N" && result.CanUpdate == "N") || navMenuItem.ChildItems.Count == 0) { NavigationMenu.Items.RemoveAt(mnuItmIDX); } else if (result != null && Session["PROJECT_ID"] == null) { if (result.ProjectDependent != null) { if (result.ProjectDependent == "Y") { //navMenuItem.NavigateUrl = ResolveUrl(projectURL + projectParams); navMenuItem.Selectable = false; navMenuItem.ToolTip = "Select a Project to continue."; //NavigationMenu.Items.RemoveAt(mnuItmIDX); } } } else if (result != null && Session["HH_ID"] == null) { if (result.PAPDependent != null) { if (result.PAPDependent == "Y") { //navMenuItem.NavigateUrl = ResolveUrl("~/UI/Compensation/PAPList.aspx"); navMenuItem.Selectable = false; navMenuItem.ToolTip = "Select a PAP to continue."; //NavigationMenu.Items.RemoveAt(mnuItmIDX); } } } } } }
/// <summary> /// Tofetch role privileges based on userID /// </summary public void getRolePrivByUserID() { int userID = Convert.ToInt32(UserIDDropDownList.SelectedItem.Value.ToString()); if (userID > 0) { CheckBox chkView = null; CheckBox chkUpdate = null; RolePrivilegesBO objRolePrivileges = new RolePrivilegesBO(); RolePrivilegesBLL RolePrivilegesBLLobj = new RolePrivilegesBLL(); RolePrivilegesList RolePrivilegesList = new RolePrivilegesList(); RolePrivilegesList = RolePrivilegesBLLobj.GetROLEPRIId(userID); Literal litMenuID = null; // Clear the controls. ClearGridSelections(); // Populate the controls foreach (RolePrivilegesBO oRolePrivilegesList in RolePrivilegesList) { foreach (RepeaterItem rptRow in rptRolePrivileges.Items) { litMenuID = (Literal)rptRow.FindControl("litMenuID"); chkView = (CheckBox)rptRow.FindControl("chkView"); chkUpdate = (CheckBox)rptRow.FindControl("chkUpdate"); if (oRolePrivilegesList.MenuID.ToString() == litMenuID.Text) { if (oRolePrivilegesList.CanView == "Y") { chkView.Checked = true; } if (oRolePrivilegesList.CanUpdate == "Y") { chkUpdate.Checked = true; } break; } } } } }
/// <summary> /// Check User Has Update Pemitions For Selected Page /// </summary> /// <param name="privilegeValue"></param> /// <returns></returns> public static bool HasUpdatePrivilege(string privilegeValue) { RolePrivilegesList PrivilegeList = null; RolePrivilegesBO result = null; string userID = string.Empty; if ((HttpContext.Current.Session["USER_ID"]) != null) { userID = HttpContext.Current.Session["USER_ID"].ToString(); } else { HttpContext.Current.Response.Redirect("~\\Login.aspx"); } bool hasUpdatePrivilege = false; if (HttpContext.Current.Cache["PRIV_" + userID] != null) { PrivilegeList = (RolePrivilegesList)HttpContext.Current.Cache["PRIV_" + userID]; } else { PrivilegeList = (new RolePrivilegesBLL()).GetROLEPRIId(Convert.ToInt32(userID)); HttpContext.Current.Cache.Insert("PRIV_" + userID, PrivilegeList, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromHours(12)); } result = PrivilegeList.Find( delegate(RolePrivilegesBO priv) { return(priv.MenuName.ToUpper() == privilegeValue.ToUpper()); } ); if (result != null && result.CanUpdate == "Y") { hasUpdatePrivilege = true; } return(hasUpdatePrivilege); }
/// <summary> /// To Get ROLE PRI Id /// </summary> /// <param name="UserID"></param> /// <returns></returns> public RolePrivilegesList GetROLEPRIId(int UserID) { OracleConnection cnn = new OracleConnection(AppConfiguration.ConnectionString); OracleCommand cmd; string proc = "USP_MST_GET_ROLEBYUSERID"; cmd = new OracleCommand(proc, cnn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("USERID_", UserID); cmd.Parameters.Add("Sp_recordset", OracleDbType.RefCursor).Direction = ParameterDirection.Output; cmd.Connection.Open(); OracleDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); RolePrivilegesBO RolePrivilegesObj = null; RolePrivilegesList RolePrivilegesList = new RolePrivilegesList(); while (dr.Read()) { RolePrivilegesObj = new RolePrivilegesBO(); if (!dr.IsDBNull(dr.GetOrdinal("USERID"))) { RolePrivilegesObj.UserID = dr.GetInt32(dr.GetOrdinal("USERID")); } if (!dr.IsDBNull(dr.GetOrdinal("MENUID"))) { RolePrivilegesObj.MenuID = dr.GetInt32(dr.GetOrdinal("MENUID")); } if (!dr.IsDBNull(dr.GetOrdinal("MENULEVEL"))) { RolePrivilegesObj.MenuLevel = dr.GetInt32(dr.GetOrdinal("MENULEVEL")); } if (!dr.IsDBNull(dr.GetOrdinal("MENUNAME"))) { RolePrivilegesObj.MenuName = dr.GetString(dr.GetOrdinal("MENUNAME")); } if (!dr.IsDBNull(dr.GetOrdinal("CANVIEW"))) { RolePrivilegesObj.CanView = dr.GetString(dr.GetOrdinal("CANVIEW")); } if (!dr.IsDBNull(dr.GetOrdinal("CANUPDATE"))) { RolePrivilegesObj.CanUpdate = dr.GetString(dr.GetOrdinal("CANUPDATE")); } if (!dr.IsDBNull(dr.GetOrdinal("CHILDMENUCOUNT"))) { RolePrivilegesObj.ChildMenuCount = dr.GetInt32(dr.GetOrdinal("CHILDMENUCOUNT")); } if (!dr.IsDBNull(dr.GetOrdinal("PROJDEPENDENT"))) { RolePrivilegesObj.ProjectDependent = dr.GetString(dr.GetOrdinal("PROJDEPENDENT")); } else { RolePrivilegesObj.ProjectDependent = "N"; } if (!dr.IsDBNull(dr.GetOrdinal("PAPDEPENDENT"))) { RolePrivilegesObj.PAPDependent = dr.GetString(dr.GetOrdinal("PAPDEPENDENT")); } else { RolePrivilegesObj.PAPDependent = "N"; } RolePrivilegesList.Add(RolePrivilegesObj); } dr.Close(); return(RolePrivilegesList); }
/// <summary> /// To save details to database /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void SaveButton_Click(object sender, EventArgs e) { string message = string.Empty; int userID = Convert.ToInt32(UserIDDropDownList.SelectedItem.Value.ToString()); int count = 0; string noneValue = String.Empty; CheckBox chkView = null; CheckBox chkUpdate = null; RolePrivilegesBLL RolePrivilegesBLLOBJ = new RolePrivilegesBLL(); RolePrivilegesBO objRolePrivileges = null; RolePrivilegesList RolePrivilegesList = new RolePrivilegesList(); DeleteRolePrivileges(userID); try { foreach (RepeaterItem rptItem in rptRolePrivileges.Items) { if (rptItem.ItemType == ListItemType.Item || rptItem.ItemType == ListItemType.AlternatingItem) { int menuID = Convert.ToInt32(((Literal)rptItem.FindControl("litMenuID")).Text); chkView = (CheckBox)rptItem.FindControl("chkView"); chkUpdate = (CheckBox)rptItem.FindControl("chkUpdate"); if (menuID > 0) { objRolePrivileges = new RolePrivilegesBO(); objRolePrivileges.MenuID = menuID; if (chkView != null && chkView.Checked) { objRolePrivileges.CanView = "Y"; } if (chkUpdate != null && chkUpdate.Checked) { objRolePrivileges.CanUpdate = "Y"; } objRolePrivileges.UserID = Convert.ToInt32(UserIDDropDownList.SelectedItem.Value); objRolePrivileges.UpdatedBy = Convert.ToInt32(Session["USER_ID"]); count = RolePrivilegesBLLOBJ.InsertRolePrivilages(objRolePrivileges); } } } if (count == -1) { message = "Data saved successfully"; System.Collections.IDictionaryEnumerator cacheDict = Cache.GetEnumerator(); while (cacheDict.MoveNext()) { if (cacheDict.Key.ToString().IndexOf("PRIV_") >= 0) { Cache.Remove(cacheDict.Key.ToString()); } } ; GenerateMenuItems(); getRolePrivByUserID(); } else { message = "Data could not be saved"; } } catch (Exception ex) { throw ex; } finally { RolePrivilegesBLLOBJ = null; } ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Added", "alert('" + message + "');", true); }