Word, excel, pdf report logic

This commit is contained in:
ShabOl 2024-05-29 13:30:31 +04:00
parent 045fd7a8e3
commit 86af9b1e5a
13 changed files with 863 additions and 3 deletions

View File

@ -0,0 +1,137 @@
using ComputerShopBusinessLogic.OfficePackage.HelperModels;
using GarmentFactoryBusinessLogic.OfficePackage.HelperEnums;
using GarmentFactoryBusinessLogic.OfficePackage.HelperModels;
namespace ComputerShopBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToExcelGuarantor
{
public void CreateReport(ExcelInfoGuarantor Info)
{
CreateExcel(Info);
//!!!2 абзаца ниже - настройка заголовков, исправить скорее всего
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = 1,
Text = Info.Title1,
StyleInfo = ExcelStyleInfoType.Title
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = 1,
Text = Info.Title2,
StyleInfo = ExcelStyleInfoType.Title
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = 1,
Text = Info.Title3,
StyleInfo = ExcelStyleInfoType.Title
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "D",
RowIndex = 1,
Text = Info.Title4,
StyleInfo = ExcelStyleInfoType.Title
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "E",
RowIndex = 1,
Text = Info.Title5,
StyleInfo = ExcelStyleInfoType.Title
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "F",
RowIndex = 1,
Text = Info.Title6,
StyleInfo = ExcelStyleInfoType.Title
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "G",
RowIndex = 1,
Text = Info.Title7,
StyleInfo = ExcelStyleInfoType.Title
});
uint RowIndex = 2;
foreach (var ComponentWithShipments in Info.ShipmentComponents)
{
int ShipmentsNum = ComponentWithShipments.Shipments.Count;
int ShipmentIndex = 0;
foreach (var Shipment in ComponentWithShipments.Shipments)
{
if (!string.IsNullOrEmpty(Shipment.ProviderName))
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = RowIndex,
Text = ComponentWithShipments.ComponentId.ToString(),
StyleInfo = ExcelStyleInfoType.Text
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = RowIndex,
Text = ComponentWithShipments.ComponentName,
StyleInfo = ExcelStyleInfoType.Text
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = RowIndex,
Text = ComponentWithShipments.ComponentCost.ToString(),
StyleInfo = ExcelStyleInfoType.Text
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "D",
RowIndex = RowIndex,
Text = Shipment.ProviderName,
StyleInfo = ExcelStyleInfoType.Text
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "E",
RowIndex = RowIndex,
Text = Shipment.ShipmentDate.ToShortDateString(),
StyleInfo = ExcelStyleInfoType.Text
});
}
ShipmentIndex++;
if (ShipmentIndex < ShipmentsNum && !string.IsNullOrEmpty(Shipment.ProviderName))
{
RowIndex++;
}
}
RowIndex++;
}
SaveExcel(Info);
}
protected abstract void CreateExcel(DocumentInfo Info);
protected abstract void InsertCellInWorksheet(ExcelCellParameters ExcelParams);
protected abstract void MergeCells(ExcelMergeParameters ExcelParams);
protected abstract void SaveExcel(DocumentInfo Info);
}
}

View File

@ -0,0 +1,58 @@
using ComputerShopBusinessLogic.OfficePackage.HelperModels;
using GarmentFactoryBusinessLogic.OfficePackage.HelperEnums;
using GarmentFactoryBusinessLogic.OfficePackage.HelperModels;
namespace ComputerShopBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToPdfGuarantor
{
public void CreateDoc(PdfInfoGuarantor 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<string> { "2cm", "2.5cm", "2cm", "2cm", "2cm", "4cm", "2.5cm", "3.5cm", "3.5cm", "2.5cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "ID комплектующей", "Название", "Стоимость", "ID сборки", "Название сборки", "Цена сборки", "Категория", "ID заявки", "Дата заявки", "Клиент" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var ComponentByDate in Info.ComponentsByDate)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string>
{
ComponentByDate.ComponentId.ToString(),
ComponentByDate.ComponentName,
ComponentByDate.ComponentCost.ToString(),
ComponentByDate.AssemblyId.ToString(),
ComponentByDate.AssemblyName,
ComponentByDate.AssemblyPrice.ToString(),
ComponentByDate.AssemblyCategory,
ComponentByDate.RequestId.ToString(),
ComponentByDate.DateRequest.ToShortDateString(),
ComponentByDate.ClientFIO,
},
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
SavePdf(Info);
}
protected abstract void CreatePdf(DocumentInfo Info);
protected abstract void CreateParagraph(PdfParagraph Paragraph);
protected abstract void CreateTable(List<string> Columns);
protected abstract void CreateRow(PdfRowParameters RowParameters);
protected abstract void SavePdf(DocumentInfo Info);
}
}

View File

