Exemplo n.º 1
0
        private static String SaveProductSmallImage(AdiProduct p, AdiMode mode)
        {
            String Prefix = Settings.GetValue("AdiImagePrefix").ToString();

            if (p.ProductImagePath == null || p.ProductImagePath.Length == 0)
                return null;

            String ImageFileName = String.Format("{0}{1}_small.{2}", Prefix, p.AdiNumber, Utility.GetFileExtension(p.ProductImagePath));
            // Small Image
            String FileName = String.Format("{0}\\{1}\\{2}", GetImageFolder(mode), CreateProductDirectory(p, mode), ImageFileName);
            String Url = (p.ProductImagePath.StartsWith("http") ? "" : "http:") + p.ProductImagePath;
            //Utility.ApplicationLog(String.Format("Downloading Image from {0} to {1}", Url, FileName));
            browser.DownloadFile(Url, FileName);

            return ImageFileName;
        }
Exemplo n.º 2
0
        private static void UpdateProductAid(AdiProduct product, Boolean SaveProductImage, AdiMode mode)
        {
            var products = adiProductManager.GetDataByPartNum(product.AdiNumber);
            if (products.Count == 1)
            {
                var prod = products[0];
                String CatagoryID = (product.CatagoryID != null && product.CatagoryID.Length > 0) ? product.CatagoryID : prod.CatagoryID == null ? null : prod.CatagoryID;
                //String BrandValue = (product.BrandValue != null && product.BrandValue.Length > 0) ? product.BrandValue : prod.BrandValue == null ? null : prod.BrandValue;
                long adiID = prod.ID;
                //adiProductManager.UpdateByID(product.CatagoryID, product.BrandValue, product.Price, product.AdiNumber, product.VendorName, DateTime.Now, product.MarketingMessage, adiID);

                prod.ProductImagePath = Utility.GetValidDirName(product.VendorName);
                //prod.CatagoryID = CatagoryID;
                prod.LastUpdateDatetime = DateTime.Now;

                adiProductManager.UpdateByID(prod.ID, prod.AdiNumber, prod.VendorName, prod.VendorNumber, prod.VendorModel
                    , prod.PartNumber, prod.Name, prod.Url, prod.AllowedToBuy, prod.DangerousGoodsMessage
                    , prod.InventoryMessage, prod.MarketingMessage, prod.MinQty, prod.ModelNumber, prod.Price
                    , prod.ProductDescription, prod.ProductImagePath, prod.RecycleFee, prod.SaleMessageIndicator, prod.SaleType
                    , prod.ST, prod.SMI, prod.InventoryMessageCode, prod.CatagoryID, prod.SmallImage, prod.BigImage
                    , prod.IsUpdating, prod.UpdateInterval, prod.LastUpdateDatetime);

                if (SaveProductImage) { }
                    adiProductManager.UpdateImageByID(adiID, SaveProductSmallImage(product, mode), SaveProductBigImage(product, mode));
            }
        }
Exemplo n.º 3
0
 private static String GetImageFolder(AdiMode mode)
 {
     String FolderName = String.Format("{0}\\Image", Application.StartupPath);
     if (mode == AdiMode.CRAWL)
         FolderName = Settings.GetValue("CrawlImageFolder").ToString().Length > 0 ? Settings.GetValue("CrawlImageFolder") : FolderName;
     else
         FolderName = Settings.GetValue("UpdateImageFolder").ToString().Length > 0 ? Settings.GetValue("UpdateImageFolder") : FolderName;
     return FolderName;
 }
