Esempio n. 1
0
        private void btnApproveOrder_Click(object sender, EventArgs e)
        {
            if (comboBoxCustomer == null || comboBoxEmployee == null || comboBoxShipping == null)
            {
                MessageBox.Show("Missing Information");
                return;
            }

            NorthWindDataContext dc = new NorthWindDataContext();

            Order neworder = new Order();

            neworder.OrderDate  = DateTime.Now;
            neworder.CustomerID = comboBoxCustomer.SelectedValue.ToString();
            neworder.EmployeeID = (int)comboBoxEmployee.SelectedValue;
            neworder.ShipVia    = (int)comboBoxShipping.SelectedValue;

            dc.Orders.InsertOnSubmit(neworder);

            dc.SubmitChanges();

            foreach (ListViewItem item in listViewProducts.Items)
            {
                Order_Detail orderdetail = new Order_Detail();
                orderdetail.OrderID   = neworder.OrderID;
                orderdetail.ProductID = (int)item.Tag;
                orderdetail.UnitPrice = decimal.Parse(item.SubItems[1].Text);
                orderdetail.Quantity  = short.Parse(item.SubItems[2].Text);
                orderdetail.Discount  = float.Parse(item.SubItems[3].Text) / 100;
                dc.Order_Details.InsertOnSubmit(orderdetail);
                dc.SubmitChanges();
            }

            listViewProducts.Items.Clear();
            comboBoxCustomer.SelectedIndex = comboBoxEmployee.SelectedIndex = comboBoxShipping.SelectedIndex = -1;
        }
Esempio n. 2
0
    public void AddProduct(string name, string category, decimal price) //add product to specific category
    {
        var categories = from c in database.Categories                  //Get category
                         where c.CategoryName == category
                         select new { GetCat = c.CategoryID };
        int myCategory = 0;

        // SomeClass a = new SomeClass();
        //myCategory = a.GetCat;
        foreach (var i in categories)
        {
            myCategory = i.GetCat;
        }

        var productIDs = from p in database.Products//selects all Products ID's
                         select p.ProductID;

        int count = 0;

        foreach (var i in productIDs)
        {
            count++;
        }

        int newid = count + 1;

        Product newproduct = new Product();

        newproduct.ProductID   = newid;
        newproduct.ProductName = name;
        newproduct.UnitPrice   = price;
        newproduct.CategoryID  = myCategory;//assign category to new product

        database.Products.InsertOnSubmit(newproduct);
        database.SubmitChanges();
    }