private void GetCategoryProductsFromSite(InCategory category) { String Url = string.Format("http://www.seclock.com/products/ajax/advanced-search-results.asp?i=&m=&c={0}&search_in=all", category.Code); HtmlAgilityPack.HtmlDocument document = browser.GetWebRequest(Url); HtmlNodeCollection productNodes = document.DocumentNode.SelectNodes("//a[@class='product-detail-from-search']"); foreach (HtmlNode productNode in productNodes) { InProduct product = new InProduct(); product.Code = productNode.InnerHtml; var dbProducts = new InProductManager(Constants.ConnectionString).GetData(product); if (dbProducts.Count() > 0) { product = dbProducts[0]; } product.Name = productNode.InnerHtml; product.Url = productNode.Attributes["href"].Value; product.CategoryName = category.Name; product.CategoyCode = category.Code; new InProductManager(Constants.ConnectionString).Save(product); category.Products.Add(product); } }
public void GetProductsByManufacturerFromSite(InManufacturer manufacturer) { String Url = "http://www.seclock.com/products/items.asp?m=" + manufacturer.Code; if (!LoggedIn) Login(); HtmlAgilityPack.HtmlDocument document = browser.GetWebRequest(Url); HtmlNodeCollection seriesNodes = document.DocumentNode.SelectNodes("//ul[@class='products']/li"); manufacturer.SeriesList = new List<InManufacturerSeries>(); if (!ReferenceEquals(seriesNodes, null)) { foreach (HtmlNode seriesNode in seriesNodes) { InManufacturerSeries series = new InManufacturerSeries(); var seriesDetail = seriesNode.SelectSingleNode("a"); if (!ReferenceEquals(seriesDetail, null)) { series.Name = seriesNode.SelectSingleNode("a").InnerText; series.Products = new List<InProduct>(); HtmlNodeCollection anchorNodes = seriesNode.SelectNodes("ul/li/a"); foreach (HtmlNode anchorNode in anchorNodes) { InProduct product = new InProduct(); product.Code = anchorNode.InnerHtml; var dbProducts = new InProductManager(Constants.ConnectionString).GetData(product); if (dbProducts.Count() > 0) { product = dbProducts[0]; } product.Name = anchorNode.InnerText; product.Url = anchorNode.Attributes["href"].Value; product.ManufacturerSeries = series.Name; product.ManufacturerName = manufacturer.Name; product.ManufacturerCode = manufacturer.Code; new InProductManager(Constants.ConnectionString).Save(product); series.Products.Add(product); } new InManufacturerSeriesManager(Constants.ConnectionString).Save(manufacturer.Code, series); manufacturer.SeriesList.Add(series); } } exportManager.Insert(Constants.SiteName.SECLOCK, Constants.ExportType.SECLOCK_MANUFACTURER_SERIES, manufacturer.Code); } }
private static void ExportProduct(string productCode) { String ConnStr = String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=True", Settings.GetValue("WebSpiderDB")); InProduct product = new InProduct(); product.Code = productCode; var secLockProduct = new InProductManager(Constants.ConnectionString).GetData(product); if (secLockProduct.Count() == 0) return; product = secLockProduct[0]; FinalTable ft = new FinalTable(); ft.SLD_SOURCE_ID = String.Empty; ft.SLD_COST = product.YourPrice; ft.SLD_PART = product.Code; ft.SLD_IMG1 = product.ImageUrl1; ft.SLD_IMG2 = product.ImageUrl2; ft.SLD_VENDOR = product.ManufacturerName; ft.SLD_INV = product.Stock; ft.SLD_DESC = product.Description; ft.SLD_TECHDOC = product.TechDoc; ft.SLD_LastUpdate = DateTime.Now.ToString(Settings.GetValue("DateFormat")); new FinalTableManager(ConnStr).SaveProduct(ft); }
public InProduct GetProductFromSite(String ProductCode, Boolean Incongito = false) { if (!Incongito && !LoggedIn) Login(); String Url = "http://www.seclock.com/products/ajax/details.asp?i=" + ProductCode; HtmlAgilityPack.HtmlNode.ElementsFlags.Remove("form"); HtmlAgilityPack.HtmlDocument doc = browser.GetWebRequest(Url); var productsSeriesUl = doc.DocumentNode.SelectNodes("//ul[@class='products']"); InProduct p = new InProduct(); p.Code = ProductCode; var dbProducts = new InProductManager(Constants.ConnectionString).GetData(p); if (dbProducts.Count == 1) p = dbProducts[0]; p.Code = doc.DocumentNode.SelectNodes("h2").First().InnerHtml; p.Name = doc.DocumentNode.SelectNodes("h2").First().InnerHtml; var img = doc.DocumentNode.SelectNodes("//img[@id='itemPic']"); p.ImageUrl1 = img == null ? String.Empty : img[0].Attributes["src"].Value; Decimal price; var listPriceHtml = doc.DocumentNode.SelectNodes("//div[@class='clearfix big-tight']").FirstOrDefault(); if (!ReferenceEquals(listPriceHtml, null)) { String ListPrice = listPriceHtml.SelectNodes("//div[@class='input list']").First().InnerHtml.Trim().Replace("$", ""); p.ListPrice = Decimal.TryParse(ListPrice, out price) ? price : 0m; } var yourPriceHtml = doc.DocumentNode.SelectNodes("//div[@class='clearfix big-tight your']").FirstOrDefault(); if (!ReferenceEquals(yourPriceHtml, null)) { String YourPrice = yourPriceHtml.SelectNodes("//div[@class='input']").First().InnerHtml.Trim().Replace("$", ""); p.YourPrice = Decimal.TryParse(YourPrice, out price) ? price : 0m; } var qty = doc.DocumentNode.SelectNodes("//div[@class='input tight']/h3"); int stock; if (Int32.TryParse(qty[0].InnerHtml.ToLower().Replace("available", "").Trim(), out stock)) p.Stock = stock.ToString(); //var productForm = doc.DocumentNode.SelectNodes("div[@class='input tight']/h3"); //if (!ReferenceEquals(productForm, null)) //{ // var qty = productForm[0].SelectNodes("h3").FirstOrDefault(); // if (!ReferenceEquals(qty, null)) // { // p.Stock = Convert.ToInt32(qty.InnerHtml.ToLower().Replace("available", "").Trim()).ToString(); // } //} HtmlNode modalBody = doc.DocumentNode.SelectNodes("//div[@id='product-modal-body']").FirstOrDefault(); if (!ReferenceEquals(modalBody, null)) { var modalBodyP = modalBody.SelectNodes("p"); int descIndex = 1; if (modalBodyP[0].Descendants("img").Count() > 0) descIndex = 2; if (!ReferenceEquals(modalBodyP[descIndex], null)) { var description = modalBodyP[descIndex].InnerHtml; p.Description = description.Trim().Replace('\'', '\"'); } //if (!ReferenceEquals(modalBodyTechDocs, null)) //{ // var techDocs = modalBodyTechDocs.FirstOrDefault().InnerHtml; // p.TechDoc = techDocs.Trim(); //} #region [ Tech Docs Download ] var modalBodyTechDocs = modalBody.SelectNodes("//ul[@class='techdocs']"); if (!ReferenceEquals(modalBodyTechDocs, null)) { if (modalBodyTechDocs.Count == 2) { List<String> TechDocs = new List<string>(); var hrefs = modalBodyTechDocs[0].Descendants("a"); foreach (var href in hrefs) { String docUrl = href.Attributes["href"].Value; try { if (docUrl.StartsWith("/")) docUrl = "http://www.seclock.com/" + docUrl; String DocFolder = Settings.GetValue("DocFolder"); if (!Directory.Exists(DocFolder)) Directory.CreateDirectory(DocFolder); String FileName = String.Format("{0}_{1}_{2}",Settings.GetValue("SecLockImagePrefix"), p.Code, docUrl.Substring(docUrl.LastIndexOf("/") + 1)); String FilePath = String.Format("{0}\\{1}", DocFolder, FileName); if (File.Exists (FilePath)) File.Delete(FilePath); browser.DownloadFile(docUrl, FilePath); TechDocs.Add(FileName); } catch (Exception ex) { Utility.ErrorLog(ex, null); if (Settings.GetValue("MailErrors") == true) Utility.ApplicationLog(String.Format("{0}", ex.Message), Constants.EmailErrorFile); } finally{ p.TechDoc = String.Join(";", TechDocs); } } } } #endregion //var manLinksNode =modalBody.SelectNodes("//ul[@class='techdocs']").FirstOrDefault(); //if (!ReferenceEquals(manLinksNode, null)) //{ // var manuFacturerLinks = manLinksNode.InnerHtml; //} } return p; }