Esempio n. 1
0
        private void EditBtn_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 (string.IsNullOrEmpty(article.Designation) || string.IsNullOrWhiteSpace(article.Designation))
                {
                    MessageBox.Show("Description field is empty.");
                    return;
                }

                if (articleRepo.IsExist(article.Reference, article.Id))
                {
                    MessageBox.Show("reference exist. choose another reference.");
                    return;
                }

                articleRepo.Edit(article);
                MessageBox.Show("article updated successfully. ");
                home.ArticleGridView.DataSource = articleRepo.Get();
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("failed!");
            }
        }