private void button2_Click(object sender, EventArgs e) { DAL d = new DAL(); Facture f = new Facture(); Class_Article a = new Class_Article(); LigneFacture c = new LigneFacture(); f.Num_facture = textBox1.Text; f.Date_facture = dateTimePicker1.Value; // int IdFact = d.Insert Facture(f); // if (IdFact > 0) // { MessageBox.Show("Facture Ajouté"); foreach (DataGridViewRow r in dataGridView1.Rows) { c.Reference = textBox1.Text; //c.IdArticle = Convert.ToString(r.Cells[0].Value); c.Quantite = Convert.ToInt16(r.Cells[3].Value); d.Insert_Commande(c); int qte = Convert.ToInt16(r.Cells[3].Value); a = d.fill_art_ref(Convert.ToString(r.Cells[0].Value)); // MessageBox.Show("" + a.Quantite1); a.Quantite1 = a.Quantite1 - qte; string refe = Convert.ToString(r.Cells[0].Value); d.UpDate_qte(a, refe); } MessageBox.Show("Facture n'est pas Ajouté"); this.Hide(); }
//Ajout Commande public Boolean Insert_Commande(LigneFacture c) { conn.Open(); string Marequet = "INSERT INTO LigneFacture (Reference , Id_act , Quantite) VALUES ( @Reference , @IdArticle , @Quantite )"; SqlCommand cmd = new SqlCommand(Marequet, conn); cmd.Parameters.AddWithValue("@Reference", c.Reference); cmd.Parameters.AddWithValue("@IdArticle", c.IdArticle); cmd.Parameters.AddWithValue("@IdArticle", c.Idfacture); cmd.Parameters.AddWithValue("@Quantite", c.Quantite); cmd.ExecuteNonQuery(); conn.Close(); return(true); }