寫左15分鐘...
- using System;
- using System.ComponentModel;
- using System.Data;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Xml.Linq;
- namespace HKJC
- {
- public partial class ApplicationMain : DevExpress.XtraEditors.XtraForm
- {
-
- BindingList<DataModel.ResultModel> bind = new BindingList<DataModel.ResultModel>();
- public ApplicationMain()
- {
- InitializeComponent();
- oddsGridControl.DataSource = bind;
- }
- private void ApplicationMain_Shown(object sender, EventArgs e)
- {
- string result = "";
- var request = (HttpWebRequest)HttpWebRequest.Create(new Uri("http://bet.hkjc.com/racing/getXML.aspx?type=win&RaceNo=2"));
- request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
- request.Method = "GET";
- request.ContentType = "text/xml; encoding='utf-8'";
- using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
- {
- using (StreamReader sr = new StreamReader(response.GetResponseStream()))
- {
- result = sr.ReadToEnd();
- }
- }
- XDocument doc = XDocument.Parse(result);
- var rows = doc.Descendants("OUT").Select(sl => new
- {
- NUM = (int)sl.Attribute("NUM"),
- ODDS = sl.Value,
- WILLPAY = sl.Attribute("WILLPAY").Value,
- HF = sl.Attribute("HF").Value,
- BIG_DROP = sl.Attribute("BIG_DROP").Value,
- ODDSDROP = sl.Attribute("ODDSDROP").Value,
- });
- foreach (var t in rows)
- {
- //System.Diagnostics.Debug.WriteLine(t.NUM);
- bind.Add(new DataModel.ResultModel(t.NUM, t.ODDS, t.WILLPAY, t.HF, t.BIG_DROP, t.ODDSDROP));
- }
- System.Diagnostics.Debug.WriteLine("Well Done");
- }
- }
- }
複製代碼- using System;
- namespace HKJC.DataModel
- {
- [Serializable]
- public class ResultModel
- {
- public int NUM { get; set; }
- public string ODDS { get; set; }
- public string WILLPAY { get; set; }
- public string HF { get; set; }
- public string BIG_DROP { get; set;}
- public string ODDSDROP { get; set; }
- public ResultModel(int _num, string _odds, string _willpay, string _hf, string _big_drop, string _oddsdrop) {
- NUM = _num;
- ODDS = _odds;
- WILLPAY = _willpay;
- HF = _hf;
- BIG_DROP = _big_drop;
- ODDSDROP = _oddsdrop;
- }
- }
- }
複製代碼 |