Exemplo n.º 4
0
        private static double SaveAdiInventory(AdiProduct product, List<ADIInventoryDetails> storesList,AdiMode mode, bool saveInventory = true)
        {
            adiInventoryDetailsManager.DeleteByPart(product.AdiNumber);
            foreach (var store in storesList)
            {
                adiInventoryDetailsManager.Insert(product.AdiNumber, store.id, store.dc, store.region, store.storeName, store.address1
                    , store.address2, store.address3, store.country, store.city, store.state, store.stateName, store.zip
                    , store.phone, store.fax, store.lat, store.lon, store.inventory, store.manager, store.responseCode
                    , store.responseMessage, store.IsHub);
            }

            double TotalInventory = 0, Dallas = 0, DC_AtlantaHub = 0, DC_Dallas_Hub = 0,
                    DC_Elk_Grove_Hub = 0, DC_Feura_Bush = 0, DC_Louisville_Hub = 0,
                    DC_Reno_Hub = 0, DC_Richmond_Dist_Ctr = 0, Oklahama = 0, RemainingBranches = 0;

            List<ADIInventoryDetails> hubsList = storesList.Where(x => x.IsHub).ToList();

            Dallas = GetInventory(storesList, "dallas");
            DC_AtlantaHub = GetInventory(hubsList, "distribution center: atlanta hub");
            DC_Dallas_Hub = GetInventory(hubsList, "distribution center: dallas hub");
            DC_Elk_Grove_Hub = GetInventory(hubsList, "distribution center: elk grove hub");
            DC_Feura_Bush = GetInventory(hubsList, "distribution center: feura bush");
            DC_Louisville_Hub = GetInventory(hubsList, "distribution center: louisville hub");
            DC_Reno_Hub = GetInventory(hubsList, "distribution center: reno hub");
            DC_Richmond_Dist_Ctr = GetInventory(hubsList, "distribution center: richmond dist ctr");
            Oklahama = GetInventory(storesList, "oklahama");
            TotalInventory = storesList.Sum(x => Convert.ToDouble("0" + x.inventory));
            try
            {
                RemainingBranches = TotalInventory - (Dallas + DC_AtlantaHub + DC_Dallas_Hub + DC_Elk_Grove_Hub + DC_Feura_Bush + DC_Louisville_Hub + DC_Reno_Hub + DC_Richmond_Dist_Ctr + Oklahama);
            }
            catch { }

            //DataTable oDataTable = adiInventoryManager.GetDataByProduct(product.AdiNumber);
            ADIInventoryExport adiInventory = adiInventoryExportManager.GetDataByProduct(product.AdiNumber);
            if (saveInventory)
            {
                if (!ReferenceEquals(adiInventory, null))
                {
                    // update
                    adiInventoryExportManager.UpdateByPartNum(
                        product.AdiNumber,
                        (int)TotalInventory,
                        (int)Dallas,
                        (int)DC_AtlantaHub,
                        (int)DC_Dallas_Hub,
                        (int)DC_Elk_Grove_Hub,
                        (int)DC_Feura_Bush,
                        (int)DC_Louisville_Hub,
                        (int)DC_Reno_Hub,
                        (int)DC_Richmond_Dist_Ctr,
                        (int)Oklahama,
                        (int)RemainingBranches,
                        DateTime.Now);
                }
                else
                {
                    // insert
                    adiInventoryExportManager.Insert(
                        product.AdiNumber,
                        (int)TotalInventory,
                        (int)Dallas,
                        (int)DC_AtlantaHub,
                        (int)DC_Dallas_Hub,
                        (int)DC_Elk_Grove_Hub,
                        (int)DC_Feura_Bush,
                        (int)DC_Louisville_Hub,
                        (int)DC_Reno_Hub,
                        (int)DC_Richmond_Dist_Ctr,
                        (int)Oklahama,
                        (int)RemainingBranches,
                        DateTime.Now);
                }
            }
            return TotalInventory;
        }
Exemplo n.º 5
0
        private static String CreateProductDirectory(AdiProduct product, AdiMode mode)
        {
            String ValidDirName = Utility.GetValidDirName(product.VendorName);
            String DirName ;

            DirName = String.Format("{0}\\{1}", GetImageFolder(mode), ValidDirName);
            if (!Directory.Exists(DirName))
            {
                //Utility.ApplicationLog(String.Format("Creating Directory {0}", DirName));
                Directory.CreateDirectory(DirName);
            }
            return ValidDirName;
        }
