9 Commits

Author SHA1 Message Date
54799f54ec Add #if !NET8 back in to pass the .net core tests 2025-05-28 13:42:05 -07:00
65a433e9ab 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
2025-05-28 22:21:03 +02:00
8bae94de96 Merged PR 16782: Added logic to display Category and Training Notification fields on PDF
Added logic to display Category and Training Notification fields on PDF

Related work items: #135474, #225483
2025-05-19 22:20:00 +02:00
032c971472 Actually cancel ECNs upon cancel 2025-05-08 10:24:40 -07:00
704df4fa8c Restrict pipeline to only run for old site 2025-04-17 15:52:38 +00:00
e452047dfb PCRB Type field 2025-04-17 07:46:58 -07:00
bf3e46a784 fix redirect links 2025-04-02 12:10:43 -07:00
909f358356 fix email subject bug 2025-04-02 09:14:19 -07:00
b3fb328b98 Audit object was being passed as byref but getting re-instantiated within the method 2025-04-01 13:38:06 -07:00
22 changed files with 871 additions and 700 deletions

View File

@ -58,6 +58,7 @@ public class AuditController : Controller {
try {
bool isAdmin = (bool)Session[GlobalVars.IS_ADMIN];
int userId = (int)Session[GlobalVars.SESSION_USERID];
audit = auditDMO.GetAuditItem(issueID, userId);
AuditEdit auditEdit = auditDMO.GetAuditEdit(issueID, audit, isAdmin, userId);
if (auditEdit.RedirectToAction)
return RedirectToAction("ReadOnlyAudit", new { auditNo = audit.AuditNo });

View File

@ -52,7 +52,7 @@ public class ChangeControlController : Controller {
string encodedJwt = System.Net.WebUtility.UrlEncode(jwt);
string refreshToken = Session["RefreshToken"].ToString();
string encodedRefreshToken = System.Net.WebUtility.UrlEncode(refreshToken);
string mrbUrl = $"{GlobalVars.AppSettings.WasmClientUrl}/redirect?jwt={encodedJwt}&refreshToken={encodedRefreshToken}&redirectPath=/pcrb/{issueID}";
string mrbUrl = $"{GlobalVars.AppSettings.WasmClientUrl}/redirect?jwt={encodedJwt}&refreshToken={encodedRefreshToken}&redirectPath=pcrb/{issueID}";
return Redirect(mrbUrl);
}
@ -62,7 +62,7 @@ public class ChangeControlController : Controller {
string encodedJwt = System.Net.WebUtility.UrlEncode(jwt);
string refreshToken = Session["RefreshToken"].ToString();
string encodedRefreshToken = System.Net.WebUtility.UrlEncode(refreshToken);
string mrbUrl = $"{GlobalVars.AppSettings.WasmClientUrl}/redirect?jwt={encodedJwt}&refreshToken={encodedRefreshToken}&redirectPath=/pcrb/{issueID}";
string mrbUrl = $"{GlobalVars.AppSettings.WasmClientUrl}/redirect?jwt={encodedJwt}&refreshToken={encodedRefreshToken}&redirectPath=pcrb/{issueID}";
return Redirect(mrbUrl);
}

View File

@ -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);

View File

@ -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;

View File

@ -79,7 +79,7 @@ public class MRBController : Controller {
string encodedJwt = System.Net.WebUtility.UrlEncode(jwt);
string refreshToken = Session["RefreshToken"].ToString();
string encodedRefreshToken = System.Net.WebUtility.UrlEncode(refreshToken);
string mrbUrl = $"{GlobalVars.AppSettings.WasmClientUrl}/redirect?jwt={encodedJwt}&refreshToken={encodedRefreshToken}&redirectPath=/mrb/{issueID}";
string mrbUrl = $"{GlobalVars.AppSettings.WasmClientUrl}/redirect?jwt={encodedJwt}&refreshToken={encodedRefreshToken}&redirectPath=mrb/{issueID}";
return Redirect(mrbUrl);
}
@ -102,7 +102,7 @@ public class MRBController : Controller {
string encodedJwt = System.Net.WebUtility.UrlEncode(jwt);
string refreshToken = Session["RefreshToken"].ToString();
string encodedRefreshToken = System.Net.WebUtility.UrlEncode(refreshToken);
string mrbUrl = $"{GlobalVars.AppSettings.WasmClientUrl}/redirect?jwt={encodedJwt}&refreshToken={encodedRefreshToken}&redirectPath=/mrb/{issueID}";
string mrbUrl = $"{GlobalVars.AppSettings.WasmClientUrl}/redirect?jwt={encodedJwt}&refreshToken={encodedRefreshToken}&redirectPath=mrb/{issueID}";
return Redirect(mrbUrl);
}

View File

@ -401,7 +401,6 @@ public class AuditDMO {
result.Is8DQA = "true";
}
audit = GetAuditItem(issueID, userId);
// transform audit users from string to list, delimited by a comma.
if (audit.Auditees == null) {
result.AuditeeNames = new List<string>();

View File

@ -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;
}
}

View File

@ -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" />

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 (Document pdfDocument = new Document(PageSize.A4, HorizontalMargin, HorizontalMargin, VerticalMargin, VerticalMargin)) {
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 renderedBuffer;
#endif
return result;
}
}

View File

@ -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>();
}
}

