Esempio n. 1
0
        private void SaveProducts()
        {
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                int catid    = 0;
                int subcatid = 0;
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    ProductCategory              cat    = new ProductCategory();
                    ProductCategoryCollection    catCol = new ProductCategoryCollection();
                    ProductSubcategory           sub    = new ProductSubcategory();
                    ProductSubcategoryCollection subCol = new ProductSubcategoryCollection();
                    Product prod = new Product();
                    string where = String.Empty;
                    string orderBy = String.Empty;

                    cat.Name         = dataGridView1.Rows[i].Cells["category"].Value.ToString();
                    cat.ModifiedDate = DateTime.Now;
                    if (cat.Name == "Candy")
                    {
                        MessageBox.Show("here");
                    }
                    if (!cat.Exsists(cat.Name))
                    {
                        catid = cat.AddProductCategory(cat);
                    }
                    else
                    {
                        where  = "[Name]='" + cat.Name + "'";
                        catCol = cat.GetProductCategoryCollection(where, orderBy);
                        if (catCol.Count > 0)
                        {
                            catid = catCol[0].ProductCategoryID;
                        }
                        else
                        {
                            MessageBox.Show("error");
                            log.Write(cat.Name, "Loading Products");
                        }
                    }

                    sub.ProductCategoryID = catid;
                    sub.Name         = dataGridView1.Rows[i].Cells["subcategory"].Value.ToString();
                    sub.ModifiedDate = DateTime.Now;
                    if (sub.Name == "Pacifire")
                    {
                        MessageBox.Show("Stealers");
                    }
                    if (sub.Exsists(sub.Name))
                    {
                        where  = "[Name]='" + sub.Name + "'";
                        subCol = sub.GetProductSubcategoryCollection(where, orderBy);
                        if (subCol.Count > 0)
                        {
                            subcatid = subCol[0].ProductSubcategoryID;
                        }
                    }
                    else
                    {
                        subcatid = sub.AddProductSubcategory(sub);
                    }

                    prod.ProductSubcategoryID = subcatid;
                    prod.Name              = dataGridView1.Rows[i].Cells["productname"].Value.ToString();
                    prod.Class             = String.Empty;
                    prod.Color             = String.Empty;
                    prod.DaysToManufacture = 0;
                    prod.Description       = dataGridView1.Rows[i].Cells["productname"].Value.ToString();
                    prod.DiscontinuedDate  = DateTime.Parse("01/01/1900");
                    prod.FinishedGoodsFlag = true;
                    prod.ListPrice         = dataGridView1.Rows[i].Cells["price"].Value.ToString() == String.Empty?0.00m:Decimal.Parse(dataGridView1.Rows[i].Cells["price"].Value.ToString());
                    prod.MakeFlag          = true;
                    prod.ModifiedDate      = DateTime.Now;
                    prod.ProductLine       = String.Empty;
                    prod.ProductModelID    = 0;
                    prod.ProductNumber     = String.Empty;
                    prod.ReorderPoint      = 0;// Int16.Parse(dataGridView1.Rows[i].Cells["Reorder Point"].Value.ToString());
                    prod.SafetyStockLevel  = 0;

                    prod.SellEndDate           = DateTime.Now;
                    prod.SellStartDate         = DateTime.Now;
                    prod.Size                  = String.Empty;
                    prod.SizeUnitMeasureCode   = String.Empty;
                    prod.StandardCost          = Decimal.Parse(dataGridView1.Rows[i].Cells["cost"].Value.ToString());
                    prod.Style                 = String.Empty;
                    prod.Weight                = 0.00m;
                    prod.WeightUnitMeasureCode = String.Empty;
                    prod.AddProduct(prod);
                    cat  = null;
                    sub  = null;
                    prod = null;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Cursor.Current = Cursors.Default;
            }
            finally
            {
                MessageBox.Show("Done");
                Cursor.Current = Cursors.Default;
            }
        }