From 9f0b8cb818dd88841e32725c9c6f7f75e73c85a3 Mon Sep 17 00:00:00 2001 From: Zyzf Date: Tue, 18 Apr 2023 04:36:18 -0700 Subject: [PATCH] done --- .../Implements/OrderStorage.cs | 21 +- .../BlacksmithWorkshopBusinessLogic.csproj | 2 + .../BusinessLogics/OrderLogic.cs | 1 - .../BusinessLogics/ReportLogic.cs | 212 +++++++ .../BusinessLogics/ShopLogic.cs | 8 +- .../OfficePackage/AbstractSaveToExcel.cs | 167 +++++ .../OfficePackage/AbstractSaveToPdf.cs | 109 ++++ .../OfficePackage/AbstractSaveToWord.cs | 92 +++ .../HelperEnums/ExcelStyleInfoType.cs | 15 + .../HelperEnums/PdfParagraphAlignmentType.cs | 15 + .../HelperEnums/WordJustificationType.cs | 14 + .../HelperModels/ExcelCellParameters.cs | 18 + .../OfficePackage/HelperModels/ExcelInfo.cs | 20 + .../HelperModels/ExcelInfoShop.cs | 16 + .../HelperModels/ExcelMergeParameters.cs | 15 + .../OfficePackage/HelperModels/PdfInfo.cs | 18 + .../HelperModels/PdfInfoOrdersByDate.cs | 16 + .../HelperModels/PdfParagraph.cs | 16 + .../HelperModels/PdfRowParameters.cs | 16 + .../OfficePackage/HelperModels/WordInfo.cs | 16 + .../HelperModels/WordInfoShopTable.cs | 16 + .../HelperModels/WordParagraph.cs | 14 + .../OfficePackage/HelperModels/WordTable.cs | 14 + .../HelperModels/WordTextProperties.cs | 16 + .../OfficePackage/Implements/SaveToExcel.cs | 320 ++++++++++ .../OfficePackage/Implements/SaveToPdf.cs | 101 +++ .../OfficePackage/Implements/SaveToWord.cs | 161 +++++ .../BindingModels/ReportBindingModel.cs | 15 + .../BusinessLogicsContracts/IReportLogic.cs | 66 ++ .../SearchModels/OrderSearchModel.cs | 2 + .../ReportManufactureComponentViewModel.cs | 15 + .../ViewModels/ReportOrdersByDateViewModel.cs | 15 + .../ViewModels/ReportOrdersViewModel.cs | 17 + .../ReportShopManufactureViewModel.cs | 17 + .../Implements/OrderStorage.cs | 12 +- .../Implements/OrderStorage.cs | 20 +- .../BlacksmithWorkshopView.csproj | 10 + .../FormMain.Designer.cs | 483 ++++++++------ .../BlacksmithWorkshopView/FormMain.cs | 420 ++++++------ ...ormReportManufactureComponents.Designer.cs | 114 ++++ .../FormReportManufactureComponents.cs | 75 +++ .../FormReportManufactureComponents.resx | 120 ++++ .../FormReportOrders.Designer.cs | 141 +++++ .../FormReportOrders.cs | 95 +++ .../FormReportOrders.resx | 120 ++++ .../FormReportOrdersByDate.Designer.cs | 85 +++ .../FormReportOrdersByDate.cs | 76 +++ .../FormReportOrdersByDate.resx | 120 ++++ .../FormReportShopManufactures.Designer.cs | 104 +++ .../FormReportShopManufactures.cs | 81 +++ .../FormReportShopManufactures.resx | 120 ++++ .../FormSellManufacture.cs | 8 +- .../FormShop.Designer.cs | 416 ++++++------ .../BlacksmithWorkshopView/FormShop.cs | 226 +++---- .../BlacksmithWorkshopView/Program.cs | 13 +- .../BlacksmithWorkshopView/ReportOrders.rdlc | 599 ++++++++++++++++++ .../ReportOrdersByDate.rdlc | 404 ++++++++++++ 57 files changed, 4718 insertions(+), 740 deletions(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToWord.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelInfoShop.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfInfoOrdersByDate.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordInfoShopTable.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordTable.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/Implements/SaveToExcel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/Implements/SaveToWord.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ReportBindingModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IReportLogic.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ReportManufactureComponentViewModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ReportOrdersByDateViewModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ReportOrdersViewModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ReportShopManufactureViewModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopView/FormReportManufactureComponents.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopView/FormReportManufactureComponents.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopView/FormReportManufactureComponents.resx create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopView/FormReportOrders.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopView/FormReportOrders.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopView/FormReportOrders.resx create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopView/FormReportOrdersByDate.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopView/FormReportOrdersByDate.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopView/FormReportOrdersByDate.resx create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopView/FormReportShopManufactures.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopView/FormReportShopManufactures.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopView/FormReportShopManufactures.resx create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopView/ReportOrders.rdlc create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopView/ReportOrdersByDate.rdlc diff --git a/BlacksmithWorkshop/BlacksmithListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithListImplement/Implements/OrderStorage.cs index 94eef7c..40e5c63 100644 --- a/BlacksmithWorkshop/BlacksmithListImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithListImplement/Implements/OrderStorage.cs @@ -31,15 +31,28 @@ namespace BlacksmithWorkshopListImplement.Implements public List GetFilteredList(OrderSearchModel model) { var result = new List(); - if (model == null) + if (!model.Id.HasValue && (model.DateFrom == null || model.DateTo == null)) { return result; } - foreach (var Order in _source.Orders) + if (model.Id.HasValue) { - if (Order.Id == model.Id) + foreach (var order in _source.Orders) { - result.Add(Order.GetViewModel); + if (order.Id == model.Id) + { + result.Add(order.GetViewModel); + } + } + } + else + { + foreach (var order in _source.Orders) + { + if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo) + { + result.Add(order.GetViewModel); + } } } return result; diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj index d1c31eb..ab679fa 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj @@ -7,9 +7,11 @@ + + diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index 672c48b..5825b62 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -132,4 +132,3 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics } } } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs new file mode 100644 index 0000000..7d5839b --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ReportLogic.cs @@ -0,0 +1,212 @@ +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels; +using BlacksmithWorkshopBusinessLogic.OfficePackage; +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopContracts.StorageContracts; + +namespace ManufactureCompanyBusinessLogic.BusinessLogics +{ + public class ReportLogic : IReportLogic + { + private readonly IComponentStorage _componentStorage; + private readonly IManufactureStorage _manufactureStorage; + private readonly IOrderStorage _orderStorage; + private readonly IShopStorage _shopStorage; + private readonly AbstractSaveToExcel _saveToExcel; + private readonly AbstractSaveToWord _saveToWord; + private readonly AbstractSaveToPdf _saveToPdf; + public ReportLogic(IManufactureStorage manufactureStorage, IComponentStorage componentStorage, IOrderStorage orderStorage, IShopStorage shopStorage, + + AbstractSaveToExcel saveToExcel, AbstractSaveToWord saveToWord, AbstractSaveToPdf saveToPdf) + { + _manufactureStorage = manufactureStorage; + _componentStorage = componentStorage; + _orderStorage = orderStorage; + _shopStorage = shopStorage; + _saveToExcel = saveToExcel; + _saveToWord = saveToWord; + _saveToPdf = saveToPdf; + } + + /// + /// Получение списка компонент с указанием, в каких изделиях используются + /// + /// + public List GetManufactureComponent() + { + var components = _componentStorage.GetFullList(); + var manufactures = _manufactureStorage.GetFullList(); + var list = new List(); + + foreach (var manufacture in manufactures) + { + var record = new ReportManufactureComponentViewModel + { + ManufactureName = manufacture.ManufactureName, + Components = new List<(string, int)>(), + TotalCount = 0 + }; + foreach (var component in components) + { + if (manufacture.ManufactureComponents.ContainsKey(component.Id)) + { + record.Components.Add(new(component.ComponentName, manufacture.ManufactureComponents[component.Id].Item2)); + record.TotalCount += manufacture.ManufactureComponents[component.Id].Item2; + } + } + list.Add(record); + } + + return list; + } + + /// + /// Получение списка компонент с указанием, в каких изделиях используются + /// + /// + public List GetShopManufacture() + { + var shops = _shopStorage.GetFullList(); + var list = new List(); + + foreach (var shop in shops) + { + var record = new ReportShopManufactureViewModel + { + ShopName = shop.ShopName, + Manufactures = new List<(string, int)>(), + TotalCount = 0 + }; + foreach (var manufacture in shop.ListManufacture) + { + record.Manufactures.Add(new(manufacture.Value.Item1.ManufactureName, manufacture.Value.Item2)); + record.TotalCount += manufacture.Value.Item2; + } + list.Add(record); + } + return list; + } + + /// + /// Получение списка заказов за определенный период + /// + /// + /// + public List GetOrders(ReportBindingModel model) + { + return _orderStorage.GetFilteredList(new OrderSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo }) + .Select(x => new ReportOrdersViewModel + { + Id = x.Id, + DateCreate = x.DateCreate, + ManufactureName = x.ManufactureName, + Sum = x.Sum, + Status = Convert.ToString(x.Status) ?? string.Empty, + }) + .ToList(); + } + + /// + /// Получение списка заказов за весь период + /// + /// + public List GetOrdersByDate() + { + return _orderStorage.GetFullList() + .GroupBy(x => x.DateCreate.Date) + .Select(x => new ReportOrdersByDateViewModel + { + DateCreate = x.Key, + Count = x.Count(), + Sum = x.Sum(x => x.Sum) + }) + .ToList(); + } + + /// + /// Сохранение компонент в файл-Word + /// + /// + public void SaveComponentsToWordFile(ReportBindingModel model) + { + _saveToWord.CreateDoc(new WordInfo + { + FileName = model.FileName, + Title = "Список компонент", + Manufactures = _manufactureStorage.GetFullList() + }); + } + + /// + /// Сохранение компонент с указаеним продуктов в файл-Excel + /// + /// + public void SaveManufactureComponentToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateReport(new ExcelInfo + { + FileName = model.FileName, + Title = "Список компонент", + ManufactureComponents = GetManufactureComponent() + }); + } + + /// + /// Сохранение заказов в файл-Pdf + /// + /// + public void SaveOrdersToPdfFile(ReportBindingModel model) + { + _saveToPdf.CreateDoc(new PdfInfo + { + FileName = model.FileName, + Title = "Список заказов", + DateFrom = model.DateFrom!.Value, + DateTo = model.DateTo!.Value, + Orders = GetOrders(model) + }); + } + /// + /// Сохранение магазинов в файл-Word + /// + /// + public void SaveShopsToWordFile(ReportBindingModel model) + { + _saveToWord.CreateDocShopTable(new WordInfoShopTable + { + FileName = model.FileName, + Title = "Список магазинов", + Shops = _shopStorage.GetFullList() + }); + } + /// + /// Сохранение магазинов с указаеним поездок в файл-Excel + /// + /// + public void SaveShopManufactureToExcelFile(ReportBindingModel model) + { + _saveToExcel.CreateShopReport(new ExcelInfoShop + { + FileName = model.FileName, + Title = "Список магазинов", + ShopManufactures = GetShopManufacture() + }); + } + /// + /// Сохранение заказов в файл-Pdf + /// + /// + public void SaveOrdersByDateToPdfFile(ReportBindingModel model) + { + _saveToPdf.CreateDocOrdersByDate(new PdfInfoOrdersByDate + { + FileName = model.FileName, + Title = "Список заказов", + Orders = GetOrdersByDate() + }); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs index e10724e..de32859 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ShopLogic.cs @@ -105,15 +105,15 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics throw new InvalidOperationException("Магазин с таким названием уже есть"); } } - public bool AddManufactureInShop(ShopSearchModel model, IManufactureModel manufacture, int count) - { + public bool AddManufactureInShop(ShopSearchModel model, IManufactureModel manufacture, int count) + { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (count < 0) { - throw new ArgumentException("Количество изделий должно быть больше 0", nameof(count)); + throw new ArgumentException("Количество поездок должно быть больше 0", nameof(count)); } _logger.LogInformation("AddManufactureInShop. ShopName:{ShopName}. Id:{Id}", model.ShopName, model.Id); var shop = _shopStorage.GetElement(model); @@ -149,7 +149,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics }); return true; } - public bool AddManufactures(IManufactureModel model, int count) + public bool AddManufactures(IManufactureModel model, int count) { if (model == null) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs new file mode 100644 index 0000000..2027926 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -0,0 +1,167 @@ +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums; +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToExcel + { + /// + /// Создание отчета + /// + /// + public void CreateReport(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.ManufactureComponents) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = pc.ManufactureName, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + foreach (var components in pc.Components) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = components.Item1, + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = components.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.TotalCount.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + } + SaveExcel(info); + } + /// + /// Создание отчета по магазинам + /// + /// + public void CreateShopReport(ExcelInfoShop info) + { + CreateExcel(new ExcelInfo() { FileName = info.FileName }); + 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 st in info.ShopManufactures) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = st.ShopName, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + foreach (var travel in st.Manufactures) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = travel.Item1, + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = travel.Item2.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); + rowIndex++; + } + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = "Итого", + StyleInfo = ExcelStyleInfoType.Text + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = st.TotalCount.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + } + SaveExcel(new ExcelInfo() { FileName = info.FileName }); + } + /// + /// Создание excel-файла + /// + /// + protected abstract void CreateExcel(ExcelInfo info); + /// + /// Добавляем новую ячейку в лист + /// + /// + protected abstract void InsertCellInWorksheet(ExcelCellParameters + excelParams); + /// + /// Объединение ячеек + /// + /// + protected abstract void MergeCells(ExcelMergeParameters excelParams); + /// + /// Сохранение файла + /// + /// + protected abstract void SaveExcel(ExcelInfo info); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs new file mode 100644 index 0000000..f1dc0fb --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -0,0 +1,109 @@ +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums; +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToPdf + { + public void CreateDoc(PdfInfo info) + { + CreatePdf(info); + CreateParagraph(new PdfParagraph + { + Text = info.Title, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateParagraph(new PdfParagraph + { + Text = $"с { info.DateFrom.ToShortDateString() } по { info.DateTo.ToShortDateString() }", Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + CreateTable(new List { "2cm", "3cm", "6cm", "3cm", "3cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Номер", "Дата заказа", "Изделие", "Статус", "Сумма" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach (var order in info.Orders) + { + CreateRow(new PdfRowParameters + { + Texts = new List { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.ManufactureName, order.Status, order.Sum.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + CreateParagraph(new PdfParagraph + { + Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Right + }); + SavePdf(info); + } + public void CreateDocOrdersByDate(PdfInfoOrdersByDate info) + { + CreatePdf(new PdfInfo() { FileName = info.FileName }); + CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + + CreateTable(new List { "5cm", "4cm", "4cm" }); + + CreateRow(new PdfRowParameters + { + Texts = new List { "Дата", "Количество", "Сумма" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach (var order in info.Orders) + { + CreateRow(new PdfRowParameters + { + Texts = new List { order.DateCreate.ToShortDateString(), order.Count.ToString(), order.Sum.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + CreateParagraph(new PdfParagraph + { + Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Right + }); + SavePdf(new PdfInfo() { FileName = info.FileName }); + } + /// + /// Создание doc-файла + /// + /// + protected abstract void CreatePdf(PdfInfo info); + /// + /// Создание параграфа с текстом + /// + /// + /// + protected abstract void CreateParagraph(PdfParagraph paragraph); + /// + /// Создание таблицы + /// + /// + /// + protected abstract void CreateTable(List columns); + /// + /// Создание и заполнение строки + /// + /// + protected abstract void CreateRow(PdfRowParameters rowParameters); + /// + /// Сохранение файла + /// + /// + protected abstract void SavePdf(PdfInfo info); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToWord.cs new file mode 100644 index 0000000..8974747 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -0,0 +1,92 @@ +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums; +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToWord + { + public void CreateDoc(WordInfo info) + { + CreateWord(info); + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Center + } + }); + foreach (var manufacture in info.Manufactures) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> + { + (manufacture.ManufactureName, new WordTextProperties { Bold = true, Size = "24", }), + (", price: " + manufacture.Price.ToString(), new WordTextProperties { Size = "24", }) + }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + } + SaveWord(info); + } + public void CreateDocShopTable(WordInfoShopTable info) + { + CreateWord(new() { FileName = info.FileName }); + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Center + } + }); + CreateTable(new() + { + Columns = new() { ("Название", 3000), ("Дата открытия", 3000), ("Адрес", 3000) }, + Rows = info.Shops.Select(x => new List + { + x.ShopName, + Convert.ToString(x.DateOpening), + x.Address, + }) + .ToList() + }); + + SaveWord(new() { FileName = info.FileName }); + } + /// + /// Создание doc-файла + /// + /// + protected abstract void CreateWord(WordInfo info); + /// + /// Создание абзаца с текстом + /// + /// + /// + protected abstract void CreateParagraph(WordParagraph paragraph); + /// + /// Создание таблицы + /// + /// + /// + protected abstract void CreateTable(WordTable table); + /// + /// Сохранение файла + /// + /// + protected abstract void SaveWord(WordInfo info); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs new file mode 100644 index 0000000..d70198a --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums +{ + public enum ExcelStyleInfoType + { + Title, + Text, + TextWithBorder + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs new file mode 100644 index 0000000..a91eeb1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums +{ + public enum PdfParagraphAlignmentType + { + Center, + Left, + Right + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs new file mode 100644 index 0000000..d9094e7 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums +{ + public enum WordJustificationType + { + Center, + Both + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs new file mode 100644 index 0000000..780ecaf --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs @@ -0,0 +1,18 @@ +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelCellParameters + { + public string ColumnName { get; set; } = string.Empty; + public uint RowIndex { get; set; } + public string Text { get; set; } = string.Empty; + public string CellReference => $"{ColumnName}{RowIndex}"; + public ExcelStyleInfoType StyleInfo { get; set; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs new file mode 100644 index 0000000..285bd45 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -0,0 +1,20 @@ +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelInfo + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List ManufactureComponents + { + get; + set; + } = new(); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelInfoShop.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelInfoShop.cs new file mode 100644 index 0000000..0faef50 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelInfoShop.cs @@ -0,0 +1,16 @@ +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelInfoShop + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List ShopManufactures { get; set; } = new(); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs new file mode 100644 index 0000000..0a0f1d6 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelMergeParameters + { + public string CellFromName { get; set; } = string.Empty; + public string CellToName { get; set; } = string.Empty; + public string Merge => $"{CellFromName}:{CellToName}"; + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs new file mode 100644 index 0000000..353cd4a --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -0,0 +1,18 @@ +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class PdfInfo + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public DateTime DateFrom { get; set; } + public DateTime DateTo { get; set; } + public List Orders { get; set; } = new(); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfInfoOrdersByDate.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfInfoOrdersByDate.cs new file mode 100644 index 0000000..96e2fff --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfInfoOrdersByDate.cs @@ -0,0 +1,16 @@ +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class PdfInfoOrdersByDate + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List Orders { get; set; } = new(); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs new file mode 100644 index 0000000..4179c2a --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs @@ -0,0 +1,16 @@ +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class PdfParagraph + { + public string Text { get; set; } = string.Empty; + public string Style { get; set; } = string.Empty; + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs new file mode 100644 index 0000000..77e4470 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs @@ -0,0 +1,16 @@ +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class PdfRowParameters + { + public List Texts { get; set; } = new(); + public string Style { get; set; } = string.Empty; + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs new file mode 100644 index 0000000..f90b458 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -0,0 +1,16 @@ +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class WordInfo + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List Manufactures { get; set; } = new(); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordInfoShopTable.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordInfoShopTable.cs new file mode 100644 index 0000000..20ebceb --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordInfoShopTable.cs @@ -0,0 +1,16 @@ +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class WordInfoShopTable + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List Shops { get; set; } = new(); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs new file mode 100644 index 0000000..cf40d79 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class WordParagraph + { + public List<(string, WordTextProperties)> Texts { get; set; } = new(); + public WordTextProperties? TextProperties { get; set; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordTable.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordTable.cs new file mode 100644 index 0000000..1c2dc7b --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/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 BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class WordTable + { + public List<(string, int)> Columns { get; set; } = new(); + public List> Rows { get; set; } = new(); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs new file mode 100644 index 0000000..ecf71ed --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs @@ -0,0 +1,16 @@ +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class WordTextProperties + { + public string Size { get; set; } = string.Empty; + public bool Bold { get; set; } + public WordJustificationType JustificationType { get; set; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/Implements/SaveToExcel.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/Implements/SaveToExcel.cs new file mode 100644 index 0000000..d8e8dcc --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/Implements/SaveToExcel.cs @@ -0,0 +1,320 @@ +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums; +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels; +using DocumentFormat.OpenXml.Office2010.Excel; +using DocumentFormat.OpenXml.Office2013.Excel; +using DocumentFormat.OpenXml.Office2016.Excel; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; +using DocumentFormat.OpenXml; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage.Implements +{ + public class SaveToExcel : AbstractSaveToExcel + { + private SpreadsheetDocument? _spreadsheetDocument; + private SharedStringTablePart? _shareStringPart; + private Worksheet? _worksheet; + /// + /// Настройка стилей для файла + /// + /// + private static void CreateStyles(WorkbookPart workbookpart) + { + var sp = workbookpart.AddNewPart(); + sp.Stylesheet = new Stylesheet(); + var fonts = new Fonts() { Count = 2U, KnownFonts = true }; + var fontUsual = new Font(); + fontUsual.Append(new FontSize() { Val = 12D }); + fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U }); + fontUsual.Append(new FontName() { Val = "Times New Roman" }); + fontUsual.Append(new FontFamilyNumbering() { Val = 2 }); + fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor }); + var fontTitle = new Font(); + fontTitle.Append(new Bold()); + fontTitle.Append(new FontSize() { Val = 14D }); + fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U }); + fontTitle.Append(new FontName() { Val = "Times New Roman" }); + fontTitle.Append(new FontFamilyNumbering() { Val = 2 }); + fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor }); + fonts.Append(fontUsual); + fonts.Append(fontTitle); + var fills = new Fills() { Count = 2U }; + var fill1 = new Fill(); + fill1.Append(new PatternFill() { PatternType = PatternValues.None }); + var fill2 = new Fill(); + fill2.Append(new PatternFill() + { + PatternType = PatternValues.Gray125 + }); + fills.Append(fill1); + fills.Append(fill2); + var borders = new Borders() { Count = 2U }; + var borderNoBorder = new Border(); + borderNoBorder.Append(new LeftBorder()); + borderNoBorder.Append(new RightBorder()); + borderNoBorder.Append(new TopBorder()); + borderNoBorder.Append(new BottomBorder()); + borderNoBorder.Append(new DiagonalBorder()); + var borderThin = new Border(); + var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin }; + leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + var rightBorder = new RightBorder() + { + Style = BorderStyleValues.Thin + }; + rightBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + var topBorder = new TopBorder() { Style = BorderStyleValues.Thin }; + topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + var bottomBorder = new BottomBorder() + { + Style = BorderStyleValues.Thin + }; + bottomBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + borderThin.Append(leftBorder); + borderThin.Append(rightBorder); + borderThin.Append(topBorder); + borderThin.Append(bottomBorder); + borderThin.Append(new DiagonalBorder()); + borders.Append(borderNoBorder); + borders.Append(borderThin); + var cellStyleFormats = new CellStyleFormats() { Count = 1U }; + var cellFormatStyle = new CellFormat() + { + NumberFormatId = 0U, + FontId = 0U, + FillId = 0U, + BorderId = 0U + }; + cellStyleFormats.Append(cellFormatStyle); + var cellFormats = new CellFormats() { Count = 3U }; + var cellFormatFont = new CellFormat() + { + NumberFormatId = 0U, + FontId = 0U, + FillId = 0U, + BorderId = 0U, + FormatId = 0U, + ApplyFont = true + }; + var cellFormatFontAndBorder = new CellFormat() + { + NumberFormatId = 0U, + FontId = 0U, + FillId = 0U, + BorderId = 1U, + FormatId = 0U, + ApplyFont = true, + ApplyBorder = true + }; + var cellFormatTitle = new CellFormat() + { + NumberFormatId = 0U, + FontId = 1U, + FillId = 0U, + BorderId = 0U, + FormatId = 0U, + Alignment = new Alignment() + { + Vertical = VerticalAlignmentValues.Center, + WrapText = true, + Horizontal = HorizontalAlignmentValues.Center + }, + ApplyFont = true + }; + cellFormats.Append(cellFormatFont); + cellFormats.Append(cellFormatFontAndBorder); + cellFormats.Append(cellFormatTitle); + var cellStyles = new CellStyles() { Count = 1U }; + cellStyles.Append(new CellStyle() + { + Name = "Normal", + FormatId = 0U, + BuiltinId = 0U + }); + var differentialFormats = new DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats() { Count = 0U }; + var tableStyles = new TableStyles() + { + Count = 0U, + DefaultTableStyle = "TableStyleMedium2", + DefaultPivotStyle = "PivotStyleLight16" + }; + var stylesheetExtensionList = new StylesheetExtensionList(); + var stylesheetExtension1 = new StylesheetExtension() + { + Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" + }; + stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); + stylesheetExtension1.Append(new SlicerStyles() + { + DefaultSlicerStyle = "SlicerStyleLight1" + }); + var stylesheetExtension2 = new StylesheetExtension() + { + Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}" + }; + stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"); + stylesheetExtension2.Append(new TimelineStyles() + { + DefaultTimelineStyle = "TimeSlicerStyleLight1" + }); + stylesheetExtensionList.Append(stylesheetExtension1); + stylesheetExtensionList.Append(stylesheetExtension2); + sp.Stylesheet.Append(fonts); + sp.Stylesheet.Append(fills); + sp.Stylesheet.Append(borders); + sp.Stylesheet.Append(cellStyleFormats); + sp.Stylesheet.Append(cellFormats); + sp.Stylesheet.Append(cellStyles); + sp.Stylesheet.Append(differentialFormats); + sp.Stylesheet.Append(tableStyles); + sp.Stylesheet.Append(stylesheetExtensionList); + } + /// + /// Получение номера стиля из типа + /// + /// + /// + private static uint GetStyleValue(ExcelStyleInfoType styleInfo) + { + return styleInfo switch + { + ExcelStyleInfoType.Title => 2U, + ExcelStyleInfoType.TextWithBorder => 1U, + ExcelStyleInfoType.Text => 0U, + _ => 0U, + }; + } + protected override void CreateExcel(ExcelInfo info) + { + _spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook); + // Создаем книгу (в ней хранятся листы) + var workbookpart = _spreadsheetDocument.AddWorkbookPart(); + workbookpart.Workbook = new Workbook(); + CreateStyles(workbookpart); + // Получаем/создаем хранилище текстов для книги + _shareStringPart = _spreadsheetDocument.WorkbookPart!.GetPartsOfType().Any() + ? _spreadsheetDocument.WorkbookPart.GetPartsOfType().First() + : _spreadsheetDocument.WorkbookPart.AddNewPart(); + // Создаем SharedStringTable, если его нет + if (_shareStringPart.SharedStringTable == null) + { + _shareStringPart.SharedStringTable = new SharedStringTable(); + } + // Создаем лист в книгу + var worksheetPart = workbookpart.AddNewPart(); + worksheetPart.Worksheet = new Worksheet(new SheetData()); + // Добавляем лист в книгу + var sheets = _spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets()); + var sheet = new Sheet() + { + Id = _spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), + SheetId = 1, + Name = "Лист" + }; + sheets.Append(sheet); + _worksheet = worksheetPart.Worksheet; + } + protected override void InsertCellInWorksheet(ExcelCellParameters excelParams) + { + if (_worksheet == null || _shareStringPart == null) + { + return; + } + var sheetData = _worksheet.GetFirstChild(); + if (sheetData == null) + { + return; + } + // Ищем строку, либо добавляем ее + Row row; + if (sheetData.Elements().Where(r => r.RowIndex! == excelParams.RowIndex).Any()) + { + row = sheetData.Elements().Where(r => r.RowIndex! == excelParams.RowIndex).First(); + } + else + { + row = new Row() { RowIndex = excelParams.RowIndex }; + sheetData.Append(row); + } + // Ищем нужную ячейку + Cell cell; + if (row.Elements().Where(c => c.CellReference!.Value == excelParams.CellReference).Any()) + { + cell = row.Elements().Where(c => c.CellReference!.Value == excelParams.CellReference).First(); + } + else + { + // Все ячейки должны быть последовательно друг за другом расположены + // нужно определить, после какой вставлять + Cell? refCell = null; + foreach (Cell rowCell in row.Elements()) + { + if (string.Compare(rowCell.CellReference!.Value, + excelParams.CellReference, true) > 0) + { + refCell = rowCell; + break; + } + } + var newCell = new Cell() + { + CellReference = excelParams.CellReference + }; + row.InsertBefore(newCell, refCell); + cell = newCell; + } + // вставляем новый текст + _shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(excelParams.Text))); + _shareStringPart.SharedStringTable.Save(); + cell.CellValue = new + CellValue((_shareStringPart.SharedStringTable.Elements().Count() - 1).ToString()); + cell.DataType = new EnumValue(CellValues.SharedString); + cell.StyleIndex = GetStyleValue(excelParams.StyleInfo); + } + protected override void MergeCells(ExcelMergeParameters excelParams) + { + if (_worksheet == null) + { + return; + } + MergeCells mergeCells; + if (_worksheet.Elements().Any()) + { + mergeCells = _worksheet.Elements().First(); + } + else + { + mergeCells = new MergeCells(); + if (_worksheet.Elements().Any()) + { + _worksheet.InsertAfter(mergeCells, + _worksheet.Elements().First()); + } + else + { + _worksheet.InsertAfter(mergeCells, + _worksheet.Elements().First()); + } + } + var mergeCell = new MergeCell() + { + Reference = new StringValue(excelParams.Merge) + }; + mergeCells.Append(mergeCell); + } + protected override void SaveExcel(ExcelInfo info) + { + if (_spreadsheetDocument == null) + { + return; + } + _spreadsheetDocument.WorkbookPart!.Workbook.Save(); + _spreadsheetDocument.Close(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs new file mode 100644 index 0000000..8383008 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/Implements/SaveToPdf.cs @@ -0,0 +1,101 @@ +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums; +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels; +using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Tables; +using MigraDoc.Rendering; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage.Implements +{ + public class SaveToPdf : AbstractSaveToPdf + { + private Document? _document; + private Section? _section; + private Table? _table; + private static ParagraphAlignment + GetParagraphAlignment(PdfParagraphAlignmentType type) + { + return type switch + { + PdfParagraphAlignmentType.Center => ParagraphAlignment.Center, + PdfParagraphAlignmentType.Left => ParagraphAlignment.Left, + PdfParagraphAlignmentType.Right => ParagraphAlignment.Right, + _ => ParagraphAlignment.Justify, + }; + } + /// + /// Создание стилей для документа + /// + /// + private static void DefineStyles(Document document) + { + var style = document.Styles["Normal"]; + style.Font.Name = "Times New Roman"; + style.Font.Size = 14; + style = document.Styles.AddStyle("NormalTitle", "Normal"); + style.Font.Bold = true; + } + protected override void CreatePdf(PdfInfo info) + { + _document = new Document(); + DefineStyles(_document); + _section = _document.AddSection(); + } + protected override void CreateParagraph(PdfParagraph pdfParagraph) + { + if (_section == null) + { + return; + } + var paragraph = _section.AddParagraph(pdfParagraph.Text); + paragraph.Format.SpaceAfter = "1cm"; + paragraph.Format.Alignment = + GetParagraphAlignment(pdfParagraph.ParagraphAlignment); + paragraph.Style = pdfParagraph.Style; + } + protected override void CreateTable(List columns) + { + if (_document == null) + { + return; + } + _table = _document.LastSection.AddTable(); + foreach (var elem in columns) + { + _table.AddColumn(elem); + } + } + protected override void CreateRow(PdfRowParameters rowParameters) + { + if (_table == null) + { + return; + } + var row = _table.AddRow(); + for (int i = 0; i < rowParameters.Texts.Count; ++i) + { + row.Cells[i].AddParagraph(rowParameters.Texts[i]); + if (!string.IsNullOrEmpty(rowParameters.Style)) + { + row.Cells[i].Style = rowParameters.Style; + } + Unit borderWidth = 0.5; + row.Cells[i].Borders.Left.Width = borderWidth; + row.Cells[i].Borders.Right.Width = borderWidth; + row.Cells[i].Borders.Top.Width = borderWidth; + row.Cells[i].Borders.Bottom.Width = borderWidth; + row.Cells[i].Format.Alignment = + GetParagraphAlignment(rowParameters.ParagraphAlignment); + row.Cells[i].VerticalAlignment = VerticalAlignment.Center; + } + } + protected override void SavePdf(PdfInfo info) + { + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(info.FileName); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/Implements/SaveToWord.cs new file mode 100644 index 0000000..c98724e --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -0,0 +1,161 @@ +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums; +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection.Metadata; +using System.Text; +using System.Threading.Tasks; +using static System.Net.Mime.MediaTypeNames; +using Document = DocumentFormat.OpenXml.Wordprocessing.Document; +using Text = DocumentFormat.OpenXml.Wordprocessing.Text; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage.Implements +{ + public class SaveToWord : AbstractSaveToWord + { + private WordprocessingDocument? _wordDocument; + private Body? _docBody; + /// + /// Получение типа выравнивания + /// + /// + /// + private static JustificationValues GetJustificationValues(WordJustificationType type) + { + return type switch + { + WordJustificationType.Both => JustificationValues.Both, + WordJustificationType.Center => JustificationValues.Center, + _ => JustificationValues.Left, + }; + } + /// + /// Настройки страницы + /// + /// + private static SectionProperties CreateSectionProperties() + { + var properties = new SectionProperties(); + var pageSize = new PageSize + { + Orient = PageOrientationValues.Portrait + }; + properties.AppendChild(pageSize); + return properties; + } + /// + /// Задание форматирования для абзаца + /// + /// + /// + private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties) + { + if (paragraphProperties == null) + { + return null; + } + var properties = new ParagraphProperties(); + properties.AppendChild(new Justification() + { + Val = GetJustificationValues(paragraphProperties.JustificationType) + }); + properties.AppendChild(new SpacingBetweenLines + { + LineRule = LineSpacingRuleValues.Auto + }); + properties.AppendChild(new Indentation()); + var paragraphMarkRunProperties = new ParagraphMarkRunProperties(); + if (!string.IsNullOrEmpty(paragraphProperties.Size)) + { + paragraphMarkRunProperties.AppendChild(new FontSize + { + Val = paragraphProperties.Size + }); + } + properties.AppendChild(paragraphMarkRunProperties); + return properties; + } + protected override void CreateWord(WordInfo info) + { + _wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document); + MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); + mainPart.Document = new Document(); + _docBody = mainPart.Document.AppendChild(new Body()); + } + protected override void CreateParagraph(WordParagraph paragraph) + { + if (_docBody == null || paragraph == null) + { + return; + } + var docParagraph = new Paragraph(); + docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties)); + foreach (var run in paragraph.Texts) + { + var docRun = new Run(); + var properties = new RunProperties(); + properties.AppendChild(new FontSize { Val = run.Item2.Size }); + if (run.Item2.Bold) + { + properties.AppendChild(new Bold()); + } + docRun.AppendChild(properties); + docRun.AppendChild(new Text + { + Text = run.Item1, + Space = SpaceProcessingModeValues.Preserve + }); + docParagraph.AppendChild(docRun); + } + _docBody.AppendChild(docParagraph); + } + private static TableCell CreateTableCell(string text, int? cellWidth = null) + { + TableCell tableCell = new(new Paragraph(new Run(new Text(text)))); + tableCell.Append(new TableCellProperties() + { + TableCellWidth = new() { Width = cellWidth.ToString() } + }); + return tableCell; + } + protected override void CreateTable(WordTable table) + { + if (_docBody == null || table == null) + { + return; + } + var docTable = new Table(); + + TableProperties tableProperties = new( + new TableBorders( + new TopBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 }, + new BottomBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 }, + new LeftBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 }, + new RightBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 }, + new InsideHorizontalBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 }, + new InsideVerticalBorder() { Val = new EnumValue(BorderValues.BasicBlackDashes), Size = 3 } + ) + ); + docTable.AppendChild(tableProperties); + + docTable.Append(new TableRow(table.Columns.Select(x => CreateTableCell(x.Item1, x.Item2)))); + docTable.Append(table.Rows.Select(x => new TableRow(x.Select(y => CreateTableCell(y))))); + + _docBody.AppendChild(docTable); + } + protected override void SaveWord(WordInfo info) + { + if (_docBody == null || _wordDocument == null) + { + return; + } + _docBody.AppendChild(CreateSectionProperties()); + _wordDocument.MainDocumentPart!.Document.Save(); + _wordDocument.Close(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ReportBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ReportBindingModel.cs new file mode 100644 index 0000000..aa09ace --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ReportBindingModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.BindingModels +{ + public class ReportBindingModel + { + public string FileName { get; set; } = string.Empty; + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IReportLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IReportLogic.cs new file mode 100644 index 0000000..5b905ed --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IReportLogic.cs @@ -0,0 +1,66 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.BusinessLogicsContracts +{ + public interface IReportLogic + { + /// + /// Получение списка компонент с указанием, в каких изделиях используются + /// + /// + List GetManufactureComponent(); + /// + /// Получение списка магазинов с изделиями + /// + /// + List GetShopManufacture(); + /// + /// Получение списка заказов за определенный период + /// + /// + /// + List GetOrders(ReportBindingModel model); + /// + /// Получение списка заказов за весь период + /// + /// + /// + List GetOrdersByDate(); + /// + /// Сохранение компонент в файл-Word + /// + /// + void SaveComponentsToWordFile(ReportBindingModel model); + /// + /// Сохранение компонент с указаеним продуктов в файл-Excel + /// + /// + void SaveManufactureComponentToExcelFile(ReportBindingModel model); + /// + /// Сохранение заказов в файл-Pdf + /// + /// + void SaveOrdersToPdfFile(ReportBindingModel model); + /// + /// Сохранение магазинов в файл-Word + /// + /// + void SaveShopsToWordFile(ReportBindingModel model); + /// + /// Сохранение магазинов с указаеним изделий в файл-Excel + /// + /// + void SaveShopManufactureToExcelFile(ReportBindingModel model); + /// + /// Сохранение заказов по дате в файл-Pdf + /// + /// + public void SaveOrdersByDateToPdfFile(ReportBindingModel model); + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs index e68f27f..da7c683 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs @@ -9,5 +9,7 @@ namespace BlacksmithWorkshopContracts.SearchModels public class OrderSearchModel { public int? Id { get; set; } + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ReportManufactureComponentViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ReportManufactureComponentViewModel.cs new file mode 100644 index 0000000..04387cd --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ReportManufactureComponentViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.ViewModels +{ + public class ReportManufactureComponentViewModel + { + public string ManufactureName { get; set; } = string.Empty; + public int TotalCount { get; set; } + public List<(string Component, int Count)> Components { get; set; } = new(); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ReportOrdersByDateViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ReportOrdersByDateViewModel.cs new file mode 100644 index 0000000..b989223 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ReportOrdersByDateViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.ViewModels +{ + public class ReportOrdersByDateViewModel + { + public DateTime DateCreate { get; set; } + public int Count { get; set; } + public double Sum { get; set; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ReportOrdersViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ReportOrdersViewModel.cs new file mode 100644 index 0000000..175fe7f --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ReportOrdersViewModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.ViewModels +{ + public class ReportOrdersViewModel + { + public int Id { get; set; } + public DateTime DateCreate { get; set; } + public string ManufactureName { get; set; } = string.Empty; + public double Sum { get; set; } + public string Status { get; set; } = string.Empty; + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ReportShopManufactureViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ReportShopManufactureViewModel.cs new file mode 100644 index 0000000..5916e5c --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ReportShopManufactureViewModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.ViewModels +{ + public class ReportShopManufactureViewModel + { + public string ShopName { get; set; } = string.Empty; + + public int TotalCount { get; set; } + + public List<(string Manufacture, int Count)> Manufactures { get; set; } = new(); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs index 8f0489a..d8196d1 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs @@ -33,12 +33,20 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements } public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && (model.DateFrom == null || model.DateTo == null)) { return new(); } using var context = new BlacksmithWorkshopDatabase(); - return context.Orders.Include(x => x.Manufacture).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); + if (model.Id.HasValue) + { + return context.Orders.Include(x => x.Manufacture).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); + } + else + { + return context.Orders.Include(x => x.Manufacture).Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) + .Select(x => x.GetViewModel).ToList(); + } } public List GetFullList() { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs index cd17fc1..ffb0865 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs @@ -21,14 +21,24 @@ namespace BlacksmithWorkshopFileImplement.Implements } public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && (model.DateFrom == null || model.DateTo == null)) { return new(); } - return source.Orders - .Where(x => x.Id == model.Id) - .Select(x => GetViewModel(x)) - .ToList(); + if (model.Id.HasValue) + { + return source.Orders + .Where(x => x.Id == model.Id) + .Select(x => GetViewModel(x)) + .ToList(); + } + else + { + return source.Orders + .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) + .Select(x => GetViewModel(x)) + .ToList(); + } } public List GetFullList() { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/BlacksmithWorkshopView.csproj b/BlacksmithWorkshop/BlacksmithWorkshopView/BlacksmithWorkshopView.csproj index 3cf23aa..ff2006b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopView/BlacksmithWorkshopView.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/BlacksmithWorkshopView.csproj @@ -15,6 +15,7 @@ + @@ -24,4 +25,13 @@ + + + Always + + + Always + + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormMain.Designer.cs index ba6f8cd..a7e8e50 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopView/FormMain.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormMain.Designer.cs @@ -1,218 +1,281 @@ namespace BlacksmithWorkshopView { - partial class FormMain - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } - #region Windows Form Designer generated code + #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - menuStrip1 = new MenuStrip(); - guideToolStripMenuItem = new ToolStripMenuItem(); - componentsToolStripMenuItem = new ToolStripMenuItem(); - goodsToolStripMenuItem = new ToolStripMenuItem(); - ShopsToolStripMenuItem = new ToolStripMenuItem(); - dataGridView = new DataGridView(); - buttonCreateOrder = new Button(); - buttonTakeOrderInWork = new Button(); - buttonOrderReady = new Button(); - buttonIssuedOrder = new Button(); - buttonRef = new Button(); - buttonAddManufactureInShop = new Button(); - buttonSellManufacture = new Button(); - menuStrip1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // menuStrip1 - // - menuStrip1.ImageScalingSize = new Size(20, 20); - menuStrip1.Items.AddRange(new ToolStripItem[] { guideToolStripMenuItem }); - menuStrip1.Location = new Point(0, 0); - menuStrip1.Name = "menuStrip1"; - menuStrip1.Padding = new Padding(5, 2, 0, 2); - menuStrip1.Size = new Size(1149, 24); - menuStrip1.TabIndex = 0; - menuStrip1.Text = "menuStrip1"; - // - // guideToolStripMenuItem - // - guideToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, goodsToolStripMenuItem, ShopsToolStripMenuItem }); - guideToolStripMenuItem.Name = "guideToolStripMenuItem"; - guideToolStripMenuItem.Size = new Size(87, 20); - guideToolStripMenuItem.Text = "Справочник"; - // - // componentsToolStripMenuItem - // - componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; - componentsToolStripMenuItem.Size = new Size(145, 22); - componentsToolStripMenuItem.Text = "Компоненты"; - componentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; - // - // goodsToolStripMenuItem - // - goodsToolStripMenuItem.Name = "goodsToolStripMenuItem"; - goodsToolStripMenuItem.Size = new Size(145, 22); - goodsToolStripMenuItem.Text = "Изделия"; - goodsToolStripMenuItem.Click += GoodsToolStripMenuItem_Click; - // - // ShopsToolStripMenuItem - // - ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem"; - ShopsToolStripMenuItem.Size = new Size(145, 22); - ShopsToolStripMenuItem.Text = "Магазины"; - ShopsToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; - // - // dataGridView - // - dataGridView.AllowUserToAddRows = false; - dataGridView.AllowUserToDeleteRows = false; - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(10, 23); - dataGridView.Margin = new Padding(3, 2, 3, 2); - dataGridView.Name = "dataGridView"; - dataGridView.ReadOnly = true; - dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new Size(855, 286); - dataGridView.TabIndex = 1; - // - // buttonCreateOrder - // - buttonCreateOrder.Location = new Point(904, 77); - buttonCreateOrder.Margin = new Padding(3, 2, 3, 2); - buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(216, 22); - buttonCreateOrder.TabIndex = 2; - buttonCreateOrder.Text = "Создать заказ"; - buttonCreateOrder.UseVisualStyleBackColor = true; - buttonCreateOrder.Click += ButtonCreateOrder_Click; - // - // buttonTakeOrderInWork - // - buttonTakeOrderInWork.Location = new Point(904, 103); - buttonTakeOrderInWork.Margin = new Padding(3, 2, 3, 2); - buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - buttonTakeOrderInWork.Size = new Size(216, 22); - buttonTakeOrderInWork.TabIndex = 3; - buttonTakeOrderInWork.Text = "Отдать на выполнение"; - buttonTakeOrderInWork.UseVisualStyleBackColor = true; - buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; - // - // buttonOrderReady - // - buttonOrderReady.Location = new Point(904, 129); - buttonOrderReady.Margin = new Padding(3, 2, 3, 2); - buttonOrderReady.Name = "buttonOrderReady"; - buttonOrderReady.Size = new Size(216, 22); - buttonOrderReady.TabIndex = 4; - buttonOrderReady.Text = "Заказ готов"; - buttonOrderReady.UseVisualStyleBackColor = true; - buttonOrderReady.Click += ButtonOrderReady_Click; - // - // buttonIssuedOrder - // - buttonIssuedOrder.Location = new Point(904, 155); - buttonIssuedOrder.Margin = new Padding(3, 2, 3, 2); - buttonIssuedOrder.Name = "buttonIssuedOrder"; - buttonIssuedOrder.Size = new Size(216, 22); - buttonIssuedOrder.TabIndex = 5; - buttonIssuedOrder.Text = "Заказ выдан"; - buttonIssuedOrder.UseVisualStyleBackColor = true; - buttonIssuedOrder.Click += ButtonIssuedOrder_Click; - // - // buttonRef - // - buttonRef.Location = new Point(904, 181); - buttonRef.Margin = new Padding(3, 2, 3, 2); - buttonRef.Name = "buttonRef"; - buttonRef.Size = new Size(216, 22); - buttonRef.TabIndex = 6; - buttonRef.Text = "Обновить список"; - buttonRef.UseVisualStyleBackColor = true; - buttonRef.Click += ButtonRef_Click; - // - // buttonAddManufactureInShop - // - buttonAddManufactureInShop.Location = new Point(904, 208); - buttonAddManufactureInShop.Name = "buttonAddManufactureInShop"; - buttonAddManufactureInShop.Size = new Size(216, 22); - buttonAddManufactureInShop.TabIndex = 7; - buttonAddManufactureInShop.Text = "Пополнение магазина"; - buttonAddManufactureInShop.UseVisualStyleBackColor = true; - buttonAddManufactureInShop.Click += buttonAddManufactureInShop_Click; - // - // buttonSellManufacture - // - buttonSellManufacture.Location = new Point(904, 236); - buttonSellManufacture.Name = "buttonSellManufacture"; - buttonSellManufacture.Size = new Size(216, 23); - buttonSellManufacture.TabIndex = 8; - buttonSellManufacture.Text = "Продать изделие"; - buttonSellManufacture.UseVisualStyleBackColor = true; - buttonSellManufacture.Click += ButtonSellManufacture_Click; - // - // FormMain - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1149, 319); - Controls.Add(buttonSellManufacture); - Controls.Add(buttonAddManufactureInShop); - Controls.Add(buttonRef); - Controls.Add(buttonIssuedOrder); - Controls.Add(buttonOrderReady); - Controls.Add(buttonTakeOrderInWork); - Controls.Add(buttonCreateOrder); - Controls.Add(dataGridView); - Controls.Add(menuStrip1); - MainMenuStrip = menuStrip1; - Margin = new Padding(3, 2, 3, 2); - Name = "FormMain"; - Text = "Кузнечная мастерская"; - Load += FormMain_Load; - menuStrip1.ResumeLayout(false); - menuStrip1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + menuStrip1 = new MenuStrip(); + guideToolStripMenuItem = new ToolStripMenuItem(); + componentsToolStripMenuItem = new ToolStripMenuItem(); + goodsToolStripMenuItem = new ToolStripMenuItem(); + ShopsToolStripMenuItem = new ToolStripMenuItem(); + отчетыToolStripMenuItem = new ToolStripMenuItem(); + componentListToolStripMenuItem = new ToolStripMenuItem(); + componentsManufactureToolStripMenuItem = new ToolStripMenuItem(); + orderListToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRef = new Button(); + buttonAddManufactureInShop = new Button(); + buttonSellManufacture = new Button(); + shopListToolStripMenuItem = new ToolStripMenuItem(); + shopsCapacityToolStripMenuItem = new ToolStripMenuItem(); + ordersByDateToolStripMenuItem = new ToolStripMenuItem(); + menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.ImageScalingSize = new Size(20, 20); + menuStrip1.Items.AddRange(new ToolStripItem[] { guideToolStripMenuItem, отчетыToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Padding = new Padding(5, 2, 0, 2); + menuStrip1.Size = new Size(1149, 24); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; + // + // guideToolStripMenuItem + // + guideToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, goodsToolStripMenuItem, ShopsToolStripMenuItem }); + guideToolStripMenuItem.Name = "guideToolStripMenuItem"; + guideToolStripMenuItem.Size = new Size(87, 20); + guideToolStripMenuItem.Text = "Справочник"; + // + // componentsToolStripMenuItem + // + componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; + componentsToolStripMenuItem.Size = new Size(180, 22); + componentsToolStripMenuItem.Text = "Компоненты"; + componentsToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click; + // + // goodsToolStripMenuItem + // + goodsToolStripMenuItem.Name = "goodsToolStripMenuItem"; + goodsToolStripMenuItem.Size = new Size(180, 22); + goodsToolStripMenuItem.Text = "Изделия"; + goodsToolStripMenuItem.Click += GoodsToolStripMenuItem_Click; + // + // ShopsToolStripMenuItem + // + ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem"; + ShopsToolStripMenuItem.Size = new Size(180, 22); + ShopsToolStripMenuItem.Text = "Магазины"; + ShopsToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; + // + // отчетыToolStripMenuItem + // + отчетыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentListToolStripMenuItem, componentsManufactureToolStripMenuItem, orderListToolStripMenuItem, shopListToolStripMenuItem, shopsCapacityToolStripMenuItem, ordersByDateToolStripMenuItem }); + отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + отчетыToolStripMenuItem.Size = new Size(60, 20); + отчетыToolStripMenuItem.Text = "Отчеты"; + // + // componentListToolStripMenuItem + // + componentListToolStripMenuItem.Name = "componentListToolStripMenuItem"; + componentListToolStripMenuItem.Size = new Size(219, 22); + componentListToolStripMenuItem.Text = "Список коспонентов"; + componentListToolStripMenuItem.Click += ComponentListToolStripMenuItem_Click; + // + // componentsManufactureToolStripMenuItem + // + componentsManufactureToolStripMenuItem.Name = "componentsManufactureToolStripMenuItem"; + componentsManufactureToolStripMenuItem.Size = new Size(219, 22); + componentsManufactureToolStripMenuItem.Text = "Компоненты по изделиям"; + componentsManufactureToolStripMenuItem.Click += ComponentManufacturesToolStripMenuItem_Click; + // + // orderListToolStripMenuItem + // + orderListToolStripMenuItem.Name = "orderListToolStripMenuItem"; + orderListToolStripMenuItem.Size = new Size(219, 22); + orderListToolStripMenuItem.Text = "Список заказов"; + orderListToolStripMenuItem.Click += OrderListToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(10, 23); + dataGridView.Margin = new Padding(3, 2, 3, 2); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(855, 286); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(904, 77); + buttonCreateOrder.Margin = new Padding(3, 2, 3, 2); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(216, 22); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Location = new Point(904, 103); + buttonTakeOrderInWork.Margin = new Padding(3, 2, 3, 2); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(216, 22); + buttonTakeOrderInWork.TabIndex = 3; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Location = new Point(904, 129); + buttonOrderReady.Margin = new Padding(3, 2, 3, 2); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(216, 22); + buttonOrderReady.TabIndex = 4; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += ButtonOrderReady_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(904, 155); + buttonIssuedOrder.Margin = new Padding(3, 2, 3, 2); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(216, 22); + buttonIssuedOrder.TabIndex = 5; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += ButtonIssuedOrder_Click; + // + // buttonRef + // + buttonRef.Location = new Point(904, 181); + buttonRef.Margin = new Padding(3, 2, 3, 2); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(216, 22); + buttonRef.TabIndex = 6; + buttonRef.Text = "Обновить список"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; + // + // buttonAddManufactureInShop + // + buttonAddManufactureInShop.Location = new Point(904, 208); + buttonAddManufactureInShop.Name = "buttonAddManufactureInShop"; + buttonAddManufactureInShop.Size = new Size(216, 22); + buttonAddManufactureInShop.TabIndex = 7; + buttonAddManufactureInShop.Text = "Пополнение магазина"; + buttonAddManufactureInShop.UseVisualStyleBackColor = true; + buttonAddManufactureInShop.Click += buttonAddManufactureInShop_Click; + // + // buttonSellManufacture + // + buttonSellManufacture.Location = new Point(904, 236); + buttonSellManufacture.Name = "buttonSellManufacture"; + buttonSellManufacture.Size = new Size(216, 23); + buttonSellManufacture.TabIndex = 8; + buttonSellManufacture.Text = "Продать изделие"; + buttonSellManufacture.UseVisualStyleBackColor = true; + buttonSellManufacture.Click += ButtonSellManufacture_Click; + // + // shopListToolStripMenuItem + // + shopListToolStripMenuItem.Name = "shopListToolStripMenuItem"; + shopListToolStripMenuItem.Size = new Size(219, 22); + shopListToolStripMenuItem.Text = "Список магазинов"; + shopListToolStripMenuItem.Click += ShopsListToolStripMenuItem_Click; + // + // shopsCapacityToolStripMenuItem + // + shopsCapacityToolStripMenuItem.Name = "shopsCapacityToolStripMenuItem"; + shopsCapacityToolStripMenuItem.Size = new Size(219, 22); + shopsCapacityToolStripMenuItem.Text = "Загруженность магазинов"; + shopsCapacityToolStripMenuItem.Click += ShopsCapacityStripMenuItem_Click; + // + // ordersByDateToolStripMenuItem + // + ordersByDateToolStripMenuItem.Name = "ordersByDateToolStripMenuItem"; + ordersByDateToolStripMenuItem.Size = new Size(219, 22); + ordersByDateToolStripMenuItem.Text = "Заказы по датам"; + ordersByDateToolStripMenuItem.Click += OrdersByDateToolStripMenuItem_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1149, 319); + Controls.Add(buttonSellManufacture); + Controls.Add(buttonAddManufactureInShop); + Controls.Add(buttonRef); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Margin = new Padding(3, 2, 3, 2); + Name = "FormMain"; + Text = "Кузнечная мастерская"; + Load += FormMain_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private MenuStrip menuStrip1; - private ToolStripMenuItem guideToolStripMenuItem; - private ToolStripMenuItem componentsToolStripMenuItem; - private ToolStripMenuItem goodsToolStripMenuItem; - private DataGridView dataGridView; - private Button buttonCreateOrder; - private Button buttonTakeOrderInWork; - private Button buttonOrderReady; - private Button buttonIssuedOrder; - private Button buttonRef; - private ToolStripMenuItem ShopsToolStripMenuItem; - private Button buttonAddManufactureInShop; - private Button buttonSellManufacture; - } + private MenuStrip menuStrip1; + private ToolStripMenuItem guideToolStripMenuItem; + private ToolStripMenuItem componentsToolStripMenuItem; + private ToolStripMenuItem goodsToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRef; + private ToolStripMenuItem ShopsToolStripMenuItem; + private Button buttonAddManufactureInShop; + private Button buttonSellManufacture; + private ToolStripMenuItem отчетыToolStripMenuItem; + private ToolStripMenuItem componentListToolStripMenuItem; + private ToolStripMenuItem componentsManufactureToolStripMenuItem; + private ToolStripMenuItem orderListToolStripMenuItem; + private ToolStripMenuItem shopListToolStripMenuItem; + private ToolStripMenuItem shopsCapacityToolStripMenuItem; + private ToolStripMenuItem ordersByDateToolStripMenuItem; + } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormMain.cs index 6ebcb3f..7e84170 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopView/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormMain.cs @@ -16,188 +16,240 @@ using BlacksmithWorkshopDataModels.Enums; namespace BlacksmithWorkshopView { - public partial class FormMain : Form - { - private readonly ILogger _logger; - private readonly IOrderLogic _orderLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic) - { - InitializeComponent(); - _logger = logger; - _orderLogic = orderLogic; - } - private void FormMain_Load(object sender, EventArgs e) - { - LoadData(); - } - private void LoadData() - { - try - { - var list = _orderLogic.ReadList(null); - if (list != null) - { - dataGridView.DataSource = list; - dataGridView.Columns["ManufactureId"].Visible = false; - dataGridView.Columns["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - _logger.LogInformation("Загрузка заказов"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки заказов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); - if (service is FormComponents form) - { - form.ShowDialog(); - } - } - private void GoodsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormManufacturies)); - if (service is FormManufacturies form) - { - form.ShowDialog(); - } - } - private void ButtonCreateOrder_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); - if (service is FormCreateOrder form) - { - form.ShowDialog(); - LoadData(); - } - } - private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ No {id}. Меняется статус на 'В работе'", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel - { - Id = id, - ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), - ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].Value.ToString(), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonOrderReady_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ No {id}. Меняется статус на 'Готов'", id); - try - { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel - { - Id = id, - ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), - ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].Value.ToString(), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), - DateImplement = DateTime.Now, - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void ButtonIssuedOrder_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ No {id}. Меняется статус на 'Выдан'", id); - try - { - var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel - { - Id = id, - ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), - ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].Value.ToString(), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), - DateImplement = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateImplement"].Value.ToString()), - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - _logger.LogInformation("Заказ No {id} выдан", id); - 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 buttonAddManufactureInShop_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormShopManufacture)); - if (service is FormShopManufacture form) - { - form.ShowDialog(); - } - } - private void ShopsToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormShops)); - if (service is FormShops form) - { - form.ShowDialog(); - } - } - private void ButtonSellManufacture_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormSellManufacture)); - if (service is FormSellManufacture form) - { - form.ShowDialog(); - LoadData(); - } - } - } + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + private readonly IReportLogic _reportLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + _reportLogic = reportLogic; + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["ManufactureId"].Visible = false; + dataGridView.Columns["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ComponentsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void GoodsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormManufacturies)); + if (service is FormManufacturies form) + { + form.ShowDialog(); + } + } + private void ButtonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ No {id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = id, + ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), + ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].Value.ToString(), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ No {id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel + { + Id = id, + ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), + ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].Value.ToString(), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + DateImplement = DateTime.Now, + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void ButtonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ No {id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = id, + ManufactureId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ManufactureId"].Value), + ManufactureName = dataGridView.SelectedRows[0].Cells["ManufactureName"].Value.ToString(), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + DateImplement = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateImplement"].Value.ToString()), + }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ No {id} выдан", id); + 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 ComponentListToolStripMenuItem_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "docx|*.docx" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + _reportLogic.SaveComponentsToWordFile(new ReportBindingModel { FileName = dialog.FileName }); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + private void ComponentManufacturesToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportManufactureComponents)); + if (service is FormReportManufactureComponents form) + { + form.ShowDialog(); + } + } + private void OrderListToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportOrders)); + if (service is FormReportOrders form) + { + form.ShowDialog(); + } + } + private void buttonAddManufactureInShop_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShopManufacture)); + if (service is FormShopManufacture form) + { + form.ShowDialog(); + } + } + private void ShopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + private void ButtonSellManufacture_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSellManufacture)); + if (service is FormSellManufacture form) + { + form.ShowDialog(); + LoadData(); + } + } + private void ShopsListToolStripMenuItem_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 ShopsCapacityStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportShopManufactures)); + if (service is FormReportShopManufactures form) + { + form.ShowDialog(); + } + } + private void OrdersByDateToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormReportOrdersByDate)); + if (service is FormReportOrdersByDate form) + { + form.ShowDialog(); + } + } + } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportManufactureComponents.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportManufactureComponents.Designer.cs new file mode 100644 index 0000000..dc82240 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportManufactureComponents.Designer.cs @@ -0,0 +1,114 @@ +namespace BlacksmithWorkshopView +{ + partial class FormReportManufactureComponents + { + /// + /// 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.buttonSaveToExcel = new System.Windows.Forms.Button(); + this.ColumnComponent = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnManufacture = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.AllowUserToAddRows = false; + this.dataGridView.AllowUserToDeleteRows = false; + this.dataGridView.AllowUserToOrderColumns = true; + this.dataGridView.AllowUserToResizeColumns = false; + this.dataGridView.AllowUserToResizeRows = false; + this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { + this.ColumnComponent, + this.ColumnManufacture, + this.ColumnCount}); + this.dataGridView.Dock = System.Windows.Forms.DockStyle.Bottom; + this.dataGridView.Location = new System.Drawing.Point(0, 41); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.ReadOnly = true; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.Size = new System.Drawing.Size(528, 442); + this.dataGridView.TabIndex = 0; + // + // buttonSaveToExcel + // + this.buttonSaveToExcel.Location = new System.Drawing.Point(12, 12); + this.buttonSaveToExcel.Name = "buttonSaveToExcel"; + this.buttonSaveToExcel.Size = new System.Drawing.Size(159, 23); + this.buttonSaveToExcel.TabIndex = 1; + this.buttonSaveToExcel.Text = "Сохранить в Excel"; + this.buttonSaveToExcel.UseVisualStyleBackColor = true; + this.buttonSaveToExcel.Click += new System.EventHandler(this.ButtonSaveToExcel_Click); + // + // ColumnComponent + // + this.ColumnComponent.HeaderText = "Компонент"; + this.ColumnComponent.Name = "ColumnComponent"; + this.ColumnComponent.ReadOnly = true; + this.ColumnComponent.Width = 200; + // + // ColumnManufacture + // + this.ColumnManufacture.HeaderText = "Изделие"; + this.ColumnManufacture.Name = "ColumnManufacture"; + this.ColumnManufacture.ReadOnly = true; + this.ColumnManufacture.Width = 200; + // + // ColumnCount + // + this.ColumnCount.HeaderText = "Количество"; + this.ColumnCount.Name = "ColumnCount"; + this.ColumnCount.ReadOnly = true; + // + // FormReportManufactureComponents + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(528, 483); + this.Controls.Add(this.buttonSaveToExcel); + this.Controls.Add(this.dataGridView); + this.Name = "FormReportManufactureComponents"; + this.Text = "Компоненты по изделиям"; + this.Load += new System.EventHandler(this.FormReportManufactureComponents_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.DataGridView dataGridView; + private System.Windows.Forms.Button buttonSaveToExcel; + private System.Windows.Forms.DataGridViewTextBoxColumn ColumnComponent; + private System.Windows.Forms.DataGridViewTextBoxColumn ColumnManufacture; + private System.Windows.Forms.DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportManufactureComponents.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportManufactureComponents.cs new file mode 100644 index 0000000..03a7666 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportManufactureComponents.cs @@ -0,0 +1,75 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace BlacksmithWorkshopView +{ + public partial class FormReportManufactureComponents : Form + { + private readonly ILogger _logger; + private readonly IReportLogic _logic; + public FormReportManufactureComponents(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormReportManufactureComponents_Load(object sender, EventArgs e) + { + try + { + var dict = _logic.GetManufactureComponent(); + if (dict != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in dict) + { + dataGridView.Rows.Add(new object[] { elem.ManufactureName, "", "" }); + foreach (var listElem in elem.Components) + { + dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 }); + } + dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount }); + 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.SaveManufactureComponentToExcelFile(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/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportManufactureComponents.resx b/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportManufactureComponents.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportManufactureComponents.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportOrders.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportOrders.Designer.cs new file mode 100644 index 0000000..32285dd --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportOrders.Designer.cs @@ -0,0 +1,141 @@ +namespace BlacksmithWorkshopView +{ + partial class FormReportOrders + { + /// + /// 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.buttonToPdf = new System.Windows.Forms.Button(); + this.buttonMake = new System.Windows.Forms.Button(); + this.dateTimePickerTo = new System.Windows.Forms.DateTimePicker(); + this.labelTo = new System.Windows.Forms.Label(); + this.dateTimePickerFrom = new System.Windows.Forms.DateTimePicker(); + this.labelFrom = new System.Windows.Forms.Label(); + this.panel.SuspendLayout(); + this.SuspendLayout(); + // + // panel + // + this.panel.Controls.Add(this.buttonToPdf); + this.panel.Controls.Add(this.buttonMake); + this.panel.Controls.Add(this.dateTimePickerTo); + this.panel.Controls.Add(this.labelTo); + this.panel.Controls.Add(this.dateTimePickerFrom); + this.panel.Controls.Add(this.labelFrom); + this.panel.Dock = System.Windows.Forms.DockStyle.Top; + this.panel.Location = new System.Drawing.Point(0, 0); + this.panel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.panel.Name = "panel"; + this.panel.Size = new System.Drawing.Size(1031, 40); + this.panel.TabIndex = 0; + // + // buttonToPdf + // + this.buttonToPdf.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonToPdf.Location = new System.Drawing.Point(878, 8); + this.buttonToPdf.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.buttonToPdf.Name = "buttonToPdf"; + this.buttonToPdf.Size = new System.Drawing.Size(139, 27); + this.buttonToPdf.TabIndex = 5; + this.buttonToPdf.Text = "В Pdf"; + this.buttonToPdf.UseVisualStyleBackColor = true; + this.buttonToPdf.Click += new System.EventHandler(this.ButtonToPdf_Click); + // + // buttonMake + // + this.buttonMake.Location = new System.Drawing.Point(476, 8); + this.buttonMake.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.buttonMake.Name = "buttonMake"; + this.buttonMake.Size = new System.Drawing.Size(139, 27); + this.buttonMake.TabIndex = 4; + this.buttonMake.Text = "Сформировать"; + this.buttonMake.UseVisualStyleBackColor = true; + this.buttonMake.Click += new System.EventHandler(this.ButtonMake_Click); + // + // dateTimePickerTo + // + this.dateTimePickerTo.Location = new System.Drawing.Point(237, 7); + this.dateTimePickerTo.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.dateTimePickerTo.Name = "dateTimePickerTo"; + this.dateTimePickerTo.Size = new System.Drawing.Size(163, 23); + this.dateTimePickerTo.TabIndex = 3; + // + // labelTo + // + this.labelTo.AutoSize = true; + this.labelTo.Location = new System.Drawing.Point(208, 10); + this.labelTo.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelTo.Name = "labelTo"; + this.labelTo.Size = new System.Drawing.Size(21, 15); + this.labelTo.TabIndex = 2; + this.labelTo.Text = "по"; + // + // dateTimePickerFrom + // + this.dateTimePickerFrom.Location = new System.Drawing.Point(37, 7); + this.dateTimePickerFrom.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.dateTimePickerFrom.Name = "dateTimePickerFrom"; + this.dateTimePickerFrom.Size = new System.Drawing.Size(163, 23); + this.dateTimePickerFrom.TabIndex = 1; + // + // labelFrom + // + this.labelFrom.AutoSize = true; + this.labelFrom.Location = new System.Drawing.Point(14, 10); + this.labelFrom.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.labelFrom.Name = "labelFrom"; + this.labelFrom.Size = new System.Drawing.Size(15, 15); + this.labelFrom.TabIndex = 0; + this.labelFrom.Text = "С"; + // + // FormReportOrders + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1031, 647); + this.Controls.Add(this.panel); + this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.Name = "FormReportOrders"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "Заказы"; + this.panel.ResumeLayout(false); + this.panel.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel panel; + private System.Windows.Forms.Button buttonToPdf; + private System.Windows.Forms.Button buttonMake; + private System.Windows.Forms.DateTimePicker dateTimePickerTo; + private System.Windows.Forms.Label labelTo; + private System.Windows.Forms.DateTimePicker dateTimePickerFrom; + private System.Windows.Forms.Label labelFrom; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportOrders.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportOrders.cs new file mode 100644 index 0000000..d52fd63 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportOrders.cs @@ -0,0 +1,95 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.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 BlacksmithWorkshopView +{ + public partial class FormReportOrders : Form + { + private readonly ReportViewer reportViewer; + private readonly ILogger _logger; + private readonly IReportLogic _logic; + public FormReportOrders(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + reportViewer = new ReportViewer + { + Dock = DockStyle.Fill + }; + 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) + { + if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date) + { + MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + var dataSource = _logic.GetOrders(new ReportBindingModel + { + DateFrom = dateTimePickerFrom.Value, + DateTo = dateTimePickerTo.Value + }); + 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); + reportViewer.RefreshReport(); + _logger.LogInformation("Загрузка списка заказов на период {From}-{To}", dateTimePickerFrom.Value.ToShortDateString(), dateTimePickerTo.Value.ToShortDateString()); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonToPdf_Click(object sender, EventArgs e) + { + if (dateTimePickerFrom.Value.Date >= dateTimePickerTo.Value.Date) + { + MessageBox.Show("Дата начала должна быть меньше даты окончания", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveOrdersToPdfFile(new ReportBindingModel + { + FileName = dialog.FileName, + DateFrom = dateTimePickerFrom.Value, + DateTo = dateTimePickerTo.Value + }); + _logger.LogInformation("Сохранение списка заказов на период {From}-{To}", dateTimePickerFrom.Value.ToShortDateString(), + dateTimePickerTo.Value.ToShortDateString()); + MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения списка заказов на период"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportOrders.resx b/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportOrders.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportOrders.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportOrdersByDate.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportOrdersByDate.Designer.cs new file mode 100644 index 0000000..ddbdb00 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportOrdersByDate.Designer.cs @@ -0,0 +1,85 @@ +namespace BlacksmithWorkshopView +{ + partial class FormReportOrdersByDate + { + /// + /// 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() + { + panel = new Panel(); + buttonToPDF = new Button(); + buttonMake = new Button(); + panel.SuspendLayout(); + SuspendLayout(); + // + // panel + // + panel.Controls.Add(buttonToPDF); + panel.Controls.Add(buttonMake); + panel.Dock = DockStyle.Top; + panel.Location = new Point(0, 0); + panel.Name = "panel"; + panel.Size = new Size(800, 58); + panel.TabIndex = 0; + // + // buttonToPDF + // + buttonToPDF.Location = new Point(618, 12); + buttonToPDF.Name = "buttonToPDF"; + buttonToPDF.Size = new Size(170, 34); + buttonToPDF.TabIndex = 6; + buttonToPDF.Text = "В PDF"; + buttonToPDF.UseVisualStyleBackColor = true; + buttonToPDF.Click += ButtonToPdf_Click; + // + // buttonMake + // + buttonMake.Location = new Point(12, 12); + buttonMake.Name = "buttonMake"; + buttonMake.Size = new Size(170, 34); + buttonMake.TabIndex = 5; + buttonMake.Text = "Сформировать"; + buttonMake.UseVisualStyleBackColor = true; + buttonMake.Click += ButtonMake_Click; + // + // FormReportOrdersByDate + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(panel); + Name = "FormReportOrdersByDate"; + Text = "Заказы по датам"; + panel.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private Panel panel; + private Button buttonMake; + private Button buttonToPDF; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportOrdersByDate.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportOrdersByDate.cs new file mode 100644 index 0000000..923292f --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportOrdersByDate.cs @@ -0,0 +1,76 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.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 BlacksmithWorkshopView +{ + public partial class FormReportOrdersByDate : Form + { + private readonly ReportViewer reportViewer; + private readonly ILogger _logger; + private readonly IReportLogic _logic; + public FormReportOrdersByDate(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + reportViewer = new ReportViewer + { + Dock = DockStyle.Fill + }; + reportViewer.LocalReport.LoadReportDefinition(new FileStream("ReportOrdersByDate.rdlc", FileMode.Open)); + Controls.Clear(); + Controls.Add(reportViewer); + Controls.Add(panel); + } + private void ButtonMake_Click(object sender, EventArgs e) + { + try + { + var dataSource = _logic.GetOrdersByDate(); + 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 ButtonToPdf_Click(object sender, EventArgs e) + { + using var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" }; + if (dialog.ShowDialog() == DialogResult.OK) + { + try + { + _logic.SaveOrdersByDateToPdfFile(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/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportOrdersByDate.resx b/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportOrdersByDate.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportOrdersByDate.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportShopManufactures.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportShopManufactures.Designer.cs new file mode 100644 index 0000000..bf81e77 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportShopManufactures.Designer.cs @@ -0,0 +1,104 @@ +namespace BlacksmithWorkshopView +{ + partial class FormReportShopManufactures + { + /// + /// 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() + { + buttonSaveToExcel = new Button(); + dataGridView = new DataGridView(); + ColumnShop = new DataGridViewTextBoxColumn(); + ColumnManufacture = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonSaveToExcel + // + buttonSaveToExcel.Location = new Point(12, 12); + buttonSaveToExcel.Name = "buttonSaveToExcel"; + buttonSaveToExcel.Size = new Size(210, 34); + buttonSaveToExcel.TabIndex = 0; + buttonSaveToExcel.Text = "Сохранить в Excel"; + buttonSaveToExcel.UseVisualStyleBackColor = true; + buttonSaveToExcel.Click += ButtonSaveToExcel_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnShop, ColumnManufacture, ColumnCount }); + dataGridView.Dock = DockStyle.Bottom; + dataGridView.Location = new Point(0, 63); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 62; + dataGridView.RowTemplate.Height = 33; + dataGridView.Size = new Size(800, 387); + dataGridView.TabIndex = 1; + // + // ColumnShop + // + ColumnShop.HeaderText = "Магазин"; + ColumnShop.MinimumWidth = 8; + ColumnShop.Name = "ColumnShop"; + ColumnShop.Width = 150; + // + // ColumnManufacture + // + ColumnManufacture.HeaderText = "Изделие"; + ColumnManufacture.MinimumWidth = 8; + ColumnManufacture.Name = "ColumnManufacture"; + ColumnManufacture.Width = 150; + // + // ColumnCount + // + ColumnCount.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 8; + ColumnCount.Name = "ColumnCount"; + // + // FormReportShopManufactures + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Controls.Add(buttonSaveToExcel); + Name = "FormReportShopManufactures"; + Text = "Магазины с изделиями"; + Load += FormReportShopManufactures_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Button buttonSaveToExcel; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnShop; + private DataGridViewTextBoxColumn ColumnManufacture; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportShopManufactures.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportShopManufactures.cs new file mode 100644 index 0000000..038e4bb --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportShopManufactures.cs @@ -0,0 +1,81 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace BlacksmithWorkshopView +{ + public partial class FormReportShopManufactures : Form + { + private readonly ILogger _logger; + private readonly IReportLogic _logic; + public FormReportShopManufactures(ILogger logger, IReportLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormReportShopManufactures_Load(object sender, EventArgs e) + { + try + { + var dict = _logic.GetShopManufacture(); + if (dict != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in dict) + { + dataGridView.Rows.Add(new object[] { elem.ShopName, "", "" }); + foreach (var listElem in elem.Manufactures) + { + dataGridView.Rows.Add(new object[] { "", listElem.Item1, listElem.Item2 }); + } + dataGridView.Rows.Add(new object[] { "Итого", "", elem.TotalCount }); + 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.SaveShopManufactureToExcelFile(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/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportShopManufactures.resx b/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportShopManufactures.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormReportShopManufactures.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormSellManufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormSellManufacture.cs index 3c05a8b..8677326 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopView/FormSellManufacture.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormSellManufacture.cs @@ -38,7 +38,7 @@ namespace BlacksmithWorkshopView { if (comboBoxManufacture.SelectedValue == null) { - MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Выберите поездку", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (string.IsNullOrEmpty(numericUpDownCount.Text)) @@ -46,7 +46,7 @@ namespace BlacksmithWorkshopView MessageBox.Show("Заполните количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - _logger.LogInformation("Продажа изделий"); + _logger.LogInformation("Продажа поездок"); try { var manufacture = _manufactureLogic.ReadElement(new() @@ -63,7 +63,7 @@ namespace BlacksmithWorkshopView ); if (!operationResult) { - throw new Exception("Ошибка при продаже изделия. Дополнительная информация в логах."); + throw new Exception("Ошибка при продаже поездки. Дополнительная информация в логах."); } MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; @@ -71,7 +71,7 @@ namespace BlacksmithWorkshopView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка сохранения изделия"); + _logger.LogError(ex, "Ошибка сохранения поездки"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormShop.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormShop.Designer.cs index e860cd7..a11be71 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopView/FormShop.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormShop.Designer.cs @@ -1,220 +1,212 @@ namespace BlacksmithWorkshopView { - partial class FormShop - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + 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); - } + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } - #region Windows Form Designer generated code + #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - buttonSave = new Button(); - buttonCancel = new Button(); - textBoxAddress = new TextBox(); - labelTime = new Label(); - labelAddress = new Label(); - dataGridView = new DataGridView(); - ColumnID = new DataGridViewTextBoxColumn(); - ColumnManufactureName = new DataGridViewTextBoxColumn(); - ColumnCount = new DataGridViewTextBoxColumn(); - labelShop = new Label(); - textBoxShop = new TextBox(); - dateTimePicker = new DateTimePicker(); - numericUpDownCapacity = new NumericUpDown(); - label1 = new Label(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - ((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).BeginInit(); - SuspendLayout(); - // - // buttonSave - // - buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonSave.Location = new Point(661, 403); - buttonSave.Margin = new Padding(3, 4, 3, 4); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(137, 29); - buttonSave.TabIndex = 17; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += ButtonSave_Click; - // - // buttonCancel - // - buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonCancel.Location = new Point(803, 403); - buttonCancel.Margin = new Padding(3, 4, 3, 4); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(118, 31); - buttonCancel.TabIndex = 16; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += ButtonCancel_Click; - // - // textBoxAddress - // - textBoxAddress.Location = new Point(182, 36); - textBoxAddress.Margin = new Padding(3, 4, 3, 4); - textBoxAddress.Name = "textBoxAddress"; - textBoxAddress.Size = new Size(252, 27); - textBoxAddress.TabIndex = 14; - // - // labelTime - // - labelTime.AutoSize = true; - labelTime.Location = new Point(441, 12); - labelTime.Name = "labelTime"; - labelTime.Size = new Size(110, 20); - labelTime.TabIndex = 13; - labelTime.Text = "Дата открытия"; - // - // labelAddress - // - labelAddress.AutoSize = true; - labelAddress.Location = new Point(182, 12); - labelAddress.Name = "labelAddress"; - labelAddress.Size = new Size(51, 20); - labelAddress.TabIndex = 12; - labelAddress.Text = "Адрес"; - // - // dataGridView - // - dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnID, ColumnManufactureName, ColumnCount }); - dataGridView.Location = new Point(14, 75); - dataGridView.Margin = new Padding(3, 4, 3, 4); - dataGridView.Name = "dataGridView"; - dataGridView.RowHeadersWidth = 62; - dataGridView.RowTemplate.Height = 25; - dataGridView.Size = new Size(907, 320); - dataGridView.TabIndex = 11; - // - // ColumnID - // - ColumnID.HeaderText = "ID"; - ColumnID.MinimumWidth = 8; - ColumnID.Name = "ColumnID"; - ColumnID.Visible = false; - ColumnID.Width = 150; - // - // ColumnManufactureName - // - ColumnManufactureName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - ColumnManufactureName.HeaderText = "Изделие"; - ColumnManufactureName.MinimumWidth = 8; - ColumnManufactureName.Name = "ColumnManufactureName"; - // - // ColumnCount - // - ColumnCount.HeaderText = "Количество"; - ColumnCount.MinimumWidth = 8; - ColumnCount.Name = "ColumnCount"; - ColumnCount.Width = 150; - // - // labelShop - // - labelShop.AutoSize = true; - labelShop.Location = new Point(14, 12); - labelShop.Name = "labelShop"; - labelShop.Size = new Size(69, 20); - labelShop.TabIndex = 9; - labelShop.Text = "Магазин"; - // - // textBoxShop - // - textBoxShop.Location = new Point(14, 36); - textBoxShop.Margin = new Padding(3, 4, 3, 4); - textBoxShop.Name = "textBoxShop"; - textBoxShop.Size = new Size(161, 27); - textBoxShop.TabIndex = 18; - // - // dateTimePicker - // - dateTimePicker.Location = new Point(441, 36); - dateTimePicker.Margin = new Padding(3, 4, 3, 4); - dateTimePicker.Name = "dateTimePicker"; - dateTimePicker.Size = new Size(236, 27); - dateTimePicker.TabIndex = 19; - // - // numericUpDownCapacity - // - numericUpDownCapacity.Location = new Point(685, 36); - numericUpDownCapacity.Margin = new Padding(3, 4, 3, 4); - numericUpDownCapacity.Name = "numericUpDownCapacity"; - numericUpDownCapacity.Size = new Size(237, 27); - numericUpDownCapacity.TabIndex = 20; - // - // label1 - // - label1.AutoSize = true; - label1.Location = new Point(685, 12); - label1.Name = "label1"; - label1.Size = new Size(100, 20); - label1.TabIndex = 21; - label1.Text = "Вместимость"; - // - // FormShop - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(935, 449); - Controls.Add(label1); - Controls.Add(numericUpDownCapacity); - Controls.Add(dateTimePicker); - Controls.Add(textBoxShop); - Controls.Add(buttonSave); - Controls.Add(buttonCancel); - Controls.Add(textBoxAddress); - Controls.Add(labelTime); - Controls.Add(labelAddress); - Controls.Add(dataGridView); - Controls.Add(labelShop); - Margin = new Padding(3, 4, 3, 4); - Name = "FormShop"; - Text = "Магазин"; - Load += FormShop_Load; - Click += FormShop_Load; - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).EndInit(); - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonSave = new Button(); + buttonCancel = new Button(); + textBoxAddress = new TextBox(); + labelTime = new Label(); + labelAddress = new Label(); + dataGridView = new DataGridView(); + ColumnID = new DataGridViewTextBoxColumn(); + ColumnManufactureName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + labelShop = new Label(); + textBoxShop = new TextBox(); + dateTimePicker = new DateTimePicker(); + numericUpDownCapacity = new NumericUpDown(); + label1 = new Label(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).BeginInit(); + SuspendLayout(); + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonSave.Location = new Point(578, 302); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(120, 22); + buttonSave.TabIndex = 17; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(703, 302); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(103, 23); + buttonCancel.TabIndex = 16; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // textBoxAddress + // + textBoxAddress.Location = new Point(159, 27); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(221, 23); + textBoxAddress.TabIndex = 14; + // + // labelTime + // + labelTime.AutoSize = true; + labelTime.Location = new Point(386, 9); + labelTime.Name = "labelTime"; + labelTime.Size = new Size(87, 15); + labelTime.TabIndex = 13; + labelTime.Text = "Дата открытия"; + // + // labelAddress + // + labelAddress.AutoSize = true; + labelAddress.Location = new Point(159, 9); + labelAddress.Name = "labelAddress"; + labelAddress.Size = new Size(40, 15); + labelAddress.TabIndex = 12; + labelAddress.Text = "Адрес"; + // + // dataGridView + // + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnID, ColumnManufactureName, ColumnCount }); + dataGridView.Location = new Point(12, 56); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 62; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(794, 240); + dataGridView.TabIndex = 11; + // + // ColumnID + // + ColumnID.HeaderText = "ID"; + ColumnID.MinimumWidth = 8; + ColumnID.Name = "ColumnID"; + ColumnID.Visible = false; + ColumnID.Width = 150; + // + // ColumnManufactureName + // + ColumnManufactureName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnManufactureName.HeaderText = "Изделие"; + ColumnManufactureName.MinimumWidth = 8; + ColumnManufactureName.Name = "ColumnManufactureName"; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 8; + ColumnCount.Name = "ColumnCount"; + ColumnCount.Width = 150; + // + // labelShop + // + labelShop.AutoSize = true; + labelShop.Location = new Point(12, 9); + labelShop.Name = "labelShop"; + labelShop.Size = new Size(54, 15); + labelShop.TabIndex = 9; + labelShop.Text = "Магазин"; + // + // textBoxShop + // + textBoxShop.Location = new Point(12, 27); + textBoxShop.Name = "textBoxShop"; + textBoxShop.Size = new Size(141, 23); + textBoxShop.TabIndex = 18; + // + // dateTimePicker + // + dateTimePicker.Location = new Point(386, 27); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(207, 23); + dateTimePicker.TabIndex = 19; + // + // numericUpDownCapacity + // + numericUpDownCapacity.Location = new Point(599, 27); + numericUpDownCapacity.Name = "numericUpDownCapacity"; + numericUpDownCapacity.Size = new Size(207, 23); + numericUpDownCapacity.TabIndex = 20; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(599, 9); + label1.Name = "label1"; + label1.Size = new Size(80, 15); + label1.TabIndex = 21; + label1.Text = "Вместимость"; + // + // FormShop + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(818, 337); + Controls.Add(label1); + Controls.Add(numericUpDownCapacity); + Controls.Add(dateTimePicker); + Controls.Add(textBoxShop); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(textBoxAddress); + Controls.Add(labelTime); + Controls.Add(labelAddress); + Controls.Add(dataGridView); + Controls.Add(labelShop); + Name = "FormShop"; + Text = "Магазин"; + Load += FormShop_Load; + Click += FormShop_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCapacity).EndInit(); + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private Button buttonSave; - private Button buttonCancel; - private TextBox textBoxAddress; - private Label labelTime; - private Label labelAddress; - private DataGridView dataGridView; - private Label labelShop; - private TextBox textBoxShop; - private DateTimePicker dateTimePicker; - private DataGridViewTextBoxColumn ColumnID; - private DataGridViewTextBoxColumn ColumnManufactureName; - private DataGridViewTextBoxColumn ColumnCount; - private NumericUpDown numericUpDownCapacity; - private Label label1; - } + private Button buttonSave; + private Button buttonCancel; + private TextBox textBoxAddress; + private Label labelTime; + private Label labelAddress; + private DataGridView dataGridView; + private Label labelShop; + private TextBox textBoxShop; + private DateTimePicker dateTimePicker; + private DataGridViewTextBoxColumn ColumnID; + private DataGridViewTextBoxColumn ColumnManufactureName; + private DataGridViewTextBoxColumn ColumnCount; + private NumericUpDown numericUpDownCapacity; + private Label label1; + } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/FormShop.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/FormShop.cs index 18f9ddf..054042f 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopView/FormShop.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/FormShop.cs @@ -16,118 +16,118 @@ using BlacksmithWorkshopDataModels.Models; namespace BlacksmithWorkshopView { - public partial class FormShop : Form - { - private readonly ILogger _logger; - private readonly IShopLogic _logic; - private int? _id; - private Dictionary _shopListManufacture; - public int Id { set { _id = value; } } - public FormShop(ILogger logger, IShopLogic logic) - { - InitializeComponent(); - _logger = logger; - _logic = logic; - _shopListManufacture = 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) - { - textBoxShop.Text = view.ShopName; - textBoxAddress.Text = view.Address; - dateTimePicker.Text = view.DateOpening.ToString(); - numericUpDownCapacity.Value = view.Capacity; - _shopListManufacture = view.ListManufacture ?? new Dictionary(); - LoadData(); - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки магазина"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } - private void LoadData() - { - _logger.LogInformation("Загрузка магазина"); - try - { - if (_shopListManufacture != null) - { - dataGridView.Rows.Clear(); - foreach (var elem in _shopListManufacture) - { - dataGridView.Rows.Add(new object[] { elem.Key, elem.Value.Item1.ManufactureName, elem.Value.Item2 }); - } - } - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка загрузки магазина"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } + public partial class FormShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + private int? _id; + private Dictionary _shopListManufacture; + public int Id { set { _id = value; } } + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _shopListManufacture = 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) + { + textBoxShop.Text = view.ShopName; + textBoxAddress.Text = view.Address; + dateTimePicker.Text = view.DateOpening.ToString(); + numericUpDownCapacity.Value = view.Capacity; + _shopListManufacture = view.ListManufacture ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка магазина"); + try + { + if (_shopListManufacture != null) + { + dataGridView.Rows.Clear(); + foreach (var elem in _shopListManufacture) + { + dataGridView.Rows.Add(new object[] { elem.Key, elem.Value.Item1.ManufactureName, elem.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(textBoxShop.Text)) - { - MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (string.IsNullOrEmpty(textBoxAddress.Text)) - { - MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (numericUpDownCapacity.Value <= 0) - { - MessageBox.Show("Вместимость должна быть больше нуля", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - _logger.LogInformation("Сохранение магазина"); - try - { - var model = new ShopBindingModel - { - Id = _id ?? 0, - ShopName = textBoxShop.Text, - Address = textBoxAddress.Text, - DateOpening = dateTimePicker.Value.Date, - Capacity = (int)numericUpDownCapacity.Value, - ListManufacture = _shopListManufacture - }; - 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(); - } - } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxShop.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (numericUpDownCapacity.Value <= 0) + { + MessageBox.Show("Вместимость должна быть больше нуля", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxShop.Text, + Address = textBoxAddress.Text, + DateOpening = dateTimePicker.Value.Date, + Capacity = (int)numericUpDownCapacity.Value, + ListManufacture = _shopListManufacture + }; + 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/BlacksmithWorkshop/BlacksmithWorkshopView/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshopView/Program.cs index b793d77..0f9ad83 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopView/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/Program.cs @@ -1,4 +1,6 @@ using BlacksmithWorkshopBusinessLogic.BusinessLogics; +using BlacksmithWorkshopBusinessLogic.OfficePackage; +using BlacksmithWorkshopBusinessLogic.OfficePackage.Implements; using BlacksmithWorkshopContracts.BusinessLogicsContracts; using BlacksmithWorkshopContracts.StorageContracts; using BlacksmithWorkshopContracts.StoragesContracts; @@ -6,6 +8,7 @@ using BlacksmithWorkshopDatabaseImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; +using ManufactureCompanyBusinessLogic.BusinessLogics; namespace BlacksmithWorkshopView { @@ -43,6 +46,10 @@ namespace BlacksmithWorkshopView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -54,6 +61,10 @@ namespace BlacksmithWorkshopView services.AddTransient(); services.AddTransient(); services.AddTransient(); - } + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopView/ReportOrders.rdlc b/BlacksmithWorkshop/BlacksmithWorkshopView/ReportOrders.rdlc new file mode 100644 index 0000000..a8c57b3 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopView/ReportOrders.rdlc @@ -0,0 +1,599 @@ + + + 0 + + + + System.Data.DataSet + /* Local Connection */ + + 10791c83-cee8-4a38-bbd0-245fc17cefb3 + + + + + + ManufactureCompanyContractsViewModels + /* Local Query */ + + + + Id + System.Int32 + + + DateCreate + System.DateTime + + + ManufactureName + System.String + + + Sum + System.Decimal + + + Status + System.String + + + + ManufactureCompanyContracts.ViewModels + ReportOrdersViewModel + ManufactureCompanyContracts.ViewModels.ReportOrdersViewModel, ManufactureCompanyContracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + + + + + + + + + true + true + + + + + Заказы + + + + + + + 0.89986cm + 17.23759cm + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Parameters!ReportParameterPeriod.Value + + + + + + + ReportParameterPeriod + 0.89986cm + 0.9175cm + 17.23759cm + 1 + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + + + + 2.07073cm + + + 2.88212cm + + + 5.97364cm + + + 3.14082cm + + + 2.5cm + + + + + 0.6cm + + + + + true + true + + + + + Номер + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Дата создания + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Поездка + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Статус + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + Сумма + + + + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + 0.6cm + + + + + true + true + + + + + =Fields!Id.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!DateCreate.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!ManufactureName.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!Status.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!Sum.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + + + + + + + + + + + + + + After + + + + + + + DataSetOrders + 1.99375cm + 0.33514cm + 1.2cm + 16.56731cm + 2 + + + + + + true + true + + + + + =Sum(Fields!Sum.Value, "DataSetOrders") + + + + + + + Textbox11 + 3.60398cm + 13.76163cm + 0.6cm + 3.14082cm + 3 + + + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + Итого: + + + + + + + Textbox12 + 3.60398cm + 11.52621cm + 0.6cm + 2.23542cm + 4 + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + 2in + + + + + + + Textbox1 + 0.89986cm + 11.67694cm + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + + + + 3.81116cm + + + 3.5551cm + + + 3.72296cm + + + + + 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!Count.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + true + true + + + + + =Fields!Sum.Value + + + 2pt + 2pt + 2pt + 2pt + + + + + + + + + + + + + + + + + + + After + + + + + + + DataSetOrders + 1.07625cm + 0.30551cm + 1.2cm + 11.08922cm + 1 + + + + + + true + true + + + + + Итого: + + + + + + + Textbox12 + 2.73389cm + 5.43634cm + 0.6cm + 2.23542cm + 2 + + + Middle + 2pt + 2pt + 2pt + 2pt + + + + true + true + + + + + =Sum(Fields!Sum.Value, "DataSetOrders") + + + + + + + Textbox11 + 2.73389cm + 7.67176cm + 0.6cm + 3.72296cm + 3 + + + 2pt + 2pt + 2pt + 2pt + + + + 1.55556in +