From f1be1d5783787ca112c459b992d0ce716f383e4d Mon Sep 17 00:00:00 2001 From: sardq Date: Wed, 29 May 2024 16:13:55 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=BE?= =?UTF-8?q?=D1=82=D1=87=D0=B5=D1=82=D0=BE=D0=B2.=20=D1=80=D0=B0=D0=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/WorkerReportLogic.cs | 77 ++++++++++++------ .../OfficePackage/AbstractSaveToExcel.cs | 57 ++++++++++++- .../OfficePackage/AbstractSaveToPdf.cs | 81 ++++++++++++++++++- .../OfficePackage/AbstractSaveToWord.cs | 44 +++++++++- .../HelperModels/WorkerExcelInfo.cs | 16 ++++ .../HelperModels/WorkerPdfInfo.cs | 14 ++++ .../HelperModels/WorkerWordInfo.cs | 15 ++++ .../OfficePackage/Implements/SaveToExcel.cs | 46 ++++++++++- .../OfficePackage/Implements/SaveToPdf.cs | 19 ++++- .../OfficePackage/Implements/SaveToWord.cs | 21 ++++- .../IWorkerReportLogic.cs | 9 ++- .../IPlanProductionStorage.cs | 5 +- .../StoragesContracts/IWorkpieceStorage.cs | 4 +- .../PlanProductionProductReportViewModel.cs | 2 +- .../WorkpieceTimeReportViewModel.cs | 4 +- .../Implements/PlanProductionStorage.cs | 18 ++++- .../Implements/WorkpieceStorage.cs | 15 ++++ .../Controllers/HomeController.cs | 24 ++---- .../Views/Home/Workpiece.cshtml | 1 - Factory/FactoryWorkerApp/WorkerLogic.cs | 7 +- 20 files changed, 411 insertions(+), 68 deletions(-) create mode 100644 Factory/FactoryBuisinessLogic/OfficePackage/HelperModels/WorkerExcelInfo.cs create mode 100644 Factory/FactoryBuisinessLogic/OfficePackage/HelperModels/WorkerPdfInfo.cs create mode 100644 Factory/FactoryBuisinessLogic/OfficePackage/HelperModels/WorkerWordInfo.cs diff --git a/Factory/FactoryBuisinessLogic/BusinessLogics/WorkerReportLogic.cs b/Factory/FactoryBuisinessLogic/BusinessLogics/WorkerReportLogic.cs index 68c6f41..c336446 100644 --- a/Factory/FactoryBuisinessLogic/BusinessLogics/WorkerReportLogic.cs +++ b/Factory/FactoryBuisinessLogic/BusinessLogics/WorkerReportLogic.cs @@ -1,4 +1,6 @@ -using FactoryContracts.BindingModels; +using FactoryBusinessLogic.OfficePackage; +using FactoryBusinessLogic.OfficePackage.HelperModels; +using FactoryContracts.BindingModels; using FactoryContracts.BusinessLogicsContracts; using FactoryContracts.SearchModels; using FactoryContracts.StoragesContracts; @@ -8,34 +10,57 @@ namespace FactoryBusinessLogic.BusinessLogics { public class WorkerReportLogic : IWorkerReportLogic { - private readonly IMachineStorage _machineStorage; - private readonly IProductStorage _productStorage; - public WorkerReportLogic(IMachineStorage machineStorage, IProductStorage productStorage) + private readonly IWorkpieceStorage _workpieceStorage; + private readonly IPlanProductionStorage _planProduction; + private readonly AbstractSaveToWord _saveToWord; + private readonly AbstractSaveToExcel _saveToExcel; + private readonly AbstractSaveToPdf _saveToPdf; + public WorkerReportLogic(IWorkpieceStorage workpieceStorage, IPlanProductionStorage planProductionStorage, AbstractSaveToWord saveToWord, AbstractSaveToExcel saveToExcel, AbstractSaveToPdf saveToPdf) { - _machineStorage = machineStorage; - _productStorage = productStorage; + _workpieceStorage = workpieceStorage; + _planProduction = planProductionStorage; + _saveToExcel = saveToExcel; + _saveToPdf = saveToPdf; + _saveToWord = saveToWord; } public List GetProductsByPlanProduction(List plans) { - //return _productStorage.GetProducts(plans); - throw new NotImplementedException(); + List ids = plans.Select(x =>(int)x.Id).ToList(); + return _planProduction.GetProducts(ids); } - public List GetWorkpieces(ClientSearchModel client, ReportBindingModel model) - { - //return _workpieceStorage.GetWorkpiecesByPeriod(client, model); - throw new NotImplementedException(); - } - public void SaveMachinesToPdfFile(ReportBindingModel model) - { - throw new NotImplementedException(); - } - public void SavePlanProductionsToExcelFile(ReportBindingModel model) - { - throw new NotImplementedException(); - } - public void SavePlanProductionsToWordFile(ReportBindingModel model) - { - throw new NotImplementedException(); - } - } + public List GetWorkpieces(ClientSearchModel client, ReportBindingModel model) + { + return _workpieceStorage.GetWorkpiecesByPeriod(client, model); + } + public void SaveWorkpiecesToPdfFile(ClientSearchModel client, ReportBindingModel model) + { + _saveToPdf.CreateWorkerDoc(new WorkerPdfInfo + { + FileName = model.FileName, + Title = "Список заготовок", + DateFrom = model.DateFrom!.Value, + DateTo = model.DateTo!.Value, + Workpieces = GetWorkpieces(client, model) + }); + } + public void SaveProductsToExcelFile(ReportBindingModel model, List plans) + { + _saveToExcel.CreateWorkerReport(new WorkerExcelInfo + { + FileName = model.FileName, + Title = "Список планов", + //PlanProductionProducts = GetProductsByPlanProduction(plans) + }); + } + public void SaveProudctsToWordFile(ReportBindingModel model, List ids) + { + var plans = _planProduction.GetProducts(ids); + _saveToWord.CreateWorkerDoc(new WorkerWordInfo + { + FileName = model.FileName, + Title = "Список планов", + //PlanProductionProducts = GetProductsByPlanProduction(plans) + }); + } + } } diff --git a/Factory/FactoryBuisinessLogic/OfficePackage/AbstractSaveToExcel.cs b/Factory/FactoryBuisinessLogic/OfficePackage/AbstractSaveToExcel.cs index 9bc19d8..4542fd8 100644 --- a/Factory/FactoryBuisinessLogic/OfficePackage/AbstractSaveToExcel.cs +++ b/Factory/FactoryBuisinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -65,9 +65,62 @@ namespace FactoryBusinessLogic.OfficePackage } SaveStorekeeperExcel(info); } - protected abstract void CreateStorekeeperExcel(StorekeeperExcelInfo info); - protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); + public void CreateWorkerReport(WorkerExcelInfo info) + { + CreateWorkerExcel(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 pp in info.PlanProductionProducts) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = pp.ProductionName, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + + foreach (var product in pp.Products) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = product.ProductName, + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = product.Price.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); + + rowIndex++; + } + rowIndex++; + } + SaveWorkerExcel(info); + } + protected abstract void CreateStorekeeperExcel(StorekeeperExcelInfo info); + protected abstract void CreateWorkerExcel(WorkerExcelInfo info); + protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); protected abstract void MergeCells(ExcelMergeParameters excelParams); protected abstract void SaveStorekeeperExcel(StorekeeperExcelInfo info); + protected abstract void SaveWorkerExcel(StorekeeperExcelInfo info); } } diff --git a/Factory/FactoryBuisinessLogic/OfficePackage/AbstractSaveToPdf.cs b/Factory/FactoryBuisinessLogic/OfficePackage/AbstractSaveToPdf.cs index 710db99..fd9032d 100644 --- a/Factory/FactoryBuisinessLogic/OfficePackage/AbstractSaveToPdf.cs +++ b/Factory/FactoryBuisinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -79,11 +79,88 @@ namespace FactoryBusinessLogic.OfficePackage } SaveStorekeeperPdf(info); } - protected abstract void CreateStorekeeperPdf(StorekeeperPdfInfo info); - protected abstract void CreateParagraph(PdfParagraph paragraph); + public void CreateWorkerDoc(WorkerPdfInfo info) + { + CreateWorkerPdf(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 { "3cm", "5cm", "5cm" }); + CreateRow(new PdfRowParameters + { + Texts = new List { "Название изделия", "Этапы выполнения", "Станки" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + foreach (var workpiece in info.Workpieces) + { + CreateRow(new PdfRowParameters + { + Texts = new List + { + workpiece.WorkpieceName, + string.Empty, + string.Empty, + }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + var phaseNames = workpiece.ExecutionPhases.Select(x => x.ExecutionPhaseName).ToList(); + var machineNames = workpiece.Machines.Select(x => x.MachineName).ToList(); + + if (phaseNames.Count != machineNames.Count) + { + if (phaseNames.Count > machineNames.Count) + { + var diff = phaseNames.Count - machineNames.Count; + for (int i = 0; i < diff; i++) + { + machineNames.Add(string.Empty); + } + } + else + { + var diff = machineNames.Count - phaseNames.Count; + for (int i = 0; i < diff; i++) + { + phaseNames.Add(string.Empty); + } + } + } + var tupleList = machineNames.Zip(phaseNames, Tuple.Create); + foreach (var tuple in tupleList) + { + CreateRow(new PdfRowParameters + { + Texts = new List + { + string.Empty, + tuple.Item1, + tuple.Item2, + }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + } + SaveWorkerPdf(info); + } + protected abstract void CreateStorekeeperPdf(StorekeeperPdfInfo info); + protected abstract void CreateWorkerPdf(WorkerPdfInfo info); + protected abstract void CreateParagraph(PdfParagraph paragraph); protected abstract void CreateTable(List columns); protected abstract void CreateRow(PdfRowParameters rowParameters); protected abstract void SaveStorekeeperPdf(StorekeeperPdfInfo info); + protected abstract void SaveWorkerPdf(WorkerPdfInfo info); } } diff --git a/Factory/FactoryBuisinessLogic/OfficePackage/AbstractSaveToWord.cs b/Factory/FactoryBuisinessLogic/OfficePackage/AbstractSaveToWord.cs index 8c42676..025c707 100644 --- a/Factory/FactoryBuisinessLogic/OfficePackage/AbstractSaveToWord.cs +++ b/Factory/FactoryBuisinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -48,9 +48,51 @@ namespace FactoryBusinessLogic.OfficePackage } SaveStorekeeperWord(info); } - protected abstract void CreateStorekeeperWord(StorekeeperWordInfo info); + public void CreateWorkerDoc(WorkerWordInfo info) + { + CreateWorkerWord(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 ppp in info.PlanProductionProducts) + { + var t = ppp.Products; + List<(string, WordTextProperties)> texts = new List<(string, WordTextProperties)> + { + (ppp.ProductionName, new WordTextProperties { Bold = true, Size = "24", }) + }; + foreach (var product in ppp.Products) + { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.Append(product.ProductName); + stringBuilder.Append(" — "); + stringBuilder.Append(product.Price.ToString()); + texts.Add((stringBuilder.ToString(), new WordTextProperties { Size = "24" })); + } + CreateParagraph(new WordParagraph + { + Texts = texts, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + } + SaveWorkerWord(info); + } + protected abstract void CreateStorekeeperWord(StorekeeperWordInfo info); + protected abstract void CreateWorkerWord(WorkerWordInfo info); protected abstract void CreateParagraph(WordParagraph paragraph); protected abstract void SaveStorekeeperWord(StorekeeperWordInfo info); + protected abstract void SaveWorkerWord(WorkerWordInfo info); } } diff --git a/Factory/FactoryBuisinessLogic/OfficePackage/HelperModels/WorkerExcelInfo.cs b/Factory/FactoryBuisinessLogic/OfficePackage/HelperModels/WorkerExcelInfo.cs new file mode 100644 index 0000000..249f50d --- /dev/null +++ b/Factory/FactoryBuisinessLogic/OfficePackage/HelperModels/WorkerExcelInfo.cs @@ -0,0 +1,16 @@ +using FactoryContracts.ViewModels; + +namespace FactoryBusinessLogic.OfficePackage.HelperModels +{ + public class WorkerExcelInfo + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List PlanProductionProducts + { + get; + set; + } = new(); + } + +} diff --git a/Factory/FactoryBuisinessLogic/OfficePackage/HelperModels/WorkerPdfInfo.cs b/Factory/FactoryBuisinessLogic/OfficePackage/HelperModels/WorkerPdfInfo.cs new file mode 100644 index 0000000..f91a333 --- /dev/null +++ b/Factory/FactoryBuisinessLogic/OfficePackage/HelperModels/WorkerPdfInfo.cs @@ -0,0 +1,14 @@ +using FactoryContracts.ViewModels; + +namespace FactoryBusinessLogic.OfficePackage.HelperModels +{ + public class WorkerPdfInfo + { + 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 Workpieces { get; set; } = new(); + } + +} diff --git a/Factory/FactoryBuisinessLogic/OfficePackage/HelperModels/WorkerWordInfo.cs b/Factory/FactoryBuisinessLogic/OfficePackage/HelperModels/WorkerWordInfo.cs new file mode 100644 index 0000000..5d5c679 --- /dev/null +++ b/Factory/FactoryBuisinessLogic/OfficePackage/HelperModels/WorkerWordInfo.cs @@ -0,0 +1,15 @@ +using FactoryContracts.ViewModels; + +namespace FactoryBusinessLogic.OfficePackage.HelperModels +{ + public class WorkerWordInfo + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List PlanProductionProducts + { + get; + set; + } = new(); + } +} diff --git a/Factory/FactoryBuisinessLogic/OfficePackage/Implements/SaveToExcel.cs b/Factory/FactoryBuisinessLogic/OfficePackage/Implements/SaveToExcel.cs index 035f9a8..22283b6 100644 --- a/Factory/FactoryBuisinessLogic/OfficePackage/Implements/SaveToExcel.cs +++ b/Factory/FactoryBuisinessLogic/OfficePackage/Implements/SaveToExcel.cs @@ -208,7 +208,40 @@ namespace FactoryBusinessLogic.OfficePackage.Implements sheets.Append(sheet); _worksheet = worksheetPart.Worksheet; } - protected override void InsertCellInWorksheet(ExcelCellParameters excelParams) + protected override void CreateWorkerExcel(WorkerExcelInfo 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) { @@ -304,5 +337,14 @@ namespace FactoryBusinessLogic.OfficePackage.Implements _spreadsheetDocument.WorkbookPart!.Workbook.Save(); _spreadsheetDocument.Dispose(); } - } + protected override void SaveWorkerExcel(WorkerExcelInfo info) + { + if (_spreadsheetDocument == null) + { + return; + } + _spreadsheetDocument.WorkbookPart!.Workbook.Save(); + _spreadsheetDocument.Dispose(); + } + } } diff --git a/Factory/FactoryBuisinessLogic/OfficePackage/Implements/SaveToPdf.cs b/Factory/FactoryBuisinessLogic/OfficePackage/Implements/SaveToPdf.cs index 098dc54..a87e5f3 100644 --- a/Factory/FactoryBuisinessLogic/OfficePackage/Implements/SaveToPdf.cs +++ b/Factory/FactoryBuisinessLogic/OfficePackage/Implements/SaveToPdf.cs @@ -35,7 +35,13 @@ namespace FactoryBusinessLogic.OfficePackage.Implements DefineStyles(_document); _section = _document.AddSection(); } - protected override void CreateParagraph(PdfParagraph pdfParagraph) + protected override void CreateWorkerPdf(WorkerPdfInfo info) + { + _document = new Document(); + DefineStyles(_document); + _section = _document.AddSection(); + } + protected override void CreateParagraph(PdfParagraph pdfParagraph) { if (_section == null) { @@ -90,6 +96,15 @@ namespace FactoryBusinessLogic.OfficePackage.Implements renderer.RenderDocument(); renderer.PdfDocument.Save(info.FileName); } + protected override void SaveWorkerPdf(WorkerPdfInfo info) + { + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(info.FileName); + } - } + } } \ No newline at end of file diff --git a/Factory/FactoryBuisinessLogic/OfficePackage/Implements/SaveToWord.cs b/Factory/FactoryBuisinessLogic/OfficePackage/Implements/SaveToWord.cs index 01adb5c..c877738 100644 --- a/Factory/FactoryBuisinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/Factory/FactoryBuisinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -63,7 +63,14 @@ namespace FactoryBusinessLogic.OfficePackage.Implements mainPart.Document = new Document(); _docBody = mainPart.Document.AppendChild(new Body()); } - protected override void CreateParagraph(WordParagraph paragraph) + protected override void CreateWorkerWord(WorkerWordInfo 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) { @@ -101,5 +108,15 @@ namespace FactoryBusinessLogic.OfficePackage.Implements _wordDocument.MainDocumentPart!.Document.Save(); _wordDocument.Dispose(); } - } + protected override void SaveWorkerWord(WorkerWordInfo info) + { + if (_docBody == null || _wordDocument == null) + { + return; + } + _docBody.AppendChild(CreateSectionProperties()); + _wordDocument.MainDocumentPart!.Document.Save(); + _wordDocument.Dispose(); + } + } } diff --git a/Factory/FactoryContracts/BusinessLogicsContracts/IWorkerReportLogic.cs b/Factory/FactoryContracts/BusinessLogicsContracts/IWorkerReportLogic.cs index e90d20d..8432ab4 100644 --- a/Factory/FactoryContracts/BusinessLogicsContracts/IWorkerReportLogic.cs +++ b/Factory/FactoryContracts/BusinessLogicsContracts/IWorkerReportLogic.cs @@ -8,8 +8,9 @@ namespace FactoryContracts.BusinessLogicsContracts { List GetProductsByPlanProduction(List plans); List GetWorkpieces(ClientSearchModel client, ReportBindingModel model); - void SavePlanProductionsToWordFile(ReportBindingModel model); - void SavePlanProductionsToExcelFile(ReportBindingModel model); - void SaveMachinesToPdfFile(ReportBindingModel model); - } + void SaveProudctsToWordFile(ReportBindingModel model, List plans); + void SaveProductsToExcelFile(ReportBindingModel model, List plans); + void SaveWorkpiecesToPdfFile(ClientSearchModel client, ReportBindingModel model); + + } } diff --git a/Factory/FactoryContracts/StoragesContracts/IPlanProductionStorage.cs b/Factory/FactoryContracts/StoragesContracts/IPlanProductionStorage.cs index a5ceb9f..6e46a87 100644 --- a/Factory/FactoryContracts/StoragesContracts/IPlanProductionStorage.cs +++ b/Factory/FactoryContracts/StoragesContracts/IPlanProductionStorage.cs @@ -17,5 +17,8 @@ namespace FactoryContracts.StoragesContracts PlanProductionViewModel? Update(PlanProductionBindingModel model); PlanProductionViewModel? Delete(PlanProductionBindingModel model); - } + + List GetProducts(List ids); + + } } \ No newline at end of file diff --git a/Factory/FactoryContracts/StoragesContracts/IWorkpieceStorage.cs b/Factory/FactoryContracts/StoragesContracts/IWorkpieceStorage.cs index 08f0ae5..d22c40f 100644 --- a/Factory/FactoryContracts/StoragesContracts/IWorkpieceStorage.cs +++ b/Factory/FactoryContracts/StoragesContracts/IWorkpieceStorage.cs @@ -9,8 +9,10 @@ namespace FactoryContracts.StoragesContracts List GetFullList(); List GetFilteredList(WorkpieceSearchModel model); + List GetWorkpiecesByPeriod(ClientSearchModel client, ReportBindingModel model); - WorkpieceViewModel? GetElement(WorkpieceSearchModel model); + + WorkpieceViewModel? GetElement(WorkpieceSearchModel model); WorkpieceViewModel? Insert(WorkpieceBindingModel model); diff --git a/Factory/FactoryContracts/ViewModels/PlanProductionProductReportViewModel.cs b/Factory/FactoryContracts/ViewModels/PlanProductionProductReportViewModel.cs index 7eef215..4aad646 100644 --- a/Factory/FactoryContracts/ViewModels/PlanProductionProductReportViewModel.cs +++ b/Factory/FactoryContracts/ViewModels/PlanProductionProductReportViewModel.cs @@ -3,6 +3,6 @@ public class PlanProductionProductReportViewModel { public string ProductionName { get; set; } = string.Empty; - public List Products { get; set; } = new(); + public List Products { get; set; } = new(); } } diff --git a/Factory/FactoryContracts/ViewModels/WorkpieceTimeReportViewModel.cs b/Factory/FactoryContracts/ViewModels/WorkpieceTimeReportViewModel.cs index 4cbb25e..5ce358f 100644 --- a/Factory/FactoryContracts/ViewModels/WorkpieceTimeReportViewModel.cs +++ b/Factory/FactoryContracts/ViewModels/WorkpieceTimeReportViewModel.cs @@ -3,7 +3,7 @@ public class WorkpieceTimeReportViewModel { public string WorkpieceName { get; set; } = string.Empty; - public List ExecutionPhases { get; set; } = new(); - public List Machines { get; set; } = new(); + public List ExecutionPhases { get; set; } = new(); + public List Machines { get; set; } = new(); } } diff --git a/Factory/FactoryDatabaseImplement/Implements/PlanProductionStorage.cs b/Factory/FactoryDatabaseImplement/Implements/PlanProductionStorage.cs index aa06610..725978f 100644 --- a/Factory/FactoryDatabaseImplement/Implements/PlanProductionStorage.cs +++ b/Factory/FactoryDatabaseImplement/Implements/PlanProductionStorage.cs @@ -123,5 +123,21 @@ namespace FactoryDatabaseImplement.Implements } } - } + public List GetProducts(List ids) + { + using var context = new FactoryDatabase(); + return context.PlanProductions + .Where(plan => ids.Contains(plan.Id)) + .Select(plan => new PlanProductionProductReportViewModel() + { + ProductionName = plan.ProductionName, + Products = context.WorkpieceProducts + .Include(x => x.Product) + .Where(product => plan.Id == product.Product.Id) + .Select(x => x.Product.GetViewModel) + .ToList() + }) + .ToList(); + } + } } \ No newline at end of file diff --git a/Factory/FactoryDatabaseImplement/Implements/WorkpieceStorage.cs b/Factory/FactoryDatabaseImplement/Implements/WorkpieceStorage.cs index a5277cb..c63f45c 100644 --- a/Factory/FactoryDatabaseImplement/Implements/WorkpieceStorage.cs +++ b/Factory/FactoryDatabaseImplement/Implements/WorkpieceStorage.cs @@ -9,6 +9,21 @@ namespace FactoryDatabaseImplement.Implements { public class WorkpieceStorage : IWorkpieceStorage { + public List GetWorkpiecesByPeriod(ClientSearchModel client, ReportBindingModel model) + { + using var context = new FactoryDatabase(); + return context.Workpieces + .Include(x => x.Client) + // not sure if its true + .Where(x => x.ClientId == client.Id && x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) + .Select(x => new WorkpieceTimeReportViewModel() + { + WorkpieceName = x.WorkpieceName, + ExecutionPhases = x.ExecutionPhases.Select(x => x.PlanProduction.GetViewModel).ToList(), + Machines = x.Machines.Select(x => x.Product.GetViewModel).ToList(), + }) + .ToList(); + } public List GetFullList() { using var context = new FactoryDatabase(); diff --git a/Factory/FactoryWorkerApp/Controllers/HomeController.cs b/Factory/FactoryWorkerApp/Controllers/HomeController.cs index 350c207..412b59e 100644 --- a/Factory/FactoryWorkerApp/Controllers/HomeController.cs +++ b/Factory/FactoryWorkerApp/Controllers/HomeController.cs @@ -1,5 +1,6 @@ using DocumentFormat.OpenXml.Office2010.Excel; using FactoryContracts.BindingModels; +using FactoryContracts.BusinessLogicsContracts; using FactoryContracts.ViewModels; using FactoryDatabaseImplement.Models; using FactoryDataModels.Enums; @@ -14,13 +15,15 @@ namespace FactoryWorkerApp.Controllers { private readonly ILogger _logger; private readonly WorkerLogic _logic; + private readonly IWorkerReportLogic _workerReportLogic; private bool IsLoggedIn { get { return Client.user != null; } } private int UserId { get { return Client.user!.Id; } } - public HomeController(ILogger logger, WorkerLogic logic) + public HomeController(ILogger logger, WorkerLogic logic, IWorkerReportLogic workerReportLogic) { _logger = logger; _logic = logic; + _workerReportLogic = workerReportLogic; } public IActionResult Index() @@ -225,24 +228,7 @@ namespace FactoryWorkerApp.Controllers { return View(); } - [HttpGet] - public IActionResult ProductProductionReport() - { - List reports = new List - { - new PlanProductionProductReportViewModel - { - ProductionName = "План производства X", - Products = new List { "Изделие 1", "Изделие 2" } - }, - new PlanProductionProductReportViewModel - { - ProductionName = "План производства Y", - Products = new List { "Изделие 3", "Изделие 4" } - } - }; - return View(reports); - } + [HttpGet] public IActionResult WorkpieceTimeChoose() { diff --git a/Factory/FactoryWorkerApp/Views/Home/Workpiece.cshtml b/Factory/FactoryWorkerApp/Views/Home/Workpiece.cshtml index 88acb43..a2014d3 100644 --- a/Factory/FactoryWorkerApp/Views/Home/Workpiece.cshtml +++ b/Factory/FactoryWorkerApp/Views/Home/Workpiece.cshtml @@ -108,7 +108,6 @@ `; $('#productsTable tbody').append(newRow); - updateSum(); $('#productSelect').val(''); } else { alert('Выберите изделие для добавления'); diff --git a/Factory/FactoryWorkerApp/WorkerLogic.cs b/Factory/FactoryWorkerApp/WorkerLogic.cs index 0ba9c2f..81145c9 100644 --- a/Factory/FactoryWorkerApp/WorkerLogic.cs +++ b/Factory/FactoryWorkerApp/WorkerLogic.cs @@ -1,3 +1,5 @@ +using DocumentFormat.OpenXml.ExtendedProperties; +using FactoryBusinessLogic.OfficePackage; using FactoryContracts.BindingModels; using FactoryContracts.BusinessLogicsContracts; using FactoryContracts.SearchModels; @@ -13,8 +15,10 @@ namespace FactoryWorkerApp private readonly IPlanProductionLogic _planProductionLogic; private readonly IProductLogic _productLogic; private readonly IExecutionPhaseLogic _executionPhaseLogic; + private readonly IWorkerReportLogic _workerReport; + - public WorkerLogic(ILogger logger, IClientLogic clientLogic, IWorkpieceLogic workpieceLogic, IPlanProductionLogic planProductionLogic, IExecutionPhaseLogic executionPhaseLogic, IProductLogic productLogic) + public WorkerLogic(ILogger logger, IClientLogic clientLogic, IWorkpieceLogic workpieceLogic, IPlanProductionLogic planProductionLogic, IExecutionPhaseLogic executionPhaseLogic, IProductLogic productLogic, IWorkerReportLogic reportLogic) { _logger = logger; _clientLogic = clientLogic; @@ -22,6 +26,7 @@ namespace FactoryWorkerApp _planProductionLogic = planProductionLogic; _executionPhaseLogic = executionPhaseLogic; _productLogic = productLogic; + _workerReport = reportLogic; } public ClientViewModel? Login(string login, string password)