Compare commits
2 Commits
compile-co
...
05-23-b
Author | SHA1 | Date | |
---|---|---|---|
7650bf2869 | |||
184e97fce3 |
@ -1,74 +0,0 @@
|
|||||||
#if NET8
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
using Fab2ApprovalSystem.PdfGenerator;
|
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
||||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
|
||||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
|
|
||||||
namespace Fab2ApprovalSystem.Extensions;
|
|
||||||
|
|
||||||
public static class ControllerExtensions {
|
|
||||||
|
|
||||||
public static ActionResult GetBinaryContentResult<TModel>(this Controller controller, string viewName, string contentType, TModel model) {
|
|
||||||
string pageTitle = string.Empty;
|
|
||||||
|
|
||||||
string htmlText = RenderViewToString(controller, viewName, model);
|
|
||||||
|
|
||||||
StandardPdfRenderer standardPdfRenderer = new();
|
|
||||||
// Let the html be rendered into a PDF document through iTextSharp.
|
|
||||||
byte[] buffer = standardPdfRenderer.Render(htmlText, pageTitle);
|
|
||||||
|
|
||||||
// Return the PDF as a binary stream to the client.
|
|
||||||
return new BinaryContentResult(buffer, contentType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string RenderViewToString<TModel>(this Controller controller, string viewName, TModel model) {
|
|
||||||
if (string.IsNullOrEmpty(viewName))
|
|
||||||
viewName = controller.ControllerContext.ActionDescriptor.ActionName;
|
|
||||||
|
|
||||||
controller.ViewData.Model = model;
|
|
||||||
|
|
||||||
using (StringWriter writer = new()) {
|
|
||||||
try {
|
|
||||||
CompositeViewEngine compositeViewEngine = controller.HttpContext.RequestServices.GetRequiredService(typeof(ICompositeViewEngine)) as CompositeViewEngine;
|
|
||||||
if (compositeViewEngine is null || compositeViewEngine.ViewEngines.Count == 0) { }
|
|
||||||
|
|
||||||
ViewEngineResult viewResult = null;
|
|
||||||
|
|
||||||
if (viewName.EndsWith(".cshtml"))
|
|
||||||
viewResult = compositeViewEngine.GetView(viewName, viewName, false);
|
|
||||||
else
|
|
||||||
viewResult = compositeViewEngine.FindView(controller.ControllerContext, viewName, false);
|
|
||||||
|
|
||||||
if (!viewResult.Success)
|
|
||||||
return $"A view with the name '{viewName}' could not be found";
|
|
||||||
|
|
||||||
ViewContext viewContext = new(
|
|
||||||
controller.ControllerContext,
|
|
||||||
viewResult.View,
|
|
||||||
controller.ViewData,
|
|
||||||
controller.TempData,
|
|
||||||
writer,
|
|
||||||
new HtmlHelperOptions()
|
|
||||||
);
|
|
||||||
|
|
||||||
Task task = viewResult.View.RenderAsync(viewContext);
|
|
||||||
task.Wait();
|
|
||||||
|
|
||||||
return writer.GetStringBuilder().ToString();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
return $"Failed - {ex.Message}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -116,3 +116,7 @@ input[type="checkbox"].input-validation-error {
|
|||||||
top: 55px;
|
top: 55px;
|
||||||
left: 25px;
|
left: 25px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.navbar-header-hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
@ -7,22 +7,22 @@ using System.Linq;
|
|||||||
#if !NET8
|
#if !NET8
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Fab2ApprovalSystem.PdfGenerator;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if NET8
|
#if NET8
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
#endif
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||||
|
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||||
#if NET8
|
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||||
using Fab2ApprovalSystem.Extensions;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using Fab2ApprovalSystem.DMO;
|
using Fab2ApprovalSystem.DMO;
|
||||||
using Fab2ApprovalSystem.Misc;
|
using Fab2ApprovalSystem.Misc;
|
||||||
using Fab2ApprovalSystem.Models;
|
using Fab2ApprovalSystem.Models;
|
||||||
using Fab2ApprovalSystem.ViewModels;
|
using Fab2ApprovalSystem.ViewModels;
|
||||||
|
using Fab2ApprovalSystem.PdfGenerator;
|
||||||
|
|
||||||
#if !NET8
|
#if !NET8
|
||||||
using Kendo.Mvc.Extensions;
|
using Kendo.Mvc.Extensions;
|
||||||
@ -35,12 +35,11 @@ namespace Fab2ApprovalSystem.Controllers;
|
|||||||
#if !NET8
|
#if !NET8
|
||||||
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
|
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
|
||||||
[SessionExpireFilter]
|
[SessionExpireFilter]
|
||||||
public class ECNController : PdfViewController {
|
|
||||||
#endif
|
#endif
|
||||||
#if NET8
|
#if NET8
|
||||||
[Route("[controller]")]
|
[Route("[controller]")]
|
||||||
public class ECNController : Controller {
|
|
||||||
#endif
|
#endif
|
||||||
|
public class ECNController : Controller {
|
||||||
|
|
||||||
private const string ECN_PREFIX = "ECN_";
|
private const string ECN_PREFIX = "ECN_";
|
||||||
private const string TECN_PREFIX = "TECN_";
|
private const string TECN_PREFIX = "TECN_";
|
||||||
@ -924,19 +923,12 @@ public class ECNController : Controller {
|
|||||||
if (!di.Exists)
|
if (!di.Exists)
|
||||||
di.Create();
|
di.Create();
|
||||||
|
|
||||||
// To render a PDF instead of an HTML, all we need to do is call ViewPdf instead of View. This
|
string htmlText;
|
||||||
// requires the controller to be inherited from MyController instead of MVC's Controller.
|
string pageTitle = string.Empty;
|
||||||
#if !NET8
|
htmlText = RenderViewToString("ECNPdf", ecn);
|
||||||
SavePdf(ecnFolderPath + "\\ECNForm_" + outputFileName, "ECNPdf", ecn);
|
StandardPdfRenderer.WritePortableDocumentFormatToFile(pageTitle, htmlText, $"{ecnFolderPath}\\ECNForm_{outputFileName}");
|
||||||
SavePdf(ecnFolderPath + "\\ECNApprovalLog_" + outputFileName, "ECNApprovalPdf", ecn);
|
htmlText = RenderViewToString("ECNApprovalPdf", ecn);
|
||||||
#endif
|
StandardPdfRenderer.WritePortableDocumentFormatToFile(pageTitle, htmlText, $"{ecnFolderPath}\\ECNApprovalLog_{outputFileName}");
|
||||||
#if NET8
|
|
||||||
string html;
|
|
||||||
html = this.RenderViewToString("ECNPdf", ecn);
|
|
||||||
System.IO.File.WriteAllText(ecnFolderPath + "\\ECNForm_" + outputFileName, html);
|
|
||||||
html = this.RenderViewToString("ECNApprovalPdf", ecn);
|
|
||||||
System.IO.File.WriteAllText(ecnFolderPath + "\\ECNApprovalLog_" + outputFileName, html);
|
|
||||||
#endif
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
EventLogDMO.Add(new WinEventLog() { IssueID = ecnNumber, UserID = GetUserIdentityName(), DocumentType = "ECN", OperationType = "Generate PDF", Comments = ex.Message });
|
EventLogDMO.Add(new WinEventLog() { IssueID = ecnNumber, UserID = GetUserIdentityName(), DocumentType = "ECN", OperationType = "Generate PDF", Comments = ex.Message });
|
||||||
ecn = null;
|
ecn = null;
|
||||||
@ -946,6 +938,54 @@ public class ECNController : Controller {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string RenderViewToString(string viewName, ECNPdf ecnPdf) {
|
||||||
|
string result;
|
||||||
|
ViewData.Model = ecnPdf;
|
||||||
|
using (StringWriter writer = new()) {
|
||||||
|
try {
|
||||||
|
#if !NET8
|
||||||
|
ViewEngineResult viewResult = ViewEngines.Engines.FindView(ControllerContext, viewName, string.Empty);
|
||||||
|
if (viewResult is null) {
|
||||||
|
return $"A view with the name '{viewName}' could not be found";
|
||||||
|
}
|
||||||
|
ViewContext viewContext = new(ControllerContext, viewResult.View, ViewData, TempData, writer);
|
||||||
|
viewResult.View.Render(viewContext, writer);
|
||||||
|
string htmlText = writer.GetStringBuilder().ToString();
|
||||||
|
result = htmlText.Replace("navbar-header", "navbar-header-hidden");
|
||||||
|
#endif
|
||||||
|
#if NET8
|
||||||
|
ViewEngineResult viewResult;
|
||||||
|
CompositeViewEngine compositeViewEngine = HttpContext.RequestServices.GetRequiredService(typeof(ICompositeViewEngine)) as CompositeViewEngine;
|
||||||
|
|
||||||
|
if (viewName.EndsWith(".cshtml")) {
|
||||||
|
viewResult = compositeViewEngine.GetView(viewName, viewName, false);
|
||||||
|
} else {
|
||||||
|
viewResult = compositeViewEngine.FindView(ControllerContext, viewName, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!viewResult.Success) {
|
||||||
|
return $"A view with the name '{viewName}' could not be found";
|
||||||
|
}
|
||||||
|
|
||||||
|
ViewContext viewContext = new(ControllerContext,
|
||||||
|
viewResult.View,
|
||||||
|
ViewData,
|
||||||
|
TempData,
|
||||||
|
writer,
|
||||||
|
new HtmlHelperOptions());
|
||||||
|
|
||||||
|
System.Threading.Tasks.Task task = viewResult.View.RenderAsync(viewContext);
|
||||||
|
task.Wait();
|
||||||
|
|
||||||
|
result = writer.GetStringBuilder().ToString();
|
||||||
|
#endif
|
||||||
|
} catch (Exception ex) {
|
||||||
|
result = $"Failed - {ex.Message}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public bool GenerateECNPdfDifferentLocation(int ecnNumber, int folderName) {
|
public bool GenerateECNPdfDifferentLocation(int ecnNumber, int folderName) {
|
||||||
ECNPdf ecn = new();
|
ECNPdf ecn = new();
|
||||||
try {
|
try {
|
||||||
@ -963,15 +1003,9 @@ public class ECNController : Controller {
|
|||||||
if (!di.Exists)
|
if (!di.Exists)
|
||||||
di.Create();
|
di.Create();
|
||||||
|
|
||||||
// To render a PDF instead of an HTML, all we need to do is call ViewPdf instead of View. This
|
string pageTitle = string.Empty;
|
||||||
// requires the controller to be inherited from MyController instead of MVC's Controller.
|
string htmlText = RenderViewToString("ECNPdf", ecn);
|
||||||
#if !NET8
|
StandardPdfRenderer.WritePortableDocumentFormatToFile(pageTitle, htmlText, $"{ecnFolderPath}\\ECNForm_{outputFileName}");
|
||||||
SavePdf(ecnFolderPath + "\\ECNForm_" + outputFileName, "ECNPdf", ecn);
|
|
||||||
#endif
|
|
||||||
#if NET8
|
|
||||||
string html = this.RenderViewToString("ECNPdf", ecn);
|
|
||||||
System.IO.File.WriteAllText(ecnFolderPath + "\\ECNForm_" + outputFileName, html);
|
|
||||||
#endif
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
EventLogDMO.Add(new WinEventLog() { IssueID = ecnNumber, UserID = GetUserIdentityName(), DocumentType = "ECN", OperationType = "Generate PDF", Comments = ex.Message });
|
EventLogDMO.Add(new WinEventLog() { IssueID = ecnNumber, UserID = GetUserIdentityName(), DocumentType = "ECN", OperationType = "Generate PDF", Comments = ex.Message });
|
||||||
ecn = null;
|
ecn = null;
|
||||||
@ -990,17 +1024,14 @@ public class ECNController : Controller {
|
|||||||
ecn = ecnDMO.GetECNPdf(ecnNumber);
|
ecn = ecnDMO.GetECNPdf(ecnNumber);
|
||||||
ViewBag.Category = ecnDMO.GetCategoryID(ecn);
|
ViewBag.Category = ecnDMO.GetCategoryID(ecn);
|
||||||
ViewBag.TrainingNotificationTo = ecnDMO.GetTrainingNotificationTo(ecn, trainingDMO);
|
ViewBag.TrainingNotificationTo = ecnDMO.GetTrainingNotificationTo(ecn, trainingDMO);
|
||||||
// To render a PDF instead of an HTML, all we need to do is call ViewPdf instead of View. This
|
string pageTitle = string.Empty;
|
||||||
// requires the controller to be inherited from MyController instead of MVC's Controller.
|
string htmlText = RenderViewToString("ECNPdf", ecn);
|
||||||
#if !NET8
|
if (Debugger.IsAttached) {
|
||||||
return ViewPdf("", "ECNPdf", ecn);
|
return Content(htmlText, "text/html");
|
||||||
#endif
|
} else {
|
||||||
#if NET8
|
byte[] buffer = StandardPdfRenderer.GetPortableDocumentFormatBytes(pageTitle, htmlText);
|
||||||
if (Debugger.IsAttached)
|
return new BinaryContentResult(buffer, "application/pdf");
|
||||||
return Content(this.RenderViewToString("ECNPdf", ecn), "text/html");
|
}
|
||||||
else
|
|
||||||
return this.GetBinaryContentResult("ECNPdf", "application/pdf", ecn);
|
|
||||||
#endif
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
EventLogDMO.Add(new WinEventLog() { IssueID = ecnNumber, UserID = GetUserIdentityName(), DocumentType = "ECN", OperationType = "Print PDF", Comments = ex.Message });
|
EventLogDMO.Add(new WinEventLog() { IssueID = ecnNumber, UserID = GetUserIdentityName(), DocumentType = "ECN", OperationType = "Print PDF", Comments = ex.Message });
|
||||||
ecn = null;
|
ecn = null;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -8,22 +9,22 @@ using System.Web;
|
|||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Fab2ApprovalSystem.PdfGenerator;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if NET8
|
#if NET8
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
#endif
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||||
|
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
||||||
#if NET8
|
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||||
using Fab2ApprovalSystem.Extensions;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using Fab2ApprovalSystem.DMO;
|
using Fab2ApprovalSystem.DMO;
|
||||||
using Fab2ApprovalSystem.Misc;
|
using Fab2ApprovalSystem.Misc;
|
||||||
using Fab2ApprovalSystem.Models;
|
using Fab2ApprovalSystem.Models;
|
||||||
using Fab2ApprovalSystem.ViewModels;
|
using Fab2ApprovalSystem.ViewModels;
|
||||||
|
using Fab2ApprovalSystem.PdfGenerator;
|
||||||
|
|
||||||
#if !NET8
|
#if !NET8
|
||||||
using Kendo.Mvc.Extensions;
|
using Kendo.Mvc.Extensions;
|
||||||
@ -36,12 +37,11 @@ namespace Fab2ApprovalSystem.Controllers;
|
|||||||
#if !NET8
|
#if !NET8
|
||||||
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
|
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
|
||||||
[SessionExpireFilter]
|
[SessionExpireFilter]
|
||||||
public class LotTravelerController : PdfViewController {
|
|
||||||
#endif
|
#endif
|
||||||
#if NET8
|
#if NET8
|
||||||
[Route("[controller]")]
|
[Route("[controller]")]
|
||||||
public class LotTravelerController : Controller {
|
|
||||||
#endif
|
#endif
|
||||||
|
public class LotTravelerController : Controller {
|
||||||
|
|
||||||
private readonly LotTravelerDMO LotTravDMO = new();
|
private readonly LotTravelerDMO LotTravDMO = new();
|
||||||
private readonly string docTypeString = "LotTraveler";
|
private readonly string docTypeString = "LotTraveler";
|
||||||
@ -220,17 +220,14 @@ public class LotTravelerController : Controller {
|
|||||||
try {
|
try {
|
||||||
workRequest = LotTravDMO.GetLTWorkRequestItemPDF(workRequestID);
|
workRequest = LotTravDMO.GetLTWorkRequestItemPDF(workRequestID);
|
||||||
|
|
||||||
// To render a PDF instead of an HTML, all we need to do is call ViewPdf instead of View. This
|
string pageTitle = string.Empty;
|
||||||
// requires the controller to be inherited from MyController instead of MVC's Controller.
|
string htmlText = RenderViewToString("WorkRequestPDF", workRequest);
|
||||||
#if !NET8
|
if (Debugger.IsAttached) {
|
||||||
return ViewPdf("", "WorkRequestPDF", workRequest);
|
return Content(htmlText, "text/html");
|
||||||
#endif
|
} else {
|
||||||
#if NET8
|
byte[] buffer = StandardPdfRenderer.GetPortableDocumentFormatBytes(pageTitle, htmlText);
|
||||||
if (Debugger.IsAttached)
|
return new BinaryContentResult(buffer, "application/pdf");
|
||||||
return Content(this.RenderViewToString("WorkRequestPDF", workRequest), "text/html");
|
}
|
||||||
else
|
|
||||||
return this.GetBinaryContentResult("WorkRequestPDF", "application/pdf", workRequest);
|
|
||||||
#endif
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n DisplayWorkRequestPDF - LotTraveler\r\n" + ex.InnerException.ToString(), EventLogEntryType.Error);
|
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n DisplayWorkRequestPDF - LotTraveler\r\n" + ex.InnerException.ToString(), EventLogEntryType.Error);
|
||||||
EventLogDMO.Add(new WinEventLog() { IssueID = workRequest.SWRNumber, UserID = GetUserIdentityName(), DocumentType = "LotTravler", OperationType = "Generate PDF", Comments = ex.Message });
|
EventLogDMO.Add(new WinEventLog() { IssueID = workRequest.SWRNumber, UserID = GetUserIdentityName(), DocumentType = "LotTravler", OperationType = "Generate PDF", Comments = ex.Message });
|
||||||
@ -239,6 +236,54 @@ public class LotTravelerController : Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string RenderViewToString(string viewName, object model) {
|
||||||
|
string result;
|
||||||
|
ViewData.Model = model;
|
||||||
|
using (StringWriter writer = new()) {
|
||||||
|
try {
|
||||||
|
#if !NET8
|
||||||
|
ViewEngineResult viewResult = ViewEngines.Engines.FindView(ControllerContext, viewName, string.Empty);
|
||||||
|
if (viewResult is null) {
|
||||||
|
return $"A view with the name '{viewName}' could not be found";
|
||||||
|
}
|
||||||
|
ViewContext viewContext = new(ControllerContext, viewResult.View, ViewData, TempData, writer);
|
||||||
|
viewResult.View.Render(viewContext, writer);
|
||||||
|
string htmlText = writer.GetStringBuilder().ToString();
|
||||||
|
result = htmlText.Replace("navbar-header", "navbar-header-hidden");
|
||||||
|
#endif
|
||||||
|
#if NET8
|
||||||
|
ViewEngineResult viewResult;
|
||||||
|
CompositeViewEngine compositeViewEngine = HttpContext.RequestServices.GetRequiredService(typeof(ICompositeViewEngine)) as CompositeViewEngine;
|
||||||
|
|
||||||
|
if (viewName.EndsWith(".cshtml")) {
|
||||||
|
viewResult = compositeViewEngine.GetView(viewName, viewName, false);
|
||||||
|
} else {
|
||||||
|
viewResult = compositeViewEngine.FindView(ControllerContext, viewName, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!viewResult.Success) {
|
||||||
|
return $"A view with the name '{viewName}' could not be found";
|
||||||
|
}
|
||||||
|
|
||||||
|
ViewContext viewContext = new(ControllerContext,
|
||||||
|
viewResult.View,
|
||||||
|
ViewData,
|
||||||
|
TempData,
|
||||||
|
writer,
|
||||||
|
new HtmlHelperOptions());
|
||||||
|
|
||||||
|
System.Threading.Tasks.Task task = viewResult.View.RenderAsync(viewContext);
|
||||||
|
task.Wait();
|
||||||
|
|
||||||
|
result = writer.GetStringBuilder().ToString();
|
||||||
|
#endif
|
||||||
|
} catch (Exception ex) {
|
||||||
|
result = $"Failed - {ex.Message}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public ActionResult WorkRequestRevision(int workRequestID) {
|
public ActionResult WorkRequestRevision(int workRequestID) {
|
||||||
int isITARCompliant = 1;
|
int isITARCompliant = 1;
|
||||||
LTWorkRequest workRequest = new();
|
LTWorkRequest workRequest = new();
|
||||||
@ -280,9 +325,7 @@ public class LotTravelerController : Controller {
|
|||||||
|
|
||||||
return Content("Successfully Saved");
|
return Content("Successfully Saved");
|
||||||
}
|
}
|
||||||
/// <summary>
|
|
||||||
///
|
|
||||||
/// </summary>
|
|
||||||
public JsonResult GetBaseFlowLocations(string baseFlow) {
|
public JsonResult GetBaseFlowLocations(string baseFlow) {
|
||||||
List<BaseFlowLocation> loclist = LotTravDMO.GetBaseFlowLocations(baseFlow);
|
List<BaseFlowLocation> loclist = LotTravDMO.GetBaseFlowLocations(baseFlow);
|
||||||
return GetJsonResult(loclist);
|
return GetJsonResult(loclist);
|
||||||
@ -369,9 +412,6 @@ public class LotTravelerController : Controller {
|
|||||||
return Content(newWorkRequestID.ToString());
|
return Content(newWorkRequestID.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// For the Revison
|
|
||||||
/// </summary>
|
|
||||||
public ActionResult UpdateMaterialDetailRevision(LTWorkRequest model) {
|
public ActionResult UpdateMaterialDetailRevision(LTWorkRequest model) {
|
||||||
var modelMaterialDetail = model.LTMaterial;
|
var modelMaterialDetail = model.LTMaterial;
|
||||||
int previousMaterialID = model.LTMaterial.ID;
|
int previousMaterialID = model.LTMaterial.ID;
|
||||||
@ -1316,17 +1356,14 @@ public class LotTravelerController : Controller {
|
|||||||
try {
|
try {
|
||||||
traveler = LotTravDMO.GetLotTravlerPdf(ltLotID, revisionNumber);
|
traveler = LotTravDMO.GetLotTravlerPdf(ltLotID, revisionNumber);
|
||||||
|
|
||||||
// To render a PDF instead of an HTML, all we need to do is call ViewPdf instead of View. This
|
string pageTitle = string.Empty;
|
||||||
// requires the controller to be inherited from MyController instead of MVC's Controller.
|
string htmlText = RenderViewToString("LotTravelerPDF", traveler);
|
||||||
#if !NET8
|
if (Debugger.IsAttached) {
|
||||||
return ViewPdf("", "LotTravelerPDF", traveler);
|
return Content(htmlText, "text/html");
|
||||||
#endif
|
} else {
|
||||||
#if NET8
|
byte[] buffer = StandardPdfRenderer.GetPortableDocumentFormatBytes(pageTitle, htmlText);
|
||||||
if (Debugger.IsAttached)
|
return new BinaryContentResult(buffer, "application/pdf");
|
||||||
return Content(this.RenderViewToString("LotTravelerPDF", traveler), "text/html");
|
}
|
||||||
else
|
|
||||||
return this.GetBinaryContentResult("LotTravelerPDF", "application/pdf", traveler);
|
|
||||||
#endif
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
EventLogDMO.Add(new WinEventLog() { IssueID = traveler.SWRNumber, UserID = GetUserIdentityName(), DocumentType = "LotTraveler", OperationType = "Generate PDF", Comments = ex.Message });
|
EventLogDMO.Add(new WinEventLog() { IssueID = traveler.SWRNumber, UserID = GetUserIdentityName(), DocumentType = "LotTraveler", OperationType = "Generate PDF", Comments = ex.Message });
|
||||||
traveler = null;
|
traveler = null;
|
||||||
@ -1415,7 +1452,7 @@ public class LotTravelerController : Controller {
|
|||||||
string fileExtension = fileName.Substring(fileName.LastIndexOf("."), fileName.Length - fileName.LastIndexOf("."));
|
string fileExtension = fileName.Substring(fileName.LastIndexOf("."), fileName.Length - fileName.LastIndexOf("."));
|
||||||
|
|
||||||
string ecnFolderPath = _AppSettings.AttachmentFolder + "LotTraveler\\" + swrNumber.ToString();
|
string ecnFolderPath = _AppSettings.AttachmentFolder + "LotTraveler\\" + swrNumber.ToString();
|
||||||
var sDocument = System.IO.Path.Combine(ecnFolderPath, fileGuid + fileExtension);
|
var sDocument = Path.Combine(ecnFolderPath, fileGuid + fileExtension);
|
||||||
|
|
||||||
var FDir_AppData = _AppSettings.AttachmentFolder;
|
var FDir_AppData = _AppSettings.AttachmentFolder;
|
||||||
if (!sDocument.StartsWith(FDir_AppData)) {
|
if (!sDocument.StartsWith(FDir_AppData)) {
|
||||||
|
@ -1,36 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
#if !NET8
|
|
||||||
using System.Web;
|
|
||||||
using System.Web.Mvc;
|
|
||||||
using System.Web.Security;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if NET8
|
|
||||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
||||||
using Microsoft.AspNetCore.Mvc.ViewEngines;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !NET8
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Net;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Security.Claims;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Fab2ApprovalSystem.PdfGenerator;
|
|
||||||
|
|
||||||
public class FakeView : IView {
|
|
||||||
|
|
||||||
public void Render(ViewContext viewContext, TextWriter writer) {
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
#if NET8
|
|
||||||
string IView.Path => throw new NotImplementedException();
|
|
||||||
Task IView.RenderAsync(ViewContext context) => throw new NotImplementedException();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -1,59 +0,0 @@
|
|||||||
|
|
||||||
#if !NET8
|
|
||||||
using System.Web;
|
|
||||||
using System.Web.Mvc;
|
|
||||||
using System.Web.Mvc.Html;
|
|
||||||
using System.Web.Security;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if NET8
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !NET8
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Net;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Security.Claims;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Fab2ApprovalSystem.PdfGenerator;
|
|
||||||
|
|
||||||
public class HtmlViewRenderer {
|
|
||||||
|
|
||||||
public string RenderViewToString(Controller controller, string viewName, object viewData) {
|
|
||||||
StringBuilder renderedView = new();
|
|
||||||
#if !NET8
|
|
||||||
using (StringWriter responseWriter = new(renderedView)) {
|
|
||||||
HttpResponse fakeResponse = new(responseWriter);
|
|
||||||
HttpContext fakeContext = new(HttpContext.Current.Request, fakeResponse);
|
|
||||||
ControllerContext fakeControllerContext = new(new HttpContextWrapper(fakeContext), controller.ControllerContext.RouteData, controller.ControllerContext.Controller);
|
|
||||||
|
|
||||||
var oldContext = HttpContext.Current;
|
|
||||||
HttpContext.Current = fakeContext;
|
|
||||||
|
|
||||||
using (var viewPage = new ViewPage()) {
|
|
||||||
HtmlHelper html = new HtmlHelper(CreateViewContext(responseWriter, fakeControllerContext), viewPage);
|
|
||||||
html.RenderPartial(viewName, viewData);
|
|
||||||
HttpContext.Current = oldContext;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return renderedView.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !NET8
|
|
||||||
|
|
||||||
private static ViewContext CreateViewContext(TextWriter responseWriter, ControllerContext fakeControllerContext) {
|
|
||||||
return new ViewContext(fakeControllerContext, new FakeView(), new ViewDataDictionary(), new TempDataDictionary(), responseWriter);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
@ -1,56 +1 @@
|
|||||||
#if !NET8
|
|
||||||
using System.Web;
|
|
||||||
using System.Web.Mvc;
|
|
||||||
using System.Web.Security;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if !NET8
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Net;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Security.Claims;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Fab2ApprovalSystem.PdfGenerator;
|
|
||||||
|
|
||||||
#if !NET8
|
|
||||||
|
|
||||||
public class PdfViewController : Controller {
|
|
||||||
|
|
||||||
private readonly HtmlViewRenderer htmlViewRenderer;
|
|
||||||
private readonly StandardPdfRenderer standardPdfRenderer;
|
|
||||||
|
|
||||||
public PdfViewController() {
|
|
||||||
htmlViewRenderer = new HtmlViewRenderer();
|
|
||||||
standardPdfRenderer = new StandardPdfRenderer();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ActionResult ViewPdf(string pageTitle, string viewName, object model) {
|
|
||||||
// Render the view html to a string.
|
|
||||||
string htmlText = htmlViewRenderer.RenderViewToString(this, viewName, model);
|
|
||||||
|
|
||||||
// Let the html be rendered into a PDF document through iTextSharp.
|
|
||||||
byte[] buffer = standardPdfRenderer.Render(htmlText, pageTitle);
|
|
||||||
|
|
||||||
// Return the PDF as a binary stream to the client.
|
|
||||||
return new BinaryContentResult(buffer, "application/pdf");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void SavePdf(string fileName, string viewName, object model) {
|
|
||||||
// Render the view html to a string.
|
|
||||||
string htmlText = htmlViewRenderer.RenderViewToString(this, viewName, model);
|
|
||||||
|
|
||||||
// Let the html be rendered into a PDF document through iTextSharp.
|
|
||||||
byte[] buffer = standardPdfRenderer.Render(htmlText, "");
|
|
||||||
|
|
||||||
using (FileStream fs = new(fileName, FileMode.Create)) {
|
|
||||||
fs.Write(buffer, 0, buffer.Length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -9,16 +9,32 @@ using System.IO;
|
|||||||
namespace Fab2ApprovalSystem.PdfGenerator;
|
namespace Fab2ApprovalSystem.PdfGenerator;
|
||||||
|
|
||||||
public class StandardPdfRenderer {
|
public class StandardPdfRenderer {
|
||||||
|
|
||||||
private const int HorizontalMargin = 40;
|
private const int HorizontalMargin = 40;
|
||||||
private const int VerticalMargin = 40;
|
private const int VerticalMargin = 40;
|
||||||
|
|
||||||
public byte[] Render(string htmlText, string pageTitle) {
|
public static byte[] GetPortableDocumentFormatBytes(string pageTitle, string htmlText) {
|
||||||
byte[] renderedBuffer;
|
byte[] results;
|
||||||
|
MemoryStream memoryStream = GetPortableDocumentFormat(pageTitle, htmlText);
|
||||||
|
results = new byte[memoryStream.Position];
|
||||||
|
memoryStream.Position = 0;
|
||||||
|
memoryStream.Read(results, 0, results.Length);
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
using (MemoryStream outputMemoryStream = new()) {
|
public static void WritePortableDocumentFormatToFile(string pageTitle, string htmlText, string path) {
|
||||||
|
using (MemoryStream memoryStream = GetPortableDocumentFormat(pageTitle, htmlText)) {
|
||||||
|
using (FileStream fileStream = new(path, FileMode.Create)) {
|
||||||
|
memoryStream.CopyTo(fileStream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MemoryStream GetPortableDocumentFormat(string pageTitle, string htmlText) {
|
||||||
|
MemoryStream result = new();
|
||||||
#if !NET8
|
#if !NET8
|
||||||
using (Document pdfDocument = new Document(PageSize.A4, HorizontalMargin, HorizontalMargin, VerticalMargin, VerticalMargin)) {
|
using (Document pdfDocument = new Document(PageSize.A4, HorizontalMargin, HorizontalMargin, VerticalMargin, VerticalMargin)) {
|
||||||
PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDocument, outputMemoryStream);
|
PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDocument, result);
|
||||||
pdfWriter.CloseStream = false;
|
pdfWriter.CloseStream = false;
|
||||||
pdfWriter.PageEvent = new PrintHeaderFooter { Title = pageTitle };
|
pdfWriter.PageEvent = new PrintHeaderFooter { Title = pageTitle };
|
||||||
pdfDocument.Open();
|
pdfDocument.Open();
|
||||||
@ -27,15 +43,9 @@ public class StandardPdfRenderer {
|
|||||||
htmlWorker.Parse(htmlViewReader);
|
htmlWorker.Parse(htmlViewReader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
return result;
|
||||||
renderedBuffer = new byte[outputMemoryStream.Position];
|
|
||||||
outputMemoryStream.Position = 0;
|
|
||||||
outputMemoryStream.Read(renderedBuffer, 0, renderedBuffer.Length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return renderedBuffer;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,5 +1,19 @@
|
|||||||
@model Fab2ApprovalSystem.ViewModels.ECNPdf
|
@model Fab2ApprovalSystem.ViewModels.ECNPdf
|
||||||
<table style="width:100%;">
|
@{
|
||||||
|
Layout = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<title></title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body class="navbar-inner">
|
||||||
|
<table style="width:100%;">
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<table cellpadding="3" cellspacing="3" border="1">
|
<table cellpadding="3" cellspacing="3" border="1">
|
||||||
@ -107,7 +121,6 @@
|
|||||||
</table>
|
</table>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -227,7 +240,6 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -254,35 +266,6 @@
|
|||||||
</table>
|
</table>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@*<tr>
|
|
||||||
<td>
|
|
||||||
|
|
||||||
<table border="1">
|
|
||||||
<tr bgcolor="#c4baba" color="#000000">
|
|
||||||
<td colspan="3">Training Notification</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<table border="0">
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<font size="1">
|
|
||||||
Training:
|
|
||||||
@(Model.TrainingRequired ? "Yes" : "No")
|
|
||||||
</font>
|
|
||||||
|
|
||||||
<font size="1">
|
|
||||||
@(Model.TrainingBy.Length > 0 ? "(" + Model.TrainingBy + ")" : Model.TrainingBy)
|
|
||||||
</font>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
</td>
|
|
||||||
</tr>*@
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
|
|
||||||
@ -338,10 +321,8 @@
|
|||||||
</font>
|
</font>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
@ -349,7 +330,7 @@
|
|||||||
|
|
||||||
<table border="1">
|
<table border="1">
|
||||||
<tr bgcolor="#c4baba" color="#000000">
|
<tr bgcolor="#c4baba" color="#000000">
|
||||||
<td colspan="5">Training Notification</td>
|
<td colspan="1">Training Notification</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr style="display:block;">
|
<tr style="display:block;">
|
||||||
<td>
|
<td>
|
||||||
@ -367,10 +348,8 @@
|
|||||||
</font>
|
</font>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
@ -517,19 +496,11 @@
|
|||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
|
||||||
</table> <!--main table -->
|
</html>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -52,7 +52,7 @@ public class EngChangeNoticeDMOTests {
|
|||||||
try { throw new Exception(); } catch (Exception) { }
|
try { throw new Exception(); } catch (Exception) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void EngChangeNoticeDMO(ILogger? logger, AppSettings appSettings) {
|
private static void EngChangeNoticeDMO(ILogger? logger, AppSettings appSettings, int ecnNumber) {
|
||||||
#pragma warning disable IDE0059
|
#pragma warning disable IDE0059
|
||||||
SetGlobalVars(logger, appSettings);
|
SetGlobalVars(logger, appSettings);
|
||||||
ECN_DMO ecnDMO = new();
|
ECN_DMO ecnDMO = new();
|
||||||
@ -84,6 +84,9 @@ public class EngChangeNoticeDMOTests {
|
|||||||
// int SubmitTECNExtensionDocument(int issueID, appSettings.UserId, int documentType, DateTime extensionDate);
|
// int SubmitTECNExtensionDocument(int issueID, appSettings.UserId, int documentType, DateTime extensionDate);
|
||||||
// void TECNExtensionLog(int ecnNumber, DateTime extensionDate);
|
// void TECNExtensionLog(int ecnNumber, DateTime extensionDate);
|
||||||
// void UpdateECNType(int ecnNumber, string ecnType);
|
// void UpdateECNType(int ecnNumber, string ecnType);
|
||||||
|
ECNPdf ecn = ecnDMO.GetECNPdf(ecnNumber);
|
||||||
|
string categoryId = ecnDMO.GetCategoryID(ecn);
|
||||||
|
string trainingNotificationTo = ecnDMO.GetTrainingNotificationTo(ecn, new TrainingDMO());
|
||||||
if (ecnDMO is null) { }
|
if (ecnDMO is null) { }
|
||||||
#pragma warning restore IDE0059
|
#pragma warning restore IDE0059
|
||||||
}
|
}
|
||||||
@ -92,13 +95,14 @@ public class EngChangeNoticeDMOTests {
|
|||||||
[Ignore]
|
[Ignore]
|
||||||
#endif
|
#endif
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void EngChangeNoticeDMOIsAttachedOnly() {
|
[DataRow(82689)]
|
||||||
|
public void EngChangeNoticeDMOIsAttachedOnly(int ecnNumber) {
|
||||||
_Logger?.LogInformation("Starting Web Application");
|
_Logger?.LogInformation("Starting Web Application");
|
||||||
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
|
||||||
AppSettings? appSettings = serviceProvider?.GetRequiredService<AppSettings>();
|
AppSettings? appSettings = serviceProvider?.GetRequiredService<AppSettings>();
|
||||||
Assert.IsTrue(appSettings is not null);
|
Assert.IsTrue(appSettings is not null);
|
||||||
if (System.Diagnostics.Debugger.IsAttached)
|
if (System.Diagnostics.Debugger.IsAttached)
|
||||||
EngChangeNoticeDMO(_Logger, appSettings);
|
EngChangeNoticeDMO(_Logger, appSettings, ecnNumber);
|
||||||
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
|
||||||
NonThrowTryCatch();
|
NonThrowTryCatch();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user