Compare commits

...

3 Commits

Author SHA1 Message Date
sardq
6c836919a1 изм 2024-05-29 16:14:23 +04:00
sardq
ba680292ef Merge branch 'main' of https://git.is.ulstu.ru/DavidMakarov/PIbd-21_Makarov_Razubaev_CourseWork 2024-05-29 16:14:03 +04:00
sardq
f1be1d5783 логика отчетов. раб 2024-05-29 16:13:55 +04:00
20 changed files with 411 additions and 68 deletions

View File

@ -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<PlanProductionProductReportViewModel> GetProductsByPlanProduction(List<PlanProductionSearchModel> plans)
{
//return _productStorage.GetProducts(plans);
throw new NotImplementedException();
List<int> ids = plans.Select(x =>(int)x.Id).ToList();
return _planProduction.GetProducts(ids);
}
public List<WorkpieceTimeReportViewModel> GetWorkpieces(ClientSearchModel client, ReportBindingModel model)
{
//return _workpieceStorage.GetWorkpiecesByPeriod(client, model);
throw new NotImplementedException();
return _workpieceStorage.GetWorkpiecesByPeriod(client, model);
}
public void SaveMachinesToPdfFile(ReportBindingModel model)
public void SaveWorkpiecesToPdfFile(ClientSearchModel client, ReportBindingModel model)
{
throw new NotImplementedException();
_saveToPdf.CreateWorkerDoc(new WorkerPdfInfo
{
FileName = model.FileName,
Title = "Список заготовок",
DateFrom = model.DateFrom!.Value,
DateTo = model.DateTo!.Value,
Workpieces = GetWorkpieces(client, model)
});
}
public void SavePlanProductionsToExcelFile(ReportBindingModel model)
public void SaveProductsToExcelFile(ReportBindingModel model, List<int> plans)
{
throw new NotImplementedException();
_saveToExcel.CreateWorkerReport(new WorkerExcelInfo
{
FileName = model.FileName,
Title = "Список планов",
//PlanProductionProducts = GetProductsByPlanProduction(plans)
});
}
public void SavePlanProductionsToWordFile(ReportBindingModel model)
public void SaveProudctsToWordFile(ReportBindingModel model, List<int> ids)
{
throw new NotImplementedException();
var plans = _planProduction.GetProducts(ids);
_saveToWord.CreateWorkerDoc(new WorkerWordInfo
{
FileName = model.FileName,
Title = "Список планов",
//PlanProductionProducts = GetProductsByPlanProduction(plans)
});
}
}
}

View File

@ -64,10 +64,63 @@ namespace FactoryBusinessLogic.OfficePackage
rowIndex++;
}
SaveStorekeeperExcel(info);
}
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(WorkerExcelInfo info);
}
}

View File

@ -78,12 +78,89 @@ namespace FactoryBusinessLogic.OfficePackage
}
}
SaveStorekeeperPdf(info);
}
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<string> { "3cm", "5cm", "5cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Название изделия", "Этапы выполнения", "Станки" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var workpiece in info.Workpieces)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string>
{
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>
{
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<string> columns);
protected abstract void CreateRow(PdfRowParameters rowParameters);
protected abstract void SaveStorekeeperPdf(StorekeeperPdfInfo info);
protected abstract void SaveWorkerPdf(WorkerPdfInfo info);
}
}

View File

@ -47,10 +47,52 @@ namespace FactoryBusinessLogic.OfficePackage
});
}
SaveStorekeeperWord(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);
}
}

View File

@ -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<PlanProductionProductReportViewModel> PlanProductionProducts
{
get;
set;
} = new();
}
}

View File

@ -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<WorkpieceTimeReportViewModel> Workpieces { get; set; } = new();
}
}

View File

@ -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<PlanProductionProductReportViewModel> PlanProductionProducts
{
get;
set;
} = new();
}
}

View File

@ -176,6 +176,39 @@ namespace FactoryBusinessLogic.OfficePackage.Implements
};
}
protected override void CreateStorekeeperExcel(StorekeeperExcelInfo info)
{
_spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook);
// Создаем книгу (в ней хранятся листы)
var workbookpart = _spreadsheetDocument.AddWorkbookPart();
workbookpart.Workbook = new Workbook();
CreateStyles(workbookpart);
// Получаем/создаем хранилище текстов для книги
_shareStringPart =
_spreadsheetDocument.WorkbookPart!.GetPartsOfType<SharedStringTablePart>().Any()
?
_spreadsheetDocument.WorkbookPart.GetPartsOfType<SharedStringTablePart>().First()
:
_spreadsheetDocument.WorkbookPart.AddNewPart<SharedStringTablePart>();
// Создаем SharedStringTable, если его нет
if (_shareStringPart.SharedStringTable == null)
{
_shareStringPart.SharedStringTable = new SharedStringTable();
}
// Создаем лист в книгу
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
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 CreateWorkerExcel(WorkerExcelInfo info)
{
_spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook);
// Создаем книгу (в ней хранятся листы)
@ -296,6 +329,15 @@ namespace FactoryBusinessLogic.OfficePackage.Implements
mergeCells.Append(mergeCell);
}
protected override void SaveStorekeeperExcel(StorekeeperExcelInfo info)
{
if (_spreadsheetDocument == null)
{
return;
}
_spreadsheetDocument.WorkbookPart!.Workbook.Save();
_spreadsheetDocument.Dispose();
}
protected override void SaveWorkerExcel(WorkerExcelInfo info)
{
if (_spreadsheetDocument == null)
{

View File

@ -30,6 +30,12 @@ namespace FactoryBusinessLogic.OfficePackage.Implements
style.Font.Bold = true;
}
protected override void CreateStorekeeperPdf(StorekeeperPdfInfo info)
{
_document = new Document();
DefineStyles(_document);
_section = _document.AddSection();
}
protected override void CreateWorkerPdf(WorkerPdfInfo info)
{
_document = new Document();
DefineStyles(_document);
@ -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);
}
}
}

