Example #1
0
        private void SubmitButton_Click(object sender, EventArgs e)
        {
            var newProduct = new Product
            {
                Name         = NameTextBox.Text.ToString(),
                UnitsInStock = Convert.ToInt32(UnitsTextBox.Text.ToString()),
                CategoryID   = Convert.ToInt32(CategoryTextBox.Text.ToString()),
                UnitPrice    = Convert.ToDecimal(PriceTextBox.Text.ToString())
            };

            db.Products.Add(newProduct);
            db.SaveChanges();
            Close();
        }
Example #2
0
        private void OrderButton_Click(object sender, EventArgs e)
        {
            var CID      = Convert.ToInt32(CustomerIDTextBox.Text.ToString());
            var newOrder = new Order {
                CustomerID = CID
            };
            var details = new List <OrderDetails>();

            for (int i = 0; i < SelectedDgv.Rows.Count; i++)
            {
                details.Add(new OrderDetails {
                    OrderID  = newOrder.OrderID, ProductID = Convert.ToInt32(SelectedDgv.Rows[i].Cells[0].Value.ToString()),
                    Quantity = Convert.ToInt32(SelectedDgv.Rows[i].Cells[2].Value.ToString())
                });
            }
            newOrder.Details = details;
            db.Orders.Add(newOrder);
            db.SaveChanges();
            Close();
        }