From e350927c0bcbddd0b4440801312d353f0ff350bf Mon Sep 17 00:00:00 2001 From: AnnaLioness Date: Fri, 23 Feb 2024 18:38:04 +0400 Subject: [PATCH 1/7] =?UTF-8?q?1=20=D1=81=D0=BB=D0=BE=D0=B6=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/ShopLogic.cs | 162 ++++++++++++++++ .../BindingModels/ShopBindingModel.cs | 26 +++ .../BusinessLogicsContracts/IShopLogic.cs | 22 +++ .../SearchModels/ShopSearchModel.cs | 14 ++ .../StoragesContracts/IShopStorage.cs | 21 ++ .../ViewModels/ShopViewModel.cs | 29 +++ .../Models/IShopModel.cs | 16 ++ .../DataListSingleton.cs | 2 + .../Implements/ShopStorage.cs | 118 ++++++++++++ .../Models/Shop.cs | 60 ++++++ LawFirm/LawFirmView/FormMain.Designer.cs | 25 ++- LawFirm/LawFirmView/FormMain.cs | 18 ++ LawFirm/LawFirmView/FormShop.Designer.cs | 182 ++++++++++++++++++ LawFirm/LawFirmView/FormShop.cs | 133 +++++++++++++ LawFirm/LawFirmView/FormShop.resx | 69 +++++++ .../LawFirmView/FormShopSupply.Designer.cs | 143 ++++++++++++++ LawFirm/LawFirmView/FormShopSupply.cs | 125 ++++++++++++ LawFirm/LawFirmView/FormShopSupply.resx | 60 ++++++ LawFirm/LawFirmView/FormShops.Designer.cs | 114 +++++++++++ LawFirm/LawFirmView/FormShops.cs | 122 ++++++++++++ LawFirm/LawFirmView/FormShops.resx | 60 ++++++ LawFirm/LawFirmView/Program.cs | 5 + 22 files changed, 1525 insertions(+), 1 deletion(-) create mode 100644 LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/ShopLogic.cs create mode 100644 LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/ShopBindingModel.cs create mode 100644 LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IShopLogic.cs create mode 100644 LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/ShopSearchModel.cs create mode 100644 LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/StoragesContracts/IShopStorage.cs create mode 100644 LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ShopViewModel.cs create mode 100644 LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IShopModel.cs create mode 100644 LawFirm/AbstractLawFirmListImplement/Implements/ShopStorage.cs create mode 100644 LawFirm/AbstractLawFirmListImplement/Models/Shop.cs 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/FormShopSupply.Designer.cs create mode 100644 LawFirm/LawFirmView/FormShopSupply.cs create mode 100644 LawFirm/LawFirmView/FormShopSupply.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/AbstractLawFirmBusinessLogic/BusinessLogic/ShopLogic.cs b/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/ShopLogic.cs new file mode 100644 index 0000000..fa2931e --- /dev/null +++ b/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/ShopLogic.cs @@ -0,0 +1,162 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.BusinessLogicsContracts; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.StoragesContracts; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmBusinessLogic.BusinessLogic +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + + private readonly IShopStorage _shopStorage; + public ShopLogic(ILogger logger, IShopStorage shopStorage) + { + _logger = logger; + _shopStorage = shopStorage; + } + public List? ReadList(ShopSearchModel? model) + { + _logger.LogInformation("ReadList. ShopName:{ShopName}.Id:{ Id}", model?.ShopName, model?.Id); + + var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ShopViewModel? ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id); + + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ShopBindingModel model) + { + CheckModel(model); + + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ShopBindingModel model) + { + CheckModel(model); + + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + public bool SupplyDocuments(ShopSearchModel model, IDocumentModel document, int count) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (document == null) + { + throw new ArgumentNullException(nameof(document)); + } + if (count <= 0) + { + throw new ArgumentException("Количество изделий должно быть больше 0", nameof(count)); + } + _logger.LogInformation("AddPlaneInShop. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id); + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("AddPlaneInShop element not found"); + return false; + } + _logger.LogInformation("AddPlaneInShop find. Id:{Id}", element.Id); + + if (element.ShopDocuments.TryGetValue(document.Id, out var pair)) + { + element.ShopDocuments[document.Id] = (document, count + pair.Item2); + _logger.LogInformation("AddPlaneInShop. Added {count} {plane} to '{ShopName}' shop", count, document.DocumentName, element.ShopName); + } + else + { + element.ShopDocuments[document.Id] = (document, count); + _logger.LogInformation("AddPlaneInShop. Added {count} new plane {plane} to '{ShopName}' shop", count,document.DocumentName, element.ShopName); + } + + _shopStorage.Update(new() + { + Id = element.Id, + Address = element.Address, + ShopName = element.ShopName, + OpeningDate = element.OpeningDate, + ShopDocuments = element.ShopDocuments + }); + 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:{ShopName}.Address:{ Address}. Id:{ Id}", 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("Магазин с таким названием уже есть"); + } + } + } +} diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/ShopBindingModel.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..b3fb02d --- /dev/null +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,26 @@ +using AbstractLawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + + public string ShopName { get; set; } = string.Empty; + + public string Address { get; set; } = string.Empty; + + public DateTime OpeningDate { get; set; } = DateTime.Now; + + public Dictionary ShopDocuments + { + get; + set; + } = new(); + } +} diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IShopLogic.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..da2f762 --- /dev/null +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,22 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmContracts.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 SupplyDocuments(ShopSearchModel model, IDocumentModel document, int count); + } +} diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/ShopSearchModel.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..34e0b05 --- /dev/null +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + public string? ShopName { get; set; } + } +} diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/StoragesContracts/IShopStorage.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..8f3360b --- /dev/null +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,21 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmContracts.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/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ShopViewModel.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..e4de58c --- /dev/null +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,29 @@ +using AbstractLawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + + [DisplayName("Название магазина")] + public string ShopName { get; set; } = string.Empty; + + [DisplayName("Адрес магазина")] + public string Address { get; set; } = string.Empty; + + [DisplayName("Дата открытия")] + public DateTime OpeningDate { get; set; } = DateTime.Now; + public Dictionary ShopDocuments + { + get; + set; + } = new(); + } +} diff --git a/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IShopModel.cs b/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..cdca195 --- /dev/null +++ b/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IShopModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmDataModels.Models +{ + public interface IShopModel : IId + { + String ShopName { get; } + String Address { get; } + DateTime OpeningDate { get; } + Dictionary ShopDocuments { get; } + } +} diff --git a/LawFirm/AbstractLawFirmListImplement/DataListSingleton.cs b/LawFirm/AbstractLawFirmListImplement/DataListSingleton.cs index ca1efab..5da0aec 100644 --- a/LawFirm/AbstractLawFirmListImplement/DataListSingleton.cs +++ b/LawFirm/AbstractLawFirmListImplement/DataListSingleton.cs @@ -13,11 +13,13 @@ namespace AbstractLawFirmListImplement public List Components { get; set; } public List Orders { get; set; } public List Documents { get; set; } + public List Shops { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Documents = new List(); + Shops = new List(); } public static DataListSingleton GetInstance() { diff --git a/LawFirm/AbstractLawFirmListImplement/Implements/ShopStorage.cs b/LawFirm/AbstractLawFirmListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..aa88ff1 --- /dev/null +++ b/LawFirm/AbstractLawFirmListImplement/Implements/ShopStorage.cs @@ -0,0 +1,118 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.StoragesContracts; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmListImplement.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/AbstractLawFirmListImplement/Models/Shop.cs b/LawFirm/AbstractLawFirmListImplement/Models/Shop.cs new file mode 100644 index 0000000..144fea1 --- /dev/null +++ b/LawFirm/AbstractLawFirmListImplement/Models/Shop.cs @@ -0,0 +1,60 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + public string ShopName { get; private set; } = string.Empty; + public string Address { get; private set; } = string.Empty; + public DateTime OpeningDate { get; private set; } + public Dictionary 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, + OpeningDate = model.OpeningDate, + ShopDocuments = model.ShopDocuments + }; + } + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + + ShopName = model.ShopName; + Address = model.Address; + OpeningDate = model.OpeningDate; + ShopDocuments = model.ShopDocuments; + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + OpeningDate = OpeningDate, + ShopDocuments = ShopDocuments + }; + } +} diff --git a/LawFirm/LawFirmView/FormMain.Designer.cs b/LawFirm/LawFirmView/FormMain.Designer.cs index 6d9d80f..a32ae7a 100644 --- a/LawFirm/LawFirmView/FormMain.Designer.cs +++ b/LawFirm/LawFirmView/FormMain.Designer.cs @@ -38,6 +38,8 @@ this.buttonOrderReady = new System.Windows.Forms.Button(); this.buttonIssuedOrder = new System.Windows.Forms.Button(); this.buttonRef = new System.Windows.Forms.Button(); + this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.buttonSupplyShop = new System.Windows.Forms.Button(); this.menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -56,7 +58,8 @@ // this.toolStripMenuItemCatalogs.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.компонентыToolStripMenuItem, - this.пакетыДокументовToolStripMenuItem}); + this.пакетыДокументовToolStripMenuItem, + this.магазиныToolStripMenuItem}); this.toolStripMenuItemCatalogs.Name = "toolStripMenuItemCatalogs"; this.toolStripMenuItemCatalogs.Size = new System.Drawing.Size(94, 20); this.toolStripMenuItemCatalogs.Text = "Справочники"; @@ -134,11 +137,29 @@ this.buttonRef.UseVisualStyleBackColor = true; this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click); // + // магазиныToolStripMenuItem + // + this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(183, 22); + this.магазиныToolStripMenuItem.Text = "Магазины"; + this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click); + // + // buttonSupplyShop + // + this.buttonSupplyShop.Location = new System.Drawing.Point(742, 187); + this.buttonSupplyShop.Name = "buttonSupplyShop"; + this.buttonSupplyShop.Size = new System.Drawing.Size(156, 23); + this.buttonSupplyShop.TabIndex = 7; + this.buttonSupplyShop.Text = "Пополнение магазина"; + this.buttonSupplyShop.UseVisualStyleBackColor = true; + this.buttonSupplyShop.Click += new System.EventHandler(this.buttonSupplyShop_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(910, 477); + this.Controls.Add(this.buttonSupplyShop); this.Controls.Add(this.buttonRef); this.Controls.Add(this.buttonIssuedOrder); this.Controls.Add(this.buttonOrderReady); @@ -170,5 +191,7 @@ private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonRef; + private ToolStripMenuItem магазиныToolStripMenuItem; + private Button buttonSupplyShop; } } \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormMain.cs b/LawFirm/LawFirmView/FormMain.cs index 134665b..859aad6 100644 --- a/LawFirm/LawFirmView/FormMain.cs +++ b/LawFirm/LawFirmView/FormMain.cs @@ -176,5 +176,23 @@ namespace LawFirmView DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }; } + + private void buttonSupplyShop_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShopSupply)); + if (service is FormShopSupply form) + { + form.ShowDialog(); + } + } + + private void магазиныToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } } } diff --git a/LawFirm/LawFirmView/FormShop.Designer.cs b/LawFirm/LawFirmView/FormShop.Designer.cs new file mode 100644 index 0000000..7eecfa1 --- /dev/null +++ b/LawFirm/LawFirmView/FormShop.Designer.cs @@ -0,0 +1,182 @@ +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.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxAddress = new System.Windows.Forms.TextBox(); + this.dateTimePicker = 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.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(122, 12); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(200, 23); + this.textBoxName.TabIndex = 0; + // + // textBoxAddress + // + this.textBoxAddress.Location = new System.Drawing.Point(122, 41); + this.textBoxAddress.Name = "textBoxAddress"; + this.textBoxAddress.Size = new System.Drawing.Size(200, 23); + this.textBoxAddress.TabIndex = 1; + // + // dateTimePicker + // + this.dateTimePicker.Location = new System.Drawing.Point(122, 70); + this.dateTimePicker.Name = "dateTimePicker"; + this.dateTimePicker.Size = new System.Drawing.Size(200, 23); + this.dateTimePicker.TabIndex = 2; + // + // dataGridView + // + this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Column1, + this.Column2, + this.Column3}); + this.dataGridView.Location = new System.Drawing.Point(12, 99); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(536, 245); + this.dataGridView.TabIndex = 3; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(347, 371); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(445, 371); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(42, 15); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(62, 15); + this.label1.TabIndex = 6; + this.label1.Text = "Название:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(52, 44); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(43, 15); + this.label2.TabIndex = 7; + this.label2.Text = "Адрес:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(26, 76); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(90, 15); + this.label3.TabIndex = 8; + this.label3.Text = "Дата открытия:"; + // + // Column1 + // + this.Column1.HeaderText = "id"; + this.Column1.Name = "Column1"; + this.Column1.Visible = false; + // + // Column2 + // + this.Column2.HeaderText = "Название пакета документов"; + this.Column2.Name = "Column2"; + // + // Column3 + // + this.Column3.HeaderText = "Количество"; + this.Column3.Name = "Column3"; + // + // FormShop + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(560, 418); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.dateTimePicker); + this.Controls.Add(this.textBoxAddress); + this.Controls.Add(this.textBoxName); + this.Name = "FormShop"; + this.Text = "FormShop"; + this.Load += new System.EventHandler(this.FormShop_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private TextBox textBoxName; + private TextBox textBoxAddress; + private DateTimePicker dateTimePicker; + private DataGridView dataGridView; + private Button buttonSave; + private Button buttonCancel; + private Label label1; + private Label label2; + private Label label3; + private DataGridViewTextBoxColumn Column1; + private DataGridViewTextBoxColumn Column2; + private DataGridViewTextBoxColumn Column3; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormShop.cs b/LawFirm/LawFirmView/FormShop.cs new file mode 100644 index 0000000..7de152f --- /dev/null +++ b/LawFirm/LawFirmView/FormShop.cs @@ -0,0 +1,133 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.BusinessLogicsContracts; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace LawFirmView +{ + public partial class FormShop : Form + { + private readonly IShopLogic _logic; + private readonly ILogger _logger; + private Dictionary _shopDocuments; + private int? _id; + public int Id { set { _id = value; } } + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _shopDocuments = new(); + } + + 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; + _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 pc in _shopDocuments) + { + dataGridView.Rows.Add(new object[] + { + pc.Key, + pc.Value.Item1.DocumentName, + pc.Value.Item2 + } + ); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки документов магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Address = textBoxAddress.Text, + OpeningDate = dateTimePicker.Value.Date, + 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..cdfa6a5 --- /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/FormShopSupply.Designer.cs b/LawFirm/LawFirmView/FormShopSupply.Designer.cs new file mode 100644 index 0000000..5f31857 --- /dev/null +++ b/LawFirm/LawFirmView/FormShopSupply.Designer.cs @@ -0,0 +1,143 @@ +namespace LawFirmView +{ + partial class FormShopSupply + { + /// + /// 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.comboBoxShop = new System.Windows.Forms.ComboBox(); + this.comboBoxDocument = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // comboBoxShop + // + this.comboBoxShop.FormattingEnabled = true; + this.comboBoxShop.Location = new System.Drawing.Point(98, 12); + this.comboBoxShop.Name = "comboBoxShop"; + this.comboBoxShop.Size = new System.Drawing.Size(213, 23); + this.comboBoxShop.TabIndex = 0; + // + // comboBoxDocument + // + this.comboBoxDocument.FormattingEnabled = true; + this.comboBoxDocument.Location = new System.Drawing.Point(98, 41); + this.comboBoxDocument.Name = "comboBoxDocument"; + this.comboBoxDocument.Size = new System.Drawing.Size(213, 23); + this.comboBoxDocument.TabIndex = 1; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(98, 70); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(213, 23); + this.textBoxCount.TabIndex = 2; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(98, 122); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 3; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(221, 122); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 4; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(21, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(66, 15); + this.label1.TabIndex = 5; + this.label1.Text = "Магазины:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(14, 44); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(73, 15); + this.label2.TabIndex = 6; + this.label2.Text = "Документы:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(14, 73); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(75, 15); + this.label3.TabIndex = 7; + this.label3.Text = "Количество:"; + // + // FormShopSupply + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(358, 159); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxDocument); + this.Controls.Add(this.comboBoxShop); + this.Name = "FormShopSupply"; + this.Text = "FormShopSupply"; + this.Load += new System.EventHandler(this.FormShopSupply_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxShop; + private ComboBox comboBoxDocument; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + private Label label1; + private Label label2; + private Label label3; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormShopSupply.cs b/LawFirm/LawFirmView/FormShopSupply.cs new file mode 100644 index 0000000..2ca73de --- /dev/null +++ b/LawFirm/LawFirmView/FormShopSupply.cs @@ -0,0 +1,125 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.BusinessLogicsContracts; +using AbstractLawFirmContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace LawFirmView +{ + public partial class FormShopSupply : Form + { + private readonly ILogger _logger; + private readonly IDocumentLogic _logicD; + private readonly IShopLogic _logicS; + public FormShopSupply(ILogger logger, IDocumentLogic logicD, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicD = logicD; + _logicS = logicS; + } + + private void FormShopSupply_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка документов для пополнения"); + try + { + var list = _logicD.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 = _logicS.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(textBoxCount.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 = _logicS.SupplyDocuments( + new ShopSearchModel + { + Id = Convert.ToInt32(comboBoxShop.SelectedValue), + ShopName = comboBoxShop.Text + }, + new DocumentBindingModel + { + Id = Convert.ToInt32(comboBoxDocument.SelectedValue), + DocumentName = comboBoxDocument.Text + }, + Convert.ToInt32(textBoxCount.Text) + ); + if (!operationResult) + { + throw new Exception("Ошибка при создании поставки. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания поставки"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/LawFirm/LawFirmView/FormShopSupply.resx b/LawFirm/LawFirmView/FormShopSupply.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/LawFirm/LawFirmView/FormShopSupply.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/FormShops.Designer.cs b/LawFirm/LawFirmView/FormShops.Designer.cs new file mode 100644 index 0000000..c314196 --- /dev/null +++ b/LawFirm/LawFirmView/FormShops.Designer.cs @@ -0,0 +1,114 @@ +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.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(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(450, 21); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(75, 23); + this.buttonAdd.TabIndex = 0; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonUpd + // + this.buttonUpd.Location = new System.Drawing.Point(450, 62); + this.buttonUpd.Name = "buttonUpd"; + this.buttonUpd.Size = new System.Drawing.Size(75, 23); + this.buttonUpd.TabIndex = 1; + this.buttonUpd.Text = "Изменить"; + this.buttonUpd.UseVisualStyleBackColor = true; + this.buttonUpd.Click += new System.EventHandler(this.buttonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(450, 104); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(75, 23); + this.buttonDel.TabIndex = 2; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.buttonDel_Click); + // + // buttonRef + // + this.buttonRef.Location = new System.Drawing.Point(450, 143); + this.buttonRef.Name = "buttonRef"; + this.buttonRef.Size = new System.Drawing.Size(75, 23); + this.buttonRef.TabIndex = 3; + this.buttonRef.Text = "Обновить"; + this.buttonRef.UseVisualStyleBackColor = true; + this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(428, 368); + this.dataGridView.TabIndex = 4; + // + // FormShops + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(558, 380); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.buttonRef); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonUpd); + this.Controls.Add(this.buttonAdd); + this.Name = "FormShops"; + this.Text = "FormShops"; + this.Load += new System.EventHandler(this.FormShops_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormShops.cs b/LawFirm/LawFirmView/FormShops.cs new file mode 100644 index 0000000..04fc851 --- /dev/null +++ b/LawFirm/LawFirmView/FormShops.cs @@ -0,0 +1,122 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace 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 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(); + } + + 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["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ShopDocuments"].Visible = false; + } + + _logger.LogInformation("Загрузка магазинов"); + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } +} 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 ab37d8c..1ee4c75 100644 --- a/LawFirm/LawFirmView/Program.cs +++ b/LawFirm/LawFirmView/Program.cs @@ -37,9 +37,11 @@ namespace LawFirmView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -47,6 +49,9 @@ namespace LawFirmView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } From ef300b17eab75a2882e62642f50d63e144f88349 Mon Sep 17 00:00:00 2001 From: AnnaLioness Date: Mon, 26 Feb 2024 11:09:55 +0400 Subject: [PATCH 2/7] =?UTF-8?q?=D0=BC=D0=B5=D0=BB=D0=BA=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirmView/FormShop.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/LawFirm/LawFirmView/FormShop.cs b/LawFirm/LawFirmView/FormShop.cs index 7de152f..cf7d42b 100644 --- a/LawFirm/LawFirmView/FormShop.cs +++ b/LawFirm/LawFirmView/FormShop.cs @@ -45,6 +45,7 @@ namespace LawFirmView { textBoxName.Text = view.ShopName; textBoxAddress.Text = view.Address; + dateTimePicker.Value = view.OpeningDate; _shopDocuments = view.ShopDocuments ?? new Dictionary(); LoadData(); } From d256b76957d8d6438a07a5fe97bd21bbfa0a1838 Mon Sep 17 00:00:00 2001 From: AnnaLioness Date: Sun, 10 Mar 2024 22:47:50 +0400 Subject: [PATCH 3/7] =?UTF-8?q?=D0=B2=D1=80=D0=BE=D0=B4=D0=B5=20=D0=B3?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B2=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/OrderLogic.cs | 100 ++++++++++++- .../BusinessLogic/ShopLogic.cs | 45 ++++-- .../BindingModels/ShopBindingModel.cs | 1 + .../BusinessLogicsContracts/IShopLogic.cs | 1 + .../StoragesContracts/IShopStorage.cs | 2 + .../ViewModels/ShopViewModel.cs | 2 + .../Models/IShopModel.cs | 1 + .../DataFileSingleton.cs | 5 + .../Implements/ShopStorage.cs | 137 ++++++++++++++++++ .../Models/Shop.cs | 113 +++++++++++++++ .../Implements/ShopStorage.cs | 5 + .../Models/Shop.cs | 1 + LawFirm/LawFirmView/FormMain.Designer.cs | 29 +++- LawFirm/LawFirmView/FormMain.cs | 9 ++ .../LawFirmView/FormSellDocuments.Designer.cs | 120 +++++++++++++++ LawFirm/LawFirmView/FormSellDocuments.cs | 94 ++++++++++++ LawFirm/LawFirmView/FormSellDocuments.resx | 60 ++++++++ LawFirm/LawFirmView/FormShop.Designer.cs | 132 ++++++++++------- LawFirm/LawFirmView/FormShop.cs | 7 + LawFirm/LawFirmView/Program.cs | 1 + 20 files changed, 785 insertions(+), 80 deletions(-) create mode 100644 LawFirm/AbstractLawFirmFileImplement/Implements/ShopStorage.cs create mode 100644 LawFirm/AbstractLawFirmFileImplement/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/AbstractLawFirmBusinessLogic/BusinessLogic/OrderLogic.cs b/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/OrderLogic.cs index cf6376c..fdcfe9f 100644 --- a/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/OrderLogic.cs @@ -4,6 +4,7 @@ using AbstractLawFirmContracts.SearchModels; using AbstractLawFirmContracts.StoragesContracts; using AbstractLawFirmContracts.ViewModels; using AbstractLawFirmDataModels.Enums; +using AbstractLawFirmDataModels.Models; using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; @@ -17,11 +18,17 @@ namespace AbstractLawFirmBusinessLogic.BusinessLogic { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; + private readonly IShopLogic _shopLogic; + private readonly IDocumentStorage _documentStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopLogic shopLogic, IDocumentStorage documentStorage, IShopStorage shopStorage) { _logger = logger; _orderStorage = orderStorage; + _shopLogic = shopLogic; + _documentStorage = documentStorage; + _shopStorage = shopStorage; } public List? ReadList(OrderSearchModel? model) @@ -45,6 +52,7 @@ namespace AbstractLawFirmBusinessLogic.BusinessLogic model.Status = OrderStatus.Принят; if (_orderStorage.Insert(model) == null) { + model.Status = OrderStatus.Неизвестен; _logger.LogWarning("Insert operation failed"); return false; } @@ -53,7 +61,7 @@ namespace AbstractLawFirmBusinessLogic.BusinessLogic public bool ChangeStatus(OrderBindingModel model, OrderStatus status) { - CheckModel(model); + CheckModel(model, false); var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); if (element == null) { @@ -65,9 +73,31 @@ namespace AbstractLawFirmBusinessLogic.BusinessLogic _logger.LogWarning("Status change operation failed"); throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); } + if (status == OrderStatus.Готов) + { + var document = _documentStorage.GetElement(new DocumentSearchModel() { Id = model.DocumentId }); + if (document == null) + { + _logger.LogWarning("Status change operation failed. Car not found."); + return false; + } + + if (!CheckThenSupplyMany(document, model.Count)) + { + _logger.LogWarning("Status change operation failed. Shop supply error."); + return false; + } + } + model.Status = status; if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; _orderStorage.Update(model); + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Update operation failed"); + return false; + } return true; } @@ -97,6 +127,10 @@ true) { return; } + if (model.DocumentId < 0) + { + throw new ArgumentNullException("Некорректный идентификатор документа", nameof(model.DocumentId)); + } if (model.Sum <= 0) { throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum)); @@ -107,5 +141,67 @@ true) } _logger.LogInformation("Order. Sum:{ Cost}. Id: { Id}", model.Sum, model.Id); } + public bool CheckThenSupplyMany(IDocumentModel document, int count) + { + if (count <= 0) + { + _logger.LogWarning("Check then supply operation error. Car count < 0."); + return false; + } + + int freeSpace = 0; + foreach (var shop in _shopStorage.GetFullList()) + { + freeSpace += shop.MaxCountDocuments; + foreach (var c in shop.ShopDocuments) + { + freeSpace -= c.Value.Item2; + } + } + + if (freeSpace < count) + { + _logger.LogWarning("Check then supply operation error. There's no place for new cars in shops."); + return false; + } + + foreach (var shop in _shopStorage.GetFullList()) + { + freeSpace = shop.MaxCountDocuments; + + foreach (var c in shop.ShopDocuments) + freeSpace -= c.Value.Item2; + + if (freeSpace <= 0) + continue; + + if (freeSpace >= count) + { + if (_shopLogic.SupplyDocuments(new ShopSearchModel() { Id = shop.Id }, document, count)) + count = 0; + else + { + _logger.LogWarning("Supply error"); + return false; + } + } + if (freeSpace < count) + { + if (_shopLogic.SupplyDocuments(new ShopSearchModel() { Id = shop.Id }, document, freeSpace)) + count -= freeSpace; + else + { + _logger.LogWarning("Supply error"); + return false; + } + } + if (count <= 0) + { + return true; + } + } + return false; + } + } } diff --git a/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/ShopLogic.cs b/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/ShopLogic.cs index fa2931e..5edb0db 100644 --- a/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/ShopLogic.cs +++ b/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/ShopLogic.cs @@ -112,26 +112,37 @@ namespace AbstractLawFirmBusinessLogic.BusinessLogic return false; } _logger.LogInformation("AddPlaneInShop find. Id:{Id}", element.Id); - - if (element.ShopDocuments.TryGetValue(document.Id, out var pair)) + int countDocuments = 0; + foreach (var c in element.ShopDocuments) + countDocuments += c.Value.Item2; + if (count > element.MaxCountDocuments - countDocuments) { - element.ShopDocuments[document.Id] = (document, count + pair.Item2); - _logger.LogInformation("AddPlaneInShop. Added {count} {plane} to '{ShopName}' shop", count, document.DocumentName, element.ShopName); + _logger.LogWarning("Required shop will be overflowed"); + return false; } else { - element.ShopDocuments[document.Id] = (document, count); - _logger.LogInformation("AddPlaneInShop. Added {count} new plane {plane} to '{ShopName}' shop", count,document.DocumentName, element.ShopName); - } + if (element.ShopDocuments.TryGetValue(document.Id, out var pair)) + { + element.ShopDocuments[document.Id] = (document, count + pair.Item2); + _logger.LogInformation("AddPlaneInShop. Added {count} {plane} to '{ShopName}' shop", count, document.DocumentName, element.ShopName); + } + else + { + element.ShopDocuments[document.Id] = (document, count); + _logger.LogInformation("AddPlaneInShop. Added {count} new plane {plane} to '{ShopName}' shop", count, document.DocumentName, element.ShopName); + } - _shopStorage.Update(new() - { - Id = element.Id, - Address = element.Address, - ShopName = element.ShopName, - OpeningDate = element.OpeningDate, - ShopDocuments = element.ShopDocuments - }); + _shopStorage.Update(new() + { + Id = element.Id, + Address = element.Address, + ShopName = element.ShopName, + MaxCountDocuments = element.MaxCountDocuments, + OpeningDate = element.OpeningDate, + ShopDocuments = element.ShopDocuments + }); + } return true; } private void CheckModel(ShopBindingModel model, bool withParams = true) @@ -158,5 +169,9 @@ namespace AbstractLawFirmBusinessLogic.BusinessLogic throw new InvalidOperationException("Магазин с таким названием уже есть"); } } + public bool SellDocument(IDocumentModel document, int count) + { + return _shopStorage.SellDocument(document, count); + } } } diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/ShopBindingModel.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/ShopBindingModel.cs index b3fb02d..d3aae79 100644 --- a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/ShopBindingModel.cs +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BindingModels/ShopBindingModel.cs @@ -22,5 +22,6 @@ namespace AbstractLawFirmContracts.BindingModels get; set; } = new(); + public int MaxCountDocuments { get; set; } } } diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IShopLogic.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IShopLogic.cs index da2f762..26afec2 100644 --- a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IShopLogic.cs @@ -18,5 +18,6 @@ namespace AbstractLawFirmContracts.BusinessLogicsContracts bool Update(ShopBindingModel model); bool Delete(ShopBindingModel model); bool SupplyDocuments(ShopSearchModel model, IDocumentModel document, int count); + bool SellDocument(IDocumentModel document, int count); } } diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/StoragesContracts/IShopStorage.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/StoragesContracts/IShopStorage.cs index 8f3360b..28ada54 100644 --- a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/StoragesContracts/IShopStorage.cs +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/StoragesContracts/IShopStorage.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using AbstractLawFirmDataModels.Models; namespace AbstractLawFirmContracts.StoragesContracts { @@ -17,5 +18,6 @@ namespace AbstractLawFirmContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); + bool SellDocument(IDocumentModel model, int count); } } diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ShopViewModel.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ShopViewModel.cs index e4de58c..4ea4f6d 100644 --- a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ShopViewModel.cs +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ShopViewModel.cs @@ -25,5 +25,7 @@ namespace AbstractLawFirmContracts.ViewModels get; set; } = new(); + [DisplayName("Максимальное количество пакетов документов в магазине")] + public int MaxCountDocuments { get; set; } } } diff --git a/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IShopModel.cs b/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IShopModel.cs index cdca195..45c3458 100644 --- a/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IShopModel.cs +++ b/LawFirm/AbstractLawFirmDataModels/AbstractLawFirmDataModels/Models/IShopModel.cs @@ -12,5 +12,6 @@ namespace AbstractLawFirmDataModels.Models String Address { get; } DateTime OpeningDate { get; } Dictionary ShopDocuments { get; } + int MaxCountDocuments { get; } } } diff --git a/LawFirm/AbstractLawFirmFileImplement/DataFileSingleton.cs b/LawFirm/AbstractLawFirmFileImplement/DataFileSingleton.cs index 33d0b0c..30e9b9c 100644 --- a/LawFirm/AbstractLawFirmFileImplement/DataFileSingleton.cs +++ b/LawFirm/AbstractLawFirmFileImplement/DataFileSingleton.cs @@ -14,9 +14,12 @@ namespace AbstractLawFirmFileImplement private readonly string ComponentFileName = "Component.xml"; private readonly string OrderFileName = "Order.xml"; private readonly string DocumentFileName = "Document.xml"; + private readonly string ShopFileName = "Shop.xml"; + public List Components { get; private set; } public List Orders { get; private set; } public List Documents { get; private set; } + public List Shops { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -28,11 +31,13 @@ namespace AbstractLawFirmFileImplement public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); public void SaveDocuments() => SaveData(Documents, DocumentFileName, "Documents", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Documents = LoadData(DocumentFileName, "Document", x => Document.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) diff --git a/LawFirm/AbstractLawFirmFileImplement/Implements/ShopStorage.cs b/LawFirm/AbstractLawFirmFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..d53eb91 --- /dev/null +++ b/LawFirm/AbstractLawFirmFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,137 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.StoragesContracts; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataModels.Models; +using AbstractLawFirmFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmFileImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataFileSingleton source; + public ShopStorage() + { + source = DataFileSingleton.GetInstance(); + } + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + return source.Shops.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel; + } + + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName)) + { + return new(); + } + return source.Shops + .Select(x => x.GetViewModel) + .Where(x => x.ShopName.Contains(model.ShopName ?? string.Empty)) + .ToList(); + } + + public List GetFullList() + { + return source.Shops.Select(shop => shop.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) + { + return null; + } + source.Shops.Remove(shop); + source.SaveShops(); + return shop.GetViewModel; + } + + public bool SellDocument(IDocumentModel model, int count) + { + var car = source.Documents.FirstOrDefault(x => x.Id == model.Id); + + if (car == null) + { + return false; + } + + + var shopDocuments = source.Shops.SelectMany(shop => shop.ShopDocuments.Where(c => c.Value.Item1.Id == car.Id)); + + int countStore = 0; + + foreach (var it in shopDocuments) + countStore += it.Value.Item2; + + if (count > countStore) + return false; + + foreach (var shop in source.Shops) + { + var documents = shop.ShopDocuments; + + foreach (var c in documents.Where(x => x.Value.Item1.Id == car.Id)) + { + int min = Math.Min(c.Value.Item2, count); + documents[c.Value.Item1.Id] = (c.Value.Item1, c.Value.Item2 - min); + count -= min; + + if (count <= 0) + break; + } + + shop.Update(new ShopBindingModel + { + Id = shop.Id, + ShopName = shop.ShopName, + Address = shop.Address, + MaxCountDocuments = shop.MaxCountDocuments, + OpeningDate = shop.OpeningDate, + ShopDocuments = documents + }); + + source.SaveShops(); + + if (count <= 0) + return true; + } + + return true; + } + } +} diff --git a/LawFirm/AbstractLawFirmFileImplement/Models/Shop.cs b/LawFirm/AbstractLawFirmFileImplement/Models/Shop.cs new file mode 100644 index 0000000..8358815 --- /dev/null +++ b/LawFirm/AbstractLawFirmFileImplement/Models/Shop.cs @@ -0,0 +1,113 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace AbstractLawFirmFileImplement.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 int MaxCountDocuments { get; private set; } + public DateTime OpeningDate { get; private set; } + public Dictionary Documents { get; private set; } = new(); + private Dictionary? _shopDocuments = null; + public Dictionary ShopDocuments + { + get + { + if (_shopDocuments == null) + { + var source = DataFileSingleton.GetInstance(); + _shopDocuments = Documents.ToDictionary( + x => x.Key, + y => ((source.Documents.FirstOrDefault(z => z.Id == y.Key) as IDocumentModel)!, y.Value) + ); + } + return _shopDocuments; + } + } + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + MaxCountDocuments = model.MaxCountDocuments, + OpeningDate = model.OpeningDate, + Documents = 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, + MaxCountDocuments = Convert.ToInt32(element.Element("MaxCountDocuments")!.Value), + OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value), + Documents = element.Element("ShopDocuments")!.Elements("ShopDocument").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; + MaxCountDocuments = model.MaxCountDocuments; + OpeningDate = model.OpeningDate; + if (model.ShopDocuments.Count > 0) + { + Documents = model.ShopDocuments.ToDictionary(x => x.Key, x => x.Value.Item2); + _shopDocuments = null; + } + } + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + MaxCountDocuments = MaxCountDocuments, + OpeningDate = OpeningDate, + ShopDocuments = ShopDocuments, + }; + + public XElement GetXElement => new( + "Shop", + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("Address", Address), + new XElement("MaxCountDocuments", MaxCountDocuments), + new XElement("OpeningDate", OpeningDate.ToString()), + new XElement("ShopDocuments", Documents.Select(x => + new XElement("ShopDocument", + new XElement("Key", x.Key), + new XElement("Value", x.Value))) + .ToArray())); + } +} diff --git a/LawFirm/AbstractLawFirmListImplement/Implements/ShopStorage.cs b/LawFirm/AbstractLawFirmListImplement/Implements/ShopStorage.cs index aa88ff1..3d67091 100644 --- a/LawFirm/AbstractLawFirmListImplement/Implements/ShopStorage.cs +++ b/LawFirm/AbstractLawFirmListImplement/Implements/ShopStorage.cs @@ -3,6 +3,7 @@ using AbstractLawFirmContracts.SearchModels; using AbstractLawFirmContracts.StoragesContracts; using AbstractLawFirmContracts.ViewModels; using AbstractLawFirmListImplement.Models; +using AbstractLawFirmDataModels.Models; using System; using System.Collections.Generic; using System.Linq; @@ -14,6 +15,10 @@ namespace AbstractLawFirmListImplement.Implements public class ShopStorage : IShopStorage { private readonly DataListSingleton _source; + public bool SellDocument(IDocumentModel document, int count) + { + throw new NotImplementedException(); + } public ShopStorage() { diff --git a/LawFirm/AbstractLawFirmListImplement/Models/Shop.cs b/LawFirm/AbstractLawFirmListImplement/Models/Shop.cs index 144fea1..92430c3 100644 --- a/LawFirm/AbstractLawFirmListImplement/Models/Shop.cs +++ b/LawFirm/AbstractLawFirmListImplement/Models/Shop.cs @@ -14,6 +14,7 @@ namespace AbstractLawFirmListImplement.Models public int Id { get; private set; } public string ShopName { get; private set; } = string.Empty; public string Address { get; private set; } = string.Empty; + public int MaxCountDocuments { get; private set; } public DateTime OpeningDate { get; private set; } public Dictionary ShopDocuments { diff --git a/LawFirm/LawFirmView/FormMain.Designer.cs b/LawFirm/LawFirmView/FormMain.Designer.cs index a32ae7a..7af45c1 100644 --- a/LawFirm/LawFirmView/FormMain.Designer.cs +++ b/LawFirm/LawFirmView/FormMain.Designer.cs @@ -32,14 +32,15 @@ this.toolStripMenuItemCatalogs = 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.buttonRef = new System.Windows.Forms.Button(); - this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.buttonSupplyShop = new System.Windows.Forms.Button(); + this.buttonSellDocs = new System.Windows.Forms.Button(); this.menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -78,6 +79,13 @@ this.пакетыДокументовToolStripMenuItem.Text = "Пакеты документов"; this.пакетыДокументовToolStripMenuItem.Click += new System.EventHandler(this.пакетыДокументовToolStripMenuItem_Click); // + // магазиныToolStripMenuItem + // + this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(183, 22); + this.магазиныToolStripMenuItem.Text = "Магазины"; + this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click); + // // dataGridView // this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -137,13 +145,6 @@ this.buttonRef.UseVisualStyleBackColor = true; this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click); // - // магазиныToolStripMenuItem - // - this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; - this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(183, 22); - this.магазиныToolStripMenuItem.Text = "Магазины"; - this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click); - // // buttonSupplyShop // this.buttonSupplyShop.Location = new System.Drawing.Point(742, 187); @@ -154,11 +155,22 @@ this.buttonSupplyShop.UseVisualStyleBackColor = true; this.buttonSupplyShop.Click += new System.EventHandler(this.buttonSupplyShop_Click); // + // buttonSellDocs + // + this.buttonSellDocs.Location = new System.Drawing.Point(742, 216); + this.buttonSellDocs.Name = "buttonSellDocs"; + this.buttonSellDocs.Size = new System.Drawing.Size(156, 23); + this.buttonSellDocs.TabIndex = 8; + this.buttonSellDocs.Text = "Продать документы"; + this.buttonSellDocs.UseVisualStyleBackColor = true; + this.buttonSellDocs.Click += new System.EventHandler(this.buttonSellDocs_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(910, 477); + this.Controls.Add(this.buttonSellDocs); this.Controls.Add(this.buttonSupplyShop); this.Controls.Add(this.buttonRef); this.Controls.Add(this.buttonIssuedOrder); @@ -193,5 +205,6 @@ private Button buttonRef; private ToolStripMenuItem магазиныToolStripMenuItem; private Button buttonSupplyShop; + private Button buttonSellDocs; } } \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormMain.cs b/LawFirm/LawFirmView/FormMain.cs index 859aad6..753cbf7 100644 --- a/LawFirm/LawFirmView/FormMain.cs +++ b/LawFirm/LawFirmView/FormMain.cs @@ -194,5 +194,14 @@ namespace LawFirmView form.ShowDialog(); } } + + private void buttonSellDocs_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSellDocuments)); + if (service is FormSellDocuments form) + { + form.ShowDialog(); + } + } } } diff --git a/LawFirm/LawFirmView/FormSellDocuments.Designer.cs b/LawFirm/LawFirmView/FormSellDocuments.Designer.cs new file mode 100644 index 0000000..07cbb98 --- /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.comboBoxDoc = new System.Windows.Forms.ComboBox(); + this.label1 = new System.Windows.Forms.Label(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.label2 = new System.Windows.Forms.Label(); + this.buttonSell = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // comboBoxDoc + // + this.comboBoxDoc.FormattingEnabled = true; + this.comboBoxDoc.Location = new System.Drawing.Point(149, 12); + this.comboBoxDoc.Name = "comboBoxDoc"; + this.comboBoxDoc.Size = new System.Drawing.Size(218, 23); + this.comboBoxDoc.TabIndex = 0; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(24, 15); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(110, 15); + this.label1.TabIndex = 1; + this.label1.Text = "Пакет документов:"; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(149, 41); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(218, 23); + this.textBoxCount.TabIndex = 2; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(59, 49); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(75, 15); + this.label2.TabIndex = 4; + this.label2.Text = "Количество:"; + // + // buttonSell + // + this.buttonSell.Location = new System.Drawing.Point(149, 92); + this.buttonSell.Name = "buttonSell"; + this.buttonSell.Size = new System.Drawing.Size(75, 23); + this.buttonSell.TabIndex = 5; + this.buttonSell.Text = "Продать"; + this.buttonSell.UseVisualStyleBackColor = true; + this.buttonSell.Click += new System.EventHandler(this.buttonSell_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(259, 92); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 6; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // FormSellDocuments + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(394, 137); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSell); + this.Controls.Add(this.label2); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.label1); + this.Controls.Add(this.comboBoxDoc); + this.Name = "FormSellDocuments"; + this.Text = "FormSellDocuments"; + this.Load += new System.EventHandler(this.FormSellDocuments_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private ComboBox comboBoxDoc; + private Label label1; + private TextBox textBoxCount; + private Label label2; + private Button buttonSell; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormSellDocuments.cs b/LawFirm/LawFirmView/FormSellDocuments.cs new file mode 100644 index 0000000..5c730d9 --- /dev/null +++ b/LawFirm/LawFirmView/FormSellDocuments.cs @@ -0,0 +1,94 @@ +using AbstractLawFirmContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using AbstractLawFirmContracts.BindingModels; +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 IDocumentLogic _logicDocument; + private readonly IShopLogic _logicShop; + public FormSellDocuments(ILogger logger, IDocumentLogic logicDocument, IShopLogic logicShop) + { + InitializeComponent(); + _logger = logger; + _logicDocument = logicDocument; + _logicShop = logicShop; + } + + private void FormSellDocuments_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка документов для продажи"); + try + { + var list = _logicDocument.ReadList(null); + if (list != null) + { + comboBoxDoc.DisplayMember = "DocumentName"; + comboBoxDoc.ValueMember = "Id"; + comboBoxDoc.DataSource = list; + comboBoxDoc.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка документов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonSell_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxDoc.SelectedValue == null) + { + MessageBox.Show("Выберите пакет документов", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание продажи"); + try + { + var operationResult = _logicShop.SellDocument( + new DocumentBindingModel + { + Id = Convert.ToInt32(comboBoxDoc.SelectedValue) + }, + Convert.ToInt32(textBoxCount.Text) + ); + if (!operationResult) + { + throw new Exception("Ошибка при создании продажи. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания продажи"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} 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 7eecfa1..85f78a7 100644 --- a/LawFirm/LawFirmView/FormShop.Designer.cs +++ b/LawFirm/LawFirmView/FormShop.Designer.cs @@ -32,34 +32,36 @@ this.textBoxAddress = new System.Windows.Forms.TextBox(); this.dateTimePicker = new System.Windows.Forms.DateTimePicker(); this.dataGridView = new System.Windows.Forms.DataGridView(); + this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.buttonSave = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); - this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); - this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.textBoxMaxCountDoc = new System.Windows.Forms.TextBox(); + this.label4 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); // // textBoxName // - this.textBoxName.Location = new System.Drawing.Point(122, 12); + this.textBoxName.Location = new System.Drawing.Point(274, 15); this.textBoxName.Name = "textBoxName"; this.textBoxName.Size = new System.Drawing.Size(200, 23); this.textBoxName.TabIndex = 0; // // textBoxAddress // - this.textBoxAddress.Location = new System.Drawing.Point(122, 41); + this.textBoxAddress.Location = new System.Drawing.Point(274, 41); this.textBoxAddress.Name = "textBoxAddress"; this.textBoxAddress.Size = new System.Drawing.Size(200, 23); this.textBoxAddress.TabIndex = 1; // // dateTimePicker // - this.dateTimePicker.Location = new System.Drawing.Point(122, 70); + this.dateTimePicker.Location = new System.Drawing.Point(274, 102); this.dateTimePicker.Name = "dateTimePicker"; this.dateTimePicker.Size = new System.Drawing.Size(200, 23); this.dateTimePicker.TabIndex = 2; @@ -72,59 +74,12 @@ this.Column1, this.Column2, this.Column3}); - this.dataGridView.Location = new System.Drawing.Point(12, 99); + this.dataGridView.Location = new System.Drawing.Point(12, 155); this.dataGridView.Name = "dataGridView"; this.dataGridView.RowTemplate.Height = 25; this.dataGridView.Size = new System.Drawing.Size(536, 245); this.dataGridView.TabIndex = 3; // - // buttonSave - // - this.buttonSave.Location = new System.Drawing.Point(347, 371); - this.buttonSave.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(75, 23); - this.buttonSave.TabIndex = 4; - this.buttonSave.Text = "Сохранить"; - this.buttonSave.UseVisualStyleBackColor = true; - this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); - // - // buttonCancel - // - this.buttonCancel.Location = new System.Drawing.Point(445, 371); - this.buttonCancel.Name = "buttonCancel"; - this.buttonCancel.Size = new System.Drawing.Size(75, 23); - this.buttonCancel.TabIndex = 5; - this.buttonCancel.Text = "Отмена"; - this.buttonCancel.UseVisualStyleBackColor = true; - this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(42, 15); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(62, 15); - this.label1.TabIndex = 6; - this.label1.Text = "Название:"; - // - // label2 - // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(52, 44); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(43, 15); - this.label2.TabIndex = 7; - this.label2.Text = "Адрес:"; - // - // label3 - // - this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(26, 76); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(90, 15); - this.label3.TabIndex = 8; - this.label3.Text = "Дата открытия:"; - // // Column1 // this.Column1.HeaderText = "id"; @@ -141,11 +96,76 @@ this.Column3.HeaderText = "Количество"; this.Column3.Name = "Column3"; // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(346, 406); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(75, 23); + this.buttonSave.TabIndex = 4; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(445, 406); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 5; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(206, 18); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(62, 15); + this.label1.TabIndex = 6; + this.label1.Text = "Название:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(225, 44); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(43, 15); + this.label2.TabIndex = 7; + this.label2.Text = "Адрес:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(178, 108); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(90, 15); + this.label3.TabIndex = 8; + this.label3.Text = "Дата открытия:"; + // + // textBoxMaxCountDoc + // + this.textBoxMaxCountDoc.Location = new System.Drawing.Point(274, 73); + this.textBoxMaxCountDoc.Name = "textBoxMaxCountDoc"; + this.textBoxMaxCountDoc.Size = new System.Drawing.Size(200, 23); + this.textBoxMaxCountDoc.TabIndex = 9; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(42, 73); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(229, 15); + this.label4.TabIndex = 10; + this.label4.Text = "Максимальное количество документов:"; + // // FormShop // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(560, 418); + this.ClientSize = new System.Drawing.Size(649, 459); + this.Controls.Add(this.label4); + this.Controls.Add(this.textBoxMaxCountDoc); this.Controls.Add(this.label3); this.Controls.Add(this.label2); this.Controls.Add(this.label1); @@ -178,5 +198,7 @@ private DataGridViewTextBoxColumn Column1; private DataGridViewTextBoxColumn Column2; private DataGridViewTextBoxColumn Column3; + private TextBox textBoxMaxCountDoc; + private Label label4; } } \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormShop.cs b/LawFirm/LawFirmView/FormShop.cs index cf7d42b..ae11116 100644 --- a/LawFirm/LawFirmView/FormShop.cs +++ b/LawFirm/LawFirmView/FormShop.cs @@ -45,6 +45,7 @@ namespace LawFirmView { textBoxName.Text = view.ShopName; textBoxAddress.Text = view.Address; + textBoxMaxCountDoc.Text = view.MaxCountDocuments.ToString(); dateTimePicker.Value = view.OpeningDate; _shopDocuments = view.ShopDocuments ?? new Dictionary(); LoadData(); @@ -98,6 +99,11 @@ namespace LawFirmView MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + if (string.IsNullOrEmpty(textBoxMaxCountDoc.Text)) + { + MessageBox.Show("Заполните макс. количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } _logger.LogInformation("Сохранение магазина"); try { @@ -106,6 +112,7 @@ namespace LawFirmView Id = _id ?? 0, ShopName = textBoxName.Text, Address = textBoxAddress.Text, + MaxCountDocuments = Convert.ToInt32(textBoxMaxCountDoc.Text), OpeningDate = dateTimePicker.Value.Date, ShopDocuments = _shopDocuments }; diff --git a/LawFirm/LawFirmView/Program.cs b/LawFirm/LawFirmView/Program.cs index 47ca4ad..6948fef 100644 --- a/LawFirm/LawFirmView/Program.cs +++ b/LawFirm/LawFirmView/Program.cs @@ -52,6 +52,7 @@ namespace LawFirmView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } From 90535a3315a8b4eef3437c92fc0a4cc53b41ec33 Mon Sep 17 00:00:00 2001 From: AnnaLioness Date: Mon, 11 Mar 2024 11:03:01 +0400 Subject: [PATCH 4/7] =?UTF-8?q?=D0=BC=D0=B5=D0=BB=D0=BA=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ShopStorage.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/LawFirm/AbstractLawFirmFileImplement/Implements/ShopStorage.cs b/LawFirm/AbstractLawFirmFileImplement/Implements/ShopStorage.cs index d53eb91..5efdaf7 100644 --- a/LawFirm/AbstractLawFirmFileImplement/Implements/ShopStorage.cs +++ b/LawFirm/AbstractLawFirmFileImplement/Implements/ShopStorage.cs @@ -83,15 +83,15 @@ namespace AbstractLawFirmFileImplement.Implements public bool SellDocument(IDocumentModel model, int count) { - var car = source.Documents.FirstOrDefault(x => x.Id == model.Id); + var document = source.Documents.FirstOrDefault(x => x.Id == model.Id); - if (car == null) + if (document == null) { return false; } - var shopDocuments = source.Shops.SelectMany(shop => shop.ShopDocuments.Where(c => c.Value.Item1.Id == car.Id)); + var shopDocuments = source.Shops.SelectMany(shop => shop.ShopDocuments.Where(c => c.Value.Item1.Id == document.Id)); int countStore = 0; @@ -105,7 +105,7 @@ namespace AbstractLawFirmFileImplement.Implements { var documents = shop.ShopDocuments; - foreach (var c in documents.Where(x => x.Value.Item1.Id == car.Id)) + foreach (var c in documents.Where(x => x.Value.Item1.Id == document.Id)) { int min = Math.Min(c.Value.Item2, count); documents[c.Value.Item1.Id] = (c.Value.Item1, c.Value.Item2 - min); From f4a72b68f49ec65a513c069c8b779dd5b83d221d Mon Sep 17 00:00:00 2001 From: AnnaLioness Date: Sun, 24 Mar 2024 22:31:39 +0400 Subject: [PATCH 5/7] =?UTF-8?q?3=20=D1=81=D0=BB=D0=BE=D0=B6=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractLawFirmDatabase.cs | 2 + .../Implements/ShopStorage.cs | 138 ++++++++++ ...240324181609_Migr_for_lab3hard.Designer.cs | 248 ++++++++++++++++++ .../20240324181609_Migr_for_lab3hard.cs | 78 ++++++ .../AbstractLawFirmDatabaseModelSnapshot.cs | 77 ++++++ .../Models/Shop.cs | 114 ++++++++ .../Models/ShopDocument.cs | 28 ++ 7 files changed, 685 insertions(+) create mode 100644 LawFirm/AbstractLawFirmDatabaseImplement/Implements/ShopStorage.cs create mode 100644 LawFirm/AbstractLawFirmDatabaseImplement/Migrations/20240324181609_Migr_for_lab3hard.Designer.cs create mode 100644 LawFirm/AbstractLawFirmDatabaseImplement/Migrations/20240324181609_Migr_for_lab3hard.cs create mode 100644 LawFirm/AbstractLawFirmDatabaseImplement/Models/Shop.cs create mode 100644 LawFirm/AbstractLawFirmDatabaseImplement/Models/ShopDocument.cs diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/AbstractLawFirmDatabase.cs b/LawFirm/AbstractLawFirmDatabaseImplement/AbstractLawFirmDatabase.cs index 910677e..ae25c5a 100644 --- a/LawFirm/AbstractLawFirmDatabaseImplement/AbstractLawFirmDatabase.cs +++ b/LawFirm/AbstractLawFirmDatabaseImplement/AbstractLawFirmDatabase.cs @@ -23,5 +23,7 @@ namespace AbstractLawFirmDatabaseImplement public virtual DbSet Documents { set; get; } public virtual DbSet DocumentComponents { set; get; } public virtual DbSet Orders { set; get; } + public virtual DbSet Shops { set; get; } + public virtual DbSet ShopDocuments { set; get; } } } diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Implements/ShopStorage.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..a36c5a7 --- /dev/null +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Implements/ShopStorage.cs @@ -0,0 +1,138 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.StoragesContracts; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataModels.Models; +using AbstractLawFirmDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmDatabaseImplement.Implements +{ + public class ShopStorage : IShopStorage + { + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return new(); + } + using var context = new AbstractLawFirmDatabase(); + return context.Shops.Include(x => x.Documents).ThenInclude(x => x.Document).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(); + } + using var context = new AbstractLawFirmDatabase(); + return context.Shops.Include(x => x.Documents).ThenInclude(x => x.Document).Where(x => x.ShopName.Contains(model.ShopName)).ToList().Select(x => x.GetViewModel).ToList(); + } + public List GetFullList() + { + using var context = new AbstractLawFirmDatabase(); + return context.Shops.Include(x => x.Documents).ThenInclude(x => x.Document).ToList().Select(x => x.GetViewModel).ToList(); + } + public ShopViewModel? Insert(ShopBindingModel model) + { + using var context = new AbstractLawFirmDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var newShop = Shop.Create(context, model); + if (newShop == null) + { + return null; + } + if (context.Shops.Any(x => x.ShopName == newShop.ShopName)) + { + throw new Exception("Название магазина уже занято"); + } + + context.Shops.Add(newShop); + context.SaveChanges(); + transaction.Commit(); + return newShop.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + public ShopViewModel? Update(ShopBindingModel model) + { + using var context = new AbstractLawFirmDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var shop = context.Shops.Include(x => x.Documents).FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + context.SaveChanges(); + if (model.ShopDocuments.Count > 0) + { + shop.UpdateDocuments(context, model); + } + transaction.Commit(); + return shop.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + public ShopViewModel? Delete(ShopBindingModel model) + { + using var context = new AbstractLawFirmDatabase(); + var shop = context.Shops.Include(x => x.Documents).FirstOrDefault(x => x.Id == model.Id); + if (shop != null) + { + context.Shops.Remove(shop); + context.SaveChanges(); + return shop.GetViewModel; + } + return null; + } + public bool SellDocument(IDocumentModel model, int count) + { + using var context = new AbstractLawFirmDatabase(); + using var transaction = context.Database.BeginTransaction(); + + foreach (var shopDocuments in context.ShopDocuments.Where(x => x.DocumentId == model.Id)) + { + var min = Math.Min(count, shopDocuments.Count); + shopDocuments.Count -= min; + count -= min; + if (count <= 0) + { + break; + } + } + + if (count == 0) + { + context.SaveChanges(); + transaction.Commit(); + } + else + transaction.Rollback(); + + if (count > 0) + return false; + + return true; + } + } +} diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/20240324181609_Migr_for_lab3hard.Designer.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/20240324181609_Migr_for_lab3hard.Designer.cs new file mode 100644 index 0000000..e79f2c6 --- /dev/null +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/20240324181609_Migr_for_lab3hard.Designer.cs @@ -0,0 +1,248 @@ +// +using System; +using AbstractLawFirmDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace AbstractLawFirmDatabaseImplement.Migrations +{ + [DbContext(typeof(AbstractLawFirmDatabase))] + [Migration("20240324181609_Migr_for_lab3hard")] + partial class Migr_for_lab3hard + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("AbstractLawFirmDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("AbstractLawFirmDatabaseImplement.Models.Document", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DocumentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Documents"); + }); + + modelBuilder.Entity("AbstractLawFirmDatabaseImplement.Models.DocumentComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DocumentId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("DocumentId"); + + b.ToTable("DocumentComponents"); + }); + + modelBuilder.Entity("AbstractLawFirmDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("DocumentId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("DocumentId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("AbstractLawFirmDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("MaxCountDocuments") + .HasColumnType("int"); + + b.Property("OpeningDate") + .HasColumnType("datetime2"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("AbstractLawFirmDatabaseImplement.Models.ShopDocument", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DocumentId") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("DocumentId"); + + b.HasIndex("ShopId"); + + b.ToTable("ShopDocuments"); + }); + + modelBuilder.Entity("AbstractLawFirmDatabaseImplement.Models.DocumentComponent", b => + { + b.HasOne("AbstractLawFirmDatabaseImplement.Models.Component", "Component") + .WithMany("DocumentComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AbstractLawFirmDatabaseImplement.Models.Document", "Document") + .WithMany("Components") + .HasForeignKey("DocumentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Document"); + }); + + modelBuilder.Entity("AbstractLawFirmDatabaseImplement.Models.Order", b => + { + b.HasOne("AbstractLawFirmDatabaseImplement.Models.Document", "Document") + .WithMany("Orders") + .HasForeignKey("DocumentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Document"); + }); + + modelBuilder.Entity("AbstractLawFirmDatabaseImplement.Models.ShopDocument", b => + { + b.HasOne("AbstractLawFirmDatabaseImplement.Models.Document", "Document") + .WithMany() + .HasForeignKey("DocumentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AbstractLawFirmDatabaseImplement.Models.Shop", "Shop") + .WithMany("Documents") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Document"); + + b.Navigation("Shop"); + }); + + modelBuilder.Entity("AbstractLawFirmDatabaseImplement.Models.Component", b => + { + b.Navigation("DocumentComponents"); + }); + + modelBuilder.Entity("AbstractLawFirmDatabaseImplement.Models.Document", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("AbstractLawFirmDatabaseImplement.Models.Shop", b => + { + b.Navigation("Documents"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/20240324181609_Migr_for_lab3hard.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/20240324181609_Migr_for_lab3hard.cs new file mode 100644 index 0000000..434bebc --- /dev/null +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/20240324181609_Migr_for_lab3hard.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace AbstractLawFirmDatabaseImplement.Migrations +{ + /// + public partial class Migr_for_lab3hard : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Shops", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ShopName = table.Column(type: "nvarchar(max)", nullable: false), + Address = table.Column(type: "nvarchar(max)", nullable: false), + OpeningDate = table.Column(type: "datetime2", nullable: false), + MaxCountDocuments = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Shops", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ShopDocuments", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + DocumentId = table.Column(type: "int", nullable: false), + ShopId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ShopDocuments", x => x.Id); + table.ForeignKey( + name: "FK_ShopDocuments_Documents_DocumentId", + column: x => x.DocumentId, + principalTable: "Documents", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ShopDocuments_Shops_ShopId", + column: x => x.ShopId, + principalTable: "Shops", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ShopDocuments_DocumentId", + table: "ShopDocuments", + column: "DocumentId"); + + migrationBuilder.CreateIndex( + name: "IX_ShopDocuments_ShopId", + table: "ShopDocuments", + column: "ShopId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ShopDocuments"); + + migrationBuilder.DropTable( + name: "Shops"); + } + } +} diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/AbstractLawFirmDatabaseModelSnapshot.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/AbstractLawFirmDatabaseModelSnapshot.cs index 095b76d..df59b20 100644 --- a/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/AbstractLawFirmDatabaseModelSnapshot.cs +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/AbstractLawFirmDatabaseModelSnapshot.cs @@ -121,6 +121,59 @@ namespace AbstractLawFirmDatabaseImplement.Migrations b.ToTable("Orders"); }); + modelBuilder.Entity("AbstractLawFirmDatabaseImplement.Models.Shop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("MaxCountDocuments") + .HasColumnType("int"); + + b.Property("OpeningDate") + .HasColumnType("datetime2"); + + b.Property("ShopName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Shops"); + }); + + modelBuilder.Entity("AbstractLawFirmDatabaseImplement.Models.ShopDocument", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DocumentId") + .HasColumnType("int"); + + b.Property("ShopId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("DocumentId"); + + b.HasIndex("ShopId"); + + b.ToTable("ShopDocuments"); + }); + modelBuilder.Entity("AbstractLawFirmDatabaseImplement.Models.DocumentComponent", b => { b.HasOne("AbstractLawFirmDatabaseImplement.Models.Component", "Component") @@ -151,6 +204,25 @@ namespace AbstractLawFirmDatabaseImplement.Migrations b.Navigation("Document"); }); + modelBuilder.Entity("AbstractLawFirmDatabaseImplement.Models.ShopDocument", b => + { + b.HasOne("AbstractLawFirmDatabaseImplement.Models.Document", "Document") + .WithMany() + .HasForeignKey("DocumentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AbstractLawFirmDatabaseImplement.Models.Shop", "Shop") + .WithMany("Documents") + .HasForeignKey("ShopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Document"); + + b.Navigation("Shop"); + }); + modelBuilder.Entity("AbstractLawFirmDatabaseImplement.Models.Component", b => { b.Navigation("DocumentComponents"); @@ -162,6 +234,11 @@ namespace AbstractLawFirmDatabaseImplement.Migrations b.Navigation("Orders"); }); + + modelBuilder.Entity("AbstractLawFirmDatabaseImplement.Models.Shop", b => + { + b.Navigation("Documents"); + }); #pragma warning restore 612, 618 } } diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Models/Shop.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Models/Shop.cs new file mode 100644 index 0000000..b8168c2 --- /dev/null +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Models/Shop.cs @@ -0,0 +1,114 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmDatabaseImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; set; } + + [Required] + public string ShopName { get; set; } = string.Empty; + + [Required] + public string Address { get; set; } = string.Empty; + + [Required] + public DateTime OpeningDate { get; set; } + + [ForeignKey("ShopId")] + public List Documents { get; set; } = new(); + + private Dictionary? _shopDocuments = null; + + [NotMapped] + public Dictionary ShopDocuments + { + get + { + if (_shopDocuments == null) + { + _shopDocuments = Documents.ToDictionary(recPC => recPC.DocumentId, recPC => (recPC.Document as IDocumentModel, recPC.Count)); + } + return _shopDocuments; + } + } + + [Required] + public int MaxCountDocuments { get; set; } + + public static Shop Create(AbstractLawFirmDatabase context, ShopBindingModel model) + { + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + OpeningDate = model.OpeningDate, + Documents = model.ShopDocuments.Select(x => new ShopDocument + { + Document = context.Documents.First(y => y.Id == x.Key), + Count = x.Value.Item2 + }).ToList(), + MaxCountDocuments = model.MaxCountDocuments + }; + } + + public void Update(ShopBindingModel model) + { + ShopName = model.ShopName; + Address = model.Address; + OpeningDate = model.OpeningDate; + MaxCountDocuments = model.MaxCountDocuments; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + OpeningDate = OpeningDate, + ShopDocuments = ShopDocuments, + MaxCountDocuments = MaxCountDocuments + }; + + public void UpdateDocuments(AbstractLawFirmDatabase context, ShopBindingModel model) + { + var ShopDocuments = context.ShopDocuments.Where(rec => rec.ShopId == model.Id).ToList(); + if (ShopDocuments != null && ShopDocuments.Count > 0) + { + // удалили те, которых нет в модели + context.ShopDocuments.RemoveRange(ShopDocuments.Where(rec => !model.ShopDocuments.ContainsKey(rec.DocumentId))); + context.SaveChanges(); + ShopDocuments = context.ShopDocuments.Where(rec => rec.ShopId == model.Id).ToList(); + // обновили количество у существующих записей + foreach (var updateDocument in ShopDocuments) + { + updateDocument.Count = model.ShopDocuments[updateDocument.DocumentId].Item2; + model.ShopDocuments.Remove(updateDocument.DocumentId); + } + context.SaveChanges(); + } + var shop = context.Shops.First(x => x.Id == Id); + foreach (var elem in model.ShopDocuments) + { + context.ShopDocuments.Add(new ShopDocument + { + Shop = shop, + Document = context.Documents.First(x => x.Id == elem.Key), + Count = elem.Value.Item2 + }); + context.SaveChanges(); + } + _shopDocuments = null; + } + } +} diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Models/ShopDocument.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Models/ShopDocument.cs new file mode 100644 index 0000000..731539e --- /dev/null +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Models/ShopDocument.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Runtime.ConstrainedExecution; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmDatabaseImplement.Models +{ + public class ShopDocument + { + public int Id { get; set; } + + [Required] + public int DocumentId { get; set; } + + [Required] + public int ShopId { get; set; } + + [Required] + public int Count { get; set; } + + public virtual Shop Shop { get; set; } = new(); + + public virtual Document Document { get; set; } = new(); + } +} From f5e9cf4dbf76dbdb75dc89072048f166fa90c3d2 Mon Sep 17 00:00:00 2001 From: AnnaLioness Date: Sat, 6 Apr 2024 15:41:38 +0400 Subject: [PATCH 6/7] =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=84=D0=BB=D0=B8=D0=BA?= =?UTF-8?q?=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirmView/FormMain.resx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LawFirm/LawFirmView/FormMain.resx b/LawFirm/LawFirmView/FormMain.resx index 2e307a2..6d8238b 100644 --- a/LawFirm/LawFirmView/FormMain.resx +++ b/LawFirm/LawFirmView/FormMain.resx @@ -61,6 +61,6 @@ 17, 17 - 96 + 51 \ No newline at end of file From dbdb29ed29635a1db70f6f383b6e6a806b6f0db3 Mon Sep 17 00:00:00 2001 From: AnnaLioness Date: Sat, 6 Apr 2024 21:27:02 +0400 Subject: [PATCH 7/7] =?UTF-8?q?=D1=81=D0=BB=D0=BE=D0=B64=20=D0=B3=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/ReportLogic.cs | 62 ++- .../OfficePackage/AbstractSaveToExcel.cs | 62 +++ .../OfficePackage/AbstractSaveToPdf.cs | 33 ++ .../OfficePackage/AbstractSaveToWord.cs | 22 + .../OfficePackage/HelperModels/ExcelInfo.cs | 6 +- .../OfficePackage/HelperModels/PdfInfo.cs | 1 + .../OfficePackage/HelperModels/WordInfo.cs | 1 + .../OfficePackage/HelperModels/WordTable.cs | 14 + .../OfficePackage/Implements/SaveToWord.cs | 79 ++++ .../BusinessLogicsContracts/IReportLogic.cs | 5 + .../ViewModels/ReportDateOrdersViewModel.cs | 15 + .../ReportShopDocumentsViewModel.cs | 15 + LawFirm/LawFirmView/FormMain.Designer.cs | 38 +- LawFirm/LawFirmView/FormMain.cs | 31 ++ LawFirm/LawFirmView/FormMain.resx | 2 +- .../FormReportDateOrders.Designer.cs | 87 ++++ LawFirm/LawFirmView/FormReportDateOrders.cs | 84 ++++ LawFirm/LawFirmView/FormReportDateOrders.resx | 60 +++ .../FormReportShopDocuments.Designer.cs | 101 +++++ .../LawFirmView/FormReportShopDocuments.cs | 80 ++++ .../LawFirmView/FormReportShopDocuments.resx | 78 ++++ LawFirm/LawFirmView/LawFirmView.csproj | 3 + LawFirm/LawFirmView/Program.cs | 2 + LawFirm/LawFirmView/ReportOrdersByDate.rdlc | 424 ++++++++++++++++++ 24 files changed, 1297 insertions(+), 8 deletions(-) create mode 100644 LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/HelperModels/WordTable.cs create mode 100644 LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ReportDateOrdersViewModel.cs create mode 100644 LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ReportShopDocumentsViewModel.cs create mode 100644 LawFirm/LawFirmView/FormReportDateOrders.Designer.cs create mode 100644 LawFirm/LawFirmView/FormReportDateOrders.cs create mode 100644 LawFirm/LawFirmView/FormReportDateOrders.resx create mode 100644 LawFirm/LawFirmView/FormReportShopDocuments.Designer.cs create mode 100644 LawFirm/LawFirmView/FormReportShopDocuments.cs create mode 100644 LawFirm/LawFirmView/FormReportShopDocuments.resx create mode 100644 LawFirm/LawFirmView/ReportOrdersByDate.rdlc diff --git a/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/ReportLogic.cs b/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/ReportLogic.cs index 0f727d3..c89bb3b 100644 --- a/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/ReportLogic.cs +++ b/LawFirm/AbstractLawFirmBusinessLogic/BusinessLogic/ReportLogic.cs @@ -18,17 +18,19 @@ namespace AbstractLawFirmBusinessLogic.BusinessLogic private readonly IComponentStorage _componentStorage; private readonly IDocumentStorage _documentStorage; private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; private readonly AbstractSaveToExcel _saveToExcel; private readonly AbstractSaveToWord _saveToWord; private readonly AbstractSaveToPdf _saveToPdf; public ReportLogic(IDocumentStorage documentStorage, IComponentStorage - componentStorage, IOrderStorage orderStorage, + componentStorage, IOrderStorage orderStorage, IShopStorage shopStorage, AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) { _documentStorage = documentStorage; _componentStorage = componentStorage; _orderStorage = orderStorage; + _shopStorage = shopStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; _saveToPdf = saveToPdf; @@ -122,6 +124,62 @@ namespace AbstractLawFirmBusinessLogic.BusinessLogic Orders = GetOrders(model) }); } - + public void SaveShopsToWordFile(ReportBindingModel model) + { + _saveToWord.CreateTableDoc(new WordInfo + { + FileName = model.FileName, + Title = "Список магазинов", + Shops = _shopStorage.GetFullList() + }); + } + public void SaveShopDocumentsToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateShopReport(new ExcelInfo + { + FileName = model.FileName, + Title = "Загруженность магазинов", + ShopDocuments = GetShopDocuments() + }); + } + public List GetShopDocuments() + { + var shops = _shopStorage.GetFullList(); + var list = new List(); + foreach (var shop in shops) + { + var record = new ReportShopDocumentsViewModel + { + ShopName = shop.ShopName, + Documents = new List>(), + Count = 0 + }; + foreach (var docCount in shop.ShopDocuments.Values) + { + record.Documents.Add(new Tuple(docCount.Item1.DocumentName, docCount.Item2)); + record.Count += docCount.Item2; + } + list.Add(record); + } + return list; + } + public List GetDateOrders() + { + return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date).Select(x => new ReportDateOrdersViewModel + { + DateCreate = x.Key, + CountOrders = x.Count(), + SumOrders = x.Sum(y => y.Sum) + }).ToList(); + } + public void SaveDateOrdersToPdfFile(ReportBindingModel model) + { + _saveToPdf.CreateReportDateDoc(new PdfInfo + { + FileName = model.FileName, + Title = "Заказы по датам", + DateOrders = GetDateOrders() + }); + } } } diff --git a/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/AbstractSaveToExcel.cs index 44c6cbc..8164b9f 100644 --- a/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -76,6 +76,68 @@ namespace AbstractLawFirmBusinessLogic.OfficePackage } SaveExcel(info); } + public void CreateShopReport(ExcelInfo info) + { + CreateExcel(info); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = 1, + Text = info.Title, + StyleInfo = ExcelStyleInfoType.Title + }); + MergeCells(new ExcelMergeParameters + { + CellFromName = "A1", + CellToName = "C1" + }); + uint rowIndex = 2; + foreach (var pc in info.ShopDocuments) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = pc.ShopName, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + foreach (var (DocumentName, Count) in pc.Documents) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = DocumentName, + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = Count.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); + rowIndex++; + } + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = "Итого", + StyleInfo = ExcelStyleInfoType.Text + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = pc.Count.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + } + SaveExcel(info); + } /// /// Создание excel-файла /// diff --git a/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/AbstractSaveToPdf.cs index 2fe0ac0..da7d3d3 100644 --- a/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -50,6 +50,39 @@ order.DateCreate.ToShortDateString(), order.DocumentName, order.Sum.ToString(), }); SavePdf(info); } + public void CreateReportDateDoc(PdfInfo info) + { + CreatePdf(info); + CreateParagraph(new PdfParagraph + { + Text = info.Title, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateTable(new List { "3cm", "3cm", "7cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Дата", "Количество", "Сумма" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach (var order in info.DateOrders) + { + CreateRow(new PdfRowParameters + { + Texts = new List { order.DateCreate.ToShortDateString(), order.CountOrders.ToString(), order.SumOrders.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + CreateParagraph(new PdfParagraph + { + Text = $"Итого: {info.DateOrders.Sum(x => x.SumOrders)}\t", + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + SavePdf(info); + } /// /// Создание doc-файла /// diff --git a/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/AbstractSaveToWord.cs index 65b5531..455456f 100644 --- a/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -39,6 +39,27 @@ namespace AbstractLawFirmBusinessLogic.OfficePackage } SaveWord(info); } + public void CreateTableDoc(WordInfo wordInfo) + { + CreateWord(wordInfo); + var list = new List(); + foreach (var shop in wordInfo.Shops) + { + list.Add(shop.ShopName); + list.Add(shop.Address); + list.Add(shop.OpeningDate.ToString()); + } + var wordTable = new WordTable + { + Headers = new List { + "Название", + "Адрес", + "Дата открытия"}, + Texts = list + }; + CreateTable(wordTable); + SaveWord(wordInfo); + } /// /// Создание doc-файла /// @@ -55,5 +76,6 @@ namespace AbstractLawFirmBusinessLogic.OfficePackage /// /// protected abstract void SaveWord(WordInfo info); + protected abstract void CreateTable(WordTable info); } } diff --git a/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs index f738e91..87f9440 100644 --- a/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -16,6 +16,10 @@ namespace AbstractLawFirmBusinessLogic.OfficePackage.HelperModels get; set; } = new(); - + public List ShopDocuments + { + get; + set; + } = new(); } } diff --git a/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs index 0d16f6f..5434a16 100644 --- a/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs +++ b/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -14,5 +14,6 @@ namespace AbstractLawFirmBusinessLogic.OfficePackage.HelperModels public DateTime DateFrom { get; set; } public DateTime DateTo { get; set; } public List Orders { get; set; } = new(); + public List DateOrders { get; set; } = new(); } } diff --git a/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/HelperModels/WordInfo.cs index f55eab7..23de53d 100644 --- a/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -12,5 +12,6 @@ namespace AbstractLawFirmBusinessLogic.OfficePackage.HelperModels public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; public List Documents { get; set; } = new(); + public List Shops { get; set; } = new(); } } diff --git a/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/HelperModels/WordTable.cs b/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/HelperModels/WordTable.cs new file mode 100644 index 0000000..ab44f51 --- /dev/null +++ b/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/HelperModels/WordTable.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmBusinessLogic.OfficePackage.HelperModels +{ + public class WordTable + { + public List Headers { get; set; } = new(); + public List Texts { get; set; } = new(); + } +} diff --git a/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/Implements/SaveToWord.cs index 7e8a991..1e39ada 100644 --- a/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/LawFirm/AbstractLawFirmBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -126,6 +126,85 @@ namespace AbstractLawFirmBusinessLogic.OfficePackage.Implements _wordDocument.MainDocumentPart!.Document.Save(); _wordDocument.Dispose(); } + protected override void CreateTable(WordTable table) + { + if (_docBody == null || table == null) + { + return; + } + Table tab = new Table(); + TableProperties props = new TableProperties( + new TableBorders( + new TopBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new BottomBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new LeftBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new RightBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideHorizontalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + }, + new InsideVerticalBorder + { + Val = new EnumValue(BorderValues.Single), + Size = 12 + } + ) + ); + tab.AppendChild(props); + TableGrid tableGrid = new TableGrid(); + for (int i = 0; i < table.Headers.Count; i++) + { + tableGrid.AppendChild(new GridColumn()); + } + tab.AppendChild(tableGrid); + TableRow tableRow = new TableRow(); + foreach (var text in table.Headers) + { + tableRow.AppendChild(CreateTableCell(text)); + } + tab.AppendChild(tableRow); + int height = table.Texts.Count / table.Headers.Count; + int width = table.Headers.Count; + for (int i = 0; i < height; i++) + { + tableRow = new TableRow(); + for (int j = 0; j < width; j++) + { + var element = table.Texts[i * table.Headers.Count + j]; + tableRow.AppendChild(CreateTableCell(element)); + } + tab.AppendChild(tableRow); + } + _docBody.AppendChild(tab); + + } + private TableCell CreateTableCell(string element) + { + var tableParagraph = new Paragraph(); + var run = new Run(); + run.AppendChild(new Text { Text = element }); + tableParagraph.AppendChild(run); + var tableCell = new TableCell(); + tableCell.AppendChild(tableParagraph); + return tableCell; + } } } diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IReportLogic.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IReportLogic.cs index 8bb9747..18188f2 100644 --- a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/BusinessLogicsContracts/IReportLogic.cs @@ -36,5 +36,10 @@ namespace AbstractLawFirmContracts.BusinessLogicsContracts /// /// void SaveOrdersToPdfFile(ReportBindingModel model); + List GetShopDocuments(); + List GetDateOrders(); + void SaveShopsToWordFile(ReportBindingModel model); + void SaveShopDocumentsToExcelFile(ReportBindingModel model); + void SaveDateOrdersToPdfFile(ReportBindingModel model); } } diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ReportDateOrdersViewModel.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ReportDateOrdersViewModel.cs new file mode 100644 index 0000000..5a8c16d --- /dev/null +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ReportDateOrdersViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmContracts.ViewModels +{ + public class ReportDateOrdersViewModel + { + public DateTime DateCreate { get; set; } + public int CountOrders { get; set; } + public double SumOrders { get; set; } + } +} diff --git a/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ReportShopDocumentsViewModel.cs b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ReportShopDocumentsViewModel.cs new file mode 100644 index 0000000..380a709 --- /dev/null +++ b/LawFirm/AbstractLawFirmContracts/AbstractLawFirmContracts/ViewModels/ReportShopDocumentsViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmContracts.ViewModels +{ + public class ReportShopDocumentsViewModel + { + public string ShopName { get; set; } = string.Empty; + public int Count { get; set; } + public List> Documents { get; set; } = new(); + } +} diff --git a/LawFirm/LawFirmView/FormMain.Designer.cs b/LawFirm/LawFirmView/FormMain.Designer.cs index e3389b3..9ea8da7 100644 --- a/LawFirm/LawFirmView/FormMain.Designer.cs +++ b/LawFirm/LawFirmView/FormMain.Designer.cs @@ -45,6 +45,9 @@ this.buttonRef = new System.Windows.Forms.Button(); this.buttonSupplyShop = new System.Windows.Forms.Button(); this.buttonSellDocs = new System.Windows.Forms.Button(); + this.списокМагазиновToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.загруженностьМагазиновToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.списокЗаказовПоДатамToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -96,7 +99,10 @@ this.отчётыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.списокПакетовДокументовToolStripMenuItem, this.компонентыПоПакетамДокументовToolStripMenuItem, - this.списокЗаказовToolStripMenuItem}); + this.списокЗаказовToolStripMenuItem, + this.списокМагазиновToolStripMenuItem, + this.загруженностьМагазиновToolStripMenuItem, + this.списокЗаказовПоДатамToolStripMenuItem}); this.отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; this.отчётыToolStripMenuItem.Size = new System.Drawing.Size(60, 20); this.отчётыToolStripMenuItem.Text = "Отчёты"; @@ -201,6 +207,27 @@ this.buttonSellDocs.UseVisualStyleBackColor = true; this.buttonSellDocs.Click += new System.EventHandler(this.buttonSellDocs_Click); // + // списокМагазиновToolStripMenuItem + // + this.списокМагазиновToolStripMenuItem.Name = "списокМагазиновToolStripMenuItem"; + this.списокМагазиновToolStripMenuItem.Size = new System.Drawing.Size(278, 22); + this.списокМагазиновToolStripMenuItem.Text = "Список магазинов"; + this.списокМагазиновToolStripMenuItem.Click += new System.EventHandler(this.списокМагазиновToolStripMenuItem_Click); + // + // загруженностьМагазиновToolStripMenuItem + // + this.загруженностьМагазиновToolStripMenuItem.Name = "загруженностьМагазиновToolStripMenuItem"; + this.загруженностьМагазиновToolStripMenuItem.Size = new System.Drawing.Size(278, 22); + this.загруженностьМагазиновToolStripMenuItem.Text = "Загруженность магазинов"; + this.загруженностьМагазиновToolStripMenuItem.Click += new System.EventHandler(this.загруженностьМагазиновToolStripMenuItem_Click); + // + // списокЗаказовПоДатамToolStripMenuItem + // + this.списокЗаказовПоДатамToolStripMenuItem.Name = "списокЗаказовПоДатамToolStripMenuItem"; + this.списокЗаказовПоДатамToolStripMenuItem.Size = new System.Drawing.Size(278, 22); + this.списокЗаказовПоДатамToolStripMenuItem.Text = "Список заказов по датам"; + this.списокЗаказовПоДатамToolStripMenuItem.Click += new System.EventHandler(this.списокЗаказовПоДатамToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -239,12 +266,15 @@ private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonRef; - private ToolStripMenuItem магазиныToolStripMenuItem; - private Button buttonSupplyShop; - private Button buttonSellDocs; private ToolStripMenuItem отчётыToolStripMenuItem; private ToolStripMenuItem списокПакетовДокументовToolStripMenuItem; private ToolStripMenuItem компонентыПоПакетамДокументовToolStripMenuItem; private ToolStripMenuItem списокЗаказовToolStripMenuItem; + private ToolStripMenuItem магазиныToolStripMenuItem; + private Button buttonSupplyShop; + private Button buttonSellDocs; + private ToolStripMenuItem списокМагазиновToolStripMenuItem; + private ToolStripMenuItem загруженностьМагазиновToolStripMenuItem; + private ToolStripMenuItem списокЗаказовПоДатамToolStripMenuItem; } } \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormMain.cs b/LawFirm/LawFirmView/FormMain.cs index 2e4a1f9..1a0587d 100644 --- a/LawFirm/LawFirmView/FormMain.cs +++ b/LawFirm/LawFirmView/FormMain.cs @@ -239,5 +239,36 @@ namespace LawFirmView form.ShowDialog(); } } + + private void списокМагазиновToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveShopsToWordFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + + private void загруженностьМагазиновToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportShopDocuments)); + if (service is FormReportShopDocuments form) + { + form.ShowDialog(); + } + } + + private void списокЗаказовПоДатамToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportDateOrders)); + if (service is FormReportDateOrders form) + { + form.ShowDialog(); + } + } } } diff --git a/LawFirm/LawFirmView/FormMain.resx b/LawFirm/LawFirmView/FormMain.resx index 6d8238b..05252e7 100644 --- a/LawFirm/LawFirmView/FormMain.resx +++ b/LawFirm/LawFirmView/FormMain.resx @@ -61,6 +61,6 @@ 17, 17 - 51 + 25 \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormReportDateOrders.Designer.cs b/LawFirm/LawFirmView/FormReportDateOrders.Designer.cs new file mode 100644 index 0000000..3d765c1 --- /dev/null +++ b/LawFirm/LawFirmView/FormReportDateOrders.Designer.cs @@ -0,0 +1,87 @@ +namespace LawFirmView +{ + partial class FormReportDateOrders + { + /// + /// 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.panel = new System.Windows.Forms.Panel(); + this.buttonSaveToPdf = new System.Windows.Forms.Button(); + this.buttonMake = new System.Windows.Forms.Button(); + this.panel.SuspendLayout(); + this.SuspendLayout(); + // + // panel + // + this.panel.Controls.Add(this.buttonSaveToPdf); + this.panel.Controls.Add(this.buttonMake); + this.panel.Dock = System.Windows.Forms.DockStyle.Top; + this.panel.Location = new System.Drawing.Point(0, 0); + this.panel.Name = "panel"; + this.panel.Size = new System.Drawing.Size(800, 51); + this.panel.TabIndex = 0; + // + // buttonSaveToPdf + // + this.buttonSaveToPdf.Location = new System.Drawing.Point(135, 12); + this.buttonSaveToPdf.Name = "buttonSaveToPdf"; + this.buttonSaveToPdf.Size = new System.Drawing.Size(75, 23); + this.buttonSaveToPdf.TabIndex = 1; + this.buttonSaveToPdf.Text = "В Pdf"; + this.buttonSaveToPdf.UseVisualStyleBackColor = true; + this.buttonSaveToPdf.Click += new System.EventHandler(this.buttonSaveToPdf_Click); + // + // buttonMake + // + this.buttonMake.Location = new System.Drawing.Point(12, 12); + this.buttonMake.Name = "buttonMake"; + this.buttonMake.Size = new System.Drawing.Size(104, 23); + this.buttonMake.TabIndex = 0; + this.buttonMake.Text = "Сформировать"; + this.buttonMake.UseVisualStyleBackColor = true; + this.buttonMake.Click += new System.EventHandler(this.buttonMake_Click); + // + // FormReportDateOrders + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 422); + this.Controls.Add(this.panel); + this.Name = "FormReportDateOrders"; + this.Text = "FormReportDateOrders"; + this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.FormReportDateOrders_FormClosed); + this.panel.ResumeLayout(false); + this.ResumeLayout(false); + + } + + #endregion + + private Panel panel; + private Button buttonSaveToPdf; + private Button buttonMake; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormReportDateOrders.cs b/LawFirm/LawFirmView/FormReportDateOrders.cs new file mode 100644 index 0000000..658b59d --- /dev/null +++ b/LawFirm/LawFirmView/FormReportDateOrders.cs @@ -0,0 +1,84 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using Microsoft.Reporting.WinForms; +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 FormReportDateOrders : Form + { + private readonly ReportViewer reportViewer; + private readonly ILogger _logger; + private readonly IReportLogic _logic; + private readonly FileStream _fileStream; + public FormReportDateOrders(ILogger logger, IReportLogic reportLogic) + { + InitializeComponent(); + _logger = logger; + _logic = reportLogic; + reportViewer = new ReportViewer + { + Dock = DockStyle.Fill + }; + _fileStream = new FileStream("ReportOrdersByDate.rdlc", FileMode.Open); + reportViewer.LocalReport.LoadReportDefinition(_fileStream); + Controls.Clear(); + Controls.Add(reportViewer); + Controls.Add(panel); + } + + private void buttonMake_Click(object sender, EventArgs e) + { + try + { + var dataSource = _logic.GetDateOrders(); + var source = new ReportDataSource("DataSetOrders", dataSource); + reportViewer.LocalReport.DataSources.Clear(); + reportViewer.LocalReport.DataSources.Add(source); + reportViewer.RefreshReport(); + _logger.LogInformation("Загрузка списка заказов на весь период по датам"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonSaveToPdf_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveDateOrdersToPdfFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + _logger.LogInformation("Сохранение списка заказов на весь период по датам"); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void FormReportDateOrders_FormClosed(object sender, FormClosedEventArgs e) + { + _fileStream.Close(); + } + } +} diff --git a/LawFirm/LawFirmView/FormReportDateOrders.resx b/LawFirm/LawFirmView/FormReportDateOrders.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/LawFirm/LawFirmView/FormReportDateOrders.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/FormReportShopDocuments.Designer.cs b/LawFirm/LawFirmView/FormReportShopDocuments.Designer.cs new file mode 100644 index 0000000..959f7bc --- /dev/null +++ b/LawFirm/LawFirmView/FormReportShopDocuments.Designer.cs @@ -0,0 +1,101 @@ +namespace LawFirmView +{ + partial class FormReportShopDocuments + { + /// + /// 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.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.buttonSaveToExcel = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.Column1, + this.Column2, + this.Column3}); + this.dataGridView.Location = new System.Drawing.Point(12, 58); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(454, 326); + this.dataGridView.TabIndex = 0; + // + // Column1 + // + this.Column1.HeaderText = "Магазин"; + this.Column1.Name = "Column1"; + // + // Column2 + // + this.Column2.HeaderText = "Пакет документов"; + this.Column2.Name = "Column2"; + // + // Column3 + // + this.Column3.HeaderText = "Количество"; + this.Column3.Name = "Column3"; + // + // buttonSaveToExcel + // + this.buttonSaveToExcel.Location = new System.Drawing.Point(12, 12); + this.buttonSaveToExcel.Name = "buttonSaveToExcel"; + this.buttonSaveToExcel.Size = new System.Drawing.Size(137, 23); + this.buttonSaveToExcel.TabIndex = 1; + this.buttonSaveToExcel.Text = "Сохранить в Excel"; + this.buttonSaveToExcel.UseVisualStyleBackColor = true; + this.buttonSaveToExcel.Click += new System.EventHandler(this.buttonSaveToExcel_Click); + // + // FormReportShopDocuments + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(513, 396); + this.Controls.Add(this.buttonSaveToExcel); + this.Controls.Add(this.dataGridView); + this.Name = "FormReportShopDocuments"; + this.Text = "FormReportShopDocuments"; + this.Load += new System.EventHandler(this.FormReportShopDocuments_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private DataGridViewTextBoxColumn Column1; + private DataGridViewTextBoxColumn Column2; + private DataGridViewTextBoxColumn Column3; + private Button buttonSaveToExcel; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormReportShopDocuments.cs b/LawFirm/LawFirmView/FormReportShopDocuments.cs new file mode 100644 index 0000000..a25a2f3 --- /dev/null +++ b/LawFirm/LawFirmView/FormReportShopDocuments.cs @@ -0,0 +1,80 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace LawFirmView +{ + public partial class FormReportShopDocuments : Form + { + private readonly ILogger _logger; + private readonly IReportLogic _logic; + public FormReportShopDocuments(ILogger logger, IReportLogic reportLogic) + { + InitializeComponent(); + _logger = logger; + _logic = reportLogic; + } + + private void FormReportShopDocuments_Load(object sender, EventArgs e) + { + try + { + var dict = _logic.GetShopDocuments(); + if (dict != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in dict) + { + dataGridView.Rows.Add(new object[] { elem.ShopName, "", "" }); + foreach (var listElem in elem.Documents) + { + dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 }); + } + dataGridView.Rows.Add(new object[] { "Всего:", "", elem.Count }); + dataGridView.Rows.Add(Array.Empty()); + } + } + _logger.LogInformation("Загрузка списка магазинов с пакетами документов в них"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка магазинов с пакетами документов в них"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonSaveToExcel_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog + { + Filter = "xlsx|*.xlsx" + }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveShopDocumentsToExcelFile(new ReportBindingModel + { + FileName = dialog.FileName + }); + _logger.LogInformation("Сохранение списка магазинов с пакетами документов в них"); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка магазинов с пакетами документов в них"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/LawFirm/LawFirmView/FormReportShopDocuments.resx b/LawFirm/LawFirmView/FormReportShopDocuments.resx new file mode 100644 index 0000000..a9dc853 --- /dev/null +++ b/LawFirm/LawFirmView/FormReportShopDocuments.resx @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/LawFirm/LawFirmView/LawFirmView.csproj b/LawFirm/LawFirmView/LawFirmView.csproj index 4c76643..2ab1801 100644 --- a/LawFirm/LawFirmView/LawFirmView.csproj +++ b/LawFirm/LawFirmView/LawFirmView.csproj @@ -29,6 +29,9 @@ Always + + Always + \ No newline at end of file diff --git a/LawFirm/LawFirmView/Program.cs b/LawFirm/LawFirmView/Program.cs index bb8e891..790f036 100644 --- a/LawFirm/LawFirmView/Program.cs +++ b/LawFirm/LawFirmView/Program.cs @@ -61,6 +61,8 @@ namespace LawFirmView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } diff --git a/LawFirm/LawFirmView/ReportOrdersByDate.rdlc b/LawFirm/LawFirmView/ReportOrdersByDate.rdlc new file mode 100644 index 0000000..35fb6a2 --- /dev/null +++ b/LawFirm/LawFirmView/ReportOrdersByDate.rdlc @@ -0,0 +1,424 @@ + + + 0 + + + + System.Data.DataSet + /* Local Connection */ + + 10791c83-cee8-4a38-bbd0-245fc17cefb3 + + + + + + AbstractLawFirmContractsViewModels + /* Local Query */ + + + + DateCreate + System.DateTime + + + CountOrders + System.Decimal + + + SumOrders + System.Double + + + + AbstractLawFirmContracts.ViewModels + ReportDateOrdersViewModel + AbstractLawFirmContracts.ViewModels.ReportDateOrdersViewModel, LawFirmContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + + + + + + + true + true + + + + + Заказы + + + + + + + 1cm + 21cm + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + + + + 3cm + + + 3cm + + + 7cm + + + + + 0.6cm + + + + + true + true + + + + + Дата + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Количество + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Сумма + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + 0.6cm + + + + + true + true + + + + + =Fields!DateCreate.Value + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!CountOrders.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!SumOrders.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + + + + + + + + + + + + After + + + + + + + DataSetOrders + 2.48391cm + 0.55245cm + 1.2cm + 13cm + 1 + + + + + + true + true + + + + + Всего: + + + + + + + 4cm + 8.55245cm + 0.6cm + 2.5cm + 2 + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Sum(Fields!SumOrders.Value, "DataSetOrders") + + + + + + + 4cm + 11.05245cm + 0.6cm + 2.5cm + 3 + + + 2pt + 2pt + 2pt + 2pt + + + + 5.72875cm +