Ejemplo n.º 1
0
 public void Click(ShowcaseRankInfo kw, int maxQueryPageNumber, AliAccounts account, bool canInquiry, InquiryMessages msg)
 {
     this.item = kw;
     this.currentPage = 1;
     this.aliAccount = account;
     this.inquiryMessage = msg;
     this.canInquiry = canInquiry;
     this.maxQueryPage = maxQueryPageNumber;
     this.eventX = new ManualResetEvent(false);
     if (this.aliAccount == null)
     {
         this.canInquiry = false;
     }
     this.clickKey = item.RankKeyword;
     searchProductUrl = string.Format(SEARCH_URL1, clickKey.Replace(" ", "+"));
     ClickingEvent(item, @"Clicking " + searchProductUrl);
     browser.DocumentCompleted -= new WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted);
     browser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(browser_DocumentCompleted);
     IEHandleUtils.Navigate(browser, searchProductUrl, null, additionalHeaders);
     //browser.Navigate(currentRequestUrl, "_self", null, additionalHeaders);
     eventX.WaitOne(Timeout.Infinite, true);
     item = null;
     aliAccount = null;
     inquiryMessage = null;
     Console.WriteLine("线程池结束!");
 }
Ejemplo n.º 2
0
 public ShowcaseRankInfo GetEffctiveProduct()
 {
     string today = DateTime.Now.ToString("yyyyMMdd");
     string sql = "select * from (select distinct k.*, count(i.account) inquiryQty from keywords k "
         + " left join inquiryinfos i on k.productId = i.productId and i.inquiryDate =" + today
         + " where k.status = 2 group by k.productId ) where inquiryQty < maxInquiryQty  order by inquiryQty asc limit 0,1";
     DataTable dt = dbHelper.ExecuteDataTable(sql, null);
     if (dt.Rows.Count > 0)
     {
         DataRow row = dt.Rows[0];
         ShowcaseRankInfo kw = new ShowcaseRankInfo();
         kw.ProductId = Convert.ToInt32(row["productId"]);
         kw.ProductName = (string)row["productName"];
         kw.MainKey = (string)row["mainKey"];
         kw.RankKeyword = (string)row["rankKeyword"];
         kw.CompanyUrl = (string)row["companyUrl"];
         kw.ProductUrl = (string)row["productUrl"];
         kw.ProductImg = (string)row["productImage"];
         kw.PrevRank = Convert.ToInt32(row["prevRank"]);
         kw.Rank = Convert.ToInt32(row["rank"]);
         kw.MaxInquiryQty = Convert.ToInt32(row["maxInquiryQty"]);
         kw.FactInquiryQty = Convert.ToInt32(row["factInquiryQty"]);
         kw.KeyAdNum = Convert.ToInt32(row["keyAdNum"]);
         kw.KeyP4Num = Convert.ToInt32(row["keyP4Num"]);
         kw.Clicked = Convert.ToInt32(row["clicked"]);
         kw.UpdateTime = Convert.ToDateTime(row["updateTime"]);
         return kw;
     }
     return null;
 }
Ejemplo n.º 3
0
 private void MaxInWindow_Load(object sender, EventArgs e)
 {
     keywordDAO = DAOFactory.Instance.GetKeywordDAO();
     rankInfo = keywordDAO.GetShowcaseRankInfo(iModifyProductId);
     this.ProductLabel.Text = rankInfo.ProductName;
     this.oldMaxInquiryQty.Text = rankInfo.MaxInquiryQty.ToString();
     this.NewMaxInquiryQty.Focus();
 }
