ANNEXES
MessageBox.Show("Echec de chargement !!! " + ex.Message);
a
LES CODES DU PROGRAMME PRINCIPAL
using System;
using System.Collections.Generic; using System.Linq; using
System.Text; using System.Threading.Tasks; using System.Data; using
System.Data.SqlClient; using System.Windows.Forms;
namespace suivie_projet {
class ConnexionBD {
string chemin;
SqlConnection con; SqlCommand cmd = null; SqlDataReader dr =
null; SqlDataAdapter da = null; DataSet ds = null; DataTable tdt;
void connect()
{ try
{
chemin = @"Data Source=DESKTOP-FAUSTIN\SA;Initial
Catalog=suivie_projet;User ID=sa;Password=FLOC1999"; con = new
SqlConnection(chemin);
}
catch (Exception ex)
{
MessageBox.Show(" Echec de connexion !!!, " + ex.Message);
}
}
public void chargepanel(Panel p, Control c)
{
p.Controls.Clear();
p.Controls.Add(c);
p.Show();
}
public void chargementdatagrid(DataGridView dt, string sql)
{
try
{
connect();
con.Open();
da = new SqlDataAdapter(sql, con);
ds = new DataSet();
da.Fill(ds, "table");
dt.DataSource = ds.Tables[0];
}
catch (Exception ex)
{
b
}
finally
{
con.Close();
}
}
public void insertionOrga(string nom, string province, string
ville, string commune, string quartier, string avenue, string code)
{
try
{
connect();
con.Open();
cmd = new SqlCommand();
cmd.CommandText = "exec insertion @code,
@nom,@prov,@ville,@com,@quart,@ave"; cmd.Connection = con;
cmd.Parameters.AddWithValue("@code", int.Parse(code));
cmd.Parameters.AddWithValue("@nom", nom); cmd.Parameters.AddWithValue("@prov",
province); cmd.Parameters.AddWithValue("@ville", ville);
cmd.Parameters.AddWithValue("@com", commune);
cmd.Parameters.AddWithValue("@quart", quartier);
cmd.Parameters.AddWithValue("@ave", avenue);
cmd.ExecuteNonQuery();
MessageBox.Show("Reussi !!!");
}
catch (Exception ex) {
MessageBox.Show("Echec d'insertion " + ex.Message);
}
finally
{
con.Close();
}
}
public void insertionBen(string nom, string effectif, string
code)
{
try
{
connect();
con.Open();
cmd = new SqlCommand("exec insertionben @code, @nom,@effectif",
con);
cmd.Parameters.AddWithValue("@code", int.Parse(code));
cmd.Parameters.AddWithValue("@nom", nom);
cmd.Parameters.AddWithValue("@effectif", int.Parse(effectif));
cmd.ExecuteNonQuery();
MessageBox.Show("Reussi !!!");
}
catch (Exception ex) {
MessageBox.Show("Echec d'insertion " + ex.Message);
}
finally
{
con.Close();
}
}
public void insertionPro(string nom, string idorg, string idben,
string code,
string budget, string lieu, string bf)
C
{
try
{
connect();
con.Open();
cmd = new SqlCommand("exec insertionPro @code,
@nom,@idorg,@idben,@budget,@lieu,@bf", con);
cmd.Parameters.AddWithValue("@code",
int.Parse(code));
cmd.Parameters.AddWithValue("@nom", nom);
cmd.Parameters.AddWithValue("@idorg",
int.Parse(GetID("idorganisation", "organisation", "nomorgan",
idorg)));
cmd.Parameters.AddWithValue("@idben",
int.Parse(GetID("idben", "beneficiaires", "nomben", idben)));
cmd.Parameters.AddWithValue("@budget",
float.Parse(budget)); cmd.Parameters.AddWithValue("@lieu", lieu);
cmd.Parameters.AddWithValue("@bf",
int.Parse(GetID("idbf", "BFond", "nom", bf)));
cmd.ExecuteNonQuery();
MessageBox.Show("Reussi !!!");
}
catch (Exception ex) {
MessageBox.Show("Echec d'insertion " +
ex.Message);
}
finally
{
con.Close();
}
}
public void supprimerA(string table, string cond, int
a)
{
try {
connect();
con.Open();
cmd = new SqlCommand("delete from " + table + " where " +
cond + " ='"
+ a + "'", con);
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show("La suppression a échouée
!!! " + ex.Message);
}
finally
{
con.Close();
}
}
public void insertionBF(string id, string nom, string
av, string quart, string
com, string ville)
{
try
{
connect();
con.Open();
cmd=new SqlCommand("exec insertionBF
@id,@nom,@avenue,@quartie,@comm,@ville",
con);
cmd.Parameters.AddWithValue("@id",
int.Parse(id));
cmd.Parameters.AddWithValue("@nom", nom);
cmd.Parameters.AddWithValue("@avenue", av);
cmd.Parameters.AddWithValue("@quartie",
quart);
cmd.Parameters.AddWithValue("@comm", com);
d
cmd.Parameters.AddWithValue("@ville", ville);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Reussi");
}catch(Exception ex)
{
MessageBox.Show("Echec " + ex.Message);
}
finally
{
con.Close();
}
}
public void insertionUtili(string id, string pr, string mont,
string motif)
{
try
{
connect();
con.Open();
cmd = new SqlCommand("exec utilisation_projet @n1,@n2,@n3,@n4",
con);
cmd.Parameters.AddWithValue("@n1", int.Parse(id));
cmd.Parameters.AddWithValue("@n2",
int.Parse(GetID("idprojet","projet","nomprojet",pr)));
cmd.Parameters.AddWithValue("@n3", float.Parse(mont));
cmd.Parameters.AddWithValue("@n4", motif);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Reussi");
}
catch (Exception ex)
{
MessageBox.Show("Echec " + ex.Message);
}
finally
{
con.Close();
}
}
float reste;
public float check_reste(string id)
{
try
{
reste=float.Parse(GetID("reste", "projet", "nomprojet", id));
}catch(Exception ex)
{
MessageBox.Show("echec de charger le reste");
}
finally
{
con.Close();
}
return reste;
}
public void rechercher(string b, DataGridView dt, string table,
string champ)
{
try {
connect(); con.Open();
e
da = new SqlDataAdapter("select * from " + table + " where " +
champ +
" like '%" + b + "%'", con);
ds = new DataSet();
da.Fill(ds, "ok");
dt.DataSource = ds.Tables[0];
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
}
public void login(string nom, string pass)
{
try
{
connect();
con.Open();
cmd = new SqlCommand("Select nom,motdepass from users where
nom=@nom
and motdepass=@pass", con);
cmd.Parameters.AddWithValue("@nom", nom);
cmd.Parameters.AddWithValue("@motdepass", pass);
dr = cmd.ExecuteReader();
if (dr.Read())
{
if (dr["nom"].ToString() == nom &&
dr["motdepass"].ToString() ==
pass) {
accueil a = new accueil(); a.Show();
} else {
MessageBox.Show("Ce compte n'existe pas!!!"); login_user l = new
login_user();
l.Show();
}
}
}
catch (Exception ex)
{
MessageBox.Show("Echec de verification !!!" + ex.Message);
}
finally
{
con.Close();
}
}
public string GetID(String champ, String table, String
champcondition1, String
valeur1)
{
string _id = string.Empty;
connect(); con.Open();
if (!con.State.ToString().Trim().ToLower().Equals("open"))
con.Open();
try
}
f
{
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "SELECT DISTINCT " + champ + " FROM " + table +
"
WHERE " + champcondition1 + " = @valeur1";
cmd.Parameters.Add(new SqlParameter("@valeur1",
SqlDbType.NVarChar)).Value = valeur1;
SqlDataReader dr = null;
dr = cmd.ExecuteReader();
if (dr.HasRows)
while (dr.Read())
_id = dr.GetFieldValue<object>(0).ToString();
cmd.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
return _id.ToString();
}
public void chargementcb(ComboBox cb, string sql, string s)
try {
}
{
connect();
con.Open();
cmd = new SqlCommand(sql, con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
cb.Items.Add(dr[s].ToString());
}
catch (Exception ex) {
MessageBox.Show("Echec de chargement !!! " + ex.Message);
}
finally
{
con.Close();
}
}
public void users(string id, string nom, string pass)
{
try
{
connect();
con.Open();
cmd = new SqlCommand("exec userinsert @code,@nom,@pass", con);
cmd.Parameters.AddWithValue("@code", int.Parse(id));
cmd.Parameters.AddWithValue("@nom", nom);
cmd.Parameters.AddWithValue("@pass", pass);
cmd.ExecuteNonQuery();
MessageBox.Show("Reussi");
}
catch (Exception ex)
{
MessageBox.Show("Echec " + ex.Message);
g
finally
{
con.Close();
}
}
public DataTable rapport(string sql)
{
connect();
da = new SqlDataAdapter(sql, con);
tdt = new DataTable();
da.Fill(tdt);
con.Close();
return tdt;
}
}
}
|