|
@@ -2,34 +2,29 @@
|
|
|
using esoft.Entities;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
-using System.Data.Entity.Core.Common.CommandTrees;
|
|
|
using System.Linq;
|
|
|
-using System.Text;
|
|
|
-using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
-using System.Windows.Data;
|
|
|
-using System.Windows.Documents;
|
|
|
-using System.Windows.Input;
|
|
|
-using System.Windows.Media;
|
|
|
-using System.Windows.Media.Imaging;
|
|
|
using System.Windows.Navigation;
|
|
|
-using System.Windows.Shapes;
|
|
|
|
|
|
namespace esoft.Pages
|
|
|
{
|
|
|
- /// <summary>
|
|
|
- /// Логика взаимодействия для AddEditServicePage.xaml
|
|
|
- /// </summary>
|
|
|
public partial class AddEditServicePage : Page
|
|
|
{
|
|
|
- ActualContext actualContext = new ActualContext(); //Контекст таблиц
|
|
|
- TaskFill tasks = new TaskFill(); //полученный контекст формы
|
|
|
- List<TaskFill> taskContext = new List<TaskFill>(); //Список задач
|
|
|
+ ActualContext actualContext = new ActualContext();
|
|
|
+ TaskFill tasks = new TaskFill();
|
|
|
+ List<TaskFill> taskContext = new List<TaskFill>();
|
|
|
+ private TaskFill selectedTask;
|
|
|
+ private bool isEditing = false;
|
|
|
|
|
|
- public AddEditServicePage()
|
|
|
+ public AddEditServicePage(TaskFill task)
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
+ selectedTask = task;
|
|
|
+ if (selectedTask.Title != null)
|
|
|
+ {
|
|
|
+ isEditing = true;
|
|
|
+ }
|
|
|
FillForm();
|
|
|
}
|
|
|
|
|
@@ -37,72 +32,114 @@ namespace esoft.Pages
|
|
|
{
|
|
|
cbStatus.ItemsSource = StatusTask.FillStatus();
|
|
|
|
|
|
- List<User> usersExecutor = actualContext.Users.Where(user => actualContext.Executor.Any(ex => ex.ID == user.ID)).ToList(); // Получение списка исполнителей
|
|
|
+ if (isEditing && selectedTask != null)
|
|
|
+ {
|
|
|
+ TBoxTitle.Text = selectedTask.Title;
|
|
|
+ cbExecutor.SelectedItem = selectedTask.FioUser;
|
|
|
+ cbManager.SelectedItem = selectedTask.FioManager;
|
|
|
+ if (cbStatus.ItemsSource is IEnumerable<StatusTask> statusList)
|
|
|
+ {
|
|
|
+ cbStatus.SelectedItem = statusList.FirstOrDefault(status => status.Name == selectedTask.Status);
|
|
|
+ }
|
|
|
+ IUDComplexityTask.Value = (int)selectedTask.Difficulty;
|
|
|
+ IUDTimeTask.Value = selectedTask.Time;
|
|
|
+ cbNatureTask.Text = selectedTask.WorkType;
|
|
|
+ TBoxDescription.Text = selectedTask.Description;
|
|
|
+ DPickerDateCreate.SelectedDate = selectedTask.CreateDateTime;
|
|
|
+ DPickerDateDeadLine.SelectedDate = selectedTask.Deadline;
|
|
|
+ }
|
|
|
+
|
|
|
+ var usersExecutor = actualContext.Users.Where(user => actualContext.Executor.Any(ex => ex.ID == user.ID)).ToList();
|
|
|
cbExecutor.ItemsSource = UserInFIO.GroupUser(usersExecutor);
|
|
|
|
|
|
- List<User> usersManager = actualContext.Users.Where(user => actualContext.Manager.Any(manager => manager.ID == user.ID)).ToList(); // Получение списка менеджеров
|
|
|
+ var usersManager = actualContext.Users.Where(user => actualContext.Manager.Any(manager => manager.ID == user.ID)).ToList();
|
|
|
cbManager.ItemsSource = UserInFIO.GroupUser(usersManager);
|
|
|
}
|
|
|
|
|
|
private void BtnSaveTask_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- // Получение значений из элементов управления формы
|
|
|
string title = TBoxTitle.Text;
|
|
|
string executorName = cbExecutor.SelectedItem?.ToString();
|
|
|
string managerName = cbManager.SelectedItem?.ToString();
|
|
|
string status = cbStatus.Text;
|
|
|
int complexity = (int)IUDComplexityTask.Value;
|
|
|
int time = (int)IUDTimeTask.Value;
|
|
|
- string nature = cbNatureTask.SelectedItem?.ToString();
|
|
|
+ string nature = cbNatureTask.Text;
|
|
|
string description = TBoxDescription.Text;
|
|
|
DateTime createDate = DPickerDateCreate.SelectedDate ?? DateTime.Now;
|
|
|
DateTime deadline = DPickerDateDeadLine.SelectedDate ?? DateTime.Now;
|
|
|
|
|
|
- // Проверка на заполнение обязательных полей
|
|
|
if (string.IsNullOrWhiteSpace(title) || string.IsNullOrWhiteSpace(executorName) || string.IsNullOrWhiteSpace(managerName) || string.IsNullOrWhiteSpace(status))
|
|
|
{
|
|
|
MessageBox.Show("Пожалуйста, заполните все обязательные поля!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // Поиск исполнителя и менеджера по их именам в контексте
|
|
|
- var executor = actualContext.Executor.FirstOrDefault(ex => ex.User.Name == executorName);
|
|
|
- var manager = actualContext.Manager.FirstOrDefault(m => m.User.Name == managerName);
|
|
|
-
|
|
|
- // Проверка на наличие исполнителя и менеджера
|
|
|
- if (executor == null || manager == null)
|
|
|
+ try
|
|
|
{
|
|
|
- MessageBox.Show("Исполнитель или менеджер не найден!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
- return;
|
|
|
- }
|
|
|
+ var context = esoftEntities.GetContext();
|
|
|
+ var executorID = actualContext.Users.FirstOrDefault(u => UserInFIO.SoloUser(u) == executorName)?.ID;
|
|
|
+ var managerID = actualContext.Users.FirstOrDefault(u => UserInFIO.SoloUser(u) == managerName)?.ID;
|
|
|
|
|
|
- // Создание новой задачи на основе введенных данных
|
|
|
- esoft.Entities.Task newTask = new esoft.Entities.Task
|
|
|
- {
|
|
|
- Title = title,
|
|
|
- ExecutorID = executor.ID,
|
|
|
- // Добавьте или измените свойства для ManagerID, если это необходимо
|
|
|
- Status = status,
|
|
|
- Difficulty = complexity,
|
|
|
- Time = time,
|
|
|
- WorkType = nature,
|
|
|
- Description = description,
|
|
|
- CreateDateTime = createDate,
|
|
|
- Deadline = deadline
|
|
|
- };
|
|
|
-
|
|
|
- // Добавление задачи в контекст базы данных
|
|
|
- var context = esoftEntities.GetContext();
|
|
|
- context.Task.Add(newTask);
|
|
|
+ if (executorID == null || managerID == null)
|
|
|
+ {
|
|
|
+ MessageBox.Show("Исполнитель или менеджер не найден!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- try
|
|
|
- {
|
|
|
- context.SaveChanges(); // Сохранение изменений в базе данных
|
|
|
- MessageBox.Show("Задача успешно добавлена!", "Успех", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ if (isEditing)
|
|
|
+ {
|
|
|
+ var existingTask = context.Task.FirstOrDefault(t => t.ID == selectedTask.ID);
|
|
|
+
|
|
|
+ if (existingTask != null)
|
|
|
+ {
|
|
|
+ existingTask.Title = title;
|
|
|
+ existingTask.ExecutorID = executorID.Value;
|
|
|
+ existingTask.Status = status;
|
|
|
+ existingTask.Difficulty = complexity;
|
|
|
+ existingTask.Time = time;
|
|
|
+ existingTask.WorkType = nature;
|
|
|
+ existingTask.Description = description;
|
|
|
+ existingTask.CreateDateTime = createDate;
|
|
|
+ existingTask.Deadline = deadline.Date;
|
|
|
+
|
|
|
+ context.SaveChanges();
|
|
|
+
|
|
|
+ MessageBoxResult result = MessageBox.Show("Задача успешно изменена!", "Успех", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ if (result == MessageBoxResult.OK)
|
|
|
+ {
|
|
|
+ NavigationService.GoBack();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else // Добавление новой задачи
|
|
|
+ {
|
|
|
+ esoft.Entities.Task newTask = new esoft.Entities.Task
|
|
|
+ {
|
|
|
+ Title = title,
|
|
|
+ ExecutorID = executorID.Value,
|
|
|
+ Status = status,
|
|
|
+ Difficulty = complexity,
|
|
|
+ Time = time,
|
|
|
+ WorkType = nature,
|
|
|
+ Description = description,
|
|
|
+ CreateDateTime = createDate,
|
|
|
+ Deadline = deadline.Date,
|
|
|
+ };
|
|
|
+
|
|
|
+ context.Task.Add(newTask);
|
|
|
+ context.SaveChanges();
|
|
|
+
|
|
|
+ MessageBoxResult result = MessageBox.Show("Задача успешно добавлена!", "Успех", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ if (result == MessageBoxResult.OK)
|
|
|
+ {
|
|
|
+ NavigationService.GoBack();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- MessageBox.Show($"Ошибка при добавлении задачи: {ex.Message}", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ MessageBox.Show($"Ошибка при обработке задачи: {ex.Message}", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
}
|
|
|
}
|
|
|
}
|