Ejemplo n.º 4
0
        public List<ShowcaseRankInfo> Seacher(string companyUrl)
        {
            HtmlWeb clinet = new HtmlWeb();
            HtmlDocument document = clinet.Load(companyUrl);
            HtmlNodeCollection nodes = document.DocumentNode.SelectNodes("//div[@id='products-show-normal']/ul/li/div[@class='products-small-info']");

            if (nodes != null)
            {
                foreach (HtmlNode node in nodes)
                {
                    ShowcaseRankInfo item = new ShowcaseRankInfo();
                    item.CompanyUrl = companyUrl;
                    HtmlNode linkNode = node.SelectSingleNode("div[@class='product-info']/a");
                    item.ProductName = linkNode.InnerText;
                    item.ProductUrl = linkNode.Attributes["href"].Value;
                    HtmlNode imgNode = node.SelectSingleNode("div[@class='products-img savm']/a/img");
                    item.Image = imgNode.Attributes["data-src"].Value;
                    showCaseProducts.Add(item);
                }
            }
            MaxCount = showCaseProducts.Count;
            if (MaxCount == 0)
            {
                return showCaseProducts;
            }
            ThreadPool.SetMinThreads(1, 40);
            ThreadPool.SetMaxThreads(1, 200);
            for (int i = 0; i < MaxCount; i++)
            {

                 ThreadPool.QueueUserWorkItem(new WaitCallback(DoWork), (object)i);
            }

            eventX.WaitOne(Timeout.Infinite, true); //WaitOne()方法使调用它的线程等待直到eventX.Set()方法被调用

            WebClient webClient = new WebClient();
            foreach (ShowcaseRankInfo productItem in showCaseProducts)
            {
                try
                {
                    string imageFile = FileUtils.GetImageFolder() + Path.DirectorySeparatorChar + productItem.ProductId + ".jpg";
                    if (File.Exists(imageFile)) File.Delete(imageFile);
                    webClient.DownloadFile(productItem.Image, imageFile);
                    productItem.ProductImg = imageFile;
                }
                catch (Exception e)
                {
                    System.Diagnostics.Trace.WriteLine(e.InnerException.Message);
                    productItem.ProductImg = "";
                }
            }
            webClient.Dispose();
            Console.WriteLine("线程池结束!");
            return showCaseProducts;
        }
Ejemplo n.º 5
0
 public static string GetRankInfo(ShowcaseRankInfo item)
 {
     if (item.Rank == 0)
     {
         return "无排名";
     }
     int page = item.Rank / 38 + 1;
     int location = ( item.Rank % 38 == 0 )? 38 :  item.Rank % 38;
     string msg = (item.Rank == 0) ? "无排名" : "第" + item.Rank + "名,第" + page + "页第" + location + "位";
     if (item.Rank  > 0 && item.PrevRank > 0)
     {
         msg += "\r\n比上次提高了" + (item.PrevRank - item.Rank) + "名";
     }
     msg += "\r\n"+ item.KeyAdNum + "个固定排名";
     msg += "\r\n" + item.KeyP4Num + "个P4P排名";
     msg += "\r\n自然排名" + (item.Rank - item.KeyAdNum - item.KeyP4Num) + "名";
     return msg;
 }
Ejemplo n.º 6
0
 private void ParseProductHtml(ShowcaseRankInfo productItem, HtmlDocument document, HtmlWeb clinet)
 {
     string url = productItem.CompanyUrl + productItem.ProductUrl;
     document = clinet.Load(url);
     string ProductPageHtml = document.DocumentNode.InnerHtml;
     document.LoadHtml(ProductPageHtml);
     HtmlNodeCollection nodes = document.DocumentNode.SelectNodes("//div[@class='related-keywords-box clearfix']/ul/li/a");
     string jsKwString = string.Empty;
     if (nodes != null)
     {
         jsKwString = nodes[0].InnerText;
         if (nodes[1] != null)
         {
             jsKwString = jsKwString + "," + nodes[1].InnerText;
         }
         if (nodes[2] != null)
         {
             jsKwString = jsKwString + "," + nodes[2].InnerText;
         }
     }
     if (!string.IsNullOrEmpty(jsKwString))
     {
         productItem.MainKey = jsKwString;
         System.Diagnostics.Trace.WriteLine(url + " = " + jsKwString);
     }
     string pidString = Regex.Match(ProductPageHtml, PIDExpressions, RegexOptions.IgnoreCase).Groups[1].Value;
     if (!string.IsNullOrEmpty(pidString))
     {
         productItem.ProductId = Convert.ToInt32(pidString);
     }
     ProductPageHtml = null;
     document = null;
 }
