Vous êtes sur la page 1sur 31

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

Structure de la base de donnes : sous SQL express Client (Id_Cli ,Nom_Cli ,Prenom_Cli ,Adresse_Cli) Commande (Id_Comm ,Id_Cli, Date_Comm) Article (Rf_Art, Dsig, qt_Stock, Prix_unit) Ligne_Commande (Id_Comm ,Rf_Art, Qt_Comm) Mode connect : sans procdures stockes

namespace Mode_Connecter { public partial class demarage : Form { public static SqlConnection cn = new SqlConnection("Data Source=.;Initial Catalog=Gestion_Commandes;Integrated Security=True"); public static SqlCommand cmd = cn.CreateCommand(); public static BindingSource bs=new BindingSource(); public static BindingSource bs1 = new BindingSource(); public static SqlDataReader odr; public demarage() { InitializeComponent(); } private void demarage_Load(object sender, EventArgs e) { } private void sansProcduresStockesToolStripMenuItem_Click(object sender, EventArgs e) { Gestion_Clients gc = new Gestion_Clients(); gc.ShowDialog(); } private void avecPrcduresStockesToolStripMenuItem_Click(object sender, EventArgs e) { Gestion_Clients_avec_PS gc_aps = new Gestion_Clients_avec_PS(); gc_aps.ShowDialog (); } private void sansProcduresStockesToolStripMenuItem1_Click(object sender, EventArgs e)

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

{ Gestion_Commandes g_com = new Gestion_Commandes(); g_com.ShowDialog(); } private void sansProcduresStockesToolStripMenuItem2_Click(object sender, EventArgs e) { Gestion_Articles ga = new Gestion_Articles(); ga.ShowDialog(); } private void avecProcduresStockesToolStripMenuItem1_Click(object sender, EventArgs e) { Gestion_Article_avec_PS gap = new Gestion_Article_avec_PS(); gap.ShowDialog(); } private void avecProcduresStockesToolStripMenuItem_Click(object sender, EventArgs e) { Gestion_Commandes_avec_PS gcp = new Gestion_Commandes_avec_PS(); gcp.ShowDialog(); } }

public partial class Gestion_Clients : Form { public Gestion_Clients() { InitializeComponent(); } private void Ajouter_Click(object sender, EventArgs e) { try { demarage.cmd.CommandText = "insert into Client values(@num,@nom,@prenom,@adresse)"; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.AddWithValue("@num", int.Parse(num.Text)); demarage.cmd.Parameters.AddWithValue("@nom", Nom.Text); demarage.cmd.Parameters.AddWithValue("@prenom", prenom.Text); demarage.cmd.Parameters.AddWithValue("@adresse", adresse.Text);

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

demarage.cn.Open(); demarage.cmd.ExecuteNonQuery(); demarage.cn.Close(); MessageBox.Show("Bien Ajouter"); vider_client(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); } charger();

private void Gestion_Clients_Load(object sender, EventArgs e) { demarage.cmd.CommandType = CommandType.Text; charger(); } public void vider_client() { num.Clear(); Nom.Clear(); prenom.Clear(); adresse.Clear(); } public void charger() { demarage.cmd.CommandText = "select * from Client"; demarage.cn.Open(); demarage.odr = demarage.cmd.ExecuteReader(); demarage.bs.DataSource = demarage.odr; dgv.DataSource = demarage.bs; demarage.cn.Close(); } private void Afficher_Click(object sender, EventArgs e) { charger(); } private void fermer_Click(object sender, EventArgs e) { Close(); } private void Modifier_Click(object sender, EventArgs e) { try { demarage.cmd.CommandText = "update Client set Nom_cli=@nom,Prenom_cli=@prenom,Adresse_cli=@adrs where id_cli=@num"; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.AddWithValue("@num", int.Parse (num.Text)); demarage.cmd.Parameters.AddWithValue("@nom", Nom.Text); demarage.cmd.Parameters.AddWithValue("@prenom", prenom.Text); demarage.cmd.Parameters.AddWithValue("@adrs", adresse.Text); demarage.cn.Open(); demarage.cmd.ExecuteNonQuery(); demarage.cn.Close(); MessageBox.Show("Bien modifier"); vider_client();

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

} private void Supprimer_Click(object sender, EventArgs e) { try {

} catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); } charger();

demarage.cmd.CommandText = "delete from Client where id_cli=@num"; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.AddWithValue("@num", int.Parse(num.Text)); demarage.cn.Open(); demarage.cmd.ExecuteNonQuery(); demarage.cn.Close(); MessageBox.Show("Bien Supprimer"); vider_client(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); } charger(); } private void dgv_CellClick(object sender, DataGridViewCellEventArgs e) { //DataRow dr; //dr = dgv.Se; //num.Text = dr[0].ToString() ; //Nom.Text = dr[1].ToString(); //prenom.Text = dr[2].ToString(); //adresse.Text = dr[3].ToString(); } private void Rechercher_Click(object sender, EventArgs e) { try { demarage.cmd.CommandText = "select * from Client where id_cli=@num"; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.AddWithValue("@num", int.Parse(num.Text)); demarage.cn.Open(); demarage.odr = demarage.cmd.ExecuteReader(); if (demarage.odr.Read() != false ) { num.Text = demarage.odr[0].ToString(); Nom.Text = demarage.odr[1].ToString(); prenom.Text = demarage.odr[2].ToString(); adresse.Text = demarage.odr[3].ToString(); demarage.cn.Close(); } } catch (Exception ) { MessageBox.Show("n exsiste pas"); } finally { demarage.cn.Close(); } } private void login_Click(object sender, EventArgs e) { try {

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

demarage.cn.Open(); MessageBox.Show("L'etat de connexion est : " + demarage.cn.State); } catch { MessageBox.Show("Probleme de connexion " + demarage.cn.State); } } private void logout_Click(object sender, EventArgs e) { try { demarage.cn.Close(); MessageBox.Show("L'etat de connexion est: " + demarage.cn.State); } catch { MessageBox.Show("probleme de connexion " + demarage.cn.State); } } private void Premier_Click(object sender, EventArgs e) { demarage.bs.MoveFirst(); } private void Prcedent_Click(object sender, EventArgs e) { demarage.bs.MovePrevious(); } private void Suivant_Click(object sender, EventArgs e) { demarage.bs.MoveNext(); } private void Drnier_Click(object sender, EventArgs e) { demarage.bs.MoveLast(); } private void dgv_SelectionChanged(object sender, EventArgs e) { num.Text = dgv.CurrentRow.Cells[0].Value.ToString(); Nom.Text = dgv.CurrentRow.Cells[1].Value.ToString(); prenom .Text = dgv.CurrentRow.Cells[2].Value.ToString(); adresse.Text = dgv.CurrentRow.Cells[3].Value.ToString(); }

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

