private void LoadProductCategories()
        {
            ProductCategory           cat       = new ProductCategory();
            ProductCategoryCollection col       = new ProductCategoryCollection();
            ProductCategory           selectNew = new ProductCategory();

            selectNew.ProductCategoryID = 0;
            selectNew.Name = "[Select Category]";
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                col = cat.GetAllProductCategoryCollection();
                col.Insert(0, selectNew);
                cmbCategory.DataSource    = col;
                cmbCategory.DisplayMember = "Name";
                cmbCategory.ValueMember   = "ProductCategoryID";

                int catID = Int32.Parse(cmbCategory.SelectedValue.ToString());
                LoadProductSubCategories(catID);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Cursor.Current = Cursors.Default;
            }
            finally
            {
                cat = null;
            }
            Cursor.Current = Cursors.Default;
        }
        private void PopulateProductCategories()
        {
            ProductCategory           cat    = new ProductCategory();
            ProductCategoryCollection catCol = new ProductCategoryCollection();

            m_Loading = true;
            try
            {
                catCol = cat.GetAllProductCategoryCollection();

                ProductCategory AllCat = new ProductCategory();
                cat.ProductCategoryID = 0;
                cat.Name         = "All";
                cat.ModifiedDate = DateTime.Now;
                catCol.Insert(0, cat);

                ddlCategory.DataSource    = catCol;
                ddlCategory.DisplayMember = "Name";
                ddlCategory.ValueMember   = "ProductCategoryID";
                // m_Loading = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Category category = CategoryManager.GetCategoryById(this.CategoryId);

            if (category != null)
            {
                ProductCategoryCollection existingProductCategories = category.ProductCategories;

                foreach (GridViewRow row in gvProducts.Rows)
                {
                    try
                    {
                        CheckBox       cbProductInfo      = row.FindControl("cbProductInfo") as CheckBox;
                        HiddenField    hfProductId        = row.FindControl("hfProductId") as HiddenField;
                        NumericTextBox txtRowDisplayOrder = row.FindControl("txtDisplayOrder") as NumericTextBox;
                        int            productId          = int.Parse(hfProductId.Value);
                        int            displayOrder       = txtRowDisplayOrder.Value;
                        if (cbProductInfo.Checked)
                        {
                            if (existingProductCategories.FindProductCategory(productId, this.CategoryId) == null)
                            {
                                CategoryManager.InsertProductCategory(productId, this.CategoryId, false, displayOrder);
                            }
                        }
                    }
                    catch (Exception exc)
                    {
                        ProcessException(exc);
                    }
                }
            }

            this.Page.ClientScript.RegisterStartupScript(typeof(CategoryProductAddControl), "closerefresh", "<script language=javascript>try {window.opener.document.forms[0]." + this.BtnId + ".click();}catch (e){} window.close();</script>");
        }
        public ProductCategoryCollection GetAllProductCategorysCollection()
        {
            IDBManager dbm = new DBManager();
            ProductCategoryCollection cols = new ProductCategoryCollection();

            try
            {
                IDataReader reader = dbm.ExecuteReader(CommandType.StoredProcedure, "SelectProductCategoriesAll");
                while (reader.Read())
                {
                    ProductCategory productCategory = new ProductCategory();
                    productCategory.ProductCategoryID = Int32.Parse(reader["ProductCategoryID"].ToString());
                    productCategory.Name         = reader["Name"].ToString();
                    productCategory.ModifiedDate = DateTime.Parse(reader["ModifiedDate"].ToString());
                    cols.Add(productCategory);
                }
            }

            catch (Exception ex)
            {
                log.Write(ex.Message, "GetAllProductCategorysCollection");
                throw (ex);
            }
            finally
            {
                dbm.Dispose();
            }
            return(cols);
        }
Beispiel #5
0
        private void PopulateCategories(int selectedId)
        {
            ProductCategory pc = new ProductCategory();

            ProductCategory selectNew = new ProductCategory();

            try
            {
                selectNew.Name = "[Select One]";
                selectNew.ProductCategoryID = 0;
                CategoryCol             = pc.GetAllProductCategoryCollection();
                CategoryGrid.DataSource = CategoryCol;
                CategoryGrid.Columns.Remove("ModifiedDate");
                CategoryGrid.Columns["ProductCategoryID"].Visible = false;
                if (selectedId > 0)
                {
                    for (int i = 0; i < CategoryCol.Count; i++)
                    {
                        if (CategoryCol[i].ProductCategoryID == selectedId)
                        {
                            CategoryGrid.Rows[i].Selected = true;
                            CategoryGrid.FirstDisplayedScrollingRowIndex = i;
                            GridRowChanged(i);
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Product Categories", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #6
0
        private void PopulateProductCategories()
        {
            Cursor.Current = Cursors.WaitCursor;
            ProductCategory           selectNew = new ProductCategory();
            ProductCategoryCollection col       = new ProductCategoryCollection();
            ProductCategory           pc        = new ProductCategory();

            try
            {
                selectNew.Name = "[Select One]";
                selectNew.ProductCategoryID = 0;
                col = pc.GetAllProductCategoryCollection();
                col.Insert(0, selectNew);
                cmbProductCategories.DataSource    = col;
                cmbProductCategories.DisplayMember = "Name";
                cmbProductCategories.ValueMember   = "ProductCategoryID";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Product Subcategories", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Cursor.Current = Cursors.Default;
            }

            Cursor.Current = Cursors.Default;
        }
        public ProductCategoryCollection GetProductCategorysDynamicCollection(string whereExpression, string orderBy)
        {
            IDBManager dbm = new DBManager();
            ProductCategoryCollection cols = new ProductCategoryCollection();

            try
            {
                dbm.CreateParameters(2);
                dbm.AddParameters(0, "@WhereCondition", whereExpression);
                dbm.AddParameters(1, "@OrderByExpression", orderBy);
                IDataReader reader = dbm.ExecuteReader(CommandType.StoredProcedure, "SelectProductCategoriesDynamic");
                while (reader.Read())
                {
                    ProductCategory productCategory = new ProductCategory();
                    productCategory.ProductCategoryID = Int32.Parse(reader["ProductCategoryID"].ToString());
                    productCategory.Name         = reader["Name"].ToString();
                    productCategory.ModifiedDate = DateTime.Parse(reader["ModifiedDate"].ToString());
                    cols.Add(productCategory);
                }
            }

            catch (Exception ex)
            {
                log.Write(ex.Message, "GetAllProductCategorysDynamicCollection");
                throw (ex);
            }
            finally
            {
                dbm.Dispose();
            }
            return(cols);
        }
        protected void CreateMenu()
        {
            CategoryCollection breadCrumb;
            Category           currentCategory = CategoryManager.GetCategoryByID(CommonHelper.QueryStringInt("CategoryID"));

            if (currentCategory == null)
            {
                Product product = ProductManager.GetProductByID(CommonHelper.QueryStringInt("ProductID"));
                if (product != null)
                {
                    ProductCategoryCollection productCategories = product.ProductCategories;
                    if (productCategories.Count > 0)
                    {
                        currentCategory = productCategories[0].Category;
                    }
                }
            }

            if (currentCategory != null)
            {
                breadCrumb = CategoryManager.GetBreadCrumb(currentCategory.CategoryID);
            }
            else
            {
                breadCrumb = new CategoryCollection();
            }

            CreateChildMenu(breadCrumb, 0, currentCategory, 0);
        }
Beispiel #9
0
        public void ExportCategories()
        {
            SqlCompactConnection conn = new SqlCompactConnection();

            try
            {
                StripStatus.Text = "Products Sub Categories..";
                ProductSubcategory sub = new ProductSubcategory();
                ProductCategory    cat = new ProductCategory();
                conn.DropProdctSubCategoryTable();
                conn.CreateProdctSubCategoryTable();
                ProductSubcategoryCollection subCol = sub.GetAllProductSubcategoryCollection();
                conn.SynchForm = this;
                conn.AddProductSubCategory(subCol);

                StripStatus.Text = "Products Categories..";
                conn.DropProdctCategoryTable();
                conn.CreateProdctCategoryTable();
                ProductCategoryCollection catCol = cat.GetAllProductCategoryCollection();
                conn.AddProductCategory(catCol);
                sub    = null;
                cat    = null;
                subCol = null;
                catCol = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.CloseDatabase();
                conn = null;
            }
        }
Beispiel #10
0
        private void BindData()
        {
            Product product = ProductManager.GetProductByID(this.ProductID);

            if (product != null)
            {
                ProductCategoryCollection existingProductCategoryCollection      = product.ProductCategories;
                List <ProductCategoryMappingHelperClass> productCategoryMappings = GetProductCategoryMappings(0, string.Empty, existingProductCategoryCollection);
                gvCategoryMappings.DataSource = productCategoryMappings;
                gvCategoryMappings.DataBind();
            }
        }
        private void BindData()
        {
            Category category = CategoryManager.GetCategoryByID(this.CategoryID);

            if (category != null)
            {
                ProductCategoryCollection existingProductCategoryCollection      = category.ProductCategories;
                List <ProductCategoryMappingHelperClass> productCategoryMappings = GetProductCategoryMappings(existingProductCategoryCollection);
                gvProductCategoryMappings.DataSource = productCategoryMappings;
                gvProductCategoryMappings.DataBind();
            }
        }
        private void BindData()
        {
            Category category = CategoryManager.GetCategoryById(this.CategoryId);

            if (category != null)
            {
                ProductCategoryCollection existingProductCategoryCollection      = category.ProductCategories;
                List <ProductCategoryMappingHelperClass> productCategoryMappings = GetProductCategoryMappings(existingProductCategoryCollection);
                gvProductCategoryMappings.Columns[1].Visible = SettingManager.GetSettingValueBoolean("Display.ShowAdminProductImages");
                gvProductCategoryMappings.DataSource         = productCategoryMappings;
                gvProductCategoryMappings.DataBind();
            }
        }
        protected void BindData()
        {
            Product product = ProductManager.GetProductByID(ProductID);

            if (product != null)
            {
                //hlProduct.NavigateUrl = SEOHelper.GetProductURL(product);

                ProductCategoryCollection productCategories = product.ProductCategories;
                if (productCategories.Count > 0)
                {
                    rptrCategoryBreadcrumb.DataSource = CategoryManager.GetBreadCrumb(productCategories[0].CategoryID);
                }
                rptrCategoryBreadcrumb.DataBind();

                hlProduct.Text = Server.HtmlEncode(product.Name);
            }
            else
            {
                Visible = false;
            }
        }
        private List <ProductCategoryMappingHelperClass> GetProductCategoryMappings(ProductCategoryCollection ExistingProductCategoryCollection)
        {
            List <ProductCategoryMappingHelperClass> result = new List <ProductCategoryMappingHelperClass>();

            foreach (ProductCategory pc in ExistingProductCategoryCollection)
            {
                Product product = pc.Product;
                if (product != null)
                {
                    ProductCategoryMappingHelperClass pcmhc = new ProductCategoryMappingHelperClass();
                    pcmhc.ProductCategoryID = pc.ProductCategoryID;
                    pcmhc.ProductID         = pc.ProductID;
                    pcmhc.ProductInfo       = product.Name;
                    pcmhc.IsMapped          = true;
                    pcmhc.IsFeatured        = pc.IsFeaturedProduct;
                    pcmhc.DisplayOrder      = pc.DisplayOrder;
                    result.Add(pcmhc);
                }
            }

            return(result);
        }
        static void Main(string[] args)
        {
            ProductCategoryCollection collection = null;

            try
            {
                IOC.ConfigureContainer();

                collection = ProductCategoryCollection.NewProductCategoryCollection();
                var childCat = collection.AddNew();
                childCat.Name = "Electronics";

                var childSub = childCat.SubcategoryCollection.AddNew();

                childSub.Name = "TVs";

                collection.Save();

                Console.WriteLine(childCat.ModifiedDate);
            }
            catch (DataPortalException ex)
            {
                Console.WriteLine(ex.BusinessException.ToString());
            }
            catch (Csla.Rules.ValidationException ex)
            {
                Console.WriteLine(ex.ToString());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            Console.WriteLine("DONE");
            Console.ReadKey();
        }
Beispiel #16
0
        private List <ProductCategoryMappingHelperClass> GetProductCategoryMappings(int ForParentCategoryID,
                                                                                    string prefix, ProductCategoryCollection ExistingProductCategoryCollection)
        {
            CategoryCollection categoryCollection           = CategoryManager.GetAllCategories(ForParentCategoryID);
            List <ProductCategoryMappingHelperClass> result = new List <ProductCategoryMappingHelperClass>();

            for (int i = 0; i < categoryCollection.Count; i++)
            {
                Category        category = categoryCollection[i];
                ProductCategory existingProductCategory = ExistingProductCategoryCollection.FindProductCategory(this.ProductID, category.CategoryID);
                ProductCategoryMappingHelperClass pcm   = new ProductCategoryMappingHelperClass();
                if (existingProductCategory != null)
                {
                    pcm.ProductCategoryID = existingProductCategory.ProductCategoryID;
                    pcm.IsMapped          = true;
                    pcm.IsFeatured        = existingProductCategory.IsFeaturedProduct;
                    pcm.DisplayOrder      = existingProductCategory.DisplayOrder;
                }
                else
                {
                    pcm.DisplayOrder = 1;
                }
                pcm.CategoryID   = category.CategoryID;
                pcm.CategoryInfo = prefix + category.Name;
                //if (pcm.CategoryID == this.CategoryID)
                //    pcm.IsMapped = true;
                result.Add(pcm);
                if (CategoryManager.GetAllCategories(category.CategoryID).Count > 0)
                {
                    result.AddRange(GetProductCategoryMappings(category.CategoryID, prefix + "--", ExistingProductCategoryCollection));
                }
            }

            return(result);
        }
Beispiel #17
0
        /// <summary>
        /// Replaces a message template tokens
        /// </summary>
        /// <param name="productVariant">Product variant instance</param>
        /// <param name="Template">Template</param>
        /// <param name="LocalFormat">Localization Provider Short name (en-US, de-DE, etc.)</param>
        /// <param name="AdditionalKeys">Additional keys</param>
        /// <param name="AffiliateID">Affiliate identifier</param>
        /// <param name="Price">Price</param>
        /// <returns>New template</returns>
        protected string replaceMessageTemplateTokens(ProductVariant productVariant, string Template, string LocalFormat, NameValueCollection AdditionalKeys,
                                                      int AffiliateID, decimal Price)
        {
            NameValueCollection tokens = new NameValueCollection();

            IFormatProvider locProvider = new System.Globalization.CultureInfo(LocalFormat);

            string strHelper = Template;

            while (strHelper.Contains("%"))
            {
                strHelper = strHelper.Substring(strHelper.IndexOf("%") + 1);
                string strToken  = strHelper.Substring(0, strHelper.IndexOf("%"));
                string strFormat = "";
                strHelper = strHelper.Substring(strHelper.IndexOf("%") + 1);

                if (strToken.Contains(":"))
                {
                    strFormat = strToken.Substring(strToken.IndexOf(":"));
                    strToken  = strToken.Substring(0, strToken.IndexOf(":"));
                }

                if (tokens.Get(strToken + strFormat) == null)
                {
                    switch (strToken.ToLower())
                    {
                    case "store.name":
                    {
                        tokens.Add(strToken + strFormat, String.Format(locProvider, "{0" + strFormat + "}", SettingManager.StoreName));
                    }
                    break;

                    case "product.pictureurl":
                    {
                        ProductPictureCollection pictures = productVariant.Product.ProductPictures;
                        if (pictures.Count > 0)
                        {
                            tokens.Add(strToken + strFormat, String.Format(locProvider, "{0" + strFormat + "}", PictureManager.GetPictureUrl(pictures[0].PictureID)));
                        }
                        else
                        {
                            tokens.Add(strToken + strFormat, String.Format(locProvider, "{0" + strFormat + "}", string.Empty));
                        }
                    }
                    break;

                    case "pv.producturl":
                    {
                        tokens.Add(strToken + strFormat, String.Format(locProvider, "{0" + strFormat + "}", getProductUrlWithPricelistProvider(productVariant.ProductID, AffiliateID)));
                    }
                    break;

                    case "pv.price":
                    {
                        tokens.Add(strToken + strFormat, String.Format(locProvider, "{0" + strFormat + "}", Price));
                    }
                    break;

                    case "pv.name":
                    {
                        tokens.Add(strToken + strFormat, String.Format(locProvider, "{0" + strFormat + "}", productVariant.FullProductName));
                    }
                    break;

                    case "pv.description":
                    {
                        tokens.Add(strToken + strFormat, String.Format(locProvider, "{0" + strFormat + "}", productVariant.Description));
                    }
                    break;

                    case "product.description":
                    {
                        tokens.Add(strToken + strFormat, String.Format(locProvider, "{0" + strFormat + "}", productVariant.Product.FullDescription));
                    }
                    break;

                    case "product.shortdescription":
                    {
                        tokens.Add(strToken + strFormat, String.Format(locProvider, "{0" + strFormat + "}", productVariant.Product.ShortDescription));
                    }
                    break;

                    case "pv.partnumber":
                    {
                        tokens.Add(strToken + strFormat, String.Format(locProvider, "{0" + strFormat + "}", productVariant.ManufacturerPartNumber));
                    }
                    break;

                    case "product.manufacturer":
                    {
                        string mans = string.Empty;
                        ProductManufacturerCollection productManufacturers = productVariant.Product.ProductManufacturers;
                        foreach (ProductManufacturer pm in productManufacturers)
                        {
                            mans += ", " + pm.Manufacturer.Name;
                        }
                        if (mans.Length != 0)
                        {
                            mans = mans.Substring(2);
                        }

                        if (productManufacturers.Count > 0)
                        {
                            tokens.Add(strToken + strFormat, String.Format(locProvider, "{0" + strFormat + "}", mans));
                        }
                    }
                    break;

                    case "product.category":
                    {
                        string cats = string.Empty;
                        ProductCategoryCollection productCategories = productVariant.Product.ProductCategories;
                        foreach (ProductCategory pc in productCategories)
                        {
                            cats += ", " + pc.Category.Name;
                        }
                        if (cats.Length != 0)
                        {
                            cats = cats.Substring(2);
                        }

                        if (productCategories.Count > 0)
                        {
                            tokens.Add(strToken + strFormat, String.Format(locProvider, "{0" + strFormat + "}", cats));
                        }
                    }
                    break;

                    case "product.shippingcosts":
                    {
                    }
                    break;

                    default:
                    {
                        tokens.Add(strToken + strFormat, strToken + strFormat);
                    }
                    break;
                    }
                }
            }

            foreach (string token in tokens.Keys)
            {
                Template = Template.Replace(string.Format(@"%{0}%", token), tokens[token]);
            }

            foreach (string token in AdditionalKeys.Keys)
            {
                Template = Template.Replace(string.Format(@"%{0}%", token), AdditionalKeys[token]);
            }

            return(Template);
        }
Beispiel #18
0
        /// <summary>
        /// Gets allowed discounts
        /// </summary>
        /// <param name="productVariant">Product variant</param>
        /// <param name="customer">Customer</param>
        /// <returns>Discounts</returns>
        protected static DiscountCollection GetAllowedDiscounts(ProductVariant productVariant, Customer customer)
        {
            int customerID = 0;

            if (customer != null)
            {
                customerID = customer.CustomerID;
            }

            DiscountCollection allowedDiscounts = new DiscountCollection();

            //CustomerRoleCollection customerRoles = CustomerManager.GetCustomerRolesByCustomerID(customerID);
            //foreach (CustomerRole _customerRole in customerRoles)
            //    foreach (Discount _discount in _customerRole.Discounts)
            //        if (_discount.IsActive && _discount.DiscountType == DiscountTypeEnum.AssignedToSKUs && !allowedDiscounts.ContainsDiscount(_discount.Name))
            //            allowedDiscounts.Add(_discount);

            string customerCouponCode = string.Empty;

            if (customer != null)
            {
                customerCouponCode = customer.LastAppliedCouponCode;
            }

            foreach (Discount _discount in productVariant.AllDiscounts)
            {
                if (_discount.IsActive(customerCouponCode) &&
                    _discount.DiscountType == DiscountTypeEnum.AssignedToSKUs &&
                    !allowedDiscounts.ContainsDiscount(_discount.Name))
                {
                    switch (_discount.DiscountRequirement)
                    {
                    case DiscountRequirementEnum.None:
                    {
                        allowedDiscounts.Add(_discount);
                    }
                    break;

                    case DiscountRequirementEnum.MustBeAssignedToCustomerRole:
                    {
                        if (_discount.CheckCustomerRoleRequirement(customerID))
                        {
                            allowedDiscounts.Add(_discount);
                        }
                    }
                    break;

                    default:
                        break;
                    }
                }
            }

            ProductCategoryCollection productCategories = CategoryManager.GetProductCategoriesByProductID(productVariant.ProductID);

            foreach (ProductCategory _productCategory in productCategories)
            {
                Category category = _productCategory.Category;
                if (category != null)
                {
                    foreach (Discount _discount in category.Discounts)
                    {
                        if (_discount.IsActive(customerCouponCode) &&
                            _discount.DiscountType == DiscountTypeEnum.AssignedToSKUs &&
                            !allowedDiscounts.ContainsDiscount(_discount.Name))
                        {
                            switch (_discount.DiscountRequirement)
                            {
                            case DiscountRequirementEnum.None:
                            {
                                allowedDiscounts.Add(_discount);
                            }
                            break;

                            case DiscountRequirementEnum.MustBeAssignedToCustomerRole:
                            {
                                allowedDiscounts.Add(_discount);
                            }
                            break;

                            default:
                                break;
                            }
                        }
                    }
                }
            }
            return(allowedDiscounts);
        }
Beispiel #19
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;
            }
        }
        public void SyncProductCatalog()
        {
            // open the file "data.csv" which is a CSV file with headers
            using (CsvReader csv =
                       new CsvReader(new StreamReader(@"D:\\LudwigMasters04072011.csv"), true))
            {
                int      fieldCount = csv.FieldCount;
                string[] headers    = csv.GetFieldHeaders();

                CatalogBiz cBiz      = new CatalogBiz();
                int        count     = 0;
                int        catalogID = 0;
                string     catNo     = string.Empty;
                while (csv.ReadNextRecord())
                {
                    try
                    {
                        catalogID = 0;
                        catNo     = string.Empty;
                        for (int i = 0; i < fieldCount; i++)
                        {
                            //Console.Write(string.Format("{0} = {1};", headers[i], csv[i]));

                            if (headers[i].Equals("CategoryID"))
                            {
                                int.TryParse(csv[i], out catalogID);
                            }
                            if (headers[i].Equals("Catno"))
                            {
                                catNo = csv[i];
                            }
                        }
                        //Console.WriteLine();
                        List <lwg_Catalog> lst = cBiz.GetListLWGCatalog(catNo);
                        LWGLog.WriteLog("catNo: " + catNo + " product Count: " + lst.Count, " updating ... ");
                        if (lst != null && lst.Count > 0)
                        {
                            foreach (lwg_Catalog item in lst)
                            {
                                if (catalogID > 0)
                                {
                                    Product product = ProductManager.GetProductById(item.CatalogId);
                                    if (product != null)
                                    {
                                        ProductCategoryCollection existingProductCategoryCollection = product.ProductCategories;
                                        LWGLog.WriteLog("productID: " + product.ProductId + " productCatagoryCollection: " + existingProductCategoryCollection.Count, " updating ... ");
                                        if (existingProductCategoryCollection != null && existingProductCategoryCollection.Count > 0)
                                        {
                                            //CategoryManager.InsertProductCategory(item.CatalogId, catalogID, false, 1);
                                            foreach (ProductCategory pc in existingProductCategoryCollection)
                                            {
                                                if (pc.CategoryId == 74)
                                                {
                                                    CategoryManager.UpdateProductCategory(pc.ProductCategoryId, pc.ProductId, catalogID, pc.IsFeaturedProduct, pc.DisplayOrder);
                                                    count++;
                                                    LWGLog.WriteLog("Sync Product to catalog Count: " + count + " productID: " + pc.ProductId + " catagoryID: " + catalogID, " updating ... ");
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        LWGLog.WriteLog("Sync Product to catalog Error: " + catNo + " ", ex.Message);
                    }
                }
                LWGLog.WriteLog("Sync Product to catalog Count: " + count + " ", " OK ");
            }
        }