public static void ExportProductUpdate(String productCode) { String ConnStr = String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Persist Security Info=True", Settings.GetValue("FinalTable")); 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_LastUpdate = DateTime.Now.ToString(Settings.GetValue("DateFormat")); new FinalTableManager(ConnStr).SaveProduct(ft); }
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); } }
private void DownloadProductImages(TaskDetail taskDetail, InProduct inProduct) { String Prefix = Settings.GetValue("SecLockImagePrefix").ToString(); String ImageFileName; String FileName; String Url; if (!String.IsNullOrEmpty(inProduct.ImageUrl1)) { ImageFileName = String.Format("{0}{1}_1.{2}", Prefix, inProduct.Code, Utility.GetFileExtension(inProduct.ImageUrl1)); ImageFileName = Utility.GetValidFileName(ImageFileName); // Small Image FileName = String.Format("{0}\\{1}\\{2}", GetImageFolder(taskDetail), CreateProductDirectory(taskDetail, inProduct), ImageFileName); Url = (inProduct.ImageUrl1.StartsWith("http") ? "" : "http://www.seclock.com") + inProduct.ImageUrl1; //Utility.ApplicationLog(String.Format("Downloading Image from {0} to {1}", Url, FileName)); browser.DownloadFile(Url, FileName); inProduct.ImageUrl1 = ImageFileName; } if (!String.IsNullOrEmpty(inProduct.ImageUrl2)) { ImageFileName = String.Format("{0}{1}_2.{2}", Prefix, inProduct.Code, Utility.GetFileExtension(inProduct.ImageUrl2)); ImageFileName = Utility.GetValidFileName(ImageFileName); // Small Image FileName = String.Format("{0}\\{1}\\{2}", GetImageFolder(taskDetail), CreateProductDirectory(taskDetail, inProduct), ImageFileName); Url = (inProduct.ImageUrl2.StartsWith("http") ? "" : "http://www.seclock.com") + inProduct.ImageUrl2; //Utility.ApplicationLog(String.Format("Downloading Image from {0} to {1}", Url, FileName)); browser.DownloadFile(Url, FileName); inProduct.ImageUrl2 = ImageFileName; } }
public List <InProduct> GetData(InProduct product) { String Query = "SELECT * FROM SecLockProduct WITH (NOLOCK) WHERE Code = '" + product.Code + "' ORDER BY Name"; SqlCeDataManager oDm = new SqlCeDataManager(this.ConnectionString, Query, true); return(DataParser.ToList <InProduct>(oDm.GetTable())); }
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 String CreateProductDirectory(TaskDetail taskDetail, InProduct inProduct) { String ValidDirName = Utility.GetValidDirName(inProduct.Code); String DirName; DirName = String.Format("{0}\\{1}", GetImageFolder(taskDetail), ValidDirName); if (!Directory.Exists(DirName)) { //Utility.ApplicationLog(String.Format("Creating Directory {0}", DirName)); Directory.CreateDirectory(DirName); } return(ValidDirName); }
private int Insert(InProduct product) { String Query = "INSERT INTO [SecLockProduct] ([Code] ,[Name] ,[Url] ,[ManufacturerCode],[ManufacturerName],[ManufacturerSeries],[CategoyCode],[CategoryName], [YourPrice] ,[ListPrice] ,[ImageUrl1],[ImageUrl2] ,[Stock] ,[Description] ,[TechDoc]) " + "VALUES ('" + product.Code + "' ,'" + product.Name + "' ,'" + product.Url + "' ,'" + product.ManufacturerCode + "', '" + product.ManufacturerName + "', '" + product.ManufacturerSeries + "', '" + product.CategoyCode + "', '" + product.CategoryName + "', '" + product.YourPrice + "' ,'" + product.ListPrice + "' ,'" + product.ImageUrl1 + "' ,'" + product.ImageUrl2 + "', '" + product.Stock + "' ,'" + (String.IsNullOrEmpty(product.Description) ? String.Empty : product.Description.Replace("\'", "\'\'")) + "' ,'" + (String.IsNullOrEmpty(product.TechDoc) ? String.Empty : product.TechDoc.Replace("'", "''")) + "')"; SqlCeDataManager oDm = new SqlCeDataManager(this.ConnectionString, Query, true); return(oDm.RunActionQuery()); }
public int Save(InProduct category) { var x = GetData(category); if (x.Count > 0) { return(Update(category)); } else { return(Insert(category)); } }
private int Update(InProduct product) { String Query = "UPDATE [SecLockProduct] SET [Name] = '" + product.Name + "', [Url] = '" + product.Url + "', [ManufacturerCode] = '" + product.ManufacturerCode + "', [ManufacturerName] = '" + product.ManufacturerName + "', [ManufacturerSeries] = '" + product.ManufacturerSeries + "', [CategoyCode] = '" + product.CategoyCode + "', [CategoryName] = '" + product.CategoryName + "', [YourPrice] = " + product.YourPrice + " , [ListPrice] = " + product.ListPrice + " , [ImageUrl1] = '" + product.ImageUrl1 + "', [ImageUrl2] = '" + product.ImageUrl2 + "', [Stock] = '" + product.Stock + "', [Description] = '" + (String.IsNullOrEmpty(product.Description) ? String.Empty : product.Description.Replace("\'", "\'\'")) + "', [TechDoc] = '" + (String.IsNullOrEmpty(product.TechDoc) ? String.Empty : product.TechDoc.Replace("'", "''")) + "' WHERE [Code] = '" + product.Code + "';"; SqlCeDataManager oDm = new SqlCeDataManager(this.ConnectionString, Query, true); return(oDm.RunActionQuery()); }
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); }