Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 9 additions & 24 deletions FMS.Domain/Dto/Reports/SiteSummaryQuerySpec.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace FMS.Domain.Dto
namespace FMS.Domain.Dto
{
public class SiteSummaryQuerySpec
{
Expand All @@ -10,6 +10,9 @@ public SiteSummaryQuerySpec() { }
[Display(Name = "Sort By")]
public SiteSummarySortBy SortBy { get; set; } = SiteSummarySortBy.Facility_Number;

[Display(Name = "Export To")]
public SiteSummaryExportTo ExportTo { get; set; } = SiteSummaryExportTo.Local;

[Display(Name = "Facility Number")]
public string FacilityNumber { get; set; }

Expand Down Expand Up @@ -46,6 +49,8 @@ public SiteSummaryQuerySpec() { }
[Display(Name = "Show Header at top of reports")]
public bool ShowHeader { get; set; } = false;

public bool IsPdf { get; set; } = false;

public IDictionary<string, string> AsRouteValues() => new Dictionary<string, string?>
{
{ nameof(FacilityNumber), FacilityNumber },
Expand All @@ -61,7 +66,8 @@ public SiteSummaryQuerySpec() { }
{ nameof(AllOrgUnits), AllOrgUnits.ToString() },
{ nameof(ShowHeader), ShowHeader.ToString() },
{ nameof(SortBy), SortBy.ToString() },
{ nameof(Include), Include.ToString() }
{ nameof(Include), Include.ToString() },
{ nameof(ExportTo), ExportTo.ToString() }
};

public void TrimAll()
Expand All @@ -83,27 +89,6 @@ public enum SiteSummaryAddlOrgUnitInclusion
Include,
Exclude
}

public string GetSiteSummarySortText(SiteSummarySortBy sortBy)
{
var title = "";
switch (sortBy)
{
case SiteSummarySortBy.Facility_Number:
title += " Facility Number";
break;
case SiteSummarySortBy.Facility_Name:
title += " Facility Name";
break;
case SiteSummarySortBy.County:
title += " County";
break;
case SiteSummarySortBy.Class:
title += " Class";
break;
}

return title;
}
}
}
}
28 changes: 28 additions & 0 deletions FMS.Domain/Entities/SiteSummaryLog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using FMS.Domain.Entities.Base;
using System;
using System.Collections.Generic;
using System.Text;

namespace FMS.Domain.Entities
{
public class SiteSummaryLog : BaseActiveModel
{
public SiteSummaryLog() { }

public SiteSummaryLog(Guid id, string fileName, string filePath, string fileType)
{
Id = id;
PdfFileName = fileName;
PdfFilePath = filePath;
PdfFileType = fileType;
}

public string PdfFileName { get; set; }

public string PdfFilePath { get; set; }

public string PdfFileType { get; set; }

public string PdfURL { get; set; }
}
}
2 changes: 2 additions & 0 deletions FMS/FMS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
<ItemGroup>
<PackageReference Include="ClosedXML" />
<PackageReference Include="FreeSpire.PDF" />
<PackageReference Include="itext.bouncy-castle-adapter" />
<PackageReference Include="itext.pdfhtml" />
<PackageReference Include="JetBrains.Annotations" />
<PackageReference Include="LigerShark.WebOptimizer.Core" />
<PackageReference Include="Markdig" />
Expand Down
2 changes: 1 addition & 1 deletion FMS/Helpers/SiteSummaryHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using FMS.Domain.Dto;
using FMS.Domain.Dto;
using FMS.Domain.Repositories;

namespace FMS.Helpers
Expand Down
81 changes: 81 additions & 0 deletions FMS/Helpers/SiteSummaryPdfHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using FMS.Domain.Dto;
using FMS.Domain.Repositories;
using iText.Commons.Utils;
using System.Net;
using System;
using System.IO;
using iText.Html2pdf;

namespace FMS.Helpers
{
public class SiteSummaryPdfHelper
{

/// <summary>
/// Converts a simple HTML file to PDF using an InputStream and an OutputStream as arguments for the convertToPdf() method.
/// </summary>

const string USER_AGENT = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; WOW64; " +
"Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; " +
".NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; " +
"InfoPath.2; OfficeLiveConnector.1.3; OfficeLivePatch.0.0)";

/// <summary>
/// The path to the resulting PDF file.
/// </summary>
public static readonly String DEST = String.Concat(Environment.GetEnvironmentVariable("PdfFilePath"), "url2pdf_1.pdf");

/// <summary>
/// The target folder for the result.
/// </summary>
public string ADDRESS = "~/Reporting/SiteSummary/Report/";

/// <summary>
/// The main method of this example.
/// </summary>
/// <param name="args">no arguments are needed to run this example.</param>
public static void CreateNewPdf(String hsiNumber)
{
FileInfo file = new FileInfo(DEST);
file.Directory.Create();

new SiteSummaryPdfHelper().CreatePdf(new Uri(new SiteSummaryPdfHelper().ADDRESS + hsiNumber), DEST);
}

/// <summary>
/// Creates the PDF file.
/// </summary>
/// <param name="url">the URL object for the web page</param>
/// <param name="dest">the path to the resulting PDF</param>
public void CreatePdf(Uri url, String dest)
{
using (var fileStream = new FileStream(dest, FileMode.Create))
{
try
{
using (var httpClient = new System.Net.Http.HttpClient())
{
httpClient.Timeout = TimeSpan.FromSeconds(15);
httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(USER_AGENT);
var websiteTask = httpClient.GetByteArrayAsync(url);
websiteTask.Wait();
byte[] website = websiteTask.Result;
HtmlConverter.ConvertToPdf(new MemoryStream(website), fileStream);
}
}
catch (AggregateException ae) when (ae.InnerException is System.Net.Http.HttpRequestException hre)
{
// Handle HTTP request exception
}
catch (System.Net.Http.HttpRequestException hre)
{
// Handle HTTP request exception
}
catch (System.TimeoutException)
{
// Handle timeout
}
}
}
}
}
10 changes: 5 additions & 5 deletions FMS/Pages/Reporting/SiteSummary/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@page
@page
@using FMS.Domain.Dto
@using FMS.Domain.Entities.Users
@model FMS.Pages.Reporting.SiteSummary.IndexModel
Expand Down Expand Up @@ -137,10 +137,10 @@
</div>
<br />
<div class="row">
<div class="col-md-6">
<div class="col-md-12">
<input type="hidden" name="handler" value="Preview" />
<button id="PreviewButton" type="submit" class="btn btn-primary me-2">Preview Report List</button>
<a asp-page="./Index" class="btn btn-outline-secondary col-sm-3 col-md-2">Clear</a>
<button id="PreviewButton" type="submit" class="btn btn-primary col-sm-3 col-md-3">Preview Report List</button>
<a asp-page="./Index" class="btn btn-outline-secondary col-sm-3 col-md-3">Clear</a>
</div>
</div>
</form>
Expand Down Expand Up @@ -193,7 +193,7 @@
<svg class="bi">
<use href="@Url.Content("~/images/app-icons.svg")#app-icon-printer-fill"></use>
</svg>
Export/Print List
Export/Print Site Summary List
</a>
</div>
<div class="col-auto align-right d-print-none ms-2">
Expand Down
1 change: 1 addition & 0 deletions FMS/Pages/Reporting/SiteSummary/Index.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using DocumentFormat.OpenXml.Office2010.Excel;
using FMS.Domain.Data;
using FMS.Domain.Dto;
using FMS.Domain.Dto.Reports;
Expand Down
Loading
Loading