WORD -> PDF
This commit is contained in:
@@ -292,5 +292,27 @@ namespace WorkFlowCheck.API.Controllers
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("GetAllRoleCheckListTemplateHeaders")]
|
||||
public async Task<ApiResponseDTO<List<RoleCheckListTemplateHeaderDTO>>> GetAllRoleCheckListTemplateHeaders()
|
||||
{
|
||||
var retVal = new ApiResponseDTO<List<RoleCheckListTemplateHeaderDTO>>()
|
||||
{
|
||||
IsSuccess = true,
|
||||
};
|
||||
var results = await _userService.GetAllRoleCheckListTemplateHeadersAsync();
|
||||
|
||||
if (results != null)
|
||||
{
|
||||
retVal.IsSuccess = true;
|
||||
retVal.Data = results;
|
||||
}
|
||||
else
|
||||
{
|
||||
retVal.IsSuccess = false;
|
||||
retVal.Errors.Add("No data!");
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
using Aspose.Words;
|
||||
using Aspose.Words.Tables;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WorkFlowCheck.BL.DocumentGenerator
|
||||
{
|
||||
public class DokumentumGenerator
|
||||
{
|
||||
static DokumentumGenerator()
|
||||
{
|
||||
Aspose.Words.License license = new Aspose.Words.License();
|
||||
|
||||
try
|
||||
{
|
||||
license.SetLicense("Aspose.Words.lic");
|
||||
Log.Information("License set successfully.");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e, "\nThere was an error setting the license: " + e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] HtmlToDocx(string html)
|
||||
{
|
||||
byte[] generated = Encoding.UTF8.GetBytes(html);
|
||||
var docHTML = new Aspose.Words.Document();
|
||||
|
||||
Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(docHTML);
|
||||
builder.InsertHtml(html);
|
||||
|
||||
docHTML.CompatibilityOptions.OptimizeFor(Aspose.Words.Settings.MsWordVersion.Word2016);
|
||||
|
||||
MemoryStream outStream = new MemoryStream();
|
||||
docHTML.Save(outStream, Aspose.Words.SaveFormat.Docx);
|
||||
|
||||
generated = outStream.ToArray();
|
||||
|
||||
outStream.Dispose();
|
||||
|
||||
return generated;
|
||||
}
|
||||
|
||||
public static byte[] HtmlToPdf(string html)
|
||||
{
|
||||
byte[] generated = Encoding.UTF8.GetBytes(html);
|
||||
|
||||
Stream inStream = new MemoryStream(generated);
|
||||
var docHTML = new Aspose.Words.Document(inStream);
|
||||
MemoryStream outStream = new MemoryStream();
|
||||
docHTML.Save(outStream, Aspose.Words.SaveFormat.Pdf);
|
||||
|
||||
generated = outStream.ToArray();
|
||||
|
||||
inStream.Dispose();
|
||||
outStream.Dispose();
|
||||
|
||||
return generated;
|
||||
}
|
||||
|
||||
public static byte[] DocxToPdf(byte[] generated)
|
||||
{
|
||||
Stream inStream = new MemoryStream(generated);
|
||||
var doc = new Aspose.Words.Document(inStream);
|
||||
MemoryStream outStream = new MemoryStream();
|
||||
doc.Save(outStream, Aspose.Words.SaveFormat.Pdf);
|
||||
|
||||
generated = outStream.ToArray();
|
||||
|
||||
inStream.Dispose();
|
||||
outStream.Dispose();
|
||||
|
||||
return generated;
|
||||
}
|
||||
|
||||
public static byte[] DocxToPdfForTopic(byte[] generated)
|
||||
{
|
||||
Stream inStream = new MemoryStream(generated);
|
||||
var doc = new Aspose.Words.Document(inStream);
|
||||
|
||||
doc.Styles.DefaultFont.Name = "Times New Roman";
|
||||
doc.Styles.DefaultFont.Size = 12;
|
||||
|
||||
var collection = doc.GetChildNodes(NodeType.Row, true);
|
||||
|
||||
foreach (Row row in collection)
|
||||
{
|
||||
row.RowFormat.Height = 40;
|
||||
row.RowFormat.HeightRule = HeightRule.AtLeast;
|
||||
}
|
||||
|
||||
MemoryStream outStream = new MemoryStream();
|
||||
doc.Save(outStream, Aspose.Words.SaveFormat.Pdf);
|
||||
|
||||
generated = outStream.ToArray();
|
||||
|
||||
inStream.Dispose();
|
||||
outStream.Dispose();
|
||||
|
||||
return generated;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,499 @@
|
||||
using DocumentFormat.OpenXml;
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace WorkFlowCheck.BL.DocumentGenerator
|
||||
{
|
||||
public class SablonGenerator : IDisposable
|
||||
{
|
||||
private readonly List<OpenXmlElement> _currentRoot;
|
||||
|
||||
private MemoryStream Mem { get; }
|
||||
private WordprocessingDocument Doc { get; set; }
|
||||
|
||||
private List<OpenXmlElement> CurrentRoot => Repeater?.SablonRoot ?? _currentRoot;
|
||||
|
||||
private SubSablon Repeater { get; set; }
|
||||
|
||||
protected class SubSablon : IDisposable
|
||||
{
|
||||
private List<OpenXmlElement> SablonRootBase { get; set; }
|
||||
protected internal List<OpenXmlElement> SablonRoot { get; private set; }
|
||||
public BookmarkStart BookmarkStart { get; }
|
||||
public BookmarkEnd BookmarkEnd { get; }
|
||||
|
||||
protected internal SubSablon(WordprocessingDocument doc, string key)
|
||||
{
|
||||
var bookmark = doc.MainDocumentPart.RootElement.Descendants<BookmarkStart>()
|
||||
.FirstOrDefault(x => x.Name == key);
|
||||
//var parentBookmark = false;
|
||||
if (bookmark != null)
|
||||
{
|
||||
SablonRoot = new List<OpenXmlElement>();
|
||||
var nextSibling = bookmark.NextSibling();
|
||||
if (nextSibling == null)
|
||||
nextSibling = bookmark.Parent;
|
||||
while (nextSibling != null)
|
||||
{
|
||||
var endBookmark = (nextSibling is BookmarkEnd end && end.Id == bookmark.Id.Value) ? end : null;
|
||||
if (endBookmark == null)
|
||||
{
|
||||
endBookmark = nextSibling.Descendants<BookmarkEnd>().FirstOrDefault(x => x.Id == bookmark.Id.Value);
|
||||
if (endBookmark != null)
|
||||
SablonRoot.Add(nextSibling);
|
||||
}
|
||||
if (endBookmark != null)
|
||||
{
|
||||
bookmark.Remove();
|
||||
endBookmark.Remove();
|
||||
break;
|
||||
}
|
||||
SablonRoot.Add(nextSibling);
|
||||
var tmpNextSibling = nextSibling.NextSibling();
|
||||
if (tmpNextSibling == null)
|
||||
{
|
||||
tmpNextSibling = nextSibling.Parent;
|
||||
if (tmpNextSibling != null && !(tmpNextSibling is Body) && !(tmpNextSibling is Document))
|
||||
SablonRoot.Clear();
|
||||
else
|
||||
break;
|
||||
}
|
||||
nextSibling = tmpNextSibling;
|
||||
}
|
||||
}
|
||||
|
||||
if (SablonRoot != null && SablonRoot.Count > 0)
|
||||
{
|
||||
SablonRootBase = new List<OpenXmlElement>();
|
||||
foreach (var item in SablonRoot)
|
||||
{
|
||||
SablonRootBase.Add(item.CloneNode(true));
|
||||
}
|
||||
BookmarkStart = new BookmarkStart() { Name = "repeater", Id = "1000" };
|
||||
BookmarkEnd = new BookmarkEnd() { Id = "1000" };
|
||||
if (SablonRoot.First().Parent != null)
|
||||
{
|
||||
SablonRoot.First().InsertBeforeSelf(BookmarkStart);
|
||||
SablonRoot.First().InsertBeforeSelf(BookmarkEnd);
|
||||
foreach (var rootItem in SablonRoot)
|
||||
rootItem.Remove();
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var rootItem in SablonRoot)
|
||||
foreach (var rootItemChildElement in rootItem.ChildElements)
|
||||
rootItemChildElement.Remove();
|
||||
SablonRoot.First().AppendChild(BookmarkStart);
|
||||
SablonRoot.First().AppendChild(BookmarkEnd);
|
||||
}
|
||||
Reset();
|
||||
}
|
||||
}
|
||||
|
||||
private void Insert()
|
||||
{
|
||||
var root = SablonRoot;
|
||||
if (root.Count == 1 && root.First() is Document)
|
||||
{
|
||||
root = root.First().ChildElements.ToList();
|
||||
}
|
||||
for (var i = 0; i < root.Count; i++)
|
||||
{
|
||||
if (i == 0)
|
||||
BookmarkStart.InsertBeforeSelf(root[i]);
|
||||
else
|
||||
root[i - 1].InsertAfterSelf(root[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private void Reset()
|
||||
{
|
||||
SablonRoot.Clear();
|
||||
foreach (var item in SablonRootBase)
|
||||
{
|
||||
SablonRoot.Add(item.CloneNode(true));
|
||||
}
|
||||
}
|
||||
|
||||
protected internal void InsertAndReset()
|
||||
{
|
||||
Insert();
|
||||
Reset();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
BookmarkStart?.Remove();
|
||||
BookmarkEnd?.Remove();
|
||||
SablonRootBase = null;
|
||||
SablonRoot = null;
|
||||
}
|
||||
}
|
||||
|
||||
public IDisposable Repeat(string key)
|
||||
{
|
||||
Repeater = new SubSablon(Doc, key);
|
||||
return Repeater;
|
||||
}
|
||||
|
||||
public SablonGenerator(byte[] content)
|
||||
{
|
||||
Mem = new MemoryStream();
|
||||
Mem.Write(content, 0, content.Length);
|
||||
try
|
||||
{
|
||||
Doc = WordprocessingDocument.Open(Mem, true, new OpenSettings()
|
||||
{
|
||||
MarkupCompatibilityProcessSettings =
|
||||
new MarkupCompatibilityProcessSettings(MarkupCompatibilityProcessMode.ProcessAllParts,
|
||||
FileFormatVersions.Office2010)
|
||||
});
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//if (!string.IsNullOrEmpty(Config.TryGetStringValue("SablonGeneratorErrorPath")))
|
||||
//{
|
||||
// File.WriteAllBytes(Path.Combine(Config.GetStringValue("SablonGeneratorErrorPath"), DateTime.Now.ToString("yyyyMMddHHHmmss.content")), content);
|
||||
//}
|
||||
throw;
|
||||
}
|
||||
|
||||
_currentRoot = new List<OpenXmlElement>();
|
||||
CurrentRoot.AddRange(Doc.MainDocumentPart.HeaderParts.Select(x => x.RootElement));
|
||||
CurrentRoot.Add(Doc.MainDocumentPart.RootElement);
|
||||
CurrentRoot.AddRange(Doc.MainDocumentPart.FooterParts.Select(x => x.RootElement));
|
||||
}
|
||||
|
||||
public static void CheckOpenXmlDocument(byte[] content)
|
||||
{
|
||||
WordprocessingDocument doc = null;
|
||||
var mem = new MemoryStream();
|
||||
mem.Write(content, 0, content.Length);
|
||||
try
|
||||
{
|
||||
doc = WordprocessingDocument.Open(mem, true, new OpenSettings()
|
||||
{
|
||||
MarkupCompatibilityProcessSettings =
|
||||
new MarkupCompatibilityProcessSettings(MarkupCompatibilityProcessMode.ProcessAllParts,
|
||||
FileFormatVersions.Office2010)
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
#if DEBUG
|
||||
//LoggerHelper.DiagnosticAudit.Information(DateTime.Now,
|
||||
//Common.Enums.Area.BaseSystem,
|
||||
//0,
|
||||
//string.Format(ex.ToString()),
|
||||
//new Guid().ToString());
|
||||
//LoggerHelper.DiagnosticAudit.Log.Information(ex.ToString());
|
||||
#else
|
||||
//LoggerHelper.DiagnosticAudit.Information(DateTime.Now,
|
||||
//Common.Enums.Area.BaseSystem,
|
||||
//0,
|
||||
//string.Format(ex.Message),
|
||||
//Guid.Empty.ToString());
|
||||
#endif
|
||||
//throw new BusinessException("Hibás vagy nem megfelelő OpenXML állomány.");
|
||||
}
|
||||
finally
|
||||
{
|
||||
mem?.Dispose();
|
||||
doc?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public void Generate(Dictionary<string, string> propertyDictionary)
|
||||
{
|
||||
ReplaceBookmarks(propertyDictionary);
|
||||
if (Repeater?.SablonRoot != null) Repeater.InsertAndReset();
|
||||
}
|
||||
|
||||
public void SimpleReplace(string key, string value)
|
||||
{
|
||||
value = value == null ? "" : value;
|
||||
|
||||
foreach (var headerPart in Doc.MainDocumentPart.HeaderParts)
|
||||
SimpleReplace2(headerPart.Header, key, value);
|
||||
SimpleReplace2(Doc.MainDocumentPart.Document.Body, key, value);
|
||||
}
|
||||
|
||||
protected void SimpleReplace(OpenXmlCompositeElement target, string key, string value)
|
||||
{
|
||||
var keyValue = key.Replace("#", "");
|
||||
var texts = target.Descendants<Text>();
|
||||
Text start = null;
|
||||
Text keyValueText = null;
|
||||
foreach (var text in texts)
|
||||
if (text.Text == "#" && start == null)
|
||||
start = text;
|
||||
else if (text.Text == "#" && start != null && keyValueText != null)
|
||||
{
|
||||
var end = text;
|
||||
keyValueText.Text = value;
|
||||
start.Remove();
|
||||
end.Remove();
|
||||
start = null;
|
||||
keyValueText = null;
|
||||
}
|
||||
else if (start != null && text.Text.ToUpper().Contains(keyValue.ToUpper()))
|
||||
keyValueText = text;
|
||||
else if (text.Text.ToUpper().Contains(key.ToUpper()))
|
||||
{
|
||||
start = null;
|
||||
keyValueText = null;
|
||||
text.Text = Regex.Replace(text.Text, key, value, RegexOptions.IgnoreCase);
|
||||
}
|
||||
else
|
||||
{
|
||||
start = null;
|
||||
keyValueText = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void SimpleReplace2(OpenXmlCompositeElement target, string key, string value)
|
||||
{
|
||||
var texts = target.Descendants<Text>();
|
||||
Text start = null;
|
||||
var tokens = new List<Text>();
|
||||
string tokenText = "";
|
||||
|
||||
foreach (var text in texts)
|
||||
{
|
||||
if (text.Text == "#" && start == null)
|
||||
{
|
||||
start = text;
|
||||
tokenText += text.Text;
|
||||
}
|
||||
else if (text.Text == "#" && start != null)
|
||||
{
|
||||
var end = text;
|
||||
tokenText += text.Text;
|
||||
|
||||
if (tokenText.ToUpper() == key.ToUpper())
|
||||
{
|
||||
start.Text = value;
|
||||
foreach (var token in tokens)
|
||||
{
|
||||
token.Remove();
|
||||
}
|
||||
tokens.Clear();
|
||||
end.Remove();
|
||||
start = null;
|
||||
tokenText = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
start = null;
|
||||
tokens.Clear();
|
||||
tokenText = "";
|
||||
end = null;
|
||||
}
|
||||
}
|
||||
else if (text.Text.Contains('#') && text.Text.ToUpper() == key.ToUpper())
|
||||
{
|
||||
text.Text = value;
|
||||
}
|
||||
else if (text.Text.Contains('#'))
|
||||
{
|
||||
|
||||
}
|
||||
else if (start != null)
|
||||
{
|
||||
tokens.Add(text);
|
||||
tokenText += text.Text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SimpleReplaceForCV(string key, string value)
|
||||
{
|
||||
value = value == null ? "" : value;
|
||||
|
||||
SimpleReplaceForCV(Doc.MainDocumentPart.Document.Body, key, value);
|
||||
}
|
||||
|
||||
protected void SimpleReplaceForCV(OpenXmlCompositeElement target, string key, string value)
|
||||
{
|
||||
var keyValue = key.Replace("#", "");
|
||||
var texts = target.Descendants<Text>();
|
||||
Text start = null;
|
||||
Text keyValueText = null;
|
||||
var keyindox = "";
|
||||
foreach (var text in texts)
|
||||
{
|
||||
if (text.Text.Contains(key))
|
||||
{
|
||||
text.Text = text.Text.Replace(key, value);
|
||||
break;
|
||||
}
|
||||
|
||||
if (text.Text.Contains(keyValue + "#") && start != null)
|
||||
{
|
||||
start.Text = "";
|
||||
text.Text = text.Text.Replace(keyValue + "#", value);
|
||||
break;
|
||||
}
|
||||
|
||||
if ((text.Text == "#" || (text.Text.Contains("#") && text.Text.Count(x => x == '#') == 1)) && start == null)
|
||||
{
|
||||
start = text;
|
||||
keyindox = start.Text;
|
||||
}
|
||||
else if (start != null && (text.Text == "#" || text.Text.Contains("#")))
|
||||
{
|
||||
for (int i = texts.ToList().IndexOf(start) + 1; i < texts.ToList().IndexOf(text) + 1; i++)
|
||||
{
|
||||
if (texts.ToList()[i].Text.Contains(key))
|
||||
{
|
||||
texts.ToList()[i].Text = texts.ToList()[i].Text.Replace(key, value);
|
||||
break;
|
||||
}
|
||||
|
||||
keyindox = keyindox + texts.ToList()[i].Text;
|
||||
}
|
||||
keyindox = keyindox.Replace("#", "");
|
||||
if (keyindox == keyValue || keyindox.Replace(" ", "") == keyValue)
|
||||
{
|
||||
for (int i = texts.ToList().IndexOf(start) + 1; i < texts.ToList().IndexOf(text); i++)
|
||||
{
|
||||
texts.ToList()[i].Text = "";
|
||||
}
|
||||
start.Text = "";
|
||||
text.Text = value;
|
||||
}
|
||||
if (keyindox.Contains(keyValue))
|
||||
{
|
||||
for (int i = texts.ToList().IndexOf(start) + 1; i < texts.ToList().IndexOf(text); i++)
|
||||
{
|
||||
texts.ToList()[i].Text = "";
|
||||
}
|
||||
start.Text = "";
|
||||
text.Text = keyindox.Replace(keyValue, value);
|
||||
}
|
||||
start = null;
|
||||
keyindox = "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ReplaceBookmarks(Dictionary<string, string> propertyDictionary)
|
||||
{
|
||||
var bookmarkEndList = new List<BookmarkEnd>();
|
||||
foreach (var item in CurrentRoot)
|
||||
{
|
||||
var bookmarkEnds = item.Descendants<BookmarkEnd>();
|
||||
bookmarkEndList.AddRange(bookmarkEnds.ToList());
|
||||
}
|
||||
|
||||
foreach (var docContent in CurrentRoot)
|
||||
{
|
||||
var bookmarkStarts = docContent.Descendants<BookmarkStart>();
|
||||
|
||||
var bookmarkStartList = bookmarkStarts.ToList();
|
||||
if (docContent is BookmarkStart)
|
||||
bookmarkStartList.Add(docContent as BookmarkStart);
|
||||
|
||||
for (int k = 0; k < bookmarkStartList.Count; k++)
|
||||
{
|
||||
Run bookmarkRun = bookmarkStartList[k].NextSibling<Run>();
|
||||
if (bookmarkRun != null)
|
||||
{
|
||||
var bookmarkText = bookmarkRun.GetFirstChild<Text>().InnerText;
|
||||
if (propertyDictionary.ContainsKey(bookmarkText))
|
||||
{
|
||||
var itemValue = propertyDictionary[bookmarkText];
|
||||
|
||||
bookmarkRun.GetFirstChild<Text>().Text = itemValue ?? string.Empty;
|
||||
var id = bookmarkStartList[k].Id.Value;
|
||||
bookmarkStartList[k].Remove();
|
||||
var end = bookmarkEndList.Find(x => x.Id == id);
|
||||
end.Remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Táblázat generálás (a keyinrow paramétert keresi a táblázat első sorában (nem fejléc), ezt a sort kitörli, és helyére szúrja be az új sorokat
|
||||
/// amit az első paraméterben kap meg
|
||||
/// </summary>
|
||||
/// <param name="rowsAndCells">sorok és benne az egyes cellák tartalma</param>
|
||||
/// <param name="keyInRow">első (nem fejléc) sorában lévő kulcs, ez alapján azonosítjuk be a táblázatot</param>
|
||||
/// <param name="deleteEmptyRow">ha igaz, a táblázat összes meglévő sorát törli</param>
|
||||
public void SetTable(List<List<string>> rowsAndCells, string keyInRow, bool deleteEmptyRow = false)
|
||||
{
|
||||
Body bod = Doc.MainDocumentPart.Document.Body;
|
||||
var table = bod.Descendants<Table>().Where(tbl => tbl.InnerText.Contains(keyInRow)).FirstOrDefault();
|
||||
if (table != null)
|
||||
{
|
||||
if (deleteEmptyRow)
|
||||
{
|
||||
var firstRow = table.ChildElements.Where(x => x is TableRow).FirstOrDefault();
|
||||
var deletedRows = table.ChildElements.Where(x => x is TableRow).ToList();
|
||||
deletedRows.Remove(firstRow);
|
||||
foreach (var item in deletedRows)
|
||||
table.RemoveChild(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
var deletedRow = table.ChildElements.Where(x => x is TableRow).LastOrDefault();
|
||||
table.RemoveChild<TableRow>(deletedRow as TableRow);
|
||||
}
|
||||
|
||||
foreach (var row in rowsAndCells)
|
||||
{
|
||||
List<OpenXmlElement> cells = new List<OpenXmlElement>();
|
||||
|
||||
foreach (var cell in row)
|
||||
{
|
||||
var tableCell = new TableCell(new Paragraph(new Run(new Text(cell))));
|
||||
cells.Add(tableCell);
|
||||
}
|
||||
|
||||
table.Append(new TableRow(cells));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] CloseAndGetDocument()
|
||||
{
|
||||
Doc.Dispose();
|
||||
Doc = null;
|
||||
return Mem.ToArray();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Doc?.Dispose();
|
||||
Mem.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hozzáfűzi a már megnyitott fájlhoz a paraméterként kapott dokumentum tartalmát.
|
||||
/// </summary>
|
||||
/// <param name="document"></param>
|
||||
/// <param name="addPageBreak"></param>
|
||||
public void AppendDocument(byte[] document, bool addPageBreak = true)
|
||||
{
|
||||
var mainPart = Doc.MainDocumentPart;
|
||||
string altChunkId = "AltChunk_" + Guid.NewGuid().ToString().Replace("-", "");
|
||||
|
||||
var chunk = mainPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.WordprocessingML, altChunkId);
|
||||
chunk.FeedData(new MemoryStream(document));
|
||||
|
||||
// oldaltörés, ha kell
|
||||
if (addPageBreak)
|
||||
{
|
||||
mainPart.Document.Body.AppendChild(new Paragraph(new Run(new Break() { Type = BreakValues.Page })));
|
||||
}
|
||||
|
||||
mainPart.Document.Body.AppendChild(new AltChunk() { Id = altChunkId });
|
||||
|
||||
mainPart.Document.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,11 @@ namespace WorkFlowCheck.BL.Mappings
|
||||
|
||||
CreateMap<CheckListRow, CheckListRowDTO>()
|
||||
.ForMember(dest => dest.CheckListTemplateRowDTO, opt => opt.MapFrom(src => src.CheckListTemplateRow));
|
||||
|
||||
|
||||
CreateMap<RoleCheckListTemplateHeader, RoleCheckListTemplateHeaderDTO>()
|
||||
.ForMember(dest => dest.RoleDTO, opt => opt.MapFrom(src => src.Role))
|
||||
.ForMember(dest => dest.CheckListTemplateHeaderDTO, opt => opt.MapFrom(src => src.CheckListTemplateHeader));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WorkFlowCheck.BL.DocumentGenerator;
|
||||
using WorkFlowCheck.BL.Services.Interfaces;
|
||||
using WorkFlowCheck.Common.DTO;
|
||||
using WorkFlowCheck.DL;
|
||||
@@ -51,7 +52,7 @@ namespace WorkFlowCheck.BL.Services
|
||||
.OrderBy(r => r.CheckListTemplateRow.CheckPoint?.ShortName ?? string.Empty)
|
||||
.ThenBy(r => r.CheckListTemplateRow.RowIndex)
|
||||
.ToList();
|
||||
|
||||
|
||||
|
||||
}
|
||||
if (res != null)
|
||||
@@ -361,5 +362,17 @@ namespace WorkFlowCheck.BL.Services
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public byte[] CreatePDF(int checkListHeaderId)
|
||||
{
|
||||
var location = System.Reflection.Assembly.GetEntryAssembly().Location;
|
||||
var directory = System.IO.Path.GetDirectoryName(location);
|
||||
byte[] byteArray = System.IO.File.ReadAllBytes(Path.Combine(directory, "DocumentGenerator", "CheckList_Template_V1.docx"));
|
||||
SablonGenerator gen = new SablonGenerator(byteArray);
|
||||
|
||||
byte[] content = gen.CloseAndGetDocument();
|
||||
|
||||
return DokumentumGenerator.DocxToPdf(content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,5 +23,6 @@ namespace WorkFlowCheck.BL.Services.Interfaces
|
||||
Task<CheckListTemplateRowDTO> GetCheckListTemplateRowAsync(int id);
|
||||
Task<CheckListTemplateRowDTO> UpdateCheckListTemplateRowAsync(CheckListTemplateRowDTO checkListTemplateRowDTO);
|
||||
|
||||
byte[] CreatePDF(int checkListHeaderId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace WorkFlowCheck.BL.Services.Interfaces
|
||||
Task<List<UserRoleDTO>> GetAllUserRoleAsync();
|
||||
Task<UserRoleDTO> UpdateUserRoleAsync(UserRoleDTO userRoleDTO);
|
||||
|
||||
|
||||
Task<List<RoleCheckListTemplateHeaderDTO>> GetAllRoleCheckListTemplateHeadersAsync();
|
||||
|
||||
string GenerateJwtToken(UserDTO userDTO);
|
||||
}
|
||||
|
||||
@@ -340,5 +340,6 @@ namespace WorkFlowCheck.BL.Services
|
||||
return retVal;
|
||||
}
|
||||
|
||||
public Task<List<RoleCheckListTemplateHeaderDTO>> GetAllRoleCheckListTemplateHeadersAsync() => throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Aspose.Words" Version="25.3.0" />
|
||||
<PackageReference Include="AutoMapper" Version="13.0.1" />
|
||||
<PackageReference Include="DocumentFormat.OpenXml" Version="3.3.0" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WorkFlowCheck.Common.DTO
|
||||
{
|
||||
public class RoleCheckListTemplateHeaderDTO
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int RoleId { get; set; }
|
||||
public RoleDTO RoleDTO { get; set; } = null!;
|
||||
public int CheckListTemplateHeaderId { get; set; }
|
||||
public CheckListTemplateHeaderDTO CheckListTemplateHeaderDTO { get; set; } = null!;
|
||||
public bool Enabled { get; set; } = false;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
|
||||
<!-- Tab navigáció -->
|
||||
<div class="card shadow p-0">
|
||||
<div class="card-header p-0">
|
||||
<div class="card-header p-0" style="border:none;">
|
||||
<ul class="nav nav-tabs" id="checklistTab" role="tablist">
|
||||
<li class="nav-item" role="presentation">
|
||||
<button class="nav-link active" id="general-tab" data-bs-toggle="tab" data-bs-target="#general" type="button" role="tab">Adatok</button>
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
<li><a class="dropdown-item" asp-area="" asp-page="/UserAndRole/RolePage">Szabályok</a></li>
|
||||
<li><hr class="dropdown-divider"></li> <!-- EZ AZ ELVÁLASZTÓ VONAL -->
|
||||
<li><a class="dropdown-item" asp-area="" asp-page="/UserAndRole/UserRolePage">Felhasználók - szabályok</a></li>
|
||||
<li><a class="dropdown-item" asp-area="" asp-page="/UserAndRole/RoleCheckListTemplateHeadersPage">Szabályok - Ellenőrzési sablonok</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
|
||||
@@ -1,4 +1,100 @@
|
||||
@page
|
||||
@model WorkFlowCheck.Web.Pages.UserAndRole.RoleCheckListTemplateHeadersPageModel
|
||||
@model WorkFlowCheck.Web.Pages.RoleCheckListTemplateHeadersAndRole.RoleCheckListTemplateHeadersPageModel
|
||||
@{
|
||||
ViewData["Title"] = "Szabályok - Ellenőrzési sablonok";
|
||||
}
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
|
||||
<div class="card shadow p-4">
|
||||
<div class="d-flex justify-content-end">
|
||||
<button id="newRoleCheckListTemplateHeadersBtn" class="btn btn-primary float-right new-btn" data-bs-toggle="tooltip" data-bs-placement="top" title="Új felhasználó">
|
||||
<i class="bi bi-plus-square"></i>
|
||||
</button>
|
||||
</div>
|
||||
<table id="tbRoleCheckListTemplateHeaderssPage" class="table table-bordered table-hover table-sm" style="width:100%">
|
||||
<thead class="table-primary">
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>First Name</th>
|
||||
<th>Last Name</th>
|
||||
<th>RoleCheckListTemplateHeaders Name</th>
|
||||
<th>E-mail</th>
|
||||
<th class="text-center">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tfoot class="table-light">
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>First Name</th>
|
||||
<th>Last Name</th>
|
||||
<th>RoleCheckListTemplateHeaders Name</th>
|
||||
<th>E-mail</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
const table = new DataTable('#tbRoleCheckListTemplateHeaderssPage', {
|
||||
ajax: {
|
||||
url: "@Url.Page("./RoleCheckListTemplateHeadersPage", "LoadRoleCheckListTemplateHeaderss")",
|
||||
type: "GET",
|
||||
dataSrc : "data"
|
||||
},
|
||||
columns: [
|
||||
{ data: "id" },
|
||||
{ data: "firstName" },
|
||||
{ data: "lastName" },
|
||||
{ data: "RoleCheckListTemplateHeadersName" },
|
||||
{ data: "email" },
|
||||
{ data: null, render: function (data, type, row) {
|
||||
return renderActionButtons(row.id);
|
||||
}}
|
||||
],
|
||||
columnDefs: [
|
||||
{
|
||||
"targets": 0,
|
||||
"visible": false
|
||||
},
|
||||
{
|
||||
"targets": 5,
|
||||
"className": "text-center",
|
||||
"width": "10%"
|
||||
}
|
||||
],
|
||||
|
||||
processing:true,
|
||||
language: { url: '//cdn.datatables.net/plug-ins/2.2.2/i18n/hu.json',}
|
||||
});
|
||||
|
||||
$('#newRoleCheckListTemplateHeadersBtn').on('click', function ()
|
||||
{
|
||||
console.log('New button clicked!"');
|
||||
window.location.href = `@Url.Page("./RoleCheckListTemplateHeadersEditPage")?id=0`;
|
||||
});
|
||||
|
||||
$('#tbRoleCheckListTemplateHeaderssPage').on('click', '.edit-btn', function ()
|
||||
{
|
||||
const row = table.row($(this).closest('tr')).data();
|
||||
window.location.href = `@Url.Page("./RoleCheckListTemplateHeadersEditPage")?id=${row.id}`;
|
||||
});
|
||||
|
||||
$('#tbRoleCheckListTemplateHeaderssPage').on('click', '.delete-btn', function ()
|
||||
{
|
||||
const row = table.row($(this).closest('tr')).data();
|
||||
console.log(row);
|
||||
showConfirmModal({
|
||||
title: 'Törlés megerősítése',
|
||||
message: 'Biztosan törölni szeretnéd ezt az elemet?',
|
||||
okText: 'Törlés',
|
||||
cancelText: 'Mégsem'
|
||||
}).then(function(result) {
|
||||
if(result === 'ok') {
|
||||
console.log('Törlés végrehajtva');
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
}
|
||||
|
||||
@@ -1,12 +1,25 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using WorkFlowCheck.Web.Services.Interfaces;
|
||||
|
||||
namespace WorkFlowCheck.Web.Pages.UserAndRole
|
||||
{
|
||||
public class RoleCheckListTemplateHeadersPageModel : PageModel
|
||||
public class RoleCheckListTemplatesPageModel : PageModel
|
||||
{
|
||||
public void OnGet()
|
||||
private readonly ILogger<IndexModel> _logger;
|
||||
private readonly IUserService _userService;
|
||||
public RoleCheckListTemplatesPageModel(ILogger<IndexModel> logger, IUserService userService)
|
||||
{
|
||||
_logger = logger;
|
||||
_userService = userService;
|
||||
}
|
||||
public async Task OnGet()
|
||||
{
|
||||
}
|
||||
public async Task<JsonResult> OnGetLoadRoleCheckListTemplates()
|
||||
{
|
||||
var results = await _userService.getall();
|
||||
return new JsonResult(new { data = results });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,6 @@ namespace WorkFlowCheck.Web.Services.Interfaces
|
||||
Task<List<UserRoleDTO>> GetAllUserRoles();
|
||||
Task<ApiResponseDTO<UserRoleDTO>> UpdateUserRole(UserRoleDTO userRoleDTO);
|
||||
|
||||
|
||||
Task<List<RoleCheckListTemplateHeaderDTO>> GetAllRoleCheckListTemplates();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,5 +265,26 @@ namespace WorkFlowCheck.Web.Services
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<RoleCheckListTemplateHeaderDTO>> GetAllRoleCheckListTemplates()
|
||||
{
|
||||
string endpoint = $"{_httpClient.BaseAddress}api/User/GetAllRoleCheckListTemplateHeaders";
|
||||
var retVal = new List<RoleCheckListTemplateHeaderDTO>();
|
||||
try
|
||||
{
|
||||
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<List<RoleCheckListTemplateHeaderDTO>>>(endpoint);
|
||||
if (response != null)
|
||||
{
|
||||
if (response.IsSuccess)
|
||||
{
|
||||
return response.Data;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error(ex.Message);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user