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 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 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("Товар уже добавлен"); } }