2024-05-26 00:28:11 +04:00

151 lines
6.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using BankContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UniversityBusinessLogics.OfficePackage.HelperEnums;
using UniversityBusinessLogics.OfficePackage.HelperModels.Pdf;
using UniversityContracts.ViewModels;
namespace UniversityBusinessLogics.OfficePackage
{
public abstract class AbstractSaveToPdf
{
public void CreateDocForPayments(PdfInfo 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> { "3cm", "6cm", "3cm", "3cm", "3cm", });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Сделка", "Операция", "Дата", "Оплаченная стоимость", "Полная стоимость" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
var sumPaidPrice = 0.0;
foreach (var pc in info.ReportObjects)
{
if (pc is not PaymentViewModel payment)
{
throw new ArgumentException($"Передан некорректный тип в отчет: " +
$"ожидается Payment; Получен объект типа: {pc.GetType()}", nameof(info));
}
if (payment.Operation == null || payment.ClassByPurchase == null)
{
throw new ArgumentNullException($"Получена модель оплаты c нулевыми полями");
}
sumPaidPrice += payment.PaidPrice;
CreateRow(new PdfRowParameters
{
Texts = new List<string>
{
payment.ClassByPurchase.PurchaseId.ToString(),
payment.Operation.Time + " " + payment.Operation.Name,
payment.Date.ToShortDateString(),
payment.PaidPrice.ToString(),
payment.FullPrice.ToString(),
},
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
CreateParagraph(new PdfParagraph { Text = $"Итого оплачено : {sumPaidPrice}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Rigth });
SavePdf(info);
}
public void CreateDocForPurchases(PdfInfo 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> { "4cm", "5cm", "5cm", "3cm", });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Дата получения", "Сделка", "Статья затрат", "Сумма затраты" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var pc in info.ReportObjects)
{
if (pc is not PurchaseViewModel purchase)
{
throw new ArgumentException($"Передан некорректный тип в отчет: " +
$"ожидается Purchase; Получен объект типа: {pc.GetType()}", nameof(info));
}
if (purchase.CostViewModels == null)
{
throw new ArgumentNullException($"Получена модель статьи затрат c нулевыми полями");
}
foreach (var cost in purchase.CostViewModels)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string>
{
purchase.DatePurchase.ToShortDateString(),
purchase.Id.ToString(),
cost.NameOfCost,
(cost.Price* cost.PurchaseModels[purchase.Id].Count).ToString(),
},
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
}
SavePdf(info);
}
/// <summary>
/// Создание doc-файла
/// </summary>
/// <param name="info"></param>
protected abstract void CreatePdf(PdfInfo info);
/// <summary>
/// Создание параграфа с текстом
/// </summary>
/// <param name="title"></param>
/// <param name="style"></param>
protected abstract void CreateParagraph(PdfParagraph paragraph);
/// <summary>
/// Создание таблицы
/// </summary>
/// <param name="title"></param>
/// <param name="style"></param>
protected abstract void CreateTable(List<string> columns);
/// <summary>
/// Создание и заполнение строки
/// </summary>
/// <param name="rowParameters"></param>
protected abstract void CreateRow(PdfRowParameters rowParameters);
/// <summary>
/// Сохранение файла
/// </summary>
/// <param name="info"></param>
protected abstract void SavePdf(PdfInfo info);
}
}