private void Add(object sender, RoutedEventArgs e)
 {
     if (string.IsNullOrWhiteSpace(TbLogin.Text))
     {
         MB.MessageBoxInfo("Введите логин");
         TbLogin.Focus();
     }
     else if (string.IsNullOrWhiteSpace(TbPassword.Text))
     {
         MB.MessageBoxInfo("Введите пароль");
         TbPassword.Focus();
     }
     else if (string.IsNullOrWhiteSpace(CbRole.Text))
     {
         MB.MessageBoxInfo("Выберите роль");
         CbRole.Focus();
     }
     else
     {
         try
         {
             DataService.GetContext().User.Add(user);
             DataService.GetContext().SaveChanges();
             MB.MessageBoxInfo("Пользователь успешно добавлен");
         }
         catch
         {
             MB.MessageBoxError("Ошибка подключения к базе данных");
         }
     }
 }
Exemplo n.º 2
0
        private void SignIn(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(TbLogin.Text))
            {
                MB.MessageBoxInfo("Введите логин");
                TbLogin.Focus();
            }
            else if (string.IsNullOrWhiteSpace(PbPassword.Password))
            {
                MB.MessageBoxInfo("Введите пароль");
                PbPassword.Focus();
            }
            else
            {
                var employee = DataService.GetContext().Employee.FirstOrDefault(u => u.User.Login == TbLogin.Text);

                if (employee == null)
                {
                    MB.MessageBoxInfo("Введен неверно логин/пароль");
                    TbLogin.Focus();
                    count++;
                }
                else
                {
                    if (employee.User.Password != PbPassword.Password)
                    {
                        MB.MessageBoxInfo("Введен неверно логин/пароль");
                        TbLogin.Clear();
                        PbPassword.Clear();
                        count++;
                    }
                    else
                    {
                        Entity.CurrentEmployee = employee;
                        switch (employee.User.IdRole)
                        {
                        case 1:
                            new WinManager().Show();
                            this.Close();
                            break;

                        case 2:
                            new WinEmployee().Show();
                            this.Close();
                            break;

                        case 3:
                            new WinAdmin().Show();
                            this.Close();
                            break;
                        }
                        count = 0;
                    }
                }
                if (count >= 3)
                {
                    TbLogin.Text           = string.Empty;
                    PbPassword.Password    = string.Empty;
                    GridSignIn.Visibility  = Visibility.Hidden;
                    GridCaptcha.Visibility = Visibility.Visible;
                    TbCaptcha.Text         = Captcha.GenerateString(5);
                    return;
                }
            }
        }