public partial class Gestion_Articles : Form { public Gestion_Articles() { InitializeComponent(); } private void Gestion_Articles_Load(object sender, EventArgs e) { demarage.cmd.CommandType = CommandType.Text; charger(); } public void vider_Article() { ref_art.Clear(); dsg.Clear(); Qt_stok.Clear(); Prix_u.Clear(); } public void charger() { try { demarage.cn.Open(); demarage.cmd.CommandText = "select * from Article"; demarage.odr = demarage.cmd.ExecuteReader(); demarage.bs.DataSource = demarage.odr; dgv.DataSource = demarage.bs; demarage.cn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); }

} private void Premier_Click(object sender, EventArgs e) { demarage.bs.MoveFirst(); } private void Drnier_Click(object sender, EventArgs e) {

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

demarage.bs.MoveLast(); } private void Suivant_Click(object sender, EventArgs e) { demarage.bs.MoveNext(); } private void Prcedent_Click(object sender, EventArgs e) { demarage.bs.MovePrevious(); } private void fermer_Click(object sender, EventArgs e) { Close();} private void Prix_u_MouseLeave(object sender, EventArgs e) { Prix_u. Text = ""; } private void Ajouter_Click(object sender, EventArgs e) { try { demarage.cmd.CommandText = "insert into Article values(@ref,@des,@qt,@prix)"; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.AddWithValue("@ref", int.Parse(ref_art .Text)); demarage.cmd.Parameters.AddWithValue("@des", dsg .Text); demarage.cmd.Parameters.AddWithValue("@qt", Qt_stok.Text); demarage.cmd.Parameters.AddWithValue("@prix", Prix_u.Text); demarage.cn.Open(); demarage.cmd.ExecuteNonQuery(); demarage.cn.Close(); charger(); MessageBox.Show("Bien Ajouter"); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); } } private void Supprimer_Click(object sender, EventArgs e) { try { demarage.cmd.CommandText = "delete from Article where Rf_Art=@ref"; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.AddWithValue("@ref", int.Parse(ref_art .Text)); demarage.cn.Open(); demarage.cmd.ExecuteNonQuery(); demarage.cn.Close(); charger(); MessageBox.Show("Bien Supprimer"); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); }

private void Rechercher_Click(object sender, EventArgs e)

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

{ Console.Beep(); try { demarage.cmd.CommandText = "select * from Article where Rf_Art=@ref"; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.AddWithValue("@ref", int.Parse(ref_art .Text)); demarage.cn.Open(); demarage.odr = demarage.cmd.ExecuteReader(); if (demarage.odr.Read() != false) { ref_art .Text = demarage.odr[0].ToString(); dsg.Text = demarage.odr[1].ToString(); Qt_stok .Text = demarage.odr[2].ToString(); Prix_u.Text = demarage.odr[3].ToString(); demarage.cn.Close(); } } catch (Exception) { MessageBox.Show("n exsiste pas"); } finally { demarage.cn.Close(); } } private void Modifier_Click(object sender, EventArgs e) { Console.Beep(); try { demarage.cmd.CommandText = "update Article set Dsig=@ds,qt_Stock=@qt,Prix_unit=@prix where Rf_art=@ref"; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.AddWithValue("@ref", int.Parse(ref_art .Text)); demarage.cmd.Parameters.AddWithValue("@ds", dsg.Text); demarage.cmd.Parameters.AddWithValue("@qt", int.Parse (Qt_stok.Text)); demarage.cmd.Parameters.AddWithValue("@prix", int.Parse(Prix_u.Text)); demarage.cn.Open(); demarage.cmd.ExecuteNonQuery(); demarage.cn.Close(); charger(); MessageBox.Show("Bien modifier"); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); }

private void dgv_SelectionChanged(object sender, EventArgs e) { ref_art .Text = dgv.CurrentRow.Cells[0].Value.ToString(); dsg.Text = dgv.CurrentRow.Cells[1].Value.ToString(); Qt_stok.Text = dgv.CurrentRow.Cells[2].Value.ToString(); Prix_u .Text = dgv.CurrentRow.Cells[3].Value.ToString(); }

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

