Merged PR 17498: Removed PdfViewController, HtmlViewRenderer and FakeView to be replaced with...
Removed PdfViewController, HtmlViewRenderer and FakeView to be replaced with ViewEngineResult Render method To test use url http://mestsa05ec.infineon.com:8080/ecn/printecnpdf?ecnNumber=82654
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
@ -21,7 +22,7 @@ namespace Fab2ApprovalSystem.Controllers;
|
||||
[Authorize]
|
||||
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
|
||||
[SessionExpireFilter]
|
||||
public class ECNController : PdfViewController {
|
||||
public class ECNController : Controller {
|
||||
|
||||
private const string ECN_PREFIX = "ECN_";
|
||||
private const string TECN_PREFIX = "TECN_";
|
||||
@ -669,9 +670,6 @@ public class ECNController : PdfViewController {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of Approvers and the status
|
||||
/// </summary>
|
||||
public ActionResult GetApproversList([DataSourceRequest] DataSourceRequest request, int issueID, byte step, bool isTECN, bool isEmergrncyTECN) {
|
||||
int isITARCompliant = 0;
|
||||
ECN ecn = new ECN();
|
||||
@ -893,10 +891,12 @@ public class ECNController : PdfViewController {
|
||||
if (!di.Exists)
|
||||
di.Create();
|
||||
|
||||
// To render a PDF instead of an HTML, all we need to do is call ViewPdf instead of View. This
|
||||
// requires the controller to be inherited from MyController instead of MVC's Controller.
|
||||
SavePdf(ecnFolderPath + "\\ECNForm_" + outputFileName, "ECNPdf", ecn);
|
||||
SavePdf(ecnFolderPath + "\\ECNApprovalLog_" + outputFileName, "ECNApprovalPdf", ecn);
|
||||
string htmlText;
|
||||
string pageTitle = string.Empty;
|
||||
htmlText = RenderViewToString("ECNPdf", ecn);
|
||||
StandardPdfRenderer.WritePortableDocumentFormatToFile(pageTitle, htmlText, $"{ecnFolderPath}\\ECNForm_{outputFileName}");
|
||||
htmlText = RenderViewToString("ECNApprovalPdf", ecn);
|
||||
StandardPdfRenderer.WritePortableDocumentFormatToFile(pageTitle, htmlText, $"{ecnFolderPath}\\ECNApprovalLog_{outputFileName}");
|
||||
} catch (Exception ex) {
|
||||
EventLogDMO.Add(new WinEventLog() { IssueID = ecnNumber, UserID = @User.Identity.Name, DocumentType = "ECN", OperationType = "Generate PDF", Comments = ex.Message });
|
||||
ecn = null;
|
||||
@ -906,6 +906,24 @@ public class ECNController : PdfViewController {
|
||||
return true;
|
||||
}
|
||||
|
||||
private string RenderViewToString(string viewName, ECNPdf ecnPdf) {
|
||||
string result;
|
||||
ViewData.Model = ecnPdf;
|
||||
using (StringWriter writer = new()) {
|
||||
try {
|
||||
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);
|
||||
result = writer.GetStringBuilder().ToString();
|
||||
} catch (Exception ex) {
|
||||
result = $"Failed - {ex.Message}";
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool GenerateECNPdfDifferentLocation(int ecnNumber, int folderName) {
|
||||
ECNPdf ecn = new ECNPdf();
|
||||
try {
|
||||
@ -923,9 +941,9 @@ public class ECNController : PdfViewController {
|
||||
if (!di.Exists)
|
||||
di.Create();
|
||||
|
||||
// To render a PDF instead of an HTML, all we need to do is call ViewPdf instead of View. This
|
||||
// requires the controller to be inherited from MyController instead of MVC's Controller.
|
||||
SavePdf(ecnFolderPath + "\\ECNForm_" + outputFileName, "ECNPdf", ecn);
|
||||
string pageTitle = string.Empty;
|
||||
string htmlText = RenderViewToString("ECNPdf", ecn);
|
||||
StandardPdfRenderer.WritePortableDocumentFormatToFile(pageTitle, htmlText, $"{ecnFolderPath}\\ECNForm_{outputFileName}");
|
||||
} catch (Exception ex) {
|
||||
EventLogDMO.Add(new WinEventLog() { IssueID = ecnNumber, UserID = @User.Identity.Name, DocumentType = "ECN", OperationType = "Generate PDF", Comments = ex.Message });
|
||||
ecn = null;
|
||||
@ -941,9 +959,14 @@ public class ECNController : PdfViewController {
|
||||
ecn = ecnDMO.GetECNPdf(ecnNumber);
|
||||
ViewBag.Category = ecnDMO.GetCategoryID(ecn);
|
||||
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
|
||||
// requires the controller to be inherited from MyController instead of MVC's Controller.
|
||||
return this.ViewPdf("", "ECNPdf", ecn);
|
||||
string pageTitle = string.Empty;
|
||||
string htmlText = RenderViewToString("ECNPdf", ecn);
|
||||
if (System.Diagnostics.Debugger.IsAttached) {
|
||||
return Content(htmlText, "text/html");
|
||||
} else {
|
||||
byte[] buffer = StandardPdfRenderer.GetPortableDocumentFormatBytes(pageTitle, htmlText);
|
||||
return new BinaryContentResult(buffer, "application/pdf");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
EventLogDMO.Add(new WinEventLog() { IssueID = ecnNumber, UserID = @User.Identity.Name, DocumentType = "ECN", OperationType = "Print PDF", Comments = ex.Message });
|
||||
ecn = null;
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Web;
|
||||
@ -20,7 +21,7 @@ namespace Fab2ApprovalSystem.Controllers;
|
||||
[Authorize]
|
||||
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
|
||||
[SessionExpireFilter]
|
||||
public class LotTravelerController : PdfViewController {
|
||||
public class LotTravelerController : Controller {
|
||||
|
||||
LotTravelerDMO LotTravDMO = new LotTravelerDMO();
|
||||
string docTypeString = "LotTraveler";
|
||||
@ -199,9 +200,14 @@ public class LotTravelerController : PdfViewController {
|
||||
try {
|
||||
workRequest = LotTravDMO.GetLTWorkRequestItemPDF(workRequestID);
|
||||
|
||||
// To render a PDF instead of an HTML, all we need to do is call ViewPdf instead of View. This
|
||||
// requires the controller to be inherited from MyController instead of MVC's Controller.
|
||||
return this.ViewPdf("", "WorkRequestPDF", workRequest);
|
||||
string pageTitle = string.Empty;
|
||||
string htmlText = RenderViewToString("WorkRequestPDF", workRequest);
|
||||
if (System.Diagnostics.Debugger.IsAttached) {
|
||||
return Content(htmlText, "text/html");
|
||||
} else {
|
||||
byte[] buffer = StandardPdfRenderer.GetPortableDocumentFormatBytes(pageTitle, htmlText);
|
||||
return new BinaryContentResult(buffer, "application/pdf");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Functions.WriteEvent(_AppSettings, @User.Identity.Name + "\r\n DisplayWorkRequestPDF - LotTraveler\r\n" + ex.InnerException.ToString(), System.Diagnostics.EventLogEntryType.Error);
|
||||
EventLogDMO.Add(new WinEventLog() { IssueID = workRequest.SWRNumber, UserID = @User.Identity.Name, DocumentType = "LotTravler", OperationType = "Generate PDF", Comments = ex.Message });
|
||||
@ -210,6 +216,24 @@ public class LotTravelerController : PdfViewController {
|
||||
}
|
||||
}
|
||||
|
||||
private string RenderViewToString(string viewName, object model) {
|
||||
string result;
|
||||
ViewData.Model = model;
|
||||
using (StringWriter writer = new()) {
|
||||
try {
|
||||
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);
|
||||
result = writer.GetStringBuilder().ToString();
|
||||
} catch (Exception ex) {
|
||||
result = $"Failed - {ex.Message}";
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public ActionResult WorkRequestRevision(int workRequestID) {
|
||||
int isITARCompliant = 1;
|
||||
LTWorkRequest workRequest = new LTWorkRequest();
|
||||
@ -251,9 +275,7 @@ public class LotTravelerController : PdfViewController {
|
||||
|
||||
return Content("Successfully Saved");
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
||||
public JsonResult GetBaseFlowLocations(string baseFlow) {
|
||||
List<BaseFlowLocation> loclist = LotTravDMO.GetBaseFlowLocations(baseFlow);
|
||||
return Json(loclist, JsonRequestBehavior.AllowGet);
|
||||
@ -332,9 +354,6 @@ public class LotTravelerController : PdfViewController {
|
||||
return Content(newWorkRequestID.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For the Revison
|
||||
/// </summary>
|
||||
public ActionResult UpdateMaterialDetailRevision(LTWorkRequest model) {
|
||||
var modelMaterialDetail = model.LTMaterial;
|
||||
int previousMaterialID = model.LTMaterial.ID;
|
||||
@ -1232,15 +1251,19 @@ public class LotTravelerController : PdfViewController {
|
||||
LotTravDMO.DeleteLot(ltLotID);
|
||||
}
|
||||
|
||||
///
|
||||
public ActionResult DisplayLotTravlerPdf(int ltLotID, int revisionNumber) {
|
||||
LotTravelerPdf traveler = new LotTravelerPdf();
|
||||
try {
|
||||
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
|
||||
// requires the controller to be inherited from MyController instead of MVC's Controller.
|
||||
return this.ViewPdf("", "LotTravelerPDF", traveler);
|
||||
string pageTitle = string.Empty;
|
||||
string htmlText = RenderViewToString("LotTravelerPDF", traveler);
|
||||
if (System.Diagnostics.Debugger.IsAttached) {
|
||||
return Content(htmlText, "text/html");
|
||||
} else {
|
||||
byte[] buffer = StandardPdfRenderer.GetPortableDocumentFormatBytes(pageTitle, htmlText);
|
||||
return new BinaryContentResult(buffer, "application/pdf");
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
EventLogDMO.Add(new WinEventLog() { IssueID = traveler.SWRNumber, UserID = @User.Identity.Name, DocumentType = "LotTraveler", OperationType = "Generate PDF", Comments = ex.Message });
|
||||
traveler = null;
|
||||
|
Reference in New Issue
Block a user