View File

@ -1,497 +1,506 @@
@model Fab2ApprovalSystem.ViewModels.ECNPdf
<table style="width:100%;">
<tr>
<td>
<table cellpadding="3" cellspacing="3" border="1">
<tr bgcolor="#c4baba" color="#000000">
<td colspan="2">
@Model.Title
</td>
@{
Layout = null;
}
</tr>
<tr>
<td>
<table border="0">
@if (@Model.ConvertedFromNumber != null)
{
<tr>
<td>
ECN# @Model.ECNNumber (Converted from TECN#:@Model.ConvertedFromNumber)
</td>
</tr>
}
@if (@Model.ConvertedToNumber != null)
{
<tr>
<td>
ECN# @Model.ECNNumber (Converted to ECN#:@Model.ConvertedToNumber)
</td>
</tr>
}
@if (@Model.ConvertedFromNumber == null && @Model.ConvertedToNumber == null)
{
<tr>
<td>
ECN# @Model.ECNNumber
</td>
</tr>
}
<!DOCTYPE html>
<tr>
<td>
<font size="2">
Submit Date#:&nbsp;
</font>
<font size="1">
@Model.SubmitedDate
</font>
</td>
</tr>
<tr>
<td>
<font size="2">
Originator Name:&nbsp;
</font>
<font size="1">
@Model.OriginatorName
</font>
</td>
</tr>
</table>
</td>
<td>
<table border="0">
@*<tr>
<td>
<font size="2">
Affected Department:&nbsp;
</font>
<font size="1">
@Model.AffectedDepartments
</font>
</td>
<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>
</tr>*@
<tr>
<td>
<font size="2">
Affected Area:&nbsp;
</font>
<font size="1">
@Model.AffectedModules
@*@Model.AffectedAreas*@
</font>
</td>
</tr>
<tr>
<td>
<font size="2">
ITAR/EC:&nbsp;
</font>
<font size="1">
@(Model.IsDocEC ? "Yes" : "No")
</font>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table border="1">
<tr bgcolor="#c4baba" color="#000000">
<td> ECN - TECN Details</td>
</tr>
<tr>
<td>
<table border="0">
<tr>
<td>
<font size="2">
ECN: &nbsp;
</font>
<font size="1">
@(Model.IsECN ? "Yes" : "No")
</font>
</td>
<td>
<font size="2">
TECN:&nbsp;
@(Model.IsTECN ? "Yes" : "No")
</font>
</td>
<td>
<font size="2">
Emergency: &nbsp;
</font>
<font size="1">
@(Model.IsEmergencyTECN ? "Yes" : "No")
</font>
</td>
</tr>
<tr>
<td>
<font size="2">
Expiration Date:
</font>
<font size="1">
@Convert.ToString(string.Format("{0:MM/dd/yyyy}", Model.ExpirationDate))
</font>
</td>
<td>
<font size="2">
Extension Date:
</font>
<font size="1">
@Convert.ToString(string.Format("{0:MM/dd/yyyy}", @Model.ExtensionDate))
</font>
</td>
<td>
<font size="2">
Cancellation Date:
</font>
<font size="1">
@Model.CancellationApprovalDate
</font>
</td>
</tr>
<tr>
<td>
<font size="2">
# lots affected:
</font>
<font size="1">
@Model.NumberOfLotsAffected
</font>
</td>
<td>
<font size="2">
Recipe Or/And Flow Change:
</font>
<font size="1">
@Model.RecipeChange
</font>
</td>
<td>
<font size="2">
Affected product families:
</font>
<font size="1">
@Model.AffectedProductFamilies
</font>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table border="0">
<tr>
<td colspan="3" style="background-color:ActiveCaption">
<font size="2">
Affected Documents:&nbsp;
</font>
<body class="navbar-inner">
<table style="width:100%;">
<tr>
<td>
<table cellpadding="3" cellspacing="3" border="1">
<tr bgcolor="#c4baba" color="#000000">
<td colspan="2">
@Model.Title
</td>
</td>
</tr>
<tr>
@foreach (string attachmentName in Model.Attachments)
</tr>
<tr>
<td>
<table border="0">
@if (@Model.ConvertedFromNumber != null)
{
<td colspan="3">
<tr>
<td>
ECN# @Model.ECNNumber (Converted from TECN#:@Model.ConvertedFromNumber)
</td>
</tr>
}
@if (@Model.ConvertedToNumber != null)
{
<tr>
<td>
ECN# @Model.ECNNumber (Converted to ECN#:@Model.ConvertedToNumber)
</td>
</tr>
}
@if (@Model.ConvertedFromNumber == null && @Model.ConvertedToNumber == null)
{
<tr>
<td>
ECN# @Model.ECNNumber
</td>
</tr>
}
<tr>
<td>
<font size="2">
Submit Date#:&nbsp;
</font>
<font size="1">
@attachmentName
@Model.SubmitedDate
</font>
</td>
}
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table border="1" >
<tr bgcolor="#c4baba" color="#000000">
<td> Description of Change</td>
<td> Reason for Change</td>
</tr>
<tr>
<td>
<font size="1">
@Html.Raw(@Model.DescriptionOfChange)
</font>
</td>
<td>
<font size="1">
@Html.Raw(@Model.ReasonForChange)
</font>
</td>
</tr>
</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>
<table border="1">
<tr bgcolor="#c4baba" color="#000000">
<td colspan="5">Systems</td>
</tr>
<tr style="display:block;">
<td>
<font size="2">
PCRB:
</font>
<font size="1">
@(Model.PCRBRequired ? "Yes": "No")
</font>
</td>
<td>
<font size="2">
PCRB#: &nbsp;
@Model.PCRBNumber
</font>
</td>
<td>
<font size="2">
Metrology Change: &nbsp;&nbsp;
</font>
<font size="1">
@(Model.MetrologyChangeRequired ? "Yes": "No")
</font>
</td>
<td>
<font size="2">
SPC Change:
</font>
<font size="1">
@(Model.SPCChangeRequired ? "Yes": "No")
</font>
</td>
<td>
<font size="2">
FI Change:
</font>
<font size="1">
@(Model.FIChangeRequired ? "Yes" : "No")
</font>
</td>
<td>
<font size="2">
OI Change:
</font>
<font size="1">
@(Model.SPNChangeRequired ? "Yes" : "No")
</font>
</td>
<td></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table border="1">
<tr bgcolor="#c4baba" color="#000000">
<td colspan="4"> Change Impact</td>
</tr>
<tr>
<td>
<table border="0">
<tr>
<td>
<font size="2">
Impact On ESH:
</font>
<font size="1">
@if (Model.ImpactOnEnvironment == 1)
{
@: Positive
}
else if (Model.ImpactOnEnvironment == 2)
{
@: Negative
}
else
{
@: N/A
}
</font>
</td>
</tr>
<tr>
<td>
<font size="1">
@Html.Raw(@Model.ImpactOnEnvironmentDescription)
</tr>
<tr>
<td>
<font size="2">
Originator Name:&nbsp;
</font>
</td>
</tr>
</table>
</td>
<td>
<table border="0">
<tr>
<td>
<font size="2">
Impact On Capacity:
</font>
<font size="1">
@(Model.ImpactOnCapacity == 1 ? "Yes" : "No")
</font>
</td>
</tr>
<tr>
<td>
<font size="1">
@Html.Raw(@Model.ImpactOnCapacityDescription)
<font size="1">
@Model.OriginatorName
</font>
</td>
</tr>
</table>
</td>
<td>
@*<table border="0">
<tr>
<td>
<font size="2">
RH(ITAR):
</font>
<font size="1">
@(Model.IsRH ? "Yes" : "No")
</font>
</td>
</tr>
</table>*@
</td>
<td>
<table border="0">
<tr>
<td>
<font size="2">
Material Consumption Change:
</font>
<font size="1">
@(Model.MaterialConsumptionChangeRequired == 1 ? "Yes" : "No")
</font>
</td>
</tr>
<tr>
<td>
<font size="1">
@Html.Raw(@Model.MaterialConsumptionChangeDescription)
</font>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table border="1">
<tr bgcolor="#c4baba" color="#ffffff">
<td>
Full Name
</td>
<td>
Role
</td>
<td>
Approved/Denied
</td>
<td>
Date Time
</td>
</tr>
</td>
</tr>
@foreach (Fab2ApprovalSystem.ViewModels.ECNApprovalLog ecnApp in Model.Approvalog)
{
</table>
</td>
<td>
<table border="0">
@*<tr>
<td>
<font size="2">
Affected Department:&nbsp;
</font>
<font size="1">
@Model.AffectedDepartments
</font>
</td>
</tr>*@
<tr>
<td>
<font size="2">
Affected Area:&nbsp;
</font>
<font size="1">
@Model.AffectedModules
@*@Model.AffectedAreas*@
</font>
</td>
</tr>
<tr>
<td>
<font size="2">
Category:&nbsp;
</font>
<font size="1">
@(ViewBag.Category)
</font>
</td>
</tr>
<tr>
<td>
<font size="2">
ITAR/EC:&nbsp;
</font>
<font size="1">
@(Model.IsDocEC ? "Yes" : "No")
</font>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table border="1">
<tr bgcolor="#c4baba" color="#000000">
<td> ECN - TECN Details</td>
</tr>
<tr>
<td>
<table border="0">
<tr>
<td>
<font size="2">
ECN: &nbsp;
</font>
<font size="1">
@(Model.IsECN ? "Yes" : "No")
</font>
</td>
<td>
<font size="2">
TECN:&nbsp;
@(Model.IsTECN ? "Yes" : "No")
</font>
</td>
<td>
<font size="2">
Emergency: &nbsp;
</font>
<font size="1">
@(Model.IsEmergencyTECN ? "Yes" : "No")
</font>
</td>
</tr>
<tr>
<td>
<font size="2">
Expiration Date:
</font>
<font size="1">
@Convert.ToString(string.Format("{0:MM/dd/yyyy}", Model.ExpirationDate))
</font>
</td>
<td>
<font size="2">
Extension Date:
</font>
<font size="1">
@Convert.ToString(string.Format("{0:MM/dd/yyyy}", @Model.ExtensionDate))
</font>
</td>
<td>
<font size="2">
Cancellation Date:
</font>
<font size="1">
@Model.CancellationApprovalDate
</font>
</td>
</tr>
<tr>
<td>
<font size="2">
# lots affected:
</font>
<font size="1">
@Model.NumberOfLotsAffected
</font>
</td>
<td>
<font size="2">
Recipe Or/And Flow Change:
</font>
<font size="1">
@Model.RecipeChange
</font>
</td>
<td>
<font size="2">
Affected product families:
</font>
<font size="1">
@Model.AffectedProductFamilies
</font>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table border="0">
<tr>
<td colspan="3" style="background-color:ActiveCaption">
<font size="2">
Affected Documents:&nbsp;
</font>
</td>
</tr>
<tr>
@foreach (string attachmentName in Model.Attachments)
{
<td colspan="3">
<font size="1">
@attachmentName
</font>
</td>
}
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table border="1">
<tr bgcolor="#c4baba" color="#000000">
<td> Description of Change</td>
<td> Reason for Change</td>
</tr>
<tr>
<td>
<font size="1">
@ecnApp.FullName
@Html.Raw(@Model.DescriptionOfChange)
</font>
</td>
<td>
<font size="1">
@ecnApp.SubRole
</font>
</td>
<td>
<font size="1">
@ecnApp.Operation
</font>
</td>
<td>
<font size="1">
@ecnApp.OperationTime
@Html.Raw(@Model.ReasonForChange)
</font>
</td>
</tr>
}
</table>
</td>
</tr>
<tr>
<td>
<table border="1">
<tr bgcolor="#c4baba" color="#000000">
<td colspan="5">Systems</td>
</tr>
<tr style="display:block;">
<td>
<font size="2">
PCRB:
</font>
<font size="1">
@(Model.PCRBRequired ? "Yes" : "No")
</font>
</td>
<td>
<font size="2">
PCRB#: &nbsp;
@Model.PCRBNumber
</font>
</td>
<td>
<font size="2">
Metrology Change: &nbsp;&nbsp;
</font>
<font size="1">
@(Model.MetrologyChangeRequired ? "Yes" : "No")
</font>
</td>
<td>
<font size="2">
SPC Change:
</font>
<font size="1">
@(Model.SPCChangeRequired ? "Yes" : "No")
</font>
</td>
<td>
<font size="2">
FI Change:
</font>
<font size="1">
@(Model.FIChangeRequired ? "Yes" : "No")
</font>
</td>
<td>
<font size="2">
OI Change:
</font>
<font size="1">
@(Model.SPNChangeRequired ? "Yes" : "No")
</font>
</td>
</tr>
</table>
</table>
</td>
</tr>
</td>
</tr>
<tr>
<td>
</table> <!--main table -->
<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: &nbsp;
@(ViewBag.TrainingNotificationTo)
</font>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table border="1">
<tr bgcolor="#c4baba" color="#000000">
<td colspan="4"> Change Impact</td>
</tr>
<tr>
<td>
<table border="0">
<tr>
<td>
<font size="2">
Impact On ESH:
</font>
<font size="1">
@if (Model.ImpactOnEnvironment == 1)
{
@: Positive
}
else if (Model.ImpactOnEnvironment == 2)
{
@: Negative
}
else
{
@: N/A
}
</font>
</td>
</tr>
<tr>
<td>
<font size="1">
@Html.Raw(@Model.ImpactOnEnvironmentDescription)
</font>
</td>
</tr>
</table>
</td>
<td>
<table border="0">
<tr>
<td>
<font size="2">
Impact On Capacity:
</font>
<font size="1">
@(Model.ImpactOnCapacity == 1 ? "Yes" : "No")
</font>
</td>
</tr>
<tr>
<td>
<font size="1">
@Html.Raw(@Model.ImpactOnCapacityDescription)
</font>
</td>
</tr>
</table>
</td>
<td>
@*<table border="0">
<tr>
<td>
<font size="2">
RH(ITAR):
</font>
<font size="1">
@(Model.IsRH ? "Yes" : "No")
</font>
</td>
</tr>
</table>*@
</td>
<td>
<table border="0">
<tr>
<td>
<font size="2">
Material Consumption Change:
</font>
<font size="1">
@(Model.MaterialConsumptionChangeRequired == 1 ? "Yes" : "No")
</font>
</td>
</tr>
<tr>
<td>
<font size="1">
@Html.Raw(@Model.MaterialConsumptionChangeDescription)
</font>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table border="1">
<tr bgcolor="#c4baba" color="#ffffff">
<td>
Full Name
</td>
<td>
Role
</td>
<td>
Approved/Denied
</td>
<td>
Date Time
</td>
</tr>
@foreach (Fab2ApprovalSystem.ViewModels.ECNApprovalLog ecnApp in Model.Approvalog)
{
<tr>
<td>
<font size="1">
@ecnApp.FullName
</font>
</td>
<td>
<font size="1">
@ecnApp.SubRole
</font>
</td>
<td>
<font size="1">
@ecnApp.Operation
</font>
</td>
<td>
<font size="1">
@ecnApp.OperationTime
</font>
</td>
</tr>
}
</table>
</td>
</tr>
</table>
</body>
</html>

