Esempio n. 1
0
        private void _button添加_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (StatementContext statement = new StatementContext(typeof(User)))
                {
                    //
                    if (string.IsNullOrEmpty(_textBox用户名.Text) || _textBox用户名.Text.Length > 20)
                    {
                        MessageBox.Show("用户名必须1-20个字符!");
                        return;
                    }
                    if (statement.Users.FirstOrDefault(user => user.UserName.Equals(_textBox用户名.Text)) != null)
                    {
                        MessageBox.Show("用户名已被占用!");
                        return;
                    }
                    if (string.IsNullOrEmpty(_textBox用户密码.Password) || _textBox用户密码.Password.Length < 6 || _textBox用户密码.Password.Length > 20)
                    {
                        MessageBox.Show("密码必须6-20个字符!");
                        return;
                    }
                    if (!_textBox用户密码.Password.Equals(_textBox用户密码2.Password))
                    {
                        MessageBox.Show("两次密码不一致!");
                        return;
                    }

                    //
                    statement.AddUser(new User {
                        Id = Guid.NewGuid(), UserName = _textBox用户名.Text, UserPassword = _textBox用户密码.Password._RSAEcrypt(), Email = _textBox邮箱.Text
                    });
                    statement.SaveChanged();
                    DialogResult = true;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }