public void loginMain() { string txtUserName = this.txtUserName.Text.ToString(); string txtPassword = this.txtUserPwd.Text.ToString(); string txtIMGCode = this.txtImageCode.Text.ToString(); if (txtUserName.Equals("") || txtUserPwd.Equals("") || txtImageCode.Equals("")) { MessageBox.Show("请输入用户名或者密码!"); return; } if (txtImageCode.Equals("")) { MessageBox.Show("请输入验证码!"); return; } if (!HttpRequestHelper.getUserLimitData(txtUserName)) { printLog("您当前账号尚未开通权限,请联系管理员进行权限开通!"); MessageBox.Show("当前账号未开通权限,请联系管理员进行权限开通才能使用!"); return; } string loginPost = "__VIEWSTATE=" + __VIEWSTATE + "&__VIEWSTATEGENERATOR=" + __VIEWSTATEGENERATOR + "&__EVENTVALIDATION=" + __EVENTVALIDATION + "&txtUserName="******"&txtPassword="******"&txtIMGCode=" + txtIMGCode + "&BtnLogin=登 录";//登陆提交 string html = ""; string error = ""; try { html = HttpRequestHelper.HttpPost(url, loginPost); html = HttpRequestHelper.replaceComma(html); int errorStart = html.IndexOf("<script>alert('"); int errorEnd = html.IndexOf("');</script>"); if (errorStart > -1) { error = html.Substring(errorStart + 15, errorEnd - errorStart - 15); if (!error.Equals("")) { printLog(error); MessageBox.Show(error); } } else { if (error.Equals("") && html.IndexOf("ych2.aspx") > -1) { //启用按钮 this.button1.Enabled = true; this.btnSubCnbh.Enabled = true; printLog("登陆成功,请在7点35分左右开始约车!"); this.saveUserInfo(txtUserName, txtPassword); //登陆成功直接获取车辆信息 this.getCarsList(); } else { printLog("登陆异常,请重新登陆!"); } } } catch (Exception) { printLog("网络异常,请稍后重试!", Color.Red); } }
//获取车辆信息列表 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); } } }