From 64d1d192e614c22841b1a4b0d856c9574e24cd13 Mon Sep 17 00:00:00 2001 From: kamilia Date: Mon, 28 Oct 2024 23:23:14 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B2=D1=80=D0=BE=D0=B4=D0=B5=20=D0=B2=D1=81?= =?UTF-8?q?=D1=91=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=D0=B0,=20=D0=BD?= =?UTF-8?q?=D0=B5=D1=82=20=D1=81=D0=B8=D0=BB=20=D0=BF=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D1=8F=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- COP_7/COP_7.sln | 28 +- COP_7/Components.csproj | 1 + EmployeeLogic/BusinessLogics/EmployeeLogic.cs | 68 +++++ EmployeeLogic/BusinessLogics/PostLogic.cs | 66 +++++ EmployeeLogic/EmployeeLogic.csproj | 14 + .../BindingModels/EmployeeBindingModel.cs | 21 ++ .../BindingModels/PostBindingModel.cs | 15 + .../BusinessLogicsContracts/IEmployeeLogic.cs | 17 ++ .../BusinessLogicsContracts/IPostLogic.cs | 17 ++ EmployeesContracts/EmployeesContracts.csproj | 14 + .../StorageContracts/IEmployeeStorage.cs | 21 ++ .../StorageContracts/IPostStorage.cs | 21 ++ .../ViewModels/EmployeeViewModel.cs | 24 ++ .../ViewModels/PostViewModel.cs | 15 + .../EmployeesDatabase.cs | 21 ++ .../EmployeesDatabaseImplement.csproj | 27 ++ .../Implements/EmployeeStorage.cs | 125 +++++++++ .../Implements/PostStorage.cs | 120 ++++++++ .../20241028190655_Initial.Designer.cs | 75 +++++ .../Migrations/20241028190655_Initial.cs | 54 ++++ .../EmployeesDatabaseModelSnapshot.cs | 72 +++++ EmployeesDatabaseImplement/Models/Employee.cs | 25 ++ EmployeesDatabaseImplement/Models/Post.cs | 17 ++ EmployeesView/EmployeesView.csproj | 29 ++ EmployeesView/FormEmployee.Designer.cs | 197 +++++++++++++ EmployeesView/FormEmployee.cs | 119 ++++++++ EmployeesView/FormEmployee.resx | 60 ++++ EmployeesView/FormMain.Designer.cs | 193 +++++++++++++ EmployeesView/FormMain.cs | 260 ++++++++++++++++++ EmployeesView/FormMain.resx | 72 +++++ EmployeesView/FormPost.Designer.cs | 67 +++++ EmployeesView/FormPost.cs | 117 ++++++++ EmployeesView/FormPost.resx | 60 ++++ EmployeesView/Program.cs | 39 +++ 34 files changed, 2089 insertions(+), 2 deletions(-) create mode 100644 EmployeeLogic/BusinessLogics/EmployeeLogic.cs create mode 100644 EmployeeLogic/BusinessLogics/PostLogic.cs create mode 100644 EmployeeLogic/EmployeeLogic.csproj create mode 100644 EmployeesContracts/BindingModels/EmployeeBindingModel.cs create mode 100644 EmployeesContracts/BindingModels/PostBindingModel.cs create mode 100644 EmployeesContracts/BusinessLogicsContracts/IEmployeeLogic.cs create mode 100644 EmployeesContracts/BusinessLogicsContracts/IPostLogic.cs create mode 100644 EmployeesContracts/EmployeesContracts.csproj create mode 100644 EmployeesContracts/StorageContracts/IEmployeeStorage.cs create mode 100644 EmployeesContracts/StorageContracts/IPostStorage.cs create mode 100644 EmployeesContracts/ViewModels/EmployeeViewModel.cs create mode 100644 EmployeesContracts/ViewModels/PostViewModel.cs create mode 100644 EmployeesDatabaseImplement/EmployeesDatabase.cs create mode 100644 EmployeesDatabaseImplement/EmployeesDatabaseImplement.csproj create mode 100644 EmployeesDatabaseImplement/Implements/EmployeeStorage.cs create mode 100644 EmployeesDatabaseImplement/Implements/PostStorage.cs create mode 100644 EmployeesDatabaseImplement/Migrations/20241028190655_Initial.Designer.cs create mode 100644 EmployeesDatabaseImplement/Migrations/20241028190655_Initial.cs create mode 100644 EmployeesDatabaseImplement/Migrations/EmployeesDatabaseModelSnapshot.cs create mode 100644 EmployeesDatabaseImplement/Models/Employee.cs create mode 100644 EmployeesDatabaseImplement/Models/Post.cs create mode 100644 EmployeesView/EmployeesView.csproj create mode 100644 EmployeesView/FormEmployee.Designer.cs create mode 100644 EmployeesView/FormEmployee.cs create mode 100644 EmployeesView/FormEmployee.resx create mode 100644 EmployeesView/FormMain.Designer.cs create mode 100644 EmployeesView/FormMain.cs create mode 100644 EmployeesView/FormMain.resx create mode 100644 EmployeesView/FormPost.Designer.cs create mode 100644 EmployeesView/FormPost.cs create mode 100644 EmployeesView/FormPost.resx create mode 100644 EmployeesView/Program.cs diff --git a/COP_7/COP_7.sln b/COP_7/COP_7.sln index 155c14f..8b08e59 100644 --- a/COP_7/COP_7.sln +++ b/COP_7/COP_7.sln @@ -3,9 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34723.18 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Components", "Components.csproj", "{0E0FD0F8-FAD2-4C5F-9F4E-E53516BCB322}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Components", "Components.csproj", "{0E0FD0F8-FAD2-4C5F-9F4E-E53516BCB322}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FormTest", "..\FormTest\FormTest.csproj", "{EB2A68E5-EF5C-48B2-90DF-E5CA53F65202}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FormTest", "..\FormTest\FormTest.csproj", "{EB2A68E5-EF5C-48B2-90DF-E5CA53F65202}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmployeesView", "..\EmployeesView\EmployeesView.csproj", "{B5FD4B5D-633F-44AD-B053-E6580DC81C62}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmployeeLogic", "..\EmployeeLogic\EmployeeLogic.csproj", "{526F24BD-B78A-4438-9AB7-C1A17DBB1295}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmployeesContracts", "..\EmployeesContracts\EmployeesContracts.csproj", "{2C1D8FF8-1097-41F4-AF5F-954C9AC93433}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmployeesDatabaseImplement", "..\EmployeesDatabaseImplement\EmployeesDatabaseImplement.csproj", "{79336B31-79AD-4BA9-9249-AECADC90E7C2}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -21,6 +29,22 @@ Global {EB2A68E5-EF5C-48B2-90DF-E5CA53F65202}.Debug|Any CPU.Build.0 = Debug|Any CPU {EB2A68E5-EF5C-48B2-90DF-E5CA53F65202}.Release|Any CPU.ActiveCfg = Release|Any CPU {EB2A68E5-EF5C-48B2-90DF-E5CA53F65202}.Release|Any CPU.Build.0 = Release|Any CPU + {B5FD4B5D-633F-44AD-B053-E6580DC81C62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B5FD4B5D-633F-44AD-B053-E6580DC81C62}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B5FD4B5D-633F-44AD-B053-E6580DC81C62}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B5FD4B5D-633F-44AD-B053-E6580DC81C62}.Release|Any CPU.Build.0 = Release|Any CPU + {526F24BD-B78A-4438-9AB7-C1A17DBB1295}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {526F24BD-B78A-4438-9AB7-C1A17DBB1295}.Debug|Any CPU.Build.0 = Debug|Any CPU + {526F24BD-B78A-4438-9AB7-C1A17DBB1295}.Release|Any CPU.ActiveCfg = Release|Any CPU + {526F24BD-B78A-4438-9AB7-C1A17DBB1295}.Release|Any CPU.Build.0 = Release|Any CPU + {2C1D8FF8-1097-41F4-AF5F-954C9AC93433}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2C1D8FF8-1097-41F4-AF5F-954C9AC93433}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2C1D8FF8-1097-41F4-AF5F-954C9AC93433}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2C1D8FF8-1097-41F4-AF5F-954C9AC93433}.Release|Any CPU.Build.0 = Release|Any CPU + {79336B31-79AD-4BA9-9249-AECADC90E7C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {79336B31-79AD-4BA9-9249-AECADC90E7C2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {79336B31-79AD-4BA9-9249-AECADC90E7C2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {79336B31-79AD-4BA9-9249-AECADC90E7C2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/COP_7/Components.csproj b/COP_7/Components.csproj index d5466ef..d890249 100644 --- a/COP_7/Components.csproj +++ b/COP_7/Components.csproj @@ -5,6 +5,7 @@ enable true enable + True diff --git a/EmployeeLogic/BusinessLogics/EmployeeLogic.cs b/EmployeeLogic/BusinessLogics/EmployeeLogic.cs new file mode 100644 index 0000000..67a43d2 --- /dev/null +++ b/EmployeeLogic/BusinessLogics/EmployeeLogic.cs @@ -0,0 +1,68 @@ +using EmployeesContracts.BindingModels; +using EmployeesContracts.BusinessLogicsContracts; +using EmployeesContracts.StorageContracts; +using EmployeesContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EmployeeLogic.BusinessLogics +{ + public class EmployeeLogic : IEmployeeLogic + { + private readonly IEmployeeStorage _employeeStorage; + + public EmployeeLogic(IEmployeeStorage employeeStorage) + { + _employeeStorage = employeeStorage; + } + public void CreateOrUpdate(EmployeeBindingModel model) + { + var element = _employeeStorage.GetElement( + new EmployeeBindingModel + { + Autobiography = model.Autobiography, + Name = model.Name, + Post = model.Post, + Upgrade = model.Upgrade + }); + if (element != null && element.Id != model.Id) + { + throw new Exception("Сотрудник с таким именем уже существует"); + } + if (model.Id.HasValue) + { + _employeeStorage.Update(model); + } + else + { + _employeeStorage.Insert(model); + } + } + + public void Delete(EmployeeBindingModel model) + { + var element = _employeeStorage.GetElement(new EmployeeBindingModel { Id = model.Id }); + if (element == null) + { + throw new Exception("Сотрудник не найден"); + } + _employeeStorage.Delete(model); + } + + public List Read(EmployeeBindingModel model) + { + if (model == null) + { + return _employeeStorage.GetFullList(); + } + if (model.Id.HasValue) + { + return new List { _employeeStorage.GetElement(model) }; + } + return _employeeStorage.GetFilteredList(model); + } + } +} diff --git a/EmployeeLogic/BusinessLogics/PostLogic.cs b/EmployeeLogic/BusinessLogics/PostLogic.cs new file mode 100644 index 0000000..cb51ead --- /dev/null +++ b/EmployeeLogic/BusinessLogics/PostLogic.cs @@ -0,0 +1,66 @@ +using EmployeesContracts.BindingModels; +using EmployeesContracts.BusinessLogicsContracts; +using EmployeesContracts.StorageContracts; +using EmployeesContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EmployeeLogic.BusinessLogics +{ + public class PostLogic : IPostLogic + { + private readonly IPostStorage _postStorage; + + public PostLogic(IPostStorage postStorage) + { + _postStorage = postStorage; + } + + public void CreateOrUpdate(PostBindingModel model) + { + var element = _postStorage.GetElement( + new PostBindingModel + { + Name = model.Name + }); + if (element != null && element.Id != model.Id) + { + throw new Exception("Такая должность уже существует"); + } + if (model.Id.HasValue) + { + _postStorage.Update(model); + } + else + { + _postStorage.Insert(model); + } + } + + public void Delete(PostBindingModel model) + { + var element = _postStorage.GetElement(new PostBindingModel { Id = model.Id }); + if (element == null) + { + throw new Exception("Должность не найдена"); + } + _postStorage.Delete(model); + } + + public List Read(PostBindingModel model) + { + if (model == null) + { + return _postStorage.GetFullList(); + } + if (model.Id.HasValue) + { + return new List { _postStorage.GetElement(model) }; + } + return _postStorage.GetFilteredList(model); + } + } +} diff --git a/EmployeeLogic/EmployeeLogic.csproj b/EmployeeLogic/EmployeeLogic.csproj new file mode 100644 index 0000000..d21c688 --- /dev/null +++ b/EmployeeLogic/EmployeeLogic.csproj @@ -0,0 +1,14 @@ + + + + net6.0-windows + enable + true + enable + + + + + + + diff --git a/EmployeesContracts/BindingModels/EmployeeBindingModel.cs b/EmployeesContracts/BindingModels/EmployeeBindingModel.cs new file mode 100644 index 0000000..237a7df --- /dev/null +++ b/EmployeesContracts/BindingModels/EmployeeBindingModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EmployeesContracts.BindingModels +{ + public class EmployeeBindingModel + { + public int? Id { get; set; } + + public string Name { get; set; } + + public string Autobiography { get; set; } + + public string Post { get; set; } + + public DateTime? Upgrade { get; set; } + } +} diff --git a/EmployeesContracts/BindingModels/PostBindingModel.cs b/EmployeesContracts/BindingModels/PostBindingModel.cs new file mode 100644 index 0000000..e807106 --- /dev/null +++ b/EmployeesContracts/BindingModels/PostBindingModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EmployeesContracts.BindingModels +{ + public class PostBindingModel + { + public int? Id { get; set; } + + public string Name { get; set; } + } +} diff --git a/EmployeesContracts/BusinessLogicsContracts/IEmployeeLogic.cs b/EmployeesContracts/BusinessLogicsContracts/IEmployeeLogic.cs new file mode 100644 index 0000000..edf6025 --- /dev/null +++ b/EmployeesContracts/BusinessLogicsContracts/IEmployeeLogic.cs @@ -0,0 +1,17 @@ +using EmployeesContracts.BindingModels; +using EmployeesContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EmployeesContracts.BusinessLogicsContracts +{ + public interface IEmployeeLogic + { + List Read(EmployeeBindingModel model); + void CreateOrUpdate(EmployeeBindingModel model); + void Delete(EmployeeBindingModel model); + } +} diff --git a/EmployeesContracts/BusinessLogicsContracts/IPostLogic.cs b/EmployeesContracts/BusinessLogicsContracts/IPostLogic.cs new file mode 100644 index 0000000..08ba513 --- /dev/null +++ b/EmployeesContracts/BusinessLogicsContracts/IPostLogic.cs @@ -0,0 +1,17 @@ +using EmployeesContracts.BindingModels; +using EmployeesContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EmployeesContracts.BusinessLogicsContracts +{ + public interface IPostLogic + { + List Read(PostBindingModel model); + void CreateOrUpdate(PostBindingModel model); + void Delete(PostBindingModel model); + } +} diff --git a/EmployeesContracts/EmployeesContracts.csproj b/EmployeesContracts/EmployeesContracts.csproj new file mode 100644 index 0000000..c95d148 --- /dev/null +++ b/EmployeesContracts/EmployeesContracts.csproj @@ -0,0 +1,14 @@ + + + + net6.0-windows + enable + true + enable + + + + + + + diff --git a/EmployeesContracts/StorageContracts/IEmployeeStorage.cs b/EmployeesContracts/StorageContracts/IEmployeeStorage.cs new file mode 100644 index 0000000..7b6b778 --- /dev/null +++ b/EmployeesContracts/StorageContracts/IEmployeeStorage.cs @@ -0,0 +1,21 @@ +using EmployeesContracts.BindingModels; +using EmployeesContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EmployeesContracts.StorageContracts +{ + public interface IEmployeeStorage + { + List GetFullList(); + List GetFilteredList(EmployeeBindingModel model); + EmployeeViewModel GetElement(EmployeeBindingModel model); + + void Insert(EmployeeBindingModel model); + void Update(EmployeeBindingModel model); + void Delete(EmployeeBindingModel model); + } +} diff --git a/EmployeesContracts/StorageContracts/IPostStorage.cs b/EmployeesContracts/StorageContracts/IPostStorage.cs new file mode 100644 index 0000000..9bbce12 --- /dev/null +++ b/EmployeesContracts/StorageContracts/IPostStorage.cs @@ -0,0 +1,21 @@ +using EmployeesContracts.BindingModels; +using EmployeesContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EmployeesContracts.StorageContracts +{ + public interface IPostStorage + { + List GetFullList(); + List GetFilteredList(PostBindingModel model); + PostViewModel GetElement(PostBindingModel model); + + void Insert(PostBindingModel model); + void Update(PostBindingModel model); + void Delete(PostBindingModel model); + } +} diff --git a/EmployeesContracts/ViewModels/EmployeeViewModel.cs b/EmployeesContracts/ViewModels/EmployeeViewModel.cs new file mode 100644 index 0000000..dd0ee93 --- /dev/null +++ b/EmployeesContracts/ViewModels/EmployeeViewModel.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EmployeesContracts.ViewModels +{ + public class EmployeeViewModel + { + public int? Id { get; set; } + + [DisplayName("Название")] + public string Name { get; set; } + + [DisplayName("Автобиография")] + public string Autobiography { get; set; } + [DisplayName("Должность")] + public string Post { get; set; } + [DisplayName("Дата повышения квалификации")] + public DateTime? Upgrade { get; set; } + } +} diff --git a/EmployeesContracts/ViewModels/PostViewModel.cs b/EmployeesContracts/ViewModels/PostViewModel.cs new file mode 100644 index 0000000..ea63220 --- /dev/null +++ b/EmployeesContracts/ViewModels/PostViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EmployeesContracts.ViewModels +{ + public class PostViewModel + { + public int? Id { get; set; } + + public string Name { get; set; } + } +} diff --git a/EmployeesDatabaseImplement/EmployeesDatabase.cs b/EmployeesDatabaseImplement/EmployeesDatabase.cs new file mode 100644 index 0000000..a173808 --- /dev/null +++ b/EmployeesDatabaseImplement/EmployeesDatabase.cs @@ -0,0 +1,21 @@ +using EmployeesDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; + +namespace EmployeesDatabaseImplement +{ + public class EmployeesDatabase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-6QDRI0N\SQLEXPRESS;Initial Catalog=DatabaseEmployees;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + } + base.OnConfiguring(optionsBuilder); + } + + public virtual DbSet Employees { set; get; } + + public virtual DbSet Posts { set; get; } + } +} \ No newline at end of file diff --git a/EmployeesDatabaseImplement/EmployeesDatabaseImplement.csproj b/EmployeesDatabaseImplement/EmployeesDatabaseImplement.csproj new file mode 100644 index 0000000..b6d7b9f --- /dev/null +++ b/EmployeesDatabaseImplement/EmployeesDatabaseImplement.csproj @@ -0,0 +1,27 @@ + + + + net6.0-windows + enable + enable + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + \ No newline at end of file diff --git a/EmployeesDatabaseImplement/Implements/EmployeeStorage.cs b/EmployeesDatabaseImplement/Implements/EmployeeStorage.cs new file mode 100644 index 0000000..3781b04 --- /dev/null +++ b/EmployeesDatabaseImplement/Implements/EmployeeStorage.cs @@ -0,0 +1,125 @@ +using EmployeesContracts.BindingModels; +using EmployeesContracts.StorageContracts; +using EmployeesContracts.ViewModels; +using EmployeesDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EmployeesDatabaseImplement.Implements +{ + public class EmployeeStorage : IEmployeeStorage + { + public void Delete(EmployeeBindingModel model) + { + var context = new EmployeesDatabase(); + var employee = context.Employees.FirstOrDefault(rec => rec.Id == model.Id); + if (employee != null) + { + context.Employees.Remove(employee); + context.SaveChanges(); + } + else + { + throw new Exception("Сотрудник не найден"); + } + } + + public EmployeeViewModel GetElement(EmployeeBindingModel model) + { + if (model == null) + { + return null; + } + using var context = new EmployeesDatabase(); + var employee = context.Employees + .ToList() + .FirstOrDefault(rec => rec.Id == model.Id); + return employee != null ? CreateModel(employee) : null; + } + + public List GetFilteredList(EmployeeBindingModel model) + { + var context = new EmployeesDatabase(); + return context.Employees + .Where(employee => employee.Name.Contains(model.Name) && employee.Post.Contains(model.Post)) + .ToList() + .Select(CreateModel) + .ToList(); + } + + public List GetFullList() + { + using (var context = new EmployeesDatabase()) + { + return context.Employees + .ToList() + .Select(CreateModel) + .ToList(); + } + } + + public void Insert(EmployeeBindingModel model) + { + var context = new EmployeesDatabase(); + var transaction = context.Database.BeginTransaction(); + try + { + context.Employees.Add(CreateModel(model, new Employee())); + context.SaveChanges(); + transaction.Commit(); + } + catch + { + transaction.Rollback(); + throw; + } + } + + public void Update(EmployeeBindingModel model) + { + var context = new EmployeesDatabase(); + var transaction = context.Database.BeginTransaction(); + try + { + var employee = context.Employees.FirstOrDefault(rec => rec.Id == model.Id); + if (employee == null) + { + throw new Exception("Сотрудник не найден"); + } + CreateModel(model, employee); + context.SaveChanges(); + transaction.Commit(); + } + catch + { + transaction.Rollback(); + throw; + } + } + + private static Employee CreateModel(EmployeeBindingModel model, Employee employee) + { + employee.Upgrade = model.Upgrade; + employee.Name = model.Name; + employee.Post = model.Post; + employee.Autobiography = model.Autobiography; + + return employee; + } + + private EmployeeViewModel CreateModel(Employee employee) + { + return new EmployeeViewModel + { + Id = employee.Id, + Upgrade = employee.Upgrade, + Name = employee.Name, + Post = employee.Post, + Autobiography = employee.Autobiography + }; + } + } +} diff --git a/EmployeesDatabaseImplement/Implements/PostStorage.cs b/EmployeesDatabaseImplement/Implements/PostStorage.cs new file mode 100644 index 0000000..fd62d1d --- /dev/null +++ b/EmployeesDatabaseImplement/Implements/PostStorage.cs @@ -0,0 +1,120 @@ +using EmployeesContracts.BindingModels; +using EmployeesContracts.StorageContracts; +using EmployeesContracts.ViewModels; +using EmployeesDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EmployeesDatabaseImplement.Implements +{ + public class PostStorage : IPostStorage + { + public void Delete(PostBindingModel model) + { + var context = new EmployeesDatabase(); + var post = context.Posts.FirstOrDefault(rec => rec.Id == model.Id); + if (post != null) + { + context.Posts.Remove(post); + context.SaveChanges(); + } + else + { + throw new Exception("Должность не найдена"); + } + } + + public PostViewModel GetElement(PostBindingModel model) + { + if (model == null) + { + return null; + } + using var context = new EmployeesDatabase(); + + var post = context.Posts + .ToList() + .FirstOrDefault(rec => rec.Id == model.Id || rec.Name == model.Name); + return post != null ? CreateModel(post) : null; + } + + + public List GetFilteredList(PostBindingModel model) + { + if (model == null) + { + return null; + } + using var context = new EmployeesDatabase(); + return context.Posts + .Where(rec => rec.Name.Contains(model.Name)) + .Select(CreateModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new EmployeesDatabase(); + return context.Posts + .Select(CreateModel) + .ToList(); + } + + public void Insert(PostBindingModel model) + { + var context = new EmployeesDatabase(); + var transaction = context.Database.BeginTransaction(); + try + { + context.Posts.Add(CreateModel(model, new Post())); + context.SaveChanges(); + transaction.Commit(); + } + catch + { + transaction.Rollback(); + throw; + } + } + + public void Update(PostBindingModel model) + { + var context = new EmployeesDatabase(); + var transaction = context.Database.BeginTransaction(); + try + { + var post = context.Posts.FirstOrDefault(rec => rec.Id == model.Id); + if (post == null) + { + throw new Exception("Должность не найдена"); + } + CreateModel(model, post); + context.SaveChanges(); + transaction.Commit(); + } + catch + { + transaction.Rollback(); + throw; + } + } + + private static Post CreateModel(PostBindingModel model, Post post) + { + post.Name = model.Name; + return post; + } + + private static PostViewModel CreateModel(Post post) + { + return new PostViewModel + { + Id = post.Id, + Name = post.Name + }; + } + } +} diff --git a/EmployeesDatabaseImplement/Migrations/20241028190655_Initial.Designer.cs b/EmployeesDatabaseImplement/Migrations/20241028190655_Initial.Designer.cs new file mode 100644 index 0000000..16243d8 --- /dev/null +++ b/EmployeesDatabaseImplement/Migrations/20241028190655_Initial.Designer.cs @@ -0,0 +1,75 @@ +// +using System; +using EmployeesDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EmployeesDatabaseImplement.Migrations +{ + [DbContext(typeof(EmployeesDatabase))] + [Migration("20241028190655_Initial")] + partial class Initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.11") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("EmployeesDatabaseImplement.Models.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Autobiography") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Post") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Upgrade") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("EmployeesDatabaseImplement.Models.Post", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Posts"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/EmployeesDatabaseImplement/Migrations/20241028190655_Initial.cs b/EmployeesDatabaseImplement/Migrations/20241028190655_Initial.cs new file mode 100644 index 0000000..58ed38e --- /dev/null +++ b/EmployeesDatabaseImplement/Migrations/20241028190655_Initial.cs @@ -0,0 +1,54 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EmployeesDatabaseImplement.Migrations +{ + /// + public partial class Initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Employees", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Autobiography = table.Column(type: "nvarchar(max)", nullable: false), + Post = table.Column(type: "nvarchar(max)", nullable: false), + Upgrade = table.Column(type: "datetime2", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Employees", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Posts", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Posts", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Employees"); + + migrationBuilder.DropTable( + name: "Posts"); + } + } +} diff --git a/EmployeesDatabaseImplement/Migrations/EmployeesDatabaseModelSnapshot.cs b/EmployeesDatabaseImplement/Migrations/EmployeesDatabaseModelSnapshot.cs new file mode 100644 index 0000000..304dd5c --- /dev/null +++ b/EmployeesDatabaseImplement/Migrations/EmployeesDatabaseModelSnapshot.cs @@ -0,0 +1,72 @@ +// +using System; +using EmployeesDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EmployeesDatabaseImplement.Migrations +{ + [DbContext(typeof(EmployeesDatabase))] + partial class EmployeesDatabaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.11") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("EmployeesDatabaseImplement.Models.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Autobiography") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Post") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Upgrade") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("EmployeesDatabaseImplement.Models.Post", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Posts"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/EmployeesDatabaseImplement/Models/Employee.cs b/EmployeesDatabaseImplement/Models/Employee.cs new file mode 100644 index 0000000..7326547 --- /dev/null +++ b/EmployeesDatabaseImplement/Models/Employee.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EmployeesDatabaseImplement.Models +{ + public class Employee + { + public int Id { get; set; } + + [Required] + public string Name { get; set; } + + [Required] + public string Autobiography { get; set; } + [Required] + public string Post { get; set; } + + public DateTime? Upgrade { get; set; } + + } +} diff --git a/EmployeesDatabaseImplement/Models/Post.cs b/EmployeesDatabaseImplement/Models/Post.cs new file mode 100644 index 0000000..17eebfb --- /dev/null +++ b/EmployeesDatabaseImplement/Models/Post.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EmployeesDatabaseImplement.Models +{ + public class Post + { + public int Id { get; set; } + + [Required] + public string Name { get; set; } + } +} diff --git a/EmployeesView/EmployeesView.csproj b/EmployeesView/EmployeesView.csproj new file mode 100644 index 0000000..992b51b --- /dev/null +++ b/EmployeesView/EmployeesView.csproj @@ -0,0 +1,29 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + \ No newline at end of file diff --git a/EmployeesView/FormEmployee.Designer.cs b/EmployeesView/FormEmployee.Designer.cs new file mode 100644 index 0000000..3880671 --- /dev/null +++ b/EmployeesView/FormEmployee.Designer.cs @@ -0,0 +1,197 @@ +namespace EmployeesView +{ + partial class FormEmployee + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.LabelFIO = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.dropDownList = new Components.DropDownList(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.textBoxAutobiography = new System.Windows.Forms.TextBox(); + this.dateTimePicker = new System.Windows.Forms.DateTimePicker(); + this.label3 = new System.Windows.Forms.Label(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.checkBox = new System.Windows.Forms.CheckBox(); + this.SuspendLayout(); + // + // LabelFIO + // + this.LabelFIO.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.LabelFIO.AutoSize = true; + this.LabelFIO.Location = new System.Drawing.Point(13, 10); + this.LabelFIO.Name = "LabelFIO"; + this.LabelFIO.Size = new System.Drawing.Size(34, 15); + this.LabelFIO.TabIndex = 0; + this.LabelFIO.Text = "ФИО"; + // + // textBoxName + // + this.textBoxName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBoxName.Location = new System.Drawing.Point(13, 31); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(374, 23); + this.textBoxName.TabIndex = 1; + // + // dropDownList + // + this.dropDownList.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dropDownList.Location = new System.Drawing.Point(12, 81); + this.dropDownList.Name = "dropDownList"; + this.dropDownList.SelectedItem = ""; + this.dropDownList.Size = new System.Drawing.Size(374, 29); + this.dropDownList.TabIndex = 2; + this.dropDownList.Load += new System.EventHandler(this.FormEmployee_Load); + // + // label1 + // + this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 61); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(69, 15); + this.label1.TabIndex = 3; + this.label1.Text = "Должность"; + // + // label2 + // + this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(13, 111); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(94, 15); + this.label2.TabIndex = 4; + this.label2.Text = "Автобиография"; + // + // textBoxAutobiography + // + this.textBoxAutobiography.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBoxAutobiography.Location = new System.Drawing.Point(13, 131); + this.textBoxAutobiography.Name = "textBoxAutobiography"; + this.textBoxAutobiography.Size = new System.Drawing.Size(374, 23); + this.textBoxAutobiography.TabIndex = 5; + // + // dateTimePicker + // + this.dateTimePicker.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dateTimePicker.Location = new System.Drawing.Point(13, 179); + this.dateTimePicker.Name = "dateTimePicker"; + this.dateTimePicker.Size = new System.Drawing.Size(374, 23); + this.dateTimePicker.TabIndex = 6; + // + // label3 + // + this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(13, 159); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(185, 15); + this.label3.TabIndex = 7; + this.label3.Text = "Дата повышения квалификаций"; + // + // buttonSave + // + this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.buttonSave.Location = new System.Drawing.Point(12, 233); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(373, 23); + this.buttonSave.TabIndex = 8; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCancel.Location = new System.Drawing.Point(12, 262); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(373, 23); + this.buttonCancel.TabIndex = 9; + this.buttonCancel.Text = "Отменить"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // checkBox + // + this.checkBox.AutoSize = true; + this.checkBox.Location = new System.Drawing.Point(13, 208); + this.checkBox.Name = "checkBox"; + this.checkBox.Size = new System.Drawing.Size(179, 19); + this.checkBox.TabIndex = 10; + this.checkBox.Text = "Квалификация не пройдена"; + this.checkBox.UseVisualStyleBackColor = true; + // + // FormEmployee + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(399, 299); + this.Controls.Add(this.checkBox); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.label3); + this.Controls.Add(this.dateTimePicker); + this.Controls.Add(this.textBoxAutobiography); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.dropDownList); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.LabelFIO); + this.Name = "FormEmployee"; + this.Text = "FormEmployee"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label LabelFIO; + private TextBox textBoxName; + private Components.DropDownList dropDownList; + private Label label1; + private Label label2; + private TextBox textBoxAutobiography; + private DateTimePicker dateTimePicker; + private Label label3; + private Button buttonSave; + private Button buttonCancel; + private CheckBox checkBox; + } +} \ No newline at end of file diff --git a/EmployeesView/FormEmployee.cs b/EmployeesView/FormEmployee.cs new file mode 100644 index 0000000..c43a783 --- /dev/null +++ b/EmployeesView/FormEmployee.cs @@ -0,0 +1,119 @@ +using EmployeesContracts.BindingModels; +using EmployeesContracts.BusinessLogicsContracts; +using EmployeesContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace EmployeesView +{ + public partial class FormEmployee : Form + { + public int Id { set { id = value; } } + + private readonly IEmployeeLogic _logic; + private readonly IPostLogic _logicS; + + private int? id; + + public FormEmployee(IEmployeeLogic logic, IPostLogic logicS) + { + InitializeComponent(); + _logic = logic; + _logicS = logicS; + } + + private void FormEmployee_Load(object sender, EventArgs e) + { + List viewS = _logicS.Read(null); + if (viewS != null) + { + foreach (PostViewModel s in viewS) + { + dropDownList.ComboBoxItems.Add(s.Name); + } + } + if (id.HasValue) + { + try + { + EmployeeViewModel view = _logic.Read(new EmployeeBindingModel { Id = id.Value })?[0]; + if (view != null) + { + textBoxAutobiography.Text = view.Autobiography; + textBoxName.Text = view.Name; + dropDownList.SelectedItem = view.Post; + if (view.Upgrade != null) + { + dateTimePicker.Value = (DateTime)view.Upgrade; + } + else + { + dateTimePicker.Value = DateTime.Now; + checkBox.Checked = true; + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните имя", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(dropDownList.SelectedItem)) + { + MessageBox.Show("Выберите должность", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (textBoxAutobiography.Text == null) + { + MessageBox.Show("Заполните автобиографию", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DateTime? upgrade = dateTimePicker.Value; + if (checkBox.Checked == true) + { + upgrade = null; + } + + try + { + _logic.CreateOrUpdate(new EmployeeBindingModel + { + Id = id, + Autobiography = textBoxAutobiography.Text, + Name = textBoxName.Text, + Post = dropDownList.SelectedItem, + Upgrade = upgrade + }); + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} \ No newline at end of file diff --git a/EmployeesView/FormEmployee.resx b/EmployeesView/FormEmployee.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/EmployeesView/FormEmployee.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/EmployeesView/FormMain.Designer.cs b/EmployeesView/FormMain.Designer.cs new file mode 100644 index 0000000..6565c07 --- /dev/null +++ b/EmployeesView/FormMain.Designer.cs @@ -0,0 +1,193 @@ +using ComponentsLibraryNet60.DocumentWithChart; + +namespace EmployeesView +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.действияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.добавитьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.изменитьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.удалитьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.документыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.документВPDFToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.отчетВEXCELToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.диаграммаВWordToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.должностьToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.controlDataTreeCell = new ControlsLibraryNet60.Data.ControlDataTreeCell(); + this.componentTextToPDF = new Components.TextToPDF(); + this.excelWithCustomTable = new WinFormsLibrary1.ExcelWithCustomTable(this.components); + this.componentDocumentWithChartPieWord = new ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartPieWord(components); + this.menuStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // menuStrip1 + // + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.действияToolStripMenuItem, + this.документыToolStripMenuItem, + this.справочникиToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(800, 24); + this.menuStrip1.TabIndex = 0; + this.menuStrip1.Text = "menuStrip1"; + // + // действияToolStripMenuItem + // + this.действияToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.добавитьToolStripMenuItem, + this.изменитьToolStripMenuItem, + this.удалитьToolStripMenuItem}); + this.действияToolStripMenuItem.Name = "действияToolStripMenuItem"; + this.действияToolStripMenuItem.Size = new System.Drawing.Size(70, 20); + this.действияToolStripMenuItem.Text = "Действия"; + // + // добавитьToolStripMenuItem + // + this.добавитьToolStripMenuItem.Name = "добавитьToolStripMenuItem"; + this.добавитьToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.A))); + this.добавитьToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.добавитьToolStripMenuItem.Text = "Добавить"; + this.добавитьToolStripMenuItem.Click += new System.EventHandler(this.добавитьToolStripMenuItem_Click); + // + // изменитьToolStripMenuItem + // + this.изменитьToolStripMenuItem.Name = "изменитьToolStripMenuItem"; + this.изменитьToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.U))); + this.изменитьToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.изменитьToolStripMenuItem.Text = "Изменить"; + this.изменитьToolStripMenuItem.Click += new System.EventHandler(this.изменитьToolStripMenuItem_Click); + // + // удалитьToolStripMenuItem + // + this.удалитьToolStripMenuItem.Name = "удалитьToolStripMenuItem"; + this.удалитьToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.D))); + this.удалитьToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.удалитьToolStripMenuItem.Text = "Удалить"; + this.удалитьToolStripMenuItem.Click += new System.EventHandler(this.удалитьToolStripMenuItem_Click); + // + // документыToolStripMenuItem + // + this.документыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.документВPDFToolStripMenuItem, + this.отчетВEXCELToolStripMenuItem, + this.диаграммаВWordToolStripMenuItem}); + this.документыToolStripMenuItem.Name = "документыToolStripMenuItem"; + this.документыToolStripMenuItem.Size = new System.Drawing.Size(82, 20); + this.документыToolStripMenuItem.Text = "Документы"; + // + // документВPDFToolStripMenuItem + // + this.документВPDFToolStripMenuItem.Name = "документВPDFToolStripMenuItem"; + this.документВPDFToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.S))); + this.документВPDFToolStripMenuItem.Size = new System.Drawing.Size(220, 22); + this.документВPDFToolStripMenuItem.Text = "Документ в PDF"; + this.документВPDFToolStripMenuItem.Click += new System.EventHandler(this.документВPDFToolStripMenuItem_Click); + // + // отчетВEXCELToolStripMenuItem + // + this.отчетВEXCELToolStripMenuItem.Name = "отчетВEXCELToolStripMenuItem"; + this.отчетВEXCELToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.T))); + this.отчетВEXCELToolStripMenuItem.Size = new System.Drawing.Size(220, 22); + this.отчетВEXCELToolStripMenuItem.Text = "Отчет в Excel"; + this.отчетВEXCELToolStripMenuItem.Click += new System.EventHandler(this.отчетВEXCELToolStripMenuItem_Click); + // + // диаграммаВWordToolStripMenuItem + // + this.диаграммаВWordToolStripMenuItem.Name = "диаграммаВWordToolStripMenuItem"; + this.диаграммаВWordToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.C))); + this.диаграммаВWordToolStripMenuItem.Size = new System.Drawing.Size(220, 22); + this.диаграммаВWordToolStripMenuItem.Text = "Диаграмма в Word"; + this.диаграммаВWordToolStripMenuItem.Click += new System.EventHandler(this.диаграммаВWordToolStripMenuItem_Click); + // + // справочникиToolStripMenuItem + // + this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.должностьToolStripMenuItem}); + this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // должностьToolStripMenuItem + // + this.должностьToolStripMenuItem.Name = "должностьToolStripMenuItem"; + this.должностьToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.должностьToolStripMenuItem.Text = "Должность"; + this.должностьToolStripMenuItem.Click += new System.EventHandler(this.должностьToolStripMenuItem_Click); + // + // controlDataTreeCell + // + this.controlDataTreeCell.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.controlDataTreeCell.Location = new System.Drawing.Point(12, 27); + this.controlDataTreeCell.Name = "controlDataTreeCell"; + this.controlDataTreeCell.Size = new System.Drawing.Size(776, 411); + this.controlDataTreeCell.TabIndex = 1; + this.controlDataTreeCell.Load += new System.EventHandler(this.FormMain_Load); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.controlDataTreeCell); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.Name = "FormMain"; + this.Text = "FormMain"; + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem действияToolStripMenuItem; + private ToolStripMenuItem добавитьToolStripMenuItem; + private ToolStripMenuItem изменитьToolStripMenuItem; + private ToolStripMenuItem удалитьToolStripMenuItem; + private ToolStripMenuItem документыToolStripMenuItem; + private ToolStripMenuItem документВPDFToolStripMenuItem; + private ToolStripMenuItem отчетВEXCELToolStripMenuItem; + private ToolStripMenuItem диаграммаВWordToolStripMenuItem; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem должностьToolStripMenuItem; + private ControlsLibraryNet60.Data.ControlDataTreeCell controlDataTreeCell; + private Components.TextToPDF componentTextToPDF; + private WinFormsLibrary1.ExcelWithCustomTable excelWithCustomTable; + private ComponentsLibraryNet60.DocumentWithChart.ComponentDocumentWithChartPieWord componentDocumentWithChartPieWord; + } +} \ No newline at end of file diff --git a/EmployeesView/FormMain.cs b/EmployeesView/FormMain.cs new file mode 100644 index 0000000..d12b4a8 --- /dev/null +++ b/EmployeesView/FormMain.cs @@ -0,0 +1,260 @@ +using WinFormsLibrary1.Models; +using ComponentsLibraryNet60.Models; +using ControlsLibraryNet60.Models; +using EmployeesContracts.BindingModels; +using EmployeesContracts.BusinessLogicsContracts; +using EmployeesContracts.ViewModels; +using EmployeesDatabaseImplement.Models; +using Components; +using COP_7.Components.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; +using ComponentsLibraryNet60.DocumentWithChart; + +namespace EmployeesView +{ + public partial class FormMain : Form + { + private readonly IEmployeeLogic _employeeLogic; + private readonly IPostLogic _postLogic; + + public FormMain(IEmployeeLogic employeeLogic, IPostLogic postLogic) + { + _employeeLogic = employeeLogic; + _postLogic = postLogic; + InitializeComponent(); + + var nodeNames = new Queue(); + nodeNames.Enqueue("Post"); + nodeNames.Enqueue("Id"); + nodeNames.Enqueue("Upgrade"); + nodeNames.Enqueue("Name"); + var treeConfig = new DataTreeNodeConfig { NodeNames = nodeNames }; + + + controlDataTreeCell.LoadConfig(treeConfig); + + } + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + controlDataTreeCell.Clear(); + var list = _employeeLogic.Read(null); + if (list != null) + { + foreach (var book in list) + { + controlDataTreeCell.AddCell(3, book); + } + controlDataTreeCell.Update(); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AddNewElement() + { + var form = Program.Container.Resolve(); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + + private void UpdateElement() + { + var form = Program.Container.Resolve(); + var selectedEmployee = controlDataTreeCell.GetSelectedObject(); + if (selectedEmployee != null) + { + form.Id = Convert.ToInt32(selectedEmployee.Id); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + else + { + // Обработка ситуации, когда объект Employee не выбран + MessageBox.Show("Выберите сотрудника для редактирования"); + } + } + + private void DeleteElement() + { + if (MessageBox.Show("Удалить запись", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(controlDataTreeCell.GetSelectedObject().Id); + try + { + _employeeLogic.Delete(new EmployeeBindingModel { Id = id }); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + + private void CreateWord() + { + string fileName = ""; + using (var dialog = new SaveFileDialog { Filter = "docx|*.docx" }) + { + if (dialog.ShowDialog() == DialogResult.OK) + { + fileName = dialog.FileName.ToString(); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + var positions = _postLogic.Read(null).Select(p => p.Name).ToList(); + var employees = _employeeLogic.Read(null); + var employeeCounts = positions.Select(p => + { + int count = employees.Count(e => e.Post != p && e.Upgrade == null); + return (Date: p, Value: count); + }).ToList(); + + // Преобразуем список в нужный формат + var list2D = new Dictionary>() + { + { "Не прошедшие повышение", employeeCounts.Select(x => (Date: int.Parse(x.Date), Value: (double)x.Value)).ToList() } + }; + + componentDocumentWithChartPieWord.CreateDoc(new ComponentDocumentWithChartConfig + { + FilePath = fileName, + Header = "Диаграмма", + ChartTitle = "Круговая диаграмма", + LegendLocation = ComponentsLibraryNet60.Models.Location.Bottom, + Data = list2D + }); + } + + + private void CreateExcel() + { + string fileName = ""; + using (var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" }) + { + if (dialog.ShowDialog() == DialogResult.OK) + { + fileName = dialog.FileName.ToString(); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + } + + var employees = _employeeLogic.Read(null); + string FilePatht = fileName; + string Headert = "Заголовое"; + List<(int Column, int Row)>? ColumnsRowsWidtht = new() { (5, 5), (10, 5), (10, 0), (5, 0), (7, 0) }; + List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)>? Headerst = new() + { + (0, 0, "Id", "Id"), + (1, 0, "Имя", "Name"), + (2, 0, "Описание", "Post"), + (3, 0, "Категория", "Upgrade"), + (4, 0, "Автобиография", "Autobiography") + }; + List? Datat = employees; + excelWithCustomTable.CreateDoc(new TableWithHeaderConfig + { + FilePath = FilePatht, + Header = Headert, + ColumnsRowsWidth = ColumnsRowsWidtht, + Headers = Headerst, + Data = Datat, + NullReplace = "не проходил" + }); + + } + + private void CreatePdf() + { + string fileName = ""; + using (var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }) + { + if (dialog.ShowDialog() == DialogResult.OK) + { + fileName = dialog.FileName.ToString(); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + List tables = new List(); + var list = _employeeLogic.Read(null); + if (list != null) + { + foreach (var employee in list) + { + if (employee.Upgrade != null) + { + string row = $"ФИО: {employee.Name} Автобиография: {employee.Autobiography}"; + tables.Add(row); + } + } + } + + // Используем метод CreateDocument из TextToPDF + var textToPDF = new TextToPDF(); + textToPDF.CreateDocument(fileName, "Формировать документ в Pdf по сотрудникам, проходившим квалификацию (в каждой строке текст с информацией: ФИО и автобиография)", tables.ToArray()); + } + + private void добавитьToolStripMenuItem_Click(object sender, EventArgs e) + { + AddNewElement(); + } + + private void должностьToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = Program.Container.Resolve(); + form.ShowDialog(); + } + + private void изменитьToolStripMenuItem_Click(object sender, EventArgs e) + { + UpdateElement(); + } + + private void удалитьToolStripMenuItem_Click(object sender, EventArgs e) + { + DeleteElement(); + } + + private void документВPDFToolStripMenuItem_Click(object sender, EventArgs e) + { + CreatePdf(); + } + + private void отчетВEXCELToolStripMenuItem_Click(object sender, EventArgs e) + { + CreateExcel(); + } + + private void диаграммаВWordToolStripMenuItem_Click(object sender, EventArgs e) + { + CreateWord(); + } + } +} diff --git a/EmployeesView/FormMain.resx b/EmployeesView/FormMain.resx new file mode 100644 index 0000000..a979615 --- /dev/null +++ b/EmployeesView/FormMain.resx @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 132, 17 + + + 301, 17 + + + 477, 17 + + \ No newline at end of file diff --git a/EmployeesView/FormPost.Designer.cs b/EmployeesView/FormPost.Designer.cs new file mode 100644 index 0000000..b115e99 --- /dev/null +++ b/EmployeesView/FormPost.Designer.cs @@ -0,0 +1,67 @@ +namespace EmployeesView +{ + partial class FormPost + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 12); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(236, 217); + this.dataGridView.TabIndex = 0; + this.dataGridView.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellEndEdit); + this.dataGridView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.dataGridView_KeyDown); + // + // FormPost + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(260, 241); + this.Controls.Add(this.dataGridView); + this.Name = "FormPost"; + this.Text = "FormPost"; + this.Load += new System.EventHandler(this.FormPost_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/EmployeesView/FormPost.cs b/EmployeesView/FormPost.cs new file mode 100644 index 0000000..7451d55 --- /dev/null +++ b/EmployeesView/FormPost.cs @@ -0,0 +1,117 @@ +using EmployeesContracts.BindingModels; +using EmployeesContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace EmployeesView +{ + public partial class FormPost : Form + { + private readonly IPostLogic postLogic; + BindingList list; + public FormPost(IPostLogic _postLogic) + { + InitializeComponent(); + postLogic = _postLogic; + list = new BindingList(); + dataGridView.AllowUserToAddRows = false; + } + + private void LoadData() + { + try + { + var list1 = postLogic.Read(null); + list.Clear(); + foreach (var item in list1) + { + list.Add(new PostBindingModel + { + Id = item.Id, + Name = item.Name, + }); + } + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns[0].Visible = false; + dataGridView.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void FormPost_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) + { + var typeName = (string)dataGridView.CurrentRow.Cells[1].Value; + if (!string.IsNullOrEmpty(typeName)) + { + if (dataGridView.CurrentRow.Cells[0].Value != null) + { + postLogic.CreateOrUpdate(new PostBindingModel() + { + Id = Convert.ToInt32(dataGridView.CurrentRow.Cells[0].Value), + Name = (string)dataGridView.CurrentRow.Cells[1].EditedFormattedValue + }); + } + else + { + postLogic.CreateOrUpdate(new PostBindingModel() + { + Name = (string)dataGridView.CurrentRow.Cells[1].EditedFormattedValue + }); + } + } + else + { + MessageBox.Show("Введена пустая строка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + + private void dataGridView_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyData == Keys.Insert) + { + if (dataGridView.Rows.Count == 0) + { + list.Add(new PostBindingModel()); + dataGridView.DataSource = new BindingList(list); + dataGridView.CurrentCell = dataGridView.Rows[0].Cells[1]; + return; + } + if (dataGridView.Rows[dataGridView.Rows.Count - 1].Cells[1].Value != null) + { + list.Add(new PostBindingModel()); + dataGridView.DataSource = new BindingList(list); + dataGridView.CurrentCell = dataGridView.Rows[dataGridView.Rows.Count - 1].Cells[1]; + return; + } + } + if (e.KeyData == Keys.Delete) + { + if (MessageBox.Show("Удалить выбранный элемент", "Удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + postLogic.Delete(new PostBindingModel() { Id = (int)dataGridView.CurrentRow.Cells[0].Value }); + LoadData(); + } + } + } + } +} diff --git a/EmployeesView/FormPost.resx b/EmployeesView/FormPost.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/EmployeesView/FormPost.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/EmployeesView/Program.cs b/EmployeesView/Program.cs new file mode 100644 index 0000000..3160fa4 --- /dev/null +++ b/EmployeesView/Program.cs @@ -0,0 +1,39 @@ +using EmployeesContracts.BusinessLogicsContracts; +using EmployeesContracts.StorageContracts; +using EmployeesDatabaseImplement.Implements; +using Unity; +using Unity.Lifetime; + +namespace EmployeesView +{ + internal static class Program + { + private static IUnityContainer container = null; + public static IUnityContainer Container { get { if (container == null) { container = BuildUnityContainer(); } return container; } } + + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.SetHighDpiMode(HighDpiMode.SystemAware); + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(Container.Resolve()); + } + + private static IUnityContainer BuildUnityContainer() + { + var currentContainer = new UnityContainer(); + + currentContainer.RegisterType(new HierarchicalLifetimeManager()); + currentContainer.RegisterType(new HierarchicalLifetimeManager()); + + currentContainer.RegisterType(new HierarchicalLifetimeManager()); + currentContainer.RegisterType(new HierarchicalLifetimeManager()); + + return currentContainer; + } + } +} \ No newline at end of file