From bf57e05c9a8cce7b1426e5d8c23a0d9ac3573ca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=90=D0=BB=D0=B5=D0=B9?= =?UTF-8?q?=D0=BA=D0=B8=D0=BD?= Date: Tue, 16 May 2023 23:26:45 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D0=BE?= =?UTF-8?q?=D1=81=D0=BD=D0=BE=D0=B2=D1=83=D1=8E=20=D1=87=D0=B0=D1=81=D1=82?= =?UTF-8?q?=D1=8C.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/OrderLogic.cs | 2 +- .../BindingModels/ComponentBindingModel.cs | 2 +- .../BindingModels/OrderBindingModel.cs | 2 +- .../BindingModels/ProductBindingModel.cs | 2 +- .../ViewModels/ComponentViewModel.cs | 2 +- .../ViewModels/OrderViewModel.cs | 2 +- .../ViewModels/ProductViewModel.cs | 2 +- .../Models/IComponentModel.cs | 2 +- .../Models/IOrderModel.cs | 2 +- .../Models/IProductModel.cs | 2 +- .../Implements/OrderStorage.cs | 10 +- .../Implements/ProductStorage.cs | 6 +- .../20230516191214_migr2.Designer.cs | 319 ++++++++++++++++++ .../Migrations/20230516191214_migr2.cs | 50 +++ .../RestaurantDatabaseModelSnapshot.cs | 8 +- .../Models/Component.cs | 25 +- .../Models/Order.cs | 5 +- .../Models/Product.cs | 2 +- .../RestaurantView/FormComponent.Designer.cs | 113 ++++--- Restaurant/RestaurantView/FormComponent.cs | 85 ++++- Restaurant/RestaurantView/FormComponent.resx | 11 +- .../FormComponentProvider.Designer.cs | 106 +++++- .../RestaurantView/FormComponentProvider.cs | 21 +- .../RestaurantView/FormComponentProvider.resx | 62 +--- .../FormCreateOrder.Designer.cs | 226 +++++++++++++ Restaurant/RestaurantView/FormCreateOrder.cs | 212 ++++++++++++ .../RestaurantView/FormCreateOrder.resx | 69 ++++ .../RestaurantView/FormMain.Designer.cs | 26 +- Restaurant/RestaurantView/FormMain.cs | 25 ++ .../FormOrderProduct.Designer.cs | 119 +++++++ Restaurant/RestaurantView/FormOrderProduct.cs | 90 +++++ .../RestaurantView/FormOrderProduct.resx | 60 ++++ .../RestaurantView/FormProduct.Designer.cs | 226 +++++++++++++ Restaurant/RestaurantView/FormProduct.cs | 221 ++++++++++++ Restaurant/RestaurantView/FormProduct.resx | 69 ++++ .../FormProductComponent.Designer.cs | 119 +++++++ .../RestaurantView/FormProductComponent.cs | 90 +++++ .../RestaurantView/FormProductComponent.resx | 60 ++++ .../RestaurantView/FormProducts.Designer.cs | 114 +++++++ Restaurant/RestaurantView/FormProducts.cs | 109 ++++++ Restaurant/RestaurantView/FormProducts.resx | 60 ++++ Restaurant/RestaurantView/Program.cs | 6 + 42 files changed, 2566 insertions(+), 178 deletions(-) create mode 100644 Restaurant/RestaurantDatabaseImplement/Migrations/20230516191214_migr2.Designer.cs create mode 100644 Restaurant/RestaurantDatabaseImplement/Migrations/20230516191214_migr2.cs create mode 100644 Restaurant/RestaurantView/FormCreateOrder.Designer.cs create mode 100644 Restaurant/RestaurantView/FormCreateOrder.cs create mode 100644 Restaurant/RestaurantView/FormCreateOrder.resx create mode 100644 Restaurant/RestaurantView/FormOrderProduct.Designer.cs create mode 100644 Restaurant/RestaurantView/FormOrderProduct.cs create mode 100644 Restaurant/RestaurantView/FormOrderProduct.resx create mode 100644 Restaurant/RestaurantView/FormProduct.Designer.cs create mode 100644 Restaurant/RestaurantView/FormProduct.cs create mode 100644 Restaurant/RestaurantView/FormProduct.resx create mode 100644 Restaurant/RestaurantView/FormProductComponent.Designer.cs create mode 100644 Restaurant/RestaurantView/FormProductComponent.cs create mode 100644 Restaurant/RestaurantView/FormProductComponent.resx create mode 100644 Restaurant/RestaurantView/FormProducts.Designer.cs create mode 100644 Restaurant/RestaurantView/FormProducts.cs create mode 100644 Restaurant/RestaurantView/FormProducts.resx diff --git a/Restaurant/RestaurantBusinessLogic/BusinessLogics/OrderLogic.cs b/Restaurant/RestaurantBusinessLogic/BusinessLogics/OrderLogic.cs index 1596756..26e2b6a 100644 --- a/Restaurant/RestaurantBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/Restaurant/RestaurantBusinessLogic/BusinessLogics/OrderLogic.cs @@ -88,7 +88,7 @@ namespace RestaurantBusinessLogic.BusinessLogics { throw new ArgumentNullException("Нет цены у заказа", nameof(model.Price)); } - if (model.Date != null) + if (model.Date == null) { throw new ArgumentNullException("Нет даты у заказа", nameof(model.Date)); } diff --git a/Restaurant/RestaurantContracts/BindingModels/ComponentBindingModel.cs b/Restaurant/RestaurantContracts/BindingModels/ComponentBindingModel.cs index 15f17e8..740d412 100644 --- a/Restaurant/RestaurantContracts/BindingModels/ComponentBindingModel.cs +++ b/Restaurant/RestaurantContracts/BindingModels/ComponentBindingModel.cs @@ -15,7 +15,7 @@ namespace RestaurantContracts.BindingModels public int Count { get; set; } - public Dictionary ComponentProviders { get; set; } = new(); + public List<(IProviderModel, int, DateTime)> ComponentProviders { get; set; } = new(); public int Id { get; set; } } diff --git a/Restaurant/RestaurantContracts/BindingModels/OrderBindingModel.cs b/Restaurant/RestaurantContracts/BindingModels/OrderBindingModel.cs index 23f5e8b..a6a920a 100644 --- a/Restaurant/RestaurantContracts/BindingModels/OrderBindingModel.cs +++ b/Restaurant/RestaurantContracts/BindingModels/OrderBindingModel.cs @@ -11,7 +11,7 @@ namespace RestaurantContracts.BindingModels { public int ClientId { get; set; } = new(); - public int Price { get; set; } + public double Price { get; set; } public DateTime Date { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); diff --git a/Restaurant/RestaurantContracts/BindingModels/ProductBindingModel.cs b/Restaurant/RestaurantContracts/BindingModels/ProductBindingModel.cs index 1f32c8f..1ca55ed 100644 --- a/Restaurant/RestaurantContracts/BindingModels/ProductBindingModel.cs +++ b/Restaurant/RestaurantContracts/BindingModels/ProductBindingModel.cs @@ -11,7 +11,7 @@ namespace RestaurantContracts.BindingModels { public string Type { get; set; } = string.Empty; - public int Price { get; set; } + public double Price { get; set; } public int Count { get; set; } diff --git a/Restaurant/RestaurantContracts/ViewModels/ComponentViewModel.cs b/Restaurant/RestaurantContracts/ViewModels/ComponentViewModel.cs index f7b11b8..fbbce1d 100644 --- a/Restaurant/RestaurantContracts/ViewModels/ComponentViewModel.cs +++ b/Restaurant/RestaurantContracts/ViewModels/ComponentViewModel.cs @@ -21,6 +21,6 @@ namespace RestaurantContracts.ViewModels [DisplayName("Количество")] public int Count { get; set; } - public Dictionary ComponentProviders { get; set; } = new(); + public List<(IProviderModel, int, DateTime)> ComponentProviders { get; set; } = new(); } } diff --git a/Restaurant/RestaurantContracts/ViewModels/OrderViewModel.cs b/Restaurant/RestaurantContracts/ViewModels/OrderViewModel.cs index fbc8248..1ad95a4 100644 --- a/Restaurant/RestaurantContracts/ViewModels/OrderViewModel.cs +++ b/Restaurant/RestaurantContracts/ViewModels/OrderViewModel.cs @@ -22,7 +22,7 @@ namespace RestaurantContracts.ViewModels public string ClientLastName { get; set; } = string.Empty; [DisplayName("Цена")] - public int Price { get; set; } + public double Price { get; set; } [DisplayName("Дата")] public DateTime Date { get; set; } diff --git a/Restaurant/RestaurantContracts/ViewModels/ProductViewModel.cs b/Restaurant/RestaurantContracts/ViewModels/ProductViewModel.cs index 82bc113..9127bdf 100644 --- a/Restaurant/RestaurantContracts/ViewModels/ProductViewModel.cs +++ b/Restaurant/RestaurantContracts/ViewModels/ProductViewModel.cs @@ -16,7 +16,7 @@ namespace RestaurantContracts.ViewModels public string Type { get; set; } = string.Empty; [DisplayName("Цена")] - public int Price { get; set; } + public double Price { get; set; } [DisplayName("Количество продуктов")] public int Count { get; set; } diff --git a/Restaurant/RestaurantDataModels/Models/IComponentModel.cs b/Restaurant/RestaurantDataModels/Models/IComponentModel.cs index 196dc30..8e5a378 100644 --- a/Restaurant/RestaurantDataModels/Models/IComponentModel.cs +++ b/Restaurant/RestaurantDataModels/Models/IComponentModel.cs @@ -14,6 +14,6 @@ namespace RestaurantDataModels.Models int Count { get; } - Dictionary ComponentProviders { get; } + List<(IProviderModel, int, DateTime)> ComponentProviders { get; } } } diff --git a/Restaurant/RestaurantDataModels/Models/IOrderModel.cs b/Restaurant/RestaurantDataModels/Models/IOrderModel.cs index 4724b4f..a2c8e3c 100644 --- a/Restaurant/RestaurantDataModels/Models/IOrderModel.cs +++ b/Restaurant/RestaurantDataModels/Models/IOrderModel.cs @@ -10,7 +10,7 @@ namespace RestaurantDataModels.Models { int ClientId { get; } - int Price { get; } + double Price { get; } DateTime Date { get; } diff --git a/Restaurant/RestaurantDataModels/Models/IProductModel.cs b/Restaurant/RestaurantDataModels/Models/IProductModel.cs index d382914..3ed5d51 100644 --- a/Restaurant/RestaurantDataModels/Models/IProductModel.cs +++ b/Restaurant/RestaurantDataModels/Models/IProductModel.cs @@ -10,7 +10,7 @@ namespace RestaurantDataModels.Models { string Type { get; } - int Price { get; } + double Price { get; } int Count { get; } diff --git a/Restaurant/RestaurantDatabaseImplement/Implements/OrderStorage.cs b/Restaurant/RestaurantDatabaseImplement/Implements/OrderStorage.cs index e16ff48..4d5c8a0 100644 --- a/Restaurant/RestaurantDatabaseImplement/Implements/OrderStorage.cs +++ b/Restaurant/RestaurantDatabaseImplement/Implements/OrderStorage.cs @@ -32,7 +32,7 @@ namespace RestaurantDatabaseImplement.Implements { return context.Orders .Include(x => x.Products) - .ThenInclude(x => x.ProductId) + .ThenInclude(x => x.Product) .Include(x => x.Client) .Where(x => x.Id == model.Id) .Select(x => x.GetViewModel) @@ -42,7 +42,7 @@ namespace RestaurantDatabaseImplement.Implements { return context.Orders .Include(x => x.Products) - .ThenInclude(x => x.ProductId) + .ThenInclude(x => x.Product) .Include(x => x.Client) .Where(x => x.ClientId == model.ClientId) .Select(x => x.GetViewModel) @@ -52,7 +52,7 @@ namespace RestaurantDatabaseImplement.Implements { return context.Orders .Include(x => x.Products) - .ThenInclude(x => x.ProductId) + .ThenInclude(x => x.Product) .Include(x => x.Client) .Where(x => x.Date == model.Date) .Select(x => x.GetViewModel) @@ -95,7 +95,7 @@ namespace RestaurantDatabaseImplement.Implements var element = context.Orders .Include(x => x.Client) .Include(x => x.Products) - .ThenInclude(x => x.ProductId) + .ThenInclude(x => x.Product) .FirstOrDefault(x => x.Id == model.Id); if (element == null) { @@ -111,7 +111,7 @@ namespace RestaurantDatabaseImplement.Implements var element = context.Orders .Include(x => x.Client) .Include(x => x.Products) - .ThenInclude(x => x.ProductId) + .ThenInclude(x => x.Product) .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { diff --git a/Restaurant/RestaurantDatabaseImplement/Implements/ProductStorage.cs b/Restaurant/RestaurantDatabaseImplement/Implements/ProductStorage.cs index 832794b..b59a8f2 100644 --- a/Restaurant/RestaurantDatabaseImplement/Implements/ProductStorage.cs +++ b/Restaurant/RestaurantDatabaseImplement/Implements/ProductStorage.cs @@ -19,7 +19,7 @@ namespace RestaurantDatabaseImplement.Implements using var context = new RestaurantDatabase(); return context.Products .Include(x => x.Components) - .ThenInclude(x => x.ComponentId) + .ThenInclude(x => x.Component) .ToList() .Select(x => x.GetViewModel) .ToList(); @@ -31,7 +31,7 @@ namespace RestaurantDatabaseImplement.Implements { return context.Products .Include(x => x.Components) - .ThenInclude(x => x.ComponentId) + .ThenInclude(x => x.Component) .Where(x => x.Id == model.Id) .Select(x => x.GetViewModel) .ToList(); @@ -40,7 +40,7 @@ namespace RestaurantDatabaseImplement.Implements { return context.Products .Include(x => x.Components) - .ThenInclude(x => x.ComponentId) + .ThenInclude(x => x.Component) .Where(x => x.Type == model.Type) .Select(x => x.GetViewModel) .ToList(); diff --git a/Restaurant/RestaurantDatabaseImplement/Migrations/20230516191214_migr2.Designer.cs b/Restaurant/RestaurantDatabaseImplement/Migrations/20230516191214_migr2.Designer.cs new file mode 100644 index 0000000..3006c59 --- /dev/null +++ b/Restaurant/RestaurantDatabaseImplement/Migrations/20230516191214_migr2.Designer.cs @@ -0,0 +1,319 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using RestaurantDatabaseImplement; + +#nullable disable + +namespace RestaurantDatabaseImplement.Migrations +{ + [DbContext(typeof(RestaurantDatabase))] + [Migration("20230516191214_migr2")] + partial class migr2 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.5") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("RestaurantDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Number") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("RestaurantDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("RestaurantDatabaseImplement.Models.ComponentProvider", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("ProviderId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ProviderId"); + + b.ToTable("ComponentProviders"); + }); + + modelBuilder.Entity("RestaurantDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("RestaurantDatabaseImplement.Models.OrderProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("OrderId") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("OrderId"); + + b.HasIndex("ProductId"); + + b.ToTable("OrderProducts"); + }); + + modelBuilder.Entity("RestaurantDatabaseImplement.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("Type") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("RestaurantDatabaseImplement.Models.ProductComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ProductId"); + + b.ToTable("ProductComponents"); + }); + + modelBuilder.Entity("RestaurantDatabaseImplement.Models.Provider", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Providers"); + }); + + modelBuilder.Entity("RestaurantDatabaseImplement.Models.ComponentProvider", b => + { + b.HasOne("RestaurantDatabaseImplement.Models.Component", "Component") + .WithMany("Providers") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("RestaurantDatabaseImplement.Models.Provider", "Provider") + .WithMany("ComponentProviders") + .HasForeignKey("ProviderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Provider"); + }); + + modelBuilder.Entity("RestaurantDatabaseImplement.Models.Order", b => + { + b.HasOne("RestaurantDatabaseImplement.Models.Client", "Client") + .WithMany() + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + }); + + modelBuilder.Entity("RestaurantDatabaseImplement.Models.OrderProduct", b => + { + b.HasOne("RestaurantDatabaseImplement.Models.Order", "Order") + .WithMany("Products") + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("RestaurantDatabaseImplement.Models.Product", "Product") + .WithMany("OrderProducts") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Order"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("RestaurantDatabaseImplement.Models.ProductComponent", b => + { + b.HasOne("RestaurantDatabaseImplement.Models.Component", "Component") + .WithMany("ProductComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("RestaurantDatabaseImplement.Models.Product", "Product") + .WithMany("Components") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("RestaurantDatabaseImplement.Models.Component", b => + { + b.Navigation("ProductComponents"); + + b.Navigation("Providers"); + }); + + modelBuilder.Entity("RestaurantDatabaseImplement.Models.Order", b => + { + b.Navigation("Products"); + }); + + modelBuilder.Entity("RestaurantDatabaseImplement.Models.Product", b => + { + b.Navigation("Components"); + + b.Navigation("OrderProducts"); + }); + + modelBuilder.Entity("RestaurantDatabaseImplement.Models.Provider", b => + { + b.Navigation("ComponentProviders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Restaurant/RestaurantDatabaseImplement/Migrations/20230516191214_migr2.cs b/Restaurant/RestaurantDatabaseImplement/Migrations/20230516191214_migr2.cs new file mode 100644 index 0000000..06e0029 --- /dev/null +++ b/Restaurant/RestaurantDatabaseImplement/Migrations/20230516191214_migr2.cs @@ -0,0 +1,50 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace RestaurantDatabaseImplement.Migrations +{ + /// + public partial class migr2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Price", + table: "Products", + type: "double precision", + nullable: false, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AlterColumn( + name: "Price", + table: "Orders", + type: "double precision", + nullable: false, + oldClrType: typeof(int), + oldType: "integer"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Price", + table: "Products", + type: "integer", + nullable: false, + oldClrType: typeof(double), + oldType: "double precision"); + + migrationBuilder.AlterColumn( + name: "Price", + table: "Orders", + type: "integer", + nullable: false, + oldClrType: typeof(double), + oldType: "double precision"); + } + } +} diff --git a/Restaurant/RestaurantDatabaseImplement/Migrations/RestaurantDatabaseModelSnapshot.cs b/Restaurant/RestaurantDatabaseImplement/Migrations/RestaurantDatabaseModelSnapshot.cs index cef9d22..ab89a52 100644 --- a/Restaurant/RestaurantDatabaseImplement/Migrations/RestaurantDatabaseModelSnapshot.cs +++ b/Restaurant/RestaurantDatabaseImplement/Migrations/RestaurantDatabaseModelSnapshot.cs @@ -113,8 +113,8 @@ namespace RestaurantDatabaseImplement.Migrations b.Property("Date") .HasColumnType("timestamp with time zone"); - b.Property("Price") - .HasColumnType("integer"); + b.Property("Price") + .HasColumnType("double precision"); b.HasKey("Id"); @@ -160,8 +160,8 @@ namespace RestaurantDatabaseImplement.Migrations b.Property("Count") .HasColumnType("integer"); - b.Property("Price") - .HasColumnType("integer"); + b.Property("Price") + .HasColumnType("double precision"); b.Property("Type") .IsRequired() diff --git a/Restaurant/RestaurantDatabaseImplement/Models/Component.cs b/Restaurant/RestaurantDatabaseImplement/Models/Component.cs index 47efc93..8000598 100644 --- a/Restaurant/RestaurantDatabaseImplement/Models/Component.cs +++ b/Restaurant/RestaurantDatabaseImplement/Models/Component.cs @@ -22,17 +22,16 @@ namespace RestaurantDatabaseImplement.Models [Required] public int Count { get; private set; } - private Dictionary? _componentProviders = null; + private List<(IProviderModel, int, DateTime)>? _componentProviders = null; [NotMapped] - public Dictionary ComponentProviders + public List<(IProviderModel, int, DateTime)> ComponentProviders { get { if (_componentProviders == null) { - _componentProviders = Providers.ToDictionary(recPC => recPC.ProviderId, recPC => - (recPC.Provider as IProviderModel, recPC.Count, recPC.Date)); + _componentProviders = Providers.Select(recPC => (recPC.Provider as IProviderModel, recPC.Count, recPC.Date)).ToList(); } return _componentProviders; } @@ -60,9 +59,9 @@ namespace RestaurantDatabaseImplement.Models Count = model.Count, Providers = model.ComponentProviders.Select(x => new ComponentProvider { - Provider = context.Providers.First(y => y.Id == x.Key), - Count = x.Value.Item2, - Date = x.Value.Item3 + Provider = context.Providers.First(y => y.ComponentProviders == x.Item1), + Count = x.Item2, + Date = x.Item3 }).ToList() }; } @@ -88,13 +87,13 @@ namespace RestaurantDatabaseImplement.Models var ComponentProviders = context.ComponentProviders.Where(rec => rec.ComponentId == model.Id).ToList(); if (ComponentProviders != null && ComponentProviders.Count > 0) { // удалили те, которых нет в модели - context.ComponentProviders.RemoveRange(ComponentProviders.Where(rec => !model.ComponentProviders.ContainsKey(rec.ProviderId))); + context.ComponentProviders.RemoveRange(ComponentProviders.Where(rec => !model.ComponentProviders.Select(x => x.Item1.Id).Contains(rec.ProviderId))); context.SaveChanges(); // обновили количество у существующих записей foreach (var updateComponent in ComponentProviders) { - updateComponent.Count = model.ComponentProviders[updateComponent.ProviderId].Item2; - model.ComponentProviders.Remove(updateComponent.ProviderId); + updateComponent.Count = model.ComponentProviders.Find(x => x.Item1.Id == updateComponent.ProviderId).Item2; + model.ComponentProviders.Remove(model.ComponentProviders.Find(x => x.Item1.Id == updateComponent.ProviderId)); } context.SaveChanges(); } @@ -104,9 +103,9 @@ namespace RestaurantDatabaseImplement.Models context.ComponentProviders.Add(new ComponentProvider { Component = Component, - Provider = context.Providers.First(x => x.Id == pc.Key), - Count = pc.Value.Item2, - Date = pc.Value.Item3 // ?????? + Provider = context.Providers.First(x => x.ComponentProviders == pc.Item1), + Count = pc.Item2, + Date = pc.Item3 // ?????? }); context.SaveChanges(); } diff --git a/Restaurant/RestaurantDatabaseImplement/Models/Order.cs b/Restaurant/RestaurantDatabaseImplement/Models/Order.cs index 19ed1be..ad23256 100644 --- a/Restaurant/RestaurantDatabaseImplement/Models/Order.cs +++ b/Restaurant/RestaurantDatabaseImplement/Models/Order.cs @@ -18,7 +18,7 @@ namespace RestaurantDatabaseImplement.Models public virtual Client Client { get; set; } = new(); [Required] - public int Price { get; set; } + public double Price { get; set; } [Required] public DateTime Date { get; set; } @@ -54,6 +54,7 @@ namespace RestaurantDatabaseImplement.Models { Id = model.Id, ClientId = model.ClientId, + Client = context.Clients.FirstOrDefault(x => x.Id == model.ClientId), Price = model.Price, Date = model.Date, Products = model.OrderProducts.Select(x => new OrderProduct @@ -74,6 +75,8 @@ namespace RestaurantDatabaseImplement.Models { Id = Id, ClientId = ClientId, + ClientFirstName = Client.FirstName, + ClientLastName = Client.LastName, Price = Price, Date = Date, }; diff --git a/Restaurant/RestaurantDatabaseImplement/Models/Product.cs b/Restaurant/RestaurantDatabaseImplement/Models/Product.cs index 6b2e033..5f09cae 100644 --- a/Restaurant/RestaurantDatabaseImplement/Models/Product.cs +++ b/Restaurant/RestaurantDatabaseImplement/Models/Product.cs @@ -17,7 +17,7 @@ namespace RestaurantDatabaseImplement.Models public string Type { get; private set; } = string.Empty; [Required] - public int Price { get; private set; } + public double Price { get; private set; } [Required] public int Count { get; private set; } diff --git a/Restaurant/RestaurantView/FormComponent.Designer.cs b/Restaurant/RestaurantView/FormComponent.Designer.cs index 0a4fc47..807092e 100644 --- a/Restaurant/RestaurantView/FormComponent.Designer.cs +++ b/Restaurant/RestaurantView/FormComponent.Designer.cs @@ -37,14 +37,14 @@ this.textBoxPrice = new System.Windows.Forms.TextBox(); this.textBoxCount = new System.Windows.Forms.TextBox(); this.groupBox1 = new System.Windows.Forms.GroupBox(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.buttonAdd = new System.Windows.Forms.Button(); - this.buttonDel = new System.Windows.Forms.Button(); - this.buttonUpd = new System.Windows.Forms.Button(); this.buttonRef = new System.Windows.Forms.Button(); - this.Id = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Provider = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.Identificator = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Provider = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -104,7 +104,6 @@ // // textBoxPrice // - this.textBoxPrice.Enabled = false; this.textBoxPrice.Location = new System.Drawing.Point(98, 65); this.textBoxPrice.Name = "textBoxPrice"; this.textBoxPrice.Size = new System.Drawing.Size(295, 23); @@ -112,6 +111,7 @@ // // textBoxCount // + this.textBoxCount.Enabled = false; this.textBoxCount.Location = new System.Drawing.Point(98, 110); this.textBoxCount.Name = "textBoxCount"; this.textBoxCount.Size = new System.Drawing.Size(295, 23); @@ -131,18 +131,35 @@ this.groupBox1.TabStop = false; this.groupBox1.Text = "Поставщики"; // - // dataGridView1 + // buttonRef // - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { - this.Id, - this.Provider, - this.Count}); - this.dataGridView.Location = new System.Drawing.Point(6, 22); - this.dataGridView.Name = "dataGridView1"; - this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.Size = new System.Drawing.Size(466, 251); - this.dataGridView.TabIndex = 0; + this.buttonRef.Location = new System.Drawing.Point(512, 194); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(75, 23); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(512, 136); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(75, 23); + this.buttonUpd.TabIndex = 3; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(512, 79); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(75, 23); + this.buttonDel.TabIndex = 2; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); // // buttonAdd // @@ -154,44 +171,24 @@ this.buttonAdd.UseVisualStyleBackColor = true; this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); // - // buttonDel + // dataGridView // - this.buttonDel.Location = new System.Drawing.Point(512, 79); - this.buttonDel.Name = "buttonDel"; - this.buttonDel.Size = new System.Drawing.Size(75, 23); - this.buttonDel.TabIndex = 2; - this.buttonDel.Text = "Удалить"; - this.buttonDel.UseVisualStyleBackColor = true; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Identificator, + this.Count, + this.Provider}); + this.dataGridView.Location = new System.Drawing.Point(6, 22); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(466, 251); + this.dataGridView.TabIndex = 0; // - // buttonUpd + // Identificator // - this.buttonUpd.Location = new System.Drawing.Point(512, 136); - this.buttonUpd.Name = "buttonUpd"; - this.buttonUpd.Size = new System.Drawing.Size(75, 23); - this.buttonUpd.TabIndex = 3; - this.buttonUpd.Text = "Изменить"; - this.buttonUpd.UseVisualStyleBackColor = true; - // - // buttonRef - // - this.buttonRef.Location = new System.Drawing.Point(512, 194); - this.buttonRef.Name = "buttonRef"; - this.buttonRef.Size = new System.Drawing.Size(75, 23); - this.buttonRef.TabIndex = 4; - this.buttonRef.Text = "Обновить"; - this.buttonRef.UseVisualStyleBackColor = true; - // - // Id - // - this.Id.HeaderText = "Id"; - this.Id.Name = "Id"; - this.Id.Visible = false; - // - // Provider - // - this.Provider.HeaderText = "Поставщик"; - this.Provider.Name = "Provider"; - this.Provider.Width = 200; + this.Identificator.HeaderText = "Identificator"; + this.Identificator.Name = "Identificator"; + this.Identificator.Visible = false; // // Count // @@ -199,6 +196,12 @@ this.Count.Name = "Count"; this.Count.Width = 200; // + // Provider + // + this.Provider.HeaderText = "Поставщик"; + this.Provider.Name = "Provider"; + this.Provider.Width = 200; + // // FormComponent // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -239,8 +242,8 @@ private Button buttonDel; private Button buttonAdd; private DataGridView dataGridView; - private DataGridViewTextBoxColumn Id; - private DataGridViewTextBoxColumn Provider; + private DataGridViewTextBoxColumn Identificator; private DataGridViewTextBoxColumn Count; + private DataGridViewTextBoxColumn Provider; } } \ No newline at end of file diff --git a/Restaurant/RestaurantView/FormComponent.cs b/Restaurant/RestaurantView/FormComponent.cs index 0c37d53..a6ca37a 100644 --- a/Restaurant/RestaurantView/FormComponent.cs +++ b/Restaurant/RestaurantView/FormComponent.cs @@ -18,14 +18,14 @@ namespace RestaurantView public partial class FormComponent : Form { private readonly IComponentLogic _componentLogic; - private Dictionary _componentProviders; + private List<(IProviderModel, int, DateTime)> _componentProviders; private int? _id; public int Id { set { _id = value; } } public FormComponent(IComponentLogic componentLogic) { InitializeComponent(); _componentLogic = componentLogic; - _componentProviders = new Dictionary(); + _componentProviders = new List<(IProviderModel, int, DateTime)>(); } private void FormComponent_Load(object sender, EventArgs e) @@ -43,7 +43,7 @@ namespace RestaurantView textBoxName.Text = view.Name; textBoxPrice.Text = view.Price.ToString(); textBoxCount.Text = view.Count.ToString(); - _componentProviders = view.ComponentProviders ?? new Dictionary(); + _componentProviders = view.ComponentProviders ?? new List<(IProviderModel, int, DateTime)>(); LoadData(); } } @@ -88,7 +88,71 @@ namespace RestaurantView private void buttonAdd_Click(object sender, EventArgs e) { - + var service = Program.ServiceProvider?.GetService(typeof(FormComponentProvider)); + if (service is FormComponentProvider form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ProviderModel == null) + { + return; + } + _componentProviders.Add((form.ProviderModel, form.Count, form.Date)); + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormComponentProvider)); + if (service is FormComponentProvider form) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _componentProviders[id].Item2; + form.Date = _componentProviders[id].Item3; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ProviderModel == null) + { + return; + } + _componentProviders[form.Id] = (form.ProviderModel, form.Count, form.Date); + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _componentProviders?.Remove(((IProviderModel, int, DateTime))dataGridView.SelectedRows[0].Cells[0].Value); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); } private void LoadData() @@ -100,8 +164,9 @@ namespace RestaurantView dataGridView.Rows.Clear(); foreach (var pc in _componentProviders) { - dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.Name, pc.Value.Item2, pc.Value.Item3 }); + dataGridView.Rows.Add(new object[] { pc.Item1.Name, pc.Item2, pc.Item3 }); } + textBoxCount.Text = CalcCount().ToString(); } } catch (Exception ex) @@ -110,5 +175,15 @@ namespace RestaurantView MessageBoxIcon.Error); } } + + private double CalcCount() + { + double count = 0; + foreach (var elem in _componentProviders) + { + count += elem.Item2; + } + return count; + } } } diff --git a/Restaurant/RestaurantView/FormComponent.resx b/Restaurant/RestaurantView/FormComponent.resx index 4c5d442..0c2bddc 100644 --- a/Restaurant/RestaurantView/FormComponent.resx +++ b/Restaurant/RestaurantView/FormComponent.resx @@ -57,22 +57,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True - - + True True - - True - True - - True - \ No newline at end of file diff --git a/Restaurant/RestaurantView/FormComponentProvider.Designer.cs b/Restaurant/RestaurantView/FormComponentProvider.Designer.cs index 09c7141..9d5b0fa 100644 --- a/Restaurant/RestaurantView/FormComponentProvider.Designer.cs +++ b/Restaurant/RestaurantView/FormComponentProvider.Designer.cs @@ -28,12 +28,114 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.comboBoxProviders = new System.Windows.Forms.ComboBox(); + this.labelProviders = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.labelCount = new System.Windows.Forms.Label(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.dateTimePicker = new System.Windows.Forms.DateTimePicker(); + this.labelDate = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // comboBoxProviders + // + this.comboBoxProviders.FormattingEnabled = true; + this.comboBoxProviders.Location = new System.Drawing.Point(91, 33); + this.comboBoxProviders.Name = "comboBoxProviders"; + this.comboBoxProviders.Size = new System.Drawing.Size(219, 23); + this.comboBoxProviders.TabIndex = 0; + // + // labelProviders + // + this.labelProviders.AutoSize = true; + this.labelProviders.Location = new System.Drawing.Point(12, 36); + this.labelProviders.Name = "labelProviders"; + this.labelProviders.Size = new System.Drawing.Size(73, 15); + this.labelProviders.TabIndex = 1; + this.labelProviders.Text = "Поставщик:"; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(91, 75); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(219, 23); + this.textBoxCount.TabIndex = 2; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(10, 78); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(75, 15); + this.labelCount.TabIndex = 3; + this.labelCount.Text = "Количество:"; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(65, 157); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(176, 157); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отменить"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // dateTimePicker + // + this.dateTimePicker.Location = new System.Drawing.Point(91, 115); + this.dateTimePicker.Name = "dateTimePicker"; + this.dateTimePicker.Size = new System.Drawing.Size(219, 23); + this.dateTimePicker.TabIndex = 6; + // + // labelDate + // + this.labelDate.AutoSize = true; + this.labelDate.Location = new System.Drawing.Point(50, 115); + this.labelDate.Name = "labelDate"; + this.labelDate.Size = new System.Drawing.Size(35, 15); + this.labelDate.TabIndex = 7; + this.labelDate.Text = "Дата:"; + // + // FormComponentProvider + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); + this.ClientSize = new System.Drawing.Size(322, 206); + this.Controls.Add(this.labelDate); + this.Controls.Add(this.dateTimePicker); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelProviders); + this.Controls.Add(this.comboBoxProviders); + this.Name = "FormComponentProvider"; this.Text = "FormComponentProvider"; + this.ResumeLayout(false); + this.PerformLayout(); + } #endregion + + private ComboBox comboBoxProviders; + private Label labelProviders; + private TextBox textBoxCount; + private Label labelCount; + private Button buttonSave; + private Button buttonCancel; + private DateTimePicker dateTimePicker; + private Label labelDate; } } \ No newline at end of file diff --git a/Restaurant/RestaurantView/FormComponentProvider.cs b/Restaurant/RestaurantView/FormComponentProvider.cs index 9a522ad..7eb98e9 100644 --- a/Restaurant/RestaurantView/FormComponentProvider.cs +++ b/Restaurant/RestaurantView/FormComponentProvider.cs @@ -21,11 +21,11 @@ namespace RestaurantView { get { - return Convert.ToInt32(comboBoxComponent.SelectedValue); + return Convert.ToInt32(comboBoxProviders.SelectedValue); } set { - comboBoxComponent.SelectedValue = value; + comboBoxProviders.SelectedValue = value; } } @@ -52,16 +52,23 @@ namespace RestaurantView get { return Convert.ToInt32(textBoxCount.Text); } set { textBoxCount.Text = value.ToString(); } } + + public DateTime Date + { + get { return DateTime.Now; } + set { dateTimePicker.Value = value; } + } + public FormComponentProvider(IProviderLogic logic) { InitializeComponent(); _list = logic.ReadList(null); if (_list != null) { - comboBoxProvider.DisplayMember = "ComponentName"; - comboBoxProvider.ValueMember = "Id"; - comboBoxProvider.DataSource = _list; - comboBoxProvider.SelectedItem = null; + comboBoxProviders.DisplayMember = "Name"; + comboBoxProviders.ValueMember = "Id"; + comboBoxProviders.DataSource = _list; + comboBoxProviders.SelectedItem = null; } } @@ -73,7 +80,7 @@ namespace RestaurantView MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - if (comboBoxComponent.SelectedValue == null) + if (comboBoxProviders.SelectedValue == null) { MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); diff --git a/Restaurant/RestaurantView/FormComponentProvider.resx b/Restaurant/RestaurantView/FormComponentProvider.resx index 1af7de1..f298a7b 100644 --- a/Restaurant/RestaurantView/FormComponentProvider.resx +++ b/Restaurant/RestaurantView/FormComponentProvider.resx @@ -1,64 +1,4 @@ - - - + diff --git a/Restaurant/RestaurantView/FormCreateOrder.Designer.cs b/Restaurant/RestaurantView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..072b3a7 --- /dev/null +++ b/Restaurant/RestaurantView/FormCreateOrder.Designer.cs @@ -0,0 +1,226 @@ +namespace RestaurantView +{ + partial class FormCreateOrder + { + /// + /// 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.labelPrice = new System.Windows.Forms.Label(); + this.labelClient = new System.Windows.Forms.Label(); + this.comboBoxClients = new System.Windows.Forms.ComboBox(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.Identificator = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Product = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(44, 21); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(38, 15); + this.labelPrice.TabIndex = 2; + this.labelPrice.Text = "Цена:"; + // + // labelClient + // + this.labelClient.AutoSize = true; + this.labelClient.Location = new System.Drawing.Point(33, 55); + this.labelClient.Name = "labelClient"; + this.labelClient.Size = new System.Drawing.Size(49, 15); + this.labelClient.TabIndex = 3; + this.labelClient.Text = "Клиент:"; + // + // comboBoxClients + // + this.comboBoxClients.FormattingEnabled = true; + this.comboBoxClients.Location = new System.Drawing.Point(88, 52); + this.comboBoxClients.Name = "comboBoxClients"; + this.comboBoxClients.Size = new System.Drawing.Size(254, 23); + this.comboBoxClients.TabIndex = 5; + // + // textBoxPrice + // + this.textBoxPrice.Enabled = false; + this.textBoxPrice.Location = new System.Drawing.Point(88, 18); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(254, 23); + this.textBoxPrice.TabIndex = 7; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(195, 345); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 8; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(308, 345); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 9; + this.buttonCancel.Text = "Отменить"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.buttonRef); + this.groupBox1.Controls.Add(this.buttonDel); + this.groupBox1.Controls.Add(this.buttonUpd); + this.groupBox1.Controls.Add(this.buttonAdd); + this.groupBox1.Controls.Add(this.dataGridView); + this.groupBox1.Location = new System.Drawing.Point(12, 94); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(555, 234); + this.groupBox1.TabIndex = 10; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Продукты"; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(464, 168); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(75, 23); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(464, 122); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(75, 23); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(464, 76); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(75, 23); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(464, 33); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(75, 23); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Identificator, + this.Product, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(6, 22); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(447, 206); + this.dataGridView.TabIndex = 0; + // + // Identificator + // + this.Identificator.HeaderText = "Id"; + this.Identificator.Name = "Identificator"; + this.Identificator.Visible = false; + // + // Product + // + this.Product.HeaderText = "Продукт"; + this.Product.Name = "Product"; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.Name = "Count"; + // + // FormCreateOrder + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(579, 382); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.comboBoxClients); + this.Controls.Add(this.labelClient); + this.Controls.Add(this.labelPrice); + this.Name = "FormCreateOrder"; + this.Text = "Заказ"; + this.Load += new System.EventHandler(this.FormCreateOrder_Load); + this.groupBox1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private Label labelPrice; + private Label labelClient; + private ComboBox comboBoxClients; + private TextBox textBoxPrice; + private Button buttonSave; + private Button buttonCancel; + private GroupBox groupBox1; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn Identificator; + private DataGridViewTextBoxColumn Product; + private DataGridViewTextBoxColumn Count; + } +} \ No newline at end of file diff --git a/Restaurant/RestaurantView/FormCreateOrder.cs b/Restaurant/RestaurantView/FormCreateOrder.cs new file mode 100644 index 0000000..2cfe21c --- /dev/null +++ b/Restaurant/RestaurantView/FormCreateOrder.cs @@ -0,0 +1,212 @@ +using Microsoft.Extensions.Logging; +using RestaurantContracts.BindingModels; +using RestaurantContracts.BusinessLogicsContracts; +using RestaurantContracts.SearchModels; +using RestaurantDatabaseImplement.Models; +using RestaurantDataModels.Models; +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 RestaurantView +{ + public partial class FormCreateOrder : Form + { + private readonly IProductLogic _logicP; + private readonly IOrderLogic _logicO; + private readonly IClientLogic _logicC; + private int? _id; + private Dictionary _orderProducts; + public int Id { set { _id = value; } } + + public FormCreateOrder(IProductLogic logicP, IOrderLogic logicO, IClientLogic logicC) + { + InitializeComponent(); + _logicP = logicP; + _logicO = logicO; + _logicC = logicC; + _orderProducts = new Dictionary(); + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + try + { + var clients = _logicC.ReadList(null); + if (clients != null) + { + comboBoxClients.DisplayMember = "FirstName"; + comboBoxClients.ValueMember = "Id"; + comboBoxClients.DataSource = clients; + comboBoxClients.SelectedItem = null; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private double CalcPrice() + { + double price = 0; + foreach (var elem in _orderProducts) + { + price += elem.Value.Item1.Price * elem.Value.Item2; + } + return price; + } + + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + if (_orderProducts == null || _orderProducts.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + var model = new OrderBindingModel + { + Id = _id ?? 0, + Price = Convert.ToDouble(textBoxPrice.Text), + ClientId = Convert.ToInt32(comboBoxClients.SelectedValue), + Date = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc), + OrderProducts = _orderProducts + }; + var operationResult = _id.HasValue ? _logicO.Update(model) : + _logicO.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void LoadData() + { + try + { + if (_orderProducts != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _orderProducts) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.Type, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormOrderProduct)); + if (service is FormOrderProduct form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ProductModel == null) + { + return; + } + if (_orderProducts.ContainsKey(form.Id)) + { + _orderProducts[form.Id] = (form.ProductModel, form.Count); + } + else + { + _orderProducts.Add(form.Id, (form.ProductModel, form.Count)); + } + LoadData(); + } + } + + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormOrderProduct)); + if (service is FormOrderProduct form) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _orderProducts[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ProductModel == null) + { + return; + } + _orderProducts[form.Id] = (form.ProductModel, form.Count); + LoadData(); + } + } + } + + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _orderProducts?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Restaurant/RestaurantView/FormCreateOrder.resx b/Restaurant/RestaurantView/FormCreateOrder.resx new file mode 100644 index 0000000..27be160 --- /dev/null +++ b/Restaurant/RestaurantView/FormCreateOrder.resx @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/Restaurant/RestaurantView/FormMain.Designer.cs b/Restaurant/RestaurantView/FormMain.Designer.cs index 69781fc..c69eff5 100644 --- a/Restaurant/RestaurantView/FormMain.Designer.cs +++ b/Restaurant/RestaurantView/FormMain.Designer.cs @@ -34,6 +34,8 @@ this.ClientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ProvidersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ProductsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.buttonUpd = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -55,13 +57,15 @@ this.buttonAdd.TabIndex = 1; this.buttonAdd.Text = "Создать заказ"; this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); // // menuStrip1 // this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ClientsToolStripMenuItem, this.ProvidersToolStripMenuItem, - this.ComponentsToolStripMenuItem}); + this.ComponentsToolStripMenuItem, + this.ProductsToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new System.Drawing.Size(1163, 24); @@ -89,11 +93,29 @@ this.ComponentsToolStripMenuItem.Text = "Компоненты"; this.ComponentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click); // + // ProductsToolStripMenuItem + // + this.ProductsToolStripMenuItem.Name = "ProductsToolStripMenuItem"; + this.ProductsToolStripMenuItem.Size = new System.Drawing.Size(74, 20); + this.ProductsToolStripMenuItem.Text = "Продукты"; + this.ProductsToolStripMenuItem.Click += new System.EventHandler(this.ProductsToolStripMenuItem_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(785, 12); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(152, 45); + this.buttonUpd.TabIndex = 3; + this.buttonUpd.Text = "Обновить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.buttonUpd_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1163, 634); + this.Controls.Add(this.buttonUpd); this.Controls.Add(this.buttonAdd); this.Controls.Add(this.dataGridView); this.Controls.Add(this.menuStrip1); @@ -117,5 +139,7 @@ private ToolStripMenuItem ClientsToolStripMenuItem; private ToolStripMenuItem ProvidersToolStripMenuItem; private ToolStripMenuItem ComponentsToolStripMenuItem; + private ToolStripMenuItem ProductsToolStripMenuItem; + private Button buttonUpd; } } \ No newline at end of file diff --git a/Restaurant/RestaurantView/FormMain.cs b/Restaurant/RestaurantView/FormMain.cs index 16365e2..7dc42cb 100644 --- a/Restaurant/RestaurantView/FormMain.cs +++ b/Restaurant/RestaurantView/FormMain.cs @@ -30,6 +30,7 @@ namespace RestaurantView { dataGridView.DataSource = list; dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["OrderProducts"].Visible = false; } } catch (Exception ex) @@ -69,5 +70,29 @@ namespace RestaurantView form.ShowDialog(); } } + + private void ProductsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormProducts)); + if (service is FormProducts form) + { + form.ShowDialog(); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void buttonUpd_Click(object sender, EventArgs e) + { + LoadData(); + } } } diff --git a/Restaurant/RestaurantView/FormOrderProduct.Designer.cs b/Restaurant/RestaurantView/FormOrderProduct.Designer.cs new file mode 100644 index 0000000..b491d47 --- /dev/null +++ b/Restaurant/RestaurantView/FormOrderProduct.Designer.cs @@ -0,0 +1,119 @@ +namespace RestaurantView +{ + partial class FormOrderProduct + { + /// + /// 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.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.labelProduct = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.comboBoxProduct = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(96, 107); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 0; + this.buttonSave.Text = "Сохранитьъ"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(220, 107); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 1; + this.buttonCancel.Text = "Отменить"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // labelProduct + // + this.labelProduct.AutoSize = true; + this.labelProduct.Location = new System.Drawing.Point(31, 24); + this.labelProduct.Name = "labelProduct"; + this.labelProduct.Size = new System.Drawing.Size(56, 15); + this.labelProduct.TabIndex = 2; + this.labelProduct.Text = "Продукт:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 65); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(75, 15); + this.labelCount.TabIndex = 3; + this.labelCount.Text = "Количество:"; + // + // comboBoxProduct + // + this.comboBoxProduct.FormattingEnabled = true; + this.comboBoxProduct.Location = new System.Drawing.Point(93, 21); + this.comboBoxProduct.Name = "comboBoxProduct"; + this.comboBoxProduct.Size = new System.Drawing.Size(245, 23); + this.comboBoxProduct.TabIndex = 4; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(92, 62); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(246, 23); + this.textBoxCount.TabIndex = 5; + // + // FormOrderProduct + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(391, 147); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxProduct); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelProduct); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Name = "FormOrderProduct"; + this.Text = "FormOrderProduct"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private Label labelProduct; + private Label labelCount; + private ComboBox comboBoxProduct; + private TextBox textBoxCount; + } +} \ No newline at end of file diff --git a/Restaurant/RestaurantView/FormOrderProduct.cs b/Restaurant/RestaurantView/FormOrderProduct.cs new file mode 100644 index 0000000..6557731 --- /dev/null +++ b/Restaurant/RestaurantView/FormOrderProduct.cs @@ -0,0 +1,90 @@ +using RestaurantContracts.BusinessLogicsContracts; +using RestaurantContracts.ViewModels; +using RestaurantDataModels.Models; +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 RestaurantView +{ + public partial class FormOrderProduct : Form + { + private readonly List? _list; + public int Id + { + get + { + return Convert.ToInt32(comboBoxProduct.SelectedValue); + } + set + { + comboBoxProduct.SelectedValue = value; + } + } + public IProductModel? ProductModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set { textBoxCount.Text = value.ToString(); } + } + public FormOrderProduct(IProductLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxProduct.DisplayMember = "Type"; + comboBoxProduct.ValueMember = "Id"; + comboBoxProduct.DataSource = _list; + comboBoxProduct.SelectedItem = null; + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxProduct.SelectedValue == null) + { + MessageBox.Show("Выберите продукт", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/Restaurant/RestaurantView/FormOrderProduct.resx b/Restaurant/RestaurantView/FormOrderProduct.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Restaurant/RestaurantView/FormOrderProduct.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Restaurant/RestaurantView/FormProduct.Designer.cs b/Restaurant/RestaurantView/FormProduct.Designer.cs new file mode 100644 index 0000000..00411f3 --- /dev/null +++ b/Restaurant/RestaurantView/FormProduct.Designer.cs @@ -0,0 +1,226 @@ +namespace RestaurantView +{ + partial class FormProduct + { + /// + /// 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.labelName = new System.Windows.Forms.Label(); + this.labelPrice = new System.Windows.Forms.Label(); + this.textBoxType = new System.Windows.Forms.TextBox(); + this.textBoxPrice = new System.Windows.Forms.TextBox(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.buttonRef = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.Identificator = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Component = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(20, 29); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(62, 15); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название:"; + // + // labelPrice + // + this.labelPrice.AutoSize = true; + this.labelPrice.Location = new System.Drawing.Point(44, 70); + this.labelPrice.Name = "labelPrice"; + this.labelPrice.Size = new System.Drawing.Size(38, 15); + this.labelPrice.TabIndex = 1; + this.labelPrice.Text = "Цена:"; + // + // textBoxType + // + this.textBoxType.Location = new System.Drawing.Point(88, 26); + this.textBoxType.Name = "textBoxType"; + this.textBoxType.Size = new System.Drawing.Size(429, 23); + this.textBoxType.TabIndex = 2; + // + // textBoxPrice + // + this.textBoxPrice.Enabled = false; + this.textBoxPrice.Location = new System.Drawing.Point(88, 67); + this.textBoxPrice.Name = "textBoxPrice"; + this.textBoxPrice.Size = new System.Drawing.Size(429, 23); + this.textBoxPrice.TabIndex = 3; + // + // groupBox1 + // + this.groupBox1.Controls.Add(this.buttonRef); + this.groupBox1.Controls.Add(this.buttonUpd); + this.groupBox1.Controls.Add(this.buttonDel); + this.groupBox1.Controls.Add(this.buttonAdd); + this.groupBox1.Controls.Add(this.dataGridView); + this.groupBox1.Location = new System.Drawing.Point(20, 124); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(643, 281); + this.groupBox1.TabIndex = 4; + this.groupBox1.TabStop = false; + this.groupBox1.Text = "Поставщики"; + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(531, 184); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(75, 23); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(531, 84); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(75, 23); + this.buttonUpd.TabIndex = 3; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(531, 132); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(75, 23); + this.buttonDel.TabIndex = 2; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(531, 36); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(75, 23); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Identificator, + this.Component, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(6, 22); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(491, 253); + this.dataGridView.TabIndex = 0; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(217, 423); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(87, 32); + this.buttonSave.TabIndex = 5; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(376, 423); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(77, 32); + this.buttonCancel.TabIndex = 6; + this.buttonCancel.Text = "Отменить"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // Identificator + // + this.Identificator.HeaderText = "Id"; + this.Identificator.Name = "Identificator"; + this.Identificator.Visible = false; + // + // Component + // + this.Component.HeaderText = "Компонент"; + this.Component.Name = "Component"; + // + // Count + // + this.Count.HeaderText = "Количество"; + this.Count.Name = "Count"; + // + // FormProduct + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(692, 472); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.groupBox1); + this.Controls.Add(this.textBoxPrice); + this.Controls.Add(this.textBoxType); + this.Controls.Add(this.labelPrice); + this.Controls.Add(this.labelName); + this.Name = "FormProduct"; + this.Text = "Продукт"; + this.Load += new System.EventHandler(this.FormProduct_Load); + this.groupBox1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private Label labelPrice; + private TextBox textBoxType; + private TextBox textBoxPrice; + private GroupBox groupBox1; + private DataGridView dataGridView; + private Button buttonRef; + private Button buttonUpd; + private Button buttonDel; + private Button buttonAdd; + private Button buttonSave; + private Button buttonCancel; + private DataGridViewTextBoxColumn Identificator; + private DataGridViewTextBoxColumn Component; + private DataGridViewTextBoxColumn Count; + } +} \ No newline at end of file diff --git a/Restaurant/RestaurantView/FormProduct.cs b/Restaurant/RestaurantView/FormProduct.cs new file mode 100644 index 0000000..c707442 --- /dev/null +++ b/Restaurant/RestaurantView/FormProduct.cs @@ -0,0 +1,221 @@ +using Microsoft.Extensions.Logging; +using RestaurantContracts.BindingModels; +using RestaurantContracts.BusinessLogicsContracts; +using RestaurantContracts.SearchModels; +using RestaurantContracts.ViewModels; +using RestaurantDataModels.Models; +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 RestaurantView +{ + public partial class FormProduct : Form + { + private readonly IProductLogic _logic; + private int? _id; + private Dictionary _productComponents; + public int Id { set { _id = value; } } + + public FormProduct(IProductLogic logic) + { + InitializeComponent(); + _logic = logic; + _productComponents = new Dictionary(); + } + + private void FormProduct_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + var view = _logic.ReadElement(new ProductSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxType.Text = view.Type; + textBoxPrice.Text = view.Price.ToString(); + _productComponents = view.ProductComponents ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + try + { + if (_productComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _productComponents) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.Name, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormProductComponent)); + if (service is FormProductComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + if (_productComponents.ContainsKey(form.Id)) + { + _productComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _productComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + } + } + + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormProductComponent)); + if (service is FormProductComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _productComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _productComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _productComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxType.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + return; + } + if (_productComponents == null || _productComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + try + { + var model = new ProductBindingModel + { + Id = _id ?? 0, + Type = textBoxType.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + Count = 1, + ProductComponents = _productComponents + }; + var operationResult = _id.HasValue ? _logic.Update(model) : + _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", + MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private double CalcPrice() + { + double price = 0; + foreach (var elem in _productComponents) + { + price += ((elem.Value.Item1?.Price ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/Restaurant/RestaurantView/FormProduct.resx b/Restaurant/RestaurantView/FormProduct.resx new file mode 100644 index 0000000..c165e95 --- /dev/null +++ b/Restaurant/RestaurantView/FormProduct.resx @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/Restaurant/RestaurantView/FormProductComponent.Designer.cs b/Restaurant/RestaurantView/FormProductComponent.Designer.cs new file mode 100644 index 0000000..f44abf9 --- /dev/null +++ b/Restaurant/RestaurantView/FormProductComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace RestaurantView +{ + partial class FormProductComponent + { + /// + /// 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.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.comboBoxComponent = new System.Windows.Forms.ComboBox(); + this.labelComponent = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(98, 119); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 0; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(209, 119); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 1; + this.buttonCancel.Text = "Отменить"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // comboBoxComponent + // + this.comboBoxComponent.FormattingEnabled = true; + this.comboBoxComponent.Location = new System.Drawing.Point(98, 24); + this.comboBoxComponent.Name = "comboBoxComponent"; + this.comboBoxComponent.Size = new System.Drawing.Size(242, 23); + this.comboBoxComponent.TabIndex = 2; + // + // labelComponent + // + this.labelComponent.AutoSize = true; + this.labelComponent.Location = new System.Drawing.Point(20, 27); + this.labelComponent.Name = "labelComponent"; + this.labelComponent.Size = new System.Drawing.Size(72, 15); + this.labelComponent.TabIndex = 3; + this.labelComponent.Text = "Компонент:"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(12, 68); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(75, 15); + this.labelCount.TabIndex = 4; + this.labelCount.Text = "Количество:"; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(98, 65); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(242, 23); + this.textBoxCount.TabIndex = 5; + // + // FormProductComponent + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(365, 157); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelComponent); + this.Controls.Add(this.comboBoxComponent); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Name = "FormProductComponent"; + this.Text = "FormProductComponent"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private ComboBox comboBoxComponent; + private Label labelComponent; + private Label labelCount; + private TextBox textBoxCount; + } +} \ No newline at end of file diff --git a/Restaurant/RestaurantView/FormProductComponent.cs b/Restaurant/RestaurantView/FormProductComponent.cs new file mode 100644 index 0000000..0b2b43f --- /dev/null +++ b/Restaurant/RestaurantView/FormProductComponent.cs @@ -0,0 +1,90 @@ +using RestaurantContracts.BusinessLogicsContracts; +using RestaurantContracts.ViewModels; +using RestaurantDataModels.Models; +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 RestaurantView +{ + public partial class FormProductComponent : Form + { + private readonly List? _list; + public int Id + { + get + { + return Convert.ToInt32(comboBoxComponent.SelectedValue); + } + set + { + comboBoxComponent.SelectedValue = value; + } + } + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set { textBoxCount.Text = value.ToString(); } + } + public FormProductComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "Name"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/Restaurant/RestaurantView/FormProductComponent.resx b/Restaurant/RestaurantView/FormProductComponent.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Restaurant/RestaurantView/FormProductComponent.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Restaurant/RestaurantView/FormProducts.Designer.cs b/Restaurant/RestaurantView/FormProducts.Designer.cs new file mode 100644 index 0000000..0b6473a --- /dev/null +++ b/Restaurant/RestaurantView/FormProducts.Designer.cs @@ -0,0 +1,114 @@ +namespace RestaurantView +{ + partial class FormProducts + { + /// + /// 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(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonUpd = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + 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(656, 452); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(691, 44); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(86, 33); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(691, 116); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(86, 34); + this.buttonUpd.TabIndex = 2; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(691, 187); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(86, 36); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(691, 260); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(86, 41); + this.buttonRef.TabIndex = 4; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormProducts + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(810, 450); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormProducts"; + this.Text = "Продукты"; + this.Load += new System.EventHandler(this.FormProducts_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/Restaurant/RestaurantView/FormProducts.cs b/Restaurant/RestaurantView/FormProducts.cs new file mode 100644 index 0000000..e52d9c7 --- /dev/null +++ b/Restaurant/RestaurantView/FormProducts.cs @@ -0,0 +1,109 @@ +using Microsoft.Extensions.Logging; +using RestaurantContracts.BindingModels; +using RestaurantContracts.BusinessLogicsContracts; +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 RestaurantView +{ + public partial class FormProducts : Form + { + private readonly IProductLogic _logic; + public FormProducts(IProductLogic logic) + { + InitializeComponent(); + _logic = logic; + } + + private void FormProducts_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["Type"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ProductComponents"].Visible = false; + dataGridView.Columns["Count"].Visible = false; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormProduct)); + if (service is FormProduct form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormProduct)); + if (service is FormProduct form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + try + { + if (!_logic.Delete(new ProductBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Restaurant/RestaurantView/FormProducts.resx b/Restaurant/RestaurantView/FormProducts.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/Restaurant/RestaurantView/FormProducts.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/Restaurant/RestaurantView/Program.cs b/Restaurant/RestaurantView/Program.cs index 9933725..eda9b82 100644 --- a/Restaurant/RestaurantView/Program.cs +++ b/Restaurant/RestaurantView/Program.cs @@ -47,6 +47,12 @@ namespace RestaurantView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file