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 @@