diff --git a/PersonnelDepartmentView/PersonnelDepartmentContracts/BindingModels/DealBindingModel.cs b/PersonnelDepartmentView/PersonnelDepartmentContracts/BindingModels/DealBindingModel.cs index e11b6c2..ccc6687 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentContracts/BindingModels/DealBindingModel.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentContracts/BindingModels/DealBindingModel.cs @@ -11,7 +11,7 @@ namespace PersonnelDepartmentContracts.BindingModels { public DateTime DateFrom { get; set; } - public DateTime? DateTo { get; set; } + public DateTime DateTo { get; set; } public int PositionId { get; set; } diff --git a/PersonnelDepartmentView/PersonnelDepartmentContracts/BindingModels/DepartmentBindingModel.cs b/PersonnelDepartmentView/PersonnelDepartmentContracts/BindingModels/DepartmentBindingModel.cs index 6461ad0..0d52c50 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentContracts/BindingModels/DepartmentBindingModel.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentContracts/BindingModels/DepartmentBindingModel.cs @@ -11,7 +11,7 @@ namespace PersonnelDepartmentContracts.BindingModels { public string Name { get; set; } = string.Empty; - public int Telephone { get; set; } + public long Telephone { get; set; } public int Id { get; set; } } diff --git a/PersonnelDepartmentView/PersonnelDepartmentContracts/SearchModels/DepartmentSearchModel.cs b/PersonnelDepartmentView/PersonnelDepartmentContracts/SearchModels/DepartmentSearchModel.cs index 0fbbcb0..20b19ed 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentContracts/SearchModels/DepartmentSearchModel.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentContracts/SearchModels/DepartmentSearchModel.cs @@ -12,6 +12,6 @@ namespace PersonnelDepartmentContracts.SearchModels public string? Name { get; set; } - public int? Telephone { get; set; } + public long? Telephone { get; set; } } } diff --git a/PersonnelDepartmentView/PersonnelDepartmentContracts/ViewModels/DealViewModel.cs b/PersonnelDepartmentView/PersonnelDepartmentContracts/ViewModels/DealViewModel.cs index c775558..d1ce476 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentContracts/ViewModels/DealViewModel.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentContracts/ViewModels/DealViewModel.cs @@ -13,7 +13,7 @@ namespace PersonnelDepartmentContracts.ViewModels [DisplayName("Дата с")] public DateTime DateFrom { get; set; } [DisplayName("Дата по")] - public DateTime? DateTo { get; set; } + public DateTime DateTo { get; set; } public int PositionId { get; set; } [DisplayName("Должность")] public string PositionName { get; set; } = string.Empty; diff --git a/PersonnelDepartmentView/PersonnelDepartmentContracts/ViewModels/DepartmentViewModel.cs b/PersonnelDepartmentView/PersonnelDepartmentContracts/ViewModels/DepartmentViewModel.cs index 934102b..a520b31 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentContracts/ViewModels/DepartmentViewModel.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentContracts/ViewModels/DepartmentViewModel.cs @@ -13,7 +13,7 @@ namespace PersonnelDepartmentContracts.ViewModels [DisplayName("Название")] public string Name { get; set; } = string.Empty; [DisplayName("Контактный телефон")] - public int Telephone { get; set; } + public long Telephone { get; set; } [DisplayName("Код")] public int Id { get; set; } } diff --git a/PersonnelDepartmentView/PersonnelDepartmentDataModels/Models/IDealModel.cs b/PersonnelDepartmentView/PersonnelDepartmentDataModels/Models/IDealModel.cs index 86ac98e..9293d18 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentDataModels/Models/IDealModel.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentDataModels/Models/IDealModel.cs @@ -9,7 +9,7 @@ namespace PersonnelDepartmentDataModels.Models public interface IDealModel : IId { DateTime DateFrom { get; } - DateTime? DateTo { get; } + DateTime DateTo { get; } int PositionId { get; } int EmployeeId { get; } int DepartmentId { get; } diff --git a/PersonnelDepartmentView/PersonnelDepartmentDataModels/Models/IDepartmentModel.cs b/PersonnelDepartmentView/PersonnelDepartmentDataModels/Models/IDepartmentModel.cs index 703619b..ebc089a 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentDataModels/Models/IDepartmentModel.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentDataModels/Models/IDepartmentModel.cs @@ -9,6 +9,6 @@ namespace PersonnelDepartmentDataModels.Models public interface IDepartmentModel : IId { string Name { get; } - int Telephone { get; } + long Telephone { get; } } } diff --git a/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/Migrations/20230502180408_InitMig.Designer.cs b/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/Migrations/20230502180408_InitMig.Designer.cs new file mode 100644 index 0000000..18d0857 --- /dev/null +++ b/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/Migrations/20230502180408_InitMig.Designer.cs @@ -0,0 +1,183 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using PersonnelDepartmentDatabaseImplement; + +#nullable disable + +namespace PersonnelDepartmentDatabaseImplement.Migrations +{ + [DbContext(typeof(PersonnelDepartmentDatabase))] + [Migration("20230502180408_InitMig")] + partial class InitMig + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.5") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("PersonnelDepartmentDatabaseImplement.Models.Deal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DateFrom") + .HasColumnType("timestamp with time zone"); + + b.Property("DateTo") + .HasColumnType("timestamp with time zone"); + + b.Property("DepartmentId") + .HasColumnType("integer"); + + b.Property("EmployeeId") + .HasColumnType("integer"); + + b.Property("PositionId") + .HasColumnType("integer"); + + b.Property("TypeId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("DepartmentId"); + + b.HasIndex("EmployeeId"); + + b.HasIndex("PositionId"); + + b.HasIndex("TypeId"); + + b.ToTable("Deals"); + }); + + modelBuilder.Entity("PersonnelDepartmentDatabaseImplement.Models.Department", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Telephone") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Departments"); + }); + + modelBuilder.Entity("PersonnelDepartmentDatabaseImplement.Models.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Patronymic") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("PersonnelDepartmentDatabaseImplement.Models.Position", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Positions"); + }); + + modelBuilder.Entity("PersonnelDepartmentDatabaseImplement.Models.Type", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Types"); + }); + + modelBuilder.Entity("PersonnelDepartmentDatabaseImplement.Models.Deal", b => + { + b.HasOne("PersonnelDepartmentDatabaseImplement.Models.Department", "Department") + .WithMany() + .HasForeignKey("DepartmentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PersonnelDepartmentDatabaseImplement.Models.Employee", "Employee") + .WithMany() + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PersonnelDepartmentDatabaseImplement.Models.Position", "Position") + .WithMany() + .HasForeignKey("PositionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PersonnelDepartmentDatabaseImplement.Models.Type", "Type") + .WithMany() + .HasForeignKey("TypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Department"); + + b.Navigation("Employee"); + + b.Navigation("Position"); + + b.Navigation("Type"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/Migrations/20230502180408_InitMig.cs b/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/Migrations/20230502180408_InitMig.cs new file mode 100644 index 0000000..f454544 --- /dev/null +++ b/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/Migrations/20230502180408_InitMig.cs @@ -0,0 +1,152 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace PersonnelDepartmentDatabaseImplement.Migrations +{ + /// + public partial class InitMig : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Departments", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false), + Telephone = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Departments", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Employees", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + FirstName = table.Column(type: "text", nullable: false), + LastName = table.Column(type: "text", nullable: false), + Patronymic = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Employees", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Positions", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Positions", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Types", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Types", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Deals", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + DateFrom = table.Column(type: "timestamp with time zone", nullable: false), + DateTo = table.Column(type: "timestamp with time zone", nullable: false), + PositionId = table.Column(type: "integer", nullable: false), + EmployeeId = table.Column(type: "integer", nullable: false), + DepartmentId = table.Column(type: "integer", nullable: false), + TypeId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Deals", x => x.Id); + table.ForeignKey( + name: "FK_Deals_Departments_DepartmentId", + column: x => x.DepartmentId, + principalTable: "Departments", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Deals_Employees_EmployeeId", + column: x => x.EmployeeId, + principalTable: "Employees", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Deals_Positions_PositionId", + column: x => x.PositionId, + principalTable: "Positions", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Deals_Types_TypeId", + column: x => x.TypeId, + principalTable: "Types", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Deals_DepartmentId", + table: "Deals", + column: "DepartmentId"); + + migrationBuilder.CreateIndex( + name: "IX_Deals_EmployeeId", + table: "Deals", + column: "EmployeeId"); + + migrationBuilder.CreateIndex( + name: "IX_Deals_PositionId", + table: "Deals", + column: "PositionId"); + + migrationBuilder.CreateIndex( + name: "IX_Deals_TypeId", + table: "Deals", + column: "TypeId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Deals"); + + migrationBuilder.DropTable( + name: "Departments"); + + migrationBuilder.DropTable( + name: "Employees"); + + migrationBuilder.DropTable( + name: "Positions"); + + migrationBuilder.DropTable( + name: "Types"); + } + } +} diff --git a/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/Migrations/20230502183034_SecMig.Designer.cs b/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/Migrations/20230502183034_SecMig.Designer.cs new file mode 100644 index 0000000..a973736 --- /dev/null +++ b/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/Migrations/20230502183034_SecMig.Designer.cs @@ -0,0 +1,183 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using PersonnelDepartmentDatabaseImplement; + +#nullable disable + +namespace PersonnelDepartmentDatabaseImplement.Migrations +{ + [DbContext(typeof(PersonnelDepartmentDatabase))] + [Migration("20230502183034_SecMig")] + partial class SecMig + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.5") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("PersonnelDepartmentDatabaseImplement.Models.Deal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DateFrom") + .HasColumnType("timestamp with time zone"); + + b.Property("DateTo") + .HasColumnType("timestamp with time zone"); + + b.Property("DepartmentId") + .HasColumnType("integer"); + + b.Property("EmployeeId") + .HasColumnType("integer"); + + b.Property("PositionId") + .HasColumnType("integer"); + + b.Property("TypeId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("DepartmentId"); + + b.HasIndex("EmployeeId"); + + b.HasIndex("PositionId"); + + b.HasIndex("TypeId"); + + b.ToTable("Deals"); + }); + + modelBuilder.Entity("PersonnelDepartmentDatabaseImplement.Models.Department", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Telephone") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.ToTable("Departments"); + }); + + modelBuilder.Entity("PersonnelDepartmentDatabaseImplement.Models.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Patronymic") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("PersonnelDepartmentDatabaseImplement.Models.Position", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Positions"); + }); + + modelBuilder.Entity("PersonnelDepartmentDatabaseImplement.Models.Type", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Types"); + }); + + modelBuilder.Entity("PersonnelDepartmentDatabaseImplement.Models.Deal", b => + { + b.HasOne("PersonnelDepartmentDatabaseImplement.Models.Department", "Department") + .WithMany() + .HasForeignKey("DepartmentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PersonnelDepartmentDatabaseImplement.Models.Employee", "Employee") + .WithMany() + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PersonnelDepartmentDatabaseImplement.Models.Position", "Position") + .WithMany() + .HasForeignKey("PositionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PersonnelDepartmentDatabaseImplement.Models.Type", "Type") + .WithMany() + .HasForeignKey("TypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Department"); + + b.Navigation("Employee"); + + b.Navigation("Position"); + + b.Navigation("Type"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/Migrations/20230502183034_SecMig.cs b/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/Migrations/20230502183034_SecMig.cs new file mode 100644 index 0000000..13622bf --- /dev/null +++ b/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/Migrations/20230502183034_SecMig.cs @@ -0,0 +1,34 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace PersonnelDepartmentDatabaseImplement.Migrations +{ + /// + public partial class SecMig : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Telephone", + table: "Departments", + type: "bigint", + nullable: false, + oldClrType: typeof(int), + oldType: "integer"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Telephone", + table: "Departments", + type: "integer", + nullable: false, + oldClrType: typeof(long), + oldType: "bigint"); + } + } +} diff --git a/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/Migrations/PersonnelDepartmentDatabaseModelSnapshot.cs b/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/Migrations/PersonnelDepartmentDatabaseModelSnapshot.cs new file mode 100644 index 0000000..878fe63 --- /dev/null +++ b/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/Migrations/PersonnelDepartmentDatabaseModelSnapshot.cs @@ -0,0 +1,180 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using PersonnelDepartmentDatabaseImplement; + +#nullable disable + +namespace PersonnelDepartmentDatabaseImplement.Migrations +{ + [DbContext(typeof(PersonnelDepartmentDatabase))] + partial class PersonnelDepartmentDatabaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.5") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("PersonnelDepartmentDatabaseImplement.Models.Deal", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DateFrom") + .HasColumnType("timestamp with time zone"); + + b.Property("DateTo") + .HasColumnType("timestamp with time zone"); + + b.Property("DepartmentId") + .HasColumnType("integer"); + + b.Property("EmployeeId") + .HasColumnType("integer"); + + b.Property("PositionId") + .HasColumnType("integer"); + + b.Property("TypeId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("DepartmentId"); + + b.HasIndex("EmployeeId"); + + b.HasIndex("PositionId"); + + b.HasIndex("TypeId"); + + b.ToTable("Deals"); + }); + + modelBuilder.Entity("PersonnelDepartmentDatabaseImplement.Models.Department", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Telephone") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.ToTable("Departments"); + }); + + modelBuilder.Entity("PersonnelDepartmentDatabaseImplement.Models.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Patronymic") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("PersonnelDepartmentDatabaseImplement.Models.Position", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Positions"); + }); + + modelBuilder.Entity("PersonnelDepartmentDatabaseImplement.Models.Type", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Types"); + }); + + modelBuilder.Entity("PersonnelDepartmentDatabaseImplement.Models.Deal", b => + { + b.HasOne("PersonnelDepartmentDatabaseImplement.Models.Department", "Department") + .WithMany() + .HasForeignKey("DepartmentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PersonnelDepartmentDatabaseImplement.Models.Employee", "Employee") + .WithMany() + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PersonnelDepartmentDatabaseImplement.Models.Position", "Position") + .WithMany() + .HasForeignKey("PositionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PersonnelDepartmentDatabaseImplement.Models.Type", "Type") + .WithMany() + .HasForeignKey("TypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Department"); + + b.Navigation("Employee"); + + b.Navigation("Position"); + + b.Navigation("Type"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/Models/Deal.cs b/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/Models/Deal.cs index 75a3f74..463f15e 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/Models/Deal.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/Models/Deal.cs @@ -14,7 +14,7 @@ namespace PersonnelDepartmentDatabaseImplement.Models { [Required] public DateTime DateFrom { get; set; } - public DateTime? DateTo { get; set; } + public DateTime DateTo { get; set; } [Required] public int PositionId { get; set; } [Required] @@ -38,8 +38,8 @@ namespace PersonnelDepartmentDatabaseImplement.Models return new Deal { Id = model.Id, - DateFrom = model.DateFrom, - DateTo = model.DateTo, + DateFrom = DateTime.SpecifyKind(model.DateFrom, DateTimeKind.Utc), + DateTo = DateTime.SpecifyKind(model.DateTo, DateTimeKind.Utc), PositionId = model.PositionId, EmployeeId = model.EmployeeId, DepartmentId = model.DepartmentId, @@ -53,8 +53,8 @@ namespace PersonnelDepartmentDatabaseImplement.Models { return; } - DateFrom = model.DateFrom; - DateTo = model.DateTo; + DateFrom = DateTime.SpecifyKind(model.DateFrom, DateTimeKind.Utc); + DateTo = DateTime.SpecifyKind(model.DateTo, DateTimeKind.Utc); } public DealViewModel GetViewModel => new() diff --git a/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/Models/Department.cs b/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/Models/Department.cs index 03b6968..02a8886 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/Models/Department.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/Models/Department.cs @@ -15,7 +15,7 @@ namespace PersonnelDepartmentDatabaseImplement.Models [Required] public string Name { get; set; } = string.Empty; [Required] - public int Telephone { get; set; } + public long Telephone { get; set; } public int Id { get; set; } public static Department? Create(DepartmentBindingModel model) diff --git a/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/PersonnelDepartmentDatabaseImplement.csproj b/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/PersonnelDepartmentDatabaseImplement.csproj index 552e6ca..d957de0 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/PersonnelDepartmentDatabaseImplement.csproj +++ b/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/PersonnelDepartmentDatabaseImplement.csproj @@ -8,6 +8,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormDeal.Designer.cs b/PersonnelDepartmentView/PersonnelDepartmentView/FormDeal.Designer.cs index d28978a..494045b 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormDeal.Designer.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormDeal.Designer.cs @@ -28,12 +28,194 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormDeal"; + buttonCancel = new Button(); + buttonSave = new Button(); + label1 = new Label(); + label2 = new Label(); + dateTimePickerFrom = new DateTimePicker(); + dateTimePickerTo = new DateTimePicker(); + label3 = new Label(); + comboBoxType = new ComboBox(); + label4 = new Label(); + comboBoxEmployee = new ComboBox(); + label5 = new Label(); + comboBoxDepartment = new ComboBox(); + label6 = new Label(); + comboBoxPosition = new ComboBox(); + label7 = new Label(); + SuspendLayout(); + // + // buttonCancel + // + buttonCancel.Location = new Point(230, 186); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 19; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(149, 186); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 18; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(15, 20); + label1.Name = "label1"; + label1.Size = new Size(44, 15); + label1.TabIndex = 20; + label1.Text = "Дата с:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(15, 47); + label2.Name = "label2"; + label2.Size = new Size(52, 15); + label2.TabIndex = 21; + label2.Text = "Дата по:"; + // + // dateTimePickerFrom + // + dateTimePickerFrom.Location = new Point(105, 12); + dateTimePickerFrom.Name = "dateTimePickerFrom"; + dateTimePickerFrom.Size = new Size(200, 23); + dateTimePickerFrom.TabIndex = 22; + // + // dateTimePickerTo + // + dateTimePickerTo.Location = new Point(105, 41); + dateTimePickerTo.Name = "dateTimePickerTo"; + dateTimePickerTo.Size = new Size(200, 23); + dateTimePickerTo.TabIndex = 23; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(15, 73); + label3.Name = "label3"; + label3.Size = new Size(84, 15); + label3.TabIndex = 24; + label3.Text = "Тип договора:"; + // + // comboBoxType + // + comboBoxType.FormattingEnabled = true; + comboBoxType.Location = new Point(105, 70); + comboBoxType.Name = "comboBoxType"; + comboBoxType.Size = new Size(200, 23); + comboBoxType.TabIndex = 25; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(114, 144); + label4.Name = "label4"; + label4.Size = new Size(0, 15); + label4.TabIndex = 26; + // + // comboBoxEmployee + // + comboBoxEmployee.FormattingEnabled = true; + comboBoxEmployee.Location = new Point(105, 99); + comboBoxEmployee.Name = "comboBoxEmployee"; + comboBoxEmployee.Size = new Size(200, 23); + comboBoxEmployee.TabIndex = 28; + // + // label5 + // + label5.AutoSize = true; + label5.Location = new Point(15, 102); + label5.Name = "label5"; + label5.Size = new Size(69, 15); + label5.TabIndex = 27; + label5.Text = "Сотрудник:"; + // + // comboBoxDepartment + // + comboBoxDepartment.FormattingEnabled = true; + comboBoxDepartment.Location = new Point(105, 128); + comboBoxDepartment.Name = "comboBoxDepartment"; + comboBoxDepartment.Size = new Size(200, 23); + comboBoxDepartment.TabIndex = 30; + // + // label6 + // + label6.AutoSize = true; + label6.Location = new Point(15, 131); + label6.Name = "label6"; + label6.Size = new Size(43, 15); + label6.TabIndex = 29; + label6.Text = "Отдел:"; + // + // comboBoxPosition + // + comboBoxPosition.FormattingEnabled = true; + comboBoxPosition.Location = new Point(105, 157); + comboBoxPosition.Name = "comboBoxPosition"; + comboBoxPosition.Size = new Size(200, 23); + comboBoxPosition.TabIndex = 32; + // + // label7 + // + label7.AutoSize = true; + label7.Location = new Point(15, 160); + label7.Name = "label7"; + label7.Size = new Size(72, 15); + label7.TabIndex = 31; + label7.Text = "Должность:"; + // + // FormDeal + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(324, 223); + Controls.Add(comboBoxPosition); + Controls.Add(label7); + Controls.Add(comboBoxDepartment); + Controls.Add(label6); + Controls.Add(comboBoxEmployee); + Controls.Add(label5); + Controls.Add(label4); + Controls.Add(comboBoxType); + Controls.Add(label3); + Controls.Add(dateTimePickerTo); + Controls.Add(dateTimePickerFrom); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Name = "FormDeal"; + Text = "Договор"; + Load += FormDeal_Load; + ResumeLayout(false); + PerformLayout(); } #endregion + + private Button buttonCancel; + private Button buttonSave; + private Label label1; + private Label label2; + private DateTimePicker dateTimePickerFrom; + private DateTimePicker dateTimePickerTo; + private Label label3; + private ComboBox comboBoxType; + private Label label4; + private ComboBox comboBoxEmployee; + private Label label5; + private ComboBox comboBoxDepartment; + private Label label6; + private ComboBox comboBoxPosition; + private Label label7; } } \ No newline at end of file diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormDeal.cs b/PersonnelDepartmentView/PersonnelDepartmentView/FormDeal.cs index f6fe0f0..bfc5166 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormDeal.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormDeal.cs @@ -1,4 +1,8 @@ -using System; +using Microsoft.EntityFrameworkCore.Metadata.Internal; +using PersonnelDepartmentContracts.BindingModels; +using PersonnelDepartmentContracts.BusinessLogicContracts; +using PersonnelDepartmentContracts.SearchModels; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,9 +16,124 @@ namespace PersonnelDepartmentView { public partial class FormDeal : Form { - public FormDeal() + private readonly IDealLogic _dealLogic; + private readonly IDepartmentLogic _departmentLogic; + private readonly IEmployeeLogic _employeeLogic; + private readonly IPositionLogic _positionLogic; + private readonly ITypeLogic _typeLogic; + private int? _id; + public int Id { set { _id = value; } } + + public FormDeal(IDealLogic dealLogic, IDepartmentLogic departmentLogic, IEmployeeLogic employeeLogic, IPositionLogic positionLogic, ITypeLogic typeLogic) { InitializeComponent(); + _dealLogic = dealLogic; + _departmentLogic = departmentLogic; + _employeeLogic = employeeLogic; + _positionLogic = positionLogic; + _typeLogic = typeLogic; + } + + private void FormDeal_Load(object sender, EventArgs e) + { + comboBoxDepartment.DisplayMember = "Name"; + comboBoxDepartment.ValueMember = "Id"; + comboBoxDepartment.DataSource = _departmentLogic.ReadList(null); + comboBoxEmployee.DisplayMember = "LastName"; + comboBoxEmployee.ValueMember = "Id"; + comboBoxEmployee.DataSource = _employeeLogic.ReadList(null); + comboBoxPosition.DisplayMember = "Name"; + comboBoxPosition.ValueMember = "Id"; + comboBoxPosition.DataSource = _positionLogic.ReadList(null); + comboBoxType.DisplayMember = "Name"; + comboBoxType.ValueMember = "Id"; + comboBoxType.DataSource = _typeLogic.ReadList(null); + if (_id.HasValue) + { + try + { + var view = _dealLogic.ReadElement(new DealSearchModel + { + Id = _id.Value + }); + if (view != null) + { + dateTimePickerFrom.Value = view.DateFrom; + dateTimePickerTo.Value = view.DateTo; + comboBoxDepartment.SelectedItem = view.DepartmentId; + comboBoxEmployee.SelectedItem = view.EmployeeId; + comboBoxPosition.SelectedItem = view.PositionId; + comboBoxType.SelectedItem = view.TypeId; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + else + { + comboBoxDepartment.SelectedItem = null; + comboBoxEmployee.SelectedItem = null; + comboBoxPosition.SelectedItem = null; + comboBoxType.SelectedItem = null; + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxDepartment.SelectedItem == null) + { + MessageBox.Show("Выберите отдел", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxEmployee.SelectedItem == null) + { + MessageBox.Show("Выберите сотрудника", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxPosition.SelectedItem == null) + { + MessageBox.Show("Выберите должность", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxType.SelectedItem == null) + { + MessageBox.Show("Выберите тип договора", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + var model = new DealBindingModel + { + Id = _id ?? 0, + DateFrom = DateTime.SpecifyKind(dateTimePickerFrom.Value, DateTimeKind.Utc), + DateTo = DateTime.SpecifyKind(dateTimePickerTo.Value, DateTimeKind.Utc), + DepartmentId = Convert.ToInt32(comboBoxDepartment.SelectedValue), + EmployeeId = Convert.ToInt32(comboBoxEmployee.SelectedValue), + PositionId = Convert.ToInt32(comboBoxPosition.SelectedValue), + TypeId = Convert.ToInt32(comboBoxType.SelectedValue) + }; + var operationResult = _id.HasValue ? _dealLogic.Update(model) : _dealLogic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); } } } diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormDeal.resx b/PersonnelDepartmentView/PersonnelDepartmentView/FormDeal.resx index 1af7de1..f298a7b 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormDeal.resx +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormDeal.resx @@ -1,64 +1,4 @@ - - - + diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormDeals.Designer.cs b/PersonnelDepartmentView/PersonnelDepartmentView/FormDeals.Designer.cs index 70c05fe..aa31200 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormDeals.Designer.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormDeals.Designer.cs @@ -28,12 +28,139 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonChange = new Button(); + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonDepartment = new Button(); + buttonEmployee = new Button(); + buttonPosition = new Button(); + buttonType = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 41); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(888, 368); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(12, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(75, 23); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Создать"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonChange + // + buttonChange.Location = new Point(93, 12); + buttonChange.Name = "buttonChange"; + buttonChange.Size = new Size(75, 23); + buttonChange.TabIndex = 2; + buttonChange.Text = "Изменить"; + buttonChange.UseVisualStyleBackColor = true; + buttonChange.Click += ButtonChange_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(174, 12); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(75, 23); + buttonDelete.TabIndex = 3; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(255, 12); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(75, 23); + buttonUpdate.TabIndex = 4; + buttonUpdate.Text = "Обновить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpdate_Click; + // + // buttonDepartment + // + buttonDepartment.Location = new Point(336, 12); + buttonDepartment.Name = "buttonDepartment"; + buttonDepartment.Size = new Size(128, 23); + buttonDepartment.TabIndex = 5; + buttonDepartment.Text = "Таблица с отделами"; + buttonDepartment.UseVisualStyleBackColor = true; + buttonDepartment.Click += ButtonDepartment_Click; + // + // buttonEmployee + // + buttonEmployee.Location = new Point(470, 12); + buttonEmployee.Name = "buttonEmployee"; + buttonEmployee.Size = new Size(152, 23); + buttonEmployee.TabIndex = 6; + buttonEmployee.Text = "Таблица с сотрудниками"; + buttonEmployee.UseVisualStyleBackColor = true; + buttonEmployee.Click += ButtonEmployee_Click; + // + // buttonPosition + // + buttonPosition.Location = new Point(628, 12); + buttonPosition.Name = "buttonPosition"; + buttonPosition.Size = new Size(149, 23); + buttonPosition.TabIndex = 7; + buttonPosition.Text = "Таблица с должностями"; + buttonPosition.UseVisualStyleBackColor = true; + buttonPosition.Click += ButtonPosition_Click; + // + // buttonType + // + buttonType.Location = new Point(783, 12); + buttonType.Name = "buttonType"; + buttonType.Size = new Size(117, 23); + buttonType.TabIndex = 8; + buttonType.Text = "Таблица с типами"; + buttonType.UseVisualStyleBackColor = true; + buttonType.Click += ButtonType_Click; + // + // FormDeals + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(914, 422); + Controls.Add(buttonType); + Controls.Add(buttonPosition); + Controls.Add(buttonEmployee); + Controls.Add(buttonDepartment); + Controls.Add(buttonUpdate); + Controls.Add(buttonDelete); + Controls.Add(buttonChange); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormDeals"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Таблица Договоров"; + Load += FormDeals_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); } #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonChange; + private Button buttonDelete; + private Button buttonUpdate; + private Button buttonDepartment; + private Button buttonEmployee; + private Button buttonPosition; + private Button buttonType; } } \ No newline at end of file diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormDeals.cs b/PersonnelDepartmentView/PersonnelDepartmentView/FormDeals.cs index 42acbba..cdc010f 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormDeals.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormDeals.cs @@ -1,10 +1,143 @@ +using PersonnelDepartmentContracts.BindingModels; +using PersonnelDepartmentContracts.BusinessLogicContracts; + namespace PersonnelDepartmentView { - public partial class Form1 : Form + public partial class FormDeals : Form { - public Form1() + private readonly IDealLogic _dealLogic; + + public FormDeals(IDealLogic dealLogic) { InitializeComponent(); + _dealLogic = dealLogic; + } + + private void LoadData() + { + try + { + var list = _dealLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["EmployeeId"].Visible = false; + dataGridView.Columns["PositionId"].Visible = false; + dataGridView.Columns["DepartmentId"].Visible = false; + dataGridView.Columns["TypeId"].Visible = false; + dataGridView.Columns["DateFrom"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["DateTo"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["TypeName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["EmployeeName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["DepartmentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["PositionName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void FormDeals_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void ButtonDepartment_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormDepartments)); + if (service is FormDepartments form) + { + form.ShowDialog(); + } + } + + private void ButtonEmployee_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormEmployees)); + if (service is FormEmployees form) + { + form.ShowDialog(); + } + } + + private void ButtonPosition_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPositions)); + if (service is FormPositions form) + { + form.ShowDialog(); + } + } + + private void ButtonType_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTypes)); + if (service is FormTypes form) + { + form.ShowDialog(); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormDeal)); + if (service is FormDeal form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonChange_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormDeal)); + if (service is FormDeal form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show(" ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + try + { + if (!_dealLogic.Delete(new DealBindingModel + { + Id = id + })) + { + throw new Exception(" ."); + } + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpdate_Click(object sender, EventArgs e) + { + LoadData(); } } } \ No newline at end of file diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormDeals.resx b/PersonnelDepartmentView/PersonnelDepartmentView/FormDeals.resx index 1af7de1..f298a7b 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormDeals.resx +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormDeals.resx @@ -1,64 +1,4 @@ - - - + diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormDepartment.Designer.cs b/PersonnelDepartmentView/PersonnelDepartmentView/FormDepartment.Designer.cs index 234f94a..c4f8fee 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormDepartment.Designer.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormDepartment.Designer.cs @@ -28,12 +28,91 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormDepartment"; + label2 = new Label(); + textBoxTelephone = new TextBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + label1 = new Label(); + textBoxName = new TextBox(); + SuspendLayout(); + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(20, 44); + label2.Name = "label2"; + label2.Size = new Size(126, 15); + label2.TabIndex = 19; + label2.Text = "Контактный телефон:"; + // + // textBoxTelephone + // + textBoxTelephone.Location = new Point(153, 41); + textBoxTelephone.Name = "textBoxTelephone"; + textBoxTelephone.Size = new Size(202, 23); + textBoxTelephone.TabIndex = 18; + // + // buttonCancel + // + buttonCancel.Location = new Point(280, 70); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 17; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(199, 70); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 16; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(20, 15); + label1.Name = "label1"; + label1.Size = new Size(102, 15); + label1.TabIndex = 15; + label1.Text = "Название отдела:"; + // + // textBoxName + // + textBoxName.Location = new Point(153, 12); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(202, 23); + textBoxName.TabIndex = 14; + // + // FormDepartment + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(375, 108); + Controls.Add(label2); + Controls.Add(textBoxTelephone); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(label1); + Controls.Add(textBoxName); + Name = "FormDepartment"; + Text = "Отдел"; + Load += FormDepartment_Load; + ResumeLayout(false); + PerformLayout(); } #endregion + + private Label label2; + private TextBox textBoxTelephone; + private Button buttonCancel; + private Button buttonSave; + private Label label1; + private TextBox textBoxName; } } \ No newline at end of file diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormDepartment.cs b/PersonnelDepartmentView/PersonnelDepartmentView/FormDepartment.cs index 88075e7..0091653 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormDepartment.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormDepartment.cs @@ -1,4 +1,8 @@ -using System; +using PersonnelDepartmentBusinessLogic.BusinessLogics; +using PersonnelDepartmentContracts.BindingModels; +using PersonnelDepartmentContracts.BusinessLogicContracts; +using PersonnelDepartmentContracts.SearchModels; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,9 +16,78 @@ namespace PersonnelDepartmentView { public partial class FormDepartment : Form { - public FormDepartment() + private readonly IDepartmentLogic _departmentLogic; + private int? _id; + public int Id { set { _id = value; } } + public FormDepartment(IDepartmentLogic departmentLogic) { InitializeComponent(); + _departmentLogic = departmentLogic; + } + + private void FormDepartment_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + var view = _departmentLogic.ReadElement(new DepartmentSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.Name; + textBoxTelephone.Text = view.Telephone.ToString(); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Введите название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxTelephone.Text)) + { + MessageBox.Show("Введите контактный номер", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + var model = new DepartmentBindingModel + { + Id = _id ?? 0, + Name = textBoxName.Text, + Telephone = long.Parse(textBoxTelephone.Text) + }; + var operationResult = _id.HasValue ? _departmentLogic.Update(model) : _departmentLogic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); } } } diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormDepartment.resx b/PersonnelDepartmentView/PersonnelDepartmentView/FormDepartment.resx index 1af7de1..f298a7b 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormDepartment.resx +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormDepartment.resx @@ -1,64 +1,4 @@ - - - + diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormDepartments.Designer.cs b/PersonnelDepartmentView/PersonnelDepartmentView/FormDepartments.Designer.cs index 9598e75..f7e462c 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormDepartments.Designer.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormDepartments.Designer.cs @@ -28,12 +28,86 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormDepartments"; + buttonUpdate = new Button(); + buttonDelete = new Button(); + buttonChange = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonUpdate + // + buttonUpdate.Location = new Point(255, 9); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(75, 23); + buttonUpdate.TabIndex = 9; + buttonUpdate.Text = "Обновить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpdate_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(174, 9); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(75, 23); + buttonDelete.TabIndex = 8; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; + // + // buttonChange + // + buttonChange.Location = new Point(93, 9); + buttonChange.Name = "buttonChange"; + buttonChange.Size = new Size(75, 23); + buttonChange.TabIndex = 7; + buttonChange.Text = "Изменить"; + buttonChange.UseVisualStyleBackColor = true; + buttonChange.Click += ButtonChange_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(12, 9); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(75, 23); + buttonAdd.TabIndex = 6; + buttonAdd.Text = "Создать"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 38); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(564, 368); + dataGridView.TabIndex = 5; + // + // FormDepartments + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(590, 418); + Controls.Add(buttonUpdate); + Controls.Add(buttonDelete); + Controls.Add(buttonChange); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormDepartments"; + Text = "Таблица Отделов"; + Load += FormDepartments_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); } #endregion + + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonChange; + private Button buttonAdd; + private DataGridView dataGridView; } } \ No newline at end of file diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormDepartments.cs b/PersonnelDepartmentView/PersonnelDepartmentView/FormDepartments.cs index 67774a8..e0b64ce 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormDepartments.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormDepartments.cs @@ -1,4 +1,7 @@ -using System; +using PersonnelDepartmentBusinessLogic.BusinessLogics; +using PersonnelDepartmentContracts.BindingModels; +using PersonnelDepartmentContracts.BusinessLogicContracts; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,9 +15,94 @@ namespace PersonnelDepartmentView { public partial class FormDepartments : Form { - public FormDepartments() + private readonly IDepartmentLogic _departmentLogic; + public FormDepartments(IDepartmentLogic departmentLogic) { InitializeComponent(); + _departmentLogic = departmentLogic; + } + + private void LoadData() + { + try + { + var list = _departmentLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Telephone"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка загрузки", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormDepartment)); + if (service is FormDepartment form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonChange_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormDepartment)); + if (service is FormDepartment form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + try + { + if (!_departmentLogic.Delete(new DepartmentBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении."); + } + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void FormDepartments_Load(object sender, EventArgs e) + { + LoadData(); } } } diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormDepartments.resx b/PersonnelDepartmentView/PersonnelDepartmentView/FormDepartments.resx index 1af7de1..f298a7b 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormDepartments.resx +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormDepartments.resx @@ -1,64 +1,4 @@ - - - + diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormEmployee.Designer.cs b/PersonnelDepartmentView/PersonnelDepartmentView/FormEmployee.Designer.cs index 7cc4e88..6ed411f 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormEmployee.Designer.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormEmployee.Designer.cs @@ -28,12 +28,113 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormEmployee"; + buttonCancel = new Button(); + buttonSave = new Button(); + label1 = new Label(); + textBoxFirstName = new TextBox(); + label2 = new Label(); + textBoxLastName = new TextBox(); + label3 = new Label(); + textBoxPatronymic = new TextBox(); + SuspendLayout(); + // + // buttonCancel + // + buttonCancel.Location = new Point(276, 99); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 11; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(195, 99); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 10; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(16, 15); + label1.Name = "label1"; + label1.Size = new Size(100, 15); + label1.TabIndex = 9; + label1.Text = "Имя сотрудника:"; + // + // textBoxFirstName + // + textBoxFirstName.Location = new Point(149, 12); + textBoxFirstName.Name = "textBoxFirstName"; + textBoxFirstName.Size = new Size(202, 23); + textBoxFirstName.TabIndex = 8; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(16, 44); + label2.Name = "label2"; + label2.Size = new Size(127, 15); + label2.TabIndex = 13; + label2.Text = "Фамилия сотрудника:"; + // + // textBoxLastName + // + textBoxLastName.Location = new Point(149, 41); + textBoxLastName.Name = "textBoxLastName"; + textBoxLastName.Size = new Size(202, 23); + textBoxLastName.TabIndex = 12; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(16, 73); + label3.Name = "label3"; + label3.Size = new Size(127, 15); + label3.TabIndex = 15; + label3.Text = "Отчество сотрудника:"; + // + // textBoxPatronymic + // + textBoxPatronymic.Location = new Point(149, 70); + textBoxPatronymic.Name = "textBoxPatronymic"; + textBoxPatronymic.Size = new Size(202, 23); + textBoxPatronymic.TabIndex = 14; + // + // FormEmployee + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(369, 136); + Controls.Add(label3); + Controls.Add(textBoxPatronymic); + Controls.Add(label2); + Controls.Add(textBoxLastName); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(label1); + Controls.Add(textBoxFirstName); + Name = "FormEmployee"; + Text = "Сотрудник"; + Load += FormEmployee_Load; + ResumeLayout(false); + PerformLayout(); } #endregion + + private Button buttonCancel; + private Button buttonSave; + private Label label1; + private TextBox textBoxFirstName; + private Label label2; + private TextBox textBoxLastName; + private Label label3; + private TextBox textBoxPatronymic; } } \ No newline at end of file diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormEmployee.cs b/PersonnelDepartmentView/PersonnelDepartmentView/FormEmployee.cs index 2cc18f7..90a2c52 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormEmployee.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormEmployee.cs @@ -1,4 +1,8 @@ -using System; +using PersonnelDepartmentBusinessLogic.BusinessLogics; +using PersonnelDepartmentContracts.BindingModels; +using PersonnelDepartmentContracts.BusinessLogicContracts; +using PersonnelDepartmentContracts.SearchModels; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,9 +16,80 @@ namespace PersonnelDepartmentView { public partial class FormEmployee : Form { - public FormEmployee() + private readonly IEmployeeLogic _employeeLogic; + private int? _id; + public int Id { set { _id = value; } } + public FormEmployee(IEmployeeLogic employeeLogic) { InitializeComponent(); + _employeeLogic = employeeLogic; + } + + private void FormEmployee_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + var view = _employeeLogic.ReadElement(new EmployeeSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxFirstName.Text = view.FirstName; + textBoxLastName.Text = view.LastName; + textBoxPatronymic.Text = view.Patronymic; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxFirstName.Text)) + { + MessageBox.Show("Введите название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxLastName.Text)) + { + MessageBox.Show("Введите контактный номер", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + var model = new EmployeeBindingModel + { + Id = _id ?? 0, + FirstName = textBoxFirstName.Text, + LastName = textBoxLastName.Text, + Patronymic = textBoxPatronymic.Text + }; + var operationResult = _id.HasValue ? _employeeLogic.Update(model) : _employeeLogic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); } } } diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormEmployee.resx b/PersonnelDepartmentView/PersonnelDepartmentView/FormEmployee.resx index 1af7de1..f298a7b 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormEmployee.resx +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormEmployee.resx @@ -1,64 +1,4 @@ - - - + diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormEmployees.Designer.cs b/PersonnelDepartmentView/PersonnelDepartmentView/FormEmployees.Designer.cs index cae9dcd..6d4d353 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormEmployees.Designer.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormEmployees.Designer.cs @@ -28,12 +28,86 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormEmployees"; + buttonUpdate = new Button(); + buttonDelete = new Button(); + buttonChange = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonUpdate + // + buttonUpdate.Location = new Point(255, 9); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(75, 23); + buttonUpdate.TabIndex = 9; + buttonUpdate.Text = "Обновить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpdate_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(174, 9); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(75, 23); + buttonDelete.TabIndex = 8; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; + // + // buttonChange + // + buttonChange.Location = new Point(93, 9); + buttonChange.Name = "buttonChange"; + buttonChange.Size = new Size(75, 23); + buttonChange.TabIndex = 7; + buttonChange.Text = "Изменить"; + buttonChange.UseVisualStyleBackColor = true; + buttonChange.Click += ButtonChange_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(12, 9); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(75, 23); + buttonAdd.TabIndex = 6; + buttonAdd.Text = "Создать"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 38); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(564, 368); + dataGridView.TabIndex = 5; + // + // FormEmployees + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(589, 418); + Controls.Add(buttonUpdate); + Controls.Add(buttonDelete); + Controls.Add(buttonChange); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormEmployees"; + Text = "Таблица Сотрудников"; + Load += FormEmployees_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); } #endregion + + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonChange; + private Button buttonAdd; + private DataGridView dataGridView; } } \ No newline at end of file diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormEmployees.cs b/PersonnelDepartmentView/PersonnelDepartmentView/FormEmployees.cs index 4887429..12a6a3a 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormEmployees.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormEmployees.cs @@ -1,4 +1,7 @@ -using System; +using PersonnelDepartmentBusinessLogic.BusinessLogics; +using PersonnelDepartmentContracts.BindingModels; +using PersonnelDepartmentContracts.BusinessLogicContracts; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,9 +15,95 @@ namespace PersonnelDepartmentView { public partial class FormEmployees : Form { - public FormEmployees() + private readonly IEmployeeLogic _employeeLogic; + public FormEmployees(IEmployeeLogic employeeLogic) { InitializeComponent(); + _employeeLogic = employeeLogic; + } + + private void LoadData() + { + try + { + var list = _employeeLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["FirstName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["LastName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Patronymic"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка загрузки", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormEmployee)); + if (service is FormEmployee form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonChange_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormEmployee)); + if (service is FormEmployee form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + try + { + if (!_employeeLogic.Delete(new EmployeeBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении."); + } + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void FormEmployees_Load(object sender, EventArgs e) + { + LoadData(); } } } diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormEmployees.resx b/PersonnelDepartmentView/PersonnelDepartmentView/FormEmployees.resx index 1af7de1..f298a7b 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormEmployees.resx +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormEmployees.resx @@ -1,64 +1,4 @@ - - - + diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormPosition.Designer.cs b/PersonnelDepartmentView/PersonnelDepartmentView/FormPosition.Designer.cs index 27102b0..2cdb1fa 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormPosition.Designer.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormPosition.Designer.cs @@ -28,12 +28,69 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormPosition"; + buttonCancel = new Button(); + buttonSave = new Button(); + label1 = new Label(); + textBoxName = new TextBox(); + SuspendLayout(); + // + // buttonCancel + // + buttonCancel.Location = new Point(112, 56); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(31, 56); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(15, 15); + label1.Name = "label1"; + label1.Size = new Size(62, 15); + label1.TabIndex = 5; + label1.Text = "Название:"; + // + // textBoxName + // + textBoxName.Location = new Point(80, 12); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(107, 23); + textBoxName.TabIndex = 4; + // + // FormPosition + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(205, 92); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(label1); + Controls.Add(textBoxName); + Name = "FormPosition"; + Text = "Должность"; + Load += FormPosition_Load; + ResumeLayout(false); + PerformLayout(); } #endregion + + private Button buttonCancel; + private Button buttonSave; + private Label label1; + private TextBox textBoxName; } } \ No newline at end of file diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormPosition.cs b/PersonnelDepartmentView/PersonnelDepartmentView/FormPosition.cs index ba89fbf..6396230 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormPosition.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormPosition.cs @@ -1,4 +1,8 @@ -using System; +using PersonnelDepartmentBusinessLogic.BusinessLogics; +using PersonnelDepartmentContracts.BindingModels; +using PersonnelDepartmentContracts.BusinessLogicContracts; +using PersonnelDepartmentContracts.SearchModels; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,9 +16,71 @@ namespace PersonnelDepartmentView { public partial class FormPosition : Form { - public FormPosition() + private readonly IPositionLogic _positionLogic; + private int? _id; + public int Id { set { _id = value; } } + public FormPosition(IPositionLogic positionLogic) { InitializeComponent(); + _positionLogic = positionLogic; + } + + private void FormPosition_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + var view = _positionLogic.ReadElement(new PositionSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.Name; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Введите название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + var model = new PositionBindingModel + { + Id = _id ?? 0, + Name = textBoxName.Text + }; + var operationResult = _id.HasValue ? _positionLogic.Update(model) : _positionLogic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); } } } diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormPosition.resx b/PersonnelDepartmentView/PersonnelDepartmentView/FormPosition.resx index 1af7de1..f298a7b 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormPosition.resx +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormPosition.resx @@ -1,64 +1,4 @@ - - - + diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormPositions.Designer.cs b/PersonnelDepartmentView/PersonnelDepartmentView/FormPositions.Designer.cs index b7f8967..4591bcf 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormPositions.Designer.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormPositions.Designer.cs @@ -28,12 +28,86 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormPositions"; + buttonUpdate = new Button(); + buttonDelete = new Button(); + buttonChange = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonUpdate + // + buttonUpdate.Location = new Point(255, 9); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(75, 23); + buttonUpdate.TabIndex = 9; + buttonUpdate.Text = "Обновить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpdate_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(174, 9); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(75, 23); + buttonDelete.TabIndex = 8; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; + // + // buttonChange + // + buttonChange.Location = new Point(93, 9); + buttonChange.Name = "buttonChange"; + buttonChange.Size = new Size(75, 23); + buttonChange.TabIndex = 7; + buttonChange.Text = "Изменить"; + buttonChange.UseVisualStyleBackColor = true; + buttonChange.Click += ButtonChange_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(12, 9); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(75, 23); + buttonAdd.TabIndex = 6; + buttonAdd.Text = "Создать"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 38); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(564, 368); + dataGridView.TabIndex = 5; + // + // FormPositions + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(590, 418); + Controls.Add(buttonUpdate); + Controls.Add(buttonDelete); + Controls.Add(buttonChange); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormPositions"; + Text = "Таблица Должностей"; + Load += FormPositions_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); } #endregion + + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonChange; + private Button buttonAdd; + private DataGridView dataGridView; } } \ No newline at end of file diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormPositions.cs b/PersonnelDepartmentView/PersonnelDepartmentView/FormPositions.cs index d0a37c5..4fbbb05 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormPositions.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormPositions.cs @@ -1,4 +1,8 @@ -using System; +using PersonnelDepartmentBusinessLogic.BusinessLogics; +using PersonnelDepartmentContracts.BindingModels; +using PersonnelDepartmentContracts.BusinessLogicContracts; +using PersonnelDepartmentContracts.SearchModels; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,9 +16,93 @@ namespace PersonnelDepartmentView { public partial class FormPositions : Form { - public FormPositions() + private readonly IPositionLogic _positionLogic; + public FormPositions(IPositionLogic positionLogic) { InitializeComponent(); + _positionLogic = positionLogic; + } + + private void LoadData() + { + try + { + var list = _positionLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка загрузки", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPosition)); + if (service is FormPosition form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonChange_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPosition)); + if (service is FormPosition form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + try + { + if (!_positionLogic.Delete(new PositionBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении."); + } + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void FormPositions_Load(object sender, EventArgs e) + { + LoadData(); } } } diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormPositions.resx b/PersonnelDepartmentView/PersonnelDepartmentView/FormPositions.resx index 1af7de1..f298a7b 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormPositions.resx +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormPositions.resx @@ -1,64 +1,4 @@ - - - + diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormType.Designer.cs b/PersonnelDepartmentView/PersonnelDepartmentView/FormType.Designer.cs index 89fc785..7dcd38b 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormType.Designer.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormType.Designer.cs @@ -28,12 +28,69 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormType"; + textBoxName = new TextBox(); + label1 = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // textBoxName + // + textBoxName.Location = new Point(78, 12); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(107, 23); + textBoxName.TabIndex = 0; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(13, 15); + label1.Name = "label1"; + label1.Size = new Size(62, 15); + label1.TabIndex = 1; + label1.Text = "Название:"; + // + // buttonSave + // + buttonSave.Location = new Point(29, 56); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 2; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(110, 56); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 3; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormType + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(204, 91); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(label1); + Controls.Add(textBoxName); + Name = "FormType"; + Text = "Тип договора"; + Load += FormType_Load; + ResumeLayout(false); + PerformLayout(); } #endregion + + private TextBox textBoxName; + private Label label1; + private Button buttonSave; + private Button buttonCancel; } } \ No newline at end of file diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormType.cs b/PersonnelDepartmentView/PersonnelDepartmentView/FormType.cs index 172d38c..57e820a 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormType.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormType.cs @@ -1,4 +1,8 @@ -using System; +using PersonnelDepartmentBusinessLogic.BusinessLogics; +using PersonnelDepartmentContracts.BindingModels; +using PersonnelDepartmentContracts.BusinessLogicContracts; +using PersonnelDepartmentContracts.SearchModels; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,9 +16,71 @@ namespace PersonnelDepartmentView { public partial class FormType : Form { - public FormType() + private readonly ITypeLogic _typeLogic; + private int? _id; + public int Id { set { _id = value; } } + public FormType(ITypeLogic typeLogic) { InitializeComponent(); + _typeLogic = typeLogic; + } + + private void FormType_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + var view = _typeLogic.ReadElement(new TypeSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.Name; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Введите название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + var model = new TypeBindingModel + { + Id = _id ?? 0, + Name = textBoxName.Text + }; + var operationResult = _id.HasValue ? _typeLogic.Update(model) : _typeLogic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); } } } diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormType.resx b/PersonnelDepartmentView/PersonnelDepartmentView/FormType.resx index 1af7de1..f298a7b 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormType.resx +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormType.resx @@ -1,64 +1,4 @@ - - - + diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormTypes.Designer.cs b/PersonnelDepartmentView/PersonnelDepartmentView/FormTypes.Designer.cs index a8d865a..7c56856 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormTypes.Designer.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormTypes.Designer.cs @@ -28,12 +28,86 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormTypes"; + buttonUpdate = new Button(); + buttonDelete = new Button(); + buttonChange = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonUpdate + // + buttonUpdate.Location = new Point(255, 9); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(75, 23); + buttonUpdate.TabIndex = 9; + buttonUpdate.Text = "Обновить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpdate_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(174, 9); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(75, 23); + buttonDelete.TabIndex = 8; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; + // + // buttonChange + // + buttonChange.Location = new Point(93, 9); + buttonChange.Name = "buttonChange"; + buttonChange.Size = new Size(75, 23); + buttonChange.TabIndex = 7; + buttonChange.Text = "Изменить"; + buttonChange.UseVisualStyleBackColor = true; + buttonChange.Click += ButtonChange_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(12, 9); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(75, 23); + buttonAdd.TabIndex = 6; + buttonAdd.Text = "Создать"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 38); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(564, 368); + dataGridView.TabIndex = 5; + // + // FormTypes + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(590, 420); + Controls.Add(buttonUpdate); + Controls.Add(buttonDelete); + Controls.Add(buttonChange); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormTypes"; + Text = "Таблица Типов"; + Load += FormTypes_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); } #endregion + + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonChange; + private Button buttonAdd; + private DataGridView dataGridView; } } \ No newline at end of file diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormTypes.cs b/PersonnelDepartmentView/PersonnelDepartmentView/FormTypes.cs index 7722d54..2b21f77 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormTypes.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormTypes.cs @@ -1,4 +1,7 @@ -using System; +using PersonnelDepartmentBusinessLogic.BusinessLogics; +using PersonnelDepartmentContracts.BindingModels; +using PersonnelDepartmentContracts.BusinessLogicContracts; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,9 +15,93 @@ namespace PersonnelDepartmentView { public partial class FormTypes : Form { - public FormTypes() + private readonly ITypeLogic _typeLogic; + public FormTypes(ITypeLogic typeLogic) { InitializeComponent(); + _typeLogic = typeLogic; + } + + private void LoadData() + { + try + { + var list = _typeLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка загрузки", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormType)); + if (service is FormType form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonChange_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormType)); + if (service is FormType form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + try + { + if (!_typeLogic.Delete(new TypeBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении."); + } + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void FormTypes_Load(object sender, EventArgs e) + { + LoadData(); } } } diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/FormTypes.resx b/PersonnelDepartmentView/PersonnelDepartmentView/FormTypes.resx index 1af7de1..f298a7b 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/FormTypes.resx +++ b/PersonnelDepartmentView/PersonnelDepartmentView/FormTypes.resx @@ -1,64 +1,4 @@ - - - + diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/PersonnelDepartmentView.csproj b/PersonnelDepartmentView/PersonnelDepartmentView/PersonnelDepartmentView.csproj index 4af9d3a..25ad927 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/PersonnelDepartmentView.csproj +++ b/PersonnelDepartmentView/PersonnelDepartmentView/PersonnelDepartmentView.csproj @@ -13,6 +13,13 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + \ No newline at end of file diff --git a/PersonnelDepartmentView/PersonnelDepartmentView/Program.cs b/PersonnelDepartmentView/PersonnelDepartmentView/Program.cs index 537de9a..cab0296 100644 --- a/PersonnelDepartmentView/PersonnelDepartmentView/Program.cs +++ b/PersonnelDepartmentView/PersonnelDepartmentView/Program.cs @@ -21,15 +21,14 @@ namespace PersonnelDepartmentView // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormDeals()); var services = new ServiceCollection(); ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); } private static void ConfigureServices(ServiceCollection services) { - _serviceProvider = services.BuildServiceProvider(); - services.AddTransient(); services.AddTransient(); services.AddTransient();