Kaynağa Gözat

fix cb employee

Сергей Москаленко 5 ay önce
ebeveyn
işleme
7937238f40
1 değiştirilmiş dosya ile 17 ekleme ve 4 silme
  1. 17 4
      PP_Ven_MosS/Pages/MenuAdmin.xaml.cs

+ 17 - 4
PP_Ven_MosS/Pages/MenuAdmin.xaml.cs

@@ -6,6 +6,7 @@ using System.Collections.ObjectModel;
 using System.Linq;
 using System.Windows;
 using System.Windows.Controls;
+using static System.Net.Mime.MediaTypeNames;
 
 namespace PP_Ven_MosS.Pages
 {
@@ -50,6 +51,7 @@ namespace PP_Ven_MosS.Pages
                 EmployeeID.employeeid = Convert.ToInt32(cb.SelectedValue);
             }
         }
+
         private void Report_Click(object sender, RoutedEventArgs e)
         {
             Button btn = (Button)sender;
@@ -62,8 +64,6 @@ namespace PP_Ven_MosS.Pages
         {
             PP_MininEntities DB = new PP_MininEntities();
             ComboBox cb = (ComboBox)sender;
-            cb.DisplayMemberPath = "Surname";
-            cb.SelectedValuePath = "Id_user";
             if (cb.Uid != null)
             {
                 int appId = int.Parse(cb.Uid);
@@ -72,8 +72,21 @@ namespace PP_Ven_MosS.Pages
                 {
                     if (ap != null)
                     {
-                        ap.Id_employee = Convert.ToInt32(cb.SelectedValue);
-                        DB.SaveChanges();
+                        var apps = DB.Applications.Where(x => x.Date_app == ap.Date_app).ToList();
+                        var busyEmployees = apps.Where(x => x.Id_application != appId).Select(x => x.Id_employee).ToList();
+                        if (!busyEmployees.Contains(Convert.ToInt32(cb.SelectedValue)))
+                        {
+                            ap.Id_employee = Convert.ToInt32(cb.SelectedValue);
+                            DB.SaveChanges();
+                        }
+                        else
+                        {
+                            MessageBox.Show("Сотрудик занят на этот день!");
+                            cb.SelectedValue = null;
+                            ap.Id_employee = Convert.ToInt32(cb.SelectedValue);
+                            DB.SaveChanges();
+                        }
+                        
                     }
                 }