Ejemplo n.º 1
0
        void popup_Closing(object sender, ToolStripDropDownClosingEventArgs e)
        {
            var ql = (QuicklyLogin)((Popup)sender).Controls[0];

            if (ql.User != "")
            {
                var selectForm = new formSelectTicket(ql.Cookie)
                {
                    UserName = ql.User
                };
                selectForm.Show();
                this.Hide();
            }
        }
Ejemplo n.º 2
0
        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();
                        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();

                    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 { }
        }
Ejemplo n.º 3
0
 void popup_Closing(object sender, ToolStripDropDownClosingEventArgs e)
 {
     var ql = (QuicklyLogin)((Popup)sender).Controls[0];
     if (ql.User != "")
     {
         var selectForm = new formSelectTicket(ql.Cookie) { UserName = ql.User };
         selectForm.Show();
         this.Hide();
     }
 }
Ejemplo n.º 4
0
        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();
                        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();

                    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 { }
        }