Exemple #1
0
        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("Упс! Что-то пошло не так!");

            }
        }
Exemple #2
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Удалить товар?", "Удалить",
                               MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                {

                    return;
                }
                else
                {
                    var temp = new ProductManager();
                    if (temp.DeleteProduct(Convert.ToInt32(txtHiddenId.Text)))
                    {
                        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("Упс! Что-то пошло не так!");
            }
        }
Exemple #3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            var products = new ProductManager();
            dtGridProducts.DataSource = products.GetAllProduct();
            dtGridProducts.Columns["Id"].Visible = false;
            dtGridProducts.Columns["LabelName"].HeaderText = "Марка";
            dtGridProducts.Columns["Name"].HeaderText = "Название";
            dtGridProducts.Columns["Name"].FillWeight = 250;
            dtGridProducts.Columns["Volume"].HeaderText = "Объем";
            dtGridProducts.Columns["Price"].HeaderText = "Цена";
            dtGridProducts.Columns["Count"].HeaderText = "Количество";

            txtCountProductGrid.Text = products.GetAllProductCount(products.GetAllProduct()).ToString();
            txtAllPriceGrid.Text = products.GetAllProductPrice(products.GetAllProduct()).ToString();

            var temp = new LabelManager();
            cmbLabel.DataSource = temp.GetAllLabel();
            cmbLabel.ValueMember = "Id";
            cmbLabel.DisplayMember = "NameLabel";
            cmbLabelGrid.DataSource = temp.GetAllLabel();
            cmbLabelGrid.ValueMember = "Id";
            cmbLabelGrid.DisplayMember = "NameLabel";
            txtDiscount.Text = "0";
        }
Exemple #4
0
 private void butnViewWithLabel_Click(object sender, EventArgs e)
 {
     var helper = new ProductManager();
     dtGridProducts.DataSource = helper.GetProductLabel(cmbLabelGrid.Text.ToString());
     txtCountProductGrid.Text = helper.GetAllProductCount(helper.GetProductLabel(cmbLabelGrid.Text.ToString())).ToString();
     txtAllPriceGrid.Text = helper.GetAllProductPrice(helper.GetProductLabel(cmbLabelGrid.Text.ToString())).ToString();
 }
Exemple #5
0
 private void btnViewAllProduct_Click(object sender, EventArgs e)
 {
     var products = new ProductManager();
     dtGridProducts.DataSource = products.GetAllProduct();
     txtCountProductGrid.Text = products.GetAllProductCount(products.GetAllProduct()).ToString();
     txtAllPriceGrid.Text = products.GetAllProductPrice(products.GetAllProduct()).ToString();
 }
Exemple #6
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("Упс! Что-то пошло не так!");
            }
        }
Exemple #7
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("Упс! Что-то пошло не так!");
            }
        }