示例#1
0
文件: Form1.cs 项目: FrolowPN/myideal
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Добавить этот товар?", "Добавить",
                               MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                {

                    return;
                }
                else
                {
                    var ctx = new ShopContext();
                    var helper = new Product()
                    {
                        Name = txtNameProduct.Text.ToString(),
                        Volume = Convert.ToInt32(txtVolumeProduct.Text),
                        Price = Convert.ToInt32(txtPriceProduct.Text),
                        Count = Convert.ToInt32(txtСountProduct.Text)
                    };
                    var temp = new ProductManager();
                    if (temp.AddProduct(helper, cmbLabel.Text.ToString()))
                    {
                        dtGridProducts.DataSource = temp.GetAllProduct();
                        txtCountProductGrid.Text = temp.GetAllProductCount(temp.GetAllProduct()).ToString();
                        txtAllPriceGrid.Text = temp.GetAllProductPrice(temp.GetAllProduct()).ToString();
                        MessageBox.Show("Товар добавлен!");
                    }
                    else
                    {
                        MessageBox.Show("Упс! Что-то пошло не так!");
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Упс! Что-то пошло не так!");

            }
        }