Example #1
0
        private void btnSale_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Продать этот товар?", "Продать",
                               MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                {

                    return;
                }
                else
                {
                    var prod = new ProductManager();
                    prod.AddSale(Convert.ToInt32(txtHiddenId.Text), Convert.ToInt32(txtСountProduct.Text));
                    var temp = new SaleProductManager();

                    var sale = new SaleProduct()
                    {

                        Name = txtNameProduct.Text.ToString(),
                        Count = Convert.ToInt32(txtСountProduct.Text),
                        Price = Convert.ToInt32(txtPriceProduct.Text),
                        Discount = Convert.ToInt32(txtDiscount.Text),
                        DateTimeSale = DateTime.Now
                    };
                    temp.AddSale(sale, cmbLabel.Text.ToString());
                    dtGridProducts.DataSource = prod.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 = prod.GetAllProductCount(prod.GetAllProduct()).ToString();
                    txtAllPriceGrid.Text = prod.GetAllProductPrice(prod.GetAllProduct()).ToString();
                    MessageBox.Show("Товар продан");
                }

            }
            catch (Exception)
            {

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