1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
| namespace DataAccess
{
public string Connection = "Data Source=YOUR-15CC61E1F8;Initial Catalog=PFA;User ID=sa;Password=@radhiapfa ; Integrated Security=False";
public DataSet Select(string _Requete)
{
SqlConnection Conn = new SqlConnection(this.Connection);
DataSet DS = new DataSet();
SqlDataAdapter adap = new SqlDataAdapter();
Conn.Open();
adap.SelectCommand = new SqlCommand(_Requete, Conn);
adap.Fill(DS);
Conn.Close();
return DS;
}
}
l'autre code dont je fais l'appel à la methode ci dessus:
string Matricule =txtmatricule.Text;
bool trouve=false;
bool admin = false;
txtmatricule.Text = "";
string message = "identification échouée";
string Nom = "";
string Prenom = "";
DataAccess.DBRequests db = new DataAccess.DBRequests();
DataSet DS = db.Select("SELECT matricule,nom,prenom,responsabilite,matriculeResponsable FROM Employes");
int i = 0;
while( i < DS.Tables[0].Rows.Count-1 && !trouve)
{
if ((string)DS.Tables[0].Rows[i].ItemArray[0] == Matricule)
{
trouve = true;
Nom = (string)DS.Tables[0].Rows[i].ItemArray[1];
Prenom = (string)DS.Tables[0].Rows[i].ItemArray[2];
if (((bool)DS.Tables[0].Rows[i].ItemArray[3]) == true)
{ admin = true; }
}
i++;
}
if (trouve)
{
this.Page.Session["nom"] = Nom;
this.Page.Session["prenom"] = Prenom;
this.Page.Session["matricule"] = Matricule;
if (admin)
{ Response.Redirect("administrateur.aspx"); }
else
{ Response.Redirect("ListePointage.aspx"); }
}
else
{ ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script language=JavaScript>alert('" + (message) + "');</script>"); }
} |
Partager