List <lwg_Dealer> ParseCSVFileToDealerList(string fullPath)
        {
            List <lwg_Dealer> dealerList = new List <lwg_Dealer>();
            CsvReader         csv        = new CsvReader(new StreamReader(fullPath), true);

            csv.MissingFieldAction = MissingFieldAction.ReplaceByNull;

            int fieldCount = csv.FieldCount;

            string[] headers = csv.GetFieldHeaders();
            while (csv.ReadNextRecord())
            {
                lwg_Dealer dealer = new lwg_Dealer();

                // Dealer ID
                if (csv[0] != null)
                {
                    dealer.DealerID = csv[0];
                }
                else
                {
                    LWGLog.WriteLog("import dealer", "null of dealerId");
                    continue;
                }

                // Dealer Name
                if (csv[1] != null)
                {
                    dealer.Name = csv[1];
                }
                else
                {
                    LWGLog.WriteLog("import dealer", string.Format("{0}: empty name", csv[0]));
                    continue;
                }

                // Address Line 1
                if (csv[2] != null)
                {
                    dealer.AddressLine1 = csv[2];
                }
                // Address Line 2
                if (csv[3] != null)
                {
                    dealer.AddressLine2 = csv[3];
                }
                // City
                if (csv[4] != null)
                {
                    dealer.City = csv[4];
                }
                // State
                if (csv[5] != null)
                {
                    dealer.State = csv[5];
                }
                // Zip
                if (csv[6] != null)
                {
                    dealer.Zip = csv[6];
                }
                // Phone
                if (csv[7] != null)
                {
                    dealer.Phone = csv[7];
                }
                // Fax
                if (csv[8] != null)
                {
                    dealer.Fax = csv[8];
                }
                // WebAddress
                if (csv[9] != null)
                {
                    dealer.WebAddress = csv[9];
                }
                // Contact
                if (csv[10] != null)
                {
                    dealer.Contact = csv[10];
                }
                // NewIssue
                if (csv[11] != null)
                {
                    dealer.NewIssue = csv[11];
                }

                dealerList.Add(dealer);
            }

            return(dealerList);
        }
        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 ");
            }
        }