Exemplo n.º 1
0
        /// <summary>
        /// 用户登录操作
        /// </summary>
        /// <param name="sender">基类</param>
        /// <param name="e">环境变量</param>
        private void button_Login_Click(object sender, EventArgs e)
        {
            var uac = textBox_UesrAccount.Text;
            var upw = textBox_UserPW.Text;

            textBox_UserPW.Text = "";
            // 空输入
            if (uac.Length == 0)
            {
                MessageBox.Show("账户不能为空!", "输入错误", MessageBoxButtons.OK);
                return;
            }
            if (upw.Length == 0)
            {
                MessageBox.Show("密码不能为空!", "输入错误", MessageBoxButtons.OK);
                return;
            }
            if (uac.Contains(' ') || upw.Contains(' '))
            {
                MessageBox.Show("任何字段不得包含空格与回车字符!", "输入错误", MessageBoxButtons.OK);
                return;
            }
            upw = Cipher.md5Encrypt(upw);
            string question = "Login " + uac + " " + upw;
            string ret;

            tcpClientLogin.Query(question, out ret);
            // 用户不存在
            if (ret == VerMessage.LOGIN_FAILED_NO_SUCH_USER)
            {
                string msg = "用户[" + uac + "]不存在!";
                MessageBox.Show(msg, "用户错误", MessageBoxButtons.OK);
                return;
            }
            // 检查密码
            if (ret == VerMessage.LOGIN_FAILED_WRONG_PW)
            {
                string msg = "用户[" + uac + "]密码错误!";
                MessageBox.Show(msg, "密码错误", MessageBoxButtons.OK);
                return;
            }
            // 成功登陆
            if (ret == VerMessage.LOGIN_SUCCESS)
            {
                string msg = "用户[" + uac + "]登录成功。正在初始化数据,请稍等。";
                MessageBox.Show(msg, "登陆成功", MessageBoxButtons.OK);
                Registry.AddKey2Registry("PublishClient", "CurrentUserPW", upw);
                isLogin = true;
                while (!isCatch)
                {
                    Thread.Sleep(100);
                }
                this.DialogResult = DialogResult.OK;
                tcpClientLogin.Close();
                this.Close();
            }
        }
Exemplo n.º 2
0
        private void button_User_Click(object sender, EventArgs e)
        {
            User      person = new User(int.Parse(uid), uac, ucl, upw);
            Form_User user   = new Form_User(person);

            user.ReturnUser += (o, e1) =>
            {
                if (!e1.CanUpdate)
                {
                    return;
                }
                User now = e1.Me;
                // 更新资料
                string     question = "Change " + now.GetRawString(), answer;
                TcpClientP request = new TcpClientP();
                request.Connect(serverIP, Port.TCP_LOGIN_PORT);
                request.Query(question, out answer);
                if (answer != VerMessage.CHANGE_SUCCESS)
                {
                    MessageBox.Show("更新信息失败", "提示", MessageBoxButtons.OK);
                    request.Close();
                    return;
                }
                MessageBox.Show("更新信息成功", "提示", MessageBoxButtons.OK);
                request.Close();
                ucl = now.name;
                Registry.AddKey2Registry("PublishClient", "CurrentUserName", ucl);
                this.Text = "教材补助经费评估软件 [" + ucl + "]" + " [#" + uid + "]";
                this.label_ClientName.Text = "[#" + uid + "] " + ucl;
            };
            user.ShowDialog();
        }
Exemplo n.º 3
0
        public bool TryLogoff()
        {
            // 登出系统
            string question, answer;

            tcpClientLogoff = new TcpClientP();
            try { tcpClientLogoff.Connect(serverIP, Port.TCP_LOGIN_PORT); }
            catch (Exception) { return(false); }
            question = "Logoff " + uac;
            tcpClientLogoff.Query(question, out answer);
            if (answer == VerMessage.LOGOFF_SUCCESS)
            {
                return(true);
            }
            return(false);
        }