private void timer1_Tick(object sender, EventArgs e) { try { SinaBean bean = GetWebContent(ConfigurationManager.AppSettings["SH_CD"]); string percent = convertPercent(bean.Percent); lblSh1.Text = bean.Price + "+" + bean.Turnover + percent; double dblMax = double.Parse(txtShMax.Value); double dblMin = double.Parse(txtShMin.Value); double dblPrice = double.Parse(bean.Price); if (dblPrice >= dblMax || dblPrice <= dblMin) { this.Activate(); this.BringToFront(); this.Focus(); if (bean.Price.CompareTo(txtShMax.Value + ".000") >= 0) { timer1.Stop(); msg.Information("↑" + bean.Price + label1.Text + bean.Turnover + percent); timer1.Start(); } else { timer1.Stop(); msg.Information("↓" + bean.Price + label1.Text + bean.Turnover + percent); timer1.Start(); } } } catch { } }
private SinaBean GetWebContent(string cd) { SinaBean bean = new SinaBean(); string url = String.Format(SINA_GB_URL, cd); byte[] buffer = client.DownloadData(url); string hqStr = Encoding.GetEncoding("GB2312").GetString(buffer, 0, buffer.Length); String[] arr = hqStr.Split(','); bean.Name = arr[0]; bean.Price = arr[1]; bean.Offset = arr[2]; bean.Percent = arr[3]; bean.Turnover = Int32.Parse(arr[5].Substring(0, arr[5].Length - 3)) / 10000; return(bean); }