public void BindModuleList(int RoleId,int DeptId,int CompId) { objAuthorizationDal = new AuthorizationDal(); DataSet dsMenuItem = new DataSet(); DataTable dtModuleName = new DataTable(); dtModuleName = objAuthorizationDal.FetchModule(RoleId,DeptId,CompId).Tables[0]; menuMainModule.Items.Clear(); // MenuItem itemHome = new MenuItem("HOME", "0"); // itemHome.Value = "0"; // menuMainModule.Items.Add(itemHome); for (int i = 0; i < dtModuleName.Rows.Count; i++) { MenuItem item = new MenuItem(dtModuleName.Rows[i]["MODULE_NAME"].ToString(), dtModuleName.Rows[i]["MODULE_ID"].ToString()); menuMainModule.Items.Add(item); } }
public void BindLeftMenu(int ModuleId, int RoleId, int CompId, int DeptId) { objAuthorizationDal = new AuthorizationDal(); DataSet dsMenuItem = new DataSet(); DataTable dtMenuItem = new DataTable(); for (int i = 1; i < 24; i++) { try { dtMenuItem = objAuthorizationDal.FetchMenuProgram(ModuleId, RoleId, i,CompId,DeptId).Tables[0]; createmenuinside(dtMenuItem); } catch (Exception ex) { } } }
protected void btnLogin_Click(object sender, EventArgs e) { string username = txtUserName.Text.Trim(); string password = txtPassword.Text.Trim(); AuthorizationDal objAuthorizationDal = new AuthorizationDal(); DataSet ds = objAuthorizationDal.ValidateSystemLogin(username, password); if (ds != null && ds.Tables.Count > 0) { if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["RESULT"].ToString() == "-2") //Restricted User { if (ds.Tables[0].Rows[0]["USER_ID"].ToString() != null) { int UserId = int.Parse(ds.Tables[0].Rows[0]["USER_ID"].ToString()); string ipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (ipaddress == "" || ipaddress == null) ipaddress = Request.ServerVariables["REMOTE_ADDR"]; int Result = objAuthorizationDal.InsertLoginLog(UserId, ipaddress, false); } lblError.Text = "Invalid Username or Password.<br />Login failed!"; } else if (ds.Tables[0].Rows[0]["RESULT"].ToString() == "-1") //Login Failed { if (ds.Tables[0].Rows[0]["USER_ID"].ToString() != null) { int UserId = int.Parse(ds.Tables[0].Rows[0]["USER_ID"].ToString()); string ipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (ipaddress == "" || ipaddress == null) ipaddress = Request.ServerVariables["REMOTE_ADDR"]; int Result = objAuthorizationDal.InsertLoginLog(UserId, ipaddress, false); } lblError.Text = "Invalid Username or Password.<br />Login failed!"; } else if (ds.Tables[0].Rows[0]["USER_STATUS_ID"].ToString() != "1") { lblError.Text = "User is inactive.<br />Login failed!"; } else if (ds.Tables[0].Rows[0]["RESULT"].ToString() == "1") //Login SucessFully { bool isPersistent = chkRememberMe.Checked; FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, username, DateTime.Now, DateTime.Now.AddMinutes(120), isPersistent, username, FormsAuthentication.FormsCookiePath); // Encrypt the ticket. string encTicket = FormsAuthentication.Encrypt(ticket); // Create the cookie. Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket)); // Add Userdata to Session if (ds != null && ds.Tables.Count > 0) { if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) { objUserProfile.UserId = Convert.ToInt32(ds.Tables[0].Rows[0]["USER_ID"]); objUserProfile.UserName = ds.Tables[0].Rows[0]["USER_NAME"].ToString(); objUserProfile.EmployeeId = Convert.ToInt32(ds.Tables[0].Rows[0]["EMP_ID"]); objUserProfile.EmployeeName = ds.Tables[0].Rows[0]["EMP_NAME"].ToString(); objUserProfile.EmployeeEmail = ds.Tables[0].Rows[0]["EMP_EMAIL"].ToString(); objUserProfile.EmployeeMobile = ds.Tables[0].Rows[0]["EMP_MOBILE"].ToString(); objUserProfile.DefaultTheme = ds.Tables[0].Rows[0]["DEFAULT_THEME"].ToString(); objUserProfile.Signature = ds.Tables[0].Rows[0]["SIGNATURE_PASSWORD"].ToString(); objUserProfile.Password = ds.Tables[0].Rows[0]["PASSWORD"].ToString(); objUserProfile.Cust_id = ds.Tables[0].Rows[0]["CUST_ID"].ToString(); objUserProfile.Supplier_id = ds.Tables[0].Rows[0]["SUPPLIER_ID"].ToString(); objUserProfile.EmployeeFlag = ds.Tables[0].Rows[0]["FLAG"].ToString(); objUserProfile.CompanyName = ds.Tables[1].Rows[0]["COMPANY_NAME"].ToString(); Session[PageConstants.ThemeName] = objUserProfile.DefaultTheme.Trim(); } if (ds.Tables[1] != null && ds.Tables[1].Rows.Count > 0) { objAuthorizationBDto.UserPermission = ds.Tables[1]; } Session["usersname"] = objUserProfile.UserName; Session["usersid"] = objUserProfile.UserId; Session["DateTime.Now"] = DateTime.Now.ToString("d"); Session["users"] = ds.Tables[0]; Session["empid"] = objUserProfile.EmployeeId; Session["signature"] = objUserProfile.Signature; Session["password"] = objUserProfile.Password; Session["cust_id"] = objUserProfile.Cust_id; Session["supplier_id"] = objUserProfile.Supplier_id; Session["FLAG"] = objUserProfile.EmployeeFlag; Session["COMPANY_NAME"] = objUserProfile.CompanyName; #region for online users int USERID = objUserProfile.UserId; string LOGINDATE = DateTime.Now.ToString("d"); DataSet dstype = objAuthorizationDal.GetUsertype(Convert.ToInt32(Session["cust_id"])); string CustTypeID = Convert.ToString(dstype.Tables[0].Rows[0]["CUST_TYPE_ID"]); Session["CustTypeID"] = CustTypeID; DataSet ds1 = objAuthorizationDal.GetOnlineUsers(USERID, LOGINDATE); Session["users1"] = ds1.Tables[0]; #endregion } //Add User Login Log if (ds.Tables[0].Rows[0]["USER_ID"].ToString() != null) { int UserId = int.Parse(ds.Tables[0].Rows[0]["USER_ID"].ToString()); string ipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (ipaddress == "" || ipaddress == null) ipaddress = Request.ServerVariables["REMOTE_ADDR"]; int Result = objAuthorizationDal.InsertLoginLog(UserId, ipaddress, true); } Session["AUTH_USER_NAME"] = username; objAuthorizationBDto.UserProfile = objUserProfile; Session[PageConstants.ssnUserAuthorization] = objAuthorizationBDto; // Redirect to requested url //Response.Redirect(FormsAuthentication.GetRedirectUrl(username, isPersistent)); Response.Redirect("~/Views/Workplace/Dashboard.aspx"); } else { lblError.Text = "Invalid Username or Password.<br />Login failed!"; } } else { lblError.Text = "Invalid Username or Password.<br />Login failed!"; } } #region Comment //if (ds != null && ds.Tables.Count > 0) //{ // bool isPersistent = chkRememberMe.Checked; // FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, // username, // DateTime.Now, // DateTime.Now.AddMinutes(60), // isPersistent, // username, // FormsAuthentication.FormsCookiePath); // // Encrypt the ticket. // string encTicket = FormsAuthentication.Encrypt(ticket); // // Create the cookie. // Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket)); // // Add Userdata to Session // if (ds != null && ds.Tables.Count > 0) // { // if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) // { // objUserProfile.UserId = Convert.ToInt32(ds.Tables[0].Rows[0]["USER_ID"]); // objUserProfile.UserName = ds.Tables[0].Rows[0]["USER_NAME"].ToString(); // objUserProfile.DefaultTheme = ds.Tables[0].Rows[0]["DEFAULT_THEME"].ToString(); // Session[PageConstants.ThemeName] = objUserProfile.DefaultTheme.Trim(); // } // if (ds.Tables[1] != null && ds.Tables[1].Rows.Count > 0) // { // objAuthorizationBDto.UserPermission = ds.Tables[1]; // } // } // //Session["AUTH_USER_NAME"] = username; // objAuthorizationBDto.UserProfile = objUserProfile; // Session[PageConstants.ssnUserAuthorization] = objAuthorizationBDto; // // Redirect to requested url // //Response.Redirect(FormsAuthentication.GetRedirectUrl(username, isPersistent)); // Response.Redirect("~/Default.aspx"); //} //else //{ // lblError.Text = "Invalid Username or Password.<br />Login failed!"; //} #endregion }
public static void CheckUserAuthorizationForProgram(string ProgramName) { DataTable dtAccess = new DataTable(); DataSet dsAccess = new DataSet(); AuthorizationBDto objAuthorizationBDto; AuthorizationDal objAuthorizationDal; if (HttpContext.Current.Session[PageConstants.ssnUserAuthorization] != null) { objAuthorizationBDto = (AuthorizationBDto)HttpContext.Current.Session[PageConstants.ssnUserAuthorization]; int RoleId = objAuthorizationBDto.UserSelectedRoleId; if (RoleId != 0) { objAuthorizationDal = new AuthorizationDal(); dsAccess = objAuthorizationDal.GetProgrameAccessByProgramName(RoleId, ProgramName); dtAccess = dsAccess.Tables[0]; if (dtAccess.Rows.Count > 0) { if (dtAccess.Rows[0]["READ_ACCESS"] != null) { if (dtAccess.Rows[0]["READ_ACCESS"].ToString() != "True") { int ModuleId = int.Parse(dtAccess.Rows[0]["MODULE_ID"].ToString()); switch (ModuleId) { case 1: // Administration HttpContext.Current.Response.Redirect("~/Views/Administration/AccessDenied.aspx"); break; case 2: // Customers HttpContext.Current.Response.Redirect("~/Views/Customers/AccessDenied.aspx"); break; case 3: // Inquiry HttpContext.Current.Response.Redirect("~/Views/Inquiry/AccessDenied.aspx"); break; case 4: // Orders HttpContext.Current.Response.Redirect("~/Views/Orders/AccessDenied.aspx"); break; case 5: // Fares HttpContext.Current.Response.Redirect("~/Views/Fares/AccessDenied.aspx"); break; case 6: // HR HttpContext.Current.Response.Redirect("~/Views/HR/AccessDenied.aspx"); break; default: break; } } } else { HttpContext.Current.Response.Redirect("~/Default.aspx"); } objAuthorizationBDto = new AuthorizationBDto(); objAuthorizationBDto = (AuthorizationBDto)HttpContext.Current.Session[PageConstants.ssnUserAuthorization]; if (dtAccess.Rows[0]["READ_ACCESS"] != null) objAuthorizationBDto.ProgramReadAccess = bool.Parse(dtAccess.Rows[0]["READ_ACCESS"].ToString()); if (dtAccess.Rows[0]["WRITE_ACCESS"] != null) objAuthorizationBDto.ProgramWriteAccess = bool.Parse(dtAccess.Rows[0]["WRITE_ACCESS"].ToString()); if (dtAccess.Rows[0]["DELETE_ACCESS"] != null) objAuthorizationBDto.ProgramDeleteAccess = bool.Parse(dtAccess.Rows[0]["DELETE_ACCESS"].ToString()); if (dtAccess.Rows[0]["PRINT_ACCESS"] != null) objAuthorizationBDto.ProgramPrintAccess = bool.Parse(dtAccess.Rows[0]["PRINT_ACCESS"].ToString()); HttpContext.Current.Session[PageConstants.ssnUserAuthorization] = objAuthorizationBDto; } else { HttpContext.Current.Response.Redirect("~/Default.aspx"); } } } }
private void SaveAndLoadUserSelectedPreferences() { DataTable dtPreference = new DataTable(); Label RoleId=new Label(); Label RoleName = new Label(); Label CompanyId = new Label(); Label CompanyName = new Label(); Label DeptId = new Label(); Label DeptName = new Label(); for (int i = 0; i < grdCompanyRoleasp.Rows.Count; i++) { if (grdCompanyRoleasp.Rows[i].FindControl("rbCompanyRole") != null) { if (((RadioButton)grdCompanyRoleasp.Rows[i].Cells[0].FindControl("rbCompanyRole")).Checked) { RoleId = (Label)grdCompanyRoleasp.Rows[i].Cells[6].FindControl("lblroleid"); RoleName = (Label)grdCompanyRoleasp.Rows[i].Cells[4].FindControl("lblrolename"); CompanyId = (Label)grdCompanyRoleasp.Rows[i].Cells[5].FindControl("lblcmpid"); CompanyName = (Label)grdCompanyRoleasp.Rows[i].Cells[1].FindControl("lblcmpname"); DeptId = (Label)grdCompanyRoleasp.Rows[i].Cells[7].FindControl("lbldeptid"); DeptName = (Label)grdCompanyRoleasp.Rows[i].Cells[3].FindControl("lbldeptname"); objAuthorizationBDto = (AuthorizationBDto)Session[PageConstants.ssnUserAuthorization]; objAuthorizationDal = new AuthorizationDal(); int Result = objAuthorizationDal.UpdateUserDefaultPreference(objAuthorizationBDto.UserProfile.UserId, int.Parse(CompanyId.Text),int.Parse(RoleId.Text),int.Parse(DeptId.Text)); } } } dtPreference = objAuthorizationDal.PreferenceGridByUserId(objAuthorizationBDto.UserProfile.UserId).Tables[0]; if (objAuthorizationBDto != null) objAuthorizationBDto.SetUserSelectedPreferences(dtPreference, int.Parse(CompanyId.Text), CompanyName.Text, int.Parse(RoleId.Text), RoleName.Text,int.Parse(DeptId.Text),DeptName.Text); }
protected void RedirectToDefaultPage() { #region for online users AuthorizationDal objAuthorizationDal = new AuthorizationDal(); UserProfileBDto objUserProfile = new UserProfileBDto(); //int ISLOGIN=1; int USERID = Convert.ToInt32(Session["usersid"]); //int USERID = objUserProfile.UserId; string LOGINDATE = DateTime.Now.ToString(); DataSet ds1 = objAuthorizationDal.GetSignOutUsers(USERID, LOGINDATE); Session.Remove("users1"); Session["users1"] = ds1.Tables[0]; #endregion HttpContext.Current.Session.RemoveAll(); HttpContext.Current.Session.Abandon(); FormsAuthentication.SignOut(); Response.Redirect("~/Default.aspx"); }
protected void btnSetDefault_Click(object sender, EventArgs e) { AuthorizationDal objAuthorizationDal = new AuthorizationDal(); objAuthorizationDal.SetTheme(objAuthorizationBDto.UserProfile.UserId, radcmbTheme.SelectedValue); objAuthorizationBDto.UserProfile.DefaultTheme = radcmbTheme.SelectedValue; Session["ThemeName"] = radcmbTheme.SelectedValue; Response.Redirect("MyProfile.aspx"); }
private void SaveAndLoadUserSelectedPreferences() { int RoleId = 0; int CompanyId = 0; int DeptId = 0; string RoleName = string.Empty; string CompanyName = string.Empty; string DeptName = string.Empty; for (int i = 0; i < grdCompanyRole.Items.Count; i++) { if (grdCompanyRole.Items[i].FindControl("rbCompanyRole") != null) { if (((RadioButton)grdCompanyRole.Items[i].FindControl("rbCompanyRole")).Checked) { RoleId = Convert.ToInt32(grdCompanyRole.Items[i]["ROLE_ID"].Text.Trim()); RoleName = grdCompanyRole.Items[i]["ROLE_NAME"].Text.Trim(); CompanyId = Convert.ToInt32(grdCompanyRole.Items[i]["COMPANY_ID"].Text.Trim()); CompanyName = grdCompanyRole.Items[i]["COMPANY_NAME"].Text.Trim(); DeptId = Convert.ToInt32(grdCompanyRole.Items[i]["DEPARTMENT_ID"].Text.Trim()); DeptName = grdCompanyRole.Items[i]["DEPARTMENT_NAME"].Text.Trim(); //objAuthorizationBDto = (AuthorizationBDto)Session[PageConstants.ssnUserAuthorization]; if (objAuthorizationBDto != null) objAuthorizationBDto.SetUserSelectedPreferences(CompanyId, CompanyName, RoleId, RoleName, DeptId, DeptName); objAuthorizationDal = new AuthorizationDal(); int Result = objAuthorizationDal.UpdateUserDefaultPreference(objAuthorizationBDto.UserProfile.UserId, CompanyId, RoleId,DeptId); } } } }