Ejemplo n.º 7
0
        public List<ShowcaseRankInfo> Seacher1(string companyUrl)
        {
            HtmlWeb clinet = new HtmlWeb();
            HtmlDocument document = clinet.Load(companyUrl,"GET");
            HtmlNodeCollection nodes = document.DocumentNode.SelectNodes("//div[@id='products-show-normal']/ul/li/div[@class='products-small-info']");

            if (nodes != null)
            {
                foreach (HtmlNode node in nodes)
                {
                    ShowcaseRankInfo item = new ShowcaseRankInfo();
                    item.CompanyUrl = companyUrl;
                    HtmlNode linkNode = node.SelectSingleNode("div[@class='product-info']/a");
                    item.ProductName = linkNode.InnerText;
                    item.ProductUrl = linkNode.Attributes["href"].Value;
                    HtmlNode imgNode = node.SelectSingleNode("div[@class='products-img savm']/a/img");
                    item.Image = imgNode.Attributes["data-src"].Value;
                    showCaseProducts.Add(item);
                }
            }
            WebClient webClient = new WebClient();
            foreach (ShowcaseRankInfo productItem in showCaseProducts)
            {
                try
                {
                    ParseProductHtml(productItem, document, clinet);
                    string imageFile = FileUtils.GetImageFolder() + Path.DirectorySeparatorChar + productItem.ProductId + ".jpg";
                    //if (File.Exists(imageFile)) File.Delete(imageFile);
                    webClient.DownloadFile(productItem.Image, imageFile);
                    productItem.ProductImg = imageFile;
                }
                catch (Exception e)
                {
                    System.Diagnostics.Trace.WriteLine(e.InnerException.Message);
                    productItem.ProductImg = "";
                }
            }
            webClient.Dispose();
            document = null;
            clinet = null;
            Console.WriteLine("橱窗产品解析结束!");
            return showCaseProducts;
        }
Ejemplo n.º 8
0
 public virtual void ClickingEvent(ShowcaseRankInfo kw, string msg)
 {
     if (OnRankClickingEvent != null)
     {
         RankEventArgs e = new RankEventArgs(kw, msg);
         OnRankClickingEvent(this, e);
     }
 }
Ejemplo n.º 9
0
 public RankEventArgs(ShowcaseRankInfo _obj, string _msg)
 {
     this.Item = _obj;
     this.Msg = _msg;
 }
Ejemplo n.º 10
0
        public List<ShowcaseRankInfo> GetProducts(string orderBy)
        {
            string SelectSql = "SELECT distinct k.productId, k.productName, k.mainKey, k.rankKeyword, k.companyUrl, k.productUrl, "
                + "k.productImage, k.prevRank,k.rank, k.keyAdNum, k.keyP4Num, k.clicked, k.updateTime, k.maxInquiryQty,k.status, count(i.account) factInquiryQty "
                + "from keywords k left join inquiryinfos i on k.productId = i.productId and k.status > 0 and i.inquiryDate =" + DateTime.Now.ToString("yyyyMMdd")
                + " group by k.productId";
            if (!string.IsNullOrEmpty(orderBy))
            {
                SelectSql = SelectSql + " order by " + orderBy;
            }
            DataTable dt = dbHelper.ExecuteDataTable(SelectSql, null);

            List<ShowcaseRankInfo> list = new List<ShowcaseRankInfo>();
            foreach (DataRow row in dt.Rows)
            {
                ShowcaseRankInfo kw = new ShowcaseRankInfo();
                kw.ProductId = Convert.ToInt32(row["productId"]);
                kw.ProductName = (string)row["productName"];
                kw.MainKey = (string)row["mainKey"];
                kw.RankKeyword = (string)row["rankKeyword"];
                kw.CompanyUrl = (string)row["companyUrl"];
                kw.ProductUrl = (string)row["productUrl"];
                kw.ProductImg = (string)row["productImage"];
                kw.PrevRank = Convert.ToInt32(row["prevRank"]);
                kw.Rank = Convert.ToInt32(row["rank"]);
                kw.MaxInquiryQty = Convert.ToInt32(row["maxInquiryQty"]);
                kw.FactInquiryQty = Convert.ToInt32(row["factInquiryQty"]);
                kw.KeyAdNum = Convert.ToInt32(row["keyAdNum"]);
                kw.KeyP4Num = Convert.ToInt32(row["keyP4Num"]);
                kw.Clicked = Convert.ToInt32(row["clicked"]);
                kw.UpdateTime = Convert.ToDateTime(row["updateTime"]);
                kw.Status = Convert.ToInt32(row["Status"]);
                list.Add(kw);
            }
            return list;
        }