View File

@ -57,6 +57,13 @@ namespace FactoryBusinessLogic.OfficePackage.Implements
return properties;
}
protected override void CreateStorekeeperWord(StorekeeperWordInfo 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 CreateWorkerWord(WorkerWordInfo info)
{
_wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document);
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
@ -92,6 +99,16 @@ namespace FactoryBusinessLogic.OfficePackage.Implements
_docBody.AppendChild(docParagraph);
}
protected override void SaveStorekeeperWord(StorekeeperWordInfo info)
{
if (_docBody == null || _wordDocument == null)
{
return;
}
_docBody.AppendChild(CreateSectionProperties());
_wordDocument.MainDocumentPart!.Document.Save();
_wordDocument.Dispose();
}
protected override void SaveWorkerWord(WorkerWordInfo info)
{
if (_docBody == null || _wordDocument == null)
{

View File

@ -8,8 +8,9 @@ namespace FactoryContracts.BusinessLogicsContracts
{
List<PlanProductionProductReportViewModel> GetProductsByPlanProduction(List<PlanProductionSearchModel> plans);
List<WorkpieceTimeReportViewModel> GetWorkpieces(ClientSearchModel client, ReportBindingModel model);
void SavePlanProductionsToWordFile(ReportBindingModel model);
void SavePlanProductionsToExcelFile(ReportBindingModel model);
void SaveMachinesToPdfFile(ReportBindingModel model);
void SaveProudctsToWordFile(ReportBindingModel model, List<int> plans);
void SaveProductsToExcelFile(ReportBindingModel model, List<int> plans);
void SaveWorkpiecesToPdfFile(ClientSearchModel client, ReportBindingModel model);
}
}

View File

@ -17,5 +17,8 @@ namespace FactoryContracts.StoragesContracts
PlanProductionViewModel? Update(PlanProductionBindingModel model);
PlanProductionViewModel? Delete(PlanProductionBindingModel model);
List<PlanProductionProductReportViewModel> GetProducts(List<int> ids);
}
}

View File

@ -9,6 +9,8 @@ namespace FactoryContracts.StoragesContracts
List<WorkpieceViewModel> GetFullList();
List<WorkpieceViewModel> GetFilteredList(WorkpieceSearchModel model);
List<WorkpieceTimeReportViewModel> GetWorkpiecesByPeriod(ClientSearchModel client, ReportBindingModel model);
WorkpieceViewModel? GetElement(WorkpieceSearchModel model);

View File

@ -3,6 +3,6 @@
public class PlanProductionProductReportViewModel
{
public string ProductionName { get; set; } = string.Empty;
public List<string> Products { get; set; } = new();
public List<ProductViewModel> Products { get; set; } = new();
}
}

View File

@ -3,7 +3,7 @@
public class WorkpieceTimeReportViewModel
{
public string WorkpieceName { get; set; } = string.Empty;
public List<string> ExecutionPhases { get; set; } = new();
public List<string> Machines { get; set; } = new();
public List<ExecutionPhaseViewModel> ExecutionPhases { get; set; } = new();
public List<MachineViewModel> Machines { get; set; } = new();
}
}

View File

@ -123,5 +123,21 @@ namespace FactoryDatabaseImplement.Implements
}
}
public List<PlanProductionProductReportViewModel> GetProducts(List<int> 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();
}
}
}

View File

@ -9,6 +9,21 @@ namespace FactoryDatabaseImplement.Implements
{
public class WorkpieceStorage : IWorkpieceStorage
{
public List<WorkpieceTimeReportViewModel> 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<WorkpieceViewModel> GetFullList()
{
using var context = new FactoryDatabase();

View File

@ -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<HomeController> _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<HomeController> logger, WorkerLogic logic)
public HomeController(ILogger<HomeController> 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<PlanProductionProductReportViewModel> reports = new List<PlanProductionProductReportViewModel>
{
new PlanProductionProductReportViewModel
{
ProductionName = "План производства X",
Products = new List<string> { "Изделие 1", "Изделие 2" }
},
new PlanProductionProductReportViewModel
{
ProductionName = "План производства Y",
Products = new List<string> { "Изделие 3", "Изделие 4" }
}
};
return View(reports);
}
[HttpGet]
public IActionResult WorkpieceTimeChoose()
{

View File

@ -108,7 +108,6 @@
`;
$('#productsTable tbody').append(newRow);
updateSum();
$('#productSelect').val('');
} else {
alert('Выберите изделие для добавления');

View File

@ -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<WorkerLogic> logger, IClientLogic clientLogic, IWorkpieceLogic workpieceLogic, IPlanProductionLogic planProductionLogic, IExecutionPhaseLogic executionPhaseLogic, IProductLogic productLogic)
public WorkerLogic(ILogger<WorkerLogic> 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)