예제 #1
0
        private void ButtonLogin_Click(object sender, RoutedEventArgs e)
        {
            string pass     = TextBoxPass.Text.Trim();
            string password = Password.Password.Trim();
            string login    = TextBoxLogin.Text.Trim();

            Users logUsers = null;

            using (HomeTaskEntities db = new HomeTaskEntities())
            {
                logUsers = db.Users.Where(data => data.Login == login && (data.Password == password || data.Password == pass)).FirstOrDefault();
            }

            if (logUsers != null)
            {
                Window2 window2 = new Window2();
                window2.Show();
                Hide();
            }

            else
            {
                MessageBox.Show("Проверьте ввод данных", "Внимание", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
예제 #2
0
 private void Page_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     if (Visibility == Visibility.Visible)
     {
         HomeTaskEntities.GetContext().ChangeTracker.Entries().ToList().ForEach(p => p.Reload());
         DGridTovar.ItemsSource = HomeTaskEntities.GetContext().Users.ToList();
     }
 }
예제 #3
0
 public static HomeTaskEntities GetContext()
 {
     if (_context == null)
     {
         _context = new HomeTaskEntities();
     }
     return(_context);
 }
예제 #4
0
        private void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            StringBuilder errors = new StringBuilder();

            if (string.IsNullOrWhiteSpace(_currentUsers.LastName))
            {
                errors.AppendLine("Укажите имя");
            }

            if (string.IsNullOrWhiteSpace(_currentUsers.FirstName))
            {
                errors.AppendLine("Укажите Фамилию");
            }

            if (string.IsNullOrWhiteSpace(_currentUsers.Login))
            {
                errors.AppendLine("Укажите Логин");
            }

            if (string.IsNullOrWhiteSpace(_currentUsers.Password))
            {
                errors.AppendLine("Укажите Пароль");
            }

            if (errors.Length > 0)
            {
                MessageBox.Show(errors.ToString());
                return;
            }

            if (_currentUsers.id == 0)
            {
                HomeTaskEntities.GetContext().Users.Add(_currentUsers);
            }

            try
            {
                HomeTaskEntities.GetContext().SaveChanges();
                MessageBox.Show("Информация сохранена");
                Manager.MainFrame.GoBack();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
예제 #5
0
        private void ButtonDelete_Click(object sender, RoutedEventArgs e)
        {
            var usersForRemoving = DGridTovar.SelectedItems.Cast <Users>().ToList();

            if (MessageBox.Show($"Вы уверены, что хотите удалить следующие {usersForRemoving.Count()} элементов?", "Внимание", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                ;
            }
            {
                try
                {
                    HomeTaskEntities.GetContext().Users.RemoveRange(usersForRemoving);
                    HomeTaskEntities.GetContext().SaveChanges();
                    MessageBox.Show("Данные удалены");

                    DGridTovar.ItemsSource = HomeTaskEntities.GetContext().Users.ToList();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
        }