From 7847a4e41a1dc176f1f2cf3e3152c02c00efe380 Mon Sep 17 00:00:00 2001 From: Sosees04ka <112947786+Sosees04ka@users.noreply.github.com> Date: Wed, 13 Nov 2024 14:41:01 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=84=D0=B0=D0=B9=D0=BB=D1=8B.=20=20=D0=A1=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=BB=20=D0=BC=D0=B8=D0=B3=D1=80=D0=B0=D1=86=D0=B8=D1=8E?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/EmployeeLogic.cs | 146 ++++++++++++- .../BusinessLogic/PhisicalPersonLogic.cs | 96 ++++++++- .../EmployeeManagmentBusinessLogic.csproj | 1 + .../BindingModels/EmployeeBindingModel.cs | 2 +- .../ViewModels/EmployeeViewModel.cs | 5 +- .../EmployeeManagementDbContext .cs | 21 +- .../EmployeeManagmentDataBaseImplement.csproj | 1 + ...0241113084724_InitialMigration.Designer.cs | 197 ++++++++++++++++++ .../20241113084724_InitialMigration.cs | 143 +++++++++++++ ...mployeeManagementDbContextModelSnapshot.cs | 194 +++++++++++++++++ .../Models/Employee.cs | 26 +-- .../Models/PhisicalPerson.cs | 15 +- .../Models/Salary.cs | 17 +- .../Models/Vacation.cs | 15 +- .../docker-compose.yml | 29 +-- .../Models/Employee.cs | 25 --- .../Models/IEmployee.cs | 20 ++ .../Models/IPhisicalPerson.cs | 20 ++ EmployeeManagmentDataModels/Models/ISalary.cs | 19 ++ .../Models/IVacation.cs | 18 ++ .../Models/PhysicalPerson.cs | 19 -- EmployeeManagmentDataModels/Models/Salary.cs | 22 -- .../Models/Vacation.cs | 21 -- EmployeeManagmentView/App.xaml.cs | 45 +++- .../EmployeeManagmentView.csproj | 14 ++ EmployeeManagmentView/EmployeesWindow.xaml.cs | 4 +- EmployeeManagmentView/MainWindow.xaml | 6 +- EmployeeManagmentView/MainWindow.xaml.cs | 32 +-- .../PhisicalPersonWindow.xaml | 30 +++ .../PhisicalPersonWindow.xaml.cs | 149 +++++++++++++ 30 files changed, 1190 insertions(+), 162 deletions(-) create mode 100644 EmployeeManagmentDataBaseImplement/Migrations/20241113084724_InitialMigration.Designer.cs create mode 100644 EmployeeManagmentDataBaseImplement/Migrations/20241113084724_InitialMigration.cs create mode 100644 EmployeeManagmentDataBaseImplement/Migrations/EmployeeManagementDbContextModelSnapshot.cs delete mode 100644 EmployeeManagmentDataModels/Models/Employee.cs create mode 100644 EmployeeManagmentDataModels/Models/IEmployee.cs create mode 100644 EmployeeManagmentDataModels/Models/IPhisicalPerson.cs create mode 100644 EmployeeManagmentDataModels/Models/ISalary.cs create mode 100644 EmployeeManagmentDataModels/Models/IVacation.cs delete mode 100644 EmployeeManagmentDataModels/Models/PhysicalPerson.cs delete mode 100644 EmployeeManagmentDataModels/Models/Salary.cs delete mode 100644 EmployeeManagmentDataModels/Models/Vacation.cs create mode 100644 EmployeeManagmentView/PhisicalPersonWindow.xaml create mode 100644 EmployeeManagmentView/PhisicalPersonWindow.xaml.cs diff --git a/EmployeeManagmentBusinessLogic/BusinessLogic/EmployeeLogic.cs b/EmployeeManagmentBusinessLogic/BusinessLogic/EmployeeLogic.cs index 375f04e..cab4dee 100644 --- a/EmployeeManagmentBusinessLogic/BusinessLogic/EmployeeLogic.cs +++ b/EmployeeManagmentBusinessLogic/BusinessLogic/EmployeeLogic.cs @@ -1,31 +1,165 @@ -using EmployeeManagmentContracts.BindingModels; +using System.Collections.Generic; +using System.Linq; +using EmployeeManagmentContracts.BindingModels; using EmployeeManagmentContracts.BusinessLogicContracts; using EmployeeManagmentContracts.SearchModels; -using EmployeeManagmentContracts.StoragesContracts; using EmployeeManagmentContracts.ViewModels; +using EmployeeManagmentDataBaseImplement; +using EmployeeManagmentDataBaseImplement.Models; namespace EmployeeManagmentBusinessLogic.BusinessLogic { public class EmployeeLogic : IEmployeeLogic { + private readonly EmployeeManagementDbContext _context; + + public EmployeeLogic(EmployeeManagementDbContext context) + { + _context = context; + } + public void CreateOrUpdate(EmployeeBindingModel model) { - throw new NotImplementedException(); + // Проверка на обязательные поля + if (string.IsNullOrWhiteSpace(model.NameJob)) + { + throw new ArgumentException("Job name cannot be empty."); + } + + // Ищем сотрудника по ID, если он уже существует + var employee = _context.Employees.FirstOrDefault(e => e.Id == model.Id); + + if (employee == null) + { + // Создаем нового сотрудника, если не найден + employee = new Employee + { + NameJob = model.NameJob, + StartJob = model.StartJob, + EndJob = model.EndJob, + PartTimeJob = model.PartTimeJob, + Bid = model.Bid, + PhisicalPersonsId = model.PhisicalPersonsId + }; + + try + { + _context.Employees.Add(employee); + _context.SaveChanges(); + } + catch (Exception ex) + { + // Логирование ошибки и обработка + throw new InvalidOperationException("Error while adding new employee: " + ex.Message); + } + } + else + { + // Обновляем данные существующего сотрудника + employee.NameJob = model.NameJob; + employee.StartJob = model.StartJob; + employee.EndJob = model.EndJob; + employee.PartTimeJob = model.PartTimeJob; + employee.Bid = model.Bid; + employee.PhisicalPersonsId = model.PhisicalPersonsId; + + try + { + _context.SaveChanges(); + } + catch (Exception ex) + { + // Логирование ошибки и обработка + throw new InvalidOperationException("Error while updating employee: " + ex.Message); + } + } } + public void Delete(int id) { - throw new NotImplementedException(); + var employee = _context.Employees.FirstOrDefault(e => e.Id == id); + if (employee != null) + { + // Дополнительная проверка на связи с другими таблицами, если необходимо + if (employee.Salaries.Any() || employee.Vacations.Any()) + { + throw new InvalidOperationException("Employee cannot be deleted because they have related data (e.g., salaries or vacations)."); + } + + _context.Employees.Remove(employee); + _context.SaveChanges(); + } + else + { + throw new KeyNotFoundException($"Employee with ID {id} not found."); + } } + public EmployeeViewModel? GetEmployeeById(int id) { - throw new NotImplementedException(); + var employee = _context.Employees + .Where(e => e.Id == id) + .Select(e => new EmployeeViewModel + { + Id = e.Id, + NameJob = e.NameJob, + StartJob = e.StartJob, + EndJob = e.EndJob, + PartTimeJob = e.PartTimeJob, + Bid = e.Bid, + PhysicalPersonsId = e.PhisicalPersonsId, + PhysicalPersonName = e.PhisicalPerson != null ? e.PhisicalPerson.Name : null + }) + .FirstOrDefault(); + + return employee; } public List GetEmployees(EmployeeSearchModel model) { - throw new NotImplementedException(); + var query = _context.Employees.AsQueryable(); + + if (model.Id.HasValue) + { + query = query.Where(e => e.Id == model.Id.Value); + } + + if (!string.IsNullOrWhiteSpace(model.NameJob)) + { + query = query.Where(e => e.NameJob.Contains(model.NameJob)); + } + + if (model.StartDateFrom.HasValue) + { + query = query.Where(e => e.StartJob >= model.StartDateFrom.Value); + } + + if (model.StartDateTo.HasValue) + { + query = query.Where(e => e.StartJob <= model.StartDateTo.Value); + } + + if (model.Bid.HasValue) + { + query = query.Where(e => e.Bid == model.Bid.Value); + } + + return query + .Select(e => new EmployeeViewModel + { + Id = e.Id, + NameJob = e.NameJob, + StartJob = e.StartJob, + EndJob = e.EndJob, + PartTimeJob = e.PartTimeJob, + Bid = e.Bid, + PhysicalPersonsId = e.PhisicalPersonsId, + PhysicalPersonName = e.PhisicalPerson != null ? e.PhisicalPerson.Name : null + }) + .ToList(); } + } } diff --git a/EmployeeManagmentBusinessLogic/BusinessLogic/PhisicalPersonLogic.cs b/EmployeeManagmentBusinessLogic/BusinessLogic/PhisicalPersonLogic.cs index 7f947bd..bd92558 100644 --- a/EmployeeManagmentBusinessLogic/BusinessLogic/PhisicalPersonLogic.cs +++ b/EmployeeManagmentBusinessLogic/BusinessLogic/PhisicalPersonLogic.cs @@ -2,6 +2,8 @@ using EmployeeManagmentContracts.BusinessLogicContracts; using EmployeeManagmentContracts.SearchModels; using EmployeeManagmentContracts.ViewModels; +using EmployeeManagmentDataBaseImplement.Models; +using EmployeeManagmentDataBaseImplement; using System; using System.Collections.Generic; using System.Linq; @@ -12,24 +14,110 @@ namespace EmployeeManagmentBusinessLogic.BusinessLogic { public class PhisicalPersonLogic : IPhisicalPersonLogic { + private readonly EmployeeManagementDbContext _context; + + public PhisicalPersonLogic(EmployeeManagementDbContext context) + { + _context = context; + } + public void CreateOrUpdate(PhisicalPersonBindingModel model) { - throw new NotImplementedException(); + PhisicalPerson? person = _context.PhysicalPersons + .FirstOrDefault(p => p.Id == model.Id); + + if (person == null) + { + // Создание нового + person = new PhisicalPerson + { + Name = model.Name, + Surname = model.Surname, + Patronymic = model.Patronomic, + Birthday = model.Birthday, + Gender = model.Gender, + Address = model.Address, + Telephone = model.Telephone + }; + _context.PhysicalPersons.Add(person); + } + else + { + // Обновление существующего + person.Name = model.Name; + person.Surname = model.Surname; + person.Patronymic = model.Patronomic; + person.Birthday = model.Birthday; + person.Gender = model.Gender; + person.Address = model.Address; + person.Telephone = model.Telephone; + } + + _context.SaveChanges(); } public void Delete(int id) { - throw new NotImplementedException(); + var person = _context.PhysicalPersons.FirstOrDefault(p => p.Id == id); + if (person != null) + { + _context.PhysicalPersons.Remove(person); + _context.SaveChanges(); + } } public PhisicalPersonViewModel? GetPhisicalPersonById(int id) { - throw new NotImplementedException(); + var person = _context.PhysicalPersons + .Where(p => p.Id == id) + .Select(p => new PhisicalPersonViewModel + { + Id = p.Id, + Name = p.Name, + Surname = p.Surname, + Patronomic = p.Patronymic, + Birthday = p.Birthday, + Gender = p.Gender, + Address = p.Address, + Telephone = p.Telephone + }) + .FirstOrDefault(); + + return person; } public List GetPhisicalPersons(PhisicalPersonSearchModel model) { - throw new NotImplementedException(); + var query = _context.PhysicalPersons.AsQueryable(); + + if (!string.IsNullOrEmpty(model.Name)) + { + query = query.Where(p => p.Name.Contains(model.Name)); + } + + if (!string.IsNullOrEmpty(model.Surname)) + { + query = query.Where(p => p.Surname.Contains(model.Surname)); + } + + if (!string.IsNullOrEmpty(model.Patronomic)) + { + query = query.Where(p => p.Patronymic.Contains(model.Patronomic)); + } + + return query + .Select(p => new PhisicalPersonViewModel + { + Id = p.Id, + Name = p.Name, + Surname = p.Surname, + Patronomic = p.Patronymic, + Birthday = p.Birthday, + Gender = p.Gender, + Address = p.Address, + Telephone = p.Telephone + }) + .ToList(); } } } diff --git a/EmployeeManagmentBusinessLogic/EmployeeManagmentBusinessLogic.csproj b/EmployeeManagmentBusinessLogic/EmployeeManagmentBusinessLogic.csproj index d14d37e..a0b5388 100644 --- a/EmployeeManagmentBusinessLogic/EmployeeManagmentBusinessLogic.csproj +++ b/EmployeeManagmentBusinessLogic/EmployeeManagmentBusinessLogic.csproj @@ -8,6 +8,7 @@ + diff --git a/EmployeeManagmentContracts/BindingModels/EmployeeBindingModel.cs b/EmployeeManagmentContracts/BindingModels/EmployeeBindingModel.cs index 574614b..d8f9e19 100644 --- a/EmployeeManagmentContracts/BindingModels/EmployeeBindingModel.cs +++ b/EmployeeManagmentContracts/BindingModels/EmployeeBindingModel.cs @@ -14,6 +14,6 @@ namespace EmployeeManagmentContracts.BindingModels public DateTime? EndJob { get; set; } public string? PartTimeJob { get; set; } public float Bid { get; set; } - public int PhisicalPersonId { get; set; } + public int PhisicalPersonsId { get; set; } } } diff --git a/EmployeeManagmentContracts/ViewModels/EmployeeViewModel.cs b/EmployeeManagmentContracts/ViewModels/EmployeeViewModel.cs index 54b3965..bdd967e 100644 --- a/EmployeeManagmentContracts/ViewModels/EmployeeViewModel.cs +++ b/EmployeeManagmentContracts/ViewModels/EmployeeViewModel.cs @@ -10,11 +10,12 @@ namespace EmployeeManagmentContracts.ViewModels { public int Id { get; set; } public string NameJob { get; set; } = string.Empty; - public DateTime StartJob { get; set; } + public DateTime? StartJob { get; set; } public DateTime? EndJob { get; set; } public string? PartTimeJob { get; set; } public float Bid { get; set; } - public string PhisicalPersonName { get; set; } = string.Empty; + public int PhysicalPersonsId { get; set; } + public string? PhysicalPersonName { get; set; } } } diff --git a/EmployeeManagmentDataBaseImplement/EmployeeManagementDbContext .cs b/EmployeeManagmentDataBaseImplement/EmployeeManagementDbContext .cs index 9b8f004..95656be 100644 --- a/EmployeeManagmentDataBaseImplement/EmployeeManagementDbContext .cs +++ b/EmployeeManagmentDataBaseImplement/EmployeeManagementDbContext .cs @@ -1,23 +1,24 @@ using EmployeeManagmentDataBaseImplement.Models; using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace EmployeeManagmentDataBaseImplement { public class EmployeeManagementDbContext : DbContext { - public DbSet Employees { get; set; } - public DbSet PhisicalPersons { get; set; } - public DbSet Salaries { get; set; } - public DbSet Vacations { get; set; } + // DbSets для моделей + public virtual DbSet Employees { get; set; } + public virtual DbSet PhysicalPersons { get; set; } + public virtual DbSet Salaries { get; set; } + public virtual DbSet Vacations { get; set; } + // Метод для настройки конфигурации protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { - optionsBuilder.UseSqlServer("YourConnectionStringHere"); + if (!optionsBuilder.IsConfigured) + { + optionsBuilder.UseMySQL("Server=localhost;Port=3306;Database=EmployeeDB;User=root;Password=SuperSecretPasswork2003;"); + } + base.OnConfiguring(optionsBuilder); } } } diff --git a/EmployeeManagmentDataBaseImplement/EmployeeManagmentDataBaseImplement.csproj b/EmployeeManagmentDataBaseImplement/EmployeeManagmentDataBaseImplement.csproj index 27a75c4..95eb660 100644 --- a/EmployeeManagmentDataBaseImplement/EmployeeManagmentDataBaseImplement.csproj +++ b/EmployeeManagmentDataBaseImplement/EmployeeManagmentDataBaseImplement.csproj @@ -23,6 +23,7 @@ + diff --git a/EmployeeManagmentDataBaseImplement/Migrations/20241113084724_InitialMigration.Designer.cs b/EmployeeManagmentDataBaseImplement/Migrations/20241113084724_InitialMigration.Designer.cs new file mode 100644 index 0000000..55dd2ce --- /dev/null +++ b/EmployeeManagmentDataBaseImplement/Migrations/20241113084724_InitialMigration.Designer.cs @@ -0,0 +1,197 @@ +// +using System; +using EmployeeManagmentDataBaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EmployeeManagmentDataBaseImplement.Migrations +{ + [DbContext(typeof(EmployeeManagementDbContext))] + [Migration("20241113084724_InitialMigration")] + partial class InitialMigration + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Bid") + .HasColumnType("float"); + + b.Property("EndJob") + .HasColumnType("datetime(6)"); + + b.Property("NameJob") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("PartTimeJob") + .HasColumnType("longtext"); + + b.Property("PhisicalPersonsId") + .HasColumnType("int"); + + b.Property("StartJob") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("PhisicalPersonsId"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.PhisicalPerson", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Address") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Birthday") + .HasColumnType("datetime(6)"); + + b.Property("Gender") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Patronymic") + .HasColumnType("longtext"); + + b.Property("Surname") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Telephone") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("PhysicalPersons"); + }); + + modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Salary", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("CountHours") + .HasColumnType("int"); + + b.Property("Data") + .HasColumnType("datetime(6)"); + + b.Property("EmployeesId") + .HasColumnType("int"); + + b.Property("Passed") + .HasColumnType("tinyint(1)"); + + b.Property("Premium") + .HasColumnType("float"); + + b.Property("PriceHour") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("EmployeesId"); + + b.ToTable("Salaries"); + }); + + modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Vacation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("EmployeesId") + .HasColumnType("int"); + + b.Property("EndData") + .HasColumnType("datetime(6)"); + + b.Property("Passed") + .HasColumnType("tinyint(1)"); + + b.Property("StartData") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("EmployeesId"); + + b.ToTable("Vacations"); + }); + + modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Employee", b => + { + b.HasOne("EmployeeManagmentDataBaseImplement.Models.PhisicalPerson", "PhisicalPerson") + .WithMany("Employees") + .HasForeignKey("PhisicalPersonsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("PhisicalPerson"); + }); + + modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Salary", b => + { + b.HasOne("EmployeeManagmentDataBaseImplement.Models.Employee", "Employee") + .WithMany("Salaries") + .HasForeignKey("EmployeesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Vacation", b => + { + b.HasOne("EmployeeManagmentDataBaseImplement.Models.Employee", "Employee") + .WithMany("Vacations") + .HasForeignKey("EmployeesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Employee", b => + { + b.Navigation("Salaries"); + + b.Navigation("Vacations"); + }); + + modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.PhisicalPerson", b => + { + b.Navigation("Employees"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/EmployeeManagmentDataBaseImplement/Migrations/20241113084724_InitialMigration.cs b/EmployeeManagmentDataBaseImplement/Migrations/20241113084724_InitialMigration.cs new file mode 100644 index 0000000..b35e8aa --- /dev/null +++ b/EmployeeManagmentDataBaseImplement/Migrations/20241113084724_InitialMigration.cs @@ -0,0 +1,143 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using MySql.EntityFrameworkCore.Metadata; + +#nullable disable + +namespace EmployeeManagmentDataBaseImplement.Migrations +{ + /// + public partial class InitialMigration : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterDatabase() + .Annotation("MySQL:Charset", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "PhysicalPersons", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn), + Name = table.Column(type: "longtext", nullable: false), + Surname = table.Column(type: "longtext", nullable: false), + Patronymic = table.Column(type: "longtext", nullable: true), + Birthday = table.Column(type: "datetime(6)", nullable: false), + Gender = table.Column(type: "longtext", nullable: false), + Address = table.Column(type: "longtext", nullable: false), + Telephone = table.Column(type: "longtext", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PhysicalPersons", x => x.Id); + }) + .Annotation("MySQL:Charset", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Employees", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn), + NameJob = table.Column(type: "longtext", nullable: false), + StartJob = table.Column(type: "datetime(6)", nullable: true), + EndJob = table.Column(type: "datetime(6)", nullable: true), + PartTimeJob = table.Column(type: "longtext", nullable: true), + Bid = table.Column(type: "float", nullable: false), + PhisicalPersonsId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Employees", x => x.Id); + table.ForeignKey( + name: "FK_Employees_PhysicalPersons_PhisicalPersonsId", + column: x => x.PhisicalPersonsId, + principalTable: "PhysicalPersons", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySQL:Charset", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Salaries", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn), + CountHours = table.Column(type: "int", nullable: false), + PriceHour = table.Column(type: "float", nullable: false), + Premium = table.Column(type: "float", nullable: true), + Data = table.Column(type: "datetime(6)", nullable: true), + Passed = table.Column(type: "tinyint(1)", nullable: false), + EmployeesId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Salaries", x => x.Id); + table.ForeignKey( + name: "FK_Salaries_Employees_EmployeesId", + column: x => x.EmployeesId, + principalTable: "Employees", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySQL:Charset", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Vacations", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn), + StartData = table.Column(type: "datetime(6)", nullable: false), + EndData = table.Column(type: "datetime(6)", nullable: false), + Passed = table.Column(type: "tinyint(1)", nullable: false), + EmployeesId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Vacations", x => x.Id); + table.ForeignKey( + name: "FK_Vacations_Employees_EmployeesId", + column: x => x.EmployeesId, + principalTable: "Employees", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySQL:Charset", "utf8mb4"); + + migrationBuilder.CreateIndex( + name: "IX_Employees_PhisicalPersonsId", + table: "Employees", + column: "PhisicalPersonsId"); + + migrationBuilder.CreateIndex( + name: "IX_Salaries_EmployeesId", + table: "Salaries", + column: "EmployeesId"); + + migrationBuilder.CreateIndex( + name: "IX_Vacations_EmployeesId", + table: "Vacations", + column: "EmployeesId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Salaries"); + + migrationBuilder.DropTable( + name: "Vacations"); + + migrationBuilder.DropTable( + name: "Employees"); + + migrationBuilder.DropTable( + name: "PhysicalPersons"); + } + } +} diff --git a/EmployeeManagmentDataBaseImplement/Migrations/EmployeeManagementDbContextModelSnapshot.cs b/EmployeeManagmentDataBaseImplement/Migrations/EmployeeManagementDbContextModelSnapshot.cs new file mode 100644 index 0000000..1c87369 --- /dev/null +++ b/EmployeeManagmentDataBaseImplement/Migrations/EmployeeManagementDbContextModelSnapshot.cs @@ -0,0 +1,194 @@ +// +using System; +using EmployeeManagmentDataBaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EmployeeManagmentDataBaseImplement.Migrations +{ + [DbContext(typeof(EmployeeManagementDbContext))] + partial class EmployeeManagementDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Bid") + .HasColumnType("float"); + + b.Property("EndJob") + .HasColumnType("datetime(6)"); + + b.Property("NameJob") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("PartTimeJob") + .HasColumnType("longtext"); + + b.Property("PhisicalPersonsId") + .HasColumnType("int"); + + b.Property("StartJob") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("PhisicalPersonsId"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.PhisicalPerson", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Address") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Birthday") + .HasColumnType("datetime(6)"); + + b.Property("Gender") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Patronymic") + .HasColumnType("longtext"); + + b.Property("Surname") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Telephone") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("PhysicalPersons"); + }); + + modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Salary", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("CountHours") + .HasColumnType("int"); + + b.Property("Data") + .HasColumnType("datetime(6)"); + + b.Property("EmployeesId") + .HasColumnType("int"); + + b.Property("Passed") + .HasColumnType("tinyint(1)"); + + b.Property("Premium") + .HasColumnType("float"); + + b.Property("PriceHour") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("EmployeesId"); + + b.ToTable("Salaries"); + }); + + modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Vacation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("EmployeesId") + .HasColumnType("int"); + + b.Property("EndData") + .HasColumnType("datetime(6)"); + + b.Property("Passed") + .HasColumnType("tinyint(1)"); + + b.Property("StartData") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("EmployeesId"); + + b.ToTable("Vacations"); + }); + + modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Employee", b => + { + b.HasOne("EmployeeManagmentDataBaseImplement.Models.PhisicalPerson", "PhisicalPerson") + .WithMany("Employees") + .HasForeignKey("PhisicalPersonsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("PhisicalPerson"); + }); + + modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Salary", b => + { + b.HasOne("EmployeeManagmentDataBaseImplement.Models.Employee", "Employee") + .WithMany("Salaries") + .HasForeignKey("EmployeesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Vacation", b => + { + b.HasOne("EmployeeManagmentDataBaseImplement.Models.Employee", "Employee") + .WithMany("Vacations") + .HasForeignKey("EmployeesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Employee"); + }); + + modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Employee", b => + { + b.Navigation("Salaries"); + + b.Navigation("Vacations"); + }); + + modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.PhisicalPerson", b => + { + b.Navigation("Employees"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/EmployeeManagmentDataBaseImplement/Models/Employee.cs b/EmployeeManagmentDataBaseImplement/Models/Employee.cs index b3127ab..826a117 100644 --- a/EmployeeManagmentDataBaseImplement/Models/Employee.cs +++ b/EmployeeManagmentDataBaseImplement/Models/Employee.cs @@ -1,27 +1,29 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations.Schema; +using EmployeeManagmentDataModels.Models; using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using EmployeeManagmentDataModels.Models; +using System.ComponentModel.DataAnnotations.Schema; namespace EmployeeManagmentDataBaseImplement.Models { - public class Employee + public class Employee : IEmployee { [Key] public int Id { get; set; } + [Required] - public string Name { get; set; } = string.Empty; + public string NameJob { get; set; } = string.Empty; + public DateTime? StartJob { get; set; } public DateTime? EndJob { get; set; } + public string? PartTimeJob { get; set; } + public float Bid { get; set; } - [ForeignKey("PhysicalPerson")] - public int PhysicalPersonsId { get; set; } - public PhysicalPerson? PhysicalPerson { get; set; } + [ForeignKey("PhisicalPerson")] + public int PhisicalPersonsId { get; set; } + public PhisicalPerson? PhisicalPerson { get; set; } + + public List Salaries { get; set; } = new(); + public List Vacations { get; set; } = new(); } } diff --git a/EmployeeManagmentDataBaseImplement/Models/PhisicalPerson.cs b/EmployeeManagmentDataBaseImplement/Models/PhisicalPerson.cs index 4f91348..01774bf 100644 --- a/EmployeeManagmentDataBaseImplement/Models/PhisicalPerson.cs +++ b/EmployeeManagmentDataBaseImplement/Models/PhisicalPerson.cs @@ -1,4 +1,5 @@ -using System; +using EmployeeManagmentDataModels.Models; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; @@ -7,21 +8,27 @@ using System.Threading.Tasks; namespace EmployeeManagmentDataBaseImplement.Models { - public class PhisicalPerson + public class PhisicalPerson : IPhisicalPerson { [Key] public int Id { get; set; } + [Required] public string Name { get; set; } = string.Empty; + [Required] public string Surname { get; set; } = string.Empty; + public string? Patronymic { get; set; } + [Required] public DateTime Birthday { get; set; } + [Required] public string Gender { get; set; } = string.Empty; + [Required] public string Address { get; set; } = string.Empty; + [Required] public string Telephone { get; set; } = string.Empty; - // Связь с сотрудниками - public List? Employees { get; set; } + public List Employees { get; set; } = new(); } } diff --git a/EmployeeManagmentDataBaseImplement/Models/Salary.cs b/EmployeeManagmentDataBaseImplement/Models/Salary.cs index f779912..d3c9304 100644 --- a/EmployeeManagmentDataBaseImplement/Models/Salary.cs +++ b/EmployeeManagmentDataBaseImplement/Models/Salary.cs @@ -1,12 +1,27 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using EmployeeManagmentDataModels.Models; namespace EmployeeManagmentDataBaseImplement.Models { - public class Salary + public class Salary : ISalary { + [Key] + public int Id { get; set; } + + public int CountHours { get; set; } + public float PriceHour { get; set; } + public float? Premium { get; set; } + public DateTime? Data { get; set; } + public bool Passed { get; set; } + + [ForeignKey("Employee")] + public int EmployeesId { get; set; } + public Employee? Employee { get; set; } } } diff --git a/EmployeeManagmentDataBaseImplement/Models/Vacation.cs b/EmployeeManagmentDataBaseImplement/Models/Vacation.cs index bce5880..bec2b39 100644 --- a/EmployeeManagmentDataBaseImplement/Models/Vacation.cs +++ b/EmployeeManagmentDataBaseImplement/Models/Vacation.cs @@ -1,12 +1,25 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; +using EmployeeManagmentDataModels.Models; namespace EmployeeManagmentDataBaseImplement.Models { - public class Vacation + public class Vacation : IVacation { + [Key] + public int Id { get; set; } + + public DateTime StartData { get; set; } + public DateTime EndData { get; set; } + public bool Passed { get; set; } + + [ForeignKey("Employee")] + public int EmployeesId { get; set; } + public Employee? Employee { get; set; } } } diff --git a/EmployeeManagmentDataBaseImplement/docker-compose.yml b/EmployeeManagmentDataBaseImplement/docker-compose.yml index e7b9c72..8ff048d 100644 --- a/EmployeeManagmentDataBaseImplement/docker-compose.yml +++ b/EmployeeManagmentDataBaseImplement/docker-compose.yml @@ -1,18 +1,23 @@ version: '3.9' services: - sqlserver-db: - image: mcr.microsoft.com/mssql/server:2022-latest - container_name: sqlserver-db - environment: - - ACCEPT_EULA=Y - - SA_PASSWORD=YourStrong@Password123 - - MSSQL_PID=Express - ports: - - "1433:1433" - volumes: - - sql_data:/var/opt/mssql + mysql: + image: mysql:8.0 + container_name: employee_db restart: always + environment: + MYSQL_ROOT_PASSWORD: SuperSecretPasswork2003 + MYSQL_DATABASE: EmployeeDB + ports: + - "3306:3306" + volumes: + - mysql_data:/var/lib/mysql + networks: + - employee_network volumes: - sql_data: + mysql_data: + +networks: + employee_network: + driver: bridge \ No newline at end of file diff --git a/EmployeeManagmentDataModels/Models/Employee.cs b/EmployeeManagmentDataModels/Models/Employee.cs deleted file mode 100644 index 8bffa70..0000000 --- a/EmployeeManagmentDataModels/Models/Employee.cs +++ /dev/null @@ -1,25 +0,0 @@ -using EmployeeManagmentDataModels.Enums; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace EmployeeManagmentDataModels.Models -{ - public class Employee - { - public int Id { get; set; } - public string NameJob { get; set; } = string.Empty; - public DateTime StartJob { get; set; } - public DateTime? EndJob { get; set; } - public JobType PartTimeJob { get; set; } - public decimal Bid { get; set; } // Ставка - public int PhysicalPersonId { get; set; } - - // Связь с физическим лицом - public PhysicalPerson? PhysicalPerson { get; set; } - public List? Salaries { get; set; } - public List? Vacations { get; set; } - } -} diff --git a/EmployeeManagmentDataModels/Models/IEmployee.cs b/EmployeeManagmentDataModels/Models/IEmployee.cs new file mode 100644 index 0000000..f19e68d --- /dev/null +++ b/EmployeeManagmentDataModels/Models/IEmployee.cs @@ -0,0 +1,20 @@ +using EmployeeManagmentDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EmployeeManagmentDataModels.Models +{ + public interface IEmployee + { + int Id { get; set; } + string NameJob { get; set; } + DateTime? StartJob { get; set; } + DateTime? EndJob { get; set; } + string? PartTimeJob { get; set; } + float Bid { get; set; } + int PhisicalPersonsId { get; set; } + } +} diff --git a/EmployeeManagmentDataModels/Models/IPhisicalPerson.cs b/EmployeeManagmentDataModels/Models/IPhisicalPerson.cs new file mode 100644 index 0000000..4e0cc7e --- /dev/null +++ b/EmployeeManagmentDataModels/Models/IPhisicalPerson.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EmployeeManagmentDataModels.Models +{ + public interface IPhisicalPerson + { + int Id { get; set; } + string Name { get; set; } + string Surname { get; set; } + string? Patronymic { get; set; } + DateTime Birthday { get; set; } + string Gender { get; set; } + string Address { get; set; } + string Telephone { get; set; } + } +} diff --git a/EmployeeManagmentDataModels/Models/ISalary.cs b/EmployeeManagmentDataModels/Models/ISalary.cs new file mode 100644 index 0000000..6dcdabc --- /dev/null +++ b/EmployeeManagmentDataModels/Models/ISalary.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EmployeeManagmentDataModels.Models +{ + public interface ISalary + { + int Id { get; set; } + int CountHours { get; set; } + float PriceHour { get; set; } + float? Premium { get; set; } + DateTime? Data { get; set; } + bool Passed { get; set; } + int EmployeesId { get; set; } + } +} diff --git a/EmployeeManagmentDataModels/Models/IVacation.cs b/EmployeeManagmentDataModels/Models/IVacation.cs new file mode 100644 index 0000000..4dc0f87 --- /dev/null +++ b/EmployeeManagmentDataModels/Models/IVacation.cs @@ -0,0 +1,18 @@ +using EmployeeManagmentDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EmployeeManagmentDataModels.Models +{ + public interface IVacation + { + int Id { get; set; } + DateTime StartData { get; set; } + DateTime EndData { get; set; } + bool Passed { get; set; } + int EmployeesId { get; set; } + } +} diff --git a/EmployeeManagmentDataModels/Models/PhysicalPerson.cs b/EmployeeManagmentDataModels/Models/PhysicalPerson.cs deleted file mode 100644 index fc9906d..0000000 --- a/EmployeeManagmentDataModels/Models/PhysicalPerson.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace EmployeeManagmentDataModels.Models -{ - public class PhysicalPerson - { - public int Id { get; set; } - public string Name { get; set; } = string.Empty; - public DateTime BirthDate { get; set; } - public string Address { get; set; } = string.Empty; - - // Связь с сотрудниками - public List? Employees { get; set; } - } -} diff --git a/EmployeeManagmentDataModels/Models/Salary.cs b/EmployeeManagmentDataModels/Models/Salary.cs deleted file mode 100644 index ff8d55f..0000000 --- a/EmployeeManagmentDataModels/Models/Salary.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace EmployeeManagmentDataModels.Models -{ - public class Salary - { - public int Id { get; set; } - public int CountHours { get; set; } - public decimal PriceHour { get; set; } - public decimal Premium { get; set; } - public DateTime Date { get; set; } - public bool Passed { get; set; } - public int EmployeeId { get; set; } - - // Связь с сотрудником - public Employee? Employee { get; set; } - } -} diff --git a/EmployeeManagmentDataModels/Models/Vacation.cs b/EmployeeManagmentDataModels/Models/Vacation.cs deleted file mode 100644 index 27e297d..0000000 --- a/EmployeeManagmentDataModels/Models/Vacation.cs +++ /dev/null @@ -1,21 +0,0 @@ -using EmployeeManagmentDataModels.Enums; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace EmployeeManagmentDataModels.Models -{ - public class Vacation - { - public int Id { get; set; } - public DateTime StartData { get; set; } - public DateTime EndData { get; set; } - public VacationStatus Passed { get; set; } - public int EmployeeId { get; set; } - - // Связь с сотрудником - public Employee? Employee { get; set; } - } -} diff --git a/EmployeeManagmentView/App.xaml.cs b/EmployeeManagmentView/App.xaml.cs index b444bc7..09e2aea 100644 --- a/EmployeeManagmentView/App.xaml.cs +++ b/EmployeeManagmentView/App.xaml.cs @@ -1,14 +1,47 @@ -using System.Configuration; -using System.Data; +using EmployeeManagmentDataBaseImplement; +using EmployeeManagmentBusinessLogic.BusinessLogic; +using EmployeeManagmentContracts.BusinessLogicContracts; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.EntityFrameworkCore; +using System; using System.Windows; namespace EmployeeManagmentView { - /// - /// Interaction logic for App.xaml - /// public partial class App : Application { - } + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + protected override void OnStartup(StartupEventArgs e) + { + var serviceCollection = new ServiceCollection(); + ConfigureServices(serviceCollection); + _serviceProvider = serviceCollection.BuildServiceProvider(); + + try + { + var mainWindow = _serviceProvider.GetRequiredService(); + mainWindow.Show(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при открытии MainWindow", MessageBoxButton.OK, MessageBoxImage.Error); + } + + base.OnStartup(e); + } + + private static void ConfigureServices(ServiceCollection services) + { + // Регистрация контекста базы данных с использованием конфигурации + services.AddLogging(configure => configure.AddConsole()); + // Регистрация бизнес-логики и других сервисов + services.AddTransient(); + services.AddTransient(); + + // Регистрация окон + services.AddTransient(); + } + } } diff --git a/EmployeeManagmentView/EmployeeManagmentView.csproj b/EmployeeManagmentView/EmployeeManagmentView.csproj index e3e33e3..02c7a05 100644 --- a/EmployeeManagmentView/EmployeeManagmentView.csproj +++ b/EmployeeManagmentView/EmployeeManagmentView.csproj @@ -8,4 +8,18 @@ true + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/EmployeeManagmentView/EmployeesWindow.xaml.cs b/EmployeeManagmentView/EmployeesWindow.xaml.cs index 0c77d29..02752bb 100644 --- a/EmployeeManagmentView/EmployeesWindow.xaml.cs +++ b/EmployeeManagmentView/EmployeesWindow.xaml.cs @@ -1,4 +1,6 @@ -using System; +using EmployeeManagmentBusinessLogic.BusinessLogic; +using EmployeeManagmentContracts.BusinessLogicContracts; +using System; using System.Collections.Generic; using System.Linq; using System.Text; diff --git a/EmployeeManagmentView/MainWindow.xaml b/EmployeeManagmentView/MainWindow.xaml index cb91b5e..9b3652d 100644 --- a/EmployeeManagmentView/MainWindow.xaml +++ b/EmployeeManagmentView/MainWindow.xaml @@ -12,7 +12,11 @@ FontSize="24" FontWeight="Bold" Margin="10"/> - +