public static CompanyDatabaseEntities GetContext()
 {
     if (_context == null)
     {
         _context = new CompanyDatabaseEntities();
     }
     return(_context);
 }
示例#2
0
 private void Page_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     if (Visibility == Visibility.Visible)
     {
         CompanyDatabaseEntities.GetContext().ChangeTracker.Entries().ToList().ForEach(p => p.Reload());
         DGridBase.ItemsSource = CompanyDatabaseEntities.GetContext().Trainees.ToList();
     }
 }
示例#3
0
        private void BtnDelete_Click(object sender, RoutedEventArgs e)
        {
            var remove = DGridBase.SelectedItems.Cast <Trainees>().ToList();

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

                    DGridBase.ItemsSource = CompanyDatabaseEntities.GetContext().Trainees.ToList();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
        }
示例#4
0
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            StringBuilder errors = new StringBuilder();

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

            if (string.IsNullOrWhiteSpace(_currentTraine.Surname))
            {
                errors.AppendLine("Укажите фамилию");
            }

            if (string.IsNullOrWhiteSpace(_currentTraine.Patronymic))
            {
                errors.AppendLine("Укажите отчество");
            }

            if (_currentTraine.Age < 18 || _currentTraine.Age > 80)
            {
                errors.AppendLine("Укажите возраст от 18 до 80");
            }

            if (string.IsNullOrWhiteSpace(_currentTraine.Classification))
            {
                errors.AppendLine("Укажите уровень");
            }

            if (string.IsNullOrWhiteSpace(_currentTraine.TheDepartment))
            {
                errors.AppendLine("Укажите отдел");
            }

            if (_currentTraine.Salary < 0 || _currentTraine.Salary > 100000)
            {
                errors.AppendLine("Укажите заплату от 0 до 100000");
            }

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

            if (_currentTraine.id == 0)
            {
                CompanyDatabaseEntities.GetContext().Trainees.Add(_currentTraine);
            }


            try
            {
                CompanyDatabaseEntities.GetContext().SaveChanges();
                MessageBox.Show("Информация сохранена");
                Manager.MainFrame.GoBack();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }