Mike Phares b1c6903c1c Tasks 184281, 184799, 184800, 184801 and 184802
Align .editorconfig files

Move Controller logic to DMO classes

GlobalVars.AppSettings = Models.AppSettings.GetFromConfigurationManager();

Question EditorConfig
Project level editorconfig
Format White Spaces
AppSetting when EnvironmentVariable not set
Corrective Actions Tests
Schedule Actions Tests
DMO Tests
Controller Tests

Get ready to use VSCode IDE
2024-12-04 11:58:13 -07:00

812 lines
34 KiB
C#

using Fab2ApprovalSystem.DMO;
using Fab2ApprovalSystem.Misc;
using Fab2ApprovalSystem.Models;
using Fab2ApprovalSystem.ViewModels;
using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;
namespace Fab2ApprovalSystem.Controllers;
[Authorize]
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
[SessionExpireFilter]
public class MRBController : Controller {
MRB_DMO mrbDMO;
WorkflowDMO wfDMO = new WorkflowDMO();
CredentialsStorage credentialsStorage = new CredentialsStorage();
private readonly AppSettings _AppSettings;
public MRBController(AppSettings appSettings) {
_AppSettings = appSettings;
mrbDMO = new MRB_DMO(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]);
//if (appoverCount > 0)
// NotifyApprovers(mrb.MRBNumber, (byte)GlobalVars.WorkFLowStepNumber.Step1);
//if (Request.IsAjaxRequest())
//{
// return Content("Redirect");
//}
//else
// return Content("Invalid");
} 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 wasmClientUrl = Environment.GetEnvironmentVariable("FabApprovalWasmClientUrl") ??
"https://localhost:7255";
string mrbUrl = $"{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 wasmClientUrl = Environment.GetEnvironmentVariable("FabApprovalWasmClientUrl") ??
"https://localhost:7255";
string mrbUrl = $"{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) {
//IEnumerable<Lot> lotlist = MiscDMO.SearchLots(searchText, searchBy);
List<String> lotlist = MiscDMO.SearchLots(searchText, searchBy).Select(x => x.LotNumber).ToList<String>();
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);
}
/// <summary>
/// Updates the lot tables
/// </summary>
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdateMRBLot([DataSourceRequest] DataSourceRequest request, Lot lot) {
//try
//{
// // RJK
// //routine to cascade the "dispo type" to all the child lots in SPN
// MRB mrbInfo = mrbDMO.GetToolIssueStartEndDateData(lot.MRBNumber);
// if (!mrbInfo.ToolCSV.ToUpper().Equals("NA"))
// {
// bool existingLotUpdated;
// Lot l = new Lot();
// l.LotNumber = lot.LotNumber;
// if (lot.DispoType.ToString().Trim().Length == 1)
// {
// l.DispoType = lot.DispoType;
// }
// l.MRBNumber = lot.MRBNumber;
// // check if the lot was sent to SPN
// bool lotSentToSPN = mrbDMO.IsLotSentToSPN(l.LotNumber, l.MRBNumber);
// //only get the child lots if it has been sent to SPN to set the MRB Flag
// if (lotSentToSPN)
// {
// if (!mrbDMO.GetChildLotsFromSPNForDispoTypeUpdate(l.MRBNumber, l.LotNumber, mrbInfo.ToolCSV, mrbInfo.IssueStartDate, mrbInfo.IssueEndDate, lot.DispoType))
// {
// //warnings.AppendFormat("Lot number {0} is not affected by these tools and issue start/end time.\n", l.LotNumber);
// }
// }
// }
//}
//catch(Exception e)
//{
// // ignore the error
// string s = e.InnerException.ToString();
//}
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));
}
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);
//if (!existingRowUpdated)
//{
// if (!mrbDMO.InsertLotSplitsAffectedByIncident(mrbNumber, l.LotNumber))
// {
// warnings.AppendFormat("Lot number {0} is not affected by these tools and issue start/end time.\n", l.LotNumber);
// }
//}
}
//warnings.Append("No tool info, split lots will NOT be automatically searched and uploaded \n please make sure to include all the child lots in the MRB");
}
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 = Path.Combine(_AppSettings.AttachmentFolder + "MRB", fileName);
FileInfo f = new 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<HttpPostedFileBase> files, int mrbNumber) {
var errorList = new List<String>();
// The Name of the Upload component is "files"
if (files != null) {
int userId = (int)Session[GlobalVars.SESSION_USERID];
foreach (var file in files) {
mrbDMO.AttachSave(mrbNumber, userId, file.FileName, file.InputStream);
}
}
//var model = mrbDMO.GetMRBAttachments(mrbNumber);
return Json(new { errors = errorList });
}
#endregion
public ActionResult ExcelLotOpen(IEnumerable<HttpPostedFileBase> Lotfile, int mrbNumber) {
var warnings = new StringBuilder();
var physicalPath = "";
try {
string userIdentityName = @User.Identity.Name;
var dispos = mrbDMO.GetDispositions(mrbNumber);
string lotTempPipeLine = ConfigurationManager.AppSettings["LotTempPipeLine"].ToString();
foreach (var file in Lotfile) {
physicalPath = mrbDMO.ExcelLotOpen(mrbNumber, warnings, dispos, userIdentityName, 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 });
FileInfo f = new 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) {
//string path = Server.MapPath("/FTPBatch/" + ConfigurationManager.AppSettings["FTPSPNBatchFileName"]);
var physicalPath = "";
try {
string message;
string c = Server.MapPath("/FTPBatch/");
string userIdentityName = @User.Identity.Name;
string b = Server.MapPath("/FTPBatch/" + ConfigurationManager.AppSettings["FTPSPNBatchFileName"]);
string a = Server.MapPath("/FTPBatch/" + ConfigurationManager.AppSettings["FTPSPNBatchFileName_Test"]);
foreach (var file in AddQDBFlag) {
message = mrbDMO.ImportAddQDBFlag(operation, out physicalPath, userIdentityName, a, b, c, file.FileName, file.InputStream);
if (string.IsNullOrEmpty(message))
continue;
return Content(message);
}
return Content("");
} catch {
FileInfo f = new 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 = @User.Identity.Name;
string b = Server.MapPath("/FTPBatch/" + ConfigurationManager.AppSettings["FTPSPNBatchFileName"]);
string a = Server.MapPath("/FTPBatch/" + ConfigurationManager.AppSettings["FTPSPNBatchFileName_Test"]);
foreach (var file in RemoveQDBFlag) {
message = mrbDMO.ImportRemoveQDBFlag(operation, out physicalPath, userIdentityName, a, b, c, file.FileName, file.InputStream);
if (string.IsNullOrEmpty(message))
continue;
return Content(message);
}
return Content("");
} catch {
FileInfo f = new 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<CloseToQDBOptionViewModel> options = new List<CloseToQDBOptionViewModel>();
options.Add(new CloseToQDBOptionViewModel { CloseToQDBOptionID = 0, CloseToQDBOption = "No" });
options.Add(new CloseToQDBOptionViewModel { CloseToQDBOptionID = 1, CloseToQDBOption = "Yes" });
//options.Add(new CloseToQDBOptionViewModel{CloseToQDBOption= "No"});
//options.Add(new CloseToQDBOptionViewModel {CloseToQDBOption = "Yes" });
ViewData["CloseToQDBOptions"] = options;
}
public void NotifyApprovers(int mrbNumber, byte currentStep) {
string emailSentList = "";
List<string> emailIst = MiscDMO.GetApproverEmailListByDocument(mrbNumber, currentStep, (int)GlobalVars.DocumentType.MRB).Distinct().ToList();
string emailTemplate = "MRBAssigned.txt";
string userEmail = string.Empty;
string subject = "MRB Assignment";
string senderName = "MRB";
foreach (string email in emailIst) {
subject = "MRB Assignment";
EmailNotification en = new EmailNotification(_AppSettings, subject, ConfigurationManager.AppSettings["EmailTemplatesPath"]);
string[] emailparams = new string[3];
emailparams[0] = mrbNumber.ToString();
emailparams[1] = mrbNumber.ToString();
emailparams[2] = GlobalVars.hostURL;
userEmail = email;
//#if(DEBUG)
// userEmail = "rkotian1@irf.com";
//#endif
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
emailSentList += email + ",";
}
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);
//dynamic data = new ExpandoObject();
//data.LotCount = lotCount;
//data.WaferCount = waferCount;
//data.DieCount = dieCount;
//string json = Newtonsoft.Json.JsonConvert.SerializeObject(data);
//return Json(json, JsonRequestBehavior.AllowGet);
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/" + ConfigurationManager.AppSettings["FTPSPNBatchFileName"]);
string a = Server.MapPath("/FTPBatch/" + ConfigurationManager.AppSettings["FTPSPNBatchFileName_Test"]);
IEnumerable<string> data = mrbDMO.GetMRBHoldLots(mrbNumber);
foreach (string tempData in data) {
//output = new StringBuilder();
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 = @"C:\Websites\SPNLotHoldFlag\" + newsourceFileName;
string ftpLogDirectory = ConfigurationManager.AppSettings["SPNMRBHoldFlagFTPLogDirectory"].ToString();
string outputFile = ConfigurationManager.AppSettings["SPNMRBHoldFlagDirectory"].ToString() + newsourceFileName;
System.IO.File.WriteAllText(outputFile, output.ToString());
#if (DEBUG)
Thread.Sleep(1000);
#endif
try {
//#if (!DEBUG)
//FTPWrapper spfSPN = new FTPWrapper(outputFile, newDestFileName);
//spfSPN.FTPToSPN();
if (mrbDMO.BatchFTP(outputFile, newDestFileName, ftpLogDirectory, userIdentityName, a, b, c)) {
//TODO
mrbDMO.LogHoldFlagSentToSPNHistory(mrbNumber);
}
//#endif
} 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);
//return false;
}
}
//return true;
} 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) {
FileInfo sourcefile = new FileInfo(sourceFile);
//FileInfo sourcefile = new FileInfo(@"C:\Websites\ECNViewerAckResultToSPN\S15122017102017.ecn");
try {
//Functions.WriteEvent("HR Emp", "SPNData - Start Send(): FTPing " + sourceFile + " to SPN server.", System.Diagnostics.EventLogEntryType.Information);
ProcessStartInfo psiFab1 = new ProcessStartInfo();
//psiFab1.FileName = ConfigurationManager.AppSettings["FTPSPNBatchFileName"];
if (GlobalVars.DBConnection.ToUpper() == "TEST" || GlobalVars.DBConnection.ToUpper() == "QUALITY") {
psiFab1.FileName = Server.MapPath("/FTPBatch/" + ConfigurationManager.AppSettings["FTPSPNBatchFileName_Test"]);
} else {
psiFab1.FileName = Server.MapPath("/FTPBatch/" + ConfigurationManager.AppSettings["FTPSPNBatchFileName"]);
}
psiFab1.Arguments = sourcefile.FullName + " " + destFile;
Process procFab1 = new Process();
procFab1.StartInfo = psiFab1;
procFab1.Start();
//Functions.WriteEvent("HR Emp", "SPNData - Finish FTPing to SPN server.", System.Diagnostics.EventLogEntryType.Information);
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) {
//fileName = "ECNForm_71132.pdf";
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 = 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;
//throw new Exception("File not found");
}
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");
}
}