|
@@ -12,6 +12,8 @@ using System.Windows.Media;
|
|
|
using System.Windows.Media.Imaging;
|
|
|
using System.Windows.Navigation;
|
|
|
using System.Windows.Shapes;
|
|
|
+using System.Linq.Expressions;
|
|
|
+using System.Data.Entity.Migrations;
|
|
|
|
|
|
namespace ROGOZ.Pages
|
|
|
{
|
|
@@ -20,17 +22,90 @@ namespace ROGOZ.Pages
|
|
|
/// </summary>
|
|
|
public partial class AddEditPage : Page
|
|
|
{
|
|
|
+ private Task _currentTask = new Task();
|
|
|
public AddEditPage()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
+ DataContext = _currentTask;
|
|
|
CmbStatus.ItemsSource = Status.FillStatus();
|
|
|
CmbExecutor.ItemsSource = user1Entities.GetContext().Executor.ToList();
|
|
|
CmbTaskType.ItemsSource = WorkType.FillWorkType();
|
|
|
}
|
|
|
|
|
|
+ public AddEditPage(Task selectedTask)
|
|
|
+ {
|
|
|
+ InitializeComponent();
|
|
|
+ _currentTask = selectedTask;
|
|
|
+ CmbStatus.ItemsSource = Status.FillStatus();
|
|
|
+ CmbExecutor.ItemsSource = user1Entities.GetContext().Executor.ToList();
|
|
|
+ CmbTaskType.ItemsSource = WorkType.FillWorkType();
|
|
|
+ if (selectedTask != null)
|
|
|
+ _currentTask = selectedTask;
|
|
|
+ DataContext = _currentTask;
|
|
|
+ }
|
|
|
private void BtnCancel_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
NavigationService.GoBack();
|
|
|
}
|
|
|
+
|
|
|
+ private string CheckErrors()
|
|
|
+ {
|
|
|
+ var errorBuilder = new StringBuilder();
|
|
|
+ if (string.IsNullOrWhiteSpace(TaskNameTB.Text))
|
|
|
+ errorBuilder.AppendLine("Укажите название заголовка!");
|
|
|
+ if (CmbStatus.Text == null)
|
|
|
+ errorBuilder.AppendLine("Выберите статус!");
|
|
|
+ if (CmbTaskType.Text == null)
|
|
|
+ errorBuilder.AppendLine("Выберите характеристику!");
|
|
|
+
|
|
|
+ if (errorBuilder.Length > 0) //проверка на ошибку
|
|
|
+ {
|
|
|
+ MessageBox.Show(errorBuilder.ToString());
|
|
|
+ return errorBuilder.ToString();
|
|
|
+ }
|
|
|
+ else return null;
|
|
|
+
|
|
|
+ }
|
|
|
+ private void BtnSaveTask_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ //var errorMessage = CheckErrors();
|
|
|
+ if (CheckErrors() == null)
|
|
|
+ {
|
|
|
+ if (_currentTask != null)
|
|
|
+ {
|
|
|
+ //try
|
|
|
+ //{
|
|
|
+ var selectedTask = new Task
|
|
|
+ {
|
|
|
+ ExecutorID = int.Parse(CmbExecutor.Text),
|
|
|
+ Title = TaskNameTB.Text,
|
|
|
+ Description = TaskDescriptionTB.Text,
|
|
|
+ CreateDateTime = DateTime.Parse(DPCreateDateTime.Text),
|
|
|
+ Deadline = DateTime.Parse(DPDeadLine.Text),
|
|
|
+ Difficulty = Double.Parse(DifficultyTB.Text),
|
|
|
+ Time = int.Parse(TimeTB.Text),
|
|
|
+ Status = CmbStatus.Text,
|
|
|
+ WorkType = CmbTaskType.Text,
|
|
|
+ IsDeleted = false
|
|
|
+ };
|
|
|
+ //App.Context.Task.Add(selectedTask);
|
|
|
+ //user1Entities.GetContext().Add(selectedTask);
|
|
|
+ //App.Context.SaveChangesw
|
|
|
+ //user1Entities.GetContext().SaveChanges();
|
|
|
+ user1Entities.GetContext().Task.Add(selectedTask);
|
|
|
+ user1Entities.GetContext().SaveChanges();
|
|
|
+ MessageBox.Show("Ну вроде получилось");
|
|
|
+ NavigationService.GoBack();
|
|
|
+ //}
|
|
|
+ //catch
|
|
|
+ //{
|
|
|
+ // MessageBox.Show(CheckErrors(), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+
|
|
|
+ //}
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
}
|