View File

@ -90,16 +90,16 @@
string encodedRefreshToken = System.Net.WebUtility.UrlEncode(refreshToken);
string wasmClientUrl = Environment.GetEnvironmentVariable("FabApprovalWasmClientUrl") ??
"https://localhost:7255";
string mrbUrl = wasmClientUrl + "/redirect?jwt=" + encodedJwt + "&refreshToken=" + encodedRefreshToken + "&redirectPath=/mrb/new";
string mrbUrl = wasmClientUrl + "/redirect?jwt=" + encodedJwt + "&refreshToken=" + encodedRefreshToken + "&redirectPath=mrb/new";
<li><a href="@mrbUrl">Create MRB</a></li>
string pcrbUrl = wasmClientUrl + "/redirect?jwt=" + encodedJwt + "&refreshToken=" + encodedRefreshToken + "&redirectPath=/pcrb/new";
string pcrbUrl = wasmClientUrl + "/redirect?jwt=" + encodedJwt + "&refreshToken=" + encodedRefreshToken + "&redirectPath=pcrb/new";
<li><a href="@pcrbUrl">Create PCRB</a></li>
} else {
string wasmClientUrl = Environment.GetEnvironmentVariable("FabApprovalWasmClientUrl") ??
"https://localhost:7255";
string mrbUrl = wasmClientUrl + "/redirect?redirectPath=/mrb/new";
string mrbUrl = wasmClientUrl + "/redirect?redirectPath=mrb/new";
<li><a href="@mrbUrl">Create MRB</a></li>
string pcrbUrl = wasmClientUrl + "/redirect?redirectPath=/pcrb/new";
string pcrbUrl = wasmClientUrl + "/redirect?redirectPath=pcrb/new";
<li><a href="@pcrbUrl">Create PCRB</a></li>
}
@*<li><a href=@Url.Action("CreateWorkRequest", "LotTraveler")>Create Special Work Request</a></li>*@
@ -150,9 +150,9 @@
string encodedRefreshToken = System.Net.WebUtility.UrlEncode(refreshToken);
string wasmClientUrl = Environment.GetEnvironmentVariable("FabApprovalWasmClientUrl") ??
"https://localhost:7255";
string mrbUrl = wasmClientUrl + "/redirect?jwt=" + encodedJwt + "&refreshToken=" + encodedRefreshToken + "&redirectPath=/mrb/all";
string mrbUrl = wasmClientUrl + "/redirect?jwt=" + encodedJwt + "&refreshToken=" + encodedRefreshToken + "&redirectPath=mrb/all";
menu.Add().Text("MRB").Url(mrbUrl);
string pcrbUrl = wasmClientUrl + "/redirect?jwt=" + encodedJwt + "&refreshToken=" + encodedRefreshToken + "&redirectPath=/pcrb/all";
string pcrbUrl = wasmClientUrl + "/redirect?jwt=" + encodedJwt + "&refreshToken=" + encodedRefreshToken + "&redirectPath=pcrb/all";
menu.Add().Text("PCRB").Url(pcrbUrl);
//menu.Add().Text("Special Work Requests").Action("SpecialWorkRequestList", "Home");
//menu.Add().Text("PCRB").Action("ChangeControlList", "Home");

