Ejemplo n.º 1
0
        private void ModifyProductForm_Load(object sender, EventArgs e)
        {
            allParts = new BindingList <partsdb>(dbHelper.GetAllParts());
            if (isNew)
            {
                SetLabels();
                loadDgvModifyProduct();
                return;
            }

            initialProduct          = dbHelper.GetProduct(productIndex);
            initialListProductParts = dbHelper.GetAllAssocParts(productIndex);
            initialListParts        = dbHelper.GetDerivedParts(productIndex);

            addedParts = new BindingList <partsdb>(dbHelper.GetDerivedParts(productIndex));
            loadDgvModifyProduct();

            productsdb modify = dbHelper.GetProduct(productIndex);

            tbModifyProductID.Text        = Convert.ToString(modify.productid);
            tbModifyProductName.Text      = modify.name;
            tbModifyProductPrice.Text     = modify.price.ToString("#,0.00");
            tbModifyProductInventory.Text = Convert.ToString(modify.instock);
            tbModifyProductMin.Text       = Convert.ToString(modify.min);
            tbModifyProductMax.Text       = Convert.ToString(modify.max);
        }
Ejemplo n.º 2
0
 public static void RemoveProduct(int index)
 {
     using (var con = new InventoryMgmtEntities())
     {
         productsdb productTemp = con.productsdbs.Find(index);
         con.productsdbs.Remove(productTemp);
         con.SaveChanges();
     }
 }
Ejemplo n.º 3
0
        //Products

        public static int AddProduct(productsdb product)
        {
            using (var con = new InventoryMgmtEntities())
            {
                con.productsdbs.Add(product);
                con.SaveChanges();
                return(product.productid);
            }
        }
Ejemplo n.º 4
0
        private void btModifyProductSave_Click(object sender, EventArgs e)
        {
            if (!isNew)
            {
                if (isDifferent() == false)
                {
                    return;
                }
            }

            if (addedParts.Count() == 0)
            {
                MessageBox.Show("You must add a part to the product.");
                return;
            }
            if (l_Modify_ProductName.Visible == true || l_Modify_Price.Visible == true || l_Modify_ProductInventory.Visible == true || l_Modify_Max.Visible == true || l_Modify_Min.Visible == true)
            {
                MessageBox.Show("You must fix the red boxes before you can save."); return;
            }
            if (Int32.Parse(tbModifyProductMax.Text) <= Int32.Parse(tbModifyProductMin.Text))
            {
                MessageBox.Show("Max must be greater than Min."); return;
            }
            if ((Int32.Parse(tbModifyProductInventory.Text) <= Int32.Parse(tbModifyProductMin.Text)) || (Int32.Parse(tbModifyProductInventory.Text) >= Int32.Parse(tbModifyProductMax.Text)))
            {
                MessageBox.Show("Inventory must be greater than min and less than max."); return;
            }

            productsdb tempProduct = new productsdb();

            tempProduct.name      = tbModifyProductName.Text; tempProduct.min = Int32.Parse(tbModifyProductMin.Text);
            tempProduct.max       = Int32.Parse(tbModifyProductMax.Text); tempProduct.instock = Int32.Parse(tbModifyProductInventory.Text); tempProduct.price = Decimal.Parse(tbModifyProductPrice.Text);
            tempProduct.createdby = dbHelper.currentUser.userid;

            if (isNew)
            {
                tempProduct.lastmodified = DateTime.Now;
                int productIndex = dbHelper.AddProduct(tempProduct);
                for (int i = 0; i < addedParts.Count; i++)
                {
                    dbHelper.AddAssocPart(productIndex, addedParts[i].partid);
                }
            }
            else
            {
                tempProduct.productid = Int32.Parse(tbModifyProductID.Text);
                dbHelper.ModifyProductImproved(tempProduct, addedParts.ToList <partsdb>(), initialListProductParts);
            }
            closeChildForm();
        }
        private static int testProduct()
        {
            DateTime   dateTimenow = DateTime.Now;
            int        testsPassed = 0;
            productsdb productTemp = new productsdb();

            productTemp.name = "productTest"; productTemp.min = 1; productTemp.max = 40; productTemp.instock = 11; productTemp.price = 19.23M; productTemp.lastmodified = dateTimenow;
            cl("");
            cl("---Running product creation test.");

            int idIndex = dbHelper.AddProduct(productTemp);

            if (dbHelper.ProductExists(idIndex))
            {
                cl("Product creation test PASSED");
                testsPassed++;
                cl("---Running product retrieval test.");
                productsdb testproduct = dbHelper.GetProduct(idIndex);
                if ((testproduct.productid == idIndex) && (testproduct.instock == productTemp.instock))
                {
                    testsPassed++;
                    cl("Product retrieval test PASSED.");
                    cl("---Running product deletion test.");
                    dbHelper.RemoveProduct(idIndex);
                    if (!dbHelper.ProductExists(idIndex))
                    {
                        testsPassed++;
                        cl("Product deletion test has PASSED.");
                    }
                    else
                    {
                        cl("Product deletion test has FAILED.");
                    }
                }
                else
                {
                    cl("Product retrieval test FAILED.");
                }
            }
            else
            {
                cl("Product creation test FAILED.");
            }
            return(testsPassed);
        }
Ejemplo n.º 6
0
        public static bool ModifyProductImproved(productsdb product, List <partsdb> partsList, List <productspart> originalParts)
        {
            using (var con = new InventoryMgmtEntities())
            {
                //Update Part Details
                productsdb productTemp = con.productsdbs.Find(product.productid);;
                productTemp.name  = product.name; productTemp.min = product.min; productTemp.max = product.max; productTemp.instock = product.instock;
                productTemp.price = product.price; productTemp.lastmodified = DateTime.Now;

                //Split list into associated parts that already exist and new parts
                List <partDerived> partDerivedList = new List <partDerived>();
                List <partsdb>     realParts       = new List <partsdb>();
                for (int i = 0; i < partsList.Count(); i++)
                {
                    if (partsList[i].GetType() == typeof(partDerived))
                    {
                        partDerived tempPart = (partDerived)(object)partsList[i];
                        partDerivedList.Add(tempPart);
                    }
                    else
                    {
                        realParts.Add(partsList[i]);
                    }
                }

                //Take original list and derived part list, where there is a match remove part from partListfinal
                List <productspart> partListFinal = originalParts;

                for (int i = 0; i < originalParts.Count(); i++)
                {
                    for (int j = 0; j < partDerivedList.Count(); j++)
                    {
                        if (originalParts[i].productpartid == partDerivedList[j].zproductpartid)
                        {
                            partListFinal.RemoveAll(u => u.productpartid == (int)partDerivedList[j].zproductpartid);
                        }
                    }
                    var temp = partListFinal;
                }

                //Remove all productparts from the db that are in the list partListFinal
                if (partListFinal.Count() > 0)
                {
                    for (int k = 0; k < partListFinal.Count(); k++)
                    {
                        productspart tempProductPart = con.productsparts.Find(partListFinal[k].productpartid);
                        con.productsparts.Remove(tempProductPart);
                    }
                }

                //Add new associated parts
                for (int l = 0; l < realParts.Count(); l++)
                {
                    productspart temp = new productspart();
                    temp.productid = product.productid;
                    temp.partid    = realParts[l].partid;
                    con.productsparts.Add(temp);
                }
                con.SaveChanges();
                return(true);
            }
        }