private void ModifyViewItem(_GoldPrice goodInfo) { ListViewItem li = new ListViewItem(); li.SubItems.Clear(); // li.SubItems[0].Text = listView.Items.Count.ToString(); li.SubItems[0].Text = goodInfo.perPrice.ToString(); // li.SubItems.Add(goodInfo.perPrice.ToString()); li.SubItems.Add(goodInfo.weight.ToString()); li.SubItems.Add(goodInfo.totalPrice.ToString()); li.SubItems.Add(goodInfo.strName); li.SubItems.Add(goodInfo.strUrl); if (goodInfo.perPrice < 340) { li.BackColor = Color.Green; } else if (goodInfo.perPrice < 350) { li.BackColor = Color.Pink; } else if (goodInfo.perPrice > 360) { li.BackColor = Color.Red; } else { li.BackColor = Color.Yellow; } listView.Items.Add(li); }
private string AnanyzePageData(string strRet) { if (m_iFreshType == 1) { return(AnanyzePageDataEx(strRet)); } string strInfo = ""; string strFindFlag = "价格:"; while (true) { int nIndex = strRet.IndexOf(strFindFlag); if (nIndex < 0) { break; } string strBefore = strRet.Substring(0, nIndex); int nPos = strBefore.LastIndexOf("<a "); strBefore = strBefore.Substring(nPos); string strAfter = strRet.Substring(nIndex); string strDetailUrl = "http://www.amazon.cn" + GetKeyString(strBefore, "href=\"", "\""); string strName = GetKeyString(strBefore, ">", "</a>"); string strPrice = GetKeyString(strAfter, "price\">", "</b>"); if (strPrice.IndexOf("-") < 0) { strPrice = strPrice.Replace("¥", ""); strPrice = strPrice.Replace(",", ""); strPrice = strPrice.Trim(); float price = -10.0f; float.TryParse(strPrice, out price); float weight = GetWeight(strName); if (weight > 0 && price > 0) { _GoldPrice gold = new _GoldPrice(); gold.weight = weight; gold.totalPrice = price; gold.perPrice = price / weight; gold.strName = strName; gold.strUrl = strDetailUrl; ShowInfo(gold); } else { AddToList(strDetailUrl); } } else { AddToList(strDetailUrl); } strRet = strRet.Substring(nIndex + strFindFlag.Length); } return(strRet); }
public void ShowInfo(_GoldPrice goodInfo) { try { if (listView.InvokeRequired) { ShowEventHandler _myInvoke = new ShowEventHandler(AddToList); this.Invoke(_myInvoke, new object[] { goodInfo }); } else { AddToList(goodInfo); } } catch (Exception e) { string strError = e.Message; } }
public void AnanyzeData(string strRet, string strUrl) { strRet = strRet.ToLower(); int nPos = strRet.IndexOf("id=\"btasintitle\""); if (nPos < 0) { return; } strRet = strRet.Substring(nPos); string strName = GetKeyString(strRet, ">", "</span>"); nPos = strRet.IndexOf("id=\"actualpricevalue\""); if (nPos < 0) { return; } strRet = strRet.Substring(nPos); string strPrice = GetKeyString(strRet, "¥", "<"); strPrice = strPrice.Replace(",", ""); strPrice = strPrice.Trim(); float weight = GetWeight(strName); float price = 0f; float.TryParse(strPrice, out price); if (price > 0 && weight > 0) { _GoldPrice gold = new _GoldPrice(); gold.perPrice = price / weight; gold.totalPrice = price; gold.weight = weight; gold.strName = strName; gold.strUrl = strUrl; m_goldPriceList.Add(gold); ShowInfo(gold); } }
private string AnanyzePageData(string strRet) { if (m_iFreshType == 1) { return AnanyzePageDataEx(strRet); } string strInfo = ""; string strFindFlag = "价格:"; while (true) { int nIndex = strRet.IndexOf(strFindFlag); if (nIndex < 0) break; string strBefore = strRet.Substring(0, nIndex); int nPos = strBefore.LastIndexOf("<a "); strBefore = strBefore.Substring(nPos); string strAfter = strRet.Substring(nIndex); string strDetailUrl = "http://www.amazon.cn" + GetKeyString(strBefore, "href=\"", "\""); string strName = GetKeyString(strBefore, ">", "</a>"); string strPrice = GetKeyString(strAfter, "price\">", "</b>"); if (strPrice.IndexOf("-") < 0) { strPrice = strPrice.Replace("¥", ""); strPrice = strPrice.Replace(",", ""); strPrice = strPrice.Trim(); float price = -10.0f; float.TryParse(strPrice, out price); float weight = GetWeight(strName); if (weight > 0 && price > 0) { _GoldPrice gold = new _GoldPrice(); gold.weight = weight; gold.totalPrice = price; gold.perPrice = price / weight; gold.strName = strName; gold.strUrl = strDetailUrl; ShowInfo(gold); } else { AddToList(strDetailUrl); } } else { AddToList(strDetailUrl); } strRet = strRet.Substring(nIndex + strFindFlag.Length); } return strRet; }
private void AddToList(_GoldPrice gold) { WriteLogEx(string.Format("{0} {1} {2} {3} {4}", gold.perPrice, gold.weight, gold.totalPrice, gold.strName, gold.strUrl)); ModifyViewItem(gold); }
public void ShowInfo(_GoldPrice goodInfo) { try { if (listView.InvokeRequired) { ShowEventHandler _myInvoke = new ShowEventHandler(AddToList); this.Invoke(_myInvoke, new object[] { goodInfo }); } else { AddToList(goodInfo); } } catch(Exception e) { string strError = e.Message; } }
private void ModifyViewItem(_GoldPrice goodInfo) { ListViewItem li = new ListViewItem(); li.SubItems.Clear(); // li.SubItems[0].Text = listView.Items.Count.ToString(); li.SubItems[0].Text = goodInfo.perPrice.ToString(); // li.SubItems.Add(goodInfo.perPrice.ToString()); li.SubItems.Add(goodInfo.weight.ToString()); li.SubItems.Add(goodInfo.totalPrice.ToString()); li.SubItems.Add(goodInfo.strName); li.SubItems.Add(goodInfo.strUrl); if (goodInfo.perPrice < 340) li.BackColor = Color.Green; else if (goodInfo.perPrice < 350) li.BackColor = Color.Pink; else if (goodInfo.perPrice > 360) li.BackColor = Color.Red; else li.BackColor = Color.Yellow; listView.Items.Add(li); }
public void AnanyzeData(string strRet, string strUrl) { strRet = strRet.ToLower(); int nPos = strRet.IndexOf("id=\"btasintitle\""); if(nPos < 0) return; strRet = strRet.Substring(nPos); string strName = GetKeyString(strRet, ">", "</span>"); nPos = strRet.IndexOf("id=\"actualpricevalue\""); if (nPos < 0) return; strRet = strRet.Substring(nPos); string strPrice = GetKeyString(strRet, "¥", "<"); strPrice = strPrice.Replace(",", ""); strPrice = strPrice.Trim(); float weight = GetWeight(strName); float price = 0f; float.TryParse(strPrice, out price); if (price > 0 && weight > 0) { _GoldPrice gold = new _GoldPrice(); gold.perPrice = price / weight; gold.totalPrice = price; gold.weight = weight; gold.strName = strName; gold.strUrl = strUrl; m_goldPriceList.Add(gold); ShowInfo(gold); } }