private void btUpDateToDay_Click(object sender, EventArgs e) { Data.KW.KeywordsDataTable dt = new Data.KW.KeywordsDataTable(); this.keywordsTableAdapter.FillBy_LessLastUpdate(dt, DateTime.Now.AddDays(-1)); DBTableAdapters.ProductTableAdapter adtp = new DBTableAdapters.ProductTableAdapter(); adtp.Connection.ConnectionString = QT.Entities.Server.ConnectionString; int i = 0; foreach (Data.KW.KeywordsRow dr in dt) { i++; int a = 0; try { String keyword = dr.KeyName.Trim().Replace(" ", "+"); a = (int)Convert.ToInt32(adtp.Product_SelectCountByFreetext_Name(keyword)); } catch (Exception) { } this.keywordsTableAdapter.UpdateQuery_KeyFreq(a, DateTime.Now, dr.KeyHash); this.lamess.Text = String.Format("({0}/{1}) keyword:{2}={3}", i, dt.Rows.Count, dr.KeyName, a); Application.DoEvents(); } this.lamess.Text = "Finish"; dt.Clear(); dt.Dispose(); }
public void GetRootProductMinPriceAndNumProducts(long productID, out int minprice, out int numProducts) { Product_KeyComparisonEntyties obj = this.SelectByProductID(productID); minprice = 0; numProducts = 0; if (obj.Code != null) { if (obj.Code.Trim().Length <= 0) { return; } obj.InitKeyword(); var adt = new DBTableAdapters.ProductTableAdapter { Connection = { ConnectionString = Server.ConnectionString } }; var productAnalyticDataTable = new DB.ProductAnalyticDataTable(); var productAnalyticTableAdapter = new DBTableAdapters.ProductAnalyticTableAdapter(); productAnalyticTableAdapter.Connection.ConnectionString = Server.ConnectionString; productAnalyticTableAdapter.CMS_Product_SearchAnaytic_v2(productAnalyticDataTable, obj.PriceMin, obj.PriceMax, obj.codeContains, obj.codeLike, obj.codeLike1, obj.codeLike2, obj.codeLike3, obj.notCode, obj.notCodeLike, obj.notCodeLike1, obj.notCodeLike2, obj.notCodeLike3, 0); /// hiện thời đang không dùng đên idproduct sản phẩm gốc để check /// if (productAnalyticDataTable.Rows.Count > 0) { numProducts = productAnalyticDataTable.Rows.Count; minprice = Common.Obj2Int(productAnalyticDataTable.Rows[0]["Price"].ToString()); } productAnalyticDataTable.Dispose(); adt.Dispose(); productAnalyticTableAdapter.Dispose(); } }
public Product_KeyComparisonEntyties UpdatePriceAndTongSP_ProductAndKeyComparision(long IDProduct) { Product_KeyComparisonEntyties obj = new Product_KeyComparisonEntyties(); obj = this.SelectByProductID(IDProduct); if (obj.Code != null) { if (obj.Code.Trim().Length <= 0) { return(obj); } obj.InitKeyword(); DBTableAdapters.ProductTableAdapter adt = new DBTableAdapters.ProductTableAdapter(); adt.Connection.ConnectionString = Server.ConnectionString; DB.ProductAnalyticDataTable dtAN = new DB.ProductAnalyticDataTable(); DBTableAdapters.ProductAnalyticTableAdapter adtAN = new DBTableAdapters.ProductAnalyticTableAdapter(); adtAN.Connection.ConnectionString = Server.ConnectionString; DBTableAdapters.Price_LogsTableAdapter adtPriceLog = new DBTableAdapters.Price_LogsTableAdapter(); adtPriceLog.Connection.ConnectionString = Server.ConnectionString; int priceMin = 0, priceMax = 0, tong = 0; try { adtAN.CMS_Product_SearchAnaytic_v2(dtAN, obj.PriceMin, obj.PriceMax, obj.codeContains, obj.codeLike, obj.codeLike1, obj.codeLike2, obj.codeLike3, obj.notCode, obj.notCodeLike, obj.notCodeLike1, obj.notCodeLike2, obj.notCodeLike3, 0); /// hiện thời đang không dùng đên idproduct sản phẩm gốc để check /// if (dtAN.Rows.Count > 0) { tong = dtAN.Rows.Count; priceMin = Common.Obj2Int(dtAN.Rows[0]["Price"].ToString()); priceMax = Common.Obj2Int(dtAN.Rows[tong - 1]["Price"].ToString()); if (dtAN.Rows.Count > 1) { obj.GiaChenh = Common.Obj2Int(dtAN.Rows[1]["Price"].ToString()) - priceMin; } else { obj.GiaChenh = 0; } /// Map lại toàn bộ product ID /// int proid = Common.Obj2Int(IDProduct); foreach (DB.ProductAnalyticRow dr in dtAN) { adt.UpdateQuery_ProductID(proid, dr.ID); } } // return xem log obj.TongSanPham = tong; obj.PriceMin = priceMin; obj.PriceMax = priceMax; } catch (Exception) { } try { adt.UpdateQuery_GiaSPGoc(priceMin, DateTime.Now, String.Format("Tìm thấy {0} sản phẩm", tong), IDProduct); if (priceMin > 0) { adtPriceLog.Insert(IDProduct, DateTime.Now, priceMin, 0); } } catch (Exception) { } try { DBTableAdapters.Product_KeyComparisonTableAdapter adtKey = new DBTableAdapters.Product_KeyComparisonTableAdapter(); adtKey.Connection.ConnectionString = Server.ConnectionString; adtKey.UpdateQuery_GiaSauPhanTich(tong, priceMin, priceMax, DateTime.Now, obj.GiaChenh, IDProduct); } catch (Exception) { } dtAN.Dispose(); adt.Dispose(); adtAN.Dispose(); adtPriceLog.Dispose(); } return(obj); }
public Company(long id) { this.MaxHourCrawlerReload = 7; ID = id; _adt = new DBTableAdapters.CompanyTableAdapter(); _dt = new DB.CompanyDataTable(); _adt.Connection.ConnectionString = Server.ConnectionString; //_adt.Connection.Open(); _adt.FillBy_ID(_dt, ID); //_adt.Connection.Close(); _adtProduct = new DBTableAdapters.ProductTableAdapter(); _adtProduct.Connection.ConnectionString = Server.ConnectionString; if (_dt.Rows.Count > 0) { Name = _dt.Rows[0]["Name"].ToString(); Description = _dt.Rows[0]["Description"].ToString(); Website = _dt.Rows[0]["Website"].ToString(); Domain = _dt.Rows[0]["Domain"].ToString(); AddDate = Common.ObjectToDataTime(_dt.Rows[0]["AddDate"].ToString()); Phone = _dt.Rows[0]["Phone"].ToString(); Fax = _dt.Rows[0]["Fax"].ToString(); Yahoo = _dt.Rows[0]["Yahoo"].ToString(); Address = _dt.Rows[0]["Address"].ToString(); Status = Common.Obj2Byte(_dt.Rows[0]["Status"].ToString()); //UseDataFeed = _dt.Rows[0]["UseDataFeed"] != DBNull.Value && (Boolean) _dt.Rows[0]["UseDataFeed"]; Image = _dt.Rows[0]["Image"].ToString(); PageRank = Common.Obj2Int(_dt.Rows[0]["PageRank"].ToString()); AlexaRank = Common.Obj2Int(_dt.Rows[0]["AlexaRank"].ToString()); // TimeDelay = Common.Obj2Int(_dt.Rows[0]["TimeDelay"].ToString()); TotalProduct = Common.Obj2Int(_dt.Rows[0]["TotalProduct"].ToString()); LastCrawler = Common.ObjectToDataTime(_dt.Rows[0]["LastCrawler"].ToString()); FullCrawlerDay = Common.Obj2Int(_dt.Rows[0]["FullCrawlerDay"].ToString()); // LastFullCrawler = Common.ObjectToDataTime(_dt.Rows[0]["LastCrawler"].ToString()); //DaatFeed DataFeedPath = Common.Obj2String(_dt.Rows[0]["DataFeedUrl"].ToString()); LastUpdateDataFeedTime = Common.ObjectToDataTime(_dt.Rows[0]["LastUpdateDataFeed"]); UpdateDataFeedFrequency = new TimeSpan(Common.Obj2Int(_dt.Rows[0]["UpdateFreq"]), 0, 0); CompanyDataFeedType = (DataFeedType)Common.Obj2Int(_dt.Rows[0]["DataFeedType"]); //User and Password của URL datafeed UserDatafeed = Common.Obj2String(_dt.Rows[0]["UserDatafeed"].ToString()); PasswordDatafeed = Common.Obj2String(_dt.Rows[0]["PasswordDatafeed"].ToString()); notVisibleProduct = (_dt.Rows[0]["NotVisibleProduct"] == DBNull.Value) ? false : Common.Obj2Bool(_dt.Rows[0]["NotVisibleProduct"]); AllowAutoPushNewProduct = Common.Obj2Bool(_dt.Rows[0]["AllowAutoPushNewProduct"]); AllowAutoBlackLink = Common.Obj2Bool(_dt.Rows[0]["AllowAutoBlackLink"]); ClearQueueWhenFN = Common.Obj2Bool(_dt.Rows[0]["ClearQueueWhenFN"]); /* * public String DataFeedPath { get; set; } //DataFeedUrl or File Path * public DataFeedType CompanyDataFeedType { get; set; } * public TimeSpan UpdateDataFeedFrequency { get; set; } * public DateTime LastUpdateDataFeedTime { get; set; } */ #region Lấy Type của công ty _adtmanagerTypeRCompany = new DBTableAdapters.ManagerTypeRCompanyTableAdapter(); _adtmanagerTypeRCompany.Connection.ConnectionString = Server.ConnectionString; DB.ManagerTypeRCompanyDataTable managerTable = new DB.ManagerTypeRCompanyDataTable(); try { _adtmanagerTypeRCompany.FillBy_IDCompany(managerTable, ID); } catch (Exception) { } if (managerTable.Rows.Count > 0) { IDManagerType = Common.Obj2Int(managerTable.Rows[0]["IDType"].ToString()); } else { IDManagerType = 0; } #endregion } else { Name = "Not In Database"; } }
private void DownloadImageProductSpGoc(MqChangeImage mqProduct, JobClient updateProductJobClient, JobClient downloadImageProductJobClient, JobClient deleteThumbJobClient) { string path = pathImageSPGOC; var productAdapter = new DBTableAdapters.ProductTableAdapter(); var historyDownloadAdapter = new DBTableAdapters.History_DownloadImageProductTableAdapter(); var productTable = new DB.ProductDataTable(); productAdapter.Connection.ConnectionString = connectionString; historyDownloadAdapter.Connection.ConnectionString = connectionString; //bien dem lay du lieu loi tu sql = 3 thì dừng int dem = 0; //lấy dữ liệu từ sql while (checkstop) { try { productAdapter.FillBy_ID(productTable, mqProduct.ProductId); break; } catch (Exception ex) { if (dem == 3) { historyDownloadAdapter.Insert(mqProduct.ProductId, DateTime.Now, false, "Get product from Database error." + ex, false); Log.ErrorFormat("SP Gốc : ProductID = {0} Get product from Database error. \r\n {1}", mqProduct.ProductId, ex); return; } dem++; Thread.Sleep(30000); } } if (productTable.Rows.Count > 0) { string nameProduct = productTable.Rows[0]["Name"].ToString(); string imageUrl = productTable.Rows[0]["ImageUrls"].ToString(); if (string.IsNullOrEmpty(nameProduct) || string.IsNullOrEmpty(imageUrl)) { Log.Error(string.Format("SP Gốc : ProductID = {0} Name or ImageUrl is null or empty.", mqProduct.ProductId)); return; } else { string filename = Common.UnicodeToKoDauAndGach(nameProduct); if (filename.Length > 100) { filename = filename.Substring(0, 99); } string folder = Common.GetFolderSaveImageRootProduct(filename); bool fileSaved = Common.SaveFileDownloadImage(imageUrl, path + folder, filename + ".jpg", mqProduct.ProductId, 6619858476258121218); if (fileSaved) { string pathsave = Common.GetImagePath(folder, filename); int demupdate = 0; while (checkstop) { try { productAdapter.UpdateImagePathAndValid(pathsave, 0, 0, true, mqProduct.ProductId); #region Send Message Update solr and redis Job job = new Job(); job.Data = BitConverter.GetBytes(mqProduct.ProductId); job.Type = 2; updateProductJobClient.PublishJob(job, updateProductJobExpirationMS); //Log.InfoFormat("Send message To RabbitMq {0} with ID = {1}", rabbitMQServerName, productId); #endregion #region Xóa ảnh Thumb nếu có //push message lên service xóa ảnh thumb Job deletejob = new Job(); var thumb = new MqThumbImageInfo { ProductId = mqProduct.ProductId, FolderImage = folder, ImageName = filename, TypeProduct = 2 }; deletejob.Data = MqThumbImageInfo.GetMess(thumb); deleteThumbJobClient.PublishJob(deletejob); #endregion #region Log Finished historyDownloadAdapter.Insert(mqProduct.ProductId, DateTime.Now, true, "SP Gốc", false); #endregion break; } catch (Exception ex) { Thread.Sleep(10000); demupdate++; if (demupdate == 1) { Log.Error(string.Format("SP Gốc : CompanyID = {0} Product = {1}, Update ImagePath Error 1", 6619858476258121218, mqProduct.ProductId), ex); } else if (demupdate == numbererror) { historyDownloadAdapter.Insert(mqProduct.ProductId, DateTime.Now, false, "Update sql fail or push message fail.", false); Log.Error(string.Format("SP Gốc : CompanyID = {0} Product = {1}, Update ImagePath Error {2}", 6619858476258121218, mqProduct.ProductId, numbererror), ex); break; } } } } } } else { historyDownloadAdapter.Insert(mqProduct.ProductId, DateTime.Now, false, "Product not in Database.", false); Log.ErrorFormat("SP Gốc : ProductID = {0} Khong ton tai trong Database.", mqProduct.ProductId); } }
private void UpdateCompany(long companyId) { DBTableAdapters.ProductTableAdapter productAdapter = new DBTableAdapters.ProductTableAdapter(); productAdapter.Connection.ConnectionString = ServerConnection.ConnectionString; DB.ProductDataTable productTable = new DB.ProductDataTable(); int demgetproduct = 0; while (!istopgetdata) { try { productAdapter.FillBy_CompanyDownloaded(productTable, companyId); break; } catch (Exception ex) { demgetproduct++; if (demgetproduct == 1) { Log.Error(string.Format("CompanyID = {0} Get Product of Company in SQL Error 1", companyId), ex); } else if (demgetproduct == 5) { Log.Error(string.Format("CompanyID = {0} Get Product of Company in SQL Error {1}", companyId, 5), ex); break; } Thread.Sleep(10000); } } try { if (productTable.Rows.Count > 0) { this.Invoke(new Action(() => { richTextBox1.AppendText("CompanyID: " + companyId + ": Get " + productTable.Rows.Count + " Product in SQL!\r\n"); })); String path = ServerConnection.FolderImage; int countsuccess = 0; for (int i = 0; i < productTable.Rows.Count; i++) { long productId = Common.Obj2Int64(productTable.Rows[i]["ID"].ToString()); string url = productTable.Rows[i]["DetailUrl"].ToString(); if (string.IsNullOrEmpty(url)) { continue; } Uri root = new Uri(url); string domain = root.DnsSafeHost.Replace("www.", ""); string char1 = domain.Substring(0, 1); String namepath = domain.Substring(0, 1) + "\\" + root.DnsSafeHost.Replace("www.", "").Replace('.', '_'); string direct = namepath + "\\"; string filename = Common.UnicodeToKoDauAndGach(productTable.Rows[i]["Name"].ToString()); string tempf = filename.Replace("-", ""); if (tempf.Length < 3) { continue; } string folder = tempf.Substring(0, 3); if (folder == "bin") { folder = "bin1"; } if (folder == "con") { folder = "con1"; } direct += folder + "\\"; if (filename.Length > 100) { filename = filename.Substring(0, 99); } filename += "_" + productId; String fullfile = path + direct + filename + ".jpg"; string imageurl = string.Empty; imageurl = productTable.Rows[i]["ImageUrls"].ToString(); if (string.IsNullOrEmpty(imageurl)) { Log.Error(string.Format("CompanyID = {0} ProductID = {1} ImageUrl is null or empty.", companyId, productId)); continue; } string pathsave = direct + filename.Replace('\\', '/') + ".jpg"; pathsave = "Store/" + pathsave.Replace('\\', '/'); int demupdate = 0; while (!istopupdate) { try { productAdapter.UpdateQuery(pathsave, 0, 0, productId); //tempAdapter.UpdateImagePathTemp(pathsave, productId); countsuccess++; this.Invoke(new Action(() => { richTextBox1.AppendText(string.Format("{0}.Update Image Path {1}!\r\n", i + 1, productId)); })); break; } catch (Exception) { demupdate++; if (demupdate == 5) { break; } Thread.Sleep(10000); } } } Log.InfoFormat("CompanyID = {0} Download Image Success {1}/{2}", companyId, countsuccess, productTable.Rows.Count); this.Invoke(new Action(() => { richTextBox1.AppendText(string.Format("CompanyID = {0} Download Image Success {1}/{2}-----------------------------\n", companyId, countsuccess, productTable.Rows.Count)); })); } else { this.Invoke(new Action(() => { richTextBox1.AppendText(string.Format("CompanyID = {0} 0 product!-----------------------------\r\n", companyId)); })); } } catch (Exception ex) { } }