public partial class Gestion_Commandes : Form { public Gestion_Commandes() { InitializeComponent(); } private void fermer_Click(object sender, EventArgs e) { Close(); } private void Gestion_Commandes_Load(object sender, EventArgs e) { demarage.cmd.CommandType = CommandType.Text; groupBox1.Enabled = false; groupBox2.Enabled = false; Nom.DisplayMember = "Nom_Cli"; Nom.ValueMember = "Id_Cli"; demarage.cmd.CommandText = "select * from Client"; try { demarage.cn.Open(); demarage.odr = demarage.cmd.ExecuteReader(); demarage.bs.DataSource = demarage.odr; Nom.DataSource = demarage.bs; } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); } } private void Nom_SelectedIndexChanged(object sender, EventArgs e) { try { demarage.cmd.CommandText = "SELECT * FROM Client WHERE(Id_Cli =@num)"; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.AddWithValue("@num", Nom.SelectedValue);

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

} catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); } } private void Ajouter_Click(object sender, EventArgs e) { groupBox1.Enabled = true; } private void Enregistrer_Click(object sender, EventArgs e) { try { demarage.cmd.CommandText = "insert into Commande values (@id_c,@id_cli,@dat)"; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.Add("@id_c", int.Parse(Num_comm.Text)); demarage.cmd.Parameters.Add("@id_cli", Nom.SelectedValue); demarage.cmd.Parameters.Add("@dat", DTP.Value); demarage.cn.Open(); demarage.cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); } groupBox2.Enabled = true; Produit .ValueMember = "Rf_Art"; Produit.DisplayMember = "Dsig"; demarage.cmd.CommandText = "select * from Article"; try { demarage.cn.Open(); demarage.odr = demarage.cmd.ExecuteReader(); demarage.bs1.DataSource = demarage.odr; Produit.DataSource = demarage.bs1; } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); }

