Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //-----------------------------------------------------------
- // Вход:
- // - если нет такого User, то "Invalid login or pswrd"
- // Регистрация:
- // - Чтобы поля не были пустыми
- // - При регистрации чтобы не было дублирования Login
- //-----------------------------------------------------------
- //login
- private void btnSubmit_Click(object sender, RoutedEventArgs e)
- {
- var userName = txtBoxUserName.Text;
- var userPswrd = txtBoxPassword.Text;
- using (var db = new Model1())
- {
- var users = (from user in db.tblUsers
- where user.NikName == userName && user.Password == userPswrd
- select user).ToList();
- if (users.Count == 1)
- {
- MainWindow mainWindow = new MainWindow(users[0]);
- mainWindow.Show();
- this.Close();
- }
- else
- {
- MessageBox.Show("Incorrect enter");
- }
- }
- }
- private void btnRegistration_Click(object sender, RoutedEventArgs e)
- {
- AddUserWndw addUserWndw = new AddUserWndw();
- addUserWndw.Show();
- this.Close();
- }
- //-------------------
- //registration
- private void btnSubmit_Click(object sender, RoutedEventArgs e)
- {
- if ( !(ValidateRegistration()) )
- {
- return;
- }
- string login = txtBoxLogin.Text;
- string password = txtBoxPswrd.Text;
- string address = txtBoxAddress.Text;
- string tel = txtBoxTel.Text;
- int num = Convert.ToInt32(txtBoxIsAdmin.Text);
- bool _isAdmin = Convert.ToBoolean(num);
- using (var db = new Model1())
- {
- var users = (from user in db.tblUsers
- where user.NikName == login
- select user).ToList();
- if (users.Count == 1)
- {
- MessageBox.Show("User with current Login is exist");
- return;
- }
- tblUser newUser = new tblUser() { NikName = login, Password = password, Address = address, Tel = tel, IsAdmin = _isAdmin };
- db.tblUsers.Add(newUser);
- db.SaveChanges();
- }
- LoginScreenWndw loginScreenWndw = new LoginScreenWndw();
- loginScreenWndw.Show();
- this.Close();
- }
- private bool ValidateRegistration()
- {
- if (txtBoxLogin.Text == "" || txtBoxPswrd.Text == "" || txtBoxAddress.Text == "" || txtBoxTel.Text == "" || txtBoxIsAdmin.Text == "")
- {
- MessageBox.Show("Please, fill the all poles");
- return false;
- }
- return true;
- }
- private void btnBack_Click(object sender, RoutedEventArgs e)
- {
- LoginScreenWndw loginScreenWndw = new LoginScreenWndw();
- loginScreenWndw.Show();
- this.Close();
- }
Add Comment
Please, Sign In to add comment