private void detach_tblOrder_Items(tblOrder_Item entity)
		{
			this.SendPropertyChanging();
			entity.tblDevice_Type = null;
		}
 partial void UpdatetblOrder_Item(tblOrder_Item instance);
 partial void DeletetblOrder_Item(tblOrder_Item instance);
 partial void InserttblOrder_Item(tblOrder_Item instance);
		private void detach_tblOrder_Items(tblOrder_Item entity)
		{
			this.SendPropertyChanging();
			entity.tblProductBrand = null;
		}
		private void attach_tblOrder_Items(tblOrder_Item entity)
		{
			this.SendPropertyChanging();
			entity.tblOrder = this;
		}
        private void btnRemove_Click(object sender, EventArgs e)
        {
            if (dgvItems.Rows.Count > 0)
            {
                tblOrder_Item tmp_item = new tblOrder_Item();
                int tmp_prod_id;

                tmp_item = productID_OrderItemsDict.ElementAt(dgvItems.CurrentRow.Index).Value;
                tmp_prod_id = productID_OrderItemsDict.ElementAt(dgvItems.CurrentRow.Index).Key;

                productID_QuantityDict[tmp_prod_id] += tmp_item.Quantity;
                productID_OrderItemsDict.Remove(tmp_prod_id);
                itemsDGVIndexesList.Remove(tmp_prod_id);

                //remove selected dgv row
                dgvItems.Rows.RemoveAt(dgvItems.CurrentRow.Index);
            }
            else //row count <= 0
            {
                MessageBox.Show("No items to remove!!!",
                       "Remove Items Error", MessageBoxButtons.OK, MessageBoxIcon.Warning,
                       MessageBoxDefaultButton.Button1);
            }
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            bool isAdded = false;
            int tmpProdID = 0;
            int outValue; //trygetvalue output value (qty in stock)

            if (cmbBxBrand.SelectedIndex == 0 || cmbBxProducts.SelectedIndex == 0)
            {
                MessageBox.Show("Select brand and model!!!",
                   "Add Items Error", MessageBoxButtons.OK, MessageBoxIcon.Warning,
                   MessageBoxDefaultButton.Button1);
            }
            else //brand, model, and quantity is selected
            {
                //query selected brand
                var brand = from table in badc.tblProductBrands
                            where table.Brand_ID == brandsIndexesList[cmbBxBrand.SelectedIndex]
                            select table;

                //query selected product
                var product = from table in badc.tblProductItems
                            where table.Product_ID == productsIndexesList[cmbBxProducts.SelectedIndex]
                            select table;

                //retrieve quantity value for selected product
                productID_QuantityDict.TryGetValue(product.FirstOrDefault().Product_ID, out outValue);
                
                //check if quantity of product desired is valid
                if (Convert.ToInt32(numUpDownQuantity.Value) > outValue)
                {
                    MessageBox.Show("Insufficient quantity!!!",
                       "Add Items Error", MessageBoxButtons.OK, MessageBoxIcon.Warning,
                       MessageBoxDefaultButton.Button1);
                }
                else //quantity desired is valid
                {
                    //check if item has already been added
                    foreach (int num in productID_OrderItemsDict.Keys)
                    {
                        if (num == product.FirstOrDefault().Product_ID)
                        { 
                            isAdded = true;
                            tmpProdID = num;
                            break;
                        }
                    }

                    if (isAdded)
                    {
                        MessageBox.Show("Item already added! Quantity will be adjusted!",
                        "Add Items Info", MessageBoxButtons.OK, MessageBoxIcon.Information,
                        MessageBoxDefaultButton.Button1);

                        //add qty to item qty/adjust quantity list
                        productID_OrderItemsDict[tmpProdID].Quantity += Convert.ToInt32(numUpDownQuantity.Value);
                        productID_QuantityDict[product.FirstOrDefault().Product_ID] -= Convert.ToInt32(numUpDownQuantity.Value);

                        //update quantity on single row in dgv
                        dgvItems.Rows[itemsDGVIndexesList.IndexOf(tmpProdID)].Cells[QUANTITY_CELL_NUM].Value = 
                            productID_OrderItemsDict[tmpProdID].Quantity;
                    }
                    else //item hasn't been added
                    {
                        //create new db order item
                        tblOrder_Item item = new tblOrder_Item();

                        //set corresponding data fields into new order item
                        item.Model = product.FirstOrDefault().Model;
                        item.Serial_Number = product.FirstOrDefault().Serial_Number;
                        item.Price = product.FirstOrDefault().Price;
                        item.Quantity = Convert.ToInt32(numUpDownQuantity.Value);
                        item.Comments = product.FirstOrDefault().Comments;
                        item.Type_ID = product.FirstOrDefault().Type_ID;
                        item.Brand_ID = product.FirstOrDefault().Brand_ID;

                        //add product id and order item into dictionary
                        productID_OrderItemsDict.Add(product.FirstOrDefault().Product_ID, item);

                        //adjust running quantity in prod id/quantity dictionary
                        productID_QuantityDict[product.FirstOrDefault().Product_ID] -= item.Quantity;

                        //add product id to list for dgv indexes
                        itemsDGVIndexesList.Add(product.FirstOrDefault().Product_ID);

                        //build string to add item to data grid view
                        String[] row = new String[] 
                        { 
                            brand.FirstOrDefault().Brand_Name, product.FirstOrDefault().Model, 
                            product.FirstOrDefault().Price.ToString("C") + " (ea.)", 
                            Convert.ToInt32(numUpDownQuantity.Value).ToString()
                        };

                        //add item to data grid view
                        dgvItems.Rows.Add(row);
                    }
                }
            }
        }