private void button4_Click(object sender, EventArgs e) { SkladDBEntities context = new SkladDBEntities(); int currentCustomer = Convert.ToInt32( dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells[1].Value); Customer c = context.Customer.Find(currentCustomer); List <Invoice> invoidce = context.Invoice .Where(o => o.ID_customer == currentCustomer).ToList(); List <Product_customer> pc = context.Product_customer .Where(o => o.ID_customer == currentCustomer).ToList(); for (int i = 0; i < invoidce.Count; i++) { context.Invoice.Remove(invoidce[i]); } for (int i = 0; i < pc.Count; i++) { context.Product_customer.Remove(pc[i]); } context.Customer.Remove(c); context.SaveChanges(); RefreshCustomer(); RefreshCustProducts(); }
private void button2_Click(object sender, EventArgs e) { SkladDBEntities context = new SkladDBEntities(); int currentProduct = Convert.ToInt32( dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[2].Value); Product c = context.Product.Find(currentProduct); List <Product_Storage_place> invoidce = context.Product_Storage_place .Where(o => o.ID_product == currentProduct).ToList(); List <Product_customer> pc = context.Product_customer .Where(o => o.ID_product == currentProduct).ToList(); for (int i = 0; i < invoidce.Count; i++) { context.Product_Storage_place.Remove(invoidce[i]); } for (int i = 0; i < pc.Count; i++) { context.Product_customer.Remove(pc[i]); } context.Product.Remove(c); context.SaveChanges(); //RefreshCustomer(); RefreshCustProducts(); RefreshProduct(); }
private void button1_Click(object sender, EventArgs e) { try { string date = textBox1.Text; SkladDBEntities context = new SkladDBEntities(); Product_customer p_c = context.Product_customer .Where(o => o.ID_customer == currentCust && o.ID_product == currentProd).First(); if (date == "") { MessageBox.Show("Заполните поле дата"); return; } p_c.Order_date = date; context.Product_customer.Attach(p_c); context.Entry(p_c).Property(o => o.Order_date).IsModified = true; context.SaveChanges(); DialogResult = DialogResult.OK; } catch (FormatException) { MessageBox.Show("Заполните поле дата"); } catch (Exception) { throw; } }
private void button1_Click(object sender, EventArgs e) { try { SkladDBEntities context = new SkladDBEntities(); int id = context.Product.Max(o => o.ID_product); string name = textBox1.Text; string manuf = textBox2.Text; List <Manufacturer> m = context.Manufacturer .Where(o => o.C_Name == name).ToList(); if (m.Count == 0) { int idM = context.Manufacturer.Max(o => o.ID_manufacturer); Manufacturer man = new Manufacturer { ID_manufacturer = idM + 1, C_Name = manuf }; Product p = new Product { C_Name = name, ID_product = id + 1, C_Count = 0, ID_manufacturer = man.ID_manufacturer }; context.Manufacturer.Add(man); context.Product.Add(p); } else { Product p = new Product { C_Name = name, ID_product = id + 1, C_Count = 0, ID_manufacturer = m[0].ID_manufacturer }; context.Product.Add(p); } context.SaveChanges(); DialogResult = DialogResult.OK; } catch (Exception) { MessageBox.Show("Заполните пустые поля"); } }
private void button1_Click(object sender, EventArgs e) { try { int count = Convert.ToInt32(textBox2.Text); string adr = textBox1.Text; if (count < 0) { MessageBox.Show("Введите корректное число в поле \"Count\""); return; } SkladDBEntities context = new SkladDBEntities(); List <Storage_place> p = context.Storage_place .Where(o => o.Adress == adr).ToList(); if (p.Count == 0) { int idStor = context.Storage_place.Count() != 0 ? context.Storage_place.Max(o => o.ID_storage_place) + 1 : 1; Storage_place s = new Storage_place { ID_storage_place = idStor, Adress = adr }; Product_Storage_place n = new Product_Storage_place { ID_storage_place = s.ID_storage_place, ID_product = currentProd, C_Count = count }; context.Storage_place.Add(s); context.Product_Storage_place.Add(n); } else { Product_Storage_place n = new Product_Storage_place { ID_storage_place = p[0].ID_storage_place, ID_product = currentProd, C_Count = count }; context.Product_Storage_place.Add(n); } context.SaveChanges(); DialogResult = DialogResult.OK; } catch (FormatException) { MessageBox.Show("Заполните поля"); } catch (Exception) { } }
private void button9_Click(object sender, EventArgs e) { int currentProd = (int)dataGridView3.CurrentRow.Cells[2].Value; int currentCust = (int)dataGridView2.CurrentRow.Cells[1].Value; SkladDBEntities context = new SkladDBEntities(); Product_customer p_c = context.Product_customer .Where(o => o.ID_customer == currentCust && o.ID_product == currentProd).First(); context.Product_customer.Remove(p_c); context.SaveChanges(); RefreshCustProducts(); }
private void button6_Click(object sender, EventArgs e) { string currentRow = dataGridView4.Rows[dataGridView4.CurrentRow.Index].Cells[0].Value.ToString(); SkladDBEntities context = new SkladDBEntities(); Storage_place stor = context.Storage_place .Where(o => o.Adress == currentRow).First(); Product_Storage_place p_s = context.Product_Storage_place .Where(o => o.ID_product == currentProduct && o.ID_storage_place == stor.ID_storage_place).First(); context.Product_Storage_place.Remove(p_s); context.SaveChanges(); RefreshProdInfo(); }
private void button3_Click(object sender, EventArgs e) { try { int nCount = Convert.ToInt32(textBox2.Text); string adr = textBox1.Text; if (nCount < 0) { MessageBox.Show("Введите корректное число в поле \"Count\""); return; } SkladDBEntities context = new SkladDBEntities(); Storage_place stor = context.Storage_place .Where(o => o.Adress == addr) .First(); Product_Storage_place p_s = context.Product_Storage_place .Where(o => o.ID_product == currentProd && o.ID_storage_place == stor.ID_storage_place).First(); //.Find(currentProd, stor.ID_storage_place); stor.Adress = adr; p_s.C_Count = nCount; context.Storage_place.Attach(stor); context.Entry(stor).Property(o => o.Adress).IsModified = true; context.Product_Storage_place.Attach(p_s); context.Entry(p_s).Property(o => o.C_Count).IsModified = true; context.SaveChanges(); DialogResult = DialogResult.OK; } catch (FormatException) { MessageBox.Show("Заполните поля"); } catch (Exception) { throw; } }
private void dataGridView1_Click(object sender, EventArgs e) { try { SkladDBEntities context = new SkladDBEntities(); int currentProd = (int)dataGridView1.CurrentRow.Cells[2].Value; Product_customer p_c = new Product_customer { ID_product = currentProd, ID_customer = currentCust, Order_date = DateTime.Now.Date.ToString() }; context.Product_customer.Add(p_c); context.SaveChanges(); MessageBox.Show("Товар добавлен"); } catch (Exception) { MessageBox.Show("Товар уже добавлен"); } }
private void button1_Click(object sender, EventArgs e) { try { SkladDBEntities context = new SkladDBEntities(); int ID = context.Customer.Max(o => o.ID_customer); string name = textBox1.Text; Customer c = new Customer { C_Name = name, ID_customer = ID + 1 }; context.Customer.Add(c); context.SaveChanges(); DialogResult = DialogResult.OK; } catch (Exception) { MessageBox.Show("Заполните поле \"Name\""); //throw; } }