ソースを参照

Вставка данных

Danila Alekseev 2 年 前
コミット
7f988758e9
4 ファイル変更51 行追加4 行削除
  1. 13 0
      LR1/Entities/Employee.cs
  2. 12 0
      LR1/LR1.csproj
  3. 22 4
      LR1/Workers.xaml.cs
  4. 4 0
      LR1/packages.config

+ 13 - 0
LR1/Entities/Employee.cs

@@ -24,5 +24,18 @@ namespace LR1.Entities
         public Nullable<int> TitleID { get; set; }
     
         public virtual Title Title { get; set; }
+
+        internal static Employee CreateEmployee(int id, string surname, string name, string patronymic, int titleId)
+        {
+            Employee employee = new Employee
+            {
+                ID = id,
+                Surname = surname,
+                Name = name,
+                Patronymic = patronymic,
+                TitleID = titleId
+            };
+            return employee;
+        }
     }
 }

+ 12 - 0
LR1/LR1.csproj

@@ -41,11 +41,23 @@
     <Reference Include="EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
       <HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
     </Reference>
+    <Reference Include="Microsoft.Data.Edm, Version=5.8.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+      <HintPath>..\packages\Microsoft.Data.Edm.5.8.5\lib\net40\Microsoft.Data.Edm.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.Data.OData, Version=5.8.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+      <HintPath>..\packages\Microsoft.Data.OData.5.8.5\lib\net40\Microsoft.Data.OData.dll</HintPath>
+    </Reference>
+    <Reference Include="Microsoft.Data.Services.Client, Version=5.8.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+      <HintPath>..\packages\Microsoft.Data.Services.Client.5.8.5\lib\net40\Microsoft.Data.Services.Client.dll</HintPath>
+    </Reference>
     <Reference Include="System" />
     <Reference Include="System.ComponentModel.DataAnnotations" />
     <Reference Include="System.Data" />
     <Reference Include="System.Runtime.Serialization" />
     <Reference Include="System.Security" />
+    <Reference Include="System.Spatial, Version=5.8.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+      <HintPath>..\packages\System.Spatial.5.8.5\lib\net40\System.Spatial.dll</HintPath>
+    </Reference>
     <Reference Include="System.Xml" />
     <Reference Include="Microsoft.CSharp" />
     <Reference Include="System.Core" />

+ 22 - 4
LR1/Workers.xaml.cs

@@ -2,7 +2,8 @@
 using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
-//using System.Data.Entity.Core.Objects;
+using System.Data.Services.Client;
+using System.Data.Entity.Core.Objects;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -66,9 +67,26 @@ namespace LR1
 
         private void AddCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e)
         {
-            MessageBox.Show("Создание");
-            isDirty = false;
-            isLoaded = true;
+            Employee employee = Employee.CreateEmployee(-1, "не задано", "не задано", "не задано", 0);
+            employee.Telephone = "не задано";
+            employee.Email = "не задано";
+            try
+            {
+                DataEntitiesEmployee.Employees.Add(employee);
+                ListEmployee.Add(employee);
+                DataGridEmployee.ScrollIntoView(employee);
+                DataGridEmployee.SelectedIndex = DataGridEmployee.Items.Count - 1;
+                DataGridEmployee.Focus();
+                DataGridEmployee.IsReadOnly = false;
+
+                MessageBox.Show("Создание");
+                isDirty = false;
+                isLoaded = true;
+            }
+            catch (DataServiceRequestException ex)
+            {
+                throw new ApplicationException("Ошибка добавления нового сотрудника в контекст данных" + ex.ToString());
+            }
         }
 
         private void EditCommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)

+ 4 - 0
LR1/packages.config

@@ -2,4 +2,8 @@
 <packages>
   <package id="EntityFramework" version="6.2.0" targetFramework="net472" />
   <package id="EntityFramework.ru" version="6.2.0" targetFramework="net472" />
+  <package id="Microsoft.Data.Edm" version="5.8.5" targetFramework="net472" />
+  <package id="Microsoft.Data.OData" version="5.8.5" targetFramework="net472" />
+  <package id="Microsoft.Data.Services.Client" version="5.8.5" targetFramework="net472" />
+  <package id="System.Spatial" version="5.8.5" targetFramework="net472" />
 </packages>