-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(formats): generate WarMaterialAndSpecialEquipmentAssignmentForma…
…t header and main info
- Loading branch information
1 parent
91d9441
commit d9e421f
Showing
7 changed files
with
151 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 84 additions & 3 deletions
87
...ntFormats/Application/Generate/WarMaterialAndSpecialEquipmentAssignmentFormatGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,95 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Armory.Formats.Shared.Domain; | ||
using Armory.Formats.WarMaterialAndSpecialEquipmentAssignmentFormats.Domain; | ||
using Armory.Shared.Domain.ClosedXML; | ||
using ClosedXML.Excel; | ||
using Microsoft.AspNetCore.Hosting; | ||
|
||
namespace Armory.Formats.WarMaterialAndSpecialEquipmentAssignmentFormats.Application.Generate | ||
{ | ||
public class WarMaterialAndSpecialEquipmentAssignmentFormatGenerator | ||
{ | ||
public async Task<MemoryStream> Generate(WarMaterialAndSpecialEquipmentAssignmentFormat format) | ||
private const string FormatName = "FORMATO ASIGNACIÓN MATERIAL DE GUERRA Y EQUIPO ESPECIAL"; | ||
private const string FormatTitle = "FUERZA AÉREA COLOMBIANA"; | ||
|
||
private readonly IHostingEnvironment _environment; | ||
private readonly IWorksheetManager _worksheetManager; | ||
|
||
public WarMaterialAndSpecialEquipmentAssignmentFormatGenerator(IHostingEnvironment environment, | ||
IWorksheetManager worksheetManager) | ||
{ | ||
_environment = environment; | ||
_worksheetManager = worksheetManager; | ||
} | ||
|
||
private void MakeWorksheetHeader(IXLWorksheet worksheet, WarMaterialAndSpecialEquipmentAssignmentFormat format) | ||
{ | ||
_worksheetManager.SetRowsHeight(worksheet.Rows(1, 3), 33); | ||
_worksheetManager.SetColumnsWidth(worksheet.Columns("B:M"), 14); | ||
worksheet.Column("A").Width = 4; | ||
_worksheetManager.SetCommonRangeStyles(worksheet.Range("A1:M3")); | ||
|
||
_worksheetManager.MergeRangeAndSetValue(worksheet.Range("A1:B3"), "ArmoryImage"); | ||
_worksheetManager.MergeRangeAndSetValue(worksheet.Range("C1:K1"), FormatTitle); | ||
_worksheetManager.MergeRangeAndSetValue(worksheet.Range("C2:K3"), FormatName); | ||
|
||
worksheet.Cell("L1").Value = "Código"; | ||
worksheet.Cell("L2").Value = "Versión"; | ||
worksheet.Cell("L3").Value = "Vigencia"; | ||
|
||
worksheet.Cell("M1").Value = format.Code; | ||
worksheet.Cell("M2").Value = 4; | ||
worksheet.Cell("M3").Value = format.Validity.ToString("d"); | ||
} | ||
|
||
private void MakeWorksheetMainInfo(IXLWorksheet worksheet, | ||
WarMaterialAndSpecialEquipmentAssignmentFormat format) | ||
{ | ||
return null; | ||
_worksheetManager.MergeRangeAndSetValue(worksheet.Range("K5:M5"), "FORMATO ACTA No."); | ||
|
||
_worksheetManager.SetRangeFontBold(worksheet.Range("K5:M5"), true); | ||
_worksheetManager.SetRangeFontBold(worksheet.Range("A6:M17"), true); | ||
|
||
_worksheetManager.MergeRangeAndSetValue(worksheet.Range("A6:F6"), | ||
$"Lugar y fecha: {format.Place}, {format.Date:d}"); | ||
_worksheetManager.MergeRangeAndSetValue(worksheet.Range("A7:F7"), $"Unidad: {format.SquadronCode}"); | ||
|
||
var warehouse = format.Warehouse == Warehouse.Air ? "AÉREO" : "TERRESTRE"; | ||
_worksheetManager.MergeRangeAndSetValue(worksheet.Range("H7:M7"), | ||
$"ALMACÉN DE ARMAMENTO: {warehouse}"); | ||
_worksheetManager.MergeRangeAndSetValue(worksheet.Range("A8:F8"), $"Solicitante: {format.TroopId}"); | ||
_worksheetManager.MergeRangeAndSetValue(worksheet.Range("A9:F9"), $"Dependencia: {format.SquadCode}"); | ||
|
||
var purpose = format.Purpose switch | ||
{ | ||
Purpose.Instruction => "INSTRUCCIÓN", | ||
Purpose.Operations => "OPERACIONES", | ||
Purpose.Verification => "COMPROBACIÓN", | ||
_ => throw new ArgumentOutOfRangeException( | ||
$"Invalid purpose value, the pass value is {format.Purpose}") | ||
}; | ||
_worksheetManager.MergeRangeAndSetValue(worksheet.Range("A11:F11"), $"Finalidad: {purpose}"); | ||
_worksheetManager.MergeRangeAndSetValue(worksheet.Range("I11:M11"), $"OTROS: {format.Others}"); | ||
|
||
var docMovement = format.DocMovement == DocMovement.Consumption ? "CONSUMO" : "DEVOLUTIVO"; | ||
_worksheetManager.MergeRangeAndSetValue(worksheet.Range("A5:F15"), $"DOC MOVIMIENTO: {docMovement}"); | ||
_worksheetManager.MergeRangeAndSetValue(worksheet.Range("A17:D17"), | ||
$"UBICACIÓN FÍSICA: {format.PhysicalLocation}"); | ||
} | ||
|
||
public MemoryStream Generate(WarMaterialAndSpecialEquipmentAssignmentFormat format) | ||
{ | ||
var workBook = new XLWorkbook(); | ||
var workSheet = workBook.AddWorksheet(format.Code); | ||
|
||
MakeWorksheetHeader(workSheet, format); | ||
MakeWorksheetMainInfo(workSheet, format); | ||
|
||
var memoryStream = new MemoryStream(); | ||
workBook.SaveAs(memoryStream); | ||
|
||
return memoryStream; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using ClosedXML.Excel; | ||
|
||
namespace Armory.Shared.Domain.ClosedXML | ||
{ | ||
public interface IWorksheetManager | ||
{ | ||
void SetRowsHeight(IXLRows rows, float height); | ||
void SetColumnsWidth(IXLColumns columns, float width); | ||
void SetCommonRangeStyles(IXLRange range); | ||
void MergeRange(IXLRange range); | ||
void MergeRangeAndSetValue<T>(IXLRange range, T value); | ||
|
||
void SetRangeFontBold(IXLRange range, bool bold); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using Armory.Shared.Domain.ClosedXML; | ||
using ClosedXML.Excel; | ||
|
||
namespace Armory.Shared.Infrastructure.ClosedXML | ||
{ | ||
public class WorksheetManager : IWorksheetManager | ||
{ | ||
public void SetRowsHeight(IXLRows rows, float height) | ||
{ | ||
rows.Height = height; | ||
} | ||
|
||
public void SetColumnsWidth(IXLColumns columns, float width) | ||
{ | ||
columns.Width = width; | ||
} | ||
|
||
public void SetCommonRangeStyles(IXLRange range) | ||
{ | ||
range.Style.Border.OutsideBorder = XLBorderStyleValues.Hair; | ||
range.Style.Border.InsideBorder = XLBorderStyleValues.Hair; | ||
range.Style.Font.FontSize = 12; | ||
range.Style.Font.FontName = "Arial"; | ||
SetRangeFontBold(range, true); | ||
range.Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; | ||
range.Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; | ||
} | ||
|
||
public void MergeRange(IXLRange range) | ||
{ | ||
range.Merge(); | ||
} | ||
|
||
public void MergeRangeAndSetValue<T>(IXLRange range, T value) | ||
{ | ||
MergeRange(range); | ||
range.Value = value; | ||
} | ||
|
||
public void SetRangeFontBold(IXLRange range, bool bold) | ||
{ | ||
range.Style.Font.Bold = bold; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters