Exemplo n.º 1
0
 private void AddBtn_Click(object sender, EventArgs e)
 {
     try
     {
         article.Reference    = ReferenceTextBox.Text;
         article.Designation  = DescriptionTextBox.Text;
         article.Promo        = InPromotionCheckBox.Checked;
         article.DateFinPromo = Convert.ToDateTime(DateEndPromotTimePicker.Text);
         float price;
         article.Prix = float.TryParse(PriceTextBox.Text, out price) ? price : 0;
         if (string.IsNullOrWhiteSpace(QuantityTextBox.Text) || string.IsNullOrEmpty(QuantityTextBox.Text))
         {
             article.Quantite = null;
         }
         else
         {
             article.Quantite = Convert.ToInt32(QuantityTextBox.Text);
         }
         if (string.IsNullOrEmpty(article.Reference) || string.IsNullOrWhiteSpace(article.Reference))
         {
             MessageBox.Show("Reference field is empty.");
             return;
         }
         if (articleRepo.IsExist(article.Reference))
         {
             MessageBox.Show("reference exist. choose another reference.");
             return;
         }
         if (string.IsNullOrEmpty(article.Designation) || string.IsNullOrWhiteSpace(article.Designation))
         {
             MessageBox.Show("Description field is empty.");
             return;
         }
         articleRepo.Insert(article);
         MessageBox.Show("article inserted. ");
         preForm.ArticleGridView.DataSource = articleRepo.Get();
         this.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show("failed!");
     }
 }