private void button1_Click(object sender, EventArgs e) { backgroundWorker1.CancelAsync(); SeatKiller.username = comboBox1.Text; SeatKiller.password = textBox1.Text; string response = SeatKiller.GetToken(false); if (response == "Success") { if (checkBox1.Checked) { User.SetValue(comboBox1.Text, textBox1.Text); } Hide(); if (!SeatKiller.CheckResInf()) { SeatKiller.exitFlag = false; Config config = new Config(); config.Show(); } Close(); } else if (response == "System Maintenance") { MessageBox.Show("系统维护中(23:45 ~ 0:15)", "登录失败"); if (!backgroundWorker1.IsBusy) { backgroundWorker1.RunWorkerAsync(); } } else if (response == "Connection lost") { MessageBox.Show("连接丢失,请稍后重试", "登录失败"); if (!backgroundWorker1.IsBusy) { backgroundWorker1.RunWorkerAsync(); } } else { MessageBox.Show(response, "提示"); if (!backgroundWorker1.IsBusy) { backgroundWorker1.RunWorkerAsync(); } } }
private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { SeatKiller.username = ""; SeatKiller.password = ""; while (!backgroundWorker1.CancellationPending) { if (SeatKiller.GetToken(false) == "登录失败: 用户名或密码不正确") { backgroundWorker1.ReportProgress(100); } else { backgroundWorker1.ReportProgress(0); } Thread.Sleep(200); } e.Cancel = true; }
private void backgroundWorker2_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { bool flag = true; while (true) { if (SeatKiller.GetUsrInf(false)) { label1.Text = "你好 , " + SeatKiller.name + " 上次网页登录时间 : " + SeatKiller.last_login_time + " 状态 : " + SeatKiller.state + " 违约记录 : " + SeatKiller.violationCount + "次"; if (flag) { SeatKiller.GetNotice(true); flag = false; } } else { Thread.Sleep(30000); SeatKiller.GetToken(false); } Thread.Sleep(10000); } }
public static void Run() { bool cancelled = false, exchange = false; if (Config.config.comboBox3.SelectedIndex == 1) { Config.config.textBox2.AppendText((enter ? "\r\n" : "") + "\r\n---------------------------进入抢座模式---------------------------\r\n"); if (DateTime.Now.TimeOfDay.TotalSeconds < 81880) { SeatKiller.Wait("22", "44", "40", false); } if (SeatKiller.GetToken() == "Success") { if (SeatKiller.CheckResInf(false)) { Config.config.textBox2.AppendText("\r\n已检测到有效预约,将自动改签预约信息\r\n"); exchange = true; } else { exchange = false; } if (DateTime.Now.TimeOfDay.TotalMinutes < 1365) { SeatKiller.GetRooms(buildingId); SeatKiller.Wait("22", "45", "00"); } else if (DateTime.Now.TimeOfDay.TotalMinutes > 1420) { Config.config.textBox2.AppendText("\r\n预约系统已关闭"); if (exchange) { if (SeatKiller.ExchangeLoop(buildingId, rooms, startTime, endTime, roomId, seatId)) { SeatKiller.LockSeat(SeatKiller.bookedSeatId); if (Config.config.checkBox6.Checked) { Config.config.backgroundWorker4.RunWorkerAsync(); return; } } } else { if (SeatKiller.Loop(buildingId, rooms, startTime, endTime, roomId, seatId)) { SeatKiller.LockSeat(SeatKiller.bookedSeatId); if (Config.config.checkBox6.Checked) { Config.config.backgroundWorker4.RunWorkerAsync(); return; } } } EnableControls(); return; } while (true) { if (DateTime.Now.TimeOfDay.TotalMinutes > 1420) { Config.config.textBox2.AppendText("\r\n\r\n抢座失败,座位预约系统已关闭"); if (exchange) { if (SeatKiller.ExchangeLoop(buildingId, rooms, startTime, endTime, roomId, seatId)) { SeatKiller.LockSeat(SeatKiller.bookedSeatId); } if (Config.config.checkBox6.Checked) { Config.config.backgroundWorker4.RunWorkerAsync(); } else { EnableControls(); } } else { if (SeatKiller.Loop(buildingId, rooms, startTime, endTime, roomId, seatId)) { SeatKiller.LockSeat(SeatKiller.bookedSeatId); } if (Config.config.checkBox6.Checked) { Config.config.backgroundWorker4.RunWorkerAsync(); } else { EnableControls(); } } return; } if (seatId != "0") { if (exchange && !SeatKiller.reserving && !cancelled) { if (SeatKiller.StopUsing()) { cancelled = true; } else { Config.config.textBox2.AppendText("\r\n\r\n释放座位失败,请稍后重试\r\n"); Config.config.textBox2.AppendText("\r\n---------------------------退出抢座模式---------------------------\r\n"); EnableControls(); return; } } else if (exchange && SeatKiller.reserving && !cancelled) { if (SeatKiller.CancelReservation(SeatKiller.res_id)) { cancelled = true; } else { Config.config.textBox2.AppendText("\r\n\r\n取消预约失败,请稍后重试\r\n"); Config.config.textBox2.AppendText("\r\n---------------------------退出抢座模式---------------------------\r\n"); EnableControls(); return; } } string res = SeatKiller.BookSeat(seatId, date, startTime, endTime); if (res == "Success") { Config.config.textBox2.AppendText("\r\n\r\n---------------------------退出抢座模式---------------------------\r\n"); SeatKiller.LockSeat(SeatKiller.bookedSeatId); if (Config.config.checkBox6.Checked) { Config.config.backgroundWorker4.RunWorkerAsync(); } else { EnableControls(); } return; } else if (res == "Connection lost") { Config.config.textBox2.AppendText("\r\n\r\n连接丢失,30秒后尝试继续预约空位\r\n"); Thread.Sleep(30000); continue; } else if (Config.config.checkBox1.Checked) { Config.config.textBox2.AppendText("\r\n\r\n指定座位预约失败,尝试检索其他空位.....\r\n"); seatId = "0"; continue; } } else { SeatKiller.freeSeats.Clear(); if (roomId == "0") { foreach (var room in rooms) { string res = SeatKiller.SearchFreeSeat(buildingId, room, date, startTime, endTime); if (res == "Success") { break; } else if (res == "Connection lost") { Config.config.textBox2.AppendText("\r\n\r\n连接丢失,30秒后尝试继续检索空位\r\n"); Thread.Sleep(30000); continue; } Thread.Sleep(1500); } } else { string res = SeatKiller.SearchFreeSeat(buildingId, roomId, date, startTime, endTime); if (res == "Connection lost") { Config.config.textBox2.AppendText("\r\n\r\n连接丢失,30秒后尝试继续检索空位\r\n"); Thread.Sleep(30000); continue; } else if (res == "Failed" && Config.config.checkBox1.Checked) { Config.config.textBox2.AppendText("\r\n\r\n当前区域暂无空位,尝试全馆检索空位.....\r\n"); foreach (var room in rooms) { string result = SeatKiller.SearchFreeSeat(buildingId, room, date, startTime, endTime); if (result == "Success") { break; } else if (result == "Connection lost") { Config.config.textBox2.AppendText("\r\n\r\n连接丢失,30秒后尝试继续检索空位\r\n"); Thread.Sleep(30000); continue; } Thread.Sleep(1500); } } } foreach (var freeSeat in SeatKiller.freeSeats) { if (exchange && !SeatKiller.reserving && !cancelled) { if (SeatKiller.StopUsing()) { cancelled = true; } else { Config.config.textBox2.AppendText("\r\n\r\n释放座位失败,请稍后重试\r\n"); Config.config.textBox2.AppendText("\r\n---------------------------退出抢座模式---------------------------\r\n"); EnableControls(); return; } } else if (exchange && SeatKiller.reserving && !cancelled) { if (SeatKiller.CancelReservation(SeatKiller.res_id)) { cancelled = true; } else { Config.config.textBox2.AppendText("\r\n\r\n取消预约失败,请稍后重试\r\n"); Config.config.textBox2.AppendText("\r\n---------------------------退出抢座模式---------------------------\r\n"); EnableControls(); return; } } switch (SeatKiller.BookSeat(freeSeat.ToString(), date, startTime, endTime)) { case "Success": SeatKiller.bookedSeatId = freeSeat.ToString(); Config.config.textBox2.AppendText("\r\n\r\n---------------------------退出抢座模式---------------------------\r\n"); SeatKiller.LockSeat(SeatKiller.bookedSeatId); if (Config.config.checkBox6.Checked) { Config.config.backgroundWorker4.RunWorkerAsync(); } else { EnableControls(); } return; case "Failed": Thread.Sleep(1500); break; case "Connection lost": Config.config.textBox2.AppendText("\r\n\r\n连接丢失,30秒后重新尝试抢座,系统开放时间剩余" + (85500 - (int)DateTime.Now.TimeOfDay.TotalSeconds).ToString() + "秒\r\n"); Thread.Sleep(30000); break; } } } Config.config.textBox2.AppendText("\r\n\r\n暂无可用座位,系统开放时间剩余" + (85200 - (int)DateTime.Now.TimeOfDay.TotalSeconds).ToString() + "秒\r\n"); Thread.Sleep(1500); } } else { Config.config.textBox2.AppendText("\r\n\r\n获取token失败,请检查网络后重试\r\n"); Config.config.textBox2.AppendText("\r\n---------------------------退出抢座模式---------------------------\r\n"); EnableControls(); return; } } else { if (SeatKiller.GetToken(false) == "Success") { if (SeatKiller.CheckResInf(false)) { Config.config.textBox2.AppendText("\r\n\r\n已检测到有效预约,将自动改签预约信息"); if (SeatKiller.ExchangeLoop(buildingId, rooms, startTime, endTime, roomId, seatId)) { SeatKiller.LockSeat(SeatKiller.bookedSeatId); } if (Config.config.checkBox6.Checked) { Config.config.backgroundWorker4.RunWorkerAsync(); } else { EnableControls(); } } else { if (SeatKiller.Loop(buildingId, rooms, startTime, endTime, roomId, seatId)) { SeatKiller.LockSeat(SeatKiller.bookedSeatId); } if (Config.config.checkBox6.Checked) { Config.config.backgroundWorker4.RunWorkerAsync(); } else { EnableControls(); } } } else { Config.config.textBox2.AppendText("\r\n\r\n获取token失败,请检查网络后重试\r\n"); EnableControls(); } return; } }