Ejemplo n.º 1
0
        private void btnUpdate_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()
                    {
                        Id = Convert.ToInt32(txtHiddenId.Text),
                        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.SaveProduct(helper, cmbLabel.Text.ToString()))
                    {
                        dtGridProducts.DataSource = temp.GetAllProduct();
                        if (Convert.ToInt32(txtHiddenIndex.Text) < dtGridProducts.RowCount)
                        {
                            dtGridProducts.ClearSelection();
                            dtGridProducts.Rows[Convert.ToInt32(txtHiddenIndex.Text)].Selected = true;
                            dtGridProducts.FirstDisplayedScrollingRowIndex = Convert.ToInt32(txtHiddenIndex.Text);
                            dtGridProducts.Update();
                        }
                        txtCountProductGrid.Text = temp.GetAllProductCount(temp.GetAllProduct()).ToString();
                        txtAllPriceGrid.Text = temp.GetAllProductPrice(temp.GetAllProduct()).ToString();
                        MessageBox.Show("Товар изменен");
                    }
                    else
                    {
                        MessageBox.Show("Упс! Что-то пошло не так!");
                    }
                }
            }
            catch (Exception)
            {

                MessageBox.Show("Упс! Что-то пошло не так!");
            }
        }