From c61f016d73ad07bf6a322967f323c22220fdf9f0 Mon Sep 17 00:00:00 2001 From: tellsense Date: Thu, 29 Feb 2024 21:13:18 +0400 Subject: [PATCH 1/3] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BD=D1=83=D0=B6=D0=BD=D1=8B=D1=85=20?= =?UTF-8?q?=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=BE=D0=B2=20=D0=B8=20=D0=BC?= =?UTF-8?q?=D0=B5=D1=82=D0=BE=D0=B4=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBarBusinessLogic/ShopLogic.cs | 160 ++++++++++++++++++ .../BindingModels/ShopBindingModel.cs | 19 +++ .../BindingModels/SupplyBindingModel.cs | 16 ++ .../BusinessLogicsContracts/IShopLogic.cs | 21 +++ .../SearchModels/ShopSearchModel.cs | 14 ++ .../StoragesContracts/IShopStorage.cs | 21 +++ .../ViewModels/ShopViewModel.cs | 22 +++ SushiBar/SushiBarDataModels/IShopModel.cs | 16 ++ SushiBar/SushiBarDataModels/ISupplyModel.cs | 15 ++ .../DataListSingleton.cs | 2 + SushiBar/SushiBarListImplement/Shop.cs | 59 +++++++ SushiBar/SushiBarListImplement/ShopStorage.cs | 113 +++++++++++++ .../SushiBarView/FormCreateSupply.Designer.cs | 39 +++++ SushiBar/SushiBarView/FormCreateSupply.cs | 99 +++++++++++ SushiBar/SushiBarView/FormCreateSupply.resx | 120 +++++++++++++ SushiBar/SushiBarView/FormMain.cs | 17 ++ SushiBar/SushiBarView/FormShop.Designer.cs | 39 +++++ SushiBar/SushiBarView/FormShop.cs | 128 ++++++++++++++ SushiBar/SushiBarView/FormShop.resx | 120 +++++++++++++ SushiBar/SushiBarView/FormShops.Designer.cs | 39 +++++ SushiBar/SushiBarView/FormShops.cs | 116 +++++++++++++ SushiBar/SushiBarView/FormShops.resx | 120 +++++++++++++ SushiBar/SushiBarView/Program.cs | 5 + 23 files changed, 1320 insertions(+) create mode 100644 SushiBar/SushiBarBusinessLogic/ShopLogic.cs create mode 100644 SushiBar/SushiBarContracts/BindingModels/ShopBindingModel.cs create mode 100644 SushiBar/SushiBarContracts/BindingModels/SupplyBindingModel.cs create mode 100644 SushiBar/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 SushiBar/SushiBarContracts/SearchModels/ShopSearchModel.cs create mode 100644 SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs create mode 100644 SushiBar/SushiBarContracts/ViewModels/ShopViewModel.cs create mode 100644 SushiBar/SushiBarDataModels/IShopModel.cs create mode 100644 SushiBar/SushiBarDataModels/ISupplyModel.cs create mode 100644 SushiBar/SushiBarListImplement/Shop.cs create mode 100644 SushiBar/SushiBarListImplement/ShopStorage.cs create mode 100644 SushiBar/SushiBarView/FormCreateSupply.Designer.cs create mode 100644 SushiBar/SushiBarView/FormCreateSupply.cs create mode 100644 SushiBar/SushiBarView/FormCreateSupply.resx create mode 100644 SushiBar/SushiBarView/FormShop.Designer.cs create mode 100644 SushiBar/SushiBarView/FormShop.cs create mode 100644 SushiBar/SushiBarView/FormShop.resx create mode 100644 SushiBar/SushiBarView/FormShops.Designer.cs create mode 100644 SushiBar/SushiBarView/FormShops.cs create mode 100644 SushiBar/SushiBarView/FormShops.resx diff --git a/SushiBar/SushiBarBusinessLogic/ShopLogic.cs b/SushiBar/SushiBarBusinessLogic/ShopLogic.cs new file mode 100644 index 0000000..c82d231 --- /dev/null +++ b/SushiBar/SushiBarBusinessLogic/ShopLogic.cs @@ -0,0 +1,160 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace SushiBarBusinessLogic.BusinessLogics +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + private readonly IShopStorage _shopStorage; + private readonly ISushiStorage _sushiStorage; + + public ShopLogic(ILogger logger, IShopStorage shopStorage, ISushiStorage sushiStorage) + { + _logger = logger; + _shopStorage = shopStorage; + _sushiStorage = sushiStorage; + } + + public List? ReadList(ShopSearchModel? model) + { + _logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id}", model?.ShopName, model?.Id); + var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public ShopViewModel? ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id); + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public bool MakeSupply(SupplyBindingModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (model.Count <= 0) + { + throw new ArgumentException("Количество изделий должно быть больше 0"); + } + var shop = _shopStorage.GetElement(new ShopSearchModel + { + Id = model.ShopId + }); + if (shop == null) + { + throw new ArgumentException("Магазина не существует"); + } + if (shop.ShopSushis.ContainsKey(model.SushiId)) + { + var oldValue = shop.ShopSushis[model.SushiId]; + oldValue.Item2 += model.Count; + shop.ShopSushis[model.SushiId] = oldValue; + } + else + { + var sushi = _sushiStorage.GetElement(new SushiSearchModel + { + Id = model.SushiId + }); + if (sushi == null) + { + throw new ArgumentException($"Поставка: Товар с id:{model.SushiId} не найденн"); + } + shop.ShopSushis.Add(model.SushiId, (sushi, model.Count)); + } + return true; + } + + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Adress)) + { + throw new ArgumentException("Адрес магазина длжен быть заполнен", nameof(model.Adress)); + } + if (string.IsNullOrEmpty(model.ShopName)) + { + throw new ArgumentException("Название магазина должно быть заполнено", nameof(model.ShopName)); + } + _logger.LogInformation("Shop. ShopName:{ShopName}.Adres:{Adres}.OpeningDate:{OpeningDate}.Id:{ Id}", model.ShopName, model.Adress, model.OpeningDate, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + ShopName = model.ShopName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/BindingModels/ShopBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..7822182 --- /dev/null +++ b/SushiBar/SushiBarContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarDataModels.Models; + +namespace SushiBarContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + public string ShopName { get; set; } = string.Empty; + public string Adress { get; set; } = string.Empty; + public DateTime OpeningDate { get; set; } = DateTime.Now; + public Dictionary ShopSushis { get; set; } = new(); + + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/BindingModels/SupplyBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/SupplyBindingModel.cs new file mode 100644 index 0000000..4143488 --- /dev/null +++ b/SushiBar/SushiBarContracts/BindingModels/SupplyBindingModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarDataModels.Models; + +namespace SushiBarContracts.BindingModels +{ + public class SupplyBindingModel : ISupplyModel + { + public int ShopId { get; set; } + public int SushiId { get; set; } + public int Count { get; set; } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..8bec166 --- /dev/null +++ b/SushiBar/SushiBarContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,21 @@ +using SushiBarContracts.BindingModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; + +namespace SushiBarContracts.BusinessLogicsContracts +{ + public interface IShopLogic + { + List? ReadList(ShopSearchModel? model); + ShopViewModel? ReadElement(ShopSearchModel model); + bool Create(ShopBindingModel model); + bool Update(ShopBindingModel model); + bool Delete(ShopBindingModel model); + bool MakeSupply(SupplyBindingModel model); + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/SearchModels/ShopSearchModel.cs b/SushiBar/SushiBarContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..8ab0e48 --- /dev/null +++ b/SushiBar/SushiBarContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? ShopName { get; set; } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs b/SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..bc30638 --- /dev/null +++ b/SushiBar/SushiBarContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,21 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarContracts.StoragesContracts +{ + public interface IShopStorage + { + List GetFullList(); + List GetFilteredList(ShopSearchModel model); + ShopViewModel? GetElement(ShopSearchModel model); + ShopViewModel? Insert(ShopBindingModel model); + ShopViewModel? Update(ShopBindingModel model); + ShopViewModel? Delete(ShopBindingModel model); + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/ViewModels/ShopViewModel.cs b/SushiBar/SushiBarContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..c04a16e --- /dev/null +++ b/SushiBar/SushiBarContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarDataModels.Models; + +namespace SushiBarContracts.ViewModels +{ + public class ShopViewModel + { + public int Id { get; set; } + [DisplayName("Название")] + public string ShopName { get; set; } = string.Empty; + [DisplayName("Адрес")] + public string Adress { get; set; } = string.Empty; + [DisplayName("Дата открытия")] + public DateTime OpeningDate { get; set; } + public Dictionary ShopSushis { get; set; } = new(); + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarDataModels/IShopModel.cs b/SushiBar/SushiBarDataModels/IShopModel.cs new file mode 100644 index 0000000..43b410f --- /dev/null +++ b/SushiBar/SushiBarDataModels/IShopModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + string Adress { get; } + DateTime OpeningDate { get; } + Dictionary ShopSushis { get; } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarDataModels/ISupplyModel.cs b/SushiBar/SushiBarDataModels/ISupplyModel.cs new file mode 100644 index 0000000..de1eaf6 --- /dev/null +++ b/SushiBar/SushiBarDataModels/ISupplyModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarDataModels.Models +{ + public interface ISupplyModel + { + int ShopId { get; } + int SushiId { get; } + int Count { get; } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarListImplement/DataListSingleton.cs b/SushiBar/SushiBarListImplement/DataListSingleton.cs index 34e703f..31ecbd0 100644 --- a/SushiBar/SushiBarListImplement/DataListSingleton.cs +++ b/SushiBar/SushiBarListImplement/DataListSingleton.cs @@ -13,11 +13,13 @@ namespace SushiBarListImplement public List Components { get; set; } public List Orders { get; set; } public List Sushis { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Sushis = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/SushiBar/SushiBarListImplement/Shop.cs b/SushiBar/SushiBarListImplement/Shop.cs new file mode 100644 index 0000000..1f283b1 --- /dev/null +++ b/SushiBar/SushiBarListImplement/Shop.cs @@ -0,0 +1,59 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; +using SushiBarDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarDataModels.Enums; + +namespace SushiBarListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + public string Adress { get; private set; } = string.Empty; + public DateTime OpeningDate { get; private set; } + public Dictionary ShopSushis { get; private set; } = new(); + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Adress = model.Adress, + OpeningDate = model.OpeningDate + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Adress = model.Adress; + OpeningDate = model.OpeningDate; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Adress = Adress, + OpeningDate = OpeningDate, + ShopSushis = ShopSushis + }; + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarListImplement/ShopStorage.cs b/SushiBar/SushiBarListImplement/ShopStorage.cs new file mode 100644 index 0000000..bd1c039 --- /dev/null +++ b/SushiBar/SushiBarListImplement/ShopStorage.cs @@ -0,0 +1,113 @@ +using SushiBarContracts.BindingModels; +using SushiBarContracts.SearchModels; +using SushiBarContracts.StoragesContracts; +using SushiBarContracts.ViewModels; +using SushiBarListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; + } + + public List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ShopName)) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.ShopName.Contains(model.ShopName)) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) || + (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + return null; + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = 1; + foreach (var shop in _source.Shops) + { + if (model.Id <= shop.Id) + { + model.Id = shop.Id + 1; + } + } + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + _source.Shops.Add(newShop); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + foreach (var shop in _source.Shops) + { + if (shop.Id == model.Id) + { + shop.Update(model); + return shop.GetViewModel; + } + } + return null; + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + for (int i = 0; i < _source.Shops.Count; ++i) + { + if (_source.Shops[i].Id == model.Id) + { + var element = _source.Shops[i]; + _source.Shops.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormCreateSupply.Designer.cs b/SushiBar/SushiBarView/FormCreateSupply.Designer.cs new file mode 100644 index 0000000..390a089 --- /dev/null +++ b/SushiBar/SushiBarView/FormCreateSupply.Designer.cs @@ -0,0 +1,39 @@ +namespace SushiBarView +{ + partial class FormCreateSupply + { + /// + /// 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 = "FormCreateSupply"; + } + + #endregion + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormCreateSupply.cs b/SushiBar/SushiBarView/FormCreateSupply.cs new file mode 100644 index 0000000..a91cfe0 --- /dev/null +++ b/SushiBar/SushiBarView/FormCreateSupply.cs @@ -0,0 +1,99 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.ViewModels; +using System; +using System.Collections; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using static System.Windows.Forms.VisualStyles.VisualStyleElement; + +namespace SushiBarView +{ + public partial class FormCreateSupply : Form + { + private readonly ILogger _logger; + private readonly ISushiLogic _logicP; + private readonly IShopLogic _logicS; + private List _shopList = new List(); + private List _sushiList = new List(); + + public FormCreateSupply(ILogger logger, ISushiLogic logicP, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicS = logicS; + } + + private void FormCreateSupply_Load(object sender, EventArgs e) + { + _shopList = _logicS.ReadList(null); + _sushiList = _logicP.ReadList(null); + if (_shopList != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = _shopList; + comboBoxShop.SelectedItem = null; + _logger.LogInformation("Загрузка магазинов для поставок"); + } + if (_sushiList != null) + { + comboBoxSushi.DisplayMember = "SushiName"; + comboBoxSushi.ValueMember = "Id"; + comboBoxSushi.DataSource = _sushiList; + comboBoxSushi.SelectedItem = null; + _logger.LogInformation("Загрузка пиццы для поставок"); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxSushi.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание поставки"); + try + { + var operationResult = _logicS.MakeSupply(new SupplyBindingModel + { + ShopId = Convert.ToInt32(comboBoxShop.SelectedValue), + SushiId = Convert.ToInt32(comboBoxSushi.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании поставки. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания поставки"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormCreateSupply.resx b/SushiBar/SushiBarView/FormCreateSupply.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/SushiBar/SushiBarView/FormCreateSupply.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormMain.cs b/SushiBar/SushiBarView/FormMain.cs index cb8c267..e5fb92c 100644 --- a/SushiBar/SushiBarView/FormMain.cs +++ b/SushiBar/SushiBarView/FormMain.cs @@ -160,5 +160,22 @@ namespace SushiBarView { LoadData(); } + private void shopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + + private void transactionToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateSupply)); + if (service is FormCreateSupply form) + { + form.ShowDialog(); + } + } } } diff --git a/SushiBar/SushiBarView/FormShop.Designer.cs b/SushiBar/SushiBarView/FormShop.Designer.cs new file mode 100644 index 0000000..a44fb47 --- /dev/null +++ b/SushiBar/SushiBarView/FormShop.Designer.cs @@ -0,0 +1,39 @@ +namespace SushiBarView +{ + partial class FormShop + { + /// + /// 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 = "FormShop"; + } + + #endregion + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormShop.cs b/SushiBar/SushiBarView/FormShop.cs new file mode 100644 index 0000000..2e494d3 --- /dev/null +++ b/SushiBar/SushiBarView/FormShop.cs @@ -0,0 +1,128 @@ +using SushiBarDataModels.Models; +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using SushiBarContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SushiBarView +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + private Dictionary _ShopSushis; + private DateTime? _openingDate = null; + + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _ShopSushis = new Dictionary(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var view = _logic.ReadElement(new ShopSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ShopName; + textBoxAdress.Text = view.Adress; + dateTimeOpen.Value = view.OpeningDate; + _ShopSushis = view.ShopSushis ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка изделий в магазине"); + try + { + if (_ShopSushis != null) + { + dataGridView.Rows.Clear(); + foreach (var sr in _ShopSushis) + { + dataGridView.Rows.Add(new object[] { sr.Key, sr.Value.Item1.SushiName, sr.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAdress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Adress = textBoxAdress.Text, + OpeningDate = dateTimeOpen.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) + { + _logger.LogError(ex, "Ошибка сохранения магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormShop.resx b/SushiBar/SushiBarView/FormShop.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/SushiBar/SushiBarView/FormShop.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormShops.Designer.cs b/SushiBar/SushiBarView/FormShops.Designer.cs new file mode 100644 index 0000000..c01f435 --- /dev/null +++ b/SushiBar/SushiBarView/FormShops.Designer.cs @@ -0,0 +1,39 @@ +namespace SushiBarView +{ + partial class FormShops + { + /// + /// 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 = "FormShops"; + } + + #endregion + } +} \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormShops.cs b/SushiBar/SushiBarView/FormShops.cs new file mode 100644 index 0000000..7e899d2 --- /dev/null +++ b/SushiBar/SushiBarView/FormShops.cs @@ -0,0 +1,116 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModels; +using SushiBarContracts.BusinessLogicsContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SushiBarView +{ + public partial class FormShops : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + + public FormShops(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormShops_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["ShopSushis"].Visible = false; + dataGridView.Columns["ShopName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление магазина"); + try + { + if (!_logic.Delete(new ShopBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/SushiBar/SushiBarView/FormShops.resx b/SushiBar/SushiBarView/FormShops.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/SushiBar/SushiBarView/FormShops.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SushiBar/SushiBarView/Program.cs b/SushiBar/SushiBarView/Program.cs index bff3589..b835c44 100644 --- a/SushiBar/SushiBarView/Program.cs +++ b/SushiBar/SushiBarView/Program.cs @@ -49,6 +49,11 @@ namespace SushiBarView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } -- 2.25.1 From f879c63415e5b47b5d97abd55b63dd400470b281 Mon Sep 17 00:00:00 2001 From: tellsense Date: Thu, 29 Feb 2024 22:07:10 +0400 Subject: [PATCH 2/3] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=BE=D0=BD?= =?UTF-8?q?=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D1=84=D0=BE?= =?UTF-8?q?=D1=80=D0=BC.=20(=D0=9B=D0=B0=D0=B1=D0=B0=201=D1=83=D1=81=D0=BB?= =?UTF-8?q?.=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SushiBarView/FormCreateSupply.Designer.cs | 111 ++++++++++++- SushiBar/SushiBarView/FormCreateSupply.resx | 50 +++--- SushiBar/SushiBarView/FormMain.Designer.cs | 51 ++++-- SushiBar/SushiBarView/FormMain.cs | 2 +- SushiBar/SushiBarView/FormShop.Designer.cs | 152 +++++++++++++++++- SushiBar/SushiBarView/FormShop.cs | 12 +- SushiBar/SushiBarView/FormShop.resx | 59 ++++--- SushiBar/SushiBarView/FormShops.Designer.cs | 85 +++++++++- SushiBar/SushiBarView/FormShops.cs | 16 +- SushiBar/SushiBarView/FormShops.resx | 50 +++--- 10 files changed, 474 insertions(+), 114 deletions(-) diff --git a/SushiBar/SushiBarView/FormCreateSupply.Designer.cs b/SushiBar/SushiBarView/FormCreateSupply.Designer.cs index 390a089..615e85e 100644 --- a/SushiBar/SushiBarView/FormCreateSupply.Designer.cs +++ b/SushiBar/SushiBarView/FormCreateSupply.Designer.cs @@ -28,12 +28,115 @@ /// 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 = "FormCreateSupply"; + labelShop = new Label(); + labelSushi = new Label(); + labelCount = new Label(); + comboBoxShop = new ComboBox(); + comboBoxSushi = new ComboBox(); + textBoxCount = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelShop + // + labelShop.AutoSize = true; + labelShop.Location = new Point(12, 25); + labelShop.Name = "labelShop"; + labelShop.Size = new Size(57, 15); + labelShop.TabIndex = 0; + labelShop.Text = "Магазин:"; + // + // labelSushi + // + labelSushi.AutoSize = true; + labelSushi.Location = new Point(12, 62); + labelSushi.Name = "labelSushi"; + labelSushi.Size = new Size(56, 15); + labelSushi.TabIndex = 1; + labelSushi.Text = "Изделие:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(12, 99); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(75, 15); + labelCount.TabIndex = 2; + labelCount.Text = "Количество:"; + // + // comboBoxShop + // + comboBoxShop.FormattingEnabled = true; + comboBoxShop.Location = new Point(100, 22); + comboBoxShop.Name = "comboBoxShop"; + comboBoxShop.Size = new Size(239, 23); + comboBoxShop.TabIndex = 3; + // + // comboBoxSushi + // + comboBoxSushi.FormattingEnabled = true; + comboBoxSushi.Location = new Point(100, 59); + comboBoxSushi.Name = "comboBoxSushi"; + comboBoxSushi.Size = new Size(239, 23); + comboBoxSushi.TabIndex = 4; + // + // textBoxCount + // + textBoxCount.Location = new Point(100, 96); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(239, 23); + textBoxCount.TabIndex = 5; + // + // buttonSave + // + buttonSave.Location = new Point(39, 138); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(118, 44); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(199, 138); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(118, 44); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormCreateSupply + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(351, 194); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(comboBoxSushi); + Controls.Add(comboBoxShop); + Controls.Add(labelCount); + Controls.Add(labelSushi); + Controls.Add(labelShop); + Name = "FormCreateSupply"; + Text = "Создание поставки"; + Load += FormCreateSupply_Load; + ResumeLayout(false); + PerformLayout(); } #endregion + + private Label labelShop; + private Label labelSushi; + private Label labelCount; + private ComboBox comboBoxShop; + private ComboBox comboBoxSushi; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; } } \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormCreateSupply.resx b/SushiBar/SushiBarView/FormCreateSupply.resx index 1af7de1..af32865 100644 --- a/SushiBar/SushiBarView/FormCreateSupply.resx +++ b/SushiBar/SushiBarView/FormCreateSupply.resx @@ -1,17 +1,17 @@  - diff --git a/SushiBar/SushiBarView/FormMain.Designer.cs b/SushiBar/SushiBarView/FormMain.Designer.cs index 5dee4ec..9270c63 100644 --- a/SushiBar/SushiBarView/FormMain.Designer.cs +++ b/SushiBar/SushiBarView/FormMain.Designer.cs @@ -38,6 +38,9 @@ toolStripMenuItem = new ToolStripMenuItem(); componentsToolStripMenuItem = new ToolStripMenuItem(); sushiToolStripMenuItem = new ToolStripMenuItem(); + shopsToolStripMenuItem = new ToolStripMenuItem(); + othersToolStripMenuItem = new ToolStripMenuItem(); + supplyToolStripMenuItem = new ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); menuStrip.SuspendLayout(); SuspendLayout(); @@ -49,12 +52,12 @@ dataGridView.Location = new Point(1, 29); dataGridView.Name = "dataGridView"; dataGridView.RowTemplate.Height = 25; - dataGridView.Size = new Size(1080, 307); + dataGridView.Size = new Size(792, 307); dataGridView.TabIndex = 0; // // ButtonCreateOrder // - ButtonCreateOrder.Location = new Point(1087, 41); + ButtonCreateOrder.Location = new Point(818, 29); ButtonCreateOrder.Name = "ButtonCreateOrder"; ButtonCreateOrder.Size = new Size(147, 33); ButtonCreateOrder.TabIndex = 1; @@ -64,7 +67,7 @@ // // ButtonTakeOrderInWork // - ButtonTakeOrderInWork.Location = new Point(1087, 80); + ButtonTakeOrderInWork.Location = new Point(818, 68); ButtonTakeOrderInWork.Name = "ButtonTakeOrderInWork"; ButtonTakeOrderInWork.Size = new Size(147, 33); ButtonTakeOrderInWork.TabIndex = 2; @@ -74,7 +77,7 @@ // // ButtonOrderReady // - ButtonOrderReady.Location = new Point(1087, 119); + ButtonOrderReady.Location = new Point(818, 107); ButtonOrderReady.Name = "ButtonOrderReady"; ButtonOrderReady.Size = new Size(147, 33); ButtonOrderReady.TabIndex = 3; @@ -84,7 +87,7 @@ // // ButtonIssuedOrder // - ButtonIssuedOrder.Location = new Point(1087, 158); + ButtonIssuedOrder.Location = new Point(818, 146); ButtonIssuedOrder.Name = "ButtonIssuedOrder"; ButtonIssuedOrder.Size = new Size(147, 33); ButtonIssuedOrder.TabIndex = 4; @@ -94,7 +97,7 @@ // // ButtonRef // - ButtonRef.Location = new Point(1087, 197); + ButtonRef.Location = new Point(818, 185); ButtonRef.Name = "ButtonRef"; ButtonRef.Size = new Size(147, 33); ButtonRef.TabIndex = 5; @@ -104,16 +107,16 @@ // // menuStrip // - menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem }); + menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem, othersToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(1265, 24); + menuStrip.Size = new Size(1014, 24); menuStrip.TabIndex = 6; menuStrip.Text = "menuStrip1"; // // toolStripMenuItem // - toolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, sushiToolStripMenuItem }); + toolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, sushiToolStripMenuItem, shopsToolStripMenuItem }); toolStripMenuItem.Name = "toolStripMenuItem"; toolStripMenuItem.Size = new Size(94, 20); toolStripMenuItem.Text = "Справочники"; @@ -121,22 +124,43 @@ // componentsToolStripMenuItem // componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; - componentsToolStripMenuItem.Size = new Size(145, 22); + componentsToolStripMenuItem.Size = new Size(180, 22); componentsToolStripMenuItem.Text = "Компоненты"; componentsToolStripMenuItem.Click += componentsToolStripMenuItem_Click; // // sushiToolStripMenuItem // sushiToolStripMenuItem.Name = "sushiToolStripMenuItem"; - sushiToolStripMenuItem.Size = new Size(145, 22); + sushiToolStripMenuItem.Size = new Size(180, 22); sushiToolStripMenuItem.Text = "Суши"; sushiToolStripMenuItem.Click += sushiToolStripMenuItem_Click; // + // shopsToolStripMenuItem + // + shopsToolStripMenuItem.Name = "shopsToolStripMenuItem"; + shopsToolStripMenuItem.Size = new Size(180, 22); + shopsToolStripMenuItem.Text = "Магазины"; + this.shopsToolStripMenuItem.Click += new System.EventHandler(this.shopsToolStripMenuItem_Click); + // + // othersToolStripMenuItem + // + othersToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { supplyToolStripMenuItem }); + othersToolStripMenuItem.Name = "othersToolStripMenuItem"; + othersToolStripMenuItem.Size = new Size(61, 20); + othersToolStripMenuItem.Text = "Прочее"; + // + // supplyToolStripMenuItem + // + supplyToolStripMenuItem.Name = "supplyToolStripMenuItem"; + supplyToolStripMenuItem.Size = new Size(198, 22); + supplyToolStripMenuItem.Text = "Пополнение магазина"; + this.supplyToolStripMenuItem.Click += new System.EventHandler(this.supplyToolStripMenuItem_Click); + // // FormMain // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1265, 337); + ClientSize = new Size(1014, 337); Controls.Add(ButtonRef); Controls.Add(ButtonIssuedOrder); Controls.Add(ButtonOrderReady); @@ -167,5 +191,8 @@ private ToolStripMenuItem toolStripMenuItem; private ToolStripMenuItem componentsToolStripMenuItem; private ToolStripMenuItem sushiToolStripMenuItem; + private ToolStripMenuItem shopsToolStripMenuItem; + private ToolStripMenuItem othersToolStripMenuItem; + private ToolStripMenuItem supplyToolStripMenuItem; } } \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormMain.cs b/SushiBar/SushiBarView/FormMain.cs index e5fb92c..71e7266 100644 --- a/SushiBar/SushiBarView/FormMain.cs +++ b/SushiBar/SushiBarView/FormMain.cs @@ -169,7 +169,7 @@ namespace SushiBarView } } - private void transactionToolStripMenuItem_Click(object sender, EventArgs e) + private void supplyToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormCreateSupply)); if (service is FormCreateSupply form) diff --git a/SushiBar/SushiBarView/FormShop.Designer.cs b/SushiBar/SushiBarView/FormShop.Designer.cs index a44fb47..d8ee7fa 100644 --- a/SushiBar/SushiBarView/FormShop.Designer.cs +++ b/SushiBar/SushiBarView/FormShop.Designer.cs @@ -28,12 +28,156 @@ /// 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 = "FormShop"; + ButtonSave = new Button(); + ButtonCancel = new Button(); + dataGridViewShop = new DataGridView(); + id = new DataGridViewTextBoxColumn(); + SushiName = new DataGridViewTextBoxColumn(); + SushiCount = new DataGridViewTextBoxColumn(); + labelName = new Label(); + labelAdress = new Label(); + labelOpenDate = new Label(); + textBoxName = new TextBox(); + textBoxAdress = new TextBox(); + dateTimeOpenShop = new DateTimePicker(); + ((System.ComponentModel.ISupportInitialize)dataGridViewShop).BeginInit(); + SuspendLayout(); + // + // ButtonSave + // + ButtonSave.Location = new Point(351, 381); + ButtonSave.Name = "ButtonSave"; + ButtonSave.Size = new Size(125, 45); + ButtonSave.TabIndex = 0; + ButtonSave.Text = "Сохранить"; + ButtonSave.UseVisualStyleBackColor = true; + ButtonSave.Click += ButtonSave_Click; + // + // ButtonCancel + // + ButtonCancel.Location = new Point(486, 381); + ButtonCancel.Name = "ButtonCancel"; + ButtonCancel.Size = new Size(125, 45); + ButtonCancel.TabIndex = 1; + ButtonCancel.Text = "Отмена"; + ButtonCancel.UseVisualStyleBackColor = true; + ButtonCancel.Click += ButtonCancel_Click; + // + // dataGridViewShop + // + dataGridViewShop.AllowUserToAddRows = false; + dataGridViewShop.AllowUserToDeleteRows = false; + dataGridViewShop.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewShop.BackgroundColor = SystemColors.Control; + dataGridViewShop.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewShop.Columns.AddRange(new DataGridViewColumn[] { id, SushiName, SushiCount }); + dataGridViewShop.GridColor = SystemColors.Control; + dataGridViewShop.Location = new Point(12, 135); + dataGridViewShop.Name = "dataGridViewShop"; + dataGridViewShop.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders; + dataGridViewShop.RowTemplate.Height = 25; + dataGridViewShop.Size = new Size(611, 240); + dataGridViewShop.TabIndex = 2; + // + // id + // + id.HeaderText = "id"; + id.Name = "id"; + id.Visible = false; + // + // SushiName + // + SushiName.HeaderText = "Суши"; + SushiName.Name = "SushiName"; + // + // SushiCount + // + SushiCount.HeaderText = "Количество"; + SushiCount.Name = "SushiCount"; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(23, 24); + labelName.Name = "labelName"; + labelName.Size = new Size(62, 15); + labelName.TabIndex = 3; + labelName.Text = "Название:"; + // + // labelAdress + // + labelAdress.AutoSize = true; + labelAdress.Location = new Point(23, 57); + labelAdress.Name = "labelAdress"; + labelAdress.Size = new Size(43, 15); + labelAdress.TabIndex = 4; + labelAdress.Text = "Адрес:"; + // + // labelOpenDate + // + labelOpenDate.AutoSize = true; + labelOpenDate.Location = new Point(23, 94); + labelOpenDate.Name = "labelOpenDate"; + labelOpenDate.Size = new Size(90, 15); + labelOpenDate.TabIndex = 5; + labelOpenDate.Text = "Дата открытия:"; + // + // textBoxName + // + textBoxName.Location = new Point(95, 21); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(491, 23); + textBoxName.TabIndex = 6; + // + // textBoxAdress + // + textBoxAdress.Location = new Point(95, 57); + textBoxAdress.Name = "textBoxAdress"; + textBoxAdress.Size = new Size(491, 23); + textBoxAdress.TabIndex = 7; + // + // dateTimeOpenShop + // + dateTimeOpenShop.Location = new Point(119, 94); + dateTimeOpenShop.Name = "dateTimeOpenShop"; + dateTimeOpenShop.Size = new Size(144, 23); + dateTimeOpenShop.TabIndex = 8; + // + // FormShop + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(635, 438); + Controls.Add(dateTimeOpenShop); + Controls.Add(textBoxAdress); + Controls.Add(textBoxName); + Controls.Add(labelOpenDate); + Controls.Add(labelAdress); + Controls.Add(labelName); + Controls.Add(dataGridViewShop); + Controls.Add(ButtonCancel); + Controls.Add(ButtonSave); + Name = "FormShop"; + Text = "Магазин"; + Load += FormShop_Load; + ((System.ComponentModel.ISupportInitialize)dataGridViewShop).EndInit(); + ResumeLayout(false); + PerformLayout(); } #endregion + + private Button ButtonSave; + private Button ButtonCancel; + private DataGridView dataGridViewShop; + private Label labelName; + private Label labelAdress; + private Label labelOpenDate; + private TextBox textBoxName; + private TextBox textBoxAdress; + private DateTimePicker dateTimeOpenShop; + private DataGridViewTextBoxColumn id; + private DataGridViewTextBoxColumn SushiName; + private DataGridViewTextBoxColumn SushiCount; } } \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormShop.cs b/SushiBar/SushiBarView/FormShop.cs index 2e494d3..350a710 100644 --- a/SushiBar/SushiBarView/FormShop.cs +++ b/SushiBar/SushiBarView/FormShop.cs @@ -47,7 +47,7 @@ namespace SushiBarView { textBoxName.Text = view.ShopName; textBoxAdress.Text = view.Adress; - dateTimeOpen.Value = view.OpeningDate; + dateTimeOpenShop.Value = view.OpeningDate; _ShopSushis = view.ShopSushis ?? new Dictionary(); LoadData(); } @@ -67,10 +67,10 @@ namespace SushiBarView { if (_ShopSushis != null) { - dataGridView.Rows.Clear(); + dataGridViewShop.Rows.Clear(); foreach (var sr in _ShopSushis) { - dataGridView.Rows.Add(new object[] { sr.Key, sr.Value.Item1.SushiName, sr.Value.Item2 }); + dataGridViewShop.Rows.Add(new object[] { sr.Key, sr.Value.Item1.SushiName, sr.Value.Item2 }); } } } @@ -81,7 +81,7 @@ namespace SushiBarView } } - private void buttonSave_Click(object sender, EventArgs e) + private void ButtonSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxName.Text)) { @@ -101,7 +101,7 @@ namespace SushiBarView Id = _id ?? 0, ShopName = textBoxName.Text, Adress = textBoxAdress.Text, - OpeningDate = dateTimeOpen.Value + OpeningDate = dateTimeOpenShop.Value }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) @@ -119,7 +119,7 @@ namespace SushiBarView } } - private void buttonCancel_Click(object sender, EventArgs e) + private void ButtonCancel_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; Close(); diff --git a/SushiBar/SushiBarView/FormShop.resx b/SushiBar/SushiBarView/FormShop.resx index 1af7de1..d7169e7 100644 --- a/SushiBar/SushiBarView/FormShop.resx +++ b/SushiBar/SushiBarView/FormShop.resx @@ -1,17 +1,17 @@  - @@ -117,4 +117,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + + + True + + + True + \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormShops.Designer.cs b/SushiBar/SushiBarView/FormShops.Designer.cs index c01f435..f05d474 100644 --- a/SushiBar/SushiBarView/FormShops.Designer.cs +++ b/SushiBar/SushiBarView/FormShops.Designer.cs @@ -28,12 +28,89 @@ /// 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 = "FormShops"; + dataGridViewShops = new DataGridView(); + buttonAdd = new Button(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonRef = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridViewShops).BeginInit(); + SuspendLayout(); + // + // dataGridViewShops + // + dataGridViewShops.AllowUserToAddRows = false; + dataGridViewShops.AllowUserToDeleteRows = false; + dataGridViewShops.BackgroundColor = SystemColors.Control; + dataGridViewShops.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewShops.Location = new Point(12, 12); + dataGridViewShops.Name = "dataGridViewShops"; + dataGridViewShops.RowTemplate.Height = 25; + dataGridViewShops.Size = new Size(501, 342); + dataGridViewShops.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(548, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(138, 38); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(548, 77); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(138, 38); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(548, 140); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(138, 38); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonRef + // + buttonRef.Location = new Point(548, 204); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(138, 38); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить список"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; + // + // FormShops + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(726, 366); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); + Controls.Add(buttonAdd); + Controls.Add(dataGridViewShops); + Name = "FormShops"; + Text = "Магазины"; + Load += FormShops_Load; + ((System.ComponentModel.ISupportInitialize)dataGridViewShops).EndInit(); + ResumeLayout(false); } #endregion + + private DataGridView dataGridViewShops; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; } } \ No newline at end of file diff --git a/SushiBar/SushiBarView/FormShops.cs b/SushiBar/SushiBarView/FormShops.cs index 7e899d2..f9dc365 100644 --- a/SushiBar/SushiBarView/FormShops.cs +++ b/SushiBar/SushiBarView/FormShops.cs @@ -37,10 +37,10 @@ namespace SushiBarView var list = _logic.ReadList(null); if (list != null) { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ShopSushis"].Visible = false; - dataGridView.Columns["ShopName"].AutoSizeMode = + dataGridViewShops.DataSource = list; + dataGridViewShops.Columns["Id"].Visible = false; + dataGridViewShops.Columns["ShopSushis"].Visible = false; + dataGridViewShops.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка магазинов"); @@ -66,12 +66,12 @@ namespace SushiBarView private void ButtonUpd_Click(object sender, EventArgs e) { - if (dataGridView.SelectedRows.Count == 1) + if (dataGridViewShops.SelectedRows.Count == 1) { var service = Program.ServiceProvider?.GetService(typeof(FormShop)); if (service is FormShop form) { - form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + form.Id = Convert.ToInt32(dataGridViewShops.SelectedRows[0].Cells["Id"].Value); if (form.ShowDialog() == DialogResult.OK) { LoadData(); @@ -82,11 +82,11 @@ namespace SushiBarView private void ButtonDel_Click(object sender, EventArgs e) { - if (dataGridView.SelectedRows.Count == 1) + if (dataGridViewShops.SelectedRows.Count == 1) { if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + int id = Convert.ToInt32(dataGridViewShops.SelectedRows[0].Cells["Id"].Value); _logger.LogInformation("Удаление магазина"); try { diff --git a/SushiBar/SushiBarView/FormShops.resx b/SushiBar/SushiBarView/FormShops.resx index 1af7de1..af32865 100644 --- a/SushiBar/SushiBarView/FormShops.resx +++ b/SushiBar/SushiBarView/FormShops.resx @@ -1,17 +1,17 @@  - -- 2.25.1 From 7ebab9fa4d760fe4315958dc0889d9ea36c3e2ef Mon Sep 17 00:00:00 2001 From: tellsense Date: Sun, 17 Mar 2024 11:08:16 +0400 Subject: [PATCH 3/3] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBarView/FormCreateSupply.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SushiBar/SushiBarView/FormCreateSupply.cs b/SushiBar/SushiBarView/FormCreateSupply.cs index a91cfe0..70fbd08 100644 --- a/SushiBar/SushiBarView/FormCreateSupply.cs +++ b/SushiBar/SushiBarView/FormCreateSupply.cs @@ -50,7 +50,7 @@ namespace SushiBarView comboBoxSushi.ValueMember = "Id"; comboBoxSushi.DataSource = _sushiList; comboBoxSushi.SelectedItem = null; - _logger.LogInformation("Загрузка пиццы для поставок"); + _logger.LogInformation("Загрузка суши для поставок"); } } -- 2.25.1