Compare commits
	
		
			4 Commits
		
	
	
		
			704df4fa8c
			...
			fix-core-t
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 54799f54ec | |||
| 65a433e9ab | |||
| 8bae94de96 | |||
| 032c971472 | 
@ -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();
 | 
			
		||||
@ -883,6 +881,8 @@ public class ECNController : PdfViewController {
 | 
			
		||||
 | 
			
		||||
            string outputFileName = "";
 | 
			
		||||
            ecn = ecnDMO.GetECNPdf(ecnNumber);
 | 
			
		||||
            ViewBag.Category = ecnDMO.GetCategoryID(ecn);
 | 
			
		||||
            ViewBag.TrainingNotificationTo = ecnDMO.GetTrainingNotificationTo(ecn, trainingDMO);
 | 
			
		||||
            outputFileName = ecnNumber.ToString() + ".pdf";
 | 
			
		||||
 | 
			
		||||
            string ecnFolderPath = _AppSettings.AttachmentFolder + "ECN\\" + ecnNumber.ToString();
 | 
			
		||||
@ -891,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;
 | 
			
		||||
@ -904,12 +906,32 @@ 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 {
 | 
			
		||||
            string outputFileName = "";
 | 
			
		||||
 | 
			
		||||
            ecn = ecnDMO.GetECNPdf(ecnNumber);
 | 
			
		||||
            ViewBag.Category = ecnDMO.GetCategoryID(ecn);
 | 
			
		||||
            ViewBag.TrainingNotificationTo = ecnDMO.GetTrainingNotificationTo(ecn, trainingDMO);
 | 
			
		||||
            outputFileName = ecnNumber.ToString() + ".pdf";
 | 
			
		||||
 | 
			
		||||
            string ecnFolderPath = _AppSettings.AttachmentFolder + "ECN\\" + folderName.ToString();
 | 
			
		||||
@ -919,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;
 | 
			
		||||
@ -935,13 +957,20 @@ public class ECNController : PdfViewController {
 | 
			
		||||
        ECNPdf ecn;
 | 
			
		||||
        try {
 | 
			
		||||
            ecn = ecnDMO.GetECNPdf(ecnNumber);
 | 
			
		||||
            // 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);
 | 
			
		||||
            ViewBag.Category = ecnDMO.GetCategoryID(ecn);
 | 
			
		||||
            ViewBag.TrainingNotificationTo = ecnDMO.GetTrainingNotificationTo(ecn, trainingDMO);
 | 
			
		||||
            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;
 | 
			
		||||
            return Content("");
 | 
			
		||||
            return Content("An unexpected error has occurred!");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -1221,6 +1250,12 @@ public class ECNController : PdfViewController {
 | 
			
		||||
            try {
 | 
			
		||||
                lastApproverAndLastStep = true;
 | 
			
		||||
 | 
			
		||||
                ecn.CancellationDate = DateTime.Now;
 | 
			
		||||
                ecn.CancellationApprovalDate = DateTime.Now;
 | 
			
		||||
                ecn.CancellationApproved = true;
 | 
			
		||||
                ecn.Cancelled = true;
 | 
			
		||||
                ecnDMO.UpdateECN(ecn);
 | 
			
		||||
 | 
			
		||||
                ECNPdf ecnPDF = new ECNPdf();
 | 
			
		||||
                GenerateECNPdf(ecnNumber, out ecnPDF);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
 | 
			
		||||
@ -42,6 +42,9 @@ public class ECN_DMO {
 | 
			
		||||
            parameters.Add("@ExpirationDate", ecn.ExpirationDate);
 | 
			
		||||
            parameters.Add("@ExtensionDate", ecn.ExtensionDate);
 | 
			
		||||
            parameters.Add("@CancellationDate", ecn.CancellationDate);
 | 
			
		||||
            parameters.Add("@CancellationApprovalDate", ecn.CancellationApprovalDate);
 | 
			
		||||
            parameters.Add("@CancellationApproved", ecn.CancellationApproved);
 | 
			
		||||
            parameters.Add("@Cancelled", ecn.Cancelled);
 | 
			
		||||
            parameters.Add("@AcknowledgementRequired", ecn.AcknowledgementRequired);
 | 
			
		||||
            parameters.Add("@TrainingRequired", ecn.TrainingRequired);
 | 
			
		||||
            parameters.Add("@AreaID", ecn.AreaID);
 | 
			
		||||
@ -353,14 +356,17 @@ public class ECN_DMO {
 | 
			
		||||
            List<string> affectedAreas = multipleResultItems.Read<string>().ToList();
 | 
			
		||||
            List<string> affectedTechnologies = multipleResultItems.Read<string>().ToList();
 | 
			
		||||
            List<string> acknowledgementBy = multipleResultItems.Read<string>().ToList();
 | 
			
		||||
            List<string> trainingBy = multipleResultItems.Read<string>().ToList();
 | 
			
		||||
            List<int> trainingby = multipleResultItems.Read<int>().ToList();
 | 
			
		||||
            if (ecnItem != null && trainingby != null) {
 | 
			
		||||
                if (trainingby.Count > 0)
 | 
			
		||||
                    ecnItem.TrainingByIDs.AddRange(trainingby);
 | 
			
		||||
            }
 | 
			
		||||
            List<string> productfamilies = multipleResultItems.Read<string>().ToList();
 | 
			
		||||
 | 
			
		||||
            ecnItem.AffectedModules = string.Join(", ", modules);
 | 
			
		||||
            ecnItem.AffectedDepartments = string.Join(", ", departments);
 | 
			
		||||
            ecnItem.AffectedAreas = string.Join(",", affectedAreas);
 | 
			
		||||
            ecnItem.AffectedTechnologies = string.Join(",", affectedTechnologies);
 | 
			
		||||
            ecnItem.TrainingBy = string.Join(",", trainingBy);
 | 
			
		||||
            ecnItem.AcknowledgementBy = string.Join(",", acknowledgementBy);
 | 
			
		||||
            ecnItem.AffectedProductFamilies = string.Join(",", productfamilies);
 | 
			
		||||
 | 
			
		||||
@ -711,4 +717,26 @@ public class ECN_DMO {
 | 
			
		||||
        return r;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    internal string GetCategoryID(ECNPdf ecn) {
 | 
			
		||||
        string result;
 | 
			
		||||
        if (ecn.CategoryID is null) {
 | 
			
		||||
            result = string.Empty;
 | 
			
		||||
        } else {
 | 
			
		||||
            List<ECNCategory> categories = GetCategories();
 | 
			
		||||
            result = (from l in categories where l.CategoryID == ecn.CategoryID.Value select l.CategoryName).FirstOrDefault();
 | 
			
		||||
        }
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    internal string GetTrainingNotificationTo(ECNPdf ecn, TrainingDMO trainingDMO) {
 | 
			
		||||
        string result;
 | 
			
		||||
        if (ecn.TrainingByIDs is null) {
 | 
			
		||||
            result = string.Empty;
 | 
			
		||||
        } else {
 | 
			
		||||
            List<TrainingGroup> trainingGroups = trainingDMO.GetTrainingGroups();
 | 
			
		||||
            result = string.Join(", ", (from l in trainingGroups where ecn.TrainingByIDs.Contains(l.TrainingGroupID) select l.TrainingGroupName).ToArray());
 | 
			
		||||
        }
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -325,9 +325,6 @@
 | 
			
		||||
    <Compile Include="Models\WinEventLogModel.cs" />
 | 
			
		||||
    <Compile Include="Models\WorkFlowModels.cs" />
 | 
			
		||||
    <Compile Include="PdfGenerator\BinaryContentResult.cs" />
 | 
			
		||||
    <Compile Include="PdfGenerator\FakeView.cs" />
 | 
			
		||||
    <Compile Include="PdfGenerator\HtmlViewRenderer.cs" />
 | 
			
		||||
    <Compile Include="PdfGenerator\PdfViewController.cs" />
 | 
			
		||||
    <Compile Include="PdfGenerator\PrintHeaderFooter.cs" />
 | 
			
		||||
    <Compile Include="PdfGenerator\StandardPdfRenderer.cs" />
 | 
			
		||||
    <Compile Include="Properties\AssemblyInfo.cs" />
 | 
			
		||||
 | 
			
		||||
@ -1,28 +0,0 @@
 | 
			
		||||
#if !NET8
 | 
			
		||||
 | 
			
		||||
// --------------------------------------------------------------------------------------------------------------------
 | 
			
		||||
// <copyright file="FakeView.cs" company="SemanticArchitecture">
 | 
			
		||||
//   http://www.SemanticArchitecture.net pkalkie@gmail.com
 | 
			
		||||
// </copyright>
 | 
			
		||||
// <summary>
 | 
			
		||||
//   Defines the FakeView type.
 | 
			
		||||
// </summary>
 | 
			
		||||
// --------------------------------------------------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
namespace Fab2ApprovalSystem.PdfGenerator {
 | 
			
		||||
    using System;
 | 
			
		||||
    using System.IO;
 | 
			
		||||
    using System.Web.Mvc;
 | 
			
		||||
 | 
			
		||||
    public class FakeView : IView {
 | 
			
		||||
        #region IView Members
 | 
			
		||||
 | 
			
		||||
        public void Render(ViewContext viewContext, TextWriter writer) {
 | 
			
		||||
            throw new NotImplementedException();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        #endregion
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@ -1,49 +0,0 @@
 | 
			
		||||
#if !NET8
 | 
			
		||||
 | 
			
		||||
// --------------------------------------------------------------------------------------------------------------------
 | 
			
		||||
// <copyright file="HtmlViewRenderer.cs" company="SemanticArchitecture">
 | 
			
		||||
//   http://www.SemanticArchitecture.net pkalkie@gmail.com
 | 
			
		||||
// </copyright>
 | 
			
		||||
// <summary>
 | 
			
		||||
//   This class is responsible for rendering a HTML view to a string.
 | 
			
		||||
// </summary>
 | 
			
		||||
// --------------------------------------------------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
namespace Fab2ApprovalSystem.PdfGenerator {
 | 
			
		||||
    using System.IO;
 | 
			
		||||
    using System.Text;
 | 
			
		||||
    using System.Web;
 | 
			
		||||
    using System.Web.Mvc;
 | 
			
		||||
    using System.Web.Mvc.Html;
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// This class is responsible for rendering a HTML view into a string. 
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class HtmlViewRenderer {
 | 
			
		||||
        public string RenderViewToString(Controller controller, string viewName, object viewData) {
 | 
			
		||||
            var renderedView = new StringBuilder();
 | 
			
		||||
            using (var responseWriter = new StringWriter(renderedView)) {
 | 
			
		||||
                var fakeResponse = new HttpResponse(responseWriter);
 | 
			
		||||
                var fakeContext = new HttpContext(HttpContext.Current.Request, fakeResponse);
 | 
			
		||||
                var fakeControllerContext = new ControllerContext(new HttpContextWrapper(fakeContext), controller.ControllerContext.RouteData, controller.ControllerContext.Controller);
 | 
			
		||||
 | 
			
		||||
                var oldContext = HttpContext.Current;
 | 
			
		||||
                HttpContext.Current = fakeContext;
 | 
			
		||||
 | 
			
		||||
                using (var viewPage = new ViewPage()) {
 | 
			
		||||
                    var html = new HtmlHelper(CreateViewContext(responseWriter, fakeControllerContext), viewPage);
 | 
			
		||||
                    html.RenderPartial(viewName, viewData);
 | 
			
		||||
                    HttpContext.Current = oldContext;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return renderedView.ToString();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static ViewContext CreateViewContext(TextWriter responseWriter, ControllerContext fakeControllerContext) {
 | 
			
		||||
            return new ViewContext(fakeControllerContext, new FakeView(), new ViewDataDictionary(), new TempDataDictionary(), responseWriter);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@ -1,54 +0,0 @@
 | 
			
		||||
#if !NET8
 | 
			
		||||
 | 
			
		||||
// --------------------------------------------------------------------------------------------------------------------
 | 
			
		||||
// <copyright file="PdfViewController.cs" company="SemanticArchitecture">
 | 
			
		||||
//   http://www.SemanticArchitecture.net pkalkie@gmail.com
 | 
			
		||||
// </copyright>
 | 
			
		||||
// <summary>
 | 
			
		||||
//   Extends the controller with functionality for rendering PDF views
 | 
			
		||||
// </summary>
 | 
			
		||||
// --------------------------------------------------------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
namespace Fab2ApprovalSystem.PdfGenerator {
 | 
			
		||||
    using System.Web.Mvc;
 | 
			
		||||
    using System.IO;
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Extends the controller with functionality for rendering PDF views
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public class PdfViewController : Controller {
 | 
			
		||||
        private readonly HtmlViewRenderer htmlViewRenderer;
 | 
			
		||||
        private readonly StandardPdfRenderer standardPdfRenderer;
 | 
			
		||||
 | 
			
		||||
        public PdfViewController() {
 | 
			
		||||
            this.htmlViewRenderer = new HtmlViewRenderer();
 | 
			
		||||
            this.standardPdfRenderer = new StandardPdfRenderer();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        protected ActionResult ViewPdf(string pageTitle, string viewName, object model) {
 | 
			
		||||
            // Render the view html to a string.
 | 
			
		||||
            string htmlText = this.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 = this.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 FileStream(fileName, FileMode.Create)) {
 | 
			
		||||
                fs.Write(buffer, 0, buffer.Length);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
@ -8,20 +8,34 @@ using System.IO;
 | 
			
		||||
 | 
			
		||||
namespace Fab2ApprovalSystem.PdfGenerator;
 | 
			
		||||
 | 
			
		||||
/// <summary>
 | 
			
		||||
/// This class is responsible for rendering a html text string to a PDF document using the html renderer of iTextSharp.
 | 
			
		||||
/// </summary>
 | 
			
		||||
public class StandardPdfRenderer {
 | 
			
		||||
 | 
			
		||||
    private const int HorizontalMargin = 40;
 | 
			
		||||
    private const int VerticalMargin = 40;
 | 
			
		||||
 | 
			
		||||
    public byte[] Render(string htmlText, string pageTitle) {
 | 
			
		||||
        byte[] renderedBuffer;
 | 
			
		||||
    public static byte[] GetPortableDocumentFormatBytes(string pageTitle, string htmlText) {
 | 
			
		||||
        byte[] results;
 | 
			
		||||
        using (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
 | 
			
		||||
        using (Document pdfDocument = new Document(PageSize.A4, HorizontalMargin, HorizontalMargin, VerticalMargin, VerticalMargin)) {
 | 
			
		||||
                PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDocument, outputMemoryStream);
 | 
			
		||||
            using (PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDocument, result)) {
 | 
			
		||||
                pdfWriter.CloseStream = false;
 | 
			
		||||
                pdfWriter.PageEvent = new PrintHeaderFooter { Title = pageTitle };
 | 
			
		||||
                pdfDocument.Open();
 | 
			
		||||
@ -30,15 +44,10 @@ public class StandardPdfRenderer {
 | 
			
		||||
                        htmlWorker.Parse(htmlViewReader);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
            renderedBuffer = new byte[outputMemoryStream.Position];
 | 
			
		||||
            outputMemoryStream.Position = 0;
 | 
			
		||||
            outputMemoryStream.Read(renderedBuffer, 0, renderedBuffer.Length);
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
        return renderedBuffer;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -30,7 +30,7 @@ public class ECNPdf {
 | 
			
		||||
    public string AffectedDepartments { get; set; }
 | 
			
		||||
    public string AffectedAreas { get; set; }
 | 
			
		||||
    public string AffectedTechnologies { get; set; }
 | 
			
		||||
    public string TrainingBy { get; set; }
 | 
			
		||||
    public List<int> TrainingByIDs { get; set; }
 | 
			
		||||
    public string AcknowledgementBy { get; set; }
 | 
			
		||||
    public bool IsECN { get; set; }
 | 
			
		||||
    public bool IsTECN { get; set; }
 | 
			
		||||
@ -79,6 +79,7 @@ public class ECNPdf {
 | 
			
		||||
    public int? ConvertedToNumber { get; set; }
 | 
			
		||||
    public int? ConvertedFromNumber { get; set; }
 | 
			
		||||
    public int WorkFlowNumber { get; set; }
 | 
			
		||||
    public int? CategoryID { get; set; }
 | 
			
		||||
    public bool FIChangeRequired { get; set; }
 | 
			
		||||
    public string NumberOfLotsAffected { get; set; }
 | 
			
		||||
    public string RecipeChange { get; set; }
 | 
			
		||||
@ -87,6 +88,7 @@ public class ECNPdf {
 | 
			
		||||
    public ECNPdf() {
 | 
			
		||||
        Approvalog = new List<ECNApprovalLog>();
 | 
			
		||||
        Attachments = new List<string>();
 | 
			
		||||
        TrainingByIDs = new List<int>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,19 @@
 | 
			
		||||
@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>
 | 
			
		||||
            <td>
 | 
			
		||||
                <table cellpadding="3" cellspacing="3" border="1">
 | 
			
		||||
@ -84,6 +98,16 @@
 | 
			
		||||
                                        </font>
 | 
			
		||||
                                    </td>
 | 
			
		||||
                                </tr>
 | 
			
		||||
                                <tr>
 | 
			
		||||
                                    <td>
 | 
			
		||||
                                        <font size="2">
 | 
			
		||||
                                            Category: 
 | 
			
		||||
                                        </font>
 | 
			
		||||
                                        <font size="1">
 | 
			
		||||
                                            @(ViewBag.Category)
 | 
			
		||||
                                        </font>
 | 
			
		||||
                                    </td>
 | 
			
		||||
                                </tr>
 | 
			
		||||
                                <tr>
 | 
			
		||||
                                    <td>
 | 
			
		||||
                                        <font size="2">
 | 
			
		||||
@ -97,7 +121,6 @@
 | 
			
		||||
                            </table>
 | 
			
		||||
                        </td>
 | 
			
		||||
                    </tr>
 | 
			
		||||
                
 | 
			
		||||
                </table>
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
@ -217,14 +240,13 @@
 | 
			
		||||
                        </td>
 | 
			
		||||
                    </tr>
 | 
			
		||||
 | 
			
		||||
                
 | 
			
		||||
                </table>
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
 | 
			
		||||
        <tr>
 | 
			
		||||
            <td>
 | 
			
		||||
            <table border="1" >
 | 
			
		||||
                <table border="1">
 | 
			
		||||
                    <tr bgcolor="#c4baba" color="#000000">
 | 
			
		||||
                        <td> Description of Change</td>
 | 
			
		||||
                        <td> Reason for Change</td>
 | 
			
		||||
@ -244,35 +266,6 @@
 | 
			
		||||
                </table>
 | 
			
		||||
            </td>
 | 
			
		||||
        </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>
 | 
			
		||||
            <td>
 | 
			
		||||
 | 
			
		||||
@ -286,7 +279,7 @@
 | 
			
		||||
                                PCRB:
 | 
			
		||||
                            </font>
 | 
			
		||||
                            <font size="1">
 | 
			
		||||
                            @(Model.PCRBRequired ? "Yes": "No")
 | 
			
		||||
                                @(Model.PCRBRequired ? "Yes" : "No")
 | 
			
		||||
                            </font>
 | 
			
		||||
                        </td>
 | 
			
		||||
                        <td>
 | 
			
		||||
@ -300,7 +293,7 @@
 | 
			
		||||
                                Metrology Change:   
 | 
			
		||||
                            </font>
 | 
			
		||||
                            <font size="1">
 | 
			
		||||
                            @(Model.MetrologyChangeRequired ? "Yes": "No")
 | 
			
		||||
                                @(Model.MetrologyChangeRequired ? "Yes" : "No")
 | 
			
		||||
                            </font>
 | 
			
		||||
                        </td>
 | 
			
		||||
                        <td>
 | 
			
		||||
@ -308,7 +301,7 @@
 | 
			
		||||
                                SPC Change:
 | 
			
		||||
                            </font>
 | 
			
		||||
                            <font size="1">
 | 
			
		||||
                            @(Model.SPCChangeRequired ? "Yes": "No")
 | 
			
		||||
                                @(Model.SPCChangeRequired ? "Yes" : "No")
 | 
			
		||||
                            </font>
 | 
			
		||||
                        </td>
 | 
			
		||||
                        <td>
 | 
			
		||||
@ -327,11 +320,35 @@
 | 
			
		||||
                                @(Model.SPNChangeRequired ? "Yes" : "No")
 | 
			
		||||
                            </font>
 | 
			
		||||
                        </td>
 | 
			
		||||
                    <td></td>
 | 
			
		||||
                    </tr>
 | 
			
		||||
                
 | 
			
		||||
                </table>
 | 
			
		||||
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
        <tr>
 | 
			
		||||
            <td>
 | 
			
		||||
 | 
			
		||||
                <table border="1">
 | 
			
		||||
                    <tr bgcolor="#c4baba" color="#000000">
 | 
			
		||||
                        <td colspan="1">Training Notification</td>
 | 
			
		||||
                    </tr>
 | 
			
		||||
                    <tr style="display:block;">
 | 
			
		||||
                        <td>
 | 
			
		||||
                            <font size="2">
 | 
			
		||||
                                Training:
 | 
			
		||||
                            </font>
 | 
			
		||||
                            <font size="1">
 | 
			
		||||
                                @(Model.TrainingRequired ? "Yes" : "No")
 | 
			
		||||
                            </font>
 | 
			
		||||
                        </td>
 | 
			
		||||
                        <td>
 | 
			
		||||
                            <font size="2">
 | 
			
		||||
                                Training Notification to:  
 | 
			
		||||
                                @(ViewBag.TrainingNotificationTo)
 | 
			
		||||
                            </font>
 | 
			
		||||
                        </td>
 | 
			
		||||
                    </tr>
 | 
			
		||||
                </table>
 | 
			
		||||
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
@ -479,19 +496,11 @@
 | 
			
		||||
                        </tr>
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                </table>
 | 
			
		||||
            </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
 | 
			
		||||
    </table>
 | 
			
		||||
</body>
 | 
			
		||||
 | 
			
		||||
</table> <!--main table -->
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
   
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
</html>
 | 
			
		||||
		Reference in New Issue
	
	Block a user