Эх сурвалжийг харах

Сохра не работает

Danila Alekseev 1 жил өмнө
parent
commit
e160044fc4

+ 1 - 0
ROGOZ/MainWindow.xaml.cs

@@ -76,5 +76,6 @@ namespace ROGOZ
         {
             MainFrame.Navigate(new Pages.TaskList());
         }
+
     }
 }

+ 5 - 5
ROGOZ/Pages/AddTask.xaml

@@ -17,32 +17,32 @@
             <StackPanel Orientation="Vertical" HorizontalAlignment="Center" Height="370" Width="750" Margin="0,20,0,0">
                 <StackPanel Orientation="Horizontal" Width="750" Margin="0,15,0,0">
                     <TextBlock Text="Задача:" Style="{StaticResource BlockHeader}" HorizontalAlignment="Left" FontSize="35"/>
-                    <TextBox x:Name="TaskName" Width="450" Height="35" Margin="135,0,0,0" Style="{StaticResource TextBoxStyle}"/>
+                    <TextBox x:Name="TaskName" Width="450" Height="35" Margin="135,0,0,0" Style="{StaticResource TextBoxStyle}" FontSize="20" Text="{Binding Title}"/>
                 </StackPanel>
 
                 <Separator Background="{x:Null}" Height="15"/>
 
                 <StackPanel Orientation="Horizontal" Width="750" Margin="0,15,0,0">
                     <TextBlock Text="Статус:" Style="{StaticResource BlockHeader}" HorizontalAlignment="Left" FontSize="35"/>
-                    <ComboBox x:Name="StatusBox" Width="450" Height="35" Margin="142,0,0,0" SelectedItem="{Binding Status}"/>
+                    <ComboBox x:Name="StatusBox" Width="450" Height="35" Margin="142,0,0,0" Text="{Binding Status}" DisplayMemberPath="Name"/>
                 </StackPanel>
                 <Separator Background="{x:Null}" Height="15"/>
 
                 <StackPanel Orientation="Horizontal" Width="750" Margin="0,15,0,0">
                     <TextBlock Text="Исполнитель:" Style="{StaticResource BlockHeader}" HorizontalAlignment="Left" FontSize="35"/>
-                    <ComboBox x:Name="ExecutorBox" Width="450" Height="35" Margin="25,0,0,0" SelectedItem="{Binding Executor.User.MiddleName}"/>
+                    <ComboBox x:Name="ExecutorBox" Width="450" Height="35" Margin="25,0,0,0" SelectedItem="{Binding Executor.User.MiddleName}" DisplayMemberPath="ID"/>
                 </StackPanel>
                 <Separator Background="{x:Null}" Height="15"/>
 
                 <StackPanel Orientation="Horizontal" Width="750" Margin="0,15,0,0">
                     <TextBlock Text="Менеджер:" Style="{StaticResource BlockHeader}" HorizontalAlignment="Left" FontSize="35"/>
-                    <ComboBox x:Name="ManagerBox" Width="450" Height="35" Margin="83,0,0,0" SelectedItem="{Binding Manager.User.MiddleName}"/>
+                    <ComboBox x:Name="ManagerBox" Width="450" Height="35" Margin="83,0,0,0" SelectedItem="{Binding Manager.User.MiddleName}" DisplayMemberPath="ID"/>
                 </StackPanel>
             </StackPanel>
             <StackPanel Width="700" Height="70" Orientation="Horizontal" Margin="0,20">
 
                 <Button Content="Отмена" Style="{StaticResource AuthoButtons}" Click="Button_Click"/>
-                <Button Content="Сохранить" Style="{StaticResource AuthoButtons}" Margin="100,0,0,0"/>
+                <Button Content="Сохранить" Name="NewTaskSave" Style="{StaticResource AuthoButtons}" Margin="100,0,0,0" Click="NewTaskSave_Click"/>
 
             </StackPanel>
         </StackPanel>

