using System; using System.Collections.Generic; using System.IO; using Fab2ApprovalSystem.DMO; using Fab2ApprovalSystem.Models; namespace Fab2ApprovalSystem.Misc; public class LotTravelerHelper { public static string NotifyRejectionToOrginator(AppSettings appSettings, string userId, int workRequestID, string username, List emailIst, LTWorkRequest ltWR) { string userEmail = string.Empty; string senderName = "Work Request"; string subject = "Work Request Rejection"; string emailTemplate = "WorkRequestReject.txt"; foreach (string email in emailIst) { subject = "Work Request Rejection notice for Number " + ltWR.SWRNumber + ", - " + ltWR.Title; EmailNotification en = new(appSettings, subject); string[] emailparams = new string[5]; emailparams[0] = ltWR.SWRNumber.ToString(); emailparams[1] = workRequestID.ToString(); emailparams[2] = GlobalVars.hostURL; emailparams[3] = username; emailparams[4] = "Work Request"; userEmail = email; try { en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams); } catch { EventLogDMO.Add(new WinEventLog() { IssueID = ltWR.SWRNumber, UserID = userId, DocumentType = "Lot Traveler", OperationType = "Error", Comments = "Lot Traveler Notify Rejection:" + email }); } } return userEmail; } public static string NotifyApprovers(AppSettings appSettings, string userId, int workRequestID, string emailSentList, LTWorkRequest ltWR, List emailIst) { string senderName = ""; string userEmail = string.Empty; string subject = "Work Request Assignment"; string emailTemplate = "WorkRequestAssigned.txt"; foreach (string email in emailIst) { subject = "Work Request Assignment notice for Number " + ltWR.SWRNumber + ", - " + ltWR.Title; EmailNotification en = new(appSettings, subject); string[] emailparams = new string[4]; emailparams[0] = ltWR.SWRNumber.ToString(); emailparams[1] = workRequestID.ToString(); emailparams[2] = GlobalVars.hostURL; emailparams[3] = "Work Request"; userEmail = email; #if (DEBUG) userEmail = "rkotian1@irf.com"; #endif try { emailSentList += email + ","; en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams); } catch { EventLogDMO.Add(new WinEventLog() { IssueID = ltWR.SWRNumber, UserID = userId, DocumentType = "Lot Traveler", OperationType = "Error", Comments = "WR Notify Approvers:" + email }); } } return emailSentList; } public static string NotifyApprovalOfWorkRequest(AppSettings appSettings, string userId, int workRequestID, string emailSentList, LTWorkRequest ltWR, List emailIst) { string senderName = ""; string userEmail = string.Empty; string subject = "Work Request Approval"; string emailTemplate = "WorkRequestApproval.txt"; foreach (string email in emailIst) { subject = "Work Request Approval notice for Number " + ltWR.SWRNumber + ", - " + ltWR.Title; EmailNotification en = new(appSettings, subject); string[] emailparams = new string[4]; emailparams[0] = ltWR.SWRNumber.ToString(); emailparams[1] = workRequestID.ToString(); emailparams[2] = GlobalVars.hostURL; emailparams[3] = "Work Request"; userEmail = email; #if (DEBUG) userEmail = "rkotian1@irf.com"; #endif try { emailSentList += email + ","; en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams); } catch { EventLogDMO.Add(new WinEventLog() { IssueID = ltWR.SWRNumber, UserID = userId, DocumentType = "Lot Traveler", OperationType = "Error", Comments = "Lot Traveler Approval Notification:" + email }); } } return emailSentList; } public static string NotifyfWorkRequestRevisionChange(AppSettings appSettings, string userId, int workRequestID, string emailSentList, LTWorkRequest ltWR, List emailIst) { string senderName = ""; string userEmail = string.Empty; string subject = "Work Request Revision Change"; string emailTemplate = "WorkRequestRevisionChange.txt"; foreach (string email in emailIst) { subject = "Work Request Revision Change notice for Number " + ltWR.SWRNumber + ", - " + ltWR.Title; EmailNotification en = new(appSettings, subject); string[] emailparams = new string[4]; emailparams[0] = ltWR.SWRNumber.ToString(); emailparams[1] = workRequestID.ToString(); emailparams[2] = GlobalVars.hostURL; emailparams[3] = "Work Request"; userEmail = email; #if (DEBUG) userEmail = "rkotian1@irf.com"; #endif try { emailSentList += email + ","; en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams); } catch { EventLogDMO.Add(new WinEventLog() { IssueID = ltWR.SWRNumber, UserID = userId, DocumentType = "Lot Traveler", OperationType = "Error", Comments = "WR Revision Change Notification:" + email }); } } return emailSentList; } public static string NotifyLotTravelerRevisionChange(AppSettings appSettings, string userId, string emailSentList, LTLotTravelerHeaderViewModel data, List emailIst) { string senderName = ""; string userEmail = string.Empty; string subject = "Lot Traveler Revision Change"; string emailTemplate = "LotTravelerRevisionChange.txt"; foreach (string email in emailIst) { subject = "Lot Traveler Revision for SWR# " + data.SWRNumber + ", Lot# " + data.LotNumber + " - " + data.Title; EmailNotification en = new(appSettings, subject); string[] emailparams = new string[4]; emailparams[0] = data.SWRNumber.ToString(); emailparams[1] = data.LTWorkRequestID.ToString(); emailparams[2] = GlobalVars.hostURL; emailparams[3] = data.LotNumber; userEmail = email; #if (DEBUG) userEmail = "rkotian1@irf.com"; #endif try { emailSentList += email + ","; en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams); } catch { EventLogDMO.Add(new WinEventLog() { IssueID = data.SWRNumber, UserID = userId, DocumentType = "Lot Traveler", OperationType = "Error", Comments = "Lot Traveler Revision Notification:" + email }); } } return emailSentList; } public static string NotifyLotTravelerCreation(AppSettings appSettings, string userId, string emailSentList, LTLotTravelerHeaderViewModel data, List emailIst) { string senderName = ""; string userEmail = string.Empty; string subject = "Lot Traveler Revision Change"; string emailTemplate = "LotTravelerCreation.txt"; foreach (string email in emailIst) { subject = "Lot Traveler created for SWR# " + data.SWRNumber + ", Lot# " + data.LotNumber + " - " + data.Title; EmailNotification en = new(appSettings, subject); string[] emailparams = new string[4]; emailparams[0] = data.SWRNumber.ToString(); emailparams[1] = data.LTWorkRequestID.ToString(); emailparams[2] = GlobalVars.hostURL; emailparams[3] = data.LotNumber; userEmail = email; #if (DEBUG) userEmail = "rkotian1@irf.com"; #endif try { emailSentList += email + ","; en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams); } catch { EventLogDMO.Add(new WinEventLog() { IssueID = data.SWRNumber, UserID = userId, DocumentType = "Lot Traveler", OperationType = "Error", Comments = "Lot Traveler Creation Email Notification:" + email }); } } return emailSentList; } public static void ReAssignApproval(AppSettings appSettings, string userId, int workRequestID, string email, LTWorkRequest ltWR) { string userEmail = string.Empty; string senderName = "Work Request"; string subject = "Work Request Re-Assignment"; string emailTemplate = "WorkRequestReAssigned.txt"; subject = "Work Request Re-Assignment" + " - Email would be sent to " + email + " for Number " + ltWR.SWRNumber + ", - " + ltWR.Title; EmailNotification en = new(appSettings, subject); string[] emailparams = new string[4]; emailparams[0] = ltWR.SWRNumber.ToString(); emailparams[1] = workRequestID.ToString(); emailparams[2] = GlobalVars.hostURL; emailparams[3] = "Work Request"; userEmail = email; try { en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams); } catch { EventLogDMO.Add(new WinEventLog() { IssueID = ltWR.SWRNumber, UserID = userId, DocumentType = "Lot Traveler", OperationType = "Error", Comments = "ReAssign Approval Notification:" + email }); } } public static string AddAdditionalApproval(AppSettings appSettings, string userId, int workRequestID, string emailSentList, string emailArray, LTWorkRequest ltWR) { string userEmail = string.Empty; string senderName = "Work Request"; string subject = "Work Request Assignment"; string emailTemplate = "WorkRequestAssigned.txt"; string[] emailIst = emailArray.Split(new char[] { '~' }); foreach (string email in emailIst) { if (email.Length > 0) { subject = "Work Request Assignment notice for Number " + workRequestID + ", - " + ltWR.Title; EmailNotification en = new(appSettings, subject); string[] emailparams = new string[4]; emailparams[0] = ltWR.SWRNumber.ToString(); emailparams[1] = workRequestID.ToString(); emailparams[2] = GlobalVars.hostURL; emailparams[3] = "Work Request"; userEmail = email; try { emailSentList += email + ","; en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams); } catch { EventLogDMO.Add(new WinEventLog() { IssueID = ltWR.SWRNumber, UserID = userId, DocumentType = "Lot Traveler", OperationType = "Error", Comments = "Addtional Approver Notification:" + email }); } } } return emailSentList; } public static void ReAssignApproverByAdmin(AppSettings appSettings, string userId, int workRequestID, string email, LTWorkRequest ltWR) { string subject; string userEmail = string.Empty; string senderName = "Work Request"; string emailTemplate = "WorkRequestReAssigned.txt"; subject = "Work Request Re-Assignment" + " - Email would be sent to " + email + " for Number " + ltWR.SWRNumber + ", - " + ltWR.Title; EmailNotification en = new(appSettings, subject); string[] emailparams = new string[4]; emailparams[0] = ltWR.SWRNumber.ToString(); emailparams[1] = workRequestID.ToString(); // goes into the link emailparams[2] = GlobalVars.hostURL; emailparams[3] = "Work Request"; userEmail = email; try { en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams); } catch { EventLogDMO.Add(new WinEventLog() { IssueID = ltWR.SWRNumber, UserID = userId, DocumentType = "Lot Traveler", OperationType = "Error", Comments = "ReAssign Approver Notification:" + email }); } } public static void HoldStepAttachSave(AppSettings appSettings, LotTravelerDMO lotTravelerDMO, int holdStepID, int swrNo, string docType, string comments, int userId, string fullFileName, Stream stream) { // Some browsers send file names with full path. // We are only interested in the file name. // TODO var fileName = Path.GetFileName(fullFileName); var fileExtension = Path.GetExtension(fullFileName); DirectoryInfo di; var SWRPhysicalPath = appSettings.AttachmentFolder + @"LotTraveler\" + swrNo; di = new DirectoryInfo(SWRPhysicalPath); if (!di.Exists) di.Create(); var SWR_RevPhysicalPath = appSettings.AttachmentFolder + @"LotTraveler\" + swrNo; di = new DirectoryInfo(SWR_RevPhysicalPath); if (!di.Exists) di.Create(); var guid = Guid.NewGuid().ToString(); var physicalPath = Path.Combine(appSettings.AttachmentFolder + @"LotTraveler\" + swrNo + @"\", guid + fileExtension); using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) { stream.CopyTo(fileStream); } LTWorkRequestAttachment attach = new() { FileGUID = guid, LTHoldStepID = holdStepID, FileName = fileName, UploadedByID = userId, DocType = docType, Comments = comments }; lotTravelerDMO.InsertLotHoldStepAttachment(attach); } public static void HoldStepAttachSaveRev(AppSettings appSettings, LotTravelerDMO lotTravelerDMO, int holdStepID, int swrNo, string docType, string comments, bool newRevision, int userId, string fullFileName, Stream stream) { // Some browsers send file names with full path. // We are only interested in the file name. // TODO var fileName = Path.GetFileName(fullFileName); var fileExtension = Path.GetExtension(fullFileName); DirectoryInfo di; var SWRPhysicalPath = appSettings.AttachmentFolder + @"LotTraveler\" + swrNo; di = new DirectoryInfo(SWRPhysicalPath); if (!di.Exists) di.Create(); var SWR_RevPhysicalPath = appSettings.AttachmentFolder + @"LotTraveler\" + swrNo; di = new DirectoryInfo(SWR_RevPhysicalPath); if (!di.Exists) di.Create(); var guid = Guid.NewGuid().ToString(); var physicalPath = Path.Combine(appSettings.AttachmentFolder + @"LotTraveler\" + swrNo + @"\", guid + fileExtension); using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) { stream.CopyTo(fileStream); } LTWorkRequestAttachment attach = new() { FileGUID = guid, LTHoldStepID = holdStepID, FileName = fileName, UploadedByID = userId, DocType = docType, Comments = comments }; if (newRevision) lotTravelerDMO.InsertLotHoldStepAttachmentRevision(attach); else lotTravelerDMO.InsertLotHoldStepAttachment(attach); } public static void AttachSaveWorkRequestRevision(AppSettings appSettings, LotTravelerDMO lotTravelerDMO, int workRequestID, int swrNo, string docType, string attachComments, bool newRevision, int userId, string fullFileName, Stream stream) { // Some browsers send file names with full path. // We are only interested in the file name. // TODO var fileName = Path.GetFileName(fullFileName); var fileExtension = Path.GetExtension(fullFileName); DirectoryInfo di; var SWRPhysicalPath = appSettings.AttachmentFolder + @"LotTraveler\" + swrNo; di = new DirectoryInfo(SWRPhysicalPath); if (!di.Exists) di.Create(); var SWR_RevPhysicalPath = appSettings.AttachmentFolder + @"LotTraveler\" + swrNo; di = new DirectoryInfo(SWR_RevPhysicalPath); if (!di.Exists) di.Create(); var guid = Guid.NewGuid().ToString(); var physicalPath = Path.Combine(appSettings.AttachmentFolder + @"LotTraveler\" + swrNo + @"\", guid + fileExtension); using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) { stream.CopyTo(fileStream); } LTWorkRequestAttachment attach = new() { WorkRequestID = workRequestID, FileGUID = guid, LTHoldStepID = -1, FileName = fileName, UploadedByID = userId, DocType = docType, Comments = attachComments }; // InsertWorkRequestAttachment(attach); if (newRevision) lotTravelerDMO.InsertWorkRequestAttachmentRevision(attach); else lotTravelerDMO.InsertWorkRequestAttachment(attach); } public static void AttachSaveWorkRequest(AppSettings appSettings, LotTravelerDMO lotTravelerDMO, int workRequestID, int swrNo, string comments, string docType, int userId, string fullFileName, Stream stream) { // Some browsers send file names with full path. // We are only interested in the file name. // TODO var fileName = Path.GetFileName(fullFileName); var fileExtension = Path.GetExtension(fullFileName); DirectoryInfo di; var SWRPhysicalPath = appSettings.AttachmentFolder + @"LotTraveler\" + swrNo; di = new DirectoryInfo(SWRPhysicalPath); if (!di.Exists) di.Create(); var SWR_RevPhysicalPath = appSettings.AttachmentFolder + @"LotTraveler\" + swrNo; di = new DirectoryInfo(SWR_RevPhysicalPath); if (!di.Exists) di.Create(); var guid = Guid.NewGuid().ToString(); var physicalPath = Path.Combine(appSettings.AttachmentFolder + @"LotTraveler\" + swrNo + @"\", guid + fileExtension); using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) { stream.CopyTo(fileStream); } LTWorkRequestAttachment attach = new() { WorkRequestID = workRequestID, FileGUID = guid, LTHoldStepID = -1, FileName = fileName, UploadedByID = userId, DocType = docType, Comments = comments }; lotTravelerDMO.InsertWorkRequestAttachment(attach); } public static void LotTravHoldStepAttachSaveRev(AppSettings appSettings, LotTravelerDMO lotTravelerDMO, int ltHoldStepID, int swrNo, string docType, int prevLotTravRevID, int newLotTravRevID, bool newRevision, int userId, string fullFileName, Stream stream) { // Some browsers send file names with full path. // We are only interested in the file name. // TODO var fileName = Path.GetFileName(fullFileName); var fileExtension = Path.GetExtension(fullFileName); DirectoryInfo di; var SWRPhysicalPath = appSettings.AttachmentFolder + @"LotTraveler\" + swrNo; di = new DirectoryInfo(SWRPhysicalPath); if (!di.Exists) di.Create(); var SWR_RevPhysicalPath = appSettings.AttachmentFolder + @"LotTraveler\" + swrNo; di = new DirectoryInfo(SWR_RevPhysicalPath); if (!di.Exists) di.Create(); var guid = Guid.NewGuid().ToString(); var physicalPath = Path.Combine(appSettings.AttachmentFolder + @"LotTraveler\" + swrNo + @"\", guid + fileExtension); using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) { stream.CopyTo(fileStream); } LTLotTravAttachment attach = new() { FileGUID = guid, LTLotTravHoldStepID = ltHoldStepID, LotTravelerRevisionID = newLotTravRevID, FileName = fileName, UploadedByID = userId, DocType = docType }; if (newRevision) { try { lotTravelerDMO.InsertLotTravLotHoldStepAttachmentRevision(attach); } catch { // roll back the revision creation lotTravelerDMO.RestoreLotTravToPrevRevision(prevLotTravRevID, newLotTravRevID); throw new Exception("There was a problem while creating the revision, Please logout and log back and then retry. \n If the problem persist please contact the Site Administrator"); } } else lotTravelerDMO.InsertLotTravLotHoldStepAttachment(attach); } }