示例#1
0
 public virtual void FinishedEvent(TopFiveInfo kw, string msg)
 {
     if (OnTopFiveSearchEndEvent != null)
     {
         TopFiveEventArgs e = new TopFiveEventArgs(kw, msg);
         OnTopFiveSearchEndEvent(this, e);
     }
 }
示例#2
0
 public TopFiveEventArgs(TopFiveInfo _obj, string _msg)
 {
     this.Item = _obj;
     this.Msg = _msg;
 }
示例#3
0
        public void Seacher(string key)
        {
            HtmlDocument document = null;
            int p4pNum = 0;
            int adaNum = 0;
            string url = string.Format(SEARCH_URL, key.Replace(" ", "+"), 1);
            HtmlWeb clinet = new HtmlWeb();
            document = clinet.Load(url);
            HtmlNodeCollection itemNodes = document.DocumentNode.SelectNodes(PATH);
            HtmlNodeCollection adNodes = document.DocumentNode.SelectNodes(AD_PATH);
            HtmlNodeCollection p4pNodes = document.DocumentNode.SelectNodes(P4P_PATH);
            HtmlNodeCollection p4pv2Nodes = document.DocumentNode.SelectNodes(P4PV2_PATH);
            if (adNodes != null)
            {
                adaNum = adNodes.Count;
            }
            if (p4pNodes != null)
            {
                p4pNum = p4pNodes.Count;
            }
            if (p4pv2Nodes != null)
            {
                p4pNum = p4pNum + p4pv2Nodes.Count;
            }
            int itemCount = itemNodes.Count;
            int kcount = itemCount >= 10 ? 10 : itemCount;
            for (int k = 0; k < kcount; k++)
            {
                TopFiveInfo item = new TopFiveInfo();
                item.KeyP4Num = p4pNum;
                item.KeyAdNum = adaNum;
                HtmlNode percentNode = itemNodes[k];

                HtmlNode ImageNode = percentNode.SelectSingleNode(IMAGE_PATH);
                string src = ImageNode.Attributes["image-src"].Value;
                string productId = ImageNode.Id.Replace("limage_", "");
                try
                {
                    WebClient webClient = new WebClient();
                    string imageFile = FileUtils.GetPhotoBankFolder() + Path.DirectorySeparatorChar + productId + ".jpg";
                    if (File.Exists(imageFile)) File.Delete(imageFile);
                    webClient.DownloadFile(src, imageFile);
                    item.Image = imageFile;
                    webClient.Dispose();
                }
                catch (Exception e)
                {
                    System.Diagnostics.Trace.WriteLine(e.InnerException.Message);
                    item.Image = "";
                }

                HtmlNode aLinkNode = percentNode.SelectSingleNode(SUBJECT_PATH);
                item.Name = aLinkNode.InnerText;
                item.Href = aLinkNode.Attributes["href"].Value;
                HtmlDocument document1 = new HtmlWeb().Load(item.Href);
                string ProductPageHtml = document1.DocumentNode.InnerHtml;
                string jsKwString = Regex.Match(ProductPageHtml, KeywordExpressions, RegexOptions.IgnoreCase).Groups[1].Value;
                if (!string.IsNullOrEmpty(jsKwString))
                {
                    item.Key = jsKwString.Replace(",", ",\n");
                 }
                string category = document1.DocumentNode.SelectSingleNode("//div[@class='crumb global']").InnerText;
                item.Category = category.Replace("\t", "").Replace("\n", "").Replace("&gt;", ">").Replace("  ", "").Replace("&amp;","&");
                string descrption = document1.DocumentNode.SelectSingleNode("//div[@id='richTextDescription']").PreviousSibling.PreviousSibling.InnerHtml;
                item.Desc = descrption.Replace("<br>", "");
                ProductPageHtml = null;
                document1 = null;
                FinishedEvent(item, "Rank search finished.");
            }
        }
示例#4
0
 void query_OnTopFiveSearchEndEvent(object sender, TopFiveEventArgs e)
 {
     TopFiveInfo item = e.Item;
     lastTopFiveInfo = e.Item;
     if (dataGridView.InvokeRequired)
     {
         UpdateDataGridView uActive = LoadItemToDataView;
         this.BeginInvoke(uActive, new object[] { item });
     }
     else
     {
         LoadItemToDataView(item);
     }
 }
示例#5
0
 void LoadItemToDataView(TopFiveInfo item)
 {
     DataTable dt = (DataTable)this.dataGridView.DataSource;
     DataRow row = dt.NewRow();
     if (string.IsNullOrEmpty(item.Image) || !File.Exists(item.Image))
     {
         row["Image"] = global::AliHelper.Properties.Resources.no_image;
     } else {
         row["Image"] = new Bitmap(Image.FromFile(item.Image));
     }
     row["Name"] = item.Name;
     row["Key"] = item.Key;
     row["Desc"] = item.Desc;
     row["Cate"] = item.Category;
     row["Href"] = item.Href;
     dt.Rows.Add(row);
 }