From e4b8afb8da32743babdcb7e840eabcb0b0c5e90f Mon Sep 17 00:00:00 2001 From: ValAnn Date: Mon, 8 Apr 2024 13:43:32 +0400 Subject: [PATCH] =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=87=D0=B5=D0=B5=20?= =?UTF-8?q?=D0=B4=D0=B5=D1=81=D0=BA=D1=82=D0=BE=D0=BF=D0=BD=D0=BE=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5,?= =?UTF-8?q?=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D0=B0=20=D0=B2=D0=B5?= =?UTF-8?q?=D0=B7=D0=B4=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BindingModels/OrderBindingModel.cs | 1 + .../SearchModels/OrderSearchModel.cs | 1 + .../ViewModels/OrderViewModel.cs | 6 +- .../SushiBarDataModels/Models/IOrderModel.cs | 1 + .../Implements/ClientStorage.cs | 86 ++++++ .../Implements/OrderStorage.cs | 6 +- ... 20240408093304_InitialCreate.Designer.cs} | 45 +++- ...ate.cs => 20240408093304_InitialCreate.cs} | 30 +++ .../SushiBarDatabaseModelSnapshot.cs | 43 +++ .../Models/Client.cs | 2 +- .../SushiBarDatabaseImplement/Models/Order.cs | 5 + .../SushiBarDatatbase.cs | 1 + .../DataFileSingleton.cs | 7 +- .../Implements/OrderStorage.cs | 34 ++- .../SushiBarFileImplement/Models/Order.cs | 5 + .../DataListSingleton.cs | 2 + .../Implements/OrderStorage.cs | 53 +++- .../SushiBarListImplement_/Models/Client.cs | 2 +- .../SushiBarListImplement_/Models/Order.cs | 3 + SushiBar/SushiBarView/FormClients.Designer.cs | 95 +++++++ SushiBar/SushiBarView/FormClients.cs | 86 ++++++ SushiBar/SushiBarView/FormClients.resx | 120 +++++++++ .../SushiBarView/FormCreateOrder.Designer.cs | 170 ++++++------ SushiBar/SushiBarView/FormCreateOrder.cs | 37 ++- SushiBar/SushiBarView/FormCreateOrder.resx | 62 ++++- SushiBar/SushiBarView/FormMain.Designer.cs | 246 +++++++++--------- SushiBar/SushiBarView/FormMain.cs | 17 +- SushiBar/SushiBarView/FormMain.resx | 62 ++++- SushiBar/SushiBarView/Program.cs | 9 + 29 files changed, 1011 insertions(+), 226 deletions(-) create mode 100644 SushiBar/SushiBarDatabaseImplement/Implements/ClientStorage.cs rename SushiBar/SushiBarDatabaseImplement/Migrations/{20240313082356_InitialCreate.Designer.cs => 20240408093304_InitialCreate.Designer.cs} (78%) rename SushiBar/SushiBarDatabaseImplement/Migrations/{20240313082356_InitialCreate.cs => 20240408093304_InitialCreate.cs} (79%) create mode 100644 SushiBar/SushiBarView/FormClients.Designer.cs create mode 100644 SushiBar/SushiBarView/FormClients.cs create mode 100644 SushiBar/SushiBarView/FormClients.resx diff --git a/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs index ee30e84..8f01d4c 100644 --- a/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs +++ b/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs @@ -12,6 +12,7 @@ namespace SushiBarContracts.BindingModels { public int Id { get; set; } public int SushiId { get; set; } + public int ClientId { get; set; } public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs index e019893..1e7a05c 100644 --- a/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs +++ b/SushiBar/SushiBarContracts/SearchModels/OrderSearchModel.cs @@ -9,6 +9,7 @@ namespace SushiBarContracts.SearchModels public class OrderSearchModel { public int? Id { get; set; } + public int? ClientId { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } } diff --git a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs index 36203b3..7727b6d 100644 --- a/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs +++ b/SushiBar/SushiBarContracts/ViewModels/OrderViewModel.cs @@ -15,7 +15,11 @@ namespace SushiBarContracts.ViewModels public int Id { get; set; } public int SushiId { get; set; } - + public int ClientId { get; set; } + + [DisplayName("ФИО клиента")] + public string ClientFIO { get; set; } = string.Empty; + [DisplayName("Изделие")] public string SushiName { get; set; } = string.Empty; diff --git a/SushiBar/SushiBarDataModels/Models/IOrderModel.cs b/SushiBar/SushiBarDataModels/Models/IOrderModel.cs index 02ca513..9e5315d 100644 --- a/SushiBar/SushiBarDataModels/Models/IOrderModel.cs +++ b/SushiBar/SushiBarDataModels/Models/IOrderModel.cs @@ -10,6 +10,7 @@ namespace SushiBarDataModels.Models public interface IOrderModel : IId { int SushiId { get; } + int ClientId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/SushiBar/SushiBarDatabaseImplement/Implements/ClientStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/ClientStorage.cs new file mode 100644 index 0000000..d4b89ea --- /dev/null +++ b/SushiBar/SushiBarDatabaseImplement/Implements/ClientStorage.cs @@ -0,0 +1,86 @@ +using SushiBar.BindingModels; +using SushiBar.SearchModels; +using SushiBar.StoragesContracts; +using SushiBar.ViewModels; +using SushiBarDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarDatabaseImplement.Implements +{ + public class ClientStorage : IClientStorage + { + public List GetFullList() + { + using var context = new SushiBarDatabase(); + return context.Clients.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(ClientSearchModel model) + { + if (string.IsNullOrEmpty(model.ClientFIO)) + { + return new(); + } + using var context = new SushiBarDatabase(); + return context.Clients.Where(x => x.ClientFIO.Contains(model.ClientFIO)).Select(x => x.GetViewModel).ToList(); + } + + public ClientViewModel? GetElement(ClientSearchModel model) + { + if (string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue) + { + return null; + } + using var context = new SushiBarDatabase(); + return context.Clients.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email && !string.IsNullOrEmpty(model.Password) && x.Password == model.Password) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public ClientViewModel? Insert(ClientBindingModel model) + { + var newComponent = Client.Create(model); + if (newComponent == null) + { + return null; + } + using var context = new SushiBarDatabase(); + context.Clients.Add(newComponent); + context.SaveChanges(); + return newComponent.GetViewModel; + } + + public ClientViewModel? Update(ClientBindingModel model) + { + using var context = new SushiBarDatabase(); + var component = context.Clients.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + context.SaveChanges(); + return component.GetViewModel; + } + + public ClientViewModel? Delete(ClientBindingModel model) + { + using var context = new SushiBarDatabase(); + var element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Clients.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } + + } + diff --git a/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs index 562ed67..1295e61 100644 --- a/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs @@ -17,7 +17,7 @@ namespace SushiBarDatabaseImplement.Implements public List GetFullList() { using var context = new SushiBarDatabase(); - return context.Orders.Include(x => x.Sushi).Select(x => x.GetViewModel).ToList(); + return context.Orders.Include(x => x.Sushi).Include(x => x.Client).Select(x => x.GetViewModel).ToList(); } public List GetFilteredList(OrderSearchModel model) @@ -31,6 +31,10 @@ namespace SushiBarDatabaseImplement.Implements { return context.Orders.Include(x => x.Sushi).Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList(); } + if (model.ClientId.HasValue) + { + return context.Orders.Include(x => x.Sushi).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList(); + } return context.Orders.Include(x => x.Sushi).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); } diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/20240313082356_InitialCreate.Designer.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/20240408093304_InitialCreate.Designer.cs similarity index 78% rename from SushiBar/SushiBarDatabaseImplement/Migrations/20240313082356_InitialCreate.Designer.cs rename to SushiBar/SushiBarDatabaseImplement/Migrations/20240408093304_InitialCreate.Designer.cs index 7809e8c..c7524ac 100644 --- a/SushiBar/SushiBarDatabaseImplement/Migrations/20240313082356_InitialCreate.Designer.cs +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/20240408093304_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using SushiBarDatabaseImplement; namespace SushiBarDatabaseImplement.Migrations { [DbContext(typeof(SushiBarDatabase))] - [Migration("20240313082356_InitialCreate")] + [Migration("20240408093304_InitialCreate")] partial class InitialCreate { /// @@ -25,6 +25,31 @@ namespace SushiBarDatabaseImplement.Migrations SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Component", b => { b.Property("Id") @@ -53,6 +78,9 @@ namespace SushiBarDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("ClientId") + .HasColumnType("int"); + b.Property("Count") .HasColumnType("int"); @@ -73,6 +101,8 @@ namespace SushiBarDatabaseImplement.Migrations b.HasKey("Id"); + b.HasIndex("ClientId"); + b.HasIndex("SushiId"); b.ToTable("Orders"); @@ -126,12 +156,20 @@ namespace SushiBarDatabaseImplement.Migrations modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b => { + b.HasOne("SushiBarDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi") .WithMany("Orders") .HasForeignKey("SushiId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.Navigation("Client"); + b.Navigation("Sushi"); }); @@ -154,6 +192,11 @@ namespace SushiBarDatabaseImplement.Migrations b.Navigation("Sushi"); }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Component", b => { b.Navigation("SushiComponents"); diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/20240313082356_InitialCreate.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/20240408093304_InitialCreate.cs similarity index 79% rename from SushiBar/SushiBarDatabaseImplement/Migrations/20240313082356_InitialCreate.cs rename to SushiBar/SushiBarDatabaseImplement/Migrations/20240408093304_InitialCreate.cs index 4367175..43ae97b 100644 --- a/SushiBar/SushiBarDatabaseImplement/Migrations/20240313082356_InitialCreate.cs +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/20240408093304_InitialCreate.cs @@ -11,6 +11,21 @@ namespace SushiBarDatabaseImplement.Migrations /// protected override void Up(MigrationBuilder migrationBuilder) { + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClientFIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Clients", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Components", columns: table => new @@ -45,6 +60,7 @@ namespace SushiBarDatabaseImplement.Migrations { Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), + ClientId = table.Column(type: "int", nullable: false), SushiId = table.Column(type: "int", nullable: false), Count = table.Column(type: "int", nullable: false), Sum = table.Column(type: "float", nullable: false), @@ -55,6 +71,12 @@ namespace SushiBarDatabaseImplement.Migrations constraints: table => { table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Orders_Sushis_SushiId", column: x => x.SushiId, @@ -90,6 +112,11 @@ namespace SushiBarDatabaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateIndex( + name: "IX_Orders_ClientId", + table: "Orders", + column: "ClientId"); + migrationBuilder.CreateIndex( name: "IX_Orders_SushiId", table: "Orders", @@ -115,6 +142,9 @@ namespace SushiBarDatabaseImplement.Migrations migrationBuilder.DropTable( name: "SushiComponents"); + migrationBuilder.DropTable( + name: "Clients"); + migrationBuilder.DropTable( name: "Components"); diff --git a/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs b/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs index 43e1c41..43bf610 100644 --- a/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs +++ b/SushiBar/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs @@ -22,6 +22,31 @@ namespace SushiBarDatabaseImplement.Migrations SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Component", b => { b.Property("Id") @@ -50,6 +75,9 @@ namespace SushiBarDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("ClientId") + .HasColumnType("int"); + b.Property("Count") .HasColumnType("int"); @@ -70,6 +98,8 @@ namespace SushiBarDatabaseImplement.Migrations b.HasKey("Id"); + b.HasIndex("ClientId"); + b.HasIndex("SushiId"); b.ToTable("Orders"); @@ -123,12 +153,20 @@ namespace SushiBarDatabaseImplement.Migrations modelBuilder.Entity("SushiBarDatabaseImplement.Models.Order", b => { + b.HasOne("SushiBarDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + b.HasOne("SushiBarDatabaseImplement.Models.Sushi", "Sushi") .WithMany("Orders") .HasForeignKey("SushiId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.Navigation("Client"); + b.Navigation("Sushi"); }); @@ -151,6 +189,11 @@ namespace SushiBarDatabaseImplement.Migrations b.Navigation("Sushi"); }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("SushiBarDatabaseImplement.Models.Component", b => { b.Navigation("SushiComponents"); diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Client.cs b/SushiBar/SushiBarDatabaseImplement/Models/Client.cs index e517239..5ca53e2 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Client.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Client.cs @@ -12,7 +12,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace PizzeriaDatabaseImplement.Models +namespace SushiBarDatabaseImplement.Models { public class Client : IClientModel { diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs index 07c4247..ec89d77 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs @@ -15,6 +15,9 @@ namespace SushiBarDatabaseImplement.Models { public int Id { get; private set; } + [Required] + public int ClientId { get; private set; } + public virtual Client Client { get; private set; } = new(); [Required] public int SushiId { get; private set; } @@ -39,6 +42,8 @@ namespace SushiBarDatabaseImplement.Models return new Order() { Id = model.Id, + ClientId = model.ClientId, + Client = context.Clients.First(x => x.Id == model.ClientId), SushiId = model.SushiId, Sushi = context.Sushis.First(x => x.Id == model.SushiId), Count = model.Count, diff --git a/SushiBar/SushiBarDatabaseImplement/SushiBarDatatbase.cs b/SushiBar/SushiBarDatabaseImplement/SushiBarDatatbase.cs index 715a501..b6b164e 100644 --- a/SushiBar/SushiBarDatabaseImplement/SushiBarDatatbase.cs +++ b/SushiBar/SushiBarDatabaseImplement/SushiBarDatatbase.cs @@ -22,5 +22,6 @@ namespace SushiBarDatabaseImplement public virtual DbSet Sushis { set; get; } public virtual DbSet SushiComponents { set; get; } public virtual DbSet Orders { set; get; } + public virtual DbSet Clients { set; get; } } } diff --git a/SushiBar/SushiBarFileImplement/DataFileSingleton.cs b/SushiBar/SushiBarFileImplement/DataFileSingleton.cs index 26bfc23..51e7da2 100644 --- a/SushiBar/SushiBarFileImplement/DataFileSingleton.cs +++ b/SushiBar/SushiBarFileImplement/DataFileSingleton.cs @@ -1,4 +1,5 @@ -using SushiBarFileImplement.Models; +using PizzeriaFileImplement.Models; +using SushiBarFileImplement.Models; using System; using System.Collections.Generic; using System.Linq; @@ -14,9 +15,11 @@ namespace SushiBarFileImplement private readonly string ComponentFileName = "Component.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string SushiFileName = "Sushi.xml"; + private readonly string ClientFileName = "Client.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Sushis { get; private set; } + public List Clients { get; private set; } public static DataFileSingleton GetInstance() { @@ -30,12 +33,14 @@ namespace SushiBarFileImplement public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); public void SaveSushis() => SaveData(Sushis, SushiFileName, "Sushis", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Sushis = LoadData(SushiFileName, "Sushi", x => Sushi.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) diff --git a/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs index cb2c3ca..ab01272 100644 --- a/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarFileImplement/Implements/OrderStorage.cs @@ -24,11 +24,21 @@ namespace SushiBarFileImplement.Implements public List GetFilteredList(OrderSearchModel model) { - if (!model.DateFrom.HasValue || !model.DateTo.HasValue) + if (model.DateFrom.HasValue) { - return new(); + return source.Orders.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) + .Select(x => GetViewModel(x)).ToList(); } - return source.Orders.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).Select(x => AttachSushiName(x.GetViewModel)).ToList(); + if (model.ClientId.HasValue && !model.Id.HasValue) + { + return source.Orders.Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList(); + } + + if (model.Id.HasValue) + { + return source.Orders.Where(x => x.Id.Equals(model.Id)).Select(x => GetViewModel(x)).ToList(); + } + return new(); } public OrderViewModel? GetElement(OrderSearchModel model) @@ -90,5 +100,23 @@ namespace SushiBarFileImplement.Implements } return model; } + + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + + var pizza = source.Sushis.FirstOrDefault(x => x.Id == order.SushiId); + var client = source.Clients.FirstOrDefault(x => x.Id == order.ClientId); + + if (pizza != null) + { + viewModel.SushiName = pizza.SushiName; + } + if (client != null) + { + viewModel.ClientFIO = client.ClientFIO; + } + return viewModel; + } } } diff --git a/SushiBar/SushiBarFileImplement/Models/Order.cs b/SushiBar/SushiBarFileImplement/Models/Order.cs index a8a207d..30d0fbc 100644 --- a/SushiBar/SushiBarFileImplement/Models/Order.cs +++ b/SushiBar/SushiBarFileImplement/Models/Order.cs @@ -14,6 +14,7 @@ namespace SushiBarFileImplement.Models internal class Order : IOrderModel { public int Id { get; private set; } + public int ClientId { get; private set; } public int SushiId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } @@ -31,6 +32,7 @@ namespace SushiBarFileImplement.Models { Id = model.Id, SushiId = model.SushiId, + ClientId = model.ClientId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -50,6 +52,7 @@ namespace SushiBarFileImplement.Models { Id = Convert.ToInt32(element.Attribute("Id")!.Value), SushiId = Convert.ToInt32(element.Element("SushiId")!.Value), + ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), Status = (OrderStatus)(Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value)), @@ -73,6 +76,7 @@ namespace SushiBarFileImplement.Models { Id = Id, SushiId = SushiId, + ClientId = ClientId, Count = Count, Sum = Sum, Status = Status, @@ -83,6 +87,7 @@ namespace SushiBarFileImplement.Models public XElement GetXElement => new("Order", new XAttribute("Id", Id), new XElement("SushiId", SushiId.ToString()), + new XElement("ClientId", ClientId.ToString()), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()), diff --git a/SushiBar/SushiBarListImplement_/DataListSingleton.cs b/SushiBar/SushiBarListImplement_/DataListSingleton.cs index 6eabe76..a5a7000 100644 --- a/SushiBar/SushiBarListImplement_/DataListSingleton.cs +++ b/SushiBar/SushiBarListImplement_/DataListSingleton.cs @@ -13,11 +13,13 @@ namespace SushiBarListImplement public List Components { get; set; } public List Orders { get; set; } public List Sushis { get; set; } + public List Clients { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Sushis = new List(); + Clients = new List(); } public static DataListSingleton GetInstance() { diff --git a/SushiBar/SushiBarListImplement_/Implements/OrderStorage.cs b/SushiBar/SushiBarListImplement_/Implements/OrderStorage.cs index 05e2b9e..7d902ee 100644 --- a/SushiBar/SushiBarListImplement_/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarListImplement_/Implements/OrderStorage.cs @@ -33,18 +33,37 @@ namespace SushiBarListImplement.Implements public List GetFilteredList(OrderSearchModel model) { var result = new List(); - if (model == null || !model.DateFrom.HasValue || !model.DateFrom.HasValue) - - { - return result; - } + if (model.DateFrom.HasValue) + + { foreach (var order in _source.Orders) { if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo) { - result.Add(AttachSushiName(order.GetViewModel)); + result.Add(GetViewModel(order)); } } + } + else if (model.ClientId.HasValue && !model.Id.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.ClientId == model.ClientId) + { + result.Add(GetViewModel(order)); + } + } + } + else if (model.Id.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(GetViewModel(order)); + } + } + } return result; } @@ -122,5 +141,27 @@ namespace SushiBarListImplement.Implements } return model; } + + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + foreach (var package in _source.Sushis) + { + if (package.Id == order.SushiId) + { + viewModel.SushiName = package.SushiName; + break; + } + } + foreach (var client in _source.Clients) + { + if (client.Id == order.ClientId) + { + viewModel.ClientFIO = client.ClientFIO; + break; + } + } + return viewModel; + } } } diff --git a/SushiBar/SushiBarListImplement_/Models/Client.cs b/SushiBar/SushiBarListImplement_/Models/Client.cs index c72d83e..88bcbe1 100644 --- a/SushiBar/SushiBarListImplement_/Models/Client.cs +++ b/SushiBar/SushiBarListImplement_/Models/Client.cs @@ -4,7 +4,7 @@ using SushiBarContracts.BindingModels; using SushiBarContracts.ViewModels; using SushiBarDataModels.Models; -namespace PizzeriaListImplement.Models +namespace SushiBarListImplement.Models { public class Client : IClientModel { diff --git a/SushiBar/SushiBarListImplement_/Models/Order.cs b/SushiBar/SushiBarListImplement_/Models/Order.cs index f1d69d4..6122d44 100644 --- a/SushiBar/SushiBarListImplement_/Models/Order.cs +++ b/SushiBar/SushiBarListImplement_/Models/Order.cs @@ -14,6 +14,7 @@ namespace SushiBarListImplement.Models { public int Id { get; private set; } public int SushiId { get; private set; } + public int ClientId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; @@ -30,6 +31,7 @@ namespace SushiBarListImplement.Models { Id = model.Id, SushiId = model.SushiId, + ClientId = model.ClientId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -52,6 +54,7 @@ namespace SushiBarListImplement.Models { Id = Id, SushiId = SushiId, + ClientId = ClientId, Count = Count, Sum = Sum, Status = Status, diff --git a/SushiBar/SushiBarView/FormClients.Designer.cs b/SushiBar/SushiBarView/FormClients.Designer.cs new file mode 100644 index 0000000..8890b03 --- /dev/null +++ b/SushiBar/SushiBarView/FormClients.Designer.cs @@ -0,0 +1,95 @@ + +namespace SushiBarView +{ + partial class FormClients + { + /// + /// 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.buttonDel = new System.Windows.Forms.Button(); + this.buttonRef = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(350, 312); + this.dataGridView.TabIndex = 0; + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(368, 12); + 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); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(368, 53); + 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); + // + // FormClients + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(464, 312); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.dataGridView); + this.Name = "FormClients"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Клиенты"; + this.Load += new System.EventHandler(this.FormClients_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + } + + #endregion + + private System.Windows.Forms.DataGridView dataGridView; + private System.Windows.Forms.Button buttonDel; + private System.Windows.Forms.Button buttonRef; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormClients.cs b/SushiBar/SushiBarView/FormClients.cs new file mode 100644 index 0000000..a602b48 --- /dev/null +++ b/SushiBar/SushiBarView/FormClients.cs @@ -0,0 +1,86 @@ +using Microsoft.Extensions.Logging; +using SushiBar.BindingModels; +using SushiBar.BusinessLogicsContracts; +using SushiBarContracts.BindingModels; +using SushiBarContracts.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 SushiBarView +{ + public partial class FormClients : Form + { + private readonly ILogger _logger; + + private readonly IClientLogic _logic; + + public FormClients(ILogger logger, IClientLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormClients_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["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка клиентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки клиентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + 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 ClientBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + _logger.LogInformation("Удаление клиента"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления клиента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/SushiBar/SushiBarView/FormClients.resx b/SushiBar/SushiBarView/FormClients.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/SushiBar/SushiBarView/FormClients.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/SushiBar/SushiBarView/FormCreateOrder.Designer.cs b/SushiBar/SushiBarView/FormCreateOrder.Designer.cs index fe9c140..7c4aa5e 100644 --- a/SushiBar/SushiBarView/FormCreateOrder.Designer.cs +++ b/SushiBar/SushiBarView/FormCreateOrder.Designer.cs @@ -28,107 +28,127 @@ /// private void InitializeComponent() { - this.textBoxCount = new System.Windows.Forms.TextBox(); - this.labelCost = new System.Windows.Forms.Label(); - this.labelName = new System.Windows.Forms.Label(); - this.textBoxSum = new System.Windows.Forms.TextBox(); - this.label1 = new System.Windows.Forms.Label(); - this.ButtonCancel = new System.Windows.Forms.Button(); - this.ButtonSave = new System.Windows.Forms.Button(); - this.comboBoxSushi = new System.Windows.Forms.ComboBox(); - this.SuspendLayout(); + textBoxCount = new TextBox(); + labelCost = new Label(); + labelName = new Label(); + textBoxSum = new TextBox(); + label1 = new Label(); + ButtonCancel = new Button(); + ButtonSave = new Button(); + comboBoxSushi = new ComboBox(); + comboBoxUser = new ComboBox(); + labelUser = new Label(); + SuspendLayout(); // // textBoxCount // - this.textBoxCount.Location = new System.Drawing.Point(83, 42); - this.textBoxCount.Name = "textBoxCount"; - this.textBoxCount.Size = new System.Drawing.Size(262, 23); - this.textBoxCount.TabIndex = 9; - this.textBoxCount.TextChanged += new System.EventHandler(this.textBoxCost_TextChanged); + textBoxCount.Location = new Point(83, 42); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(262, 23); + textBoxCount.TabIndex = 9; + textBoxCount.TextChanged += textBoxCost_TextChanged; // // labelCost // - this.labelCost.AutoSize = true; - this.labelCost.Location = new System.Drawing.Point(5, 45); - this.labelCost.Name = "labelCost"; - this.labelCost.Size = new System.Drawing.Size(72, 15); - this.labelCost.TabIndex = 7; - this.labelCost.Text = "Количество"; - this.labelCost.Click += new System.EventHandler(this.labelCost_Click); + labelCost.AutoSize = true; + labelCost.Location = new Point(5, 45); + labelCost.Name = "labelCost"; + labelCost.Size = new Size(72, 15); + labelCost.TabIndex = 7; + labelCost.Text = "Количество"; + labelCost.Click += labelCost_Click; // // labelName // - this.labelName.AutoSize = true; - this.labelName.Location = new System.Drawing.Point(5, 12); - this.labelName.Name = "labelName"; - this.labelName.Size = new System.Drawing.Size(53, 15); - this.labelName.TabIndex = 6; - this.labelName.Text = "Изделие"; + labelName.AutoSize = true; + labelName.Location = new Point(5, 12); + labelName.Name = "labelName"; + labelName.Size = new Size(53, 15); + labelName.TabIndex = 6; + labelName.Text = "Изделие"; // // textBoxSum // - this.textBoxSum.Location = new System.Drawing.Point(83, 80); - this.textBoxSum.Name = "textBoxSum"; - this.textBoxSum.Size = new System.Drawing.Size(262, 23); - this.textBoxSum.TabIndex = 11; + textBoxSum.Location = new Point(83, 75); + textBoxSum.Name = "textBoxSum"; + textBoxSum.Size = new Size(262, 23); + textBoxSum.TabIndex = 11; // // label1 // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(5, 83); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(45, 15); - this.label1.TabIndex = 10; - this.label1.Text = "Сумма"; + label1.AutoSize = true; + label1.Location = new Point(5, 83); + label1.Name = "label1"; + label1.Size = new Size(45, 15); + label1.TabIndex = 10; + label1.Text = "Сумма"; // // ButtonCancel // - this.ButtonCancel.Location = new System.Drawing.Point(258, 120); - this.ButtonCancel.Name = "ButtonCancel"; - this.ButtonCancel.Size = new System.Drawing.Size(87, 26); - this.ButtonCancel.TabIndex = 13; - this.ButtonCancel.Text = "Отмена"; - this.ButtonCancel.UseVisualStyleBackColor = true; - this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + ButtonCancel.Location = new Point(258, 166); + ButtonCancel.Name = "ButtonCancel"; + ButtonCancel.Size = new Size(87, 26); + ButtonCancel.TabIndex = 13; + ButtonCancel.Text = "Отмена"; + ButtonCancel.UseVisualStyleBackColor = true; + ButtonCancel.Click += ButtonCancel_Click; // // ButtonSave // - this.ButtonSave.Location = new System.Drawing.Point(165, 120); - this.ButtonSave.Name = "ButtonSave"; - this.ButtonSave.Size = new System.Drawing.Size(87, 26); - this.ButtonSave.TabIndex = 12; - this.ButtonSave.Text = "Сохранить"; - this.ButtonSave.UseVisualStyleBackColor = true; - this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + ButtonSave.Location = new Point(165, 166); + ButtonSave.Name = "ButtonSave"; + ButtonSave.Size = new Size(87, 26); + ButtonSave.TabIndex = 12; + ButtonSave.Text = "Сохранить"; + ButtonSave.UseVisualStyleBackColor = true; + ButtonSave.Click += ButtonSave_Click; // // comboBoxSushi // - this.comboBoxSushi.FormattingEnabled = true; - this.comboBoxSushi.Location = new System.Drawing.Point(83, 9); - this.comboBoxSushi.Name = "comboBoxSushi"; - this.comboBoxSushi.Size = new System.Drawing.Size(262, 23); - this.comboBoxSushi.TabIndex = 14; - this.comboBoxSushi.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); + comboBoxSushi.FormattingEnabled = true; + comboBoxSushi.Location = new Point(83, 9); + comboBoxSushi.Name = "comboBoxSushi"; + comboBoxSushi.Size = new Size(262, 23); + comboBoxSushi.TabIndex = 14; + comboBoxSushi.SelectedIndexChanged += comboBox1_SelectedIndexChanged; + // + // comboBoxUser + // + comboBoxUser.FormattingEnabled = true; + comboBoxUser.Location = new Point(95, 110); + comboBoxUser.Name = "comboBoxUser"; + comboBoxUser.Size = new Size(250, 23); + comboBoxUser.TabIndex = 15; + // + // labelUser + // + labelUser.AutoSize = true; + labelUser.Location = new Point(5, 113); + labelUser.Name = "labelUser"; + labelUser.Size = new Size(84, 15); + labelUser.TabIndex = 16; + labelUser.Text = "Пользователь"; // // FormCreateOrder // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(354, 158); - this.Controls.Add(this.comboBoxSushi); - this.Controls.Add(this.ButtonCancel); - this.Controls.Add(this.ButtonSave); - this.Controls.Add(this.textBoxSum); - this.Controls.Add(this.label1); - this.Controls.Add(this.textBoxCount); - this.Controls.Add(this.labelCost); - this.Controls.Add(this.labelName); - this.Name = "FormCreateOrder"; - this.Text = "FormCreateOrder"; - this.Load += new System.EventHandler(this.FormCreateOrder_Load); - this.ResumeLayout(false); - this.PerformLayout(); - + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(354, 204); + Controls.Add(labelUser); + Controls.Add(comboBoxUser); + Controls.Add(comboBoxSushi); + Controls.Add(ButtonCancel); + Controls.Add(ButtonSave); + Controls.Add(textBoxSum); + Controls.Add(label1); + Controls.Add(textBoxCount); + Controls.Add(labelCost); + Controls.Add(labelName); + Name = "FormCreateOrder"; + Text = "FormCreateOrder"; + Load += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); } #endregion @@ -141,5 +161,7 @@ private Button ButtonCancel; private Button ButtonSave; private ComboBox comboBoxSushi; + private ComboBox comboBoxUser; + private Label labelUser; } } \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormCreateOrder.cs b/SushiBar/SushiBarView/FormCreateOrder.cs index fd23448..e1624d4 100644 --- a/SushiBar/SushiBarView/FormCreateOrder.cs +++ b/SushiBar/SushiBarView/FormCreateOrder.cs @@ -1,4 +1,6 @@ using Microsoft.Extensions.Logging; +using SushiBar.BusinessLogicsContracts; +using SushiBar.ViewModels; using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.SearchModels; @@ -21,30 +23,42 @@ namespace SushiBarView private readonly ILogger _logger; private readonly ISushiLogic _logicP; private readonly IOrderLogic _logicO; - private List? _list; + private readonly IClientLogic _logicC; + private List? _listSushis; + private List? _listClients; public FormCreateOrder() { InitializeComponent(); } - public FormCreateOrder(ILogger logger, ISushiLogic logicP, IOrderLogic logicO) + public FormCreateOrder(ILogger logger, ISushiLogic logicP, IOrderLogic logicO, IClientLogic logicC) { InitializeComponent(); _logger = logger; _logicP = logicP; _logicO = logicO; + _logicC = logicC; } private void FormCreateOrder_Load(object sender, EventArgs e) { _logger.LogInformation("Загрузка изделий для заказа"); - _list = _logicP.ReadList(null); - if (_list != null) + _listSushis = _logicP.ReadList(null); + if (_listSushis != null) { comboBoxSushi.DisplayMember = "SushiName"; comboBoxSushi.ValueMember = "Id"; - comboBoxSushi.DataSource = _list; + comboBoxSushi.DataSource = _listSushis; comboBoxSushi.SelectedItem = null; _logger.LogInformation("Загрузка суши для заказа"); } + _listClients = _logicC.ReadList(null); + if (_listClients != null) + { + comboBoxUser.DisplayMember = "ClientFIO"; + comboBoxUser.ValueMember = "Id"; + comboBoxUser.DataSource = _listClients; + comboBoxUser.SelectedItem = null; + _logger.LogInformation("Загрузка клиентов для заказа"); + } } private void labelCost_Click(object sender, EventArgs e) { @@ -65,11 +79,17 @@ namespace SushiBarView MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + if (comboBoxUser.SelectedValue == null) + { + MessageBox.Show("Выберите клиента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } _logger.LogInformation("Создание заказа"); try { var operationResult = _logicO.CreateOrder(new OrderBindingModel { + ClientId = Convert.ToInt32(comboBoxUser.SelectedValue), SushiId = Convert.ToInt32(comboBoxSushi.SelectedValue), Count = Convert.ToInt32(textBoxCount.Text), Sum = Convert.ToDouble(textBoxSum.Text) @@ -92,16 +112,15 @@ namespace SushiBarView } private void CalcSum() { - if (comboBoxSushi.SelectedValue != null && + if (comboBoxSushi.SelectedValue != null && comboBoxUser.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) { try { - int id = Convert.ToInt32(comboBoxSushi.SelectedValue); + int idSushi = Convert.ToInt32(comboBoxSushi.SelectedValue); var sushi = _logicP.ReadElement(new SushiSearchModel { - Id - = id + Id = idSushi }); int count = Convert.ToInt32(textBoxCount.Text); textBoxSum.Text = Math.Round(count * (sushi?.Price ?? 0), diff --git a/SushiBar/SushiBarView/FormCreateOrder.resx b/SushiBar/SushiBarView/FormCreateOrder.resx index f298a7b..af32865 100644 --- a/SushiBar/SushiBarView/FormCreateOrder.resx +++ b/SushiBar/SushiBarView/FormCreateOrder.resx @@ -1,4 +1,64 @@ - + + + diff --git a/SushiBar/SushiBarView/FormMain.Designer.cs b/SushiBar/SushiBarView/FormMain.Designer.cs index cfbe231..c215ef9 100644 --- a/SushiBar/SushiBarView/FormMain.Designer.cs +++ b/SushiBar/SushiBarView/FormMain.Designer.cs @@ -28,170 +28,171 @@ /// private void InitializeComponent() { - this.ButtonCreateOrder = new System.Windows.Forms.Button(); - this.ButtonOrderReady = new System.Windows.Forms.Button(); - this.ButtonRef = new System.Windows.Forms.Button(); - this.ButtonIssuedOrder = new System.Windows.Forms.Button(); - this.ButtonTakeOrderInWork = new System.Windows.Forms.Button(); - this.menuStrip = new System.Windows.Forms.MenuStrip(); - this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); - this.componentsToolStripMenuItemToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.sushiToolStripMenuItemToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.отчётыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.componentsToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); - this.componentSushiToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); - this.ordersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.menuStrip.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); + ButtonCreateOrder = new Button(); + ButtonOrderReady = new Button(); + ButtonRef = new Button(); + ButtonIssuedOrder = new Button(); + ButtonTakeOrderInWork = new Button(); + menuStrip = new MenuStrip(); + toolStripMenuItem1 = new ToolStripMenuItem(); + componentsToolStripMenuItemToolStripMenuItem = new ToolStripMenuItem(); + sushiToolStripMenuItemToolStripMenuItem = new ToolStripMenuItem(); + отчётыToolStripMenuItem = new ToolStripMenuItem(); + componentsToolStripMenuItem1 = new ToolStripMenuItem(); + componentSushiToolStripMenuItem1 = new ToolStripMenuItem(); + ordersToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + ClientToolStripMenuItem = new ToolStripMenuItem(); + menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); // // ButtonCreateOrder // - this.ButtonCreateOrder.Location = new System.Drawing.Point(676, 37); - this.ButtonCreateOrder.Name = "ButtonCreateOrder"; - this.ButtonCreateOrder.Size = new System.Drawing.Size(217, 29); - this.ButtonCreateOrder.TabIndex = 0; - this.ButtonCreateOrder.Text = "Создать заказ"; - this.ButtonCreateOrder.UseVisualStyleBackColor = true; - this.ButtonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + ButtonCreateOrder.Location = new Point(676, 37); + ButtonCreateOrder.Name = "ButtonCreateOrder"; + ButtonCreateOrder.Size = new Size(217, 29); + ButtonCreateOrder.TabIndex = 0; + ButtonCreateOrder.Text = "Создать заказ"; + ButtonCreateOrder.UseVisualStyleBackColor = true; + ButtonCreateOrder.Click += ButtonCreateOrder_Click; // // ButtonOrderReady // - this.ButtonOrderReady.Location = new System.Drawing.Point(676, 180); - this.ButtonOrderReady.Name = "ButtonOrderReady"; - this.ButtonOrderReady.Size = new System.Drawing.Size(217, 29); - this.ButtonOrderReady.TabIndex = 1; - this.ButtonOrderReady.Text = "Заказ готов"; - this.ButtonOrderReady.UseVisualStyleBackColor = true; - this.ButtonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + ButtonOrderReady.Location = new Point(676, 180); + ButtonOrderReady.Name = "ButtonOrderReady"; + ButtonOrderReady.Size = new Size(217, 29); + ButtonOrderReady.TabIndex = 1; + ButtonOrderReady.Text = "Заказ готов"; + ButtonOrderReady.UseVisualStyleBackColor = true; + ButtonOrderReady.Click += ButtonOrderReady_Click; // // ButtonRef // - this.ButtonRef.Location = new System.Drawing.Point(676, 323); - this.ButtonRef.Name = "ButtonRef"; - this.ButtonRef.Size = new System.Drawing.Size(217, 29); - this.ButtonRef.TabIndex = 2; - this.ButtonRef.Text = "Обновить список"; - this.ButtonRef.UseVisualStyleBackColor = true; - this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + ButtonRef.Location = new Point(676, 323); + ButtonRef.Name = "ButtonRef"; + ButtonRef.Size = new Size(217, 29); + ButtonRef.TabIndex = 2; + ButtonRef.Text = "Обновить список"; + ButtonRef.UseVisualStyleBackColor = true; + ButtonRef.Click += ButtonRef_Click; // // ButtonIssuedOrder // - this.ButtonIssuedOrder.Location = new System.Drawing.Point(676, 256); - this.ButtonIssuedOrder.Name = "ButtonIssuedOrder"; - this.ButtonIssuedOrder.Size = new System.Drawing.Size(217, 29); - this.ButtonIssuedOrder.TabIndex = 3; - this.ButtonIssuedOrder.Text = "Заказ выполнен"; - this.ButtonIssuedOrder.UseVisualStyleBackColor = true; - this.ButtonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + ButtonIssuedOrder.Location = new Point(676, 256); + ButtonIssuedOrder.Name = "ButtonIssuedOrder"; + ButtonIssuedOrder.Size = new Size(217, 29); + ButtonIssuedOrder.TabIndex = 3; + ButtonIssuedOrder.Text = "Заказ выполнен"; + ButtonIssuedOrder.UseVisualStyleBackColor = true; + ButtonIssuedOrder.Click += ButtonIssuedOrder_Click; // // ButtonTakeOrderInWork // - this.ButtonTakeOrderInWork.Location = new System.Drawing.Point(676, 109); - this.ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; - this.ButtonTakeOrderInWork.Size = new System.Drawing.Size(217, 29); - this.ButtonTakeOrderInWork.TabIndex = 4; - this.ButtonTakeOrderInWork.Text = "Отдать на выполнение"; - this.ButtonTakeOrderInWork.UseVisualStyleBackColor = true; - this.ButtonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + ButtonTakeOrderInWork.Location = new Point(676, 109); + ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; + ButtonTakeOrderInWork.Size = new Size(217, 29); + ButtonTakeOrderInWork.TabIndex = 4; + ButtonTakeOrderInWork.Text = "Отдать на выполнение"; + ButtonTakeOrderInWork.UseVisualStyleBackColor = true; + ButtonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; // // menuStrip // - this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.toolStripMenuItem1, this.отчётыToolStripMenuItem}); - this.menuStrip.Location = new System.Drawing.Point(0, 0); - this.menuStrip.Name = "menuStrip"; - this.menuStrip.Size = new System.Drawing.Size(922, 24); - this.menuStrip.TabIndex = 5; - this.menuStrip.Text = "menuStrip1"; + menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem1, отчётыToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(922, 24); + menuStrip.TabIndex = 5; + menuStrip.Text = "menuStrip1"; // // toolStripMenuItem1 // - this.toolStripMenuItem1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.componentsToolStripMenuItemToolStripMenuItem, - this.sushiToolStripMenuItemToolStripMenuItem}); - this.toolStripMenuItem1.Name = "toolStripMenuItem1"; - this.toolStripMenuItem1.Size = new System.Drawing.Size(94, 20); - this.toolStripMenuItem1.Text = "Справочники"; + toolStripMenuItem1.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItemToolStripMenuItem, sushiToolStripMenuItemToolStripMenuItem, ClientToolStripMenuItem }); + toolStripMenuItem1.Name = "toolStripMenuItem1"; + toolStripMenuItem1.Size = new Size(94, 20); + toolStripMenuItem1.Text = "Справочники"; // // componentsToolStripMenuItemToolStripMenuItem // - this.componentsToolStripMenuItemToolStripMenuItem.Name = "componentsToolStripMenuItemToolStripMenuItem"; - this.componentsToolStripMenuItemToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.componentsToolStripMenuItemToolStripMenuItem.Text = "Компоненты"; - this.componentsToolStripMenuItemToolStripMenuItem.Click += new System.EventHandler(this.componentsToolStripMenuItem_Click); + componentsToolStripMenuItemToolStripMenuItem.Name = "componentsToolStripMenuItemToolStripMenuItem"; + componentsToolStripMenuItemToolStripMenuItem.Size = new Size(180, 22); + componentsToolStripMenuItemToolStripMenuItem.Text = "Компоненты"; + componentsToolStripMenuItemToolStripMenuItem.Click += componentsToolStripMenuItem_Click; // // sushiToolStripMenuItemToolStripMenuItem // - this.sushiToolStripMenuItemToolStripMenuItem.Name = "sushiToolStripMenuItemToolStripMenuItem"; - this.sushiToolStripMenuItemToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.sushiToolStripMenuItemToolStripMenuItem.Text = "Суши"; - this.sushiToolStripMenuItemToolStripMenuItem.Click += new System.EventHandler(this.sushiToolStripMenuItem_Click); - // - // dataGridView - // - this.dataGridView.BackgroundColor = System.Drawing.Color.White; - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(12, 27); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.Size = new System.Drawing.Size(647, 344); - this.dataGridView.TabIndex = 6; + sushiToolStripMenuItemToolStripMenuItem.Name = "sushiToolStripMenuItemToolStripMenuItem"; + sushiToolStripMenuItemToolStripMenuItem.Size = new Size(180, 22); + sushiToolStripMenuItemToolStripMenuItem.Text = "Суши"; + sushiToolStripMenuItemToolStripMenuItem.Click += sushiToolStripMenuItem_Click; // // отчётыToolStripMenuItem // - this.отчётыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.componentsToolStripMenuItem1, - this.componentSushiToolStripMenuItem1, - this.ordersToolStripMenuItem}); - this.отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; - this.отчётыToolStripMenuItem.Size = new System.Drawing.Size(60, 20); - this.отчётыToolStripMenuItem.Text = "Отчёты"; + отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem1, componentSushiToolStripMenuItem1, ordersToolStripMenuItem }); + отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; + отчётыToolStripMenuItem.Size = new Size(60, 20); + отчётыToolStripMenuItem.Text = "Отчёты"; // // componentsToolStripMenuItem1 // - this.componentsToolStripMenuItem1.Name = "componentsToolStripMenuItem1"; - this.componentsToolStripMenuItem1.Size = new System.Drawing.Size(205, 22); - this.componentsToolStripMenuItem1.Text = "Суши"; - this.componentsToolStripMenuItem1.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click); + componentsToolStripMenuItem1.Name = "componentsToolStripMenuItem1"; + componentsToolStripMenuItem1.Size = new Size(201, 22); + componentsToolStripMenuItem1.Text = "Суши"; + componentsToolStripMenuItem1.Click += ComponentsToolStripMenuItem_Click; // // componentSushiToolStripMenuItem1 // - this.componentSushiToolStripMenuItem1.Name = "componentSushiToolStripMenuItem1"; - this.componentSushiToolStripMenuItem1.Size = new System.Drawing.Size(205, 22); - this.componentSushiToolStripMenuItem1.Text = "Суши с компонентами"; - this.componentSushiToolStripMenuItem1.Click += new System.EventHandler(this.ComponentSushiToolStripMenuItem_Click); + componentSushiToolStripMenuItem1.Name = "componentSushiToolStripMenuItem1"; + componentSushiToolStripMenuItem1.Size = new Size(201, 22); + componentSushiToolStripMenuItem1.Text = "Суши с компонентами"; + componentSushiToolStripMenuItem1.Click += ComponentSushiToolStripMenuItem_Click; // // ordersToolStripMenuItem // - this.ordersToolStripMenuItem.Name = "ordersToolStripMenuItem"; - this.ordersToolStripMenuItem.Size = new System.Drawing.Size(205, 22); - this.ordersToolStripMenuItem.Text = "Заказы"; - this.ordersToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click); + ordersToolStripMenuItem.Name = "ordersToolStripMenuItem"; + ordersToolStripMenuItem.Size = new Size(201, 22); + ordersToolStripMenuItem.Text = "Заказы"; + ordersToolStripMenuItem.Click += OrdersToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.BackgroundColor = Color.White; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 27); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(647, 344); + dataGridView.TabIndex = 6; + // + // ClientToolStripMenuItem + // + ClientToolStripMenuItem.Name = "ClientToolStripMenuItem"; + ClientToolStripMenuItem.Size = new Size(180, 22); + ClientToolStripMenuItem.Text = "Клиенты"; + ClientToolStripMenuItem.Click += ClientToolStripMenuItem_Click; // // FormMain // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(922, 383); - this.Controls.Add(this.dataGridView); - this.Controls.Add(this.ButtonTakeOrderInWork); - this.Controls.Add(this.ButtonIssuedOrder); - this.Controls.Add(this.ButtonRef); - this.Controls.Add(this.ButtonOrderReady); - this.Controls.Add(this.ButtonCreateOrder); - this.Controls.Add(this.menuStrip); - this.MainMenuStrip = this.menuStrip; - this.Name = "FormMain"; - this.Text = "FormMain"; - this.Load += new System.EventHandler(this.FormMain_Load); - this.menuStrip.ResumeLayout(false); - this.menuStrip.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); - + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(922, 383); + Controls.Add(dataGridView); + Controls.Add(ButtonTakeOrderInWork); + Controls.Add(ButtonIssuedOrder); + Controls.Add(ButtonRef); + Controls.Add(ButtonOrderReady); + Controls.Add(ButtonCreateOrder); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Name = "FormMain"; + Text = "FormMain"; + Load += FormMain_Load; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); } #endregion @@ -210,5 +211,6 @@ private ToolStripMenuItem componentsToolStripMenuItem1; private ToolStripMenuItem componentSushiToolStripMenuItem1; private ToolStripMenuItem ordersToolStripMenuItem; + private ToolStripMenuItem ClientToolStripMenuItem; } } \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormMain.cs b/SushiBar/SushiBarView/FormMain.cs index 17856df..936bcab 100644 --- a/SushiBar/SushiBarView/FormMain.cs +++ b/SushiBar/SushiBarView/FormMain.cs @@ -57,7 +57,8 @@ namespace SushiBarView { dataGridView.DataSource = list; dataGridView.Columns["SushiId"].Visible = false; - + dataGridView.Columns["ClientId"].Visible = false; + } _logger.LogInformation("Загрузка заказов"); } @@ -91,7 +92,7 @@ namespace SushiBarView int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); - try + try { var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel @@ -132,8 +133,8 @@ namespace SushiBarView catch (Exception ex) { _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, -MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); } } } @@ -200,5 +201,13 @@ MessageBoxIcon.Error); } } + private void ClientToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormClients)); + if (service is FormClients form) + { + form.ShowDialog(); + } + } } } diff --git a/SushiBar/SushiBarView/FormMain.resx b/SushiBar/SushiBarView/FormMain.resx index 81a9e3d..6c82d08 100644 --- a/SushiBar/SushiBarView/FormMain.resx +++ b/SushiBar/SushiBarView/FormMain.resx @@ -1,4 +1,64 @@ - + + + diff --git a/SushiBar/SushiBarView/Program.cs b/SushiBar/SushiBarView/Program.cs index 1682684..c2864f9 100644 --- a/SushiBar/SushiBarView/Program.cs +++ b/SushiBar/SushiBarView/Program.cs @@ -11,6 +11,9 @@ using SushiBarBusinessLogic.OfficePackage.Implements; using SushiBarBusinessLogic.OfficePackage; using SushiBarBusinessLogic; using SushiBarView.Reports; +using SushiBar.StoragesContracts; +using Microsoft.EntityFrameworkCore.Design; +using SushiBar.BusinessLogicsContracts; namespace SushiBarView { @@ -40,9 +43,13 @@ namespace SushiBarView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -53,6 +60,8 @@ namespace SushiBarView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient();