using System; using System.Collections.Generic; using System.Configuration; using System.Diagnostics; using System.Dynamic; using System.Linq; using System.Text; using System.Threading; using System.Web; using System.Web.Mvc; using System.Web.Script.Serialization; using Fab2ApprovalSystem.DMO; using Fab2ApprovalSystem.Misc; using Fab2ApprovalSystem.Models; using Fab2ApprovalSystem.ViewModels; using Kendo.Mvc.Extensions; using Kendo.Mvc.UI; namespace Fab2ApprovalSystem.Controllers; [Authorize] [OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")] [SessionExpireFilter] public class MRBController : Controller { MRB_DMO mrbDMO = new MRB_DMO(GlobalVars.AppSettings); WorkflowDMO wfDMO = new WorkflowDMO(); CredentialsStorage credentialsStorage = new CredentialsStorage(); 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(); MRB_DMO mrbDMO = new MRB_DMO(_AppSettings); mrb.OriginatorID = (int)Session[GlobalVars.SESSION_USERID]; mrbDMO.InsertMRB(mrb); // Automatically Submit the Document as soon as an MRB is created try { PopulateCloseToQDB(); mrbDMO.SubmitDocument(mrb.MRBNumber, (int)Session[GlobalVars.SESSION_USERID]); } 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, @User.Identity.Name + "\r\n SubmitDocument - MRB\r\n" + e.Message.ToString(), System.Diagnostics.EventLogEntryType.Error); EventLogDMO.Add(new WinEventLog() { IssueID = mrb.MRBNumber, UserID = @User.Identity.Name, DocumentType = "MRB", OperationType = "Error", Comments = "SubmitDocument - " + exceptionString }); throw new Exception(e.Message); } return RedirectToAction("Edit", new { IssueID = mrb.MRBNumber }); } // POST: /MRB/Create [HttpPost] public ActionResult Create(FormCollection collection) { try { // TODO: Add insert logic here return RedirectToAction("Index"); } catch { return View(); } } // GET: /MRB/Edit/5 public ActionResult Edit(int issueID) { string jwt = Session["JWT"].ToString(); 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}"; 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, @User.Identity.Name + "\r\n UpdateEdit MRB\r\n" + e.Message.ToString(), System.Diagnostics.EventLogEntryType.Error); EventLogDMO.Add(new WinEventLog() { IssueID = mrb.MRBNumber, UserID = @User.Identity.Name, DocumentType = "MRB", OperationType = "Error", Comments = exceptionString }); throw new Exception(e.Message); } } public ActionResult ReadOnly(int issueID) { string jwt = Session["JWT"].ToString(); 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}"; return Redirect(mrbUrl); } // GET: /MRB/Delete/5 public ActionResult Delete(int id) { return View(); } // POST: /MRB/Delete/5 [HttpPost] public ActionResult Delete(int id, FormCollection collection) { try { // TODO: Add delete logic here return RedirectToAction("Index"); } catch { return View(); } } public JsonResult SearchLots(string searchText, string searchBy) { List lotlist = MiscDMO.SearchLots(searchText, searchBy).Select(x => x.LotNumber).ToList(); return Json(lotlist, JsonRequestBehavior.AllowGet); } public ActionResult GetMRBLots([DataSourceRequest] DataSourceRequest request, int mrbNumber) { return Json(mrbDMO.GetMRBLots(mrbNumber).ToDataSourceResult(request)); } [HttpGet] public ActionResult GetTools() { return Json(mrbDMO.GetTools(), JsonRequestBehavior.AllowGet); } /// /// Updates the lot tables /// [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)); } /// /// Deletes record from the lot table /// [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)); } 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, @User.Identity.Name + "\r\n Add Lot Disposition\r\n" + e.Message.ToString(), System.Diagnostics.EventLogEntryType.Error); EventLogDMO.Add(new WinEventLog() { IssueID = l.IssueID, UserID = @User.Identity.Name, DocumentType = "MRB", OperationType = "Error", Comments = exceptionString }); throw new Exception(e.Message); } return Json(l, JsonRequestBehavior.AllowGet); } public ActionResult AddLots(string lotNumbers, int mrbNumber) { // This is for adding lot(s) via search try { var warnings = new StringBuilder(); if (lotNumbers.Length > 0) { string[] tempLots = lotNumbers.Split(new char[] { '~' }); foreach (string lotNumber in tempLots) { bool existingRowUpdated; Lot l = new Lot(); 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, @User.Identity.Name + "\r\n AddLots MRB\r\n" + e.Message.ToString(), System.Diagnostics.EventLogEntryType.Error); EventLogDMO.Add(new WinEventLog() { UserID = @User.Identity.Name, OperationType = "Error", DocumentType = "MRB", Comments = exceptionString }); Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError; return Content(e.Message); } } #region ATTACHMENT public ActionResult Attachment_Read([DataSourceRequest] DataSourceRequest request, int mrbNumber) { return Json(mrbDMO.GetMRBAttachments(mrbNumber).ToDataSourceResult(request)); } [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 System.IO.FileInfo(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, @User.Identity.Name + "\r\n AttachmentID MRB\r\n" + e.Message.ToString(), System.Diagnostics.EventLogEntryType.Error); EventLogDMO.Add(new WinEventLog() { IssueID = 999, UserID = @User.Identity.Name, DocumentType = "MRB", OperationType = "Error", Comments = "AttachmentID Disposition " + exceptionString }); throw new Exception(e.Message); } } public ActionResult AttachSave(IEnumerable files, int mrbNumber) { var errorList = new List(); // The Name of the Upload component is "files" if (files != null) { int userId = (int)Session[GlobalVars.SESSION_USERID]; foreach (var file in files) { MRBHelper.AttachSave(_AppSettings, mrbDMO, mrbNumber, userId, file.FileName, file.InputStream); } } return Json(new { errors = errorList }); } #endregion public ActionResult ExcelLotOpen(IEnumerable Lotfile, int mrbNumber) { var warnings = new StringBuilder(); var physicalPath = ""; try { string userIdentityName = @User.Identity.Name; 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, @User.Identity.Name + "\r\n MRB Excel\r\n" + detailedException, System.Diagnostics.EventLogEntryType.Error); EventLogDMO.Add(new WinEventLog() { IssueID = mrbNumber, UserID = @User.Identity.Name, 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 AddQDBFlag, string operation) { var physicalPath = ""; try { string message; string c = Server.MapPath("/FTPBatch/"); string userIdentityName = @User.Identity.Name; 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 RemoveQDBFlag, string operation) { var physicalPath = ""; try { string message; string c = Server.MapPath("/FTPBatch/"); string userIdentityName = @User.Identity.Name; 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"); } } public ActionResult GetContainmentActions([DataSourceRequest] DataSourceRequest request, int mrbNumber) { return Json(mrbDMO.GetContainmentActions(mrbNumber).ToDataSourceResult(request)); } [AcceptVerbs(HttpVerbs.Post)] public ActionResult UpdateContainmentAction(ContainmentActionObj model) { if (model != null && ModelState.IsValid) { mrbDMO.UpdateContainmentAction(model); } return Content(""); } [AcceptVerbs(HttpVerbs.Post)] public ActionResult InsertContainmentAction(ContainmentActionObj model) { if (model != null && ModelState.IsValid) { mrbDMO.InsertContainmentAction(model); } return Content(""); } [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)); } #region public ActionResult GetDispostions([DataSourceRequest] DataSourceRequest request, int mrbNumber) { return Json(mrbDMO.GetDispositions(mrbNumber).ToDataSourceResult(request)); } [AcceptVerbs(HttpVerbs.Post)] public ActionResult UpdateDisposition(Disposition model) { if (model != null && ModelState.IsValid) { mrbDMO.UpdateDisposition(model); } return Json(model, JsonRequestBehavior.AllowGet); } [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 Json(model, JsonRequestBehavior.AllowGet); } #endregion public void PopulateCloseToQDB() { List options = new List(); 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 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 = @User.Identity.Name, 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(); mrb = mrbDMO.GetMRBItem(issueID, out isITARCompliant, (int)Session[GlobalVars.SESSION_USERID]); try { bool lastStep = false; bool lastApprover = wfDMO.Approve(_AppSettings, issueID, currentStep, comments, out lastStep, (int)Session[GlobalVars.SESSION_USERID], (int)GlobalVars.DocumentType.MRB, mrb.WorkFlowNumber); while (lastApprover && !lastStep) { currentStep++; lastApprover = wfDMO.Approve(_AppSettings, issueID, currentStep, comments, out lastStep, (int)Session[GlobalVars.SESSION_USERID], (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, @User.Identity.Name + "\r\n Approve\r\n" + e.Message.ToString(), System.Diagnostics.EventLogEntryType.Error); EventLogDMO.Add(new WinEventLog() { IssueID = issueID, UserID = @User.Identity.Name, 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 Json(lotCount.ToString() + "~" + waferCount.ToString() + "~" + dieCount, JsonRequestBehavior.AllowGet); } 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 Lot(); 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 StringBuilder(); try { string c = Server.MapPath("/FTPBatch/"); string userIdentityName = @User.Identity.Name; string b = Server.MapPath("/FTPBatch/" + _AppSettings.FTPSPNBatchFileName); string a = Server.MapPath("/FTPBatch/" + _AppSettings.FTPSPNBatchFileName_Test); IEnumerable 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 = @User.Identity.Name, DocumentType = "MRB", OperationType = "Error", Comments = exceptionString }); return Json(new { Error = true, Message = e.Message }, JsonRequestBehavior.AllowGet); } } } 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, @User.Identity.Name + "\r\n Approve\r\n" + e.Message.ToString(), System.Diagnostics.EventLogEntryType.Error); EventLogDMO.Add(new WinEventLog() { IssueID = -1, UserID = @User.Identity.Name, DocumentType = "MRB", OperationType = "Error", Comments = exceptionString }); return Json(new { Error = true, Message = e.Message }, JsonRequestBehavior.AllowGet); ; } return Json(new { Error = false, Message = "Success" }, JsonRequestBehavior.AllowGet); } 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, @User.Identity.Name + "\r\n Approve\r\n" + e.Message.ToString(), System.Diagnostics.EventLogEntryType.Error); EventLogDMO.Add(new WinEventLog() { IssueID = -1, UserID = @User.Identity.Name, DocumentType = "MRB", OperationType = "Error", Comments = exceptionString }); return Json(new { Error = true, Message = e.Message }, JsonRequestBehavior.AllowGet); } } public bool BatchFTP_Old(string sourceFile, string destFile) { System.IO.FileInfo sourcefile = new System.IO.FileInfo(sourceFile); try { ProcessStartInfo psiFab1 = new ProcessStartInfo(); 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 Process(); procFab1.StartInfo = psiFab1; procFab1.Start(); return true; } catch (Exception e) { Functions.WriteEvent(_AppSettings, @User.Identity.Name + "\r\n Approve\r\n" + e.Message.ToString(), System.Diagnostics.EventLogEntryType.Error); return false; } } 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) { var sb = new StringBuilder(); 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) { var sb = new StringBuilder(); 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) { var sb = new StringBuilder(); 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"); } }