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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
| using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace DataAccessLayer
{
class Personne
{
private String Prof;
public String Profils
{
get { return Prof; }
set { Prof = value; }
}
public static bool Insert(int cnip,
string nom,string prenom,string loginp,string passwrd,int telp, string emailp,int autop)
{
bool Resultat = false;
Properties.Settings1 properties = new DataAccessLayer.Properties.Settings1();
string chainedeconnexion = properties.CS;
SqlConnection connexion = new SqlConnection(chainedeconnexion);
try
{
connexion.Open();
string requete = "insert into personne(cni,nom_personne,prenom_personne,login,mdp,tel,email,autorisation) values ('" + cnip + "','" + nom + "','" + prenom + "','" + loginp + "','" + passwrd + "','" + telp + "','" + emailp + "','" + autop + "')";
SqlCommand commande = new SqlCommand(requete, connexion);
int nbre = commande.ExecuteNonQuery();
if (nbre > 0)
Resultat = true;
}
finally
{
connexion.Close();
connexion.Dispose();
}
return Resultat;
}
public static bool Delete(int id)
{
bool Resultat = false;
Properties.Settings1 properties = new DataAccessLayer.Properties.Settings1();
string chainedeconnexion = properties.CS;
SqlConnection connection = new SqlConnection(chainedeconnexion);
try
{
connection.Open();
string req = "delete personne where id_personne = " + id;
SqlCommand command = new SqlCommand(req, connection);
int nbre = command.ExecuteNonQuery();
if (nbre > 0)
Resultat = true;
}
finally
{
connection.Close();
connection.Dispose();
}
return Resultat;
}
public Boolean rechPerson(int id)
{
Boolean Prof = false;
DataSet resultat = new DataSet();
Properties.Settings1 properties = new DataAccessLayer.Properties.Settings1();
string chainedeconnexion = properties.CS;
SqlConnection connexion = new SqlConnection(chainedeconnexion);
try
{
connexion.Open();
String requete = "select * from personne where id_personne=" + id;
SqlCommand myCommand = new SqlCommand(requete, connexion);
SqlDataReader mySqDataReader = myCommand.ExecuteReader();
if (mySqDataReader.Read())
{
this.Prof = mySqDataReader["nom_personne"].ToString();
Prof = true;
}
mySqDataReader.Close();
}
catch (Exception)
{
throw;
}
finally
{
connexion.Close();
connexion.Dispose(); //si l'objet occupe une place dans la mémoire libérer le.
}
return Prof;
}
public static Boolean personne_existe(String log,String passwd)
{
bool valide = false;
Properties.Settings1 properties = new DataAccessLayer.Properties.Settings1();
string chainedeconnexion = properties.CS;
SqlConnection connexion = new SqlConnection(chainedeconnexion);
try
{
connexion.Open();
string requete = "select id_personne,nom_personne,prenom_personne from personne where login='" + log+ "' and mdp='"+passwd+"' ";
SqlCommand myCommand = new SqlCommand(requete, connexion);
SqlDataReader mySqDataReader = myCommand.ExecuteReader();
if (mySqDataReader.Read())
{
valide = true;
}
mySqDataReader.Close();
}
finally
{
connexion.Close();
connexion.Dispose();
}
return valide;
} |
Partager