コード例 #1
0
ファイル: main.cs プロジェクト: qq858187064/12306
 private void FormatDG()
 {
     for (int i = 0; i < this.dataGridView1.Rows.Count; i++)
     {
         bool canOrder = false;
         DataGridViewDisableButtonCell cell      = (DataGridViewDisableButtonCell)dataGridView1[this.dataGridView1.ColumnCount - 2, i];
         DataGridViewLinkCell          cellCheci = (DataGridViewLinkCell)dataGridView1[0, i];
         for (int j = 4; j < this.dataGridView1.ColumnCount - 2; j++)
         {
             string value = dataGridView1.Rows[i].Cells[j].Value.ToString();
             if (Common.IsNumeric(value) || value.IndexOf("有") > -1)
             {
                 //dataGridView1.Rows[i].Cells[j].Style.BackColor = System.Drawing.Color.Red;
                 canOrder = true;
             }
             else
             {
                 dataGridView1.Rows[i].Cells[j].Style.BackColor = System.Drawing.Color.Gray;
                 continue;
             }
         }
         if (canOrder)
         {
             cell.Tag             = cellCheci.Value;
             cell.Enabled         = true;
             cell.Style.ForeColor = System.Drawing.Color.Red;
         }
         else
         {
             cell.Enabled = false;
             cell.Value   = "无票";
         }
     }
 }
コード例 #2
0
        // Override the Clone method so that the Enabled property is copied.
        public override object Clone()
        {
            DataGridViewDisableButtonCell cell =
                (DataGridViewDisableButtonCell)base.Clone();

            cell.Enabled = this.Enabled;
            return(cell);
        }
