diff --git a/COP_9/COP_9.sln b/COP_9/COP_9.sln index 702dffe..81f8fb0 100644 --- a/COP_9/COP_9.sln +++ b/COP_9/COP_9.sln @@ -5,7 +5,15 @@ VisualStudioVersion = 17.8.34525.116 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormsLibrary1", "WinFormsLibrary1\WinFormsLibrary1.csproj", "{724D4035-21A3-4029-9B19-7ED9C5712EA8}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestForm", "TestForm\TestForm.csproj", "{9D20622F-576C-4F80-B5A9-65F869DB9AEE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestForm", "TestForm\TestForm.csproj", "{9D20622F-576C-4F80-B5A9-65F869DB9AEE}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EnterpriseBusinessLogic", "EnterpriseBusinessLogic\EnterpriseBusinessLogic.csproj", "{986F8D46-E1D8-4692-9487-6B4AC3CB3607}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EnterpriseContracts", "EnterpriseContracts\EnterpriseContracts.csproj", "{841BB332-2CB3-4939-92DD-69C9A24F40D7}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EnterpriseDataBaseImplement", "EnterpriseDataBaseImplemen\EnterpriseDataBaseImplement.csproj", "{C093A0DD-037C-4DD7-BE8A-4DD1AFA7BF16}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FormView", "FormView\FormView.csproj", "{17934640-9B04-4A8F-85B9-9C99882ACD31}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -21,6 +29,22 @@ Global {9D20622F-576C-4F80-B5A9-65F869DB9AEE}.Debug|Any CPU.Build.0 = Debug|Any CPU {9D20622F-576C-4F80-B5A9-65F869DB9AEE}.Release|Any CPU.ActiveCfg = Release|Any CPU {9D20622F-576C-4F80-B5A9-65F869DB9AEE}.Release|Any CPU.Build.0 = Release|Any CPU + {986F8D46-E1D8-4692-9487-6B4AC3CB3607}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {986F8D46-E1D8-4692-9487-6B4AC3CB3607}.Debug|Any CPU.Build.0 = Debug|Any CPU + {986F8D46-E1D8-4692-9487-6B4AC3CB3607}.Release|Any CPU.ActiveCfg = Release|Any CPU + {986F8D46-E1D8-4692-9487-6B4AC3CB3607}.Release|Any CPU.Build.0 = Release|Any CPU + {841BB332-2CB3-4939-92DD-69C9A24F40D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {841BB332-2CB3-4939-92DD-69C9A24F40D7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {841BB332-2CB3-4939-92DD-69C9A24F40D7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {841BB332-2CB3-4939-92DD-69C9A24F40D7}.Release|Any CPU.Build.0 = Release|Any CPU + {C093A0DD-037C-4DD7-BE8A-4DD1AFA7BF16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C093A0DD-037C-4DD7-BE8A-4DD1AFA7BF16}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C093A0DD-037C-4DD7-BE8A-4DD1AFA7BF16}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C093A0DD-037C-4DD7-BE8A-4DD1AFA7BF16}.Release|Any CPU.Build.0 = Release|Any CPU + {17934640-9B04-4A8F-85B9-9C99882ACD31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {17934640-9B04-4A8F-85B9-9C99882ACD31}.Debug|Any CPU.Build.0 = Debug|Any CPU + {17934640-9B04-4A8F-85B9-9C99882ACD31}.Release|Any CPU.ActiveCfg = Release|Any CPU + {17934640-9B04-4A8F-85B9-9C99882ACD31}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/COP_9/EnterpriseBusinessLogic/BusinessLogics/EmployeeLogic.cs b/COP_9/EnterpriseBusinessLogic/BusinessLogics/EmployeeLogic.cs new file mode 100644 index 0000000..a90e6aa --- /dev/null +++ b/COP_9/EnterpriseBusinessLogic/BusinessLogics/EmployeeLogic.cs @@ -0,0 +1,50 @@ +using EnterpriseContracts.BusinessLogicContracts; +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.StorageContracts; +using EnterpriseContracts.ViewModels; +using System; +using System.Collections.Generic; + +namespace EnterpriseBusinessLogic.BusinessLogics +{ + + public class EmployeeLogic : IEmployeeLogic + { + private readonly IEmployeeStorage _empStorage; + + public EmployeeLogic(IEmployeeStorage empStorage) + { + _empStorage = empStorage ?? throw new ArgumentNullException(nameof(empStorage), "Хранилище сотрудников не инициализировано."); + } + + public List Read(EmployeeBindingModel? model) + { + if (model == null) + { + return _empStorage.GetFullList(); + } + + return model.Id.HasValue + ? new List { _empStorage.GetElement(model) ?? throw new Exception("Сотрудник не найден.") } + : _empStorage.GetFilteredList(model); + } + + public void CreateOrUpdate(EmployeeBindingModel model) + { + var element = _empStorage.GetElement(new EmployeeBindingModel + { + Id = model.Id + }); + if (element != null) + _empStorage.Update(model); + else + _empStorage.Insert(model); + } + + public void Delete(EmployeeBindingModel model) + { + _ = _empStorage.GetElement(new EmployeeBindingModel { Id = model.Id }) ?? throw new Exception("Id don't exist"); + _empStorage.Delete(model); + } + } +} diff --git a/COP_9/EnterpriseBusinessLogic/BusinessLogics/SubdivisionLogic.cs b/COP_9/EnterpriseBusinessLogic/BusinessLogics/SubdivisionLogic.cs new file mode 100644 index 0000000..7902ddb --- /dev/null +++ b/COP_9/EnterpriseBusinessLogic/BusinessLogics/SubdivisionLogic.cs @@ -0,0 +1,50 @@ +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.BusinessLogicContracts; +using EnterpriseContracts.StorageContracts; +using EnterpriseContracts.ViewModels; + +namespace EnterpriseBusinessLogic.BusinessLogics +{ + public class SubdivisionLogic : ISubdivisionLogic + { + private readonly ISubdivisionStorage _subdivisionStorage; + + public SubdivisionLogic(ISubdivisionStorage subdivisionStorage) + { + _subdivisionStorage = subdivisionStorage; + } + + public List Read(SubdivisionBindingModel? model) + { + if (model == null) + return _subdivisionStorage.GetFullList(); + return model.Id != 0 ? + new List { _subdivisionStorage.GetElement(model) } : + _subdivisionStorage.GetFilteredList(model); + } + + public void CreateOrUpdate(SubdivisionBindingModel model) + { + var element = _subdivisionStorage.GetElement(new SubdivisionBindingModel + { + Name = model.Name + }); + + if (element != null && element.Id != model.Id) + throw new Exception("This name is exists!"); + if (model.Id != 0) + _subdivisionStorage.Update(model); + else + _subdivisionStorage.Insert(model); + } + + public bool Delete(SubdivisionBindingModel model) + { + var element = _subdivisionStorage.GetElement(new SubdivisionBindingModel { Id = model.Id }); + if (element == null) + return false; + _subdivisionStorage.Delete(model); + return true; + } + } +} \ No newline at end of file diff --git a/COP_9/EnterpriseBusinessLogic/EnterpriseBusinessLogic.csproj b/COP_9/EnterpriseBusinessLogic/EnterpriseBusinessLogic.csproj new file mode 100644 index 0000000..d72c77c --- /dev/null +++ b/COP_9/EnterpriseBusinessLogic/EnterpriseBusinessLogic.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/COP_9/EnterpriseContracts/BindingModels/EmployeeBindingModel.cs b/COP_9/EnterpriseContracts/BindingModels/EmployeeBindingModel.cs new file mode 100644 index 0000000..be7073e --- /dev/null +++ b/COP_9/EnterpriseContracts/BindingModels/EmployeeBindingModel.cs @@ -0,0 +1,11 @@ +namespace EnterpriseContracts.BindingModels; + +public class EmployeeBindingModel +{ + public int? Id { get; set; } + public string Fio { get; set; } = string.Empty; + public int Experience { get; set; } + public string Subdivision { get; set; } = string.Empty; + public string Posts { get; set; } = string.Empty; + public (int, int)? ExperienceStep { get; set; } +} \ No newline at end of file diff --git a/COP_9/EnterpriseContracts/BindingModels/SubdivisionBindingModel.cs b/COP_9/EnterpriseContracts/BindingModels/SubdivisionBindingModel.cs new file mode 100644 index 0000000..8713b70 --- /dev/null +++ b/COP_9/EnterpriseContracts/BindingModels/SubdivisionBindingModel.cs @@ -0,0 +1,7 @@ +namespace EnterpriseContracts.BindingModels; + +public class SubdivisionBindingModel +{ + public int Id { get; set; } + public string Name { get; set; } = string.Empty; +} \ No newline at end of file diff --git a/COP_9/EnterpriseContracts/BusinessLogicContracts/IEmployeeLogic.cs b/COP_9/EnterpriseContracts/BusinessLogicContracts/IEmployeeLogic.cs new file mode 100644 index 0000000..0557887 --- /dev/null +++ b/COP_9/EnterpriseContracts/BusinessLogicContracts/IEmployeeLogic.cs @@ -0,0 +1,11 @@ +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.ViewModels; + +namespace EnterpriseContracts.BusinessLogicContracts; + +public interface IEmployeeLogic +{ + List Read(EmployeeBindingModel model); + void CreateOrUpdate(EmployeeBindingModel model); + void Delete(EmployeeBindingModel model); +} \ No newline at end of file diff --git a/COP_9/EnterpriseContracts/BusinessLogicContracts/ISubdivisionLogic.cs b/COP_9/EnterpriseContracts/BusinessLogicContracts/ISubdivisionLogic.cs new file mode 100644 index 0000000..b9784e0 --- /dev/null +++ b/COP_9/EnterpriseContracts/BusinessLogicContracts/ISubdivisionLogic.cs @@ -0,0 +1,11 @@ +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.ViewModels; + +namespace EnterpriseContracts.BusinessLogicContracts; + +public interface ISubdivisionLogic +{ + List Read(SubdivisionBindingModel model); + void CreateOrUpdate(SubdivisionBindingModel model); + bool Delete(SubdivisionBindingModel model); +} \ No newline at end of file diff --git a/COP_9/EnterpriseContracts/EnterpriseContracts.csproj b/COP_9/EnterpriseContracts/EnterpriseContracts.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/COP_9/EnterpriseContracts/EnterpriseContracts.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/COP_9/EnterpriseContracts/StorageContracts/IEmployeeStorage.cs b/COP_9/EnterpriseContracts/StorageContracts/IEmployeeStorage.cs new file mode 100644 index 0000000..140526f --- /dev/null +++ b/COP_9/EnterpriseContracts/StorageContracts/IEmployeeStorage.cs @@ -0,0 +1,14 @@ +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.ViewModels; + +namespace EnterpriseContracts.StorageContracts; + +public interface IEmployeeStorage +{ + List GetFullList(); + List GetFilteredList(EmployeeBindingModel model); + EmployeeViewModel? GetElement(EmployeeBindingModel model); + void Insert(EmployeeBindingModel model); + void Update(EmployeeBindingModel model); + void Delete(EmployeeBindingModel model); +} \ No newline at end of file diff --git a/COP_9/EnterpriseContracts/StorageContracts/ISubdivisionStorage.cs b/COP_9/EnterpriseContracts/StorageContracts/ISubdivisionStorage.cs new file mode 100644 index 0000000..64ceba4 --- /dev/null +++ b/COP_9/EnterpriseContracts/StorageContracts/ISubdivisionStorage.cs @@ -0,0 +1,14 @@ +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.ViewModels; + +namespace EnterpriseContracts.StorageContracts; + +public interface ISubdivisionStorage +{ + List GetFullList(); + List GetFilteredList(SubdivisionBindingModel model); + SubdivisionViewModel? GetElement(SubdivisionBindingModel? model); + void Insert(SubdivisionBindingModel model); + void Update(SubdivisionBindingModel model); + void Delete(SubdivisionBindingModel model); +} \ No newline at end of file diff --git a/COP_9/EnterpriseContracts/ViewModels/EmployeeViewModel.cs b/COP_9/EnterpriseContracts/ViewModels/EmployeeViewModel.cs new file mode 100644 index 0000000..8f9dc03 --- /dev/null +++ b/COP_9/EnterpriseContracts/ViewModels/EmployeeViewModel.cs @@ -0,0 +1,11 @@ +namespace EnterpriseContracts.ViewModels; + +public class EmployeeViewModel +{ + public int Id { get; set; } + public string Fio { get; set; } = string.Empty; + public int Experience { get; set; } + public string Subdivision { get; set; } = string.Empty; + public string Posts { get; set; } = string.Empty; + +} \ No newline at end of file diff --git a/COP_9/EnterpriseContracts/ViewModels/SubdivisionViewModel.cs b/COP_9/EnterpriseContracts/ViewModels/SubdivisionViewModel.cs new file mode 100644 index 0000000..aa0b4db --- /dev/null +++ b/COP_9/EnterpriseContracts/ViewModels/SubdivisionViewModel.cs @@ -0,0 +1,7 @@ +namespace EnterpriseContracts.ViewModels; + +public class SubdivisionViewModel +{ + public int Id { get; set; } + public string Name { get; set; } = string.Empty; +} \ No newline at end of file diff --git a/COP_9/EnterpriseDataBaseImplemen/EnterpriseDataBase.cs b/COP_9/EnterpriseDataBaseImplemen/EnterpriseDataBase.cs new file mode 100644 index 0000000..a400209 --- /dev/null +++ b/COP_9/EnterpriseDataBaseImplemen/EnterpriseDataBase.cs @@ -0,0 +1,18 @@ +using EnterpriseDataBaseImplement.Models; +using Microsoft.EntityFrameworkCore; + +namespace EnterpriseDataBaseImplement; + +public class EnterpriseDataBase : DbContext +{ + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (!optionsBuilder.IsConfigured) { + optionsBuilder.UseSqlServer(@"Data Source=WIN-45522256GVD\SQLEXPRESS;Initial Catalog=EnterpriseDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + } + base.OnConfiguring(optionsBuilder); + } + + public virtual DbSet Employees { set; get; } + public virtual DbSet Subdivisions { set; get; } +} \ No newline at end of file diff --git a/COP_9/EnterpriseDataBaseImplemen/EnterpriseDataBaseImplement.csproj b/COP_9/EnterpriseDataBaseImplemen/EnterpriseDataBaseImplement.csproj new file mode 100644 index 0000000..cb055d1 --- /dev/null +++ b/COP_9/EnterpriseDataBaseImplemen/EnterpriseDataBaseImplement.csproj @@ -0,0 +1,23 @@ + + + + net6.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/COP_9/EnterpriseDataBaseImplemen/Implements/EmployeeStorage.cs b/COP_9/EnterpriseDataBaseImplemen/Implements/EmployeeStorage.cs new file mode 100644 index 0000000..525c89c --- /dev/null +++ b/COP_9/EnterpriseDataBaseImplemen/Implements/EmployeeStorage.cs @@ -0,0 +1,91 @@ +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.StorageContracts; +using EnterpriseContracts.ViewModels; +using EnterpriseDataBaseImplement.Models; + +namespace EnterpriseDataBaseImplement.Implements; + +public class EmployeeStorage : IEmployeeStorage +{ + public List GetFullList() + { + var context = new EnterpriseDataBase(); + return context.Employees + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(EmployeeBindingModel model) + { + var context = new EnterpriseDataBase(); + if (!model.ExperienceStep.HasValue) return new(); + return context.Employees + .Where(x => model.ExperienceStep.Value.Item1 <= x.Experience && + model.ExperienceStep.Value.Item2 >= x.Experience) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public EmployeeViewModel? GetElement(EmployeeBindingModel model) + { + if (model == null || !model.Id.HasValue) return null; + using var context = new EnterpriseDataBase(); + var x = context.Employees + .ToList() + .FirstOrDefault(rec => rec.Id == model.Id); + return x?.GetViewModel; + } + + public void Insert(EmployeeBindingModel model) + { + var context = new EnterpriseDataBase(); + var transaction = context.Database.BeginTransaction(); + try + { + var x = Employee.Create(model); + context.Employees.Add(x); + context.SaveChanges(); + transaction.Commit(); + } + catch + { + transaction.Rollback(); + throw; + } + } + + public void Update(EmployeeBindingModel model) + { + var context = new EnterpriseDataBase(); + var transaction = context.Database.BeginTransaction(); + try + { + var x = context.Employees.FirstOrDefault(rec => rec.Id == model.Id); + if (x == null) + throw new Exception("Not found"); + x.Update(model); + context.SaveChanges(); + transaction.Commit(); + } + catch + { + transaction.Rollback(); + throw; + } + } + + public void Delete(EmployeeBindingModel model) + { + var context = new EnterpriseDataBase(); + var x = context.Employees.FirstOrDefault(rec => rec.Id == model.Id); + if (x != null) + { + context.Employees.Remove(x); + context.SaveChanges(); + } + else + throw new Exception("Id isn't exists"); + } +} \ No newline at end of file diff --git a/COP_9/EnterpriseDataBaseImplemen/Implements/SubdivisionStorage.cs b/COP_9/EnterpriseDataBaseImplemen/Implements/SubdivisionStorage.cs new file mode 100644 index 0000000..7f86f4e --- /dev/null +++ b/COP_9/EnterpriseDataBaseImplemen/Implements/SubdivisionStorage.cs @@ -0,0 +1,89 @@ +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.StorageContracts; +using EnterpriseContracts.ViewModels; +using EnterpriseDataBaseImplement.Models; + +namespace EnterpriseDataBaseImplement.Implements; + +public class SubdivisionStorage : ISubdivisionStorage +{ + public List GetFullList() + { + var context = new EnterpriseDataBase(); + return context.Subdivisions + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(SubdivisionBindingModel model) + { + var context = new EnterpriseDataBase(); + return context.Subdivisions + .Where(x => x.Name.Contains(model.Name)) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public SubdivisionViewModel? GetElement(SubdivisionBindingModel? model) + { + if (model == null) return null; + using var context = new EnterpriseDataBase(); + var x = context.Subdivisions + .ToList() + .FirstOrDefault(rec => rec.Name == model.Name || rec.Id == model.Id); + return x?.GetViewModel; + } + + public void Insert(SubdivisionBindingModel model) + { + var context = new EnterpriseDataBase(); + var transaction = context.Database.BeginTransaction(); + try + { + var x = Subdivision.Create(model); + context.Subdivisions.Add(x); + context.SaveChanges(); + transaction.Commit(); + } + catch + { + transaction.Rollback(); + throw; + } + } + + public void Update(SubdivisionBindingModel model) + { + var context = new EnterpriseDataBase(); + var transaction = context.Database.BeginTransaction(); + try + { + var x = context.Subdivisions.FirstOrDefault(rec => rec.Id == model.Id); + if (x == null) + throw new Exception("Not found"); + x.Update(model); + context.SaveChanges(); + transaction.Commit(); + } + catch + { + transaction.Rollback(); + throw; + } + } + + public void Delete(SubdivisionBindingModel model) + { + var context = new EnterpriseDataBase(); + var x = context.Subdivisions.FirstOrDefault(rec => rec.Id == model.Id); + if (x != null) + { + context.Subdivisions.Remove(x); + context.SaveChanges(); + } + else + throw new Exception("Id isn't exists"); + } +} \ No newline at end of file diff --git a/COP_9/EnterpriseDataBaseImplemen/Migrations/20241028192747_Initial.Designer.cs b/COP_9/EnterpriseDataBaseImplemen/Migrations/20241028192747_Initial.Designer.cs new file mode 100644 index 0000000..87ab4c4 --- /dev/null +++ b/COP_9/EnterpriseDataBaseImplemen/Migrations/20241028192747_Initial.Designer.cs @@ -0,0 +1,74 @@ +// +using EnterpriseDataBaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EnterpriseDataBaseImplemen.Migrations +{ + [DbContext(typeof(EnterpriseDataBase))] + [Migration("20241028192747_Initial")] + partial class Initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.18") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("EnterpriseDataBaseImplement.Models.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Experience") + .HasColumnType("int"); + + b.Property("Fio") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Posts") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subdivision") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("EnterpriseDataBaseImplement.Models.Subdivision", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Subdivisions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/COP_9/EnterpriseDataBaseImplemen/Migrations/20241028192747_Initial.cs b/COP_9/EnterpriseDataBaseImplemen/Migrations/20241028192747_Initial.cs new file mode 100644 index 0000000..e4f86b9 --- /dev/null +++ b/COP_9/EnterpriseDataBaseImplemen/Migrations/20241028192747_Initial.cs @@ -0,0 +1,53 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace EnterpriseDataBaseImplemen.Migrations +{ + /// + public partial class Initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Employees", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Fio = table.Column(type: "nvarchar(max)", nullable: false), + Experience = table.Column(type: "int", nullable: false), + Posts = table.Column(type: "nvarchar(max)", nullable: false), + Subdivision = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Employees", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Subdivisions", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Subdivisions", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Employees"); + + migrationBuilder.DropTable( + name: "Subdivisions"); + } + } +} diff --git a/COP_9/EnterpriseDataBaseImplemen/Migrations/EnterpriseDataBaseModelSnapshot.cs b/COP_9/EnterpriseDataBaseImplemen/Migrations/EnterpriseDataBaseModelSnapshot.cs new file mode 100644 index 0000000..7fd61b2 --- /dev/null +++ b/COP_9/EnterpriseDataBaseImplemen/Migrations/EnterpriseDataBaseModelSnapshot.cs @@ -0,0 +1,71 @@ +// +using EnterpriseDataBaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace EnterpriseDataBaseImplemen.Migrations +{ + [DbContext(typeof(EnterpriseDataBase))] + partial class EnterpriseDataBaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.18") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("EnterpriseDataBaseImplement.Models.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Experience") + .HasColumnType("int"); + + b.Property("Fio") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Posts") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Subdivision") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("EnterpriseDataBaseImplement.Models.Subdivision", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Subdivisions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/COP_9/EnterpriseDataBaseImplemen/Models/Employee.cs b/COP_9/EnterpriseDataBaseImplemen/Models/Employee.cs new file mode 100644 index 0000000..55046b0 --- /dev/null +++ b/COP_9/EnterpriseDataBaseImplemen/Models/Employee.cs @@ -0,0 +1,54 @@ +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.ViewModels; +using System.ComponentModel.DataAnnotations; + +namespace EnterpriseDataBaseImplement.Models; + +public class Employee +{ + public int Id { get; set; } + public string Fio { get; set; } = string.Empty; + public int Experience { get; set; } + public string Posts { get; set; } = string.Empty; + public string Subdivision { get; set; } = string.Empty; + + public static Employee? Create(EmployeeBindingModel? model) + { + if (model == null) return null; + return new() + { + Fio = model.Fio, + Experience = model.Experience, + Posts = model.Posts, + Subdivision = model.Subdivision + }; + } + + public static Employee Create(EmployeeViewModel model) + { + return new Employee + { + Id = model.Id, + Fio = model.Fio, + Experience = model.Experience, + Posts = model.Posts, + Subdivision = model.Subdivision + }; + } + + public void Update(EmployeeBindingModel? model) + { + if (model == null) return; + Posts = model.Posts; + Subdivision = model.Subdivision; + } + + public EmployeeViewModel GetViewModel => new() + { + Id = Id, + Fio = Fio, + Experience = Experience, + Subdivision = Subdivision, + Posts = Posts, + }; +} \ No newline at end of file diff --git a/COP_9/EnterpriseDataBaseImplemen/Models/Subdivision.cs b/COP_9/EnterpriseDataBaseImplemen/Models/Subdivision.cs new file mode 100644 index 0000000..3413d36 --- /dev/null +++ b/COP_9/EnterpriseDataBaseImplemen/Models/Subdivision.cs @@ -0,0 +1,42 @@ +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.ViewModels; + +namespace EnterpriseDataBaseImplement.Models; + +public class Subdivision +{ + public int Id { get; set; } + public string Name { get; set; } = string.Empty; + + public static Subdivision? Create(SubdivisionBindingModel? model) + { + if (model == null) return null; + return new() + { + Id = model.Id, + Name = model.Name + }; + } + + public static Subdivision? Create(SubdivisionViewModel? model) + { + if (model == null) return null; + return new() + { + Id = model.Id, + Name = model.Name + }; + } + + public void Update(SubdivisionBindingModel? model) + { + if (model == null) return; + if (!string.IsNullOrEmpty(model.Name)) Name = model.Name; + } + + public SubdivisionViewModel GetViewModel => new() + { + Id = Id, + Name = Name + }; +} \ No newline at end of file diff --git a/COP_9/Form/Directory.Designer.cs b/COP_9/Form/Directory.Designer.cs new file mode 100644 index 0000000..04ddada --- /dev/null +++ b/COP_9/Form/Directory.Designer.cs @@ -0,0 +1,39 @@ +namespace Form +{ + partial class Directory + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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 = "Directory"; + } + + #endregion + } +} \ No newline at end of file diff --git a/COP_9/Form/Directory.cs b/COP_9/Form/Directory.cs new file mode 100644 index 0000000..722ebb0 --- /dev/null +++ b/COP_9/Form/Directory.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Form +{ + public partial class Directory : Form + { + public Directory() + { + InitializeComponent(); + } + } +} diff --git a/COP_9/Form/FormView.csproj b/COP_9/Form/FormView.csproj new file mode 100644 index 0000000..c0e0819 --- /dev/null +++ b/COP_9/Form/FormView.csproj @@ -0,0 +1,24 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/COP_9/Form/Program.cs b/COP_9/Form/Program.cs new file mode 100644 index 0000000..27232e9 --- /dev/null +++ b/COP_9/Form/Program.cs @@ -0,0 +1,24 @@ +using Form; +using System.ComponentModel; +using EnterpriseBusinessLogic; +using EnterpriseContracts; +using EnterpriseDataBaseImplemen; + +namespace Form +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + + Application.SetHighDpiMode(HighDpiMode.SystemAware); + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(Container.Resolve
()); + } + } +} \ No newline at end of file diff --git a/COP_9/FormView/Directory.Designer.cs b/COP_9/FormView/Directory.Designer.cs new file mode 100644 index 0000000..8900d7f --- /dev/null +++ b/COP_9/FormView/Directory.Designer.cs @@ -0,0 +1,65 @@ +namespace FormView +{ + partial class Directory + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Fill; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(414, 261); + this.dataGridView.TabIndex = 0; + this.dataGridView.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.DataGridView_CellEndEdit); + this.dataGridView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.DataGridView_KeyDown); + // + // Directory + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(414, 261); + this.Controls.Add(this.dataGridView); + this.Name = "Directory"; + this.Text = "Directory"; + this.Load += new System.EventHandler(this.Directory_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + } +} diff --git a/COP_9/FormView/Directory.cs b/COP_9/FormView/Directory.cs new file mode 100644 index 0000000..4e48b5a --- /dev/null +++ b/COP_9/FormView/Directory.cs @@ -0,0 +1,128 @@ +using System.ComponentModel; +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.BusinessLogicContracts; + + +namespace FormView +{ + public partial class Directory : Form + { + private readonly ISubdivisionLogic _logicS; + BindingList list; + + public Directory(ISubdivisionLogic logicS) + { + InitializeComponent(); + _logicS = logicS; + dataGridView.AllowUserToDeleteRows = true; + list = new BindingList(); + } + + private void LoadData() + { + try + { + var list1 = _logicS.Read(null); + list.Clear(); + foreach (var item in list1) + { + list.Add(new() + { + Id = item.Id, + Name = item.Name, + }); + } + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns[0].Visible = false; + dataGridView.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void Directory_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void DataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) + { + var typeName = (string)dataGridView.CurrentRow.Cells[1].Value; + if (!string.IsNullOrEmpty(typeName)) + { + if (dataGridView.CurrentRow.Cells[0].Value != null) + { + _logicS.CreateOrUpdate(new() + { + Id = Convert.ToInt32(dataGridView.CurrentRow.Cells[0].Value), + Name = (string)dataGridView.CurrentRow.Cells[1].EditedFormattedValue + }); + } + else + { + _logicS.CreateOrUpdate(new() + { + Name = (string)dataGridView.CurrentRow.Cells[1].EditedFormattedValue + }); + } + } + else + { + MessageBox.Show("Empty name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + + private void DataGridView_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyData == Keys.Insert) + { + if (dataGridView.Rows.Count == 0) + { + list.Add(new()); + dataGridView.DataSource = new List(list); + dataGridView.CurrentCell = dataGridView.Rows[0].Cells[1]; + return; + } + if (dataGridView.Rows[^1].Cells[1].Value != null) + { + list.Add(new()); + dataGridView.DataSource = new List(list); + dataGridView.CurrentCell = dataGridView.Rows[^1].Cells[1]; + return; + } + } + if (e.KeyData == Keys.Delete) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Confirm deleting", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + try + { + if (!_logicS.Delete(new() + { + Id = id + })) + { + throw new Exception("Error on delete"); + } + dataGridView.Rows.RemoveAt(dataGridView.SelectedRows[0].Index); + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + } + } +} diff --git a/COP_9/FormView/Directory.resx b/COP_9/FormView/Directory.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/COP_9/FormView/Directory.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/COP_9/FormView/EmployerForm.Designer.cs b/COP_9/FormView/EmployerForm.Designer.cs new file mode 100644 index 0000000..0ce5ade --- /dev/null +++ b/COP_9/FormView/EmployerForm.Designer.cs @@ -0,0 +1,163 @@ +namespace FormView +{ + partial class EmployerForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + textBoxFio = new TextBox(); + label1 = new Label(); + label2 = new Label(); + customInputRangeNumber = new ControlsLibraryNet60.Input.ControlInputRangeNumber(); + dropDownList = new Components.DropDownList(); + label3 = new Label(); + label4 = new Label(); + textBoxPosts = new TextBox(); + buttonCreate = new Button(); + SuspendLayout(); + // + // textBoxFio + // + textBoxFio.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + textBoxFio.Location = new Point(52, 6); + textBoxFio.Name = "textBoxFio"; + textBoxFio.Size = new Size(335, 23); + textBoxFio.TabIndex = 0; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 9); + label1.Name = "label1"; + label1.Size = new Size(34, 15); + label1.TabIndex = 1; + label1.Text = "ФИО"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(12, 43); + label2.Name = "label2"; + label2.Size = new Size(37, 15); + label2.TabIndex = 2; + label2.Text = "Опыт"; + // + // customInputRangeNumber + // + customInputRangeNumber.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + customInputRangeNumber.AutoSize = true; + customInputRangeNumber.AutoValidate = AutoValidate.Disable; + customInputRangeNumber.CausesValidation = false; + customInputRangeNumber.Location = new Point(82, 35); + customInputRangeNumber.Margin = new Padding(5, 3, 5, 3); + customInputRangeNumber.MaxValue = new decimal(new int[] { 30, 0, 0, 0 }); + customInputRangeNumber.MinValue = new decimal(new int[] { 1, 0, 0, 0 }); + customInputRangeNumber.Name = "customInputRangeNumber"; + customInputRangeNumber.Size = new Size(305, 31); + customInputRangeNumber.TabIndex = 3; + customInputRangeNumber.Value = null; + // + // dropDownList + // + dropDownList.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + dropDownList.Location = new Point(110, 73); + dropDownList.Margin = new Padding(3, 2, 3, 2); + dropDownList.Name = "dropDownList"; + dropDownList.SelectedItem = ""; + dropDownList.Size = new Size(277, 29); + dropDownList.TabIndex = 4; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(12, 78); + label3.Name = "label3"; + label3.Size = new Size(92, 15); + label3.TabIndex = 5; + label3.Text = "Подразделение"; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(12, 109); + label4.Name = "label4"; + label4.Size = new Size(70, 15); + label4.TabIndex = 6; + label4.Text = "Должности"; + // + // textBoxPosts + // + textBoxPosts.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + textBoxPosts.Location = new Point(88, 107); + textBoxPosts.Name = "textBoxPosts"; + textBoxPosts.Size = new Size(299, 23); + textBoxPosts.TabIndex = 7; + // + // buttonCreate + // + buttonCreate.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + buttonCreate.Location = new Point(12, 141); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(375, 45); + buttonCreate.TabIndex = 8; + buttonCreate.Text = "Create"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += ButtonCreate_Click; + // + // EmployerForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(399, 198); + Controls.Add(buttonCreate); + Controls.Add(textBoxPosts); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(dropDownList); + Controls.Add(customInputRangeNumber); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(textBoxFio); + Name = "EmployerForm"; + Text = "EmployerForm"; + Load += EmployerForm_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxFio; + private Label label1; + private Label label2; + private ControlsLibraryNet60.Input.ControlInputRangeNumber customInputRangeNumber; + private Components.DropDownList dropDownList; + private Label label3; + private Label label4; + private TextBox textBoxPosts; + private Button buttonCreate; + } +} \ No newline at end of file diff --git a/COP_9/FormView/EmployerForm.cs b/COP_9/FormView/EmployerForm.cs new file mode 100644 index 0000000..3899e37 --- /dev/null +++ b/COP_9/FormView/EmployerForm.cs @@ -0,0 +1,87 @@ +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.BusinessLogicContracts; +using EnterpriseContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FormView +{ + public partial class EmployerForm : Form + { + private readonly IEmployeeLogic _logic; + private readonly ISubdivisionLogic _logicS; + public int? Id { get; set; } + + public EmployerForm(IEmployeeLogic logic, ISubdivisionLogic logicS) + { + InitializeComponent(); + _logic = logic; + _logicS = logicS; + customInputRangeNumber.MinValue = 1; + customInputRangeNumber.MaxValue = 30; + customInputRangeNumber.Value = 1; + } + + private void ButtonCreate_Click(object sender, EventArgs e) + { + try + { + _logic.CreateOrUpdate(new EmployeeBindingModel + { + Id = Id, + Fio = textBoxFio.Text, + Subdivision = dropDownList.SelectedItem, + Posts = textBoxPosts.Text, + Experience = (int)customInputRangeNumber.Value + }); + MessageBox.Show("Succesfully", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void EmployerForm_Load(object sender, EventArgs e) + { + List? viewS = _logicS.Read(null); + + if (viewS != null) + { + // Используем свойство ComboBoxItems для добавления элементов + dropDownList.ComboBoxItems.AddRange(viewS.Select(x => x.Name).ToArray()); + } + + if (Id.HasValue) + { + try + { + EmployeeViewModel? view = _logic.Read(new EmployeeBindingModel { Id = Id.Value })?[0]; + if (view != null) + { + textBoxFio.Text = view.Fio; + + // Используем свойство SelectedItem для установки выбранного элемента + dropDownList.SelectedItem = view.Subdivision; + + customInputRangeNumber.Value = view.Experience; + textBoxPosts.Text = view.Posts; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/COP_9/FormView/EmployerForm.resx b/COP_9/FormView/EmployerForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/COP_9/FormView/EmployerForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/COP_9/FormView/FormEmployer1.Designer.cs b/COP_9/FormView/FormEmployer1.Designer.cs new file mode 100644 index 0000000..cbcfa34 --- /dev/null +++ b/COP_9/FormView/FormEmployer1.Designer.cs @@ -0,0 +1,158 @@ +using DocumentFormat.OpenXml.Spreadsheet; +using DocumentFormat.OpenXml.Wordprocessing; + +namespace FormView +{ + partial class EmployerForm1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelFio = new Label(); + textBoxFio = new TextBox(); + labelExp = new Label(); + customInputRangeNumber = new ControlsLibraryNet60.Input.ControlInputRangeNumber(); + labelSubvision = new Label(); + labelPosts = new Label(); + sqlDataAdapter1 = new Microsoft.Data.SqlClient.SqlDataAdapter(); + textBoxPosts = new TextBox(); + buttonCreate = new Button(); + dropDownList = new Components.DropDownList(); + SuspendLayout(); + // + // labelFio + // + labelFio.AutoSize = true; + labelFio.Location = new Point(35, 39); + labelFio.Name = "labelFio"; + labelFio.Size = new Size(31, 20); + labelFio.TabIndex = 0; + labelFio.Text = "FIO"; + // + // textBoxFio + // + textBoxFio.Location = new Point(122, 36); + textBoxFio.Name = "textBoxFio"; + textBoxFio.Size = new Size(179, 27); + textBoxFio.TabIndex = 1; + // + // labelExp + // + labelExp.AutoSize = true; + labelExp.Location = new Point(35, 80); + labelExp.Name = "labelExp"; + labelExp.Size = new Size(81, 20); + labelExp.TabIndex = 2; + labelExp.Text = "Experience"; + // + // customInputRangeNumber + // + customInputRangeNumber.Location = new Point(122, 80); + customInputRangeNumber.MaxValue = new decimal(new int[] { 30, 0, 0, 0 }); + customInputRangeNumber.MinValue = new decimal(new int[] { 1, 0, 0, 0 }); + customInputRangeNumber.Name = "customInputRangeNumber"; + customInputRangeNumber.Size = new Size(161, 45); + customInputRangeNumber.TabIndex = 3; + // + // labelSubvision + // + labelSubvision.AutoSize = true; + labelSubvision.Location = new Point(35, 134); + labelSubvision.Name = "labelSubvision"; + labelSubvision.Size = new Size(72, 20); + labelSubvision.TabIndex = 4; + labelSubvision.Text = "Subvision"; + // + // labelPosts + // + labelPosts.AutoSize = true; + labelPosts.Location = new Point(35, 220); + labelPosts.Name = "labelPosts"; + labelPosts.Size = new Size(42, 20); + labelPosts.TabIndex = 5; + labelPosts.Text = "Posts"; + // + // textBoxPosts + // + textBoxPosts.Location = new Point(122, 217); + textBoxPosts.Name = "textBoxPosts"; + textBoxPosts.Size = new Size(179, 27); + textBoxPosts.TabIndex = 6; + // + // buttonCreate + // + buttonCreate.Location = new Point(113, 274); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(94, 29); + buttonCreate.TabIndex = 8; + buttonCreate.Text = "Create"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += ButtonCreate_Click; + // + // dropDownList + // + dropDownList.Location = new Point(120, 132); + dropDownList.Margin = new Padding(3, 4, 3, 4); + dropDownList.Name = "dropDownList"; + dropDownList.SelectedItem = ""; + dropDownList.Size = new Size(181, 49); + dropDownList.TabIndex = 9; + dropDownList.Load += EmployerForm1_Load; + // + // EmployerForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(562, 312); + Controls.Add(dropDownList); + Controls.Add(buttonCreate); + Controls.Add(textBoxPosts); + Controls.Add(labelPosts); + Controls.Add(labelSubvision); + Controls.Add(customInputRangeNumber); + Controls.Add(labelExp); + Controls.Add(textBoxFio); + Controls.Add(labelFio); + Name = "EmployerForm1"; + Text = "FormEmployer1"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelFio; + private TextBox textBoxFio; + private Label labelExp; + private ControlsLibraryNet60.Input.ControlInputRangeNumber customInputRangeNumber; + private Label labelSubvision; + private Label labelPosts; + private Microsoft.Data.SqlClient.SqlDataAdapter sqlDataAdapter1; + private TextBox textBoxPosts; + private Button buttonCreate; + private Components.DropDownList dropDownList; + } +} \ No newline at end of file diff --git a/COP_9/FormView/FormEmployer1.cs b/COP_9/FormView/FormEmployer1.cs new file mode 100644 index 0000000..c82f16c --- /dev/null +++ b/COP_9/FormView/FormEmployer1.cs @@ -0,0 +1,84 @@ +using Components; +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.BusinessLogicContracts; +using EnterpriseContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FormView +{ + public partial class EmployerForm1 : Form + { + private readonly IEmployeeLogic _logic; + private readonly ISubdivisionLogic _logicS; + public int? Id { get; set; } + + public EmployerForm1(IEmployeeLogic logic, ISubdivisionLogic logicS) + { + InitializeComponent(); + _logic = logic; + _logicS = logicS; + customInputRangeNumber.MinValue = 1; + customInputRangeNumber.MaxValue = 30; + customInputRangeNumber.Value = 1; + } + + private void ButtonCreate_Click(object sender, EventArgs e) + { + try + { + _logic.CreateOrUpdate(new EmployeeBindingModel + { + Id = Id, + Fio = textBoxFio.Text, + Subdivision = dropDownList.SelectedItem, + Posts = textBoxPosts.Text, + Experience = (int)customInputRangeNumber.Value + }); + MessageBox.Show("Succesfully", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void EmployerForm1_Load(object sender, EventArgs e) + { + List? viewS = _logicS.Read(null); + + if (viewS != null) + { + dropDownList.ComboBoxItems.AddRange(viewS.Select(x => x.Name).ToArray()); + } + + if (Id.HasValue) + { + try + { + EmployeeViewModel? view = _logic.Read(new EmployeeBindingModel { Id = Id.Value })?[0]; + if (view != null) + { + textBoxFio.Text = view.Fio; + dropDownList.SelectedItem = view.Subdivision; + customInputRangeNumber.Value = view.Experience; + textBoxPosts.Text = view.Posts; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/COP_9/FormView/FormEmployer1.resx b/COP_9/FormView/FormEmployer1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/COP_9/FormView/FormEmployer1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/COP_9/FormView/FormMain.Designer.cs b/COP_9/FormView/FormMain.Designer.cs new file mode 100644 index 0000000..ed1f57f --- /dev/null +++ b/COP_9/FormView/FormMain.Designer.cs @@ -0,0 +1,174 @@ +using ComponentsLibraryNet60.DocumentWithTable; + +namespace FormView +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + listBoxMany = new Components.ListBoxMany(); + excelTable = new WinFormsLibrary1.ExcelTable(components); + componentDiagramToPdf = new Components.DiagramToPDF(components); + wordWithTable = new ComponentDocumentWithTableMultiHeaderWord(components); + menuStrip1 = new MenuStrip(); + actionToolStripMenuItem = new ToolStripMenuItem(); + createEmployerToolStripMenuItem = new ToolStripMenuItem(); + editEmployerToolStripMenuItem = new ToolStripMenuItem(); + deleteEmployerToolStripMenuItem = new ToolStripMenuItem(); + excelToolStripMenuItem = new ToolStripMenuItem(); + wordToolStripMenuItem = new ToolStripMenuItem(); + pdfToolStripMenuItem = new ToolStripMenuItem(); + directoryToolStripMenuItem = new ToolStripMenuItem(); + toolStripMenuItem1 = new ToolStripMenuItem(); + menuStrip1.SuspendLayout(); + SuspendLayout(); + // + // listBoxMany + // + listBoxMany.AutoSizeMode = AutoSizeMode.GrowAndShrink; + listBoxMany.Dock = DockStyle.Fill; + listBoxMany.Location = new Point(0, 24); + listBoxMany.Margin = new Padding(3, 4, 3, 4); + listBoxMany.Name = "listBoxMany"; + listBoxMany.SelectedIndex = -1; + listBoxMany.Size = new Size(895, 453); + listBoxMany.TabIndex = 1; + // + // menuStrip1 + // + menuStrip1.Items.AddRange(new ToolStripItem[] { actionToolStripMenuItem, directoryToolStripMenuItem, toolStripMenuItem1 }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(895, 24); + menuStrip1.TabIndex = 2; + menuStrip1.Text = "menuStrip1"; + // + // actionToolStripMenuItem + // + actionToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { createEmployerToolStripMenuItem, editEmployerToolStripMenuItem, deleteEmployerToolStripMenuItem, excelToolStripMenuItem, wordToolStripMenuItem, pdfToolStripMenuItem }); + actionToolStripMenuItem.Name = "actionToolStripMenuItem"; + actionToolStripMenuItem.Size = new Size(70, 20); + actionToolStripMenuItem.Text = "Действие"; + // + // createEmployerToolStripMenuItem + // + createEmployerToolStripMenuItem.Name = "createEmployerToolStripMenuItem"; + createEmployerToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.A; + createEmployerToolStripMenuItem.Size = new Size(274, 22); + createEmployerToolStripMenuItem.Text = "Создать работодателя"; + createEmployerToolStripMenuItem.Click += CreateEmployerToolStripMenuItem_Click; + // + // editEmployerToolStripMenuItem + // + editEmployerToolStripMenuItem.Name = "editEmployerToolStripMenuItem"; + editEmployerToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.U; + editEmployerToolStripMenuItem.Size = new Size(274, 22); + editEmployerToolStripMenuItem.Text = "Редактировать работодателя"; + editEmployerToolStripMenuItem.Click += EditEmployerToolStripMenuItem_Click; + // + // deleteEmployerToolStripMenuItem + // + deleteEmployerToolStripMenuItem.Name = "deleteEmployerToolStripMenuItem"; + deleteEmployerToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.D; + deleteEmployerToolStripMenuItem.Size = new Size(274, 22); + deleteEmployerToolStripMenuItem.Text = "Удалить работодателя"; + deleteEmployerToolStripMenuItem.Click += DeleteEmployerToolStripMenuItem_Click; + // + // excelToolStripMenuItem + // + excelToolStripMenuItem.Name = "excelToolStripMenuItem"; + excelToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S; + excelToolStripMenuItem.Size = new Size(274, 22); + excelToolStripMenuItem.Text = "Excel"; + excelToolStripMenuItem.Click += ExcelToolStripMenuItem_Click; + // + // wordToolStripMenuItem + // + wordToolStripMenuItem.Name = "wordToolStripMenuItem"; + wordToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.T; + wordToolStripMenuItem.Size = new Size(274, 22); + wordToolStripMenuItem.Text = "Word"; + wordToolStripMenuItem.Click += WordToolStripMenuItem_Click; + // + // pdfToolStripMenuItem + // + pdfToolStripMenuItem.Name = "pdfToolStripMenuItem"; + pdfToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.C; + pdfToolStripMenuItem.Size = new Size(274, 22); + pdfToolStripMenuItem.Text = "Pdf"; + pdfToolStripMenuItem.Click += PdfToolStripMenuItem_Click; + // + // directoryToolStripMenuItem + // + directoryToolStripMenuItem.Checked = true; + directoryToolStripMenuItem.CheckState = CheckState.Checked; + directoryToolStripMenuItem.Name = "directoryToolStripMenuItem"; + directoryToolStripMenuItem.Size = new Size(67, 20); + directoryToolStripMenuItem.Text = "Directory"; + directoryToolStripMenuItem.Click += DirectoryToolStripMenuItem_Click; + // + // toolStripMenuItem1 + // + toolStripMenuItem1.Name = "toolStripMenuItem1"; + toolStripMenuItem1.Size = new Size(12, 20); + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(895, 477); + Controls.Add(listBoxMany); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "FormMain"; + Text = "Приложение"; + Load += FormMain_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + + #endregion + private Components.ListBoxMany listBoxMany; + private WinFormsLibrary1.ExcelTable excelTable; + private Components.DiagramToPDF componentDiagramToPdf; + private ComponentsLibraryNet60.DocumentWithTable.ComponentDocumentWithTableMultiHeaderWord wordWithTable; + private MenuStrip menuStrip1; + private ToolStripMenuItem actionToolStripMenuItem; + private ToolStripMenuItem createEmployerToolStripMenuItem; + private ToolStripMenuItem editEmployerToolStripMenuItem; + private ToolStripMenuItem deleteEmployerToolStripMenuItem; + private ToolStripMenuItem excelToolStripMenuItem; + private ToolStripMenuItem wordToolStripMenuItem; + private ToolStripMenuItem pdfToolStripMenuItem; + private ToolStripMenuItem directoryToolStripMenuItem; + private ToolStripMenuItem toolStripMenuItem1; + } +} \ No newline at end of file diff --git a/COP_9/FormView/FormMain.cs b/COP_9/FormView/FormMain.cs new file mode 100644 index 0000000..f7eeff8 --- /dev/null +++ b/COP_9/FormView/FormMain.cs @@ -0,0 +1,567 @@ +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.BusinessLogicContracts; +using EnterpriseContracts.ViewModels; +using ComponentsLibraryNet60.DocumentWithTable; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; +using ControlsLibraryNet60.Models; +using Components; +using ComponentsLibraryNet60.Models; + +namespace FormView +{ + public partial class FormMain : Form + { + private readonly IEmployeeLogic _LogicE; + private readonly ISubdivisionLogic _LogicS; + public FormMain(IEmployeeLogic logicE, ISubdivisionLogic logicS) + { + InitializeComponent(); + _LogicE = logicE; + _LogicS = logicS; + } + + private void DropComponents() + { + Controls.Clear(); + InitializeComponent(); + } + + private void LoadData() + { + try + { + DropComponents(); + + listBoxMany.SetTemplateString("Индификатор: {Id} Имя: {Fio} Опыт: {Experience} Подразделение: {Subdivision}", "{", "}"); + + var list = _LogicE.Read(null) ?? throw new Exception("Error on read"); + + for (int i = 0; i < list.Count; i++) + { + + for (int j = 0; j < 4; j++) + { + listBoxMany.FillProperty(list[i], i, GetPropertyName(j)); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private string GetPropertyName(int index) + { + + switch (index) + { + case 0: return "Subdivision"; + case 1: return "Id"; + case 2: return "Fio"; + case 3: return "Experience"; + default: return string.Empty; + } + } + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void CreateEmployerToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = Program.Container.Resolve(); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + + private void EditEmployerToolStripMenuItem_Click(object sender, EventArgs e) + { + var selectedEmployee = listBoxMany.GetObjectFromStr(); + if (selectedEmployee == null) + { + MessageBox.Show("Please select an employee from the list.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + var form = Program.Container.Resolve(); + form.Id = selectedEmployee.Id; + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + + private void DeleteEmployerToolStripMenuItem_Click(object sender, EventArgs e) + { + var selectedEmployee = listBoxMany.GetObjectFromStr(); + if (selectedEmployee == null) + { + MessageBox.Show("Please select an employee from the list.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (MessageBox.Show("Delete record", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _LogicE.Delete(new EmployeeBindingModel { Id = selectedEmployee.Id }); + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ExcelToolStripMenuItem_Click(object sender, EventArgs e) + { + if (_LogicE == null) + { + MessageBox.Show("Logic not initialized.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (excelTable == null) + { + MessageBox.Show("Excel object not initialized.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + string fileName = ""; + using (var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" }) + { + if (dialog.ShowDialog() == DialogResult.OK) + { + fileName = dialog.FileName; + MessageBox.Show("Success", "Ready", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + var selectedEmployee = listBoxMany.GetObjectFromStr(); + if (selectedEmployee == null) + { + MessageBox.Show("Select an item from the list.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + var emplList = _LogicE.Read(new EmployeeBindingModel { Id = selectedEmployee.Id }); + if (emplList == null || emplList.Count == 0) + { + MessageBox.Show("Could not find employee.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + var empl = emplList[0]; + + if (string.IsNullOrEmpty(empl.Posts)) + { + MessageBox.Show("No positions for the employee.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return; + } + + var posts = empl.Posts.Split(","); + var data = new string[1, Math.Min(posts.Length, 5)]; + for (int i = 0; i < data.GetLength(1); i++) + { + data[0, i] = posts[i]; + } + + var dataList = new List() { data }; + + if (string.IsNullOrEmpty(fileName)) + { + MessageBox.Show("File not selected.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + excelTable.CreateDoc(new WinFormsLibrary1.Models.TableConfig + { + FilePath = fileName, + Header = "Example", + Data = dataList + }); + } + + + private void WordToolStripMenuItem_Click(object sender, EventArgs e) + { + string fileName = ""; + using (var dialog = new SaveFileDialog { Filter = "docx|*.docx" }) + { + if (dialog.ShowDialog() == DialogResult.OK) + { + fileName = dialog.FileName.ToString(); + MessageBox.Show("Success", "Ready", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + var list = _LogicE.Read(null); + wordWithTable.CreateDoc(new ComponentDocumentWithTableHeaderDataConfig + { + FilePath = fileName, + Header = "Table:", + UseUnion = true, + ColumnsRowsWidth = new List<(int, int)> { (0, 5), (0, 5), (0, 10), (0, 10) }, + ColumnUnion = new List<(int StartIndex, int Count)> { (2, 2) }, + Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)> + { + (0, 0, "Id", "Id"), + (1, 0, "Fio", "Fio"), + (2, 0, "Work", ""), + (2, 1, "Subdivision", "Subdivision"), + (3, 1, "Experience", "Experience"), + }, + Data = list + }); + } + + private void PdfToolStripMenuItem_Click(object sender, EventArgs e) + { + string fileName = ""; + using (var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }) + { + if (dialog.ShowDialog() == DialogResult.OK) + { + fileName = dialog.FileName.ToString(); + MessageBox.Show("Success", "Ready", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + var listEmp = _LogicE.Read(null); + var listSubd = _LogicS.Read(null); + + var data = new Dictionary>(); + + foreach (var item in listSubd) + { + var listSorted = listEmp.Where(x => x.Subdivision.Equals(item.Name)); + + (int, int, int, int) x = ( + listSorted.Where(y => y.Experience >= 1 && y.Experience < 5).Count(), + listSorted.Where(y => y.Experience >= 5 && y.Experience < 10).Count(), + listSorted.Where(y => y.Experience >= 10 && y.Experience < 20).Count(), + listSorted.Where(y => y.Experience >= 20 && y.Experience < 30).Count()); + + data.Add(item.Name, new List { x.Item1, x.Item2, x.Item3, x.Item4 }); + } + + componentDiagramToPdf.CreateLineDiagram(fileName, "Chart", "Chart", data); + } + + private void DirectoryToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = Program.Container.Resolve(); + form.ShowDialog(); + } + } +} + + +//namespace FormView +//{ +// public partial class FormMain : Form +// { +// private readonly IEmployeeLogic _LogicE; +// private readonly ISubdivisionLogic _LogicS; + +// public FormMain(IEmployeeLogic logicE, ISubdivisionLogic logicS) +// { +// InitializeComponent(); +// _LogicE = logicE; +// _LogicS = logicS; +// } + +// private void DropComponents() +// { +// Controls.Clear(); +// InitializeComponent(); +// } + +// private void LoadData() +// { +// try +// { +// DropComponents(); + +// // Устанавливаем шаблон строки и символы начала и конца +// listBoxMany.SetTemplateString("{Subdivision} {Id} {Fio} {Experience}", "{", "}"); + +// var list = _LogicE.Read(null); +// if (list == null) throw new Exception("Error on read"); + +// for (int i = 0; i < list.Count; i++) +// { +// // Добавляем элементы в ListBoxMany +// listBoxMany.FillProperty(list[i], i, "Subdivision"); +// listBoxMany.FillProperty(list[i], i, "Id"); +// listBoxMany.FillProperty(list[i], i, "Fio"); +// listBoxMany.FillProperty(list[i], i, "Experience"); +// } +// } +// catch (Exception ex) +// { +// MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); +// } +// } + +// private void FormMain_Load(object sender, EventArgs e) +// { +// LoadData(); +// } + +// private void CreateEmployerToolStripMenuItem_Click(object sender, EventArgs e) +// { +// var form = Program.Container.Resolve(); +// if (form.ShowDialog() == DialogResult.OK) +// { +// LoadData(); +// } +// } + +// private void EditEmployerToolStripMenuItem_Click(object sender, EventArgs e) +// { +// var selectedEmployee = listBoxMany.GetObjectFromStr(); +// if (selectedEmployee == null) +// { +// MessageBox.Show("Please select an employee from the list.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); +// return; +// } +// var form = Program.Container.Resolve(); +// form.Id = Convert.ToInt32(listBoxMany.GetObjectFromStr().Id); +// if (form.ShowDialog() == DialogResult.OK) +// { +// LoadData(); +// } +// } + +// private void DeleteEmployerToolStripMenuItem_Click(object sender, EventArgs e) +// { +// if (MessageBox.Show("Delete record", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) +// { +// var ent = listBoxMany.GetObjectFromStr(); + +// try +// { +// int id = Convert.ToInt32(ent.Id); +// _LogicE.Delete(new EmployeeBindingModel { Id = id }); +// } +// catch (Exception ex) +// { +// MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); +// } +// LoadData(); +// } +// } + +// private void ExcelToolStripMenuItem_Click(object sender, EventArgs e) +// { +// //string fileName = ""; +// //using (var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" }) +// //{ +// // if (dialog.ShowDialog() == DialogResult.OK) +// // { +// // fileName = dialog.FileName.ToString(); +// // MessageBox.Show("Success", "Ready", MessageBoxButtons.OK, MessageBoxIcon.Information); +// // } +// //} +// //var ent = listBoxMany.GetObjectFromStr(); +// //var Empl = _LogicE.Read(new EmployeeBindingModel { Id = ent.Id })[0]; +// //var Data = new string[1, 5]; +// //int i = 0; +// //foreach (var post in Empl.Posts.Split(",")) +// //{ +// // Data[0, i++] = post; +// //} + +// //excelTable.CreateDoc(new WinFormsLibrary1.Models.TableConfig +// //{ +// // FilePath = fileName, +// // Header = "Example", +// // Data = new List { Data } +// //}); +// if (_LogicE == null) +// { +// MessageBox.Show("Logic not initialized.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); +// return; +// } + +// if (excelTable == null) +// { +// MessageBox.Show("Excel object not initialized.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); +// return; +// } + +// string fileName = ""; +// using (var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" }) +// { +// if (dialog.ShowDialog() == DialogResult.OK) +// { +// fileName = dialog.FileName; +// MessageBox.Show("Success", "Ready", MessageBoxButtons.OK, MessageBoxIcon.Information); +// } +// } + +// var selectedEmployee = listBoxMany.GetObjectFromStr(); +// if (selectedEmployee == null) +// { +// MessageBox.Show("Select an item from the list.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); +// return; +// } + +// var emplList = _LogicE.Read(new EmployeeBindingModel { Id = selectedEmployee.Id }); +// if (emplList == null || emplList.Count == 0) +// { +// MessageBox.Show("Could not find employee.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); +// return; +// } + +// var empl = emplList[0]; + +// if (string.IsNullOrEmpty(empl.Posts)) +// { +// MessageBox.Show("No positions for the employee.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); +// return; +// } + +// var posts = empl.Posts.Split(","); +// var data = new string[1, Math.Min(posts.Length, 5)]; +// for (int i = 0; i < data.GetLength(1); i++) +// { +// data[0, i] = posts[i]; +// } + +// var dataList = new List() { data }; + +// if (string.IsNullOrEmpty(fileName)) +// { +// MessageBox.Show("File not selected.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); +// return; +// } + +// excelTable.CreateDoc(new WinFormsLibrary1.Models.TableConfig +// { +// FilePath = fileName, +// Header = "Example", +// Data = dataList +// }); +// } + +// private void WordToolStripMenuItem_Click(object sender, EventArgs e) +// { +// string fileName = ""; +// using (var dialog = new SaveFileDialog { Filter = "docx|*.docx" }) +// { +// if (dialog.ShowDialog() == DialogResult.OK) +// { +// fileName = dialog.FileName.ToString(); +// MessageBox.Show("Success", "Ready", MessageBoxButtons.OK, MessageBoxIcon.Information); +// } +// } +// var list = _LogicE.Read(null); +// wordWithTable.CreateDoc(new ComponentDocumentWithTableHeaderDataConfig +// { +// FilePath = fileName, +// Header = "Table:", +// UseUnion = true, +// ColumnsRowsWidth = new List<(int, int)> { (0, 5), (0, 5), (0, 10), (0, 10) }, +// ColumnUnion = new List<(int StartIndex, int Count)> { (2, 2) }, +// Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)> +// { +// (0, 0, "Id", "Id"), +// (1, 0, "Fio", "Fio"), +// (2, 0, "Work", ""), +// (2, 1, "Subdivision", "Subdivision"), +// (3, 1, "Experience", "Experience"), +// }, +// Data = list +// }); +// } + +// /*private void PdfToolStripMenuItem_Click(object sender, EventArgs e) +// { +// string fileName = ""; +// using (var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }) +// { +// if (dialog.ShowDialog() == DialogResult.OK) +// { +// fileName = dialog.FileName.ToString(); +// MessageBox.Show("Success", "Ready", MessageBoxButtons.OK, MessageBoxIcon.Information); +// } +// } +// var listEmp = _LogicE.Read(null); +// var listSubd = _LogicS.Read(null); +// var Data = new Dictionary>(); +// foreach (var item in listSubd) +// { +// var listSorted = listEmp.Where(x => x.Subdivision.Equals(item.Name)); +// (int, int, int, int) x = ( +// listSorted.Where(y => y.Experience >= 1 && y.Experience < 5).Count(), +// listSorted.Where(y => y.Experience >= 5 && y.Experience < 10).Count(), +// listSorted.Where(y => y.Experience >= 10 && y.Experience < 20).Count(), +// listSorted.Where(y => y.Experience >= 20 && y.Experience < 30).Count()); +// Data.Add(item.Name, new() { ("1-5", x.Item1), ("5-10", x.Item2), ("10-20", x.Item3), ("20-30", x.Item4) }); +// } +// DiagramToPDF.CreateLineDiagram(new() +// { +// FilePath = fileName, +// Header = "Chart", +// ChartTitle = "Chart", +// Data = Data +// }); +// }*/ +// private void PdfToolStripMenuItem_Click(object sender, EventArgs e) +// { +// string fileName = ""; +// using (var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }) +// { +// if (dialog.ShowDialog() == DialogResult.OK) +// { +// fileName = dialog.FileName.ToString(); +// MessageBox.Show("Success", "Ready", MessageBoxButtons.OK, MessageBoxIcon.Information); +// } +// } + +// var listEmp = _LogicE.Read(null); +// var listSubd = _LogicS.Read(null); + +// // Преобразуем данные в нужный формат +// var data = new Dictionary>(); +// foreach (var item in listSubd) +// { +// var listSorted = listEmp.Where(x => x.Subdivision.Equals(item.Name)); +// var counts = new List +// { +// listSorted.Where(y => y.Experience >= 1 && y.Experience < 5).Count(), +// listSorted.Where(y => y.Experience >= 5 && y.Experience < 10).Count(), +// listSorted.Where(y => y.Experience >= 10 && y.Experience < 20).Count(), +// listSorted.Where(y => y.Experience >= 20 && y.Experience < 30).Count() +// }; +// data.Add(item.Name, counts); +// } + +// // Используем компонент DiagramToPDF для создания диаграммы +// componentDiagramToPdf.CreateLineDiagram(fileName, "Chart", "Chart", data); +// } + +// private void DirectoryToolStripMenuItem_Click(object sender, EventArgs e) +// { +// var form = Program.Container.Resolve(); +// form.ShowDialog(); +// } + +// } +//} \ No newline at end of file diff --git a/COP_9/FormView/FormMain.resx b/COP_9/FormView/FormMain.resx new file mode 100644 index 0000000..3d03b9f --- /dev/null +++ b/COP_9/FormView/FormMain.resx @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + 125, 17 + + + 316, 17 + + + 449, 17 + + \ No newline at end of file diff --git a/COP_9/FormView/FormMain1.Designer.cs b/COP_9/FormView/FormMain1.Designer.cs new file mode 100644 index 0000000..6b1360d --- /dev/null +++ b/COP_9/FormView/FormMain1.Designer.cs @@ -0,0 +1,169 @@ +using ComponentsLibraryNet60.DocumentWithTable; +using DocumentFormat.OpenXml.Spreadsheet; +using DocumentFormat.OpenXml.Wordprocessing; + +namespace FormView +{ + partial class FormMain1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + menuStrip = new MenuStrip(); + actionToolStripMenuItem = new ToolStripMenuItem(); + createEmployerCtrlAToolStripMenuItem = new ToolStripMenuItem(); + editEmployerCtrlUToolStripMenuItem = new ToolStripMenuItem(); + deleteEmployerCtrlDToolStripMenuItem = new ToolStripMenuItem(); + exelCtrlSToolStripMenuItem = new ToolStripMenuItem(); + wordCtrlTToolStripMenuItem = new ToolStripMenuItem(); + pdfCtrlCToolStripMenuItem = new ToolStripMenuItem(); + directoryToolStripMenuItem = new ToolStripMenuItem(); + excelTable = new WinFormsLibrary1.ExcelTable(components); + pdfDiagram = new Components.DiagramToPDF(components); + wordWithTable = new ComponentDocumentWithTableMultiHeaderWord(components); + customListBox = new Components.ListBoxMany(); + menuStrip.SuspendLayout(); + SuspendLayout(); + // + // menuStrip + // + menuStrip.ImageScalingSize = new Size(20, 20); + menuStrip.Items.AddRange(new ToolStripItem[] { actionToolStripMenuItem, directoryToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Padding = new Padding(5, 2, 0, 2); + menuStrip.Size = new Size(724, 24); + menuStrip.TabIndex = 1; + menuStrip.Text = "menuStrip1"; + // + // actionToolStripMenuItem + // + actionToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { createEmployerCtrlAToolStripMenuItem, editEmployerCtrlUToolStripMenuItem, deleteEmployerCtrlDToolStripMenuItem, exelCtrlSToolStripMenuItem, wordCtrlTToolStripMenuItem, pdfCtrlCToolStripMenuItem }); + actionToolStripMenuItem.Name = "actionToolStripMenuItem"; + actionToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.A; + actionToolStripMenuItem.Size = new Size(54, 20); + actionToolStripMenuItem.Text = "Action"; + // + // createEmployerCtrlAToolStripMenuItem + // + createEmployerCtrlAToolStripMenuItem.Name = "createEmployerCtrlAToolStripMenuItem"; + createEmployerCtrlAToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.A; + createEmployerCtrlAToolStripMenuItem.Size = new Size(203, 22); + createEmployerCtrlAToolStripMenuItem.Text = "Create Employer"; + createEmployerCtrlAToolStripMenuItem.Click += CreateEmployerToolStripMenuItem_Click; + // + // editEmployerCtrlUToolStripMenuItem + // + editEmployerCtrlUToolStripMenuItem.Name = "editEmployerCtrlUToolStripMenuItem"; + editEmployerCtrlUToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.U; + editEmployerCtrlUToolStripMenuItem.Size = new Size(203, 22); + editEmployerCtrlUToolStripMenuItem.Text = "Edit Employer"; + editEmployerCtrlUToolStripMenuItem.Click += EditEmployerToolStripMenuItem_Click_1; + // + // deleteEmployerCtrlDToolStripMenuItem + // + deleteEmployerCtrlDToolStripMenuItem.Name = "deleteEmployerCtrlDToolStripMenuItem"; + deleteEmployerCtrlDToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.D; + deleteEmployerCtrlDToolStripMenuItem.Size = new Size(203, 22); + deleteEmployerCtrlDToolStripMenuItem.Text = "Delete Employer"; + deleteEmployerCtrlDToolStripMenuItem.TextDirection = ToolStripTextDirection.Horizontal; + deleteEmployerCtrlDToolStripMenuItem.Click += DeleteEmployerToolStripMenuItem_Click_1; + // + // exelCtrlSToolStripMenuItem + // + exelCtrlSToolStripMenuItem.Name = "exelCtrlSToolStripMenuItem"; + exelCtrlSToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S; + exelCtrlSToolStripMenuItem.Size = new Size(203, 22); + exelCtrlSToolStripMenuItem.Text = "Exel"; + exelCtrlSToolStripMenuItem.Click += ExcelToolStripMenuItem_Click; + // + // wordCtrlTToolStripMenuItem + // + wordCtrlTToolStripMenuItem.Name = "wordCtrlTToolStripMenuItem"; + wordCtrlTToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.T; + wordCtrlTToolStripMenuItem.Size = new Size(203, 22); + wordCtrlTToolStripMenuItem.Text = "Word"; + wordCtrlTToolStripMenuItem.Click += WordToolStripMenuItem_Click; + // + // pdfCtrlCToolStripMenuItem + // + pdfCtrlCToolStripMenuItem.Name = "pdfCtrlCToolStripMenuItem"; + pdfCtrlCToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.C; + pdfCtrlCToolStripMenuItem.Size = new Size(203, 22); + pdfCtrlCToolStripMenuItem.Text = "Pdf"; + pdfCtrlCToolStripMenuItem.Click += PdfToolStripMenuItem_Click; + // + // directoryToolStripMenuItem + // + directoryToolStripMenuItem.Name = "directoryToolStripMenuItem"; + directoryToolStripMenuItem.Size = new Size(67, 20); + directoryToolStripMenuItem.Text = "Directory"; + directoryToolStripMenuItem.Click += DirectoryToolStripMenuItem_Click; + // + // customListBox + // + customListBox.Location = new Point(0, 26); + customListBox.Margin = new Padding(3, 2, 3, 2); + customListBox.Name = "customListBox"; + customListBox.SelectedIndex = -1; + customListBox.Size = new Size(724, 308); + customListBox.TabIndex = 2; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(724, 323); + Controls.Add(customListBox); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Margin = new Padding(3, 2, 3, 2); + Name = "FormMain"; + Text = "Zavod"; + Load += FormMain1_Load; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + private MenuStrip menuStrip; + private ToolStripMenuItem actionToolStripMenuItem; + private ToolStripMenuItem createEmployerCtrlAToolStripMenuItem; + private ToolStripMenuItem editEmployerCtrlUToolStripMenuItem; + private ToolStripMenuItem deleteEmployerCtrlDToolStripMenuItem; + private ToolStripMenuItem exelCtrlSToolStripMenuItem; + private ToolStripMenuItem wordCtrlTToolStripMenuItem; + private ToolStripMenuItem pdfCtrlCToolStripMenuItem; + private ToolStripMenuItem directoryToolStripMenuItem; + private Components.ListBoxMany customListBox; + private WinFormsLibrary1.ExcelTable excelTable; + private Components.DiagramToPDF pdfDiagram; + private ComponentsLibraryNet60.DocumentWithTable.ComponentDocumentWithTableMultiHeaderWord wordWithTable; + } +} diff --git a/COP_9/FormView/FormMain1.cs b/COP_9/FormView/FormMain1.cs new file mode 100644 index 0000000..539fc54 --- /dev/null +++ b/COP_9/FormView/FormMain1.cs @@ -0,0 +1,268 @@ +using ComponentsLibraryNet60.Models; +using EnterpriseContracts.BindingModels; +using EnterpriseContracts.BusinessLogicContracts; +using EnterpriseContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace FormView +{ + public partial class FormMain1 : Form + { + private readonly IEmployeeLogic _LogicE; + private readonly ISubdivisionLogic _LogicS; + public FormMain1(IEmployeeLogic logicE, ISubdivisionLogic logicS) + { + InitializeComponent(); + _LogicE = logicE; + _LogicS = logicS; + } + + private void DropComponents() + { + Controls.Clear(); + InitializeComponent(); + } + + private void LoadData() + { + try + { + DropComponents(); + + customListBox.SetTemplateString("Индификатор: {Id} Имя: {Fio} Опыт: {Experience} Подразделение: {Subdivision}", "{", "}"); + + var list = _LogicE.Read(null) ?? throw new Exception("Error on read"); + + for (int i = 0; i < list.Count; i++) + { + + for (int j = 0; j < 4; j++) + { + customListBox.FillProperty(list[i], i, GetPropertyName(j)); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private string GetPropertyName(int index) + { + + switch (index) + { + case 0: return "Subdivision"; + case 1: return "Id"; + case 2: return "Fio"; + case 3: return "Experience"; + default: return string.Empty; + } + } + + private void FormMain1_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void CreateEmployerToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = Program.Container.Resolve(); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + + private void EditEmployerToolStripMenuItem_Click_1(object sender, EventArgs e) + { + var selectedEmployee = customListBox.GetObjectFromStr(); + if (selectedEmployee == null) + { + MessageBox.Show("Please select an employee from the list.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + var form = Program.Container.Resolve(); + form.Id = selectedEmployee.Id; + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + + private void DeleteEmployerToolStripMenuItem_Click_1(object sender, EventArgs e) + { + var selectedEmployee = customListBox.GetObjectFromStr(); + if (selectedEmployee == null) + { + MessageBox.Show("Please select an employee from the list.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (MessageBox.Show("Delete record", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _LogicE.Delete(new EmployeeBindingModel { Id = selectedEmployee.Id }); + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ExcelToolStripMenuItem_Click(object sender, EventArgs e) + { + if (_LogicE == null) + { + MessageBox.Show("Logic not initialized.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (excelTable == null) + { + MessageBox.Show("Excel object not initialized.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + string fileName = ""; + using (var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" }) + { + if (dialog.ShowDialog() == DialogResult.OK) + { + fileName = dialog.FileName; + MessageBox.Show("Success", "Ready", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + var selectedEmployee = customListBox.GetObjectFromStr(); + if (selectedEmployee == null) + { + MessageBox.Show("Select an item from the list.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + var emplList = _LogicE.Read(new EmployeeBindingModel { Id = selectedEmployee.Id }); + if (emplList == null || emplList.Count == 0) + { + MessageBox.Show("Could not find employee.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + var empl = emplList[0]; + + if (string.IsNullOrEmpty(empl.Posts)) + { + MessageBox.Show("No positions for the employee.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return; + } + + var posts = empl.Posts.Split(","); + var data = new string[1, Math.Min(posts.Length, 5)]; + for (int i = 0; i < data.GetLength(1); i++) + { + data[0, i] = posts[i]; + } + + var dataList = new List() { data }; + + if (string.IsNullOrEmpty(fileName)) + { + MessageBox.Show("File not selected.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + excelTable.CreateDoc(new WinFormsLibrary1.Models.TableConfig + { + FilePath = fileName, + Header = "Example", + Data = dataList + }); + } + + private void WordToolStripMenuItem_Click(object sender, EventArgs e) + { + string fileName = ""; + using (var dialog = new SaveFileDialog { Filter = "docx|*.docx" }) + { + if (dialog.ShowDialog() == DialogResult.OK) + { + fileName = dialog.FileName.ToString(); + MessageBox.Show("Success", "Ready", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + var list = _LogicE.Read(null); + wordWithTable.CreateDoc(new ComponentDocumentWithTableHeaderDataConfig + { + FilePath = fileName, + Header = "Table:", + UseUnion = true, + ColumnsRowsWidth = new List<(int, int)> { (0, 5), (0, 5), (0, 10), (0, 10) }, + ColumnUnion = new List<(int StartIndex, int Count)> { (2, 2) }, + Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)> + { + (0, 0, "Id", "Id"), + (1, 0, "Fio", "Fio"), + (2, 0, "Work", ""), + (2, 1, "Subdivision", "Subdivision"), + (3, 1, "Experience", "Experience"), + }, + Data = list + }); + } + + private void PdfToolStripMenuItem_Click(object sender, EventArgs e) + { + string fileName = ""; + using (var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }) + { + if (dialog.ShowDialog() == DialogResult.OK) + { + fileName = dialog.FileName.ToString(); + MessageBox.Show("Success", "Ready", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + var listEmp = _LogicE.Read(null); + var listSubd = _LogicS.Read(null); + + var data = new Dictionary>(); + + foreach (var item in listSubd) + { + var listSorted = listEmp.Where(x => x.Subdivision.Equals(item.Name)); + + (int, int, int, int) x = ( + listSorted.Where(y => y.Experience >= 1 && y.Experience < 5).Count(), + listSorted.Where(y => y.Experience >= 5 && y.Experience < 10).Count(), + listSorted.Where(y => y.Experience >= 10 && y.Experience < 20).Count(), + listSorted.Where(y => y.Experience >= 20 && y.Experience < 30).Count()); + + data.Add(item.Name, new List { x.Item1, x.Item2, x.Item3, x.Item4 }); + } + + pdfDiagram.CreateLineDiagram(fileName, "Chart", "Chart", data); + } + + private void DirectoryToolStripMenuItem_Click(object sender, EventArgs e) + { + var form = Program.Container.Resolve(); + form.ShowDialog(); + } + } +} diff --git a/COP_9/FormView/FormMain1.resx b/COP_9/FormView/FormMain1.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/COP_9/FormView/FormMain1.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/COP_9/FormView/FormView.csproj b/COP_9/FormView/FormView.csproj new file mode 100644 index 0000000..503ee57 --- /dev/null +++ b/COP_9/FormView/FormView.csproj @@ -0,0 +1,29 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + \ No newline at end of file diff --git a/COP_9/FormView/Program.cs b/COP_9/FormView/Program.cs new file mode 100644 index 0000000..36d0c97 --- /dev/null +++ b/COP_9/FormView/Program.cs @@ -0,0 +1,45 @@ +using EnterpriseBusinessLogic.BusinessLogics; +using EnterpriseContracts.BusinessLogicContracts; +using EnterpriseContracts.StorageContracts; +using EnterpriseDataBaseImplement.Implements; +using Unity; +using Unity.Lifetime; + + + +namespace FormView +{ + internal static class Program + { + private static IUnityContainer container = null; + public static IUnityContainer Container { get { container ??= BuildUnityContainer; return container; } } + + [STAThread] + static void Main() + { + Application.SetHighDpiMode(HighDpiMode.SystemAware); + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(Container.Resolve()); + } + + private static IUnityContainer BuildUnityContainer + { + get + { + var currentContainer = new UnityContainer(); + + currentContainer.RegisterType(new HierarchicalLifetimeManager()); + currentContainer.RegisterType(new HierarchicalLifetimeManager()); + + currentContainer.RegisterType(new HierarchicalLifetimeManager()); + currentContainer.RegisterType(new HierarchicalLifetimeManager()); + + currentContainer.RegisterType(); + currentContainer.RegisterType(); + + return currentContainer; + } + } + } +} \ No newline at end of file diff --git a/COP_9/TestForm/TestForm.csproj b/COP_9/TestForm/TestForm.csproj index aa5e600..447ce39 100644 --- a/COP_9/TestForm/TestForm.csproj +++ b/COP_9/TestForm/TestForm.csproj @@ -8,6 +8,13 @@ enable + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + +