From de1f96bbe67ae7ee6003871c57274a6c6a14f000 Mon Sep 17 00:00:00 2001 From: antoc0der <1@DESKTOP-K1L8ND3> Date: Wed, 14 Feb 2024 21:27:41 +0300 Subject: [PATCH 01/12] =?UTF-8?q?=D1=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FlowerShopBusinessLogic/ShopLogic.cs | 135 +++++++++++++++++ .../BindingModels/ShopBindingModel.cs | 18 +++ .../BusinessLogicsContracts/IShopLogic.cs | 22 +++ .../SearchModels/ShopSearchModel.cs | 14 ++ .../StoragesContracts/IShopStorage.cs | 23 +++ .../ViewModels/ShopViewModel.cs | 22 +++ FlowerShopDataModels/IShopModel.cs | 16 ++ FlowerShopListImplement/DataListSingleton.cs | 2 + FlowerShopListImplement/Shop.cs | 55 +++++++ FlowerShopListImplement/ShopStorage.cs | 140 ++++++++++++++++++ 10 files changed, 447 insertions(+) create mode 100644 FlowerShopBusinessLogic/ShopLogic.cs create mode 100644 FlowerShopContracts/BindingModels/ShopBindingModel.cs create mode 100644 FlowerShopContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 FlowerShopContracts/SearchModels/ShopSearchModel.cs create mode 100644 FlowerShopContracts/StoragesContracts/IShopStorage.cs create mode 100644 FlowerShopContracts/ViewModels/ShopViewModel.cs create mode 100644 FlowerShopDataModels/IShopModel.cs create mode 100644 FlowerShopListImplement/Shop.cs create mode 100644 FlowerShopListImplement/ShopStorage.cs diff --git a/FlowerShopBusinessLogic/ShopLogic.cs b/FlowerShopBusinessLogic/ShopLogic.cs new file mode 100644 index 0000000..050e6ca --- /dev/null +++ b/FlowerShopBusinessLogic/ShopLogic.cs @@ -0,0 +1,135 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.StoragesContracts; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopBusinessLogic +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + private readonly IShopStorage _shopStorage; + + public ShopLogic(ILogger logger, IShopStorage shopStorage) + { + _logger = logger; + _shopStorage = shopStorage; + } + + public List ReadList(ShopSearchModel model) + { + _logger.LogInformation("ReadList. ShopName:{Name}. Id:{ Id}", model?.Name, 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 bool MakeSupply(ShopSearchModel model, IFlowerModel flower, int count) + { + if (model == null) + return false; + return _shopStorage.SupplyFlowers(model, flower, count); + } + + public ShopViewModel ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.Name, 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; + } + + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ShopName)) + { + throw new ArgumentNullException("Нет названия магазина", + nameof(model.ShopName)); + } + if (string.IsNullOrEmpty(model.Address)) + { + throw new ArgumentNullException("Нет адресса магазина", + nameof(model.ShopName)); + } + if (model.DateOpen == null) + { + throw new ArgumentNullException("Нет даты открытия магазина", + nameof(model.ShopName)); + } + _logger.LogInformation("Shop. ShopName:{ShopName}.Address:{Address}. DateOpen:{DateOpen}. Id: { Id}", model.ShopName, model.Address, model.DateOpen, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + Name = model.ShopName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + } +} diff --git a/FlowerShopContracts/BindingModels/ShopBindingModel.cs b/FlowerShopContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..9afd7ed --- /dev/null +++ b/FlowerShopContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,18 @@ +using FlowerShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + public string ShopName { get; set; } + public string Address { get; set; } + public DateTime DateOpen { get; set; } + public Dictionary ShopFlowers { get; set; } = new(); + } +} diff --git a/FlowerShopContracts/BusinessLogicsContracts/IShopLogic.cs b/FlowerShopContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..c9a8e57 --- /dev/null +++ b/FlowerShopContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,22 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.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(ShopSearchModel model, IFlowerModel flower, int count); + } +} diff --git a/FlowerShopContracts/SearchModels/ShopSearchModel.cs b/FlowerShopContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..8a99201 --- /dev/null +++ b/FlowerShopContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? Name { get; set; } + } +} diff --git a/FlowerShopContracts/StoragesContracts/IShopStorage.cs b/FlowerShopContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..de5a976 --- /dev/null +++ b/FlowerShopContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,23 @@ +using FlowerShopContracts.ViewModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.BindingModels; +using FlowerShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopContracts.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); + bool SupplyFlowers(ShopSearchModel model, IFlowerModel flower, int Count); + } +} diff --git a/FlowerShopContracts/ViewModels/ShopViewModel.cs b/FlowerShopContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..bb7556f --- /dev/null +++ b/FlowerShopContracts/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 FlowerShopDataModels.Models; + +namespace FlowerShopContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + [DisplayName("Название магазина")] + public string ShopName { get; set; } + [DisplayName("Адрес магазина")] + public string Address { get; set; } + [DisplayName("Дата открытия")] + public DateTime DateOpen { get; set; } + public Dictionary ShopFlowers { get; set; } = new(); + } +} diff --git a/FlowerShopDataModels/IShopModel.cs b/FlowerShopDataModels/IShopModel.cs new file mode 100644 index 0000000..54bba9f --- /dev/null +++ b/FlowerShopDataModels/IShopModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + string Address { get; } + DateTime DateOpen { get; } + Dictionary ShopFlowers { get; } + } +} diff --git a/FlowerShopListImplement/DataListSingleton.cs b/FlowerShopListImplement/DataListSingleton.cs index 117b155..92f37db 100644 --- a/FlowerShopListImplement/DataListSingleton.cs +++ b/FlowerShopListImplement/DataListSingleton.cs @@ -13,11 +13,13 @@ namespace FlowerShopListImplement public List Components { get; set; } public List Orders { get; set; } public List Flowers { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Flowers = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/FlowerShopListImplement/Shop.cs b/FlowerShopListImplement/Shop.cs new file mode 100644 index 0000000..e7bba4a --- /dev/null +++ b/FlowerShopListImplement/Shop.cs @@ -0,0 +1,55 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } + public string Address { get; private set; } + public DateTime DateOpen { get; private set; } + public Dictionary ShopFlowers { get; private set; } = new(); + + public static Shop? Create(ShopBindingModel model) + { + if (model == null) + return null; + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpen = model.DateOpen, + ShopFlowers = new() + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpen = model.DateOpen; + ShopFlowers = model.ShopFlowers; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpen = DateOpen, + ShopFlowers = ShopFlowers + }; + } +} diff --git a/FlowerShopListImplement/ShopStorage.cs b/FlowerShopListImplement/ShopStorage.cs new file mode 100644 index 0000000..77219a3 --- /dev/null +++ b/FlowerShopListImplement/ShopStorage.cs @@ -0,0 +1,140 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.StoragesContracts; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Models; +using FlowerShopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FlowerShopListImplement.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.Name)) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.ShopName.Contains(model.Name)) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.Name) && + shop.ShopName == model.Name) || + (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; + } + + public bool SupplyFlowers(ShopSearchModel model, IFlowerModel flower, int count) + { + if (model == null) + throw new ArgumentNullException(nameof(model)); + if (flower == null) + throw new ArgumentNullException(nameof(flower)); + if (count <= 0) + throw new ArgumentNullException("Количество должно быть положительным числом"); + + ShopViewModel curModel = GetElement(model); + if (curModel == null) + throw new ArgumentNullException(nameof(curModel)); + if (curModel.ShopFlowers.TryGetValue(flower.Id, out var pair)) + { + curModel.ShopFlowers[flower.Id] = (pair.Item1, pair.Item2 + count); + } + else + { + curModel.ShopFlowers.Add(flower.Id, (flower, count)); + } + Update(new() + { + Id = curModel.Id, + ShopName = curModel.ShopName, + DateOpen = curModel.DateOpen, + Address = curModel.Address, + ShopFlowers = curModel.ShopFlowers, + }); + return true; + } + } +} From 44adb1d84aa26f88be102858a8f26f0cf5bc9b70 Mon Sep 17 00:00:00 2001 From: antoc0der <1@DESKTOP-K1L8ND3> Date: Thu, 15 Feb 2024 19:18:46 +0300 Subject: [PATCH 02/12] =?UTF-8?q?=D0=BF=D0=BE=D0=BA=D0=B0=20=D0=BA=D1=82?= =?UTF-8?q?=D0=BE-=D1=82=D0=BE=20=D1=82=D0=B0=D0=BC,=20=D1=87=D1=82=D0=BE-?= =?UTF-8?q?=D1=82=D0=BE=20=D1=82=D0=B0=D0=BC,=20=D0=B3=D0=B4=D0=B5-=D1=82?= =?UTF-8?q?=D0=BE=20=D1=82=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectFlowerShop/ShopForm.Designer.cs | 133 +++++++++++++++++++++ ProjectFlowerShop/ShopForm.cs | 124 +++++++++++++++++++ ProjectFlowerShop/ShopForm.resx | 120 +++++++++++++++++++ ProjectFlowerShop/ShopsForm.Designer.cs | 114 ++++++++++++++++++ ProjectFlowerShop/ShopsForm.cs | 117 ++++++++++++++++++ ProjectFlowerShop/ShopsForm.resx | 120 +++++++++++++++++++ ProjectFlowerShop/SupplyForm.Designer.cs | 141 ++++++++++++++++++++++ ProjectFlowerShop/SupplyForm.cs | 146 +++++++++++++++++++++++ ProjectFlowerShop/SupplyForm.resx | 120 +++++++++++++++++++ 9 files changed, 1135 insertions(+) create mode 100644 ProjectFlowerShop/ShopForm.Designer.cs create mode 100644 ProjectFlowerShop/ShopForm.cs create mode 100644 ProjectFlowerShop/ShopForm.resx create mode 100644 ProjectFlowerShop/ShopsForm.Designer.cs create mode 100644 ProjectFlowerShop/ShopsForm.cs create mode 100644 ProjectFlowerShop/ShopsForm.resx create mode 100644 ProjectFlowerShop/SupplyForm.Designer.cs create mode 100644 ProjectFlowerShop/SupplyForm.cs create mode 100644 ProjectFlowerShop/SupplyForm.resx diff --git a/ProjectFlowerShop/ShopForm.Designer.cs b/ProjectFlowerShop/ShopForm.Designer.cs new file mode 100644 index 0000000..5378e5a --- /dev/null +++ b/ProjectFlowerShop/ShopForm.Designer.cs @@ -0,0 +1,133 @@ +namespace ProjectFlowerShop +{ + partial class ShopForm + { + /// + /// 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(); + buttonSave = new Button(); + buttonCancel = new Button(); + textBoxName = new TextBox(); + textBoxAddress = new TextBox(); + labelName = new Label(); + labelAddress = new Label(); + ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + SuspendLayout(); + // + // DataGridView + // + DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + DataGridView.Location = new Point(21, 12); + DataGridView.Name = "DataGridView"; + DataGridView.RowHeadersWidth = 51; + DataGridView.RowTemplate.Height = 29; + DataGridView.Size = new Size(397, 305); + DataGridView.TabIndex = 0; + // + // buttonSave + // + buttonSave.Location = new Point(424, 288); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(123, 29); + buttonSave.TabIndex = 1; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(553, 288); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(116, 29); + buttonCancel.TabIndex = 2; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // textBoxName + // + textBoxName.Location = new Point(424, 34); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(245, 27); + textBoxName.TabIndex = 3; + // + // textBoxAddress + // + textBoxAddress.Location = new Point(424, 95); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(245, 27); + textBoxAddress.TabIndex = 4; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(424, 12); + labelName.Name = "labelName"; + labelName.Size = new Size(77, 20); + labelName.TabIndex = 5; + labelName.Text = "Название"; + // + // labelAddress + // + labelAddress.AutoSize = true; + labelAddress.Location = new Point(424, 72); + labelAddress.Name = "labelAddress"; + labelAddress.Size = new Size(51, 20); + labelAddress.TabIndex = 6; + labelAddress.Text = "Адрес"; + // + // ShopForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(681, 329); + Controls.Add(labelAddress); + Controls.Add(labelName); + Controls.Add(textBoxAddress); + Controls.Add(textBoxName); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(DataGridView); + Name = "ShopForm"; + Text = "ShopForm"; + Load += ShopForm_Load; + ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private DataGridView DataGridView; + private Button buttonSave; + private Button buttonCancel; + private TextBox textBoxName; + private TextBox textBoxAddress; + private Label labelName; + private Label labelAddress; + } +} \ No newline at end of file diff --git a/ProjectFlowerShop/ShopForm.cs b/ProjectFlowerShop/ShopForm.cs new file mode 100644 index 0000000..90f1a02 --- /dev/null +++ b/ProjectFlowerShop/ShopForm.cs @@ -0,0 +1,124 @@ +using FlowerShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using FlowerShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; + + +namespace ProjectFlowerShop +{ + public partial class ShopForm : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public int? _id; + private Dictionary _flowers; + public ShopForm(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void LoadData() + { + _logger.LogInformation("Загрузка товаров магазина"); + try + { + if (_flowers != null) + { + foreach (var flower in _flowers) + { + DataGridView.Rows.Add(new object[] { flower.Key, flower.Value.Item1.FlowerName, flower.Value.Item1.Price, flower.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(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Address = textBoxAddress.Text, + DateOpen = DateTimePicker.Value.Date, + ShopFlowers = _flowers + }; + 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(); + } + + private void ShopForm_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var shop = _logic.ReadElement(new ShopSearchModel { Id = _id }); + if (shop != null) + { + textBoxName.Text = shop.ShopName; + textBoxAddress.Text = shop.Address; + DateTimePicker.Text = shop.DateOpen.ToString(); + _flowers = shop.ShopFlowers; + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + } +} diff --git a/ProjectFlowerShop/ShopForm.resx b/ProjectFlowerShop/ShopForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectFlowerShop/ShopForm.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/ProjectFlowerShop/ShopsForm.Designer.cs b/ProjectFlowerShop/ShopsForm.Designer.cs new file mode 100644 index 0000000..431686d --- /dev/null +++ b/ProjectFlowerShop/ShopsForm.Designer.cs @@ -0,0 +1,114 @@ +namespace ProjectFlowerShop +{ + partial class ShopsForm + { + /// + /// 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(); + buttonAdd = new Button(); + buttonChange = new Button(); + buttonRemove = new Button(); + buttonRefresh = new Button(); + ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + SuspendLayout(); + // + // DataGridView + // + DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + DataGridView.Location = new Point(12, 12); + DataGridView.Name = "DataGridView"; + DataGridView.RowHeadersWidth = 51; + DataGridView.RowTemplate.Height = 29; + DataGridView.Size = new Size(531, 426); + DataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(549, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(239, 36); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonChange + // + buttonChange.Location = new Point(549, 54); + buttonChange.Name = "buttonChange"; + buttonChange.Size = new Size(239, 36); + buttonChange.TabIndex = 2; + buttonChange.Text = "Изменить"; + buttonChange.UseVisualStyleBackColor = true; + buttonChange.Click += buttonChange_Click; + // + // buttonRemove + // + buttonRemove.Location = new Point(549, 96); + buttonRemove.Name = "buttonRemove"; + buttonRemove.Size = new Size(239, 36); + buttonRemove.TabIndex = 3; + buttonRemove.Text = "Удалить"; + buttonRemove.UseVisualStyleBackColor = true; + buttonRemove.Click += buttonRemove_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(549, 138); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(239, 36); + buttonRefresh.TabIndex = 4; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // ShopsForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonRefresh); + Controls.Add(buttonRemove); + Controls.Add(buttonChange); + Controls.Add(buttonAdd); + Controls.Add(DataGridView); + Name = "ShopsForm"; + Text = "ShopsForm"; + Load += ShopsForm_Load; + ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView DataGridView; + private Button buttonAdd; + private Button buttonChange; + private Button buttonRemove; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/ProjectFlowerShop/ShopsForm.cs b/ProjectFlowerShop/ShopsForm.cs new file mode 100644 index 0000000..4832033 --- /dev/null +++ b/ProjectFlowerShop/ShopsForm.cs @@ -0,0 +1,117 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ProjectFlowerShop +{ + public partial class ShopsForm : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public ShopsForm(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + DataGridView.DataSource = list; + DataGridView.Columns["Id"].Visible = false; + DataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["Address"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["DateOpen"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + DataGridView.Columns["ShopFlowers"].Visible = false; + } + _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(ShopForm)); + if (service is ShopForm form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ShopsForm_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void buttonChange_Click(object sender, EventArgs e) + { + if (DataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(ShopForm)); + if (service is ShopForm form) + { + var tmp = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + form._id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void buttonRemove_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 buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/ProjectFlowerShop/ShopsForm.resx b/ProjectFlowerShop/ShopsForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectFlowerShop/ShopsForm.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/ProjectFlowerShop/SupplyForm.Designer.cs b/ProjectFlowerShop/SupplyForm.Designer.cs new file mode 100644 index 0000000..87d9587 --- /dev/null +++ b/ProjectFlowerShop/SupplyForm.Designer.cs @@ -0,0 +1,141 @@ +namespace ProjectFlowerShop +{ + partial class SupplyForm + { + /// + /// 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() + { + buttonSave = new Button(); + buttonCancel = new Button(); + labelShop = new Label(); + labelFlower = new Label(); + labelNumber = new Label(); + comboBoxShop = new ComboBox(); + comboBoxFlower = new ComboBox(); + textBoxNumber = new TextBox(); + SuspendLayout(); + // + // buttonSave + // + buttonSave.Location = new Point(195, 186); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(111, 29); + buttonSave.TabIndex = 0; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(312, 186); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(108, 29); + buttonCancel.TabIndex = 1; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // labelShop + // + labelShop.AutoSize = true; + labelShop.Location = new Point(12, 13); + labelShop.Name = "labelShop"; + labelShop.Size = new Size(69, 20); + labelShop.TabIndex = 2; + labelShop.Text = "Магазин"; + // + // labelFlower + // + labelFlower.AutoSize = true; + labelFlower.Location = new Point(12, 67); + labelFlower.Name = "labelFlower"; + labelFlower.Size = new Size(53, 20); + labelFlower.TabIndex = 3; + labelFlower.Text = "Цветы"; + // + // labelNumber + // + labelNumber.AutoSize = true; + labelNumber.Location = new Point(12, 121); + labelNumber.Name = "labelNumber"; + labelNumber.Size = new Size(90, 20); + labelNumber.TabIndex = 4; + labelNumber.Text = "Количество"; + // + // comboBoxShop + // + comboBoxShop.FormattingEnabled = true; + comboBoxShop.Location = new Point(12, 36); + comboBoxShop.Name = "comboBoxShop"; + comboBoxShop.Size = new Size(294, 28); + comboBoxShop.TabIndex = 5; + // + // comboBoxFlower + // + comboBoxFlower.FormattingEnabled = true; + comboBoxFlower.Location = new Point(12, 90); + comboBoxFlower.Name = "comboBoxFlower"; + comboBoxFlower.Size = new Size(294, 28); + comboBoxFlower.TabIndex = 6; + // + // textBoxNumber + // + textBoxNumber.Location = new Point(12, 144); + textBoxNumber.Name = "textBoxNumber"; + textBoxNumber.Size = new Size(151, 27); + textBoxNumber.TabIndex = 7; + // + // SupplyForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(430, 227); + Controls.Add(textBoxNumber); + Controls.Add(comboBoxFlower); + Controls.Add(comboBoxShop); + Controls.Add(labelNumber); + Controls.Add(labelFlower); + Controls.Add(labelShop); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Name = "SupplyForm"; + Text = "SupplyForm"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private Label labelShop; + private Label labelFlower; + private Label labelNumber; + private ComboBox comboBoxShop; + private ComboBox comboBoxFlower; + private TextBox textBoxNumber; + } +} \ No newline at end of file diff --git a/ProjectFlowerShop/SupplyForm.cs b/ProjectFlowerShop/SupplyForm.cs new file mode 100644 index 0000000..e1e647e --- /dev/null +++ b/ProjectFlowerShop/SupplyForm.cs @@ -0,0 +1,146 @@ +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ProjectFlowerShop +{ + public partial class SupplyForm : Form + { + private readonly List? _flowerList; + private readonly List? _shopsList; + IShopLogic _shopLogic; + IFlowerLogic _flowerLogic; + public SupplyForm(IFlowerLogic flowerLogic, IShopLogic shopLogic) + { + InitializeComponent(); + _shopLogic = shopLogic; + _flowerLogic = flowerLogic; + _flowerList = flowerLogic.ReadList(null); + _shopsList = shopLogic.ReadList(null); + if (_flowerList != null) + { + comboBoxFlower.DisplayMember = "FlowerName"; + comboBoxFlower.ValueMember = "Id"; + comboBoxFlower.DataSource = _flowerList; + comboBoxFlower.SelectedItem = null; + } + if (_shopsList != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = _shopsList; + comboBoxShop.SelectedItem = null; + } + } + public int ShopId + { + get + { + return Convert.ToInt32(comboBoxShop.SelectedValue); + } + set + { + comboBoxShop.SelectedValue = value; + } + } + + public int FlowerId + { + get + { + return Convert.ToInt32(comboBoxFlower.SelectedValue); + } + set + { + comboBoxFlower.SelectedValue = value; + } + } + + public IFlowerModel? FlowerModel + { + get + { + if (_flowerList == null) + { + return null; + } + foreach (var elem in _flowerList) + { + if (elem.Id == FlowerId) + { + return elem; + } + } + return null; + } + } + public int Number + { + get { return Convert.ToInt32(textBoxNumber.Text); } + set { textBoxNumber.Text = value.ToString(); } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxNumber.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxFlower.SelectedValue == null) + { + MessageBox.Show("Выберите цветы", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + int count = Convert.ToInt32(textBoxNumber.Text); + + bool res = _shopLogic.MakeSupply( + new ShopSearchModel() { Id = Convert.ToInt32(comboBoxShop.SelectedValue) }, + _flowerLogic.ReadElement(new() { Id = Convert.ToInt32(comboBoxFlower.SelectedValue) }), + count + ); + + if (!res) + { + throw new Exception("Ошибка при пополнении. Дополнительная информация в логах"); + } + + MessageBox.Show("Пополнение прошло успешно"); + DialogResult = DialogResult.OK; + Close(); + + } + catch (Exception err) + { + MessageBox.Show("Ошибка пополнения"); + return; + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/ProjectFlowerShop/SupplyForm.resx b/ProjectFlowerShop/SupplyForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectFlowerShop/SupplyForm.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 From 2385ba168a831756d24e1c7a4b928a62f62a27d0 Mon Sep 17 00:00:00 2001 From: antoc0der <1@DESKTOP-K1L8ND3> Date: Thu, 15 Feb 2024 19:22:45 +0300 Subject: [PATCH 03/12] =?UTF-8?q?=D0=BD=D0=BE=D1=80=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectFlowerShop/Program.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ProjectFlowerShop/Program.cs b/ProjectFlowerShop/Program.cs index d423dcb..320cfed 100644 --- a/ProjectFlowerShop/Program.cs +++ b/ProjectFlowerShop/Program.cs @@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; using System; using System.Drawing; +using FlowerShopBusinessLogic; namespace ProjectFlowerShop { @@ -40,6 +41,8 @@ namespace ProjectFlowerShop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -47,6 +50,9 @@ namespace ProjectFlowerShop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } From 05dc9185d60811934b5827fc44c25cc2b2989f36 Mon Sep 17 00:00:00 2001 From: antoc0der <1@DESKTOP-K1L8ND3> Date: Thu, 15 Feb 2024 21:38:10 +0300 Subject: [PATCH 04/12] =?UTF-8?q?=D0=BA=D1=82=D0=BE=20=D0=BF=D0=BE=D0=B2?= =?UTF-8?q?=D0=B5=D0=B4=D0=B0=D0=BB=20=D0=BF=D1=80=D0=BE=20=D0=B3=D1=80?= =?UTF-8?q?=D0=B0=D0=B9=D0=BC=20=D0=B8=20=D0=B4=D0=B0=D0=B1=D1=81=D1=82?= =?UTF-8?q?=D0=B5=D0=BF=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectFlowerShop/ShopForm.Designer.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ProjectFlowerShop/ShopForm.Designer.cs b/ProjectFlowerShop/ShopForm.Designer.cs index 5378e5a..a9b799c 100644 --- a/ProjectFlowerShop/ShopForm.Designer.cs +++ b/ProjectFlowerShop/ShopForm.Designer.cs @@ -35,6 +35,8 @@ textBoxAddress = new TextBox(); labelName = new Label(); labelAddress = new Label(); + DateTimePicker = new DateTimePicker(); + labelDate = new Label(); ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); SuspendLayout(); // @@ -100,11 +102,29 @@ labelAddress.TabIndex = 6; labelAddress.Text = "Адрес"; // + // DateTimePicker + // + DateTimePicker.Location = new Point(424, 148); + DateTimePicker.Name = "DateTimePicker"; + DateTimePicker.Size = new Size(245, 27); + DateTimePicker.TabIndex = 7; + // + // labelDate + // + labelDate.AutoSize = true; + labelDate.Location = new Point(424, 125); + labelDate.Name = "labelDate"; + labelDate.Size = new Size(41, 20); + labelDate.TabIndex = 8; + labelDate.Text = "Дата"; + // // ShopForm // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(681, 329); + Controls.Add(labelDate); + Controls.Add(DateTimePicker); Controls.Add(labelAddress); Controls.Add(labelName); Controls.Add(textBoxAddress); @@ -129,5 +149,7 @@ private TextBox textBoxAddress; private Label labelName; private Label labelAddress; + private DateTimePicker DateTimePicker; + private Label labelDate; } } \ No newline at end of file From d1dff985e1ce813ec76e6c8ad1c2873e6311669f Mon Sep 17 00:00:00 2001 From: antoc0der <1@DESKTOP-K1L8ND3> Date: Tue, 27 Feb 2024 13:05:58 +0300 Subject: [PATCH 05/12] null --- ...ormProduct.Designer.cs => FormFlower.Designer.cs} | 2 +- ProjectFlowerShop/{FormProduct.cs => FormFlower.cs} | 12 ++++++------ .../{FormProduct.resx => FormFlower.resx} | 0 ...t.Designer.cs => FormFlowerComponent.Designer.cs} | 2 +- ...ormProductComponent.cs => FormFlowerComponent.cs} | 4 ++-- ...roductComponent.resx => FormFlowerComponent.resx} | 0 ProjectFlowerShop/FormFlowers.cs | 8 ++++---- ProjectFlowerShop/Program.cs | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) rename ProjectFlowerShop/{FormProduct.Designer.cs => FormFlower.Designer.cs} (99%) rename ProjectFlowerShop/{FormProduct.cs => FormFlower.cs} (96%) rename ProjectFlowerShop/{FormProduct.resx => FormFlower.resx} (100%) rename ProjectFlowerShop/{FormProductComponent.Designer.cs => FormFlowerComponent.Designer.cs} (99%) rename ProjectFlowerShop/{FormProductComponent.cs => FormFlowerComponent.cs} (95%) rename ProjectFlowerShop/{FormProductComponent.resx => FormFlowerComponent.resx} (100%) diff --git a/ProjectFlowerShop/FormProduct.Designer.cs b/ProjectFlowerShop/FormFlower.Designer.cs similarity index 99% rename from ProjectFlowerShop/FormProduct.Designer.cs rename to ProjectFlowerShop/FormFlower.Designer.cs index 1d8f653..aa3790a 100644 --- a/ProjectFlowerShop/FormProduct.Designer.cs +++ b/ProjectFlowerShop/FormFlower.Designer.cs @@ -1,6 +1,6 @@ namespace ProjectFlowerShop { - partial class FormProduct + partial class FormFlower { /// /// Required designer variable. diff --git a/ProjectFlowerShop/FormProduct.cs b/ProjectFlowerShop/FormFlower.cs similarity index 96% rename from ProjectFlowerShop/FormProduct.cs rename to ProjectFlowerShop/FormFlower.cs index abc08d3..40ad362 100644 --- a/ProjectFlowerShop/FormProduct.cs +++ b/ProjectFlowerShop/FormFlower.cs @@ -15,7 +15,7 @@ using System.Windows.Forms; namespace ProjectFlowerShop { - public partial class FormProduct : Form + public partial class FormFlower : Form { private readonly ILogger _logger; private readonly IFlowerLogic _logic; @@ -23,7 +23,7 @@ namespace ProjectFlowerShop private Dictionary _flowerComponents; public int Id { set { _id = value; } } - public FormProduct(ILogger logger, IFlowerLogic logic) + public FormFlower(ILogger logger, IFlowerLogic logic) { InitializeComponent(); _logger = logger; @@ -95,8 +95,8 @@ namespace ProjectFlowerShop private void buttonAdd_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormProductComponent)); - if (service is FormProductComponent form) + var service = Program.ServiceProvider?.GetService(typeof(FormFlowerComponent)); + if (service is FormFlowerComponent form) { if (form.ShowDialog() == DialogResult.OK) { @@ -124,8 +124,8 @@ namespace ProjectFlowerShop if (dataGridView.SelectedRows.Count == 1) { var service = - Program.ServiceProvider?.GetService(typeof(FormProductComponent)); - if (service is FormProductComponent form) + Program.ServiceProvider?.GetService(typeof(FormFlowerComponent)); + if (service is FormFlowerComponent form) { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); diff --git a/ProjectFlowerShop/FormProduct.resx b/ProjectFlowerShop/FormFlower.resx similarity index 100% rename from ProjectFlowerShop/FormProduct.resx rename to ProjectFlowerShop/FormFlower.resx diff --git a/ProjectFlowerShop/FormProductComponent.Designer.cs b/ProjectFlowerShop/FormFlowerComponent.Designer.cs similarity index 99% rename from ProjectFlowerShop/FormProductComponent.Designer.cs rename to ProjectFlowerShop/FormFlowerComponent.Designer.cs index 807a79e..8e3378b 100644 --- a/ProjectFlowerShop/FormProductComponent.Designer.cs +++ b/ProjectFlowerShop/FormFlowerComponent.Designer.cs @@ -1,6 +1,6 @@ namespace ProjectFlowerShop { - partial class FormProductComponent + partial class FormFlowerComponent { /// /// Required designer variable. diff --git a/ProjectFlowerShop/FormProductComponent.cs b/ProjectFlowerShop/FormFlowerComponent.cs similarity index 95% rename from ProjectFlowerShop/FormProductComponent.cs rename to ProjectFlowerShop/FormFlowerComponent.cs index cafef61..697ece2 100644 --- a/ProjectFlowerShop/FormProductComponent.cs +++ b/ProjectFlowerShop/FormFlowerComponent.cs @@ -13,7 +13,7 @@ using System.Windows.Forms; namespace ProjectFlowerShop { - public partial class FormProductComponent : Form + public partial class FormFlowerComponent : Form { private readonly List? _list; public int Id @@ -52,7 +52,7 @@ namespace ProjectFlowerShop set { textBoxNumber.Text = value.ToString(); } } - public FormProductComponent(IComponentLogic logic) + public FormFlowerComponent(IComponentLogic logic) { InitializeComponent(); _list = logic.ReadList(null); diff --git a/ProjectFlowerShop/FormProductComponent.resx b/ProjectFlowerShop/FormFlowerComponent.resx similarity index 100% rename from ProjectFlowerShop/FormProductComponent.resx rename to ProjectFlowerShop/FormFlowerComponent.resx diff --git a/ProjectFlowerShop/FormFlowers.cs b/ProjectFlowerShop/FormFlowers.cs index 5d5b18c..49c1b87 100644 --- a/ProjectFlowerShop/FormFlowers.cs +++ b/ProjectFlowerShop/FormFlowers.cs @@ -53,8 +53,8 @@ namespace ProjectFlowerShop private void AddButton_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(FormProduct)); - if (service is FormProduct form) + var service = Program.ServiceProvider?.GetService(typeof(FormFlower)); + if (service is FormFlower form) { if (form.ShowDialog() == DialogResult.OK) { @@ -67,8 +67,8 @@ namespace ProjectFlowerShop { if (DataGridView.SelectedRows.Count == 1) { - var service = Program.ServiceProvider?.GetService(typeof(FormProduct)); - if (service is FormProduct form) + var service = Program.ServiceProvider?.GetService(typeof(FormFlower)); + if (service is FormFlower form) { var tmp = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value); diff --git a/ProjectFlowerShop/Program.cs b/ProjectFlowerShop/Program.cs index 320cfed..d9210a5 100644 --- a/ProjectFlowerShop/Program.cs +++ b/ProjectFlowerShop/Program.cs @@ -47,8 +47,8 @@ namespace ProjectFlowerShop services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); From 66a55b2d903b149624878b7e62ae30398887e25d Mon Sep 17 00:00:00 2001 From: antoc0der <1@DESKTOP-K1L8ND3> Date: Wed, 28 Feb 2024 15:39:48 +0300 Subject: [PATCH 06/12] aaaaaaaaaaa --- FlowerShopBusinessLogic/ShopLogic.cs | 33 ++++++++++++++- .../StoragesContracts/IShopStorage.cs | 2 +- FlowerShopListImplement/ShopStorage.cs | 30 -------------- ProjectFlowerShop/MainForm.Designer.cs | 20 +++++++++- ProjectFlowerShop/MainForm.cs | 19 +++++++++ ProjectFlowerShop/ShopForm.Designer.cs | 40 ++++++++++++++++++- ProjectFlowerShop/ShopForm.resx | 12 ++++++ 7 files changed, 122 insertions(+), 34 deletions(-) diff --git a/FlowerShopBusinessLogic/ShopLogic.cs b/FlowerShopBusinessLogic/ShopLogic.cs index 050e6ca..e22e00b 100644 --- a/FlowerShopBusinessLogic/ShopLogic.cs +++ b/FlowerShopBusinessLogic/ShopLogic.cs @@ -43,7 +43,7 @@ namespace FlowerShopBusinessLogic { if (model == null) return false; - return _shopStorage.SupplyFlowers(model, flower, count); + return SupplyFlowers(model, flower, count); } public ShopViewModel ReadElement(ShopSearchModel model) @@ -131,5 +131,36 @@ namespace FlowerShopBusinessLogic throw new InvalidOperationException("Магазин с таким названием уже есть"); } } + + public bool SupplyFlowers(ShopSearchModel model, IFlowerModel flower, int count) + { + if (model == null) + throw new ArgumentNullException(nameof(model)); + if (flower == null) + throw new ArgumentNullException(nameof(flower)); + if (count <= 0) + throw new ArgumentNullException("Количество должно быть положительным числом"); + + var curModel = _shopStorage.GetElement(model); + if (curModel == null) + throw new ArgumentNullException(nameof(curModel)); + if (curModel.ShopFlowers.TryGetValue(flower.Id, out var pair)) + { + curModel.ShopFlowers[flower.Id] = (pair.Item1, pair.Item2 + count); + } + else + { + curModel.ShopFlowers.Add(flower.Id, (flower, count)); + } + Update(new() + { + Id = curModel.Id, + ShopName = curModel.ShopName, + DateOpen = curModel.DateOpen, + Address = curModel.Address, + ShopFlowers = curModel.ShopFlowers, + }); + return true; + } } } diff --git a/FlowerShopContracts/StoragesContracts/IShopStorage.cs b/FlowerShopContracts/StoragesContracts/IShopStorage.cs index de5a976..122a79f 100644 --- a/FlowerShopContracts/StoragesContracts/IShopStorage.cs +++ b/FlowerShopContracts/StoragesContracts/IShopStorage.cs @@ -18,6 +18,6 @@ namespace FlowerShopContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); - bool SupplyFlowers(ShopSearchModel model, IFlowerModel flower, int Count); + //bool SupplyFlowers(ShopSearchModel model, IFlowerModel flower, int Count); } } diff --git a/FlowerShopListImplement/ShopStorage.cs b/FlowerShopListImplement/ShopStorage.cs index 77219a3..a97253b 100644 --- a/FlowerShopListImplement/ShopStorage.cs +++ b/FlowerShopListImplement/ShopStorage.cs @@ -106,35 +106,5 @@ namespace FlowerShopListImplement.Implements return null; } - public bool SupplyFlowers(ShopSearchModel model, IFlowerModel flower, int count) - { - if (model == null) - throw new ArgumentNullException(nameof(model)); - if (flower == null) - throw new ArgumentNullException(nameof(flower)); - if (count <= 0) - throw new ArgumentNullException("Количество должно быть положительным числом"); - - ShopViewModel curModel = GetElement(model); - if (curModel == null) - throw new ArgumentNullException(nameof(curModel)); - if (curModel.ShopFlowers.TryGetValue(flower.Id, out var pair)) - { - curModel.ShopFlowers[flower.Id] = (pair.Item1, pair.Item2 + count); - } - else - { - curModel.ShopFlowers.Add(flower.Id, (flower, count)); - } - Update(new() - { - Id = curModel.Id, - ShopName = curModel.ShopName, - DateOpen = curModel.DateOpen, - Address = curModel.Address, - ShopFlowers = curModel.ShopFlowers, - }); - return true; - } } } diff --git a/ProjectFlowerShop/MainForm.Designer.cs b/ProjectFlowerShop/MainForm.Designer.cs index 56eb0e9..40db63c 100644 --- a/ProjectFlowerShop/MainForm.Designer.cs +++ b/ProjectFlowerShop/MainForm.Designer.cs @@ -32,6 +32,8 @@ ToolStripMenu = new ToolStripMenuItem(); КомпонентыStripMenuItem = new ToolStripMenuItem(); ЦветыStripMenuItem = new ToolStripMenuItem(); + магазиныToolStripMenuItem = new ToolStripMenuItem(); + поставкиToolStripMenuItem = new ToolStripMenuItem(); DataGridView = new DataGridView(); CreateOrderButton = new Button(); TakeInWorkButton = new Button(); @@ -54,7 +56,7 @@ // // ToolStripMenu // - ToolStripMenu.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыStripMenuItem, ЦветыStripMenuItem }); + ToolStripMenu.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыStripMenuItem, ЦветыStripMenuItem, магазиныToolStripMenuItem, поставкиToolStripMenuItem }); ToolStripMenu.Name = "ToolStripMenu"; ToolStripMenu.Size = new Size(117, 24); ToolStripMenu.Text = "Справочники"; @@ -73,6 +75,20 @@ ЦветыStripMenuItem.Text = "Цветы"; ЦветыStripMenuItem.Click += ЦветыStripMenuItem_Click; // + // магазиныToolStripMenuItem + // + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(224, 26); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click; + // + // поставкиToolStripMenuItem + // + поставкиToolStripMenuItem.Name = "поставкиToolStripMenuItem"; + поставкиToolStripMenuItem.Size = new Size(224, 26); + поставкиToolStripMenuItem.Text = "Поставки"; + поставкиToolStripMenuItem.Click += поставкиToolStripMenuItem_Click; + // // DataGridView // DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -167,5 +183,7 @@ private Button ReadyButton; private Button IssuedButton; private Button RefreshButton; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem поставкиToolStripMenuItem; } } \ No newline at end of file diff --git a/ProjectFlowerShop/MainForm.cs b/ProjectFlowerShop/MainForm.cs index 5d70efb..cc1bea1 100644 --- a/ProjectFlowerShop/MainForm.cs +++ b/ProjectFlowerShop/MainForm.cs @@ -37,6 +37,7 @@ namespace ProjectFlowerShop } + private void MainForm_Load(object sender, EventArgs e) { LoadData(); @@ -179,5 +180,23 @@ namespace ProjectFlowerShop { LoadData(); } + + private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(ShopsForm)); + if (service is ShopsForm form) + { + form.ShowDialog(); + } + } + + private void поставкиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(SupplyForm)); + if (service is SupplyForm form) + { + form.ShowDialog(); + } + } } } diff --git a/ProjectFlowerShop/ShopForm.Designer.cs b/ProjectFlowerShop/ShopForm.Designer.cs index a9b799c..ffdac20 100644 --- a/ProjectFlowerShop/ShopForm.Designer.cs +++ b/ProjectFlowerShop/ShopForm.Designer.cs @@ -37,12 +37,17 @@ labelAddress = new Label(); DateTimePicker = new DateTimePicker(); labelDate = new Label(); + ColumnID = new DataGridViewTextBoxColumn(); + Name = new DataGridViewTextBoxColumn(); + Price = new DataGridViewTextBoxColumn(); + Number = new DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); SuspendLayout(); // // DataGridView // DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + DataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnID, Name, Price, Number }); DataGridView.Location = new Point(21, 12); DataGridView.Name = "DataGridView"; DataGridView.RowHeadersWidth = 51; @@ -118,6 +123,35 @@ labelDate.TabIndex = 8; labelDate.Text = "Дата"; // + // ColumnID + // + ColumnID.HeaderText = "ColumnID"; + ColumnID.MinimumWidth = 6; + ColumnID.Name = "ColumnID"; + ColumnID.Visible = false; + ColumnID.Width = 125; + // + // Name + // + Name.HeaderText = "Название"; + Name.MinimumWidth = 6; + Name.Name = "Name"; + Name.Width = 125; + // + // Price + // + Price.HeaderText = "Цена"; + Price.MinimumWidth = 6; + Price.Name = "Price"; + Price.Width = 125; + // + // Number + // + Number.HeaderText = "Количество"; + Number.MinimumWidth = 6; + Number.Name = "Number"; + Number.Width = 125; + // // ShopForm // AutoScaleDimensions = new SizeF(8F, 20F); @@ -132,7 +166,7 @@ Controls.Add(buttonCancel); Controls.Add(buttonSave); Controls.Add(DataGridView); - Name = "ShopForm"; + //Name = "ShopForm"; Text = "ShopForm"; Load += ShopForm_Load; ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); @@ -151,5 +185,9 @@ private Label labelAddress; private DateTimePicker DateTimePicker; private Label labelDate; + private DataGridViewTextBoxColumn ColumnID; + private DataGridViewTextBoxColumn Name; + private DataGridViewTextBoxColumn Price; + private DataGridViewTextBoxColumn Number; } } \ No newline at end of file diff --git a/ProjectFlowerShop/ShopForm.resx b/ProjectFlowerShop/ShopForm.resx index af32865..e4ea5ef 100644 --- a/ProjectFlowerShop/ShopForm.resx +++ b/ProjectFlowerShop/ShopForm.resx @@ -117,4 +117,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + + + True + + + True + + + True + \ No newline at end of file From 0f24ed319f961b79e41f55b164b4045be88c29ec Mon Sep 17 00:00:00 2001 From: antoc0der <1@DESKTOP-K1L8ND3> Date: Fri, 1 Mar 2024 22:42:42 +0400 Subject: [PATCH 07/12] freee tato --- FlowerShopBusinessLogic/ShopLogic.cs | 59 ++++++++----------- .../StoragesContracts/IShopStorage.cs | 1 - 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/FlowerShopBusinessLogic/ShopLogic.cs b/FlowerShopBusinessLogic/ShopLogic.cs index e22e00b..9e064d1 100644 --- a/FlowerShopBusinessLogic/ShopLogic.cs +++ b/FlowerShopBusinessLogic/ShopLogic.cs @@ -42,8 +42,32 @@ namespace FlowerShopBusinessLogic public bool MakeSupply(ShopSearchModel model, IFlowerModel flower, int count) { if (model == null) - return false; - return SupplyFlowers(model, flower, count); + throw new ArgumentNullException(nameof(model)); + if (flower == null) + throw new ArgumentNullException(nameof(flower)); + if (count <= 0) + throw new ArgumentNullException("Количество должно быть положительным числом"); + + var curModel = _shopStorage.GetElement(model); + if (curModel == null) + throw new ArgumentNullException(nameof(curModel)); + if (curModel.ShopFlowers.TryGetValue(flower.Id, out var pair)) + { + curModel.ShopFlowers[flower.Id] = (pair.Item1, pair.Item2 + count); + } + else + { + curModel.ShopFlowers.Add(flower.Id, (flower, count)); + } + Update(new() + { + Id = curModel.Id, + ShopName = curModel.ShopName, + DateOpen = curModel.DateOpen, + Address = curModel.Address, + ShopFlowers = curModel.ShopFlowers, + }); + return true; } public ShopViewModel ReadElement(ShopSearchModel model) @@ -131,36 +155,5 @@ namespace FlowerShopBusinessLogic throw new InvalidOperationException("Магазин с таким названием уже есть"); } } - - public bool SupplyFlowers(ShopSearchModel model, IFlowerModel flower, int count) - { - if (model == null) - throw new ArgumentNullException(nameof(model)); - if (flower == null) - throw new ArgumentNullException(nameof(flower)); - if (count <= 0) - throw new ArgumentNullException("Количество должно быть положительным числом"); - - var curModel = _shopStorage.GetElement(model); - if (curModel == null) - throw new ArgumentNullException(nameof(curModel)); - if (curModel.ShopFlowers.TryGetValue(flower.Id, out var pair)) - { - curModel.ShopFlowers[flower.Id] = (pair.Item1, pair.Item2 + count); - } - else - { - curModel.ShopFlowers.Add(flower.Id, (flower, count)); - } - Update(new() - { - Id = curModel.Id, - ShopName = curModel.ShopName, - DateOpen = curModel.DateOpen, - Address = curModel.Address, - ShopFlowers = curModel.ShopFlowers, - }); - return true; - } } } diff --git a/FlowerShopContracts/StoragesContracts/IShopStorage.cs b/FlowerShopContracts/StoragesContracts/IShopStorage.cs index 122a79f..671f8c8 100644 --- a/FlowerShopContracts/StoragesContracts/IShopStorage.cs +++ b/FlowerShopContracts/StoragesContracts/IShopStorage.cs @@ -18,6 +18,5 @@ namespace FlowerShopContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); - //bool SupplyFlowers(ShopSearchModel model, IFlowerModel flower, int Count); } } From 964a2996b657dc3a020e1f92bb45ee1ecf0ffabe Mon Sep 17 00:00:00 2001 From: antoc0der <1@DESKTOP-K1L8ND3> Date: Thu, 14 Mar 2024 21:28:58 +0400 Subject: [PATCH 08/12] =?UTF-8?q?=D0=BF=D1=80=D0=BB=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FlowerShopBusinessLogic/OrderLogic.cs | 85 ++++- FlowerShopBusinessLogic/ShopLogic.cs | 41 ++- .../BindingModels/ShopBindingModel.cs | 1 + .../BusinessLogicsContracts/IShopLogic.cs | 1 + .../StoragesContracts/IShopStorage.cs | 1 + .../ViewModels/ShopViewModel.cs | 2 + FlowerShopDataModels/IShopModel.cs | 1 + FlowerShopFileImplement/DataFileSingleton.cs | 7 +- FlowerShopFileImplement/Shop.cs | 120 ++++++ FlowerShopFileImplement/ShopStorage.cs | 133 +++++++ FlowerShopListImplement/Shop.cs | 1 + FlowerShopListImplement/ShopStorage.cs | 46 +++ ProjectFlowerShop/MainForm.Designer.cs | 11 +- ProjectFlowerShop/MainForm.cs | 9 + ProjectFlowerShop/Program.cs | 1 + ProjectFlowerShop/SellForm.Designer.cs | 118 ++++++ ProjectFlowerShop/SellForm.cs | 122 ++++++ ProjectFlowerShop/SellForm.resx | 120 ++++++ ProjectFlowerShop/ShopForm.Designer.cs | 118 +++--- ProjectFlowerShop/ShopForm.agq-CM.resx | 120 ++++++ ProjectFlowerShop/ShopForm.cs | 5 +- ProjectFlowerShop/ShopForm.resx | 347 ++++++++++++++++++ 22 files changed, 1324 insertions(+), 86 deletions(-) create mode 100644 FlowerShopFileImplement/Shop.cs create mode 100644 FlowerShopFileImplement/ShopStorage.cs create mode 100644 ProjectFlowerShop/SellForm.Designer.cs create mode 100644 ProjectFlowerShop/SellForm.cs create mode 100644 ProjectFlowerShop/SellForm.resx create mode 100644 ProjectFlowerShop/ShopForm.agq-CM.resx diff --git a/FlowerShopBusinessLogic/OrderLogic.cs b/FlowerShopBusinessLogic/OrderLogic.cs index c19d04d..f7efbde 100644 --- a/FlowerShopBusinessLogic/OrderLogic.cs +++ b/FlowerShopBusinessLogic/OrderLogic.cs @@ -4,6 +4,7 @@ using FlowerShopContracts.SearchModels; using FlowerShopContracts.StoragesContracts; using FlowerShopContracts.ViewModels; using FlowerShopDataModels.Enums; +using FlowerShopDataModels.Models; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -17,11 +18,17 @@ namespace FlowerShopBusinessLogic.BusinessLogic { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; + private readonly IShopLogic _shopLogic; + private readonly IFlowerStorage _flowerStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + public OrderLogic(IOrderStorage orderStorage, IShopStorage shopStorage, IShopLogic shopLogic, IFlowerStorage flowerStorage, ILogger logger) { - _logger = logger; _orderStorage = orderStorage; + _shopStorage = shopStorage; + _logger = logger; + _shopLogic = shopLogic; + _flowerStorage = flowerStorage; } public List? ReadList(OrderSearchModel? model) @@ -65,6 +72,20 @@ namespace FlowerShopBusinessLogic.BusinessLogic _logger.LogWarning("Status change operation failed"); throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); } + if (element.Status == OrderStatus.Готов) + { + var flower = _flowerStorage.GetElement(new FlowerSearchModel() { Id = model.FlowerId }); + if (flower == null) + { + _logger.LogWarning("Status update to " + status.ToString() + " operation failed. Document not found."); + return false; + } + if (CheckSupply(flower, model.Count) == false) + { + _logger.LogWarning("Status update to " + status.ToString() + " operation failed. Shop supply error."); + return false; + } + } model.Status = status; if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; _orderStorage.Update(model); @@ -106,5 +127,65 @@ namespace FlowerShopBusinessLogic.BusinessLogic } _logger.LogInformation("Order. Sum:{ Cost}. Id: { Id}", model.Sum, model.Id); } + + public bool CheckSupply(IFlowerModel flower, int count) + { + if (count <= 0) + { + _logger.LogWarning("Check then supply operation error. IceCream count < 0."); + return false; + } + + int sumCapacity = 0; + int sumCount = 0; + sumCapacity = _shopStorage.GetFullList().Select(x => x.MaxCapacity).Sum(); + sumCount = _shopStorage.GetFullList().Select(x => x.ShopFlowers.Select(y => y.Value.Item2).Sum()).Sum(); + int freeSpace = sumCapacity - sumCount; + + if (freeSpace - count < 0) + { + _logger.LogWarning("Check then supply operation error. There's no place for new IceCream in shops."); + return false; + } + + foreach (var shop in _shopStorage.GetFullList()) + { + freeSpace = shop.MaxCapacity; + foreach (var doc in shop.ShopFlowers) + { + freeSpace -= doc.Value.Item2; + } + if (freeSpace == 0) + { + continue; + } + if (freeSpace - count >= 0) + { + if (_shopLogic.MakeSupply(new() { Id = shop.Id }, flower, count)) + count = 0; + else + { + _logger.LogWarning("Supply error"); + return false; + } + } + if (freeSpace - count < 0) + { + if (_shopLogic.MakeSupply(new() { Id = shop.Id }, flower, freeSpace)) + count -= freeSpace; + else + { + _logger.LogWarning("Supply error"); + return false; + } + } + if (count <= 0) + { + return true; + } + } + return false; + } + } } diff --git a/FlowerShopBusinessLogic/ShopLogic.cs b/FlowerShopBusinessLogic/ShopLogic.cs index 9e064d1..d92d22c 100644 --- a/FlowerShopBusinessLogic/ShopLogic.cs +++ b/FlowerShopBusinessLogic/ShopLogic.cs @@ -51,22 +51,35 @@ namespace FlowerShopBusinessLogic var curModel = _shopStorage.GetElement(model); if (curModel == null) throw new ArgumentNullException(nameof(curModel)); - if (curModel.ShopFlowers.TryGetValue(flower.Id, out var pair)) + + var countItems = curModel.ShopFlowers.Select(x => x.Value.Item2).Sum(); + if (curModel.MaxCapacity - countItems >= count) { - curModel.ShopFlowers[flower.Id] = (pair.Item1, pair.Item2 + count); + if (curModel.ShopFlowers.TryGetValue(flower.Id, out var sameDocument)) + { + curModel.ShopFlowers[flower.Id] = (flower, sameDocument.Item2 + count); + _logger.LogInformation("Same flower found by supply. Added {0} of {1} in {2} shop", count, flower.FlowerName, curModel.ShopName); + } + else + { + curModel.ShopFlowers[flower.Id] = (flower, count); + _logger.LogInformation("New flower added by supply. Added {0} of {1} in {2} shop", count, flower.FlowerName, curModel.ShopName); + } + _shopStorage.Update(new() + { + Id = curModel.Id, + ShopName = curModel.ShopName, + Address = curModel.Address, + DateOpen = curModel.DateOpen, + ShopFlowers = curModel.ShopFlowers, + MaxCapacity = curModel.MaxCapacity + }); } else { - curModel.ShopFlowers.Add(flower.Id, (flower, count)); + _logger.LogWarning("Required shop is overflowed"); + return false; } - Update(new() - { - Id = curModel.Id, - ShopName = curModel.ShopName, - DateOpen = curModel.DateOpen, - Address = curModel.Address, - ShopFlowers = curModel.ShopFlowers, - }); return true; } @@ -155,5 +168,11 @@ namespace FlowerShopBusinessLogic throw new InvalidOperationException("Магазин с таким названием уже есть"); } } + + public bool MakeSell(IFlowerModel flower, int count) + { + return _shopStorage.SellFlowers(flower, count); + } + } } diff --git a/FlowerShopContracts/BindingModels/ShopBindingModel.cs b/FlowerShopContracts/BindingModels/ShopBindingModel.cs index 9afd7ed..2298fa6 100644 --- a/FlowerShopContracts/BindingModels/ShopBindingModel.cs +++ b/FlowerShopContracts/BindingModels/ShopBindingModel.cs @@ -13,6 +13,7 @@ namespace FlowerShopContracts.BindingModels public string ShopName { get; set; } public string Address { get; set; } public DateTime DateOpen { get; set; } + public int MaxCapacity { get; set; } public Dictionary ShopFlowers { get; set; } = new(); } } diff --git a/FlowerShopContracts/BusinessLogicsContracts/IShopLogic.cs b/FlowerShopContracts/BusinessLogicsContracts/IShopLogic.cs index c9a8e57..695685f 100644 --- a/FlowerShopContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/FlowerShopContracts/BusinessLogicsContracts/IShopLogic.cs @@ -18,5 +18,6 @@ namespace FlowerShopContracts.BusinessLogicsContracts bool Update(ShopBindingModel model); bool Delete(ShopBindingModel model); bool MakeSupply(ShopSearchModel model, IFlowerModel flower, int count); + bool MakeSell(IFlowerModel flower, int count); } } diff --git a/FlowerShopContracts/StoragesContracts/IShopStorage.cs b/FlowerShopContracts/StoragesContracts/IShopStorage.cs index 671f8c8..d274c09 100644 --- a/FlowerShopContracts/StoragesContracts/IShopStorage.cs +++ b/FlowerShopContracts/StoragesContracts/IShopStorage.cs @@ -18,5 +18,6 @@ namespace FlowerShopContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); + public bool SellFlowers(IFlowerModel model, int count); } } diff --git a/FlowerShopContracts/ViewModels/ShopViewModel.cs b/FlowerShopContracts/ViewModels/ShopViewModel.cs index bb7556f..50e8691 100644 --- a/FlowerShopContracts/ViewModels/ShopViewModel.cs +++ b/FlowerShopContracts/ViewModels/ShopViewModel.cs @@ -17,6 +17,8 @@ namespace FlowerShopContracts.ViewModels public string Address { get; set; } [DisplayName("Дата открытия")] public DateTime DateOpen { get; set; } + [DisplayName("Вместимость")] + public int MaxCapacity { get; set; } public Dictionary ShopFlowers { get; set; } = new(); } } diff --git a/FlowerShopDataModels/IShopModel.cs b/FlowerShopDataModels/IShopModel.cs index 54bba9f..26c1497 100644 --- a/FlowerShopDataModels/IShopModel.cs +++ b/FlowerShopDataModels/IShopModel.cs @@ -11,6 +11,7 @@ namespace FlowerShopDataModels.Models string ShopName { get; } string Address { get; } DateTime DateOpen { get; } + int MaxCapacity { get; } Dictionary ShopFlowers { get; } } } diff --git a/FlowerShopFileImplement/DataFileSingleton.cs b/FlowerShopFileImplement/DataFileSingleton.cs index 83754aa..9a2812c 100644 --- a/FlowerShopFileImplement/DataFileSingleton.cs +++ b/FlowerShopFileImplement/DataFileSingleton.cs @@ -9,9 +9,11 @@ internal class DataFileSingleton private readonly string ComponentFileName = "Component.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string FlowerFileName = "Product.xml"; + private readonly string ShopFileName = "Shops.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Flowers { get; private set; } + public List Shops { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -26,11 +28,14 @@ internal class DataFileSingleton "Flowers", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); -private DataFileSingleton() + public void SaveShops() => SaveData(Shops, ShopFileName, + "Shops", x => x.GetXElement); + private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Flowers = LoadData(FlowerFileName, "Flower", x => Flower.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { diff --git a/FlowerShopFileImplement/Shop.cs b/FlowerShopFileImplement/Shop.cs new file mode 100644 index 0000000..67076e4 --- /dev/null +++ b/FlowerShopFileImplement/Shop.cs @@ -0,0 +1,120 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Threading.Tasks.Dataflow; +using System.Xml.Linq; + + +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Models; +using FlowerShopFileImplement; +using FlowerShopFileImplement.Implements; + +namespace FlowerShopFileImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } + public string Address { get; private set; } + public DateTime DateOpen { get; private set; } + public Dictionary Flowers { get; private set; } = new(); + private Dictionary? _shopFlowers = null; + public Dictionary ShopFlowers + { + get + { + if (_shopFlowers == null) + { + var source = DataFileSingleton.GetInstance(); + _shopFlowers = Flowers.ToDictionary(x => x.Key, y => + ((source.Flowers.FirstOrDefault(z => z.Id == y.Key) as IFlowerModel)!, + y.Value)); + } + return _shopFlowers; + } + } + + public int MaxCapacity { get; private set; } + + public static Shop? Create(ShopBindingModel model) + { + if (model == null) + return null; + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpen = model.DateOpen, + MaxCapacity = model.MaxCapacity, + Flowers = model.ShopFlowers.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + + public static Shop? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Shop() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ShopName = element.Element("ShopName")!.Value, + Address = element.Element("Address")!.Value, + MaxCapacity = Convert.ToInt32(element.Element("MaxCapacity")!.Value), + DateOpen = Convert.ToDateTime(element.Element("DateOpen")!.Value), + Flowers = + element.Element("ShopFlowers")!.Elements("ShopFlower") + .ToDictionary(x => + Convert.ToInt32(x.Element("Key")?.Value), x => + Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + + + public void Update(ShopBindingModel model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpen = model.DateOpen; + MaxCapacity = model.MaxCapacity; + if (model.ShopFlowers.Count > 0) + { + Flowers = model.ShopFlowers.ToDictionary(x => x.Key, x => x.Value.Item2); + _shopFlowers = null; + } + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpen = DateOpen, + MaxCapacity = MaxCapacity, + ShopFlowers = ShopFlowers + }; + + public XElement GetXElement => new("Shop", + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("Address", Address), + new XElement("DateOpen", DateOpen), + new XElement("MaxCapacity", MaxCapacity), + new XElement("ShopFlowers", Flowers + .Select(x => new XElement("ShopFlower", + new XElement("Key", x.Key), + new XElement("Value", x.Value)) + ).ToArray())); + } +} diff --git a/FlowerShopFileImplement/ShopStorage.cs b/FlowerShopFileImplement/ShopStorage.cs new file mode 100644 index 0000000..c9d41d4 --- /dev/null +++ b/FlowerShopFileImplement/ShopStorage.cs @@ -0,0 +1,133 @@ +using FlowerShopContracts.BindingModels; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.StoragesContracts; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Models; +using FlowerShopFileImplement.Implements; +using FlowerShopFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +namespace FlowerShopFileImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataFileSingleton _source; + public ShopStorage() + { + _source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return _source.Shops + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(ShopSearchModel + model) + { + if (string.IsNullOrEmpty(model.Name)) + { + return new(); + } + return _source.Shops + .Where(x => x.ShopName.Contains(model.Name)) + .Select(x => x.GetViewModel) + .ToList(); ; + } + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) + { + return null; + } + return _source.Shops + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.Name) && x.ShopName == model.Name) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = _source.Shops.Count > 0 ? _source.Shops.Max(x => x.Id) + 1 : 1; + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + _source.Shops.Add(newShop); + _source.SaveShops(); + return newShop.GetViewModel; + } + public ShopViewModel? Update(ShopBindingModel model) + { + var component = _source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + _source.SaveShops(); + return component.GetViewModel; + } + public ShopViewModel? Delete(ShopBindingModel model) + { + var element = _source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + _source.Shops.Remove(element); + _source.SaveShops(); + return element.GetViewModel; + } + return null; + } + //проверка наполненности магазинов + public bool CheckAvailability(int flowerId, int count) + { + count -= _source.Shops.Select(x => x.ShopFlowers.Select(y => (y.Value.Item1.Id == flowerId ? y.Value.Item2 : 0)).Sum()).Sum(); + return count <= 0; + } + //логика продажи + public bool SellFlowers(IFlowerModel model, int count) + { + var flower = _source.Flowers.FirstOrDefault(x => x.Id == model.Id); + + if (flower == null || !CheckAvailability(flower.Id, count)) + { + return false; + } + + for (int i = 0; i < _source.Shops.Count; i++) + { + var shop = _source.Shops[i]; + var flowers = shop.ShopFlowers; + + foreach (var flowerr in flowers.Where(x => x.Value.Item1.Id == flower.Id)) + { + var min = Math.Min(flowerr.Value.Item2, count); + flowers[flowerr.Value.Item1.Id] = (flowerr.Value.Item1, flowerr.Value.Item2 - min); + count -= min; + + if (count <= 0) + { + break; + } + } + + shop.Update(new ShopBindingModel + { + Id = shop.Id, + ShopName = shop.ShopName, + Address = shop.Address, + DateOpen = shop.DateOpen, + MaxCapacity = shop.MaxCapacity, + ShopFlowers = flowers + }); + } + _source.SaveShops(); + return true; + } + } +} diff --git a/FlowerShopListImplement/Shop.cs b/FlowerShopListImplement/Shop.cs index e7bba4a..96f42a8 100644 --- a/FlowerShopListImplement/Shop.cs +++ b/FlowerShopListImplement/Shop.cs @@ -15,6 +15,7 @@ namespace FlowerShopListImplement.Models public string ShopName { get; private set; } public string Address { get; private set; } public DateTime DateOpen { get; private set; } + public int MaxCapacity { get; private set; } public Dictionary ShopFlowers { get; private set; } = new(); public static Shop? Create(ShopBindingModel model) diff --git a/FlowerShopListImplement/ShopStorage.cs b/FlowerShopListImplement/ShopStorage.cs index a97253b..b3e8a3a 100644 --- a/FlowerShopListImplement/ShopStorage.cs +++ b/FlowerShopListImplement/ShopStorage.cs @@ -106,5 +106,51 @@ namespace FlowerShopListImplement.Implements return null; } + public bool CheckAvailability(int flowerId, int count) + { + int minus = _source.Shops.Select(x => x.ShopFlowers.Select(y => (y.Value.Item1.Id == flowerId ? y.Value.Item2 : 0)).Sum()).Sum(); + count -= minus; + return count <= 0; + } + + public bool SellFlowers(IFlowerModel model, int count) + { + var flower = _source.Flowers.FirstOrDefault(x => x.Id == model.Id); + + if (flower == null || !CheckAvailability(flower.Id, count)) + { + return false; + } + + for (int i = 0; i < _source.Shops.Count; i++) + { + var shop = _source.Shops[i]; + var flowers = shop.ShopFlowers; + + foreach (var flowerr in flowers.Where(x => x.Value.Item1.Id == flower.Id)) + { + var min = Math.Min(flowerr.Value.Item2, count); + flowers[flowerr.Value.Item1.Id] = (flowerr.Value.Item1, flowerr.Value.Item2 - min); + count -= min; + + if (count <= 0) + { + break; + } + } + + shop.Update(new ShopBindingModel + { + Id = shop.Id, + ShopName = shop.ShopName, + Address = shop.Address, + DateOpen = shop.DateOpen, + MaxCapacity = shop.MaxCapacity, + ShopFlowers = flowers + }); + } + return true; + } + } } diff --git a/ProjectFlowerShop/MainForm.Designer.cs b/ProjectFlowerShop/MainForm.Designer.cs index 40db63c..78536fd 100644 --- a/ProjectFlowerShop/MainForm.Designer.cs +++ b/ProjectFlowerShop/MainForm.Designer.cs @@ -40,6 +40,7 @@ ReadyButton = new Button(); IssuedButton = new Button(); RefreshButton = new Button(); + продажиToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); SuspendLayout(); @@ -56,7 +57,7 @@ // // ToolStripMenu // - ToolStripMenu.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыStripMenuItem, ЦветыStripMenuItem, магазиныToolStripMenuItem, поставкиToolStripMenuItem }); + ToolStripMenu.DropDownItems.AddRange(new ToolStripItem[] { КомпонентыStripMenuItem, ЦветыStripMenuItem, магазиныToolStripMenuItem, поставкиToolStripMenuItem, продажиToolStripMenuItem }); ToolStripMenu.Name = "ToolStripMenu"; ToolStripMenu.Size = new Size(117, 24); ToolStripMenu.Text = "Справочники"; @@ -148,6 +149,13 @@ RefreshButton.UseVisualStyleBackColor = true; RefreshButton.Click += RefreshButton_Click; // + // продажиToolStripMenuItem + // + продажиToolStripMenuItem.Name = "продажиToolStripMenuItem"; + продажиToolStripMenuItem.Size = new Size(224, 26); + продажиToolStripMenuItem.Text = "Продажи"; + продажиToolStripMenuItem.Click += продажиToolStripMenuItem_Click; + // // MainForm // AutoScaleDimensions = new SizeF(8F, 20F); @@ -185,5 +193,6 @@ private Button RefreshButton; private ToolStripMenuItem магазиныToolStripMenuItem; private ToolStripMenuItem поставкиToolStripMenuItem; + private ToolStripMenuItem продажиToolStripMenuItem; } } \ No newline at end of file diff --git a/ProjectFlowerShop/MainForm.cs b/ProjectFlowerShop/MainForm.cs index 7b6b80d..cf1b07a 100644 --- a/ProjectFlowerShop/MainForm.cs +++ b/ProjectFlowerShop/MainForm.cs @@ -198,5 +198,14 @@ namespace ProjectFlowerShop form.ShowDialog(); } } + + private void продажиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(SellForm)); + if (service is SellForm form) + { + form.ShowDialog(); + } + } } } diff --git a/ProjectFlowerShop/Program.cs b/ProjectFlowerShop/Program.cs index 19c9645..22ea896 100644 --- a/ProjectFlowerShop/Program.cs +++ b/ProjectFlowerShop/Program.cs @@ -53,6 +53,7 @@ namespace ProjectFlowerShop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } diff --git a/ProjectFlowerShop/SellForm.Designer.cs b/ProjectFlowerShop/SellForm.Designer.cs new file mode 100644 index 0000000..f458653 --- /dev/null +++ b/ProjectFlowerShop/SellForm.Designer.cs @@ -0,0 +1,118 @@ +namespace ProjectFlowerShop +{ + partial class SellForm + { + /// + /// 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() + { + labelFlower = new Label(); + labelCount = new Label(); + comboBoxFlower = new ComboBox(); + textBoxCount = new TextBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + SuspendLayout(); + // + // labelFlower + // + labelFlower.AutoSize = true; + labelFlower.Location = new Point(12, 9); + labelFlower.Name = "labelFlower"; + labelFlower.Size = new Size(53, 20); + labelFlower.TabIndex = 0; + labelFlower.Text = "Цветы"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(12, 87); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(90, 20); + labelCount.TabIndex = 1; + labelCount.Text = "Количество"; + // + // comboBoxFlower + // + comboBoxFlower.FormattingEnabled = true; + comboBoxFlower.Location = new Point(12, 32); + comboBoxFlower.Name = "comboBoxFlower"; + comboBoxFlower.Size = new Size(151, 28); + comboBoxFlower.TabIndex = 2; + // + // textBoxCount + // + textBoxCount.Location = new Point(12, 110); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(151, 27); + textBoxCount.TabIndex = 3; + // + // buttonCancel + // + buttonCancel.Location = new Point(277, 153); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(180, 153); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // SellForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(383, 198); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(textBoxCount); + Controls.Add(comboBoxFlower); + Controls.Add(labelCount); + Controls.Add(labelFlower); + Name = "SellForm"; + Text = "Продажи"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelFlower; + private Label labelCount; + private ComboBox comboBoxFlower; + private TextBox textBoxCount; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/ProjectFlowerShop/SellForm.cs b/ProjectFlowerShop/SellForm.cs new file mode 100644 index 0000000..36169f1 --- /dev/null +++ b/ProjectFlowerShop/SellForm.cs @@ -0,0 +1,122 @@ +using FlowerShopContracts.BusinessLogicsContracts; +using FlowerShopContracts.SearchModels; +using FlowerShopContracts.ViewModels; +using FlowerShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ProjectFlowerShop +{ + public partial class SellForm : Form + { + private readonly List? _flowerList; + IShopLogic _shopLogic; + IFlowerLogic _flowerLogic; + public SellForm(IFlowerLogic flowerLogic, IShopLogic shopLogic) + { + InitializeComponent(); + _shopLogic = shopLogic; + _flowerLogic = flowerLogic; + _flowerList = flowerLogic.ReadList(null); + if (_flowerList != null) + { + comboBoxFlower.DisplayMember = "FlowerName"; + comboBoxFlower.ValueMember = "Id"; + comboBoxFlower.DataSource = _flowerList; + comboBoxFlower.SelectedItem = null; + } + } + public int FlowerId + { + get + { + return Convert.ToInt32(comboBoxFlower.SelectedValue); + } + set + { + comboBoxFlower.SelectedValue = value; + } + } + + public IFlowerModel? FlowerModel + { + get + { + if (_flowerList == null) + { + return null; + } + foreach (var elem in _flowerList) + { + if (elem.Id == FlowerId) + { + return elem; + } + } + return null; + } + } + + + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set + { textBoxCount.Text = value.ToString(); } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxFlower.SelectedValue == null) + { + MessageBox.Show("Выберите цветы", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + try + { + int count = Convert.ToInt32(textBoxCount.Text); + + bool res = _shopLogic.MakeSell( + _flowerLogic.ReadElement(new() { Id = Convert.ToInt32(comboBoxFlower.SelectedValue) }), + count + ); + + if (!res) + { + throw new Exception("Ошибка при продаже."); + } + + MessageBox.Show("Продажа прошла успешно"); + DialogResult = DialogResult.OK; + Close(); + + } + catch (Exception err) + { + MessageBox.Show("Ошибка продажи"); + return; + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/ProjectFlowerShop/SellForm.resx b/ProjectFlowerShop/SellForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectFlowerShop/SellForm.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/ProjectFlowerShop/ShopForm.Designer.cs b/ProjectFlowerShop/ShopForm.Designer.cs index ffdac20..64f568d 100644 --- a/ProjectFlowerShop/ShopForm.Designer.cs +++ b/ProjectFlowerShop/ShopForm.Designer.cs @@ -28,7 +28,12 @@ /// private void InitializeComponent() { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ShopForm)); DataGridView = new DataGridView(); + ColumnID = new DataGridViewTextBoxColumn(); + Name = new DataGridViewTextBoxColumn(); + Price = new DataGridViewTextBoxColumn(); + Number = new DataGridViewTextBoxColumn(); buttonSave = new Button(); buttonCancel = new Button(); textBoxName = new TextBox(); @@ -37,126 +42,100 @@ labelAddress = new Label(); DateTimePicker = new DateTimePicker(); labelDate = new Label(); - ColumnID = new DataGridViewTextBoxColumn(); - Name = new DataGridViewTextBoxColumn(); - Price = new DataGridViewTextBoxColumn(); - Number = new DataGridViewTextBoxColumn(); + CapacityUpDown = new NumericUpDown(); + labelCapacity = new Label(); ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + ((System.ComponentModel.ISupportInitialize)CapacityUpDown).BeginInit(); SuspendLayout(); // // DataGridView // DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; DataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnID, Name, Price, Number }); - DataGridView.Location = new Point(21, 12); + resources.ApplyResources(DataGridView, "DataGridView"); DataGridView.Name = "DataGridView"; - DataGridView.RowHeadersWidth = 51; DataGridView.RowTemplate.Height = 29; - DataGridView.Size = new Size(397, 305); - DataGridView.TabIndex = 0; + // + // ColumnID + // + resources.ApplyResources(ColumnID, "ColumnID"); + ColumnID.Name = "ColumnID"; + // + // Name + // + resources.ApplyResources(Name, "Name"); + Name.Name = "Name"; + // + // Price + // + resources.ApplyResources(Price, "Price"); + Price.Name = "Price"; + // + // Number + // + resources.ApplyResources(Number, "Number"); + Number.Name = "Number"; // // buttonSave // - buttonSave.Location = new Point(424, 288); + resources.ApplyResources(buttonSave, "buttonSave"); buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(123, 29); - buttonSave.TabIndex = 1; - buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; buttonSave.Click += buttonSave_Click; // // buttonCancel // - buttonCancel.Location = new Point(553, 288); + resources.ApplyResources(buttonCancel, "buttonCancel"); buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(116, 29); - buttonCancel.TabIndex = 2; - buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; buttonCancel.Click += buttonCancel_Click; // // textBoxName // - textBoxName.Location = new Point(424, 34); + resources.ApplyResources(textBoxName, "textBoxName"); textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(245, 27); - textBoxName.TabIndex = 3; // // textBoxAddress // - textBoxAddress.Location = new Point(424, 95); + resources.ApplyResources(textBoxAddress, "textBoxAddress"); textBoxAddress.Name = "textBoxAddress"; - textBoxAddress.Size = new Size(245, 27); - textBoxAddress.TabIndex = 4; // // labelName // - labelName.AutoSize = true; - labelName.Location = new Point(424, 12); + resources.ApplyResources(labelName, "labelName"); labelName.Name = "labelName"; - labelName.Size = new Size(77, 20); - labelName.TabIndex = 5; - labelName.Text = "Название"; // // labelAddress // - labelAddress.AutoSize = true; - labelAddress.Location = new Point(424, 72); + resources.ApplyResources(labelAddress, "labelAddress"); labelAddress.Name = "labelAddress"; - labelAddress.Size = new Size(51, 20); - labelAddress.TabIndex = 6; - labelAddress.Text = "Адрес"; // // DateTimePicker // - DateTimePicker.Location = new Point(424, 148); + resources.ApplyResources(DateTimePicker, "DateTimePicker"); DateTimePicker.Name = "DateTimePicker"; - DateTimePicker.Size = new Size(245, 27); - DateTimePicker.TabIndex = 7; // // labelDate // - labelDate.AutoSize = true; - labelDate.Location = new Point(424, 125); + resources.ApplyResources(labelDate, "labelDate"); labelDate.Name = "labelDate"; - labelDate.Size = new Size(41, 20); - labelDate.TabIndex = 8; - labelDate.Text = "Дата"; // - // ColumnID + // CapacityUpDown // - ColumnID.HeaderText = "ColumnID"; - ColumnID.MinimumWidth = 6; - ColumnID.Name = "ColumnID"; - ColumnID.Visible = false; - ColumnID.Width = 125; + resources.ApplyResources(CapacityUpDown, "CapacityUpDown"); + CapacityUpDown.Name = "CapacityUpDown"; // - // Name + // labelCapacity // - Name.HeaderText = "Название"; - Name.MinimumWidth = 6; - Name.Name = "Name"; - Name.Width = 125; - // - // Price - // - Price.HeaderText = "Цена"; - Price.MinimumWidth = 6; - Price.Name = "Price"; - Price.Width = 125; - // - // Number - // - Number.HeaderText = "Количество"; - Number.MinimumWidth = 6; - Number.Name = "Number"; - Number.Width = 125; + resources.ApplyResources(labelCapacity, "labelCapacity"); + labelCapacity.Name = "labelCapacity"; // // ShopForm // - AutoScaleDimensions = new SizeF(8F, 20F); + resources.ApplyResources(this, "$this"); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(681, 329); + Controls.Add(labelCapacity); + Controls.Add(CapacityUpDown); Controls.Add(labelDate); Controls.Add(DateTimePicker); Controls.Add(labelAddress); @@ -166,10 +145,9 @@ Controls.Add(buttonCancel); Controls.Add(buttonSave); Controls.Add(DataGridView); - //Name = "ShopForm"; - Text = "ShopForm"; Load += ShopForm_Load; ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ((System.ComponentModel.ISupportInitialize)CapacityUpDown).EndInit(); ResumeLayout(false); PerformLayout(); } @@ -189,5 +167,7 @@ private DataGridViewTextBoxColumn Name; private DataGridViewTextBoxColumn Price; private DataGridViewTextBoxColumn Number; + private NumericUpDown CapacityUpDown; + private Label labelCapacity; } } \ No newline at end of file diff --git a/ProjectFlowerShop/ShopForm.agq-CM.resx b/ProjectFlowerShop/ShopForm.agq-CM.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ProjectFlowerShop/ShopForm.agq-CM.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/ProjectFlowerShop/ShopForm.cs b/ProjectFlowerShop/ShopForm.cs index 90f1a02..a982d9a 100644 --- a/ProjectFlowerShop/ShopForm.cs +++ b/ProjectFlowerShop/ShopForm.cs @@ -71,7 +71,7 @@ namespace ProjectFlowerShop ShopName = textBoxName.Text, Address = textBoxAddress.Text, DateOpen = DateTimePicker.Value.Date, - ShopFlowers = _flowers + MaxCapacity = Convert.ToInt32(CapacityUpDown.Value), }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) @@ -108,7 +108,8 @@ namespace ProjectFlowerShop textBoxName.Text = shop.ShopName; textBoxAddress.Text = shop.Address; DateTimePicker.Text = shop.DateOpen.ToString(); - _flowers = shop.ShopFlowers; + CapacityUpDown.Value = shop.MaxCapacity; + _flowers = shop.ShopFlowers ?? new Dictionary(); } LoadData(); } diff --git a/ProjectFlowerShop/ShopForm.resx b/ProjectFlowerShop/ShopForm.resx index e4ea5ef..9158edf 100644 --- a/ProjectFlowerShop/ShopForm.resx +++ b/ProjectFlowerShop/ShopForm.resx @@ -120,13 +120,360 @@ True + + ColumnID + + + + 6 + + + False + + + 125 + True + + Название + + + 6 + + + 125 + True + + Цена + + + 6 + + + 125 + True + + Количество + + + 6 + + + 125 + + + + 21, 12 + + + 51 + + + 397, 305 + + + 0 + + + DataGridView + + + System.Windows.Forms.DataGridView, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 10 + + + 424, 288 + + + 123, 29 + + + 1 + + + Сохранить + + + buttonSave + + + System.Windows.Forms.Button, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 9 + + + 553, 288 + + + 116, 29 + + + 2 + + + Отмена + + + buttonCancel + + + System.Windows.Forms.Button, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 8 + + + 424, 34 + + + 245, 27 + + + 3 + + + textBoxName + + + System.Windows.Forms.TextBox, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 7 + + + 424, 95 + + + 245, 27 + + + 4 + + + textBoxAddress + + + System.Windows.Forms.TextBox, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 6 + + + True + + + 424, 12 + + + 77, 20 + + + 5 + + + Название + + + labelName + + + System.Windows.Forms.Label, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 5 + + + True + + + 424, 72 + + + 51, 20 + + + 6 + + + Адрес + + + labelAddress + + + System.Windows.Forms.Label, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 4 + + + 424, 148 + + + 245, 27 + + + 7 + + + DateTimePicker + + + System.Windows.Forms.DateTimePicker, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 3 + + + True + + + 424, 125 + + + 41, 20 + + + 8 + + + Дата + + + labelDate + + + System.Windows.Forms.Label, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 2 + + + 424, 207 + + + 245, 27 + + + 9 + + + CapacityUpDown + + + System.Windows.Forms.NumericUpDown, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 + + + True + + + 424, 184 + + + 100, 20 + + + 10 + + + Вместимость + + + labelCapacity + + + System.Windows.Forms.Label, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 0 + + + True + + + 8, 20 + + + 681, 329 + + + Магазин + + + ColumnID + + + System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Name + + + System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Price + + + System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Number + + + System.Windows.Forms.DataGridViewTextBoxColumn, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ShopForm + + + System.Windows.Forms.Form, System.Windows.Forms, Culture=neutral, PublicKeyToken=b77a5c561934e089 + \ No newline at end of file From bc2e607a5f2ae6b2a2b60621e6a944f01be6284b Mon Sep 17 00:00:00 2001 From: antoc0der <1@DESKTOP-K1L8ND3> Date: Fri, 15 Mar 2024 22:20:26 +0400 Subject: [PATCH 09/12] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormFlowerComponent.Designer.cs | 6 ++--- ProjectFlowerShop/FormFlowers.Designer.cs | 2 +- ProjectFlowerShop/MainForm.Designer.cs | 26 +++++++++---------- ProjectFlowerShop/ShopsForm.Designer.cs | 2 +- ProjectFlowerShop/SupplyForm.Designer.cs | 2 +- Temp.txt | 1 + 6 files changed, 20 insertions(+), 19 deletions(-) create mode 100644 Temp.txt diff --git a/ProjectFlowerShop/FormFlowerComponent.Designer.cs b/ProjectFlowerShop/FormFlowerComponent.Designer.cs index 8e3378b..334204e 100644 --- a/ProjectFlowerShop/FormFlowerComponent.Designer.cs +++ b/ProjectFlowerShop/FormFlowerComponent.Designer.cs @@ -89,7 +89,7 @@ buttonCancel.UseVisualStyleBackColor = true; buttonCancel.Click += buttonCancel_Click; // - // FormProductComponent + // FormFlowerComponent // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; @@ -100,8 +100,8 @@ Controls.Add(comboBoxComponent); Controls.Add(labelNumber); Controls.Add(labelComponent); - Name = "FormProductComponent"; - Text = "FormProductComponent"; + Name = "FormFlowerComponent"; + Text = "Цветы-компоненты"; Load += FormProductComponent_Load; ResumeLayout(false); PerformLayout(); diff --git a/ProjectFlowerShop/FormFlowers.Designer.cs b/ProjectFlowerShop/FormFlowers.Designer.cs index 5d3d3e7..9c2001a 100644 --- a/ProjectFlowerShop/FormFlowers.Designer.cs +++ b/ProjectFlowerShop/FormFlowers.Designer.cs @@ -96,7 +96,7 @@ Controls.Add(AddButton); Controls.Add(DataGridView); Name = "FormFlowers"; - Text = "FlowersForm"; + Text = "Цветы"; Load += IceCreamsForm_Load; ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); ResumeLayout(false); diff --git a/ProjectFlowerShop/MainForm.Designer.cs b/ProjectFlowerShop/MainForm.Designer.cs index 78536fd..a955075 100644 --- a/ProjectFlowerShop/MainForm.Designer.cs +++ b/ProjectFlowerShop/MainForm.Designer.cs @@ -34,13 +34,13 @@ ЦветыStripMenuItem = new ToolStripMenuItem(); магазиныToolStripMenuItem = new ToolStripMenuItem(); поставкиToolStripMenuItem = new ToolStripMenuItem(); + продажиToolStripMenuItem = new ToolStripMenuItem(); DataGridView = new DataGridView(); CreateOrderButton = new Button(); TakeInWorkButton = new Button(); ReadyButton = new Button(); IssuedButton = new Button(); RefreshButton = new Button(); - продажиToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); SuspendLayout(); @@ -65,31 +65,38 @@ // КомпонентыStripMenuItem // КомпонентыStripMenuItem.Name = "КомпонентыStripMenuItem"; - КомпонентыStripMenuItem.Size = new Size(224, 26); + КомпонентыStripMenuItem.Size = new Size(182, 26); КомпонентыStripMenuItem.Text = "Компоненты"; КомпонентыStripMenuItem.Click += КомпонентыStripMenuItem_Click; // // ЦветыStripMenuItem // ЦветыStripMenuItem.Name = "ЦветыStripMenuItem"; - ЦветыStripMenuItem.Size = new Size(224, 26); + ЦветыStripMenuItem.Size = new Size(182, 26); ЦветыStripMenuItem.Text = "Цветы"; ЦветыStripMenuItem.Click += ЦветыStripMenuItem_Click; // // магазиныToolStripMenuItem // магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; - магазиныToolStripMenuItem.Size = new Size(224, 26); + магазиныToolStripMenuItem.Size = new Size(182, 26); магазиныToolStripMenuItem.Text = "Магазины"; магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click; // // поставкиToolStripMenuItem // поставкиToolStripMenuItem.Name = "поставкиToolStripMenuItem"; - поставкиToolStripMenuItem.Size = new Size(224, 26); + поставкиToolStripMenuItem.Size = new Size(182, 26); поставкиToolStripMenuItem.Text = "Поставки"; поставкиToolStripMenuItem.Click += поставкиToolStripMenuItem_Click; // + // продажиToolStripMenuItem + // + продажиToolStripMenuItem.Name = "продажиToolStripMenuItem"; + продажиToolStripMenuItem.Size = new Size(182, 26); + продажиToolStripMenuItem.Text = "Продажи"; + продажиToolStripMenuItem.Click += продажиToolStripMenuItem_Click; + // // DataGridView // DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -149,13 +156,6 @@ RefreshButton.UseVisualStyleBackColor = true; RefreshButton.Click += RefreshButton_Click; // - // продажиToolStripMenuItem - // - продажиToolStripMenuItem.Name = "продажиToolStripMenuItem"; - продажиToolStripMenuItem.Size = new Size(224, 26); - продажиToolStripMenuItem.Text = "Продажи"; - продажиToolStripMenuItem.Click += продажиToolStripMenuItem_Click; - // // MainForm // AutoScaleDimensions = new SizeF(8F, 20F); @@ -170,7 +170,7 @@ Controls.Add(menuStrip1); MainMenuStrip = menuStrip1; Name = "MainForm"; - Text = "MainForm"; + Text = "Главная форма"; Load += MainForm_Load; menuStrip1.ResumeLayout(false); menuStrip1.PerformLayout(); diff --git a/ProjectFlowerShop/ShopsForm.Designer.cs b/ProjectFlowerShop/ShopsForm.Designer.cs index 431686d..dfa8927 100644 --- a/ProjectFlowerShop/ShopsForm.Designer.cs +++ b/ProjectFlowerShop/ShopsForm.Designer.cs @@ -97,7 +97,7 @@ Controls.Add(buttonAdd); Controls.Add(DataGridView); Name = "ShopsForm"; - Text = "ShopsForm"; + Text = "Форма магазинов"; Load += ShopsForm_Load; ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); ResumeLayout(false); diff --git a/ProjectFlowerShop/SupplyForm.Designer.cs b/ProjectFlowerShop/SupplyForm.Designer.cs index 87d9587..14dfb09 100644 --- a/ProjectFlowerShop/SupplyForm.Designer.cs +++ b/ProjectFlowerShop/SupplyForm.Designer.cs @@ -122,7 +122,7 @@ Controls.Add(buttonCancel); Controls.Add(buttonSave); Name = "SupplyForm"; - Text = "SupplyForm"; + Text = "Форма поставки"; ResumeLayout(false); PerformLayout(); } diff --git a/Temp.txt b/Temp.txt new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/Temp.txt @@ -0,0 +1 @@ + \ No newline at end of file From 357e9bb315aaf27d93515c2f33b0c7a0378d1fc9 Mon Sep 17 00:00:00 2001 From: antoc0der <1@DESKTOP-K1L8ND3> Date: Fri, 15 Mar 2024 22:23:58 +0400 Subject: [PATCH 10/12] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectFlowerShop/FormFlower.Designer.cs | 5 ----- ProjectFlowerShop/FormFlower.cs | 10 ---------- ProjectFlowerShop/FormFlowerComponent.Designer.cs | 1 - ProjectFlowerShop/FormFlowerComponent.cs | 5 ----- 4 files changed, 21 deletions(-) diff --git a/ProjectFlowerShop/FormFlower.Designer.cs b/ProjectFlowerShop/FormFlower.Designer.cs index aa3790a..4573ebf 100644 --- a/ProjectFlowerShop/FormFlower.Designer.cs +++ b/ProjectFlowerShop/FormFlower.Designer.cs @@ -72,7 +72,6 @@ textBoxName.Name = "textBoxName"; textBoxName.Size = new Size(204, 27); textBoxName.TabIndex = 2; - textBoxName.TextChanged += textBox1_TextChanged; // // textBoxPrice // @@ -145,7 +144,6 @@ dataGridView.RowTemplate.Height = 29; dataGridView.Size = new Size(432, 262); dataGridView.TabIndex = 0; - dataGridView.CellContentClick += dataGridView_CellContentClick; // // Save // @@ -208,7 +206,6 @@ Controls.Add(textBoxName); Controls.Add(labelPrice); Controls.Add(labelName); - // Name = "FormProduct"; Text = "Изделие"; Load += FormProduct_Load; groupBoxComponent.ResumeLayout(false); @@ -231,10 +228,8 @@ private DataGridView dataGridView; private Button Save; private Button buttonCancel; - // private DataGridViewTextBoxColumn Id; private DataGridViewTextBoxColumn Name; private DataGridViewTextBoxColumn Number; - //private DataGridViewTextBoxColumn Id; private DataGridViewTextBoxColumn Component; private DataGridViewTextBoxColumn idd; private DataGridViewTextBoxColumn Numbers; diff --git a/ProjectFlowerShop/FormFlower.cs b/ProjectFlowerShop/FormFlower.cs index 40ad362..6ee4831 100644 --- a/ProjectFlowerShop/FormFlower.cs +++ b/ProjectFlowerShop/FormFlower.cs @@ -31,11 +31,6 @@ namespace ProjectFlowerShop _flowerComponents = new Dictionary(); } - private void textBox1_TextChanged(object sender, EventArgs e) - { - - } - private void FormProduct_Load(object sender, EventArgs e) { if (_id.HasValue) @@ -88,11 +83,6 @@ namespace ProjectFlowerShop } } - private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) - { - - } - private void buttonAdd_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormFlowerComponent)); diff --git a/ProjectFlowerShop/FormFlowerComponent.Designer.cs b/ProjectFlowerShop/FormFlowerComponent.Designer.cs index 334204e..f509bbd 100644 --- a/ProjectFlowerShop/FormFlowerComponent.Designer.cs +++ b/ProjectFlowerShop/FormFlowerComponent.Designer.cs @@ -102,7 +102,6 @@ Controls.Add(labelComponent); Name = "FormFlowerComponent"; Text = "Цветы-компоненты"; - Load += FormProductComponent_Load; ResumeLayout(false); PerformLayout(); } diff --git a/ProjectFlowerShop/FormFlowerComponent.cs b/ProjectFlowerShop/FormFlowerComponent.cs index 697ece2..cd55022 100644 --- a/ProjectFlowerShop/FormFlowerComponent.cs +++ b/ProjectFlowerShop/FormFlowerComponent.cs @@ -65,11 +65,6 @@ namespace ProjectFlowerShop } } - private void FormProductComponent_Load(object sender, EventArgs e) - { - - } - private void buttonSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxNumber.Text)) From e3dfb7b0c0a54610e11ede924cd94bfa6f925044 Mon Sep 17 00:00:00 2001 From: antoc0der <1@DESKTOP-K1L8ND3> Date: Fri, 15 Mar 2024 22:27:17 +0400 Subject: [PATCH 11/12] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FlowerShopFileImplement/FlowerStorage.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/FlowerShopFileImplement/FlowerStorage.cs b/FlowerShopFileImplement/FlowerStorage.cs index c06d89a..e1ac660 100644 --- a/FlowerShopFileImplement/FlowerStorage.cs +++ b/FlowerShopFileImplement/FlowerStorage.cs @@ -67,25 +67,25 @@ namespace FlowerShopFileImplement.Implements public FlowerViewModel? Update(FlowerBindingModel model) { - var iceCream = source.Flowers.FirstOrDefault(x => x.Id == + var flower = source.Flowers.FirstOrDefault(x => x.Id == model.Id); - if (iceCream == null) + if (flower == null) { return null; } - iceCream.Update(model); + flower.Update(model); source.SaveFlowers(); - return iceCream.GetViewModel; + return flower.GetViewModel; } public FlowerViewModel? Delete(FlowerBindingModel model) { - var iceCream = source.Flowers.FirstOrDefault(x => x.Id == + var flower = source.Flowers.FirstOrDefault(x => x.Id == model.Id); - if (iceCream != null) + if (flower != null) { - source.Flowers.Remove(iceCream); + source.Flowers.Remove(flower); source.SaveFlowers(); - return iceCream.GetViewModel; + return flower.GetViewModel; } return null; } From b92f1381f6a17f0b0a8826147f3bb01f2b1c696a Mon Sep 17 00:00:00 2001 From: antoc0der <1@DESKTOP-K1L8ND3> Date: Fri, 15 Mar 2024 22:45:21 +0400 Subject: [PATCH 12/12] =?UTF-8?q?=D0=B5=D1=89=D0=B5=20=D0=BD=D0=B8=D0=BA?= =?UTF-8?q?=D0=BE=D0=B3=D0=B4=D0=B0=20=D0=BD=D0=B5=20=D0=B1=D1=8B=D0=BB=20?= =?UTF-8?q?=D1=82=D0=B0=D0=BA=20=D0=B1=D0=BB=D0=B8=D0=B7=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=BA=20=D0=BA=D1=80=D0=B0=D1=8E=20=D0=BF=D1=80=D0=BE=D0=BF?= =?UTF-8?q?=D0=B0=D1=81=D1=82=D0=B8,=20=D0=B7=D0=B4=D0=B5=D1=81=D1=8C=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=B2=D0=BE=D0=BB=D1=8C=D0=BD=D0=BE=20=D1=81=D0=B2?= =?UTF-8?q?=D0=B5=D0=B6=D0=BE,=20=D0=BD=D0=BE=20=D0=BD=D0=B5=20=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=B5=D0=B5=20=D1=81=D1=82=D1=80=D0=B0=D1=88=D0=BD?= =?UTF-8?q?=D0=BE.=20=D1=82=D0=B5=D0=BC=D0=BD=D0=BE=D1=82=D0=B0=20=D0=B2?= =?UTF-8?q?=D0=BD=D0=B8=D0=B7=D1=83=20=D0=B7=D0=B0=D1=81=D1=82=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D1=8F=D0=B5=D1=82=20=D1=87=D1=82=D0=BE-=D1=82=D0=BE=20?= =?UTF-8?q?=D0=B2=D0=BD=D1=83=D1=82=D1=80=D0=B8=20=D0=B3=D0=BE=D0=BB=D0=BE?= =?UTF-8?q?=D0=B2=D1=8B=20=D0=B2=D0=B8=D0=B1=D1=80=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D1=82=D1=8C,=20=D0=BA=D1=80=D0=B8=D1=87=D0=B0=20=D0=BE?= =?UTF-8?q?=20=D0=BD=D0=B5=D0=BF=D1=80=D0=B5=D0=BE=D0=B4=D0=BE=D0=BB=D0=B8?= =?UTF-8?q?=D0=BC=D0=BE=D0=B9=20=D0=BE=D0=BF=D0=B0=D1=81=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B8,=20=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=BD=D0=B0=D1=85=D0=BE=D0=B4=D0=B8=D1=82=D1=81=D1=8F=20=D0=B1?= =?UTF-8?q?=D1=83=D0=BA=D0=B2=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=20=D0=B2=20?= =?UTF-8?q?=D1=88=D0=B0=D0=B3=D0=B5.=20=D0=B4=D0=B0=D0=B6=D0=B5=20=D0=BD?= =?UTF-8?q?=D0=B5=20=D0=B7=D0=BD=D0=B0=D1=8E,=20=D1=87=D1=82=D0=BE=20?= =?UTF-8?q?=D0=B1=D1=83=D0=B4=D0=B5=D1=82=20=D0=B4=D0=B0=D0=BB=D1=8C=D1=88?= =?UTF-8?q?=D0=B5=20-=20=D0=BC=D0=BB=D0=B8=D1=82=D0=B0...=20=D0=BE=D1=81..?= =?UTF-8?q?.=20=D1=82=D1=81=D1=87=D0=BC=D0=B8...=20=D1=80=D0=BF=D0=BF...?= =?UTF-8?q?=20=D0=B2=D1=81=D0=B5=20=D0=BE=D0=BD=D0=B8=20=D0=BF=D0=BE=D0=B4?= =?UTF-8?q?=D1=82=D0=B0=D0=BB=D0=BA=D0=B8=D0=B2=D0=B0=D1=8E=D1=82=20=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D1=82=D1=8C=20=D0=BD=D0=B0=20=D1=88=D0=B0=D0=B3=20?= =?UTF-8?q?=D0=B1=D0=BB=D0=B8=D0=B6=D0=B5=20=D0=BA=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=BF=D0=B0=D1=81=D1=82=D0=B8,=20=D0=B8=D0=BC=D1=8F=20=D0=BA?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D1=80=D0=BE=D0=B9=20-?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectFlowerShop/FormFlowers.Designer.cs | 2 +- ProjectFlowerShop/FormFlowers.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ProjectFlowerShop/FormFlowers.Designer.cs b/ProjectFlowerShop/FormFlowers.Designer.cs index 9c2001a..7e9c22c 100644 --- a/ProjectFlowerShop/FormFlowers.Designer.cs +++ b/ProjectFlowerShop/FormFlowers.Designer.cs @@ -97,7 +97,7 @@ Controls.Add(DataGridView); Name = "FormFlowers"; Text = "Цветы"; - Load += IceCreamsForm_Load; + Load += FormFlowers_Load; ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); ResumeLayout(false); } diff --git a/ProjectFlowerShop/FormFlowers.cs b/ProjectFlowerShop/FormFlowers.cs index 49c1b87..80ede4f 100644 --- a/ProjectFlowerShop/FormFlowers.cs +++ b/ProjectFlowerShop/FormFlowers.cs @@ -25,7 +25,7 @@ namespace ProjectFlowerShop _logic = logic; } - private void IceCreamsForm_Load(object sender, EventArgs e) + private void FormFlowers_Load(object sender, EventArgs e) { LoadData(); }