Example #1
0
 public OrderForm(TicketInfo ti)
 {
     InitializeComponent();
     this.ti = ti; 
     LoadVc();
     InitiControl(ti);
 }
Example #2
0
 public OrderForm(TicketInfo ti)
 {
     InitializeComponent();
     this.ti = ti;
     LoadVc();
     InitiControl(ti);
 }
Example #3
0
        private void InitiControl(TicketInfo ti)
        {
            QueryLeftTicketRequestDTO qt = ti.LeftTicketInfo;
            string trainInfo             = qt.train_date + " " + qt.station_train_code + "次 " + qt.from_station_name + "(" + qt.start_time + ") → " + qt.to_station_name + "(" + qt.arrive_time + ") 历时:" + qt.lishi;

            lbStationInfo.Text = trainInfo;
            int      i      = 0;
            int      btnX   = 2;
            int      margin = 0;
            Font     f      = this.Font;
            Graphics g      = this.plSeatType.CreateGraphics();

            foreach (TickePriceInfo tpi in ti.TicketList)
            {
                i++;
                string    seatInfo    = tpi.SeatType + tpi.TicektCnt + "(" + tpi.Price + ") ";
                string    tag         = tpi.SeatType;
                LinkLabel lnkSeatType = new LinkLabel();
                lnkSeatType.LinkBehavior = LinkBehavior.HoverUnderline;
                lnkSeatType.Tag          = tpi.SeatType;
                lnkSeatType.Text         = seatInfo;
                lnkSeatType.Name         = "btnSeatType" + i;
                lnkSeatType.Location     = new Point(btnX, 7);
                lnkSeatType.Font         = f;
                lnkSeatType.ForeColor    = Color.DarkOliveGreen;
                lnkSeatType.FlatStyle    = FlatStyle.Flat;
                g.PageUnit = GraphicsUnit.Display;
                int leng = Convert.ToInt32(g.MeasureString(seatInfo, f).Width) + 10;
                lnkSeatType.Size    = new Size(leng, 30);
                btnX                = btnX + margin + leng;
                lnkSeatType.Enabled = !tpi.TicektCnt.Contains("无");
                plSeatType.Controls.Add(lnkSeatType);
                lnkSeatType.Click += new EventHandler(SelectSeat);
            }
            LoadPassenger(StaticValues.PassengerList);
            //默认选择自己
            for (int j = 0; j < chkListPassenger.Items.Count; j++)
            {
                PassengerDTOs p = (PassengerDTOs)chkListPassenger.Items[j];
                if (p.passenger_name == StaticValues.UserName)
                {
                    chkListPassenger.SetItemCheckState(j, CheckState.Checked);
                    break;
                }
            }
        }