Exemplo n.º 6
0
        public static bool SaveProduct(AdiProduct product,AdiMode mode)
        {
            //Utility.ApplicationLog(String.Format("Saving Adi product {0} {1}", product.AdiNumber, product.ProductDescription));
            bool Saved = false;
            Saved = false;
            var products = adiProductManager.GetDataByPartNum(product.AdiNumber);
            if (products.Count == 1)
            {
                var prod = products[0];
                product.CatagoryID = (product.CatagoryID != null && product.CatagoryID.Length > 0) ? product.CatagoryID : prod.CatagoryID == null ? null : prod.CatagoryID;
                //product.BrandValue = (product.BrandValue != null && product.BrandValue.Length > 0) ? product.BrandValue : prod.BrandValue == null ? null : prod.BrandValue;
                long adiID = prod.ID;
                product.LastUpdateDatetime = DateTime.Now;
                Saved = (adiProductManager.UpdateByID(products[0].ID, product.AdiNumber, product.VendorName, product.VendorNumber, product.VendorModel
                    , product.PartNumber, product.Name, product.Url, product.AllowedToBuy, product.DangerousGoodsMessage
                    , product.InventoryMessage, product.MarketingMessage, product.MinQty, product.ModelNumber, product.Price
                    , product.ProductDescription, product.ProductImagePath, product.RecycleFee, product.SaleMessageIndicator, product.SaleType
                    , product.ST, product.SMI, product.InventoryMessageCode, product.CatagoryID, product.SmallImage, product.BigImage
                    , product.IsUpdating, product.UpdateInterval, product.LastUpdateDatetime) == 1);
            }
            else
            {
                //product.ProductImagePath = Utility.GetValidDirName(product.VendorName);
                product.LastUpdateDatetime = DateTime.Now;
                product.UpdateInterval = Settings.GetValue("ADIProductDefaultUpdateInterval");

                Saved = (adiProductManager.InsertNew(product.ID, product.AdiNumber, product.VendorName, product.VendorNumber, product.VendorModel
                    , product.PartNumber, product.Name, product.Url, product.AllowedToBuy, product.DangerousGoodsMessage
                    , product.InventoryMessage, product.MarketingMessage, product.MinQty, product.ModelNumber, product.Price
                    , product.ProductDescription, product.ProductImagePath, product.RecycleFee, product.SaleMessageIndicator, product.SaleType
                    , product.ST, product.SMI, product.InventoryMessageCode, product.CatagoryID, product.SmallImage, product.BigImage
                    , product.IsUpdating, product.UpdateInterval, product.LastUpdateDatetime) == 1);
            }
            return Saved;
        }
Exemplo n.º 7
0
        //public static void GetProductSpecification(String ProductID, String ProductName)
        public static void GetProductSpecification(ref AdiProduct product,AdiMode mode)
        {
            //ADIChildTableAdapter adapter = new ADIChildTableAdapter();
            NameValueCollection JsonPatameters = new NameValueCollection();
            JsonPatameters.Add("productID", product.AdiNumber);
            JsonPatameters.Add("productDefinitionName", product.ProductDescription);
            String Url = "http://adiglobal.us/_vti_bin/requests.asmx/ProductSpecifications";
            String responseJson = browser.AjaxPost(Url, JsonPatameters);

            Dictionary<string, object> d = browser.parseJson(browser.parseJson(responseJson)["d"].ToString());

            foreach (String rootKey in d.Keys)
            {
                Dictionary<string, object> dInfo = browser.parseJson(d[rootKey].ToString());
                foreach (String key in dInfo.Keys)
                {
                    adiProductSpecificationManager.Save(product.AdiNumber, key, dInfo[key].ToString());
                    //if (adiProductSpecificationManager.GetValue(product.AdiNumber, key) == null)
                    //    adiProductSpecificationManager.Insert(product.AdiNumber, key, dInfo[key].ToString());
                    //else
                    //    adiProductSpecificationManager.UpdateValue(dInfo[key].ToString(), product.AdiNumber, key);
                }
            }
        }
