Ох уж эти ошибки в VisualStudio...
This commit is contained in:
parent
7847a4e41a
commit
4b004a2628
@ -3,163 +3,53 @@ using System.Linq;
|
||||
using EmployeeManagmentContracts.BindingModels;
|
||||
using EmployeeManagmentContracts.BusinessLogicContracts;
|
||||
using EmployeeManagmentContracts.SearchModels;
|
||||
using EmployeeManagmentContracts.StoragesContracts;
|
||||
using EmployeeManagmentContracts.ViewModels;
|
||||
using EmployeeManagmentDataBaseImplement;
|
||||
using EmployeeManagmentDataBaseImplement.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace EmployeeManagmentBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class EmployeeLogic : IEmployeeLogic
|
||||
{
|
||||
private readonly EmployeeManagementDbContext _context;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IEmployeeStorage _employeeStorage;
|
||||
|
||||
public EmployeeLogic(EmployeeManagementDbContext context)
|
||||
public EmployeeLogic(ILogger<EmployeeLogic> logger, IEmployeeStorage employeeStorage)
|
||||
{
|
||||
_context = context;
|
||||
_logger = logger;
|
||||
_employeeStorage = employeeStorage;
|
||||
}
|
||||
|
||||
public void CreateOrUpdate(EmployeeBindingModel model)
|
||||
{
|
||||
// Проверка на обязательные поля
|
||||
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)
|
||||
{
|
||||
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.");
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
public EmployeeViewModel? GetEmployeeById(int id)
|
||||
public EmployeeViewModel? GetElement(int id)
|
||||
{
|
||||
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;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<EmployeeViewModel> GetEmployees(EmployeeSearchModel model)
|
||||
public List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model)
|
||||
{
|
||||
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();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<EmployeeViewModel> GetFullList()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Insert(EmployeeViewModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Update(EmployeeViewModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,21 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\EmployeeManagmentContracts\EmployeeManagmentContracts.csproj" />
|
||||
<ProjectReference Include="..\EmployeeManagmentDataBaseImplement\EmployeeManagmentDataBaseImplement.csproj" />
|
||||
<ProjectReference Include="..\EmployeeManagmentDataModels\EmployeeManagmentDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -11,9 +11,11 @@ namespace EmployeeManagmentContracts.BusinessLogicContracts
|
||||
{
|
||||
public interface IEmployeeLogic
|
||||
{
|
||||
List<EmployeeViewModel> GetEmployees(EmployeeSearchModel model);
|
||||
EmployeeViewModel? GetEmployeeById(int id);
|
||||
void CreateOrUpdate(EmployeeBindingModel model);
|
||||
List<EmployeeViewModel> GetFullList();
|
||||
List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model);
|
||||
EmployeeViewModel? GetElement(int id);
|
||||
void Insert(EmployeeViewModel model);
|
||||
void Update(EmployeeViewModel model);
|
||||
void Delete(int id);
|
||||
}
|
||||
|
||||
|
@ -9,5 +9,19 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\EmployeeManagmentDataModels\EmployeeManagmentDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -16,7 +16,7 @@ namespace EmployeeManagmentDataBaseImplement
|
||||
{
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
optionsBuilder.UseMySQL("Server=localhost;Port=3306;Database=EmployeeDB;User=root;Password=SuperSecretPasswork2003;");
|
||||
optionsBuilder.UseNpgsql("Host=localhost;Database=EmployeeManagementDB;Username=postgres;Password=23859");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
@ -9,25 +9,21 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
|
||||
<PackageReference Include="MySql.EntityFrameworkCore" Version="8.0.8" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\EmployeeManagmentContracts\EmployeeManagmentContracts.csproj" />
|
||||
<ProjectReference Include="..\EmployeeManagmentDataModels\EmployeeManagmentDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -9,34 +9,34 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace EmployeeManagmentDataBaseImplement.Implements
|
||||
{
|
||||
public class VacationStorage : ISalaryStorage
|
||||
public class VacationStorage : IVacationStorage
|
||||
{
|
||||
public void Delete(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public SalaryViewModel? GetElement(int id)
|
||||
public VacationViewModel? GetElement(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<SalaryViewModel> GetFilteredList(SalarySearchModel model)
|
||||
public List<VacationViewModel> GetFilteredList(VacationSearchModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public List<SalaryViewModel> GetFullList()
|
||||
public List<VacationViewModel> GetFullList()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Insert(SalaryViewModel model)
|
||||
public void Insert(VacationViewModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Update(SalaryViewModel model)
|
||||
public void Update(VacationViewModel model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@ -5,14 +5,15 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace EmployeeManagmentDataBaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(EmployeeManagementDbContext))]
|
||||
[Migration("20241113084724_InitialMigration")]
|
||||
partial class InitialMigration
|
||||
[Migration("20241124115213_InitMigration")]
|
||||
partial class InitMigration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
@ -20,32 +21,36 @@ namespace EmployeeManagmentDataBaseImplement.Migrations
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.10")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Employee", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<float>("Bid")
|
||||
.HasColumnType("float");
|
||||
.HasColumnType("real");
|
||||
|
||||
b.Property<DateTime?>("EndJob")
|
||||
.HasColumnType("datetime(6)");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("NameJob")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PartTimeJob")
|
||||
.HasColumnType("longtext");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("PhisicalPersonsId")
|
||||
.HasColumnType("int");
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime?>("StartJob")
|
||||
.HasColumnType("datetime(6)");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
@ -58,33 +63,35 @@ namespace EmployeeManagmentDataBaseImplement.Migrations
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("Birthday")
|
||||
.HasColumnType("datetime(6)");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Gender")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Patronymic")
|
||||
.HasColumnType("longtext");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Surname")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Telephone")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
@ -95,25 +102,27 @@ namespace EmployeeManagmentDataBaseImplement.Migrations
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("CountHours")
|
||||
.HasColumnType("int");
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime?>("Data")
|
||||
.HasColumnType("datetime(6)");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("EmployeesId")
|
||||
.HasColumnType("int");
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<bool>("Passed")
|
||||
.HasColumnType("tinyint(1)");
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<float?>("Premium")
|
||||
.HasColumnType("float");
|
||||
.HasColumnType("real");
|
||||
|
||||
b.Property<float>("PriceHour")
|
||||
.HasColumnType("float");
|
||||
.HasColumnType("real");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
@ -126,19 +135,21 @@ namespace EmployeeManagmentDataBaseImplement.Migrations
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("EmployeesId")
|
||||
.HasColumnType("int");
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("EndData")
|
||||
.HasColumnType("datetime(6)");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<bool>("Passed")
|
||||
.HasColumnType("tinyint(1)");
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<DateTime>("StartData")
|
||||
.HasColumnType("datetime(6)");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
@ -1,52 +1,48 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using MySql.EntityFrameworkCore.Metadata;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace EmployeeManagmentDataBaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialMigration : Migration
|
||||
public partial class InitMigration : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AlterDatabase()
|
||||
.Annotation("MySQL:Charset", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "PhysicalPersons",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn),
|
||||
Name = table.Column<string>(type: "longtext", nullable: false),
|
||||
Surname = table.Column<string>(type: "longtext", nullable: false),
|
||||
Patronymic = table.Column<string>(type: "longtext", nullable: true),
|
||||
Birthday = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
||||
Gender = table.Column<string>(type: "longtext", nullable: false),
|
||||
Address = table.Column<string>(type: "longtext", nullable: false),
|
||||
Telephone = table.Column<string>(type: "longtext", nullable: false)
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Name = table.Column<string>(type: "text", nullable: false),
|
||||
Surname = table.Column<string>(type: "text", nullable: false),
|
||||
Patronymic = table.Column<string>(type: "text", nullable: true),
|
||||
Birthday = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
Gender = table.Column<string>(type: "text", nullable: false),
|
||||
Address = table.Column<string>(type: "text", nullable: false),
|
||||
Telephone = table.Column<string>(type: "text", 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<int>(type: "int", nullable: false)
|
||||
.Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn),
|
||||
NameJob = table.Column<string>(type: "longtext", nullable: false),
|
||||
StartJob = table.Column<DateTime>(type: "datetime(6)", nullable: true),
|
||||
EndJob = table.Column<DateTime>(type: "datetime(6)", nullable: true),
|
||||
PartTimeJob = table.Column<string>(type: "longtext", nullable: true),
|
||||
Bid = table.Column<float>(type: "float", nullable: false),
|
||||
PhisicalPersonsId = table.Column<int>(type: "int", nullable: false)
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
NameJob = table.Column<string>(type: "text", nullable: false),
|
||||
StartJob = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||
EndJob = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||
PartTimeJob = table.Column<string>(type: "text", nullable: true),
|
||||
Bid = table.Column<float>(type: "real", nullable: false),
|
||||
PhisicalPersonsId = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
@ -57,21 +53,20 @@ namespace EmployeeManagmentDataBaseImplement.Migrations
|
||||
principalTable: "PhysicalPersons",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
})
|
||||
.Annotation("MySQL:Charset", "utf8mb4");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Salaries",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn),
|
||||
CountHours = table.Column<int>(type: "int", nullable: false),
|
||||
PriceHour = table.Column<float>(type: "float", nullable: false),
|
||||
Premium = table.Column<float>(type: "float", nullable: true),
|
||||
Data = table.Column<DateTime>(type: "datetime(6)", nullable: true),
|
||||
Passed = table.Column<bool>(type: "tinyint(1)", nullable: false),
|
||||
EmployeesId = table.Column<int>(type: "int", nullable: false)
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
CountHours = table.Column<int>(type: "integer", nullable: false),
|
||||
PriceHour = table.Column<float>(type: "real", nullable: false),
|
||||
Premium = table.Column<float>(type: "real", nullable: true),
|
||||
Data = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
|
||||
Passed = table.Column<bool>(type: "boolean", nullable: false),
|
||||
EmployeesId = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
@ -82,19 +77,18 @@ namespace EmployeeManagmentDataBaseImplement.Migrations
|
||||
principalTable: "Employees",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
})
|
||||
.Annotation("MySQL:Charset", "utf8mb4");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Vacations",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("MySQL:ValueGenerationStrategy", MySQLValueGenerationStrategy.IdentityColumn),
|
||||
StartData = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
||||
EndData = table.Column<DateTime>(type: "datetime(6)", nullable: false),
|
||||
Passed = table.Column<bool>(type: "tinyint(1)", nullable: false),
|
||||
EmployeesId = table.Column<int>(type: "int", nullable: false)
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
StartData = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
EndData = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
Passed = table.Column<bool>(type: "boolean", nullable: false),
|
||||
EmployeesId = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
@ -105,8 +99,7 @@ namespace EmployeeManagmentDataBaseImplement.Migrations
|
||||
principalTable: "Employees",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
})
|
||||
.Annotation("MySQL:Charset", "utf8mb4");
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Employees_PhisicalPersonsId",
|
@ -4,6 +4,7 @@ using EmployeeManagmentDataBaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
@ -17,32 +18,36 @@ namespace EmployeeManagmentDataBaseImplement.Migrations
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "8.0.10")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 64);
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("EmployeeManagmentDataBaseImplement.Models.Employee", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<float>("Bid")
|
||||
.HasColumnType("float");
|
||||
.HasColumnType("real");
|
||||
|
||||
b.Property<DateTime?>("EndJob")
|
||||
.HasColumnType("datetime(6)");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("NameJob")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("PartTimeJob")
|
||||
.HasColumnType("longtext");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("PhisicalPersonsId")
|
||||
.HasColumnType("int");
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime?>("StartJob")
|
||||
.HasColumnType("datetime(6)");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
@ -55,33 +60,35 @@ namespace EmployeeManagmentDataBaseImplement.Migrations
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<DateTime>("Birthday")
|
||||
.HasColumnType("datetime(6)");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("Gender")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Patronymic")
|
||||
.HasColumnType("longtext");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Surname")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("Telephone")
|
||||
.IsRequired()
|
||||
.HasColumnType("longtext");
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
@ -92,25 +99,27 @@ namespace EmployeeManagmentDataBaseImplement.Migrations
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("CountHours")
|
||||
.HasColumnType("int");
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime?>("Data")
|
||||
.HasColumnType("datetime(6)");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("EmployeesId")
|
||||
.HasColumnType("int");
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<bool>("Passed")
|
||||
.HasColumnType("tinyint(1)");
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<float?>("Premium")
|
||||
.HasColumnType("float");
|
||||
.HasColumnType("real");
|
||||
|
||||
b.Property<float>("PriceHour")
|
||||
.HasColumnType("float");
|
||||
.HasColumnType("real");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
@ -123,19 +132,21 @@ namespace EmployeeManagmentDataBaseImplement.Migrations
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("EmployeesId")
|
||||
.HasColumnType("int");
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("EndData")
|
||||
.HasColumnType("datetime(6)");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<bool>("Passed")
|
||||
.HasColumnType("tinyint(1)");
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<DateTime>("StartData")
|
||||
.HasColumnType("datetime(6)");
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
|
@ -5,5 +5,19 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,8 +1,6 @@
|
||||
<Application x:Class="EmployeeManagmentView.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:EmployeeManagmentView"
|
||||
StartupUri="MainWindow.xaml">
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
|
@ -5,6 +5,9 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Windows;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using EmployeeManagmentContracts.StoragesContracts;
|
||||
using EmployeeManagmentDataBaseImplement.Implements;
|
||||
|
||||
namespace EmployeeManagmentView
|
||||
{
|
||||
@ -29,19 +32,28 @@ namespace EmployeeManagmentView
|
||||
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<IEmployeeStorage, EmployeeStorage>();
|
||||
services.AddTransient<IPhisicalPersonStorage, PhisicalPersonStorage>();
|
||||
services.AddTransient<ISalaryStorage, SalaryStorage>();
|
||||
services.AddTransient<IVacationStorage, VacationStorage>();
|
||||
|
||||
services.AddTransient<IPhisicalPersonLogic, PhisicalPersonLogic>();
|
||||
services.AddTransient<IEmployeeLogic, EmployeeLogic>();
|
||||
|
||||
// Регистрация окон
|
||||
services.AddTransient<MainWindow>();
|
||||
services.AddTransient<EmployeesWindow>();
|
||||
services.AddTransient<SalariesWindow>();
|
||||
services.AddTransient<VacationsWindow>();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,17 +9,26 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Extended.Wpf.Toolkit" Version="4.6.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0">
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
|
||||
<PackageReference Include="Extended.Wpf.Toolkit" Version="4.6.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\EmployeeManagmentBusinessLogic\EmployeeManagmentBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\EmployeeManagmentContracts\EmployeeManagmentContracts.csproj" />
|
||||
<ProjectReference Include="..\EmployeeManagmentDataBaseImplement\EmployeeManagmentDataBaseImplement.csproj" />
|
||||
<ProjectReference Include="..\EmployeeManagmentDataModels\EmployeeManagmentDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -12,11 +12,6 @@
|
||||
FontSize="24"
|
||||
FontWeight="Bold"
|
||||
Margin="10"/>
|
||||
<Button Content="Просмотр физических лиц"
|
||||
Width="200"
|
||||
Height="40"
|
||||
Margin="10"
|
||||
Click="ViewPhisicalPerson_Click"/>
|
||||
<Button Content="Просмотр сотрудников"
|
||||
Width="200"
|
||||
Height="40"
|
||||
|
@ -7,13 +7,12 @@ namespace EmployeeManagmentView
|
||||
{
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
private readonly IPhisicalPersonLogic _phisicalPersonLogic;
|
||||
|
||||
private readonly IEmployeeLogic _employeeLogic;
|
||||
|
||||
// Constructor with Dependency Injection
|
||||
public MainWindow(IPhisicalPersonLogic phisicalPersonLogic, IEmployeeLogic employeeLogic)
|
||||
public MainWindow(IEmployeeLogic employeeLogic)
|
||||
{
|
||||
_phisicalPersonLogic = phisicalPersonLogic;
|
||||
_employeeLogic = employeeLogic;
|
||||
InitializeComponent();
|
||||
}
|
||||
@ -25,13 +24,6 @@ namespace EmployeeManagmentView
|
||||
employeesWindow.Show();
|
||||
}
|
||||
|
||||
private void ViewPhisicalPerson_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Передаем логику в конструктор окна
|
||||
var phisicalPersonWindow = new PhisicalPersonWindow(_phisicalPersonLogic);
|
||||
phisicalPersonWindow.Show();
|
||||
}
|
||||
|
||||
private void ManageSalaries_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Логика для открытия окна управления зарплатами
|
||||
|
@ -1,30 +0,0 @@
|
||||
<Window x:Class="EmployeeManagmentView.PhisicalPersonWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:EmployeeManagmentView"
|
||||
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
|
||||
mc:Ignorable="d"
|
||||
Title="Physical Person Management" Height="450" Width="800">
|
||||
<Grid>
|
||||
<StackPanel>
|
||||
<!-- TextBoxes with Watermark for all fields -->
|
||||
<xctk:WatermarkTextBox Name="NameTextBox" Width="200" Margin="10" Watermark="Enter Name"/>
|
||||
<xctk:WatermarkTextBox Name="SurnameTextBox" Width="200" Margin="10" Watermark="Enter Surname"/>
|
||||
<xctk:WatermarkTextBox Name="AgeTextBox" Width="200" Margin="10" Watermark="Enter Age"/>
|
||||
<xctk:WatermarkTextBox Name="AddressTextBox" Width="200" Margin="10" Watermark="Enter Address"/>
|
||||
<xctk:WatermarkTextBox Name="TelephoneTextBox" Width="200" Margin="10" Watermark="Enter Telephone"/>
|
||||
<xctk:WatermarkTextBox Name="GenderTextBox" Width="200" Margin="10" Watermark="Enter Gender"/>
|
||||
<xctk:WatermarkTextBox Name="BirthdayTextBox" Width="200" Margin="10" Watermark="Enter Birthday (YYYY-MM-DD)"/>
|
||||
|
||||
<!-- Buttons for CRUD actions -->
|
||||
<Button Content="Add" Width="100" Margin="10" Click="AddButton_Click"/>
|
||||
<Button Content="Update" Width="100" Margin="10" Click="UpdateButton_Click"/>
|
||||
<Button Content="Delete" Width="100" Margin="10" Click="DeleteButton_Click"/>
|
||||
|
||||
<!-- DataGrid to display PhysicalPersons -->
|
||||
<DataGrid Name="PhysicalPersonsDataGrid" Margin="10" AutoGenerateColumns="True"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
@ -1,149 +0,0 @@
|
||||
using EmployeeManagmentContracts.BindingModels;
|
||||
using EmployeeManagmentContracts.BusinessLogicContracts;
|
||||
using EmployeeManagmentContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace EmployeeManagmentView
|
||||
{
|
||||
/// <summary>
|
||||
/// Логика взаимодействия для PhisicalPersonWindow.xaml
|
||||
/// </summary>
|
||||
public partial class PhisicalPersonWindow : Window
|
||||
{
|
||||
private readonly IPhisicalPersonLogic _phisicalPersonLogic;
|
||||
|
||||
public PhisicalPersonWindow(IPhisicalPersonLogic phisicalPersonLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_phisicalPersonLogic = phisicalPersonLogic;
|
||||
LoadData();
|
||||
}
|
||||
|
||||
// Загрузка данных в DataGrid
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var physicalPersons = _phisicalPersonLogic.GetPhisicalPersons(null); // Здесь можно передавать параметры для фильтрации
|
||||
PhysicalPersonsDataGrid.ItemsSource = physicalPersons;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Error loading data: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void TextBox_GotFocus(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var textBox = sender as TextBox;
|
||||
if (textBox != null && textBox.Text == "Enter Name")
|
||||
{
|
||||
textBox.Text = "";
|
||||
textBox.Foreground = new SolidColorBrush(Colors.Black); // Change text color to black
|
||||
}
|
||||
}
|
||||
|
||||
private void TextBox_LostFocus(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var textBox = sender as TextBox;
|
||||
if (textBox != null && string.IsNullOrEmpty(textBox.Text))
|
||||
{
|
||||
textBox.Text = "Enter Name"; // Reset placeholder text
|
||||
textBox.Foreground = new SolidColorBrush(Colors.Gray); // Change text color to gray
|
||||
}
|
||||
}
|
||||
|
||||
// Обработчик для кнопки "Add"
|
||||
private void AddButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var model = new PhisicalPersonBindingModel
|
||||
{
|
||||
Name = NameTextBox.Text,
|
||||
Surname = SurnameTextBox.Text,
|
||||
Birthday = DateTime.TryParse(BirthdayTextBox.Text, out DateTime birthday) ? birthday : DateTime.Now,
|
||||
Address = AddressTextBox.Text,
|
||||
Telephone = TelephoneTextBox.Text,
|
||||
Gender = GenderTextBox.Text
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
_phisicalPersonLogic.CreateOrUpdate(model);
|
||||
MessageBox.Show("Physical person added successfully!");
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Error adding data: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
// Обработчик для кнопки "Update"
|
||||
private void UpdateButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Получаем выбранную запись в DataGrid
|
||||
var selectedPerson = PhysicalPersonsDataGrid.SelectedItem as PhisicalPersonViewModel;
|
||||
if (selectedPerson == null)
|
||||
{
|
||||
MessageBox.Show("No person selected.");
|
||||
return;
|
||||
}
|
||||
|
||||
var model = new PhisicalPersonBindingModel
|
||||
{
|
||||
Id = selectedPerson.Id,
|
||||
Name = NameTextBox.Text,
|
||||
Surname = SurnameTextBox.Text,
|
||||
Birthday = DateTime.TryParse(BirthdayTextBox.Text, out DateTime birthday) ? birthday : DateTime.Now,
|
||||
Address = AddressTextBox.Text,
|
||||
Telephone = TelephoneTextBox.Text,
|
||||
Gender = GenderTextBox.Text
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
_phisicalPersonLogic.CreateOrUpdate(model);
|
||||
MessageBox.Show("Physical person updated successfully!");
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Error updating data: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
// Обработчик для кнопки "Delete"
|
||||
private void DeleteButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var selectedPerson = PhysicalPersonsDataGrid.SelectedItem as PhisicalPersonViewModel;
|
||||
if (selectedPerson == null)
|
||||
{
|
||||
MessageBox.Show("No person selected.");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_phisicalPersonLogic.Delete(selectedPerson.Id);
|
||||
MessageBox.Show("Physical person deleted successfully!");
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Error deleting data: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user