Ejemplo n.º 11
0
 public ShowcaseRankInfo UpdateRank(ShowcaseRankInfo item)
 {
     Object prank = dbHelper.ExecuteScalar(@"select rank from keywords where productId = " + item.ProductId, null);
     if (Convert.IsDBNull(prank))
     {
         item.PrevRank = 0;
     }else{
         item.PrevRank = Convert.ToInt32(prank);
     }
     string sql = @"UPDATE keywords SET prevRank= @prevRank,  "
         + "rank = @rank, keyAdNum = @keyAdNum, keyP4Num = @keyP4Num, queryStatus = 1,  "
         + "updateTime = @updateTime where productId = @productId ";
     SQLiteParameter[] parameter = new SQLiteParameter[]
     {
         new SQLiteParameter("@prevRank",item.PrevRank),
         new SQLiteParameter("@rank",item.Rank),
         new SQLiteParameter("@keyAdNum",item.KeyAdNum),
         new SQLiteParameter("@keyP4Num",item.KeyP4Num),
         new SQLiteParameter("@updateTime", DateTime.Now),
         new SQLiteParameter("@productId",item.ProductId),
          new SQLiteParameter("@productId",item.ProductId)
     };
     item.QueryStatus = dbHelper.ExecuteNonQuery(sql, parameter);
     return item;
 }
Ejemplo n.º 12
0
 public void UpdateClicked(ShowcaseRankInfo kw)
 {
     string sql = @"UPDATE keywords SET clicked = @clicked, updateTime = @updateTime where productId = @productId";
     SQLiteParameter[] parameter = new SQLiteParameter[]
     {
         new SQLiteParameter("@clicked",kw.Clicked),
         new SQLiteParameter("@updateTime", DateTime.Now),
         new SQLiteParameter("@productId",kw.ProductId)
     };
     dbHelper.ExecuteNonQuery(sql, parameter);
 }
Ejemplo n.º 13
0
        public ShowcaseRankInfo GetShowcaseRankInfo(int ProductId)
        {
            DataTable dt = dbHelper.ExecuteDataTable(
                  "SELECT productId, productName, mainKey, rankKeyword, companyUrl, productUrl, "
                + "productImage, prevRank,rank, keyAdNum, keyP4Num, clicked, updateTime , maxInquiryQty, factInquiryQty, status  "
                + "FROM keywords where productId = " + ProductId, null);

            if (dt.Rows.Count > 0)
            {
                DataRow row = dt.Rows[0];
                ShowcaseRankInfo kw = new ShowcaseRankInfo();
                kw.ProductId = Convert.ToInt32(row["productId"]);
                kw.ProductName = (string)row["productName"];
                kw.MainKey = (string)row["mainKey"];
                kw.RankKeyword = (string)row["rankKeyword"];
                kw.CompanyUrl = (string)row["companyUrl"];
                kw.ProductUrl = (string)row["productUrl"];
                kw.ProductImg = (string)row["productImage"];
                kw.PrevRank = Convert.ToInt32(row["prevRank"]);
                kw.Rank = Convert.ToInt32(row["rank"]);
                kw.MaxInquiryQty = Convert.ToInt32(row["maxInquiryQty"]);
                kw.FactInquiryQty = Convert.ToInt32(row["factInquiryQty"]);
                kw.KeyAdNum = Convert.ToInt32(row["keyAdNum"]);
                kw.KeyP4Num = Convert.ToInt32(row["keyP4Num"]);
                kw.Clicked = Convert.ToInt32(row["clicked"]);
                kw.Status = Convert.ToInt32(row["status"]);
                return kw;
            }
            return null;
        }