private void btnLogin_Click(object sender, EventArgs e) { lblInfomation.Text = ""; if (cboName.Text.Length < 4) { return; } if (txtPwd.Text.Length < 4) { return; } if (txtRandCode.TextLength < 4) { return; } btnLogin.Enabled = false; btnLogin.Text = "正在登录"; Application.DoEvents(); string name = cboName.Text; string pwd = txtPwd.Text; var htmlTran = new HTML_Translation(); //采用同步方式登录 _la.PostData = string.Format(@"loginUserDTO.user_name={0}&userDTO.password={1}&randCode={2}", name, pwd, txtRandCode.Text); var strHash = _la.BeginLogin(); string strHtml = ""; var cookie = new CookieContainer(); if (strHash == null) { MessageBox.Show("难道12306又挂了?", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question); return; } foreach (var v in strHash.Keys) { cookie = (CookieContainer)v; strHtml = strHash[v].ToString(); break; } if (strHtml == "") { lblInfomation.Text = "登录失败!"; btnLogin.Enabled = true; btnLogin.Text = "登录"; txtRandCode.Focus(); GetRandCodeImg(); return; } try { var returnString = htmlTran.TranslationHtmlEx(strHtml); if (returnString["messages"].Any()) { GetRandCodeImg(); DeterMineCall(() => { lblInfomation.Text = returnString["messages"][0].ToString(); this.BeginInvoke(new Action(FormShake)); txtRandCode.Text = ""; btnLogin.Enabled = true; btnLogin.Text = "登录"; txtRandCode.Focus(); Application.DoEvents(); }); return; } //var loginCheck = returnString["data"] as JavaScriptObject; if (returnString["data"] != null && returnString["data"]["loginCheck"].ToString() == "Y") { if (chkUserInfo.Checked) { var dc = new DesCryption(); ConfigInfo.conf.username = name; ConfigInfo.conf.password = dc.EncryptString(pwd, name); ConfigInfo.savetofile(ConfigInfo.conf.username); string path = AppDomain.CurrentDomain.BaseDirectory + "data\\" + name; if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } LocalCookie.WriteCookiesToDisk(path + "\\usrCookie.cfg", LoginAction.cookieContainer); } btnLogin.Enabled = true; btnLogin.Text = "登录"; this.Hide(); // MessageBox.Show(@"温馨提示: // //1. 自2013年1月4日起,火车票互联网、电话订票预售期延长至20天(含当日),代售点和车站部分售票窗口预售期延长至18天(含当日)。 // //2. 自2013年1月1日起,通过电话预订车票的旅客可凭订票时乘车人有效身份证件,到全国任一车站窗口或代售点换取已订车票。当日12:00前已订车票于第二日12:00前取有效;当日12:00后已订车票于第二日24:00前取有效。 // // //请广大旅客注意电话订票取票时间和范围、互联网和电话订票起售时间、火车票预售期的变化,合理安排好购票计划。", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information); var selectForm = new formSelectTicket(cookie) { ThisCookie = cookie, /*formSelectTicket.cookieContainer = cookie;*/ UserName = cboName.Text }; selectForm.Show(); } else { GetRandCodeImg(); lblInfomation.Text = "登录失败"; txtRandCode.Text = ""; btnLogin.Enabled = true; btnLogin.Text = "登录"; txtRandCode.Focus(); return; } } catch (Exception) { MessageBox.Show("23:00至07:00为系统维护时间!", "温馨提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } finally { } }
private void btnLogin_Click(object sender, EventArgs e) { DeterMineCall(() => { if (txtName.Text.Length < 4) { return; } if (txtPwd.Text.Length < 4) { return; } if (txtRandCode.TextLength < 4) { return; } btnLogin.Enabled = false; btnLogin.Text = "正在登录"; Application.DoEvents(); //获取随机码 string loginRand = ""; HTML_Translation htmlTran = new HTML_Translation(); la.GetLoginRand((strrand) => { if (strrand == "获取信息失败") { MessageBox.Show("信息获取失败,请重试", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } loginRand = htmlTran.TranslationHtml(strrand, "loginRand"); //登录 string result = ""; la.PostData = string.Format(@"loginRand={0}&loginUser.user_name={1}&nameErrorFocus=&passwordErrorFocus=&randCode={2}&randErrorFocus=&refundFlag=Y&refundLogin=N&user.password={3}", loginRand, txtName.Text, txtRandCode.Text, txtPwd.Text); la.BeginLogin((str) => { result = str; DeterMineCall(() => { //登录返回结果 if (result.IndexOf("请输入正确的验证码") > -1) { lblInfomation.Text = "验证码不正确"; GetRandCodeImg(); txtRandCode.Text = ""; btnLogin.Enabled = true; btnLogin.Text = "登录"; txtRandCode.Focus(); return; } if (result.IndexOf("系统维护") > -1) { lblInfomation.Text = "系统维护中....."; GetRandCodeImg(); txtRandCode.Text = ""; btnLogin.Enabled = true; btnLogin.Text = "登录"; txtRandCode.Focus(); return; } if (result.IndexOf("登录名不存在") > -1) { lblInfomation.Text = "登录名不存在"; GetRandCodeImg(); txtRandCode.Text = ""; btnLogin.Enabled = true; btnLogin.Text = "登录"; txtRandCode.Focus(); return; } else if (result.IndexOf("密码输入错误") > -1) { lblInfomation.Text = "密码输入错误"; GetRandCodeImg(); txtPwd.Text = ""; btnLogin.Enabled = true; btnLogin.Text = "登录"; txtPwd.Focus(); return; } else if (result.IndexOf("锁定") > -1) { lblInfomation.Text = "帐号被锁定"; GetRandCodeImg(); btnLogin.Enabled = true; btnLogin.Text = "登录"; return; } else if (result.IndexOf("网络") > -1) { lblInfomation.Text = "网站又挂了"; GetRandCodeImg(); btnLogin.Enabled = true; btnLogin.Text = "登录"; return; } else if (result.IndexOf("欢迎您登录") != -1) { if (chkUserInfo.Checked) { ConfigInfo.conf.username = EncodeAndDecode.EncodeBase64(EncodeAndDecode.EncodeBase64(txtName.Text)); ConfigInfo.conf.password = EncodeAndDecode.EncodeBase64(EncodeAndDecode.EncodeBase64(txtPwd.Text)); ConfigInfo.savetofile(); LocalCookie.WriteCookiesToDisk(AppDomain.CurrentDomain.BaseDirectory + "usrCookie.cfg", la.cookieContainer); } btnLogin.Enabled = true; btnLogin.Text = "登录"; this.Hide(); formSelectTicket selectForm = new formSelectTicket(); selectForm.user = txtName.Text; selectForm.Show(); } else { lblInfomation.Text = "登录失败"; GetRandCodeImg(); txtRandCode.Text = ""; btnLogin.Enabled = true; btnLogin.Text = "登录"; txtRandCode.Focus(); return; } }); }); }); }); }