@ -0,0 +1,83 @@
using ComputerShopBusinessLogic.OfficePackage.HelperModels;
using GarmentFactoryBusinessLogic.OfficePackage.HelperEnums;
using GarmentFactoryBusinessLogic.OfficePackage.HelperModels;
namespace ComputerShopBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToWordGuarantor
{
public void CreateDoc(WordInfoGuarantor 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 ComponentWithShipments in Info.ShipmentComponents)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{
("Комплектующая №" + ComponentWithShipments.ComponentId.ToString() + " - " +
ComponentWithShipments.ComponentName.ToString() + " - " +
ComponentWithShipments.ComponentCost.ToString() + " - ", new WordTextProperties {Size = "24", Bold=true})
},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
foreach (var Shipment in ComponentWithShipments.Shipments)
{
if (!string.IsNullOrEmpty(Shipment.ProviderName))
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> {
(Shipment.ProviderName + " - ", new WordTextProperties { Size = "24" }),
(Shipment.ShipmentDate.ToShortDateString() + " - ", new WordTextProperties { Size = "24" })
},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
}
}
}
SaveWord(Info);
}
/// <summary>
/// Создание doc-файла
/// </summary>
/// <param name="info"></param>
protected abstract void CreateWord(DocumentInfo Info);
/// <summary>
/// Создание абзаца с текстом
/// </summary>
/// <param name="paragraph"></param>
/// <returns></returns>
protected abstract void CreateParagraph(WordParagraph paragraph);
/// <summary>
/// Сохранение файла
/// </summary>
/// <param name="info"></param>
protected abstract void SaveWord(DocumentInfo Info);
}
}

View File

@ -0,0 +1,23 @@
using ComputerShopContracts.ViewModels;
namespace ComputerShopBusinessLogic.OfficePackage.HelperModels
{
public class ExcelInfoGuarantor : DocumentInfo
{
public string Title1 { get; set; } = "ID заказа";
public string Title2 { get; set; } = "Дата заказа";
public string Title3 { get; set; } = "Стоимость заказа";
public string Title4 { get; set; } = "Статус заказа";
public string Title5 { get; set; } = "Название сборки";
public string Title6 { get; set; } = "Категория сборки";
public string Title7 { get; set; } = "Цена сборки";
public List<ReportComponentWithShipmentViewModel> ShipmentComponents { get; set; } = new();
}
}

View File

