From eec33dadc41cfce7cb76cba2428fc3f6e5cf1487 Mon Sep 17 00:00:00 2001 From: Sergey Kozyrev Date: Tue, 20 Feb 2024 19:32:55 +0400 Subject: [PATCH 01/14] savecommit --- .../BusinessLogic/ShopLogic.cs | 129 +++++++++++++++ .../BindingModels/ShopBindingModel.cs | 18 +++ .../BusinessLogicsContracts/IShopLogic.cs | 22 +++ .../SearchModels/ShopSearchModel.cs | 14 ++ .../StoragesContracts/IShopStorage.cs | 23 +++ .../ViewModels/ShopViewModel.cs | 18 +++ .../Models/IShopModel.cs | 15 ++ .../DataListSingleton.cs | 2 + .../Implements/OrderStorage.cs | 16 +- .../SewingDressesListImplement/Models/Shop.cs | 20 +++ .../SewingDressesView/ShopForm.Designer.cs | 39 +++++ SewingDresses/SewingDressesView/ShopForm.cs | 20 +++ SewingDresses/SewingDressesView/ShopForm.resx | 120 ++++++++++++++ .../SewingDressesView/ShopsForm.Designer.cs | 39 +++++ SewingDresses/SewingDressesView/ShopsForm.cs | 20 +++ .../SewingDressesView/ShopsForm.resx | 120 ++++++++++++++ .../SewingDressesView/SupplyForm.Designer.cs | 141 +++++++++++++++++ SewingDresses/SewingDressesView/SupplyForm.cs | 149 ++++++++++++++++++ .../SewingDressesView/SupplyForm.resx | 120 ++++++++++++++ 19 files changed, 1043 insertions(+), 2 deletions(-) create mode 100644 SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ShopLogic.cs create mode 100644 SewingDresses/SewingDressesContracts/BindingModels/ShopBindingModel.cs create mode 100644 SewingDresses/SewingDressesContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 SewingDresses/SewingDressesContracts/SearchModels/ShopSearchModel.cs create mode 100644 SewingDresses/SewingDressesContracts/StoragesContracts/IShopStorage.cs create mode 100644 SewingDresses/SewingDressesContracts/ViewModels/ShopViewModel.cs create mode 100644 SewingDresses/SewingDressesDataModels/Models/IShopModel.cs create mode 100644 SewingDresses/SewingDressesListImplement/Models/Shop.cs create mode 100644 SewingDresses/SewingDressesView/ShopForm.Designer.cs create mode 100644 SewingDresses/SewingDressesView/ShopForm.cs create mode 100644 SewingDresses/SewingDressesView/ShopForm.resx create mode 100644 SewingDresses/SewingDressesView/ShopsForm.Designer.cs create mode 100644 SewingDresses/SewingDressesView/ShopsForm.cs create mode 100644 SewingDresses/SewingDressesView/ShopsForm.resx create mode 100644 SewingDresses/SewingDressesView/SupplyForm.Designer.cs create mode 100644 SewingDresses/SewingDressesView/SupplyForm.cs create mode 100644 SewingDresses/SewingDressesView/SupplyForm.resx diff --git a/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ShopLogic.cs b/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ShopLogic.cs new file mode 100644 index 0000000..e52b504 --- /dev/null +++ b/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ShopLogic.cs @@ -0,0 +1,129 @@ +using Microsoft.Extensions.Logging; +using SewingDressesContracts.BindingModels; +using SewingDressesContracts.BusinessLogicsContracts; +using SewingDressesContracts.SearchModels; +using SewingDressesContracts.StoragesContracts; +using SewingDressesContracts.ViewModels; +using SewingDressesDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesBusinessLogic.BusinessLogic +{ + 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 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.Adress)) + { + 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.Adress, model.DateOpen, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + Name = model.ShopName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + public bool MakeSupply(ShopSearchModel model, IDressModel dress, int count) + { + if (model == null) + return false; + return _shopStorage.SupplyDress(model, dress, count); + } + } +} diff --git a/SewingDresses/SewingDressesContracts/BindingModels/ShopBindingModel.cs b/SewingDresses/SewingDressesContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..6ae5676 --- /dev/null +++ b/SewingDresses/SewingDressesContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,18 @@ +using SewingDressesDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + public string ShopName { get; set; } + public string Adress { get; set; } + public DateTime DateOpen { get; set; } + public Dictionary ShopDresses { get; set; } = new(); + } +} diff --git a/SewingDresses/SewingDressesContracts/BusinessLogicsContracts/IShopLogic.cs b/SewingDresses/SewingDressesContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..56f29cc --- /dev/null +++ b/SewingDresses/SewingDressesContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,22 @@ +using SewingDressesContracts.BindingModels; +using SewingDressesContracts.SearchModels; +using SewingDressesContracts.ViewModels; +using SewingDressesDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesContracts.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, IDressModel dress, int count); + } +} diff --git a/SewingDresses/SewingDressesContracts/SearchModels/ShopSearchModel.cs b/SewingDresses/SewingDressesContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..410d012 --- /dev/null +++ b/SewingDresses/SewingDressesContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? Name { get; set; } + } +} diff --git a/SewingDresses/SewingDressesContracts/StoragesContracts/IShopStorage.cs b/SewingDresses/SewingDressesContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..5758bce --- /dev/null +++ b/SewingDresses/SewingDressesContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,23 @@ +using SewingDressesContracts.BindingModels; +using SewingDressesContracts.SearchModels; +using SewingDressesContracts.ViewModels; +using SewingDressesDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesContracts.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 SupplyDress(ShopSearchModel model, IDressModel dress, int count); + } +} diff --git a/SewingDresses/SewingDressesContracts/ViewModels/ShopViewModel.cs b/SewingDresses/SewingDressesContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..0b22497 --- /dev/null +++ b/SewingDresses/SewingDressesContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,18 @@ +using SewingDressesDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + public string ShopName { get; set; } = string.Empty; + public string Adress { get; set; } = string.Empty; + public DateTime DateOpen { get; set; } + public Dictionary ShopDresses { get; set; } = new(); + } +} diff --git a/SewingDresses/SewingDressesDataModels/Models/IShopModel.cs b/SewingDresses/SewingDressesDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..a423ef5 --- /dev/null +++ b/SewingDresses/SewingDressesDataModels/Models/IShopModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + string Adress { get; } + DateTime DateOpen { get; } + } +} diff --git a/SewingDresses/SewingDressesListImplement/DataListSingleton.cs b/SewingDresses/SewingDressesListImplement/DataListSingleton.cs index 0bdf6ab..b89fe53 100644 --- a/SewingDresses/SewingDressesListImplement/DataListSingleton.cs +++ b/SewingDresses/SewingDressesListImplement/DataListSingleton.cs @@ -8,11 +8,13 @@ namespace SewingDressesListImplement public List Components { get; set; } public List Orders { get; set; } public List Dresses { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Dresses = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/SewingDresses/SewingDressesListImplement/Implements/OrderStorage.cs b/SewingDresses/SewingDressesListImplement/Implements/OrderStorage.cs index 7201f57..ac8d62f 100644 --- a/SewingDresses/SewingDressesListImplement/Implements/OrderStorage.cs +++ b/SewingDresses/SewingDressesListImplement/Implements/OrderStorage.cs @@ -19,7 +19,7 @@ namespace SewingDressesListImplement.Implements var result = new List(); foreach (var order in _source.Orders) { - result.Add(order.GetViewModel); + result.Add(AcessDressesStorage(order.GetViewModel)); } return result; } @@ -31,7 +31,7 @@ namespace SewingDressesListImplement.Implements { if (order.Id == model.Id) { - result.Add(order.GetViewModel); + result.Add(AcessDressesStorage(order.GetViewModel)); } } return result; @@ -94,5 +94,17 @@ namespace SewingDressesListImplement.Implements } return null; } + public OrderViewModel AcessDressesStorage(OrderViewModel model) + { + foreach(var dress in _source.Dresses) + { + if (dress.Id == model.DressId) + { + model.DressName = dress.DressName; + break; + } + } + return model; + } } } diff --git a/SewingDresses/SewingDressesListImplement/Models/Shop.cs b/SewingDresses/SewingDressesListImplement/Models/Shop.cs new file mode 100644 index 0000000..9615b12 --- /dev/null +++ b/SewingDresses/SewingDressesListImplement/Models/Shop.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SewingDressesContracts.ViewModels; +using SewingDressesDataModels.Models; +using SewingDressesContracts.BindingModels; + +namespace SewingDressesListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } + public string Adress { get; private set; } + public DateTime DateOpen { get; private set; } + public Dictionary ShopDresses { get; private set; } = new(); + } +} diff --git a/SewingDresses/SewingDressesView/ShopForm.Designer.cs b/SewingDresses/SewingDressesView/ShopForm.Designer.cs new file mode 100644 index 0000000..a07e403 --- /dev/null +++ b/SewingDresses/SewingDressesView/ShopForm.Designer.cs @@ -0,0 +1,39 @@ +namespace SewingDressesView +{ + 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() + { + this.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "ShopForm"; + } + + #endregion + } +} \ No newline at end of file diff --git a/SewingDresses/SewingDressesView/ShopForm.cs b/SewingDresses/SewingDressesView/ShopForm.cs new file mode 100644 index 0000000..17fb65f --- /dev/null +++ b/SewingDresses/SewingDressesView/ShopForm.cs @@ -0,0 +1,20 @@ +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 SewingDressesView +{ + public partial class ShopForm : Form + { + public ShopForm() + { + InitializeComponent(); + } + } +} diff --git a/SewingDresses/SewingDressesView/ShopForm.resx b/SewingDresses/SewingDressesView/ShopForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/SewingDresses/SewingDressesView/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/SewingDresses/SewingDressesView/ShopsForm.Designer.cs b/SewingDresses/SewingDressesView/ShopsForm.Designer.cs new file mode 100644 index 0000000..91d7a47 --- /dev/null +++ b/SewingDresses/SewingDressesView/ShopsForm.Designer.cs @@ -0,0 +1,39 @@ +namespace SewingDressesView +{ + 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() + { + this.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "ShopsForm"; + } + + #endregion + } +} \ No newline at end of file diff --git a/SewingDresses/SewingDressesView/ShopsForm.cs b/SewingDresses/SewingDressesView/ShopsForm.cs new file mode 100644 index 0000000..a70e26e --- /dev/null +++ b/SewingDresses/SewingDressesView/ShopsForm.cs @@ -0,0 +1,20 @@ +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 SewingDressesView +{ + public partial class ShopsForm : Form + { + public ShopsForm() + { + InitializeComponent(); + } + } +} diff --git a/SewingDresses/SewingDressesView/ShopsForm.resx b/SewingDresses/SewingDressesView/ShopsForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/SewingDresses/SewingDressesView/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/SewingDresses/SewingDressesView/SupplyForm.Designer.cs b/SewingDresses/SewingDressesView/SupplyForm.Designer.cs new file mode 100644 index 0000000..f74e507 --- /dev/null +++ b/SewingDresses/SewingDressesView/SupplyForm.Designer.cs @@ -0,0 +1,141 @@ +namespace SewingDressesView +{ + 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() + { + ShopComboBox = new ComboBox(); + DressComboBox = new ComboBox(); + CountTextBox = new TextBox(); + SaveButton = new Button(); + Cancel = new Button(); + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + SuspendLayout(); + // + // ShopComboBox + // + ShopComboBox.FormattingEnabled = true; + ShopComboBox.Location = new Point(155, 34); + ShopComboBox.Name = "ShopComboBox"; + ShopComboBox.Size = new Size(318, 28); + ShopComboBox.TabIndex = 0; + // + // DressComboBox + // + DressComboBox.FormattingEnabled = true; + DressComboBox.Location = new Point(155, 79); + DressComboBox.Name = "DressComboBox"; + DressComboBox.Size = new Size(318, 28); + DressComboBox.TabIndex = 1; + // + // CountTextBox + // + CountTextBox.Location = new Point(155, 128); + CountTextBox.Name = "CountTextBox"; + CountTextBox.Size = new Size(318, 27); + CountTextBox.TabIndex = 2; + // + // SaveButton + // + SaveButton.Location = new Point(252, 200); + SaveButton.Name = "SaveButton"; + SaveButton.Size = new Size(107, 36); + SaveButton.TabIndex = 3; + SaveButton.Text = "Сохранить"; + SaveButton.UseVisualStyleBackColor = true; + SaveButton.Click += SaveButton_Click; + // + // Cancel + // + Cancel.Location = new Point(365, 200); + Cancel.Name = "Cancel"; + Cancel.Size = new Size(108, 36); + Cancel.TabIndex = 4; + Cancel.Text = "Отмена"; + Cancel.UseVisualStyleBackColor = true; + Cancel.Click += CancelButton_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(40, 37); + label1.Name = "label1"; + label1.Size = new Size(69, 20); + label1.TabIndex = 5; + label1.Text = "Магазин"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(40, 82); + label2.Name = "label2"; + label2.Size = new Size(58, 20); + label2.TabIndex = 6; + label2.Text = "Платье"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(40, 131); + label3.Name = "label3"; + label3.Size = new Size(90, 20); + label3.TabIndex = 7; + label3.Text = "Количество"; + // + // SupplyForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(506, 260); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(Cancel); + Controls.Add(SaveButton); + Controls.Add(CountTextBox); + Controls.Add(DressComboBox); + Controls.Add(ShopComboBox); + Name = "SupplyForm"; + Text = "SupplyForm"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox ShopComboBox; + private ComboBox DressComboBox; + private TextBox CountTextBox; + private Button SaveButton; + private Button Cancel; + private Label label1; + private Label label2; + private Label label3; + } +} \ No newline at end of file diff --git a/SewingDresses/SewingDressesView/SupplyForm.cs b/SewingDresses/SewingDressesView/SupplyForm.cs new file mode 100644 index 0000000..1542093 --- /dev/null +++ b/SewingDresses/SewingDressesView/SupplyForm.cs @@ -0,0 +1,149 @@ +using SewingDressesContracts.BusinessLogicsContracts; +using SewingDressesContracts.SearchModels; +using SewingDressesContracts.ViewModels; +using SewingDressesDataModels.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 SewingDressesView +{ + public partial class SupplyForm : Form + { + private readonly List? _dressList; + private readonly List? _shopsList; + IShopLogic _shopLogic; + IDressLogic _dressLogic; + public int ShopId + { + get + { + return Convert.ToInt32(ShopComboBox.SelectedValue); + } + set + { + ShopComboBox.SelectedValue = value; + } + } + public int DressId + { + get + { + return Convert.ToInt32(DressComboBox.SelectedValue); + } + set + { + DressComboBox.SelectedValue = value; + } + } + + public IDressModel? DressModel + { + get + { + if (_dressList == null) + { + return null; + } + foreach (var elem in _dressList) + { + if (elem.Id == DressId) + { + return elem; + } + } + return null; + } + } + + + public int Count + { + get { return Convert.ToInt32(CountTextBox.Text); } + set + { CountTextBox.Text = value.ToString(); } + } + public SupplyForm(IDressLogic dressLogic, IShopLogic shopLogic) + { + InitializeComponent(); + _shopLogic = shopLogic; + _dressLogic = dressLogic; + _dressList = dressLogic.ReadList(null); + _shopsList = shopLogic.ReadList(null); + if (_dressList != null) + { + DressComboBox.DisplayMember = "DressName"; + DressComboBox.ValueMember = "Id"; + DressComboBox.DataSource = _dressList; + DressComboBox.SelectedItem = null; + } + if (_shopsList != null) + { + ShopComboBox.DisplayMember = "ShopName"; + ShopComboBox.ValueMember = "Id"; + ShopComboBox.DataSource = _shopsList; + ShopComboBox.SelectedItem = null; + } + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(CountTextBox.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (DressComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите мороженное", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (ShopComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + try + { + int count = Convert.ToInt32(CountTextBox.Text); + + bool res = _shopLogic.MakeSupply( + new ShopSearchModel() { Id = Convert.ToInt32(ShopComboBox.SelectedValue) }, + _dressLogic.ReadElement(new() { Id = Convert.ToInt32(DressComboBox.SelectedValue) }), + count + ); + + if (!res) + { + throw new Exception("Ошибка при пополнении. Дополнительная информация в логах"); + } + + MessageBox.Show("Пополнение прошло успешно"); + DialogResult = DialogResult.OK; + Close(); + + } + catch (Exception er) + { + MessageBox.Show("Ошибка пополнения"); + return; + } + } + + private void CancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SewingDresses/SewingDressesView/SupplyForm.resx b/SewingDresses/SewingDressesView/SupplyForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SewingDresses/SewingDressesView/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 -- 2.25.1 From 4720434f98326456531b83aea85db2db92fdf5d2 Mon Sep 17 00:00:00 2001 From: Sergey Kozyrev Date: Wed, 21 Feb 2024 17:38:19 +0400 Subject: [PATCH 02/14] UpdateCommit --- .../Implements/ShopStorage.cs | 140 +++++++++++++++ .../SewingDressesListImplement/Models/Shop.cs | 34 ++++ .../SewingDressesView/MainForm.Designer.cs | 24 ++- SewingDresses/SewingDressesView/MainForm.cs | 18 ++ SewingDresses/SewingDressesView/Program.cs | 5 + .../SewingDressesView/ShopForm.Designer.cs | 161 +++++++++++++++++- SewingDresses/SewingDressesView/ShopForm.cs | 106 +++++++++++- SewingDresses/SewingDressesView/ShopForm.resx | 74 +++++--- .../SewingDressesView/ShopsForm.Designer.cs | 129 +++++++++++++- SewingDresses/SewingDressesView/ShopsForm.cs | 102 ++++++++++- .../SewingDressesView/ShopsForm.resx | 65 ++++--- 11 files changed, 793 insertions(+), 65 deletions(-) create mode 100644 SewingDresses/SewingDressesListImplement/Implements/ShopStorage.cs diff --git a/SewingDresses/SewingDressesListImplement/Implements/ShopStorage.cs b/SewingDresses/SewingDressesListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..9b58370 --- /dev/null +++ b/SewingDresses/SewingDressesListImplement/Implements/ShopStorage.cs @@ -0,0 +1,140 @@ +using SewingDressesContracts.BindingModels; +using SewingDressesContracts.SearchModels; +using SewingDressesContracts.StoragesContracts; +using SewingDressesContracts.ViewModels; +using SewingDressesDataModels.Models; +using SewingDressesListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesListImplement.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 SupplyDress(ShopSearchModel model, IDressModel dress, int count) + { + if (model == null) + throw new ArgumentNullException(nameof(model)); + if (dress == null) + throw new ArgumentNullException(nameof(dress)); + if (count <= 0) + throw new ArgumentNullException("Количество должно быть положительным числом"); + + ShopViewModel curModel = GetElement(model); + if (curModel == null) + throw new ArgumentNullException(nameof(curModel)); + if (curModel.ShopDresses.TryGetValue(dress.Id, out var pair)) + { + curModel.ShopDresses[dress.Id] = (pair.Item1, pair.Item2 + count); + } + else + { + curModel.ShopDresses.Add(dress.Id, (dress, count)); + } + Update(new() + { + Id = curModel.Id, + ShopName = curModel.ShopName, + DateOpen = curModel.DateOpen, + Adress = curModel.Adress, + ShopDresses = curModel.ShopDresses, + }); + return true; + + } + } +} diff --git a/SewingDresses/SewingDressesListImplement/Models/Shop.cs b/SewingDresses/SewingDressesListImplement/Models/Shop.cs index 9615b12..3845ddf 100644 --- a/SewingDresses/SewingDressesListImplement/Models/Shop.cs +++ b/SewingDresses/SewingDressesListImplement/Models/Shop.cs @@ -16,5 +16,39 @@ namespace SewingDressesListImplement.Models public string Adress { get; private set; } public DateTime DateOpen { get; private set; } public Dictionary ShopDresses { get; private set; } = new(); + public static Shop? Create (ShopBindingModel model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Adress = model.Adress, + DateOpen = model.DateOpen, + ShopDresses = new() + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Adress = model.Adress; + DateOpen = model.DateOpen; + ShopDresses = model.ShopDresses; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Adress = Adress, + DateOpen = DateOpen, + ShopDresses = ShopDresses + }; } } diff --git a/SewingDresses/SewingDressesView/MainForm.Designer.cs b/SewingDresses/SewingDressesView/MainForm.Designer.cs index cee4ca6..35f8ddb 100644 --- a/SewingDresses/SewingDressesView/MainForm.Designer.cs +++ b/SewingDresses/SewingDressesView/MainForm.Designer.cs @@ -38,6 +38,8 @@ справочникиToolStripMenuItem = new ToolStripMenuItem(); компонентыToolStripMenuItem = new ToolStripMenuItem(); платьяToolStripMenuItem = new ToolStripMenuItem(); + магазиныToolStripMenuItem = new ToolStripMenuItem(); + поставкиToolStripMenuItem = new ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); menuStrip1.SuspendLayout(); SuspendLayout(); @@ -114,7 +116,7 @@ // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, платьяToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, платьяToolStripMenuItem, магазиныToolStripMenuItem, поставкиToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(117, 24); справочникиToolStripMenuItem.Text = "Справочники"; @@ -122,17 +124,31 @@ // компонентыToolStripMenuItem // компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(182, 26); + компонентыToolStripMenuItem.Size = new Size(224, 26); компонентыToolStripMenuItem.Text = "Компоненты"; компонентыToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; // // платьяToolStripMenuItem // платьяToolStripMenuItem.Name = "платьяToolStripMenuItem"; - платьяToolStripMenuItem.Size = new Size(182, 26); + платьяToolStripMenuItem.Size = new Size(224, 26); платьяToolStripMenuItem.Text = "Платья"; платьяToolStripMenuItem.Click += DressesToolStripMenuItem_Click; // + // магазиныToolStripMenuItem + // + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(224, 26); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; + // + // поставкиToolStripMenuItem + // + поставкиToolStripMenuItem.Name = "поставкиToolStripMenuItem"; + поставкиToolStripMenuItem.Size = new Size(224, 26); + поставкиToolStripMenuItem.Text = "Поставки"; + поставкиToolStripMenuItem.Click += SupplyToolStripMenuItem_Click; + // // MainForm // AutoScaleDimensions = new SizeF(8F, 20F); @@ -167,5 +183,7 @@ private ToolStripMenuItem справочникиToolStripMenuItem; private ToolStripMenuItem компонентыToolStripMenuItem; private ToolStripMenuItem платьяToolStripMenuItem; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem поставкиToolStripMenuItem; } } \ No newline at end of file diff --git a/SewingDresses/SewingDressesView/MainForm.cs b/SewingDresses/SewingDressesView/MainForm.cs index 4e37350..00ee379 100644 --- a/SewingDresses/SewingDressesView/MainForm.cs +++ b/SewingDresses/SewingDressesView/MainForm.cs @@ -142,5 +142,23 @@ namespace SewingDressesView { LoadData(); } + + private void ShopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(ShopsForm)); + if (service is ShopsForm form) + { + form.ShowDialog(); + } + } + + private void SupplyToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(ShopsForm)); + if (service is ShopsForm form) + { + form.ShowDialog(); + } + } } } diff --git a/SewingDresses/SewingDressesView/Program.cs b/SewingDresses/SewingDressesView/Program.cs index 34e4274..b688eb9 100644 --- a/SewingDresses/SewingDressesView/Program.cs +++ b/SewingDresses/SewingDressesView/Program.cs @@ -35,6 +35,8 @@ namespace SewingDressesView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -42,6 +44,9 @@ namespace SewingDressesView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/SewingDresses/SewingDressesView/ShopForm.Designer.cs b/SewingDresses/SewingDressesView/ShopForm.Designer.cs index a07e403..6188727 100644 --- a/SewingDresses/SewingDressesView/ShopForm.Designer.cs +++ b/SewingDresses/SewingDressesView/ShopForm.Designer.cs @@ -28,12 +28,165 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "ShopForm"; + dateTimePicker = new DateTimePicker(); + textBoxName = new TextBox(); + textBoxAdress = new TextBox(); + dataGridView = new DataGridView(); + Column1 = new DataGridViewTextBoxColumn(); + Column2 = new DataGridViewTextBoxColumn(); + Column3 = new DataGridViewTextBoxColumn(); + Column4 = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dateTimePicker + // + dateTimePicker.Location = new Point(714, 34); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(250, 27); + dateTimePicker.TabIndex = 0; + // + // textBoxName + // + textBoxName.Location = new Point(714, 85); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(250, 27); + textBoxName.TabIndex = 1; + // + // textBoxAdress + // + textBoxAdress.Location = new Point(714, 139); + textBoxAdress.Name = "textBoxAdress"; + textBoxAdress.Size = new Size(250, 27); + textBoxAdress.TabIndex = 2; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { Column1, Column2, Column3, Column4 }); + dataGridView.Location = new Point(10, 32); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(553, 380); + dataGridView.TabIndex = 3; + // + // Column1 + // + Column1.HeaderText = "Column1"; + Column1.MinimumWidth = 6; + Column1.Name = "Column1"; + Column1.Width = 125; + // + // Column2 + // + Column2.HeaderText = "Column2"; + Column2.MinimumWidth = 6; + Column2.Name = "Column2"; + Column2.Width = 125; + // + // Column3 + // + Column3.HeaderText = "Column3"; + Column3.MinimumWidth = 6; + Column3.Name = "Column3"; + Column3.Width = 125; + // + // Column4 + // + Column4.HeaderText = "Column4"; + Column4.MinimumWidth = 6; + Column4.Name = "Column4"; + Column4.Width = 125; + // + // buttonSave + // + buttonSave.Location = new Point(714, 219); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(870, 219); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(592, 39); + label1.Name = "label1"; + label1.Size = new Size(110, 20); + label1.TabIndex = 6; + label1.Text = "Дата создания"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(592, 88); + label2.Name = "label2"; + label2.Size = new Size(77, 20); + label2.TabIndex = 7; + label2.Text = "Название"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(592, 142); + label3.Name = "label3"; + label3.Size = new Size(51, 20); + label3.TabIndex = 8; + label3.Text = "Адрес"; + // + // ShopForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(976, 450); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(dataGridView); + Controls.Add(textBoxAdress); + Controls.Add(textBoxName); + Controls.Add(dateTimePicker); + Name = "ShopForm"; + Text = "ShopForm"; + Load += ShopForm_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); } #endregion + + private DateTimePicker dateTimePicker; + private TextBox textBoxName; + private TextBox textBoxAdress; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn Column1; + private DataGridViewTextBoxColumn Column2; + private DataGridViewTextBoxColumn Column3; + private DataGridViewTextBoxColumn Column4; + private Button buttonSave; + private Button buttonCancel; + private Label label1; + private Label label2; + private Label label3; } } \ No newline at end of file diff --git a/SewingDresses/SewingDressesView/ShopForm.cs b/SewingDresses/SewingDressesView/ShopForm.cs index 17fb65f..3d3224a 100644 --- a/SewingDresses/SewingDressesView/ShopForm.cs +++ b/SewingDresses/SewingDressesView/ShopForm.cs @@ -1,4 +1,9 @@ -using System; +using Microsoft.Extensions.Logging; +using SewingDressesContracts.BindingModels; +using SewingDressesContracts.BusinessLogicsContracts; +using SewingDressesContracts.SearchModels; +using SewingDressesDataModels.Models; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,9 +17,106 @@ namespace SewingDressesView { public partial class ShopForm : Form { - public ShopForm() + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public int? _id; + private Dictionary _dresses; + public ShopForm(ILogger logger, IShopLogic logic) { InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void ShopForm_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Shop load"); + try + { + var shop = _logic.ReadElement(new ShopSearchModel { Id = _id }); + if (shop != null) + { + textBoxName.Text = shop.ShopName; + textBoxAdress.Text = shop.Adress; + dateTimePicker.Text = shop.DateOpen.ToString(); + _dresses = shop.ShopDresses; + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Load shop error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Load dresses"); + try + { + if (_dresses != null) + { + foreach (var dress in _dresses) + { + dataGridView.Rows.Add(new object[] { dress.Key, dress.Value.Item1.DressName, dress.Value.Item1.Price, dress.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Load dresses into shop error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAdress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Save shop"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Adress = textBoxAdress.Text, + DateOpen = dateTimePicker.Value.Date, + ShopDresses = _dresses + }; + 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, "Save shop error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); } } } diff --git a/SewingDresses/SewingDressesView/ShopForm.resx b/SewingDresses/SewingDressesView/ShopForm.resx index 1af7de1..58b3d6d 100644 --- a/SewingDresses/SewingDressesView/ShopForm.resx +++ b/SewingDresses/SewingDressesView/ShopForm.resx @@ -1,17 +1,17 @@  - @@ -117,4 +117,28 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + + + True + + + True + + + True + + + True + + + True + + + True + + + True + \ No newline at end of file diff --git a/SewingDresses/SewingDressesView/ShopsForm.Designer.cs b/SewingDresses/SewingDressesView/ShopsForm.Designer.cs index 91d7a47..8873a8c 100644 --- a/SewingDresses/SewingDressesView/ShopsForm.Designer.cs +++ b/SewingDresses/SewingDressesView/ShopsForm.Designer.cs @@ -28,12 +28,133 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "ShopsForm"; + dataGridView = new DataGridView(); + Column1 = new DataGridViewTextBoxColumn(); + Column2 = new DataGridViewTextBoxColumn(); + Column3 = new DataGridViewTextBoxColumn(); + Column4 = new DataGridViewTextBoxColumn(); + Column5 = new DataGridViewTextBoxColumn(); + buttonAdd = new Button(); + buttonUpdate = new Button(); + buttonReset = new Button(); + buttonDelete = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { Column1, Column2, Column3, Column4, Column5 }); + dataGridView.Location = new Point(14, 17); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(646, 415); + dataGridView.TabIndex = 0; + // + // Column1 + // + Column1.HeaderText = "Column1"; + Column1.MinimumWidth = 6; + Column1.Name = "Column1"; + Column1.Width = 125; + // + // Column2 + // + Column2.HeaderText = "Column2"; + Column2.MinimumWidth = 6; + Column2.Name = "Column2"; + Column2.Width = 125; + // + // Column3 + // + Column3.HeaderText = "Column3"; + Column3.MinimumWidth = 6; + Column3.Name = "Column3"; + Column3.Width = 125; + // + // Column4 + // + Column4.HeaderText = "Column4"; + Column4.MinimumWidth = 6; + Column4.Name = "Column4"; + Column4.Width = 125; + // + // Column5 + // + Column5.HeaderText = "Column5"; + Column5.MinimumWidth = 6; + Column5.Name = "Column5"; + Column5.Width = 125; + // + // buttonAdd + // + buttonAdd.Location = new Point(797, 49); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 29); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(797, 114); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(94, 29); + buttonUpdate.TabIndex = 2; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // buttonReset + // + buttonReset.Location = new Point(797, 184); + buttonReset.Name = "buttonReset"; + buttonReset.Size = new Size(94, 29); + buttonReset.TabIndex = 3; + buttonReset.Text = "Обновить"; + buttonReset.UseVisualStyleBackColor = true; + buttonReset.Click += buttonReset_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(797, 263); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(94, 29); + buttonDelete.TabIndex = 4; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // ShopsForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(942, 450); + Controls.Add(buttonDelete); + Controls.Add(buttonReset); + Controls.Add(buttonUpdate); + 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 DataGridViewTextBoxColumn Column1; + private DataGridViewTextBoxColumn Column2; + private DataGridViewTextBoxColumn Column3; + private DataGridViewTextBoxColumn Column4; + private DataGridViewTextBoxColumn Column5; + private Button buttonAdd; + private Button buttonUpdate; + private Button buttonReset; + private Button buttonDelete; } } \ No newline at end of file diff --git a/SewingDresses/SewingDressesView/ShopsForm.cs b/SewingDresses/SewingDressesView/ShopsForm.cs index a70e26e..56eccbf 100644 --- a/SewingDresses/SewingDressesView/ShopsForm.cs +++ b/SewingDresses/SewingDressesView/ShopsForm.cs @@ -1,4 +1,7 @@ -using System; +using Microsoft.Extensions.Logging; +using SewingDressesContracts.BindingModels; +using SewingDressesContracts.BusinessLogicsContracts; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,9 +15,104 @@ namespace SewingDressesView { public partial class ShopsForm : Form { - public ShopsForm() + 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["Adress"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["DateOpen"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ShopDresses"].Visible = false; + } + _logger.LogInformation("Load shops"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Load shop error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ShopsForm_Load(object sender, EventArgs e) + { + LoadData(); + } + + 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 buttonUpdate_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 buttonReset_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void buttonDelete_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); + } + } + } } } } diff --git a/SewingDresses/SewingDressesView/ShopsForm.resx b/SewingDresses/SewingDressesView/ShopsForm.resx index 1af7de1..970e83c 100644 --- a/SewingDresses/SewingDressesView/ShopsForm.resx +++ b/SewingDresses/SewingDressesView/ShopsForm.resx @@ -1,17 +1,17 @@  - @@ -117,4 +117,19 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + + + True + + + True + + + True + + + True + \ No newline at end of file -- 2.25.1 From b8e31eb30870334abb21b58b85f60ec902e48966 Mon Sep 17 00:00:00 2001 From: Sergey Kozyrev Date: Fri, 23 Feb 2024 17:16:11 +0400 Subject: [PATCH 03/14] HardFinal --- .../ViewModels/ShopViewModel.cs | 4 + SewingDresses/SewingDressesView/MainForm.cs | 4 +- .../SewingDressesView/ShopForm.Designer.cs | 77 ++++++++++--------- SewingDresses/SewingDressesView/ShopForm.resx | 21 +---- .../SewingDressesView/ShopsForm.Designer.cs | 46 ----------- .../SewingDressesView/ShopsForm.resx | 15 ---- 6 files changed, 48 insertions(+), 119 deletions(-) diff --git a/SewingDresses/SewingDressesContracts/ViewModels/ShopViewModel.cs b/SewingDresses/SewingDressesContracts/ViewModels/ShopViewModel.cs index 0b22497..9d7d47f 100644 --- a/SewingDresses/SewingDressesContracts/ViewModels/ShopViewModel.cs +++ b/SewingDresses/SewingDressesContracts/ViewModels/ShopViewModel.cs @@ -1,6 +1,7 @@ using SewingDressesDataModels.Models; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -10,8 +11,11 @@ namespace SewingDressesContracts.ViewModels public class ShopViewModel : IShopModel { public int Id { get; set; } + [DisplayName("Название магазина")] public string ShopName { get; set; } = string.Empty; + [DisplayName("Адрес")] public string Adress { get; set; } = string.Empty; + [DisplayName("Дата открытия")] public DateTime DateOpen { get; set; } public Dictionary ShopDresses { get; set; } = new(); } diff --git a/SewingDresses/SewingDressesView/MainForm.cs b/SewingDresses/SewingDressesView/MainForm.cs index 00ee379..828e9a4 100644 --- a/SewingDresses/SewingDressesView/MainForm.cs +++ b/SewingDresses/SewingDressesView/MainForm.cs @@ -154,8 +154,8 @@ namespace SewingDressesView private void SupplyToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(ShopsForm)); - if (service is ShopsForm form) + var service = Program.ServiceProvider?.GetService(typeof(SupplyForm)); + if (service is SupplyForm form) { form.ShowDialog(); } diff --git a/SewingDresses/SewingDressesView/ShopForm.Designer.cs b/SewingDresses/SewingDressesView/ShopForm.Designer.cs index 6188727..4f5ad5e 100644 --- a/SewingDresses/SewingDressesView/ShopForm.Designer.cs +++ b/SewingDresses/SewingDressesView/ShopForm.Designer.cs @@ -32,15 +32,15 @@ textBoxName = new TextBox(); textBoxAdress = new TextBox(); dataGridView = new DataGridView(); - Column1 = new DataGridViewTextBoxColumn(); - Column2 = new DataGridViewTextBoxColumn(); - Column3 = new DataGridViewTextBoxColumn(); - Column4 = new DataGridViewTextBoxColumn(); buttonSave = new Button(); buttonCancel = new Button(); label1 = new Label(); label2 = new Label(); label3 = new Label(); + IdColumn = new DataGridViewTextBoxColumn(); + Title = new DataGridViewTextBoxColumn(); + Cost = new DataGridViewTextBoxColumn(); + Count = new DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // @@ -68,42 +68,14 @@ // dataGridView // dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Columns.AddRange(new DataGridViewColumn[] { Column1, Column2, Column3, Column4 }); + dataGridView.Columns.AddRange(new DataGridViewColumn[] { IdColumn, Title, Cost, Count }); dataGridView.Location = new Point(10, 32); dataGridView.Name = "dataGridView"; dataGridView.RowHeadersWidth = 51; dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new Size(553, 380); + dataGridView.Size = new Size(554, 380); dataGridView.TabIndex = 3; // - // Column1 - // - Column1.HeaderText = "Column1"; - Column1.MinimumWidth = 6; - Column1.Name = "Column1"; - Column1.Width = 125; - // - // Column2 - // - Column2.HeaderText = "Column2"; - Column2.MinimumWidth = 6; - Column2.Name = "Column2"; - Column2.Width = 125; - // - // Column3 - // - Column3.HeaderText = "Column3"; - Column3.MinimumWidth = 6; - Column3.Name = "Column3"; - Column3.Width = 125; - // - // Column4 - // - Column4.HeaderText = "Column4"; - Column4.MinimumWidth = 6; - Column4.Name = "Column4"; - Column4.Width = 125; - // // buttonSave // buttonSave.Location = new Point(714, 219); @@ -151,6 +123,35 @@ label3.TabIndex = 8; label3.Text = "Адрес"; // + // IdColumn + // + IdColumn.HeaderText = "Номер платья"; + IdColumn.MinimumWidth = 6; + IdColumn.Name = "IdColumn"; + IdColumn.Visible = false; + IdColumn.Width = 125; + // + // Title + // + Title.HeaderText = "Название"; + Title.MinimumWidth = 6; + Title.Name = "Title"; + Title.Width = 125; + // + // Cost + // + Cost.HeaderText = "Цена"; + Cost.MinimumWidth = 6; + Cost.Name = "Cost"; + Cost.Width = 125; + // + // Count + // + Count.HeaderText = "Количество"; + Count.MinimumWidth = 6; + Count.Name = "Count"; + Count.Width = 125; + // // ShopForm // AutoScaleDimensions = new SizeF(8F, 20F); @@ -179,14 +180,14 @@ private TextBox textBoxName; private TextBox textBoxAdress; private DataGridView dataGridView; - private DataGridViewTextBoxColumn Column1; - private DataGridViewTextBoxColumn Column2; - private DataGridViewTextBoxColumn Column3; - private DataGridViewTextBoxColumn Column4; private Button buttonSave; private Button buttonCancel; private Label label1; private Label label2; private Label label3; + private DataGridViewTextBoxColumn IdColumn; + private DataGridViewTextBoxColumn Title; + private DataGridViewTextBoxColumn Cost; + private DataGridViewTextBoxColumn Count; } } \ No newline at end of file diff --git a/SewingDresses/SewingDressesView/ShopForm.resx b/SewingDresses/SewingDressesView/ShopForm.resx index 58b3d6d..141820e 100644 --- a/SewingDresses/SewingDressesView/ShopForm.resx +++ b/SewingDresses/SewingDressesView/ShopForm.resx @@ -117,28 +117,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + True - + True - - True - - - True - - - True - - - True - - - True - - + True \ No newline at end of file diff --git a/SewingDresses/SewingDressesView/ShopsForm.Designer.cs b/SewingDresses/SewingDressesView/ShopsForm.Designer.cs index 8873a8c..12204ef 100644 --- a/SewingDresses/SewingDressesView/ShopsForm.Designer.cs +++ b/SewingDresses/SewingDressesView/ShopsForm.Designer.cs @@ -29,11 +29,6 @@ private void InitializeComponent() { dataGridView = new DataGridView(); - Column1 = new DataGridViewTextBoxColumn(); - Column2 = new DataGridViewTextBoxColumn(); - Column3 = new DataGridViewTextBoxColumn(); - Column4 = new DataGridViewTextBoxColumn(); - Column5 = new DataGridViewTextBoxColumn(); buttonAdd = new Button(); buttonUpdate = new Button(); buttonReset = new Button(); @@ -44,7 +39,6 @@ // dataGridView // dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Columns.AddRange(new DataGridViewColumn[] { Column1, Column2, Column3, Column4, Column5 }); dataGridView.Location = new Point(14, 17); dataGridView.Name = "dataGridView"; dataGridView.RowHeadersWidth = 51; @@ -52,41 +46,6 @@ dataGridView.Size = new Size(646, 415); dataGridView.TabIndex = 0; // - // Column1 - // - Column1.HeaderText = "Column1"; - Column1.MinimumWidth = 6; - Column1.Name = "Column1"; - Column1.Width = 125; - // - // Column2 - // - Column2.HeaderText = "Column2"; - Column2.MinimumWidth = 6; - Column2.Name = "Column2"; - Column2.Width = 125; - // - // Column3 - // - Column3.HeaderText = "Column3"; - Column3.MinimumWidth = 6; - Column3.Name = "Column3"; - Column3.Width = 125; - // - // Column4 - // - Column4.HeaderText = "Column4"; - Column4.MinimumWidth = 6; - Column4.Name = "Column4"; - Column4.Width = 125; - // - // Column5 - // - Column5.HeaderText = "Column5"; - Column5.MinimumWidth = 6; - Column5.Name = "Column5"; - Column5.Width = 125; - // // buttonAdd // buttonAdd.Location = new Point(797, 49); @@ -147,11 +106,6 @@ #endregion private DataGridView dataGridView; - private DataGridViewTextBoxColumn Column1; - private DataGridViewTextBoxColumn Column2; - private DataGridViewTextBoxColumn Column3; - private DataGridViewTextBoxColumn Column4; - private DataGridViewTextBoxColumn Column5; private Button buttonAdd; private Button buttonUpdate; private Button buttonReset; diff --git a/SewingDresses/SewingDressesView/ShopsForm.resx b/SewingDresses/SewingDressesView/ShopsForm.resx index 970e83c..af32865 100644 --- a/SewingDresses/SewingDressesView/ShopsForm.resx +++ b/SewingDresses/SewingDressesView/ShopsForm.resx @@ -117,19 +117,4 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True - - - True - - - True - - - True - - - True - \ No newline at end of file -- 2.25.1 From 67452aaa466432b39ec72a76651f4bc1a8c35f52 Mon Sep 17 00:00:00 2001 From: Sergey Kozyrev Date: Fri, 23 Feb 2024 20:19:36 +0400 Subject: [PATCH 04/14] orderUpdate --- SewingDresses/SewingDressesListImplement/Models/Order.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/SewingDresses/SewingDressesListImplement/Models/Order.cs b/SewingDresses/SewingDressesListImplement/Models/Order.cs index cbed685..9dc5697 100644 --- a/SewingDresses/SewingDressesListImplement/Models/Order.cs +++ b/SewingDresses/SewingDressesListImplement/Models/Order.cs @@ -39,9 +39,6 @@ namespace SewingDressesListImplement.Models { return; } - DressId = model.DressId == 0 ? DressId : model.DressId; - Count = model.Count == 0 ? Count : model.Count; - Sum = model.Sum == 0 ? Sum : model.Sum; Status = model.Status; DateImplement = model.DateImplement; } -- 2.25.1 From 626b501cda0d10460358cb8961087e088f45262c Mon Sep 17 00:00:00 2001 From: Sergey Kozyrev Date: Sat, 24 Feb 2024 08:05:42 +0400 Subject: [PATCH 05/14] FormUpdate --- SewingDresses/SewingDressesView/MainForm.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SewingDresses/SewingDressesView/MainForm.cs b/SewingDresses/SewingDressesView/MainForm.cs index 828e9a4..a4ee92c 100644 --- a/SewingDresses/SewingDressesView/MainForm.cs +++ b/SewingDresses/SewingDressesView/MainForm.cs @@ -45,8 +45,8 @@ namespace SewingDressesView private void DressesToolStripMenuItem_Click(object sender, EventArgs e) { - var service = Program.ServiceProvider?.GetService(typeof(DressForm)); - if (service is DressForm form) + var service = Program.ServiceProvider?.GetService(typeof(DressesForm)); + if (service is DressesForm form) { form.ShowDialog(); } -- 2.25.1 From bf1eaebd1c6c6c156094ff33c84ad661b4321b8a Mon Sep 17 00:00:00 2001 From: Sergey Kozyrev Date: Sat, 24 Feb 2024 08:10:44 +0400 Subject: [PATCH 06/14] 1 --- SewingDresses/SewingDressesView/SupplyForm.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SewingDresses/SewingDressesView/SupplyForm.cs b/SewingDresses/SewingDressesView/SupplyForm.cs index 1542093..ad71c4f 100644 --- a/SewingDresses/SewingDressesView/SupplyForm.cs +++ b/SewingDresses/SewingDressesView/SupplyForm.cs @@ -102,7 +102,7 @@ namespace SewingDressesView } if (DressComboBox.SelectedValue == null) { - MessageBox.Show("Выберите мороженное", "Ошибка", + MessageBox.Show("Выберите платье", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } -- 2.25.1 From c8d59d9fbca581548369b7913220b6b3d0c897b6 Mon Sep 17 00:00:00 2001 From: Sergey Kozyrev Date: Sat, 24 Feb 2024 08:42:24 +0400 Subject: [PATCH 07/14] dress --- SewingDresses/SewingDressesView/DressesForm.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/SewingDresses/SewingDressesView/DressesForm.cs b/SewingDresses/SewingDressesView/DressesForm.cs index 04fa669..117fc30 100644 --- a/SewingDresses/SewingDressesView/DressesForm.cs +++ b/SewingDresses/SewingDressesView/DressesForm.cs @@ -99,6 +99,7 @@ namespace SewingDressesView { dataGridView.DataSource = list; dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["DressComponents"].Visible = false; dataGridView.Columns["DressName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Load components"); -- 2.25.1 From e9f8e389ff5f2966ab8a083132352c323d0655f4 Mon Sep 17 00:00:00 2001 From: Sergey Kozyrev Date: Sat, 24 Feb 2024 10:02:06 +0400 Subject: [PATCH 08/14] make it better --- .../BusinessLogic/ShopLogic.cs | 28 ++++++++++++++-- .../StoragesContracts/IShopStorage.cs | 1 - .../Implements/ShopStorage.cs | 32 ------------------- 3 files changed, 26 insertions(+), 35 deletions(-) diff --git a/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ShopLogic.cs b/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ShopLogic.cs index e52b504..fb1a8c0 100644 --- a/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ShopLogic.cs +++ b/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ShopLogic.cs @@ -122,8 +122,32 @@ namespace SewingDressesBusinessLogic.BusinessLogic public bool MakeSupply(ShopSearchModel model, IDressModel dress, int count) { if (model == null) - return false; - return _shopStorage.SupplyDress(model, dress, count); + throw new ArgumentNullException(nameof(model)); + if (dress == null) + throw new ArgumentNullException(nameof(dress)); + if (count <= 0) + throw new ArgumentNullException("Количество должно быть положительным числом"); + + ShopViewModel? curModel = _shopStorage.GetElement(model); + _logger.LogInformation("Make Supply"); + if (curModel == null) + throw new ArgumentNullException(nameof(curModel)); + if (curModel.ShopDresses.TryGetValue(dress.Id, out var pair)) + { + curModel.ShopDresses[dress.Id] = (pair.Item1, pair.Item2 + count); + } + else + { + curModel.ShopDresses.Add(dress.Id, (dress, count)); + } + return Update(new() + { + Id = curModel.Id, + ShopName = curModel.ShopName, + DateOpen = curModel.DateOpen, + Adress = curModel.Adress, + ShopDresses = curModel.ShopDresses, + }); } } } diff --git a/SewingDresses/SewingDressesContracts/StoragesContracts/IShopStorage.cs b/SewingDresses/SewingDressesContracts/StoragesContracts/IShopStorage.cs index 5758bce..b47e78c 100644 --- a/SewingDresses/SewingDressesContracts/StoragesContracts/IShopStorage.cs +++ b/SewingDresses/SewingDressesContracts/StoragesContracts/IShopStorage.cs @@ -18,6 +18,5 @@ namespace SewingDressesContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); - bool SupplyDress(ShopSearchModel model, IDressModel dress, int count); } } diff --git a/SewingDresses/SewingDressesListImplement/Implements/ShopStorage.cs b/SewingDresses/SewingDressesListImplement/Implements/ShopStorage.cs index 9b58370..8ad8513 100644 --- a/SewingDresses/SewingDressesListImplement/Implements/ShopStorage.cs +++ b/SewingDresses/SewingDressesListImplement/Implements/ShopStorage.cs @@ -104,37 +104,5 @@ namespace SewingDressesListImplement.Implements } return null; } - - public bool SupplyDress(ShopSearchModel model, IDressModel dress, int count) - { - if (model == null) - throw new ArgumentNullException(nameof(model)); - if (dress == null) - throw new ArgumentNullException(nameof(dress)); - if (count <= 0) - throw new ArgumentNullException("Количество должно быть положительным числом"); - - ShopViewModel curModel = GetElement(model); - if (curModel == null) - throw new ArgumentNullException(nameof(curModel)); - if (curModel.ShopDresses.TryGetValue(dress.Id, out var pair)) - { - curModel.ShopDresses[dress.Id] = (pair.Item1, pair.Item2 + count); - } - else - { - curModel.ShopDresses.Add(dress.Id, (dress, count)); - } - Update(new() - { - Id = curModel.Id, - ShopName = curModel.ShopName, - DateOpen = curModel.DateOpen, - Adress = curModel.Adress, - ShopDresses = curModel.ShopDresses, - }); - return true; - - } } } -- 2.25.1 From 32bd22a63ebab06fca089f455b71eaeaf7a22666 Mon Sep 17 00:00:00 2001 From: Sergey Kozyrev Date: Sat, 24 Feb 2024 10:15:21 +0400 Subject: [PATCH 09/14] Naming Update plus log --- .../BusinessLogic/ShopLogic.cs | 5 +- .../ComponentsForm.Designer.cs | 2 +- .../SewingDressesView/DressesForm.Designer.cs | 2 +- .../SewingDressesView/OrderForm.Designer.cs | 2 +- SewingDresses/SewingDressesView/OrderForm.cs | 2 +- .../SewingDressesView/ShopForm.Designer.cs | 68 +++++++++---------- .../SewingDressesView/ShopsForm.Designer.cs | 2 +- .../SewingDressesView/SupplyForm.Designer.cs | 2 +- 8 files changed, 44 insertions(+), 41 deletions(-) diff --git a/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ShopLogic.cs b/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ShopLogic.cs index fb1a8c0..c2b15b0 100644 --- a/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ShopLogic.cs +++ b/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ShopLogic.cs @@ -129,17 +129,20 @@ namespace SewingDressesBusinessLogic.BusinessLogic throw new ArgumentNullException("Количество должно быть положительным числом"); ShopViewModel? curModel = _shopStorage.GetElement(model); - _logger.LogInformation("Make Supply"); + _logger.LogInformation("Make Supply. Id: {Id}. ShopName: {Name}",model.Id, model.Name); if (curModel == null) throw new ArgumentNullException(nameof(curModel)); if (curModel.ShopDresses.TryGetValue(dress.Id, out var pair)) { curModel.ShopDresses[dress.Id] = (pair.Item1, pair.Item2 + count); + _logger.LogInformation("Make Supply. Add Dress. DressName: {Name}. Count: {Count}", pair.Item1, count + pair.Item2); } else { curModel.ShopDresses.Add(dress.Id, (dress, count)); + _logger.LogInformation("Make Supply. Add new Dress. DressName: {Name}. Count: {Count}", pair.Item1, count); } + return Update(new() { Id = curModel.Id, diff --git a/SewingDresses/SewingDressesView/ComponentsForm.Designer.cs b/SewingDresses/SewingDressesView/ComponentsForm.Designer.cs index 3ab7ce4..0c06be1 100644 --- a/SewingDresses/SewingDressesView/ComponentsForm.Designer.cs +++ b/SewingDresses/SewingDressesView/ComponentsForm.Designer.cs @@ -97,7 +97,7 @@ Controls.Add(buttonAdd); Controls.Add(dataGridView); Name = "ComponentsForm"; - Text = "ComponentsForm"; + Text = "Форма компонентов"; Load += ComponentsForm_Load; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); diff --git a/SewingDresses/SewingDressesView/DressesForm.Designer.cs b/SewingDresses/SewingDressesView/DressesForm.Designer.cs index 95f03f6..ca9ec2c 100644 --- a/SewingDresses/SewingDressesView/DressesForm.Designer.cs +++ b/SewingDresses/SewingDressesView/DressesForm.Designer.cs @@ -97,7 +97,7 @@ Controls.Add(buttonAdd); Controls.Add(dataGridView); Name = "DressesForm"; - Text = "DressesForm"; + Text = "Форма с платьем"; Load += DressesForm_Load; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); diff --git a/SewingDresses/SewingDressesView/OrderForm.Designer.cs b/SewingDresses/SewingDressesView/OrderForm.Designer.cs index 9f4d082..441e123 100644 --- a/SewingDresses/SewingDressesView/OrderForm.Designer.cs +++ b/SewingDresses/SewingDressesView/OrderForm.Designer.cs @@ -123,7 +123,7 @@ Controls.Add(label2); Controls.Add(label1); Name = "OrderForm"; - Text = "OrderForm"; + Text = "Форма заказа"; Load += OrderForm_Load; ResumeLayout(false); PerformLayout(); diff --git a/SewingDresses/SewingDressesView/OrderForm.cs b/SewingDresses/SewingDressesView/OrderForm.cs index fa7ffab..5d8c620 100644 --- a/SewingDresses/SewingDressesView/OrderForm.cs +++ b/SewingDresses/SewingDressesView/OrderForm.cs @@ -99,7 +99,7 @@ namespace SewingDressesView try { var list = _logicD.ReadList(null); - if (list != null) + if (list != null) { comboBoxDress.DisplayMember = "DressName"; comboBoxDress.ValueMember = "Id"; diff --git a/SewingDresses/SewingDressesView/ShopForm.Designer.cs b/SewingDresses/SewingDressesView/ShopForm.Designer.cs index 4f5ad5e..8623746 100644 --- a/SewingDresses/SewingDressesView/ShopForm.Designer.cs +++ b/SewingDresses/SewingDressesView/ShopForm.Designer.cs @@ -32,15 +32,15 @@ textBoxName = new TextBox(); textBoxAdress = new TextBox(); dataGridView = new DataGridView(); + IdColumn = new DataGridViewTextBoxColumn(); + Title = new DataGridViewTextBoxColumn(); + Cost = new DataGridViewTextBoxColumn(); + Count = new DataGridViewTextBoxColumn(); buttonSave = new Button(); buttonCancel = new Button(); label1 = new Label(); label2 = new Label(); label3 = new Label(); - IdColumn = new DataGridViewTextBoxColumn(); - Title = new DataGridViewTextBoxColumn(); - Cost = new DataGridViewTextBoxColumn(); - Count = new DataGridViewTextBoxColumn(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // @@ -76,6 +76,35 @@ dataGridView.Size = new Size(554, 380); dataGridView.TabIndex = 3; // + // IdColumn + // + IdColumn.HeaderText = "Номер платья"; + IdColumn.MinimumWidth = 6; + IdColumn.Name = "IdColumn"; + IdColumn.Visible = false; + IdColumn.Width = 125; + // + // Title + // + Title.HeaderText = "Название"; + Title.MinimumWidth = 6; + Title.Name = "Title"; + Title.Width = 125; + // + // Cost + // + Cost.HeaderText = "Цена"; + Cost.MinimumWidth = 6; + Cost.Name = "Cost"; + Cost.Width = 125; + // + // Count + // + Count.HeaderText = "Количество"; + Count.MinimumWidth = 6; + Count.Name = "Count"; + Count.Width = 125; + // // buttonSave // buttonSave.Location = new Point(714, 219); @@ -123,35 +152,6 @@ label3.TabIndex = 8; label3.Text = "Адрес"; // - // IdColumn - // - IdColumn.HeaderText = "Номер платья"; - IdColumn.MinimumWidth = 6; - IdColumn.Name = "IdColumn"; - IdColumn.Visible = false; - IdColumn.Width = 125; - // - // Title - // - Title.HeaderText = "Название"; - Title.MinimumWidth = 6; - Title.Name = "Title"; - Title.Width = 125; - // - // Cost - // - Cost.HeaderText = "Цена"; - Cost.MinimumWidth = 6; - Cost.Name = "Cost"; - Cost.Width = 125; - // - // Count - // - Count.HeaderText = "Количество"; - Count.MinimumWidth = 6; - Count.Name = "Count"; - Count.Width = 125; - // // ShopForm // AutoScaleDimensions = new SizeF(8F, 20F); @@ -167,7 +167,7 @@ Controls.Add(textBoxName); Controls.Add(dateTimePicker); Name = "ShopForm"; - Text = "ShopForm"; + Text = "Форма магазина"; Load += ShopForm_Load; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); diff --git a/SewingDresses/SewingDressesView/ShopsForm.Designer.cs b/SewingDresses/SewingDressesView/ShopsForm.Designer.cs index 12204ef..389ce34 100644 --- a/SewingDresses/SewingDressesView/ShopsForm.Designer.cs +++ b/SewingDresses/SewingDressesView/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/SewingDresses/SewingDressesView/SupplyForm.Designer.cs b/SewingDresses/SewingDressesView/SupplyForm.Designer.cs index f74e507..0befc04 100644 --- a/SewingDresses/SewingDressesView/SupplyForm.Designer.cs +++ b/SewingDresses/SewingDressesView/SupplyForm.Designer.cs @@ -122,7 +122,7 @@ Controls.Add(DressComboBox); Controls.Add(ShopComboBox); Name = "SupplyForm"; - Text = "SupplyForm"; + Text = "Форма поставки"; ResumeLayout(false); PerformLayout(); } -- 2.25.1 From 527a8e2931f9e97d054cf764b82887b230f29f20 Mon Sep 17 00:00:00 2001 From: Sergey Kozyrev Date: Tue, 5 Mar 2024 14:02:54 +0400 Subject: [PATCH 10/14] save base --- .../SewingDressesListImplement/Implements/OrderStorage.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SewingDresses/SewingDressesListImplement/Implements/OrderStorage.cs b/SewingDresses/SewingDressesListImplement/Implements/OrderStorage.cs index ac8d62f..acb06fe 100644 --- a/SewingDresses/SewingDressesListImplement/Implements/OrderStorage.cs +++ b/SewingDresses/SewingDressesListImplement/Implements/OrderStorage.cs @@ -96,9 +96,9 @@ namespace SewingDressesListImplement.Implements } public OrderViewModel AcessDressesStorage(OrderViewModel model) { - foreach(var dress in _source.Dresses) + foreach (var dress in _source.Dresses) { - if (dress.Id == model.DressId) + if (dress.Id == model.DressId) { model.DressName = dress.DressName; break; -- 2.25.1 From 880272b84d99b6a146ef4019115df9c0acf3fe4d Mon Sep 17 00:00:00 2001 From: Sergey Kozyrev Date: Tue, 5 Mar 2024 14:34:27 +0400 Subject: [PATCH 11/14] RemoveConflict --- SewingDresses/SewingDressesView/MainForm.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/SewingDresses/SewingDressesView/MainForm.cs b/SewingDresses/SewingDressesView/MainForm.cs index a5d837f..a4ee92c 100644 --- a/SewingDresses/SewingDressesView/MainForm.cs +++ b/SewingDresses/SewingDressesView/MainForm.cs @@ -24,6 +24,7 @@ namespace SewingDressesView { dataGridView.DataSource = list; dataGridView.Columns["DressId"].Visible = false; + dataGridView.Columns["DressName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Load orders"); } @@ -142,9 +143,22 @@ namespace SewingDressesView LoadData(); } - private void MainForm_Load(object sender, EventArgs e) + private void ShopsToolStripMenuItem_Click(object sender, EventArgs e) { - LoadData(); + var service = Program.ServiceProvider?.GetService(typeof(ShopsForm)); + if (service is ShopsForm form) + { + form.ShowDialog(); + } + } + + private void SupplyToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(SupplyForm)); + if (service is SupplyForm form) + { + form.ShowDialog(); + } } } } -- 2.25.1 From a0f9235e3dd79800c8536f2e70e873b424967568 Mon Sep 17 00:00:00 2001 From: Sergey Kozyrev Date: Tue, 5 Mar 2024 21:02:14 +0400 Subject: [PATCH 12/14] SomeDoing --- .../BusinessLogic/OrderLogic.cs | 71 +++++++++- .../BusinessLogic/ShopLogic.cs | 17 ++- .../BindingModels/ShopBindingModel.cs | 1 + .../BusinessLogicsContracts/IShopLogic.cs | 1 + .../StoragesContracts/IShopStorage.cs | 1 + .../ViewModels/ShopViewModel.cs | 2 + .../Models/IShopModel.cs | 1 + .../DataFileSingleton.cs | 4 + .../Implements/ShopStorage.cs | 121 ++++++++++++++++++ .../SewingDressesFileImplement/Models/Shop.cs | 101 +++++++++++++++ .../Implements/ShopStorage.cs | 43 +++++++ .../SewingDressesListImplement/Models/Shop.cs | 4 + SewingDresses/SewingDressesView/MainForm.cs | 6 + .../SewingDressesView/ShopForm.Designer.cs | 28 +++- SewingDresses/SewingDressesView/ShopForm.cs | 5 +- 15 files changed, 398 insertions(+), 8 deletions(-) create mode 100644 SewingDresses/SewingDressesFileImplement/Implements/ShopStorage.cs create mode 100644 SewingDresses/SewingDressesFileImplement/Models/Shop.cs diff --git a/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/OrderLogic.cs b/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/OrderLogic.cs index a99f4f3..d8a2e54 100644 --- a/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/OrderLogic.cs @@ -5,6 +5,8 @@ using SewingDressesContracts.SearchModels; using SewingDressesContracts.StoragesContracts; using SewingDressesContracts.ViewModels; using SewingDressesDataModels.Enums; +using SewingDressesDataModels.Models; +using System.Collections.Specialized; namespace SewingDressesBusinessLogic.BusinessLogic { @@ -12,11 +14,16 @@ namespace SewingDressesBusinessLogic.BusinessLogic { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; - - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + private readonly IShopStorage _shopStorage; + private readonly IShopLogic _shopLogic; + private readonly IDressStorage _dressStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopStorage shopStorage, IShopLogic shopLogic, IDressStorage dressStorage) { _logger = logger; _orderStorage = orderStorage; + _shopStorage = shopStorage; + _shopLogic = shopLogic; + _dressStorage = dressStorage; } public List? ReadList(OrderSearchModel? model) @@ -99,5 +106,65 @@ namespace SewingDressesBusinessLogic.BusinessLogic { return ChangeStatus(model, OrderStatus.Выдан); } + + public bool CheckSupply(IDressModel dress, int count) + { + if (count <= 0) + { + _logger.LogWarning("Check supply operation error. Dress count < 0"); + return false; + } + int sumCapacity = _shopStorage.GetFullList().Select(x => x.MaxCount).Sum(); + int sumCount = _shopStorage.GetFullList().Select(x => x.ShopDresses.Select(y => y.Value.Item2).Sum()).Sum(); + int free = sumCapacity - sumCount; + + if (free < count) + { + _logger.LogWarning("Check supply error. No place for new Dresses"); + return false; + } + foreach (var shop in _shopStorage.GetFullList()) + { + free = shop.MaxCount; + foreach (var doc in shop.ShopDresses) + { + free -= doc.Value.Item2; + } + if (free == 0) + { + continue; + } + if (free >= count) + { + if (_shopLogic.MakeSupply(new() + { + Id = shop.Id + }, dress, count)) + { + count = 0; + } + else + { + _logger.LogWarning("Supply error"); + return false; + } + } + else + { + if (_shopLogic.MakeSupply(new() { Id = shop.Id}, dress, free)) + count -= free; + else + { + _logger.LogWarning("Supply error"); + return false; + } + } + if (count <= 0) + { + return true; + } + } + return false; + } } } diff --git a/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ShopLogic.cs b/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ShopLogic.cs index c2b15b0..0bae47f 100644 --- a/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ShopLogic.cs +++ b/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ShopLogic.cs @@ -119,6 +119,11 @@ namespace SewingDressesBusinessLogic.BusinessLogic throw new InvalidOperationException("Магазин с таким названием уже есть"); } } + + public bool MakeSell(IDressModel model, int count) + { + return _shopStorage.SellDresses(model, count); + } public bool MakeSupply(ShopSearchModel model, IDressModel dress, int count) { if (model == null) @@ -132,15 +137,23 @@ namespace SewingDressesBusinessLogic.BusinessLogic _logger.LogInformation("Make Supply. Id: {Id}. ShopName: {Name}",model.Id, model.Name); if (curModel == null) throw new ArgumentNullException(nameof(curModel)); + + var countItems = curModel.ShopDresses.Select(x => x.Value.Item2).Sum(); + if (curModel.MaxCount - countItems < count) + { + _logger.LogWarning("Shop is overflowed"); + return false; + } + if (curModel.ShopDresses.TryGetValue(dress.Id, out var pair)) { curModel.ShopDresses[dress.Id] = (pair.Item1, pair.Item2 + count); - _logger.LogInformation("Make Supply. Add Dress. DressName: {Name}. Count: {Count}", pair.Item1, count + pair.Item2); + _logger.LogInformation("Make Supply. Add Dress. ShopName: {ShopName}. DressName: {Name}. Count: {Count}", curModel.ShopName, pair.Item1, count + pair.Item2); } else { curModel.ShopDresses.Add(dress.Id, (dress, count)); - _logger.LogInformation("Make Supply. Add new Dress. DressName: {Name}. Count: {Count}", pair.Item1, count); + _logger.LogInformation("Make Supply. Add new Dress. ShopName: {ShopName}. DressName: {Name}. Count: {Count}", curModel.ShopName, pair.Item1, count); } return Update(new() diff --git a/SewingDresses/SewingDressesContracts/BindingModels/ShopBindingModel.cs b/SewingDresses/SewingDressesContracts/BindingModels/ShopBindingModel.cs index 6ae5676..e3b5ec6 100644 --- a/SewingDresses/SewingDressesContracts/BindingModels/ShopBindingModel.cs +++ b/SewingDresses/SewingDressesContracts/BindingModels/ShopBindingModel.cs @@ -13,6 +13,7 @@ namespace SewingDressesContracts.BindingModels public string ShopName { get; set; } public string Adress { get; set; } public DateTime DateOpen { get; set; } + public int MaxCount { get; set; } public Dictionary ShopDresses { get; set; } = new(); } } diff --git a/SewingDresses/SewingDressesContracts/BusinessLogicsContracts/IShopLogic.cs b/SewingDresses/SewingDressesContracts/BusinessLogicsContracts/IShopLogic.cs index 56f29cc..d716469 100644 --- a/SewingDresses/SewingDressesContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/SewingDresses/SewingDressesContracts/BusinessLogicsContracts/IShopLogic.cs @@ -18,5 +18,6 @@ namespace SewingDressesContracts.BusinessLogicsContracts bool Update (ShopBindingModel? model); bool Delete (ShopBindingModel? model); bool MakeSupply(ShopSearchModel model, IDressModel dress, int count); + bool MakeSell(IDressModel model, int count); } } diff --git a/SewingDresses/SewingDressesContracts/StoragesContracts/IShopStorage.cs b/SewingDresses/SewingDressesContracts/StoragesContracts/IShopStorage.cs index b47e78c..3e7992e 100644 --- a/SewingDresses/SewingDressesContracts/StoragesContracts/IShopStorage.cs +++ b/SewingDresses/SewingDressesContracts/StoragesContracts/IShopStorage.cs @@ -18,5 +18,6 @@ namespace SewingDressesContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); + bool SellDresses(IDressModel model, int count); } } diff --git a/SewingDresses/SewingDressesContracts/ViewModels/ShopViewModel.cs b/SewingDresses/SewingDressesContracts/ViewModels/ShopViewModel.cs index 9d7d47f..cb17fbd 100644 --- a/SewingDresses/SewingDressesContracts/ViewModels/ShopViewModel.cs +++ b/SewingDresses/SewingDressesContracts/ViewModels/ShopViewModel.cs @@ -17,6 +17,8 @@ namespace SewingDressesContracts.ViewModels public string Adress { get; set; } = string.Empty; [DisplayName("Дата открытия")] public DateTime DateOpen { get; set; } + [DisplayName("Вмещаемость")] + public int MaxCount { get; set; } public Dictionary ShopDresses { get; set; } = new(); } } diff --git a/SewingDresses/SewingDressesDataModels/Models/IShopModel.cs b/SewingDresses/SewingDressesDataModels/Models/IShopModel.cs index a423ef5..d39b30a 100644 --- a/SewingDresses/SewingDressesDataModels/Models/IShopModel.cs +++ b/SewingDresses/SewingDressesDataModels/Models/IShopModel.cs @@ -11,5 +11,6 @@ namespace SewingDressesDataModels.Models string ShopName { get; } string Adress { get; } DateTime DateOpen { get; } + int MaxCount { get; } } } diff --git a/SewingDresses/SewingDressesFileImplement/DataFileSingleton.cs b/SewingDresses/SewingDressesFileImplement/DataFileSingleton.cs index 27d6d67..e192233 100644 --- a/SewingDresses/SewingDressesFileImplement/DataFileSingleton.cs +++ b/SewingDresses/SewingDressesFileImplement/DataFileSingleton.cs @@ -9,9 +9,11 @@ namespace SewingDressesFileImplement private readonly string ComponentFileName = "Component.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string DressFileName = "Dress.xml"; + private readonly string ShopFileName = "Shop.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Dresses { get; private set;} + public List Shops { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -39,11 +41,13 @@ namespace SewingDressesFileImplement public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); public void SaveDresses() => SaveData(Dresses, DressFileName, "Dresses", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Dresses = LoadData(DressFileName, "Dress", x => Dress.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; } } } diff --git a/SewingDresses/SewingDressesFileImplement/Implements/ShopStorage.cs b/SewingDresses/SewingDressesFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..2da86f4 --- /dev/null +++ b/SewingDresses/SewingDressesFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,121 @@ +using SewingDressesContracts.BindingModels; +using SewingDressesContracts.SearchModels; +using SewingDressesContracts.StoragesContracts; +using SewingDressesContracts.ViewModels; +using SewingDressesDataModels.Models; +using SewingDressesFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingDressesFileImplement.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 dressId, int count) + { + int store = _source.Shops.Select(x => x.ShopDresses.Select(y => (y.Value.Item1.Id == dressId ? y.Value.Item2 : 0)).Sum()).Sum(); + return store >= count; + } + public bool SellDresses(IDressModel model, int count) + { + var dres = _source.Dresses.FirstOrDefault(x => x.Id == model.Id); + + if (dres == null || CheckAvailability(model.Id, count)) + { + return false; + } + + for (int i = 0; i < _source.Shops.Count; i++) + { + var shop = _source.Shops[i]; + var dresses = shop.ShopDresses; + foreach (var dress in dresses.Where(x => x.Value.Item1.Id == dres.Id)) + { + var selling = Math.Min(dress.Value.Item2, count); + dresses[dress.Value.Item1.Id] = (dress.Value.Item1, dress.Value.Item2 - selling); + + count -= selling; + + if (count <= 0) + { + break; + } + } + shop.Update(new ShopBindingModel + { + Id = model.Id, + ShopName = shop.ShopName, + Adress = shop.Adress, + MaxCount = shop.MaxCount, + DateOpen = shop.DateOpen, + ShopDresses = dresses + }); + } + _source.SaveShops(); + return true; + } + } +} diff --git a/SewingDresses/SewingDressesFileImplement/Models/Shop.cs b/SewingDresses/SewingDressesFileImplement/Models/Shop.cs new file mode 100644 index 0000000..f520ed1 --- /dev/null +++ b/SewingDresses/SewingDressesFileImplement/Models/Shop.cs @@ -0,0 +1,101 @@ +using SewingDressesContracts.BindingModels; +using SewingDressesContracts.ViewModels; +using SewingDressesDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace SewingDressesFileImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } + public string Adress { get; private set; } + public DateTime DateOpen { get; private set; } + public int MaxCount { get; private set; } + public Dictionary Dresses { get; private set; } = new(); + private Dictionary? _shopDresses = null; + public Dictionary ShopDresses + { + get + { + if (_shopDresses == null) + { + var source = DataFileSingleton.GetInstance(); + _shopDresses = Dresses.ToDictionary(x => x.Key, y => ((source.Dresses.FirstOrDefault(z => z.Id == y.Key) as IDressModel)!, y.Value)); + } + return _shopDresses; + } + } + public static Shop? Create(ShopBindingModel model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Adress = model.Adress, + DateOpen = model.DateOpen, + MaxCount = model.MaxCount, + Dresses = model.ShopDresses.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, + Adress = element.Element("Adress")!.Value, + MaxCount = Convert.ToInt32(element.Element("MaxCount")!.Value), + DateOpen = Convert.ToDateTime(element.Element("DateOpen")!.Value), + Dresses = element.Element("ShopDresses")!.Elements("ShopDress").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; + Adress = model.Adress; + DateOpen = model.DateOpen; + MaxCount = model.MaxCount; + if (model.ShopDresses.Count > 0) + { + Dresses = model.ShopDresses.ToDictionary(x => x.Key, x => x.Value.Item2); + _shopDresses = null; + } + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Adress = Adress, + DateOpen = DateOpen, + MaxCount = MaxCount, + ShopDresses = ShopDresses + }; + + public XElement GetXElement => new XElement("Shop", + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("Adress", Adress), + new XElement("DateOpen", DateOpen), + new XElement("MaxCount", MaxCount), + new XElement("ShopDresses", Dresses.Select(x => new XElement("ShopDress", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray())); + } +} diff --git a/SewingDresses/SewingDressesListImplement/Implements/ShopStorage.cs b/SewingDresses/SewingDressesListImplement/Implements/ShopStorage.cs index 8ad8513..1be6bfe 100644 --- a/SewingDresses/SewingDressesListImplement/Implements/ShopStorage.cs +++ b/SewingDresses/SewingDressesListImplement/Implements/ShopStorage.cs @@ -104,5 +104,48 @@ namespace SewingDressesListImplement.Implements } return null; } + + public bool CheckAvailability(int dressId, int count) + { + int store = _source.Shops.Select(x => x.ShopDresses.Select(y => (y.Value.Item1.Id == dressId ? y.Value.Item2 : 0)).Sum()).Sum(); + return store >= count; + } + public bool SellDresses(IDressModel model, int count) + { + var dres = _source.Dresses.FirstOrDefault(x => x.Id == model.Id); + + if (dres == null || CheckAvailability(model.Id, count)) + { + return false; + } + + for (int i = 0; i < _source.Shops.Count; i++) + { + var shop = _source.Shops[i]; + var dresses = shop.ShopDresses; + foreach( var dress in dresses.Where(x => x.Value.Item1.Id == dres.Id)) + { + var selling = Math.Min(dress.Value.Item2, count); + dresses[dress.Value.Item1.Id] = (dress.Value.Item1, dress.Value.Item2 - selling); + + count -= selling; + + if (count <= 0) + { + break; + } + } + shop.Update(new ShopBindingModel + { + Id = model.Id, + ShopName = shop.ShopName, + Adress = shop.Adress, + MaxCount = shop.MaxCount, + DateOpen = shop.DateOpen, + ShopDresses = dresses + }); + } + return true; + } } } diff --git a/SewingDresses/SewingDressesListImplement/Models/Shop.cs b/SewingDresses/SewingDressesListImplement/Models/Shop.cs index 3845ddf..02672cc 100644 --- a/SewingDresses/SewingDressesListImplement/Models/Shop.cs +++ b/SewingDresses/SewingDressesListImplement/Models/Shop.cs @@ -15,6 +15,7 @@ namespace SewingDressesListImplement.Models public string ShopName { get; private set; } public string Adress { get; private set; } public DateTime DateOpen { get; private set; } + public int MaxCount { get; private set; } public Dictionary ShopDresses { get; private set; } = new(); public static Shop? Create (ShopBindingModel model) { @@ -28,6 +29,7 @@ namespace SewingDressesListImplement.Models ShopName = model.ShopName, Adress = model.Adress, DateOpen = model.DateOpen, + MaxCount = model.MaxCount, ShopDresses = new() }; } @@ -40,6 +42,7 @@ namespace SewingDressesListImplement.Models ShopName = model.ShopName; Adress = model.Adress; DateOpen = model.DateOpen; + MaxCount = model.MaxCount; ShopDresses = model.ShopDresses; } public ShopViewModel GetViewModel => new() @@ -48,6 +51,7 @@ namespace SewingDressesListImplement.Models ShopName = ShopName, Adress = Adress, DateOpen = DateOpen, + MaxCount = MaxCount, ShopDresses = ShopDresses }; } diff --git a/SewingDresses/SewingDressesView/MainForm.cs b/SewingDresses/SewingDressesView/MainForm.cs index a4ee92c..70644d5 100644 --- a/SewingDresses/SewingDressesView/MainForm.cs +++ b/SewingDresses/SewingDressesView/MainForm.cs @@ -160,5 +160,11 @@ namespace SewingDressesView form.ShowDialog(); } } + + private void MainForm_Load(object sender, EventArgs e) + { + LoadData(); + } + } } diff --git a/SewingDresses/SewingDressesView/ShopForm.Designer.cs b/SewingDresses/SewingDressesView/ShopForm.Designer.cs index 8623746..d9f618b 100644 --- a/SewingDresses/SewingDressesView/ShopForm.Designer.cs +++ b/SewingDresses/SewingDressesView/ShopForm.Designer.cs @@ -41,7 +41,10 @@ label1 = new Label(); label2 = new Label(); label3 = new Label(); + numeric = new NumericUpDown(); + label4 = new Label(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numeric).BeginInit(); SuspendLayout(); // // dateTimePicker @@ -107,7 +110,7 @@ // // buttonSave // - buttonSave.Location = new Point(714, 219); + buttonSave.Location = new Point(714, 248); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(94, 29); buttonSave.TabIndex = 4; @@ -117,7 +120,7 @@ // // buttonCancel // - buttonCancel.Location = new Point(870, 219); + buttonCancel.Location = new Point(870, 248); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(94, 29); buttonCancel.TabIndex = 5; @@ -152,11 +155,29 @@ label3.TabIndex = 8; label3.Text = "Адрес"; // + // numeric + // + numeric.Location = new Point(714, 196); + numeric.Name = "numeric"; + numeric.Size = new Size(150, 27); + numeric.TabIndex = 9; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(592, 198); + label4.Name = "label4"; + label4.Size = new Size(100, 20); + label4.TabIndex = 10; + label4.Text = "Вместимость"; + // // ShopForm // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(976, 450); + Controls.Add(label4); + Controls.Add(numeric); Controls.Add(label3); Controls.Add(label2); Controls.Add(label1); @@ -170,6 +191,7 @@ Text = "Форма магазина"; Load += ShopForm_Load; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ((System.ComponentModel.ISupportInitialize)numeric).EndInit(); ResumeLayout(false); PerformLayout(); } @@ -189,5 +211,7 @@ private DataGridViewTextBoxColumn Title; private DataGridViewTextBoxColumn Cost; private DataGridViewTextBoxColumn Count; + private NumericUpDown numeric; + private Label label4; } } \ No newline at end of file diff --git a/SewingDresses/SewingDressesView/ShopForm.cs b/SewingDresses/SewingDressesView/ShopForm.cs index 3d3224a..4917cda 100644 --- a/SewingDresses/SewingDressesView/ShopForm.cs +++ b/SewingDresses/SewingDressesView/ShopForm.cs @@ -41,7 +41,8 @@ namespace SewingDressesView textBoxName.Text = shop.ShopName; textBoxAdress.Text = shop.Adress; dateTimePicker.Text = shop.DateOpen.ToString(); - _dresses = shop.ShopDresses; + numeric.Value = shop.MaxCount; + _dresses = shop.ShopDresses ?? new Dictionary(); } LoadData(); } @@ -95,7 +96,7 @@ namespace SewingDressesView ShopName = textBoxName.Text, Adress = textBoxAdress.Text, DateOpen = dateTimePicker.Value.Date, - ShopDresses = _dresses + MaxCount = Convert.ToInt32(numeric.Value) }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) -- 2.25.1 From f134d1fb63f679e329dfd2f8635bc6b8715626b9 Mon Sep 17 00:00:00 2001 From: Sergey Kozyrev Date: Wed, 6 Mar 2024 17:03:40 +0400 Subject: [PATCH 13/14] Finish hard --- .../BusinessLogic/OrderLogic.cs | 14 ++ .../SewingDressesView/MainForm.Designer.cs | 11 +- SewingDresses/SewingDressesView/MainForm.cs | 11 +- SewingDresses/SewingDressesView/Program.cs | 1 + .../SewingDressesView/SellForm.Designer.cs | 118 +++++++++++++++++ SewingDresses/SewingDressesView/SellForm.cs | 120 ++++++++++++++++++ SewingDresses/SewingDressesView/SellForm.resx | 120 ++++++++++++++++++ 7 files changed, 393 insertions(+), 2 deletions(-) create mode 100644 SewingDresses/SewingDressesView/SellForm.Designer.cs create mode 100644 SewingDresses/SewingDressesView/SellForm.cs create mode 100644 SewingDresses/SewingDressesView/SellForm.resx diff --git a/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/OrderLogic.cs b/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/OrderLogic.cs index d8a2e54..3d615db 100644 --- a/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/OrderLogic.cs @@ -86,6 +86,20 @@ namespace SewingDressesBusinessLogic.BusinessLogic _logger.LogWarning("Status change failed"); throw new InvalidOperationException("Невозможно перевести состояние заказа"); } + if (status == OrderStatus.Готов) + { + var dress = _dressStorage.GetElement(new DressSearchModel() { Id = model.DressId }); + if (dress == null) + { + _logger.LogWarning("Status change error. Dress not found"); + return false; + } + if (!CheckSupply(dress, model.Count)) + { + _logger.LogWarning("Status change error. Shop doesnt have dresses"); + return false; + } + } model.Status = status; if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; _orderStorage.Update(model); diff --git a/SewingDresses/SewingDressesView/MainForm.Designer.cs b/SewingDresses/SewingDressesView/MainForm.Designer.cs index 584ca56..d6f7a68 100644 --- a/SewingDresses/SewingDressesView/MainForm.Designer.cs +++ b/SewingDresses/SewingDressesView/MainForm.Designer.cs @@ -40,6 +40,7 @@ платьяToolStripMenuItem = new ToolStripMenuItem(); магазиныToolStripMenuItem = new ToolStripMenuItem(); поставкиToolStripMenuItem = new ToolStripMenuItem(); + продажаToolStripMenuItem = new ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); menuStrip1.SuspendLayout(); SuspendLayout(); @@ -116,7 +117,7 @@ // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, платьяToolStripMenuItem, магазиныToolStripMenuItem, поставкиToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, платьяToolStripMenuItem, магазиныToolStripMenuItem, поставкиToolStripMenuItem, продажаToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(117, 24); справочникиToolStripMenuItem.Text = "Справочники"; @@ -149,6 +150,13 @@ поставкиToolStripMenuItem.Text = "Поставки"; поставкиToolStripMenuItem.Click += SupplyToolStripMenuItem_Click; // + // продажаToolStripMenuItem + // + продажаToolStripMenuItem.Name = "продажаToolStripMenuItem"; + продажаToolStripMenuItem.Size = new Size(224, 26); + продажаToolStripMenuItem.Text = "Продажа"; + продажаToolStripMenuItem.Click += SellToolStripMenuItem_Click; + // // MainForm // AutoScaleDimensions = new SizeF(8F, 20F); @@ -186,5 +194,6 @@ private ToolStripMenuItem платьяToolStripMenuItem; private ToolStripMenuItem магазиныToolStripMenuItem; private ToolStripMenuItem поставкиToolStripMenuItem; + private ToolStripMenuItem продажаToolStripMenuItem; } } \ No newline at end of file diff --git a/SewingDresses/SewingDressesView/MainForm.cs b/SewingDresses/SewingDressesView/MainForm.cs index 70644d5..0f2d012 100644 --- a/SewingDresses/SewingDressesView/MainForm.cs +++ b/SewingDresses/SewingDressesView/MainForm.cs @@ -24,7 +24,7 @@ namespace SewingDressesView { dataGridView.DataSource = list; dataGridView.Columns["DressId"].Visible = false; - dataGridView.Columns["DressName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["DressName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; } _logger.LogInformation("Load orders"); } @@ -166,5 +166,14 @@ namespace SewingDressesView LoadData(); } + private void SellToolStripMenuItem_Click(Object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(SellForm)); + if (service is SellForm form) + { + form.ShowDialog(); + } + } + } } diff --git a/SewingDresses/SewingDressesView/Program.cs b/SewingDresses/SewingDressesView/Program.cs index 756ce9b..74ba1b8 100644 --- a/SewingDresses/SewingDressesView/Program.cs +++ b/SewingDresses/SewingDressesView/Program.cs @@ -47,6 +47,7 @@ namespace SewingDressesView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/SewingDresses/SewingDressesView/SellForm.Designer.cs b/SewingDresses/SewingDressesView/SellForm.Designer.cs new file mode 100644 index 0000000..0d02a77 --- /dev/null +++ b/SewingDresses/SewingDressesView/SellForm.Designer.cs @@ -0,0 +1,118 @@ +namespace SewingDressesView +{ + 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() + { + comboBoxDress = new ComboBox(); + textBoxCount = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + label1 = new Label(); + label2 = new Label(); + SuspendLayout(); + // + // comboBoxDress + // + comboBoxDress.FormattingEnabled = true; + comboBoxDress.Location = new Point(126, 30); + comboBoxDress.Name = "comboBoxDress"; + comboBoxDress.Size = new Size(151, 28); + comboBoxDress.TabIndex = 0; + // + // textBoxCount + // + textBoxCount.Location = new Point(126, 95); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(151, 27); + textBoxCount.TabIndex = 1; + // + // buttonSave + // + buttonSave.Location = new Point(45, 172); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 2; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(183, 172); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 3; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(27, 33); + label1.Name = "label1"; + label1.Size = new Size(58, 20); + label1.TabIndex = 4; + label1.Text = "Платье"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(27, 98); + label2.Name = "label2"; + label2.Size = new Size(90, 20); + label2.TabIndex = 5; + label2.Text = "Количество"; + // + // SellForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(306, 234); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(comboBoxDress); + Name = "SellForm"; + Text = "Продажа"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxDress; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + private Label label1; + private Label label2; + } +} \ No newline at end of file diff --git a/SewingDresses/SewingDressesView/SellForm.cs b/SewingDresses/SewingDressesView/SellForm.cs new file mode 100644 index 0000000..33fdfea --- /dev/null +++ b/SewingDresses/SewingDressesView/SellForm.cs @@ -0,0 +1,120 @@ +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 SewingDressesContracts.BusinessLogicsContracts; +using SewingDressesContracts.ViewModels; +using SewingDressesDataModels.Models; + +namespace SewingDressesView +{ + public partial class SellForm : Form + { + private readonly List? _dressList; + IShopLogic _shopLogic; + IDressLogic _dressLogic; + public SellForm(IDressLogic dressLogic, IShopLogic shopLogic) + { + InitializeComponent(); + _shopLogic = shopLogic; + _dressLogic = dressLogic; + _dressList = dressLogic.ReadList(null); + if (_dressList != null) + { + comboBoxDress.DisplayMember = "DressName"; + comboBoxDress.ValueMember = "Id"; + comboBoxDress.DataSource = _dressList; + comboBoxDress.SelectedItem = null; + } + } + public int DressId + { + get + { + return Convert.ToInt32(comboBoxDress.SelectedValue); + } + set + { + comboBoxDress.SelectedValue = value; + } + } + + public IDressModel? IceCreamModel + { + get + { + if (_dressList == null) + { + return null; + } + foreach (var elem in _dressList) + { + if (elem.Id == DressId) + { + 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 (comboBoxDress.SelectedValue == null) + { + MessageBox.Show("Выберите мороженное", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + try + { + int count = Convert.ToInt32(textBoxCount.Text); + + bool res = _shopLogic.MakeSell( + _dressLogic.ReadElement(new() { Id = Convert.ToInt32(comboBoxDress.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) + { + Close(); + } + } +} diff --git a/SewingDresses/SewingDressesView/SellForm.resx b/SewingDresses/SewingDressesView/SellForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SewingDresses/SewingDressesView/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 -- 2.25.1 From ac8618e3e5ffe1a1f168d30f66b9be3da0a8bb59 Mon Sep 17 00:00:00 2001 From: Sergey Kozyrev Date: Sat, 9 Mar 2024 09:52:08 +0400 Subject: [PATCH 14/14] BaseUpdate --- .../BusinessLogic/ShopLogic.cs | 1 + .../Implements/ShopStorage.cs | 2 +- .../Implements/ShopStorage.cs | 36 +------------------ SewingDresses/SewingDressesView/MainForm.cs | 12 +++---- 4 files changed, 8 insertions(+), 43 deletions(-) diff --git a/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ShopLogic.cs b/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ShopLogic.cs index 0bae47f..cc6b010 100644 --- a/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ShopLogic.cs +++ b/SewingDresses/SewingDressesBusinessLogic/BusinessLogic/ShopLogic.cs @@ -161,6 +161,7 @@ namespace SewingDressesBusinessLogic.BusinessLogic Id = curModel.Id, ShopName = curModel.ShopName, DateOpen = curModel.DateOpen, + MaxCount = curModel.MaxCount, Adress = curModel.Adress, ShopDresses = curModel.ShopDresses, }); diff --git a/SewingDresses/SewingDressesFileImplement/Implements/ShopStorage.cs b/SewingDresses/SewingDressesFileImplement/Implements/ShopStorage.cs index 2da86f4..19ef35a 100644 --- a/SewingDresses/SewingDressesFileImplement/Implements/ShopStorage.cs +++ b/SewingDresses/SewingDressesFileImplement/Implements/ShopStorage.cs @@ -83,7 +83,7 @@ namespace SewingDressesFileImplement.Implements { var dres = _source.Dresses.FirstOrDefault(x => x.Id == model.Id); - if (dres == null || CheckAvailability(model.Id, count)) + if (dres == null || !CheckAvailability(model.Id, count)) { return false; } diff --git a/SewingDresses/SewingDressesListImplement/Implements/ShopStorage.cs b/SewingDresses/SewingDressesListImplement/Implements/ShopStorage.cs index 1be6bfe..3e7fbe9 100644 --- a/SewingDresses/SewingDressesListImplement/Implements/ShopStorage.cs +++ b/SewingDresses/SewingDressesListImplement/Implements/ShopStorage.cs @@ -107,44 +107,10 @@ namespace SewingDressesListImplement.Implements public bool CheckAvailability(int dressId, int count) { - int store = _source.Shops.Select(x => x.ShopDresses.Select(y => (y.Value.Item1.Id == dressId ? y.Value.Item2 : 0)).Sum()).Sum(); - return store >= count; + return true; } public bool SellDresses(IDressModel model, int count) { - var dres = _source.Dresses.FirstOrDefault(x => x.Id == model.Id); - - if (dres == null || CheckAvailability(model.Id, count)) - { - return false; - } - - for (int i = 0; i < _source.Shops.Count; i++) - { - var shop = _source.Shops[i]; - var dresses = shop.ShopDresses; - foreach( var dress in dresses.Where(x => x.Value.Item1.Id == dres.Id)) - { - var selling = Math.Min(dress.Value.Item2, count); - dresses[dress.Value.Item1.Id] = (dress.Value.Item1, dress.Value.Item2 - selling); - - count -= selling; - - if (count <= 0) - { - break; - } - } - shop.Update(new ShopBindingModel - { - Id = model.Id, - ShopName = shop.ShopName, - Adress = shop.Adress, - MaxCount = shop.MaxCount, - DateOpen = shop.DateOpen, - ShopDresses = dresses - }); - } return true; } } diff --git a/SewingDresses/SewingDressesView/MainForm.cs b/SewingDresses/SewingDressesView/MainForm.cs index 0f2d012..a7e3e67 100644 --- a/SewingDresses/SewingDressesView/MainForm.cs +++ b/SewingDresses/SewingDressesView/MainForm.cs @@ -90,15 +90,13 @@ namespace SewingDressesView { if (dataGridView.SelectedRows.Count == 1) { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Order №{id}. Change status on 'Ready'", - id); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + var dressId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DressId"].Value); + var count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value); + _logger.LogInformation("Order №{id}. Change status on 'Ready'", id); try { - var operationResult = _orderLogic.FinishOrder(new - OrderBindingModel - { Id = id }); + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id, DressId = dressId, Count = count }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); -- 2.25.1