View File

@ -1,3 +1,11 @@
trigger:
branches:
include:
- master
paths:
include:
- Fab2ApprovalSystem
variables:
coreVersion: "net8.0"
targetFrameworkVersion: "v4.8"

View File

@ -51,7 +51,7 @@ public class AuditDMOTests {
try { throw new Exception(); } catch (Exception) { }
}
private static void AuditDMO(ILogger? logger, AppSettings appSettings) {
private static void AuditDMO(ILogger? logger, AppSettings appSettings, int auditNo, bool isAdmin) {
#pragma warning disable IDE0059
SetGlobalVars(logger, appSettings);
AuditDMO auditDMO = new(appSettings);
@ -61,25 +61,25 @@ public class AuditDMOTests {
AuditedArea[] auditedAreas = auditDMO.GetAuditAreaList().ToArray();
// IEnumerable<int> GetAuditFindingCategoryIdsByFindingId(int auditFindingsID);
// AuditFindings GetAuditFindingsByID(int auditFindingsID);
// IEnumerable<AuditFindings> GetAuditFindingsList(int auditNo);
// Audit GetAuditItem(int auditNo, appSettings.UserId);
// Audit GetAuditItemReadOnly(int auditNo, appSettings.UserId);
AuditFindings[] auditFindings = auditDMO.GetAuditFindingsList(auditNo).ToArray();
Audit auditB = auditDMO.GetAuditItem(auditNo, appSettings.UserId);
Audit auditC = new();
AuditEdit auditEdit = auditDMO.GetAuditEdit(auditNo, auditC, isAdmin, appSettings.UserId);
Audit auditD = auditDMO.GetAuditItemReadOnly(auditNo, appSettings.UserId);
Auditor[] auditors = auditDMO.GetAuditorList().ToArray();
// IEnumerable<AuditReportAttachment> GetAuditReportAttachments(int auditNo);
AuditReportAttachment[] auditReportAttachments = auditDMO.GetAuditReportAttachments(auditNo).ToArray();
// C_8DAuditedStandard[] c_8DAuditedStandards = auditDMO.GetAuditStandardList().ToArray();
AuditType[] auditTypes = auditDMO.GetAuditTypeList().ToArray();
// CAFindings GetCAFindingsItem(int caFindingsID);
// IEnumerable<AuditReportAttachment> GetCAFindingsItemAttachments(int caFindingsID);
// IEnumerable<CAFindings> GetCAFindingsList(int auditNo);
CAFindings[] caFindings = auditDMO.GetCAFindingsList(auditNo).ToArray();
CANoList[] cANoLists = auditDMO.GetCorrectiveActionNoList().ToArray();
// int GetOpenCACountByAuditNo(int auditNo);
int openCACountByAuditNo = auditDMO.GetOpenCACountByAuditNo(auditNo);
CAUserList[] cAUserLists = auditDMO.GetUserList().ToArray();
// Audit InsertAudit(Audit audit);
// void InsertAuditReportAttachment(AuditReportAttachment attach);
// void InsertCAFindings(CAFindings model);
// int IsCAAssignedToAudit(int CANo, int auditNo);
// void ReleaseLockOnDocument(appSettings.UserId, int issueID);
// void UpdateAudit(Audit audit, appSettings.UserId);
// void UpdateCAFindings(CAFindings model);
if (auditDMO is null) { }
#pragma warning restore IDE0059
@ -89,13 +89,14 @@ public class AuditDMOTests {
[Ignore]
#endif
[TestMethod]
public void AuditDMOIsAttachedOnly() {
[DataRow(250, true)]
public void AuditDMOIsAttachedOnly(int auditNo, bool isAdmin) {
_Logger?.LogInformation("Starting Web Application");
IServiceProvider? serviceProvider = _WebApplicationFactory?.Services.CreateScope().ServiceProvider;
AppSettings? appSettings = serviceProvider?.GetRequiredService<AppSettings>();
Assert.IsTrue(appSettings is not null);
if (System.Diagnostics.Debugger.IsAttached)
AuditDMO(_Logger, appSettings);
AuditDMO(_Logger, appSettings, auditNo, isAdmin);
_Logger?.LogInformation("{TestName} completed", _TestContext?.TestName);
NonThrowTryCatch();
}

View File

@ -25,25 +25,33 @@ public static class MockMemoryCacheService {
public class PCRBServiceTests {
private readonly Mock<ILogger<PCRBService>> _loggerMock;
private readonly Mock<IDalService> _dalServiceMock;
private readonly Mock<IMemoryCache> _cacheMock;
private Mock<IMemoryCache> _cacheMock;
private readonly Mock<IUserService> _userServiceMock;
private readonly Mock<IApprovalService> _approvalServiceMock;
private readonly Mock<ISmtpService> _smtpServiceMock;
private readonly PCRBService _pcrbService;
private PCRBService _pcrbService;
private static IEnumerable<PCRB> PCRBS = new List<PCRB>() {
new PCRB {
PlanNumber = 1,
OwnerID = 1,
Title = "Test Title",
ChangeLevel = "Level 1",
ReasonForChange = "Test Reason",
ChangeDescription = "Test Description",
IsITAR = false,
CurrentStep = 1,
InsertTimeStamp = DateTime.Now,
LastUpdateDate = DateTime.Now,
Type = "Type 1"
}
};
private static IEnumerable<PCRBFollowUp> FOLLOW_UPS = new List<PCRBFollowUp>() {
new PCRBFollowUp { ID = 1, PlanNumber = 1, Step = 1, FollowUpDate = DateTime.Now }
};
public PCRBServiceTests() {
_loggerMock = new Mock<ILogger<PCRBService>>();
_dalServiceMock = new Mock<IDalService>();
_userServiceMock = new Mock<IUserService>();
_approvalServiceMock = new Mock<IApprovalService>();
_smtpServiceMock = new Mock<ISmtpService>();
_cacheMock = MockMemoryCacheService.GetMemoryCache(FOLLOW_UPS);
var appSettings = new AppSettings(
private static AppSettings appSettings = new AppSettings(
Company: "Infineon",
DbConnectionString: "connectionString",
JwtAudience: "audience",
@ -56,6 +64,14 @@ public class PCRBServiceTests {
WorkingDirectoryName: "workingDirectoryName"
);
public PCRBServiceTests() {
_loggerMock = new Mock<ILogger<PCRBService>>();
_dalServiceMock = new Mock<IDalService>();
_userServiceMock = new Mock<IUserService>();
_approvalServiceMock = new Mock<IApprovalService>();
_smtpServiceMock = new Mock<ISmtpService>();
_cacheMock = MockMemoryCacheService.GetMemoryCache(FOLLOW_UPS);
_pcrbService = new PCRBService(
_loggerMock.Object,
_dalServiceMock.Object,
@ -67,6 +83,161 @@ public class PCRBServiceTests {
);
}
[Fact]
public async Task CreateNewPCRB_WithValidParam_ShouldCreatePCRB() {
var pcrb = new PCRB {
OwnerID = 1,
Title = "Test Title",
ChangeLevel = "Level 1",
ReasonForChange = "Test Reason",
ChangeDescription = "Test Description",
IsITAR = false,
CurrentStep = 1,
InsertTimeStamp = DateTime.Now,
LastUpdateDate = DateTime.Now,
Type = "Type 1"
};
_dalServiceMock.Setup(d => d.ExecuteAsync(It.IsAny<string>(), pcrb))
.ReturnsAsync(1);
await _pcrbService.CreateNewPCRB(pcrb);
_dalServiceMock.Verify(d => d.ExecuteAsync(It.IsAny<string>(), pcrb), Times.Once);
}
[Fact]
public async Task CreateNewPCRB_WithNullParam_ShouldThrowException() {
await Assert.ThrowsAsync<ArgumentNullException>(() => _pcrbService.CreateNewPCRB(null));
}
[Fact]
public async Task CreateNewPCRB_WithDatabaseFailure_ShouldThrowException() {
var pcrb = new PCRB {
OwnerID = 1,
Title = "Test Title",
ChangeLevel = "Level 1",
ReasonForChange = "Test Reason",
ChangeDescription = "Test Description",
IsITAR = false,
CurrentStep = 1,
InsertTimeStamp = DateTime.Now,
LastUpdateDate = DateTime.Now,
Type = "Type 1"
};
_dalServiceMock.Setup(d => d.ExecuteAsync(It.IsAny<string>(), pcrb))
.ReturnsAsync(0);
await Assert.ThrowsAsync<Exception>(() => _pcrbService.CreateNewPCRB(pcrb));
}
[Fact]
public async Task CreateNewPCRB_WithDatabaseException_ShouldThrowException() {
var pcrb = new PCRB {
OwnerID = 1,
Title = "Test Title",
ChangeLevel = "Level 1",
ReasonForChange = "Test Reason",
ChangeDescription = "Test Description",
IsITAR = false,
CurrentStep = 1,
InsertTimeStamp = DateTime.Now,
LastUpdateDate = DateTime.Now,
Type = "Type 1"
};
_dalServiceMock.Setup(d => d.ExecuteAsync(It.IsAny<string>(), pcrb))
.Throws<Exception>();
await Assert.ThrowsAsync<Exception>(() => _pcrbService.CreateNewPCRB(pcrb));
}
[Fact]
public async Task UpdatePCRB_WithValidParam_ShouldUpdatePCRB() {
_cacheMock = MockMemoryCacheService.GetMemoryCache(PCRBS);
_pcrbService = new PCRBService(
_loggerMock.Object,
_dalServiceMock.Object,
_cacheMock.Object,
_userServiceMock.Object,
_approvalServiceMock.Object,
_smtpServiceMock.Object,
appSettings
);
var pcrb = new PCRB {
PlanNumber = 1,
OwnerID = 1,
Title = "Test Title",
ChangeLevel = "Level 1",
ReasonForChange = "Test Reason",
ChangeDescription = "Test Description",
IsITAR = false,
CurrentStep = 1,
LastUpdateDate = DateTime.Now,
ClosedDate = DateTime.Now,
Type = "Type 1"
};
_dalServiceMock.Setup(d => d.ExecuteAsync(It.IsAny<string>(), pcrb))
.ReturnsAsync(1);
await _pcrbService.UpdatePCRB(pcrb);
_dalServiceMock.Verify(d => d.ExecuteAsync(It.IsAny<string>(), pcrb), Times.Once);
}
[Fact]
public async Task UpdatePCRB_WithNullParam_ShouldThrowException() {
await Assert.ThrowsAsync<ArgumentNullException>(() => _pcrbService.UpdatePCRB(null));
}
[Fact]
public async Task UpdatePCRB_WithDatabaseFailure_ShouldThrowException() {
var pcrb = new PCRB {
PlanNumber = 1,
OwnerID = 1,
Title = "Test Title",
ChangeLevel = "Level 1",
ReasonForChange = "Test Reason",
ChangeDescription = "Test Description",
IsITAR = false,
CurrentStep = 1,
LastUpdateDate = DateTime.Now,
ClosedDate = DateTime.Now,
Type = "Type 1"
};
_dalServiceMock.Setup(d => d.ExecuteAsync(It.IsAny<string>(), pcrb))
.ReturnsAsync(0);
await Assert.ThrowsAsync<Exception>(() => _pcrbService.UpdatePCRB(pcrb));
}
[Fact]
public async Task UpdatePCRB_WithDatabaseException_ShouldThrowException() {
var pcrb = new PCRB {
PlanNumber = 1,
OwnerID = 1,
Title = "Test Title",
ChangeLevel = "Level 1",
ReasonForChange = "Test Reason",
ChangeDescription = "Test Description",
IsITAR = false,
CurrentStep = 1,
LastUpdateDate = DateTime.Now,
ClosedDate = DateTime.Now,
Type = "Type 1"
};
_dalServiceMock.Setup(d => d.ExecuteAsync(It.IsAny<string>(), pcrb))
.Throws<Exception>();
await Assert.ThrowsAsync<Exception>(() => _pcrbService.UpdatePCRB(pcrb));
}
[Fact]
public async Task CreateFollowUp_WithValidParam_ShouldCreateFollowUp() {
var followUp = new PCRBFollowUp {

View File

@ -15,6 +15,8 @@ public class SmtpClientWrapper : ISmtpClientWrapper {
}
public void Send(MailMessage message) {
message.Subject = message.Subject.Replace('\r', ' ').Replace('\n', ' ');
_client.Send(message);
}
}

View File

@ -78,16 +78,15 @@ public class PCRBService : IPCRBService {
if (pcrb is null) throw new ArgumentNullException("PCRB cannot be null");
pcrb.LastUpdateDate = DateTime.Now;
StringBuilder queryBuilder = new();
queryBuilder.Append("insert into CCChangeControl (OwnerID, Title, ChangeLevel, ReasonForChange, ");
queryBuilder.Append("ChangeDescription, IsITAR, CurrentStep, InsertTimeStamp, LastUpdateDate) ");
queryBuilder.Append($"values ({pcrb.OwnerID}, '{pcrb.Title}', '{pcrb.ChangeLevel}', ");
queryBuilder.Append($"'{pcrb.ReasonForChange}', '{pcrb.ChangeDescription}', ");
queryBuilder.Append($"{Convert.ToInt32(pcrb.IsITAR)}, {pcrb.CurrentStep}, ");
queryBuilder.Append($"'{pcrb.InsertTimeStamp.ToString("yyyy-MM-dd HH:mm:ss")}', ");
queryBuilder.Append($"'{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')");
queryBuilder.Append("ChangeDescription, IsITAR, CurrentStep, InsertTimeStamp, LastUpdateDate, Type) ");
queryBuilder.Append("values (@OwnerID, @Title, @ChangeLevel, @ReasonForChange, @ChangeDescription, ");
queryBuilder.Append("@IsITAR, @CurrentStep, @InsertTimeStamp, @LastUpdateDate, @Type)");
int rowsCreated = await _dalService.ExecuteAsync(queryBuilder.ToString());
int rowsCreated = await _dalService.ExecuteAsync(queryBuilder.ToString(), pcrb);
if (rowsCreated <= 0) throw new Exception("unable to insert new PCRB in the database");
} catch (Exception ex) {
@ -198,18 +197,16 @@ public class PCRBService : IPCRBService {
if (pcrb is null) throw new ArgumentNullException("PCRB cannot be null");
StringBuilder queryBuilder = new();
queryBuilder.Append($"update CCChangeControl set OwnerID={pcrb.OwnerID}, ");
queryBuilder.Append($"Title='{pcrb.Title.Replace("'", "''")}', ChangeLevel='{pcrb.ChangeLevel}', ");
queryBuilder.Append($"CurrentStep={pcrb.CurrentStep}, ReasonForChange='{pcrb.ReasonForChange.Replace("'", "''")}', ");
queryBuilder.Append($"ChangeDescription='{pcrb.ChangeDescription.Replace("'", "''")}', ");
queryBuilder.Append($"IsITAR={Convert.ToInt32(pcrb.IsITAR)}, ");
queryBuilder.Append($"InsertTimeStamp='{pcrb.InsertTimeStamp.ToString("yyyy-MM-dd HH:mm:ss")}', ");
queryBuilder.Append($"ClosedDate='{pcrb.ClosedDate.ToString("yyyy-MM-dd HH:mm:ss")}', ");
queryBuilder.Append($"LastUpdateDate='{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}' ");
queryBuilder.Append($"where PlanNumber={pcrb.PlanNumber}");
pcrb.LastUpdateDate = DateTime.Now;
int rowsAffected = await _dalService.ExecuteAsync(queryBuilder.ToString());
StringBuilder queryBuilder = new();
queryBuilder.Append("update CCChangeControl set OwnerID=@OwnerID, Title=@Title, ChangeLevel=@ChangeLevel, ");
queryBuilder.Append("Type=@Type, CurrentStep=@CurrentStep, ReasonForChange=@ReasonForChange, ");
queryBuilder.Append("ChangeDescription=@ChangeDescription, IsITAR=@IsITAR, ClosedDate=@ClosedDate, ");
queryBuilder.Append("LastUpdateDate=@LastUpdateDate ");
queryBuilder.Append($"where PlanNumber=@PlanNumber");
int rowsAffected = await _dalService.ExecuteAsync(queryBuilder.ToString(), pcrb);
if (rowsAffected <= 0) throw new Exception("unable to perform update in database");

View File

@ -137,6 +137,20 @@
<MudSelectItem Value="@("Other Site + Mesa - Class 2")" />
<MudSelectItem Value="@("Mesa - Class 3")" />
</MudSelect>
<MudSelect T="string"
Variant="Variant.Outlined"
Required
Clearable
AnchorOrigin="Origin.BottomCenter"
Disabled="@pcrbIsSubmitted"
@bind-Value="@pcrb.Type"
Text="@pcrb.Type"
Label="Change Type">
<MudSelectItem Value="@("Cost Savings")" />
<MudSelectItem Value="@("Process Efficiency")" />
<MudSelectItem Value="@("Process Improvement")" />
<MudSelectItem Value="@("Business Continuity")" />
</MudSelect>
<MudCheckBox Disabled="@pcrbIsSubmitted"
Color="Color.Tertiary"
@bind-Value=pcrb.IsITAR
@ -152,6 +166,11 @@
Value="@DateTimeUtilities.GetDateAsStringMinDefault(pcrb.LastUpdateDate)"
Label="Last Update"
Variant="Variant.Outlined" />
<MudTextField Disabled="true"
T="string"
Value="@DateTimeUtilities.GetDateAsStringMaxDefault(pcrb.ClosedDate)"
Label="Complete Date"
Variant="Variant.Outlined" />
</MudPaper>
<MudPaper Outlined="true"

View File

@ -23,4 +23,5 @@ public class PCRB {
public DateTime InsertTimeStamp { get; set; } = DateTimeUtilities.MIN_DT;
public DateTime LastUpdateDate { get; set; } = DateTimeUtilities.MIN_DT;
public DateTime ClosedDate { get; set; } = DateTimeUtilities.MAX_DT;
public string Type { get; set; } = "";
}