@ -0,0 +1,9 @@
namespace ComputerShopBusinessLogic.OfficePackage.HelperModels
{
public class DocumentInfo
{
public string Filename { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,13 @@
using ComputerShopContracts.ViewModels;
namespace ComputerShopBusinessLogic.OfficePackage.HelperModels
{
public class PdfInfoGuarantor : DocumentInfo
{
public DateTime DateFrom { get; set; }
public DateTime DateTo { get; set; }
public List<ReportComponentByDateViewModel> ComponentsByDate { get; set; } = new();
}
}

View File

@ -0,0 +1,9 @@
using ComputerShopContracts.ViewModels;
namespace ComputerShopBusinessLogic.OfficePackage.HelperModels
{
public class WordInfoGuarantor : DocumentInfo
{
public List<ReportComponentWithShipmentViewModel> ShipmentComponents { get; set; } = new();
}
}

View File

@ -0,0 +1,292 @@
using ComputerShopBusinessLogic.OfficePackage.HelperModels;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Office2010.Excel;
using DocumentFormat.OpenXml.Office2013.Excel;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using GarmentFactoryBusinessLogic.OfficePackage.HelperEnums;
using GarmentFactoryBusinessLogic.OfficePackage.HelperModels;
namespace ComputerShopBusinessLogic.OfficePackage.Implements
{
public class SaveToExcelGuarantor : AbstractSaveToExcelGuarantor
{
private SpreadsheetDocument? _spreadsheetDocument;
private SharedStringTablePart? _shareStringPart;
private Worksheet? _worksheet;
private static void CreateStyles(WorkbookPart workbookpart)
{
var sp = workbookpart.AddNewPart<WorkbookStylesPart>();
sp.Stylesheet = new Stylesheet();
var fonts = new Fonts() { Count = 2U, KnownFonts = true };
// Создание шрифтов для основного текста и заголовка (в ячейке A1)
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);
// Создание 3 стилей ячеек
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(DocumentInfo 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>();
if (_shareStringPart.SharedStringTable == null)
{
_shareStringPart.SharedStringTable = new SharedStringTable();
}
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet(new SheetData());
Columns lstColumns = worksheetPart.Worksheet.GetFirstChild<Columns>();
if (lstColumns == null)
{
lstColumns = new Columns();
}
lstColumns.Append(new Column() { Min = 1, Max = 1, Width = 10, CustomWidth = true });
lstColumns.Append(new Column() { Min = 2, Max = 2, Width = 10, CustomWidth = true });
lstColumns.Append(new Column() { Min = 3, Max = 3, Width = 20, CustomWidth = true });
lstColumns.Append(new Column() { Min = 4, Max = 4, Width = 10, CustomWidth = true });
lstColumns.Append(new Column() { Min = 5, Max = 5, Width = 20, CustomWidth = true });
lstColumns.Append(new Column() { Min = 6, Max = 6, Width = 20, CustomWidth = true });
lstColumns.Append(new Column() { Min = 7, Max = 7, Width = 20, CustomWidth = true });
worksheetPart.Worksheet.InsertAt(lstColumns, 0);
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<SheetData>();
if (sheetData == null)
{
return;
}
Row row;
if (sheetData.Elements<Row>().Where(r => r.RowIndex! == ExcelParams.RowIndex).Any())
{
row = sheetData.Elements<Row>().Where(r => r.RowIndex! == ExcelParams.RowIndex).First();
}
else
{
row = new Row() { RowIndex = ExcelParams.RowIndex };
sheetData.Append(row);
}
Cell cell;
if (row.Elements<Cell>().Where(c => c.CellReference!.Value == ExcelParams.CellReference).Any())
{
cell = row.Elements<Cell>().Where(c => c.CellReference!.Value == ExcelParams.CellReference).First();
}
else
{
Cell? refCell = null;
foreach (Cell rowCell in row.Elements<Cell>())
{
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<SharedStringItem>().Count() - 1).ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
cell.StyleIndex = GetStyleValue(ExcelParams.StyleInfo);
}
protected override void MergeCells(ExcelMergeParameters ExcelParams)
{
if (_worksheet == null)
{
return;
}
MergeCells MergeCells;
if (_worksheet.Elements<MergeCells>().Any())
{
MergeCells = _worksheet.Elements<MergeCells>().First();
}
else
{
MergeCells = new MergeCells();
if (_worksheet.Elements<CustomSheetView>().Any())
{
_worksheet.InsertAfter(MergeCells, _worksheet.Elements<CustomSheetView>().First());
}
else
{
_worksheet.InsertAfter(MergeCells, _worksheet.Elements<SheetData>().First());
}
}
var MergeCell = new MergeCell()
{
Reference = new StringValue(ExcelParams.Merge)
};
MergeCells.Append(MergeCell);
}
protected override void SaveExcel(DocumentInfo Info)
{
if (_spreadsheetDocument == null)
{
return;
}
_spreadsheetDocument.WorkbookPart!.Workbook.Save();
_spreadsheetDocument.Close();
}
}
}

View File

@ -0,0 +1,109 @@
using ComputerShopBusinessLogic.OfficePackage.HelperModels;
using GarmentFactoryBusinessLogic.OfficePackage.HelperEnums;
using GarmentFactoryBusinessLogic.OfficePackage.HelperModels;
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Tables;
using MigraDoc.Rendering;
namespace ComputerShopBusinessLogic.OfficePackage.Implements
{
public class SaveToPdfGuarantor : AbstractSaveToPdfGuarantor
{
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.Rigth => 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(HelperModels.DocumentInfo 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<string> 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(HelperModels.DocumentInfo Info)
{
var Renderer = new PdfDocumentRenderer(true)
{
Document = _document
};
Renderer.RenderDocument();
Renderer.PdfDocument.Save(Info.Filename);
}
}
}

View File

@ -0,0 +1,122 @@
using ComputerShopBusinessLogic.OfficePackage.HelperModels;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
using GarmentFactoryBusinessLogic.OfficePackage.HelperEnums;
using GarmentFactoryBusinessLogic.OfficePackage.HelperModels;
namespace ComputerShopBusinessLogic.OfficePackage.Implements
{
public class SaveToWordGuarantor : AbstractSaveToWordGuarantor
{
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,
};
}
/// <summary>
/// Настройки страницы
/// </summary>
/// <returns></returns>
private static SectionProperties CreateSectionProperties()
{
var Properties = new SectionProperties();
var PageSize = new PageSize
{
Orient = PageOrientationValues.Portrait
};
Properties.AppendChild(PageSize);
return Properties;
}
/// <summary>
/// Задание форматирования для абзаца
/// </summary>
/// <param name="ParagraphProperties"></param>
/// <returns></returns>
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(DocumentInfo 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);
}
protected override void SaveWord(DocumentInfo Info)
{
if (_docBody == null || _wordDocument == null)
{
return;
}
_docBody.AppendChild(CreateSectionProperties());
_wordDocument.MainDocumentPart!.Document.Save();
_wordDocument.Close();
}
}
}

View File

@ -8,6 +8,6 @@
public double ComponentCost { get; set; } public double ComponentCost { get; set; }
public List<(int Count, string ProductName, double ProductPrice, string ProviderName, DateTime ShipmentDate)> Shipments { get; set; } = new(); public List<(string ProductName, double ProductPrice, string ProviderName, DateTime ShipmentDate)> Shipments { get; set; } = new();
} }
} }

View File

@ -265,6 +265,11 @@ namespace ComputerShopGuarantorApp.Controllers
Response.Redirect("../Products"); Response.Redirect("../Products");
} }
/*------------------------------------------------------
* Отчеты
*-----------------------------------------------------*/
// ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ // ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ ОСТАЛЬНОЕ

View File

@ -3,6 +3,6 @@
} }
<div class="text-center"> <div class="text-center">
<h1 class="display-4">Welcome</h1> <h1 class="display-4">Добро пожаловать в приложение поручителя магазина "Ты ж программист"</h1>
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p> <p>Выберите страницу из верхнего меню</p>
</div> </div>