示例#1
0
        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();
        }