diff --git a/BuisnessLogic/BuisnessLogic.csproj b/BuisnessLogic/BuisnessLogic.csproj new file mode 100644 index 0000000..7a3c2c6 --- /dev/null +++ b/BuisnessLogic/BuisnessLogic.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/BuisnessLogic/DeliveryLogic.cs b/BuisnessLogic/DeliveryLogic.cs new file mode 100644 index 0000000..a76c2d2 --- /dev/null +++ b/BuisnessLogic/DeliveryLogic.cs @@ -0,0 +1,100 @@ +using Contracts.BindingModels; +using Contracts.BuisnessLogicsContracts; +using Contracts.SearchModels; +using Contracts.StorageContracts; +using Contracts.ViewModels; + +namespace BuisnessLogic +{ + public class DeliveryLogic : IDeliveryLogic + { + IDeliveryStorage _deliveryStorage; + + public DeliveryLogic(IDeliveryStorage deliveryStorage) + { + _deliveryStorage = deliveryStorage; + } + + public bool Create(DeliveryBindingModel model) + { + CheckModel(model); + if (_deliveryStorage.Insert(model) == null) + { + return false; + } + return true; + } + + public bool Delete(DeliveryBindingModel model) + { + CheckModel(model, false); + if (_deliveryStorage.Delete(model) == null) + { + return false; + } + return true; + } + + public DeliveryViewModel? ReadElement(DeliverySearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + var element = _deliveryStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + + public List? ReadList(DeliverySearchModel? model) + { + var list = model == null ? _deliveryStorage.GetFullList() : _deliveryStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + + public bool Update(DeliveryBindingModel model) + { + CheckModel(model); + if (_deliveryStorage.Update(model) == null) + { + return false; + } + return true; + } + + private void CheckModel(DeliveryBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.CourierFIO)) + { + throw new ArgumentNullException("Нет ФИО Курьера", nameof(model.CourierFIO)); + } + if (string.IsNullOrEmpty(model.Phone)) + { + throw new ArgumentNullException("Нет телефона офиса", nameof(model.Phone)); + } + if (string.IsNullOrEmpty(model.Image)) + { + throw new ArgumentNullException("Нет фото посылки", nameof(model.Image)); + } + if (string.IsNullOrEmpty(model.Type)) + { + throw new ArgumentNullException("Нет типа посылки", nameof(model.Type)); + } + } + } +} diff --git a/BuisnessLogic/TypeLogic.cs b/BuisnessLogic/TypeLogic.cs new file mode 100644 index 0000000..d1d6b35 --- /dev/null +++ b/BuisnessLogic/TypeLogic.cs @@ -0,0 +1,92 @@ +using Contracts.BindingModels; +using Contracts.BuisnessLogicsContracts; +using Contracts.SearchModels; +using Contracts.StorageContracts; +using Contracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BuisnessLogic +{ + public class TypeLogic : ITypeLogic + { + ITypeStorage _typeStorage; + + public TypeLogic(ITypeStorage typeStorage) + { + _typeStorage = typeStorage; + } + + public bool Create(TypeBindingModel model) + { + CheckModel(model); + if (_typeStorage.Insert(model) == null) + { + return false; + } + return true; + } + + public bool Delete(TypeBindingModel model) + { + CheckModel(model, false); + if (_typeStorage.Delete(model) == null) + { + return false; + } + return true; + } + + public TypeViewModel? ReadElement(TypeSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + var element = _typeStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + + public List? ReadList(TypeSearchModel? model) + { + var list = model == null ? _typeStorage.GetFullList() : _typeStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + + public bool Update(TypeBindingModel model) + { + CheckModel(model); + if (_typeStorage.Update(model) == null) + { + return false; + } + return true; + } + private void CheckModel(TypeBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.PostType)) + { + throw new ArgumentNullException("Тип не указан", nameof(model.PostType)); + } + } + } +} diff --git a/Contracts/BindingModels/DeliveryBindingModel.cs b/Contracts/BindingModels/DeliveryBindingModel.cs new file mode 100644 index 0000000..b263d40 --- /dev/null +++ b/Contracts/BindingModels/DeliveryBindingModel.cs @@ -0,0 +1,18 @@ +using DataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.BindingModels +{ + public class DeliveryBindingModel : IDeliveryModel + { + public int Id { get; set; } + public string CourierFIO { get; set; } = string.Empty; + public string Image { get; set; } = string.Empty; + public string Type { get; set; } = string.Empty; + public string Phone { get; set; } = string.Empty; + } +} diff --git a/Contracts/BindingModels/ITypeModel.cs b/Contracts/BindingModels/ITypeModel.cs new file mode 100644 index 0000000..c0b7b30 --- /dev/null +++ b/Contracts/BindingModels/ITypeModel.cs @@ -0,0 +1,15 @@ +using DataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.BindingModels +{ + public class TypeBindingModel : ITypeModel + { + public int Id { get; set; } + public string PostType { get; set; } = string.Empty; + } +} diff --git a/Contracts/BuisnessLogicsContracts/IDeliveryLogic.cs b/Contracts/BuisnessLogicsContracts/IDeliveryLogic.cs new file mode 100644 index 0000000..eec6e96 --- /dev/null +++ b/Contracts/BuisnessLogicsContracts/IDeliveryLogic.cs @@ -0,0 +1,20 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.BuisnessLogicsContracts +{ + public interface IDeliveryLogic + { + List? ReadList(DeliverySearchModel? model); + DeliveryViewModel? ReadElement(DeliverySearchModel model); + bool Create(DeliveryBindingModel model); + bool Update(DeliveryBindingModel model); + bool Delete(DeliveryBindingModel model); + } +} diff --git a/Contracts/BuisnessLogicsContracts/ITypeLogic.cs b/Contracts/BuisnessLogicsContracts/ITypeLogic.cs new file mode 100644 index 0000000..c916dc5 --- /dev/null +++ b/Contracts/BuisnessLogicsContracts/ITypeLogic.cs @@ -0,0 +1,20 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.BuisnessLogicsContracts +{ + public interface ITypeLogic + { + List? ReadList(TypeSearchModel? model); + TypeViewModel? ReadElement(TypeSearchModel model); + bool Create(TypeBindingModel model); + bool Update(TypeBindingModel model); + bool Delete(TypeBindingModel model); + } +} diff --git a/Contracts/Contracts.csproj b/Contracts/Contracts.csproj new file mode 100644 index 0000000..2e520d2 --- /dev/null +++ b/Contracts/Contracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Contracts/SearchModels/DeliverySearchModel.cs b/Contracts/SearchModels/DeliverySearchModel.cs new file mode 100644 index 0000000..9b46f63 --- /dev/null +++ b/Contracts/SearchModels/DeliverySearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.SearchModels +{ + public class DeliverySearchModel + { + public int? Id { get; set; } + } +} diff --git a/Contracts/SearchModels/TypeSearchModel.cs b/Contracts/SearchModels/TypeSearchModel.cs new file mode 100644 index 0000000..825496a --- /dev/null +++ b/Contracts/SearchModels/TypeSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.SearchModels +{ + public class TypeSearchModel + { + public int? Id { get; set; } + } +} diff --git a/Contracts/StorageContracts/IDeliveryStorage.cs b/Contracts/StorageContracts/IDeliveryStorage.cs new file mode 100644 index 0000000..a2781bb --- /dev/null +++ b/Contracts/StorageContracts/IDeliveryStorage.cs @@ -0,0 +1,21 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.StorageContracts +{ + public interface IDeliveryStorage + { + List GetFullList(); + List GetFilteredList(DeliverySearchModel model); + DeliveryViewModel? GetElement(DeliverySearchModel model); + DeliveryViewModel? Insert(DeliveryBindingModel model); + DeliveryViewModel? Update(DeliveryBindingModel model); + DeliveryViewModel? Delete(DeliveryBindingModel model); + } +} diff --git a/Contracts/StorageContracts/ITypeStorage.cs b/Contracts/StorageContracts/ITypeStorage.cs new file mode 100644 index 0000000..d3a2fac --- /dev/null +++ b/Contracts/StorageContracts/ITypeStorage.cs @@ -0,0 +1,21 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.StorageContracts +{ + public interface ITypeStorage + { + List GetFullList(); + List GetFilteredList(TypeSearchModel model); + TypeViewModel? GetElement(TypeSearchModel model); + TypeViewModel? Insert(TypeBindingModel model); + TypeViewModel? Update(TypeBindingModel model); + TypeViewModel? Delete(TypeBindingModel model); + } +} diff --git a/Contracts/ViewModels/DeliveryViewModel.cs b/Contracts/ViewModels/DeliveryViewModel.cs new file mode 100644 index 0000000..0dcbe59 --- /dev/null +++ b/Contracts/ViewModels/DeliveryViewModel.cs @@ -0,0 +1,18 @@ +using DataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.ViewModels +{ + public class DeliveryViewModel : IDeliveryModel + { + public int Id { get; set; } + public string CourierFIO { get; set; } = string.Empty; + public string Image { get; set; } = string.Empty; + public string Type { get; set; } = string.Empty; + public string Phone { get; set; } = string.Empty; + } +} diff --git a/Contracts/ViewModels/TypeViewModel.cs b/Contracts/ViewModels/TypeViewModel.cs new file mode 100644 index 0000000..0f3224c --- /dev/null +++ b/Contracts/ViewModels/TypeViewModel.cs @@ -0,0 +1,15 @@ +using DataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.ViewModels +{ + public class TypeViewModel : ITypeModel + { + public int Id { get; set; } + public string PostType { get; set; } = string.Empty; + } +} diff --git a/DataLayer/DataLayer.csproj b/DataLayer/DataLayer.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/DataLayer/DataLayer.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/DataLayer/Models/Delivery.cs b/DataLayer/Models/Delivery.cs new file mode 100644 index 0000000..6e01c54 --- /dev/null +++ b/DataLayer/Models/Delivery.cs @@ -0,0 +1,7 @@ +namespace DataLayer +{ + public class Class1 + { + + } +} diff --git a/DataModels/DataModels.csproj b/DataModels/DataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/DataModels/DataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/DataModels/Models/Fix.cs b/DataModels/Models/Fix.cs new file mode 100644 index 0000000..ab281cd --- /dev/null +++ b/DataModels/Models/Fix.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataModels.Models +{ + public class Fix + { + public int Id { get; set; } + public string CourierFIO { get; set; } = string.Empty; + public string Phone { get; set; } = string.Empty; + public string Type { get; set; } = string.Empty; + + + + } +} diff --git a/DataModels/Models/IDeliveryModel.cs b/DataModels/Models/IDeliveryModel.cs new file mode 100644 index 0000000..81ac844 --- /dev/null +++ b/DataModels/Models/IDeliveryModel.cs @@ -0,0 +1,10 @@ +namespace DataModels.Models +{ + public interface IDeliveryModel + { + public string CourierFIO { get; } + public string Image { get; } + public string Type { get; } + public string Phone { get; } + } +} diff --git a/DataModels/Models/ITypeModel.cs b/DataModels/Models/ITypeModel.cs new file mode 100644 index 0000000..b356fd9 --- /dev/null +++ b/DataModels/Models/ITypeModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataModels.Models +{ + public interface ITypeModel + { + public string PostType { get; } + } +} diff --git a/DatabaseImplements/DatabaseImplements.csproj b/DatabaseImplements/DatabaseImplements.csproj new file mode 100644 index 0000000..fb6d462 --- /dev/null +++ b/DatabaseImplements/DatabaseImplements.csproj @@ -0,0 +1,28 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + diff --git a/DatabaseImplements/DeliveryDatabase.cs b/DatabaseImplements/DeliveryDatabase.cs new file mode 100644 index 0000000..6661eb6 --- /dev/null +++ b/DatabaseImplements/DeliveryDatabase.cs @@ -0,0 +1,24 @@ +using DatabaseImplements.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseImplements +{ + public class DeliveryDataBase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS02;Initial Catalog=DeliveryApp;Integrated Security=True;MultipleActiveResultSets=True;TrustServerCertificate=True"); + } + base.OnConfiguring(optionsBuilder); + } + public virtual DbSet Deliverys { set; get; } + public virtual DbSet Types { set; get; } + } +} diff --git a/DatabaseImplements/Implements/DeliveryStorage.cs b/DatabaseImplements/Implements/DeliveryStorage.cs new file mode 100644 index 0000000..58aedb9 --- /dev/null +++ b/DatabaseImplements/Implements/DeliveryStorage.cs @@ -0,0 +1,111 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.StorageContracts; +using Contracts.ViewModels; +using DatabaseImplements.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseImplements.Implements +{ + public class DeliveryStorage : IDeliveryStorage + { + public DeliveryViewModel? Delete(DeliveryBindingModel model) + { + using var context = new DeliveryDataBase(); + var element = context.Deliverys.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Deliverys.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public DeliveryViewModel? GetElement(DeliverySearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new DeliveryDataBase(); + return context.Deliverys.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } + + public List GetFilteredList(DeliverySearchModel model) + { + using var context = new DeliveryDataBase(); + return context.Deliverys + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new DeliveryDataBase(); + return context.Deliverys + .Select(x => x.GetViewModel) + .ToList(); + } + + public DeliveryViewModel? Insert(DeliveryBindingModel model) + { + using var context = new DeliveryDataBase(); + using var transaction = context.Database.BeginTransaction(); + { + try + { + var newDl = Delivery.Create(model); + if (newDl == null) + { + transaction.Rollback(); + return null; + } + context.Deliverys.Add(newDl); + + context.SaveChanges(); + context.Database.CommitTransaction(); + + return newDl.GetViewModel; + } + catch (Exception) + { + transaction.Rollback(); + return null; + } + } + } + + public DeliveryViewModel? Update(DeliveryBindingModel model) + { + using var context = new DeliveryDataBase(); + using var transaction = context.Database.BeginTransaction(); + { + try + { + var dl = context.Deliverys.FirstOrDefault(x => x.Id == model.Id); + if (dl == null) + { + transaction.Rollback(); + return null; + } + dl.Update(model); + + context.SaveChanges(); + context.Database.CommitTransaction(); + + return dl.GetViewModel; + } + catch (Exception) + { + transaction.Rollback(); + return null; + } + } + } + } +} diff --git a/DatabaseImplements/Implements/TypeStorage.cs b/DatabaseImplements/Implements/TypeStorage.cs new file mode 100644 index 0000000..3656e87 --- /dev/null +++ b/DatabaseImplements/Implements/TypeStorage.cs @@ -0,0 +1,111 @@ +using Contracts.BindingModels; +using Contracts.SearchModels; +using Contracts.StorageContracts; +using Contracts.ViewModels; +using DatabaseImplements.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseImplements.Implements +{ + public class TypeStorage : ITypeStorage + { + public TypeViewModel? Delete(TypeBindingModel model) + { + using var context = new DeliveryDataBase(); + var element = context.Types.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Types.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public TypeViewModel? GetElement(TypeSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new DeliveryDataBase(); + return context.Types.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } + + public List GetFilteredList(TypeSearchModel model) + { + using var context = new DeliveryDataBase(); + return context.Types + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new DeliveryDataBase(); + return context.Types + .Select(x => x.GetViewModel) + .ToList(); + } + + public TypeViewModel? Insert(TypeBindingModel model) + { + using var context = new DeliveryDataBase(); + using var transaction = context.Database.BeginTransaction(); + { + try + { + var newTp = Models.Type.Create(model); + if (newTp == null) + { + transaction.Rollback(); + return null; + } + context.Types.Add(newTp); + + context.SaveChanges(); + context.Database.CommitTransaction(); + + return newTp.GetViewModel; + } + catch (Exception) + { + transaction.Rollback(); + return null; + } + } + } + + public TypeViewModel? Update(TypeBindingModel model) + { + using var context = new DeliveryDataBase(); + using var transaction = context.Database.BeginTransaction(); + { + try + { + var tp = context.Types.FirstOrDefault(x => x.Id == model.Id); + if (tp == null) + { + transaction.Rollback(); + return null; + } + tp.Update(model); + + context.SaveChanges(); + context.Database.CommitTransaction(); + + return tp.GetViewModel; + } + catch (Exception) + { + transaction.Rollback(); + return null; + } + } + } + } +} diff --git a/DatabaseImplements/Migrations/20241022162407_InitialCreate.Designer.cs b/DatabaseImplements/Migrations/20241022162407_InitialCreate.Designer.cs new file mode 100644 index 0000000..d6cdf0c --- /dev/null +++ b/DatabaseImplements/Migrations/20241022162407_InitialCreate.Designer.cs @@ -0,0 +1,75 @@ +// +using DatabaseImplements; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DatabaseImplements.Migrations +{ + [DbContext(typeof(DeliveryDataBase))] + [Migration("20241022162407_InitialCreate")] + partial class InitialCreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DatabaseImplements.Models.Delivery", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CourierFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Image") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Phone") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Type") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Deliverys"); + }); + + modelBuilder.Entity("DatabaseImplements.Models.Type", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PostType") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Types"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DatabaseImplements/Migrations/20241022162407_InitialCreate.cs b/DatabaseImplements/Migrations/20241022162407_InitialCreate.cs new file mode 100644 index 0000000..73c4a39 --- /dev/null +++ b/DatabaseImplements/Migrations/20241022162407_InitialCreate.cs @@ -0,0 +1,53 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace DatabaseImplements.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Deliverys", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + CourierFIO = table.Column(type: "nvarchar(max)", nullable: false), + Phone = table.Column(type: "nvarchar(max)", nullable: false), + Image = table.Column(type: "nvarchar(max)", nullable: false), + Type = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Deliverys", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Types", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + PostType = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Types", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Deliverys"); + + migrationBuilder.DropTable( + name: "Types"); + } + } +} diff --git a/DatabaseImplements/Migrations/DeliveryDataBaseModelSnapshot.cs b/DatabaseImplements/Migrations/DeliveryDataBaseModelSnapshot.cs new file mode 100644 index 0000000..7970760 --- /dev/null +++ b/DatabaseImplements/Migrations/DeliveryDataBaseModelSnapshot.cs @@ -0,0 +1,72 @@ +// +using DatabaseImplements; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace DatabaseImplements.Migrations +{ + [DbContext(typeof(DeliveryDataBase))] + partial class DeliveryDataBaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("DatabaseImplements.Models.Delivery", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CourierFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Image") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Phone") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Type") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Deliverys"); + }); + + modelBuilder.Entity("DatabaseImplements.Models.Type", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PostType") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Types"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DatabaseImplements/Models/Delivery.cs b/DatabaseImplements/Models/Delivery.cs new file mode 100644 index 0000000..46884f1 --- /dev/null +++ b/DatabaseImplements/Models/Delivery.cs @@ -0,0 +1,51 @@ +using Contracts.BindingModels; +using Contracts.ViewModels; +using DataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseImplements.Models +{ + public class Delivery : IDeliveryModel + { + public int Id { get; private set; } + [Required] + public string CourierFIO { get; private set; } = string.Empty; + [Required] + public string Phone { get; private set; } = string.Empty; + [Required] + public string Image { get; private set; } = string.Empty; + [Required] + public string Type { get; private set; } = string.Empty; + public static Delivery? Create(DeliveryBindingModel model) + { + return new Delivery() + { + Id = model.Id, + CourierFIO = model.CourierFIO, + Image = model.Image, + Phone = model.Phone, + Type = model.Type, + }; + } + public void Update(DeliveryBindingModel model) + { + CourierFIO = model.CourierFIO; + Image = model.Image; + Phone = model.Phone; + Type = model.Type; + } + public DeliveryViewModel GetViewModel => new() + { + Id = Id, + CourierFIO = CourierFIO, + Image = Image, + Phone = Phone, + Type = Type, + }; + } +} diff --git a/DatabaseImplements/Models/Type.cs b/DatabaseImplements/Models/Type.cs new file mode 100644 index 0000000..ff2893f --- /dev/null +++ b/DatabaseImplements/Models/Type.cs @@ -0,0 +1,37 @@ +using Contracts.BindingModels; +using Contracts.ViewModels; +using DataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseImplements.Models +{ + public class Type : ITypeModel + { + public int Id { get; private set; } + [Required] + public string PostType { get; private set; } = string.Empty; + public static Type? Create(TypeBindingModel model) + { + return new Type() + { + Id = model.Id, + PostType = model.PostType, + }; + } + + public void Update(TypeBindingModel model) + { + PostType = model.PostType; + } + public TypeViewModel GetViewModel => new() + { + Id = Id, + PostType = PostType, + }; + } +} diff --git a/DeliveryApp.sln b/DeliveryApp.sln new file mode 100644 index 0000000..8ef8638 --- /dev/null +++ b/DeliveryApp.sln @@ -0,0 +1,49 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34714.143 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DeliveryApp", "DeliveryApp\DeliveryApp.csproj", "{95BE9CF8-06E8-4A97-91D2-390B4DCC6F5B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BuisnessLogic", "BuisnessLogic\BuisnessLogic.csproj", "{435AEE3E-FD12-452D-9895-27A8F0489405}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contracts", "Contracts\Contracts.csproj", "{83B5614E-215C-4B87-AF7D-D2E0ED781B2D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataModels", "DataModels\DataModels.csproj", "{268CE725-6E11-4421-91F5-BBCE7B2DFF15}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DatabaseImplements", "DatabaseImplements\DatabaseImplements.csproj", "{AE946053-9269-4DCD-A71E-F5B1E570CFD9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {95BE9CF8-06E8-4A97-91D2-390B4DCC6F5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {95BE9CF8-06E8-4A97-91D2-390B4DCC6F5B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {95BE9CF8-06E8-4A97-91D2-390B4DCC6F5B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {95BE9CF8-06E8-4A97-91D2-390B4DCC6F5B}.Release|Any CPU.Build.0 = Release|Any CPU + {435AEE3E-FD12-452D-9895-27A8F0489405}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {435AEE3E-FD12-452D-9895-27A8F0489405}.Debug|Any CPU.Build.0 = Debug|Any CPU + {435AEE3E-FD12-452D-9895-27A8F0489405}.Release|Any CPU.ActiveCfg = Release|Any CPU + {435AEE3E-FD12-452D-9895-27A8F0489405}.Release|Any CPU.Build.0 = Release|Any CPU + {83B5614E-215C-4B87-AF7D-D2E0ED781B2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {83B5614E-215C-4B87-AF7D-D2E0ED781B2D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {83B5614E-215C-4B87-AF7D-D2E0ED781B2D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {83B5614E-215C-4B87-AF7D-D2E0ED781B2D}.Release|Any CPU.Build.0 = Release|Any CPU + {268CE725-6E11-4421-91F5-BBCE7B2DFF15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {268CE725-6E11-4421-91F5-BBCE7B2DFF15}.Debug|Any CPU.Build.0 = Debug|Any CPU + {268CE725-6E11-4421-91F5-BBCE7B2DFF15}.Release|Any CPU.ActiveCfg = Release|Any CPU + {268CE725-6E11-4421-91F5-BBCE7B2DFF15}.Release|Any CPU.Build.0 = Release|Any CPU + {AE946053-9269-4DCD-A71E-F5B1E570CFD9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AE946053-9269-4DCD-A71E-F5B1E570CFD9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AE946053-9269-4DCD-A71E-F5B1E570CFD9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AE946053-9269-4DCD-A71E-F5B1E570CFD9}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6B20F53F-C289-4B79-BE0E-6380B03F4E4D} + EndGlobalSection +EndGlobal diff --git a/DeliveryApp/DeliveryApp.csproj b/DeliveryApp/DeliveryApp.csproj new file mode 100644 index 0000000..862ccac --- /dev/null +++ b/DeliveryApp/DeliveryApp.csproj @@ -0,0 +1,54 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + tlbimp + 7 + 8 + 00020905-0000-0000-c000-000000000046 + 0 + false + true + + + + + + + + + + + + + + + + + + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + \ No newline at end of file diff --git a/DeliveryApp/Form1.Designer.cs b/DeliveryApp/Form1.Designer.cs new file mode 100644 index 0000000..4c29589 --- /dev/null +++ b/DeliveryApp/Form1.Designer.cs @@ -0,0 +1,171 @@ +namespace DeliveryApp +{ + partial class Form1 + { + /// + /// 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(); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); + toolStrip1 = new ToolStrip(); + toolStripType = new ToolStripButton(); + toolStripPdf = new ToolStripButton(); + toolStripWord = new ToolStripButton(); + toolStripExcel = new ToolStripButton(); + toolStripDropDownButton1 = new ToolStripDropDownButton(); + добавитьToolStripMenuItem = new ToolStripMenuItem(); + редактироватьToolStripMenuItem = new ToolStripMenuItem(); + удалитьToolStripMenuItem = new ToolStripMenuItem(); + listOutputComponent1 = new CreateVisualComponent.ListOutputComponent(); + tableComponent1 = new Controls.TableComponent(components); + imageWord1 = new CustomComponents.NonViewComponents.ImageWord(components); + excelDiagram1 = new NotVisualComponent.ExcelDiagram(components); + toolStrip1.SuspendLayout(); + SuspendLayout(); + // + // toolStrip1 + // + toolStrip1.ImageScalingSize = new Size(20, 20); + toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripType, toolStripPdf, toolStripWord, toolStripExcel, toolStripDropDownButton1 }); + toolStrip1.Location = new Point(0, 0); + toolStrip1.Name = "toolStrip1"; + toolStrip1.Size = new Size(853, 27); + toolStrip1.TabIndex = 1; + toolStrip1.Text = "toolStrip1"; + // + // toolStripType + // + toolStripType.DisplayStyle = ToolStripItemDisplayStyle.Text; + toolStripType.Image = (Image)resources.GetObject("toolStripType.Image"); + toolStripType.ImageTransparentColor = Color.Magenta; + toolStripType.Name = "toolStripType"; + toolStripType.Size = new Size(106, 24); + toolStripType.Text = "Форма типов"; + toolStripType.Click += toolStripType_Click; + // + // toolStripPdf + // + toolStripPdf.DisplayStyle = ToolStripItemDisplayStyle.Text; + toolStripPdf.Image = (Image)resources.GetObject("toolStripPdf.Image"); + toolStripPdf.ImageTransparentColor = Color.Magenta; + toolStripPdf.Name = "toolStripPdf"; + toolStripPdf.Size = new Size(83, 24); + toolStripPdf.Text = "Отчет пдф"; + toolStripPdf.Click += toolStripPdf_Click; + // + // toolStripWord + // + toolStripWord.DisplayStyle = ToolStripItemDisplayStyle.Text; + toolStripWord.Image = (Image)resources.GetObject("toolStripWord.Image"); + toolStripWord.ImageTransparentColor = Color.Magenta; + toolStripWord.Name = "toolStripWord"; + toolStripWord.Size = new Size(90, 24); + toolStripWord.Text = "Отчет ворд"; + toolStripWord.Click += toolStripWord_Click; + // + // toolStripExcel + // + toolStripExcel.DisplayStyle = ToolStripItemDisplayStyle.Text; + toolStripExcel.Image = (Image)resources.GetObject("toolStripExcel.Image"); + toolStripExcel.ImageTransparentColor = Color.Magenta; + toolStripExcel.Name = "toolStripExcel"; + toolStripExcel.Size = new Size(101, 24); + toolStripExcel.Text = "Отчет эксель"; + toolStripExcel.Click += toolStripExcel_Click; + // + // toolStripDropDownButton1 + // + toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text; + toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { добавитьToolStripMenuItem, редактироватьToolStripMenuItem, удалитьToolStripMenuItem }); + toolStripDropDownButton1.Image = (Image)resources.GetObject("toolStripDropDownButton1.Image"); + toolStripDropDownButton1.ImageTransparentColor = Color.Magenta; + toolStripDropDownButton1.Name = "toolStripDropDownButton1"; + toolStripDropDownButton1.Size = new Size(193, 24); + toolStripDropDownButton1.Text = "Управление доставками"; + // + // добавитьToolStripMenuItem + // + добавитьToolStripMenuItem.Name = "добавитьToolStripMenuItem"; + добавитьToolStripMenuItem.Size = new Size(224, 26); + добавитьToolStripMenuItem.Text = "Добавить"; + добавитьToolStripMenuItem.Click += добавитьToolStripMenuItem_Click; + // + // редактироватьToolStripMenuItem + // + редактироватьToolStripMenuItem.Name = "редактироватьToolStripMenuItem"; + редактироватьToolStripMenuItem.Size = new Size(224, 26); + редактироватьToolStripMenuItem.Text = "Редактировать"; + редактироватьToolStripMenuItem.Click += редактироватьToolStripMenuItem_Click; + // + // удалитьToolStripMenuItem + // + удалитьToolStripMenuItem.Name = "удалитьToolStripMenuItem"; + удалитьToolStripMenuItem.Size = new Size(224, 26); + удалитьToolStripMenuItem.Text = "Удалить"; + удалитьToolStripMenuItem.Click += удалитьToolStripMenuItem_Click; + // + // listOutputComponent1 + // + listOutputComponent1.Dock = DockStyle.Fill; + listOutputComponent1.Location = new Point(0, 27); + listOutputComponent1.Name = "listOutputComponent1"; + listOutputComponent1.Size = new Size(853, 423); + listOutputComponent1.TabIndex = 2; + // + // Form1 + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(853, 450); + Controls.Add(listOutputComponent1); + Controls.Add(toolStrip1); + KeyPreview = true; + Name = "Form1"; + Text = "FormMain"; + Load += Form1_Load; + KeyDown += OnKeyPressed; + toolStrip1.ResumeLayout(false); + toolStrip1.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + private ToolStrip toolStrip1; + private ToolStripButton toolStripType; + private CreateVisualComponent.ListOutputComponent listOutputComponent1; + private ToolStripButton toolStripPdf; + private ToolStripButton toolStripWord; + private ToolStripButton toolStripExcel; + private Controls.TableComponent tableComponent1; + private CustomComponents.NonViewComponents.ImageWord imageWord1; + private NotVisualComponent.ExcelDiagram excelDiagram1; + private ToolStripDropDownButton toolStripDropDownButton1; + private ToolStripMenuItem добавитьToolStripMenuItem; + private ToolStripMenuItem редактироватьToolStripMenuItem; + private ToolStripMenuItem удалитьToolStripMenuItem; + } +} diff --git a/DeliveryApp/Form1.cs b/DeliveryApp/Form1.cs new file mode 100644 index 0000000..b58d657 --- /dev/null +++ b/DeliveryApp/Form1.cs @@ -0,0 +1,339 @@ +using Contracts.BindingModels; +using Contracts.BuisnessLogicsContracts; +using Contracts.ViewModels; +using Controls.Models; +using CreateVisualComponent; +using CustomComponents.NonViewComponents.SupportClasses; +using DatabaseImplements.Models; +using DataModels.Models; +using DocumentFormat.OpenXml.Spreadsheet; +using MigraDoc.DocumentObjectModel; +using MigraDoc.Rendering; +using NotVisualComponent.Models; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Windows.Forms; +using Word = Microsoft.Office.Interop.Word; + +namespace DeliveryApp +{ + public partial class Form1 : Form + { + private readonly IDeliveryLogic _deliveryLogic; + private readonly ITypeLogic _typeLogic; + public Form1(IDeliveryLogic deliveryLogic, ITypeLogic typeLogic) + { + _deliveryLogic = deliveryLogic; + _typeLogic = typeLogic; + InitializeComponent(); + ColumnsConfiguratoin columnsConfiguratoin = new ColumnsConfiguratoin(); + columnsConfiguratoin.Columns.Add(new ColumnConfig + { + ColumnName = "Id", + Width = 10, + Visible = false, + PropertyObject = "Id" + }); + columnsConfiguratoin.Columns.Add(new ColumnConfig + { + ColumnName = "", + Width = 400, + Visible = true, + PropertyObject = "CourierFIO" + }); + columnsConfiguratoin.Columns.Add(new ColumnConfig + { + ColumnName = " ", + Width = 250, + Visible = true, + PropertyObject = "Type" + }); + columnsConfiguratoin.Columns.Add(new ColumnConfig + { + ColumnName = "", + Width = 200, + Visible = true, + PropertyObject = "Phone" + }); + listOutputComponent1.ConfigColumn(columnsConfiguratoin); + } + private void Form1_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + listOutputComponent1.ClearDataGrid(); + try + { + var deliverys = _deliveryLogic.ReadList(null); + if (deliverys == null) + { + return; + } + int k = -1; + foreach (var delivery in deliverys) + { + k++; + for (int i = 0; i < 4; i++) + { + listOutputComponent1.AddItem(delivery, k, i); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void AddElement() + { + var service = Program.ServiceProvider?.GetService(typeof(FormDelivery)); + if (!(service is FormDelivery form)) + { + return; + } + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + private void UpdateElement() + { + var service = Program.ServiceProvider?.GetService(typeof(FormDelivery)); + if (service is FormDelivery form) + { + var selectedDelivery = listOutputComponent1.GetSelectedObjectInRow(); + if (selectedDelivery == null) + { + MessageBox.Show(" !", " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + form.Id = selectedDelivery.Id; + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void DeleteElement() + { + if (MessageBox.Show(" ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + + var selectedDelivery = listOutputComponent1.GetSelectedObjectInRow(); + int id = Convert.ToInt32(selectedDelivery.Id); + try + { + _deliveryLogic.Delete(new DeliveryBindingModel { Id = id }); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + LoadData(); + } + + private void toolStripType_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormType)); + if (!(service is FormType form)) + { + return; + } + + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + + private void toolStripDelivery_Click(object sender, EventArgs e) + { + AddElement(); + } + private void toolStripPdf_Click(object sender, EventArgs e) + { + CreatePDF(); + } + private void CreatePDF() + { + Document document = new Document(); + Section section = document.AddSection(); + Paragraph paragraph = section.AddParagraph(); + PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(); + pdfRenderer.Document = document; + pdfRenderer.RenderDocument(); + using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + pdfRenderer.PdfDocument.Save(dialog.FileName); + List columns = new List() + { + new ColumnInfo("Id","Id",50), + new ColumnInfo("CourierFIO","",100), + new ColumnInfo("Phone","",100), + new ColumnInfo("Type","",75), + + }; + List mergeCells = new List() + { + new Controls.Models.MergeCells("", new int[] {0,3,4}), + }; + try + { + var list = _deliveryLogic.ReadList(null); + if (list == null) + { + return; + } + List dm = new List(); + foreach (var cell in list) + { + dm.Add( + new Fix() + { + Phone = cell.Phone, + Id = cell.Id, + CourierFIO = cell.CourierFIO, + Type = cell.Type, + }); + } + tableComponent1.CreateTable(dialog.FileName, "", mergeCells, columns, dm); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + } + + private void OnKeyPressed(object sender, KeyEventArgs e) + { + if (e.Control) + { + switch (e.KeyCode) + { + case Keys.A: + AddElement(); + break; + case Keys.U: + UpdateElement(); + break; + case Keys.D: + DeleteElement(); + break; + case Keys.S: + CreateWord(); + break; + case Keys.T: + CreatePDF(); + break; + case Keys.C: + CreateExcel(); + break; + default: break; + } + } + } + private void toolStripWord_Click(object sender, EventArgs e) + { + CreateWord(); + } + private void CreateWord() + { + var wordApp = new Word.Application(); + var document = wordApp.Documents.Add(); + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + List> prg = new List>(); + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + var list = _deliveryLogic.ReadList(null); + if (list == null) + { + return; + } + foreach (var cell in list) + { + var paragraph = document.Paragraphs.Add(); + paragraph.Range.Text = $" :{cell.Id}. :{cell.Type}"; + paragraph.Range.Font.Size = 24; + paragraph.Range.Font.Bold = 1; + paragraph.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter; + paragraph.Range.InsertParagraphAfter(); + prg.Add(new Tuple($" :{cell.Id}. :{cell.Type}", new DocImage[] { new DocImage { Path = cell.Image, Height = 200, Width = 200 } })); + } + document.SaveAs2(dialog.FileName); + wordApp.Quit(); + foreach (var cell in prg) + { + imageWord1.AddImages(dialog.FileName, cell.Item1, cell.Item2); + } + + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " docx", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void toolStripExcel_Click(object sender, EventArgs e) + { + CreateExcel(); + } + private void CreateExcel() + { + using var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + var list = _deliveryLogic.ReadList(null); + Dictionary> data = new Dictionary>(); + if (list == null) + { + return; + } + List<(string Name, double Value)> smth = new List<(string Name, double Value)>(); + Dictionary dt = new Dictionary(); + foreach (var cell in list) + { + if (dt.ContainsKey(cell.Type)) + { + dt[cell.Type]++; + continue; + } + dt.Add(cell.Type, 1); + } + foreach (var f in dt) + { + smth.Add(new(f.Key, f.Value)); + } + data.Add("Series 1", smth); + ChartConfig conf = new ChartConfig { ChartTitle = " ", FilePath = dialog.FileName, Header = "Chart", LegendLocation = NotVisualComponent.Models.Location.Top, Data = data }; + excelDiagram1.CreateDoc(conf); + } + } + + private void ToolStripMenuItem_Click(object sender, EventArgs e) + { + AddElement(); + } + + private void ToolStripMenuItem_Click(object sender, EventArgs e) + { + UpdateElement(); + } + + private void ToolStripMenuItem_Click(object sender, EventArgs e) + { + DeleteElement(); + } + } +} diff --git a/DeliveryApp/Form1.resx b/DeliveryApp/Form1.resx new file mode 100644 index 0000000..7b85678 --- /dev/null +++ b/DeliveryApp/Form1.resx @@ -0,0 +1,188 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + + iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAEKSURBVEhL3ZG9DsFQHMXvczDZvIOtXsHObuhqkViI3Quw + 6CYmNoMYJJ0NBiFFIoIytOuf0+TeXP3yde+iyS+3OcP53Z4y3/dJJ4HAsiwyTVMp6BQCBIZhKAWdEcHV + vSlBmeB82NFy1KLluEWOPRC5MoHdMWhazwi4RJlALgf4EuT6BI+5kCsTrGddUY658E+QvyXYHq9UnRyC + U87f4aUApcXhnrI9Jzg/laQKFntXlHM+lSQK5psL5fvbp/JvJLGCQqmSWM5JkiCT84igXGtSrruKLQ0T + luAdmZxHBG37FFuWBC/j5XKOmX8WAH7rcI6ZMffPgjQwN2bXJgDo/COBTpjneQ2dML0PY3cISreGe8HM + qgAAAABJRU5ErkJggg== + + + + + iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAEKSURBVEhL3ZG9DsFQHMXvczDZvIOtXsHObuhqkViI3Quw + 6CYmNoMYJJ0NBiFFIoIytOuf0+TeXP3yde+iyS+3OcP53Z4y3/dJJ4HAsiwyTVMp6BQCBIZhKAWdEcHV + vSlBmeB82NFy1KLluEWOPRC5MoHdMWhazwi4RJlALgf4EuT6BI+5kCsTrGddUY658E+QvyXYHq9UnRyC + U87f4aUApcXhnrI9Jzg/laQKFntXlHM+lSQK5psL5fvbp/JvJLGCQqmSWM5JkiCT84igXGtSrruKLQ0T + luAdmZxHBG37FFuWBC/j5XKOmX8WAH7rcI6ZMffPgjQwN2bXJgDo/COBTpjneQ2dML0PY3cISreGe8HM + qgAAAABJRU5ErkJggg== + + + + + iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAEKSURBVEhL3ZG9DsFQHMXvczDZvIOtXsHObuhqkViI3Quw + 6CYmNoMYJJ0NBiFFIoIytOuf0+TeXP3yde+iyS+3OcP53Z4y3/dJJ4HAsiwyTVMp6BQCBIZhKAWdEcHV + vSlBmeB82NFy1KLluEWOPRC5MoHdMWhazwi4RJlALgf4EuT6BI+5kCsTrGddUY658E+QvyXYHq9UnRyC + U87f4aUApcXhnrI9Jzg/laQKFntXlHM+lSQK5psL5fvbp/JvJLGCQqmSWM5JkiCT84igXGtSrruKLQ0T + luAdmZxHBG37FFuWBC/j5XKOmX8WAH7rcI6ZMffPgjQwN2bXJgDo/COBTpjneQ2dML0PY3cISreGe8HM + qgAAAABJRU5ErkJggg== + + + + + iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAEKSURBVEhL3ZG9DsFQHMXvczDZvIOtXsHObuhqkViI3Quw + 6CYmNoMYJJ0NBiFFIoIytOuf0+TeXP3yde+iyS+3OcP53Z4y3/dJJ4HAsiwyTVMp6BQCBIZhKAWdEcHV + vSlBmeB82NFy1KLluEWOPRC5MoHdMWhazwi4RJlALgf4EuT6BI+5kCsTrGddUY658E+QvyXYHq9UnRyC + U87f4aUApcXhnrI9Jzg/laQKFntXlHM+lSQK5psL5fvbp/JvJLGCQqmSWM5JkiCT84igXGtSrruKLQ0T + luAdmZxHBG37FFuWBC/j5XKOmX8WAH7rcI6ZMffPgjQwN2bXJgDo/COBTpjneQ2dML0PY3cISreGe8HM + qgAAAABJRU5ErkJggg== + + + + + iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAEKSURBVEhL3ZG9DsFQHMXvczDZvIOtXsHObuhqkViI3Quw + 6CYmNoMYJJ0NBiFFIoIytOuf0+TeXP3yde+iyS+3OcP53Z4y3/dJJ4HAsiwyTVMp6BQCBIZhKAWdEcHV + vSlBmeB82NFy1KLluEWOPRC5MoHdMWhazwi4RJlALgf4EuT6BI+5kCsTrGddUY658E+QvyXYHq9UnRyC + U87f4aUApcXhnrI9Jzg/laQKFntXlHM+lSQK5psL5fvbp/JvJLGCQqmSWM5JkiCT84igXGtSrruKLQ0T + luAdmZxHBG37FFuWBC/j5XKOmX8WAH7rcI6ZMffPgjQwN2bXJgDo/COBTpjneQ2dML0PY3cISreGe8HM + qgAAAABJRU5ErkJggg== + + + + 143, 17 + + + 319, 17 + + + 461, 17 + + \ No newline at end of file diff --git a/DeliveryApp/FormDelivery.Designer.cs b/DeliveryApp/FormDelivery.Designer.cs new file mode 100644 index 0000000..b25a7a1 --- /dev/null +++ b/DeliveryApp/FormDelivery.Designer.cs @@ -0,0 +1,214 @@ +namespace DeliveryApp +{ + partial class FormDelivery + { + /// + /// 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() + { + tableLayoutPanel1 = new TableLayoutPanel(); + label1 = new Label(); + textBox1 = new TextBox(); + label2 = new Label(); + label3 = new Label(); + label4 = new Label(); + buttonImage = new Button(); + customCheckedListBox1 = new CustomComponents.CustomCheckedListBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + customTextBoxNumber2 = new textboxfix.CustomTextBoxNumber(); + pictureBox1 = new PictureBox(); + tableLayoutPanel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit(); + SuspendLayout(); + // + // tableLayoutPanel1 + // + tableLayoutPanel1.ColumnCount = 5; + tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 46.62162F)); + tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 53.37838F)); + tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 94F)); + tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 169F)); + tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 100F)); + tableLayoutPanel1.Controls.Add(label1, 0, 0); + tableLayoutPanel1.Controls.Add(textBox1, 0, 1); + tableLayoutPanel1.Controls.Add(label2, 1, 0); + tableLayoutPanel1.Controls.Add(label3, 2, 0); + tableLayoutPanel1.Controls.Add(label4, 3, 0); + tableLayoutPanel1.Controls.Add(buttonImage, 2, 1); + tableLayoutPanel1.Controls.Add(customCheckedListBox1, 3, 1); + tableLayoutPanel1.Controls.Add(buttonCancel, 4, 0); + tableLayoutPanel1.Controls.Add(buttonSave, 4, 1); + tableLayoutPanel1.Controls.Add(customTextBoxNumber2, 1, 1); + tableLayoutPanel1.Dock = DockStyle.Top; + tableLayoutPanel1.Location = new Point(0, 0); + tableLayoutPanel1.Name = "tableLayoutPanel1"; + tableLayoutPanel1.RowCount = 2; + tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 30.06993F)); + tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Percent, 69.93007F)); + tableLayoutPanel1.Size = new Size(660, 143); + tableLayoutPanel1.TabIndex = 0; + // + // label1 + // + label1.Anchor = AnchorStyles.Top; + label1.AutoSize = true; + label1.Location = new Point(48, 0); + label1.Name = "label1"; + label1.Size = new Size(42, 20); + label1.TabIndex = 0; + label1.Text = "ФИО"; + // + // textBox1 + // + textBox1.Dock = DockStyle.Fill; + textBox1.Location = new Point(3, 46); + textBox1.Name = "textBox1"; + textBox1.Size = new Size(132, 27); + textBox1.TabIndex = 1; + // + // label2 + // + label2.Anchor = AnchorStyles.Top; + label2.AutoSize = true; + label2.Location = new Point(182, 0); + label2.Name = "label2"; + label2.Size = new Size(69, 20); + label2.TabIndex = 2; + label2.Text = "Телефон"; + // + // label3 + // + label3.Anchor = AnchorStyles.Top; + label3.AutoSize = true; + label3.Location = new Point(321, 0); + label3.Name = "label3"; + label3.Size = new Size(44, 20); + label3.TabIndex = 3; + label3.Text = "Фото"; + // + // label4 + // + label4.Anchor = AnchorStyles.Top; + label4.AutoSize = true; + label4.Location = new Point(457, 0); + label4.Name = "label4"; + label4.Size = new Size(35, 20); + label4.TabIndex = 4; + label4.Text = "Тип"; + // + // buttonImage + // + buttonImage.Dock = DockStyle.Fill; + buttonImage.Location = new Point(299, 46); + buttonImage.Name = "buttonImage"; + buttonImage.Size = new Size(88, 94); + buttonImage.TabIndex = 5; + buttonImage.Text = "Выбрать фото"; + buttonImage.UseVisualStyleBackColor = true; + buttonImage.Click += buttonImage_Click; + // + // customCheckedListBox1 + // + customCheckedListBox1.Anchor = AnchorStyles.None; + customCheckedListBox1.Location = new Point(393, 49); + customCheckedListBox1.Name = "customCheckedListBox1"; + customCheckedListBox1.SelectedValue = ""; + customCheckedListBox1.Size = new Size(163, 88); + customCheckedListBox1.TabIndex = 6; + // + // buttonCancel + // + buttonCancel.Dock = DockStyle.Fill; + buttonCancel.Location = new Point(562, 3); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(95, 37); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отменить"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Dock = DockStyle.Fill; + buttonSave.Location = new Point(562, 46); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(95, 94); + buttonSave.TabIndex = 8; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // customTextBoxNumber2 + // + customTextBoxNumber2.Dock = DockStyle.Fill; + customTextBoxNumber2.Location = new Point(141, 46); + customTextBoxNumber2.Name = "customTextBoxNumber2"; + customTextBoxNumber2.NumPattern = "\\(\\d{4}\\)\\d{2}-\\d{2}-\\d{2}"; + customTextBoxNumber2.Size = new Size(152, 94); + customTextBoxNumber2.TabIndex = 9; + // + // pictureBox1 + // + pictureBox1.Dock = DockStyle.Fill; + pictureBox1.Location = new Point(0, 143); + pictureBox1.Name = "pictureBox1"; + pictureBox1.Size = new Size(660, 362); + pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; + pictureBox1.TabIndex = 1; + pictureBox1.TabStop = false; + // + // FormDelivery + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(660, 505); + Controls.Add(pictureBox1); + Controls.Add(tableLayoutPanel1); + Name = "FormDelivery"; + Text = "FormDelivery"; + Load += FormDelivery_Load; + tableLayoutPanel1.ResumeLayout(false); + tableLayoutPanel1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit(); + ResumeLayout(false); + } + + #endregion + + private TableLayoutPanel tableLayoutPanel1; + private Label label1; + private TextBox textBox1; + private Label label2; + private Label label3; + private Label label4; + private PictureBox pictureBox1; + private Button buttonImage; + private CustomComponents.CustomCheckedListBox customCheckedListBox1; + private Button buttonCancel; + private Button buttonSave; + private textboxfix.CustomTextBoxNumber customTextBoxNumber2; + } +} \ No newline at end of file diff --git a/DeliveryApp/FormDelivery.cs b/DeliveryApp/FormDelivery.cs new file mode 100644 index 0000000..63e2ac3 --- /dev/null +++ b/DeliveryApp/FormDelivery.cs @@ -0,0 +1,143 @@ +using BuisnessLogic; +using Contracts.BindingModels; +using Contracts.BuisnessLogicsContracts; +using Contracts.SearchModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace DeliveryApp +{ + public partial class FormDelivery : Form + { + private readonly ITypeLogic _typeLogic; + private readonly IDeliveryLogic _deliveryLogic; + private int? _id; + private string? currentImage; + public int Id { set { _id = value; } } + public FormDelivery(ITypeLogic typeLogic, IDeliveryLogic deliveryLogic) + { + _typeLogic = typeLogic; + _deliveryLogic = deliveryLogic; + InitializeComponent(); + } + + private void FormDelivery_Load(object sender, EventArgs e) + { + customTextBoxNumber2.TextBoxNumber = "(0000)00-00-00"; + LoadData(); + } + private void LoadData() + { + var list = _typeLogic.ReadList(null); + if (list != null) + { + foreach (var item in list) + { + customCheckedListBox1.DataList.Add(item.PostType); + } + } + if (_id.HasValue) + { + try + { + var element = _deliveryLogic.ReadElement(new DeliverySearchModel + { + Id = _id.Value, + }); + if (element != null) + { + textBox1.Text = element.CourierFIO; + customTextBoxNumber2.TextBoxNumber = element.Phone; + customCheckedListBox1.SelectedValue = element.Type; + pictureBox1.Image = Image.FromFile(element.Image); + currentImage = element.Image; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBox1.Text)) + { + MessageBox.Show("Заполните фио", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (customCheckedListBox1.SelectedValue == null) + { + MessageBox.Show("Выберите тип", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + var ss = customTextBoxNumber2.NumPattern; + if (customTextBoxNumber2.TextBoxNumber == null) + { + MessageBox.Show("Заполните номер", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (currentImage == null) + { + MessageBox.Show("Выберите фото", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + var model = new DeliveryBindingModel + { + Id = _id ?? 0, + CourierFIO = textBox1.Text, + Image = currentImage, + Phone = customTextBoxNumber2.TextBoxNumber, + Type = customCheckedListBox1.SelectedValue, + + }; + var operationResult = _id.HasValue ? _deliveryLogic.Update(model) : + _deliveryLogic.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 buttonImage_Click(object sender, EventArgs e) + { + using (OpenFileDialog dlg = new OpenFileDialog()) + { + dlg.Title = "Выберите фото"; + dlg.Filter = "Image Files (*.bmp;*.jpg;*.jpeg,*.png)|*.BMP;*.JPG;*.JPEG;*.PNG"; + if (dlg.ShowDialog() == DialogResult.OK) + { + pictureBox1.Image = new Bitmap(dlg.FileName); + currentImage = dlg.FileName; + } + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/DeliveryApp/FormDelivery.resx b/DeliveryApp/FormDelivery.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/DeliveryApp/FormDelivery.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/DeliveryApp/FormType.Designer.cs b/DeliveryApp/FormType.Designer.cs new file mode 100644 index 0000000..8b49102 --- /dev/null +++ b/DeliveryApp/FormType.Designer.cs @@ -0,0 +1,67 @@ +namespace DeliveryApp +{ + partial class FormType + { + /// + /// 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() + { + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(800, 450); + dataGridView.TabIndex = 0; + dataGridView.CellEndEdit += dataGridView_CellEndEdit; + dataGridView.KeyDown += dataGridView_KeyDown; + // + // FormType + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Name = "FormType"; + Text = "FormType"; + Load += FormType_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/DeliveryApp/FormType.cs b/DeliveryApp/FormType.cs new file mode 100644 index 0000000..75b73c0 --- /dev/null +++ b/DeliveryApp/FormType.cs @@ -0,0 +1,122 @@ +using Contracts.BindingModels; +using Contracts.BuisnessLogicsContracts; +using Contracts.ViewModels; +using Microsoft.EntityFrameworkCore.Diagnostics; +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 DeliveryApp +{ + public partial class FormType : Form + { + private readonly ITypeLogic _logic; + List? _list; + public FormType(ITypeLogic logic) + { + InitializeComponent(); + _logic = logic; + } + + private void FormType_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + _list = _logic.ReadList(null); + if (_list != null) + { + dataGridView.DataSource = _list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["PostType"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void dataGridView_UserAddedRow(object sender, DataGridViewRowEventArgs e) + { + + } + + private void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) + { + try + { + if (dataGridView.SelectedCells[1].Value == null) + { + throw new Exception("Ошибка, нельзя сохранить пустую строку"); + } + int _id; + bool id = Int32.TryParse(dataGridView.SelectedRows[0].Cells["Id"].Value?.ToString(), out _id); + if (_id == -1) + { + id = false; + } + var model = new TypeBindingModel + { + Id = id ? _id : 0, + PostType = dataGridView.SelectedCells[1].Value.ToString()!, + }; + var operationResult = id ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении."); + } + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void dataGridView_KeyDown(object sender, KeyEventArgs e) + { + if(e.KeyCode == Keys.Insert) + { + _list?.Add(new TypeViewModel { Id = -1, PostType = "" }); + if (_list != null) + { + dataGridView.DataSource = null; + dataGridView.DataSource = _list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["PostType"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + if(e.KeyCode == Keys.Delete) + { + if (MessageBox.Show("Вы уверены?", "Удалить", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + int _id; + bool id = Int32.TryParse(dataGridView.SelectedRows[0].Cells["Id"].Value?.ToString(), out _id); + if (_id == -1 || !id) + { + id = false; + return; + } + var model = new TypeBindingModel + { + Id = _id, + PostType = dataGridView.SelectedCells[1].Value.ToString()!, + }; + _logic.Delete(model); + LoadData(); + } + } + } +} diff --git a/DeliveryApp/FormType.resx b/DeliveryApp/FormType.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/DeliveryApp/FormType.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/DeliveryApp/Program.cs b/DeliveryApp/Program.cs new file mode 100644 index 0000000..8b2df8a --- /dev/null +++ b/DeliveryApp/Program.cs @@ -0,0 +1,49 @@ +using BuisnessLogic; +using Contracts.BuisnessLogicsContracts; +using Contracts.StorageContracts; +using DatabaseImplements.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using System; + +namespace DeliveryApp +{ + internal static class Program + { + private static ServiceProvider? _serviceProvider; + /// + /// The main entry point for the application. + /// + public static ServiceProvider? ServiceProvider => _serviceProvider; + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + + Application.Run(_serviceProvider.GetRequiredService()); + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + //option.AddNLog("nlog.config"); + }); + + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } + } +} \ No newline at end of file diff --git a/DeliveryApp/Properties/Resources.Designer.cs b/DeliveryApp/Properties/Resources.Designer.cs new file mode 100644 index 0000000..6c08cef --- /dev/null +++ b/DeliveryApp/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace DeliveryApp.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DeliveryApp.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/DeliveryApp/Properties/Resources.resx b/DeliveryApp/Properties/Resources.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/DeliveryApp/Properties/Resources.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