public TrainLeftTicketStatus(DateTime date, string[] status, AttentionItem attentionItem = null) { Status = status; Date = date; UpdateTime = DateTime.Now; this.TrainNo = Regex.Match(status[0], ">(?<no>[^<]+)</span>").Groups["no"].Value; AttentionItem = attentionItem; var parts = status[1].Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); int offset = 0; if (parts[0].StartsWith("<img")) offset++; StartTime = parts[offset + 2]; this.FromSationName = parts[offset]; parts = status[2].Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); offset = 0; if (parts[0].StartsWith("<img")) offset++; EndTime = parts[offset + 2]; this.ToStationName = parts[offset]; CostTime = status[3]; var counters = new Dictionary<string, int>(); for (int j = 0; j < RunTimeData.SeatTypeNames.Length; j++) { var val = status[4 + j]; if (val == "--") { counters[RunTimeData.SeatTypeNames[j]] = -1; } else if (val.IndexOf('无') != -1) { counters[RunTimeData.SeatTypeNames[j]] = 0; } else if (val.IndexOf('*') != -1) { counters[RunTimeData.SeatTypeNames[j]] = 0; } else if (val.IndexOf('有') != -1) { counters[RunTimeData.SeatTypeNames[j]] = 99999; } else { counters[RunTimeData.SeatTypeNames[j]] = int.Parse(val); } } SeatCounters = counters; if (counters.Count == 0) { this.LeftTicketDescription = "无数据"; CanBook = false; } else { var list = new List<string>(counters.Count); foreach (var item in counters) { if (item.Value > 0) { if (item.Value >= 99999) { list.Add(string.Format("{0}:有", item.Key, item.Value)); } else { list.Add(string.Format("{0}:{1}张", item.Key, item.Value)); } } } CanBook = list.Count > 0; if (list.Count == 0) { this.LeftTicketDescription = "--"; } else { this.LeftTicketDescription = string.Join(",", list.ToArray()); } } }
public void RunCheck(AttentionItem item) { var query = new NameValueCollection(); query["method"] = "queryLeftTicket"; query["orderRequest.train_date"] = item.Date.ToString("yyyy-MM-dd"); query["orderRequest.from_station_telecode"] = item.FromStation.Code; query["orderRequest.to_station_telecode"] = item.ToStation.Code; query["orderRequest.train_no"] = item.Train != null ? item.Train.id : ""; query["trainPassType"] = "QB"; query["trainClass"] = "QB#D#Z#T#K#QT#"; query["includeStudent"] = "00"; query["seatTypeAndNum"] = ""; query["orderRequest.start_time_str"] = "00:00--24:00"; HTTP.Request(new HttpRequest() { OperationName = "后台查询关注票" + item.Key, Method = "GET", Url = Properties.Settings.Default.QuerySingleActionUrl + "?" + HTTP.ToString(query), Referer = Properties.Settings.Default.QuerySingleActionUrl + "?method=init", MaxRetryCount = 0, OnCancel = (req, reasion) => { }, OnHtml = (req, uri, html) => { bool needUpdate = false; bool isAttentionAvailable = false; lock (InnerLeftTicketStatus) { var rawStatus = html.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (rawStatus.Length > 0 && (rawStatus.Length - 1) % 16 == 0) { needUpdate = true; InnerLeftTicketStatus.RemoveAll(v => v.Key == item.Key); int count = (rawStatus.Length - 1) >> 4; for (int i = 0; i < count; i++) { var status = new string[16]; Array.Copy(rawStatus, 1 + (i << 4), status, 0, 16); var itemStatus = new TrainLeftTicketStatus(item.Date, status, item); InnerLeftTicketStatus.Add(itemStatus); if (itemStatus.IsAttentionAvailable) { isAttentionAvailable = true; } } InnerLeftTicketStatus.Sort( (l, r)=>r.IsAttentionAvailable.CompareTo(l.IsAttentionAvailable)); } DetermineCall(() => { if (needUpdate) { LeftTicketStatus.ResetBindings(); } }); } if (isAttentionAvailable) { MainForm.ShowMyAttentionTicketsForm(true); } } }); }
private void btnQueryLeftTickets_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(cbxFrom.Text)) { MessageBox.Show(this, "请输入出发地", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(cbxTo.Text)) { MessageBox.Show(this, "请输入目的地", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var fromSation = Array.Find(RunTimeData.Stations, v => v.Name == cbxFrom.Text || v.ShortCut == cbxFrom.Text); if (fromSation == null) { MessageBox.Show(this, "请输入正确的出发地", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var toStation = Array.Find(RunTimeData.Stations, v => v.Name == cbxTo.Text || v.ShortCut == cbxTo.Text); if (toStation == null) { MessageBox.Show(this, "请输入正确的目的地", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (cbxFrom.Text != fromSation.Name) { cbxFrom.Text = fromSation.Name; } if (cbxTo.Text != toStation.Name) { cbxTo.Text = toStation.Name; } var query = new NameValueCollection(); query["method"] = "queryLeftTicket"; query["orderRequest.train_date"] = dtpGoDate.Value.Date.ToString("yyyy-MM-dd"); query["orderRequest.from_station_telecode"] = fromSation.Code; query["orderRequest.to_station_telecode"] = toStation.Code; query["orderRequest.train_no"] = "";// cbxTrainNo.SelectedValue as string; query["trainPassType"] = Array.Find(rbTrainPassTypes, v => v.Checked).Tag as string; var trainClass = new List<string>(); Array.ForEach(Array.FindAll(cbxTrainTypes, v => v.Checked), v => trainClass.Add(v.Tag as string)); query["trainClass"] = string.Join("#", trainClass.ToArray()) + "#"; ; query["includeStudent"] = Array.Find(rbStudentFlags, v => v.Checked).Tag as string; ; query["seatTypeAndNum"] = ""; query["orderRequest.start_time_str"] = cbxGoTime.SelectedItem as string; //btnQueryLeftTickets.Enabled = false; btnQueryLeftTickets.Text = "查询中……"; _CurrentQueryRequest = new HttpRequest() { OperationName = "查询余票", Method = "GET", Url = Properties.Settings.Default.QuerySingleActionUrl + "?" + HTTP.ToString(query), Referer = Properties.Settings.Default.QuerySingleActionUrl + "?method=init", MaxRetryCount = 0, OnCancel = (req, reasion) => { DetermineCall(() => { btnQueryLeftTickets.Enabled = true; btnQueryLeftTickets.Text = "查询"; }); }, OnHtml = (req, uri, html) => { try { var rawStatus = html.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); _LeftTicketStatus.Clear(); if (rawStatus.Length > 0 && (rawStatus.Length - 1) % 16 == 0) { int count = (rawStatus.Length - 1) >> 4; for (int i = 0; i < count; i++) { var status = new string[16]; Array.Copy(rawStatus, 1 + (i << 4), status, 0, 16); var aItem = new AttentionItem() { Date = dtpGoDate.Value.Date, FromStation = fromSation, ToStation = toStation }; var item = new TrainLeftTicketStatus(dtpGoDate.Value.Date, status, aItem); _LeftTicketStatus.Add(item); } } else { } DetermineCall(() => { _BindingLeftTicketStatus.ResetBindings(); }); } catch (Exception ex) { } btnQueryLeftTickets.Enabled = true; btnQueryLeftTickets.Text = "查询"; } }; QueryLeftTicketStatus(); }