protected void UserMailID_TextChanged(object sender, EventArgs e) { if (Page.IsPostBack == true && UserMailID.Text != String.Empty.ToString()) { SqlConnection tempcon = new SqlConnection(constr); tempcon.Open(); SqlCommand tempcmd = new SqlCommand("Select * From Employee where EmployeeMailID='" + UserMailID.Text + "' AND isactive = '1'", tempcon); SqlDataReader tempdr = tempcmd.ExecuteReader(); tempdr.Read(); if (tempdr.HasRows && tempdr["SecondaryPosition"].ToString() != "Approver" && tempdr["Position"].ToString() == "Employee") { Apprvckeck.Visible = false; UserPassword.Focus(); } else if (tempdr.HasRows && tempdr["SecondaryPosition"].ToString() == "Approver" && tempdr["Position"].ToString() == "Employee") { Apprvckeck.Visible = true; UserPassword.Focus(); } else if (tempdr.HasRows && tempdr["SecondaryPosition"].ToString() != "Approver" && tempdr["Position"].ToString() == "Admin") { Apprvckeck.Visible = false; UserPassword.Focus(); } else { Apprvckeck.Visible = false; Response.Write("<script>alert('Invalid Mail ID');</script>"); UserMailID.Focus(); } //UserPassword.Focus(); } else { UserMailID.Focus(); } }
protected void btnSubmit_Click(object sender, EventArgs e) { encryptpwdfun(UserPassword.Text); SqlConnection Logincon = new SqlConnection(constr); Logincon.Open(); //SqlCommand ses = new SqlCommand("Select SecondaryPosition From Employee where EmployeeMailID='" + UserMailID.Text + "' AND EmployeePassword='******' AND isactive = '1'", Logincon); //SqlDataReader dr = ses.ExecuteReader(); //string ss = dr["SecondaryPosition"].ToString(); //dr.Close(); SqlCommand Logincmd = new SqlCommand("Select * From Employee where EmployeeMailID='" + UserMailID.Text + "' AND EmployeePassword='******' AND isactive = '1'", Logincon); SqlDataReader Logindr = Logincmd.ExecuteReader(); Logindr.Read(); if (Logindr.HasRows && (Logindr["Position"].ToString() == "Employee" && Logindr["SecondaryPosition"].ToString() == "NA")) { // Session["EmployeeID"] = Logindr["EmployeeID"].ToString(); Session["SessionUserPosition"] = "Employee"; Session["SessionUserSecondryPosition"] = "NA"; Logindr.Close(); AMSsessions(); Response.Redirect("~/Operations/Dashboard.aspx"); } else if (Logindr.HasRows && (Logindr["Position"].ToString() == "Admin" && Logindr["SecondaryPosition"].ToString() == "NA")) { Session["SessionUserPosition"] = "Admin"; Session["SessionUserSecondryPosition"] = "NA"; Logindr.Close(); AMSsessions(); Response.Redirect("~/Admin/AdminDashboard.aspx"); } else if (Logindr.HasRows && (Logindr["Position"].ToString() == "Employee" && Logindr["SecondaryPosition"].ToString() == "Approver" && Apprvckeck.Checked == false)) { Session["SessionUserPosition"] = "Employee"; Session["SessionUserSecondryPosition"] = "Approver"; Session["SessionUserSecondryPositioncheck"] = "false"; Logindr.Close(); AMSsessions(); Response.Redirect("~/Operations/Dashboard.aspx"); } else if ((!Logindr.HasRows) || (Logindr["Position"].ToString() == "Employee" && Logindr["SecondaryPosition"].ToString() == "Approver" && Apprvckeck.Checked == true)) { Logindr.Close(); Logindr.Dispose(); try { //Checking for Valid Approver or not? SqlCommand checkcmd = new SqlCommand("select SecondaryPosition, isactive " + "from Employee where EmployeeMailID = '" + UserMailID.Text + "' AND isactive = '1' ", Logincon); SqlDataReader checkdr = checkcmd.ExecuteReader(); checkdr.Read(); string secondaryposition = checkdr["SecondaryPosition"].ToString(); checkdr.Close(); checkdr.Dispose(); //Aprover command SqlCommand Loginapprvcmd = new SqlCommand("select * from ERSApprover where ERSApproverMailID = '" + UserMailID.Text + "' AND ERSApproverPassword ='******' " + "AND isactive = '1'", Logincon); SqlDataReader Loginapprvdr = Loginapprvcmd.ExecuteReader(); Loginapprvdr.Read(); if (secondaryposition == "Approver" && Loginapprvdr.HasRows && Apprvckeck.Checked == true) { Session["SessionUserPosition"] = "Employee"; Session["SessionUserSecondryPosition"] = "Approver"; Session["SessionUserSecondryPositioncheck"] = "true"; Loginapprvdr.Close(); AMSsessions(); Response.Redirect("~/Operations/ApproverDashboard.aspx"); } else if (secondaryposition == "Approver" && Loginapprvdr.HasRows && Apprvckeck.Checked == false) { // ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Please Check the Approver Checkbox');", true); alertmod.Style.Add("background-color", "#ffc2b3"); alert.Style.Add("background-color", "#ffc2b3"); Label5.ForeColor = System.Drawing.ColorTranslator.FromHtml("red"); Label5.Text = "Please Check the Approver Checkbox"; alert.Visible = true; } else { Session["SessionUserSecondryPosition"] = "NA"; alertmod.Style.Add("background-color", "#ffc2b3"); alert.Style.Add("background-color", "#ffc2b3"); Label5.ForeColor = System.Drawing.ColorTranslator.FromHtml("red"); Label5.Text = "Incorrect User Name/Password"; alert.Visible = true; //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Incorrect User Name / Password!');", true); UserMailID.Text = string.Empty.ToString(); UserMailID.Focus(); } Loginapprvdr.Close(); // Loginapprvdr.Dispose(); } catch (Exception ex) { //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Incorrect User Name / Password!');", true); //UserMailID.Text = string.Empty.ToString(); //UserMailID.Focus(); throw ex; } } else { Logindr.Close(); alertmod.Style.Add("background-color", "#ffc2b3"); alert.Style.Add("background-color", "#ffc2b3"); Label5.ForeColor = System.Drawing.ColorTranslator.FromHtml("red"); Label5.Text = "Incorrect User Name/Password"; alert.Visible = true; // ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Incorrect User Name / Password!');", true); } Logincon.Close(); Logincon.Dispose(); }