private void SignUpButton_Click(object sender, EventArgs e)
        {
            string _username = username.Text.Trim();
            string _password = password.Text.Trim();

            if (_username != "" && _password != "")
            {
                UserAccess  db    = new UserAccess();
                List <User> users = db.GetManyBySelector(user => user.Username.Trim() == _username);
                if (users.Count == 0)
                {
                    try
                    {
                        User user = new User(-1, _username, _password, DateTime.Now);
                        db.Add(user);
                        MessageLabel.Text = "Successfull sign up";
                    }
                    catch (Exception ex)
                    {
                        MessageLabel.Text = ex.Message;
                    }
                }
                else
                {
                    MessageLabel.Text = "This username exists. Enter a different username or use the username to sign in.";
                }
            }
            else
            {
                MessageLabel.Text = "Please enter username and password";
            }
        }
Ejemplo n.º 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            string userName  = this.tbUserName.Text;
            string mail      = this.tbMail.Text;
            string passWord1 = this.tbUserPassWord1.Text;
            string passWord2 = this.tbUserPassWord2.Text;
            string identify  = this.tbnIdentify1.Text;
            string phoneNum  = this.tbPhoneNumber.Text;
            User   user      = new User();
            bool   agree     = this.checkBox1.Checked;

            if (agree)
            {
                if (identify == Identify)
                {
                    if (passWord1 == passWord2)
                    {
                        user.USName          = userName;
                        user.USEmail         = mail;
                        user.USPassWord      = passWord1;
                        user.USPhone         = phoneNum;
                        user.USRegisterTime  = DateTime.Now;
                        user.USLastLoginTime = DateTime.Now;
                        user.USLastLoginIp   = Dns.GetHostEntry(Dns.GetHostName()).AddressList[0].ToString();
                        user.USValid         = 1;
                        if (UserAccess.Add(user))
                        {
                            MessageBox.Show("注册成功!");
                            Homepage homePage = new Homepage(UserAccess.Select(userName));
                            homePage.Show();
                        }
                    }
                    else
                    {
                        MessageBox.Show("两次填写的密码不一致!");
                    }
                }
                else
                {
                    MessageBox.Show("验证码填写有误");
                }
            }
            else
            {
                MessageBox.Show("请勾选同意!");
            }
        }