From 4add59d1f62c1c11bbd5e78aea31bf70c0dc4e86 Mon Sep 17 00:00:00 2001 From: Oleg Shabunov Date: Fri, 24 May 2024 01:56:34 +0400 Subject: [PATCH] Forms --- .../BindingModels/DishBindingModel.cs | 10 +- .../DishIngredientBindingModel.cs | 9 - .../BindingModels/IngredientBindingModel.cs | 6 +- SushiBarContracts/SushiBarContracts.csproj | 4 + .../ViewModels/ChequeItemViewModel.cs | 2 + .../ViewModels/ChequeViewModel.cs | 1 + .../ViewModels/DishIngredientViewModel.cs | 17 -- SushiBarContracts/ViewModels/DishViewModel.cs | 10 +- .../ViewModels/IngredientViewModel.cs | 5 +- SushiBarDataModels/Models/IDish.cs | 9 - SushiBarDataModels/Models/IDishIngredient.cs | 11 - SushiBarDataModels/Models/IDishModel.cs | 13 + .../{IIngredient.cs => IIngredientModel.cs} | 2 +- ...523183058_Fix DishIngredients.Designer.cs} | 11 +- ... => 20240523183058_Fix DishIngredients.cs} | 5 +- .../SushiBarDatabaseModelSnapshot.cs | 7 +- SushiBarDatabaseImplement/Models/Dish.cs | 81 +++++- .../Models/Ingredient.cs | 3 +- .../Storages/ChequeStorage.cs | 13 + .../Storages/DishStorage.cs | 10 +- SushiBarDatabaseImplement/SushiBarDatabase.cs | 3 +- SushiBarView/Form1.Designer.cs | 39 --- SushiBarView/Form1.cs | 10 - SushiBarView/Forms/FormCook.Designer.cs | 105 ++++++++ SushiBarView/Forms/FormCook.cs | 78 ++++++ SushiBarView/Forms/FormCook.resx | 120 +++++++++ SushiBarView/Forms/FormCooks.Designer.cs | 113 ++++++++ SushiBarView/Forms/FormCooks.cs | 98 +++++++ .../{Form1.resx => Forms/FormCooks.resx} | 0 .../Forms/FormCreateCheque.Designer.cs | 199 ++++++++++++++ SushiBarView/Forms/FormCreateCheque.cs | 165 ++++++++++++ SushiBarView/Forms/FormCreateCheque.resx | 123 +++++++++ .../Forms/FormCreateChequeItem.Designer.cs | 143 ++++++++++ SushiBarView/Forms/FormCreateChequeItem.cs | 136 ++++++++++ SushiBarView/Forms/FormCreateChequeItem.resx | 120 +++++++++ SushiBarView/Forms/FormCustomer.Designer.cs | 128 +++++++++ SushiBarView/Forms/FormCustomer.cs | 80 ++++++ SushiBarView/Forms/FormCustomer.resx | 120 +++++++++ SushiBarView/Forms/FormCustomers.Designer.cs | 113 ++++++++ SushiBarView/Forms/FormCustomers.cs | 98 +++++++ SushiBarView/Forms/FormCustomers.resx | 120 +++++++++ SushiBarView/Forms/FormDish.Designer.cs | 249 ++++++++++++++++++ SushiBarView/Forms/FormDish.cs | 205 ++++++++++++++ SushiBarView/Forms/FormDish.resx | 120 +++++++++ .../Forms/FormDishIngredient.Designer.cs | 119 +++++++++ SushiBarView/Forms/FormDishIngredient.cs | 87 ++++++ SushiBarView/Forms/FormDishIngredient.resx | 120 +++++++++ SushiBarView/Forms/FormDishes.Designer.cs | 113 ++++++++ SushiBarView/Forms/FormDishes.cs | 97 +++++++ SushiBarView/Forms/FormDishes.resx | 120 +++++++++ SushiBarView/Forms/FormIngredient.Designer.cs | 127 +++++++++ SushiBarView/Forms/FormIngredient.cs | 81 ++++++ SushiBarView/Forms/FormIngredient.resx | 120 +++++++++ .../Forms/FormIngredients.Designer.cs | 113 ++++++++ SushiBarView/Forms/FormIngredients.cs | 98 +++++++ SushiBarView/Forms/FormIngredients.resx | 120 +++++++++ SushiBarView/Forms/FormPromotion.Designer.cs | 127 +++++++++ SushiBarView/Forms/FormPromotion.cs | 80 ++++++ SushiBarView/Forms/FormPromotion.resx | 120 +++++++++ SushiBarView/Forms/FormPromotions.Designer.cs | 113 ++++++++ SushiBarView/Forms/FormPromotions.cs | 98 +++++++ SushiBarView/Forms/FormPromotions.resx | 120 +++++++++ SushiBarView/MainForm.Designer.cs | 174 ++++++++++++ SushiBarView/MainForm.cs | 99 +++++++ SushiBarView/MainForm.resx | 123 +++++++++ SushiBarView/Program.cs | 12 +- SushiBarView/SushiBarView.csproj | 1 + 67 files changed, 5155 insertions(+), 141 deletions(-) delete mode 100644 SushiBarContracts/BindingModels/DishIngredientBindingModel.cs delete mode 100644 SushiBarContracts/ViewModels/DishIngredientViewModel.cs delete mode 100644 SushiBarDataModels/Models/IDish.cs delete mode 100644 SushiBarDataModels/Models/IDishIngredient.cs create mode 100644 SushiBarDataModels/Models/IDishModel.cs rename SushiBarDataModels/Models/{IIngredient.cs => IIngredientModel.cs} (77%) rename SushiBarDatabaseImplement/Migrations/{20240515171525_Initial.Designer.cs => 20240523183058_Fix DishIngredients.Designer.cs} (97%) rename SushiBarDatabaseImplement/Migrations/{20240515171525_Initial.cs => 20240523183058_Fix DishIngredients.cs} (98%) delete mode 100644 SushiBarView/Form1.Designer.cs delete mode 100644 SushiBarView/Form1.cs create mode 100644 SushiBarView/Forms/FormCook.Designer.cs create mode 100644 SushiBarView/Forms/FormCook.cs create mode 100644 SushiBarView/Forms/FormCook.resx create mode 100644 SushiBarView/Forms/FormCooks.Designer.cs create mode 100644 SushiBarView/Forms/FormCooks.cs rename SushiBarView/{Form1.resx => Forms/FormCooks.resx} (100%) create mode 100644 SushiBarView/Forms/FormCreateCheque.Designer.cs create mode 100644 SushiBarView/Forms/FormCreateCheque.cs create mode 100644 SushiBarView/Forms/FormCreateCheque.resx create mode 100644 SushiBarView/Forms/FormCreateChequeItem.Designer.cs create mode 100644 SushiBarView/Forms/FormCreateChequeItem.cs create mode 100644 SushiBarView/Forms/FormCreateChequeItem.resx create mode 100644 SushiBarView/Forms/FormCustomer.Designer.cs create mode 100644 SushiBarView/Forms/FormCustomer.cs create mode 100644 SushiBarView/Forms/FormCustomer.resx create mode 100644 SushiBarView/Forms/FormCustomers.Designer.cs create mode 100644 SushiBarView/Forms/FormCustomers.cs create mode 100644 SushiBarView/Forms/FormCustomers.resx create mode 100644 SushiBarView/Forms/FormDish.Designer.cs create mode 100644 SushiBarView/Forms/FormDish.cs create mode 100644 SushiBarView/Forms/FormDish.resx create mode 100644 SushiBarView/Forms/FormDishIngredient.Designer.cs create mode 100644 SushiBarView/Forms/FormDishIngredient.cs create mode 100644 SushiBarView/Forms/FormDishIngredient.resx create mode 100644 SushiBarView/Forms/FormDishes.Designer.cs create mode 100644 SushiBarView/Forms/FormDishes.cs create mode 100644 SushiBarView/Forms/FormDishes.resx create mode 100644 SushiBarView/Forms/FormIngredient.Designer.cs create mode 100644 SushiBarView/Forms/FormIngredient.cs create mode 100644 SushiBarView/Forms/FormIngredient.resx create mode 100644 SushiBarView/Forms/FormIngredients.Designer.cs create mode 100644 SushiBarView/Forms/FormIngredients.cs create mode 100644 SushiBarView/Forms/FormIngredients.resx create mode 100644 SushiBarView/Forms/FormPromotion.Designer.cs create mode 100644 SushiBarView/Forms/FormPromotion.cs create mode 100644 SushiBarView/Forms/FormPromotion.resx create mode 100644 SushiBarView/Forms/FormPromotions.Designer.cs create mode 100644 SushiBarView/Forms/FormPromotions.cs create mode 100644 SushiBarView/Forms/FormPromotions.resx create mode 100644 SushiBarView/MainForm.Designer.cs create mode 100644 SushiBarView/MainForm.cs create mode 100644 SushiBarView/MainForm.resx diff --git a/SushiBarContracts/BindingModels/DishBindingModel.cs b/SushiBarContracts/BindingModels/DishBindingModel.cs index bd7e47f..d27c851 100644 --- a/SushiBarContracts/BindingModels/DishBindingModel.cs +++ b/SushiBarContracts/BindingModels/DishBindingModel.cs @@ -1,6 +1,8 @@ -namespace SushiBarContracts.BindingModels +using SushiBarDataModels.Models; + +namespace SushiBarContracts.BindingModels { - public class DishBindingModel + public class DishBindingModel : IDishModel { public int Id { get; set; } @@ -8,6 +10,8 @@ public string Category { get; set;} = string.Empty; - public List Ingredients { get; set; } = new(); + public double Price { get; set; } + + public Dictionary DishIngredients { get; set; } = new(); } } diff --git a/SushiBarContracts/BindingModels/DishIngredientBindingModel.cs b/SushiBarContracts/BindingModels/DishIngredientBindingModel.cs deleted file mode 100644 index dd27e4c..0000000 --- a/SushiBarContracts/BindingModels/DishIngredientBindingModel.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace SushiBarContracts.BindingModels -{ - public class DishIngredientBindingModel - { - public int IngredientId { get; set; } - - public int Count { get; set; } - } -} diff --git a/SushiBarContracts/BindingModels/IngredientBindingModel.cs b/SushiBarContracts/BindingModels/IngredientBindingModel.cs index 201d44f..e826955 100644 --- a/SushiBarContracts/BindingModels/IngredientBindingModel.cs +++ b/SushiBarContracts/BindingModels/IngredientBindingModel.cs @@ -1,6 +1,8 @@ -namespace SushiBarContracts.BindingModels +using SushiBarDataModels.Models; + +namespace SushiBarContracts.BindingModels { - public class IngredientBindingModel + public class IngredientBindingModel : IIngredientModel { public int Id { get; set; } diff --git a/SushiBarContracts/SushiBarContracts.csproj b/SushiBarContracts/SushiBarContracts.csproj index 132c02c..ef52534 100644 --- a/SushiBarContracts/SushiBarContracts.csproj +++ b/SushiBarContracts/SushiBarContracts.csproj @@ -6,4 +6,8 @@ enable + + + + diff --git a/SushiBarContracts/ViewModels/ChequeItemViewModel.cs b/SushiBarContracts/ViewModels/ChequeItemViewModel.cs index c39e0d1..9ad4dcf 100644 --- a/SushiBarContracts/ViewModels/ChequeItemViewModel.cs +++ b/SushiBarContracts/ViewModels/ChequeItemViewModel.cs @@ -11,6 +11,8 @@ namespace SushiBarContracts.ViewModels [DisplayName("Название блюда")] public string DishName { get; set; } = string.Empty; + public double DishPrice { get; set; } + public int CookId { get; set; } [DisplayName("Повар")] diff --git a/SushiBarContracts/ViewModels/ChequeViewModel.cs b/SushiBarContracts/ViewModels/ChequeViewModel.cs index 57db2bb..3d34fa9 100644 --- a/SushiBarContracts/ViewModels/ChequeViewModel.cs +++ b/SushiBarContracts/ViewModels/ChequeViewModel.cs @@ -4,6 +4,7 @@ namespace SushiBarContracts.ViewModels { public class ChequeViewModel { + [DisplayName("Номер")] public int Id { get; set; } public int? CustomerId { get; set; } diff --git a/SushiBarContracts/ViewModels/DishIngredientViewModel.cs b/SushiBarContracts/ViewModels/DishIngredientViewModel.cs deleted file mode 100644 index e2822d1..0000000 --- a/SushiBarContracts/ViewModels/DishIngredientViewModel.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.ComponentModel; - -namespace SushiBarContracts.ViewModels -{ - public class DishIngredientViewModel - { - public int DishId { get; set; } - - public int IngredientId { get; set; } - - [DisplayName("Наименование ингредиента")] - public string IngredientName { get; set; } = string.Empty; - - [DisplayName("Количество")] - public int Count { get; set; } - } -} diff --git a/SushiBarContracts/ViewModels/DishViewModel.cs b/SushiBarContracts/ViewModels/DishViewModel.cs index cdea94b..33fcd03 100644 --- a/SushiBarContracts/ViewModels/DishViewModel.cs +++ b/SushiBarContracts/ViewModels/DishViewModel.cs @@ -1,8 +1,9 @@ -using System.ComponentModel; +using SushiBarDataModels.Models; +using System.ComponentModel; namespace SushiBarContracts.ViewModels { - public class DishViewModel + public class DishViewModel : IDishModel { public int Id { get; set; } @@ -12,6 +13,9 @@ namespace SushiBarContracts.ViewModels [DisplayName("Категория")] public string Category { get; set; } = string.Empty; - public Dictionary Ingredients { get; set; } = new(); + [DisplayName("Стоимость")] + public double Price { get; set; } + + public Dictionary DishIngredients { get; set; } = new(); } } diff --git a/SushiBarContracts/ViewModels/IngredientViewModel.cs b/SushiBarContracts/ViewModels/IngredientViewModel.cs index 59760fa..0d8dfce 100644 --- a/SushiBarContracts/ViewModels/IngredientViewModel.cs +++ b/SushiBarContracts/ViewModels/IngredientViewModel.cs @@ -1,8 +1,9 @@ -using System.ComponentModel; +using SushiBarDataModels.Models; +using System.ComponentModel; namespace SushiBarContracts.ViewModels { - public class IngredientViewModel + public class IngredientViewModel : IIngredientModel { public int Id { get; set; } diff --git a/SushiBarDataModels/Models/IDish.cs b/SushiBarDataModels/Models/IDish.cs deleted file mode 100644 index 752a96a..0000000 --- a/SushiBarDataModels/Models/IDish.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace SushiBarDataModels.Models -{ - public interface IDish : IId - { - string DishName { get; } - - string Category { get; } - } -} diff --git a/SushiBarDataModels/Models/IDishIngredient.cs b/SushiBarDataModels/Models/IDishIngredient.cs deleted file mode 100644 index 5ca5945..0000000 --- a/SushiBarDataModels/Models/IDishIngredient.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace SushiBarDataModels.Models -{ - public interface IDishIngredient : IId - { - int DishId { get; } - - int IngredientId { get; } - - int Count { get; } - } -} diff --git a/SushiBarDataModels/Models/IDishModel.cs b/SushiBarDataModels/Models/IDishModel.cs new file mode 100644 index 0000000..10d3cd5 --- /dev/null +++ b/SushiBarDataModels/Models/IDishModel.cs @@ -0,0 +1,13 @@ +namespace SushiBarDataModels.Models +{ + public interface IDishModel : IId + { + string DishName { get; } + + string Category { get; } + + double Price { get; } + + Dictionary DishIngredients { get; } + } +} diff --git a/SushiBarDataModels/Models/IIngredient.cs b/SushiBarDataModels/Models/IIngredientModel.cs similarity index 77% rename from SushiBarDataModels/Models/IIngredient.cs rename to SushiBarDataModels/Models/IIngredientModel.cs index fae8847..633497d 100644 --- a/SushiBarDataModels/Models/IIngredient.cs +++ b/SushiBarDataModels/Models/IIngredientModel.cs @@ -1,6 +1,6 @@ namespace SushiBarDataModels.Models { - public interface IIngredient : IId + public interface IIngredientModel : IId { string IngredientName { get; } diff --git a/SushiBarDatabaseImplement/Migrations/20240515171525_Initial.Designer.cs b/SushiBarDatabaseImplement/Migrations/20240523183058_Fix DishIngredients.Designer.cs similarity index 97% rename from SushiBarDatabaseImplement/Migrations/20240515171525_Initial.Designer.cs rename to SushiBarDatabaseImplement/Migrations/20240523183058_Fix DishIngredients.Designer.cs index 2558210..d71574f 100644 --- a/SushiBarDatabaseImplement/Migrations/20240515171525_Initial.Designer.cs +++ b/SushiBarDatabaseImplement/Migrations/20240523183058_Fix DishIngredients.Designer.cs @@ -12,8 +12,8 @@ using SushiBarDatabaseImplement; namespace SushiBarDatabaseImplement.Migrations { [DbContext(typeof(SushiBarDatabase))] - [Migration("20240515171525_Initial")] - partial class Initial + [Migration("20240523183058_Fix DishIngredients")] + partial class FixDishIngredients { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -144,6 +144,9 @@ namespace SushiBarDatabaseImplement.Migrations .IsRequired() .HasColumnType("text"); + b.Property("Price") + .HasColumnType("double precision"); + b.HasKey("Id"); b.ToTable("Dishes"); @@ -267,7 +270,7 @@ namespace SushiBarDatabaseImplement.Migrations modelBuilder.Entity("SushiBarDatabaseImplement.Models.DishIngredient", b => { b.HasOne("SushiBarDatabaseImplement.Models.Dish", "Dish") - .WithMany("DishIngredients") + .WithMany("Ingredients") .HasForeignKey("DishId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -302,7 +305,7 @@ namespace SushiBarDatabaseImplement.Migrations { b.Navigation("ChequeItems"); - b.Navigation("DishIngredients"); + b.Navigation("Ingredients"); }); modelBuilder.Entity("SushiBarDatabaseImplement.Models.Ingredient", b => diff --git a/SushiBarDatabaseImplement/Migrations/20240515171525_Initial.cs b/SushiBarDatabaseImplement/Migrations/20240523183058_Fix DishIngredients.cs similarity index 98% rename from SushiBarDatabaseImplement/Migrations/20240515171525_Initial.cs rename to SushiBarDatabaseImplement/Migrations/20240523183058_Fix DishIngredients.cs index 56be936..d3ebcba 100644 --- a/SushiBarDatabaseImplement/Migrations/20240515171525_Initial.cs +++ b/SushiBarDatabaseImplement/Migrations/20240523183058_Fix DishIngredients.cs @@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace SushiBarDatabaseImplement.Migrations { /// - public partial class Initial : Migration + public partial class FixDishIngredients : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -48,7 +48,8 @@ namespace SushiBarDatabaseImplement.Migrations Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), DishName = table.Column(type: "text", nullable: false), - Category = table.Column(type: "text", nullable: false) + Category = table.Column(type: "text", nullable: false), + Price = table.Column(type: "double precision", nullable: false) }, constraints: table => { diff --git a/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs b/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs index 6f76b71..33d8604 100644 --- a/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs +++ b/SushiBarDatabaseImplement/Migrations/SushiBarDatabaseModelSnapshot.cs @@ -141,6 +141,9 @@ namespace SushiBarDatabaseImplement.Migrations .IsRequired() .HasColumnType("text"); + b.Property("Price") + .HasColumnType("double precision"); + b.HasKey("Id"); b.ToTable("Dishes"); @@ -264,7 +267,7 @@ namespace SushiBarDatabaseImplement.Migrations modelBuilder.Entity("SushiBarDatabaseImplement.Models.DishIngredient", b => { b.HasOne("SushiBarDatabaseImplement.Models.Dish", "Dish") - .WithMany("DishIngredients") + .WithMany("Ingredients") .HasForeignKey("DishId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); @@ -299,7 +302,7 @@ namespace SushiBarDatabaseImplement.Migrations { b.Navigation("ChequeItems"); - b.Navigation("DishIngredients"); + b.Navigation("Ingredients"); }); modelBuilder.Entity("SushiBarDatabaseImplement.Models.Ingredient", b => diff --git a/SushiBarDatabaseImplement/Models/Dish.cs b/SushiBarDatabaseImplement/Models/Dish.cs index a75a85b..2b3d9bb 100644 --- a/SushiBarDatabaseImplement/Models/Dish.cs +++ b/SushiBarDatabaseImplement/Models/Dish.cs @@ -1,11 +1,12 @@ using SushiBarContracts.BindingModels; using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace SushiBarDatabaseImplement.Models { - public class Dish + public class Dish : IDishModel { [Key] public int Id { get; set; } @@ -16,22 +17,44 @@ namespace SushiBarDatabaseImplement.Models [Required] public string Category { get; set; } = string.Empty; + [Required] + public double Price { get; set; } + [ForeignKey("DishId")] - public virtual List DishIngredients { get; set; } = new(); + public virtual List Ingredients { get; set; } = new(); [ForeignKey("DishId")] public virtual List ChequeItems { get; set; } = new(); + private Dictionary? _dishIngredients = null; + + [NotMapped] + public Dictionary DishIngredients + { + get + { + if (_dishIngredients == null) + { + _dishIngredients = Ingredients.ToDictionary(DishIngredient => DishIngredient.IngredientId, DishIngredient => + (DishIngredient.Ingredient as IIngredientModel, DishIngredient.Count)); + } + + return _dishIngredients; + } + } + public static Dish Create(SushiBarDatabase Context, DishBindingModel Model) { return new Dish() { + Id = Model.Id, DishName = Model.DishName, Category = Model.Category, - DishIngredients = Model.Ingredients.Select(x => new DishIngredient + Price = Model.Price, + Ingredients = Model.DishIngredients.Select(x => new DishIngredient { - Ingredient = Context.Ingredients.First(y => y.Id == x.IngredientId), - Count = x.Count, + Ingredient = Context.Ingredients.First(y => y.Id == x.Key), + Count = x.Value.Item2, }).ToList() }; } @@ -40,22 +63,55 @@ namespace SushiBarDatabaseImplement.Models { DishName = Model.DishName; Category = Model.Category; + Price = Model.Price; } public DishViewModel ViewModel => new() { Id = Id, DishName = DishName, + Price = Price, Category = Category, - Ingredients = DishIngredients.ToDictionary(x => x.IngredientId, x => new DishIngredientViewModel - { - DishId = x.DishId, - IngredientId = x.IngredientId, - IngredientName = x.Ingredient.IngredientName, - Count = x.Count, - }) + DishIngredients = DishIngredients, }; + public void UpdateIngredients(SushiBarDatabase Context, DishBindingModel Model) + { + var IngredientsForThisDish = Context.DishIngredients.Where(x => x.DishId == Model.Id).ToList(); + + if (IngredientsForThisDish.Count > 0) + { + // Delete DishIngredient records for selected dish if there is no record with such ingredient in passed model + Context.DishIngredients.RemoveRange(IngredientsForThisDish.Where(x => !Model.DishIngredients.ContainsKey(x.IngredientId))); + Context.SaveChanges(); + + foreach (var DishIngredientToUpdate in IngredientsForThisDish) + { + DishIngredientToUpdate.Count = Model.DishIngredients[DishIngredientToUpdate.IngredientId].Item2; + Model.DishIngredients.Remove(DishIngredientToUpdate.IngredientId); + } + + Context.SaveChanges(); + } + + var Dish = Context.Dishes.First(x => x.Id == Id); + + foreach (var DishIngredient in Model.DishIngredients) + { + Context.DishIngredients.Add(new DishIngredient + { + Dish = Dish, + Ingredient = Context.Ingredients.First(x => x.Id == DishIngredient.Key), + Count = DishIngredient.Value.Item2 + }); + + Context.SaveChanges(); + } + + _dishIngredients = null; + } + + /* public void UpdateIngredients(SushiBarDatabase Context, DishBindingModel Model) { var IngredientsForThisDish = Context.DishIngredients.Where(x => x.DishId == Model.Id).ToList(); @@ -90,5 +146,6 @@ namespace SushiBarDatabaseImplement.Models Context.SaveChanges(); } } + */ } } diff --git a/SushiBarDatabaseImplement/Models/Ingredient.cs b/SushiBarDatabaseImplement/Models/Ingredient.cs index cf3cdb9..84a71ce 100644 --- a/SushiBarDatabaseImplement/Models/Ingredient.cs +++ b/SushiBarDatabaseImplement/Models/Ingredient.cs @@ -1,11 +1,12 @@ using SushiBarContracts.BindingModels; using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace SushiBarDatabaseImplement.Models { - public class Ingredient + public class Ingredient : IIngredientModel { [Key] public int Id { get; set; } diff --git a/SushiBarDatabaseImplement/Storages/ChequeStorage.cs b/SushiBarDatabaseImplement/Storages/ChequeStorage.cs index 98e980a..94f20fe 100644 --- a/SushiBarDatabaseImplement/Storages/ChequeStorage.cs +++ b/SushiBarDatabaseImplement/Storages/ChequeStorage.cs @@ -16,6 +16,9 @@ namespace SushiBarDatabaseImplement.Storages .Include(x => x.Customer) .Include(x => x.Promotion) .Include(x => x.ChequeItems) + .ThenInclude(x => x.Dish) + .Include(x => x.ChequeItems) + .ThenInclude(x => x.Cook) .Select(x => x.ViewModel) .ToList(); } @@ -30,6 +33,9 @@ namespace SushiBarDatabaseImplement.Storages .Include(x => x.Customer) .Include(x => x.Promotion) .Include(x => x.ChequeItems) + .ThenInclude(x => x.Dish) + .Include(x => x.ChequeItems) + .ThenInclude(x => x.Cook) .Where(x => x.CustomerId == Model.CustomerId) .Select(x => x.ViewModel) .ToList(); @@ -41,6 +47,9 @@ namespace SushiBarDatabaseImplement.Storages .Include(x => x.Customer) .Include(x => x.Promotion) .Include(x => x.ChequeItems) + .ThenInclude(x => x.Dish) + .Include(x => x.ChequeItems) + .ThenInclude(x => x.Cook) .Where(x => x.OrderDate >= Model.OrderDateFrom && x.OrderDate <= Model.OrderDateTo) .Select(x => x.ViewModel) .ToList(); @@ -59,6 +68,9 @@ namespace SushiBarDatabaseImplement.Storages .Include(x => x.Customer) .Include(x => x.Promotion) .Include(x => x.ChequeItems) + .ThenInclude(x => x.Dish) + .Include(x => x.ChequeItems) + .ThenInclude(x => x.Cook) .FirstOrDefault(x => x.Id == Model.Id)?.ViewModel; } @@ -72,6 +84,7 @@ namespace SushiBarDatabaseImplement.Storages Context.Cheques.Add(NewCheque); Context.SaveChanges(); + NewCheque.UpdateChequeItems(Context, Model); return NewCheque.ViewModel; } diff --git a/SushiBarDatabaseImplement/Storages/DishStorage.cs b/SushiBarDatabaseImplement/Storages/DishStorage.cs index 788e8d9..b351802 100644 --- a/SushiBarDatabaseImplement/Storages/DishStorage.cs +++ b/SushiBarDatabaseImplement/Storages/DishStorage.cs @@ -13,7 +13,8 @@ namespace SushiBarDatabaseImplement.Storages using var Context = new SushiBarDatabase(); return Context.Dishes - .Include(x => x.DishIngredients) + .Include(x => x.Ingredients) + .ThenInclude(x => x.Ingredient) .Select(x => x.ViewModel) .ToList(); } @@ -25,7 +26,8 @@ namespace SushiBarDatabaseImplement.Storages using var Context = new SushiBarDatabase(); return Context.Dishes - .Include(x => x.DishIngredients) + .Include(x => x.Ingredients) + .ThenInclude(x => x.Ingredient) .Where(x => x.DishName.Contains(Model.DishName)) .Select(x => x.ViewModel) .ToList(); @@ -38,7 +40,8 @@ namespace SushiBarDatabaseImplement.Storages using var Context = new SushiBarDatabase(); return Context.Dishes - .Include(x => x.DishIngredients) + .Include(x => x.Ingredients) + .ThenInclude(x => x.Ingredient) .FirstOrDefault(x => x.Id == Model.Id)?.ViewModel; } @@ -86,7 +89,6 @@ namespace SushiBarDatabaseImplement.Storages { using var Context = new SushiBarDatabase(); var Dish = Context.Dishes - .Include(x => x.DishIngredients) .FirstOrDefault(rec => rec.Id == Model.Id); if (Dish == null) diff --git a/SushiBarDatabaseImplement/SushiBarDatabase.cs b/SushiBarDatabaseImplement/SushiBarDatabase.cs index 5f89973..b4e4f5c 100644 --- a/SushiBarDatabaseImplement/SushiBarDatabase.cs +++ b/SushiBarDatabaseImplement/SushiBarDatabase.cs @@ -9,7 +9,8 @@ namespace SushiBarDatabaseImplement { if (OptionsBuilder.IsConfigured == false) { - OptionsBuilder.UseNpgsql(@"Host=192.168.56.101;Port=5436;Database=postgres;Username=postgres;Password=admin"); + //OptionsBuilder.UseNpgsql(@"Host=192.168.56.101;Port=5436;Database=postgres;Username=postgres;Password=admin"); + OptionsBuilder.UseNpgsql(@"Host=localhost;Port=5000;Database=SushiBarTest;Username=postgres;Password=admin"); } base.OnConfiguring(OptionsBuilder); diff --git a/SushiBarView/Form1.Designer.cs b/SushiBarView/Form1.Designer.cs deleted file mode 100644 index 0c36341..0000000 --- a/SushiBarView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace SushiBar -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} diff --git a/SushiBarView/Form1.cs b/SushiBarView/Form1.cs deleted file mode 100644 index 56e1d8c..0000000 --- a/SushiBarView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace SushiBar -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/SushiBarView/Forms/FormCook.Designer.cs b/SushiBarView/Forms/FormCook.Designer.cs new file mode 100644 index 0000000..bb83d2c --- /dev/null +++ b/SushiBarView/Forms/FormCook.Designer.cs @@ -0,0 +1,105 @@ +namespace SushiBarView.Forms +{ + partial class FormCook + { + /// + /// 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() + { + label1 = new Label(); + FioTextBox = new TextBox(); + label2 = new Label(); + EmploymentDateTimePicker = new DateTimePicker(); + button1 = new Button(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(11, 15); + label1.Name = "label1"; + label1.Size = new Size(34, 15); + label1.TabIndex = 0; + label1.Text = "ФИО"; + // + // FioTextBox + // + FioTextBox.Location = new Point(144, 12); + FioTextBox.Name = "FioTextBox"; + FioTextBox.Size = new Size(200, 23); + FioTextBox.TabIndex = 1; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(11, 47); + label2.Name = "label2"; + label2.Size = new Size(127, 15); + label2.TabIndex = 2; + label2.Text = "Дата трудоустройства"; + // + // EmploymentDateTimePicker + // + EmploymentDateTimePicker.Location = new Point(144, 41); + EmploymentDateTimePicker.Name = "EmploymentDateTimePicker"; + EmploymentDateTimePicker.Size = new Size(200, 23); + EmploymentDateTimePicker.TabIndex = 3; + // + // button1 + // + button1.Location = new Point(255, 86); + button1.Name = "button1"; + button1.Size = new Size(89, 28); + button1.TabIndex = 4; + button1.Text = "Сохранить"; + button1.UseVisualStyleBackColor = true; + button1.Click += ButtonSave_Click; + // + // FormCook + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(358, 123); + Controls.Add(button1); + Controls.Add(EmploymentDateTimePicker); + Controls.Add(label2); + Controls.Add(FioTextBox); + Controls.Add(label1); + Name = "FormCook"; + Text = "Повар"; + Load += FormCook_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private TextBox FioTextBox; + private Label label2; + private DateTimePicker EmploymentDateTimePicker; + private Button button1; + } +} \ No newline at end of file diff --git a/SushiBarView/Forms/FormCook.cs b/SushiBarView/Forms/FormCook.cs new file mode 100644 index 0000000..6599882 --- /dev/null +++ b/SushiBarView/Forms/FormCook.cs @@ -0,0 +1,78 @@ +using SushiBarBusinessLogic; +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; + +namespace SushiBarView.Forms +{ + public partial class FormCook : Form + { + private readonly CookLogic _logic; + + private int? _id; + public int Id { set { _id = value; } } + + public FormCook(CookLogic Logic) + { + InitializeComponent(); + _logic = Logic; + } + + private void FormCook_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + var View = _logic.ReadElement(new CookSearchModel + { + Id = _id.Value + }); + + if (View != null) + { + FioTextBox.Text = View.Fio; + EmploymentDateTimePicker.Value = View.EmploymentDate; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(FioTextBox.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + try + { + var Model = new CookBindingModel + { + Id = _id ?? 0, + Fio = FioTextBox.Text, + EmploymentDate = EmploymentDateTimePicker.Value, + }; + + var OperationResult = _id.HasValue ? _logic.Update(Model) : _logic.Create(Model); + + if (!OperationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка сохранения повара", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/SushiBarView/Forms/FormCook.resx b/SushiBarView/Forms/FormCook.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SushiBarView/Forms/FormCook.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/SushiBarView/Forms/FormCooks.Designer.cs b/SushiBarView/Forms/FormCooks.Designer.cs new file mode 100644 index 0000000..a71d257 --- /dev/null +++ b/SushiBarView/Forms/FormCooks.Designer.cs @@ -0,0 +1,113 @@ +namespace SushiBarView.Forms +{ + partial class FormCooks + { + /// + /// 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(); + AddButton = new Button(); + ChangeButton = new Button(); + DeleteButton = new Button(); + UpdateButton = new Button(); + ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + SuspendLayout(); + // + // DataGridView + // + DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + DataGridView.Location = new Point(12, 12); + DataGridView.Name = "DataGridView"; + DataGridView.RowTemplate.Height = 25; + DataGridView.Size = new Size(413, 358); + DataGridView.TabIndex = 0; + // + // AddButton + // + AddButton.Location = new Point(431, 12); + AddButton.Name = "AddButton"; + AddButton.Size = new Size(138, 29); + AddButton.TabIndex = 1; + AddButton.Text = "Добавить"; + AddButton.UseVisualStyleBackColor = true; + AddButton.Click += AddButton_Click; + // + // ChangeButton + // + ChangeButton.Location = new Point(431, 47); + ChangeButton.Name = "ChangeButton"; + ChangeButton.Size = new Size(138, 29); + ChangeButton.TabIndex = 2; + ChangeButton.Text = "Изменить"; + ChangeButton.UseVisualStyleBackColor = true; + ChangeButton.Click += ChangeButton_Click; + // + // DeleteButton + // + DeleteButton.Location = new Point(431, 82); + DeleteButton.Name = "DeleteButton"; + DeleteButton.Size = new Size(138, 29); + DeleteButton.TabIndex = 3; + DeleteButton.Text = "Удалить"; + DeleteButton.UseVisualStyleBackColor = true; + DeleteButton.Click += DeleteButton_Click; + // + // UpdateButton + // + UpdateButton.Location = new Point(431, 117); + UpdateButton.Name = "UpdateButton"; + UpdateButton.Size = new Size(138, 29); + UpdateButton.TabIndex = 4; + UpdateButton.Text = "Обновить"; + UpdateButton.UseVisualStyleBackColor = true; + UpdateButton.Click += RefreshButton_Click; + // + // FormCooks + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(580, 384); + Controls.Add(UpdateButton); + Controls.Add(DeleteButton); + Controls.Add(ChangeButton); + Controls.Add(AddButton); + Controls.Add(DataGridView); + Name = "FormCooks"; + Text = "Повара"; + Load += FormCooks_Load; + ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView DataGridView; + private Button AddButton; + private Button ChangeButton; + private Button DeleteButton; + private Button UpdateButton; + } +} \ No newline at end of file diff --git a/SushiBarView/Forms/FormCooks.cs b/SushiBarView/Forms/FormCooks.cs new file mode 100644 index 0000000..dfb55e4 --- /dev/null +++ b/SushiBarView/Forms/FormCooks.cs @@ -0,0 +1,98 @@ +using SushiBarBusinessLogic; +using SushiBarContracts.BindingModels; + +namespace SushiBarView.Forms +{ + public partial class FormCooks : Form + { + private readonly CookLogic _logic; + + public FormCooks(CookLogic Logic) + { + InitializeComponent(); + _logic = Logic; + } + + private void FormCooks_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["Fio"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["EmploymentDate"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AddButton_Click(object sender, EventArgs e) + { + FormCook Form = new FormCook(new CookLogic(new SushiBarDatabaseImplement.Storages.CookStorage())); + + if (Form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + + private void ChangeButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + FormCook Form = new FormCook(new CookLogic(new SushiBarDatabaseImplement.Storages.CookStorage())); + Form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + + if (Form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void DeleteButton_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 CookBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void RefreshButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/SushiBarView/Form1.resx b/SushiBarView/Forms/FormCooks.resx similarity index 100% rename from SushiBarView/Form1.resx rename to SushiBarView/Forms/FormCooks.resx diff --git a/SushiBarView/Forms/FormCreateCheque.Designer.cs b/SushiBarView/Forms/FormCreateCheque.Designer.cs new file mode 100644 index 0000000..140be86 --- /dev/null +++ b/SushiBarView/Forms/FormCreateCheque.Designer.cs @@ -0,0 +1,199 @@ +namespace SushiBarView.Forms +{ + partial class FormCreateCheque + { + /// + /// 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() + { + NameLabel = new Label(); + PriceLabel = new Label(); + PriceTextBox = new TextBox(); + ComponentsGroupBox = new GroupBox(); + AddButton = new Button(); + DataGridView = new DataGridView(); + IdColumn = new DataGridViewTextBoxColumn(); + DishNameColumn = new DataGridViewTextBoxColumn(); + CountColumn = new DataGridViewTextBoxColumn(); + CookColumn = new DataGridViewTextBoxColumn(); + SaveButton = new Button(); + CancelButton = new Button(); + CustomerComboBox = new ComboBox(); + ComponentsGroupBox.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + SuspendLayout(); + // + // NameLabel + // + NameLabel.AutoSize = true; + NameLabel.Location = new Point(12, 9); + NameLabel.Name = "NameLabel"; + NameLabel.Size = new Size(75, 15); + NameLabel.TabIndex = 0; + NameLabel.Text = "Покупатель:"; + // + // PriceLabel + // + PriceLabel.AutoSize = true; + PriceLabel.Location = new Point(12, 38); + PriceLabel.Name = "PriceLabel"; + PriceLabel.Size = new Size(88, 15); + PriceLabel.TabIndex = 1; + PriceLabel.Text = "Общая сумма:"; + // + // PriceTextBox + // + PriceTextBox.Location = new Point(108, 35); + PriceTextBox.Name = "PriceTextBox"; + PriceTextBox.ReadOnly = true; + PriceTextBox.Size = new Size(100, 23); + PriceTextBox.TabIndex = 3; + // + // ComponentsGroupBox + // + ComponentsGroupBox.Controls.Add(AddButton); + ComponentsGroupBox.Controls.Add(DataGridView); + ComponentsGroupBox.Location = new Point(12, 64); + ComponentsGroupBox.Name = "ComponentsGroupBox"; + ComponentsGroupBox.Size = new Size(706, 318); + ComponentsGroupBox.TabIndex = 4; + ComponentsGroupBox.TabStop = false; + ComponentsGroupBox.Text = "Заказанные блюда"; + // + // AddButton + // + AddButton.Location = new Point(588, 22); + AddButton.Name = "AddButton"; + AddButton.Size = new Size(112, 29); + AddButton.TabIndex = 1; + AddButton.Text = "Добавить"; + AddButton.UseVisualStyleBackColor = true; + AddButton.Click += AddButton_Click; + // + // DataGridView + // + DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + DataGridView.Columns.AddRange(new DataGridViewColumn[] { IdColumn, DishNameColumn, CountColumn, CookColumn }); + DataGridView.Location = new Point(6, 22); + DataGridView.Name = "DataGridView"; + DataGridView.RowHeadersWidth = 51; + DataGridView.Size = new Size(567, 290); + DataGridView.TabIndex = 0; + // + // IdColumn + // + IdColumn.HeaderText = "Column1"; + IdColumn.MinimumWidth = 6; + IdColumn.Name = "IdColumn"; + IdColumn.Visible = false; + IdColumn.Width = 6; + // + // DishNameColumn + // + DishNameColumn.HeaderText = "Блюдо"; + DishNameColumn.MinimumWidth = 6; + DishNameColumn.Name = "DishNameColumn"; + DishNameColumn.Width = 175; + // + // CountColumn + // + CountColumn.HeaderText = "Количество"; + CountColumn.MinimumWidth = 6; + CountColumn.Name = "CountColumn"; + CountColumn.Width = 139; + // + // CookColumn + // + CookColumn.HeaderText = "Повар"; + CookColumn.Name = "CookColumn"; + CookColumn.ReadOnly = true; + CookColumn.Width = 200; + // + // SaveButton + // + SaveButton.Location = new Point(523, 404); + SaveButton.Name = "SaveButton"; + SaveButton.Size = new Size(96, 33); + SaveButton.TabIndex = 5; + SaveButton.Text = "Сохранить"; + SaveButton.UseVisualStyleBackColor = true; + SaveButton.Click += SaveButton_Click; + // + // CancelButton + // + CancelButton.Location = new Point(625, 404); + CancelButton.Name = "CancelButton"; + CancelButton.Size = new Size(87, 33); + CancelButton.TabIndex = 6; + CancelButton.Text = "Отмена"; + CancelButton.UseVisualStyleBackColor = true; + // + // CustomerComboBox + // + CustomerComboBox.DropDownStyle = ComboBoxStyle.DropDownList; + CustomerComboBox.FormattingEnabled = true; + CustomerComboBox.Location = new Point(108, 6); + CustomerComboBox.Name = "CustomerComboBox"; + CustomerComboBox.Size = new Size(225, 23); + CustomerComboBox.TabIndex = 9; + // + // FormCreateCheque + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(730, 449); + Controls.Add(CustomerComboBox); + Controls.Add(CancelButton); + Controls.Add(SaveButton); + Controls.Add(ComponentsGroupBox); + Controls.Add(PriceTextBox); + Controls.Add(PriceLabel); + Controls.Add(NameLabel); + Name = "FormCreateCheque"; + Text = "Чек"; + Load += FormCreateCheque_Load; + ComponentsGroupBox.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label NameLabel; + private Label PriceLabel; + private TextBox PriceTextBox; + private GroupBox ComponentsGroupBox; + private Button AddButton; + private DataGridView DataGridView; + private Button SaveButton; + private Button CancelButton; + private ComboBox CustomerComboBox; + private DataGridViewTextBoxColumn IdColumn; + private DataGridViewTextBoxColumn DishNameColumn; + private DataGridViewTextBoxColumn CountColumn; + private DataGridViewTextBoxColumn CookColumn; + } +} \ No newline at end of file diff --git a/SushiBarView/Forms/FormCreateCheque.cs b/SushiBarView/Forms/FormCreateCheque.cs new file mode 100644 index 0000000..44bf707 --- /dev/null +++ b/SushiBarView/Forms/FormCreateCheque.cs @@ -0,0 +1,165 @@ +using SushiBarBusinessLogic; +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; + +namespace SushiBarView.Forms +{ + public partial class FormCreateCheque : Form + { + private readonly ChequeLogic _chequeLogic; + private readonly CustomerLogic _customerLogic; + + private List ChequeItems; + + private int? _id; + public int Id { set { _id = value; } } + + public FormCreateCheque(ChequeLogic ChequeLogic, CustomerLogic customerLogic) + { + InitializeComponent(); + + _chequeLogic = ChequeLogic; + _customerLogic = customerLogic; + + ChequeItems = new(); + } + + private void FormCreateCheque_Load(object sender, EventArgs e) + { + var List = _customerLogic.ReadList(null); + if (List != null) + { + CustomerComboBox.DisplayMember = "Fio"; + CustomerComboBox.ValueMember = "Id"; + CustomerComboBox.DataSource = List; + CustomerComboBox.SelectedItem = null; + } + + if (_id.HasValue) + { + try + { + var View = _chequeLogic.ReadElement(new ChequeSearchModel + { + Id = _id.Value + }); + + if (View != null) + { + CustomerComboBox.SelectedItem = View.CustomerId; + ChequeItems = View.ChequeItems.Select(x => x.Value).ToList(); + + CustomerComboBox.Enabled = false; + AddButton.Enabled = false; + SaveButton.Enabled = false; + + LoadData(); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + try + { + DataGridView.Rows.Clear(); + foreach (var ChequeItem in ChequeItems) + { + DataGridView.Rows.Add(new object[] { ChequeItem.DishId, ChequeItem.DishName, ChequeItem.Count, ChequeItem.CookFio }); + } + + PriceTextBox.Text = CalcPrice().ToString(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AddButton_Click(object sender, EventArgs e) + { + var Form = new FormCreateChequeItem( + new DishLogic(new SushiBarDatabaseImplement.Storages.DishStorage()), + new CookLogic(new SushiBarDatabaseImplement.Storages.CookStorage())); + + if (Form.ShowDialog() == DialogResult.OK) + { + if (Form.DishModel == null || Form.CookModel == null) + { + return; + } + + ChequeItems.Add(new ChequeItemViewModel + { + DishId = Form.DishId, + DishName = Form.DishModel.DishName, + DishPrice = Form.DishModel.Price, + CookId = Form.CookId, + CookFio = Form.CookModel.Fio, + Count = Form.Count, + }); + LoadData(); + } + } + + private void SaveButton_Click(object sender, EventArgs e) + { + try + { + var Мodel = new ChequeBindingModel + { + Id = 0, + ChequeItems = ChequeItems.Select(x => new ChequeItemBindingModel + { + DishId = x.DishId, + CookId = x.CookId, + Count = x.Count, + }).ToList(), + CustomerId = null, + OrderDate = DateTime.Now, + TotalSum = CalcPrice(), + PromotionId = null, + }; + + var OperationResult = _chequeLogic.CreateCheque(Мodel); + + if (!OperationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private double CalcPrice() + { + double Price = 0; + + foreach (var Elem in ChequeItems) + { + Price += Elem.DishPrice * Elem.Count; + } + + return Math.Round(Price * 1.1, 2); + } + } +} diff --git a/SushiBarView/Forms/FormCreateCheque.resx b/SushiBarView/Forms/FormCreateCheque.resx new file mode 100644 index 0000000..b74c85d --- /dev/null +++ b/SushiBarView/Forms/FormCreateCheque.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + \ No newline at end of file diff --git a/SushiBarView/Forms/FormCreateChequeItem.Designer.cs b/SushiBarView/Forms/FormCreateChequeItem.Designer.cs new file mode 100644 index 0000000..de6ddde --- /dev/null +++ b/SushiBarView/Forms/FormCreateChequeItem.Designer.cs @@ -0,0 +1,143 @@ +namespace SushiBarView.Forms +{ + partial class FormCreateChequeItem + { + /// + /// 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() + { + label1 = new Label(); + DishComboBox = new ComboBox(); + label2 = new Label(); + CookComboBox = new ComboBox(); + label3 = new Label(); + CountTextBox = new TextBox(); + CancelButton = new Button(); + SaveButton = new Button(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 15); + label1.Name = "label1"; + label1.Size = new Size(47, 15); + label1.TabIndex = 0; + label1.Text = "Блюдо:"; + // + // DishComboBox + // + DishComboBox.DropDownStyle = ComboBoxStyle.DropDownList; + DishComboBox.FormattingEnabled = true; + DishComboBox.Location = new Point(93, 12); + DishComboBox.Name = "DishComboBox"; + DishComboBox.Size = new Size(232, 23); + DishComboBox.TabIndex = 1; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(12, 44); + label2.Name = "label2"; + label2.Size = new Size(45, 15); + label2.TabIndex = 2; + label2.Text = "Повар:"; + // + // CookComboBox + // + CookComboBox.DropDownStyle = ComboBoxStyle.DropDownList; + CookComboBox.FormattingEnabled = true; + CookComboBox.Location = new Point(93, 41); + CookComboBox.Name = "CookComboBox"; + CookComboBox.Size = new Size(232, 23); + CookComboBox.TabIndex = 3; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(12, 73); + label3.Name = "label3"; + label3.Size = new Size(75, 15); + label3.TabIndex = 4; + label3.Text = "Количество:"; + // + // CountTextBox + // + CountTextBox.Location = new Point(93, 70); + CountTextBox.Name = "CountTextBox"; + CountTextBox.Size = new Size(232, 23); + CountTextBox.TabIndex = 5; + // + // CancelButton + // + CancelButton.Location = new Point(250, 109); + CancelButton.Name = "CancelButton"; + CancelButton.Size = new Size(75, 23); + CancelButton.TabIndex = 8; + CancelButton.Text = "Отмена"; + CancelButton.UseVisualStyleBackColor = true; + CancelButton.Click += CancelButton_Click; + // + // SaveButton + // + SaveButton.Location = new Point(163, 109); + SaveButton.Name = "SaveButton"; + SaveButton.Size = new Size(81, 23); + SaveButton.TabIndex = 9; + SaveButton.Text = "Сохранить"; + SaveButton.UseVisualStyleBackColor = true; + SaveButton.Click += SaveButton_Click; + // + // FormCreateChequeItem + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(347, 146); + Controls.Add(SaveButton); + Controls.Add(CancelButton); + Controls.Add(CountTextBox); + Controls.Add(label3); + Controls.Add(CookComboBox); + Controls.Add(label2); + Controls.Add(DishComboBox); + Controls.Add(label1); + Name = "FormCreateChequeItem"; + Text = "Элемент чека"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private ComboBox DishComboBox; + private Label label2; + private ComboBox CookComboBox; + private Label label3; + private TextBox CountTextBox; + private Button CancelButton; + private Button SaveButton; + } +} \ No newline at end of file diff --git a/SushiBarView/Forms/FormCreateChequeItem.cs b/SushiBarView/Forms/FormCreateChequeItem.cs new file mode 100644 index 0000000..a881e15 --- /dev/null +++ b/SushiBarView/Forms/FormCreateChequeItem.cs @@ -0,0 +1,136 @@ +using SushiBarBusinessLogic; +using SushiBarContracts.ViewModels; + +namespace SushiBarView.Forms +{ + public partial class FormCreateChequeItem : Form + { + private readonly List? _dishes; + private readonly List? _cooks; + + public int DishId + { + get + { + return Convert.ToInt32(DishComboBox.SelectedValue); + } + set + { + DishComboBox.SelectedValue = value; + } + } + + public int CookId + { + get + { + return Convert.ToInt32(CookComboBox.SelectedValue); + } + set + { + CookComboBox.SelectedValue = value; + } + } + + public DishViewModel? DishModel + { + get + { + if (_dishes == null) + { + return null; + } + + foreach (var Elem in _dishes) + { + if (Elem.Id == DishId) + { + return Elem; + } + } + + return null; + } + } + + public CookViewModel? CookModel + { + get + { + if (_cooks == null) + { + return null; + } + + foreach (var Elem in _cooks) + { + if (Elem.Id == CookId) + { + return Elem; + } + } + + return null; + } + } + + public int Count + { + get { return Convert.ToInt32(CountTextBox.Text); } + set { CountTextBox.Text = value.ToString(); } + } + + public FormCreateChequeItem(DishLogic DishLogic, CookLogic CookLogic) + { + InitializeComponent(); + + _dishes = DishLogic.ReadList(null); + if (_dishes != null) + { + DishComboBox.DisplayMember = "DishName"; + DishComboBox.ValueMember = "Id"; + DishComboBox.DataSource = _dishes; + DishComboBox.SelectedItem = null; + } + + _cooks = CookLogic.ReadList(null); + if (_cooks != null) + { + CookComboBox.DisplayMember = "Fio"; + CookComboBox.ValueMember = "Id"; + CookComboBox.DataSource = _cooks; + CookComboBox.SelectedItem = null; + } + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(CountTextBox.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (DishComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите блюдо", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (CookComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите повара", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + DialogResult = DialogResult.OK; + Close(); + } + + private void CancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SushiBarView/Forms/FormCreateChequeItem.resx b/SushiBarView/Forms/FormCreateChequeItem.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SushiBarView/Forms/FormCreateChequeItem.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/SushiBarView/Forms/FormCustomer.Designer.cs b/SushiBarView/Forms/FormCustomer.Designer.cs new file mode 100644 index 0000000..2119dbb --- /dev/null +++ b/SushiBarView/Forms/FormCustomer.Designer.cs @@ -0,0 +1,128 @@ +namespace SushiBarView.Forms +{ + partial class FormCustomer + { + /// + /// 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() + { + label1 = new Label(); + FioTextBox = new TextBox(); + label2 = new Label(); + EmploymentDateTimePicker = new DateTimePicker(); + button1 = new Button(); + label3 = new Label(); + SumOfAllOrdersTextBox = new TextBox(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(11, 15); + label1.Name = "label1"; + label1.Size = new Size(34, 15); + label1.TabIndex = 0; + label1.Text = "ФИО"; + // + // FioTextBox + // + FioTextBox.Location = new Point(119, 12); + FioTextBox.Name = "FioTextBox"; + FioTextBox.Size = new Size(225, 23); + FioTextBox.TabIndex = 1; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(11, 47); + label2.Name = "label2"; + label2.Size = new Size(90, 15); + label2.TabIndex = 2; + label2.Text = "Дата рождения"; + // + // EmploymentDateTimePicker + // + EmploymentDateTimePicker.Location = new Point(119, 41); + EmploymentDateTimePicker.Name = "EmploymentDateTimePicker"; + EmploymentDateTimePicker.Size = new Size(225, 23); + EmploymentDateTimePicker.TabIndex = 3; + // + // button1 + // + button1.Location = new Point(255, 117); + button1.Name = "button1"; + button1.Size = new Size(89, 28); + button1.TabIndex = 4; + button1.Text = "Сохранить"; + button1.UseVisualStyleBackColor = true; + button1.Click += ButtonSave_Click; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(11, 77); + label3.Name = "label3"; + label3.Size = new Size(89, 15); + label3.TabIndex = 5; + label3.Text = "Сумма заказов"; + // + // SumOfAllOrdersTextBox + // + SumOfAllOrdersTextBox.Location = new Point(119, 74); + SumOfAllOrdersTextBox.Name = "SumOfAllOrdersTextBox"; + SumOfAllOrdersTextBox.ReadOnly = true; + SumOfAllOrdersTextBox.Size = new Size(225, 23); + SumOfAllOrdersTextBox.TabIndex = 6; + // + // FormCustomer + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(358, 155); + Controls.Add(SumOfAllOrdersTextBox); + Controls.Add(label3); + Controls.Add(button1); + Controls.Add(EmploymentDateTimePicker); + Controls.Add(label2); + Controls.Add(FioTextBox); + Controls.Add(label1); + Name = "FormCustomer"; + Text = "Покупатель"; + Load += FormCustomer_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private TextBox FioTextBox; + private Label label2; + private DateTimePicker EmploymentDateTimePicker; + private Button button1; + private Label label3; + private TextBox SumOfAllOrdersTextBox; + } +} \ No newline at end of file diff --git a/SushiBarView/Forms/FormCustomer.cs b/SushiBarView/Forms/FormCustomer.cs new file mode 100644 index 0000000..cb26db6 --- /dev/null +++ b/SushiBarView/Forms/FormCustomer.cs @@ -0,0 +1,80 @@ +using SushiBarBusinessLogic; +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; + +namespace SushiBarView.Forms +{ + public partial class FormCustomer : Form + { + private readonly CustomerLogic _logic; + + private int? _id; + public int Id { set { _id = value; } } + + public FormCustomer(CustomerLogic Logic) + { + InitializeComponent(); + _logic = Logic; + } + + private void FormCustomer_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + var View = _logic.ReadElement(new CustomerSearchModel + { + Id = _id.Value + }); + + if (View != null) + { + FioTextBox.Text = View.Fio; + EmploymentDateTimePicker.Value = View.BirthdayDate ?? new DateTime(); + SumOfAllOrdersTextBox.Text = View.SumOfAllOrders.ToString(); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(FioTextBox.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + try + { + var Model = new CustomerBindingModel + { + Id = _id ?? 0, + Fio = FioTextBox.Text, + BirthdayDate = EmploymentDateTimePicker.Value, + SumOfAllOrders = 0, + }; + + var OperationResult = _id.HasValue ? _logic.Update(Model) : _logic.Create(Model); + + if (!OperationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка сохранения повара", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/SushiBarView/Forms/FormCustomer.resx b/SushiBarView/Forms/FormCustomer.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SushiBarView/Forms/FormCustomer.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/SushiBarView/Forms/FormCustomers.Designer.cs b/SushiBarView/Forms/FormCustomers.Designer.cs new file mode 100644 index 0000000..d9b4e67 --- /dev/null +++ b/SushiBarView/Forms/FormCustomers.Designer.cs @@ -0,0 +1,113 @@ +namespace SushiBarView.Forms +{ + partial class FormCustomers + { + /// + /// 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(); + AddButton = new Button(); + ChangeButton = new Button(); + DeleteButton = new Button(); + UpdateButton = new Button(); + ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + SuspendLayout(); + // + // DataGridView + // + DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + DataGridView.Location = new Point(12, 12); + DataGridView.Name = "DataGridView"; + DataGridView.RowTemplate.Height = 25; + DataGridView.Size = new Size(413, 358); + DataGridView.TabIndex = 0; + // + // AddButton + // + AddButton.Location = new Point(431, 12); + AddButton.Name = "AddButton"; + AddButton.Size = new Size(138, 29); + AddButton.TabIndex = 1; + AddButton.Text = "Добавить"; + AddButton.UseVisualStyleBackColor = true; + AddButton.Click += AddButton_Click; + // + // ChangeButton + // + ChangeButton.Location = new Point(431, 47); + ChangeButton.Name = "ChangeButton"; + ChangeButton.Size = new Size(138, 29); + ChangeButton.TabIndex = 2; + ChangeButton.Text = "Изменить"; + ChangeButton.UseVisualStyleBackColor = true; + ChangeButton.Click += ChangeButton_Click; + // + // DeleteButton + // + DeleteButton.Location = new Point(431, 82); + DeleteButton.Name = "DeleteButton"; + DeleteButton.Size = new Size(138, 29); + DeleteButton.TabIndex = 3; + DeleteButton.Text = "Удалить"; + DeleteButton.UseVisualStyleBackColor = true; + DeleteButton.Click += DeleteButton_Click; + // + // UpdateButton + // + UpdateButton.Location = new Point(431, 117); + UpdateButton.Name = "UpdateButton"; + UpdateButton.Size = new Size(138, 29); + UpdateButton.TabIndex = 4; + UpdateButton.Text = "Обновить"; + UpdateButton.UseVisualStyleBackColor = true; + UpdateButton.Click += RefreshButton_Click; + // + // FormCustomers + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(580, 384); + Controls.Add(UpdateButton); + Controls.Add(DeleteButton); + Controls.Add(ChangeButton); + Controls.Add(AddButton); + Controls.Add(DataGridView); + Name = "FormCustomers"; + Text = "Покупатели"; + Load += FormCustomers_Load; + ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView DataGridView; + private Button AddButton; + private Button ChangeButton; + private Button DeleteButton; + private Button UpdateButton; + } +} \ No newline at end of file diff --git a/SushiBarView/Forms/FormCustomers.cs b/SushiBarView/Forms/FormCustomers.cs new file mode 100644 index 0000000..9896d30 --- /dev/null +++ b/SushiBarView/Forms/FormCustomers.cs @@ -0,0 +1,98 @@ +using SushiBarBusinessLogic; +using SushiBarContracts.BindingModels; + +namespace SushiBarView.Forms +{ + public partial class FormCustomers : Form + { + private readonly CustomerLogic _logic; + + public FormCustomers(CustomerLogic Logic) + { + InitializeComponent(); + _logic = Logic; + } + + private void FormCustomers_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["Fio"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["BirthdayDate"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AddButton_Click(object sender, EventArgs e) + { + FormCustomer Form = new FormCustomer(new CustomerLogic(new SushiBarDatabaseImplement.Storages.CustomerStorage())); + + if (Form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + + private void ChangeButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + FormCustomer Form = new FormCustomer(new CustomerLogic(new SushiBarDatabaseImplement.Storages.CustomerStorage())); + Form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + + if (Form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void DeleteButton_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 CustomerBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void RefreshButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/SushiBarView/Forms/FormCustomers.resx b/SushiBarView/Forms/FormCustomers.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/SushiBarView/Forms/FormCustomers.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/SushiBarView/Forms/FormDish.Designer.cs b/SushiBarView/Forms/FormDish.Designer.cs new file mode 100644 index 0000000..2ec55e8 --- /dev/null +++ b/SushiBarView/Forms/FormDish.Designer.cs @@ -0,0 +1,249 @@ +namespace SushiBarView.Forms +{ + partial class FormDish + { + /// + /// 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() + { + NameLabel = new Label(); + PriceLabel = new Label(); + NameTextBox = new TextBox(); + PriceTextBox = new TextBox(); + ComponentsGroupBox = new GroupBox(); + RefreshButton = new Button(); + DeleteButton = new Button(); + UpdateButton = new Button(); + AddButton = new Button(); + DataGridView = new DataGridView(); + IdColumn = new DataGridViewTextBoxColumn(); + IngredientNameColumn = new DataGridViewTextBoxColumn(); + CountColumn = new DataGridViewTextBoxColumn(); + SaveButton = new Button(); + CancelButton = new Button(); + label1 = new Label(); + CategoryTextBox = new TextBox(); + ComponentsGroupBox.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + SuspendLayout(); + // + // NameLabel + // + NameLabel.AutoSize = true; + NameLabel.Location = new Point(12, 9); + NameLabel.Name = "NameLabel"; + NameLabel.Size = new Size(59, 15); + NameLabel.TabIndex = 0; + NameLabel.Text = "Название"; + // + // PriceLabel + // + PriceLabel.AutoSize = true; + PriceLabel.Location = new Point(12, 67); + PriceLabel.Name = "PriceLabel"; + PriceLabel.Size = new Size(35, 15); + PriceLabel.TabIndex = 1; + PriceLabel.Text = "Цена"; + // + // NameTextBox + // + NameTextBox.Location = new Point(81, 6); + NameTextBox.Name = "NameTextBox"; + NameTextBox.Size = new Size(237, 23); + NameTextBox.TabIndex = 2; + // + // PriceTextBox + // + PriceTextBox.Location = new Point(81, 64); + PriceTextBox.Name = "PriceTextBox"; + PriceTextBox.ReadOnly = true; + PriceTextBox.Size = new Size(100, 23); + PriceTextBox.TabIndex = 3; + // + // ComponentsGroupBox + // + ComponentsGroupBox.Controls.Add(RefreshButton); + ComponentsGroupBox.Controls.Add(DeleteButton); + ComponentsGroupBox.Controls.Add(UpdateButton); + ComponentsGroupBox.Controls.Add(AddButton); + ComponentsGroupBox.Controls.Add(DataGridView); + ComponentsGroupBox.Location = new Point(12, 95); + ComponentsGroupBox.Name = "ComponentsGroupBox"; + ComponentsGroupBox.Size = new Size(582, 287); + ComponentsGroupBox.TabIndex = 4; + ComponentsGroupBox.TabStop = false; + ComponentsGroupBox.Text = "Компоненты"; + // + // RefreshButton + // + RefreshButton.Location = new Point(464, 127); + RefreshButton.Name = "RefreshButton"; + RefreshButton.Size = new Size(112, 29); + RefreshButton.TabIndex = 4; + RefreshButton.Text = "Обновить"; + RefreshButton.UseVisualStyleBackColor = true; + RefreshButton.Click += RefreshButton_Click; + // + // DeleteButton + // + DeleteButton.Location = new Point(464, 92); + DeleteButton.Name = "DeleteButton"; + DeleteButton.Size = new Size(112, 29); + DeleteButton.TabIndex = 3; + DeleteButton.Text = "Удалить"; + DeleteButton.UseVisualStyleBackColor = true; + DeleteButton.Click += DeleteButton_Click; + // + // UpdateButton + // + UpdateButton.Location = new Point(464, 57); + UpdateButton.Name = "UpdateButton"; + UpdateButton.Size = new Size(112, 29); + UpdateButton.TabIndex = 2; + UpdateButton.Text = "Изменить"; + UpdateButton.UseVisualStyleBackColor = true; + UpdateButton.Click += UpdateButton_Click; + // + // AddButton + // + AddButton.Location = new Point(464, 22); + AddButton.Name = "AddButton"; + AddButton.Size = new Size(112, 29); + AddButton.TabIndex = 1; + AddButton.Text = "Добавить"; + AddButton.UseVisualStyleBackColor = true; + AddButton.Click += AddButton_Click; + // + // DataGridView + // + DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + DataGridView.Columns.AddRange(new DataGridViewColumn[] { IdColumn, IngredientNameColumn, CountColumn }); + DataGridView.Location = new Point(6, 22); + DataGridView.Name = "DataGridView"; + DataGridView.RowHeadersWidth = 51; + DataGridView.Size = new Size(442, 259); + DataGridView.TabIndex = 0; + // + // IdColumn + // + IdColumn.HeaderText = "Column1"; + IdColumn.MinimumWidth = 6; + IdColumn.Name = "IdColumn"; + IdColumn.Visible = false; + IdColumn.Width = 6; + // + // IngredientNameColumn + // + IngredientNameColumn.HeaderText = "Ингредиент"; + IngredientNameColumn.MinimumWidth = 6; + IngredientNameColumn.Name = "IngredientNameColumn"; + IngredientNameColumn.Width = 300; + // + // CountColumn + // + CountColumn.HeaderText = "Количество"; + CountColumn.MinimumWidth = 6; + CountColumn.Name = "CountColumn"; + CountColumn.Width = 125; + // + // SaveButton + // + SaveButton.Location = new Point(421, 404); + SaveButton.Name = "SaveButton"; + SaveButton.Size = new Size(92, 33); + SaveButton.TabIndex = 5; + SaveButton.Text = "Сохранить"; + SaveButton.UseVisualStyleBackColor = true; + SaveButton.Click += SaveButton_Click; + // + // CancelButton + // + CancelButton.Location = new Point(519, 404); + CancelButton.Name = "CancelButton"; + CancelButton.Size = new Size(75, 33); + CancelButton.TabIndex = 6; + CancelButton.Text = "Отмена"; + CancelButton.UseVisualStyleBackColor = true; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 38); + label1.Name = "label1"; + label1.Size = new Size(63, 15); + label1.TabIndex = 7; + label1.Text = "Категория"; + // + // CategoryTextBox + // + CategoryTextBox.Location = new Point(81, 35); + CategoryTextBox.Name = "CategoryTextBox"; + CategoryTextBox.Size = new Size(237, 23); + CategoryTextBox.TabIndex = 8; + // + // FormDish + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(606, 449); + Controls.Add(CategoryTextBox); + Controls.Add(label1); + Controls.Add(CancelButton); + Controls.Add(SaveButton); + Controls.Add(ComponentsGroupBox); + Controls.Add(PriceTextBox); + Controls.Add(NameTextBox); + Controls.Add(PriceLabel); + Controls.Add(NameLabel); + Name = "FormDish"; + Text = "Блюдо"; + Load += FormDish_Load; + ComponentsGroupBox.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label NameLabel; + private Label PriceLabel; + private TextBox NameTextBox; + private TextBox PriceTextBox; + private GroupBox ComponentsGroupBox; + private Button RefreshButton; + private Button DeleteButton; + private Button UpdateButton; + private Button AddButton; + private DataGridView DataGridView; + private DataGridViewTextBoxColumn IdColumn; + private DataGridViewTextBoxColumn IngredientNameColumn; + private DataGridViewTextBoxColumn CountColumn; + private Button SaveButton; + private Button CancelButton; + private Label label1; + private TextBox CategoryTextBox; + } +} \ No newline at end of file diff --git a/SushiBarView/Forms/FormDish.cs b/SushiBarView/Forms/FormDish.cs new file mode 100644 index 0000000..5d9b846 --- /dev/null +++ b/SushiBarView/Forms/FormDish.cs @@ -0,0 +1,205 @@ +using SushiBarBusinessLogic; +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarDataModels.Models; + +namespace SushiBarView.Forms +{ + public partial class FormDish : Form + { + private readonly DishLogic _dishLogic; + + private int? _id; + private Dictionary _dishIngredients; + + public int Id { set { _id = value; } } + + public FormDish(DishLogic DishLogic) + { + InitializeComponent(); + + _dishLogic = DishLogic; + _dishIngredients = new Dictionary(); + } + + private void FormDish_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + var View = _dishLogic.ReadElement(new DishSearchModel + { + Id = _id.Value + }); + + if (View != null) + { + NameTextBox.Text = View.DishName; + CategoryTextBox.Text = View.Category; + PriceTextBox.Text = View.Price.ToString(); + + _dishIngredients = View.DishIngredients ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + try + { + if (_dishIngredients != null) + { + DataGridView.Rows.Clear(); + foreach (var Ingredient in _dishIngredients) + { + DataGridView.Rows.Add(new object[] { Ingredient.Key, Ingredient.Value.Item1.IngredientName, Ingredient.Value.Item2 }); + } + + PriceTextBox.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AddButton_Click(object sender, EventArgs e) + { + var Form = new FormDishIngredient(new IngredientLogic(new SushiBarDatabaseImplement.Storages.IngredientStorage())); + if (Form.ShowDialog() == DialogResult.OK) + { + if (Form.IngredientModel == null) + { + return; + } + + if (_dishIngredients.ContainsKey(Form.Id)) + { + _dishIngredients[Form.Id] = (Form.IngredientModel, Form.Count); + } + else + { + _dishIngredients.Add(Form.Id, (Form.IngredientModel, Form.Count)); + } + + LoadData(); + } + } + + private void UpdateButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + var Form = new FormDishIngredient(new IngredientLogic(new SushiBarDatabaseImplement.Storages.IngredientStorage())); + int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value); + Form.Id = id; + Form.Count = _dishIngredients[id].Item2; + + if (Form.ShowDialog() == DialogResult.OK) + { + if (Form.IngredientModel == null) + { + return; + } + + _dishIngredients[Form.Id] = (Form.IngredientModel, Form.Count); + LoadData(); + } + } + } + + private void DeleteButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _dishIngredients?.Remove(Convert.ToInt32(DataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + LoadData(); + } + } + } + + private void RefreshButton_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void SaveButton_Click(object sender, EventArgs e) + { + + if (string.IsNullOrEmpty(NameTextBox.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (string.IsNullOrEmpty(PriceTextBox.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (_dishIngredients == null || _dishIngredients.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + try + { + var Мodel = new DishBindingModel + { + Id = _id ?? 0, + DishName = NameTextBox.Text, + Category = CategoryTextBox.Text, + Price = Convert.ToDouble(PriceTextBox.Text), + DishIngredients = _dishIngredients, + }; + + var OperationResult = _id.HasValue ? _dishLogic.Update(Мodel) : _dishLogic.Create(Мodel); + + if (!OperationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private double CalcPrice() + { + double Price = 0; + + foreach (var Elem in _dishIngredients) + { + Price += ((Elem.Value.Item1?.Cost ?? 0) * Elem.Value.Item2); + } + + return Math.Round(Price * 1.1, 2); + } + } +} diff --git a/SushiBarView/Forms/FormDish.resx b/SushiBarView/Forms/FormDish.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SushiBarView/Forms/FormDish.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/SushiBarView/Forms/FormDishIngredient.Designer.cs b/SushiBarView/Forms/FormDishIngredient.Designer.cs new file mode 100644 index 0000000..fc843b2 --- /dev/null +++ b/SushiBarView/Forms/FormDishIngredient.Designer.cs @@ -0,0 +1,119 @@ +namespace SushiBarView.Forms +{ + partial class FormDishIngredient + { + /// + /// 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() + { + ComponentLabel = new Label(); + CountLabel = new Label(); + CountTextBox = new TextBox(); + ComboBox = new ComboBox(); + SaveButton = new Button(); + CancelButton = new Button(); + SuspendLayout(); + // + // ComponentLabel + // + ComponentLabel.AutoSize = true; + ComponentLabel.Location = new Point(14, 15); + ComponentLabel.Name = "ComponentLabel"; + ComponentLabel.Size = new Size(75, 15); + ComponentLabel.TabIndex = 0; + ComponentLabel.Text = "Ингредиент:"; + // + // CountLabel + // + CountLabel.AutoSize = true; + CountLabel.Location = new Point(14, 46); + CountLabel.Name = "CountLabel"; + CountLabel.Size = new Size(75, 15); + CountLabel.TabIndex = 1; + CountLabel.Text = "Количество:"; + // + // CountTextBox + // + CountTextBox.Location = new Point(95, 43); + CountTextBox.Name = "CountTextBox"; + CountTextBox.Size = new Size(292, 23); + CountTextBox.TabIndex = 2; + // + // ComboBox + // + ComboBox.DropDownStyle = ComboBoxStyle.DropDownList; + ComboBox.FormattingEnabled = true; + ComboBox.Location = new Point(95, 12); + ComboBox.Name = "ComboBox"; + ComboBox.Size = new Size(292, 23); + ComboBox.TabIndex = 3; + // + // SaveButton + // + SaveButton.Location = new Point(205, 81); + SaveButton.Name = "SaveButton"; + SaveButton.Size = new Size(90, 32); + SaveButton.TabIndex = 4; + SaveButton.Text = "Сохранить"; + SaveButton.UseVisualStyleBackColor = true; + SaveButton.Click += ButtonSave_Click; + // + // CancelButton + // + CancelButton.Location = new Point(301, 81); + CancelButton.Name = "CancelButton"; + CancelButton.Size = new Size(86, 32); + CancelButton.TabIndex = 5; + CancelButton.Text = "Отмена"; + CancelButton.UseVisualStyleBackColor = true; + CancelButton.Click += ButtonCancel_Click; + // + // FormDishIngredient + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(407, 130); + Controls.Add(CancelButton); + Controls.Add(SaveButton); + Controls.Add(ComboBox); + Controls.Add(CountTextBox); + Controls.Add(CountLabel); + Controls.Add(ComponentLabel); + Name = "FormDishIngredient"; + Text = "Ингредиент блюда"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label ComponentLabel; + private Label CountLabel; + private TextBox CountTextBox; + private ComboBox ComboBox; + private Button SaveButton; + private Button CancelButton; + } +} \ No newline at end of file diff --git a/SushiBarView/Forms/FormDishIngredient.cs b/SushiBarView/Forms/FormDishIngredient.cs new file mode 100644 index 0000000..66c5cb0 --- /dev/null +++ b/SushiBarView/Forms/FormDishIngredient.cs @@ -0,0 +1,87 @@ +using SushiBarBusinessLogic; +using SushiBarContracts.ViewModels; + +namespace SushiBarView.Forms +{ + public partial class FormDishIngredient : Form + { + private readonly List? _list; + + public int Id + { + get + { + return Convert.ToInt32(ComboBox.SelectedValue); + } + set + { + ComboBox.SelectedValue = value; + } + } + + public IngredientViewModel? IngredientModel + { + get + { + if (_list == null) + { + return null; + } + + foreach (var Elem in _list) + { + if (Elem.Id == Id) + { + return Elem; + } + } + + return null; + } + } + + public int Count + { + get { return Convert.ToInt32(CountTextBox.Text); } + set { CountTextBox.Text = value.ToString(); } + } + + public FormDishIngredient(IngredientLogic Logic) + { + InitializeComponent(); + _list = Logic.ReadList(null); + + if (_list != null) + { + ComboBox.DisplayMember = "IngredientName"; + ComboBox.ValueMember = "Id"; + ComboBox.DataSource = _list; + ComboBox.SelectedItem = null; + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(CountTextBox.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (ComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите ингредиент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + DialogResult = DialogResult.OK; + Close(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SushiBarView/Forms/FormDishIngredient.resx b/SushiBarView/Forms/FormDishIngredient.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SushiBarView/Forms/FormDishIngredient.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/SushiBarView/Forms/FormDishes.Designer.cs b/SushiBarView/Forms/FormDishes.Designer.cs new file mode 100644 index 0000000..96b95d9 --- /dev/null +++ b/SushiBarView/Forms/FormDishes.Designer.cs @@ -0,0 +1,113 @@ +namespace SushiBarView.Forms +{ + partial class FormDishes + { + /// + /// 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(); + AddButton = new Button(); + ChangeButton = new Button(); + DeleteButton = new Button(); + UpdateButton = new Button(); + ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + SuspendLayout(); + // + // DataGridView + // + DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + DataGridView.Location = new Point(12, 12); + DataGridView.Name = "DataGridView"; + DataGridView.RowTemplate.Height = 25; + DataGridView.Size = new Size(413, 358); + DataGridView.TabIndex = 0; + // + // AddButton + // + AddButton.Location = new Point(431, 12); + AddButton.Name = "AddButton"; + AddButton.Size = new Size(138, 29); + AddButton.TabIndex = 1; + AddButton.Text = "Добавить"; + AddButton.UseVisualStyleBackColor = true; + AddButton.Click += AddButton_Click; + // + // ChangeButton + // + ChangeButton.Location = new Point(431, 47); + ChangeButton.Name = "ChangeButton"; + ChangeButton.Size = new Size(138, 29); + ChangeButton.TabIndex = 2; + ChangeButton.Text = "Изменить"; + ChangeButton.UseVisualStyleBackColor = true; + ChangeButton.Click += UpdateButton_Click; + // + // DeleteButton + // + DeleteButton.Location = new Point(431, 82); + DeleteButton.Name = "DeleteButton"; + DeleteButton.Size = new Size(138, 29); + DeleteButton.TabIndex = 3; + DeleteButton.Text = "Удалить"; + DeleteButton.UseVisualStyleBackColor = true; + DeleteButton.Click += DeleteButton_Click; + // + // UpdateButton + // + UpdateButton.Location = new Point(431, 117); + UpdateButton.Name = "UpdateButton"; + UpdateButton.Size = new Size(138, 29); + UpdateButton.TabIndex = 4; + UpdateButton.Text = "Обновить"; + UpdateButton.UseVisualStyleBackColor = true; + UpdateButton.Click += RefreshButton_Click; + // + // FormDishes + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(580, 384); + Controls.Add(UpdateButton); + Controls.Add(DeleteButton); + Controls.Add(ChangeButton); + Controls.Add(AddButton); + Controls.Add(DataGridView); + Name = "FormDishes"; + Text = "FormDishes"; + Load += FormDishes_Load; + ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView DataGridView; + private Button AddButton; + private Button ChangeButton; + private Button DeleteButton; + private Button UpdateButton; + } +} \ No newline at end of file diff --git a/SushiBarView/Forms/FormDishes.cs b/SushiBarView/Forms/FormDishes.cs new file mode 100644 index 0000000..9bf612b --- /dev/null +++ b/SushiBarView/Forms/FormDishes.cs @@ -0,0 +1,97 @@ +using SushiBarBusinessLogic; +using SushiBarContracts.BindingModels; + +namespace SushiBarView.Forms +{ + public partial class FormDishes : Form + { + private readonly DishLogic _logic; + + public FormDishes(DishLogic Logic) + { + InitializeComponent(); + _logic = Logic; + } + + private void FormDishes_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["DishName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["DishIngredients"].Visible = false; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AddButton_Click(object sender, EventArgs e) + { + FormDish Form = new FormDish(new DishLogic(new SushiBarDatabaseImplement.Storages.DishStorage())); + + if (Form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + + private void UpdateButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + FormDish Form = new FormDish(new DishLogic(new SushiBarDatabaseImplement.Storages.DishStorage())); + Form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + + if (Form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void DeleteButton_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 DishBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void RefreshButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/SushiBarView/Forms/FormDishes.resx b/SushiBarView/Forms/FormDishes.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SushiBarView/Forms/FormDishes.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/SushiBarView/Forms/FormIngredient.Designer.cs b/SushiBarView/Forms/FormIngredient.Designer.cs new file mode 100644 index 0000000..9d82cb4 --- /dev/null +++ b/SushiBarView/Forms/FormIngredient.Designer.cs @@ -0,0 +1,127 @@ +namespace SushiBarView.Forms +{ + partial class FormIngredient + { + /// + /// 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() + { + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + CostTextBox = new TextBox(); + UnitTextBox = new TextBox(); + IngredientNameTextBox = new TextBox(); + SaveButton = new Button(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 15); + label1.Name = "label1"; + label1.Size = new Size(93, 15); + label1.TabIndex = 0; + label1.Text = "Наименование:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(12, 44); + label2.Name = "label2"; + label2.Size = new Size(122, 15); + label2.TabIndex = 1; + label2.Text = "Единицы измерения:"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(12, 73); + label3.Name = "label3"; + label3.Size = new Size(133, 15); + label3.TabIndex = 2; + label3.Text = "Стоимость за единицу:"; + // + // CostTextBox + // + CostTextBox.Location = new Point(151, 70); + CostTextBox.Name = "CostTextBox"; + CostTextBox.Size = new Size(86, 23); + CostTextBox.TabIndex = 3; + // + // UnitTextBox + // + UnitTextBox.Location = new Point(151, 41); + UnitTextBox.Name = "UnitTextBox"; + UnitTextBox.Size = new Size(170, 23); + UnitTextBox.TabIndex = 4; + // + // IngredientNameTextBox + // + IngredientNameTextBox.Location = new Point(151, 12); + IngredientNameTextBox.Name = "IngredientNameTextBox"; + IngredientNameTextBox.Size = new Size(170, 23); + IngredientNameTextBox.TabIndex = 5; + // + // SaveButton + // + SaveButton.Location = new Point(219, 109); + SaveButton.Name = "SaveButton"; + SaveButton.Size = new Size(102, 30); + SaveButton.TabIndex = 6; + SaveButton.Text = "Сохранить"; + SaveButton.UseVisualStyleBackColor = true; + SaveButton.Click += ButtonSave_Click; + // + // FormIngredient + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(335, 151); + Controls.Add(SaveButton); + Controls.Add(IngredientNameTextBox); + Controls.Add(UnitTextBox); + Controls.Add(CostTextBox); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormIngredient"; + Text = "Ингредиент"; + Load += FormIngredient_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private TextBox CostTextBox; + private TextBox UnitTextBox; + private TextBox IngredientNameTextBox; + private Button SaveButton; + } +} \ No newline at end of file diff --git a/SushiBarView/Forms/FormIngredient.cs b/SushiBarView/Forms/FormIngredient.cs new file mode 100644 index 0000000..ffaf8d3 --- /dev/null +++ b/SushiBarView/Forms/FormIngredient.cs @@ -0,0 +1,81 @@ +using SushiBarBusinessLogic; +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; + +namespace SushiBarView.Forms +{ + public partial class FormIngredient : Form + { + private readonly IngredientLogic _logic; + + private int? _id; + + public int Id { set { _id = value; } } + + public FormIngredient(IngredientLogic Logic) + { + InitializeComponent(); + _logic = Logic; + } + + private void FormIngredient_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + var View = _logic.ReadElement(new IngredientSearchModel + { + Id = _id.Value + }); + + if (View != null) + { + IngredientNameTextBox.Text = View.IngredientName; + UnitTextBox.Text = View.Unit; + CostTextBox.Text = View.Cost.ToString(); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(IngredientNameTextBox.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + try + { + var Model = new IngredientBindingModel + { + Id = _id ?? 0, + IngredientName = IngredientNameTextBox.Text, + Unit = UnitTextBox.Text, + Cost = Convert.ToDouble(CostTextBox.Text), + }; + + var OperationResult = _id.HasValue ? _logic.Update(Model) : _logic.Create(Model); + + if (!OperationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка сохранения ингредиента", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/SushiBarView/Forms/FormIngredient.resx b/SushiBarView/Forms/FormIngredient.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SushiBarView/Forms/FormIngredient.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/SushiBarView/Forms/FormIngredients.Designer.cs b/SushiBarView/Forms/FormIngredients.Designer.cs new file mode 100644 index 0000000..7add834 --- /dev/null +++ b/SushiBarView/Forms/FormIngredients.Designer.cs @@ -0,0 +1,113 @@ +namespace SushiBarView.Forms +{ + partial class FormIngredients + { + /// + /// 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(); + AddButton = new Button(); + ChangeButton = new Button(); + DeleteButton = new Button(); + UpdateButton = new Button(); + ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + SuspendLayout(); + // + // DataGridView + // + DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + DataGridView.Location = new Point(12, 12); + DataGridView.Name = "DataGridView"; + DataGridView.RowTemplate.Height = 25; + DataGridView.Size = new Size(413, 358); + DataGridView.TabIndex = 0; + // + // AddButton + // + AddButton.Location = new Point(431, 12); + AddButton.Name = "AddButton"; + AddButton.Size = new Size(138, 29); + AddButton.TabIndex = 1; + AddButton.Text = "Добавить"; + AddButton.UseVisualStyleBackColor = true; + AddButton.Click += AddButton_Click; + // + // ChangeButton + // + ChangeButton.Location = new Point(431, 47); + ChangeButton.Name = "ChangeButton"; + ChangeButton.Size = new Size(138, 29); + ChangeButton.TabIndex = 2; + ChangeButton.Text = "Изменить"; + ChangeButton.UseVisualStyleBackColor = true; + ChangeButton.Click += ChangeButton_Click; + // + // DeleteButton + // + DeleteButton.Location = new Point(431, 82); + DeleteButton.Name = "DeleteButton"; + DeleteButton.Size = new Size(138, 29); + DeleteButton.TabIndex = 3; + DeleteButton.Text = "Удалить"; + DeleteButton.UseVisualStyleBackColor = true; + DeleteButton.Click += DeleteButton_Click; + // + // UpdateButton + // + UpdateButton.Location = new Point(431, 117); + UpdateButton.Name = "UpdateButton"; + UpdateButton.Size = new Size(138, 29); + UpdateButton.TabIndex = 4; + UpdateButton.Text = "Обновить"; + UpdateButton.UseVisualStyleBackColor = true; + UpdateButton.Click += RefreshButton_Click; + // + // FormIngredients + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(580, 384); + Controls.Add(UpdateButton); + Controls.Add(DeleteButton); + Controls.Add(ChangeButton); + Controls.Add(AddButton); + Controls.Add(DataGridView); + Name = "FormIngredients"; + Text = "Ингредиенты"; + Load += FormIngredients_Load; + ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView DataGridView; + private Button AddButton; + private Button ChangeButton; + private Button DeleteButton; + private Button UpdateButton; + } +} \ No newline at end of file diff --git a/SushiBarView/Forms/FormIngredients.cs b/SushiBarView/Forms/FormIngredients.cs new file mode 100644 index 0000000..7702b14 --- /dev/null +++ b/SushiBarView/Forms/FormIngredients.cs @@ -0,0 +1,98 @@ +using SushiBarBusinessLogic; +using SushiBarContracts.BindingModels; + +namespace SushiBarView.Forms +{ + public partial class FormIngredients : Form + { + private readonly IngredientLogic _logic; + + public FormIngredients(IngredientLogic Logic) + { + InitializeComponent(); + _logic = Logic; + } + + private void FormIngredients_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["IngredientName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AddButton_Click(object sender, EventArgs e) + { + FormIngredient Form = new FormIngredient(new IngredientLogic(new SushiBarDatabaseImplement.Storages.IngredientStorage())); + + if (Form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + + private void ChangeButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + FormIngredient Form = new FormIngredient(new IngredientLogic(new SushiBarDatabaseImplement.Storages.IngredientStorage())); + Form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + + if (Form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void DeleteButton_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 IngredientBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void RefreshButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/SushiBarView/Forms/FormIngredients.resx b/SushiBarView/Forms/FormIngredients.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SushiBarView/Forms/FormIngredients.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/SushiBarView/Forms/FormPromotion.Designer.cs b/SushiBarView/Forms/FormPromotion.Designer.cs new file mode 100644 index 0000000..1f4c996 --- /dev/null +++ b/SushiBarView/Forms/FormPromotion.Designer.cs @@ -0,0 +1,127 @@ +namespace SushiBarView.Forms +{ + partial class FormPromotion + { + /// + /// 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() + { + label1 = new Label(); + NameTextBox = new TextBox(); + label2 = new Label(); + button1 = new Button(); + DiscountTextBox = new TextBox(); + TriggeringSumTextBox = new TextBox(); + label3 = new Label(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 15); + label1.Name = "label1"; + label1.Size = new Size(59, 15); + label1.TabIndex = 0; + label1.Text = "Название"; + // + // NameTextBox + // + NameTextBox.Location = new Point(187, 12); + NameTextBox.Name = "NameTextBox"; + NameTextBox.Size = new Size(200, 23); + NameTextBox.TabIndex = 1; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(12, 44); + label2.Name = "label2"; + label2.Size = new Size(88, 15); + label2.TabIndex = 2; + label2.Text = "Размер скидки"; + // + // button1 + // + button1.Location = new Point(298, 108); + button1.Name = "button1"; + button1.Size = new Size(89, 28); + button1.TabIndex = 4; + button1.Text = "Сохранить"; + button1.UseVisualStyleBackColor = true; + button1.Click += ButtonSave_Click; + // + // DiscountTextBox + // + DiscountTextBox.Location = new Point(187, 41); + DiscountTextBox.Name = "DiscountTextBox"; + DiscountTextBox.Size = new Size(200, 23); + DiscountTextBox.TabIndex = 5; + // + // TriggeringSumTextBox + // + TriggeringSumTextBox.Location = new Point(187, 70); + TriggeringSumTextBox.Name = "TriggeringSumTextBox"; + TriggeringSumTextBox.Size = new Size(200, 23); + TriggeringSumTextBox.TabIndex = 6; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(12, 73); + label3.Name = "label3"; + label3.Size = new Size(169, 15); + label3.TabIndex = 7; + label3.Text = "Минимальная сумма заказов"; + // + // FormPromotion + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(397, 145); + Controls.Add(label3); + Controls.Add(TriggeringSumTextBox); + Controls.Add(DiscountTextBox); + Controls.Add(button1); + Controls.Add(label2); + Controls.Add(NameTextBox); + Controls.Add(label1); + Name = "FormPromotion"; + Text = "Акция"; + Load += FormPromotion_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private TextBox NameTextBox; + private Label label2; + private Button button1; + private TextBox DiscountTextBox; + private TextBox TriggeringSumTextBox; + private Label label3; + } +} \ No newline at end of file diff --git a/SushiBarView/Forms/FormPromotion.cs b/SushiBarView/Forms/FormPromotion.cs new file mode 100644 index 0000000..295b1c9 --- /dev/null +++ b/SushiBarView/Forms/FormPromotion.cs @@ -0,0 +1,80 @@ +using SushiBarBusinessLogic; +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; + +namespace SushiBarView.Forms +{ + public partial class FormPromotion : Form + { + private readonly PromotionLogic _logic; + + private int? _id; + public int Id { set { _id = value; } } + + public FormPromotion(PromotionLogic Logic) + { + InitializeComponent(); + _logic = Logic; + } + + private void FormPromotion_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + var View = _logic.ReadElement(new PromotionSearchModel + { + Id = _id.Value + }); + + if (View != null) + { + NameTextBox.Text = View.PromotionName; + DiscountTextBox.Text = View.Discount.ToString(); + TriggeringSumTextBox.Text = View.TriggeringSum.ToString(); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(NameTextBox.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + try + { + var Model = new PromotionBindingModel + { + Id = _id ?? 0, + PromotionName = NameTextBox.Text, + Discount = float.Parse(DiscountTextBox.Text), + TriggeringSum = Double.Parse(TriggeringSumTextBox.Text), + }; + + var OperationResult = _id.HasValue ? _logic.Update(Model) : _logic.Create(Model); + + if (!OperationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка сохранения акции", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/SushiBarView/Forms/FormPromotion.resx b/SushiBarView/Forms/FormPromotion.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SushiBarView/Forms/FormPromotion.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/SushiBarView/Forms/FormPromotions.Designer.cs b/SushiBarView/Forms/FormPromotions.Designer.cs new file mode 100644 index 0000000..480908f --- /dev/null +++ b/SushiBarView/Forms/FormPromotions.Designer.cs @@ -0,0 +1,113 @@ +namespace SushiBarView.Forms +{ + partial class FormPromotions + { + /// + /// 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(); + AddButton = new Button(); + ChangeButton = new Button(); + DeleteButton = new Button(); + UpdateButton = new Button(); + ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + SuspendLayout(); + // + // DataGridView + // + DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + DataGridView.Location = new Point(12, 12); + DataGridView.Name = "DataGridView"; + DataGridView.RowTemplate.Height = 25; + DataGridView.Size = new Size(413, 358); + DataGridView.TabIndex = 0; + // + // AddButton + // + AddButton.Location = new Point(431, 12); + AddButton.Name = "AddButton"; + AddButton.Size = new Size(138, 29); + AddButton.TabIndex = 1; + AddButton.Text = "Добавить"; + AddButton.UseVisualStyleBackColor = true; + AddButton.Click += AddButton_Click; + // + // ChangeButton + // + ChangeButton.Location = new Point(431, 47); + ChangeButton.Name = "ChangeButton"; + ChangeButton.Size = new Size(138, 29); + ChangeButton.TabIndex = 2; + ChangeButton.Text = "Изменить"; + ChangeButton.UseVisualStyleBackColor = true; + ChangeButton.Click += ChangeButton_Click; + // + // DeleteButton + // + DeleteButton.Location = new Point(431, 82); + DeleteButton.Name = "DeleteButton"; + DeleteButton.Size = new Size(138, 29); + DeleteButton.TabIndex = 3; + DeleteButton.Text = "Удалить"; + DeleteButton.UseVisualStyleBackColor = true; + DeleteButton.Click += DeleteButton_Click; + // + // UpdateButton + // + UpdateButton.Location = new Point(431, 117); + UpdateButton.Name = "UpdateButton"; + UpdateButton.Size = new Size(138, 29); + UpdateButton.TabIndex = 4; + UpdateButton.Text = "Обновить"; + UpdateButton.UseVisualStyleBackColor = true; + UpdateButton.Click += RefreshButton_Click; + // + // FormPromotions + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(580, 384); + Controls.Add(UpdateButton); + Controls.Add(DeleteButton); + Controls.Add(ChangeButton); + Controls.Add(AddButton); + Controls.Add(DataGridView); + Name = "FormPromotions"; + Text = "Акции"; + Load += FormPromotions_Load; + ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView DataGridView; + private Button AddButton; + private Button ChangeButton; + private Button DeleteButton; + private Button UpdateButton; + } +} \ No newline at end of file diff --git a/SushiBarView/Forms/FormPromotions.cs b/SushiBarView/Forms/FormPromotions.cs new file mode 100644 index 0000000..b42ff9c --- /dev/null +++ b/SushiBarView/Forms/FormPromotions.cs @@ -0,0 +1,98 @@ +using SushiBarBusinessLogic; +using SushiBarContracts.BindingModels; + +namespace SushiBarView.Forms +{ + public partial class FormPromotions : Form + { + private readonly PromotionLogic _logic; + + public FormPromotions(PromotionLogic Logic) + { + InitializeComponent(); + _logic = Logic; + } + + private void FormPromotions_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["PromotionName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["Discount"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AddButton_Click(object sender, EventArgs e) + { + FormPromotion Form = new FormPromotion(new PromotionLogic(new SushiBarDatabaseImplement.Storages.PromotionStorage())); + + if (Form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + + private void ChangeButton_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + FormPromotion Form = new FormPromotion(new PromotionLogic(new SushiBarDatabaseImplement.Storages.PromotionStorage())); + Form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + + if (Form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void DeleteButton_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 PromotionBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void RefreshButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/SushiBarView/Forms/FormPromotions.resx b/SushiBarView/Forms/FormPromotions.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SushiBarView/Forms/FormPromotions.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/SushiBarView/MainForm.Designer.cs b/SushiBarView/MainForm.Designer.cs new file mode 100644 index 0000000..bb7618f --- /dev/null +++ b/SushiBarView/MainForm.Designer.cs @@ -0,0 +1,174 @@ +namespace SushiBarView +{ + partial class MainForm + { + /// + /// 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() + { + menuStrip1 = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + IngredientsToolStripMenuItem = new ToolStripMenuItem(); + DishesToolStripMenuItem = new ToolStripMenuItem(); + CooksToolStripMenuItem = new ToolStripMenuItem(); + CustomersToolStripMenuItem = new ToolStripMenuItem(); + PromotionsToolStripMenuItem = new ToolStripMenuItem(); + DataGridView = new DataGridView(); + CreateOrderButton = new Button(); + RefreshButton = new Button(); + ChequeInfoButton = new Button(); + menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(1189, 24); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { IngredientsToolStripMenuItem, DishesToolStripMenuItem, CooksToolStripMenuItem, CustomersToolStripMenuItem, PromotionsToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(94, 20); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // IngredientsToolStripMenuItem + // + IngredientsToolStripMenuItem.Name = "IngredientsToolStripMenuItem"; + IngredientsToolStripMenuItem.Size = new Size(148, 22); + IngredientsToolStripMenuItem.Text = "Ингредиенты"; + IngredientsToolStripMenuItem.Click += IngredientsToolStripMenuItem_Click; + // + // DishesToolStripMenuItem + // + DishesToolStripMenuItem.Name = "DishesToolStripMenuItem"; + DishesToolStripMenuItem.Size = new Size(148, 22); + DishesToolStripMenuItem.Text = "Блюда"; + DishesToolStripMenuItem.Click += DishesToolStripMenuItem_Click; + // + // CooksToolStripMenuItem + // + CooksToolStripMenuItem.Name = "CooksToolStripMenuItem"; + CooksToolStripMenuItem.Size = new Size(148, 22); + CooksToolStripMenuItem.Text = "Повара"; + CooksToolStripMenuItem.Click += CooksToolStripMenuItem_Click; + // + // CustomersToolStripMenuItem + // + CustomersToolStripMenuItem.Name = "CustomersToolStripMenuItem"; + CustomersToolStripMenuItem.Size = new Size(148, 22); + CustomersToolStripMenuItem.Text = "Покупатели"; + CustomersToolStripMenuItem.Click += CustomersToolStripMenuItem_Click; + // + // PromotionsToolStripMenuItem + // + PromotionsToolStripMenuItem.Name = "PromotionsToolStripMenuItem"; + PromotionsToolStripMenuItem.Size = new Size(148, 22); + PromotionsToolStripMenuItem.Text = "Акции"; + PromotionsToolStripMenuItem.Click += PromotionsToolStripMenuItem_Click; + // + // DataGridView + // + DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + DataGridView.Location = new Point(12, 27); + DataGridView.Name = "DataGridView"; + DataGridView.RowTemplate.Height = 25; + DataGridView.Size = new Size(931, 370); + DataGridView.TabIndex = 1; + // + // CreateOrderButton + // + CreateOrderButton.Location = new Point(949, 27); + CreateOrderButton.Margin = new Padding(3, 2, 3, 2); + CreateOrderButton.Name = "CreateOrderButton"; + CreateOrderButton.Size = new Size(227, 30); + CreateOrderButton.TabIndex = 3; + CreateOrderButton.Text = "Создать заказ"; + CreateOrderButton.UseVisualStyleBackColor = true; + CreateOrderButton.Click += CreateOrderButton_Click; + // + // RefreshButton + // + RefreshButton.Location = new Point(949, 61); + RefreshButton.Margin = new Padding(3, 2, 3, 2); + RefreshButton.Name = "RefreshButton"; + RefreshButton.Size = new Size(227, 30); + RefreshButton.TabIndex = 7; + RefreshButton.Text = "Обновить"; + RefreshButton.UseVisualStyleBackColor = true; + RefreshButton.Click += RefreshButton_Click; + // + // ChequeInfoButton + // + ChequeInfoButton.Location = new Point(950, 114); + ChequeInfoButton.Margin = new Padding(3, 2, 3, 2); + ChequeInfoButton.Name = "ChequeInfoButton"; + ChequeInfoButton.Size = new Size(227, 30); + ChequeInfoButton.TabIndex = 8; + ChequeInfoButton.Text = "Информация о заказе"; + ChequeInfoButton.UseVisualStyleBackColor = true; + ChequeInfoButton.Click += ChequeInfo_Click; + // + // MainForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1189, 405); + Controls.Add(ChequeInfoButton); + Controls.Add(RefreshButton); + Controls.Add(CreateOrderButton); + Controls.Add(DataGridView); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "MainForm"; + Text = "MainForm"; + Load += MainForm_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem IngredientsToolStripMenuItem; + private ToolStripMenuItem DishesToolStripMenuItem; + private ToolStripMenuItem CooksToolStripMenuItem; + private ToolStripMenuItem CustomersToolStripMenuItem; + private ToolStripMenuItem PromotionsToolStripMenuItem; + private DataGridView DataGridView; + private Button CreateOrderButton; + private Button RefreshButton; + private Button ChequeInfoButton; + } +} \ No newline at end of file diff --git a/SushiBarView/MainForm.cs b/SushiBarView/MainForm.cs new file mode 100644 index 0000000..5c93aec --- /dev/null +++ b/SushiBarView/MainForm.cs @@ -0,0 +1,99 @@ +using SushiBarBusinessLogic; +using SushiBarView.Forms; + +namespace SushiBarView +{ + public partial class MainForm : Form + { + private readonly ChequeLogic _chequeLogic; + + public MainForm(ChequeLogic ChequeLogic) + { + InitializeComponent(); + _chequeLogic = ChequeLogic; + } + + private void MainForm_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var List = _chequeLogic.ReadList(null); + + if (List != null) + { + DataGridView.DataSource = List; + DataGridView.Columns["CustomerId"].Visible = false; + DataGridView.Columns["PromotionId"].Visible = false; + DataGridView.Columns["ChequeItems"].Visible = false; + DataGridView.Columns["OrderDate"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["TotalSum"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void IngredientsToolStripMenuItem_Click(object sender, EventArgs e) + { + FormIngredients Form = new FormIngredients(new SushiBarBusinessLogic.IngredientLogic(new SushiBarDatabaseImplement.Storages.IngredientStorage())); + Form.ShowDialog(); + } + + private void DishesToolStripMenuItem_Click(object sender, EventArgs e) + { + FormDishes Form = new FormDishes(new SushiBarBusinessLogic.DishLogic(new SushiBarDatabaseImplement.Storages.DishStorage())); + Form.ShowDialog(); + } + + private void CooksToolStripMenuItem_Click(object sender, EventArgs e) + { + FormCooks Form = new FormCooks(new SushiBarBusinessLogic.CookLogic(new SushiBarDatabaseImplement.Storages.CookStorage())); + Form.ShowDialog(); + } + + private void CustomersToolStripMenuItem_Click(object sender, EventArgs e) + { + FormCustomers Form = new FormCustomers(new SushiBarBusinessLogic.CustomerLogic(new SushiBarDatabaseImplement.Storages.CustomerStorage())); + Form.ShowDialog(); + } + + private void PromotionsToolStripMenuItem_Click(object sender, EventArgs e) + { + FormPromotions Form = new FormPromotions(new SushiBarBusinessLogic.PromotionLogic(new SushiBarDatabaseImplement.Storages.PromotionStorage())); + Form.ShowDialog(); + } + + private void CreateOrderButton_Click(object sender, EventArgs e) + { + FormCreateCheque Form = new FormCreateCheque( + new ChequeLogic(new SushiBarDatabaseImplement.Storages.ChequeStorage()), + new CustomerLogic(new SushiBarDatabaseImplement.Storages.CustomerStorage())); + + Form.ShowDialog(); + LoadData(); + } + + private void RefreshButton_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void ChequeInfo_Click(object sender, EventArgs e) + { + FormCreateCheque Form = new FormCreateCheque( + new ChequeLogic(new SushiBarDatabaseImplement.Storages.ChequeStorage()), + new CustomerLogic(new SushiBarDatabaseImplement.Storages.CustomerStorage())); + Form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + + Form.ShowDialog(); + LoadData(); + } + } +} diff --git a/SushiBarView/MainForm.resx b/SushiBarView/MainForm.resx new file mode 100644 index 0000000..a0623c8 --- /dev/null +++ b/SushiBarView/MainForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/SushiBarView/Program.cs b/SushiBarView/Program.cs index 402417b..d0ee695 100644 --- a/SushiBarView/Program.cs +++ b/SushiBarView/Program.cs @@ -1,17 +1,11 @@ -namespace SushiBar +namespace SushiBarView { internal static class Program { - /// - /// The main entry point for the application. - /// [STAThread] static void Main() { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + Application.Run(new MainForm(new SushiBarBusinessLogic.ChequeLogic(new SushiBarDatabaseImplement.Storages.ChequeStorage()))); } } -} \ No newline at end of file +} diff --git a/SushiBarView/SushiBarView.csproj b/SushiBarView/SushiBarView.csproj index c3d2ab9..4915e3b 100644 --- a/SushiBarView/SushiBarView.csproj +++ b/SushiBarView/SushiBarView.csproj @@ -16,6 +16,7 @@ +