if (demarage.cn.State == ConnectionState.Closed) { demarage.cn.Open(); demarage.odr = demarage.cmd.ExecuteReader(); if ( demarage.odr.Read()) { Prenom.Text = demarage.odr[2].ToString(); Adresse.Text = demarage.odr[3].ToString(); } }

} private void Produit_SelectedIndexChanged(object sender, EventArgs e) { try { demarage.cmd.CommandText = "SELECT * FROM Article WHERE(Rf_Art =@ref)"; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.AddWithValue("@ref", Produit.SelectedValue); if (demarage.cn.State == ConnectionState.Closed) {

10

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

demarage.cn.Open(); demarage.odr = demarage.cmd.ExecuteReader(); if (demarage.odr.Read()) { dsig.Text = demarage.odr[1].ToString(); qt_stock .Text = demarage.odr[2].ToString(); prix_u .Text = demarage.odr[3].ToString(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); } } private void Ajouter_art_comm_Click(object sender, EventArgs e) { try { demarage.cmd.CommandText="select qt_Stock from Article where Rf_Art = @qt" ; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.AddWithValue("@qt", Produit.SelectedValue); demarage.cn.Open(); demarage.odr=demarage.cmd.ExecuteReader(); demarage.odr.Read(); if (int.Parse(qt_comm.Text) <= int.Parse(demarage.odr[0].ToString())) { demarage.cmd.CommandText = "insert into Ligne_Commande values (@id,@ref,@qt);update Article set qt_Stock =qt_Stock-@qt where Rf_art=@ref"; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.AddWithValue("@id", int.Parse(Num_comm.Text)); demarage.cmd.Parameters.AddWithValue("@ref", Produit.SelectedValue); demarage.cmd.Parameters.AddWithValue("@qt", int.Parse(qt_comm.Text)); demarage.odr.Close(); demarage.cmd.ExecuteNonQuery(); MessageBox.Show("Bien Ajouter"); } else { MessageBox.Show("Qt > au stock existant"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); demarage.odr.Close(); } }

Mode connect : Avec les procdures stockes

11

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

public partial class Gestion_Clients_avec_PS : Form { public Gestion_Clients_avec_PS() { InitializeComponent(); } private void Ajouter_Click(object sender, EventArgs e) { try { demarage.cmd.CommandType = CommandType.StoredProcedure; demarage.cmd.CommandText = "Ajout"; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.AddWithValue("@num", int.Parse(num.Text)); demarage.cmd.Parameters.AddWithValue("@nom", Nom.Text); demarage.cmd.Parameters.AddWithValue("@prenom", prenom.Text); demarage.cmd.Parameters.AddWithValue("@adres", adresse.Text); demarage.cn.Open(); demarage.cmd.ExecuteNonQuery(); charger(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); } } private void Modifier_Click(object sender, EventArgs e) { try { demarage.cmd.CommandType = CommandType.StoredProcedure; demarage.cmd.CommandText = "modif"; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.AddWithValue("@num", int.Parse(num.Text)); demarage.cmd.Parameters.AddWithValue("@nom", Nom.Text);

12

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

demarage.cmd.Parameters.AddWithValue("@prenom", prenom.Text); demarage.cmd.Parameters.AddWithValue("@adres", adresse.Text); demarage.cn.Open(); demarage.cmd.ExecuteNonQuery(); charger(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); } } private void Gestion_Clients_avec_PS_Load(object sender, EventArgs e) { charger(); } public void vider_client() { num.Clear(); Nom.Clear(); prenom.Clear(); adresse.Clear(); } private void Rechercher_Click(object sender, EventArgs e) { try { demarage.cmd.CommandType = CommandType.StoredProcedure; demarage.cmd.CommandText = "recherch_sp"; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.AddWithValue("@num", int.Parse(num.Text)); demarage.cn.Open(); demarage.odr=demarage.cmd.ExecuteReader (); demarage.odr.Read(); num.Text = demarage.odr[0].ToString(); Nom.Text = demarage.odr[1].ToString(); prenom.Text = demarage.odr[2].ToString(); adresse.Text = demarage.odr[3].ToString(); charger(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); } charger(); } public void charger() { try { if (demarage.cn.State == ConnectionState.Open) { demarage.cn.Close(); } demarage.cmd.CommandType = CommandType.Text; demarage.cmd.CommandText = "select * from Client"; demarage.cn.Open(); demarage.odr = demarage.cmd.ExecuteReader(); demarage.bs.DataSource = demarage.odr; dgv.DataSource = demarage.bs;

13

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

} private void Supprimer_Click(object sender, EventArgs e) { try { demarage.cmd.CommandType = CommandType.StoredProcedure; demarage.cmd.CommandText = "supprimer"; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.AddWithValue("@num", int.Parse(num.Text)); demarage.cn.Open(); demarage.cmd.ExecuteNonQuery(); charger(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); } } private void fermer_Click(object sender, EventArgs e) { Close(); } private void button1_Click(object sender, EventArgs e) { charger(); } private void dgv_CellClick(object sender, DataGridViewCellEventArgs e) { num.Text = dgv.CurrentRow.Cells[0].Value.ToString(); Nom.Text = dgv.CurrentRow.Cells[1].Value.ToString(); prenom.Text = dgv.CurrentRow.Cells[2].Value.ToString(); adresse.Text = dgv.CurrentRow.Cells[3].Value.ToString(); } private void Premier_Click(object sender, EventArgs e) { demarage.bs.MoveFirst(); } private void Prcedent_Click(object sender, EventArgs e) { demarage.bs.MovePrevious (); } private void Suivant_Click(object sender, EventArgs e) { demarage.bs.MoveNext (); } private void Drnier_Click(object sender, EventArgs e) { demarage.bs.MoveLast(); } private void dgv_SelectionChanged(object sender, EventArgs e) { num.Text = dgv.CurrentRow.Cells[0].Value.ToString(); Nom.Text = dgv.CurrentRow.Cells[1].Value.ToString(); prenom.Text = dgv.CurrentRow.Cells[2].Value.ToString(); adresse.Text = dgv.CurrentRow.Cells[3].Value.ToString(); }

} catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); }

14

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

public partial class Gestion_Article_avec_PS : Form { public Gestion_Article_avec_PS() { InitializeComponent(); } private void Ajouter_Click(object sender, EventArgs e) { try { demarage.cmd.CommandType = CommandType.StoredProcedure; demarage.cmd.CommandText = "ajout_art"; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.AddWithValue("@ref", int.Parse(ref_art.Text)); demarage.cmd.Parameters.AddWithValue("@des", dsg.Text); demarage.cmd.Parameters.AddWithValue("@qt", int.Parse(Qt_stok.Text)); demarage.cmd.Parameters.AddWithValue("@prix", Prix_u.Text); demarage.cn.Open(); demarage.cmd.ExecuteNonQuery(); charger(); MessageBox.Show("Bien Ajouter"); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); } } private void Gestion_Article_avec_PS_Load(object sender, EventArgs e) { charger(); } public void vider_Article() { ref_art.Clear(); dsg.Clear(); Qt_stok.Clear(); Prix_u.Clear(); } public void charger()

15

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

{ try { if (demarage.cn.State == ConnectionState.Open) { demarage.cn.Close(); } demarage.cn.Open(); demarage.cmd.CommandType = CommandType.Text; demarage.cmd.CommandText = "select * from Article"; demarage.odr = demarage.cmd.ExecuteReader(); demarage.bs.DataSource = demarage.odr; dgv.DataSource = demarage.bs; demarage.cn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); }

private void fermer_Click(object sender, EventArgs e) { Close(); } private void Modifier_Click(object sender, EventArgs e) { try { demarage.cmd.CommandType = CommandType.StoredProcedure; demarage.cmd.CommandText = "modif_art"; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.AddWithValue("@ref", int.Parse(ref_art.Text )); demarage.cmd.Parameters.AddWithValue("@des", dsg.Text); demarage.cmd.Parameters.AddWithValue("@qt", Qt_stok.Text); demarage.cmd.Parameters.AddWithValue("@prix", Prix_u.Text); demarage.cn.Open(); demarage.cmd.ExecuteNonQuery(); charger(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); } } private void dgv_CellClick(object sender, DataGridViewCellEventArgs e) { ref_art .Text = dgv.CurrentRow.Cells[0].Value.ToString(); dsg .Text = dgv.CurrentRow.Cells[1].Value.ToString(); Qt_stok.Text = dgv.CurrentRow.Cells[2].Value.ToString(); Prix_u .Text = dgv.CurrentRow.Cells[3].Value.ToString(); } private void Supprimer_Click(object sender, EventArgs e) { try { demarage.cmd.CommandType = CommandType.StoredProcedure; demarage.cmd.CommandText = "supprimer_art"; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.AddWithValue("@ref", int.Parse(ref_art.Text));

16

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

demarage.cn.Open(); demarage.cmd.ExecuteNonQuery(); charger(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); }

private void Rechercher_Click(object sender, EventArgs e) { try { demarage.cmd.CommandType = CommandType.StoredProcedure; demarage.cmd.CommandText = "recherch_art"; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.AddWithValue("@ref", int.Parse(ref_art .Text)); demarage.cn.Open(); demarage.odr = demarage.cmd.ExecuteReader(); demarage.odr.Read(); ref_art .Text = demarage.odr[0].ToString(); dsg.Text = demarage.odr[1].ToString(); Qt_stok .Text = demarage.odr[2].ToString(); Prix_u.Text = demarage.odr[3].ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); } } private void Premier_Click(object sender, EventArgs e) { demarage.bs.MoveFirst();} private void Prcedent_Click(object sender, EventArgs e) {demarage.bs.MovePrevious();} private void Suivant_Click(object sender, EventArgs e) {demarage.bs.MoveNext(); } private void Drnier_Click(object sender, EventArgs e) {demarage.bs.MoveLast(); } private void dgv_SelectionChanged(object sender, EventArgs e) { ref_art .Text = dgv.CurrentRow.Cells[0].Value.ToString(); dsg.Text = dgv.CurrentRow.Cells[1].Value.ToString(); Qt_stok.Text = dgv.CurrentRow.Cells[2].Value.ToString(); Prix_u .Text = dgv.CurrentRow.Cells[3].Value.ToString(); }

17

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

public partial class Gestion_Commandes_avec_PS : Form { public Gestion_Commandes_avec_PS() { InitializeComponent(); } private void Gestion_Commandes_avec_PS_Load(object sender, EventArgs e) { groupBox1.Enabled groupBox2.Enabled Nom.DisplayMember Nom.ValueMember = = false; = false; = "Nom_Cli"; "Id_Cli";

demarage.cmd.CommandText = "select * from Client"; try { demarage.cn.Open(); demarage.odr = demarage.cmd.ExecuteReader(); demarage.bs.DataSource = demarage.odr; Nom.DataSource = demarage.bs; } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); } } private void Nom_SelectedIndexChanged(object sender, EventArgs e) { try { demarage.cmd.CommandText = "SELECT * FROM Client WHERE(Id_Cli =@num)"; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.AddWithValue("@num", Nom.SelectedValue); if (demarage.cn.State == ConnectionState.Closed) { demarage.cn.Open(); demarage.odr = demarage.cmd.ExecuteReader();

18

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

if (demarage.odr.Read()) { Prenom.Text = demarage.odr[2].ToString(); Adresse.Text = demarage.odr[3].ToString(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); }

private void fermer_Click(object sender, EventArgs e) { Close(); } private void Ajouter_Click(object sender, EventArgs e) { groupBox1.Enabled = true; } private void Enregistrer_Click(object sender, EventArgs e) { try { demarage.cmd.CommandType = CommandType.StoredProcedure; demarage.cmd.CommandText = "ajout_comm"; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.AddWithValue("@id_c", int.Parse(Num_comm.Text)); demarage.cmd.Parameters.AddWithValue("@id_cli", Nom.SelectedValue); demarage.cmd.Parameters.AddWithValue("@dat", DTP.Value); demarage.cn.Open(); demarage.cmd.ExecuteNonQuery(); MessageBox.Show("Bien Ajouter"); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); } groupBox2.Enabled = true; Produit.ValueMember = "Rf_Art"; Produit.DisplayMember = "Dsig"; demarage.cmd.CommandType = CommandType.Text ; demarage.cmd.CommandText = "select * from Article"; try {

} catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); } } private void Produit_SelectedIndexChanged(object sender, EventArgs e) {

demarage.cn.Open(); demarage.odr = demarage.cmd.ExecuteReader(); demarage.bs1.DataSource = demarage.odr; Produit.DataSource = demarage.bs1;

19

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

try { demarage.cmd.CommandType = CommandType.Text; demarage.cmd.CommandText = "SELECT * FROM Article WHERE(Rf_Art =@ref)"; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.AddWithValue("@ref", Produit.SelectedValue); if (demarage.cn.State == ConnectionState.Closed) { demarage.cn.Open(); demarage.odr = demarage.cmd.ExecuteReader(); if (demarage.odr.Read()) { dsig.Text = demarage.odr[1].ToString(); qt_stock.Text = demarage.odr[2].ToString(); prix_u.Text = demarage.odr[3].ToString(); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); } } private void Ajouter_art_comm_Click(object sender, EventArgs e) { try{ demarage.cmd.CommandText="select qt_Stock from Article where Rf_Art = @qt" ; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.AddWithValue("@qt", Produit.SelectedValue); demarage.cn.Open(); demarage.odr=demarage.cmd.ExecuteReader(); demarage.odr.Read(); if (int.Parse(qt_comm.Text) <= int.Parse(demarage.odr[0].ToString())) { demarage.cmd.CommandType = CommandType.StoredProcedure; demarage.cmd.CommandText = "ajout_art_comm"; demarage.cmd.Parameters.Clear(); demarage.cmd.Parameters.AddWithValue("@id", int.Parse(Num_comm.Text)); demarage.cmd.Parameters.AddWithValue("@ref", Produit.SelectedValue); demarage.cmd.Parameters.AddWithValue("@qt", qt_comm.Text); demarage.odr.Close(); demarage.cmd.ExecuteNonQuery(); MessageBox.Show("Bien Ajouter"); } else { MessageBox.Show("Qt > au stock existant"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { demarage.cn.Close(); demarage.odr.Close(); } } }

Mode dconnect :

20

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

public partial class Demarage : Form { public static DataTable dt = new DataTable(); public static DataTable dt1 = new DataTable(); public static DataTable dt2 = new DataTable(); public static DataTable dt3 = new DataTable(); public static DataRow dr; public static SqlConnection cn = new SqlConnection("Data Source=.;Initial Catalog=Gestion_Commandes;Integrated Security=True"); public static SqlDataAdapter da = new SqlDataAdapter(); public static DataSet ds = new DataSet(); public static SqlCommandBuilder build = new SqlCommandBuilder(da); public static DataRow rowco; public Demarage() { InitializeComponent(); } private void listeClientsToolStripMenuItem_Click(object sender, EventArgs e) { Client_View cl = new Client_View(); cl.Show(); } private void clientToolStripMenuItem_Click(object sender, EventArgs e) { Form1 cli = new Form1(); cli.Show(); } private void Demarage_Load(object sender, EventArgs e) { da.SelectCommand = cn.CreateCommand(); da.SelectCommand.CommandText = "select * from Client"; da.Fill(ds, "Client"); dt = ds.Tables["Client"]; dt.PrimaryKey = new DataColumn[] { dt.Columns[0] }; da.SelectCommand = cn.CreateCommand(); da.SelectCommand.CommandText = "select * from Commande"; da.Fill(ds, "Commande"); dt1 = ds.Tables["Commande"]; dt1.PrimaryKey = new DataColumn[] { dt1.Columns[0] };

21

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

da.SelectCommand = cn.CreateCommand(); da.SelectCommand.CommandText = "select * from Article"; da.Fill(ds, "Article"); dt2 = ds.Tables["Article"]; dt2.PrimaryKey = new DataColumn[] { dt2.Columns[0] }; da.SelectCommand = cn.CreateCommand(); da.SelectCommand.CommandText = "select * from Ligne_Commande"; da.Fill(ds, "LigCom"); dt3 = ds.Tables["LigCom"]; ForeignKeyConstraint fkcomm = new ForeignKeyConstraint(dt.Columns["Id_Cli"], dt1.Columns["Id_Cli"]); fkcomm.DeleteRule = Rule.Cascade; fkcomm.UpdateRule = Rule.Cascade; dt1.Constraints.Add(fkcomm); ForeignKeyConstraint fklignco = new ForeignKeyConstraint(dt1.Columns["Id_Comm"], dt3.Columns["Id_Comm"]); fklignco.DeleteRule = Rule.Cascade; fklignco.UpdateRule = Rule.Cascade; dt3.Constraints.Add(fklignco); ForeignKeyConstraint fkrefart = new ForeignKeyConstraint(dt2.Columns["Rf_Art"], dt3.Columns["Rf_Art"]); fkrefart.DeleteRule = Rule.Cascade; fkrefart.UpdateRule = Rule.Cascade; dt3.Constraints.Add(fkrefart); ds.Relations.Add("clicom", dt.Columns["Id_Cli"], dt1.Columns["Id_Cli"]); ds.Relations.Add("comlig", dt1.Columns["Id_Comm"], dt3.Columns["Id_Comm"]); ds.Relations.Add("lignart", dt2.Columns["Rf_Art"], dt3.Columns["Rf_Art"]); ds.EnforceConstraints = true; // Teste: DGV.DataSource = dt; DGV1.DataSource = dt1; DGV2.DataSource = dt2; DGV3.DataSource = dt3;

private void artcileToolStripMenuItem_Click(object sender, EventArgs e) { Article ar = new Article(); ar.Show(); } private void quitterToolStripMenuItem_Click(object sender, EventArgs e) { this.Close(); } private void commandeToolStripMenuItem_Click(object sender, EventArgs e) { Commande c = new Commande(); c.Show(); } private void listeDesCommandesToolStripMenuItem_Click(object sender, EventArgs e) { Commande_View cv = new Commande_View();

22

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

cv.Show(); } private void listeDesArticlesToolStripMenuItem_Click(object sender, EventArgs e) { Article_View ar = new Article_View(); ar.Show(); } private void factureToolStripMenuItem_Click(object sender, EventArgs e) { Facture_View f = new Facture_View(); f.Show(); }

public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { try { DGV.DataSource = Demarage.dt; DGV1.DataSource = Demarage.dt1; } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { Demarage.cn.Close(); }

23

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

private void ajouter_Click(object sender, EventArgs e) { try{ Demarage.dr = Demarage.dt.NewRow(); Demarage.dr[0] = cin.Text; Demarage.dr[1] = nom.Text; Demarage.dr[2] = prenom.Text; Demarage.dr[3] = adresse.Text; Demarage.dt.Rows.Add(Demarage.dr); //Demarage.da.Update(Demarage.ds, "Client"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } public void vider() { cin.Clear(); nom .Clear(); prenom .Clear(); adresse.Clear(); cin.Focus(); } private void supprimer_Click(object sender, EventArgs e) { try{ Demarage.dr = Demarage.dt.Rows.Find(int.Parse(cin.Text)); Demarage.dr.Delete(); vider(); //Demarage.da.Update(ds, "Client"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void Rchercher_Click(object sender, EventArgs e) { try { Demarage.dr = Demarage.dt.Rows.Find(int.Parse(cin.Text)); cin.Text = Demarage.dr[0].ToString(); nom.Text = Demarage.dr[1].ToString(); prenom.Text = Demarage.dr[2].ToString(); adresse.Text = Demarage.dr[3].ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void Modifier_Click(object sender, EventArgs e) { try{ Demarage.dr = Demarage.dt.Rows.Find(int.Parse(cin.Text)); Demarage.dr[1] = nom.Text; Demarage.dr[2] = prenom.Text; Demarage.dr[3] = adresse.Text; //Demarage.da.Update(ds, "Client"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }

24

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

private void fermer_Click(object sender, EventArgs e) { Close(); } private void Valider_Click(object sender, EventArgs e) { //Demarage.da.Update(ds, "Client"); try { Demarage.da.InsertCommand = Demarage.cn.CreateCommand(); Demarage.da.InsertCommand.CommandText = "insert into Client values (@id,@nom,@pren,@adres)"; Demarage.da.InsertCommand.Parameters.Add("@id", SqlDbType.Int, 15, "Id_Cli"); Demarage.da.InsertCommand.Parameters.Add("@nom", SqlDbType.VarChar, 50, "Nom_Cli"); Demarage.da.InsertCommand.Parameters.Add("@pren", SqlDbType.VarChar, 50, "Prenom_Cli"); Demarage.da.InsertCommand.Parameters.Add("@adres", SqlDbType.VarChar, 50, "Adresse_Cli"); //Demarage.da.Update(Demarage.ds, "Client"); Demarage.da.DeleteCommand = Demarage.cn.CreateCommand(); Demarage.da.DeleteCommand.CommandText = "delete from Client where Id_Cli=@id"; Demarage.da.DeleteCommand.Parameters.Add("@id", SqlDbType.Int, 15, "Id_Cli"); Demarage.da.DeleteCommand.Parameters.Add("@nom", SqlDbType.VarChar, 50, "Nom_Cli"); Demarage.da.DeleteCommand.Parameters.Add("@pren", SqlDbType.VarChar, 50, "Prenom_Cli"); Demarage.da.DeleteCommand.Parameters.Add("@adres", SqlDbType.VarChar, 50, "Adresse_Cli"); //Demarage.da.Update(Demarage.ds, "Client"); Demarage.da.UpdateCommand = Demarage.cn.CreateCommand(); Demarage.da.UpdateCommand.CommandText = "update Client set Nom_Cli=@nom,Prenom_Cli=@pren,Adresse_Cli=@adres where Id_Cli=@id"; Demarage.da.UpdateCommand.Parameters.Add("@id", SqlDbType.Int, 15, "Id_Cli"); Demarage.da.UpdateCommand.Parameters.Add("@nom", SqlDbType.VarChar, 50, "Nom_Cli"); Demarage.da.UpdateCommand.Parameters.Add("@pren", SqlDbType.VarChar, 50, "Prenom_Cli"); Demarage.da.UpdateCommand.Parameters.Add("@adres", SqlDbType.VarChar, 50, "Adresse_Cli"); Demarage.da.Update(Demarage.ds, "Client"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void DGV_CellClick(object sender, DataGridViewCellEventArgs e) { cin.Text = DGV.CurrentRow.Cells[0].Value.ToString(); nom .Text = DGV.CurrentRow.Cells[1].Value.ToString(); prenom .Text = DGV.CurrentRow.Cells[2].Value.ToString(); adresse.Text = DGV.CurrentRow.Cells[3].Value.ToString(); } private void Afficher_Click(object sender, EventArgs e) { try { Demarage.rowco = Demarage.dt.Rows.Find(int.Parse(cin.Text)); DataRow[] rows = Demarage.rowco.GetChildRows("clicom"); DataTable comds = new DataTable(); comds.Columns.Add("Numro Client");

25

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

comds.Columns.Add("Date de Commande"); for (int a = 0; a < rows.Count(); a++) { comds.Rows.Add(new object[] { rows[a][0], rows[a][2] }); } DGV .DataSource = comds; } catch (Exception ex) { MessageBox.Show(ex.Message); }

public partial class Article : Form { public Article() { InitializeComponent(); } private void Article_Load(object sender, EventArgs e) { DGV.DataSource = Demarage.dt2; } private void fermer_Click(object sender, EventArgs e) { this.Close(); } private void ajouter_Click(object sender, EventArgs e) { try{ Demarage.dr = Demarage.dt2.NewRow(); Demarage.dr[0] = int.Parse(ref_art.Text); Demarage.dr[1] = dsg.Text; Demarage.dr[2] = int.Parse(Qt_stok .Text); Demarage.dr[3] = int.Parse(Prix_u .Text);

26

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

Demarage.dt2.Rows.Add(Demarage.dr); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void Modifier_Click(object sender, EventArgs e) { try { Demarage.dr=Demarage.dt2.Rows.Find(int.Parse(ref_art.Text)); // Demarage.dr[0] = int.Parse(ref_art.Text); Demarage.dr[1]=dsg.Text; Demarage.dr[2]=int.Parse(Qt_stok.Text); Demarage.dr[3]=Prix_u.Text; } catch(Exception ex){MessageBox.Show(ex.Message); }

private void Rchercher_Click(object sender, EventArgs e) { try { Demarage.dr = Demarage.dt2.Rows.Find(int.Parse(ref_art.Text)); ref_art.Text=Demarage.dr[0].ToString() ; dsg.Text = Demarage.dr[1].ToString(); Qt_stok.Text = Demarage.dr[2].ToString(); Prix_u.Text = Demarage.dr[3].ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } public void vider() { ref_art.Clear(); dsg.Clear(); Qt_stok.Clear(); Prix_u.Clear(); ref_art.Focus(); } private void supprimer_Click(object sender, EventArgs e) { try { Demarage.dr = Demarage.dt2.Rows.Find(int.Parse(ref_art.Text)); Demarage.dr.Delete(); vider(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }

27

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

private void DGV_CellClick(object sender, DataGridViewCellEventArgs e) { ref_art.Text = DGV.CurrentRow.Cells[0].Value.ToString(); dsg.Text = DGV.CurrentRow.Cells[1].Value.ToString(); Qt_stok.Text = DGV.CurrentRow.Cells[2].Value.ToString(); Prix_u.Text = DGV.CurrentRow.Cells[3].Value.ToString(); } private void Valider_Click(object sender, EventArgs e) { try{ Demarage.da.InsertCommand = Demarage.cn.CreateCommand(); Demarage.da.InsertCommand.CommandText = "insert into article values (@r,@d,@q,@p)"; Demarage.da.InsertCommand.Parameters.Add("@r", SqlDbType.Int, 15, "Rf_Art"); Demarage.da.InsertCommand.Parameters.Add("@d",SqlDbType.Text,50 ,"Dsig"); Demarage.da.InsertCommand.Parameters.Add("@q", SqlDbType.Int, 15, "qt_Stock"); Demarage.da.InsertCommand.Parameters.Add("@p", SqlDbType.Int, 15, "Prix_unit"); //Demarage.da.Update(Demarage.ds, "article"); Demarage.da.DeleteCommand = Demarage.cn.CreateCommand(); Demarage.da.DeleteCommand.CommandText = "delete from article where Rf_Art=@r"; Demarage.da.DeleteCommand.Parameters.Add("@r", SqlDbType.Int, 15, "Rf_Art"); //Demarage.da.Update(Demarage.ds, "article"); Demarage.da.UpdateCommand = Demarage.cn.CreateCommand(); Demarage.da.UpdateCommand.CommandText = "update Article set Dsig=@d,qt_Stock=@q,Prix_unit=@p where Rf_Art=@r"; Demarage.da.UpdateCommand.Parameters.Add("@r", SqlDbType.Int, 15, "Rf_Art"); Demarage.da.UpdateCommand.Parameters.Add("@d", SqlDbType.Text, 50, "Dsig"); Demarage.da.UpdateCommand.Parameters.Add("@q", SqlDbType.Int, 15, "qt_Stock"); Demarage.da.UpdateCommand.Parameters.Add("@p", SqlDbType.Int, 15, "Prix_unit"); Demarage.da.Update(Demarage.ds, "article"); } catch (Exception ex) { MessageBox.Show(ex.Message);}

public partial class Commande : Form {

28

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

public Commande() { InitializeComponent(); } private void fermer_Click(object sender, EventArgs e) { this.Close(); } private void Commande_Load(object sender, EventArgs e) { groupBox1.Enabled = false; groupBox2.Enabled = false; Nom.DisplayMember="Nom_Cli"; Nom.ValueMember="Id_Cli"; Demarage.da.SelectCommand = Demarage.cn.CreateCommand(); Demarage.da.SelectCommand.CommandText = "select * from Client"; Demarage.da.Fill(Demarage.ds, "C1"); Nom.DataSource = Demarage.ds.Tables["C1"]; } private void Nom_SelectedIndexChanged(object sender, EventArgs e) { Demarage.dr = Demarage.dt.Rows.Find(Nom.SelectedValue); Prenom.Text = Demarage.dr[2].ToString(); Adresse.Text = Demarage.dr[3].ToString(); } private void Ajouter_Click(object sender, EventArgs e) { groupBox1.Enabled = true ; } private void Enregistrer_Click(object sender, EventArgs e) { try { Demarage.dr = Demarage.dt1.NewRow(); Demarage.dr[0] = Num_comm.Text; Demarage.dr[1] = Nom.SelectedValue; Demarage.dr[2] = DTP.Text; Demarage.dt1.Rows.Add(Demarage.dr); Demarage.da.InsertCommand = Demarage.cn.CreateCommand(); Demarage.da.InsertCommand.CommandText = "insert into commande values (@id_c,@id_cl,@date)"; Demarage.da.InsertCommand.Parameters.Add("@id_c", SqlDbType.Int, 15, "Id_Comm"); Demarage.da.InsertCommand.Parameters.Add("@id_cl", SqlDbType.Int, 50, "Id_Cli"); Demarage.da.InsertCommand.Parameters.Add("@date", SqlDbType.DateTime, 15, "Date_Comm"); Demarage.da.Update(Demarage.ds, "commande"); Produit.DisplayMember = "Dsig"; Produit.ValueMember = "Rf_Art";

29

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

Demarage.da.SelectCommand.CommandText = "select * from article"; Demarage.da.Fill(Demarage.ds, "AR"); Demarage.dt2 = Demarage.ds.Tables["AR"]; Produit.DataSource = Demarage.dt2; groupBox2.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void Produit_SelectedIndexChanged(object sender, EventArgs e) { Demarage.dt2.PrimaryKey = new DataColumn[] { Demarage.dt2.Columns[0] }; Demarage.dr = Demarage.dt2.Rows.Find(Produit.SelectedValue); dsig.Text = Demarage.dr[1].ToString(); qt_stock .Text = Demarage.dr[2].ToString(); prix_u .Text = Demarage.dr[3].ToString(); } private void Ajouter_art_comm_Click(object sender, EventArgs e) { try { if (int.Parse(qt_comm.Text) <= int.Parse(qt_stock.Text)) { Demarage.dr = Demarage.dt3.NewRow(); Demarage.dr[0] = int.Parse (Num_comm.Text); Demarage.dr[1] = Produit.SelectedValue; Demarage.dr[2] =int.Parse (qt_comm.Text); Demarage.dt3.Rows.Add(Demarage.dr); DataRow dra = Demarage.dt2.NewRow(); dra = Demarage.dt2.Rows.Find(Produit.SelectedValue); dra[2] = int.Parse(dra[2].ToString()) - int.Parse(qt_comm.Text); Demarage.da.UpdateCommand = Demarage.cn.CreateCommand(); Demarage.da.UpdateCommand.CommandText = "update Article set qt_Stock= @qt_c where Rf_Art=@r"; Demarage.da.UpdateCommand.Parameters.Add("@r", SqlDbType.Int, 15, "Rf_Art"); Demarage.da.UpdateCommand.Parameters.Add("@qt_c", SqlDbType.Int, 15, "qt_Stock"); Demarage.da.Update(Demarage.ds, "Article"); MessageBox.Show("Mise a jours avec succ"); } else { MessageBox.Show("Qt commander est suprieur a la qt en stock"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void Valider_Click(object sender, EventArgs e) { try { Demarage.da.InsertCommand = Demarage.cn.CreateCommand(); Demarage.da.InsertCommand.CommandText = "insert into Ligne_Commande values (@id,@ref,@qt)";

30

Echerfaoui Mhammed

3me Anne TS TDI

CFHN

Formateur : Hamid Azzi

Demarage.da.InsertCommand.Parameters.Add("@id", SqlDbType.Int, 15, "Id_Comm"); Demarage.da.InsertCommand.Parameters.Add("@ref", SqlDbType.VarChar, 50, "Rf_Art"); Demarage.da.InsertCommand.Parameters.Add("@qt", SqlDbType.Int, 15, "Qt_Comm"); Demarage.da.Update(Demarage.ds, "LigCom"); Demarage.da.UpdateCommand = Demarage.cn.CreateCommand(); Demarage.da.UpdateCommand.CommandText = "update Article set qt_Stock= @qt_c where Rf_Art=@r "; Demarage.da.UpdateCommand.Parameters.Add("@r", SqlDbType.Int, 15, "Rf_Art"); Demarage.da.UpdateCommand.Parameters.Add("@qt_c", SqlDbType.Int, 15, "Qt_Comm"); Demarage.da.Update(Demarage.ds, "Article"); } catch (Exception ex) { MessageBox.Show(ex.Message);

Les tats de Sortie : CrystalReport.rpt

31