コード例 #3
0
ファイル: main.cs プロジェクト: qq858187064/12306
        private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridView dgv = (DataGridView)sender; //如果是"Link"列,被点击

            if (dgv.Columns[e.ColumnIndex].Name == "colCheci")
            {
            }
            if (dgv.Columns[e.ColumnIndex].Name == "colgoupiao")
            {
                DataGridViewDisableButtonCell cell1 = (DataGridViewDisableButtonCell)dgv[e.ColumnIndex, e.RowIndex];
                if (cell1.Value.ToString() == "预定")
                {
                    try
                    {
                        queryThread.Abort();
                        btnQuery.Enabled = true;
                        btnStop.Enabled  = false;
                    }
                    catch
                    {
                    }
                    Application.DoEvents();
                    DataGridViewTextBoxCell cell = (DataGridViewTextBoxCell)dgv[e.ColumnIndex + 1, e.RowIndex];
                    string   selectStr           = cell.Value.ToString();
                    string[] selectStr_arr       = selectStr.Split("#".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    var      station_train_code  = selectStr_arr[0];
                    myTraincode = station_train_code;
                    var train_date = dateCFRQ.Value.ToString("yyyy-MM-dd");
                    myDate = train_date;
                    var lishi     = selectStr_arr[1];
                    var starttime = selectStr_arr[2];
                    var trainno   = selectStr_arr[3];
                    myTrainno = trainno;
                    var from_station_telecode = selectStr_arr[4];
                    var to_station_telecode   = selectStr_arr[5];
                    var arrive_time           = selectStr_arr[6];
                    var from_station_name     = selectStr_arr[7];
                    myFrom = from_station_name;
                    var to_station_name = selectStr_arr[8];
                    myTo = to_station_name;
                    var from_station_no = selectStr_arr[9];
                    myFromno = from_station_telecode;
                    var to_station_no = selectStr_arr[10];
                    myTono = to_station_telecode;
                    var    ypInfoDetail         = selectStr_arr[11];
                    var    mmStr                = selectStr_arr[12];
                    var    include_student      = chkIsStudent.Checked ? "0X00" : "00";
                    var    locationCode         = selectStr_arr[13];
                    var    round_start_time_str = cmboxCFSJ.SelectedItem.ToString();
                    string checi                = string.Empty;
                    for (int i = 0; i < this.panel2.Controls.Count; i++)
                    {
                        CheckBox cbox = (CheckBox)this.panel2.Controls[i];
                        if (cbox.Checked)
                        {
                            checi = checi + cbox.Tag.ToString() + "#";
                        }
                    }
                    string url = "https://dynamic.12306.cn/otsweb/order/querySingleAction.do?method=submutOrderRequest";
                    Dictionary <string, string> dic = new Dictionary <string, string>();
                    dic.Add("station_train_code", station_train_code);
                    dic.Add("train_date", train_date);
                    dic.Add("seattype_num", "");
                    dic.Add("from_station_telecode", from_station_telecode);
                    dic.Add("to_station_telecode", to_station_telecode);
                    dic.Add("include_student", include_student);
                    dic.Add("from_station_telecode_name", System.Web.HttpUtility.UrlEncode(from_station_name));
                    dic.Add("to_station_telecode_name", System.Web.HttpUtility.UrlEncode(to_station_name));
                    dic.Add("round_train_date", System.Web.HttpUtility.UrlEncode(round_start_time_str));
                    dic.Add("single_round_type", "1");
                    dic.Add("train_pass_type", "QB");
                    dic.Add("train_class_arr", System.Web.HttpUtility.UrlEncode(checi));
                    dic.Add("start_time_str", System.Web.HttpUtility.UrlEncode(round_start_time_str));
                    dic.Add("lishi", System.Web.HttpUtility.UrlEncode(lishi));
                    dic.Add("train_start_time", System.Web.HttpUtility.UrlEncode(starttime));
                    dic.Add("trainno4", trainno);
                    dic.Add("arrive_time", System.Web.HttpUtility.UrlEncode(arrive_time));
                    dic.Add("from_station_name", System.Web.HttpUtility.UrlEncode(from_station_name));
                    dic.Add("to_station_name", System.Web.HttpUtility.UrlEncode(to_station_name));
                    dic.Add("from_station_no", from_station_no);
                    dic.Add("to_station_no", to_station_no);
                    dic.Add("ypInfoDetail", ypInfoDetail);
                    dic.Add("mmStr", mmStr);
                    dic.Add("locationCode", locationCode);
                    string data = "";
                    foreach (string key in dic.Keys)
                    {
                        data = data + key + "=" + dic[key] + "&";
                    }
                    data = data.Substring(0, data.Length - 1);
                    this.BeginInvoke((ThreadStart) delegate()
                    {
                        lbCheciInfo.Text = "数据加载中。。。";
                        string str       = HttpHelper.GetResponse(url, "POST", data);
                        if (!str.Contains("目前您还有未处理的订单"))
                        {
                            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                            doc.LoadHtml(str);
                            HtmlNodeCollection node = doc.DocumentNode.SelectNodes("//tr[1]//td");
                            string checiinfo        = "";
                            for (int i = 0; i < node.Count; i++)
                            {
                                string info = node[i].InnerText;
                                info        = info.Replace("\r", "").Replace("\n", "").Replace("\t", "").Replace("&nbsp;", "");
                                if (i == 2)
                                {
                                    var temp    = info;
                                    myStartTime = temp.Replace(myFrom, "").Replace("开", "").Replace("(", "").Replace(")", "").Trim();
                                }
                                if (i == 3)
                                {
                                    var temp  = info;
                                    myEndTime = temp.Replace(myTo, "").Replace("到", "").Replace("(", "").Replace(")", "").Trim();
                                }
                                checiinfo = checiinfo + info + "                 ";
                            }
                            lbCheciInfo.Text      = checiinfo;
                            string _piaojia       = doc.DocumentNode.SelectNodes("//tr[2]")[0].InnerText.Replace("\r", " ").Replace("\n", " ").Replace("\t", " ").Replace("&nbsp;", " ");
                            string[] _piaojiaList = _piaojia.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                            for (int i = 0; i < _piaojiaList.Length; i++)
                            {
                                string info = _piaojiaList[i];
                                piaojia     = piaojia + info + "                 ";
                            }
                            lbPiaojia.Text = piaojia;

                            this.dataGridView1.Height = this.dataGridView1.Height = this.panel3.Height;
                            this.panel3.Show();

                            // 更新 TOKEN
                            url           = "https://dynamic.12306.cn/otsweb/order/confirmPassengerAction.do?method=init";
                            data          = string.Empty;
                            string html   = HttpHelper.GetResponse(url, "POST", data);
                            string temp1  = html;
                            temp1         = temp1.Substring(temp1.IndexOf("name=\"org.apache.struts.taglib.html.TOKEN\" value=\"") + 50);
                            token         = temp1.Substring(0, temp1.IndexOf('"')); // 获取令牌
                            temp1         = html;
                            int index     = temp1.IndexOf("id=\"left_ticket\"");
                            temp1         = temp1.Substring(temp1.IndexOf("id=\"left_ticket\"") + 26);
                            leftTicketStr = temp1.Substring(0, temp1.IndexOf('"'));
                        }
                        else
                        {
                            MessageBox.Show("目前您还有未处理的订单,请先处理订单!");
                        }
                    });
                }
            }
        }