protected void Button1_Click(object sender, EventArgs e) { if (acces.SelectedValue.ToString().Equals("bo")) { AgentBO agent = LoginService.loginAgentBO(user.Text.ToString(), mdp.Text.ToString()); if (agent != null) { result.Text = agent.getId() + " " + agent.getNom() + " " + agent.getPrenom(); Session["type"] = "BO"; Session["user"] = agent; Response.Redirect("index.aspx"); } else { result.Text = "Identifiants incorrectes"; } } else { AgentUA agent = LoginService.loginAgentUA(user.Text.ToString(), mdp.Text.ToString()); if (agent != null) { result.Text = agent.getId() + " " + agent.getNom() + " " + agent.getPrenom(); Session["type"] = "UA"; Session["user"] = agent; Response.Redirect("index.aspx"); } else { result.Text = "Identifiants incorrectes"; } } }
public static AgentUA loginAgentUA(string login, string password) { SqlConnection cnx = new SqlConnection(ConfigurationManager.AppSettings["cnx"].ToString()); cnx.Open(); SqlCommand cmd = new SqlCommand(String.Format("select id_agent,nom,prenom,tel,adresse,sexe,id_unit from agent_ua where login='******' and password='******'", login, password), cnx); SqlDataReader dr = cmd.ExecuteReader(); if (dr != null && dr.HasRows) { dr.Read(); AgentUA agent = new AgentUA(dr.GetInt32(0), dr.GetString(1), dr.GetString(2), dr.GetString(3), dr.GetString(4), dr.GetString(5).First(), null); return(agent); } return(null); }