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("Упс! Что-то пошло не так!"); } }
private void btnCancelSale_Click(object sender, EventArgs e) { if (MessageBox.Show("Отменить продажу?", "Отменить", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } else { try { var helperSale = new SaleProductManager(); var helperProduct = new ProductManager(); if (helperProduct.DelSale(Convert.ToInt32(txtHiddenIdProduct.Text), Convert.ToInt32(txtHiddenCount.Text)) && helperSale.DelSale(Convert.ToInt32(txtHiddenId.Text))) { dtGrSale.DataSource = helperSale.GetAllSale(); MessageBox.Show("Продажа успешно отменена!"); var products = new ProductManager(); Form1 form = new Form1(); form.dtGridProducts.DataSource = products.GetAllProduct(); } else { } } catch (Exception) { MessageBox.Show("Упс! Что-то пошло не так!"); } } }
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("Упс! Что-то пошло не так!"); } }
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"; }
private void bетDelLabel_Click(object sender, EventArgs e) { if (MessageBox.Show("Изменить марку?", "Изменить", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } else { var helper = new LabelManager(); helper.DelLabel(Convert.ToInt32(txtHiddenIdLabel.Text), cmbLabel.Text.ToString()); cmbLabel.DataSource = helper.GetAllLabel(); cmbLabelGrid.DataSource = helper.GetAllLabel(); var prod = new ProductManager(); dtGridProducts.DataSource = prod.GetAllProduct(); MessageBox.Show("Марка успешно изменена!"); } }
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(); }
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("Упс! Что-то пошло не так!"); } }
private void btnSaveInFile_Click(object sender, EventArgs e) { FolderBrowserDialog FBD = new FolderBrowserDialog(); if (FBD.ShowDialog() == DialogResult.OK) { var helper = new ProductManager(); if (helper.WriteProductsFile(helper.GetAllProduct(), FBD.SelectedPath.ToString())) { MessageBox.Show("Товары сохранены в файл!"); } else { MessageBox.Show("Упс! Что-то пошло не так!"); } } }
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("Упс! Что-то пошло не так!"); } }