private void button1_Click(object sender, EventArgs e) { string product_id = comboBox2.SelectedValue.ToString(); int id = 0; bool convert = Int32.TryParse(product_id, out id); if (convert == false) { return; } Invoice invoice = new Invoice(); FillInvoice(invoice, id); Product product = db.Products.Find(id); var minus = (product.in_stock.Value - Int32.Parse(textBox1.Text)); if (minus >= 0) { product.in_stock = (product.in_stock - invoice.quantity); fillProductInfo(product); db.Entry(product).State = EntityState.Modified; db.Invoices.Add(invoice); db.SaveChanges(); MessageBox.Show("Покупка совершена", "Внимание!", MessageBoxButtons.OK); } else { MessageBox.Show("Указанное количество товара \"" + product.name + "\" нет в наличии!", "Ошибка"); } }
//редактирвоание категории private void button2_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count > 0) { int index = dataGridView1.SelectedRows[0].Index; int id = 0; bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id); if (converted == false) { return; } Category category = db.Categories.Find(id); CategoryUpdateForm cuForm = new CategoryUpdateForm(); cuForm.textBox2.Text = category.name; ; DialogResult result = cuForm.ShowDialog(this); if (result == DialogResult.Cancel) { return; } category.name = cuForm.textBox2.Text; db.Entry(category).State = EntityState.Modified; db.SaveChanges(); RefreshGrid(); MessageBox.Show("Категория обновлена"); } }
//добавление накладной private void button1_Click(object sender, EventArgs e) { InvoicesAddForm invoicesAddForm = new InvoicesAddForm(); invoicesAddForm.comboBox1.DataSource = products; invoicesAddForm.comboBox1.ValueMember = "id"; invoicesAddForm.comboBox1.DisplayMember = "name"; DialogResult result = invoicesAddForm.ShowDialog(this); if (result == DialogResult.Cancel) { return; } Invoice invoice = new Invoice(); invoice.invoice_code = invoicesAddForm.textBox2.Text; invoice.sale_date = invoicesAddForm.dateTimePicker1.Value; invoice.product_id = (int)invoicesAddForm.comboBox1.SelectedValue; invoice.quantity = Int32.Parse(invoicesAddForm.textBox1.Text); if (invoice.quantity != null) { Product product = db.Products.Find(invoicesAddForm.comboBox1.SelectedValue); var minus = (product.in_stock.Value - Int32.Parse(invoicesAddForm.textBox1.Text)); if (minus >= 0) { invoice.price = (product.price * invoice.quantity); db.Entry(product).State = EntityState.Modified; db.SaveChanges(); db.Invoices.Add(invoice); db.SaveChanges(); RefreshGrid(dataGridView1); MessageBox.Show("Накладная добавлена"); } else { MessageBox.Show("Указанное количество товара \"" + product.name + "\" нет в наличии!", "Ошибка"); } } }
//редактирвоание товара private void button2_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count > 0) { int index = dataGridView1.SelectedRows[0].Index; int id = 0; bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id); if (converted == false) { return; } Manufacturer manufacturer = db.Manufacturers.Find(id); ManufacturerAddForm muForm = new ManufacturerAddForm(); muForm.textBox1.Text = manufacturer.name; muForm.textBox2.Text = manufacturer.country; muForm.textBox3.Text = manufacturer.state; muForm.textBox4.Text = manufacturer.city; muForm.textBox5.Text = manufacturer.address; muForm.textBox6.Text = manufacturer.ZIP; muForm.textBox7.Text = manufacturer.telephone; DialogResult result = muForm.ShowDialog(this); if (result == DialogResult.Cancel) { return; } manufacturer.name = muForm.textBox1.Text; manufacturer.country = muForm.textBox2.Text; manufacturer.state = muForm.textBox3.Text; manufacturer.city = muForm.textBox4.Text; manufacturer.address = muForm.textBox5.Text; manufacturer.ZIP = muForm.textBox6.Text; manufacturer.telephone = muForm.textBox7.Text; db.Entry(manufacturer).State = EntityState.Modified; db.SaveChanges(); RefreshGrid(dataGridView1); MessageBox.Show("Производитель обновлен"); } }
//редактирвоание товара private void button2_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count > 0) { int index = dataGridView1.SelectedRows[0].Index; int id = 0; bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id); if (converted == false) { return; } Supplier supplier = db.Suppliers.Find(id); SupplierAddForm suForm = new SupplierAddForm(); suForm.textBox1.Text = supplier.name; suForm.textBox2.Text = supplier.country; suForm.textBox3.Text = supplier.state; suForm.textBox4.Text = supplier.city; suForm.textBox7.Text = supplier.telephone; DialogResult result = suForm.ShowDialog(this); if (result == DialogResult.Cancel) { return; } supplier.name = suForm.textBox1.Text; supplier.country = suForm.textBox2.Text; supplier.state = suForm.textBox3.Text; supplier.city = suForm.textBox4.Text; supplier.telephone = suForm.textBox7.Text; db.Entry(supplier).State = EntityState.Modified; db.SaveChanges(); RefreshGrid(dataGridView1); MessageBox.Show("Поставщик обновлен"); } }
//редактирвоание товара private void button2_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count > 0) { int index = dataGridView1.SelectedRows[0].Index; int id = 0; bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id); if (converted == false) { return; } Product product = db.Products.Find(id); ProductUpdateForm puForm = new ProductUpdateForm(); puForm.maskedTextBox1.Text = product.productCode; puForm.textBox2.Text = product.name; puForm.comboBox1.DataSource = categories; puForm.comboBox1.ValueMember = "id"; puForm.comboBox1.DisplayMember = "name"; if (product.Category != null) { puForm.comboBox1.SelectedValue = product.Category.id; } puForm.comboBox2.DataSource = expires; puForm.comboBox2.ValueMember = "id"; puForm.comboBox2.DisplayMember = "expire_date"; if (product.Expire != null) { puForm.comboBox2.SelectedValue = product.Expire.id; } puForm.comboBox3.DataSource = temperatures; puForm.comboBox3.ValueMember = "id"; puForm.comboBox3.DisplayMember = "temperature"; if (product.Temperature != null) { puForm.comboBox3.SelectedValue = product.Temperature.id; } puForm.comboBox4.DataSource = manufacturers; puForm.comboBox4.ValueMember = "id"; puForm.comboBox4.DisplayMember = "name"; if (product.Manufacturer != null) { puForm.comboBox4.SelectedValue = product.Manufacturer.id; } puForm.comboBox5.DataSource = suppliers; puForm.comboBox5.ValueMember = "id"; puForm.comboBox5.DisplayMember = "name"; if (product.Supplier != null) { puForm.comboBox5.SelectedValue = product.Supplier.id; } puForm.numericUpDown1.Value = (decimal)product.price; puForm.textBox4.Text = product.in_stock.ToString(); puForm.textBox1.Text = product.description; DialogResult result = puForm.ShowDialog(this); if (result == DialogResult.Cancel) { return; } product.productCode = puForm.maskedTextBox1.Text; product.name = puForm.textBox2.Text; product.category_id = (int)puForm.comboBox1.SelectedValue; product.price = (decimal)puForm.numericUpDown1.Value; product.in_stock = Int32.Parse(puForm.textBox4.Text); product.expire_date_id = (int)puForm.comboBox2.SelectedValue; product.temperature_id = (int)puForm.comboBox3.SelectedValue; product.manufacturer_id = (int)puForm.comboBox4.SelectedValue; product.supplier_id = (int)puForm.comboBox5.SelectedValue; product.description = puForm.textBox1.Text; db.Entry(product).State = EntityState.Modified; db.SaveChanges(); RefreshGrid(dataGridView1); MessageBox.Show("Товар обновлен"); } }