From a413897992e790af978e82d16bfb232dc344c602 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Wed, 14 Feb 2024 13:47:06 +0400 Subject: [PATCH 01/16] save --- .../BlacksmithWorkshop/FormShop.Designer.cs | 159 ++++++++++++++++++ .../BlacksmithWorkshop/FormShop.cs | 122 ++++++++++++++ .../BlacksmithWorkshop/FormShop.resx | 132 +++++++++++++++ .../BusinessLogics/ShopLogic.cs | 152 +++++++++++++++++ .../BindingModels/ShopBindingModel.cs | 18 ++ .../BusinessLogicsContracts/IShopLogic.cs | 22 +++ .../SearchModels/ShopSearchModel.cs | 14 ++ .../StoragesContracts/IShopStorage.cs | 21 +++ .../ViewModels/ShopViewModel.cs | 22 +++ .../Models/IShopModel.cs | 16 ++ .../DataListSingleton.cs | 2 + .../Implements/ShopStorage.cs | 107 ++++++++++++ .../Models/Shop.cs | 54 ++++++ 13 files changed, 841 insertions(+) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormShop.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormShop.resx create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ShopBindingModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ShopSearchModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IShopStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ShopViewModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IShopModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ShopStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Shop.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs new file mode 100644 index 0000000..e9c3004 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs @@ -0,0 +1,159 @@ +namespace BlacksmithWorkshop +{ + partial class FormShop + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + DataGridView = new DataGridView(); + dateTimePicker1 = new DateTimePicker(); + labelName = new Label(); + label2 = new Label(); + labelDate = new Label(); + textBox1 = new TextBox(); + textBox2 = new TextBox(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnName = new DataGridViewTextBoxColumn(); + ColumnPrice = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + SuspendLayout(); + // + // DataGridView + // + DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + DataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnPrice, ColumnCount }); + DataGridView.Location = new Point(12, 101); + DataGridView.Name = "DataGridView"; + DataGridView.RowTemplate.Height = 25; + DataGridView.Size = new Size(479, 281); + DataGridView.TabIndex = 0; + // + // dateTimePicker1 + // + dateTimePicker1.Location = new Point(150, 63); + dateTimePicker1.Name = "dateTimePicker1"; + dateTimePicker1.Size = new Size(166, 23); + dateTimePicker1.TabIndex = 1; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(12, 9); + labelName.Name = "labelName"; + labelName.Size = new Size(62, 15); + labelName.TabIndex = 2; + labelName.Text = "Название:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(12, 38); + label2.Name = "label2"; + label2.Size = new Size(43, 15); + label2.TabIndex = 3; + label2.Text = "Адрес:"; + // + // labelDate + // + labelDate.AutoSize = true; + labelDate.Location = new Point(12, 69); + labelDate.Name = "labelDate"; + labelDate.Size = new Size(90, 15); + labelDate.TabIndex = 4; + labelDate.Text = "Дата открытия:"; + // + // textBox1 + // + textBox1.Location = new Point(150, 6); + textBox1.Name = "textBox1"; + textBox1.Size = new Size(166, 23); + textBox1.TabIndex = 5; + // + // textBox2 + // + textBox2.Location = new Point(150, 35); + textBox2.Name = "textBox2"; + textBox2.Size = new Size(166, 23); + textBox2.TabIndex = 6; + // + // ColumnId + // + ColumnId.HeaderText = ""; + ColumnId.Name = "ColumnId"; + ColumnId.Visible = false; + // + // ColumnName + // + ColumnName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnName.HeaderText = "Изделие"; + ColumnName.Name = "ColumnName"; + // + // ColumnPrice + // + ColumnPrice.HeaderText = "Цена"; + ColumnPrice.Name = "ColumnPrice"; + ColumnPrice.Width = 236; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.Name = "ColumnCount"; + // + // FormShop + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(textBox2); + Controls.Add(textBox1); + Controls.Add(labelDate); + Controls.Add(label2); + Controls.Add(labelName); + Controls.Add(dateTimePicker1); + Controls.Add(DataGridView); + Name = "FormShop"; + Text = "FormShop"; + ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private DataGridView DataGridView; + private DateTimePicker dateTimePicker1; + private Label labelName; + private Label label2; + private Label labelDate; + private TextBox textBox1; + private TextBox textBox2; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnPrice; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.cs new file mode 100644 index 0000000..1cfe0fd --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.cs @@ -0,0 +1,122 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopDataModels.Models; +using Microsoft.Extensions.Logging; +using Microsoft.VisualBasic.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace BlacksmithWorkshop +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public int? _id; + private Dictionary _manufactures; + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _manufactures = new(); + } + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var shop = _logic.ReadElement(new ShopSearchModel { Id = _id }); + if (shop != null) + { + NameTextBox.Text = shop.ShopName; + AddressTextBox.Text = shop.Address; + DateTimePicker.Text = shop.OpeningDate.ToString(); + _manufactures = shop.ShopManufactures; + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка товаров магазина"); + try + { + if (_manufactures != null) + { + foreach (var manufactures in _manufactures) + { + System.Windows.Forms.DataGridView.Rows.Add(new object[] { manufactures.Key, manufactures.Value.Item1.ManufactureName, + manufactures.Value.Item1.Price, manufactures.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void CancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(NameTextBox.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(AddressTextBox.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = NameTextBox.Text, + Address = AddressTextBox.Text, + DateOpen = DateTimePicker.Value.Date, + ShopComputers = _manufactures + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.resx new file mode 100644 index 0000000..b0c7c5d --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.resx @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs new file mode 100644 index 0000000..02ba054 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs @@ -0,0 +1,152 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.BusinessLogics +{ + 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:{ShopName}. Id:{ Id}", model?.ShopName, model?.Id); + var list = model == null ? _shopStorage.GetFullList() : + _shopStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ShopViewModel? ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id); + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + public bool ReplenishManufactures(ShopSearchModel model, IManufactureModel manufacture, int count) + { + _logger.LogInformation("Try to replenish manufactures. ShopName:{ShopName}. Id:{Id}", model.ShopName, model.Id); + if (model == null) + throw new ArgumentNullException(nameof(model)); + ShopViewModel? curModel = ReadElement(model); + if (curModel == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (manufacture == null) + throw new ArgumentNullException(nameof(manufacture)); + if (count <= 0) + throw new ArgumentException("Количество должно быть положительным числом"); + if (curModel.ShopManufactures.TryGetValue(manufacture.Id, out var pair)) + { + curModel.ShopManufactures[manufacture.Id] = (pair.Item1, pair.Item2 + count); + } + else + { + curModel.ShopManufactures.Add(manufacture.Id, (manufacture, count)); + } + Update(new() + { + Id = curModel.Id, + ShopName = curModel.ShopName, + OpeningDate = curModel.OpeningDate, + Address = curModel.Address, + ShopManufactures = curModel.ShopManufactures, + }); + _logger.LogInformation("Success. ManufactureName:{ManufactureName}. Id:{Id}. Replenish:{count}", + manufacture.ManufactureName, manufacture.Id, count); + return true; + } + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ShopName)) + { + throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName)); + } + if (string.IsNullOrEmpty(model.Address)) + { + throw new ArgumentNullException("Нет адреса магазина", nameof(model.Address)); + } + _logger.LogInformation("Shop. ShopName:{ShopName}.Address:{Address}. DateOpen:{DateOpen}. Id: { Id}", + model.ShopName, model.Address, model.OpeningDate, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + ShopName = model.ShopName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ShopBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..79ff366 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BlacksmithWorkshopDataModels.Models; + +namespace BlacksmithWorkshopContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + public string ShopName { get; set; } = string.Empty; + public string Address { get; set; } = string.Empty; + public DateTime OpeningDate { get; set; } + public Dictionary ShopManufactures { get; set; } = new(); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IShopLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..5b6358d --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,22 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.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 ReplenishManufactures(ShopSearchModel shop, IManufactureModel manufacture, int count); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ShopSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..64a9f62 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? ShopName { get; set; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IShopStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..c36afa4 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,21 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.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); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ShopViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..1a17384 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,22 @@ +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + [DisplayName("Название магазина")] + public string ShopName { get; set; } = string.Empty; + [DisplayName("Адрес магазина")] + public string Address { get; set; } = string.Empty; + [DisplayName("Дата открытия")] + public DateTime OpeningDate { get; set; } + public Dictionary ShopManufactures { get; set; } = new(); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IShopModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..1e742af --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IShopModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + string Address { get; } + DateTime OpeningDate { get; } + Dictionary ShopManufactures { get; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs index 71c00d4..32ab5b6 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs @@ -13,11 +13,13 @@ namespace BlacksmithWorkshopListImplement public List Components { get; set; } public List Orders { get; set; } public List Manufactures { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Manufactures = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ShopStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..eb418a9 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ShopStorage.cs @@ -0,0 +1,107 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + List result = new List(); + foreach(var Shop in _source.Shops) + { + result.Add(Shop.GetViewModel); + } + return result; + } + public List GetFilteredList(ShopSearchModel model) + { + List result = new(); + if (string.IsNullOrEmpty(model.ShopName)) + { + return result; + } + foreach(var Shop in _source.Shops) + { + if (Shop.ShopName.Contains(model.ShopName)) + { + result.Add(Shop.GetViewModel); + } + } + return result; + } + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + foreach(var Shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.ShopName) && + Shop.ShopName == model.ShopName) || + (model.Id.HasValue && Shop.Id == model.Id)) + { + return Shop.GetViewModel; + } + } + return null; + } + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = 1; + foreach(var Shop in _source.Shops) + { + if (Shop.Id >= model.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; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Shop.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Shop.cs new file mode 100644 index 0000000..4c761e4 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Shop.cs @@ -0,0 +1,54 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + public string Address { get; private set; } = string.Empty; + public DateTime OpeningDate { get; private set; } + public Dictionary ShopManufactures { get; private set; } = new(); + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + OpeningDate = model.OpeningDate, + ShopManufactures = model.ShopManufactures + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + OpeningDate = model.OpeningDate; + ShopManufactures = model.ShopManufactures; + } + public ShopViewModel GetViewModel => new ShopViewModel() + { + Id = Id, + ShopName = ShopName, + Address = Address, + OpeningDate = OpeningDate, + ShopManufactures = ShopManufactures + }; + } +} -- 2.25.1 From 798bbe5552fd20f751d1c3782ea923e3499d0ad5 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Wed, 14 Feb 2024 13:55:10 +0400 Subject: [PATCH 02/16] FormShop --- .../BlacksmithWorkshop/FormShop.Designer.cs | 180 ++++++++++-------- .../BlacksmithWorkshop/FormShop.cs | 20 +- .../BlacksmithWorkshop/FormShop.resx | 12 ++ 3 files changed, 125 insertions(+), 87 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs index e9c3004..f949e94 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs @@ -28,77 +28,31 @@ /// private void InitializeComponent() { - DataGridView = new DataGridView(); - dateTimePicker1 = new DateTimePicker(); - labelName = new Label(); - label2 = new Label(); - labelDate = new Label(); - textBox1 = new TextBox(); - textBox2 = new TextBox(); + dataGridView = new DataGridView(); ColumnId = new DataGridViewTextBoxColumn(); ColumnName = new DataGridViewTextBoxColumn(); ColumnPrice = new DataGridViewTextBoxColumn(); ColumnCount = new DataGridViewTextBoxColumn(); - ((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit(); + dateTimePicker = new DateTimePicker(); + labelName = new Label(); + labelAddress = new Label(); + labelDate = new Label(); + textBoxName = new TextBox(); + textBoxAddress = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // - // DataGridView + // dataGridView // - DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - DataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnPrice, ColumnCount }); - DataGridView.Location = new Point(12, 101); - DataGridView.Name = "DataGridView"; - DataGridView.RowTemplate.Height = 25; - DataGridView.Size = new Size(479, 281); - DataGridView.TabIndex = 0; - // - // dateTimePicker1 - // - dateTimePicker1.Location = new Point(150, 63); - dateTimePicker1.Name = "dateTimePicker1"; - dateTimePicker1.Size = new Size(166, 23); - dateTimePicker1.TabIndex = 1; - // - // labelName - // - labelName.AutoSize = true; - labelName.Location = new Point(12, 9); - labelName.Name = "labelName"; - labelName.Size = new Size(62, 15); - labelName.TabIndex = 2; - labelName.Text = "Название:"; - // - // label2 - // - label2.AutoSize = true; - label2.Location = new Point(12, 38); - label2.Name = "label2"; - label2.Size = new Size(43, 15); - label2.TabIndex = 3; - label2.Text = "Адрес:"; - // - // labelDate - // - labelDate.AutoSize = true; - labelDate.Location = new Point(12, 69); - labelDate.Name = "labelDate"; - labelDate.Size = new Size(90, 15); - labelDate.TabIndex = 4; - labelDate.Text = "Дата открытия:"; - // - // textBox1 - // - textBox1.Location = new Point(150, 6); - textBox1.Name = "textBox1"; - textBox1.Size = new Size(166, 23); - textBox1.TabIndex = 5; - // - // textBox2 - // - textBox2.Location = new Point(150, 35); - textBox2.Name = "textBox2"; - textBox2.Size = new Size(166, 23); - textBox2.TabIndex = 6; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnPrice, ColumnCount }); + dataGridView.Location = new Point(12, 101); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(553, 281); + dataGridView.TabIndex = 0; // // ColumnId // @@ -116,44 +70,116 @@ // ColumnPrice.HeaderText = "Цена"; ColumnPrice.Name = "ColumnPrice"; - ColumnPrice.Width = 236; // // ColumnCount // ColumnCount.HeaderText = "Количество"; ColumnCount.Name = "ColumnCount"; // + // dateTimePicker + // + dateTimePicker.Location = new Point(150, 63); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(166, 23); + dateTimePicker.TabIndex = 1; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(12, 9); + labelName.Name = "labelName"; + labelName.Size = new Size(62, 15); + labelName.TabIndex = 2; + labelName.Text = "Название:"; + // + // labelAddress + // + labelAddress.AutoSize = true; + labelAddress.Location = new Point(12, 38); + labelAddress.Name = "labelAddress"; + labelAddress.Size = new Size(43, 15); + labelAddress.TabIndex = 3; + labelAddress.Text = "Адрес:"; + // + // labelDate + // + labelDate.AutoSize = true; + labelDate.Location = new Point(12, 69); + labelDate.Name = "labelDate"; + labelDate.Size = new Size(90, 15); + labelDate.TabIndex = 4; + labelDate.Text = "Дата открытия:"; + // + // textBoxName + // + textBoxName.Location = new Point(150, 6); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(166, 23); + textBoxName.TabIndex = 5; + // + // textBoxAddress + // + textBoxAddress.Location = new Point(150, 35); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(166, 23); + textBoxAddress.TabIndex = 6; + // + // buttonSave + // + buttonSave.Location = new Point(12, 401); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(123, 25); + buttonSave.TabIndex = 7; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += SaveButton_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(150, 401); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(123, 25); + buttonCancel.TabIndex = 8; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += CancelButton_Click; + // // FormShop // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); - Controls.Add(textBox2); - Controls.Add(textBox1); + ClientSize = new Size(585, 450); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxAddress); + Controls.Add(textBoxName); Controls.Add(labelDate); - Controls.Add(label2); + Controls.Add(labelAddress); Controls.Add(labelName); - Controls.Add(dateTimePicker1); - Controls.Add(DataGridView); + Controls.Add(dateTimePicker); + Controls.Add(dataGridView); Name = "FormShop"; Text = "FormShop"; - ((System.ComponentModel.ISupportInitialize)DataGridView).EndInit(); + Load += FormShop_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); PerformLayout(); } #endregion - private DataGridView DataGridView; - private DateTimePicker dateTimePicker1; + private DataGridView dataGridView; + private DateTimePicker dateTimePicker; private Label labelName; - private Label label2; + private Label labelAddress; private Label labelDate; - private TextBox textBox1; - private TextBox textBox2; + private TextBox textBoxName; + private TextBox textBoxAddress; private DataGridViewTextBoxColumn ColumnId; private DataGridViewTextBoxColumn ColumnName; private DataGridViewTextBoxColumn ColumnPrice; private DataGridViewTextBoxColumn ColumnCount; + private Button buttonSave; + private Button buttonCancel; } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.cs index 1cfe0fd..9d551fe 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.cs @@ -39,9 +39,9 @@ namespace BlacksmithWorkshop var shop = _logic.ReadElement(new ShopSearchModel { Id = _id }); if (shop != null) { - NameTextBox.Text = shop.ShopName; - AddressTextBox.Text = shop.Address; - DateTimePicker.Text = shop.OpeningDate.ToString(); + textBoxName.Text = shop.ShopName; + textBoxAddress.Text = shop.Address; + dateTimePicker.Text = shop.OpeningDate.ToString(); _manufactures = shop.ShopManufactures; } LoadData(); @@ -63,7 +63,7 @@ namespace BlacksmithWorkshop { foreach (var manufactures in _manufactures) { - System.Windows.Forms.DataGridView.Rows.Add(new object[] { manufactures.Key, manufactures.Value.Item1.ManufactureName, + dataGridView.Rows.Add(new object[] { manufactures.Key, manufactures.Value.Item1.ManufactureName, manufactures.Value.Item1.Price, manufactures.Value.Item2 }); } } @@ -82,12 +82,12 @@ namespace BlacksmithWorkshop } private void SaveButton_Click(object sender, EventArgs e) { - if (string.IsNullOrEmpty(NameTextBox.Text)) + if (string.IsNullOrEmpty(textBoxName.Text)) { MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - if (string.IsNullOrEmpty(AddressTextBox.Text)) + if (string.IsNullOrEmpty(textBoxAddress.Text)) { MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; @@ -98,10 +98,10 @@ namespace BlacksmithWorkshop var model = new ShopBindingModel { Id = _id ?? 0, - ShopName = NameTextBox.Text, - Address = AddressTextBox.Text, - DateOpen = DateTimePicker.Value.Date, - ShopComputers = _manufactures + ShopName = textBoxName.Text, + Address = textBoxAddress.Text, + OpeningDate = dateTimePicker.Value.Date, + ShopManufactures = _manufactures }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.resx index b0c7c5d..ef64542 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.resx +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.resx @@ -129,4 +129,16 @@ True + + True + + + True + + + True + + + True + \ No newline at end of file -- 2.25.1 From e7a06e494e7a17496839748958ec922c8efabadd Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Wed, 14 Feb 2024 14:04:43 +0400 Subject: [PATCH 03/16] FormShops --- .../BlacksmithWorkshop/FormShops.Designer.cs | 113 +++++++++++++++++ .../BlacksmithWorkshop/FormShops.cs | 110 ++++++++++++++++ .../BlacksmithWorkshop/FormShops.resx | 120 ++++++++++++++++++ 3 files changed, 343 insertions(+) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormShops.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormShops.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormShops.resx diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.Designer.cs new file mode 100644 index 0000000..b511e71 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.Designer.cs @@ -0,0 +1,113 @@ +namespace BlacksmithWorkshop +{ + partial class FormShops + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonUpdate = new Button(); + buttonDelete = new Button(); + buttonRefresh = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(567, 450); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(617, 22); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(152, 33); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Создать"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += AddButton_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(617, 61); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(152, 33); + buttonUpdate.TabIndex = 2; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += UpdateButton_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(617, 100); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(152, 33); + buttonDelete.TabIndex = 3; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += DeleteButton_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(617, 139); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(152, 33); + buttonRefresh.TabIndex = 4; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += RefreshButton_Click; + // + // FormShops + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormShops"; + Text = "FormShops"; + Load += FormShops_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.cs new file mode 100644 index 0000000..892417a --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.cs @@ -0,0 +1,110 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace BlacksmithWorkshop +{ + public partial class FormShops : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public FormShops(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Address"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["DateOpen"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ShopComputers"].Visible = false; + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void FormShops_Load(object sender, EventArgs e) + { + LoadData(); + } + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void UpdateButton_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + form._id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void RefreshButton_Click(object sender, EventArgs e) + { + LoadData(); + } + private void DeleteButton_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _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/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file -- 2.25.1 From de39a707641ad2e21130c04fad3f969413450a42 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Wed, 14 Feb 2024 14:22:47 +0400 Subject: [PATCH 04/16] FormSupply --- .../BlacksmithWorkshop/FormShops.cs | 2 +- .../BlacksmithWorkshop/FormSupply.Designer.cs | 107 ++++++++++++++ .../BlacksmithWorkshop/FormSupply.cs | 139 ++++++++++++++++++ .../BlacksmithWorkshop/FormSupply.resx | 120 +++++++++++++++ 4 files changed, 367 insertions(+), 1 deletion(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.resx diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.cs index 892417a..327add1 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.cs @@ -35,7 +35,7 @@ namespace BlacksmithWorkshop dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["Address"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["DateOpen"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["ShopComputers"].Visible = false; + dataGridView.Columns["ShopManufactures"].Visible = false; } _logger.LogInformation("Загрузка магазинов"); } diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs new file mode 100644 index 0000000..3894c27 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs @@ -0,0 +1,107 @@ +namespace BlacksmithWorkshop +{ + partial class FormSupply + { + /// + /// 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(); + ManufactureComboBox = new ComboBox(); + CountTextBox = new TextBox(); + button1 = new Button(); + button2 = new Button(); + SuspendLayout(); + // + // ShopComboBox + // + ShopComboBox.DropDownStyle = ComboBoxStyle.DropDownList; + ShopComboBox.FormattingEnabled = true; + ShopComboBox.Location = new Point(12, 12); + ShopComboBox.Name = "ShopComboBox"; + ShopComboBox.Size = new Size(224, 23); + ShopComboBox.TabIndex = 0; + // + // ManufactureComboBox + // + ManufactureComboBox.DropDownStyle = ComboBoxStyle.DropDownList; + ManufactureComboBox.FormattingEnabled = true; + ManufactureComboBox.Location = new Point(242, 12); + ManufactureComboBox.Name = "ManufactureComboBox"; + ManufactureComboBox.Size = new Size(224, 23); + ManufactureComboBox.TabIndex = 1; + // + // CountTextBox + // + CountTextBox.Location = new Point(472, 12); + CountTextBox.Name = "CountTextBox"; + CountTextBox.Size = new Size(224, 23); + CountTextBox.TabIndex = 2; + // + // button1 + // + button1.Location = new Point(162, 47); + button1.Name = "button1"; + button1.Size = new Size(157, 28); + button1.TabIndex = 3; + button1.Text = "Сохранить"; + button1.UseVisualStyleBackColor = true; + button1.Click += SaveButton_Click; + // + // button2 + // + button2.Location = new Point(394, 47); + button2.Name = "button2"; + button2.Size = new Size(157, 28); + button2.TabIndex = 4; + button2.Text = "Отмена"; + button2.UseVisualStyleBackColor = true; + button2.Click += CancelButton_Click; + // + // FormSupply + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(707, 87); + Controls.Add(button2); + Controls.Add(button1); + Controls.Add(CountTextBox); + Controls.Add(ManufactureComboBox); + Controls.Add(ShopComboBox); + Name = "FormSupply"; + Text = "FormSupply"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox ShopComboBox; + private ComboBox ManufactureComboBox; + private TextBox CountTextBox; + private Button button1; + private Button button2; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs new file mode 100644 index 0000000..8e2c04c --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs @@ -0,0 +1,139 @@ +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.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 BlacksmithWorkshop +{ + public partial class FormSupply : Form + { + private readonly List? _manufactureList; + private readonly List? _shopsList; + IShopLogic _shopLogic; + IManufactureLogic _ManufactureLogic; + public int ShopId + { + get + { + return Convert.ToInt32(ShopComboBox.SelectedValue); + } + set + { + ShopComboBox.SelectedValue = value; + } + } + public int ManufactureId + { + get + { + return Convert.ToInt32(ManufactureComboBox.SelectedValue); + } + set + { + ManufactureComboBox.SelectedValue = value; + } + } + public IManufactureModel? ManufactureModel + { + get + { + if (_manufactureList == null) + { + return null; + } + foreach (var elem in _manufactureList) + { + if (elem.Id == ManufactureId) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(CountTextBox.Text); } + set { CountTextBox.Text = value.ToString(); } + } + public FormSupply(IManufactureLogic ManufactureLogic, IShopLogic shopLogic) + { + InitializeComponent(); + _shopLogic = shopLogic; + _ManufactureLogic = ManufactureLogic; + _manufactureList = ManufactureLogic.ReadList(null); + _shopsList = shopLogic.ReadList(null); + if (_manufactureList != null) + { + ManufactureComboBox.DisplayMember = "ManufactureName"; + ManufactureComboBox.ValueMember = "Id"; + ManufactureComboBox.DataSource = _manufactureList; + ManufactureComboBox.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 (ManufactureComboBox.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.ReplenishManufactures( + new ShopSearchModel() { Id = Convert.ToInt32(ShopComboBox.SelectedValue) }, + _ManufactureLogic.ReadElement(new() { Id = Convert.ToInt32(ManufactureComboBox.SelectedValue) }), + count + ); + if (!res) + { + throw new Exception("Ошибка при пополнении. Дополнительная информация в логах"); + } + MessageBox.Show("Пополнение прошло успешно"); + DialogResult = DialogResult.OK; + Close(); + + } + catch (Exception) + { + MessageBox.Show("Ошибка пополнения"); + return; + } + } + private void CancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.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 71b94c585dc0d33407e584b947e3fdf7c2033c5b Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Wed, 14 Feb 2024 14:32:32 +0400 Subject: [PATCH 05/16] FormMain & Program --- .../BlacksmithWorkshop/FormMain.Designer.cs | 344 +++++++++--------- .../BlacksmithWorkshop/FormMain.cs | 316 ++++++++-------- .../BlacksmithWorkshop/Program.cs | 9 +- 3 files changed, 354 insertions(+), 315 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs index e8e1949..aabf10c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs @@ -1,171 +1,189 @@ namespace BlacksmithWorkshop { - partial class FormMain - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + partial class FormMain + { + /// + /// 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); - } + /// + /// 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 + #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() - { - menuStrip = new MenuStrip(); - GuidesToolStripMenuItem = new ToolStripMenuItem(); - ComponentsToolStripMenuItem = new ToolStripMenuItem(); - ManufacturesToolStripMenuItem = new ToolStripMenuItem(); - dataGridView = new DataGridView(); - buttonCreateOrder = new Button(); - buttonRefresh = new Button(); - buttonIssued = new Button(); - buttonReady = new Button(); - buttonTakeInWork = new Button(); - menuStrip.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // menuStrip - // - menuStrip.Items.AddRange(new ToolStripItem[] { GuidesToolStripMenuItem }); - menuStrip.Location = new Point(0, 0); - menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(1011, 24); - menuStrip.TabIndex = 0; - menuStrip.Text = "menuStrip1"; - // - // GuidesToolStripMenuItem - // - GuidesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, ManufacturesToolStripMenuItem }); - GuidesToolStripMenuItem.Name = "GuidesToolStripMenuItem"; - GuidesToolStripMenuItem.Size = new Size(94, 20); - GuidesToolStripMenuItem.Text = "Справочники"; - // - // ComponentsToolStripMenuItem - // - ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem"; - ComponentsToolStripMenuItem.Size = new Size(181, 22); - ComponentsToolStripMenuItem.Text = "Компоненты"; - ComponentsToolStripMenuItem.Click += ComponentsStripMenuItem_Click; - // - // ManufacturesToolStripMenuItem - // - ManufacturesToolStripMenuItem.Name = "ManufacturesToolStripMenuItem"; - ManufacturesToolStripMenuItem.Size = new Size(181, 22); - ManufacturesToolStripMenuItem.Text = "Кузнечные изделия"; - ManufacturesToolStripMenuItem.Click += ManufacturesStripMenuItem_Click; - // - // dataGridView - // - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(0, 23); - dataGridView.Name = "dataGridView"; - dataGridView.RowTemplate.Height = 25; - dataGridView.Size = new Size(847, 427); - dataGridView.TabIndex = 1; - // - // buttonCreateOrder - // - buttonCreateOrder.Location = new Point(853, 38); - buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(148, 31); - buttonCreateOrder.TabIndex = 2; - buttonCreateOrder.Text = "Создать заказ"; - buttonCreateOrder.UseVisualStyleBackColor = true; - buttonCreateOrder.Click += CreateOrderButton_Click; - // - // buttonRefresh - // - buttonRefresh.Location = new Point(853, 186); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(148, 31); - buttonRefresh.TabIndex = 3; - buttonRefresh.Text = "Обновить список"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += RefreshButton_Click; - // - // buttonIssued - // - buttonIssued.Location = new Point(853, 149); - buttonIssued.Name = "buttonIssued"; - buttonIssued.Size = new Size(148, 31); - buttonIssued.TabIndex = 4; - buttonIssued.Text = "Заказ выдан"; - buttonIssued.UseVisualStyleBackColor = true; - buttonIssued.Click += IssuedButton_Click; - // - // buttonReady - // - buttonReady.Location = new Point(853, 112); - buttonReady.Name = "buttonReady"; - buttonReady.Size = new Size(148, 31); - buttonReady.TabIndex = 5; - buttonReady.Text = "Заказ готов"; - buttonReady.UseVisualStyleBackColor = true; - buttonReady.Click += ReadyButton_Click; - // - // buttonTakeInWork - // - buttonTakeInWork.Location = new Point(853, 75); - buttonTakeInWork.Name = "buttonTakeInWork"; - buttonTakeInWork.Size = new Size(148, 31); - buttonTakeInWork.TabIndex = 6; - buttonTakeInWork.Text = "Отдать на выполнение"; - buttonTakeInWork.UseVisualStyleBackColor = true; - buttonTakeInWork.Click += TakeInWorkButton_Click; - // - // FormMain - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1011, 450); - Controls.Add(buttonTakeInWork); - Controls.Add(buttonReady); - Controls.Add(buttonIssued); - Controls.Add(buttonRefresh); - Controls.Add(buttonCreateOrder); - Controls.Add(dataGridView); - Controls.Add(menuStrip); - MainMenuStrip = menuStrip; - Name = "FormMain"; - StartPosition = FormStartPosition.CenterParent; - Text = "Кузница"; - Load += FormMain_Load; - menuStrip.ResumeLayout(false); - menuStrip.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + menuStrip = new MenuStrip(); + GuidesToolStripMenuItem = new ToolStripMenuItem(); + ComponentsToolStripMenuItem = new ToolStripMenuItem(); + ManufacturesToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonRefresh = new Button(); + buttonIssued = new Button(); + buttonReady = new Button(); + buttonTakeInWork = new Button(); + ShopsToolStripMenuItem = new ToolStripMenuItem(); + SupplyToolStripMenuItem = new ToolStripMenuItem(); + menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip + // + menuStrip.Items.AddRange(new ToolStripItem[] { GuidesToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(1011, 24); + menuStrip.TabIndex = 0; + menuStrip.Text = "menuStrip1"; + // + // GuidesToolStripMenuItem + // + GuidesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, ManufacturesToolStripMenuItem, ShopsToolStripMenuItem, SupplyToolStripMenuItem }); + GuidesToolStripMenuItem.Name = "GuidesToolStripMenuItem"; + GuidesToolStripMenuItem.Size = new Size(94, 20); + GuidesToolStripMenuItem.Text = "Справочники"; + // + // ComponentsToolStripMenuItem + // + ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem"; + ComponentsToolStripMenuItem.Size = new Size(181, 22); + ComponentsToolStripMenuItem.Text = "Компоненты"; + ComponentsToolStripMenuItem.Click += ComponentsStripMenuItem_Click; + // + // ManufacturesToolStripMenuItem + // + ManufacturesToolStripMenuItem.Name = "ManufacturesToolStripMenuItem"; + ManufacturesToolStripMenuItem.Size = new Size(181, 22); + ManufacturesToolStripMenuItem.Text = "Кузнечные изделия"; + ManufacturesToolStripMenuItem.Click += ManufacturesStripMenuItem_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 23); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(847, 427); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(853, 38); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(148, 31); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += CreateOrderButton_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(853, 186); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(148, 31); + buttonRefresh.TabIndex = 3; + buttonRefresh.Text = "Обновить список"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += RefreshButton_Click; + // + // buttonIssued + // + buttonIssued.Location = new Point(853, 149); + buttonIssued.Name = "buttonIssued"; + buttonIssued.Size = new Size(148, 31); + buttonIssued.TabIndex = 4; + buttonIssued.Text = "Заказ выдан"; + buttonIssued.UseVisualStyleBackColor = true; + buttonIssued.Click += IssuedButton_Click; + // + // buttonReady + // + buttonReady.Location = new Point(853, 112); + buttonReady.Name = "buttonReady"; + buttonReady.Size = new Size(148, 31); + buttonReady.TabIndex = 5; + buttonReady.Text = "Заказ готов"; + buttonReady.UseVisualStyleBackColor = true; + buttonReady.Click += ReadyButton_Click; + // + // buttonTakeInWork + // + buttonTakeInWork.Location = new Point(853, 75); + buttonTakeInWork.Name = "buttonTakeInWork"; + buttonTakeInWork.Size = new Size(148, 31); + buttonTakeInWork.TabIndex = 6; + buttonTakeInWork.Text = "Отдать на выполнение"; + buttonTakeInWork.UseVisualStyleBackColor = true; + buttonTakeInWork.Click += TakeInWorkButton_Click; + // + // ShopsToolStripMenuItem + // + ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem"; + ShopsToolStripMenuItem.Size = new Size(181, 22); + ShopsToolStripMenuItem.Text = "Магазины"; + ShopsToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; + // + // SupplyToolStripMenuItem + // + SupplyToolStripMenuItem.Name = "SupplyToolStripMenuItem"; + SupplyToolStripMenuItem.Size = new Size(181, 22); + SupplyToolStripMenuItem.Text = "Поставки"; + SupplyToolStripMenuItem.Click += SupplyToolStripMenuItem_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1011, 450); + Controls.Add(buttonTakeInWork); + Controls.Add(buttonReady); + Controls.Add(buttonIssued); + Controls.Add(buttonRefresh); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Name = "FormMain"; + StartPosition = FormStartPosition.CenterParent; + Text = "Кузница"; + Load += FormMain_Load; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private MenuStrip menuStrip; - private ToolStripMenuItem GuidesToolStripMenuItem; - private ToolStripMenuItem ComponentsToolStripMenuItem; - private ToolStripMenuItem ManufacturesToolStripMenuItem; - private DataGridView dataGridView; - private Button buttonCreateOrder; - private Button buttonRefresh; - private Button buttonIssued; - private Button buttonReady; - private Button buttonTakeInWork; - } + private MenuStrip menuStrip; + private ToolStripMenuItem GuidesToolStripMenuItem; + private ToolStripMenuItem ComponentsToolStripMenuItem; + private ToolStripMenuItem ManufacturesToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonRefresh; + private Button buttonIssued; + private Button buttonReady; + private Button buttonTakeInWork; + private ToolStripMenuItem ShopsToolStripMenuItem; + private ToolStripMenuItem SupplyToolStripMenuItem; + } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index 7174015..60cf34a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -14,154 +14,170 @@ using System.Windows.Forms; namespace BlacksmithWorkshop { - public partial class FormMain : Form - { - private readonly ILogger _logger; - private readonly IOrderLogic _orderLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic) - { - InitializeComponent(); - _logger = logger; - _orderLogic = orderLogic; - } - private void ComponentsStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } - } - private void FormMain_Load(object sender, EventArgs e) - { - LoadData(); - } - private void LoadData() - { - _logger.LogInformation("Загрузка заказов"); - try - { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["ManufactureId"].Visible = false; - dataGridView.Columns["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка заказов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки заказов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - private void ManufacturesStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormManufactures)); - if (service is FormManufactures form) - { - form.ShowDialog(); - } - } - private void CreateOrderButton_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } - } - private OrderBindingModel CreateBindingModel(int id, bool isDone = false) - { - return new OrderBindingModel - { - Id = id, - ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), - }; - } - private void TakeInWorkButton_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(CreateBindingModel(id)); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } - private void ReadyButton_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", - id); - try - { - var operationResult = _orderLogic.FinishOrder(CreateBindingModel(id)); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void IssuedButton_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", - id); - try - { - var operationResult = _orderLogic.DeliveryOrder(CreateBindingModel(id)); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - _logger.LogInformation("Заказ №{id} выдан", id); - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } - private void RefreshButton_Click(object sender, EventArgs e) - { - LoadData(); - } - } + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + private void ComponentsStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["ManufactureId"].Visible = false; + dataGridView.Columns["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ManufacturesStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormManufactures)); + if (service is FormManufactures form) + { + form.ShowDialog(); + } + } + private void CreateOrderButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private OrderBindingModel CreateBindingModel(int id, bool isDone = false) + { + return new OrderBindingModel + { + Id = id, + ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }; + } + private void TakeInWorkButton_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ReadyButton_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", + id); + try + { + var operationResult = _orderLogic.FinishOrder(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void IssuedButton_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", + id); + try + { + var operationResult = _orderLogic.DeliveryOrder(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void RefreshButton_Click(object sender, EventArgs e) + { + LoadData(); + } + private void ShopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + private void SupplyToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSupply)); + if (service is FormSupply form) + { + form.ShowDialog(); + } + } + } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs index 65045db..ccbd192 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs @@ -40,13 +40,18 @@ namespace BlacksmithWorkshop services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); - } + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } } } \ No newline at end of file -- 2.25.1 From f7bddcd360beff67cb7a068957f84beeabc1aeb6 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Wed, 14 Feb 2024 15:47:20 +0400 Subject: [PATCH 06/16] some minor fixes --- .../BlacksmithWorkshop/FormMain.Designer.cs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs index aabf10c..cb21a02 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs @@ -32,14 +32,14 @@ GuidesToolStripMenuItem = new ToolStripMenuItem(); ComponentsToolStripMenuItem = new ToolStripMenuItem(); ManufacturesToolStripMenuItem = new ToolStripMenuItem(); + ShopsToolStripMenuItem = new ToolStripMenuItem(); + SupplyToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); buttonRefresh = new Button(); buttonIssued = new Button(); buttonReady = new Button(); buttonTakeInWork = new Button(); - ShopsToolStripMenuItem = new ToolStripMenuItem(); - SupplyToolStripMenuItem = new ToolStripMenuItem(); menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -63,17 +63,31 @@ // ComponentsToolStripMenuItem // ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem"; - ComponentsToolStripMenuItem.Size = new Size(181, 22); + ComponentsToolStripMenuItem.Size = new Size(198, 22); ComponentsToolStripMenuItem.Text = "Компоненты"; ComponentsToolStripMenuItem.Click += ComponentsStripMenuItem_Click; // // ManufacturesToolStripMenuItem // ManufacturesToolStripMenuItem.Name = "ManufacturesToolStripMenuItem"; - ManufacturesToolStripMenuItem.Size = new Size(181, 22); + ManufacturesToolStripMenuItem.Size = new Size(198, 22); ManufacturesToolStripMenuItem.Text = "Кузнечные изделия"; ManufacturesToolStripMenuItem.Click += ManufacturesStripMenuItem_Click; // + // ShopsToolStripMenuItem + // + ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem"; + ShopsToolStripMenuItem.Size = new Size(198, 22); + ShopsToolStripMenuItem.Text = "Магазины"; + ShopsToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; + // + // SupplyToolStripMenuItem + // + SupplyToolStripMenuItem.Name = "SupplyToolStripMenuItem"; + SupplyToolStripMenuItem.Size = new Size(198, 22); + SupplyToolStripMenuItem.Text = "Пополнение магазина"; + SupplyToolStripMenuItem.Click += SupplyToolStripMenuItem_Click; + // // dataGridView // dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -133,20 +147,6 @@ buttonTakeInWork.UseVisualStyleBackColor = true; buttonTakeInWork.Click += TakeInWorkButton_Click; // - // ShopsToolStripMenuItem - // - ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem"; - ShopsToolStripMenuItem.Size = new Size(181, 22); - ShopsToolStripMenuItem.Text = "Магазины"; - ShopsToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; - // - // SupplyToolStripMenuItem - // - SupplyToolStripMenuItem.Name = "SupplyToolStripMenuItem"; - SupplyToolStripMenuItem.Size = new Size(181, 22); - SupplyToolStripMenuItem.Text = "Поставки"; - SupplyToolStripMenuItem.Click += SupplyToolStripMenuItem_Click; - // // FormMain // AutoScaleDimensions = new SizeF(7F, 15F); -- 2.25.1 From 1c79247c2634edeecbff993c45f53341a8948479 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Wed, 14 Feb 2024 16:15:36 +0400 Subject: [PATCH 07/16] some minor fixes --- .../BlacksmithWorkshop/FormShop.Designer.cs | 3 ++- BlacksmithWorkshop/BlacksmithWorkshop/FormShop.resx | 12 ------------ .../BlacksmithWorkshop/FormShops.Designer.cs | 3 ++- BlacksmithWorkshop/BlacksmithWorkshop/FormShops.cs | 2 +- .../BlacksmithWorkshop/FormSupply.Designer.cs | 3 ++- 5 files changed, 7 insertions(+), 16 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs index f949e94..1d9d90e 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs @@ -159,7 +159,8 @@ Controls.Add(dateTimePicker); Controls.Add(dataGridView); Name = "FormShop"; - Text = "FormShop"; + StartPosition = FormStartPosition.CenterParent; + Text = "Магазин"; Load += FormShop_Load; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.resx index ef64542..b0c7c5d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.resx +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.resx @@ -129,16 +129,4 @@ True - - True - - - True - - - True - - - True - \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.Designer.cs index b511e71..7755f6d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.Designer.cs @@ -96,7 +96,8 @@ Controls.Add(buttonAdd); Controls.Add(dataGridView); Name = "FormShops"; - Text = "FormShops"; + StartPosition = FormStartPosition.CenterParent; + Text = "Магазины"; Load += FormShops_Load; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.cs index 327add1..e9fcb99 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.cs @@ -34,7 +34,7 @@ namespace BlacksmithWorkshop dataGridView.Columns["Id"].Visible = false; dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["Address"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["DateOpen"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["OpeningDate"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["ShopManufactures"].Visible = false; } _logger.LogInformation("Загрузка магазинов"); diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs index 3894c27..e350ec8 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs @@ -91,7 +91,8 @@ Controls.Add(ManufactureComboBox); Controls.Add(ShopComboBox); Name = "FormSupply"; - Text = "FormSupply"; + StartPosition = FormStartPosition.CenterParent; + Text = "Пополнение магазина"; ResumeLayout(false); PerformLayout(); } -- 2.25.1 From 96dd6c0089de4bab6739f5f8c1aa3c830fbf63c6 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Wed, 14 Feb 2024 16:36:39 +0400 Subject: [PATCH 08/16] some minor fixes --- BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs index 8e2c04c..4288560 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs @@ -19,7 +19,7 @@ namespace BlacksmithWorkshop private readonly List? _manufactureList; private readonly List? _shopsList; IShopLogic _shopLogic; - IManufactureLogic _ManufactureLogic; + IManufactureLogic _manufactureLogic; public int ShopId { get @@ -69,7 +69,7 @@ namespace BlacksmithWorkshop { InitializeComponent(); _shopLogic = shopLogic; - _ManufactureLogic = ManufactureLogic; + _manufactureLogic = ManufactureLogic; _manufactureList = ManufactureLogic.ReadList(null); _shopsList = shopLogic.ReadList(null); if (_manufactureList != null) @@ -112,7 +112,7 @@ namespace BlacksmithWorkshop int count = Convert.ToInt32(CountTextBox.Text); bool res = _shopLogic.ReplenishManufactures( new ShopSearchModel() { Id = Convert.ToInt32(ShopComboBox.SelectedValue) }, - _ManufactureLogic.ReadElement(new() { Id = Convert.ToInt32(ManufactureComboBox.SelectedValue) }), + _manufactureLogic.ReadElement(new() { Id = Convert.ToInt32(ManufactureComboBox.SelectedValue) }), count ); if (!res) -- 2.25.1 From 290c6606925231564e134ee59e4697dcb6062a35 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Mon, 19 Feb 2024 21:30:39 +0400 Subject: [PATCH 09/16] =?UTF-8?q?=D0=BF=D0=BE=D0=B4=D0=B3=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=D0=BA=D0=B0=20=D0=BA=20=D0=BF=D1=83=D0=BB=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshopListImplement/Models/Order .cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order .cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order .cs index c49044e..ee69919 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order .cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order .cs @@ -43,12 +43,7 @@ namespace BlacksmithWorkshopListImplement.Models { return; } - Id = model.Id; - ManufactureId = model.ManufactureId; - Count = model.Count; - Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() -- 2.25.1 From c6b12b088418e3eac55a17d832d4654e518d7bb7 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Mon, 19 Feb 2024 21:44:02 +0400 Subject: [PATCH 10/16] =?UTF-8?q?=D0=BF=D0=BE=D0=B4=D0=B3=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=D0=BA=D0=B0=20=D0=BA=20=D0=BF=D1=83=D0=BB=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs index cb21a02..bddda41 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs @@ -51,7 +51,7 @@ menuStrip.Name = "menuStrip"; menuStrip.Size = new Size(1011, 24); menuStrip.TabIndex = 0; - menuStrip.Text = "menuStrip1"; + menuStrip.Text = "Меню"; // // GuidesToolStripMenuItem // -- 2.25.1 From e80baaa4fe1abd6dd8398b95aa81fcedd4b60798 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Mon, 19 Feb 2024 22:52:50 +0400 Subject: [PATCH 11/16] =?UTF-8?q?=D0=BF=D0=BE=D0=B4=D0=B3=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=D0=BA=D0=B0=20=D0=BA=20=D0=BF=D1=83=D0=BB=D1=83=20?= =?UTF-8?q?=D1=873?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlacksmithWorkshop/FormMain.Designer.cs | 362 +++++++++--------- .../BlacksmithWorkshop/FormMain.cs | 332 ++++++++-------- 2 files changed, 347 insertions(+), 347 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs index bddda41..1a721e2 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs @@ -1,189 +1,189 @@ namespace BlacksmithWorkshop { - partial class FormMain - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + partial class FormMain + { + /// + /// 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); - } + /// + /// 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 + #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() - { - menuStrip = new MenuStrip(); - GuidesToolStripMenuItem = new ToolStripMenuItem(); - ComponentsToolStripMenuItem = new ToolStripMenuItem(); - ManufacturesToolStripMenuItem = new ToolStripMenuItem(); - ShopsToolStripMenuItem = new ToolStripMenuItem(); - SupplyToolStripMenuItem = new ToolStripMenuItem(); - dataGridView = new DataGridView(); - buttonCreateOrder = new Button(); - buttonRefresh = new Button(); - buttonIssued = new Button(); - buttonReady = new Button(); - buttonTakeInWork = new Button(); - menuStrip.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // menuStrip - // - menuStrip.Items.AddRange(new ToolStripItem[] { GuidesToolStripMenuItem }); - menuStrip.Location = new Point(0, 0); - menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(1011, 24); - menuStrip.TabIndex = 0; - menuStrip.Text = "Меню"; - // - // GuidesToolStripMenuItem - // - GuidesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, ManufacturesToolStripMenuItem, ShopsToolStripMenuItem, SupplyToolStripMenuItem }); - GuidesToolStripMenuItem.Name = "GuidesToolStripMenuItem"; - GuidesToolStripMenuItem.Size = new Size(94, 20); - GuidesToolStripMenuItem.Text = "Справочники"; - // - // ComponentsToolStripMenuItem - // - ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem"; - ComponentsToolStripMenuItem.Size = new Size(198, 22); - ComponentsToolStripMenuItem.Text = "Компоненты"; - ComponentsToolStripMenuItem.Click += ComponentsStripMenuItem_Click; - // - // ManufacturesToolStripMenuItem - // - ManufacturesToolStripMenuItem.Name = "ManufacturesToolStripMenuItem"; - ManufacturesToolStripMenuItem.Size = new Size(198, 22); - ManufacturesToolStripMenuItem.Text = "Кузнечные изделия"; - ManufacturesToolStripMenuItem.Click += ManufacturesStripMenuItem_Click; - // - // ShopsToolStripMenuItem - // - ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem"; - ShopsToolStripMenuItem.Size = new Size(198, 22); - ShopsToolStripMenuItem.Text = "Магазины"; - ShopsToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; - // - // SupplyToolStripMenuItem - // - SupplyToolStripMenuItem.Name = "SupplyToolStripMenuItem"; - SupplyToolStripMenuItem.Size = new Size(198, 22); - SupplyToolStripMenuItem.Text = "Пополнение магазина"; - SupplyToolStripMenuItem.Click += SupplyToolStripMenuItem_Click; - // - // dataGridView - // - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(0, 23); - dataGridView.Name = "dataGridView"; - dataGridView.RowTemplate.Height = 25; - dataGridView.Size = new Size(847, 427); - dataGridView.TabIndex = 1; - // - // buttonCreateOrder - // - buttonCreateOrder.Location = new Point(853, 38); - buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(148, 31); - buttonCreateOrder.TabIndex = 2; - buttonCreateOrder.Text = "Создать заказ"; - buttonCreateOrder.UseVisualStyleBackColor = true; - buttonCreateOrder.Click += CreateOrderButton_Click; - // - // buttonRefresh - // - buttonRefresh.Location = new Point(853, 186); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(148, 31); - buttonRefresh.TabIndex = 3; - buttonRefresh.Text = "Обновить список"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += RefreshButton_Click; - // - // buttonIssued - // - buttonIssued.Location = new Point(853, 149); - buttonIssued.Name = "buttonIssued"; - buttonIssued.Size = new Size(148, 31); - buttonIssued.TabIndex = 4; - buttonIssued.Text = "Заказ выдан"; - buttonIssued.UseVisualStyleBackColor = true; - buttonIssued.Click += IssuedButton_Click; - // - // buttonReady - // - buttonReady.Location = new Point(853, 112); - buttonReady.Name = "buttonReady"; - buttonReady.Size = new Size(148, 31); - buttonReady.TabIndex = 5; - buttonReady.Text = "Заказ готов"; - buttonReady.UseVisualStyleBackColor = true; - buttonReady.Click += ReadyButton_Click; - // - // buttonTakeInWork - // - buttonTakeInWork.Location = new Point(853, 75); - buttonTakeInWork.Name = "buttonTakeInWork"; - buttonTakeInWork.Size = new Size(148, 31); - buttonTakeInWork.TabIndex = 6; - buttonTakeInWork.Text = "Отдать на выполнение"; - buttonTakeInWork.UseVisualStyleBackColor = true; - buttonTakeInWork.Click += TakeInWorkButton_Click; - // - // FormMain - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1011, 450); - Controls.Add(buttonTakeInWork); - Controls.Add(buttonReady); - Controls.Add(buttonIssued); - Controls.Add(buttonRefresh); - Controls.Add(buttonCreateOrder); - Controls.Add(dataGridView); - Controls.Add(menuStrip); - MainMenuStrip = menuStrip; - Name = "FormMain"; - StartPosition = FormStartPosition.CenterParent; - Text = "Кузница"; - Load += FormMain_Load; - menuStrip.ResumeLayout(false); - menuStrip.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + menuStrip = new MenuStrip(); + GuidesToolStripMenuItem = new ToolStripMenuItem(); + ComponentsToolStripMenuItem = new ToolStripMenuItem(); + ManufacturesToolStripMenuItem = new ToolStripMenuItem(); + ShopsToolStripMenuItem = new ToolStripMenuItem(); + SupplyToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonRefresh = new Button(); + buttonIssued = new Button(); + buttonReady = new Button(); + buttonTakeInWork = new Button(); + menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip + // + menuStrip.Items.AddRange(new ToolStripItem[] { GuidesToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(1011, 24); + menuStrip.TabIndex = 0; + menuStrip.Text = "Меню"; + // + // GuidesToolStripMenuItem + // + GuidesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, ManufacturesToolStripMenuItem, ShopsToolStripMenuItem, SupplyToolStripMenuItem }); + GuidesToolStripMenuItem.Name = "GuidesToolStripMenuItem"; + GuidesToolStripMenuItem.Size = new Size(94, 20); + GuidesToolStripMenuItem.Text = "Справочники"; + // + // ComponentsToolStripMenuItem + // + ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem"; + ComponentsToolStripMenuItem.Size = new Size(198, 22); + ComponentsToolStripMenuItem.Text = "Компоненты"; + ComponentsToolStripMenuItem.Click += ComponentsStripMenuItem_Click; + // + // ManufacturesToolStripMenuItem + // + ManufacturesToolStripMenuItem.Name = "ManufacturesToolStripMenuItem"; + ManufacturesToolStripMenuItem.Size = new Size(198, 22); + ManufacturesToolStripMenuItem.Text = "Кузнечные изделия"; + ManufacturesToolStripMenuItem.Click += ManufacturesStripMenuItem_Click; + // + // ShopsToolStripMenuItem + // + ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem"; + ShopsToolStripMenuItem.Size = new Size(198, 22); + ShopsToolStripMenuItem.Text = "Магазины"; + ShopsToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; + // + // SupplyToolStripMenuItem + // + SupplyToolStripMenuItem.Name = "SupplyToolStripMenuItem"; + SupplyToolStripMenuItem.Size = new Size(198, 22); + SupplyToolStripMenuItem.Text = "Пополнение магазина"; + SupplyToolStripMenuItem.Click += SupplyToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 23); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(847, 427); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(853, 38); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(148, 31); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += CreateOrderButton_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(853, 186); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(148, 31); + buttonRefresh.TabIndex = 3; + buttonRefresh.Text = "Обновить список"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += RefreshButton_Click; + // + // buttonIssued + // + buttonIssued.Location = new Point(853, 149); + buttonIssued.Name = "buttonIssued"; + buttonIssued.Size = new Size(148, 31); + buttonIssued.TabIndex = 4; + buttonIssued.Text = "Заказ выдан"; + buttonIssued.UseVisualStyleBackColor = true; + buttonIssued.Click += IssuedButton_Click; + // + // buttonReady + // + buttonReady.Location = new Point(853, 112); + buttonReady.Name = "buttonReady"; + buttonReady.Size = new Size(148, 31); + buttonReady.TabIndex = 5; + buttonReady.Text = "Заказ готов"; + buttonReady.UseVisualStyleBackColor = true; + buttonReady.Click += ReadyButton_Click; + // + // buttonTakeInWork + // + buttonTakeInWork.Location = new Point(853, 75); + buttonTakeInWork.Name = "buttonTakeInWork"; + buttonTakeInWork.Size = new Size(148, 31); + buttonTakeInWork.TabIndex = 6; + buttonTakeInWork.Text = "Отдать на выполнение"; + buttonTakeInWork.UseVisualStyleBackColor = true; + buttonTakeInWork.Click += TakeInWorkButton_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1011, 450); + Controls.Add(buttonTakeInWork); + Controls.Add(buttonReady); + Controls.Add(buttonIssued); + Controls.Add(buttonRefresh); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Name = "FormMain"; + StartPosition = FormStartPosition.CenterParent; + Text = "Кузница"; + Load += FormMain_Load; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private MenuStrip menuStrip; - private ToolStripMenuItem GuidesToolStripMenuItem; - private ToolStripMenuItem ComponentsToolStripMenuItem; - private ToolStripMenuItem ManufacturesToolStripMenuItem; - private DataGridView dataGridView; - private Button buttonCreateOrder; - private Button buttonRefresh; - private Button buttonIssued; - private Button buttonReady; - private Button buttonTakeInWork; - private ToolStripMenuItem ShopsToolStripMenuItem; - private ToolStripMenuItem SupplyToolStripMenuItem; - } + private MenuStrip menuStrip; + private ToolStripMenuItem GuidesToolStripMenuItem; + private ToolStripMenuItem ComponentsToolStripMenuItem; + private ToolStripMenuItem ManufacturesToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonRefresh; + private Button buttonIssued; + private Button buttonReady; + private Button buttonTakeInWork; + private ToolStripMenuItem ShopsToolStripMenuItem; + private ToolStripMenuItem SupplyToolStripMenuItem; + } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index 60cf34a..bbfa082 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -14,170 +14,170 @@ using System.Windows.Forms; namespace BlacksmithWorkshop { - public partial class FormMain : Form - { - private readonly ILogger _logger; - private readonly IOrderLogic _orderLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic) - { - InitializeComponent(); - _logger = logger; - _orderLogic = orderLogic; - } - private void ComponentsStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } - } - private void FormMain_Load(object sender, EventArgs e) - { - LoadData(); - } - private void LoadData() - { - _logger.LogInformation("Загрузка заказов"); - try - { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["ManufactureId"].Visible = false; - dataGridView.Columns["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка заказов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки заказов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - private void ManufacturesStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormManufactures)); - if (service is FormManufactures form) - { - form.ShowDialog(); - } - } - private void CreateOrderButton_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } - } - private OrderBindingModel CreateBindingModel(int id, bool isDone = false) - { - return new OrderBindingModel - { - Id = id, - ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), - }; - } - private void TakeInWorkButton_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(CreateBindingModel(id)); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } - private void ReadyButton_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", - id); - try - { - var operationResult = _orderLogic.FinishOrder(CreateBindingModel(id)); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void IssuedButton_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", - id); - try - { - var operationResult = _orderLogic.DeliveryOrder(CreateBindingModel(id)); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - _logger.LogInformation("Заказ №{id} выдан", id); - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } - private void RefreshButton_Click(object sender, EventArgs e) - { - LoadData(); - } - private void ShopsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormShops)); - if (service is FormShops form) - { - form.ShowDialog(); - } - } - private void SupplyToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormSupply)); - if (service is FormSupply form) - { - form.ShowDialog(); - } - } - } + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + private void ComponentsStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["ManufactureId"].Visible = false; + dataGridView.Columns["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ManufacturesStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormManufactures)); + if (service is FormManufactures form) + { + form.ShowDialog(); + } + } + private void CreateOrderButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private OrderBindingModel CreateBindingModel(int id, bool isDone = false) + { + return new OrderBindingModel + { + Id = id, + ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }; + } + private void TakeInWorkButton_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ReadyButton_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", + id); + try + { + var operationResult = _orderLogic.FinishOrder(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void IssuedButton_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", + id); + try + { + var operationResult = _orderLogic.DeliveryOrder(CreateBindingModel(id)); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void RefreshButton_Click(object sender, EventArgs e) + { + LoadData(); + } + private void ShopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + private void SupplyToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSupply)); + if (service is FormSupply form) + { + form.ShowDialog(); + } + } + } } -- 2.25.1 From 7482c15d823c4111c9bfe539c57bfe74ec033c07 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Tue, 27 Feb 2024 14:43:19 +0400 Subject: [PATCH 12/16] lab 2 --- .../BlacksmithWorkshopFileImplement.csproj | 14 +++ .../DataFileSingleton.cs | 58 +++++++++++ .../Implements/ComponentStorage.cs | 91 +++++++++++++++++ .../Implements/ManufactureStorage.cs | 91 +++++++++++++++++ .../Implements/OrderStorage.cs | 99 +++++++++++++++++++ .../Models/Component.cs | 64 ++++++++++++ .../Models/Manufacture.cs | 96 ++++++++++++++++++ .../Models/Order.cs | 87 ++++++++++++++++ BlacksmithWorkshop/BlacksmithWorkshop.sln | 14 ++- .../BlacksmithWorkshop.csproj | 1 + .../BlacksmithWorkshop/Program.cs | 2 +- 11 files changed, 612 insertions(+), 5 deletions(-) create mode 100644 BlacksmithWorkshop/BlackcmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj create mode 100644 BlacksmithWorkshop/BlackcmithWorkshopFileImplement/DataFileSingleton.cs create mode 100644 BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/ComponentStorage.cs create mode 100644 BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/ManufactureStorage.cs create mode 100644 BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/OrderStorage.cs create mode 100644 BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Component.cs create mode 100644 BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Manufacture.cs create mode 100644 BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Order.cs diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj new file mode 100644 index 0000000..4b96496 --- /dev/null +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/BlacksmithWorkshopFileImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/DataFileSingleton.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/DataFileSingleton.cs new file mode 100644 index 0000000..b3b3671 --- /dev/null +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/DataFileSingleton.cs @@ -0,0 +1,58 @@ +using BlacksmithWorkshopFileImplement.Models; +using System.Xml.Linq; + +namespace BlackcmithWorkshopFileImplement +{ + internal class DataFileSingleton + { + private static DataFileSingleton? instance; + private readonly string ComponentFileName = "Component.xml"; + private readonly string OrderFileName = "Order.xml"; + private readonly string ManufactureFileName = "Manufacture.xml"; + public List Components { get; private set; } + public List Orders { get; private set; } + public List Manufactures { get; private set; } + public static DataFileSingleton GetInstance() + { + if (instance == null) + { + instance = new DataFileSingleton(); + } + return instance; + } + public void SaveComponents() => SaveData(Components, ComponentFileName, + "Components", x => x.GetXElement); + public void SaveManufactures() => SaveData(Manufactures, ManufactureFileName, + "Manufactures", x => x.GetXElement); + public void SaveOrders() => SaveData(Orders, OrderFileName, + "Orders", x => x.GetXElement); + private DataFileSingleton() + { + Components = LoadData(ComponentFileName, "Component", x => + Component.Create(x)!)!; + Manufactures = LoadData(ManufactureFileName, "Manufacture", x => + Manufacture.Create(x)!)!; + Orders = LoadData(OrderFileName, "Order", x => + Order.Create(x)!)!; + } + private static List? LoadData(string filename, string xmlNodeName, + Func selectFunction) + { + if (File.Exists(filename)) + { + return + XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList(); + } + return new List(); + } + private static void SaveData(List data, string filename, string + xmlNodeName, Func selectFunction) + { + if (data != null) + { + new XDocument(new XElement(xmlNodeName, + data.Select(selectFunction).ToArray())).Save(filename); + } + } + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/ComponentStorage.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..3caaf00 --- /dev/null +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/ComponentStorage.cs @@ -0,0 +1,91 @@ +using BlackcmithWorkshopFileImplement; +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopFileImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataFileSingleton source; + public ComponentStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Components + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(ComponentSearchModel + model) + { + if (string.IsNullOrEmpty(model.ComponentName)) + { + return new(); + } + return source.Components + .Where(x => x.ComponentName.Contains(model.ComponentName)) + .Select(x => x.GetViewModel) + .ToList(); + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + return source.Components + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == + model.ComponentName) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = source.Components.Count > 0 ? source.Components.Max(x => + x.Id) + 1 : 1; + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + source.Components.Add(newComponent); + source.SaveComponents(); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + var component = source.Components.FirstOrDefault(x => x.Id == + model.Id); + if (component == null) + { + return null; + } + component.Update(model); + source.SaveComponents(); + return component.GetViewModel; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + var element = source.Components.FirstOrDefault(x => x.Id == + model.Id); + if (element != null) + { + source.Components.Remove(element); + source.SaveComponents(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/ManufactureStorage.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/ManufactureStorage.cs new file mode 100644 index 0000000..64849ca --- /dev/null +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/ManufactureStorage.cs @@ -0,0 +1,91 @@ +using BlackcmithWorkshopFileImplement; +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopFileImplement.Implements +{ + public class ManufactureStorage : IManufactureStorage + { + private readonly DataFileSingleton source; + public ManufactureStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Manufactures + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(ManufactureSearchModel model) + { + if (string.IsNullOrEmpty(model.ManufactureName)) + { + return new(); + } + return source.Manufactures + .Where(x => x.ManufactureName.Contains(model.ManufactureName)) + .Select(x => x.GetViewModel) + .ToList(); + } + public ManufactureViewModel? GetElement(ManufactureSearchModel model) + { + if (string.IsNullOrEmpty(model.ManufactureName) && !model.Id.HasValue) + { + return null; + } + return source.Manufactures + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ManufactureName) && x.ManufactureName == + model.ManufactureName) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + public ManufactureViewModel? Insert(ManufactureBindingModel model) + { + model.Id = source.Manufactures.Count > 0 ? source.Manufactures.Max(x => + x.Id) + 1 : 1; + var newManufacture = Manufacture.Create(model); + if (newManufacture == null) + { + return null; + } + source.Manufactures.Add(newManufacture); + source.SaveManufactures(); + return newManufacture.GetViewModel; + } + public ManufactureViewModel? Update(ManufactureBindingModel model) + { + var Manufacture = source.Manufactures.FirstOrDefault(x => x.Id == + model.Id); + if (Manufacture == null) + { + return null; + } + Manufacture.Update(model); + source.SaveManufactures(); + return Manufacture.GetViewModel; + } + public ManufactureViewModel? Delete(ManufactureBindingModel model) + { + var Manufacture = source.Manufactures.FirstOrDefault(x => x.Id == + model.Id); + if (Manufacture != null) + { + source.Manufactures.Remove(Manufacture); + source.SaveManufactures(); + return Manufacture.GetViewModel; + } + return null; + } + } +} diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..78d937a --- /dev/null +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/OrderStorage.cs @@ -0,0 +1,99 @@ +using BlackcmithWorkshopFileImplement; +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopFileImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataFileSingleton source; + public OrderStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Orders + .Select(x => AccessManufactureStorage(x.GetViewModel)) + .ToList(); + } + public List GetFilteredList(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + return source.Orders + .Where(x => x.Id == model.Id) + .Select(x => AccessManufactureStorage(x.GetViewModel)) + .ToList(); + } + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + return AccessManufactureStorage(source.Orders.FirstOrDefault( + x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel + ); + } + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + source.Orders.Add(newOrder); + source.SaveOrders(); + return AccessManufactureStorage(newOrder.GetViewModel); + } + public OrderViewModel? Update(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + source.SaveOrders(); + return AccessManufactureStorage(order.GetViewModel); + } + public OrderViewModel? Delete(OrderBindingModel model) + { + var element = source.Orders.FirstOrDefault(x => x.Id == + model.Id); + if (element != null) + { + source.Orders.Remove(element); + source.SaveOrders(); + return AccessManufactureStorage(element.GetViewModel); + } + return null; + } + public OrderViewModel? AccessManufactureStorage(OrderViewModel model) + { + if (model == null) + return null; + foreach (var Manufacture in source.Manufactures) + { + if (Manufacture.Id == model.ManufactureId) + { + model.ManufactureName = Manufacture.ManufactureName; + break; + } + } + return model; + } + } +} diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Component.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Component.cs new file mode 100644 index 0000000..e7a419c --- /dev/null +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Component.cs @@ -0,0 +1,64 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace BlacksmithWorkshopFileImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost, + }; + } + public static Component? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Component() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ComponentName = element.Element("ComponentName")!.Value, + Cost = Convert.ToDouble(element.Element("Cost")!.Value), + }; + } + public void Update(ComponentBindingModel model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + public XElement GetXElement => new("Component", + new XAttribute("Id", Id), + new XElement("ComponentName", ComponentName), + new XElement("Cost", Cost.ToString())); + } +} diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Manufacture.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Manufacture.cs new file mode 100644 index 0000000..7d42aa5 --- /dev/null +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Manufacture.cs @@ -0,0 +1,96 @@ +using BlackcmithWorkshopFileImplement; +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace BlacksmithWorkshopFileImplement.Models +{ + public class Manufacture : IManufactureModel + { + public int Id { get; private set; } + public string ManufactureName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary Components { get; private set; } = new(); + private Dictionary? _ManufactureComponents = null; + public Dictionary ManufactureComponents + { + get + { + if (_ManufactureComponents == null) + { + var source = DataFileSingleton.GetInstance(); + _ManufactureComponents = Components.ToDictionary(x => x.Key, y => + ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, + y.Value)); + } + return _ManufactureComponents; + } + } + public static Manufacture? Create(ManufactureBindingModel model) + { + if (model == null) + { + return null; + } + return new Manufacture() + { + Id = model.Id, + ManufactureName = model.ManufactureName, + Price = model.Price, + Components = model.ManufactureComponents.ToDictionary(x => x.Key, x + => x.Value.Item2) + }; + } + public static Manufacture? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Manufacture() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ManufactureName = element.Element("ManufactureName")!.Value, + Price = Convert.ToDouble(element.Element("Price")!.Value), + Components = + element.Element("ManufactureComponents")!.Elements("ManufactureComponent") + .ToDictionary(x => + Convert.ToInt32(x.Element("Key")?.Value), x => + Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + public void Update(ManufactureBindingModel model) + { + if (model == null) + { + return; + } + ManufactureName = model.ManufactureName; + Price = model.Price; + Components = model.ManufactureComponents.ToDictionary(x => x.Key, x => + x.Value.Item2); + _ManufactureComponents = null; + } + public ManufactureViewModel GetViewModel => new() + { + Id = Id, + ManufactureName = ManufactureName, + Price = Price, + ManufactureComponents = ManufactureComponents + }; + public XElement GetXElement => new("Manufacture", + new XAttribute("Id", Id), + new XElement("ManufactureName", ManufactureName), + new XElement("Price", Price.ToString()), + new XElement("ManufactureComponents", Components.Select(x => + new XElement("ManufactureComponent", + new XElement("Key", x.Key), + new XElement("Value", x.Value))).ToArray())); + } +} diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Order.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Order.cs new file mode 100644 index 0000000..0b0d08e --- /dev/null +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Order.cs @@ -0,0 +1,87 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Enums; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace BlacksmithWorkshopFileImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int ManufactureId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } + public DateTime DateCreate { get; private set; } + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + ManufactureId = model.ManufactureId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } + public static Order? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Order() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ManufactureId = Convert.ToInt32(element.Element("ManufactureId")!.Value), + Count = Convert.ToInt32(element.Element("Count")!.Value), + Sum = Convert.ToDouble(element.Element("Sum")!.Value), + Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value.ToString()), + DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), + DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value) + }; + } + public void Update(OrderBindingModel model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + ManufactureId = ManufactureId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + }; + public XElement GetXElement => new("Order", + new XAttribute("Id", Id), + new XElement("ManufactureId", ManufactureId), + new XElement("Sum", Sum.ToString()), + new XElement("Count", Count), + new XElement("Status", Status.ToString()), + new XElement("DateCreate", DateCreate.ToString()), + new XElement("DateImplement", DateImplement.ToString()) + ); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop.sln b/BlacksmithWorkshop/BlacksmithWorkshop.sln index 408f263..5d4e3e7 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop.sln +++ b/BlacksmithWorkshop/BlacksmithWorkshop.sln @@ -5,13 +5,15 @@ VisualStudioVersion = 17.7.34031.279 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshop", "BlacksmithWorkshop\BlacksmithWorkshop.csproj", "{54575961-6705-47D3-8063-416A45518BED}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopDataModels", "BlacksmithWorkshopDataModels\BlacksmithWorkshopDataModels.csproj", "{96E8CFC7-A9D8-438B-AE8C-184ED25D5AAC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopDataModels", "BlacksmithWorkshopDataModels\BlacksmithWorkshopDataModels.csproj", "{96E8CFC7-A9D8-438B-AE8C-184ED25D5AAC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopContracts", "BlacksmithWorkshopContracts\BlacksmithWorkshopContracts.csproj", "{40A50297-20F6-4F73-834D-0902F6F7965B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopContracts", "BlacksmithWorkshopContracts\BlacksmithWorkshopContracts.csproj", "{40A50297-20F6-4F73-834D-0902F6F7965B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopBusinessLogic", "BlacksmithWorkshopBusinessLogic\BlacksmithWorkshopBusinessLogic.csproj", "{81DD48F2-F58D-4C86-AC0C-74E447366DFA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopBusinessLogic", "BlacksmithWorkshopBusinessLogic\BlacksmithWorkshopBusinessLogic.csproj", "{81DD48F2-F58D-4C86-AC0C-74E447366DFA}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopListImplement", "BlacksmithWorkshopListImplement\BlacksmithWorkshopListImplement.csproj", "{F6B2AA66-2A89-4DEA-AE90-84991C1EE424}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopListImplement", "BlacksmithWorkshopListImplement\BlacksmithWorkshopListImplement.csproj", "{F6B2AA66-2A89-4DEA-AE90-84991C1EE424}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopFileImplement", "BlackcmithWorkshopFileImplement\BlacksmithWorkshopFileImplement.csproj", "{63C0A1A4-FA76-4F7C-8144-A33085F7DF08}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {F6B2AA66-2A89-4DEA-AE90-84991C1EE424}.Debug|Any CPU.Build.0 = Debug|Any CPU {F6B2AA66-2A89-4DEA-AE90-84991C1EE424}.Release|Any CPU.ActiveCfg = Release|Any CPU {F6B2AA66-2A89-4DEA-AE90-84991C1EE424}.Release|Any CPU.Build.0 = Release|Any CPU + {63C0A1A4-FA76-4F7C-8144-A33085F7DF08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {63C0A1A4-FA76-4F7C-8144-A33085F7DF08}.Debug|Any CPU.Build.0 = Debug|Any CPU + {63C0A1A4-FA76-4F7C-8144-A33085F7DF08}.Release|Any CPU.ActiveCfg = Release|Any CPU + {63C0A1A4-FA76-4F7C-8144-A33085F7DF08}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj index 0d78b48..537a10a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshop/BlacksmithWorkshop.csproj @@ -13,6 +13,7 @@ + diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs index 65045db..7769977 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs @@ -1,7 +1,7 @@ using BlacksmithWorkshopBusinessLogic.BusinessLogics; using BlacksmithWorkshopContracts.BusinessLogicsContracts; using BlacksmithWorkshopContracts.StoragesContracts; -using BlacksmithWorkshopListImplement.Implements; +using BlacksmithWorkshopFileImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; -- 2.25.1 From e874cf8f01f028d3b3a515b4836d649d219f3ee1 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Wed, 28 Feb 2024 10:25:23 +0400 Subject: [PATCH 13/16] some minor fixes --- .../BlackcmithWorkshopFileImplement/Implements/OrderStorage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/OrderStorage.cs index 78d937a..d724dc4 100644 --- a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/OrderStorage.cs @@ -72,7 +72,7 @@ namespace BlacksmithWorkshopFileImplement.Implements public OrderViewModel? Delete(OrderBindingModel model) { var element = source.Orders.FirstOrDefault(x => x.Id == - model.Id); + model.Id); if (element != null) { source.Orders.Remove(element); -- 2.25.1 From dd0195a593c38ebb2a04f863ef31a1e96dce1ae5 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Wed, 28 Feb 2024 16:51:41 +0400 Subject: [PATCH 14/16] added logging in ShopLogic.ReplenishManufactures --- .../BusinessLogics/ShopLogic.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs index 02ba054..48e1963 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs @@ -88,17 +88,26 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics { _logger.LogInformation("Try to replenish manufactures. ShopName:{ShopName}. Id:{Id}", model.ShopName, model.Id); if (model == null) - throw new ArgumentNullException(nameof(model)); + { + _logger.LogWarning("Read operation failed"); + throw new ArgumentNullException(nameof(model)); + } ShopViewModel? curModel = ReadElement(model); if (curModel == null) { _logger.LogWarning("Read operation failed"); - return false; + throw new ArgumentNullException(nameof(curModel)); } if (manufacture == null) - throw new ArgumentNullException(nameof(manufacture)); + { + _logger.LogWarning("Read operation failed"); + throw new ArgumentNullException(nameof(manufacture)); + } if (count <= 0) - throw new ArgumentException("Количество должно быть положительным числом"); + { + _logger.LogWarning("Read operation failed"); + throw new ArgumentException("Количество должно быть положительным числом"); + } if (curModel.ShopManufactures.TryGetValue(manufacture.Id, out var pair)) { curModel.ShopManufactures[manufacture.Id] = (pair.Item1, pair.Item2 + count); -- 2.25.1 From c358e0c5c86679593706e21fc94c5021974df99a Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Sat, 9 Mar 2024 21:18:26 +0400 Subject: [PATCH 15/16] lab 1 hard: error correction --- .../BlacksmithWorkshop/FormSupply.Designer.cs | 200 +++++++-------- .../BlacksmithWorkshop/FormSupply.cs | 242 +++++++++--------- 2 files changed, 221 insertions(+), 221 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs index e350ec8..5e2f0fd 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs @@ -1,108 +1,108 @@ namespace BlacksmithWorkshop { - partial class FormSupply - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + partial class FormSupply + { + /// + /// 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); - } + /// + /// 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 + #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(); - ManufactureComboBox = new ComboBox(); - CountTextBox = new TextBox(); - button1 = new Button(); - button2 = new Button(); - SuspendLayout(); - // - // ShopComboBox - // - ShopComboBox.DropDownStyle = ComboBoxStyle.DropDownList; - ShopComboBox.FormattingEnabled = true; - ShopComboBox.Location = new Point(12, 12); - ShopComboBox.Name = "ShopComboBox"; - ShopComboBox.Size = new Size(224, 23); - ShopComboBox.TabIndex = 0; - // - // ManufactureComboBox - // - ManufactureComboBox.DropDownStyle = ComboBoxStyle.DropDownList; - ManufactureComboBox.FormattingEnabled = true; - ManufactureComboBox.Location = new Point(242, 12); - ManufactureComboBox.Name = "ManufactureComboBox"; - ManufactureComboBox.Size = new Size(224, 23); - ManufactureComboBox.TabIndex = 1; - // - // CountTextBox - // - CountTextBox.Location = new Point(472, 12); - CountTextBox.Name = "CountTextBox"; - CountTextBox.Size = new Size(224, 23); - CountTextBox.TabIndex = 2; - // - // button1 - // - button1.Location = new Point(162, 47); - button1.Name = "button1"; - button1.Size = new Size(157, 28); - button1.TabIndex = 3; - button1.Text = "Сохранить"; - button1.UseVisualStyleBackColor = true; - button1.Click += SaveButton_Click; - // - // button2 - // - button2.Location = new Point(394, 47); - button2.Name = "button2"; - button2.Size = new Size(157, 28); - button2.TabIndex = 4; - button2.Text = "Отмена"; - button2.UseVisualStyleBackColor = true; - button2.Click += CancelButton_Click; - // - // FormSupply - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(707, 87); - Controls.Add(button2); - Controls.Add(button1); - Controls.Add(CountTextBox); - Controls.Add(ManufactureComboBox); - Controls.Add(ShopComboBox); - Name = "FormSupply"; - StartPosition = FormStartPosition.CenterParent; - Text = "Пополнение магазина"; - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + ShopComboBox = new ComboBox(); + ManufactureComboBox = new ComboBox(); + CountTextBox = new TextBox(); + buttonSave = new Button(); + buttonCansel = new Button(); + SuspendLayout(); + // + // ShopComboBox + // + ShopComboBox.DropDownStyle = ComboBoxStyle.DropDownList; + ShopComboBox.FormattingEnabled = true; + ShopComboBox.Location = new Point(12, 12); + ShopComboBox.Name = "ShopComboBox"; + ShopComboBox.Size = new Size(224, 23); + ShopComboBox.TabIndex = 0; + // + // ManufactureComboBox + // + ManufactureComboBox.DropDownStyle = ComboBoxStyle.DropDownList; + ManufactureComboBox.FormattingEnabled = true; + ManufactureComboBox.Location = new Point(242, 12); + ManufactureComboBox.Name = "ManufactureComboBox"; + ManufactureComboBox.Size = new Size(224, 23); + ManufactureComboBox.TabIndex = 1; + // + // CountTextBox + // + CountTextBox.Location = new Point(472, 12); + CountTextBox.Name = "CountTextBox"; + CountTextBox.Size = new Size(224, 23); + CountTextBox.TabIndex = 2; + // + // buttonSave + // + buttonSave.Location = new Point(162, 47); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(157, 28); + buttonSave.TabIndex = 3; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += SaveButton_Click; + // + // buttonCansel + // + buttonCansel.Location = new Point(394, 47); + buttonCansel.Name = "buttonCansel"; + buttonCansel.Size = new Size(157, 28); + buttonCansel.TabIndex = 4; + buttonCansel.Text = "Отмена"; + buttonCansel.UseVisualStyleBackColor = true; + buttonCansel.Click += CancelButton_Click; + // + // FormSupply + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(707, 87); + Controls.Add(buttonCansel); + Controls.Add(buttonSave); + Controls.Add(CountTextBox); + Controls.Add(ManufactureComboBox); + Controls.Add(ShopComboBox); + Name = "FormSupply"; + StartPosition = FormStartPosition.CenterParent; + Text = "Пополнение магазина"; + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private ComboBox ShopComboBox; - private ComboBox ManufactureComboBox; - private TextBox CountTextBox; - private Button button1; - private Button button2; - } + private ComboBox ShopComboBox; + private ComboBox ManufactureComboBox; + private TextBox CountTextBox; + private Button buttonSave; + private Button buttonCansel; + } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs index 4288560..9742c1e 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs @@ -14,126 +14,126 @@ using System.Windows.Forms; namespace BlacksmithWorkshop { - public partial class FormSupply : Form - { - private readonly List? _manufactureList; - private readonly List? _shopsList; - IShopLogic _shopLogic; - IManufactureLogic _manufactureLogic; - public int ShopId - { - get - { - return Convert.ToInt32(ShopComboBox.SelectedValue); - } - set - { - ShopComboBox.SelectedValue = value; - } - } - public int ManufactureId - { - get - { - return Convert.ToInt32(ManufactureComboBox.SelectedValue); - } - set - { - ManufactureComboBox.SelectedValue = value; - } - } - public IManufactureModel? ManufactureModel - { - get - { - if (_manufactureList == null) - { - return null; - } - foreach (var elem in _manufactureList) - { - if (elem.Id == ManufactureId) - { - return elem; - } - } - return null; - } - } - public int Count - { - get { return Convert.ToInt32(CountTextBox.Text); } - set { CountTextBox.Text = value.ToString(); } - } - public FormSupply(IManufactureLogic ManufactureLogic, IShopLogic shopLogic) - { - InitializeComponent(); - _shopLogic = shopLogic; - _manufactureLogic = ManufactureLogic; - _manufactureList = ManufactureLogic.ReadList(null); - _shopsList = shopLogic.ReadList(null); - if (_manufactureList != null) - { - ManufactureComboBox.DisplayMember = "ManufactureName"; - ManufactureComboBox.ValueMember = "Id"; - ManufactureComboBox.DataSource = _manufactureList; - ManufactureComboBox.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 (ManufactureComboBox.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.ReplenishManufactures( - new ShopSearchModel() { Id = Convert.ToInt32(ShopComboBox.SelectedValue) }, - _manufactureLogic.ReadElement(new() { Id = Convert.ToInt32(ManufactureComboBox.SelectedValue) }), - count - ); - if (!res) - { - throw new Exception("Ошибка при пополнении. Дополнительная информация в логах"); - } - MessageBox.Show("Пополнение прошло успешно"); - DialogResult = DialogResult.OK; - Close(); + public partial class FormSupply : Form + { + private readonly List? _manufactureList; + private readonly List? _shopsList; + IShopLogic _shopLogic; + IManufactureLogic _manufactureLogic; + public int ShopId + { + get + { + return Convert.ToInt32(ShopComboBox.SelectedValue); + } + set + { + ShopComboBox.SelectedValue = value; + } + } + public int ManufactureId + { + get + { + return Convert.ToInt32(ManufactureComboBox.SelectedValue); + } + set + { + ManufactureComboBox.SelectedValue = value; + } + } + public IManufactureModel? ManufactureModel + { + get + { + if (_manufactureList == null) + { + return null; + } + foreach (var elem in _manufactureList) + { + if (elem.Id == ManufactureId) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(CountTextBox.Text); } + set { CountTextBox.Text = value.ToString(); } + } + public FormSupply(IManufactureLogic ManufactureLogic, IShopLogic shopLogic) + { + InitializeComponent(); + _shopLogic = shopLogic; + _manufactureLogic = ManufactureLogic; + _manufactureList = ManufactureLogic.ReadList(null); + _shopsList = shopLogic.ReadList(null); + if (_manufactureList != null) + { + ManufactureComboBox.DisplayMember = "ManufactureName"; + ManufactureComboBox.ValueMember = "Id"; + ManufactureComboBox.DataSource = _manufactureList; + ManufactureComboBox.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 (ManufactureComboBox.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.ReplenishManufactures( + new ShopSearchModel() { Id = Convert.ToInt32(ShopComboBox.SelectedValue) }, + _manufactureLogic.ReadElement(new() { Id = Convert.ToInt32(ManufactureComboBox.SelectedValue) }), + count + ); + if (!res) + { + throw new Exception("Ошибка при пополнении. Дополнительная информация в логах"); + } + MessageBox.Show("Пополнение прошло успешно"); + DialogResult = DialogResult.OK; + Close(); - } - catch (Exception) - { - MessageBox.Show("Ошибка пополнения"); - return; - } - } - private void CancelButton_Click(object sender, EventArgs e) - { - DialogResult = DialogResult.Cancel; - Close(); - } - } + } + catch (Exception) + { + MessageBox.Show("Ошибка пополнения"); + return; + } + } + private void CancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } } -- 2.25.1 From 05a860995ad4f951933c16b8983e253b75792e8b Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Thu, 14 Mar 2024 18:22:57 +0400 Subject: [PATCH 16/16] revert merge commit --- .../BlacksmithWorkshop/FormMain.Designer.cs | 24 +-- .../BlacksmithWorkshop/FormMain.cs | 16 -- .../BlacksmithWorkshop/FormShop.Designer.cs | 186 ------------------ .../BlacksmithWorkshop/FormShop.cs | 122 ------------ .../BlacksmithWorkshop/FormShop.resx | 132 ------------- .../BlacksmithWorkshop/FormShops.Designer.cs | 114 ----------- .../BlacksmithWorkshop/FormShops.cs | 110 ----------- .../BlacksmithWorkshop/FormShops.resx | 120 ----------- .../BlacksmithWorkshop/FormSupply.Designer.cs | 108 ---------- .../BlacksmithWorkshop/FormSupply.cs | 139 ------------- .../BlacksmithWorkshop/FormSupply.resx | 120 ----------- .../BlacksmithWorkshop/Program.cs | 9 +- .../BusinessLogics/ShopLogic.cs | 161 --------------- .../BindingModels/ShopBindingModel.cs | 18 -- .../BusinessLogicsContracts/IShopLogic.cs | 22 --- .../SearchModels/ShopSearchModel.cs | 14 -- .../StoragesContracts/IShopStorage.cs | 21 -- .../ViewModels/ShopViewModel.cs | 22 --- .../Models/IShopModel.cs | 16 -- .../DataListSingleton.cs | 2 - .../Implements/ShopStorage.cs | 107 ---------- .../Models/Shop.cs | 54 ----- 22 files changed, 5 insertions(+), 1632 deletions(-) delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormShop.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormShop.resx delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormShops.Designer.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormShops.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormShops.resx delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.resx delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ShopBindingModel.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IShopLogic.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ShopSearchModel.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IShopStorage.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ShopViewModel.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IShopModel.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ShopStorage.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Shop.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs index 1a721e2..0e7c108 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs @@ -32,8 +32,6 @@ GuidesToolStripMenuItem = new ToolStripMenuItem(); ComponentsToolStripMenuItem = new ToolStripMenuItem(); ManufacturesToolStripMenuItem = new ToolStripMenuItem(); - ShopsToolStripMenuItem = new ToolStripMenuItem(); - SupplyToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); buttonRefresh = new Button(); @@ -55,7 +53,7 @@ // // GuidesToolStripMenuItem // - GuidesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, ManufacturesToolStripMenuItem, ShopsToolStripMenuItem, SupplyToolStripMenuItem }); + GuidesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, ManufacturesToolStripMenuItem }); GuidesToolStripMenuItem.Name = "GuidesToolStripMenuItem"; GuidesToolStripMenuItem.Size = new Size(94, 20); GuidesToolStripMenuItem.Text = "Справочники"; @@ -63,31 +61,17 @@ // ComponentsToolStripMenuItem // ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem"; - ComponentsToolStripMenuItem.Size = new Size(198, 22); + ComponentsToolStripMenuItem.Size = new Size(181, 22); ComponentsToolStripMenuItem.Text = "Компоненты"; ComponentsToolStripMenuItem.Click += ComponentsStripMenuItem_Click; // // ManufacturesToolStripMenuItem // ManufacturesToolStripMenuItem.Name = "ManufacturesToolStripMenuItem"; - ManufacturesToolStripMenuItem.Size = new Size(198, 22); + ManufacturesToolStripMenuItem.Size = new Size(181, 22); ManufacturesToolStripMenuItem.Text = "Кузнечные изделия"; ManufacturesToolStripMenuItem.Click += ManufacturesStripMenuItem_Click; // - // ShopsToolStripMenuItem - // - ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem"; - ShopsToolStripMenuItem.Size = new Size(198, 22); - ShopsToolStripMenuItem.Text = "Магазины"; - ShopsToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; - // - // SupplyToolStripMenuItem - // - SupplyToolStripMenuItem.Name = "SupplyToolStripMenuItem"; - SupplyToolStripMenuItem.Size = new Size(198, 22); - SupplyToolStripMenuItem.Text = "Пополнение магазина"; - SupplyToolStripMenuItem.Click += SupplyToolStripMenuItem_Click; - // // dataGridView // dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -183,7 +167,5 @@ private Button buttonIssued; private Button buttonReady; private Button buttonTakeInWork; - private ToolStripMenuItem ShopsToolStripMenuItem; - private ToolStripMenuItem SupplyToolStripMenuItem; } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index bbfa082..7174015 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -163,21 +163,5 @@ namespace BlacksmithWorkshop { LoadData(); } - private void ShopsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormShops)); - if (service is FormShops form) - { - form.ShowDialog(); - } - } - private void SupplyToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormSupply)); - if (service is FormSupply form) - { - form.ShowDialog(); - } - } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs deleted file mode 100644 index 1d9d90e..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs +++ /dev/null @@ -1,186 +0,0 @@ -namespace BlacksmithWorkshop -{ - partial class FormShop - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - dataGridView = new DataGridView(); - ColumnId = new DataGridViewTextBoxColumn(); - ColumnName = new DataGridViewTextBoxColumn(); - ColumnPrice = new DataGridViewTextBoxColumn(); - ColumnCount = new DataGridViewTextBoxColumn(); - dateTimePicker = new DateTimePicker(); - labelName = new Label(); - labelAddress = new Label(); - labelDate = new Label(); - textBoxName = new TextBox(); - textBoxAddress = new TextBox(); - buttonSave = new Button(); - buttonCancel = new Button(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // dataGridView - // - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnPrice, ColumnCount }); - dataGridView.Location = new Point(12, 101); - dataGridView.Name = "dataGridView"; - dataGridView.RowTemplate.Height = 25; - dataGridView.Size = new Size(553, 281); - dataGridView.TabIndex = 0; - // - // ColumnId - // - ColumnId.HeaderText = ""; - ColumnId.Name = "ColumnId"; - ColumnId.Visible = false; - // - // ColumnName - // - ColumnName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - ColumnName.HeaderText = "Изделие"; - ColumnName.Name = "ColumnName"; - // - // ColumnPrice - // - ColumnPrice.HeaderText = "Цена"; - ColumnPrice.Name = "ColumnPrice"; - // - // ColumnCount - // - ColumnCount.HeaderText = "Количество"; - ColumnCount.Name = "ColumnCount"; - // - // dateTimePicker - // - dateTimePicker.Location = new Point(150, 63); - dateTimePicker.Name = "dateTimePicker"; - dateTimePicker.Size = new Size(166, 23); - dateTimePicker.TabIndex = 1; - // - // labelName - // - labelName.AutoSize = true; - labelName.Location = new Point(12, 9); - labelName.Name = "labelName"; - labelName.Size = new Size(62, 15); - labelName.TabIndex = 2; - labelName.Text = "Название:"; - // - // labelAddress - // - labelAddress.AutoSize = true; - labelAddress.Location = new Point(12, 38); - labelAddress.Name = "labelAddress"; - labelAddress.Size = new Size(43, 15); - labelAddress.TabIndex = 3; - labelAddress.Text = "Адрес:"; - // - // labelDate - // - labelDate.AutoSize = true; - labelDate.Location = new Point(12, 69); - labelDate.Name = "labelDate"; - labelDate.Size = new Size(90, 15); - labelDate.TabIndex = 4; - labelDate.Text = "Дата открытия:"; - // - // textBoxName - // - textBoxName.Location = new Point(150, 6); - textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(166, 23); - textBoxName.TabIndex = 5; - // - // textBoxAddress - // - textBoxAddress.Location = new Point(150, 35); - textBoxAddress.Name = "textBoxAddress"; - textBoxAddress.Size = new Size(166, 23); - textBoxAddress.TabIndex = 6; - // - // buttonSave - // - buttonSave.Location = new Point(12, 401); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(123, 25); - buttonSave.TabIndex = 7; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += SaveButton_Click; - // - // buttonCancel - // - buttonCancel.Location = new Point(150, 401); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(123, 25); - buttonCancel.TabIndex = 8; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += CancelButton_Click; - // - // FormShop - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(585, 450); - Controls.Add(buttonCancel); - Controls.Add(buttonSave); - Controls.Add(textBoxAddress); - Controls.Add(textBoxName); - Controls.Add(labelDate); - Controls.Add(labelAddress); - Controls.Add(labelName); - Controls.Add(dateTimePicker); - Controls.Add(dataGridView); - Name = "FormShop"; - StartPosition = FormStartPosition.CenterParent; - Text = "Магазин"; - Load += FormShop_Load; - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - PerformLayout(); - } - - #endregion - - private DataGridView dataGridView; - private DateTimePicker dateTimePicker; - private Label labelName; - private Label labelAddress; - private Label labelDate; - private TextBox textBoxName; - private TextBox textBoxAddress; - private DataGridViewTextBoxColumn ColumnId; - private DataGridViewTextBoxColumn ColumnName; - private DataGridViewTextBoxColumn ColumnPrice; - private DataGridViewTextBoxColumn ColumnCount; - private Button buttonSave; - private Button buttonCancel; - } -} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.cs deleted file mode 100644 index 9d551fe..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.cs +++ /dev/null @@ -1,122 +0,0 @@ -using BlacksmithWorkshopContracts.BindingModels; -using BlacksmithWorkshopContracts.BusinessLogicsContracts; -using BlacksmithWorkshopContracts.SearchModels; -using BlacksmithWorkshopDataModels.Models; -using Microsoft.Extensions.Logging; -using Microsoft.VisualBasic.Logging; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace BlacksmithWorkshop -{ - public partial class FormShop : Form - { - private readonly ILogger _logger; - private readonly IShopLogic _logic; - public int? _id; - private Dictionary _manufactures; - public FormShop(ILogger logger, IShopLogic logic) - { - InitializeComponent(); - _logger = logger; - _logic = logic; - _manufactures = new(); - } - private void FormShop_Load(object sender, EventArgs e) - { - if (_id.HasValue) - { - _logger.LogInformation("Загрузка магазина"); - try - { - var shop = _logic.ReadElement(new ShopSearchModel { Id = _id }); - if (shop != null) - { - textBoxName.Text = shop.ShopName; - textBoxAddress.Text = shop.Address; - dateTimePicker.Text = shop.OpeningDate.ToString(); - _manufactures = shop.ShopManufactures; - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки магазина"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } - private void LoadData() - { - _logger.LogInformation("Загрузка товаров магазина"); - try - { - if (_manufactures != null) - { - foreach (var manufactures in _manufactures) - { - dataGridView.Rows.Add(new object[] { manufactures.Key, manufactures.Value.Item1.ManufactureName, - manufactures.Value.Item1.Price, manufactures.Value.Item2 }); - } - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки изделий магазина"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - private void CancelButton_Click(object sender, EventArgs e) - { - DialogResult = DialogResult.Cancel; - Close(); - } - private void SaveButton_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(textBoxName.Text)) - { - MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (string.IsNullOrEmpty(textBoxAddress.Text)) - { - MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - _logger.LogInformation("Сохранение магазина"); - try - { - var model = new ShopBindingModel - { - Id = _id ?? 0, - ShopName = textBoxName.Text, - Address = textBoxAddress.Text, - OpeningDate = dateTimePicker.Value.Date, - ShopManufactures = _manufactures - }; - var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); - DialogResult = DialogResult.OK; - Close(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка сохранения магазина"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.resx deleted file mode 100644 index b0c7c5d..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.resx +++ /dev/null @@ -1,132 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - True - - - True - - - True - - - True - - \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.Designer.cs deleted file mode 100644 index 7755f6d..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.Designer.cs +++ /dev/null @@ -1,114 +0,0 @@ -namespace BlacksmithWorkshop -{ - partial class FormShops - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - dataGridView = new DataGridView(); - buttonAdd = new Button(); - buttonUpdate = new Button(); - buttonDelete = new Button(); - buttonRefresh = new Button(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // dataGridView - // - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(0, 0); - dataGridView.Name = "dataGridView"; - dataGridView.RowTemplate.Height = 25; - dataGridView.Size = new Size(567, 450); - dataGridView.TabIndex = 0; - // - // buttonAdd - // - buttonAdd.Location = new Point(617, 22); - buttonAdd.Name = "buttonAdd"; - buttonAdd.Size = new Size(152, 33); - buttonAdd.TabIndex = 1; - buttonAdd.Text = "Создать"; - buttonAdd.UseVisualStyleBackColor = true; - buttonAdd.Click += AddButton_Click; - // - // buttonUpdate - // - buttonUpdate.Location = new Point(617, 61); - buttonUpdate.Name = "buttonUpdate"; - buttonUpdate.Size = new Size(152, 33); - buttonUpdate.TabIndex = 2; - buttonUpdate.Text = "Изменить"; - buttonUpdate.UseVisualStyleBackColor = true; - buttonUpdate.Click += UpdateButton_Click; - // - // buttonDelete - // - buttonDelete.Location = new Point(617, 100); - buttonDelete.Name = "buttonDelete"; - buttonDelete.Size = new Size(152, 33); - buttonDelete.TabIndex = 3; - buttonDelete.Text = "Удалить"; - buttonDelete.UseVisualStyleBackColor = true; - buttonDelete.Click += DeleteButton_Click; - // - // buttonRefresh - // - buttonRefresh.Location = new Point(617, 139); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(152, 33); - buttonRefresh.TabIndex = 4; - buttonRefresh.Text = "Обновить"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += RefreshButton_Click; - // - // FormShops - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); - Controls.Add(buttonRefresh); - Controls.Add(buttonDelete); - Controls.Add(buttonUpdate); - Controls.Add(buttonAdd); - Controls.Add(dataGridView); - Name = "FormShops"; - StartPosition = FormStartPosition.CenterParent; - Text = "Магазины"; - Load += FormShops_Load; - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - } - - #endregion - - private DataGridView dataGridView; - private Button buttonAdd; - private Button buttonUpdate; - private Button buttonDelete; - private Button buttonRefresh; - } -} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.cs deleted file mode 100644 index e9fcb99..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.cs +++ /dev/null @@ -1,110 +0,0 @@ -using BlacksmithWorkshopContracts.BindingModels; -using BlacksmithWorkshopContracts.BusinessLogicsContracts; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace BlacksmithWorkshop -{ - public partial class FormShops : Form - { - private readonly ILogger _logger; - private readonly IShopLogic _logic; - public FormShops(ILogger logger, IShopLogic logic) - { - InitializeComponent(); - _logger = logger; - _logic = logic; - } - private void LoadData() - { - try - { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["Address"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["OpeningDate"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - dataGridView.Columns["ShopManufactures"].Visible = false; - } - _logger.LogInformation("Загрузка магазинов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки магазинов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - private void FormShops_Load(object sender, EventArgs e) - { - LoadData(); - } - private void AddButton_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormShop)); - if (service is FormShop form) - { - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } - private void UpdateButton_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - var service = Program.ServiceProvider?.GetService(typeof(FormShop)); - if (service is FormShop form) - { - form._id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } - } - private void RefreshButton_Click(object sender, EventArgs e) - { - LoadData(); - } - private void DeleteButton_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _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/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.resx deleted file mode 100644 index af32865..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs deleted file mode 100644 index 5e2f0fd..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs +++ /dev/null @@ -1,108 +0,0 @@ -namespace BlacksmithWorkshop -{ - partial class FormSupply - { - /// - /// 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(); - ManufactureComboBox = new ComboBox(); - CountTextBox = new TextBox(); - buttonSave = new Button(); - buttonCansel = new Button(); - SuspendLayout(); - // - // ShopComboBox - // - ShopComboBox.DropDownStyle = ComboBoxStyle.DropDownList; - ShopComboBox.FormattingEnabled = true; - ShopComboBox.Location = new Point(12, 12); - ShopComboBox.Name = "ShopComboBox"; - ShopComboBox.Size = new Size(224, 23); - ShopComboBox.TabIndex = 0; - // - // ManufactureComboBox - // - ManufactureComboBox.DropDownStyle = ComboBoxStyle.DropDownList; - ManufactureComboBox.FormattingEnabled = true; - ManufactureComboBox.Location = new Point(242, 12); - ManufactureComboBox.Name = "ManufactureComboBox"; - ManufactureComboBox.Size = new Size(224, 23); - ManufactureComboBox.TabIndex = 1; - // - // CountTextBox - // - CountTextBox.Location = new Point(472, 12); - CountTextBox.Name = "CountTextBox"; - CountTextBox.Size = new Size(224, 23); - CountTextBox.TabIndex = 2; - // - // buttonSave - // - buttonSave.Location = new Point(162, 47); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(157, 28); - buttonSave.TabIndex = 3; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += SaveButton_Click; - // - // buttonCansel - // - buttonCansel.Location = new Point(394, 47); - buttonCansel.Name = "buttonCansel"; - buttonCansel.Size = new Size(157, 28); - buttonCansel.TabIndex = 4; - buttonCansel.Text = "Отмена"; - buttonCansel.UseVisualStyleBackColor = true; - buttonCansel.Click += CancelButton_Click; - // - // FormSupply - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(707, 87); - Controls.Add(buttonCansel); - Controls.Add(buttonSave); - Controls.Add(CountTextBox); - Controls.Add(ManufactureComboBox); - Controls.Add(ShopComboBox); - Name = "FormSupply"; - StartPosition = FormStartPosition.CenterParent; - Text = "Пополнение магазина"; - ResumeLayout(false); - PerformLayout(); - } - - #endregion - - private ComboBox ShopComboBox; - private ComboBox ManufactureComboBox; - private TextBox CountTextBox; - private Button buttonSave; - private Button buttonCansel; - } -} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs deleted file mode 100644 index 9742c1e..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs +++ /dev/null @@ -1,139 +0,0 @@ -using BlacksmithWorkshopContracts.BusinessLogicsContracts; -using BlacksmithWorkshopContracts.SearchModels; -using BlacksmithWorkshopContracts.ViewModels; -using BlacksmithWorkshopDataModels.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 BlacksmithWorkshop -{ - public partial class FormSupply : Form - { - private readonly List? _manufactureList; - private readonly List? _shopsList; - IShopLogic _shopLogic; - IManufactureLogic _manufactureLogic; - public int ShopId - { - get - { - return Convert.ToInt32(ShopComboBox.SelectedValue); - } - set - { - ShopComboBox.SelectedValue = value; - } - } - public int ManufactureId - { - get - { - return Convert.ToInt32(ManufactureComboBox.SelectedValue); - } - set - { - ManufactureComboBox.SelectedValue = value; - } - } - public IManufactureModel? ManufactureModel - { - get - { - if (_manufactureList == null) - { - return null; - } - foreach (var elem in _manufactureList) - { - if (elem.Id == ManufactureId) - { - return elem; - } - } - return null; - } - } - public int Count - { - get { return Convert.ToInt32(CountTextBox.Text); } - set { CountTextBox.Text = value.ToString(); } - } - public FormSupply(IManufactureLogic ManufactureLogic, IShopLogic shopLogic) - { - InitializeComponent(); - _shopLogic = shopLogic; - _manufactureLogic = ManufactureLogic; - _manufactureList = ManufactureLogic.ReadList(null); - _shopsList = shopLogic.ReadList(null); - if (_manufactureList != null) - { - ManufactureComboBox.DisplayMember = "ManufactureName"; - ManufactureComboBox.ValueMember = "Id"; - ManufactureComboBox.DataSource = _manufactureList; - ManufactureComboBox.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 (ManufactureComboBox.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.ReplenishManufactures( - new ShopSearchModel() { Id = Convert.ToInt32(ShopComboBox.SelectedValue) }, - _manufactureLogic.ReadElement(new() { Id = Convert.ToInt32(ManufactureComboBox.SelectedValue) }), - count - ); - if (!res) - { - throw new Exception("Ошибка при пополнении. Дополнительная информация в логах"); - } - MessageBox.Show("Пополнение прошло успешно"); - DialogResult = DialogResult.OK; - Close(); - - } - catch (Exception) - { - MessageBox.Show("Ошибка пополнения"); - return; - } - } - private void CancelButton_Click(object sender, EventArgs e) - { - DialogResult = DialogResult.Cancel; - Close(); - } - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.resx deleted file mode 100644 index af32865..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs index 46eb659..7769977 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs @@ -40,18 +40,13 @@ namespace BlacksmithWorkshop services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - } + } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs deleted file mode 100644 index 48e1963..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs +++ /dev/null @@ -1,161 +0,0 @@ -using BlacksmithWorkshopContracts.BindingModels; -using BlacksmithWorkshopContracts.BusinessLogicsContracts; -using BlacksmithWorkshopContracts.SearchModels; -using BlacksmithWorkshopContracts.StoragesContracts; -using BlacksmithWorkshopContracts.ViewModels; -using BlacksmithWorkshopDataModels.Models; -using Microsoft.Extensions.Logging; -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; - -namespace BlacksmithWorkshopBusinessLogic.BusinessLogics -{ - 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:{ShopName}. Id:{ Id}", model?.ShopName, model?.Id); - var list = model == null ? _shopStorage.GetFullList() : - _shopStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } - public ShopViewModel? ReadElement(ShopSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id); - var element = _shopStorage.GetElement(model); - if (element == null) - { - _logger.LogWarning("ReadElement element not found"); - return null; - } - _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); - return element; - } - public bool Create(ShopBindingModel model) - { - CheckModel(model); - if (_shopStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } - public bool Update(ShopBindingModel model) - { - CheckModel(model); - if (_shopStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - public bool Delete(ShopBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_shopStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; - } - public bool ReplenishManufactures(ShopSearchModel model, IManufactureModel manufacture, int count) - { - _logger.LogInformation("Try to replenish manufactures. ShopName:{ShopName}. Id:{Id}", model.ShopName, model.Id); - if (model == null) - { - _logger.LogWarning("Read operation failed"); - throw new ArgumentNullException(nameof(model)); - } - ShopViewModel? curModel = ReadElement(model); - if (curModel == null) - { - _logger.LogWarning("Read operation failed"); - throw new ArgumentNullException(nameof(curModel)); - } - if (manufacture == null) - { - _logger.LogWarning("Read operation failed"); - throw new ArgumentNullException(nameof(manufacture)); - } - if (count <= 0) - { - _logger.LogWarning("Read operation failed"); - throw new ArgumentException("Количество должно быть положительным числом"); - } - if (curModel.ShopManufactures.TryGetValue(manufacture.Id, out var pair)) - { - curModel.ShopManufactures[manufacture.Id] = (pair.Item1, pair.Item2 + count); - } - else - { - curModel.ShopManufactures.Add(manufacture.Id, (manufacture, count)); - } - Update(new() - { - Id = curModel.Id, - ShopName = curModel.ShopName, - OpeningDate = curModel.OpeningDate, - Address = curModel.Address, - ShopManufactures = curModel.ShopManufactures, - }); - _logger.LogInformation("Success. ManufactureName:{ManufactureName}. Id:{Id}. Replenish:{count}", - manufacture.ManufactureName, manufacture.Id, count); - return true; - } - private void CheckModel(ShopBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (string.IsNullOrEmpty(model.ShopName)) - { - throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName)); - } - if (string.IsNullOrEmpty(model.Address)) - { - throw new ArgumentNullException("Нет адреса магазина", nameof(model.Address)); - } - _logger.LogInformation("Shop. ShopName:{ShopName}.Address:{Address}. DateOpen:{DateOpen}. Id: { Id}", - model.ShopName, model.Address, model.OpeningDate, model.Id); - var element = _shopStorage.GetElement(new ShopSearchModel - { - ShopName = model.ShopName - }); - if (element != null && element.Id != model.Id) - { - throw new InvalidOperationException("Магазин с таким названием уже есть"); - } - } - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ShopBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ShopBindingModel.cs deleted file mode 100644 index 79ff366..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ShopBindingModel.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BlacksmithWorkshopDataModels.Models; - -namespace BlacksmithWorkshopContracts.BindingModels -{ - public class ShopBindingModel : IShopModel - { - public int Id { get; set; } - public string ShopName { get; set; } = string.Empty; - public string Address { get; set; } = string.Empty; - public DateTime OpeningDate { get; set; } - public Dictionary ShopManufactures { get; set; } = new(); - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IShopLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IShopLogic.cs deleted file mode 100644 index 5b6358d..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IShopLogic.cs +++ /dev/null @@ -1,22 +0,0 @@ -using BlacksmithWorkshopContracts.BindingModels; -using BlacksmithWorkshopContracts.SearchModels; -using BlacksmithWorkshopContracts.ViewModels; -using BlacksmithWorkshopDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlacksmithWorkshopContracts.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 ReplenishManufactures(ShopSearchModel shop, IManufactureModel manufacture, int count); - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ShopSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ShopSearchModel.cs deleted file mode 100644 index 64a9f62..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ShopSearchModel.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlacksmithWorkshopContracts.SearchModels -{ - public class ShopSearchModel - { - public int? Id { get; set; } - public string? ShopName { get; set; } - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IShopStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IShopStorage.cs deleted file mode 100644 index c36afa4..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IShopStorage.cs +++ /dev/null @@ -1,21 +0,0 @@ -using BlacksmithWorkshopContracts.BindingModels; -using BlacksmithWorkshopContracts.SearchModels; -using BlacksmithWorkshopContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlacksmithWorkshopContracts.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); - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ShopViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ShopViewModel.cs deleted file mode 100644 index 1a17384..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ShopViewModel.cs +++ /dev/null @@ -1,22 +0,0 @@ -using BlacksmithWorkshopDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlacksmithWorkshopContracts.ViewModels -{ - public class ShopViewModel : IShopModel - { - public int Id { get; set; } - [DisplayName("Название магазина")] - public string ShopName { get; set; } = string.Empty; - [DisplayName("Адрес магазина")] - public string Address { get; set; } = string.Empty; - [DisplayName("Дата открытия")] - public DateTime OpeningDate { get; set; } - public Dictionary ShopManufactures { get; set; } = new(); - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IShopModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IShopModel.cs deleted file mode 100644 index 1e742af..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IShopModel.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlacksmithWorkshopDataModels.Models -{ - public interface IShopModel : IId - { - string ShopName { get; } - string Address { get; } - DateTime OpeningDate { get; } - Dictionary ShopManufactures { get; } - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs index 32ab5b6..71c00d4 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs @@ -13,13 +13,11 @@ namespace BlacksmithWorkshopListImplement public List Components { get; set; } public List Orders { get; set; } public List Manufactures { get; set; } - public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Manufactures = new List(); - Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ShopStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ShopStorage.cs deleted file mode 100644 index eb418a9..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ShopStorage.cs +++ /dev/null @@ -1,107 +0,0 @@ -using BlacksmithWorkshopContracts.BindingModels; -using BlacksmithWorkshopContracts.SearchModels; -using BlacksmithWorkshopContracts.StoragesContracts; -using BlacksmithWorkshopContracts.ViewModels; -using BlacksmithWorkshopListImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlacksmithWorkshopListImplement.Implements -{ - public class ShopStorage : IShopStorage - { - private readonly DataListSingleton _source; - public ShopStorage() - { - _source = DataListSingleton.GetInstance(); - } - public List GetFullList() - { - List result = new List(); - foreach(var Shop in _source.Shops) - { - result.Add(Shop.GetViewModel); - } - return result; - } - public List GetFilteredList(ShopSearchModel model) - { - List result = new(); - if (string.IsNullOrEmpty(model.ShopName)) - { - return result; - } - foreach(var Shop in _source.Shops) - { - if (Shop.ShopName.Contains(model.ShopName)) - { - result.Add(Shop.GetViewModel); - } - } - return result; - } - public ShopViewModel? GetElement(ShopSearchModel model) - { - if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) - { - return null; - } - foreach(var Shop in _source.Shops) - { - if ((!string.IsNullOrEmpty(model.ShopName) && - Shop.ShopName == model.ShopName) || - (model.Id.HasValue && Shop.Id == model.Id)) - { - return Shop.GetViewModel; - } - } - return null; - } - public ShopViewModel? Insert(ShopBindingModel model) - { - model.Id = 1; - foreach(var Shop in _source.Shops) - { - if (Shop.Id >= model.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; - } - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Shop.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Shop.cs deleted file mode 100644 index 4c761e4..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Shop.cs +++ /dev/null @@ -1,54 +0,0 @@ -using BlacksmithWorkshopContracts.BindingModels; -using BlacksmithWorkshopContracts.ViewModels; -using BlacksmithWorkshopDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BlacksmithWorkshopListImplement.Models -{ - public class Shop : IShopModel - { - public int Id { get; private set; } - public string ShopName { get; private set; } = string.Empty; - public string Address { get; private set; } = string.Empty; - public DateTime OpeningDate { get; private set; } - public Dictionary ShopManufactures { get; private set; } = new(); - public static Shop? Create(ShopBindingModel? model) - { - if (model == null) - { - return null; - } - return new Shop() - { - Id = model.Id, - ShopName = model.ShopName, - Address = model.Address, - OpeningDate = model.OpeningDate, - ShopManufactures = model.ShopManufactures - }; - } - public void Update(ShopBindingModel? model) - { - if (model == null) - { - return; - } - ShopName = model.ShopName; - Address = model.Address; - OpeningDate = model.OpeningDate; - ShopManufactures = model.ShopManufactures; - } - public ShopViewModel GetViewModel => new ShopViewModel() - { - Id = Id, - ShopName = ShopName, - Address = Address, - OpeningDate = OpeningDate, - ShopManufactures = ShopManufactures - }; - } -} -- 2.25.1