From 0f6ddf9ba807ae7d4dcf324963b1814e4ff3a69d Mon Sep 17 00:00:00 2001 From: Yourdax Date: Sun, 26 May 2024 21:55:55 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9E=D1=81=D1=82=D0=B0=D0=BB=D0=B8=D1=81?= =?UTF-8?q?=D1=8C=20=D0=BE=D1=82=D1=87=D0=B5=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/OrderLogic.cs | 4 - .../BindingModels/OrderBindingModel.cs | 28 ++-- .../SearchModels/OrderSearchModel.cs | 1 + .../ViewModels/OrderViewModel.cs | 45 +++--- .../Models/IOrderModel.cs | 2 +- .../Implements/OrderStorage.cs | 5 +- ... 20240526174629_InitialCreate.Designer.cs} | 116 +++++++------- ...ate.cs => 20240526174629_InitialCreate.cs} | 5 +- .../DiningRoomDatabaseModelSnapshot.cs | 114 +++++++------- .../Models/Order.cs | 140 ++++++++--------- DiningRoom/DiningRoomView/FormCreateOrder.cs | 37 +++-- .../DiningRoomView/FormOrders.Designer.cs | 122 ++++++++------- DiningRoom/DiningRoomView/FormOrders.cs | 122 ++++++++------- .../DiningRoomView/FormOrdersOld.Designer.cs | 127 +++++++++++++++ DiningRoom/DiningRoomView/FormOrdersOld.cs | 145 ++++++++++++++++++ DiningRoom/DiningRoomView/FormOrdersOld.resx | 120 +++++++++++++++ .../FormReportOrders.Designer.cs | 141 +++++++++++++++++ DiningRoom/DiningRoomView/FormReportOrders.cs | 101 ++++++++++++ .../DiningRoomView/FormReportOrders.resx | 120 +++++++++++++++ .../FormReportWoodComponents.Designer.cs | 114 ++++++++++++++ .../FormReportWoodComponents.cs | 79 ++++++++++ .../FormReportWoodComponents.resx | 120 +++++++++++++++ 22 files changed, 1422 insertions(+), 386 deletions(-) rename DiningRoom/DiningRoomDatabaseImplement/Migrations/{20240526163252_InitialCreate.Designer.cs => 20240526174629_InitialCreate.Designer.cs} (97%) rename DiningRoom/DiningRoomDatabaseImplement/Migrations/{20240526163252_InitialCreate.cs => 20240526174629_InitialCreate.cs} (98%) create mode 100644 DiningRoom/DiningRoomView/FormOrdersOld.Designer.cs create mode 100644 DiningRoom/DiningRoomView/FormOrdersOld.cs create mode 100644 DiningRoom/DiningRoomView/FormOrdersOld.resx create mode 100644 DiningRoom/DiningRoomView/FormReportOrders.Designer.cs create mode 100644 DiningRoom/DiningRoomView/FormReportOrders.cs create mode 100644 DiningRoom/DiningRoomView/FormReportOrders.resx create mode 100644 DiningRoom/DiningRoomView/FormReportWoodComponents.Designer.cs create mode 100644 DiningRoom/DiningRoomView/FormReportWoodComponents.cs create mode 100644 DiningRoom/DiningRoomView/FormReportWoodComponents.resx diff --git a/DiningRoom/DiningRoomBusinessLogic/BusinessLogic/OrderLogic.cs b/DiningRoom/DiningRoomBusinessLogic/BusinessLogic/OrderLogic.cs index 5295162..bc03e33 100644 --- a/DiningRoom/DiningRoomBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/DiningRoom/DiningRoomBusinessLogic/BusinessLogic/OrderLogic.cs @@ -61,10 +61,6 @@ namespace DiningRoomBusinessLogic.BusinessLogic { throw new ArgumentNullException(nameof(model)); } - if (!withParams) - { - return; - } if (model.DateCreate > DateTime.Now) { throw new ArgumentException($"Дата создания заказа {model.DateCreate} не может быть в будущем"); diff --git a/DiningRoom/DiningRoomContracts/BindingModels/OrderBindingModel.cs b/DiningRoom/DiningRoomContracts/BindingModels/OrderBindingModel.cs index 64657d7..618d93f 100644 --- a/DiningRoom/DiningRoomContracts/BindingModels/OrderBindingModel.cs +++ b/DiningRoom/DiningRoomContracts/BindingModels/OrderBindingModel.cs @@ -1,23 +1,15 @@ using DiningRoomDataModels.Enums; using DiningRoomDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace DiningRoomContracts.BindingModels +public class OrderBindingModel : IOrderModel { - public class OrderBindingModel : IOrderModel - { - public int Id { get; set; } - public string Name { get; set; } = string.Empty; - public int UserId { get; set; } - public int ProductId { get; set; } - public string ProductName { get; set; } = string.Empty; - public DateTime DateCreate { get; set; } = DateTime.Now; - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - public int Count { get; set; } - public double Sum { get; set; } - } + public int Id { get; set; } + public string Name { get; set; } = string.Empty; + public int UserId { get; set; } + public int? ProductId { get; set; } + public string ProductName { get; set; } = string.Empty; + public DateTime DateCreate { get; set; } = DateTime.Now; + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public int Count { get; set; } + public double Sum { get; set; } } diff --git a/DiningRoom/DiningRoomContracts/SearchModels/OrderSearchModel.cs b/DiningRoom/DiningRoomContracts/SearchModels/OrderSearchModel.cs index ad15058..1d4db81 100644 --- a/DiningRoom/DiningRoomContracts/SearchModels/OrderSearchModel.cs +++ b/DiningRoom/DiningRoomContracts/SearchModels/OrderSearchModel.cs @@ -11,6 +11,7 @@ namespace DiningRoomContracts.SearchModels public class OrderSearchModel { public int? Id { get; set; } + public int? ProductId { get; set; } public string Name { get; set; } = string.Empty; public int? UserId { get; set; } diff --git a/DiningRoom/DiningRoomContracts/ViewModels/OrderViewModel.cs b/DiningRoom/DiningRoomContracts/ViewModels/OrderViewModel.cs index 0a0f6b0..a9567b9 100644 --- a/DiningRoom/DiningRoomContracts/ViewModels/OrderViewModel.cs +++ b/DiningRoom/DiningRoomContracts/ViewModels/OrderViewModel.cs @@ -1,33 +1,24 @@ using DiningRoomDataModels.Enums; using DiningRoomDataModels.Models; -using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace DiningRoomContracts.ViewModels +public class OrderViewModel : IOrderModel { - public class OrderViewModel : IOrderModel - { - [DisplayName("Номер")] - public int Id { get; set; } - [DisplayName("Название заказа")] - public string Name { get; set; } = string.Empty; - public int UserId { get; set; } - public string? Login { get; set; } = string.Empty; - public int ProductId { get; set; } - [DisplayName("Дата Создания")] - public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Блюдо")] - public string ProductName { get; set; } = string.Empty; - [DisplayName("Статус")] - public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Количество")] - public int Count { get; set; } - [DisplayName("Стоимость")] - public double Sum { get; set; } - - } + [DisplayName("Номер")] + public int Id { get; set; } + [DisplayName("Название заказа")] + public string Name { get; set; } = string.Empty; + public int UserId { get; set; } + public string? Login { get; set; } = string.Empty; + public int? ProductId { get; set; } + [DisplayName("Дата Создания")] + public DateTime DateCreate { get; set; } = DateTime.Now; + [DisplayName("Блюдо")] + public string? ProductName { get; set; } = string.Empty; + [DisplayName("Статус")] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [DisplayName("Количество")] + public int Count { get; set; } + [DisplayName("Стоимость")] + public double Sum { get; set; } } diff --git a/DiningRoom/DiningRoomDataModels/Models/IOrderModel.cs b/DiningRoom/DiningRoomDataModels/Models/IOrderModel.cs index 7818980..b150ad8 100644 --- a/DiningRoom/DiningRoomDataModels/Models/IOrderModel.cs +++ b/DiningRoom/DiningRoomDataModels/Models/IOrderModel.cs @@ -18,7 +18,7 @@ namespace DiningRoomDataModels.Models /// Дата создания заказа /// DateTime DateCreate { get; } - int ProductId { get; } + int? ProductId { get; } /// /// Статус заказа /// diff --git a/DiningRoom/DiningRoomDatabaseImplement/Implements/OrderStorage.cs b/DiningRoom/DiningRoomDatabaseImplement/Implements/OrderStorage.cs index d47d3ab..082db57 100644 --- a/DiningRoom/DiningRoomDatabaseImplement/Implements/OrderStorage.cs +++ b/DiningRoom/DiningRoomDatabaseImplement/Implements/OrderStorage.cs @@ -84,10 +84,6 @@ namespace DiningRoomDatabaseImplement.Implements } using var context = new DiningRoomDatabase(); - if (newOrder == null) - { - return null; - } context.Orders.Add(newOrder); context.SaveChanges(); return newOrder.GetViewModel; @@ -106,5 +102,6 @@ namespace DiningRoomDatabaseImplement.Implements context.SaveChanges(); return order.GetViewModel; } + } } diff --git a/DiningRoom/DiningRoomDatabaseImplement/Migrations/20240526163252_InitialCreate.Designer.cs b/DiningRoom/DiningRoomDatabaseImplement/Migrations/20240526174629_InitialCreate.Designer.cs similarity index 97% rename from DiningRoom/DiningRoomDatabaseImplement/Migrations/20240526163252_InitialCreate.Designer.cs rename to DiningRoom/DiningRoomDatabaseImplement/Migrations/20240526174629_InitialCreate.Designer.cs index 4d1b197..5460de8 100644 --- a/DiningRoom/DiningRoomDatabaseImplement/Migrations/20240526163252_InitialCreate.Designer.cs +++ b/DiningRoom/DiningRoomDatabaseImplement/Migrations/20240526174629_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace DiningRoomDatabaseImplement.Migrations { [DbContext(typeof(DiningRoomDatabase))] - [Migration("20240526163252_InitialCreate")] + [Migration("20240526174629_InitialCreate")] partial class InitialCreate { /// @@ -104,45 +104,6 @@ namespace DiningRoomDatabaseImplement.Migrations b.ToTable("DrinkComponents"); }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("integer"); - - b.Property("DateCreate") - .HasColumnType("timestamp without time zone"); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.Property("ProductId") - .HasColumnType("integer"); - - b.Property("Status") - .HasColumnType("integer"); - - b.Property("Sum") - .HasColumnType("double precision"); - - b.Property("UserId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("ProductId"); - - b.HasIndex("UserId"); - - b.ToTable("Orders"); - }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Product", b => { b.Property("Id") @@ -249,6 +210,45 @@ namespace DiningRoomDatabaseImplement.Migrations b.ToTable("Drinks"); }); + modelBuilder.Entity("Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("DateCreate") + .HasColumnType("timestamp without time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("ProductId") + .HasColumnType("integer"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("Sum") + .HasColumnType("double precision"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("UserId"); + + b.ToTable("Orders"); + }); + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Card", b => { b.HasOne("DiningRoomDatabaseImplement.Models.User", "User") @@ -290,25 +290,6 @@ namespace DiningRoomDatabaseImplement.Migrations b.Navigation("Drink"); }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Order", b => - { - b.HasOne("DiningRoomDatabaseImplement.Models.Product", "Product") - .WithMany("Order") - .HasForeignKey("ProductId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("DiningRoomDatabaseImplement.Models.User", "User") - .WithMany("Orders") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Product"); - - b.Navigation("User"); - }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Product", b => { b.HasOne("DiningRoomDatabaseImplement.Models.User", "User") @@ -356,6 +337,23 @@ namespace DiningRoomDatabaseImplement.Migrations b.Navigation("User"); }); + modelBuilder.Entity("Order", b => + { + b.HasOne("DiningRoomDatabaseImplement.Models.Product", "Product") + .WithMany("Order") + .HasForeignKey("ProductId"); + + b.HasOne("DiningRoomDatabaseImplement.Models.User", "User") + .WithMany("Orders") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + + b.Navigation("User"); + }); + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Card", b => { b.Navigation("Drinks"); diff --git a/DiningRoom/DiningRoomDatabaseImplement/Migrations/20240526163252_InitialCreate.cs b/DiningRoom/DiningRoomDatabaseImplement/Migrations/20240526174629_InitialCreate.cs similarity index 98% rename from DiningRoom/DiningRoomDatabaseImplement/Migrations/20240526163252_InitialCreate.cs rename to DiningRoom/DiningRoomDatabaseImplement/Migrations/20240526174629_InitialCreate.cs index 67d1422..d1027c1 100644 --- a/DiningRoom/DiningRoomDatabaseImplement/Migrations/20240526163252_InitialCreate.cs +++ b/DiningRoom/DiningRoomDatabaseImplement/Migrations/20240526174629_InitialCreate.cs @@ -125,7 +125,7 @@ namespace DiningRoomDatabaseImplement.Migrations Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), Name = table.Column(type: "text", nullable: false), - ProductId = table.Column(type: "integer", nullable: false), + ProductId = table.Column(type: "integer", nullable: true), Count = table.Column(type: "integer", nullable: false), Sum = table.Column(type: "double precision", nullable: false), Status = table.Column(type: "integer", nullable: false), @@ -139,8 +139,7 @@ namespace DiningRoomDatabaseImplement.Migrations name: "FK_Orders_Products_ProductId", column: x => x.ProductId, principalTable: "Products", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); + principalColumn: "Id"); table.ForeignKey( name: "FK_Orders_Users_UserId", column: x => x.UserId, diff --git a/DiningRoom/DiningRoomDatabaseImplement/Migrations/DiningRoomDatabaseModelSnapshot.cs b/DiningRoom/DiningRoomDatabaseImplement/Migrations/DiningRoomDatabaseModelSnapshot.cs index c380025..7ed8d9b 100644 --- a/DiningRoom/DiningRoomDatabaseImplement/Migrations/DiningRoomDatabaseModelSnapshot.cs +++ b/DiningRoom/DiningRoomDatabaseImplement/Migrations/DiningRoomDatabaseModelSnapshot.cs @@ -101,45 +101,6 @@ namespace DiningRoomDatabaseImplement.Migrations b.ToTable("DrinkComponents"); }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); - - b.Property("Count") - .HasColumnType("integer"); - - b.Property("DateCreate") - .HasColumnType("timestamp without time zone"); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.Property("ProductId") - .HasColumnType("integer"); - - b.Property("Status") - .HasColumnType("integer"); - - b.Property("Sum") - .HasColumnType("double precision"); - - b.Property("UserId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("ProductId"); - - b.HasIndex("UserId"); - - b.ToTable("Orders"); - }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Product", b => { b.Property("Id") @@ -246,6 +207,45 @@ namespace DiningRoomDatabaseImplement.Migrations b.ToTable("Drinks"); }); + modelBuilder.Entity("Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("DateCreate") + .HasColumnType("timestamp without time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("ProductId") + .HasColumnType("integer"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("Sum") + .HasColumnType("double precision"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("UserId"); + + b.ToTable("Orders"); + }); + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Card", b => { b.HasOne("DiningRoomDatabaseImplement.Models.User", "User") @@ -287,25 +287,6 @@ namespace DiningRoomDatabaseImplement.Migrations b.Navigation("Drink"); }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Order", b => - { - b.HasOne("DiningRoomDatabaseImplement.Models.Product", "Product") - .WithMany("Order") - .HasForeignKey("ProductId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("DiningRoomDatabaseImplement.Models.User", "User") - .WithMany("Orders") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Product"); - - b.Navigation("User"); - }); - modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Product", b => { b.HasOne("DiningRoomDatabaseImplement.Models.User", "User") @@ -353,6 +334,23 @@ namespace DiningRoomDatabaseImplement.Migrations b.Navigation("User"); }); + modelBuilder.Entity("Order", b => + { + b.HasOne("DiningRoomDatabaseImplement.Models.Product", "Product") + .WithMany("Order") + .HasForeignKey("ProductId"); + + b.HasOne("DiningRoomDatabaseImplement.Models.User", "User") + .WithMany("Orders") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + + b.Navigation("User"); + }); + modelBuilder.Entity("DiningRoomDatabaseImplement.Models.Card", b => { b.Navigation("Drinks"); diff --git a/DiningRoom/DiningRoomDatabaseImplement/Models/Order.cs b/DiningRoom/DiningRoomDatabaseImplement/Models/Order.cs index 835274d..70f256f 100644 --- a/DiningRoom/DiningRoomDatabaseImplement/Models/Order.cs +++ b/DiningRoom/DiningRoomDatabaseImplement/Models/Order.cs @@ -1,88 +1,82 @@ using DiningRoomContracts.BindingModels; using DiningRoomContracts.ViewModels; +using DiningRoomDatabaseImplement.Models; +using DiningRoomDatabaseImplement; using DiningRoomDataModels.Enums; using DiningRoomDataModels.Models; -using System; -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace DiningRoomDatabaseImplement.Models +public class Order : IOrderModel { - public class Order : IOrderModel - { - [Required] - public string Name { get; set; } - public int Id { get; set; } + [Required] + public string Name { get; set; } + public int Id { get; set; } - public int ProductId { get; set; } + public int? ProductId { get; set; } - public int Count { get; set; } + public int Count { get; set; } - public double Sum { get; set; } - [Required] - public OrderStatus Status { get; set; } - [Required] - public DateTime DateCreate { get; set; } - public int UserId { get; set; } - public User User { get; set; } + public double Sum { get; set; } + [Required] + public OrderStatus Status { get; set; } + [Required] + public DateTime DateCreate { get; set; } + public int UserId { get; set; } + public User User { get; set; } - public virtual Product Product { get; set; } + public virtual Product? Product { get; set; } + public static Order? Create(OrderBindingModel model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + Name = model.Name, + UserId = model.UserId, + ProductId = model.ProductId, + Count = model.Count, + Sum = model.Sum, + DateCreate = model.DateCreate, + Status = model.Status, + }; + } - public static Order? Create(OrderBindingModel model) - { - if (model == null) - { - return null; - } - return new Order() - { - Id = model.Id, - Name = model.Name, - UserId = model.UserId, - ProductId = model.ProductId, - DateCreate = model.DateCreate, - Status = model.Status, - Count = model.Count, - Sum = model.Sum, - }; - } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + using var context = new DiningRoomDatabase(); + Status = model.Status; + ProductId = model.ProductId; + Count = model.Count; + Sum = model.Sum; + context.SaveChanges(); + } - public void Update(OrderBindingModel? model) - { - if (model == null) - { - return; - } - using var context = new DiningRoomDatabase(); - Name = model.Name; - Status = model.Status; - context.SaveChanges(); - } - - public OrderViewModel GetViewModel - { - get - { - using var context = new DiningRoomDatabase(); - return new OrderViewModel - { - Id = Id, - Name = Name, - UserId = UserId, - Login = context.Users.FirstOrDefault(x=> x.Id == UserId)?.Login ?? string.Empty, - ProductId = ProductId, - ProductName = context.Products.FirstOrDefault(x => x.Id == ProductId)?.ProductName ?? string.Empty, - DateCreate = DateCreate, - Status = Status, - Count = Count, - Sum = Sum - }; - } - } - } + public OrderViewModel GetViewModel + { + get + { + using var context = new DiningRoomDatabase(); + return new OrderViewModel + { + Id = Id, + Name = Name, + UserId = UserId, + Login = context.Users.FirstOrDefault(x => x.Id == UserId)?.Login ?? string.Empty, + ProductId = ProductId, + ProductName = ProductId.HasValue ? context.Products.FirstOrDefault(x => x.Id == ProductId)?.ProductName ?? string.Empty : null, + DateCreate = DateCreate, + Status = Status, + Count = Count, + Sum = Sum + }; + } + } } diff --git a/DiningRoom/DiningRoomView/FormCreateOrder.cs b/DiningRoom/DiningRoomView/FormCreateOrder.cs index 7295771..fef04ff 100644 --- a/DiningRoom/DiningRoomView/FormCreateOrder.cs +++ b/DiningRoom/DiningRoomView/FormCreateOrder.cs @@ -22,6 +22,7 @@ namespace DiningRoomView private readonly ILogger _logger; private readonly IProductLogic _logicP; private readonly IOrderLogic _logicO; + public int Id { get ; set ; } public int UserId { get; set; } public FormCreateOrder(ILogger logger, IProductLogic logicP, IOrderLogic logicO) @@ -36,7 +37,7 @@ namespace DiningRoomView { _logger.LogInformation("Загрузка изделий для заказа"); // прописать логику - List list = _logicP.ReadList(new ProductSearchModel { UserId = UserId }); + List list = _logicP.ReadList(null); if (list != null) { comboBoxProduct.DisplayMember = "ProductName"; @@ -74,36 +75,42 @@ namespace DiningRoomView } private void ButtonSave_Click(object sender, EventArgs e) { - if (UserId == 0) + if (string.IsNullOrEmpty(textBoxCount.Text)) { - MessageBox.Show("Ошибка авторизации", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxProduct.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - _logger.LogInformation("Создание заказа"); try { - var operationResult = _logicO.Create(new OrderBindingModel + var model = new OrderBindingModel { - ProductId = Convert.ToInt32(comboBoxProduct.SelectedValue), - ProductName = comboBoxProduct.Text, - Count = Convert.ToInt32(textBoxCount.Text), - Sum = Convert.ToDouble(textBoxSum.Text), + Id = Id, Status = OrderStatus.Принят, - UserId = UserId - }); + ProductId = comboBoxProduct.SelectedValue as int?, + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + + }; + var operationResult = _logicO.Update(model); if (!operationResult) { - throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); } MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); - DialogResult = DialogResult.OK; - Close(); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка создания заказа"); + _logger.LogError(ex, "Ошибка сохранения карты"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } + + DialogResult = DialogResult.OK; + Close(); } private void ButtonCancel_Click(object sender, EventArgs e) { diff --git a/DiningRoom/DiningRoomView/FormOrders.Designer.cs b/DiningRoom/DiningRoomView/FormOrders.Designer.cs index 3c8d8f2..6e4a946 100644 --- a/DiningRoom/DiningRoomView/FormOrders.Designer.cs +++ b/DiningRoom/DiningRoomView/FormOrders.Designer.cs @@ -29,11 +29,11 @@ private void InitializeComponent() { dataGridView = new DataGridView(); - ButtonCreateOrder = new Button(); + ButtonAdd = new Button(); + ButtonUpd = new Button(); + ButtonDel = new Button(); ButtonRef = new Button(); - ButtonIssuedOrder = new Button(); - ButtonOrderReady = new Button(); - ButtonTakeOrderInWork = new Button(); + textBoxName = new TextBox(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // @@ -41,87 +41,85 @@ // dataGridView.BackgroundColor = SystemColors.ButtonHighlight; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.EnableHeadersVisualStyles = false; - dataGridView.Location = new Point(12, 12); - dataGridView.MultiSelect = false; + dataGridView.Location = new Point(0, 0); dataGridView.Name = "dataGridView"; - dataGridView.Size = new Size(600, 371); - dataGridView.TabIndex = 1; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(433, 448); + dataGridView.TabIndex = 0; // - // ButtonCreateOrder + // ButtonAdd // - ButtonCreateOrder.Location = new Point(618, 12); - ButtonCreateOrder.Name = "ButtonCreateOrder"; - ButtonCreateOrder.Size = new Size(122, 23); - ButtonCreateOrder.TabIndex = 2; - ButtonCreateOrder.Text = "Создать заказ"; - ButtonCreateOrder.UseVisualStyleBackColor = true; - ButtonCreateOrder.Click += ButtonCreateOrder_Click; + ButtonAdd.Location = new Point(439, 116); + ButtonAdd.Name = "ButtonAdd"; + ButtonAdd.Size = new Size(225, 23); + ButtonAdd.TabIndex = 1; + ButtonAdd.Text = "Добавить"; + ButtonAdd.UseVisualStyleBackColor = true; + ButtonAdd.Click += ButtonAdd_Click; + // + // ButtonUpd + // + ButtonUpd.Location = new Point(439, 145); + ButtonUpd.Name = "ButtonUpd"; + ButtonUpd.Size = new Size(225, 23); + ButtonUpd.TabIndex = 2; + ButtonUpd.Text = "Изменить"; + ButtonUpd.UseVisualStyleBackColor = true; + ButtonUpd.Click += ButtonCreateOrder_Click; + // + // ButtonDel + // + ButtonDel.Location = new Point(439, 174); + ButtonDel.Name = "ButtonDel"; + ButtonDel.Size = new Size(225, 23); + ButtonDel.TabIndex = 3; + ButtonDel.Text = "Удалить"; + ButtonDel.UseVisualStyleBackColor = true; + ButtonDel.Click += ButtonDel_Click; // // ButtonRef // - ButtonRef.Location = new Point(618, 147); + ButtonRef.Location = new Point(439, 203); ButtonRef.Name = "ButtonRef"; - ButtonRef.Size = new Size(122, 23); - ButtonRef.TabIndex = 6; - ButtonRef.Text = "Обновить список"; + ButtonRef.Size = new Size(225, 23); + ButtonRef.TabIndex = 4; + ButtonRef.Text = "Обновить"; ButtonRef.UseVisualStyleBackColor = true; ButtonRef.Click += ButtonRef_Click; // - // ButtonIssuedOrder + // textBoxName // - ButtonIssuedOrder.Location = new Point(618, 118); - ButtonIssuedOrder.Name = "ButtonIssuedOrder"; - ButtonIssuedOrder.Size = new Size(122, 23); - ButtonIssuedOrder.TabIndex = 5; - ButtonIssuedOrder.Text = "Заказ выдан"; - ButtonIssuedOrder.UseVisualStyleBackColor = true; - ButtonIssuedOrder.Click += ButtonIssuedOrder_Click; + textBoxName.Location = new Point(439, 30); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(225, 23); + textBoxName.TabIndex = 5; // - // ButtonOrderReady - // - ButtonOrderReady.Location = new Point(618, 89); - ButtonOrderReady.Name = "ButtonOrderReady"; - ButtonOrderReady.Size = new Size(122, 23); - ButtonOrderReady.TabIndex = 4; - ButtonOrderReady.Text = "Заказ готов"; - ButtonOrderReady.UseVisualStyleBackColor = true; - ButtonOrderReady.Click += ButtonOrderReady_Click; - // - // ButtonTakeOrderInWork - // - ButtonTakeOrderInWork.Location = new Point(618, 41); - ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; - ButtonTakeOrderInWork.Size = new Size(122, 42); - ButtonTakeOrderInWork.TabIndex = 3; - ButtonTakeOrderInWork.Text = "Отдать на выполнение"; - ButtonTakeOrderInWork.UseVisualStyleBackColor = true; - ButtonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; - // - // FormOrders + // FormCards // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(752, 391); + ClientSize = new Size(668, 450); + Controls.Add(textBoxName); Controls.Add(ButtonRef); - Controls.Add(ButtonIssuedOrder); - Controls.Add(ButtonOrderReady); - Controls.Add(ButtonTakeOrderInWork); - Controls.Add(ButtonCreateOrder); + Controls.Add(ButtonDel); + Controls.Add(ButtonUpd); + Controls.Add(ButtonAdd); Controls.Add(dataGridView); - Name = "FormOrders"; - Text = "Заказы"; - Load += FormMain_Load; + Name = "FormCards"; + Text = "Изделия"; + Load += FormProducts_Load; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); + PerformLayout(); } #endregion + private System.Windows.Forms.DataGridView dataGridView; - private System.Windows.Forms.Button ButtonCreateOrder; + private System.Windows.Forms.Button ButtonAdd; + private System.Windows.Forms.Button ButtonUpd; + private System.Windows.Forms.Button ButtonDel; private System.Windows.Forms.Button ButtonRef; - private Button ButtonIssuedOrder; - private Button ButtonOrderReady; - private Button ButtonTakeOrderInWork; + private TextBox textBoxName; } } \ No newline at end of file diff --git a/DiningRoom/DiningRoomView/FormOrders.cs b/DiningRoom/DiningRoomView/FormOrders.cs index 9eb476c..c8b2ac4 100644 --- a/DiningRoom/DiningRoomView/FormOrders.cs +++ b/DiningRoom/DiningRoomView/FormOrders.cs @@ -1,8 +1,8 @@ -using DiningRoomBusinessLogic.BusinessLogic; -using DiningRoomContracts.BindingModels; +using DiningRoomContracts.BindingModels; using DiningRoomContracts.BusinessLogicContracts; using DiningRoomContracts.SearchModels; using DiningRoomContracts.ViewModels; +using DiningRoomDataModels.Models; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -13,21 +13,22 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using static System.Windows.Forms.DataFormats; namespace DiningRoomView { public partial class FormOrders : Form { private readonly ILogger _logger; - private readonly IOrderLogic _orderLogic; + private readonly IOrderLogic _logic; public UserViewModel? _currentUser { get; set; } - public FormOrders(ILogger logger, IOrderLogic orderLogic) + public FormOrders(ILogger logger, IOrderLogic logic) { InitializeComponent(); _logger = logger; - _orderLogic = orderLogic; + _logic = logic; } - private void FormMain_Load(object sender, EventArgs e) + private void FormProducts_Load(object sender, EventArgs e) { LoadData(); } @@ -36,104 +37,101 @@ namespace DiningRoomView if (_currentUser == null) { MessageBox.Show("Ошибка авторизации", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + Close(); return; } - _logger.LogInformation("Загрузка заказов"); - // прописать логику try { - var list = _orderLogic.ReadList(new OrderSearchModel { UserId = _currentUser.Id }); + var list = _logic.ReadList(new OrderSearchModel { UserId = _currentUser.Id }); if (list != null) { dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["UserId"].Visible = false; dataGridView.Columns["ProductId"].Visible = false; + dataGridView.Columns["Login"].Visible = false; + } - _logger.LogInformation("Загрузка продуктов"); + _logger.LogInformation("Загрузка карт"); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки продуктов"); + _logger.LogError(ex, "Ошибка загрузки карт"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void ButtonCreateOrder_Click(object sender, EventArgs e) + private void ButtonAdd_Click(object sender, EventArgs e) { if (_currentUser == null) { MessageBox.Show("Ошибка авторизации", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) + if (string.IsNullOrEmpty(textBoxName.Text)) { - form.UserId = _currentUser.Id; - form.ShowDialog(); + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение карты"); + try + { + var model = new OrderBindingModel + { + Id = 0, + Name = textBoxName.Text, + UserId = _currentUser.Id, + }; + var operationResult =_logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadData(); } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения карты"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } - private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + private void ButtonCreateOrder_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); - try + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); - if (!operationResult) + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + if (form.ShowDialog() == DialogResult.OK) { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + LoadData(); } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } - private void ButtonOrderReady_Click(object sender, EventArgs e) + private void ButtonDel_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); - try + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); - if (!operationResult) + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление карты"); + try { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + if (!_logic.Delete(new OrderBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonIssuedOrder_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); - try - { - var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); - if (!operationResult) + catch (Exception ex) { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + _logger.LogError(ex, "Ошибка удаления продукта"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } - _logger.LogInformation("Заказ №{id} выдан", id); - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } diff --git a/DiningRoom/DiningRoomView/FormOrdersOld.Designer.cs b/DiningRoom/DiningRoomView/FormOrdersOld.Designer.cs new file mode 100644 index 0000000..5f129e2 --- /dev/null +++ b/DiningRoom/DiningRoomView/FormOrdersOld.Designer.cs @@ -0,0 +1,127 @@ +namespace DiningRoomView +{ + partial class FormOrdersOld + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + ButtonCreateOrder = new Button(); + ButtonRef = new Button(); + ButtonIssuedOrder = new Button(); + ButtonOrderReady = new Button(); + ButtonTakeOrderInWork = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.BackgroundColor = SystemColors.ButtonHighlight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.EnableHeadersVisualStyles = false; + dataGridView.Location = new Point(12, 12); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.Size = new Size(600, 371); + dataGridView.TabIndex = 1; + // + // ButtonCreateOrder + // + ButtonCreateOrder.Location = new Point(618, 12); + ButtonCreateOrder.Name = "ButtonCreateOrder"; + ButtonCreateOrder.Size = new Size(122, 23); + ButtonCreateOrder.TabIndex = 2; + ButtonCreateOrder.Text = "Создать заказ"; + ButtonCreateOrder.UseVisualStyleBackColor = true; + ButtonCreateOrder.Click += ButtonCreateOrder_Click; + // + // ButtonRef + // + ButtonRef.Location = new Point(618, 147); + ButtonRef.Name = "ButtonRef"; + ButtonRef.Size = new Size(122, 23); + ButtonRef.TabIndex = 6; + ButtonRef.Text = "Обновить список"; + ButtonRef.UseVisualStyleBackColor = true; + ButtonRef.Click += ButtonRef_Click; + // + // ButtonIssuedOrder + // + ButtonIssuedOrder.Location = new Point(618, 118); + ButtonIssuedOrder.Name = "ButtonIssuedOrder"; + ButtonIssuedOrder.Size = new Size(122, 23); + ButtonIssuedOrder.TabIndex = 5; + ButtonIssuedOrder.Text = "Заказ выдан"; + ButtonIssuedOrder.UseVisualStyleBackColor = true; + ButtonIssuedOrder.Click += ButtonIssuedOrder_Click; + // + // ButtonOrderReady + // + ButtonOrderReady.Location = new Point(618, 89); + ButtonOrderReady.Name = "ButtonOrderReady"; + ButtonOrderReady.Size = new Size(122, 23); + ButtonOrderReady.TabIndex = 4; + ButtonOrderReady.Text = "Заказ готов"; + ButtonOrderReady.UseVisualStyleBackColor = true; + ButtonOrderReady.Click += ButtonOrderReady_Click; + // + // ButtonTakeOrderInWork + // + ButtonTakeOrderInWork.Location = new Point(618, 41); + ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; + ButtonTakeOrderInWork.Size = new Size(122, 42); + ButtonTakeOrderInWork.TabIndex = 3; + ButtonTakeOrderInWork.Text = "Отдать на выполнение"; + ButtonTakeOrderInWork.UseVisualStyleBackColor = true; + ButtonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; + // + // FormOrders + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(752, 391); + Controls.Add(ButtonRef); + Controls.Add(ButtonIssuedOrder); + Controls.Add(ButtonOrderReady); + Controls.Add(ButtonTakeOrderInWork); + Controls.Add(ButtonCreateOrder); + Controls.Add(dataGridView); + Name = "FormOrders"; + Text = "Заказы"; + Load += FormMain_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + private System.Windows.Forms.DataGridView dataGridView; + private System.Windows.Forms.Button ButtonCreateOrder; + private System.Windows.Forms.Button ButtonRef; + private Button ButtonIssuedOrder; + private Button ButtonOrderReady; + private Button ButtonTakeOrderInWork; + } +} \ No newline at end of file diff --git a/DiningRoom/DiningRoomView/FormOrdersOld.cs b/DiningRoom/DiningRoomView/FormOrdersOld.cs new file mode 100644 index 0000000..8202f68 --- /dev/null +++ b/DiningRoom/DiningRoomView/FormOrdersOld.cs @@ -0,0 +1,145 @@ +using DiningRoomBusinessLogic.BusinessLogic; +using DiningRoomContracts.BindingModels; +using DiningRoomContracts.BusinessLogicContracts; +using DiningRoomContracts.SearchModels; +using DiningRoomContracts.ViewModels; +using Microsoft.Extensions.Logging; +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 DiningRoomView +{ + public partial class FormOrdersOld : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public UserViewModel? _currentUser { get; set; } + public FormOrdersOld(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + if (_currentUser == null) + { + MessageBox.Show("Ошибка авторизации", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Загрузка заказов"); + // прописать логику + try + { + var list = _orderLogic.ReadList(new OrderSearchModel { UserId = _currentUser.Id }); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["ProductId"].Visible = false; + } + _logger.LogInformation("Загрузка продуктов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки продуктов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + if (_currentUser == null) + { + MessageBox.Show("Ошибка авторизации", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.UserId = _currentUser.Id; + form.ShowDialog(); + LoadData(); + } + } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/DiningRoom/DiningRoomView/FormOrdersOld.resx b/DiningRoom/DiningRoomView/FormOrdersOld.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/DiningRoom/DiningRoomView/FormOrdersOld.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/DiningRoom/DiningRoomView/FormReportOrders.Designer.cs b/DiningRoom/DiningRoomView/FormReportOrders.Designer.cs new file mode 100644 index 0000000..8a4481e --- /dev/null +++ b/DiningRoom/DiningRoomView/FormReportOrders.Designer.cs @@ -0,0 +1,141 @@ +namespace CarpentryWorkshopView +{ + partial class FormReportOrders + { + /// + /// 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.panel = new System.Windows.Forms.Panel(); + this.buttonToPdf = new System.Windows.Forms.Button(); + this.buttonMake = new System.Windows.Forms.Button(); + this.dateTimePickerTo = new System.Windows.Forms.DateTimePicker(); + this.labelTo = new System.Windows.Forms.Label(); + this.dateTimePickerFrom = new System.Windows.Forms.DateTimePicker(); + this.labelFrom = new System.Windows.Forms.Label(); + this.panel.SuspendLayout(); + this.SuspendLayout(); + // + // panel + // + this.panel.Controls.Add(this.buttonToPdf); + this.panel.Controls.Add(this.buttonMake); + this.panel.Controls.Add(this.dateTimePickerTo); + this.panel.Controls.Add(this.labelTo); + this.panel.Controls.Add(this.dateTimePickerFrom); + this.panel.Controls.Add(this.labelFrom); + this.panel.Dock = System.Windows.Forms.DockStyle.Top; + this.panel.Location = new System.Drawing.Point(0, 0); + this.panel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.panel.Name = "panel"; + this.panel.Size = new System.Drawing.Size(1031, 40); + this.panel.TabIndex = 0; + // + // buttonToPdf + // + this.buttonToPdf.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonToPdf.Location = new System.Drawing.Point(878, 8); + this.buttonToPdf.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.buttonToPdf.Name = "buttonToPdf"; + this.buttonToPdf.Size = new System.Drawing.Size(139, 27); + this.buttonToPdf.TabIndex = 5; + this.buttonToPdf.Text = "В Pdf"; + this.buttonToPdf.UseVisualStyleBackColor = true; + this.buttonToPdf.Click += new System.EventHandler(this.ButtonToPdf_Click); + // + // buttonMake + // + this.buttonMake.Location = new System.Drawing.Point(476, 8); + this.buttonMake.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.buttonMake.Name = "buttonMake"; + this.buttonMake.Size = new System.Drawing.Size(139, 27); + this.buttonMake.TabIndex = 4; + this.buttonMake.Text = "Сформировать"; + this.buttonMake.UseVisualStyleBackColor = true; + this.buttonMake.Click += new System.EventHandler(this.ButtonMake_Click); + // + // dateTimePickerTo + // + this.dateTimePickerTo.Location = new System.Drawing.Point(237, 7); + this.dateTimePickerTo.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.dateTimePickerTo.Name = "dateTimePickerTo"; + this.dateTimePickerTo.Size = new System.Drawing.Size(163, 23); + this.dateTimePickerTo.TabIndex = 3; + // + // labelTo + // + this.labelTo.AutoSize = true; + this.labelTo.Location = new System.Drawing.Point(208, 10); + this.labelTo.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelTo.Name = "labelTo"; + this.labelTo.Size = new System.Drawing.Size(21, 15); + this.labelTo.TabIndex = 2; + this.labelTo.Text = "по"; + // + // dateTimePickerFrom + // + this.dateTimePickerFrom.Location = new System.Drawing.Point(37, 7); + this.dateTimePickerFrom.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.dateTimePickerFrom.Name = "dateTimePickerFrom"; + this.dateTimePickerFrom.Size = new System.Drawing.Size(163, 23); + this.dateTimePickerFrom.TabIndex = 1; + // + // labelFrom + // + this.labelFrom.AutoSize = true; + this.labelFrom.Location = new System.Drawing.Point(14, 10); + this.labelFrom.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelFrom.Name = "labelFrom"; + this.labelFrom.Size = new System.Drawing.Size(15, 15); + this.labelFrom.TabIndex = 0; + this.labelFrom.Text = "С"; + // + // FormReportOrders + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1031, 647); + this.Controls.Add(this.panel); + this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.Name = "FormReportOrders"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Заказы"; + this.panel.ResumeLayout(false); + this.panel.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel panel; + private System.Windows.Forms.Button buttonToPdf; + private System.Windows.Forms.Button buttonMake; + private System.Windows.Forms.DateTimePicker dateTimePickerTo; + private System.Windows.Forms.Label labelTo; + private System.Windows.Forms.DateTimePicker dateTimePickerFrom; + private System.Windows.Forms.Label labelFrom; + } +} \ No newline at end of file diff --git a/DiningRoom/DiningRoomView/FormReportOrders.cs b/DiningRoom/DiningRoomView/FormReportOrders.cs new file mode 100644 index 0000000..631e269 --- /dev/null +++ b/DiningRoom/DiningRoomView/FormReportOrders.cs @@ -0,0 +1,101 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using Microsoft.Reporting.WinForms; +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 CarpentryWorkshopView +{ + public partial class FormReportOrders : Form + { + private readonly ReportViewer reportViewer; + + private readonly ILogger _logger; + + private readonly IReportLogic _logic; + + public FormReportOrders(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + reportViewer = new ReportViewer + { + Dock = DockStyle.Fill + }; + reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportOrders.rdlc", FileMode.Open)); + Controls.Clear(); + Controls.Add(reportViewer); + Controls.Add(panel); + } + + private void ButtonMake_Click(object sender, EventArgs e) + { + if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date) + { + MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + var dataSource = _logic.GetOrders(new ReportBindingModel + { + DateFrom = DateTime.SpecifyKind(dateTimePickerFrom.Value, DateTimeKind.Utc), + DateTo = DateTime.SpecifyKind(dateTimePickerTo.Value, DateTimeKind.Utc) + }); + var source = new ReportDataSource("DataSetOrders", dataSource); + reportViewer.LocalReport.DataSources.Clear(); + reportViewer.LocalReport.DataSources.Add(source); + var parameters = new[] { new ReportParameter("ReportParameterPeriod", + $"c {dateTimePickerFrom.Value.ToShortDateString()} по {dateTimePickerTo.Value.ToShortDateString()}") }; + reportViewer.LocalReport.SetParameters(parameters); + + reportViewer.RefreshReport(); + _logger.LogInformation("Загрузка списка заказов на период {From}-{To}", dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString()); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonToPdf_Click(object sender, EventArgs e) + { + System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); + if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date) + { + MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveOrdersToPdfFile(new ReportBindingModel + { + FileName = dialog.FileName, + DateFrom = DateTime.SpecifyKind(dateTimePickerFrom.Value, DateTimeKind.Utc), + DateTo = DateTime.SpecifyKind(dateTimePickerTo.Value, DateTimeKind.Utc) + }); + _logger.LogInformation("Сохранение списка заказов на период {From}-{To}", dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString()); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/DiningRoom/DiningRoomView/FormReportOrders.resx b/DiningRoom/DiningRoomView/FormReportOrders.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/DiningRoom/DiningRoomView/FormReportOrders.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/DiningRoom/DiningRoomView/FormReportWoodComponents.Designer.cs b/DiningRoom/DiningRoomView/FormReportWoodComponents.Designer.cs new file mode 100644 index 0000000..9035a72 --- /dev/null +++ b/DiningRoom/DiningRoomView/FormReportWoodComponents.Designer.cs @@ -0,0 +1,114 @@ +namespace CarpentryWorkshopView +{ + partial class FormReportWoodComponents + { + /// + /// 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.buttonSaveToExcel = new System.Windows.Forms.Button(); + this.ColumnComponent = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnWood = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.AllowUserToOrderColumns = true; + this.dataGridView.AllowUserToResizeColumns = false; + this.dataGridView.AllowUserToResizeRows = false; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ColumnComponent, + this.ColumnWood, + this.ColumnCount}); + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Bottom; + this.dataGridView.Location = new System.Drawing.Point(0, 41); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.Size = new System.Drawing.Size(528, 442); + this.dataGridView.TabIndex = 0; + // + // buttonSaveToExcel + // + this.buttonSaveToExcel.Location = new System.Drawing.Point(12, 12); + this.buttonSaveToExcel.Name = "buttonSaveToExcel"; + this.buttonSaveToExcel.Size = new System.Drawing.Size(159, 23); + this.buttonSaveToExcel.TabIndex = 1; + this.buttonSaveToExcel.Text = "Сохранить в Excel"; + this.buttonSaveToExcel.UseVisualStyleBackColor = true; + this.buttonSaveToExcel.Click += new System.EventHandler(this.ButtonSaveToExcel_Click); + // + // ColumnComponent + // + this.ColumnComponent.HeaderText = "Изделие"; + this.ColumnComponent.Name = "ColumnWood"; + this.ColumnComponent.ReadOnly = true; + this.ColumnComponent.Width = 200; + // + // ColumnWood + // + this.ColumnWood.HeaderText = "Компонент"; + this.ColumnWood.Name = "ColumnComponent"; + this.ColumnWood.ReadOnly = true; + this.ColumnWood.Width = 200; + // + // ColumnCount + // + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.Name = "ColumnCount"; + this.ColumnCount.ReadOnly = true; + // + // FormReportWoodComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(528, 483); + this.Controls.Add(this.buttonSaveToExcel); + this.Controls.Add(this.dataGridView); + this.Name = "FormReportWoodComponents"; + this.Text = "Компоненты по изделиям"; + this.Load += new System.EventHandler(this.FormReportWoodComponents_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.DataGridView dataGridView; + private System.Windows.Forms.Button buttonSaveToExcel; + private System.Windows.Forms.DataGridViewTextBoxColumn ColumnComponent; + private System.Windows.Forms.DataGridViewTextBoxColumn ColumnWood; + private System.Windows.Forms.DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/DiningRoom/DiningRoomView/FormReportWoodComponents.cs b/DiningRoom/DiningRoomView/FormReportWoodComponents.cs new file mode 100644 index 0000000..d401b62 --- /dev/null +++ b/DiningRoom/DiningRoomView/FormReportWoodComponents.cs @@ -0,0 +1,79 @@ +using CarpentryWorkshopContracts.BindingModels; +using CarpentryWorkshopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +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 CarpentryWorkshopView +{ + public partial class FormReportWoodComponents : Form + { + private readonly ILogger _logger; + + private readonly IReportLogic _logic; + + public FormReportWoodComponents(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormReportWoodComponents_Load(object sender, EventArgs e) + { + try + { + var dict = _logic.GetWoodComponent(); + if (dict != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in dict) + { + dataGridView.Rows.Add(new object[] { elem.WoodName, "", "" }); + foreach (var listElem in elem.Components) + { + dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 }); + } + dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount }); + dataGridView.Rows.Add(Array.Empty()); + } + } + _logger.LogInformation("Загрузка списка изделий по компонентам"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка изделий по компонентам"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSaveToExcel_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveWoodComponentToExcelFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + _logger.LogInformation("Сохранение списка изделий по компонентам"); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка изделий по компонентам"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/DiningRoom/DiningRoomView/FormReportWoodComponents.resx b/DiningRoom/DiningRoomView/FormReportWoodComponents.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/DiningRoom/DiningRoomView/FormReportWoodComponents.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file