private int AddSubCategory()
        {
            int ret = 0;

            Cursor.Current = Cursors.WaitCursor;
            ProductSubcategory psc        = new ProductSubcategory();
            string             subCatName = txtSubcategory.Text.Trim();

            try
            {
                int categoryID = 0;
                try
                {
                    categoryID = Int32.Parse(cmbCategories.SelectedValue.ToString());
                }
                catch
                {
                    categoryID = 0;
                }
                if (categoryID > 0)
                {
                    psc.Name = subCatName;
                    psc.ProductCategoryID = categoryID;
                    int pscid = psc.Exists(psc.Name, psc.ProductCategoryID);
                    if (pscid > 0)
                    {
                        DialogResult result = MessageBox.Show("Product Subcategory " + psc.Name + " already exists\nWould you like to update it?", "MICS", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (result == DialogResult.Yes)
                        {
                            psc.UpdateProductSubcategory(psc);
                            MessageBox.Show("Record updated successfully", "MICS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("Record is not saved", "MICS", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    else
                    {
                        psc.AddProductSubcategory(psc);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Product Subcategories", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Cursor.Current = Cursors.Default;
            }
            finally
            {
                psc = null;
            }
            Cursor.Current = Cursors.Default;
            return(ret);
        }
        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;
            }
        }