public void AddByList(Facture fc) { try { Article Artic; SqlCommand MySqlCommand = new SqlCommand("insert into [Facture](Reference,Montant, Date) values(@Facture_ref, @Facture_Montant ,@Facture_date)"); MySqlCommand.Parameters.Add("@Facture_ref", SqlDbType.VarChar).Value = Convert.ToString(fc.RefProp); MySqlCommand.Parameters.Add("@Facture_Date", SqlDbType.DateTime).Value = Convert.ToDateTime(fc.DateProp); MySqlCommand.Parameters.Add("@Facture_Montant", SqlDbType.Int).Value = fc.MontantProp; Connexion.FunctionToWrite(MySqlCommand); foreach (LigneFacture ListLf in fc.ListLgFacture) { MySqlCommand = new SqlCommand("insert into [LigneFacture](IdFacture, IdArticle, Reference , Pu, Quantite) values(@FactureId, @ArticleId, @articles_ref, @articles_prix, @articles_quant)"); MySqlCommand.Parameters.Add("@articles_ref", SqlDbType.VarChar).Value = Convert.ToString(ListLf.RefProp); MySqlCommand.Parameters.Add("@articles_prix", SqlDbType.Float).Value = Convert.ToDouble(ListLf.PrixUProp); MySqlCommand.Parameters.Add("@articles_quant", SqlDbType.Int).Value = Convert.ToInt32(ListLf.QuantProp); MySqlCommand.Parameters.Add("@ArticleId", SqlDbType.Int).Value = Convert.ToInt32(GetArticleId(ListLf.RefProp)); MySqlCommand.Parameters.Add("@FactureId", SqlDbType.Int).Value = Convert.ToInt32(GetFactureId(fc.RefProp)); DataTable MyDat = new DALArticle().SelectByRef(ListLf.RefProp); Artic = new Article(ListLf.RefProp, MyDat.Rows[0]["Designation"].ToString(), float.Parse(MyDat.Rows[0]["Prix"].ToString()), Convert.ToBoolean(MyDat.Rows[0]["Promo"].ToString()) , MyDat.Rows[0]["DateInPromo"].ToString(), Int32.Parse(MyDat.Rows[0]["Quantite"].ToString()) - ListLf.QuantProp); new DALArticle().Update(ListLf.RefProp, Artic); Connexion.FunctionToWrite(MySqlCommand); } } catch (SqlException es) { MessageBox.Show(es.Message); } }
private void AjouterLineFacture_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); dt = new DALArticle().GetAllArticles(); for (int i = 0; i < dt.Rows.Count; i++) { this.Cbx_Ref.Items.Add(dt.Rows[i]["Reference"]); } }
public void DeleteFact(Facture fac) { Article Artic; MySqlCommand = new SqlCommand("DELETE FROM [Facture] WHERE Reference = @Rdel"); MySqlCommand.Parameters.Add("@Rdel", SqlDbType.VarChar).Value = fac.RefProp; foreach (LigneFacture ListLf in fac.ListLgFacture) { DataTable MyDat = new DALArticle().SelectByRef(fac.RefProp); Artic = new Article(ListLf.RefProp, MyDat.Rows[0]["Designation"].ToString(), float.Parse(MyDat.Rows[0]["Prix"].ToString()), Convert.ToBoolean(MyDat.Rows[0]["Promo"].ToString()) , MyDat.Rows[0]["DateInPromo"].ToString(), Int32.Parse(MyDat.Rows[0]["Quantite"].ToString()) + ListLf.QuantProp); new DALArticle().Update(ListLf.RefProp, Artic); } Connexion.FunctionToWrite(MySqlCommand); }