Example #4
0
        private void DoPrevOrder(string orderyKey)
        {
            string msg = string.Empty;

            if (this.InvokeRequired)
            {
                this.BeginInvoke(new MethodInvoker(delegate()
                {
                    this.lbLoding.BringToFront();
                    this.lbLoding.Visible = true;
                }));
            }
            TicketInfo ti = null;

            if (!this.IsDisposed)
            {
                ti = TicketHelper.GetTicketInfo(orderyKey, qe, ref msg);
            }
            Action finishAction = () =>
            {
                this.dgTicket.Enabled = true;
                this.lbLoding.Visible = false;
                if (ti != null)
                {
                    OrderForm of = new OrderForm(ti);
                    of.ShowDialog(this);
                }
                else
                {
                    if (msg != "")
                    {
                        if (msg.Contains("您还有未处理的订单"))
                        {
                            msg = "您还有未处理的订单,请处理完后再订票!";
                        }
                        MessageBox.Show(msg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        msg = "获取车次预订信息失败!";
                    }
                }
            };

            this.BeginInvoke(finishAction);
        }
Example #5
0
 private void InitiControl(TicketInfo ti)
 {
     QueryLeftTicketRequestDTO qt=ti.LeftTicketInfo;
     string trainInfo=qt.train_date+" "+qt.station_train_code+"次 "+qt.from_station_name+"("+qt.start_time+") → "+qt.to_station_name+"("+qt.arrive_time+") 历时:"+qt.lishi;
     lbStationInfo.Text = trainInfo;
     int i = 0;
     int btnX = 2;
     int margin = 0;
     Font f = this.Font;
     Graphics g = this.plSeatType.CreateGraphics();
     foreach (TickePriceInfo tpi in ti.TicketList)
     {
         i++;
         string seatInfo = tpi.SeatType + tpi.TicektCnt + "(" + tpi.Price + ") ";
         string tag = tpi.SeatType;
         LinkLabel lnkSeatType = new LinkLabel();
         lnkSeatType.LinkBehavior = LinkBehavior.HoverUnderline;
         lnkSeatType.Tag = tpi.SeatType;
         lnkSeatType.Text = seatInfo;
         lnkSeatType.Name = "btnSeatType" + i;
         lnkSeatType.Location = new Point(btnX, 7);
         lnkSeatType.Font = f;
         lnkSeatType.ForeColor = Color.DarkOliveGreen;
         lnkSeatType.FlatStyle = FlatStyle.Flat;
         g.PageUnit = GraphicsUnit.Display;
         int leng = Convert.ToInt32(g.MeasureString(seatInfo, f).Width) + 10;
         lnkSeatType.Size = new Size(leng, 30);
         btnX = btnX + margin + leng;
         lnkSeatType.Enabled = !tpi.TicektCnt.Contains("无");
         plSeatType.Controls.Add(lnkSeatType);
         lnkSeatType.Click += new EventHandler(SelectSeat);
     }
     LoadPassenger(StaticValues.PassengerList);
     //默认选择自己
     for (int j = 0; j < chkListPassenger.Items.Count; j++)
     {
         PassengerDTOs p = (PassengerDTOs)chkListPassenger.Items[j];
         if (p.passenger_name == StaticValues.UserName)
         {
             chkListPassenger.SetItemCheckState(j, CheckState.Checked);
             break;
         }
     }
 }
Example #6
0
 private void DoOrder()
 {
     try
     {
         string    canBuyTrainCode = string.Empty;
         DataTable dtTrainCode     = dt.DefaultView.ToTable("TrainCode");
         for (int i = 0; i < dtTrainCode.Rows.Count; i++)
         {
             string trainCode = dtTrainCode.Rows[i][0].ToString().Trim();
             if (canBuyTrainCode == "")
             {
                 canBuyTrainCode = trainCode;
             }
             else
             {
                 canBuyTrainCode = canBuyTrainCode + "," + trainCode;
             }
             canBuyTrainCode = canBuyTrainCode + ",";
         }
         WriteLog("查询到符合条件的车次有" + dt.Rows.Count + "个:" + canBuyTrainCode + ".", txtLog);
         //尝试订票
         string msg  = string.Empty;
         bool   exit = false;
         for (int i = 0; i < dt.Rows.Count; i++)
         {
             if (!exit)
             {
                 DataRow       row        = dt.Rows[i];
                 string        _trainCode = row["TrainCode"].ToString().Trim();
                 List <string> seatList   = GetSeatList(row);
                 if (seatList.Count > 0)
                 {
                     for (int j = 0; j < seatList.Count; j++)
                     {
                         string seatName = seatList[j];
                         string seatType = StaticValues.DicSeatType[seatName];
                         WriteLog("正在尝试预定:" + _trainCode + "次," + seatName, txtLog);
                         string _orderKey = dt.Rows[i]["OrderKey"].ToString().Trim();
                         WriteLog("正在提取预定车次信息...", txtLog);
                         TicketInfo ti = TicketHelper.GetTicketInfo(_orderKey, qe, ref msg);
                         if (ti != null)
                         {
                             List <PassengerInfo> _passengerList = Convert2PassengerInfo(seatType);
                             WriteLog("正在加载并识别验证码...", txtLog);
                             VcForm vcForm = new VcForm(this, ti.Token);
                             if (vcForm.ShowDialog() == DialogResult.OK)
                             {
                                 WriteLog("订单确认中...", txtLog);
                                 bool flag = TicketHelper.CheckOrderInfo(ti.Token, code, _passengerList, ref msg);
                                 if (flag)
                                 {
                                     bool      canBuy   = true;
                                     CountInfo ci       = TicketHelper.GetQueueCount(ti, seatType);
                                     string[]  seatInfo = ci.ticketCnt.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                                     string    info     = string.Empty;
                                     if (seatInfo.Length == 2)
                                     {
                                         info = "本次列车,剩余" + "[" + StaticValues.DicSeatType1[seatType] + "]" + seatInfo[0] + "张,[无座]" + seatInfo[1] + "张。";
                                     }
                                     if (seatInfo.Length == 1)
                                     {
                                         info = "本次列车,剩余" + "[" + StaticValues.DicSeatType1[seatType] + "]" + seatInfo[0] + "张。";
                                     }
                                     if (ci.op_2 == "true")
                                     {
                                         info  += "目前排队人数已经超过余票张数,请您选择其他席别或车次。";
                                         canBuy = false;
                                     }
                                     else
                                     {
                                         if (Convert.ToInt32(ci.countT) > 0)
                                         {
                                             info += "目前排队人数" + ci.countT + "人";
                                         }
                                     }
                                     WriteLog(info, txtLog);
                                     if (canBuy)
                                     {
                                         WriteLog("正在处理订单中,请稍后...", txtLog);
                                         //确认
                                         flag = TicketHelper.ConfirmSingleForQueue(ti, code, _passengerList, ref msg);
                                         WriteLog("订单处理成功,正在检查订单状态...", txtLog);
                                         while (true)
                                         {
                                             var result = TicketHelper.QueryOrderWaitTime(ti.Token);
                                             if (result.waitTime <= 0)
                                             {
                                                 if (result.orderId != "")
                                                 {
                                                     string tip = "恭喜你,订单完成,订单编号为:" + result.orderId + "!";
                                                     MessageBox.Show(tip, "订单成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                                     this.BeginInvoke(new MethodInvoker(delegate()
                                                     {
                                                         TipForm tf = new TipForm(tip, "订单号:" + result.orderId);
                                                         tf.Show();
                                                         this.Close();
                                                     }));
                                                 }
                                                 else
                                                 {
                                                     WriteLog("出票失败,可能没有足够的票!", txtLog);
                                                 }
                                                 break;
                                             }
                                             else
                                             {
                                                 string tip = result.count > 0 ? "你前面还有" + result.count + "个订单要处理,大约需要等待时间:" + result.waitTime + "秒" : "订单正在处理,大概需要等待+:" + result.waitTime + "秒";
                                                 WriteLog(tip, txtLog);
                                                 Thread.Sleep(500);
                                             }
                                         }
                                         break;
                                     }
                                     else
                                     {
                                         this.WriteLog(msg, this.txtLog);
                                     }
                                 }
                                 else
                                 {
                                     exit = true;
                                     if (msg == "")
                                     {
                                         msg = "订单确认失败或者网络超时!";
                                     }
                                     this.WriteLog(msg, this.txtLog);
                                     break;
                                 }
                             }
                             else
                             {
                                 exit = true;
                                 this.WriteLog("提取预定车次信息错误!", this.txtLog);
                                 break;
                             }
                         }
                         else
                         {
                             exit = true;
                             if (msg.Contains("您还有未处理的订单"))
                             {
                                 msg = "您还有未处理的订单,请处理完后再订票!";
                             }
                             this.WriteLog(msg, this.txtLog);
                             break;
                         }
                     }
                 }
                 else
                 {
                     WriteLog(_trainCode + "票数不够!", txtLog);
                 }
             }
         }
         WriteLog("本次自动购票结束!", txtLog);
     }
     catch
     { }
 }