コード例 #1
0
        //注册按钮
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            //使用CURD类直连数据库
            CURD s = new CURD();

            //禁止使用管理员账户进行注册
            if (registerid.Text == "admin")
            {
                MessageBox.Show("禁止使用管理员账户!", "提示", MessageBoxButton.OK);
            }
            else
            {
                //判断账号是否存在
                if (s.SearchNumber(registerid.Text))
                {
                    MessageBox.Show("该用户名已经存在!", "提示", MessageBoxButton.OK);
                }
                else
                {
                    //账号不存在则验证重复密码是否正确
                    if (registerpassword1.Password == registerpassword2.Password)
                    {
                        //将数据注册到数据库
                        s.Addmessage(registerid.Text, nickname.Text, registerpassword1.Password);
                        MessageBox.Show("注册成功!" + registerid.Text + registerpassword1.Password, "提示", MessageBoxButton.OK);
                    }
                    else
                    {
                        MessageBox.Show("重复密码不正确!", "提示", MessageBoxButton.OK);
                    }
                }
            }
        }
コード例 #2
0
        //登录连接服务端方法
        public void login()
        {
            //使用CURD类直连数据库
            CURD s = new CURD();

            //判断账号是否存在
            if (s.SearchNumber(loginid.Text))
            {
                //验证账号对应的密码
                if (s.SearchPassword(loginid.Text, loginpassword.Password))
                {
                    //获取昵称
                    loginname = s.SearchName(loginid.Text);

                    //发送验证消息给服务端判断是否在线
                    OnlineOrOffline();

                    //不在线则直接登录
                    if (Online == false)
                    {
                        usernametext.Text       = loginname;
                        usernametext.IsReadOnly = true;
                        Loginwindow.Visibility  = Visibility.Hidden;
                        Chatwindow.Visibility   = Visibility.Visible;
                        setting.Visibility      = Visibility.Hidden;
                        mainest.Height          = 430;
                        mainest.Width           = 840;

                        //开启接收消息监听
                        Thread threadacceptmsg = new Thread(ClientMessage);
                        threadacceptmsg.IsBackground = true;
                        threadacceptmsg.Start();
                    }
                    //用户已在线
                    else
                    {
                        MessageBox.Show("该用户已经在线!!!!!", "提示", MessageBoxButton.OK);
                    }
                }
                //密码错误
                else
                {
                    MessageBox.Show("密码错误!", "提示", MessageBoxButton.OK);
                }
            }
            //账号不存在
            else
            {
                MessageBox.Show("账号不存在!  " + loginid.Text + "||" + loginpassword.Password, "提示", MessageBoxButton.OK);
            }
        }