private void button1_Click(object sender, EventArgs e) { var vCompanyName = textBox1.Text; var vDescription = textBox2.Text; using (var prodDB = new ProdContent()) { var isCompanyNameExists = from c in prodDB.Customers where c.CompanyName == vCompanyName select c.CompanyName; if (isCompanyNameExists.Contains(vCompanyName)) { MessageBox.Show("Company with this name exists"); return; } var newCustomer = new Customer(); newCustomer.CompanyName = vCompanyName; newCustomer.Description = vDescription; prodDB.Customers.Add(newCustomer); prodDB.SaveChanges(); } Hide(); DestroyHandle(); }
private void button1_Click(object sender, EventArgs e) { var selectedCustomer = (string)comboBox1.SelectedItem; var selectedProduct = (string)comboBox2.SelectedItem; int selectedQuantity = Int32.Parse(textBox1.Text); using (var prodDB = new ProdContent()) { var availableQuantity = from p in prodDB.Product where p.Name == selectedProduct select p.UnitsInStock; if (selectedQuantity > availableQuantity.First()) { MessageBox.Show("Do not have enough product available"); return; } var selectedProductID = from p in prodDB.Product where p.Name == selectedProduct select p.ProductID; var vOrder = new Order(); vOrder.CompanyName = selectedCustomer; vOrder.ProductID = selectedProductID.First(); vOrder.Quantity = selectedQuantity; prodDB.Orders.Add(vOrder); prodDB.SaveChanges(); } Hide(); DestroyHandle(); }
private void button1_Click(object sender, EventArgs e) { var vCategoryName = textBox1.Text; var vDescription = textBox2.Text; using (var prodDB = new ProdContent()) { var isCategoryExists = prodDB.Category .Where(cat => cat.Name == vCategoryName) .Select(c => c.Name); if (isCategoryExists.Contains(vCategoryName)) { MessageBox.Show("Category with this name already exists"); return; } var newCategory = new Category(); newCategory.Name = vCategoryName; newCategory.Description = vDescription; prodDB.Category.Add(newCategory); prodDB.SaveChanges(); } Hide(); DestroyHandle(); }
private void button1_Click(object sender, EventArgs e) { var vProductName = textBox1.Text; var vUnitsInStock = Int32.Parse(textBox2.Text); var vCategory = (String)comboBox2.SelectedItem; var vUnitPrice = textBox3.Text; using (var prodDB = new ProdContent()) { var catId = (from c in prodDB.Category where c.Name == vCategory select c.CategoryId).FirstOrDefault(); if (catId == 0) { MessageBox.Show("You have to choose category!"); return; } var isProductExists = from p in prodDB.Product where p.Name == vProductName select p.Name; if (isProductExists.Contains(vProductName)) { MessageBox.Show("Product with this name already exists"); return; } var newProduct = new Product(); newProduct.Name = vProductName; newProduct.UnitsInStock = vUnitsInStock; newProduct.CategoryId = catId; newProduct.Unitprice = Decimal.Parse(vUnitPrice); prodDB.Product.Add(newProduct); prodDB.SaveChanges(); } Hide(); DestroyHandle(); }