+ 91 - 2
ROGOZ/Pages/AddTask.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.Data.Entity.Migrations;
+using System.Linq.Expressions;
 
 namespace ROGOZ.Pages
 {
@@ -24,14 +26,101 @@ namespace ROGOZ.Pages
         public AddTask()
         {
             InitializeComponent();
-            StatusBox.ItemsSource = user1Entities.GetContext().Task.ToList();
+            
+
+        }
+
+        public AddTask(Task selectedTask)
+        {
+            InitializeComponent();
+            StatusBox.ItemsSource = Status.FillStatus();
             ExecutorBox.ItemsSource = user1Entities.GetContext().Executor.ToList();
             ManagerBox.ItemsSource = user1Entities.GetContext().Manager.ToList();
         }
 
         private void Button_Click(object sender, RoutedEventArgs e)
         {
-            NavigationService.Navigate(new TaskList());
+            NavigationService.GoBack();
+        }
+
+        private void NewTaskSave_Click(object sender, RoutedEventArgs e)
+        {
+
+            var errorMessage = CheckErrors();
+            if (errorMessage.Length > 0)
+            {
+                MessageBox.Show(errorMessage, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
+            }
+            else
+            {
+                if (_currentTask != null)
+                {
+                    var selectedTask = new Task
+                    {
+                        Title = TaskName.Text,
+                        Status = StatusBox.Text,
+                        ExecutorID = int.Parse(ExecutorBox.Text),
+                        
+                    };
+                    user1Entities.GetContext().Task.Add(_currentTask);
+                    user1Entities.GetContext().SaveChanges();
+                    //App.Context.Task.Add(selectedTask);
+                    //App.Context.SaveChanges();
+                    //MessageBox.Show("Добавление успешно выполнено");
+                    //NavigationService.GoBack();
+                }
+
+                NavigationService.GoBack();
+            }
+
+            //StringBuilder errors = new StringBuilder();
+
+            //if (string.IsNullOrEmpty(_currentTask.Title))
+            //    errors.AppendLine("Укажите название задачи");
+            //if (_currentTask.Status == null)
+            //    errors.AppendLine("Выберите статус задачи");
+            //if (_currentTask.Executor == null)
+            //    errors.AppendLine("Выберите исполнителя");
+
+            //if (errors.Length > 0)
+            //{
+            //    MessageBox.Show(errors.ToString());
+            //    return;
+            //}
+            //if (_currentTask.ID == 0)
+            //    user1Entities.GetContext().Task.Add(_currentTask);
+            //try
+            //{
+            //    user1Entities.GetContext().SaveChanges();
+            //    MessageBox.Show("Задача добавлена");
+            //    NavigationService.GoBack();
+            //}
+            //catch (Exception ex)
+            //{
+            //    MessageBox.Show(ex.Message.ToString());
+            //}
+
+        }
+        private string CheckErrors()
+        {
+            var errorBuilder = new StringBuilder();
+
+            //Проверка на заполнение наименования Задачи
+            if (string.IsNullOrWhiteSpace(TaskName.Text))
+                errorBuilder.AppendLine("Название задачи обязательно для заполнения");
+            //if (_currentTask.Status == null)
+            //    errorBuilder.AppendLine("Выберите статус задачи");
+            //if (_currentTask.Executor == null)
+            //    errorBuilder.AppendLine("Выберите исполнителя");
+
+
+
+            //Просто вывод ошибок, которые нужно исправить
+            if (errorBuilder.Length > 0)
+            {
+                errorBuilder.Insert(0, "Устраните следующие ошибки:\n");
+            }
+            return errorBuilder.ToString();
         }
     }
 }

+ 1 - 0
ROGOZ/ROGOZ.csproj

@@ -101,6 +101,7 @@
     <Compile Include="Pages\General.xaml.cs">
       <DependentUpon>General.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Status.cs" />
     <Compile Include="Task.cs">
       <DependentUpon>Model1.tt</DependentUpon>
     </Compile>

+ 32 - 0
ROGOZ/Status.cs

@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ROGOZ
+{
+    internal class Status
+    {
+
+        string name;
+
+        public string Name
+        {
+            get { return name; }
+            set { name = value; }
+        }
+
+        public static List<Status> FillStatus()
+        {
+            List<Status> list = new List<Status>
+            {
+                new Status { Name = "запланирована" },
+                new Status { Name = "принята к исполнению" },
+                new Status { Name = "выполнена" },
+                new Status { Name = "отменена" }
+            };
+            return list;
+        }
+    }
+}