From 1303ba8d803686c1fd8d5c52d4b73c0504ab91ab Mon Sep 17 00:00:00 2001 From: maksim Date: Tue, 26 Nov 2024 20:02:29 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=BE=D0=B5=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BC=D0=B5=D0=B6=D0=B4=D1=83=20=D1=8D=D0=BA=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D0=B0=D0=BC=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.xaml | 53 +++++++-- Migrations/20241126112638_InitDB.Designer.cs | 2 +- Migrations/ApplicationConextModelSnapshot.cs | 2 +- {Data => Model/Data}/ApplicationConext.cs | 2 +- Model/DataWorker.cs | 109 +++++++++++++++++- Model/RelayCommand.cs | 35 ++++++ View/MainWindow.xaml | 2 +- View/MainWindow.xaml.cs | 4 +- .../AddPhysicalPersonWindow.xaml | 78 +++++++++++++ ...aml.cs => AddPhysicalPersonWindow.xaml.cs} | 6 +- .../PhysicalPersoManagementWindow.xaml | 44 +++++++ .../PhysicalPersoManagementWindow.xaml.cs | 29 +++++ View/PhysicalPerson/WorkInPhysicalPerson.xaml | 12 -- View/TextBoxPlaceholderConverter.cs | 26 +++++ ViewModel/DataManageViewModel.cs | 81 ++++++++++++- 15 files changed, 451 insertions(+), 34 deletions(-) rename {Data => Model/Data}/ApplicationConext.cs (95%) create mode 100644 Model/RelayCommand.cs create mode 100644 View/PhysicalPerson/AddPhysicalPersonWindow.xaml rename View/PhysicalPerson/{WorkInPhysicalPerson.xaml.cs => AddPhysicalPersonWindow.xaml.cs} (73%) create mode 100644 View/PhysicalPerson/PhysicalPersoManagementWindow.xaml create mode 100644 View/PhysicalPerson/PhysicalPersoManagementWindow.xaml.cs delete mode 100644 View/PhysicalPerson/WorkInPhysicalPerson.xaml create mode 100644 View/TextBoxPlaceholderConverter.cs diff --git a/App.xaml b/App.xaml index 96272f2..517e8e2 100644 --- a/App.xaml +++ b/App.xaml @@ -12,10 +12,10 @@ + CornerRadius="15" + BorderBrush="Transparent" + BorderThickness="0" + x:Name="ButtonBorder"> @@ -29,8 +29,8 @@ + Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" + To="#0066CC" Duration="0:0:0.2" /> @@ -38,8 +38,8 @@ + Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)" + To="#004890" Duration="0:0:0.2" /> @@ -63,5 +63,42 @@ + + + + + + + diff --git a/Migrations/20241126112638_InitDB.Designer.cs b/Migrations/20241126112638_InitDB.Designer.cs index e07b64e..cd0b0f9 100644 --- a/Migrations/20241126112638_InitDB.Designer.cs +++ b/Migrations/20241126112638_InitDB.Designer.cs @@ -1,6 +1,6 @@ // using System; -using EmployeeManager.Data; +using EmployeeManager.Model.Data; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; diff --git a/Migrations/ApplicationConextModelSnapshot.cs b/Migrations/ApplicationConextModelSnapshot.cs index c0a298e..cc46114 100644 --- a/Migrations/ApplicationConextModelSnapshot.cs +++ b/Migrations/ApplicationConextModelSnapshot.cs @@ -1,6 +1,6 @@ // using System; -using EmployeeManager.Data; +using EmployeeManager.Model.Data; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; diff --git a/Data/ApplicationConext.cs b/Model/Data/ApplicationConext.cs similarity index 95% rename from Data/ApplicationConext.cs rename to Model/Data/ApplicationConext.cs index 45fb27c..5d76a2e 100644 --- a/Data/ApplicationConext.cs +++ b/Model/Data/ApplicationConext.cs @@ -1,7 +1,7 @@ using EmployeeManager.Model; using Microsoft.EntityFrameworkCore; -namespace EmployeeManager.Data +namespace EmployeeManager.Model.Data { public class ApplicationConext : DbContext { diff --git a/Model/DataWorker.cs b/Model/DataWorker.cs index a8c900e..1dc973d 100644 --- a/Model/DataWorker.cs +++ b/Model/DataWorker.cs @@ -1,12 +1,113 @@ -using System; -using System.Collections.Generic; +using EmployeeManager.Model.Data; +using System.Data.Common; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace EmployeeManager.Model { public static class DataWorker { + public static string CreatePhysicalPerson(string namePhysicalPersons, string surnamePhysicalPersons, string patronomicPhysicalPersons, DateTime birthday, string gender, string address, string telephone) + { + string result = "Возникла ошибка. Обратитесь в ЛАОД."; + + using(ApplicationConext db = new ApplicationConext()) + { + bool checkIsExist = db.PhysicalPersons.Any( + e => e.NamePhysicalPersons == namePhysicalPersons + && e.SurnamePhysicalPersons == surnamePhysicalPersons + && e.PatronomicPhysicalPersons == patronomicPhysicalPersons + && e.Birthday == birthday + ); + + if (!checkIsExist) + { + PhysicalPerson newPhysicalPerson = new PhysicalPerson + { + NamePhysicalPersons = namePhysicalPersons, + SurnamePhysicalPersons = surnamePhysicalPersons, + PatronomicPhysicalPersons = patronomicPhysicalPersons, + Birthday = birthday, + Gender = gender, + Address = address, + Telephone = telephone + }; + db.PhysicalPersons.Add(newPhysicalPerson); + db.SaveChanges(); + result = "Физическое лицо добавлено."; + } + return result; + } + } + + public static string CreateEmployee(string nameJob, DateTime startJob, DateTime? endJob, string? partTimeJob, float bid, PhysicalPerson? physicalPersons) + { + string result = "Возникла ошибка. Обратитесь в ЛАОД."; + + using (ApplicationConext db = new ApplicationConext()) + { + + Employee newEmployee = new Employee + { + NameJob = nameJob, + StartJob = startJob, + EndJob = endJob, + PartTimeJob = partTimeJob, + Bid = bid, + PhysicalPersonsId = physicalPersons.Id + + }; + db.Employees.Add(newEmployee); + db.SaveChanges(); + result = "Работник добавлен."; + + return result; + + } + } + + public static string DeletePhysicalPerson(PhysicalPerson physicalPerson) + { + string result = "Возникла ошибка. Обратитесь в ЛАОД."; + + using(ApplicationConext db = new ApplicationConext()) + { + db.PhysicalPersons.Remove(physicalPerson); + db.SaveChanges(); + result = "Физическое лицо удалено."; + } + + return result; + + } + + public static string EditPhysicalPerson(PhysicalPerson oldPhysicalPerson, string newNamePhysicalPersons, string newSurnamePhysicalPersons, string newPatronomicPhysicalPersons, DateTime newBirthday, string newGender, string newAddress, string newTelephone) + { + string result = "Возникла ошибка. Обратитесь в ЛАОД."; + + using (ApplicationConext db = new ApplicationConext()) + { + PhysicalPerson physicalPerson = db.PhysicalPersons.FirstOrDefault(e => e.Id == oldPhysicalPerson.Id); + + physicalPerson.SurnamePhysicalPersons = newSurnamePhysicalPersons; + physicalPerson.NamePhysicalPersons = newNamePhysicalPersons; + physicalPerson.PatronomicPhysicalPersons = newPatronomicPhysicalPersons; + physicalPerson.Birthday = newBirthday; + physicalPerson.Gender = newGender; + physicalPerson.Address = newAddress; + physicalPerson.Telephone = newTelephone; + } + + return result; + + } + + public static List GetAllPhysicalPerson() + { + using (ApplicationConext db = new ApplicationConext()) + { + var result = db.PhysicalPersons.ToList(); + return result; + } + } } } diff --git a/Model/RelayCommand.cs b/Model/RelayCommand.cs new file mode 100644 index 0000000..b59a60a --- /dev/null +++ b/Model/RelayCommand.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Input; + +namespace EmployeeManager.Model +{ + public class RelayCommand : ICommand + { + private Action _execute; + private Func _canExecute; + public event EventHandler CanExecuteChanged + { + add { CommandManager.RequerySuggested += value; } + remove { CommandManager.RequerySuggested -= value; } + } + public RelayCommand(Action execute, Func canExecute = null) + { + _execute = execute; + _canExecute = canExecute; + } + + public bool CanExecute(object parameter) + { + return _canExecute == null || _canExecute(parameter); + } + + public void Execute(object parameter) + { + _execute(parameter); + } + } +} diff --git a/View/MainWindow.xaml b/View/MainWindow.xaml index 5c2f229..433b6b8 100644 --- a/View/MainWindow.xaml +++ b/View/MainWindow.xaml @@ -16,7 +16,7 @@