private void formLogin_Shown(object sender, EventArgs e) { string path = AppDomain.CurrentDomain.BaseDirectory + "usrCookie.cfg"; DateTime time = DateTime.Now.AddDays(-1); if (System.IO.File.Exists(path)) { time = System.IO.File.GetLastWriteTime(path); if (DateTime.Now.Subtract(time).TotalMinutes > 20) { System.IO.File.Delete(path); } } la.cookieContainer = LocalCookie.ReadCookiesFromDisk(path); if (la.cookieContainer.Count != 0) { formSelectTicket.cookieContainer = la.cookieContainer; 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(path, la.cookieContainer); } this.Hide(); formSelectTicket selectForm = new formSelectTicket(); selectForm.user = txtName.Text; selectForm.Show(); } GetRandCodeImg(); }
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; } }); }); }); }); }