75 lines
2.7 KiB
C#
75 lines
2.7 KiB
C#
|
using PdfSharp.Pdf;
|
|||
|
using ServiceSourceBusinessLogic.OfficePackage.HelperEnums;
|
|||
|
using ServiceSourceBusinessLogic.OfficePackage.HelperModels;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace ServiceSourceBusinessLogic.OfficePackage {
|
|||
|
public abstract class AbstractSaveToPdf {
|
|||
|
|
|||
|
public PdfDocument CreateDoc (PdfInfo info) {
|
|||
|
CreatePdf(info);
|
|||
|
|
|||
|
CreateParagraph(new PdfParagraph {
|
|||
|
Text = info.Title,
|
|||
|
Style = "NormalTitle",
|
|||
|
alignmentType = PdfParagraphAlignmentType.Center,
|
|||
|
});
|
|||
|
|
|||
|
CreateParagraph(new PdfParagraph {
|
|||
|
Text = $"С {info.Date_From} по {info.Date_To}",
|
|||
|
Style = "Normal",
|
|||
|
alignmentType = PdfParagraphAlignmentType.Right,
|
|||
|
});
|
|||
|
|
|||
|
CreateTable(new List<string> { "3cm", "4cm", "3cm", "2cm", "4cm" });
|
|||
|
|
|||
|
CreateRow(new PdfRowParameters {
|
|||
|
Text = new List<string> { "Номер работы", "Дата работы", "Стоимость", "Номер задачи", "Название задачи" },
|
|||
|
Style = "NormalTittle",
|
|||
|
alignmentType = PdfParagraphAlignmentType.Left,
|
|||
|
});
|
|||
|
|
|||
|
foreach (var rec in info.WorkTask) {
|
|||
|
CreateRow(new PdfRowParameters {
|
|||
|
Text = new List<string> {
|
|||
|
rec.work_id.ToString(),
|
|||
|
rec.work_date,
|
|||
|
rec.work_price.ToString(),
|
|||
|
rec.task_id.ToString(),
|
|||
|
rec.task_name.ToString()
|
|||
|
},
|
|||
|
Style = "Normal",
|
|||
|
alignmentType = PdfParagraphAlignmentType.Left,
|
|||
|
});
|
|||
|
}
|
|||
|
CreateParagraph(new PdfParagraph {
|
|||
|
Text = $"Итого: {info.TotalCount}",
|
|||
|
Style = "Normal",
|
|||
|
alignmentType = PdfParagraphAlignmentType.Right,
|
|||
|
});
|
|||
|
|
|||
|
var document = SavePdf(info);
|
|||
|
return document;
|
|||
|
}
|
|||
|
|
|||
|
// Создание документа
|
|||
|
protected abstract void CreatePdf(PdfInfo info);
|
|||
|
|
|||
|
// Создание параграфа с текстом
|
|||
|
protected abstract void CreateParagraph(PdfParagraph paragraph);
|
|||
|
|
|||
|
// Создание таблицы
|
|||
|
protected abstract void CreateTable(List<string> columns);
|
|||
|
|
|||
|
// Создание и заполнение строки
|
|||
|
protected abstract void CreateRow(PdfRowParameters rowParameters);
|
|||
|
|
|||
|
// Сохранение файла
|
|||
|
protected abstract PdfDocument SavePdf(PdfInfo info);
|
|||
|
}
|
|||
|
}
|