Beispiel #1
0
 private void button11_Click(object sender, EventArgs e)
 {
     TranTime.Clear();
 }
Beispiel #2
0
        private static ParameterizedThreadStart ThreadStart()
        {
            //int m = 6 * 100;
            //int n = 0;
            return((o) =>
            {
                object[] objs = o as object[];
                var times = objs[0] as List <string>;
                var checkedItemCollection = objs[1] as CheckedListBox.CheckedItemCollection;
                var Seats = objs[2] as List <SeatsType>;
                var from1 = objs[3] as Form1;
                var checkedPeople = objs[4] as CheckedListBox.CheckedItemCollection;
                List <Train> selectTrainList = new List <Train>();
                foreach (Train v in checkedItemCollection)
                {
                    selectTrainList.Add(v);
                }
                List <Contact> selectContactList = new List <Contact>();
                foreach (Contact v in checkedPeople)
                {
                    selectContactList.Add(v);
                }
                ConfigStore.lastFailedTime = DateTime.Now;
                while (start)
                {
                    foreach (var time in times)
                    {
                        //n = 0;
                        var tempTrainList = _12306Class.GetTrains(time
                                                                  , _12306Class.From.Code
                                                                  , _12306Class.To.Code);
                        if (tempTrainList == null || tempTrainList.Count == 0)
                        {
                            ShowMessage(null, new List <Message>()
                            {
                                new Message("系统异常", Color.Red)
                            });
                            break;
                        }
                        bool hasTask = false;
                        bool GetTickTrue = false;
                        foreach (Train train in selectTrainList)
                        {
                            if (hasTask)
                            {
                                break;
                            }
                            var tempTrain = tempTrainList.SingleOrDefault(fun => fun.TrainValue == train.TrainValue);
                            if (tempTrain == null)
                            {
                                ShowMessage(null,
                                            new List <Message>()
                                {
                                    new Message("车次(" + train.TrainValue + ")不存在", Color.Yellow)
                                });
                                continue;
                            }
                            List <Message> listMessage = new List <Message>();
                            listMessage.Add(new Message("正在检查"));
                            listMessage.Add(new Message(train.TrainValue, Color.Yellow));
                            listMessage.Add(new Message(".."));

                            ShowMessage(null, listMessage);
                            listMessage.Clear();
                            foreach (SeatsType trainSeat in Seats)
                            {
                                if (hasTask)
                                {
                                    break;
                                }
                                switch (trainSeat)
                                {
                                case SeatsType.商务座:
                                    hasTask = HasTask(train.SWZ);
                                    break;

                                case SeatsType.特等座:
                                    hasTask = HasTask(train.TZ);
                                    break;

                                case SeatsType.一等座:
                                    hasTask = HasTask(train.ZY);
                                    break;

                                case SeatsType.二等座:
                                    hasTask = HasTask(train.ZE);
                                    break;

                                case SeatsType.高级软卧:
                                    hasTask = HasTask(train.GR);
                                    break;

                                case SeatsType.软卧:
                                    hasTask = HasTask(train.RW);
                                    break;

                                case SeatsType.硬卧:
                                    hasTask = HasTask(train.YW);
                                    break;

                                case SeatsType.软座:
                                    hasTask = HasTask(train.RZ);
                                    break;

                                case SeatsType.硬座:
                                    hasTask = HasTask(train.YZ);
                                    break;

                                case SeatsType.无座:
                                    hasTask = HasTask(train.WZ);
                                    break;
                                }


                                if (hasTask)
                                {
                                    ShowMessage(null, new List <Message>()
                                    {
                                        new Message(trainSeat.ToString() + ":" + "有..")
                                    });

                                    if (checkedPeople.Count <= 0)
                                    {
                                        ShowMessage(null,
                                                    new List <Message>()
                                        {
                                            new Message("未选择常用联系人,不进行预订。", Color.Yellow)
                                        });
                                        //如果未选择常用联系人,则不订票
                                        hasTask = false;
                                    }
                                }
                                else
                                {
                                    ShowMessage(null,
                                                new List <Message>()
                                    {
                                        new Message(trainSeat.ToString() + ":" + "无..")
                                    });
                                }

                                if (hasTask)
                                {
                                    // from1.button12_Click(null, null);
                                    GetTickTrue = GetTask(train, time, trainSeat, selectContactList);
                                    if (GetTickTrue)
                                    {
                                        from1.button12_Click(null, null);
                                    }
                                }
                            }
                            ShowMessage(null, listMessage);
                        }

                        //foreach (SeatsType trainSeat in selectTrainList)
                        //{
                        //    var seat = _trainSeat.List.SingleOrDefault(fun => fun.Name == trainSeat.ToString() && fun.Count != "无");
                        //    if (seat != null)
                        //    {
                        //        HasTask(_trainSeat, time, seat);

                        //        break;
                        //    }
                        //}

                        /*while (start && n < m)
                         * {
                         *  n++;
                         *  Thread.Sleep(10);
                         * }*/
                        Thread.Sleep(200);
                        if (hasTask && GetTickTrue)
                        {
                            if (ConfigStore.yesFailedTimes < ConfigStore.failedTimes)
                            {
                                DateTime dt1 = ConfigStore.lastFailedTime;
                                int cha = TranTime.DateDiff(DateTime.Now, dt1) / 1000;
                                if (cha < 20)
                                {
                                    ConfigStore.yesFailedTimes++;
                                    Program.mainForm.ShowMessage(String.Format("自动输入验证码,失败{0}次", ConfigStore.yesFailedTimes));
                                }
                                else
                                {
                                    ConfigStore.yesFailedTimes = 0;
                                }
                                ConfigStore.lastFailedTime = DateTime.Now;
                            }
                            else
                            {
                                Program.mainForm.ShowMessage(String.Format("自动输入验证码失败次数超过{0}次,改为手动输入!", ConfigStore.failedTimes));
                                Program.mainForm.SetAutoWriterVerify(false);
                            }
                        }
                    }
                }


                end = true;
                ShowMessage(null, new List <Message>()
                {
                    new Message(string.Format("线程{0}已经停止...", thread.ManagedThreadId))
                });
                if (ThreadClosed != null)
                {
                    ThreadClosed(null, null);
                }
            });
        }
Beispiel #3
0
 private void button1_Click(object sender, EventArgs e)
 {
     TranTime.AddTime(dateTimePicker1.Value.ToString("yyyy-MM-dd"));
     this.Dispose();
 }