private void EditBtn_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(ReferenceTextBox.Text) || string.IsNullOrWhiteSpace(ReferenceTextBox.Text)) { MessageBox.Show("reference non valid"); return; } facture.Reference = ReferenceTextBox.Text; if (facturesRepo.IsExist(facture.Reference, facture.Id)) { MessageBox.Show("reference exist. choose another reference."); return; } facture.Date = DateDP.Value; facturesRepo.Edit(facture); facturesForm.FacturesGridView.DataSource = facturesRepo.Get(); this.Close(); } catch { MessageBox.Show("something went wrong !"); } }
private void ConfirmBtn_Click(object sender, EventArgs e) { if (Items.Count == 0) { MessageBox.Show("Invoice could not be empty !"); return; } string reference = ReferenceTextBox.Text; DateTime Date = Convert.ToDateTime(DateDP.Text); if (string.IsNullOrEmpty(reference) || string.IsNullOrWhiteSpace(reference)) { MessageBox.Show("Reference non valid"); return; } if (facturesRepo.IsExist(reference)) { MessageBox.Show("Reference exist. choose another reference."); return; } Facture facture = new Facture() { Date = DateDP.Value, Reference = ReferenceTextBox.Text, Total = GetMontant(), }; List <LigneFacture> factureLignes = new List <LigneFacture>(); foreach (var item in Items) { factureLignes.Add(new LigneFacture(item)); } List <Article> UpdatedArticles = new List <Article>(); foreach (var factureLigne in factureLignes) { UpdatedArticles.Add(new Article() { Quantite = factureLigne.Quantite, Id = factureLigne.IdArticle }); } if (transactionsRepository.AddFactureWithTransaction(facture, factureLignes, UpdatedArticles)) { MessageBox.Show("Facture added successfully "); } else { MessageBox.Show("Something went wrong :( "); } facturesForm.FacturesGridView.DataSource = facturesRepo.Get(); this.Close(); }