瀏覽代碼

Сохранение работает
очень криво

Danila Alekseev 1 年之前
父節點
當前提交
d059bf973d
共有 3 個文件被更改,包括 90 次插入15 次删除
  1. 1 1
      ROGOZ/Pages/AddEditPage.xaml
  2. 75 0
      ROGOZ/Pages/AddEditPage.xaml.cs
  3. 14 14
      ROGOZ/Pages/AddTask.xaml.cs

+ 1 - 1
ROGOZ/Pages/AddEditPage.xaml

@@ -62,7 +62,7 @@
 
         <StackPanel Width="700" Height="70" Orientation="Horizontal" VerticalAlignment="Bottom" Margin="0,20,0,5">
             <Button x:Name="BtnCancel" Content="Отмена" Style="{StaticResource AuthoButtons}" Click="BtnCancel_Click"/>
-            <Button x:Name="BtnSaveTask" Content="Сохранить" Style="{StaticResource AuthoButtons}" Margin="100,0,0,0"/>
+            <Button x:Name="BtnSaveTask" Content="Сохранить" Style="{StaticResource AuthoButtons}" Margin="100,0,0,0" Click="BtnSaveTask_Click"/>
         </StackPanel>
 
     </Grid>

+ 75 - 0
ROGOZ/Pages/AddEditPage.xaml.cs

@@ -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);
+
+                    //}
+                }
+
+            }
+
+        }
     }
 }

+ 14 - 14
ROGOZ/Pages/AddTask.xaml.cs

@@ -15,20 +15,20 @@ using System.Windows.Shapes;
 using System.Data.Entity.Migrations;
 using System.Linq.Expressions;
 
-namespace ROGOZ.Pages
-{
-    /// <summary>
-    /// Логика взаимодействия для AddTask.xaml
-    /// </summary>
-    public partial class AddTask : Page
-    {
-        private Task _currentTask = new Task();
-        public AddTask()
-        {
-            InitializeComponent();
+//namespace ROGOZ.Pages
+//{
+//    /// <summary>
+//    /// Логика взаимодействия для AddTask.xaml
+//    /// </summary>
+//    public partial class AddTask : Page
+//    {
+//        private Task _currentTask = new Task();
+//        public AddTask()
+//        {
+//            InitializeComponent();
             
 
-        }
+//        }
 
 
         //public AddTask(Task selectedTask)
@@ -123,5 +123,5 @@ namespace ROGOZ.Pages
         //    }
         //    return errorBuilder.ToString();
         //}
-    }
-}
+//    }
+//}