Added HttpException class for missing HttpException for net8 Wrapped HttpContext.Session, GetJsonResult, IsAjaxRequest and GetUserIdentityName in controllers for net8 Added AuthenticationService to test Fab2ApprovalMKLink code for net8 Compile conditionally flags to debug in dotnet core
770 lines
30 KiB
C#
770 lines
30 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Text;
|
|
#if !NET8
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using System.Web.Script.Serialization;
|
|
#endif
|
|
|
|
#if NET8
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
#endif
|
|
|
|
using Fab2ApprovalSystem.DMO;
|
|
using Fab2ApprovalSystem.Misc;
|
|
using Fab2ApprovalSystem.Models;
|
|
using Fab2ApprovalSystem.ViewModels;
|
|
|
|
#if !NET8
|
|
using System.Dynamic;
|
|
using System.Threading;
|
|
using System.Configuration;
|
|
#endif
|
|
|
|
#if !NET8
|
|
using Kendo.Mvc.Extensions;
|
|
using Kendo.Mvc.UI;
|
|
#endif
|
|
|
|
namespace Fab2ApprovalSystem.Controllers;
|
|
|
|
[Authorize]
|
|
#if !NET8
|
|
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
|
|
[SessionExpireFilter]
|
|
#endif
|
|
#if NET8
|
|
[Route("[controller]")]
|
|
#endif
|
|
public class MRBController : Controller {
|
|
|
|
private readonly MRB_DMO mrbDMO = new(GlobalVars.AppSettings);
|
|
private readonly WorkflowDMO wfDMO = new();
|
|
private readonly CredentialsStorage credentialsStorage = new();
|
|
private readonly AppSettings _AppSettings = GlobalVars.AppSettings;
|
|
|
|
// GET: /MRB/
|
|
public ActionResult Index() {
|
|
return View();
|
|
}
|
|
|
|
// GET: /MRB/Details/5
|
|
public ActionResult Details(int id) {
|
|
return View();
|
|
}
|
|
|
|
// GET: /MRB/Create
|
|
public ActionResult Create() {
|
|
MRB mrb = new();
|
|
MRB_DMO mrbDMO = new(_AppSettings);
|
|
mrb.OriginatorID = GlobalVars.GetUserId(GetSession());
|
|
mrbDMO.InsertMRB(mrb);
|
|
|
|
// Automatically Submit the Document as soon as an MRB is created
|
|
try {
|
|
PopulateCloseToQDB();
|
|
mrbDMO.SubmitDocument(mrb.MRBNumber, GlobalVars.GetUserId(GetSession()));
|
|
} catch (Exception e) {
|
|
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "Issue=" + mrb.MRBNumber.ToString() + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
|
|
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n SubmitDocument - MRB\r\n" + e.Message.ToString(), EventLogEntryType.Error);
|
|
EventLogDMO.Add(new WinEventLog() { IssueID = mrb.MRBNumber, UserID = GetUserIdentityName(), DocumentType = "MRB", OperationType = "Error", Comments = "SubmitDocument - " + exceptionString });
|
|
throw new Exception(e.Message);
|
|
}
|
|
|
|
return RedirectToAction("Edit", new { IssueID = mrb.MRBNumber });
|
|
}
|
|
|
|
#if !NET8
|
|
|
|
// POST: /MRB/Create
|
|
[HttpPost]
|
|
public ActionResult Create(FormCollection collection) {
|
|
try {
|
|
// TODO: Add insert logic here
|
|
|
|
return RedirectToAction("Index");
|
|
} catch {
|
|
return View();
|
|
}
|
|
}
|
|
|
|
#endif
|
|
|
|
// GET: /MRB/Edit/5
|
|
public ActionResult Edit(int issueID) {
|
|
string jwt = GlobalVars.GetJWT(GetSession());
|
|
string encodedJwt = System.Net.WebUtility.UrlEncode(jwt);
|
|
string refreshToken = GlobalVars.GetRefreshToken(GetSession());
|
|
string encodedRefreshToken = System.Net.WebUtility.UrlEncode(refreshToken);
|
|
string mrbUrl = $"{GlobalVars.AppSettings.WasmClientUrl}/redirect?jwt={encodedJwt}&refreshToken={encodedRefreshToken}&redirectPath=mrb/{issueID}";
|
|
|
|
return Redirect(mrbUrl);
|
|
}
|
|
|
|
// POST: /MRB/Edit/5
|
|
[HttpPost]
|
|
public void Edit(MRB mrb) {
|
|
try {
|
|
mrbDMO.UpdateMRB(mrb);
|
|
} catch (Exception e) {
|
|
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "IssueID=" + mrb.MRBNumber.ToString() + " " + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
|
|
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n UpdateEdit MRB\r\n" + e.Message.ToString(), EventLogEntryType.Error);
|
|
EventLogDMO.Add(new WinEventLog() { IssueID = mrb.MRBNumber, UserID = GetUserIdentityName(), DocumentType = "MRB", OperationType = "Error", Comments = exceptionString });
|
|
throw new Exception(e.Message);
|
|
}
|
|
}
|
|
|
|
public ActionResult ReadOnly(int issueID) {
|
|
string jwt = GlobalVars.GetJWT(GetSession());
|
|
string encodedJwt = System.Net.WebUtility.UrlEncode(jwt);
|
|
string refreshToken = GlobalVars.GetRefreshToken(GetSession());
|
|
string encodedRefreshToken = System.Net.WebUtility.UrlEncode(refreshToken);
|
|
string mrbUrl = $"{GlobalVars.AppSettings.WasmClientUrl}/redirect?jwt={encodedJwt}&refreshToken={encodedRefreshToken}&redirectPath=mrb/{issueID}";
|
|
|
|
return Redirect(mrbUrl);
|
|
}
|
|
|
|
// GET: /MRB/Delete/5
|
|
public ActionResult Delete(int id) {
|
|
return View();
|
|
}
|
|
|
|
#if !NET8
|
|
|
|
// POST: /MRB/Delete/5
|
|
[HttpPost]
|
|
public ActionResult Delete(int id, FormCollection collection) {
|
|
try {
|
|
// TODO: Add delete logic here
|
|
|
|
return RedirectToAction("Index");
|
|
} catch {
|
|
return View();
|
|
}
|
|
}
|
|
|
|
#endif
|
|
|
|
public JsonResult SearchLots(string searchText, string searchBy) {
|
|
List<string> lotlist = MiscDMO.SearchLots(searchText, searchBy).Select(x => x.LotNumber).ToList();
|
|
return GetJsonResult(lotlist);
|
|
}
|
|
|
|
#if !NET8
|
|
|
|
public ActionResult GetMRBLots([DataSourceRequest] DataSourceRequest request, int mrbNumber) {
|
|
return Json(mrbDMO.GetMRBLots(mrbNumber).ToDataSourceResult(request));
|
|
}
|
|
|
|
#endif
|
|
|
|
[HttpGet]
|
|
public ActionResult GetTools() {
|
|
return GetJsonResult(mrbDMO.GetTools());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Updates the lot tables
|
|
/// </summary>
|
|
#if !NET8
|
|
|
|
[AcceptVerbs(HttpVerbs.Post)]
|
|
public ActionResult UpdateMRBLot([DataSourceRequest] DataSourceRequest request, Lot lot) {
|
|
if (lot != null && ModelState.IsValid) {
|
|
mrbDMO.UpdateMRBLot(lot);
|
|
}
|
|
|
|
return Json(new[] { lot }.ToDataSourceResult(request, ModelState));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deletes record from the lot table
|
|
/// </summary>
|
|
[AcceptVerbs(HttpVerbs.Post)]
|
|
public ActionResult DeleteMRBLot([DataSourceRequest] DataSourceRequest request, Lot lot) {
|
|
try {
|
|
if (lot != null && ModelState.IsValid) {
|
|
mrbDMO.DeleteMRBLot(lot.LotID);
|
|
|
|
}
|
|
} catch (Exception ex) {
|
|
// TODO
|
|
throw new Exception(ex.Message);
|
|
}
|
|
|
|
return Json(new[] { lot }.ToDataSourceResult(request, ModelState));
|
|
}
|
|
|
|
#endif
|
|
|
|
public void DeleteAllMRBLots(int issueID) {
|
|
// trap the error on then client side
|
|
mrbDMO.DeleteAllMRBLot(issueID);
|
|
}
|
|
|
|
public JsonResult AddLot(Lot lot) {
|
|
// This is to add a manually entered lot
|
|
|
|
Lot l = lot;
|
|
|
|
try {
|
|
bool existingRowUpdated;
|
|
mrbDMO.InsertLot(lot, false, out existingRowUpdated);
|
|
} catch (Exception e) {
|
|
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "IssueID=" + lot.IssueID.ToString() + " " + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
|
|
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n Add Lot Disposition\r\n" + e.Message.ToString(), EventLogEntryType.Error);
|
|
EventLogDMO.Add(new WinEventLog() { IssueID = l.IssueID, UserID = GetUserIdentityName(), DocumentType = "MRB", OperationType = "Error", Comments = exceptionString });
|
|
throw new Exception(e.Message);
|
|
}
|
|
return GetJsonResult(l);
|
|
}
|
|
|
|
public ActionResult AddLots(string lotNumbers, int mrbNumber) {
|
|
// This is for adding lot(s) via search
|
|
|
|
try {
|
|
StringBuilder warnings = new();
|
|
|
|
if (lotNumbers.Length > 0) {
|
|
string[] tempLots = lotNumbers.Split(new char[] { '~' });
|
|
foreach (string lotNumber in tempLots) {
|
|
bool existingRowUpdated;
|
|
Lot l = new();
|
|
l.LotNumber = lotNumber;
|
|
l.MRBNumber = mrbNumber;
|
|
mrbDMO.InsertLot(l, true, out existingRowUpdated);
|
|
}
|
|
}
|
|
|
|
return Content(warnings.ToString());
|
|
} catch (Exception e) {
|
|
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "MRBNumber=" + mrbNumber.ToString() + " " + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
|
|
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n AddLots MRB\r\n" + e.Message.ToString(), EventLogEntryType.Error);
|
|
EventLogDMO.Add(new WinEventLog() { UserID = GetUserIdentityName(), OperationType = "Error", DocumentType = "MRB", Comments = exceptionString });
|
|
|
|
Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
|
|
return Content(e.Message);
|
|
}
|
|
}
|
|
|
|
#region ATTACHMENT
|
|
|
|
#if !NET8
|
|
|
|
public ActionResult Attachment_Read([DataSourceRequest] DataSourceRequest request, int mrbNumber) {
|
|
return Json(mrbDMO.GetMRBAttachments(mrbNumber).ToDataSourceResult(request));
|
|
}
|
|
|
|
#endif
|
|
|
|
[HttpPost]
|
|
public void DeleteAttachment(int attachmentID) {
|
|
try {
|
|
if (ModelState.IsValid) {
|
|
var attachment = mrbDMO.GetMRBAttachment(attachmentID);
|
|
|
|
if (attachment == null)
|
|
return;
|
|
|
|
string fileName = attachment.Path;
|
|
if (string.IsNullOrEmpty(fileName))
|
|
fileName = attachment.FileName;
|
|
|
|
mrbDMO.DeleteMRBAttachment(attachmentID);
|
|
|
|
if (!string.IsNullOrWhiteSpace(fileName)) {
|
|
var physicalPath = System.IO.Path.Combine(_AppSettings.AttachmentFolder + "MRB", fileName);
|
|
|
|
System.IO.FileInfo f = new(physicalPath);
|
|
|
|
if (f.Exists)
|
|
f.Delete();
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "AttachmentID=" + attachmentID.ToString() + " " + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
|
|
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n AttachmentID MRB\r\n" + e.Message.ToString(), EventLogEntryType.Error);
|
|
EventLogDMO.Add(new WinEventLog() { IssueID = 999, UserID = GetUserIdentityName(), DocumentType = "MRB", OperationType = "Error", Comments = "AttachmentID Disposition " + exceptionString });
|
|
throw new Exception(e.Message);
|
|
}
|
|
}
|
|
|
|
#if !NET8
|
|
|
|
public ActionResult AttachSave(IEnumerable<HttpPostedFileBase> files, int mrbNumber) {
|
|
var errorList = new List<String>();
|
|
|
|
// The Name of the Upload component is "files"
|
|
if (files != null) {
|
|
int userId = GlobalVars.GetUserId(GetSession());
|
|
foreach (var file in files) {
|
|
MRBHelper.AttachSave(_AppSettings, mrbDMO, mrbNumber, userId, file.FileName, file.InputStream);
|
|
}
|
|
}
|
|
return Json(new { errors = errorList });
|
|
}
|
|
|
|
#endif
|
|
|
|
#endregion
|
|
|
|
#if !NET8
|
|
|
|
public ActionResult ExcelLotOpen(IEnumerable<HttpPostedFileBase> Lotfile, int mrbNumber) {
|
|
var warnings = new StringBuilder();
|
|
var physicalPath = "";
|
|
try {
|
|
string userIdentityName = GetUserIdentityName();
|
|
var dispos = mrbDMO.GetDispositions(mrbNumber);
|
|
foreach (var file in Lotfile) {
|
|
physicalPath = MRBHelper.ExcelLotOpen(mrbDMO, mrbNumber, warnings, dispos, userIdentityName, _AppSettings.LotTempPipeLine, file.FileName, file.InputStream);
|
|
}
|
|
|
|
return Content(warnings.ToString());
|
|
} catch (Exception e) {
|
|
string detailedException = "";
|
|
try {
|
|
detailedException = e.InnerException.ToString();
|
|
} catch {
|
|
detailedException = e.Message;
|
|
}
|
|
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "IssueID=" + mrbNumber.ToString() + " " + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
|
|
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n MRB Excel\r\n" + detailedException, EventLogEntryType.Error);
|
|
EventLogDMO.Add(new WinEventLog() { IssueID = mrbNumber, UserID = GetUserIdentityName(), DocumentType = "Lot Disposition", OperationType = "Error", Comments = exceptionString });
|
|
|
|
System.IO.FileInfo f = new System.IO.FileInfo(physicalPath);
|
|
if (f.Exists)
|
|
f.Delete();
|
|
|
|
Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
|
|
return Content(e.Message);
|
|
}
|
|
}
|
|
|
|
public ActionResult ImportAddQDBFlag(IEnumerable<HttpPostedFileBase> AddQDBFlag, string operation) {
|
|
var physicalPath = "";
|
|
try {
|
|
string message;
|
|
string c = Server.MapPath("/FTPBatch/");
|
|
string userIdentityName = GetUserIdentityName();
|
|
string b = Server.MapPath("/FTPBatch/" + _AppSettings.FTPSPNBatchFileName);
|
|
string a = Server.MapPath("/FTPBatch/" + _AppSettings.FTPSPNBatchFileName_Test);
|
|
foreach (var file in AddQDBFlag) {
|
|
message = MRBHelper.ImportAddQDBFlag(_AppSettings, mrbDMO, operation, out physicalPath, userIdentityName, a, b, c, file.FileName, file.InputStream);
|
|
if (string.IsNullOrEmpty(message))
|
|
continue;
|
|
return Content(message);
|
|
}
|
|
|
|
return Content("");
|
|
} catch {
|
|
System.IO.FileInfo f = new System.IO.FileInfo(physicalPath);
|
|
if (f.Exists)
|
|
f.Delete();
|
|
|
|
return Content("Incorrect File Format/Data");
|
|
}
|
|
}
|
|
|
|
public ActionResult ImportRemoveQDBFlag(IEnumerable<HttpPostedFileBase> RemoveQDBFlag, string operation) {
|
|
var physicalPath = "";
|
|
try {
|
|
string message;
|
|
string c = Server.MapPath("/FTPBatch/");
|
|
string userIdentityName = GetUserIdentityName();
|
|
string b = Server.MapPath("/FTPBatch/" + _AppSettings.FTPSPNBatchFileName);
|
|
string a = Server.MapPath("/FTPBatch/" + _AppSettings.FTPSPNBatchFileName_Test);
|
|
foreach (var file in RemoveQDBFlag) {
|
|
message = MRBHelper.ImportRemoveQDBFlag(_AppSettings, mrbDMO, operation, out physicalPath, userIdentityName, a, b, c, file.FileName, file.InputStream);
|
|
if (string.IsNullOrEmpty(message))
|
|
continue;
|
|
return Content(message);
|
|
}
|
|
|
|
return Content("");
|
|
} catch {
|
|
System.IO.FileInfo f = new System.IO.FileInfo(physicalPath);
|
|
if (f.Exists)
|
|
f.Delete();
|
|
|
|
return Content("Incorrect File Format/Data");
|
|
}
|
|
}
|
|
|
|
#if !NET8
|
|
|
|
public ActionResult GetContainmentActions([DataSourceRequest] DataSourceRequest request, int mrbNumber) {
|
|
return Json(mrbDMO.GetContainmentActions(mrbNumber).ToDataSourceResult(request));
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if !NET8
|
|
[AcceptVerbs(HttpVerbs.Post)]
|
|
#endif
|
|
public ActionResult UpdateContainmentAction(ContainmentActionObj model) {
|
|
if (model != null && ModelState.IsValid) {
|
|
mrbDMO.UpdateContainmentAction(model);
|
|
}
|
|
|
|
return Content("");
|
|
}
|
|
|
|
#if !NET8
|
|
[AcceptVerbs(HttpVerbs.Post)]
|
|
#endif
|
|
public ActionResult InsertContainmentAction(ContainmentActionObj model) {
|
|
if (model != null && ModelState.IsValid) {
|
|
mrbDMO.InsertContainmentAction(model);
|
|
}
|
|
|
|
return Content("");
|
|
}
|
|
|
|
#if !NET8
|
|
|
|
[AcceptVerbs(HttpVerbs.Post)]
|
|
public ActionResult DeleteContainmentAction([DataSourceRequest] DataSourceRequest request, ContainmentActionObj model) {
|
|
if (model != null && ModelState.IsValid) {
|
|
mrbDMO.DeleteContainmentAction(model);
|
|
}
|
|
|
|
return Json(new[] { model }.ToDataSourceResult(request, ModelState));
|
|
}
|
|
|
|
#endif
|
|
|
|
#region
|
|
|
|
#if !NET8
|
|
public ActionResult GetDispostions([DataSourceRequest] DataSourceRequest request, int mrbNumber) {
|
|
return Json(mrbDMO.GetDispositions(mrbNumber).ToDataSourceResult(request));
|
|
}
|
|
|
|
#endif
|
|
|
|
#if !NET8
|
|
|
|
[AcceptVerbs(HttpVerbs.Post)]
|
|
public ActionResult UpdateDisposition(Disposition model) {
|
|
if (model != null && ModelState.IsValid) {
|
|
mrbDMO.UpdateDisposition(model);
|
|
}
|
|
return GetJsonResult(model);
|
|
}
|
|
|
|
[AcceptVerbs(HttpVerbs.Post)]
|
|
public void InsertDisposition(Disposition model) {
|
|
if (model != null && ModelState.IsValid) {
|
|
mrbDMO.InsertDisposition(model);
|
|
}
|
|
}
|
|
|
|
[AcceptVerbs(HttpVerbs.Post)]
|
|
public ActionResult DeleteDisposition(Disposition model) {
|
|
if (model != null && ModelState.IsValid) {
|
|
mrbDMO.DeleteDisposition(model);
|
|
}
|
|
|
|
return GetJsonResult(model);
|
|
}
|
|
|
|
#endif
|
|
|
|
#endregion
|
|
|
|
public void PopulateCloseToQDB() {
|
|
List<CloseToQDBOptionViewModel> options = new();
|
|
options.Add(new CloseToQDBOptionViewModel { CloseToQDBOptionID = 0, CloseToQDBOption = "No" });
|
|
options.Add(new CloseToQDBOptionViewModel { CloseToQDBOptionID = 1, CloseToQDBOption = "Yes" });
|
|
ViewData["CloseToQDBOptions"] = options;
|
|
}
|
|
|
|
public void NotifyApprovers(int mrbNumber, byte currentStep) {
|
|
|
|
List<string> emailIst = MiscDMO.GetApproverEmailListByDocument(mrbNumber, currentStep, (int)GlobalVars.DocumentType.MRB).Distinct().ToList();
|
|
string emailSentList = MRBHelper.NotifyApprovers(_AppSettings, mrbNumber, emailIst);
|
|
try {
|
|
EventLogDMO.Add(new WinEventLog() { IssueID = mrbNumber, UserID = GetUserIdentityName(), DocumentType = "MRB", OperationType = "Email", Comments = "Approvers for Step " + currentStep.ToString() + ":" + emailSentList });
|
|
} catch { }
|
|
}
|
|
|
|
public void Approve(int issueID, byte currentStep, string comments) {
|
|
int isITARCompliant = 1;
|
|
MRB mrb = new();
|
|
mrb = mrbDMO.GetMRBItem(issueID, out isITARCompliant, GlobalVars.GetUserId(GetSession()));
|
|
try {
|
|
bool lastStep = false;
|
|
|
|
bool lastApprover = wfDMO.Approve(_AppSettings, issueID, currentStep, comments, out lastStep, GlobalVars.GetUserId(GetSession()), (int)GlobalVars.DocumentType.MRB, mrb.WorkFlowNumber);
|
|
|
|
while (lastApprover && !lastStep) {
|
|
currentStep++;
|
|
lastApprover = wfDMO.Approve(_AppSettings, issueID, currentStep, comments, out lastStep, GlobalVars.GetUserId(GetSession()), (int)GlobalVars.DocumentType.MRB, mrb.WorkFlowNumber);
|
|
NotifyApprovers(issueID, currentStep);
|
|
}
|
|
} catch (Exception e) {
|
|
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "Issue=" + issueID.ToString() + " Step:" + currentStep + " " + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
|
|
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n Approve\r\n" + e.Message.ToString(), EventLogEntryType.Error);
|
|
EventLogDMO.Add(new WinEventLog() { IssueID = issueID, UserID = GetUserIdentityName(), DocumentType = "Lot Disposition", OperationType = "Error", Comments = "Approve - " + exceptionString });
|
|
throw new Exception(e.Message);
|
|
}
|
|
}
|
|
|
|
public void CloseDocument(int mrb) {
|
|
mrbDMO.CloseDocument(mrb);
|
|
}
|
|
|
|
public void SetDispositionTypeForAllLots(int mrb, string dispoType) {
|
|
mrbDMO.SetDispositionTypeForAllLots(mrb, dispoType);
|
|
}
|
|
|
|
public JsonResult GetLotWaferDieCount(int mrbNumber) {
|
|
int lotCount = 0;
|
|
int waferCount = 0;
|
|
int dieCount = 0;
|
|
mrbDMO.GetLotWaferDieCount(mrbNumber, out lotCount, out waferCount, out dieCount);
|
|
return GetJsonResult(lotCount.ToString() + "~" + waferCount.ToString() + "~" + dieCount);
|
|
}
|
|
|
|
#if !NET8
|
|
|
|
public ActionResult SendMRBHoldFlagToSPN(int mrbNumber) {
|
|
MRB mrbInfo;
|
|
try {
|
|
mrbInfo = mrbDMO.GetToolIssueStartEndDateData(mrbNumber);
|
|
} catch {
|
|
// if tools or issue start/end date is not provided, set them to null
|
|
mrbInfo = new MRB { ToolCSV = "", IssueStartDate = null, IssueEndDate = null };
|
|
}
|
|
|
|
if (!mrbInfo.ToolCSV.ToUpper().Equals("NA")) {
|
|
Lot l = new();
|
|
|
|
var mrbLotInfo = mrbDMO.GetLotsToFindNewChildLots(mrbNumber);
|
|
foreach (Lot lot in mrbLotInfo) {
|
|
// routine to cascade the "dispo type" to all the child lots in SPN (Lot that are not present in FAb App Sys,)
|
|
mrbDMO.ChildLotsUpdateInSPNWithNewDispoType(lot, mrbInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// SEND DATA to SPN
|
|
|
|
StringBuilder output = new();
|
|
try {
|
|
string c = Server.MapPath("/FTPBatch/");
|
|
string userIdentityName = GetUserIdentityName();
|
|
string b = Server.MapPath("/FTPBatch/" + _AppSettings.FTPSPNBatchFileName);
|
|
string a = Server.MapPath("/FTPBatch/" + _AppSettings.FTPSPNBatchFileName_Test);
|
|
IEnumerable<string> data = mrbDMO.GetMRBHoldLots(mrbNumber);
|
|
foreach (string tempData in data) {
|
|
if (tempData != null)
|
|
output.Append(tempData.Trim() + Environment.NewLine);
|
|
|
|
}
|
|
|
|
try {
|
|
if (output.Length > 0) {
|
|
DateTime dt = DateTime.Now;
|
|
string newsourceFileName = mrbNumber.ToString() + "_S" + dt.Day.ToString("00") + dt.Month.ToString("00") + dt.Year.ToString("00") + dt.Hour.ToString("00") + dt.Minute.ToString("00") + dt.Second.ToString("00") + ".mrb";
|
|
string newDestFileName = "S" + dt.Hour.ToString("00") + dt.Minute.ToString("00") + dt.Second.ToString("00");
|
|
|
|
string outputFile = _AppSettings.SPNMRBHoldFlagDirectory + newsourceFileName;
|
|
|
|
System.IO.File.WriteAllText(outputFile, output.ToString());
|
|
|
|
#if (DEBUG)
|
|
Thread.Sleep(1000);
|
|
#endif
|
|
try {
|
|
if (MRBHelper.BatchFTP(_AppSettings, outputFile, newDestFileName, _AppSettings.SPNMRBHoldFlagFTPLogDirectory, userIdentityName, a, b, c)) {
|
|
// TODO
|
|
mrbDMO.LogHoldFlagSentToSPNHistory(mrbNumber);
|
|
}
|
|
} catch (Exception e) {
|
|
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "MRB =" + mrbNumber.ToString() + " FTPToSPN(): SendMRBHoldFlagToSPN(mrbNumber) - FTP Upload Error " + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
|
|
EventLogDMO.Add(new WinEventLog() { IssueID = -1, UserID = GetUserIdentityName(), DocumentType = "MRB", OperationType = "Error", Comments = exceptionString });
|
|
return GetJsonResult(new { Error = true, Message = e.Message });
|
|
}
|
|
|
|
}
|
|
} catch (Exception e) {
|
|
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "MRB =" + mrbNumber.ToString() + " SendMRBHoldFlagToSPN(mrbNumber) " + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
|
|
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n Approve\r\n" + e.Message.ToString(), EventLogEntryType.Error);
|
|
EventLogDMO.Add(new WinEventLog() { IssueID = -1, UserID = GetUserIdentityName(), DocumentType = "MRB", OperationType = "Error", Comments = exceptionString });
|
|
return GetJsonResult(new { Error = true, Message = e.Message });
|
|
;
|
|
}
|
|
|
|
return GetJsonResult(new { Error = false, Message = "Success" });
|
|
} catch (Exception e) {
|
|
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "GUID =" + mrbNumber.ToString() + " SendMRBHoldFlagToSPN(mrbNumber) " + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
|
|
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n Approve\r\n" + e.Message.ToString(), EventLogEntryType.Error);
|
|
EventLogDMO.Add(new WinEventLog() { IssueID = -1, UserID = GetUserIdentityName(), DocumentType = "MRB", OperationType = "Error", Comments = exceptionString });
|
|
return GetJsonResult(new { Error = true, Message = e.Message });
|
|
}
|
|
}
|
|
|
|
public bool BatchFTP_Old(string sourceFile, string destFile) {
|
|
System.IO.FileInfo sourcefile = new(sourceFile);
|
|
try {
|
|
|
|
ProcessStartInfo psiFab1 = new();
|
|
if (GlobalVars.DBConnection.ToUpper() == "TEST" || GlobalVars.DBConnection.ToUpper() == "QUALITY") {
|
|
psiFab1.FileName = Server.MapPath("/FTPBatch/" + _AppSettings.FTPSPNBatchFileName_Test);
|
|
} else {
|
|
psiFab1.FileName = Server.MapPath("/FTPBatch/" + _AppSettings.FTPSPNBatchFileName);
|
|
}
|
|
|
|
psiFab1.Arguments = sourcefile.FullName + " " + destFile;
|
|
|
|
Process procFab1 = new();
|
|
procFab1.StartInfo = psiFab1;
|
|
procFab1.Start();
|
|
return true;
|
|
} catch (Exception e) {
|
|
Functions.WriteEvent(_AppSettings, GetUserIdentityName() + "\r\n Approve\r\n" + e.Message.ToString(), EventLogEntryType.Error);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
#endif
|
|
|
|
public FileResult DownloadFile(string attachmentID) {
|
|
var attachment = mrbDMO.GetMRBAttachment(Convert.ToInt32(attachmentID));
|
|
|
|
if (attachment == null)
|
|
throw new Exception("Invalid attachment ID");
|
|
|
|
string fileName = attachment.Path;
|
|
if (string.IsNullOrEmpty(fileName))
|
|
fileName = attachment.FileName;
|
|
|
|
var sDocument = System.IO.Path.Combine(_AppSettings.AttachmentFolder + "MRB", fileName);
|
|
var FDir_AppData = _AppSettings.AttachmentFolder;
|
|
if (!sDocument.StartsWith(FDir_AppData)) {
|
|
// Ensure that we are serving file only inside the Fab2ApprovalAttachments folder
|
|
// and block requests outside like "../web.config"
|
|
throw new HttpException(403, "Forbidden");
|
|
}
|
|
|
|
if (!System.IO.File.Exists(sDocument)) {
|
|
return null;
|
|
}
|
|
|
|
return File(sDocument, System.Net.Mime.MediaTypeNames.Application.Octet, attachment.FileName);
|
|
}
|
|
|
|
public FileResult ExportMRBHoldFlagReport(int mrbNumber) {
|
|
StringBuilder sb = new();
|
|
sb.AppendLine("LotNo,PartNo ,CurrentLocation,CurrentOperation,StartQty,CurrentQty,LotStatus,OperStatus,Successful,Comment,PriorMRB_DispoType,PriorMRBHoldLocation,PriorMRBHoldOperation,CurrentMRB_DispoType,CurrentMRBHoldLocation,CurrentMRBHoldOperation,TransactionDatetime");
|
|
foreach (var report in mrbDMO.GetMRBHoldFlagReport(mrbNumber)) {
|
|
sb.AppendLine(MRB_DMO.FormCSV(
|
|
report.LotNo,
|
|
report.PartNo,
|
|
report.CurrentLocation,
|
|
report.CurrentOperation,
|
|
report.StartQty,
|
|
report.CurrentQty,
|
|
report.LotStatus,
|
|
report.OperStatus,
|
|
report.Successful,
|
|
report.Comment,
|
|
report.PriorMRB_DispoType,
|
|
report.PriorMRBHoldLocation,
|
|
report.PriorMRBHoldOperation,
|
|
report.CurrentMRB_DispoType,
|
|
report.CurrentMRBHoldLocation,
|
|
report.CurrentMRBHoldOperation,
|
|
report.TransactionDateTime
|
|
|
|
));
|
|
}
|
|
var b = System.Text.ASCIIEncoding.ASCII.GetBytes(sb.ToString());
|
|
return File(b, "application/octet-stream", "mrb_lots_" + mrbNumber.ToString() + ".csv");
|
|
}
|
|
|
|
public FileResult PreviewMRBHoldFlagTobeSentToSPN(int mrbNumber) {
|
|
StringBuilder sb = new();
|
|
sb.AppendLine("LotNumber,MRBNumber,DispoType,MRB Flag,Modified,Sent To SPN,Last Sent to SPN");
|
|
foreach (var lot in mrbDMO.GetMRHoldFlagSentHistory(mrbNumber)) {
|
|
sb.AppendLine(MRB_DMO.FormCSV(
|
|
lot.LotNumber,
|
|
lot.MRBNumber,
|
|
lot.DispoType,
|
|
lot.AddRemoveChangeMRBFlag,
|
|
lot.IsDirty,
|
|
lot.SentToSPN,
|
|
lot.MRBLotLastSentToSPNDatetime
|
|
));
|
|
}
|
|
var b = System.Text.ASCIIEncoding.ASCII.GetBytes(sb.ToString());
|
|
return File(b, "application/octet-stream", "mrb_lots_" + mrbNumber.ToString() + ".csv");
|
|
}
|
|
|
|
public FileResult ExportLots(int mrbNumber) {
|
|
StringBuilder sb = new();
|
|
sb.AppendLine("LotNumber,DieLotNumber,WipPartNo,DispoType,WaferCount,DiePartNo,DieCount,SourceLot,TotalCost,ProductFamily,Gen,HexSize,Channel,Voltage,Location,Status,QualityCode");
|
|
foreach (var lot in mrbDMO.GetMRBLots(mrbNumber)) {
|
|
sb.AppendLine(MRB_DMO.FormCSV(
|
|
lot.LotNumber,
|
|
lot.DieLotNumber,
|
|
lot.WipPartNo,
|
|
lot.DispoType,
|
|
lot.WaferCount,
|
|
lot.DiePartNo,
|
|
lot.DieCount,
|
|
lot.SourceLot,
|
|
lot.TotalCost,
|
|
lot.ProductFamily,
|
|
lot.Gen,
|
|
lot.Hexsize,
|
|
lot.Channel,
|
|
lot.Voltage,
|
|
lot.Location,
|
|
lot.Status,
|
|
lot.QualityCode
|
|
));
|
|
}
|
|
var b = System.Text.ASCIIEncoding.ASCII.GetBytes(sb.ToString());
|
|
return File(b, "application/octet-stream", "mrb_lots_" + mrbNumber.ToString() + ".csv");
|
|
}
|
|
|
|
#if !NET8
|
|
|
|
private System.Web.HttpSessionStateBase GetSession() =>
|
|
Session;
|
|
|
|
private JsonResult GetJsonResult(object? data) =>
|
|
Json(data, JsonRequestBehavior.AllowGet);
|
|
|
|
private bool IsAjaxRequest() =>
|
|
Request.IsAjaxRequest();
|
|
|
|
#endif
|
|
|
|
#if NET8
|
|
|
|
private Microsoft.AspNetCore.Http.ISession GetSession() =>
|
|
HttpContext.Session;
|
|
|
|
private JsonResult GetJsonResult(object? data) =>
|
|
Json(data);
|
|
|
|
private bool IsAjaxRequest() =>
|
|
Request.Headers.TryGetValue("X-Requested-With", out Microsoft.Extensions.Primitives.StringValues strings) && strings[0] == "XMLHttpRequest";
|
|
|
|
#endif
|
|
|
|
private string GetUserIdentityName() =>
|
|
@User.Identity.Name;
|
|
|
|
} |