From cfdeca8b930af0eac22d4139177cde2593795126 Mon Sep 17 00:00:00 2001 From: Danil Markov Date: Tue, 28 Mar 2023 10:24:47 +0400 Subject: [PATCH 1/3] done --- .../BusinessLogics/ShopLogic.cs | 152 ++++++++++++++ .../BindingModels/ShopBindingModel.cs | 18 ++ .../BusinessLogicsContracts/IShopLogic.cs | 22 ++ .../SearchModels/ShopSearchModel.cs | 14 ++ .../StoragesContracts/IShopStorage.cs | 21 ++ .../ViewModels/ShopViewModel.cs | 24 +++ LawFirm/LawFirmDataModel/Models/IShopModel.cs | 13 ++ .../LawFirmListImplement/DataListSingleton.cs | 3 + .../Implements/ShopStorage.cs | 112 +++++++++++ LawFirm/LawFirmListImplement/Models/Shop.cs | 58 ++++++ .../LawFirmView/FormAddDocument.Designer.cs | 151 ++++++++++++++ LawFirm/LawFirmView/FormAddDocument.cs | 108 ++++++++++ LawFirm/LawFirmView/FormAddDocument.resx | 60 ++++++ LawFirm/LawFirmView/FormMain.Designer.cs | 25 ++- LawFirm/LawFirmView/FormMain.cs | 19 ++ LawFirm/LawFirmView/FormShop.Designer.cs | 188 ++++++++++++++++++ LawFirm/LawFirmView/FormShop.cs | 122 ++++++++++++ LawFirm/LawFirmView/FormShop.resx | 69 +++++++ LawFirm/LawFirmView/FormShops.Designer.cs | 123 ++++++++++++ LawFirm/LawFirmView/FormShops.cs | 104 ++++++++++ LawFirm/LawFirmView/FormShops.resx | 60 ++++++ LawFirm/LawFirmView/Program.cs | 5 + 22 files changed, 1470 insertions(+), 1 deletion(-) create mode 100644 LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs create mode 100644 LawFirm/LawFirmContracts/BindingModels/ShopBindingModel.cs create mode 100644 LawFirm/LawFirmContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 LawFirm/LawFirmContracts/SearchModels/ShopSearchModel.cs create mode 100644 LawFirm/LawFirmContracts/StoragesContracts/IShopStorage.cs create mode 100644 LawFirm/LawFirmContracts/ViewModels/ShopViewModel.cs create mode 100644 LawFirm/LawFirmDataModel/Models/IShopModel.cs create mode 100644 LawFirm/LawFirmListImplement/Implements/ShopStorage.cs create mode 100644 LawFirm/LawFirmListImplement/Models/Shop.cs create mode 100644 LawFirm/LawFirmView/FormAddDocument.Designer.cs create mode 100644 LawFirm/LawFirmView/FormAddDocument.cs create mode 100644 LawFirm/LawFirmView/FormAddDocument.resx create mode 100644 LawFirm/LawFirmView/FormShop.Designer.cs create mode 100644 LawFirm/LawFirmView/FormShop.cs create mode 100644 LawFirm/LawFirmView/FormShop.resx create mode 100644 LawFirm/LawFirmView/FormShops.Designer.cs create mode 100644 LawFirm/LawFirmView/FormShops.cs create mode 100644 LawFirm/LawFirmView/FormShops.resx diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs new file mode 100644 index 0000000..e07d5bb --- /dev/null +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs @@ -0,0 +1,152 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicsContracts; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StoragesContracts; +using LawFirmContracts.ViewModels; +using LawFirmDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmBusinessLogic.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; + } + 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)); + } + _logger.LogInformation("Shop. ShopName:{0}. Address:{1}. Id:{2}", + model.ShopName, model.Address, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + ShopName = model.ShopName + }); + if (element != null && element.Id != model.Id && element.ShopName == model.ShopName) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + + public bool AddDocument(ShopSearchModel model, IDocumentModel ship, int count) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (count <= 0) + { + throw new ArgumentException("Количество поездок должно быть больше 0", nameof(count)); + } + _logger.LogInformation("AddDocument. ShopName:{ShopName}. Id:{Id}", model.ShopName, model.Id); + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("AddDocument element not found"); + return false; + } + _logger.LogInformation("AddDocument find. Id:{Id}", element.Id); + + if (element.ShopDocuments.TryGetValue(ship.Id, out var pair)) + { + element.ShopDocuments[ship.Id] = (ship, count + pair.Item2); + _logger.LogInformation("AddDocument. Added {count} {ship} to '{ShopName}' shop", + count, ship.DocumentName, element.ShopName); + } + else + { + element.ShopDocuments[ship.Id] = (ship, count); + _logger.LogInformation("AddDocument. Added {count} new ship {ship} to '{ShopName}' shop", + count, ship.DocumentName, element.ShopName); + } + _shopStorage.Update(new() + { + Id = element.Id, + Address = element.Address, + ShopName = element.ShopName, + DateOpen = element.DateOpen, + ShopDocuments = element.ShopDocuments + }); + return true; + } + } +} diff --git a/LawFirm/LawFirmContracts/BindingModels/ShopBindingModel.cs b/LawFirm/LawFirmContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..4eff95f --- /dev/null +++ b/LawFirm/LawFirmContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,18 @@ +using LawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public string ShopName { get; set; } = string.Empty; + public string Address { get; set; } = string.Empty; + public DateTime DateOpen { get; set; } = DateTime.Now; + public Dictionary ShopDocuments { get; set; } = new(); + public int Id { get; set; } + } +} diff --git a/LawFirm/LawFirmContracts/BusinessLogicsContracts/IShopLogic.cs b/LawFirm/LawFirmContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..a4c15d2 --- /dev/null +++ b/LawFirm/LawFirmContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,22 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; +using LawFirmContracts.ViewModels; +using LawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmContracts.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 AddDocument(ShopSearchModel model, IDocumentModel document, int count); + } +} diff --git a/LawFirm/LawFirmContracts/SearchModels/ShopSearchModel.cs b/LawFirm/LawFirmContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..fa7522f --- /dev/null +++ b/LawFirm/LawFirmContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? ShopName { get; set; } + } +} diff --git a/LawFirm/LawFirmContracts/StoragesContracts/IShopStorage.cs b/LawFirm/LawFirmContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..0bc1574 --- /dev/null +++ b/LawFirm/LawFirmContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,21 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; +using LawFirmContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmContracts.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/LawFirm/LawFirmContracts/ViewModels/ShopViewModel.cs b/LawFirm/LawFirmContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..9334e2d --- /dev/null +++ b/LawFirm/LawFirmContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,24 @@ +using LawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + [DisplayName("Название магазина")] + public string ShopName { get; set; } = string.Empty; + + [DisplayName("Адрес магазина")] + public string Address { get; set; } = string.Empty; + + [DisplayName("Дата открытия")] + public DateTime DateOpen { get; set; } = DateTime.Now; + public Dictionary ShopDocuments { get; set; } = new(); + public int Id { get; set; } + } +} diff --git a/LawFirm/LawFirmDataModel/Models/IShopModel.cs b/LawFirm/LawFirmDataModel/Models/IShopModel.cs new file mode 100644 index 0000000..783e810 --- /dev/null +++ b/LawFirm/LawFirmDataModel/Models/IShopModel.cs @@ -0,0 +1,13 @@ +using LawFirmDataModels; +using LawFirmDataModels.Models; + +namespace LawFirmDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + string Address { get; } + DateTime DateOpen { get; } + Dictionary ShopDocuments { get; } + } +} diff --git a/LawFirm/LawFirmListImplement/DataListSingleton.cs b/LawFirm/LawFirmListImplement/DataListSingleton.cs index 52f5fb5..05d71c4 100644 --- a/LawFirm/LawFirmListImplement/DataListSingleton.cs +++ b/LawFirm/LawFirmListImplement/DataListSingleton.cs @@ -8,11 +8,14 @@ namespace LawFirmListImplement public List Blanks { get; set; } public List Orders { get; set; } public List Documents { get; set; } + public List Shops { get; set; } + private DataListSingleton() { Blanks = new List(); Orders = new List(); Documents = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/LawFirm/LawFirmListImplement/Implements/ShopStorage.cs b/LawFirm/LawFirmListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..dd23b9e --- /dev/null +++ b/LawFirm/LawFirmListImplement/Implements/ShopStorage.cs @@ -0,0 +1,112 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StoragesContracts; +using LawFirmContracts.ViewModels; +using LawFirmListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + + 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 List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ShopName)) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.ShopName.Contains(model.ShopName)) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = 1; + foreach (var shop in _source.Shops) + { + if (model.Id <= shop.Id) + { + model.Id = shop.Id + 1; + } + } + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + _source.Shops.Add(newShop); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + foreach (var shop in _source.Shops) + { + if (shop.Id == model.Id) + { + shop.Update(model); + return shop.GetViewModel; + } + } + return null; + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + for (int i = 0; i < _source.Shops.Count; ++i) + { + if (_source.Shops[i].Id == model.Id) + { + var element = _source.Shops[i]; + _source.Shops.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/LawFirm/LawFirmListImplement/Models/Shop.cs b/LawFirm/LawFirmListImplement/Models/Shop.cs new file mode 100644 index 0000000..4b18e0d --- /dev/null +++ b/LawFirm/LawFirmListImplement/Models/Shop.cs @@ -0,0 +1,58 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.ViewModels; +using LawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmListImplement.Models +{ + public class Shop : IShopModel + { + public string ShopName { get; set; } = string.Empty; + + public string Address { get; set; } = string.Empty; + public DateTime DateOpen { get; set; } + public int Id { get; set; } + public Dictionary ShopDocuments { get; private set; } = new Dictionary(); + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpen = model.DateOpen, + ShopDocuments = model.ShopDocuments + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpen = model.DateOpen; + ShopDocuments = model.ShopDocuments; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpen = DateOpen, + ShopDocuments = ShopDocuments + }; + } +} diff --git a/LawFirm/LawFirmView/FormAddDocument.Designer.cs b/LawFirm/LawFirmView/FormAddDocument.Designer.cs new file mode 100644 index 0000000..c2e9891 --- /dev/null +++ b/LawFirm/LawFirmView/FormAddDocument.Designer.cs @@ -0,0 +1,151 @@ +namespace LawFirmView +{ + partial class FormAddDocument + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelShop = new System.Windows.Forms.Label(); + this.labelDocument = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.comboBoxDocument = new System.Windows.Forms.ComboBox(); + this.numericUpDownCount = new System.Windows.Forms.NumericUpDown(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit(); + this.SuspendLayout(); + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(10, 23); + this.labelShop.Name = "labelShop"; + this.labelShop.Size = new System.Drawing.Size(54, 15); + this.labelShop.TabIndex = 0; + this.labelShop.Text = "Магазин"; + // + // labelDocument + // + this.labelDocument.AutoSize = true; + this.labelDocument.Location = new System.Drawing.Point(10, 57); + this.labelDocument.Name = "labelDocument"; + this.labelDocument.Size = new System.Drawing.Size(61, 15); + this.labelDocument.TabIndex = 1; + this.labelDocument.Text = "Документ"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(10, 95); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(72, 15); + this.labelCount.TabIndex = 2; + this.labelCount.Text = "Количество"; + // + // comboBoxShop + // + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(97, 23); + this.comboBoxShop.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(323, 23); + this.comboBoxShop.TabIndex = 3; + // + // comboBoxDocument + // + this.comboBoxDocument.FormattingEnabled = true; + this.comboBoxDocument.Location = new System.Drawing.Point(97, 57); + this.comboBoxDocument.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.comboBoxDocument.Name = "comboBoxDocument"; + this.comboBoxDocument.Size = new System.Drawing.Size(323, 23); + this.comboBoxDocument.TabIndex = 4; + // + // numericUpDownCount + // + this.numericUpDownCount.Location = new System.Drawing.Point(97, 90); + this.numericUpDownCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.numericUpDownCount.Name = "numericUpDownCount"; + this.numericUpDownCount.Size = new System.Drawing.Size(323, 23); + this.numericUpDownCount.TabIndex = 5; + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(244, 125); + this.ButtonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(82, 22); + this.ButtonSave.TabIndex = 6; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(338, 125); + this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(82, 22); + this.ButtonCancel.TabIndex = 7; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormAddDocument + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(430, 155); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.numericUpDownCount); + this.Controls.Add(this.comboBoxDocument); + this.Controls.Add(this.comboBoxShop); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelDocument); + this.Controls.Add(this.labelShop); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormAddDocument"; + this.Text = "Добавление документа"; + this.Load += new System.EventHandler(this.FormAddDocument_Load); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelShop; + private Label labelDocument; + private Label labelCount; + private ComboBox comboBoxShop; + private ComboBox comboBoxDocument; + private NumericUpDown numericUpDownCount; + private Button ButtonSave; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormAddDocument.cs b/LawFirm/LawFirmView/FormAddDocument.cs new file mode 100644 index 0000000..27add3d --- /dev/null +++ b/LawFirm/LawFirmView/FormAddDocument.cs @@ -0,0 +1,108 @@ +using Microsoft.Extensions.Logging; +using LawFirmContracts.BusinessLogicsContracts; +using LawFirmContracts.SearchModels; + +namespace LawFirmView +{ + public partial class FormAddDocument : Form + { + private readonly ILogger _logger; + private readonly IDocumentLogic _logicDocument; + private readonly IShopLogic _logicShop; + public FormAddDocument(ILogger logger, IDocumentLogic logicDocument, IShopLogic logicShop) + { + InitializeComponent(); + _logger = logger; + _logicDocument = logicDocument; + _logicShop = logicShop; + } + + private void FormAddDocument_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка списка кораблей для пополнения"); + try + { + var list = _logicDocument.ReadList(null); + if (list != null) + { + comboBoxDocument.DisplayMember = "DocumentName"; + comboBoxDocument.ValueMember = "Id"; + comboBoxDocument.DataSource = list; + comboBoxDocument.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка кораблей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + _logger.LogInformation("Загрузка списка магазинов для пополнения"); + try + { + var list = _logicShop.ReadList(null); + if (list != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = list; + comboBoxShop.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(numericUpDownCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxDocument.SelectedValue == null) + { + MessageBox.Show("Выберите документ", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Пополнение магазина"); + try + { + var operationResult = _logicShop.AddDocument(new ShopSearchModel + { + Id = Convert.ToInt32(comboBoxShop.SelectedValue) + }, + _logicDocument.ReadElement(new DocumentSearchModel() + { + Id = Convert.ToInt32(comboBoxDocument.SelectedValue) + })!, Convert.ToInt32(numericUpDownCount.Text)); + if (!operationResult) + { + throw new Exception("Ошибка при пополнении магазина. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/LawFirm/LawFirmView/FormAddDocument.resx b/LawFirm/LawFirmView/FormAddDocument.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/LawFirm/LawFirmView/FormAddDocument.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/LawFirm/LawFirmView/FormMain.Designer.cs b/LawFirm/LawFirmView/FormMain.Designer.cs index 66ad50d..3738201 100644 --- a/LawFirm/LawFirmView/FormMain.Designer.cs +++ b/LawFirm/LawFirmView/FormMain.Designer.cs @@ -32,12 +32,14 @@ this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.бланкиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.документыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); this.buttonOrderReady = new System.Windows.Forms.Button(); this.buttonIssuedOrder = new System.Windows.Forms.Button(); this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonAddDocument = new System.Windows.Forms.Button(); this.menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -56,7 +58,8 @@ // this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.бланкиToolStripMenuItem, - this.документыToolStripMenuItem}); + this.документыToolStripMenuItem, + this.магазиныToolStripMenuItem}); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); this.справочникиToolStripMenuItem.Text = "Справочники"; @@ -75,6 +78,13 @@ this.документыToolStripMenuItem.Text = "Документы"; this.документыToolStripMenuItem.Click += new System.EventHandler(this.DocumentsToolStripMenuItem_Click); // + // магазиныToolStripMenuItem + // + this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.магазиныToolStripMenuItem.Text = "Магазины"; + this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.ShopToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.AllowUserToAddRows = false; @@ -138,11 +148,22 @@ this.buttonUpdate.UseVisualStyleBackColor = true; this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); // + // buttonAddDocument + // + this.buttonAddDocument.Location = new System.Drawing.Point(605, 172); + this.buttonAddDocument.Name = "buttonAddDocument"; + this.buttonAddDocument.Size = new System.Drawing.Size(168, 23); + this.buttonAddDocument.TabIndex = 7; + this.buttonAddDocument.Text = "Добавить документ"; + this.buttonAddDocument.UseVisualStyleBackColor = true; + this.buttonAddDocument.Click += new System.EventHandler(this.ButtonAddDocument_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonAddDocument); this.Controls.Add(this.buttonUpdate); this.Controls.Add(this.buttonIssuedOrder); this.Controls.Add(this.buttonOrderReady); @@ -173,5 +194,7 @@ private Button buttonUpdate; private ToolStripMenuItem бланкиToolStripMenuItem; private ToolStripMenuItem документыToolStripMenuItem; + private ToolStripMenuItem магазиныToolStripMenuItem; + private Button buttonAddDocument; } } \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormMain.cs b/LawFirm/LawFirmView/FormMain.cs index 62fa289..319d0d6 100644 --- a/LawFirm/LawFirmView/FormMain.cs +++ b/LawFirm/LawFirmView/FormMain.cs @@ -162,5 +162,24 @@ namespace LawFirmView form.ShowDialog(); } } + + private void ShopToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + + private void ButtonAddDocument_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormAddDocument)); + if (service is FormAddDocument form) + { + form.ShowDialog(); + LoadData(); + } + } } } diff --git a/LawFirm/LawFirmView/FormShop.Designer.cs b/LawFirm/LawFirmView/FormShop.Designer.cs new file mode 100644 index 0000000..6762acc --- /dev/null +++ b/LawFirm/LawFirmView/FormShop.Designer.cs @@ -0,0 +1,188 @@ +namespace LawFirmView +{ + partial class FormShop + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.labelShop = new System.Windows.Forms.Label(); + this.labelAddress = new System.Windows.Forms.Label(); + this.labelDate = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxAddress = new System.Windows.Forms.TextBox(); + this.dateTimePickerDateOpen = new System.Windows.Forms.DateTimePicker(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.DocumentName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(12, 21); + this.labelShop.Name = "labelShop"; + this.labelShop.Size = new System.Drawing.Size(69, 20); + this.labelShop.TabIndex = 0; + this.labelShop.Text = "Магазин"; + // + // labelAddress + // + this.labelAddress.AutoSize = true; + this.labelAddress.Location = new System.Drawing.Point(195, 21); + this.labelAddress.Name = "labelAddress"; + this.labelAddress.Size = new System.Drawing.Size(51, 20); + this.labelAddress.TabIndex = 1; + this.labelAddress.Text = "Адрес"; + // + // labelDate + // + this.labelDate.AutoSize = true; + this.labelDate.Location = new System.Drawing.Point(474, 21); + this.labelDate.Name = "labelDate"; + this.labelDate.Size = new System.Drawing.Size(110, 20); + this.labelDate.TabIndex = 2; + this.labelDate.Text = "Дата открытия"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(12, 44); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(160, 27); + this.textBoxName.TabIndex = 3; + // + // textBoxAddress + // + this.textBoxAddress.Location = new System.Drawing.Point(195, 44); + this.textBoxAddress.Name = "textBoxAddress"; + this.textBoxAddress.Size = new System.Drawing.Size(246, 27); + this.textBoxAddress.TabIndex = 4; + // + // dateTimePickerDateOpen + // + this.dateTimePickerDateOpen.Location = new System.Drawing.Point(474, 44); + this.dateTimePickerDateOpen.Name = "dateTimePickerDateOpen"; + this.dateTimePickerDateOpen.Size = new System.Drawing.Size(250, 27); + this.dateTimePickerDateOpen.TabIndex = 5; + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ID, + this.DocumentName, + this.Count}); + this.dataGridView.Location = new System.Drawing.Point(12, 77); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(712, 330); + this.dataGridView.TabIndex = 6; + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(490, 413); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(111, 29); + this.ButtonSave.TabIndex = 7; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(630, 413); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(94, 29); + this.ButtonCancel.TabIndex = 8; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // ID + // + this.ID.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ID.HeaderText = "ID"; + this.ID.MinimumWidth = 6; + this.ID.Name = "ID"; + this.ID.Visible = false; + // + // DocumentName + // + this.DocumentName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.DocumentName.HeaderText = "DocumentName"; + this.DocumentName.MinimumWidth = 6; + this.DocumentName.Name = "DocumentName"; + // + // Count + // + this.Count.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Count.HeaderText = "Count"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + // + // FormShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(740, 450); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.dateTimePickerDateOpen); + this.Controls.Add(this.textBoxAddress); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelDate); + this.Controls.Add(this.labelAddress); + this.Controls.Add(this.labelShop); + this.Name = "FormShop"; + this.Text = "Магазин"; + this.Load += new System.EventHandler(this.FormShop_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelShop; + private Label labelAddress; + private Label labelDate; + private TextBox textBoxName; + private TextBox textBoxAddress; + private DateTimePicker dateTimePickerDateOpen; + private DataGridView dataGridView; + private Button ButtonSave; + private Button ButtonCancel; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn DocumentName; + private DataGridViewTextBoxColumn Count; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormShop.cs b/LawFirm/LawFirmView/FormShop.cs new file mode 100644 index 0000000..4229ec1 --- /dev/null +++ b/LawFirm/LawFirmView/FormShop.cs @@ -0,0 +1,122 @@ +using LawFirmContracts.BusinessLogicsContracts; +using LawFirmContracts.SearchModels; +using LawFirmDataModels.Models; +using Microsoft.Extensions.Logging; +using LawFirmContracts.BindingModels; + +namespace LawFirmView +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + private int? _id; + private Dictionary _shopDocuments; + public int Id { set { _id = value; } } + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _shopDocuments = new Dictionary(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var view = _logic.ReadElement(new ShopSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ShopName; + textBoxAddress.Text = view.Address.ToString(); + dateTimePickerDateOpen.Text = view.DateOpen.ToString(); + _shopDocuments = view.ShopDocuments ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка кораблей магазина"); + try + { + if (_shopDocuments != null) + { + dataGridView.Rows.Clear(); + foreach (var element in _shopDocuments) + { + dataGridView.Rows.Add(new object[] { element.Key, element.Value.Item1.DocumentName, element.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки кораблей магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(dateTimePickerDateOpen.Text)) + { + MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Address = textBoxAddress.Text, + DateOpen = DateTime.Parse(dateTimePickerDateOpen.Text), + ShopDocuments = _shopDocuments + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/LawFirm/LawFirmView/FormShop.resx b/LawFirm/LawFirmView/FormShop.resx new file mode 100644 index 0000000..c9ecac1 --- /dev/null +++ b/LawFirm/LawFirmView/FormShop.resx @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormShops.Designer.cs b/LawFirm/LawFirmView/FormShops.Designer.cs new file mode 100644 index 0000000..0dd8b7e --- /dev/null +++ b/LawFirm/LawFirmView/FormShops.Designer.cs @@ -0,0 +1,123 @@ +namespace LawFirmView +{ + partial class FormShops + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ButtonAdd = new System.Windows.Forms.Button(); + this.ButtonUpd = new System.Windows.Forms.Button(); + this.ButtonDel = new System.Windows.Forms.Button(); + this.ButtonRef = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(552, 338); + this.dataGridView.TabIndex = 0; + // + // ButtonAdd + // + this.ButtonAdd.Location = new System.Drawing.Point(586, 25); + this.ButtonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.ButtonAdd.Name = "ButtonAdd"; + this.ButtonAdd.Size = new System.Drawing.Size(93, 36); + this.ButtonAdd.TabIndex = 1; + this.ButtonAdd.Text = "Создать"; + this.ButtonAdd.UseVisualStyleBackColor = true; + this.ButtonAdd.Click += new System.EventHandler(this.ButtonAdd_Click); + // + // ButtonUpd + // + this.ButtonUpd.Location = new System.Drawing.Point(586, 76); + this.ButtonUpd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.ButtonUpd.Name = "ButtonUpd"; + this.ButtonUpd.Size = new System.Drawing.Size(93, 36); + this.ButtonUpd.TabIndex = 2; + this.ButtonUpd.Text = "Изменить"; + this.ButtonUpd.UseVisualStyleBackColor = true; + this.ButtonUpd.Click += new System.EventHandler(this.ButtonUpd_Click); + // + // ButtonDel + // + this.ButtonDel.Location = new System.Drawing.Point(586, 124); + this.ButtonDel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.ButtonDel.Name = "ButtonDel"; + this.ButtonDel.Size = new System.Drawing.Size(93, 36); + this.ButtonDel.TabIndex = 3; + this.ButtonDel.Text = "Удалить"; + this.ButtonDel.UseVisualStyleBackColor = true; + this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // ButtonRef + // + this.ButtonRef.Location = new System.Drawing.Point(586, 172); + this.ButtonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.ButtonRef.Name = "ButtonRef"; + this.ButtonRef.Size = new System.Drawing.Size(93, 36); + this.ButtonRef.TabIndex = 4; + this.ButtonRef.Text = "Обновить"; + this.ButtonRef.UseVisualStyleBackColor = true; + this.ButtonRef.Click += new System.EventHandler(this.ButtonRef_Click); + // + // FormShops + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(700, 338); + this.Controls.Add(this.ButtonRef); + this.Controls.Add(this.ButtonDel); + this.Controls.Add(this.ButtonUpd); + this.Controls.Add(this.ButtonAdd); + this.Controls.Add(this.dataGridView); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormShops"; + this.Text = "Магазины"; + this.Load += new System.EventHandler(this.FormShops_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button ButtonAdd; + private Button ButtonUpd; + private Button ButtonDel; + private Button ButtonRef; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormShops.cs b/LawFirm/LawFirmView/FormShops.cs new file mode 100644 index 0000000..d685835 --- /dev/null +++ b/LawFirm/LawFirmView/FormShops.cs @@ -0,0 +1,104 @@ +using Microsoft.Extensions.Logging; +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicsContracts; + +namespace LawFirmView +{ + public partial class FormShops : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public FormShops(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormShops_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ShopDocuments"].Visible = false; + dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление магазина"); + try + { + if (!_logic.Delete(new ShopBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления кораблей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/LawFirm/LawFirmView/FormShops.resx b/LawFirm/LawFirmView/FormShops.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/LawFirm/LawFirmView/FormShops.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/LawFirm/LawFirmView/Program.cs b/LawFirm/LawFirmView/Program.cs index ce6f4f6..537d740 100644 --- a/LawFirm/LawFirmView/Program.cs +++ b/LawFirm/LawFirmView/Program.cs @@ -36,10 +36,12 @@ namespace LawFirmView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -48,6 +50,9 @@ namespace LawFirmView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file From 218590201926ab608f1d8a43620e8dee813b4f2a Mon Sep 17 00:00:00 2001 From: Danil Markov Date: Tue, 11 Apr 2023 01:53:51 +0400 Subject: [PATCH 2/3] lab2hard vrode work --- .../BusinessLogics/OrderLogic.cs | 28 +- .../BusinessLogics/ShopLogic.cs | 79 ++++- .../BindingModels/ShopBindingModel.cs | 3 +- .../BusinessLogicsContracts/IShopLogic.cs | 4 +- .../StoragesContracts/IShopStorage.cs | 2 + .../ViewModels/ShopViewModel.cs | 4 +- LawFirm/LawFirmDataModel/Models/IShopModel.cs | 3 +- .../LawFirmFileImplement/DataFileSingleton.cs | 19 +- .../Implements/DocumentStorage.cs | 8 +- .../Implements/OrderStorage.cs | 6 +- .../Implements/ShopStorage.cs | 129 ++++++++ LawFirm/LawFirmFileImplement/Models/Shop.cs | 108 ++++++ .../Implements/ShopStorage.cs | 6 + LawFirm/LawFirmListImplement/Models/Shop.cs | 3 +- LawFirm/LawFirmView/FormAddDocument.cs | 4 +- LawFirm/LawFirmView/FormMain.Designer.cs | 310 +++++++++--------- LawFirm/LawFirmView/FormMain.cs | 12 +- .../LawFirmView/FormSellDocuments.Designer.cs | 120 +++++++ LawFirm/LawFirmView/FormSellDocuments.cs | 86 +++++ LawFirm/LawFirmView/FormSellDocuments.resx | 60 ++++ LawFirm/LawFirmView/FormShop.Designer.cs | 305 +++++++++-------- LawFirm/LawFirmView/FormShop.cs | 22 +- LawFirm/LawFirmView/FormShops.cs | 2 +- LawFirm/LawFirmView/Program.cs | 3 +- 24 files changed, 994 insertions(+), 332 deletions(-) create mode 100644 LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs create mode 100644 LawFirm/LawFirmFileImplement/Models/Shop.cs create mode 100644 LawFirm/LawFirmView/FormSellDocuments.Designer.cs create mode 100644 LawFirm/LawFirmView/FormSellDocuments.cs create mode 100644 LawFirm/LawFirmView/FormSellDocuments.resx diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs index a87b215..cb2e310 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs @@ -12,10 +12,17 @@ namespace LawFirmBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + private readonly IShopLogic _shopLogic; + private readonly IDocumentStorage _documentStorage; + public OrderLogic(ILogger logger, + IOrderStorage orderStorage, + IShopLogic shopLogic, + IDocumentStorage documentStorage) { _logger = logger; _orderStorage = orderStorage; + _shopLogic = shopLogic; + _documentStorage = documentStorage; } public bool CreateOrder(OrderBindingModel model) { @@ -47,16 +54,29 @@ namespace LawFirmBusinessLogic.BusinessLogics return false; } model.Status = newStatus; - if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now; + if (model.Status == OrderStatus.Готов) + { + + model.DateImplement = DateTime.Now; + var document = _documentStorage.GetElement(new() { Id = viewModel.DocumentId }); + if (document == null) + { + throw new ArgumentNullException(nameof(document)); + } + if (!_shopLogic.AddDocuments(document, viewModel.Count)) + { + throw new Exception($"AddDocuments operation failed - нет места"); + } + } else { model.DateImplement = viewModel.DateImplement; } - CheckModel(model); + CheckModel(model, false); if (_orderStorage.Update(model) == null) { model.Status--; - _logger.LogWarning("Update operation failed"); + _logger.LogWarning("Change status operation failed"); return false; } return true; diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs index e07d5bb..5dec67d 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs @@ -107,7 +107,7 @@ namespace LawFirmBusinessLogic.BusinessLogics } } - public bool AddDocument(ShopSearchModel model, IDocumentModel ship, int count) + public bool AddDocument(ShopSearchModel model, IDocumentModel document, int count) { if (model == null) { @@ -115,6 +115,7 @@ namespace LawFirmBusinessLogic.BusinessLogics } if (count <= 0) { + return false; throw new ArgumentException("Количество поездок должно быть больше 0", nameof(count)); } _logger.LogInformation("AddDocument. ShopName:{ShopName}. Id:{Id}", model.ShopName, model.Id); @@ -124,19 +125,22 @@ namespace LawFirmBusinessLogic.BusinessLogics _logger.LogWarning("AddDocument element not found"); return false; } - _logger.LogInformation("AddDocument find. Id:{Id}", element.Id); + if (element.Capacity - element.ShopDocuments.Select(x => x.Value.Item2).Sum() < count) + { + throw new ArgumentNullException("В магазине не хватает места", nameof(count)); + } - if (element.ShopDocuments.TryGetValue(ship.Id, out var pair)) + if (element.ShopDocuments.TryGetValue(document.Id, out var pair)) { - element.ShopDocuments[ship.Id] = (ship, count + pair.Item2); - _logger.LogInformation("AddDocument. Added {count} {ship} to '{ShopName}' shop", - count, ship.DocumentName, element.ShopName); + element.ShopDocuments[document.Id] = (document, count + pair.Item2); + _logger.LogInformation("AddDocument. Added {count} {document} to '{ShopName}' shop", + count, document.DocumentName, element.ShopName); } else { - element.ShopDocuments[ship.Id] = (ship, count); - _logger.LogInformation("AddDocument. Added {count} new ship {ship} to '{ShopName}' shop", - count, ship.DocumentName, element.ShopName); + element.ShopDocuments[document.Id] = (document, count); + _logger.LogInformation("AddDocument. Added {count} new document {document} to '{ShopName}' shop", + count, document.DocumentName, element.ShopName); } _shopStorage.Update(new() { @@ -144,9 +148,64 @@ namespace LawFirmBusinessLogic.BusinessLogics Address = element.Address, ShopName = element.ShopName, DateOpen = element.DateOpen, + Capacity = element.Capacity, ShopDocuments = element.ShopDocuments }); return true; } - } + public bool AddDocuments(IDocumentModel model, int count) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (count <= 0) + { + throw new ArgumentException("Количество документов должно быть больше 0", nameof(count)); + } + _logger.LogInformation("AddDocuments. ShopName:{ShopName}. Id:{Id}", model.DocumentName, model.Id); + var allFreeQuantity = _shopStorage.GetFullList().Select(x => x.Capacity - x.ShopDocuments.Select(x => x.Value.Item2).Sum()).Sum(); + if (allFreeQuantity < count) + { + _logger.LogWarning("AddTravels operation failed."); + return false; + } + foreach (var shop in _shopStorage.GetFullList()) + { + int freeQuantity = shop.Capacity - shop.ShopDocuments.Select(x => x.Value.Item2).Sum(); + if (freeQuantity <= 0) + { + continue; + } + if (freeQuantity < count) + { + if (!AddDocument(new() { Id = shop.Id }, model, freeQuantity)) + { + _logger.LogWarning("AddDocuments operation failed."); + return false; + } + count -= freeQuantity; + } + else + { + if (!AddDocument(new() { Id = shop.Id }, model, count)) + { + _logger.LogWarning("AddDocuments operation failed."); + return false; + } + count = 0; + } + if (count == 0) + { + return true; + } + } + _logger.LogWarning("AddDocuments operation failed."); + return false; + } + public bool SellDocuments(IDocumentModel model, int count) + { + return _shopStorage.SellDocuments(model, count); + } + } } diff --git a/LawFirm/LawFirmContracts/BindingModels/ShopBindingModel.cs b/LawFirm/LawFirmContracts/BindingModels/ShopBindingModel.cs index 4eff95f..6cc0b4e 100644 --- a/LawFirm/LawFirmContracts/BindingModels/ShopBindingModel.cs +++ b/LawFirm/LawFirmContracts/BindingModels/ShopBindingModel.cs @@ -12,7 +12,8 @@ namespace LawFirmContracts.BindingModels public string ShopName { get; set; } = string.Empty; public string Address { get; set; } = string.Empty; public DateTime DateOpen { get; set; } = DateTime.Now; - public Dictionary ShopDocuments { get; set; } = new(); + public int Capacity { get; set; } + public Dictionary ShopDocuments { get; set; } = new(); public int Id { get; set; } } } diff --git a/LawFirm/LawFirmContracts/BusinessLogicsContracts/IShopLogic.cs b/LawFirm/LawFirmContracts/BusinessLogicsContracts/IShopLogic.cs index a4c15d2..60c4985 100644 --- a/LawFirm/LawFirmContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/LawFirm/LawFirmContracts/BusinessLogicsContracts/IShopLogic.cs @@ -17,6 +17,8 @@ namespace LawFirmContracts.BusinessLogicsContracts bool Create(ShopBindingModel model); bool Update(ShopBindingModel model); bool Delete(ShopBindingModel model); - bool AddDocument(ShopSearchModel model, IDocumentModel document, int count); + bool AddDocuments(IDocumentModel model, int count); + bool SellDocuments(IDocumentModel model, int count); + bool AddDocument(ShopSearchModel model, IDocumentModel document, int count); } } diff --git a/LawFirm/LawFirmContracts/StoragesContracts/IShopStorage.cs b/LawFirm/LawFirmContracts/StoragesContracts/IShopStorage.cs index 0bc1574..4fb68eb 100644 --- a/LawFirm/LawFirmContracts/StoragesContracts/IShopStorage.cs +++ b/LawFirm/LawFirmContracts/StoragesContracts/IShopStorage.cs @@ -1,6 +1,7 @@ using LawFirmContracts.BindingModels; using LawFirmContracts.SearchModels; using LawFirmContracts.ViewModels; +using LawFirmDataModels.Models; using System; using System.Collections.Generic; using System.Linq; @@ -17,5 +18,6 @@ namespace LawFirmContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); + bool SellDocuments(IDocumentModel model, int count); } } diff --git a/LawFirm/LawFirmContracts/ViewModels/ShopViewModel.cs b/LawFirm/LawFirmContracts/ViewModels/ShopViewModel.cs index 9334e2d..2f021bd 100644 --- a/LawFirm/LawFirmContracts/ViewModels/ShopViewModel.cs +++ b/LawFirm/LawFirmContracts/ViewModels/ShopViewModel.cs @@ -18,7 +18,9 @@ namespace LawFirmContracts.ViewModels [DisplayName("Дата открытия")] public DateTime DateOpen { get; set; } = DateTime.Now; - public Dictionary ShopDocuments { get; set; } = new(); + [DisplayName("Вместимость магазина")] + public int Capacity { get; set; } + public Dictionary ShopDocuments { get; set; } = new(); public int Id { get; set; } } } diff --git a/LawFirm/LawFirmDataModel/Models/IShopModel.cs b/LawFirm/LawFirmDataModel/Models/IShopModel.cs index 783e810..4049c17 100644 --- a/LawFirm/LawFirmDataModel/Models/IShopModel.cs +++ b/LawFirm/LawFirmDataModel/Models/IShopModel.cs @@ -8,6 +8,7 @@ namespace LawFirmDataModels.Models string ShopName { get; } string Address { get; } DateTime DateOpen { get; } - Dictionary ShopDocuments { get; } + public int Capacity { get; } + Dictionary ShopDocuments { get; } } } diff --git a/LawFirm/LawFirmFileImplement/DataFileSingleton.cs b/LawFirm/LawFirmFileImplement/DataFileSingleton.cs index dba4b10..96f7113 100644 --- a/LawFirm/LawFirmFileImplement/DataFileSingleton.cs +++ b/LawFirm/LawFirmFileImplement/DataFileSingleton.cs @@ -9,10 +9,14 @@ namespace LawFirmFileImplement private readonly string BlankFileName = "Blank.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string DocumentFileName = "Document.xml"; - public List Blanks { get; private set; } + private readonly string ShopFileName = "Shop.xml"; + + public List Blanks { get; private set; } public List Orders { get; private set; } public List Documents { get; private set; } - public static DataFileSingleton GetInstance() + public List Shops { get; private set; } + + public static DataFileSingleton GetInstance() { if (instance == null) { @@ -23,13 +27,16 @@ namespace LawFirmFileImplement public void SaveBlanks() => SaveData(Blanks, BlankFileName, "Blanks", x => x.GetXElement); public void SaveDocuments() => SaveData(Documents, DocumentFileName, "Documents", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); - private DataFileSingleton() + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); + + private DataFileSingleton() { Blanks = LoadData(BlankFileName, "Blank", x => Blank.Create(x)!)!; Documents = LoadData(DocumentFileName, "Document", x => Document.Create(x)!)!; - Orders = new List(); - } - private static List? LoadData(string filename, string xmlNodeName, + Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; + } + private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { if (File.Exists(filename)) diff --git a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs index 559f389..7a0d8da 100644 --- a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs @@ -50,14 +50,14 @@ namespace LawFirmFileImplement.Implements } public DocumentViewModel? Update(DocumentBindingModel model) { - var ship = source.Documents.FirstOrDefault(x => x.Id == model.Id); - if (ship == null) + var document = source.Documents.FirstOrDefault(x => x.Id == model.Id); + if (document == null) { return null; } - ship.Update(model); + document.Update(model); source.SaveDocuments(); - return ship.GetViewModel; + return document.GetViewModel; } public DocumentViewModel? Delete(DocumentBindingModel model) { diff --git a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs index 783ef1a..0a958dc 100644 --- a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs @@ -38,10 +38,10 @@ namespace LawFirmFileImplement.Implements private OrderViewModel GetViewModel(Order order) { var viewModel = order.GetViewModel; - var ship = source.Documents.FirstOrDefault(x => x.Id == order.DocumentId); - if (ship != null) + var document = source.Documents.FirstOrDefault(x => x.Id == order.DocumentId); + if (document != null) { - viewModel.DocumentName = ship.DocumentName; + viewModel.DocumentName = document.DocumentName; } return viewModel; } diff --git a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..156ac44 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,129 @@ + +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StoragesContracts; +using LawFirmContracts.ViewModels; +using LawFirmDataModels.Models; +using LawFirmFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmFileImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataFileSingleton source; + + public ShopStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + return source.Shops + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName)) + { + return new(); + } + /*return source.Shops + .Where(x => x.ShopName.Contains(model.ShopName)) + .Select(x => x.GetViewModel) + .ToList();*/ + return source.Shops + .Where(x => x.ShopName.Contains(model.ShopName)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + return source.Shops.Select(x => x.GetViewModel).ToList(); + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1; + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + source.Shops.Add(newShop); + source.SaveShops(); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + source.SaveShops(); + return shop.GetViewModel; + } + public ShopViewModel? Delete(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop != null) + { + source.Shops.Remove(shop); + source.SaveShops(); + return shop.GetViewModel; + } + return null; + } + public bool SellDocuments(IDocumentModel model, int count) + { + int availableQuantity = source.Shops.Select(x => x.ShopDocuments.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum(); + if (availableQuantity < count) + { + return false; + } + var shops = source.Shops.Where(x => x.ShopDocuments.ContainsKey(model.Id)); + foreach (var shop in shops) + { + int countInCurrentShop = shop.ShopDocuments[model.Id].Item2; + if (countInCurrentShop <= count) + { + shop.ShopDocuments[model.Id] = (shop.ShopDocuments[model.Id].Item1, 0); + count -= countInCurrentShop; + } + else + { + shop.ShopDocuments[model.Id] = (shop.ShopDocuments[model.Id].Item1, countInCurrentShop - count); + count = 0; + } + Update(new ShopBindingModel + { + Id = shop.Id, + ShopName = shop.ShopName, + Address = shop.Address, + DateOpen = shop.DateOpen, + ShopDocuments = shop.ShopDocuments, + Capacity = shop.Capacity + }); + if (count == 0) + { + return true; + } + } + return false; + } + } +} diff --git a/LawFirm/LawFirmFileImplement/Models/Shop.cs b/LawFirm/LawFirmFileImplement/Models/Shop.cs new file mode 100644 index 0000000..b8d1a9f --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Models/Shop.cs @@ -0,0 +1,108 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.ViewModels; +using LawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace LawFirmFileImplement.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 DateOpen { get; private set; } + public int Capacity { get; private set; } + public Dictionary DocumentsCount = new(); + public Dictionary? _documents = null; + public Dictionary ShopDocuments + { + get + { + if (_documents == null) + { + var source = DataFileSingleton.GetInstance(); + _documents = DocumentsCount.ToDictionary( + x => x.Key, + y => ((source.Documents.FirstOrDefault(z => z.Id == y.Key) as IDocumentModel)!, + y.Value) + ); + } + return _documents; + } + } + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpen = model.DateOpen, + Capacity = model.Capacity, + DocumentsCount = model.ShopDocuments.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + public static Shop? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Shop() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ShopName = element.Element("ShopName")!.Value, + Address = element.Element("Address")!.Value, + DateOpen = Convert.ToDateTime(element.Element("DateOpening")!.Value), + Capacity = Convert.ToInt32(element.Element("Capacity")!.Value), + DocumentsCount = element.Element("Documents")!.Elements("Document") + .ToDictionary( + x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpen = model.DateOpen; + Capacity = model.Capacity; + DocumentsCount = model.ShopDocuments.ToDictionary(x => x.Key, x => x.Value.Item2); + _documents = null; + + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpen = DateOpen, + Capacity = Capacity, + ShopDocuments = ShopDocuments + }; + public XElement GetXElement => new("Shop", + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("Address", Address), + new XElement("DateOpening", DateOpen.ToString()), + new XElement("Capacity", Capacity.ToString()), + new XElement("Documents", DocumentsCount.Select(x => + new XElement("Document", + new XElement("Key", x.Key), + new XElement("Value", x.Value))) + .ToArray())); + } +} diff --git a/LawFirm/LawFirmListImplement/Implements/ShopStorage.cs b/LawFirm/LawFirmListImplement/Implements/ShopStorage.cs index dd23b9e..c1b39ff 100644 --- a/LawFirm/LawFirmListImplement/Implements/ShopStorage.cs +++ b/LawFirm/LawFirmListImplement/Implements/ShopStorage.cs @@ -2,6 +2,7 @@ using LawFirmContracts.SearchModels; using LawFirmContracts.StoragesContracts; using LawFirmContracts.ViewModels; +using LawFirmDataModels.Models; using LawFirmListImplement.Models; using System; using System.Collections.Generic; @@ -108,5 +109,10 @@ namespace LawFirmListImplement.Implements } return null; } + + public bool SellDocuments(IDocumentModel model, int count) + { + throw new NotImplementedException(); + } } } diff --git a/LawFirm/LawFirmListImplement/Models/Shop.cs b/LawFirm/LawFirmListImplement/Models/Shop.cs index 4b18e0d..4703cc8 100644 --- a/LawFirm/LawFirmListImplement/Models/Shop.cs +++ b/LawFirm/LawFirmListImplement/Models/Shop.cs @@ -15,7 +15,8 @@ namespace LawFirmListImplement.Models public string Address { get; set; } = string.Empty; public DateTime DateOpen { get; set; } - public int Id { get; set; } + public int Capacity { get; private set; } + public int Id { get; set; } public Dictionary ShopDocuments { get; private set; } = new Dictionary(); public static Shop? Create(ShopBindingModel? model) diff --git a/LawFirm/LawFirmView/FormAddDocument.cs b/LawFirm/LawFirmView/FormAddDocument.cs index 27add3d..10ad81f 100644 --- a/LawFirm/LawFirmView/FormAddDocument.cs +++ b/LawFirm/LawFirmView/FormAddDocument.cs @@ -19,7 +19,7 @@ namespace LawFirmView private void FormAddDocument_Load(object sender, EventArgs e) { - _logger.LogInformation("Загрузка списка кораблей для пополнения"); + _logger.LogInformation("Загрузка списка документов для пополнения"); try { var list = _logicDocument.ReadList(null); @@ -33,7 +33,7 @@ namespace LawFirmView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки списка кораблей"); + _logger.LogError(ex, "Ошибка загрузки списка документов"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } diff --git a/LawFirm/LawFirmView/FormMain.Designer.cs b/LawFirm/LawFirmView/FormMain.Designer.cs index 3738201..5aa99c0 100644 --- a/LawFirm/LawFirmView/FormMain.Designer.cs +++ b/LawFirm/LawFirmView/FormMain.Designer.cs @@ -28,157 +28,170 @@ /// private void InitializeComponent() { - this.menuStrip1 = new System.Windows.Forms.MenuStrip(); - this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.бланкиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.документыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.buttonCreateOrder = new System.Windows.Forms.Button(); - this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); - this.buttonOrderReady = new System.Windows.Forms.Button(); - this.buttonIssuedOrder = new System.Windows.Forms.Button(); - this.buttonUpdate = new System.Windows.Forms.Button(); - this.buttonAddDocument = new System.Windows.Forms.Button(); - this.menuStrip1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); - // - // menuStrip1 - // - this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.бланкиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.документыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonCreateOrder = new System.Windows.Forms.Button(); + this.buttonTakeOrderInWork = new System.Windows.Forms.Button(); + this.buttonOrderReady = new System.Windows.Forms.Button(); + this.buttonIssuedOrder = new System.Windows.Forms.Button(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonAddDocument = new System.Windows.Forms.Button(); + this.buttonSellDocument = new System.Windows.Forms.Button(); + this.menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // menuStrip1 + // + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.справочникиToolStripMenuItem}); - this.menuStrip1.Location = new System.Drawing.Point(0, 0); - this.menuStrip1.Name = "menuStrip1"; - this.menuStrip1.Size = new System.Drawing.Size(800, 24); - this.menuStrip1.TabIndex = 0; - this.menuStrip1.Text = "menuStrip1"; - // - // справочникиToolStripMenuItem - // - this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Size = new System.Drawing.Size(800, 24); + this.menuStrip1.TabIndex = 0; + this.menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.бланкиToolStripMenuItem, this.документыToolStripMenuItem, this.магазиныToolStripMenuItem}); - this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; - this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); - this.справочникиToolStripMenuItem.Text = "Справочники"; - // - // бланкиToolStripMenuItem - // - this.бланкиToolStripMenuItem.Name = "бланкиToolStripMenuItem"; - this.бланкиToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.бланкиToolStripMenuItem.Text = "Бланки"; - this.бланкиToolStripMenuItem.Click += new System.EventHandler(this.BlanksToolStripMenuItem_Click); - // - // документыToolStripMenuItem - // - this.документыToolStripMenuItem.Name = "документыToolStripMenuItem"; - this.документыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.документыToolStripMenuItem.Text = "Документы"; - this.документыToolStripMenuItem.Click += new System.EventHandler(this.DocumentsToolStripMenuItem_Click); - // - // магазиныToolStripMenuItem - // - this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; - this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.магазиныToolStripMenuItem.Text = "Магазины"; - this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.ShopToolStripMenuItem_Click); - // - // dataGridView - // - this.dataGridView.AllowUserToAddRows = false; - this.dataGridView.AllowUserToDeleteRows = false; - this.dataGridView.BackgroundColor = System.Drawing.Color.White; - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(12, 27); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.ReadOnly = true; - this.dataGridView.RowTemplate.Height = 25; - this.dataGridView.Size = new System.Drawing.Size(566, 411); - this.dataGridView.TabIndex = 1; - // - // buttonCreateOrder - // - this.buttonCreateOrder.Location = new System.Drawing.Point(605, 27); - this.buttonCreateOrder.Name = "buttonCreateOrder"; - this.buttonCreateOrder.Size = new System.Drawing.Size(168, 23); - this.buttonCreateOrder.TabIndex = 2; - this.buttonCreateOrder.Text = "Создать заказ"; - this.buttonCreateOrder.UseVisualStyleBackColor = true; - this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); - // - // buttonTakeOrderInWork - // - this.buttonTakeOrderInWork.Location = new System.Drawing.Point(605, 56); - this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - this.buttonTakeOrderInWork.Size = new System.Drawing.Size(168, 23); - this.buttonTakeOrderInWork.TabIndex = 3; - this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; - this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; - this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); - // - // buttonOrderReady - // - this.buttonOrderReady.Location = new System.Drawing.Point(605, 85); - this.buttonOrderReady.Name = "buttonOrderReady"; - this.buttonOrderReady.Size = new System.Drawing.Size(168, 23); - this.buttonOrderReady.TabIndex = 4; - this.buttonOrderReady.Text = "Заказ готов"; - this.buttonOrderReady.UseVisualStyleBackColor = true; - this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); - // - // buttonIssuedOrder - // - this.buttonIssuedOrder.Location = new System.Drawing.Point(605, 114); - this.buttonIssuedOrder.Name = "buttonIssuedOrder"; - this.buttonIssuedOrder.Size = new System.Drawing.Size(168, 23); - this.buttonIssuedOrder.TabIndex = 5; - this.buttonIssuedOrder.Text = "Заказ выдан"; - this.buttonIssuedOrder.UseVisualStyleBackColor = true; - this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); - // - // buttonUpdate - // - this.buttonUpdate.Location = new System.Drawing.Point(605, 143); - this.buttonUpdate.Name = "buttonUpdate"; - this.buttonUpdate.Size = new System.Drawing.Size(168, 23); - this.buttonUpdate.TabIndex = 6; - this.buttonUpdate.Text = "Обновить список"; - this.buttonUpdate.UseVisualStyleBackColor = true; - this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); - // - // buttonAddDocument - // - this.buttonAddDocument.Location = new System.Drawing.Point(605, 172); - this.buttonAddDocument.Name = "buttonAddDocument"; - this.buttonAddDocument.Size = new System.Drawing.Size(168, 23); - this.buttonAddDocument.TabIndex = 7; - this.buttonAddDocument.Text = "Добавить документ"; - this.buttonAddDocument.UseVisualStyleBackColor = true; - this.buttonAddDocument.Click += new System.EventHandler(this.ButtonAddDocument_Click); - // - // FormMain - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Controls.Add(this.buttonAddDocument); - this.Controls.Add(this.buttonUpdate); - this.Controls.Add(this.buttonIssuedOrder); - this.Controls.Add(this.buttonOrderReady); - this.Controls.Add(this.buttonTakeOrderInWork); - this.Controls.Add(this.buttonCreateOrder); - this.Controls.Add(this.dataGridView); - this.Controls.Add(this.menuStrip1); - this.MainMenuStrip = this.menuStrip1; - this.Name = "FormMain"; - this.Text = "Юридическая фирма"; - this.menuStrip1.ResumeLayout(false); - this.menuStrip1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); + this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); + this.справочникиToolStripMenuItem.Text = "Справочники"; + // + // бланкиToolStripMenuItem + // + this.бланкиToolStripMenuItem.Name = "бланкиToolStripMenuItem"; + this.бланкиToolStripMenuItem.Size = new System.Drawing.Size(137, 22); + this.бланкиToolStripMenuItem.Text = "Бланки"; + this.бланкиToolStripMenuItem.Click += new System.EventHandler(this.BlanksToolStripMenuItem_Click); + // + // документыToolStripMenuItem + // + this.документыToolStripMenuItem.Name = "документыToolStripMenuItem"; + this.документыToolStripMenuItem.Size = new System.Drawing.Size(137, 22); + this.документыToolStripMenuItem.Text = "Документы"; + this.документыToolStripMenuItem.Click += new System.EventHandler(this.DocumentsToolStripMenuItem_Click); + // + // магазиныToolStripMenuItem + // + this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(137, 22); + this.магазиныToolStripMenuItem.Text = "Магазины"; + this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.ShopToolStripMenuItem_Click); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 27); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(566, 411); + this.dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + this.buttonCreateOrder.Location = new System.Drawing.Point(605, 27); + this.buttonCreateOrder.Name = "buttonCreateOrder"; + this.buttonCreateOrder.Size = new System.Drawing.Size(168, 23); + this.buttonCreateOrder.TabIndex = 2; + this.buttonCreateOrder.Text = "Создать заказ"; + this.buttonCreateOrder.UseVisualStyleBackColor = true; + this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click); + // + // buttonTakeOrderInWork + // + this.buttonTakeOrderInWork.Location = new System.Drawing.Point(605, 56); + this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + this.buttonTakeOrderInWork.Size = new System.Drawing.Size(168, 23); + this.buttonTakeOrderInWork.TabIndex = 3; + this.buttonTakeOrderInWork.Text = "Отдать на выполнение"; + this.buttonTakeOrderInWork.UseVisualStyleBackColor = true; + this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click); + // + // buttonOrderReady + // + this.buttonOrderReady.Location = new System.Drawing.Point(605, 85); + this.buttonOrderReady.Name = "buttonOrderReady"; + this.buttonOrderReady.Size = new System.Drawing.Size(168, 23); + this.buttonOrderReady.TabIndex = 4; + this.buttonOrderReady.Text = "Заказ готов"; + this.buttonOrderReady.UseVisualStyleBackColor = true; + this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click); + // + // buttonIssuedOrder + // + this.buttonIssuedOrder.Location = new System.Drawing.Point(605, 114); + this.buttonIssuedOrder.Name = "buttonIssuedOrder"; + this.buttonIssuedOrder.Size = new System.Drawing.Size(168, 23); + this.buttonIssuedOrder.TabIndex = 5; + this.buttonIssuedOrder.Text = "Заказ выдан"; + this.buttonIssuedOrder.UseVisualStyleBackColor = true; + this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(605, 143); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(168, 23); + this.buttonUpdate.TabIndex = 6; + this.buttonUpdate.Text = "Обновить список"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click); + // + // buttonAddDocument + // + this.buttonAddDocument.Location = new System.Drawing.Point(605, 172); + this.buttonAddDocument.Name = "buttonAddDocument"; + this.buttonAddDocument.Size = new System.Drawing.Size(168, 23); + this.buttonAddDocument.TabIndex = 7; + this.buttonAddDocument.Text = "Добавить документ"; + this.buttonAddDocument.UseVisualStyleBackColor = true; + this.buttonAddDocument.Click += new System.EventHandler(this.ButtonAddDocument_Click); + // + // buttonSellDocument + // + this.buttonSellDocument.Location = new System.Drawing.Point(605, 201); + this.buttonSellDocument.Name = "buttonSellDocument"; + this.buttonSellDocument.Size = new System.Drawing.Size(168, 23); + this.buttonSellDocument.TabIndex = 8; + this.buttonSellDocument.Text = "Продать документ"; + this.buttonSellDocument.UseVisualStyleBackColor = true; + this.buttonSellDocument.Click += new System.EventHandler(this.ButtonSellDocument_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.buttonSellDocument); + this.Controls.Add(this.buttonAddDocument); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonIssuedOrder); + this.Controls.Add(this.buttonOrderReady); + this.Controls.Add(this.buttonTakeOrderInWork); + this.Controls.Add(this.buttonCreateOrder); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.Name = "FormMain"; + this.Text = "Юридическая фирма"; + this.Load += new System.EventHandler(this.FormMain_Load); + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); } @@ -196,5 +209,6 @@ private ToolStripMenuItem документыToolStripMenuItem; private ToolStripMenuItem магазиныToolStripMenuItem; private Button buttonAddDocument; - } + private Button buttonSellDocument; + } } \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormMain.cs b/LawFirm/LawFirmView/FormMain.cs index 319d0d6..c855f61 100644 --- a/LawFirm/LawFirmView/FormMain.cs +++ b/LawFirm/LawFirmView/FormMain.cs @@ -181,5 +181,15 @@ namespace LawFirmView LoadData(); } } - } + + private void ButtonSellDocument_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSellDocuments)); + if (service is FormSellDocuments form) + { + form.ShowDialog(); + LoadData(); + } + } + } } diff --git a/LawFirm/LawFirmView/FormSellDocuments.Designer.cs b/LawFirm/LawFirmView/FormSellDocuments.Designer.cs new file mode 100644 index 0000000..1d5afea --- /dev/null +++ b/LawFirm/LawFirmView/FormSellDocuments.Designer.cs @@ -0,0 +1,120 @@ +namespace LawFirmView +{ + partial class FormSellDocuments + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.ButtonCancel = new System.Windows.Forms.Button(); + this.comboBoxDocuments = new System.Windows.Forms.ComboBox(); + this.numericUpDownCount = new System.Windows.Forms.NumericUpDown(); + this.labelDocument = new System.Windows.Forms.Label(); + this.labelCount = new System.Windows.Forms.Label(); + this.ButtonSave = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit(); + this.SuspendLayout(); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(266, 153); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(94, 29); + this.ButtonCancel.TabIndex = 1; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // comboBoxDocuments + // + this.comboBoxDocuments.FormattingEnabled = true; + this.comboBoxDocuments.Location = new System.Drawing.Point(144, 38); + this.comboBoxDocuments.Name = "comboBoxDocuments"; + this.comboBoxDocuments.Size = new System.Drawing.Size(216, 28); + this.comboBoxDocuments.TabIndex = 2; + // + // numericUpDownCount + // + this.numericUpDownCount.Location = new System.Drawing.Point(144, 102); + this.numericUpDownCount.Name = "numericUpDownCount"; + this.numericUpDownCount.Size = new System.Drawing.Size(216, 27); + this.numericUpDownCount.TabIndex = 3; + // + // labelDocument + // + this.labelDocument.AutoSize = true; + this.labelDocument.Location = new System.Drawing.Point(34, 38); + this.labelDocument.Name = "labelDocument"; + this.labelDocument.Size = new System.Drawing.Size(69, 20); + this.labelDocument.TabIndex = 4; + this.labelDocument.Text = "Корабль"; + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(34, 109); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(90, 20); + this.labelCount.TabIndex = 5; + this.labelCount.Text = "Количество"; + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(144, 153); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(94, 29); + this.ButtonSave.TabIndex = 6; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // FormSellDocuments + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(373, 194); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.labelCount); + this.Controls.Add(this.labelDocument); + this.Controls.Add(this.numericUpDownCount); + this.Controls.Add(this.comboBoxDocuments); + this.Controls.Add(this.ButtonCancel); + this.Name = "FormSellDocuments"; + this.Text = "Продажа документов"; + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private Button ButtonCancel; + private ComboBox comboBoxDocuments; + private NumericUpDown numericUpDownCount; + private Label labelDocument; + private Label labelCount; + private Button ButtonSave; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormSellDocuments.cs b/LawFirm/LawFirmView/FormSellDocuments.cs new file mode 100644 index 0000000..1d479fb --- /dev/null +++ b/LawFirm/LawFirmView/FormSellDocuments.cs @@ -0,0 +1,86 @@ +using Microsoft.Extensions.Logging; +using LawFirmContracts.BusinessLogicsContracts; +using LawFirmContracts.ViewModels; +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 LawFirmView +{ + public partial class FormSellDocuments : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _shopLogic; + private readonly IDocumentLogic _documentLogic; + private readonly List? _listDocument; + public FormSellDocuments(ILogger logger, IShopLogic shopLogic, IDocumentLogic documentLogic) + { + InitializeComponent(); + _logger = logger; + _shopLogic = shopLogic; + _documentLogic = documentLogic; + _listDocument = documentLogic.ReadList(null); + if (_listDocument != null) + { + comboBoxDocuments.DisplayMember = "DocumentName"; + comboBoxDocuments.ValueMember = "Id"; + comboBoxDocuments.DataSource=_listDocument; + comboBoxDocuments.SelectedItem = null; + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxDocuments.SelectedValue == null) + { + MessageBox.Show("Выберите корабль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(numericUpDownCount.Text)) + { + MessageBox.Show("Заполните количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Продажа поездок"); + try + { + var document = _documentLogic.ReadElement(new() + { + Id = (int)comboBoxDocuments.SelectedValue + }); + if (document == null) + { + throw new Exception("Корабль не найден. Дополнительная информация в логах."); + } + var operationResult = _shopLogic.SellDocuments( + model: document, + count: (int)numericUpDownCount.Value + ); + if (!operationResult) + { + throw new Exception("Ошибка при продаже корабля. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения корабля"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/LawFirm/LawFirmView/FormSellDocuments.resx b/LawFirm/LawFirmView/FormSellDocuments.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/LawFirm/LawFirmView/FormSellDocuments.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/LawFirm/LawFirmView/FormShop.Designer.cs b/LawFirm/LawFirmView/FormShop.Designer.cs index 6762acc..aaa3e36 100644 --- a/LawFirm/LawFirmView/FormShop.Designer.cs +++ b/LawFirm/LawFirmView/FormShop.Designer.cs @@ -28,145 +28,174 @@ /// private void InitializeComponent() { - this.labelShop = new System.Windows.Forms.Label(); - this.labelAddress = new System.Windows.Forms.Label(); - this.labelDate = new System.Windows.Forms.Label(); - this.textBoxName = new System.Windows.Forms.TextBox(); - this.textBoxAddress = new System.Windows.Forms.TextBox(); - this.dateTimePickerDateOpen = new System.Windows.Forms.DateTimePicker(); - this.dataGridView = new System.Windows.Forms.DataGridView(); - this.ButtonSave = new System.Windows.Forms.Button(); - this.ButtonCancel = new System.Windows.Forms.Button(); - this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.DocumentName = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); - this.SuspendLayout(); - // - // labelShop - // - this.labelShop.AutoSize = true; - this.labelShop.Location = new System.Drawing.Point(12, 21); - this.labelShop.Name = "labelShop"; - this.labelShop.Size = new System.Drawing.Size(69, 20); - this.labelShop.TabIndex = 0; - this.labelShop.Text = "Магазин"; - // - // labelAddress - // - this.labelAddress.AutoSize = true; - this.labelAddress.Location = new System.Drawing.Point(195, 21); - this.labelAddress.Name = "labelAddress"; - this.labelAddress.Size = new System.Drawing.Size(51, 20); - this.labelAddress.TabIndex = 1; - this.labelAddress.Text = "Адрес"; - // - // labelDate - // - this.labelDate.AutoSize = true; - this.labelDate.Location = new System.Drawing.Point(474, 21); - this.labelDate.Name = "labelDate"; - this.labelDate.Size = new System.Drawing.Size(110, 20); - this.labelDate.TabIndex = 2; - this.labelDate.Text = "Дата открытия"; - // - // textBoxName - // - this.textBoxName.Location = new System.Drawing.Point(12, 44); - this.textBoxName.Name = "textBoxName"; - this.textBoxName.Size = new System.Drawing.Size(160, 27); - this.textBoxName.TabIndex = 3; - // - // textBoxAddress - // - this.textBoxAddress.Location = new System.Drawing.Point(195, 44); - this.textBoxAddress.Name = "textBoxAddress"; - this.textBoxAddress.Size = new System.Drawing.Size(246, 27); - this.textBoxAddress.TabIndex = 4; - // - // dateTimePickerDateOpen - // - this.dateTimePickerDateOpen.Location = new System.Drawing.Point(474, 44); - this.dateTimePickerDateOpen.Name = "dateTimePickerDateOpen"; - this.dateTimePickerDateOpen.Size = new System.Drawing.Size(250, 27); - this.dateTimePickerDateOpen.TabIndex = 5; - // - // dataGridView - // - this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.labelShop = new System.Windows.Forms.Label(); + this.labelAddress = new System.Windows.Forms.Label(); + this.labelDate = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxAddress = new System.Windows.Forms.TextBox(); + this.dateTimePickerDateOpen = new System.Windows.Forms.DateTimePicker(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.DocumentName = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ButtonSave = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.numericUpDownCapacity = new System.Windows.Forms.NumericUpDown(); + this.labelCapacity = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCapacity)).BeginInit(); + this.SuspendLayout(); + // + // labelShop + // + this.labelShop.AutoSize = true; + this.labelShop.Location = new System.Drawing.Point(10, 16); + this.labelShop.Name = "labelShop"; + this.labelShop.Size = new System.Drawing.Size(54, 15); + this.labelShop.TabIndex = 0; + this.labelShop.Text = "Магазин"; + // + // labelAddress + // + this.labelAddress.AutoSize = true; + this.labelAddress.Location = new System.Drawing.Point(156, 16); + this.labelAddress.Name = "labelAddress"; + this.labelAddress.Size = new System.Drawing.Size(40, 15); + this.labelAddress.TabIndex = 1; + this.labelAddress.Text = "Адрес"; + // + // labelDate + // + this.labelDate.AutoSize = true; + this.labelDate.Location = new System.Drawing.Point(375, 16); + this.labelDate.Name = "labelDate"; + this.labelDate.Size = new System.Drawing.Size(87, 15); + this.labelDate.TabIndex = 2; + this.labelDate.Text = "Дата открытия"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(10, 33); + this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(140, 23); + this.textBoxName.TabIndex = 3; + // + // textBoxAddress + // + this.textBoxAddress.Location = new System.Drawing.Point(156, 33); + this.textBoxAddress.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.textBoxAddress.Name = "textBoxAddress"; + this.textBoxAddress.Size = new System.Drawing.Size(216, 23); + this.textBoxAddress.TabIndex = 4; + // + // dateTimePickerDateOpen + // + this.dateTimePickerDateOpen.Location = new System.Drawing.Point(375, 33); + this.dateTimePickerDateOpen.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dateTimePickerDateOpen.Name = "dateTimePickerDateOpen"; + this.dateTimePickerDateOpen.Size = new System.Drawing.Size(123, 23); + this.dateTimePickerDateOpen.TabIndex = 5; + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.ID, this.DocumentName, this.Count}); - this.dataGridView.Location = new System.Drawing.Point(12, 77); - this.dataGridView.Name = "dataGridView"; - this.dataGridView.RowHeadersWidth = 51; - this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(712, 330); - this.dataGridView.TabIndex = 6; - // - // ButtonSave - // - this.ButtonSave.Location = new System.Drawing.Point(490, 413); - this.ButtonSave.Name = "ButtonSave"; - this.ButtonSave.Size = new System.Drawing.Size(111, 29); - this.ButtonSave.TabIndex = 7; - this.ButtonSave.Text = "Сохранить"; - this.ButtonSave.UseVisualStyleBackColor = true; - this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); - // - // ButtonCancel - // - this.ButtonCancel.Location = new System.Drawing.Point(630, 413); - this.ButtonCancel.Name = "ButtonCancel"; - this.ButtonCancel.Size = new System.Drawing.Size(94, 29); - this.ButtonCancel.TabIndex = 8; - this.ButtonCancel.Text = "Отмена"; - this.ButtonCancel.UseVisualStyleBackColor = true; - this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); - // - // ID - // - this.ID.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.ID.HeaderText = "ID"; - this.ID.MinimumWidth = 6; - this.ID.Name = "ID"; - this.ID.Visible = false; - // - // DocumentName - // - this.DocumentName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.DocumentName.HeaderText = "DocumentName"; - this.DocumentName.MinimumWidth = 6; - this.DocumentName.Name = "DocumentName"; - // - // Count - // - this.Count.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - this.Count.HeaderText = "Count"; - this.Count.MinimumWidth = 6; - this.Count.Name = "Count"; - // - // FormShop - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(740, 450); - this.Controls.Add(this.ButtonCancel); - this.Controls.Add(this.ButtonSave); - this.Controls.Add(this.dataGridView); - this.Controls.Add(this.dateTimePickerDateOpen); - this.Controls.Add(this.textBoxAddress); - this.Controls.Add(this.textBoxName); - this.Controls.Add(this.labelDate); - this.Controls.Add(this.labelAddress); - this.Controls.Add(this.labelShop); - this.Name = "FormShop"; - this.Text = "Магазин"; - this.Load += new System.EventHandler(this.FormShop_Load); - ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); + this.dataGridView.Location = new System.Drawing.Point(10, 58); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.Size = new System.Drawing.Size(623, 248); + this.dataGridView.TabIndex = 6; + // + // ID + // + this.ID.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.ID.HeaderText = "ID"; + this.ID.MinimumWidth = 6; + this.ID.Name = "ID"; + this.ID.Visible = false; + // + // DocumentName + // + this.DocumentName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.DocumentName.HeaderText = "DocumentName"; + this.DocumentName.MinimumWidth = 6; + this.DocumentName.Name = "DocumentName"; + // + // Count + // + this.Count.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; + this.Count.HeaderText = "Count"; + this.Count.MinimumWidth = 6; + this.Count.Name = "Count"; + // + // ButtonSave + // + this.ButtonSave.Location = new System.Drawing.Point(429, 310); + this.ButtonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.ButtonSave.Name = "ButtonSave"; + this.ButtonSave.Size = new System.Drawing.Size(97, 22); + this.ButtonSave.TabIndex = 7; + this.ButtonSave.Text = "Сохранить"; + this.ButtonSave.UseVisualStyleBackColor = true; + this.ButtonSave.Click += new System.EventHandler(this.ButtonSave_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(551, 310); + this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(82, 22); + this.ButtonCancel.TabIndex = 8; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // numericUpDownCapacity + // + this.numericUpDownCapacity.Location = new System.Drawing.Point(504, 33); + this.numericUpDownCapacity.Name = "numericUpDownCapacity"; + this.numericUpDownCapacity.Size = new System.Drawing.Size(120, 23); + this.numericUpDownCapacity.TabIndex = 9; + // + // labelCapacity + // + this.labelCapacity.AutoSize = true; + this.labelCapacity.Location = new System.Drawing.Point(504, 16); + this.labelCapacity.Name = "labelCapacity"; + this.labelCapacity.Size = new System.Drawing.Size(134, 15); + this.labelCapacity.TabIndex = 10; + this.labelCapacity.Text = "Вместимость магазина"; + // + // FormShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(648, 338); + this.Controls.Add(this.labelCapacity); + this.Controls.Add(this.numericUpDownCapacity); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.ButtonSave); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.dateTimePickerDateOpen); + this.Controls.Add(this.textBoxAddress); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelDate); + this.Controls.Add(this.labelAddress); + this.Controls.Add(this.labelShop); + this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.Name = "FormShop"; + this.Text = "Магазин"; + this.Load += new System.EventHandler(this.FormShop_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownCapacity)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); } @@ -184,5 +213,7 @@ private DataGridViewTextBoxColumn ID; private DataGridViewTextBoxColumn DocumentName; private DataGridViewTextBoxColumn Count; - } + private NumericUpDown numericUpDownCapacity; + private Label labelCapacity; + } } \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormShop.cs b/LawFirm/LawFirmView/FormShop.cs index 4229ec1..5243b19 100644 --- a/LawFirm/LawFirmView/FormShop.cs +++ b/LawFirm/LawFirmView/FormShop.cs @@ -37,7 +37,8 @@ namespace LawFirmView textBoxName.Text = view.ShopName; textBoxAddress.Text = view.Address.ToString(); dateTimePickerDateOpen.Text = view.DateOpen.ToString(); - _shopDocuments = view.ShopDocuments ?? new Dictionary(); + numericUpDownCapacity.Value = view.Capacity; + _shopDocuments = view.ShopDocuments ?? new Dictionary(); LoadData(); } } @@ -50,7 +51,7 @@ namespace LawFirmView } private void LoadData() { - _logger.LogInformation("Загрузка кораблей магазина"); + _logger.LogInformation("Загрузка документов магазина"); try { if (_shopDocuments != null) @@ -64,7 +65,7 @@ namespace LawFirmView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки кораблей магазина"); + _logger.LogError(ex, "Ошибка загрузки документов магазина"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -91,12 +92,13 @@ namespace LawFirmView { var model = new ShopBindingModel { - Id = _id ?? 0, - ShopName = textBoxName.Text, - Address = textBoxAddress.Text, - DateOpen = DateTime.Parse(dateTimePickerDateOpen.Text), - ShopDocuments = _shopDocuments - }; + Id = _id ?? 0, + ShopName = textBoxName.Text, + Address = textBoxAddress.Text, + DateOpen = DateTime.Parse(dateTimePickerDateOpen.Text), + Capacity = (int)numericUpDownCapacity.Value, + ShopDocuments = _shopDocuments + }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) { @@ -118,5 +120,5 @@ namespace LawFirmView DialogResult = DialogResult.Cancel; Close(); } - } + } } diff --git a/LawFirm/LawFirmView/FormShops.cs b/LawFirm/LawFirmView/FormShops.cs index d685835..ed08f38 100644 --- a/LawFirm/LawFirmView/FormShops.cs +++ b/LawFirm/LawFirmView/FormShops.cs @@ -89,7 +89,7 @@ namespace LawFirmView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка удаления кораблей"); + _logger.LogError(ex, "Ошибка удаления документов"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/LawFirm/LawFirmView/Program.cs b/LawFirm/LawFirmView/Program.cs index f86d2bc..9fb2eea 100644 --- a/LawFirm/LawFirmView/Program.cs +++ b/LawFirm/LawFirmView/Program.cs @@ -53,6 +53,7 @@ namespace LawFirmView services.AddTransient(); services.AddTransient(); services.AddTransient(); - } + services.AddTransient(); + } } } \ No newline at end of file From 650d6d2e0beae5b950820d3828de00eaa970ca20 Mon Sep 17 00:00:00 2001 From: Danil Markov Date: Tue, 11 Apr 2023 02:03:01 +0400 Subject: [PATCH 3/3] fix --- LawFirm/LawFirmView/FormMain.cs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/LawFirm/LawFirmView/FormMain.cs b/LawFirm/LawFirmView/FormMain.cs index c855f61..2ea2821 100644 --- a/LawFirm/LawFirmView/FormMain.cs +++ b/LawFirm/LawFirmView/FormMain.cs @@ -88,12 +88,7 @@ namespace LawFirmView { var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { - Id = id, - DocumentId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DocumentId"].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()) + Id = id }); if (!operationResult) { @@ -120,12 +115,7 @@ namespace LawFirmView var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { - Id = id, - DocumentId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DocumentId"].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()) + Id = id }); if (!operationResult) {