Exemplo n.º 8
0
        public static double GetProductInventory(AdiProduct product,AdiMode mode, bool saveInventory = true)
        {
            //Utility.ApplicationLog(String.Format("Getting Inventory for {0} {1}", product.AdiNumber, product.ProductDescription));
            String Url = "https://adiglobal.us/_vti_bin/requests.asmx/InventoryByProduct";
            NameValueCollection parameters = new NameValueCollection();
            parameters.Add("productId", product.AdiNumber);
            String responseJson = browser.AjaxPost(Url, parameters);
            //String responseJson = File.ReadAllText("JsonResult.txt");

            Dictionary<string, object> response = browser.parseJson(browser.parseJson(browser.parseJson(responseJson)["d"].ToString())["Response"].ToString());
            List<ADIInventoryDetails> storesList  = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ADIInventoryDetails>>(response["Stores"].ToString());
            storesList.AddRange(Newtonsoft.Json.JsonConvert.DeserializeObject<List<ADIInventoryDetails>>(response["Regional"].ToString()));
            storesList.AddRange(Newtonsoft.Json.JsonConvert.DeserializeObject<List<ADIInventoryDetails>>(response["National"].ToString()));
            storesList.AddRange(Newtonsoft.Json.JsonConvert.DeserializeObject<List<ADIInventoryDetails>>(response["Hubs"].ToString()));
            storesList.AddRange(Newtonsoft.Json.JsonConvert.DeserializeObject<List<ADIInventoryDetails>>(response["Ring"].ToString()));
            return SaveAdiInventory(product, storesList,mode,saveInventory);
        }
Exemplo n.º 9
0
        public static void GetProductDetails(AdiProduct product, Boolean SaveImage = false, AdiMode mode=AdiMode.CRAWL)
        {
            String Url = GetAbsoluteUrl(product.Url);
            var productDoc = browser.GetWebRequest(Url);

            try
            {
                var overview = productDoc.DocumentNode.SelectSingleNode("//div[@class='ProductDetailtab-container']")
                    .SelectSingleNode("//div[@class='tab-content overview clearfix']").Descendants("div");

                foreach (HtmlNode node in overview)
                {
                    var h3 = node.Descendants("h3").FirstOrDefault();
                    if (h3 != null)
                    {
                        String Name = h3.InnerHtml;
                        String Value = node.InnerHtml.Replace(h3.OuterHtml, "").Trim();
                        Value = Regex.Replace(Value, @"<[^>]*(>|$)|&nbsp;|&zwnj;|&raquo;|&laquo;", String.Empty);
                        adiProductSpecificationManager.Save(product.AdiNumber, Name, Value);
                    }
                }
            }
            catch (Exception ex)
            {
                Utility.ApplicationLog(String.Format("Error downloading product overview"));
                String json = null;
                Utility.ErrorLog(ex, json);
                if (Settings.GetValue("MailErrors") == true)
                    Utility.ApplicationLog(String.Format("Error downloading product overview. {0}", ex.Message), Constants.EmailErrorFile);
            }

            try
            {
                if (SaveImage)
                {
                    var productImages = productDoc.DocumentNode.SelectSingleNode("//div[@class='product-img-big']").Descendants("img");

                    product.BigImage = productImages.FirstOrDefault().Attributes["src"].Value;
                    if (!product.BigImage.StartsWith("http"))
                        product.BigImage = GetAbsoluteUrl(product.BigImage);

                    if (productImages.Count() > 1)
                    {
                        product.SmallImage = productImages.ToList()[1].Attributes["src"].Value;
                        if (!product.SmallImage.StartsWith("http"))
                            product.SmallImage = GetAbsoluteUrl(product.SmallImage);
                    }
                }
            }
            catch (Exception ex)
            {
                Utility.ApplicationLog(String.Format("Error downloading product image"));
                String json = null;
                Utility.ErrorLog(ex, json);
                if (Settings.GetValue("MailErrors") == true)
                    Utility.ApplicationLog(String.Format("Error downloading product image. {0}", ex.Message), Constants.EmailErrorFile);
            }
            GetProductSpecification(ref product,mode);
            UpdateProductAid(product, SaveImage, mode);
        }