private void button2_Click(object sender, EventArgs e)//order { if (comboBox1.SelectedItem == null || comboBox2.SelectedItem == null || textBox1.Text == "") { MessageBox.Show("Błędne dane"); return; } var selectedCustomer = (string)comboBox1.SelectedItem; var selectedProduct = (string)comboBox2.SelectedItem; var quantity = Int32.Parse(textBox2.Text); var unitsInStock = from p in db.Products where p.Name == selectedProduct select p.UnitsInStock; if (unitsInStock.First() < quantity) { MessageBox.Show("Nie ma tylu towarów"); return; } var prodId = from p in db.Products where p.Name == selectedProduct select p.ProductId; int prodIdInt = prodId.First(); var newOrder = new Order { ProductId = prodId.First(), CompanyName = selectedCustomer, Quantity = quantity }; db.Orders.Add(newOrder); db.SaveChanges(); Hide(); DestroyHandle(); }
private void button1_Click(object sender, EventArgs e)//save customer { if (textBox1.Text == "" || textBox2.Text == "") { MessageBox.Show("Błędne dane"); return; } using (var db = new ProdContentBase()) { var customers = db.Customers.Select(c => c.CompanyName).ToArray(); foreach (var c in customers) { if (c == textBox1.Text) { MessageBox.Show("Istnieje już taki klient"); return; } } } var companyName = textBox1.Text; var description = textBox2.Text; using (var db = new ProdContentBase()) { var newCustomer = new Customer { CompanyName = companyName, Description = description }; db.Customers.Add(newCustomer); db.SaveChanges(); _customers.Items.Add(companyName); Hide(); DestroyHandle(); } }