kreta/Kreta.BusinessLogic/Helpers/AsposeHelperMulasztasiErtesitokNkt.cs
2024-03-13 00:33:46 +01:00

156 lines
10 KiB
C#

using System.IO;
using Aspose.Words;
using Aspose.Words.Tables;
using Kreta.BusinessLogic.Classes.AsposeHelpers;
using Kreta.BusinessLogic.HelperClasses.MulasztasiErtesitokCOs;
using Kreta.BusinessLogic.Utils;
using Kreta.Core;
using Kreta.Enums.ManualEnums;
namespace Kreta.BusinessLogic.Helpers
{
public partial class AsposeHelper
{
public MemoryStream GetErtesitesTanuloAlapon(Stream sablonStream, int formatumId)
{
var resultDoc = new Document();
var mulasztasiErtesitoCo = new MulasztasiErtesitoCo(_ds, options.DocumentParameters);
foreach (var item in mulasztasiErtesitoCo.TanuloMulasztasErtesitoDictionary)
{
var doc = new Document(sablonStream, new LoadOptions());
doc.Styles.DefaultFont.Name = "Times New Roman";
ErtesitesTanuloAlaponEgyszeruHelyettesitesek(item.Value, doc, options);
if (options.MulasztasErtesitoNktGondviseloTableIndex.HasValue)
{
var table = (Table)doc.GetChild(NodeType.Table, options.MulasztasErtesitoNktGondviseloTableIndex.Value, true);
ErtesitesGondviseloHozzaadas(table, item.Value);
}
if (options.MulasztasErtesitoNktMulasztasTableIndex.HasValue)
{
var mulasztasTable = (Table)doc.GetChild(NodeType.Table, options.MulasztasErtesitoNktMulasztasTableIndex.Value, true);
ErtesitesMulasztasSorokHozzadas(item.Value, doc, mulasztasTable);
}
resultDoc.AppendDocument(doc, ImportFormatMode.KeepSourceFormatting);
}
resultDoc.Sections.RemoveAt(0);
SetCustomHeaderOnDocument(resultDoc, options.EgyediFejlec);
var ms = new MemoryStream();
resultDoc.Save(ms, formatumId == (int)NyomtatvanyFormatumEnum.Word ? SaveFormat.Docx : SaveFormat.Pdf);
ms.Position = 0;
return ms;
}
public MemoryStream GetErtesitesGondviseloAlapon(Stream sablonStream, int formatumId)
{
var resultDoc = new Document();
var mulasztasiErtesitoCo = new MulasztasiErtesitoCo(_ds, options.DocumentParameters);
foreach (var item in mulasztasiErtesitoCo.TanuloMulasztasErtesitoDictionary)
{
foreach (var gondviseloCo in item.Value.GondviseloAdatokList)
{
var doc = new Document(sablonStream, new LoadOptions());
doc.Styles.DefaultFont.Name = "Times New Roman";
ErtesitesGondviseloAlaponEgyszeruHelyettesitesek(gondviseloCo, item.Value, doc, options);
resultDoc.AppendDocument(doc, ImportFormatMode.KeepSourceFormatting);
}
}
resultDoc.Sections.RemoveAt(0);
SetCustomHeaderOnDocument(resultDoc, options.EgyediFejlec);
var ms = new MemoryStream();
resultDoc.Save(ms, formatumId == (int)NyomtatvanyFormatumEnum.Word ? SaveFormat.Docx : SaveFormat.Pdf);
ms.Position = 0;
return ms;
}
private static void ErtesitesTanuloAlaponEgyszeruHelyettesitesek(TanuloMulasztasErtesitoCo co, Document doc, AsposeHelperOptions options)
{
Story body = doc.FirstSection.Body;
body.Range.Replace(MulasztasiErtesitokReplacers.TanuloNeveRegex, co.MulasztasFej.TanuloNeve, MulasztasiErtesitokReplacers.FindReplaceoptions);
body.Range.Replace(MulasztasiErtesitokReplacers.IntezmenyNeveRegex, co.MulasztasFej.IntezmenyNeve, MulasztasiErtesitokReplacers.FindReplaceoptions);
body.Range.Replace(MulasztasiErtesitokReplacers.IntezmenyCimeRegex, co.MulasztasFej.IntezmenyCime, MulasztasiErtesitokReplacers.FindReplaceoptions);
body.Range.Replace(MulasztasiErtesitokReplacers.TagintezmenyNeveRegex, options.DocumentParameters.IsTagintezmenyAdatokMegjelenjen ? options.DocumentParameters.TagintezmenyNeve : string.Empty, MulasztasiErtesitokReplacers.FindReplaceoptions);
body.Range.Replace(MulasztasiErtesitokReplacers.TagintezmenyCimeRegex, options.DocumentParameters.IsTagintezmenyAdatokMegjelenjen ? options.DocumentParameters.TagintezmenyCime : string.Empty, MulasztasiErtesitokReplacers.FindReplaceoptions);
body.Range.Replace(MulasztasiErtesitokReplacers.OsztalyNeveRegex, co.MulasztasFej.OsztalyCsoportNeve, MulasztasiErtesitokReplacers.FindReplaceoptions);
body.Range.Replace(MulasztasiErtesitokReplacers.AnyjaNeveRegex, co.MulasztasFej.AnyjaNeve, MulasztasiErtesitokReplacers.FindReplaceoptions);
body.Range.Replace(MulasztasiErtesitokReplacers.SzuletesiHelyRegex, co.MulasztasFej.SzuletesiHely, MulasztasiErtesitokReplacers.FindReplaceoptions);
body.Range.Replace(MulasztasiErtesitokReplacers.SzuletesiIdoRegex, co.MulasztasFej.SzuletesiIdo.ToString(Constants.ToStringPattern.HungarianDate), MulasztasiErtesitokReplacers.FindReplaceoptions);
body.Range.Replace(MulasztasiErtesitokReplacers.LakohelyCimeRegex, co.MulasztasFej.TanuloAllandoCim, MulasztasiErtesitokReplacers.FindReplaceoptions);
body.Range.Replace(MulasztasiErtesitokReplacers.TartozkodasiCimeRegex, co.MulasztasFej.TanuloTartozkodasiCim ?? string.Empty, MulasztasiErtesitokReplacers.FindReplaceoptions);
body.Range.Replace(MulasztasiErtesitokReplacers.OsztalyfonokNeveRegex, co.MulasztasFej.OsztalyfonokNeve, MulasztasiErtesitokReplacers.FindReplaceoptions);
body.Range.Replace(MulasztasiErtesitokReplacers.IgazoltMulasztasokSzamaRegex, co.MulasztasFej.Igazolt.ToString(), MulasztasiErtesitokReplacers.FindReplaceoptions);
body.Range.Replace(MulasztasiErtesitokReplacers.IgazolatlanMulasztasokSzamaRegex, co.MulasztasFej.Igazolatlan.ToString(), MulasztasiErtesitokReplacers.FindReplaceoptions);
body.Range.Replace(MulasztasiErtesitokReplacers.IgazoltHozottMulasztasokSzamaRegex, co.MulasztasFej.HozottIgazolt.ToString(), MulasztasiErtesitokReplacers.FindReplaceoptions);
body.Range.Replace(MulasztasiErtesitokReplacers.IgazolatlanHozottMulasztasokSzamaRegex, co.MulasztasFej.HozottIgazolatlan.ToString(), MulasztasiErtesitokReplacers.FindReplaceoptions);
body.Range.Replace(MulasztasiErtesitokReplacers.KeltezesVarosRegex, !options.DocumentParameters.IsTagintezmenyAdatokMegjelenjen ? co.MulasztasFej.IntezmenyVarosNeve : options.DocumentParameters.TagintezmenyVaros, MulasztasiErtesitokReplacers.FindReplaceoptions);
body.Range.Replace(MulasztasiErtesitokReplacers.KeltezesDatumRegex, options.DocumentParameters.Kelt.ToString(options.DocumentParameters.KeltFormatum == KeltFormatumTipusEnum.Szammal ? Constants.ToStringPattern.HungarianDateWithSpaces : Constants.ToStringPattern.HungarianLongDate));
body.Range.Replace(MulasztasiErtesitokReplacers.IntezmenyVezetoNeveRegex, options.DocumentParameters.AlairoSzemely["Nev"], MulasztasiErtesitokReplacers.FindReplaceoptions);
body.Range.Replace(MulasztasiErtesitokReplacers.IntezmenyVezetoRegex, options.DocumentParameters.AlairoSzemely["Beosztas"], MulasztasiErtesitokReplacers.FindReplaceoptions);
body.Range.Replace(MulasztasiErtesitokReplacers.TanevNeveRegex, co.MulasztasFej.TanevNeve, MulasztasiErtesitokReplacers.FindReplaceoptions);
body.Range.Replace(MulasztasiErtesitokReplacers.OsszesMulasztasSzamaRegex, co.MulasztasFej.OsszesMulasztas.ToString(), MulasztasiErtesitokReplacers.FindReplaceoptions);
}
private static void ErtesitesGondviseloAlaponEgyszeruHelyettesitesek(GondviseloAdatokCo gondviseloCo, TanuloMulasztasErtesitoCo co, Document doc, AsposeHelperOptions options)
{
ErtesitesTanuloAlaponEgyszeruHelyettesitesek(co, doc, options);
Story body = doc.FirstSection.Body;
body.Range.Replace(MulasztasiErtesitokReplacers.GondviseloNeveRegex, gondviseloCo.GondviseloNeve, MulasztasiErtesitokReplacers.FindReplaceoptions);
body.Range.Replace(MulasztasiErtesitokReplacers.GondviseloLakohelyeRegex, gondviseloCo.GondviseloAllandoCim ?? string.Empty, MulasztasiErtesitokReplacers.FindReplaceoptions);
}
private static void ErtesitesMulasztasSorokHozzadas(TanuloMulasztasErtesitoCo item, Document doc, Table mulasztasTable)
{
var mulasztasSor = mulasztasTable.LastRow.Clone(true);
if (item.MulasztasAdatList.Count > 0)
{
mulasztasTable.LastRow.Remove();
}
for (var i = 0; i < item.MulasztasAdatList.Count; i++)
{
var mulasztas = item.MulasztasAdatList[i];
var cloned = (Row)mulasztasSor.Clone(true);
cloned.Cells[0].FirstParagraph.Runs.Add(new Run(doc, (i + 1).ToString()));
cloned.Cells[1].FirstParagraph.Runs.Add(new Run(doc, mulasztas.Datum.ToString(Constants.ToStringPattern.HungarianDate)));
cloned.Cells[2].FirstParagraph.Runs.Add(new Run(doc, mulasztas.Oraszam));
cloned.Cells[3].FirstParagraph.Runs.Add(new Run(doc, mulasztas.Tipusa));
cloned.Cells[4].FirstParagraph.Runs.Add(new Run(doc, mulasztas.KesesPercben.ToString()));
cloned.Cells[5].FirstParagraph.Runs.Add(new Run(doc, mulasztas.OsztalyCsoportNeve));
cloned.Cells[6].FirstParagraph.Runs.Add(new Run(doc, mulasztas.TantargyNeve));
mulasztasTable.AppendChild(cloned);
}
}
private static void ErtesitesGondviseloHozzaadas(Table table, TanuloMulasztasErtesitoCo co)
{
var gondviseloSor = table.Rows[1].Clone(true);
table.LastRow.Remove();
foreach (var gondviselo in co.GondviseloAdatokList)
{
var cloned = gondviseloSor.Clone(true);
cloned.Range.Replace(MulasztasiErtesitokReplacers.GondviseloNeveRegex, gondviselo.GondviseloNeve, MulasztasiErtesitokReplacers.FindReplaceoptions);
cloned.Range.Replace(MulasztasiErtesitokReplacers.GondviseloLakohelyeRegex, gondviselo.GondviseloAllandoCim ?? string.Empty, MulasztasiErtesitokReplacers.FindReplaceoptions);
cloned.Range.Replace(MulasztasiErtesitokReplacers.GondviseloTelefonszamaRegex, gondviselo.GondviseloTelefon ?? string.Empty, MulasztasiErtesitokReplacers.FindReplaceoptions);
table.AppendChild(cloned);
}
}
}
}