From dcde585e86a1731e62cf88ff60f70a093e57680d Mon Sep 17 00:00:00 2001 From: GokaPek Date: Tue, 9 Apr 2024 23:28:01 +0400 Subject: [PATCH] =?UTF-8?q?2=20=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 --- .../AbstractLawFirmDataBase.cs | 5 +- .../Implements/ComponentStorage.cs | 12 +- .../Implements/DocumentStorage.cs | 192 +++++++++--------- .../Implements/OrderStorage.cs | 13 +- .../20240325152423_InitialCreate.Designer.cs | 2 +- .../AbstractLawFirmDataBaseModelSnapshot.cs | 2 +- .../Models/Component.cs | 1 + .../Models/Document.cs | 31 +-- .../Models/DocumentComponent.cs | 8 +- .../Models/Order.cs | 36 ++-- LawFirm/LawFirmView/FormMain.cs | 13 +- LawFirm/LawFirmView/FormMain.designer.cs | 32 ++- .../FormReportDocumentComponents.cs | 3 +- LawFirm/LawFirmView/FormReportOrders.cs | 30 ++- LawFirm/LawFirmView/LawFirmView.csproj | 5 + LawFirm/LawFirmView/Report.rdlc | 32 +-- 16 files changed, 224 insertions(+), 193 deletions(-) diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/AbstractLawFirmDataBase.cs b/LawFirm/AbstractLawFirmDatabaseImplement/AbstractLawFirmDataBase.cs index d0f654f..863d9a1 100644 --- a/LawFirm/AbstractLawFirmDatabaseImplement/AbstractLawFirmDataBase.cs +++ b/LawFirm/AbstractLawFirmDatabaseImplement/AbstractLawFirmDataBase.cs @@ -1,4 +1,5 @@ -using AbstractLawFirmDataBaseImplement.Models; +using AbstractLawFirmDatabaseImplement.Models; +using AbstractLawFirmDataBaseImplement.Models; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; @@ -8,7 +9,7 @@ using System.Threading.Tasks; namespace AbstractLawFirmDataBaseImplement { - public class AbstractLawFirmDataBase : DbContext + public class AbstractLawFirmDatabase : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Implements/ComponentStorage.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Implements/ComponentStorage.cs index a6bbbde..b2f8973 100644 --- a/LawFirm/AbstractLawFirmDatabaseImplement/Implements/ComponentStorage.cs +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Implements/ComponentStorage.cs @@ -16,7 +16,7 @@ namespace AbstractLawFirmDatabaseImplement.Implements { public List GetFullList() { - using var context = new AbstractLawFirmDataBase(); + using var context = new AbstractLawFirmDatabase(); return context.Components .Select(x => x.GetViewModel) .ToList(); @@ -27,7 +27,7 @@ namespace AbstractLawFirmDatabaseImplement.Implements { return new(); } - using var context = new AbstractLawFirmDataBase(); + using var context = new AbstractLawFirmDatabase(); return context.Components .Where(x => x.ComponentName.Contains(model.ComponentName)) .Select(x => x.GetViewModel) @@ -39,7 +39,7 @@ namespace AbstractLawFirmDatabaseImplement.Implements { return null; } - using var context = new AbstractLawFirmDataBase(); + using var context = new AbstractLawFirmDatabase(); return context.Components .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || (model.Id.HasValue && x.Id == model.Id)) ?.GetViewModel; @@ -51,14 +51,14 @@ namespace AbstractLawFirmDatabaseImplement.Implements { return null; } - using var context = new AbstractLawFirmDataBase(); + using var context = new AbstractLawFirmDatabase(); context.Components.Add(newComponent); context.SaveChanges(); return newComponent.GetViewModel; } public ComponentViewModel? Update(ComponentBindingModel model) { - using var context = new AbstractLawFirmDataBase(); + using var context = new AbstractLawFirmDatabase(); var component = context.Components.FirstOrDefault(x => x.Id == model.Id); if (component == null) { @@ -70,7 +70,7 @@ namespace AbstractLawFirmDatabaseImplement.Implements } public ComponentViewModel? Delete(ComponentBindingModel model) { - using var context = new AbstractLawFirmDataBase(); + using var context = new AbstractLawFirmDatabase(); var element = context.Components.FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Implements/DocumentStorage.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Implements/DocumentStorage.cs index a916835..5792f56 100644 --- a/LawFirm/AbstractLawFirmDatabaseImplement/Implements/DocumentStorage.cs +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Implements/DocumentStorage.cs @@ -1,112 +1,108 @@ using AbstractLawFirmContracts.BindingModels; -using AbstractLawFirmContracts.BindingModels.BindingModels; using AbstractLawFirmContracts.SearchModels; using AbstractLawFirmContracts.StoragesContracts; using AbstractLawFirmContracts.ViewModels; -using AbstractLawFirmDataBaseImplement; -using AbstractLawFirmDataBaseImplement.Models; -using Microsoft.EntityFrameworkCore; +using AbstractLawFirmDataBaseImplement.Models; +using AbstractLawFirmDataBaseImplement; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using AbstractLawFirmDatabaseImplement.Models; namespace AbstractLawFirmDatabaseImplement.Implements { public class DocumentStorage : IDocumentStorage - { - public List GetFullList() - { - using var context = new AbstractLawFirmDataBase(); - return context.Documents - .Include(x => x.Components) - .ThenInclude(x => x.Component) - .ToList() - .Select(x => x.GetViewModel) - .ToList(); - } - public List GetFilteredList(DocumentSearchModel model) - { - if (string.IsNullOrEmpty(model.DocumentName)) - { - return new(); - } - using var context = new AbstractLawFirmDataBase(); - return context.Documents - .Include(x => x.Components) - .ThenInclude(x => x.Component) - .Where(x => x.DocumentName.Contains(model.DocumentName)) - .ToList() - .Select(x => x.GetViewModel) - .ToList(); - } - public DocumentViewModel? GetElement(DocumentSearchModel model) - { - if (string.IsNullOrEmpty(model.DocumentName) && - !model.Id.HasValue) - { - return null; - } - using var context = new AbstractLawFirmDataBase(); - return context.Documents - .Include(x => x.Components) - .ThenInclude(x => x.Component) - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.DocumentName) && - x.DocumentName == model.DocumentName) || - (model.Id.HasValue && x.Id == - model.Id)) - ?.GetViewModel; - } - public DocumentViewModel? Insert(DocumentBindingModel model) - { - using var context = new AbstractLawFirmDataBase(); - var newDocument = Document.Create(context, model); - if (newDocument == null) - { - return null; - } - context.Documents.Add(newDocument); - context.SaveChanges(); - return newDocument.GetViewModel; - } - public DocumentViewModel? Update(DocumentBindingModel model) - { - using var context = new AbstractLawFirmDataBase(); - using var transaction = context.Database.BeginTransaction(); - try - { - var product = context.Documents.FirstOrDefault(rec => - rec.Id == model.Id); - if (product == null) - { - return null; - } - product.Update(model); - context.SaveChanges(); - product.UpdateComponents(context, model); - transaction.Commit(); - return product.GetViewModel; - } - catch - { - transaction.Rollback(); - throw; - } - } - public DocumentViewModel? Delete(DocumentBindingModel model) - { - using var context = new AbstractLawFirmDataBase(); - var element = context.Documents - .Include(x => x.Components) - .FirstOrDefault(rec => rec.Id == model.Id); - if (element != null) - { - context.Documents.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; - } + { + public List GetFullList() + { + using var context = new AbstractLawFirmDatabase(); + return context.Documents + .Include(x => x.Components) + .ThenInclude(x => x.Component) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(DocumentSearchModel model) + { + if (string.IsNullOrEmpty(model.DocumentName)) + { + return new(); + } + using var context = new AbstractLawFirmDatabase(); + return context.Documents + .Include(x => x.Components) + .ThenInclude(x => x.Component) + .Where(x => x.DocumentName.Contains(model.DocumentName)) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + public DocumentViewModel? GetElement(DocumentSearchModel model) + { + if (string.IsNullOrEmpty(model.DocumentName) && + !model.Id.HasValue) + { + return null; + } + using var context = new AbstractLawFirmDatabase(); + return context.Documents.Include(x => x.Components).ThenInclude(x => x.Component) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.DocumentName) && + x.DocumentName == model.DocumentName) || + (model.Id.HasValue && x.Id == + model.Id)) + ?.GetViewModel; + } + public DocumentViewModel? Insert(DocumentBindingModel model) + { + using var context = new AbstractLawFirmDatabase(); + var newDocument = Document.Create(context, model); + if (newDocument == null) + { + return null; + } + context.Documents.Add(newDocument); + context.SaveChanges(); + return newDocument.GetViewModel; + } + public DocumentViewModel? Update(DocumentBindingModel model) + { + using var context = new AbstractLawFirmDatabase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var document = context.Documents.FirstOrDefault(rec => + rec.Id == model.Id); + if (document == null) + { + return null; + } + document.Update(model); + context.SaveChanges(); + document.UpdateComponents(context, model); + transaction.Commit(); + return document.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + public DocumentViewModel? Delete(DocumentBindingModel model) + { + using var context = new AbstractLawFirmDatabase(); + var element = context.Documents.Include(x => x.Components).FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Documents.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } } -} +} \ No newline at end of file diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Implements/OrderStorage.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Implements/OrderStorage.cs index fb419ea..4ffbc9d 100644 --- a/LawFirm/AbstractLawFirmDatabaseImplement/Implements/OrderStorage.cs +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Implements/OrderStorage.cs @@ -10,6 +10,7 @@ using System.Text; using System.Threading.Tasks; using AbstractLawFirmDataBaseImplement; using Microsoft.EntityFrameworkCore; +using AbstractLawFirmDatabaseImplement.Models; namespace AbstractLawFirmDatabaseImplement.Implements { @@ -17,7 +18,7 @@ namespace AbstractLawFirmDatabaseImplement.Implements { public OrderViewModel? Delete(OrderBindingModel model) { - using var context = new AbstractLawFirmDataBase(); + using var context = new AbstractLawFirmDatabase(); var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { @@ -34,7 +35,7 @@ namespace AbstractLawFirmDatabaseImplement.Implements { return null; } - using var context = new AbstractLawFirmDataBase(); + using var context = new AbstractLawFirmDatabase(); return context.Orders .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; @@ -46,7 +47,7 @@ namespace AbstractLawFirmDatabaseImplement.Implements { return new(); } - using var context = new AbstractLawFirmDataBase(); + using var context = new AbstractLawFirmDatabase(); return context.Orders .Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo) .Select(x => x.GetViewModel) @@ -55,7 +56,7 @@ namespace AbstractLawFirmDatabaseImplement.Implements public List GetFullList() { - using var context = new AbstractLawFirmDataBase(); + using var context = new AbstractLawFirmDatabase(); return context.Orders .Select(x => x.GetViewModel) .ToList(); @@ -68,7 +69,7 @@ namespace AbstractLawFirmDatabaseImplement.Implements { return null; } - using var context = new AbstractLawFirmDataBase(); + using var context = new AbstractLawFirmDatabase(); context.Orders.Add(newOrder); context.SaveChanges(); return newOrder.GetViewModel; @@ -76,7 +77,7 @@ namespace AbstractLawFirmDatabaseImplement.Implements public OrderViewModel? Update(OrderBindingModel model) { - using var context = new AbstractLawFirmDataBase(); + using var context = new AbstractLawFirmDatabase(); var component = context.Orders.FirstOrDefault(x => x.Id == model.Id); if (component == null) { diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/20240325152423_InitialCreate.Designer.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/20240325152423_InitialCreate.Designer.cs index 7dedd3d..716d4c8 100644 --- a/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/20240325152423_InitialCreate.Designer.cs +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/20240325152423_InitialCreate.Designer.cs @@ -11,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace AbstractLawFirmDatabaseImplement.Migrations { - [DbContext(typeof(AbstractLawFirmDataBase))] + [DbContext(typeof(AbstractLawFirmDatabase))] [Migration("20240325152423_InitialCreate")] partial class InitialCreate { diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/AbstractLawFirmDataBaseModelSnapshot.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/AbstractLawFirmDataBaseModelSnapshot.cs index f356f2b..910988c 100644 --- a/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/AbstractLawFirmDataBaseModelSnapshot.cs +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Migrations/AbstractLawFirmDataBaseModelSnapshot.cs @@ -10,7 +10,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace AbstractLawFirmDatabaseImplement.Migrations { - [DbContext(typeof(AbstractLawFirmDataBase))] + [DbContext(typeof(AbstractLawFirmDatabase))] partial class AbstractLawFirmDataBaseModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Models/Component.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Models/Component.cs index c1edd27..8069012 100644 --- a/LawFirm/AbstractLawFirmDatabaseImplement/Models/Component.cs +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Models/Component.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using AbstractLawFirmDataBaseImplement.Models; +using AbstractLawFirmDatabaseImplement.Models; namespace AbstractLawFirmDataBaseImplement.Models { diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Models/Document.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Models/Document.cs index b1ba0a2..e38dcd4 100644 --- a/LawFirm/AbstractLawFirmDatabaseImplement/Models/Document.cs +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Models/Document.cs @@ -9,8 +9,9 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using AbstractLawFirmDataBaseImplement.Models; +using AbstractLawFirmDataBaseImplement; -namespace AbstractLawFirmDataBaseImplement.Models +namespace AbstractLawFirmDatabaseImplement.Models { public class Document : IDocumentModel { @@ -19,34 +20,36 @@ namespace AbstractLawFirmDataBaseImplement.Models public string DocumentName { get; set; } = string.Empty; [Required] public double Price { get; set; } - private Dictionary? _productComponents = + private Dictionary? _documentComponents = null; [NotMapped] public Dictionary DocumentComponents { get { - if (_productComponents == null) + if (_documentComponents == null) { - _productComponents = Components + _documentComponents = Components .ToDictionary(recPC => recPC.ComponentId, recPC => (recPC.Component as IComponentModel, recPC.Count)); } - return _productComponents; + return _documentComponents; } } [ForeignKey("DocumentId")] public virtual List Components { get; set; } = new(); [ForeignKey("DocumentId")] public virtual List Orders { get; set; } = new(); - public static Document Create(AbstractLawFirmDataBase context, DocumentBindingModel model) + public static Document Create(AbstractLawFirmDatabase context, + DocumentBindingModel model) { return new Document() { Id = model.Id, DocumentName = model.DocumentName, Price = model.Price, - Components = model.DocumentComponents.Select(x => new DocumentComponent + Components = model.DocumentComponents.Select(x => new + DocumentComponent { Component = context.Components.First(y => y.Id == x.Key), Count = x.Value.Item2 @@ -65,12 +68,14 @@ namespace AbstractLawFirmDataBaseImplement.Models Price = Price, DocumentComponents = DocumentComponents }; - public void UpdateComponents(AbstractLawFirmDataBase context, DocumentBindingModel model) + public void UpdateComponents(AbstractLawFirmDatabase context, + DocumentBindingModel model) { var documentComponents = context.DocumentComponents.Where(rec => rec.DocumentId == model.Id).ToList(); if (documentComponents != null && documentComponents.Count > 0) { // удалили те, которых нет в модели - context.DocumentComponents.RemoveRange(documentComponents.Where(rec => !model.DocumentComponents.ContainsKey(rec.ComponentId))); + context.DocumentComponents.RemoveRange(documentComponents.Where(rec + => !model.DocumentComponents.ContainsKey(rec.ComponentId))); context.SaveChanges(); // обновили количество у существующих записей foreach (var updateComponent in documentComponents) @@ -80,18 +85,18 @@ namespace AbstractLawFirmDataBaseImplement.Models } context.SaveChanges(); } - var product = context.Documents.First(x => x.Id == Id); + var document = context.Documents.First(x => x.Id == Id); foreach (var pc in model.DocumentComponents) { context.DocumentComponents.Add(new DocumentComponent { - Document = product, + Document = document, Component = context.Components.First(x => x.Id == pc.Key), Count = pc.Value.Item2 }); context.SaveChanges(); } - _productComponents = null; + _documentComponents = null; } } -} +} \ No newline at end of file diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Models/DocumentComponent.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Models/DocumentComponent.cs index a24c3f4..b7656ee 100644 --- a/LawFirm/AbstractLawFirmDatabaseImplement/Models/DocumentComponent.cs +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Models/DocumentComponent.cs @@ -1,13 +1,13 @@ -using AbstractLawFirmDataBaseImplement.Models; +using AbstractLawFirmDatabaseImplement.Models; +using AbstractLawFirmDataBaseImplement.Models; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; -using System.Reflection.Metadata; using System.Text; using System.Threading.Tasks; -namespace AbstractLawFirmDataBaseImplement.Models +namespace AbstractLawFirmDatabaseImplement.Models { public class DocumentComponent { @@ -21,4 +21,4 @@ namespace AbstractLawFirmDataBaseImplement.Models public virtual Component Component { get; set; } = new(); public virtual Document Document { get; set; } = new(); } -} +} \ No newline at end of file diff --git a/LawFirm/AbstractLawFirmDatabaseImplement/Models/Order.cs b/LawFirm/AbstractLawFirmDatabaseImplement/Models/Order.cs index f875f25..dfed9cd 100644 --- a/LawFirm/AbstractLawFirmDatabaseImplement/Models/Order.cs +++ b/LawFirm/AbstractLawFirmDatabaseImplement/Models/Order.cs @@ -4,62 +4,68 @@ using AbstractLawFirmDataModels.Enums; using AbstractLawFirmDataModels.Models; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace AbstractLawFirmDataBaseImplement.Models +namespace AbstractLawFirmDatabaseImplement.Models { public class Order : IOrderModel { public int Id { get; private set; } + [Required] public int DocumentId { get; private set; } + [Required] public int Count { get; private set; } + [Required] public double Sum { get; private set; } - public OrderStatus Status { get; private set; } - public DateTime DateCreate { get; private set; } + [Required] + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + [Required] + public DateTime DateCreate { get; private set; } = DateTime.Now; + public DateTime? DateImplement { get; private set; } + public virtual Document Document { get; set; } + public static Order? Create(OrderBindingModel? model) { if (model == null) { return null; } - return new Order() + return new Order { - Id = model.Id, DocumentId = model.DocumentId, Count = model.Count, Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement, + Id = model.Id, }; } + public void Update(OrderBindingModel? model) { if (model == null) { return; } - Id = model.Id; - DocumentId = model.DocumentId; - Count = model.Count; - Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; DateImplement = model.DateImplement; } - public OrderViewModel GetViewModel => new() + + public OrderViewModel GetViewModel => new OrderViewModel { - Id = Id, DocumentId = DocumentId, Count = Count, Sum = Sum, - Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, + Id = Id, + Status = Status, + DocumentName = Document?.DocumentName ?? string.Empty // Безопасное использование DocumentName }; - } -} +} \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormMain.cs b/LawFirm/LawFirmView/FormMain.cs index d3d4f04..b29bb8c 100644 --- a/LawFirm/LawFirmView/FormMain.cs +++ b/LawFirm/LawFirmView/FormMain.cs @@ -3,15 +3,7 @@ using AbstractLawFirmContracts.BindingModels; using AbstractLawFirmContracts.BusinessLogicsContracts; using AbstractLawFirmDataModels.Enums; 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; +using AbstractLawFirmBusinessLogic.BusinessLogic; namespace LawFirmView { @@ -211,7 +203,7 @@ namespace LawFirmView form.ShowDialog(); } } - /* private void списокПакетовДокументовToolStripMenuItem_Click(object sender, EventArgs e) + private void списокПакетовДокументовToolStripMenuItem_Click(object sender, EventArgs e) { using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; if (dialog.ShowDialog() == DialogResult.OK) @@ -224,7 +216,6 @@ namespace LawFirmView MessageBoxIcon.Information); } } - */ private void компонентыПоПакетамДокументовToolStripMenuItem_Click(object sender, EventArgs e) { diff --git a/LawFirm/LawFirmView/FormMain.designer.cs b/LawFirm/LawFirmView/FormMain.designer.cs index 20f7278..6708305 100644 --- a/LawFirm/LawFirmView/FormMain.designer.cs +++ b/LawFirm/LawFirmView/FormMain.designer.cs @@ -33,13 +33,15 @@ компонентыToolStripMenuItem = new ToolStripMenuItem(); пакетыДокументовToolStripMenuItem = new ToolStripMenuItem(); формированиеОтчётовToolStripMenuItem = new ToolStripMenuItem(); + компонентыПоПакетамДокументовToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); buttonTakeOrderInWork = new Button(); buttonOrderReady = new Button(); buttonIssuedOrder = new Button(); buttonRef = new Button(); - компонентыПоПакетамДокументовToolStripMenuItem = new ToolStripMenuItem(); + списокПакетовДокументовToolStripMenuItem = new ToolStripMenuItem(); + списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -78,11 +80,18 @@ // // формированиеОтчётовToolStripMenuItem // - формированиеОтчётовToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыПоПакетамДокументовToolStripMenuItem }); + формированиеОтчётовToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыПоПакетамДокументовToolStripMenuItem, списокПакетовДокументовToolStripMenuItem, списокЗаказовToolStripMenuItem }); формированиеОтчётовToolStripMenuItem.Name = "формированиеОтчётовToolStripMenuItem"; формированиеОтчётовToolStripMenuItem.Size = new Size(259, 26); формированиеОтчётовToolStripMenuItem.Text = "Формирование отчётов"; // + // компонентыПоПакетамДокументовToolStripMenuItem + // + компонентыПоПакетамДокументовToolStripMenuItem.Name = "компонентыПоПакетамДокументовToolStripMenuItem"; + компонентыПоПакетамДокументовToolStripMenuItem.Size = new Size(351, 26); + компонентыПоПакетамДокументовToolStripMenuItem.Text = "Компоненты по пакетам документов"; + компонентыПоПакетамДокументовToolStripMenuItem.Click += компонентыПоПакетамДокументовToolStripMenuItem_Click; + // // dataGridView // dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -149,12 +158,19 @@ buttonRef.UseVisualStyleBackColor = true; buttonRef.Click += buttonRef_Click; // - // компонентыПоПакетамДокументовToolStripMenuItem + // списокПакетовДокументовToolStripMenuItem // - компонентыПоПакетамДокументовToolStripMenuItem.Name = "компонентыПоПакетамДокументовToolStripMenuItem"; - компонентыПоПакетамДокументовToolStripMenuItem.Size = new Size(357, 26); - компонентыПоПакетамДокументовToolStripMenuItem.Text = "Компоненты По Пакетам Документов"; - компонентыПоПакетамДокументовToolStripMenuItem.Click += компонентыПоПакетамДокументовToolStripMenuItem_Click; + списокПакетовДокументовToolStripMenuItem.Name = "списокПакетовДокументовToolStripMenuItem"; + списокПакетовДокументовToolStripMenuItem.Size = new Size(351, 26); + списокПакетовДокументовToolStripMenuItem.Text = "Список пакетов документов"; + списокПакетовДокументовToolStripMenuItem.Click += списокПакетовДокументовToolStripMenuItem_Click; + // + // списокЗаказовToolStripMenuItem + // + списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; + списокЗаказовToolStripMenuItem.Size = new Size(351, 26); + списокЗаказовToolStripMenuItem.Text = "Список заказов"; + списокЗаказовToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click; // // FormMain // @@ -194,5 +210,7 @@ private Button buttonRef; private ToolStripMenuItem формированиеОтчётовToolStripMenuItem; private ToolStripMenuItem компонентыПоПакетамДокументовToolStripMenuItem; + private ToolStripMenuItem списокПакетовДокументовToolStripMenuItem; + private ToolStripMenuItem списокЗаказовToolStripMenuItem; } } \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormReportDocumentComponents.cs b/LawFirm/LawFirmView/FormReportDocumentComponents.cs index 6a8bf0a..aec9d2d 100644 --- a/LawFirm/LawFirmView/FormReportDocumentComponents.cs +++ b/LawFirm/LawFirmView/FormReportDocumentComponents.cs @@ -34,7 +34,6 @@ namespace LawFirmView dataGridView.Rows.Clear(); foreach (var elem in dict) { - // проверить ComponentName Document (поменять местами) dataGridView.Rows.Add(new object[] { elem.DocumentName, "", "" }); foreach (var listElem in elem.Components) { @@ -86,4 +85,4 @@ namespace LawFirmView } } } -} +} \ No newline at end of file diff --git a/LawFirm/LawFirmView/FormReportOrders.cs b/LawFirm/LawFirmView/FormReportOrders.cs index c32b800..58804a5 100644 --- a/LawFirm/LawFirmView/FormReportOrders.cs +++ b/LawFirm/LawFirmView/FormReportOrders.cs @@ -1,5 +1,4 @@ -using AbstractLawFirmContracts.BindingModels; -using AbstractLawFirmContracts.BusinessLogicsContracts; +using AbstractLawFirmContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; using Microsoft.Reporting.WinForms; using System; @@ -11,6 +10,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using AbstractLawFirmContracts.BindingModels; namespace LawFirmView { @@ -19,8 +19,7 @@ namespace LawFirmView private readonly ReportViewer reportViewer; private readonly ILogger _logger; private readonly IReportLogic _logic; - public FormReportOrders(ILogger logger, IReportLogic - logic) + public FormReportOrders(ILogger logger, IReportLogic logic) { InitializeComponent(); _logger = logger; @@ -29,13 +28,14 @@ namespace LawFirmView { Dock = DockStyle.Fill }; - reportViewer.LocalReport.LoadReportDefinition(new - FileStream("ReportOrders.rdlc", FileMode.Open)); + reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportOrders.rdlc", FileMode.Open)); Controls.Clear(); Controls.Add(reportViewer); Controls.Add(panel); + } - private void ButtonMake_Click(object sender, EventArgs e) + + private void buttonMake_Click(object sender, EventArgs e) { if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date) { @@ -53,9 +53,12 @@ namespace LawFirmView var source = new ReportDataSource("DataSetOrders", dataSource); reportViewer.LocalReport.DataSources.Clear(); reportViewer.LocalReport.DataSources.Add(source); - var parameters = new[] { new ReportParameter("ReportParameterPeriod", $"c {dateTimePickerFrom.Value.ToShortDateString()} по{dateTimePickerTo.Value.ToShortDateString()}") }; reportViewer.LocalReport.SetParameters(parameters); + var parameters = new[] { new ReportParameter("ReportParameterPeriod", + $"c {dateTimePickerFrom.Value.ToShortDateString()} по {dateTimePickerTo.Value.ToShortDateString()}") }; + reportViewer.LocalReport.SetParameters(parameters); reportViewer.RefreshReport(); - _logger.LogInformation("Загрузка списка заказов на период {From}- { To} ", dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString()); + _logger.LogInformation("Загрузка списка заказов на период {From}- { To} ", dateTimePickerFrom.Value.ToShortDateString(), + dateTimePickerTo.Value.ToShortDateString()); } catch (Exception ex) { @@ -63,8 +66,10 @@ namespace LawFirmView MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } + } - private void ButtonToPdf_Click(object sender, EventArgs e) + + private void buttonToPdf_Click(object sender, EventArgs e) { if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date) { @@ -86,7 +91,8 @@ namespace LawFirmView DateFrom = dateTimePickerFrom.Value, DateTo = dateTimePickerTo.Value }); - _logger.LogInformation("Сохранение списка заказов на период { From} -{ To} ", dateTimePickerFrom.Value.ToShortDateString(), + _logger.LogInformation("Сохранение списка заказов на период { From} -{ To} ", + dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString()); MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); @@ -94,10 +100,12 @@ namespace LawFirmView catch (Exception ex) { _logger.LogError(ex, "Ошибка сохранения списка заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + } } } diff --git a/LawFirm/LawFirmView/LawFirmView.csproj b/LawFirm/LawFirmView/LawFirmView.csproj index c2052cd..4febd57 100644 --- a/LawFirm/LawFirmView/LawFirmView.csproj +++ b/LawFirm/LawFirmView/LawFirmView.csproj @@ -25,4 +25,9 @@ + + + Always + + \ No newline at end of file diff --git a/LawFirm/LawFirmView/Report.rdlc b/LawFirm/LawFirmView/Report.rdlc index c30cb52..77e3f91 100644 --- a/LawFirm/LawFirmView/Report.rdlc +++ b/LawFirm/LawFirmView/Report.rdlc @@ -1,6 +1,6 @@ - 0 + 0 @@ -581,19 +581,19 @@ ReportParameter1 - - - 4 - 2 - - - 0 - 0 - ReportParameterPeriod - - - - - Cm - 0450af05-3af7-4c1a-9e54-1c474b4807b8 + + + 4 + 2 + + + 0 + 0 + ReportParameterPeriod + + + + + Cm + 2de0031a-4d17-449d-922d-d9fc54572312 \ No newline at end of file