//约车功能 public void bookCar(string yyrq, string yysd, string cnbhStr) { if (isSuccess) { resetState(); stopThread(); } else { string bookCarUrl = "http://haijia.bjxueche.net/Han/ServiceBooking.asmx/BookingCar"; //{"yyrq":"20160328","xnsd":"712","cnbh":"02258","imgCode":"","KMID":"3"} string param = "{\"yyrq\":\"" + yyrq + "\",\"xnsd\":\"" + yysd + "\",\"cnbh\":\"" + cnbhStr + "\",\"imgCode\":\"\",\"KMID\":\"" + yykm + "\"}"; string html = ""; try { html = HttpRequestHelper.HttpPostByJson(bookCarUrl, param); html = HttpRequestHelper.replaceComma(html); if (html.IndexOf("LoginOut") > -1) { printLog("系统已自动断开连接,请重新登陆!"); } else { if (html.IndexOf("\"Result\":true") > -1) { printLog("您预约的" + this.dtYyrq.Value + " " + HttpRequestHelper.getXnsdName(yysd) + " 车牌号" + cnbhStr + "的车辆预约成功!", Color.Green); MessageBox.Show("恭喜你,约车成功,您当前预约的车牌号为:" + cnbhStr + ",记得给我一个小小的评价,谢谢!"); isSuccess = true; resetState(); stopThread(); } else { printLog("车牌号为" + cnbhStr + "的车辆,预约失败!", Color.Red); //累计错误次数,过多要及时暂停,否则可能会被系统查处 if (errorNum > 9) { stopThread(); resetState(); } errorNum++; } } } catch (Exception ex) { printLog("约车失败:" + ex.Message, Color.Red); stopThread(); resetState(); } } }
//获取车辆信息列表 public void getCarsList() { //判断有车是否提交 if (this.rdoYes.Checked) { isYueChe = true; } else { isYueChe = false; } //预约科目 yykm = this.cboKemu.Text.ToString(); if (yykm.Equals("科二")) { yykm = "2"; } else { yykm = "3"; } //预约日期 int year = this.dtYyrq.Value.Year; int month = this.dtYyrq.Value.Month; int day = this.dtYyrq.Value.Day; yyrq = "" + year; if (month < 10) { yyrq += "0" + month; } else { yyrq += "" + month; } if (day < 10) { yyrq += "0" + day; } else { yyrq += "" + day; } //预约时段 string yysdName = this.cboYysd.Text.ToString(); yysd = HttpRequestHelper.getXnsd(yysdName); //累计错误次数 errorNum = 0; //初始化是否约车成功状态,一单约车成功,线程立马终止 isSuccess = false; //查询科目二 if (false) { string getCarUrl = "http://haijia.bjxueche.net/Han/ServiceBooking.asmx/GetCars"; string param = "{\"yyrq\":\"" + yyrq + "\",\"yysd\":\"" + yysd + "\",\"xllxID\":\"" + yykm + "\",\"pageSize\":35,\"pageNum\":1}"; //string param = "yyrq=" + yyrq + "&yysd=" + yysd + "&xllxID=" + yykm + "&pageSize=35&pageNum=1"; string html = ""; try { html = HttpRequestHelper.HttpPost(getCarUrl, param); html = html.Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", "").Replace("<string xmlns=\"http://tempuri.org/\">", "").Replace("</string>", ""); string jsonString = html.Split('_')[0]; int num = Convert.ToInt32(html.Split('_')[1]); List <CarInfo> obj = FromJsonTo <List <CarInfo> >(jsonString); if (obj != null && obj.Count > 0) { printLog("您当前查询的" + this.dtYyrq.Value + " " + HttpRequestHelper.getXnsdName(yysd) + ",一共有" + obj.Count + "辆车可以预约。", Color.Green); if (isYueChe) { string[] arr = new string[obj.Count]; int i = 0; foreach (CarInfo item in obj) { arr[i++] = item.CNBH; } carNum = obj.Count; //string[] ary = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };//要分割的数组 int splitSize = 3; //分割线程数量 Object[] arrys = HttpRequestHelper.splitAry(arr, splitSize); //分割后的子块数组 for (int l = 0; l < arrys.Length; l++) { if (l == 0) { l1 = (string[])arrys[l]; } if (l == 1) { l2 = (string[])arrys[l]; } if (l == 2) { l3 = (string[])arrys[l]; } } printLog("系统已开启多线程预约功能..."); //调用约车功能 startAllThreadYueChe(); } } else { printLog("当前暂未查询到车辆。"); } } catch (Exception) { printLog("查询车辆失败", Color.Red); } } else { string getCarUrl = "http://haijia.bjxueche.net/Han/ServiceBooking.asmx/GetCars"; string param = "{\"yyrq\":\"" + yyrq + "\",\"yysd\":\"" + yysd + "\",\"xllxID\":\"" + yykm + "\",\"pageSize\":35,\"pageNum\":1}"; string html = ""; try { html = HttpRequestHelper.HttpPostByJson(getCarUrl, param); html = HttpRequestHelper.replaceComma(html); if (html.IndexOf("LoginOut") > -1) { printLog("系统已自动断开连接,软件正尝试登陆...!"); loginMain(); } else { html = html.Replace("{\"d\":\"", ""); string jsonString = html.Split('_')[0]; int num = Convert.ToInt32(html.Split('_')[1].Replace("\"}", "")); List <CarInfo> obj = FromJsonTo <List <CarInfo> >(jsonString); if (obj != null && obj.Count > 0) { printLog("您当前查询的" + this.dtYyrq.Value + " " + HttpRequestHelper.getXnsdName(yysd) + ",一共有" + obj.Count + "辆车可以预约。", Color.Green); if (isYueChe) { string[] arr = new string[obj.Count]; int i = 0; foreach (CarInfo item in obj) { arr[i++] = item.CNBH; } carNum = obj.Count; //string[] ary = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };//要分割的数组 int splitSize = 3; //分割线程数量 Object[] arrys = HttpRequestHelper.splitAry(arr, splitSize); //分割后的子块数组 for (int l = 0; l < arrys.Length; l++) { if (l == 0) { l1 = (string[])arrys[l]; } if (l == 1) { l2 = (string[])arrys[l]; } if (l == 2) { l3 = (string[])arrys[l]; } } printLog("系统已开启多线程预约功能..."); //开启约车功能 startAllThreadYueChe(); } } else { printLog("当前暂未查询到车辆。"); } } } catch (Exception) { printLog("查询车辆失败", Color.Red); } } }