Moved System.IO references from DMO classes to Static Helpers

Removed nugetSource from pipeline
Removed more comments
Created Static Classes for most DMO / Controller Classes
Push ConfigurationManager.AppSettings to controller
Align Tests with other Projects
This commit is contained in:
2024-12-11 09:29:01 -07:00
parent b1c6903c1c
commit b99b721458
86 changed files with 2961 additions and 4432 deletions

View File

@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.IO;
using Fab2ApprovalSystem.DMO;
using Fab2ApprovalSystem.Models;
namespace Fab2ApprovalSystem.Misc;
public class AuditHelper {
public static List<string> GetFileNameAndDocument(AppSettings appSettings, AuditDMO auditDMO, string fileGuid, int auditNo) {
List<string> results = new();
string fileName = auditDMO.GetAuditReportAttachmentFileName(fileGuid);
string fileExtension = fileName.Substring(fileName.LastIndexOf("."), fileName.Length - fileName.LastIndexOf("."));
string ecnFolderPath = appSettings.AttachmentFolder + "Audit\\" + auditNo.ToString();
string sDocument = Path.Combine(ecnFolderPath, fileGuid + fileExtension);
string FDir_AppData = appSettings.AttachmentFolder;
if (!sDocument.StartsWith(FDir_AppData)) {
sDocument = string.Empty;
}
results.Add(fileName);
results.Add(sDocument);
return results;
}
public static void AuditReportAttachSave(AppSettings appSettings, AuditDMO auditDMO, int auditNo, int userId, string fullFileName, Stream stream) {
// Some browsers send file names with full path.
// We are only interested in the file name.
var fileName = Path.GetFileName(fullFileName);
var fileExtension = Path.GetExtension(fullFileName);
DirectoryInfo di;
var ccPhysicalPath = appSettings.AttachmentFolder + @"Audit\" + auditNo;
di = new DirectoryInfo(ccPhysicalPath);
if (!di.Exists)
di.Create();
var guid = Guid.NewGuid().ToString();
var physicalPath = Path.Combine(appSettings.AttachmentFolder + @"Audit\" + auditNo + @"\", guid + fileExtension);
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
stream.CopyTo(fileStream);
}
AuditReportAttachment attach = new() {
AuditNo = auditNo,
FileGUID = guid,
FileName = fileName,
UploadedByID = userId
};
auditDMO.InsertAuditReportAttachment(attach);
}
public static void SaveAndInsert(AppSettings appSettings, AuditDMO auditDMO, int caFindingsID, int auditNo, int userId, string fullFileName, Stream stream) {
// Some browsers send file names with full path.
// We are only interested in the file name.
var fileName = Path.GetFileName(fullFileName);
var fileExtension = Path.GetExtension(fullFileName);
DirectoryInfo di;
var ccPhysicalPath = appSettings.AttachmentFolder + @"Audit\" + auditNo;
di = new DirectoryInfo(ccPhysicalPath);
if (!di.Exists)
di.Create();
var guid = Guid.NewGuid().ToString();
var physicalPath = Path.Combine(appSettings.AttachmentFolder + @"Audit\" + auditNo + @"\", guid + fileExtension);
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
stream.CopyTo(fileStream);
}
AuditReportAttachment attach = new() {
CAFindingsID = caFindingsID,
AuditNo = auditNo,
FileGUID = guid,
FileName = fileName,
UploadedByID = userId
};
auditDMO.InsertAuditReportAttachment(attach);
}
}

View File

@ -0,0 +1,96 @@
using System;
using System.IO;
using Fab2ApprovalSystem.DMO;
using Fab2ApprovalSystem.Models;
namespace Fab2ApprovalSystem.Misc;
public class ChangeControlHelper {
public static void AttachSaveCC(AppSettings appSettings, ChangeControlDMO changeControlDMO, int planNumber, int attachID, int userId, string fullFileName, Stream stream) {
// Some browsers send file names with full path.
// We are only interested in the file name.
var fileName = Path.GetFileName(fullFileName);
var fileExtension = Path.GetExtension(fullFileName);
DirectoryInfo di;
var ccPhysicalPath = appSettings.AttachmentFolder + @"ChangeControl\" + planNumber;
di = new DirectoryInfo(ccPhysicalPath);
if (!di.Exists)
di.Create();
var guid = Guid.NewGuid().ToString();
var physicalPath = Path.Combine(appSettings.AttachmentFolder + @"ChangeControl\" + planNumber + @"\", guid + fileExtension);
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
stream.CopyTo(fileStream);
}
CCAttachment attach = new() {
ID = attachID,
FileGUID = guid,
FileName = fileName,
UploadedByID = userId
};
changeControlDMO.UpdateCCAttachmentDocument(attach);
}
public static void AttachSaveMeeting(AppSettings appSettings, ChangeControlDMO changeControlDMO, int planNumber, int attachID, int userId, string fullFileName, Stream stream) {
// Some browsers send file names with full path.
// We are only interested in the file name.
var fileName = Path.GetFileName(fullFileName);
var fileExtension = Path.GetExtension(fullFileName);
DirectoryInfo di;
var ccPhysicalPath = appSettings.AttachmentFolder + @"ChangeControl\" + planNumber;
di = new DirectoryInfo(ccPhysicalPath);
if (!di.Exists)
di.Create();
var guid = Guid.NewGuid().ToString();
var physicalPath = Path.Combine(appSettings.AttachmentFolder + @"ChangeControl\" + planNumber + @"\", guid + fileExtension);
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
stream.CopyTo(fileStream);
}
CCMeetingAttachment attach = new() {
ID = attachID,
FileGUID = guid,
FileName = fileName,
UploadedByID = userId
};
changeControlDMO.UpdateMeetingAttachmentDocument(attach);
}
public static void AttachSaveActionItem(AppSettings appSettings, ChangeControlDMO changeControlDMO, int planNumber, int attachID, int userId, string fullFileName, Stream stream) {
// Some browsers send file names with full path.
// We are only interested in the file name.
var fileName = Path.GetFileName(fullFileName);
var fileExtension = Path.GetExtension(fullFileName);
DirectoryInfo di;
var ccPhysicalPath = appSettings.AttachmentFolder + @"ChangeControl\" + planNumber;
di = new DirectoryInfo(ccPhysicalPath);
if (!di.Exists)
di.Create();
var guid = Guid.NewGuid().ToString();
var physicalPath = Path.Combine(appSettings.AttachmentFolder + @"ChangeControl\" + planNumber + @"\", guid + fileExtension);
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
stream.CopyTo(fileStream);
}
CCMeetingActionItemAll attach = new() {
ID = attachID,
FileGUID = guid,
FileName = fileName,
UploadedByID = userId
};
changeControlDMO.UpdateActionItemAttachment(attach);
}
}

View File

@ -0,0 +1,464 @@
using System;
using System.Collections.Generic;
using System.IO;
using Fab2ApprovalSystem.DMO;
using Fab2ApprovalSystem.Models;
namespace Fab2ApprovalSystem.Misc;
public class CorrectiveActionHelper {
public static void ProcessCARDueDates(AppSettings appSettings, CAD3D5D7Due dueCA, CorrectiveAction ca, LoginModel user) {
string[] emailparams = new string[7];
string emailTemplate = "D3D5D7Due.txt";
string senderName = "CorrectiveAction";
string subject = "Corrective Action " + dueCA.ItemDue + " " + dueCA.ExpiryType + " - " + Functions.ReturnCANoStringFormat(dueCA.CANo);
emailparams[0] = Functions.ReturnCANoStringFormat(dueCA.CANo);
emailparams[1] = dueCA.CANo.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = dueCA.ExpiryType;
emailparams[4] = dueCA.ItemDue;
if (ca.D3DueDate != null) {
emailparams[5] = ca.D3DueDate is null ? string.Empty : ca.D3DueDate.Value.ToString();
} else {
emailparams[5] = "N/A";
}
if (ca.D5D7DueDate != null) {
emailparams[6] = ca.D5D7DueDate is null ? string.Empty : ca.D5D7DueDate.Value.ToString();
} else {
emailparams[6] = "N/A";
}
EmailNotification en = new(appSettings, subject);
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, user.Email, "jonathan.ouellette@infineon.com", subject, emailparams);
}
public static void NotifyUsersDSectionApproved(AppSettings appSettings, int issueID, string dSection, string userEmail) {
string senderName = "CorrectiveAction";
string emailTemplate = "CorrectiveActionSectionApproved.txt";
string subject = "Corrective Action Section Approval - " + Functions.ReturnCANoStringFormat(issueID);
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[4];
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = dSection;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
}
public static void NotifyForD5D6D7Validation(AppSettings appSettings, int issueID, string dSection, string userEmail) {
string senderName = "CorrectiveAction";
string emailTemplate = "CorrectiveActionSectionApproved.txt";
string subject = "Corrective Action Section Approval - " + Functions.ReturnCANoStringFormat(issueID);
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[4];
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = dSection;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
}
public static void NotifySectionRejection(AppSettings appSettings, int issueID, int loggedInUserId, string section, string comment, LoginModel recipient, LoginModel loggedInUser) {
string senderName = "CorrectiveAction";
string recipientEmail = recipient.Email;
string emailTemplate = "CorrectiveActionSectionRejection.txt";
string subject = "Corrective Action Rejection - " + Functions.ReturnCANoStringFormat(issueID);
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[6];
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = section;
emailparams[4] = loggedInUser.FirstName + " " + loggedInUser.LastName;
emailparams[5] = comment;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, recipientEmail, null, subject, emailparams);
}
public static void NotifySectionRejection(AppSettings appSettings, int issueID, string section, string comment, LoginModel recipient, LoginModel loggedInUser) {
string senderName = "CorrectiveAction";
string recipientEmail = recipient.Email;
string emailTemplate = "CorrectiveActionSectionRejection.txt";
string subject = "Corrective Action Rejection - " + Functions.ReturnCANoStringFormat(issueID);
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[6];
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = section;
emailparams[4] = loggedInUser.FirstName + " " + loggedInUser.LastName;
emailparams[5] = comment;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, recipientEmail, null, subject, emailparams);
}
public static string NotifyCompletionOf8D(AppSettings appSettings, int issueID, DateTime? followUpDate) {
string emailSentList = "";
string senderName = "CorrectiveAction";
string emailTemplate = "CorrectiveActionCompleted.txt";
List<string> emailIst = MiscDMO.Get8DEmailListForClosureNotification(issueID);
string subject = "Corrective Action Completion - " + Functions.ReturnCANoStringFormat(issueID);
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[4];
foreach (string email in emailIst) {
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
emailparams[1] = GlobalVars.hostURL;
emailparams[2] = issueID.ToString();
emailparams[3] = followUpDate is null ? string.Empty : followUpDate.Value.ToString();
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, email, null, subject, emailparams);
emailSentList += email + ",";
}
return emailSentList;
}
public static string NotifyClosureOf8D(AppSettings appSettings, int issueID) {
string emailSentList = "";
string senderName = "CorrectiveAction";
string emailTemplate = "CorrectiveActionClosed.txt";
List<string> emailIst = MiscDMO.Get8DEmailListForClosureNotification(issueID);
string subject = "Corrective Action Follow Up Closure - " + Functions.ReturnCANoStringFormat(issueID);
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[3];
foreach (string email in emailIst) {
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
emailparams[1] = GlobalVars.hostURL;
emailparams[2] = issueID.ToString();
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, email, null, subject, emailparams);
emailSentList += email + ",";
}
return emailSentList;
}
public static string NotifyActionItemCompletion(AppSettings appSettings, int issueID, DateTime? dueDate, int? recipientId, string template) {
string emailSentList = "";
string emailTemplate = template;
string userEmail = string.Empty;
string senderName = "CorrectiveAction";
string email = MiscDMO.GetEmail(recipientId);
string subject = "8D Action Item Completion - " + Functions.ReturnCANoStringFormat(issueID);
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[5];
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
emailparams[1] = dueDate is null ? string.Empty : dueDate.Value.ToString();
emailparams[2] = Functions.DocumentTypeMapper(GlobalVars.DocumentType.CorrectiveAction);
emailparams[3] = GlobalVars.hostURL;
emailparams[4] = issueID.ToString();
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, email, null, subject, emailparams);
emailSentList += email + ",";
return email;
}
public static string NotifyActionItemOwner(AppSettings appSettings, int issueID, DateTime? dueDate, int? responsibleOwnerID, string template) {
string emailSentList = "";
string emailTemplate = template;
string userEmail = string.Empty;
string senderName = "CorrectiveAction";
string email = MiscDMO.GetEmail(responsibleOwnerID);
string subject = "Action Item in " + Functions.ReturnCANoStringFormat(issueID);
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[5];
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
emailparams[1] = dueDate is null ? string.Empty : dueDate.Value.ToString();
emailparams[2] = Functions.DocumentTypeMapper(GlobalVars.DocumentType.CorrectiveAction);
emailparams[3] = GlobalVars.hostURL;
emailparams[4] = issueID.ToString();
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, email, null, subject, emailparams);
emailSentList += email + ",";
return email;
}
public static void NotifyAssignee(AppSettings appSettings, int issueID, string template, DateTime? D3DueDate, DateTime? D5D7DueDate, string email) {
string emailSentList = "";
string emailTemplate = template;
string userEmail = string.Empty;
string senderName = "CorrectiveAction";
string subject = "CAR Assigned - " + Functions.ReturnCANoStringFormat(issueID);
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[6];
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
emailparams[1] = Functions.DocumentTypeMapper(GlobalVars.DocumentType.CorrectiveAction);
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = issueID.ToString();
emailparams[4] = D3DueDate is not null ? D3DueDate.Value.ToString() : "N/A";
emailparams[5] = D5D7DueDate is not null ? D5D7DueDate.Value.ToString() : "N/A";
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, email, null, subject, emailparams);
emailSentList += email + ",";
}
public static void NotifyRequestor(AppSettings appSettings, int issueID, DateTime? dueDate, string template, string email) {
string emailSentList = "";
string emailTemplate = template;
string userEmail = string.Empty;
string senderName = "CorrectiveAction";
string subject = "Corrective Action Assignment - " + Functions.ReturnCANoStringFormat(issueID);
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[5];
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
emailparams[1] = dueDate is null ? string.Empty : dueDate.Value.ToString();
emailparams[2] = Functions.DocumentTypeMapper(GlobalVars.DocumentType.CorrectiveAction);
emailparams[3] = GlobalVars.hostURL;
emailparams[4] = issueID.ToString();
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, email, null, subject, emailparams);
emailSentList += email + ",";
}
public static string AddAdditionalApproval(AppSettings appSettings, int issueID, string emailSentList, string emailArray) {
string userEmail = string.Empty;
string senderName = "CorrectiveAction";
string emailTemplate = "CorrectiveActionAssigned.txt";
string subject = "Corrective Action Assignment - Final Approval";
string[] emailIst = emailArray.Split(new char[] { '~' });
foreach (string email in emailIst) {
if (email.Length > 0) {
subject = "Corrective Action Assignment";
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[3];
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
userEmail = email;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
emailSentList += email + ",";
}
}
return emailSentList;
}
public static string NotifyApprovers(AppSettings appSettings, int issueID, List<string> emailIst) {
string emailSentList = "";
string userEmail = string.Empty;
string senderName = "CorrectiveAction";
string subject = "Corrective Action Assignment";
string emailTemplate = "CorrectiveActionAssigned.txt";
foreach (string email in emailIst) {
subject = "Corrective Action Assignment - Final Approval";
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[3];
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
userEmail = email;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
emailSentList += email + ",";
}
return emailSentList;
}
public static void NotifySectionApprover(AppSettings appSettings, int issueID, string section, string userEmail) {
string senderName = "CorrectiveAction";
string subject = "Corrective Action Assignment";
string emailTemplate = "CorrectiveActionSectionAssignee.txt";
subject = "Corrective Action Assignment - Section Approval";
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[4];
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = section;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
}
public static string NotifyRejectionToAssignee(AppSettings appSettings, int issueID, string comments, string username, List<string> emailIst) {
string userEmail = string.Empty;
string senderName = "CorrectiveAction";
string subject = "Corrective Action Rejection";
string emailTemplate = "CorrectiveActionReject.txt";
foreach (string email in emailIst) {
subject = "Corrective Action Rejection";
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[5];
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = username;
emailparams[4] = comments;
userEmail = email;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
}
return userEmail;
}
public static void ReAssignApproval(AppSettings appSettings, int issueID, string email) {
string userEmail = string.Empty;
string senderName = "CorrectiveAction";
string subject = "Corrective Action Re-Assignment";
string emailTemplate = "CorrectiveActionReAssigned.txt";
subject = "Corrective Action Re-Assignment" + " - Email would be sent to " + email;
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[3];
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
userEmail = email;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
}
public static void ReAssignApproverByAdmin(AppSettings appSettings, int issueID, string email) {
string userEmail = string.Empty;
string senderName = "CorrectiveAction";
string subject = "Corrective Action Re-Assignment";
string emailTemplate = "CorrectiveActionReAssigned.txt";
subject = "Corrective Action Re-Assignment" + " - Email would be sent to " + email;
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[3];
emailparams[0] = Functions.ReturnCANoStringFormat(issueID);
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
userEmail = email;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
}
public static void AttachSave(AppSettings appSettings, CorrectiveActionDMO correctiveActionDMO, int caNo, int userId, string fullFileName, Stream stream) {
// Some browsers send file names with full path.
// We are only interested in the file name.
var fileName = Path.GetFileName(fullFileName);
var fileExtension = Path.GetExtension(fullFileName);
DirectoryInfo di;
var ccPhysicalPath = appSettings.AttachmentFolder + @"CorrectiveAction\" + caNo;
di = new DirectoryInfo(ccPhysicalPath);
if (!di.Exists)
di.Create();
var guid = Guid.NewGuid().ToString();
var physicalPath = Path.Combine(appSettings.AttachmentFolder + @"CorrectiveAction\" + caNo + @"\", guid + fileExtension);
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
stream.CopyTo(fileStream);
}
CA_Attachment attach = new() {
CANo = caNo,
FileGUID = guid,
FileName = fileName,
UploadedByID = userId,
Section = Functions.CASectionMapper(GlobalVars.CASection.Main)
};
correctiveActionDMO.InsertCAAttachment(attach);
}
public static void D4FilesAttachSave(AppSettings appSettings, CorrectiveActionDMO correctiveActionDMO, int caNo, int userId, string fullFileName, Stream stream) {
// Some browsers send file names with full path.
// We are only interested in the file name.
var fileName = Path.GetFileName(fullFileName);
var fileExtension = Path.GetExtension(fullFileName);
DirectoryInfo di;
var ccPhysicalPath = appSettings.AttachmentFolder + @"CorrectiveAction\" + caNo;
di = new DirectoryInfo(ccPhysicalPath);
if (!di.Exists)
di.Create();
var guid = Guid.NewGuid().ToString();
var physicalPath = Path.Combine(appSettings.AttachmentFolder + @"CorrectiveAction\" + caNo + @"\", guid + fileExtension);
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
stream.CopyTo(fileStream);
}
CA_Attachment attach = new() {
CANo = caNo,
FileGUID = guid,
FileName = fileName,
UploadedByID = userId,
Section = Functions.CASectionMapper(GlobalVars.CASection.D4)
};
correctiveActionDMO.InsertCAAttachment(attach);
}
public static void SaveD7PA_Attachemnt(AppSettings appSettings, CorrectiveActionDMO correctiveActionDMO, int d7PAID, int caNo, int userId, string fullFileName, Stream stream) {
// Some browsers send file names with full path.
// We are only interested in the file name.
var fileName = Path.GetFileName(fullFileName);
var fileExtension = Path.GetExtension(fullFileName);
DirectoryInfo di;
var ccPhysicalPath = appSettings.AttachmentFolder + @"CorrectiveAction\" + caNo;
di = new DirectoryInfo(ccPhysicalPath);
if (!di.Exists)
di.Create();
var guid = Guid.NewGuid().ToString();
var physicalPath = Path.Combine(appSettings.AttachmentFolder + @"CorrectiveAction\" + caNo + @"\", guid + fileExtension);
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
stream.CopyTo(fileStream);
}
CA_Attachment attach = new() {
D7PAID = d7PAID,
CANo = caNo,
FileGUID = guid,
FileName = fileName,
UploadedByID = userId,
Section = Functions.CASectionMapper(GlobalVars.CASection.D7)
};
correctiveActionDMO.InsertCAAttachment(attach);
}
public static void SaveD5D6CA_Attachemnt(AppSettings appSettings, CorrectiveActionDMO correctiveActionDMO, int d5d6CAID, int caNo, int userId, string fullFileName, Stream stream) {
// Some browsers send file names with full path.
// We are only interested in the file name.
var fileName = Path.GetFileName(fullFileName);
var fileExtension = Path.GetExtension(fullFileName);
DirectoryInfo di;
var ccPhysicalPath = appSettings.AttachmentFolder + @"CorrectiveAction\" + caNo;
di = new DirectoryInfo(ccPhysicalPath);
if (!di.Exists)
di.Create();
var guid = Guid.NewGuid().ToString();
var physicalPath = Path.Combine(appSettings.AttachmentFolder + @"CorrectiveAction\" + caNo + @"\", guid + fileExtension);
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
stream.CopyTo(fileStream);
}
CA_Attachment attach = new() {
D5D6CAID = d5d6CAID,
CANo = caNo,
FileGUID = guid,
FileName = fileName,
UploadedByID = userId,
Section = Functions.CASectionMapper(GlobalVars.CASection.D5)
};
correctiveActionDMO.InsertCAAttachment(attach);
}
}

View File

@ -0,0 +1,524 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Fab2ApprovalSystem.DMO;
using Fab2ApprovalSystem.Models;
using Fab2ApprovalSystem.ViewModels;
namespace Fab2ApprovalSystem.Misc;
public class ECNHelper {
private const string ECN_PREFIX = "ECN_";
private const string TECN_PREFIX = "TECN_";
private const string ETECN_PREFIX = "ETECN_";
public static bool IsITAR(ECN ecn) {
if (ecn.IsRH && !ecn.IsAU && !ecn.IsIndustrial && !ecn.IsMA) {
return true;
} else
return false;
}
public static string NotifyEmergencyTECNApproval(AppSettings appSettings, int ecnNumber, DateTime? expDate, ECN ecn) {
string emailSentList = "";
string senderName = "E-TECN";
string userEmail = string.Empty;
string subject = "E-TECN Approved";
string emailTemplate = "ETECNApproved.txt";
List<string> emailIst = MiscDMO.GetEmergencyTECNApprovalNotifyList(ecnNumber).Distinct().ToList();
string ecnFolderPath = appSettings.AttachmentFolder + "E-TECNZipped\\" + ETECN_PREFIX + ecnNumber.ToString() + ".zip";
subject = "E-TECN Approved notice for Number " + ecn.ECNNumber + ", - " + ecn.Title;
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[5];
emailparams[0] = ecnNumber.ToString();
emailparams[1] = ecnNumber.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = "E-TECN";
emailparams[4] = expDate is null ? string.Empty : expDate.Value.ToString();
if (IsITAR(ecn))
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, emailIst, null, subject, emailparams);
else
en.SendNotificationEmailWithAttachment(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, emailIst, null, subject, ecnFolderPath, emailparams);
emailSentList = string.Join(", ", emailIst.Distinct().ToArray());
return emailSentList;
}
public static string NotifyApproversForCancellation(AppSettings appSettings, int ecnNumber, byte currentStep, int documentType, string ecnTypeString, ECN ecn) {
string emailSentList = "";
string userEmail = string.Empty;
string senderName = ecnTypeString;
string emailTemplate = "TECNCancellationApproval.txt";
List<string> emailIst = MiscDMO.GetApproverEmailListByDocument(@ecnNumber, currentStep, documentType).Distinct().ToList();
string subject = ecnTypeString + " Cancellation Approval Required - " + ecnNumber + " for " + ecn.Title + ", Cancellation initiated on :" + ecn.CancellationDate;
foreach (string email in emailIst) {
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[4];
emailparams[0] = ecnNumber.ToString();
emailparams[1] = ecnNumber.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = ecnTypeString;
userEmail = email;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
emailSentList += email + ",";
}
return emailSentList;
}
public static string NotifyApproversForRecall(AppSettings appSettings, int ecnNumber, byte currentStep, int documentType, string ecnTypeString, string recallComments, ECN ecn) {
string emailSentList = "";
List<string> emailIst = MiscDMO.GetApproverEmailListByDocument(@ecnNumber, currentStep, documentType).Distinct().ToList();
emailIst.Add("Jeanne.McIntyre@infineon.com");
emailIst.Add("Jonathan.Ouellette@infineon.com");
string emailTemplate = "ECNRecallApproval.txt";
string userEmail = string.Empty;
string subject = ecnTypeString + " Recalled - " + ecnNumber + " for " + ecn.Title + ", Recall initiated on :" + DateTime.Now.ToString();
string senderName = ecnTypeString;
foreach (string email in emailIst) {
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[5];
emailparams[0] = ecnNumber.ToString();
emailparams[1] = ecnNumber.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = ecnTypeString;
emailparams[4] = recallComments;
userEmail = email;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
emailSentList += email + ",";
}
return emailSentList;
}
public static string NotifyApproversForExpiration(AppSettings appSettings, int ecnNumber, byte currentStep, int documentType, string ecnTypeString, ECN ecn) {
string emailSentList = "";
string userEmail = string.Empty;
string senderName = ecnTypeString;
string emailTemplate = "TECNExpirationApproval.txt";
List<string> emailIst = MiscDMO.GetApproverEmailListByDocument(@ecnNumber, currentStep, documentType).Distinct().ToList();
string subject = " TECN Expiration Approval Reqquired - " + ecnTypeString + "# " + ecnNumber + " for " + ecn.Title + ", Expired:" + ecn.ExpirationDate;
foreach (string email in emailIst) {
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[4];
emailparams[0] = ecnNumber.ToString();
emailparams[1] = ecnNumber.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = ecnTypeString;
userEmail = email;
#if (DEBUG)
userEmail = GlobalVars.SENDER_EMAIL;
#endif
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
emailSentList += email + ",";
}
return emailSentList;
}
public static string NotifyTECNCancellation(AppSettings appSettings, UserAccountDMO userDMO, int ecnNumber, string ecnFolderPath, ECN ecn, List<int> notificationUserList) {
string emailSentList = "";
List<string> emailIst = MiscDMO.GetTECNCancelledApprovalNotifyList(ecnNumber).Distinct().ToList();
foreach (int userId in notificationUserList) {
string email = userDMO.GetUserEmailByID(userId);
if (email != null && !emailIst.Contains(email))
emailIst.Add(email);
}
string subject = string.Empty;
string userEmail = string.Empty;
string emailTemplate = "TECNCancelled.txt";
if (ecn.CancellationApprovalDate == null) {
subject = "TECN Cancellation Initiated Notice - " + ecnNumber + " for " + ecn.Title + ", Cancellation Initiated on:" + DateTime.Now;
} else {
subject = "TECN Cancellation Approved Notice - " + ecnNumber + " for " + ecn.Title + ", Cancelled:" + ecn.CancellationApprovalDate;
}
string senderName = "ECN";
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[5];
emailparams[0] = ecnNumber.ToString();
emailparams[1] = ecnNumber.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = "TECN";
emailparams[4] = DateTime.Now.ToString();
#if (DEBUG)
userEmail = GlobalVars.SENDER_EMAIL;
#endif
if (IsITAR(ecn))
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, emailIst, null, subject, emailparams);
else
en.SendNotificationEmailWithAttachment(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, emailIst, null, subject, ecnFolderPath, emailparams);
emailSentList = string.Join(", ", emailIst.Distinct().ToArray());
return emailSentList;
}
public static string NotifyTECNAutoCancellation(AppSettings appSettings, int ecnNumber, int tecnNumber, List<string> attachments, ECN ecn) {
string emailSentList = "";
string senderName = "ECN";
string subject = string.Empty;
string userEmail = string.Empty;
string emailTemplate = "TECNAutoCancelled.txt";
List<string> emailIst = MiscDMO.GetTECNCancelledApprovalNotifyList(ecnNumber).Distinct().ToList();
subject = "TECN Conversion and Cancellation Notice - " + tecnNumber + " for " + ecn.Title + ", Converted on:" + DateTime.Now;
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[6];
emailparams[0] = tecnNumber.ToString();
emailparams[1] = tecnNumber.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = "TECN";
emailparams[4] = DateTime.Now.ToString();
emailparams[5] = ecnNumber.ToString();
#if (DEBUG)
userEmail = GlobalVars.SENDER_EMAIL;
#endif
if (IsITAR(ecn))
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, emailIst, null, subject, emailparams);
else
en.SendNotificationEmailWithAttachments(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, emailIst, null, subject, attachments, emailparams);
emailSentList = string.Join(", ", emailIst.Distinct().ToArray());
return emailSentList;
}
public static string NotifyTECNExpiration(AppSettings appSettings, int ecnNumber, string ecnFolderPath, ECN ecn) {
string emailSentList = "";
string senderName = "ECN";
string userEmail = string.Empty;
string emailTemplate = "TECNExpired.txt";
List<string> emailIst = MiscDMO.GetEmergencyTECNApprovalNotifyList(ecnNumber).Distinct().ToList();
string subject = "TECN Expiration Approved Notice - " + ecnNumber + " for " + ecn.Title + ", Expired:" + ecn.ExpirationDate;
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[5];
emailparams[0] = ecnNumber.ToString();
emailparams[1] = ecnNumber.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = "TECN";
emailparams[4] = ecn.ExpirationDate.Value.ToShortDateString();
if (IsITAR(ecn))
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, emailIst, null, subject, emailparams);
else
en.SendNotificationEmailWithAttachment(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, emailIst, null, subject, ecnFolderPath, emailparams);
emailSentList = string.Join(", ", emailIst.Distinct().ToArray());
return emailSentList;
}
public static void ReAssignApproval(AppSettings appSettings, int issueID, string ecnTypeString, string email, ECN ecn) {
string userEmail = string.Empty;
string senderName = ecnTypeString;
string emailTemplate = "ECNReAssigned.txt";
string subject = ecnTypeString + " Re-Assignment";
subject = ecnTypeString + " Re-Assignment" + " - Email would be sent to " + email + " for Number " + ecn.ECNNumber + ", - " + ecn.Title;
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[4];
emailparams[0] = issueID.ToString();
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = ecnTypeString;
userEmail = email;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
}
public static string AddEECNApproval(AppSettings appSettings, int ecnNumber, string emailSentList, string emailArray, ECN ecn) {
string senderName = "E-TECN";
string userEmail = string.Empty;
string subject = "E-TECN Assignment";
string emailTemplate = "ECNAssigned.txt";
string[] emailIst = emailArray.Split(new char[] { '~' });
foreach (string email in emailIst) {
if (email.Length > 0) {
subject = "E-TECN Assignment notice for Number " + ecn.ECNNumber + ", - " + ecn.Title;
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[4];
emailparams[0] = ecnNumber.ToString();
emailparams[1] = ecnNumber.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = "E-TECN";
userEmail = email;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
emailSentList += email + ",";
}
}
return emailSentList;
}
public static string AddAdditionalApproval(AppSettings appSettings, int issueID, string ecnTypeString, string emailSentList, string emailArray, ECN ecn) {
string userEmail = string.Empty;
string senderName = ecnTypeString;
string emailTemplate = "ECNAssigned.txt";
string subject = ecnTypeString + " Assignment";
string[] emailIst = emailArray.Split(new char[] { '~' });
foreach (string email in emailIst) {
if (email.Length > 0) {
subject = ecnTypeString + "Assignment notice for Number " + ecn.ECNNumber + ", - " + ecn.Title;
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[4];
emailparams[0] = issueID.ToString();
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = ecnTypeString;
userEmail = email;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
emailSentList += email + ",";
}
}
return emailSentList;
}
public static void ReAssignApproverByAdmin(AppSettings appSettings, int issueID, string ecnTypeString, string email, ECN ecn) {
string subject;
string userEmail = string.Empty;
string senderName = ecnTypeString;
string emailTemplate = "ECNReAssigned.txt";
subject = ecnTypeString + " Re-Assignment" + " - ECN #" + ecn.ECNNumber + ", - " + ecn.Title;
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[4];
emailparams[0] = issueID.ToString();
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = ecnTypeString;
userEmail = email;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
}
public static string NotifyTECNExtensionRejectionToOrginator(AppSettings appSettings, int issueID, string ecnTypeString, List<string> emailIst, ECN ecn, string username) {
string userEmail = string.Empty;
string senderName = ecnTypeString;
string subject = ecnTypeString + " Rejection";
string emailTemplate = "TECNExtensionReject.txt";
foreach (string email in emailIst) {
subject = ecnTypeString + " Extension Rejection notice for Number " + ecn.ECNNumber + ", - " + ecn.Title;
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[5];
emailparams[0] = issueID.ToString();
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = username;
emailparams[4] = ecnTypeString;
userEmail = email;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
}
return userEmail;
}
public static string NotifyRejectionToOrginator(AppSettings appSettings, int issueID, string ecnTypeString, string comments, List<string> emailIst, ECN ecn, string username) {
string userEmail = string.Empty;
string senderName = ecnTypeString;
string emailTemplate = "ECNReject.txt";
string subject = ecnTypeString + " Rejection";
foreach (string email in emailIst) {
subject = ecnTypeString + " Rejection notice for Number " + ecn.ECNNumber + ", - " + ecn.Title;
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[6];
emailparams[0] = issueID.ToString();
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = username;
emailparams[4] = ecnTypeString;
emailparams[5] = comments;
userEmail = email;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
}
return userEmail;
}
public static string NotifyApprovers(AppSettings appSettings, int ecnNumber, string ecnTypeString, string emailSentList, ECN ecn, List<string> emailIst) {
string subject = string.Empty;
string userEmail = string.Empty;
string senderName = ecnTypeString;
string emailTemplate = "ECNAssigned.txt";
subject = ecnTypeString + " Assignment notice for Number " + ecn.ECNNumber + ", - " + ecn.Title;
foreach (string email in emailIst) {
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[4];
emailparams[0] = ecnNumber.ToString();
emailparams[1] = ecnNumber.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = ecnTypeString;
userEmail = email;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
emailSentList += email + ",";
}
return emailSentList;
}
public static string NotifyAdmin(AppSettings appSettings, int ecnNumber, string ecnTypeString, ECN ecn, int id) {
string emailSentList;
string subject = string.Empty;
string userEmail = string.Empty;
string senderName = ecnTypeString;
string emailTemplate = "ECNApproved.txt";
string ecnCreatedByEmail = MiscDMO.GetEmail(id);
subject = ecnTypeString + " Approval notice for Number " + ecn.ECNNumber + ", - " + ecn.Title;
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[4];
emailparams[0] = ecnNumber.ToString();
emailparams[1] = ecnNumber.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = ecnTypeString;
userEmail = ecnCreatedByEmail;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
emailSentList = ecnCreatedByEmail;
return emailSentList;
}
public static string NotifySubmitter(AppSettings appSettings, int ecnNumber, string ecnTypeString, ECN ecn) {
string emailSentList;
string subject = string.Empty;
string userEmail = string.Empty;
string senderName = ecnTypeString;
int ecnCreatedById = ecn.OriginatorID;
string emailTemplate = "ECNApproved.txt";
string ecnCreatedByEmail = MiscDMO.GetEmail(ecnCreatedById);
subject = ecnTypeString + " Approval notice for Number " + ecn.ECNNumber + ", - " + ecn.Title;
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[4];
emailparams[0] = ecnNumber.ToString();
emailparams[1] = ecnNumber.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = ecnTypeString;
userEmail = ecnCreatedByEmail;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
emailSentList = ecnCreatedByEmail;
return emailSentList;
}
public static bool CreateZip(AppSettings appSettings, ECNPdf ecn, string UserId) {
try {
string sourceDirectory = appSettings.AttachmentFolder + "ECN\\" + ecn.ECNNumber.ToString() + "\\";
string outputFullFilePath = "";
string outputFileName;
if (ecn.IsTECN) {
if (ecn.ExtensionDate != null)
outputFileName = TECN_PREFIX + ecn.ECNNumber.ToString() + "_Extension.zip";
else
outputFileName = TECN_PREFIX + ecn.ECNNumber.ToString() + ".zip";
outputFullFilePath = appSettings.AttachmentFolder + "\\ECNZipped\\" + outputFileName;
} else if (ecn.IsEmergencyTECN) // Transfer it to different folder , coz documentum does not need to have a Workflow Item created for Emergency TECN
{
outputFileName = ETECN_PREFIX + ecn.ECNNumber.ToString() + ".zip";
outputFullFilePath = appSettings.AttachmentFolder + "\\E-TECNZipped\\" + outputFileName;
} else {
outputFileName = ECN_PREFIX + ecn.ECNNumber.ToString() + ".zip";
outputFullFilePath = appSettings.AttachmentFolder + "\\ECNZipped\\" + outputFileName;
}
Zipper zip = new();
zip.CreateZip(outputFullFilePath, sourceDirectory);
} catch (Exception ex) {
EventLogDMO.Add(new WinEventLog() { IssueID = ecn.ECNNumber, UserID = UserId, DocumentType = ecn.IsECN ? "ECN" : (ecn.IsEmergencyTECN ? "E-TECN" : "TECN"), OperationType = "Error", Comments = ex.Message });
return false;
}
return true;
}
public static string AddEECNApproval(AppSettings appSettings, string userId, WorkflowDMO wfDMO, int ecnNumber, out byte step, string engUserIDs, string OpUserIDs, ECN ecn) {
string emailSentList = "";
step = 1;
string emailArray = "";
try {
emailArray = wfDMO.AddEECNApproval(ecnNumber, step, (int)GlobalVars.DocumentType.EECN, engUserIDs, OpUserIDs);
} catch (Exception e) {
string detailedException = "";
try {
detailedException = e.InnerException.ToString();
} catch {
detailedException = e.Message;
}
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "Issue=" + ecnNumber.ToString() + " Step:" + step + " " + " Userid:" + engUserIDs + " - " + OpUserIDs + " - " + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
Functions.WriteEvent(appSettings, userId + "\r\n AddEECNApproval\r\n" + detailedException, System.Diagnostics.EventLogEntryType.Error);
EventLogDMO.Add(new WinEventLog() { IssueID = ecnNumber, UserID = userId, DocumentType = "E-TECN ", OperationType = "Error", Comments = "AddEECNApproval - " + exceptionString });
throw new Exception(e.Message);
}
emailSentList = AddEECNApproval(appSettings, ecnNumber, emailSentList, emailArray, ecn);
return emailSentList;
}
public static string AttachSave(AppSettings appSettings, ECN_DMO ecnDMO, int ecnNumber, string returnString, int userId, string fullFileName, Stream stream) {
// Some browsers send file names with full path.
// We are only interested in the file name.
var fileName = Path.GetFileName(fullFileName);
string ecnFolderPath = appSettings.AttachmentFolder + "ECN\\" + ecnNumber.ToString();
DirectoryInfo di = new(ecnFolderPath);
if (!di.Exists)
try {
di.Create();
} catch {
returnString = "Error creating ECN directory.";
}
if (returnString == "") {
var physicalPath = Path.Combine(ecnFolderPath, fileName);
if (!File.Exists(physicalPath)) {
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
stream.CopyTo(fileStream);
}
ECNAttachment attach = new() {
ECNNumber = ecnNumber,
FileName = fileName,
UserID = userId,
};
if (File.Exists(physicalPath)) {
ecnDMO.InsertECNAttachment(attach);
} else {
returnString = "File was not uploaded to server.";
}
} else {
returnString = "Cannot have duplicate file names.";
}
}
return returnString;
}
}

View File

@ -22,6 +22,12 @@ public class EmailNotification {
public EmailNotification(Models.AppSettings appSettings) =>
_AppSettings = appSettings;
public EmailNotification(Models.AppSettings appSettings, string EmailHeaderSubject) {
_AppSettings = appSettings;
_subject = EmailHeaderSubject;
_TemplatesPath = appSettings.EmailTemplatesPath;
}
/// <summary>
/// The Constructor Function
/// </summary>
@ -52,16 +58,15 @@ public class EmailNotification {
protected string ReadEmailFile(string FileName) {
string retVal = null;
try {
//setting the file name path
string path = _TemplatesPath + FileName;
#if !NET8
FileInfo TheFile = new FileInfo(System.Web.HttpContext.Current.Server.MapPath(path));
//check if the file exists in the location.
// check if the file exists in the location.
if (!TheFile.Exists)
throw new Exception("Could Not Find the file : " + FileName + " in the location " + _TemplatesPath); // throw an exception here.
//start reading the file. i have used Encoding 1256 to support arabic text also.
// start reading the file. i have used Encoding 1256 to support arabic text also.
StreamReader sr = new StreamReader(System.Web.HttpContext.Current.Server.MapPath(@path), System.Text.Encoding.GetEncoding(1256));
retVal = sr.ReadToEnd(); // getting the entire text from the file.
sr.Close();
@ -88,21 +93,19 @@ public class EmailNotification {
msg.IsBodyHtml = true;// email body will allow html elements
// setting the Sender Email ID
//msg.From = new MailAddress(SenderEmail, SenderName);
msg.From = new MailAddress("MesaFabApproval@infineon.com", "Mesa Fab Approval");
msg.Sender = new MailAddress("MesaFabApproval@infineon.com", "Mesa Fab Approval");
// adding the Recepient Email ID
msg.To.Add(Recep);
//msg.To.Add("Jonathan.Ouellette@infineon.com");
// add CC email ids if supplied.
if (!string.IsNullOrEmpty(cc))
msg.CC.Add(cc);
//setting email subject and body
// setting email subject and body
msg.Subject = email_title;
msg.Body = email_body;
//create a Smtp Mail which will automatically get the smtp server details from web.config mailSettings section
// create a Smtp Mail which will automatically get the smtp server details from web.config mailSettings section
SmtpClient SmtpMail = new("mailrelay-internal.infineon.com");
// sending the message.
@ -130,12 +133,12 @@ public class EmailNotification {
if (!string.IsNullOrEmpty(cc))
msg.CC.Add(cc);
//setting email subject and body
// setting email subject and body
msg.Subject = email_title;
msg.Body = email_body;
msg.Attachments.Add(new Attachment(attachmentPath));
//create a Smtp Mail which will automatically get the smtp server details from web.config mailSettings section
// create a Smtp Mail which will automatically get the smtp server details from web.config mailSettings section
SmtpClient SmtpMail = new();
#if(!DEBUG)
// sending the message.
@ -150,7 +153,6 @@ public class EmailNotification {
msg.IsBodyHtml = true;// email body will allow html elements
// setting the Sender Email ID
//msg.From = new MailAddress(SenderEmail, SenderName);
msg.From = new MailAddress("MesaFabApproval@infineon.com", "Mesa Fab Approval");
// adding the Recepient Email ID
foreach (string recepient in RecepientList) {
@ -161,11 +163,11 @@ public class EmailNotification {
if (!string.IsNullOrEmpty(cc))
msg.CC.Add(cc);
//setting email subject and body
// setting email subject and body
msg.Subject = email_title;
msg.Body = email_body;
//create a Smtp Mail which will automatically get the smtp server details from web.config mailSettings section
// create a Smtp Mail which will automatically get the smtp server details from web.config mailSettings section
SmtpClient SmtpMail = new();
// sending the message.
@ -196,12 +198,12 @@ public class EmailNotification {
if (!string.IsNullOrEmpty(cc))
msg.CC.Add(cc);
//setting email subject and body
// setting email subject and body
msg.Subject = email_title;
msg.Body = email_body;
msg.Attachments.Add(new Attachment(attachmentPath));
//create a Smtp Mail which will automatically get the smtp server details from web.config mailSettings section
// create a Smtp Mail which will automatically get the smtp server details from web.config mailSettings section
SmtpClient SmtpMail = new();
// sending the message.
@ -223,14 +225,14 @@ public class EmailNotification {
if (!string.IsNullOrEmpty(cc))
msg.CC.Add(cc);
//setting email subject and body
// setting email subject and body
msg.Subject = email_title;
msg.Body = email_body;
foreach (string attachment in attachments) {
msg.Attachments.Add(new Attachment(attachment));
}
//create a Smtp Mail which will automatically get the smtp server details from web.config mailSettings section
// create a Smtp Mail which will automatically get the smtp server details from web.config mailSettings section
SmtpClient SmtpMail = new();
#if(!DEBUG)
// sending the message.
@ -256,7 +258,7 @@ public class EmailNotification {
if (!string.IsNullOrEmpty(cc))
msg.CC.Add(cc);
//setting email subject and body
// setting email subject and body
msg.Subject = email_title;
msg.Body = email_body;
@ -264,7 +266,7 @@ public class EmailNotification {
msg.Attachments.Add(new Attachment(attachment));
}
//create a Smtp Mail which will automatically get the smtp server details from web.config mailSettings section
// create a Smtp Mail which will automatically get the smtp server details from web.config mailSettings section
SmtpClient SmtpMail = new();
// sending the message.
@ -285,16 +287,16 @@ public class EmailNotification {
public string SendNotificationEmail(string EmailTemplateFile, string SenderEmail, string SenderName, string RecepientEmail, string CC, string Subject, params string[] Args) {
string retVal = null;
//reading the file
// reading the file
string FileContents = ReadEmailFile(EmailTemplateFile);
string emailBody = FileContents;
//setting formatting the string
// setting formatting the string
retVal = string.Format(emailBody, Args);
try {
//check if we are in debug mode or not. to send email
// check if we are in debug mode or not. to send email
if (GlobalVars.DBConnection.ToUpper() == "TEST" || GlobalVars.DBConnection.ToUpper() == "QUALITY") {
SendEmail(SenderEmail, SenderName, GetTestRecipientsList(), CC, (!string.IsNullOrEmpty(Subject) ? Subject + " for: " + RecepientEmail : _subject), retVal);
} else {
@ -316,16 +318,16 @@ public class EmailNotification {
public string SendNotificationEmailWithAttachment(string EmailTemplateFile, string SenderEmail, string SenderName, string RecepientEmail, string CC, string Subject, string attachmentPath, params string[] Args) {
string retVal = null;
//reading the file
// reading the file
string FileContents = ReadEmailFile(EmailTemplateFile);
string emailBody = FileContents;
//setting formatting the string
// setting formatting the string
retVal = string.Format(emailBody, Args);
try {
//check if we are in debug mode or not. to send email
// check if we are in debug mode or not. to send email
if (GlobalVars.DBConnection.ToUpper() == "TEST" || GlobalVars.DBConnection.ToUpper() == "QUALITY") {
SendEmailWithAttachment(SenderEmail, SenderName, GetTestRecipientsList(), CC, (!string.IsNullOrEmpty(Subject) ? " TESTING ONLY -IGNORE : " + Subject + RecepientEmail : _subject), retVal, attachmentPath);
} else {
@ -343,16 +345,16 @@ public class EmailNotification {
public string SendNotificationEmailWithAttachment(string EmailTemplateFile, string SenderEmail, string SenderName, List<string> RecepientEmail, string CC, string Subject, string attachmentPath, params string[] Args) {
string retVal = null;
//reading the file
// reading the file
string FileContents = ReadEmailFile(EmailTemplateFile);
string emailBody = FileContents;
//setting formatting the string
// setting formatting the string
retVal = string.Format(emailBody, Args);
try {
//check if we are in debug mode or not. to send email
// check if we are in debug mode or not. to send email
if (GlobalVars.DBConnection.ToUpper() == "TEST" || GlobalVars.DBConnection.ToUpper() == "QUALITY") {
foreach (string email in RecepientEmail) {
Subject += email + ";";
@ -375,16 +377,16 @@ public class EmailNotification {
public string SendNotificationEmailWithAttachments(string EmailTemplateFile, string SenderEmail, string SenderName, string RecepientEmail, string CC, string Subject, List<string> attachments, params string[] Args) {
string retVal = null;
//reading the file
// reading the file
string FileContents = ReadEmailFile(EmailTemplateFile);
string emailBody = FileContents;
//setting formatting the string
// setting formatting the string
retVal = string.Format(emailBody, Args);
try {
//check if we are in debug mode or not. to send email
// check if we are in debug mode or not. to send email
if (GlobalVars.DBConnection.ToUpper() == "TEST" || GlobalVars.DBConnection.ToUpper() == "QUALITY") {
SendEmailWithAttachments(SenderEmail, SenderName, GetTestRecipientsList(), CC, (!string.IsNullOrEmpty(Subject) ? " TESTING ONLY -IGNORE : " + Subject + RecepientEmail : _subject), retVal, attachments);
} else {
@ -402,16 +404,16 @@ public class EmailNotification {
public string SendNotificationEmailWithAttachments(string EmailTemplateFile, string SenderEmail, string SenderName, List<string> RecepientEmail, string CC, string Subject, List<string> attachments, params string[] Args) {
string retVal = null;
//reading the file
// reading the file
string FileContents = ReadEmailFile(EmailTemplateFile);
string emailBody = FileContents;
//setting formatting the string
// setting formatting the string
retVal = string.Format(emailBody, Args);
try {
//check if we are in debug mode or not. to send email
// check if we are in debug mode or not. to send email
if (GlobalVars.DBConnection.ToUpper() == "TEST" || GlobalVars.DBConnection.ToUpper() == "QUALITY") {
foreach (string email in RecepientEmail) {
Subject += email + ";";
@ -434,16 +436,16 @@ public class EmailNotification {
public string SendNotificationEmail(string EmailTemplateFile, string SenderEmail, string SenderName, List<string> RecepientEmail, string CC, string Subject, params string[] Args) {
string retVal = null;
//reading the file
// reading the file
string FileContents = ReadEmailFile(EmailTemplateFile);
string emailBody = FileContents;
//setting formatting the string
// setting formatting the string
retVal = string.Format(emailBody, Args);
try {
//check if we are in debug mode or not. to send email
// check if we are in debug mode or not. to send email
if (GlobalVars.DBConnection.ToUpper() == "TEST" || GlobalVars.DBConnection.ToUpper() == "QUALITY") {
foreach (string email in RecepientEmail) {
Subject += email + ";";
@ -480,9 +482,7 @@ public class EmailNotification {
msg.Subject = subject;
msg.Body = temp;
msg.Priority = importance;
//#if(!DEBUG)
client.Send(msg);
//#endif
} catch (Exception ex) {
throw;
}

View File

@ -44,10 +44,6 @@ namespace Fab2ApprovalSystem.Misc {
public string LotDispo { get; set; }
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public IEnumerable<ExcelLotInfo> ReadData() {
var r = new List<ExcelLotInfo>();
var excelData = new ExcelData(_path);
@ -78,7 +74,6 @@ namespace Fab2ApprovalSystem.Misc {
List<string> s = new List<string>();
// We return the interface, so that
var excelData = new ExcelData(_path);
//var albums = excelData.getData("Sheet1");
var lotNos = excelData.getData();
foreach (var row in lotNos) {
string temValue = row[0].ToString();
@ -94,11 +89,6 @@ namespace Fab2ApprovalSystem.Misc {
return s;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public IEnumerable<DataRow> getData(bool firstRowIsColumnNames = true) {
var reader = this.getExcelReader();
reader.IsFirstRowAsColumnNames = firstRowIsColumnNames;

View File

@ -16,13 +16,10 @@ internal class FTPWrapper {
_DestinationFileName = destinationFileName;
}
/// <summary>
///
/// </summary>
public void FTPToSPN() {
FTP ftpLib = new();
//Connect to the FTP server
// Connect to the FTP server
try {
ftpLib.Connect(_AppSettings.FTPServer, _AppSettings.FTPUser, _AppSettings.FTPPassword);
} catch (Exception ec) {
@ -30,7 +27,7 @@ internal class FTPWrapper {
": " + ec.Message, System.Diagnostics.EventLogEntryType.Error);
}
//Upload the file
// Upload the file
try {
int pct = 0;
ftpLib.OpenUpload(_OutputFile, _DestinationFileName);

View File

@ -28,7 +28,6 @@ public static class Functions {
/// </summary>
public static void WriteEvent(AppSettings? appSettings, string logtext, EventLogEntryType eventType) {
//#if(!DEBUG)
#if !NET8
EmailNotification? en = appSettings is null ? null : new EmailNotification(appSettings);
#endif
@ -36,22 +35,19 @@ public static class Functions {
ev.Source = "Fab Approval System";
try {
//Write to the Event Log
// Write to the Event Log
ev.WriteEntry(logtext, eventType);
////Send an email notification if appropriate
////Don't attempt to send an email if the error is pertaining to an email problem
// Send an email notification if appropriate
// Don't attempt to send an email if the error is pertaining to an email problem
if (!logtext.Contains("SendEmailNotification()")) {
//Only send email notifications for Error and Warning level events
// Only send email notifications for Error and Warning level events
#if !NET8
if (appSettings is not null && eventType == System.Diagnostics.EventLogEntryType.Error)
en.SendNotificationEmailToAdmin(ev.Source + " - Error Notification", logtext, MailPriority.High);
#endif
//else if (eventType == System.Diagnostics.EventLogEntryType.Warning)
// SendEmailNotification(ErrorRecipient(), ev.Source + " Warning Event Logged", logtext, NORMAL_PRI);
}
} catch {
//throw;
} finally {
ev = null;
}
@ -70,7 +66,6 @@ public static class Functions {
FileInfo[] existingFiles = new DirectoryInfo(oldFolderPath).GetFiles();
foreach (FileInfo file in existingFiles) {
if (!file.Name.Contains("ECNApprovalLog_" + oldECNNumber.ToString()) && !file.Name.Contains("ECNForm_" + oldECNNumber.ToString()))
//var fileName = Path.GetFileName(file.FullName);
file.CopyTo(Path.Combine(newFolderPath, file.Name));
}
}

View File

@ -53,10 +53,10 @@ public static class GlobalVars {
Pending = 0,
Approved = 1,
Denied = 2,
Waiting = 3, //waiting on other approver to approve first
Skipped = 4, //set to this state if the original approval is no longer needed.
ReAssigned = 5, //set to this state if current approver got reassigned
Terminated = 6, //future use
Waiting = 3, // waiting on other approver to approve first
Skipped = 4, // set to this state if the original approval is no longer needed.
ReAssigned = 5, // set to this state if current approver got reassigned
Terminated = 6, // future use
Closed = 7,
Recalled = 8

View File

@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using Fab2ApprovalSystem.Models;
namespace Fab2ApprovalSystem.Misc;
public class HomeHelper {
public static void NotifyApprover(AppSettings appSettings, string toEmail, string title, int issueId, string docType) {
string emailSentList = "";
string senderName = docType;
string subject = string.Empty;
string userEmail = string.Empty;
string emailTemplate = "ApprovalReminders.txt";
subject = docType + " Approval Reminder: " + title;
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[4];
emailparams[0] = docType;
emailparams[1] = title;
emailparams[2] = issueId.ToString();
userEmail = toEmail;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, "jonathan.ouellette@infineon.com", subject, emailparams);
}
public static void NotifyDelegation(AppSettings appSettings, DateTime startDate, DateTime endDate, LoginModel delegateFrom, LoginModel delegateTo, List<string> emailList) {
string userEmail = string.Empty;
string senderName = "Mesa Approval";
string emailTemplate = "DelegationOn.txt";
string subject = "Mesa Approval Delegation Notification";
foreach (string email in emailList) {
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[5];
emailparams[0] = delegateFrom.FullName;
emailparams[1] = delegateTo.FullName;
emailparams[2] = startDate.ToString("yyyy-MM-dd");
emailparams[3] = endDate.ToString("yyyy-MM-dd");
userEmail = email;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
}
}
public static void DelegateDocumentApproval(AppSettings appSettings, int issueID, string ecnTypeString, string title, string email) {
string subject;
string userEmail = string.Empty;
string senderName = ecnTypeString;
string emailTemplate = "DelegateApproval.txt";
subject = ecnTypeString + " Delegation" + " - Email would be sent to " + email + " for Number " + issueID + ", - " + title;
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[4];
emailparams[0] = issueID.ToString();
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = ecnTypeString;
userEmail = email;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
}
}

View File

@ -0,0 +1,167 @@
using System;
using System.Collections.Generic;
using System.IO;
using Fab2ApprovalSystem.DMO;
using Fab2ApprovalSystem.Models;
namespace Fab2ApprovalSystem.Misc;
public class LotDispositionHelper {
public static string NotifyRejectionToOrginator(AppSettings appSettings, int issueID, string username, List<string> emailIst) {
string userEmail = string.Empty;
string senderName = "LotDisposition";
string subject = "Lot Disposition Rejection";
string emailTemplate = "LotDispositionReject.txt";
foreach (string email in emailIst) {
subject = "Lot Disposition Rejection";
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[4];
emailparams[0] = issueID.ToString();
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = username;
userEmail = email;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
}
return userEmail;
}
public static string NotifyApprovers(AppSettings appSettings, int issueID, List<string> emailIst) {
string emailSentList = "";
string userEmail = string.Empty;
string senderName = "LotDisposition";
string subject = "Lot Disposition Assignment";
string emailTemplate = "LotDispositionAssigned.txt";
foreach (string email in emailIst) {
subject = "Lot Disposition Assignment";
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[3];
emailparams[0] = issueID.ToString();
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
userEmail = email;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
emailSentList += email + ",";
}
return emailSentList;
}
public static string AddAdditionalApproval(AppSettings appSettings, int issueID, string emailSentList, string emailArray) {
string userEmail = string.Empty;
string senderName = "LotDisposition";
string subject = "Lot Disposition Assignment";
string emailTemplate = "LotDispositionAssigned.txt";
string[] emailIst = emailArray.Split(new char[] { '~' });
foreach (string email in emailIst) {
if (email.Length > 0) {
subject = "Lot Disposition Assignment";
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[3];
emailparams[0] = issueID.ToString();
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
userEmail = email;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
emailSentList += email + ",";
}
}
return emailSentList;
}
public static void ReAssignApproverByAdmin(AppSettings appSettings, int issueID, string email) {
string userEmail = string.Empty;
string senderName = "LotDisposition";
string subject = "Lot Disposition Re-Assignment";
string emailTemplate = "LotDispositionReAssigned.txt";
subject = "Lot Disposition Re-Assignment" + " - Email would be sent to " + email;
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[3];
emailparams[0] = issueID.ToString();
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
userEmail = email;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
}
public static void ReAssignApproval(AppSettings appSettings, int issueID, string email) {
string userEmail = string.Empty;
string senderName = "LotDisposition";
string subject = "Lot Disposition Re-Assignment";
string emailTemplate = "LotDispositionReAssigned.txt";
subject = "Lot Disposition Re-Assignment" + " - Email would be sent to " + email;
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[3];
emailparams[0] = issueID.ToString();
emailparams[1] = issueID.ToString();
emailparams[2] = GlobalVars.hostURL;
userEmail = email;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
}
public static void AttachSave(AppSettings appSettings, LotDispositionDMO lotDispositionDMO, int issueID, int userId, string fullFileName, Stream stream) {
// Some browsers send file names with full path.
// We are only interested in the file name.
var fileName = Path.GetFileName(fullFileName);
var physicalPath = Path.Combine(appSettings.AttachmentFolder + "LotDisposition", fileName);
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
stream.CopyTo(fileStream);
}
Attachment attach = new() {
IssueID = issueID,
FileName = fileName,
UserID = userId,
};
lotDispositionDMO.InsertLotDispositionAttachment(attach);
}
public static string ExcelLotOpen(LotDispositionDMO lotDispositionDMO, int issueID, string userIdentityName, string lotTempPipeLine, string fullFileName, Stream stream) {
string physicalPath;
var fileExtension = Path.GetExtension(fullFileName);
string fName = userIdentityName + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
physicalPath = Path.Combine(lotTempPipeLine, fName + "." + fileExtension);
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
stream.CopyTo(fileStream);
}
#if !NET8
ExcelData x = new ExcelData(physicalPath);
var lotNumbers = x.ReadData();
foreach (var lotInfo in lotNumbers) {
Lot l = new Lot();
l.LotNumber = lotInfo.LotNo;
l.IssueID = issueID;
if (l.LotStatusOptionID == 0)
l.LotStatusOption.LotStatusOptionID = (int)GlobalVars.LotStatusOption.Release;
lotDispositionDMO.InsertLot(l, true);
}
#endif
FileInfo f = new(physicalPath);
if (f.Exists)
f.Delete();
return physicalPath;
}
}

View File

@ -0,0 +1,469 @@
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<string> 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<string> 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<string> 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<string> 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<string> 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<string> 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);
}
}

View File

@ -0,0 +1,320 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using Fab2ApprovalSystem.DMO;
using Fab2ApprovalSystem.Models;
namespace Fab2ApprovalSystem.Misc;
public class MRBHelper {
public static string NotifyApprovers(AppSettings appSettings, int mrbNumber, List<string> emailIst) {
string emailSentList = "";
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(appSettings, subject, emailTemplate);
string[] emailparams = new string[3];
emailparams[0] = mrbNumber.ToString();
emailparams[1] = mrbNumber.ToString();
emailparams[2] = GlobalVars.hostURL;
userEmail = email;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
emailSentList += email + ",";
}
return emailSentList;
}
public static string ImportRemoveQDBFlag(AppSettings appSettings, MRB_DMO mrbDMO, string operation, out string physicalPath, string userIdentityName, string a, string b, string c, string fullFileName, Stream stream) {
IEnumerable<string> lotDataList = null;
var guid = Guid.NewGuid().ToString();
var fileExtension = Path.GetExtension(fullFileName);
physicalPath = Path.Combine(appSettings.LotTempPipeLine, guid + "." + fileExtension);
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
stream.CopyTo(fileStream);
}
#if !NET8
ExcelData x = new ExcelData(physicalPath);
lotDataList = x.ReadQDBFlagData();
foreach (string lotData in lotDataList) {
mrbDMO.InsertMRB_QDB_HoldFlag(guid, lotData, operation);
}
#endif
FileInfo f = new(physicalPath);
if (f.Exists)
f.Delete();
// Send the data to SPN
if (SendQDBFlagToSPN(appSettings, mrbDMO, guid, userIdentityName, a, b, c))
mrbDMO.UpdateMRB_QDB_HoldFlag(guid, true);
else {
mrbDMO.UpdateMRB_QDB_HoldFlag(guid, false);
return "Problems while uploading to SPN";
}
return string.Empty;
}
public static bool BatchFTP(AppSettings appSettings, string sourceFile, string destFile, string ftpLogDirectory, string userIdentityName, string a, string b, string c) {
FileInfo sourcefile = new(sourceFile);
try {
ProcessStartInfo psiFab1 = new();
Process procFab1 = new();
StringBuilder sb = new();
if (GlobalVars.DBConnection.ToUpper() == "TEST" || GlobalVars.DBConnection.ToUpper() == "QUALITY") {
psiFab1.FileName = a;
} else {
psiFab1.FileName = b;
}
psiFab1.Arguments = sourcefile.FullName + " " + destFile;
psiFab1.RedirectStandardOutput = true;
psiFab1.UseShellExecute = false;
psiFab1.WorkingDirectory = c;
procFab1.StartInfo = psiFab1;
procFab1.OutputDataReceived += (sender, args) => sb.AppendLine(args.Data);
;
procFab1.Start();
procFab1.BeginOutputReadLine();
procFab1.WaitForExit(4000);
File.WriteAllText(Path.Combine(ftpLogDirectory, sourcefile.Name + ".txt"), sb.ToString());
return true;
} catch (Exception e) {
Functions.WriteEvent(appSettings, userIdentityName + "\r\n Approve\r\n" + e.Message.ToString(), EventLogEntryType.Error);
return false;
}
}
public static bool SendQDBFlagToSPN(AppSettings appSettings, MRB_DMO mrbDMO, string guid, string userIdentityName, string a, string b, string c) {
StringBuilder output = new();
try {
IEnumerable<string> data = mrbDMO.GetMRB_QDB_HoldFlags(guid);
foreach (string tempData in data) {
output.Append(tempData.Trim() + Environment.NewLine);
}
try {
if (output.Length > 0) {
DateTime dt = DateTime.Now;
string newsourceFileName = "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") + ".mrb";
string outputFile = appSettings.HoldFlagDirectory + newsourceFileName;
File.WriteAllText(outputFile, output.ToString());
#if (DEBUG)
Thread.Sleep(1000);
#endif
try {
if (BatchFTP(appSettings, outputFile, newDestFileName, appSettings.SPNMRBHoldFlagFTPLogDirectory, userIdentityName, a, b, c)) {
mrbDMO.UpdateMRB_QDB_HoldFlag(guid, true);
} else {
mrbDMO.UpdateMRB_QDB_HoldFlag(guid, false);
}
} catch (Exception e) {
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "MRB =" + guid.ToString() + " FTPToSPN(): FTP Upload Error " + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
EventLogDMO.Add(new WinEventLog() { IssueID = -1, UserID = userIdentityName, DocumentType = "MRB", OperationType = "Error", Comments = exceptionString });
return false;
}
}
return true;
} catch (Exception e) {
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "MRB =" + guid.ToString() + " SPN Hold Flag(SendToSPN) " + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
Functions.WriteEvent(appSettings, userIdentityName + "\r\n Approve\r\n" + e.Message.ToString(), EventLogEntryType.Error);
EventLogDMO.Add(new WinEventLog() { IssueID = -1, UserID = userIdentityName, DocumentType = "MRB", OperationType = "Error", Comments = exceptionString });
return false;
}
} catch (Exception e) {
string exceptionString = e.Message.ToString().Trim().Length > 500 ? "GUID =" + guid.ToString() + " SPN Hold Flag(SendToSPN) " + e.Message.ToString().Substring(0, 250) : e.Message.ToString();
Functions.WriteEvent(appSettings, userIdentityName + "\r\n Approve\r\n" + e.Message.ToString(), EventLogEntryType.Error);
EventLogDMO.Add(new WinEventLog() { IssueID = -1, UserID = userIdentityName, DocumentType = "MRB", OperationType = "Error", Comments = exceptionString });
return false;
}
}
public static string ImportAddQDBFlag(AppSettings appSettings, MRB_DMO mrbDMO, string operation, out string physicalPath, string userIdentityName, string a, string b, string c, string fullFileName, Stream stream) {
IEnumerable<string> lotDataList = null;
var guid = Guid.NewGuid().ToString();
var fileExtension = Path.GetExtension(fullFileName);
physicalPath = Path.Combine(appSettings.LotTempPipeLine, guid + "." + fileExtension);
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
stream.CopyTo(fileStream);
}
#if !NET8
ExcelData x = new ExcelData(physicalPath);
lotDataList = x.ReadQDBFlagData();
foreach (string lotData in lotDataList) {
mrbDMO.InsertMRB_QDB_HoldFlag(guid, lotData, operation);
}
#endif
FileInfo f = new(physicalPath);
if (f.Exists)
f.Delete();
if (SendQDBFlagToSPN(appSettings, mrbDMO, guid, userIdentityName, a, b, c))
mrbDMO.UpdateMRB_QDB_HoldFlag(guid, true);
else {
mrbDMO.UpdateMRB_QDB_HoldFlag(guid, false);
return "Problems while uploading to SPN";
}
return string.Empty;
}
public static void AttachSave(AppSettings appSettings, MRB_DMO mrbDMO, int mrbNumber, int userId, string fullFileName, Stream stream) {
// Some browsers send file names with full path.
// We are only interested in the file name.
var fileName = Path.GetFileName(fullFileName);
string physicalFileName;
string physicalPath;
// Check to see if this filename is in use
var attachments = mrbDMO.GetMRBAttachments(mrbNumber);
if (attachments.Count() > 0) {
if (attachments.Count(a => string.Equals(a.FileName, fileName, StringComparison.OrdinalIgnoreCase)) > 0) {
// This filename is used on this MRB
// So we want to delete those records so the new record replaces them
foreach (var a in attachments) {
mrbDMO.DeleteMRBAttachment(a.AttachmentID);
physicalFileName = a.Path;
if (string.IsNullOrEmpty(physicalFileName))
physicalFileName = a.FileName;
physicalPath = Path.Combine(appSettings.AttachmentFolder + "MRB", physicalFileName);
if (File.Exists(physicalPath))
File.Delete(physicalPath);
}
}
}
physicalFileName = mrbNumber.ToString() + "_" + Guid.NewGuid().ToString() + Path.GetExtension(fileName);
physicalPath = Path.Combine(appSettings.AttachmentFolder + "MRB", physicalFileName);
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
stream.CopyTo(fileStream);
}
MRBAttachment attach = new() {
MRBNumber = mrbNumber,
FileName = fileName,
Path = physicalFileName,
#if (DEBUG)
UserID = 114,
#endif
#if (!DEBUG)
UserID = userId,
#endif
};
mrbDMO.InsertMRBAttachment(attach);
}
public static string ExcelLotOpen(MRB_DMO mrbDMO, int mrbNumber, StringBuilder warnings, IEnumerable<Disposition> dispos, string userIdentityName, string lotTempPipeLine, string fullFileName, Stream stream) {
var fileName = Path.GetFileName(fullFileName);
var fileExtension = Path.GetExtension(fullFileName);
string fName = userIdentityName + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
string physicalPath = Path.Combine(lotTempPipeLine, fName + "." + fileExtension);
#if !NET8
IEnumerable<ExcelData.ExcelLotInfo> lotNumbers;
try {
using (var fileStream = new FileStream(physicalPath, FileMode.Create, FileAccess.Write)) {
stream.CopyTo(fileStream);
}
ExcelData x = new ExcelData(physicalPath);
lotNumbers = x.ReadData();
} catch (Exception ex) {
throw new Exception(String.Format("Invalid file format for {0}: {1}", fileName, ex.Message));
}
// Get Tool, Issue Start and End Date
MRB mrbInfo = mrbDMO.GetToolIssueStartEndDateData(mrbNumber, null);
foreach (var lotInfo in lotNumbers) {
if (lotInfo.LotDispo.Length == 1) {
if (dispos.Count(d => d.DispositionType.Trim().ToUpper() == lotInfo.LotDispo.Trim().ToUpper()) == 0) {
throw new Exception(String.Format("Invalid lot disposition {0} for lot no {1}",
lotInfo.LotDispo, lotInfo.LotNo));
}
}
}
// RJK - 12/17
// Only find the child Splits when a Tool or a list of Tools is provided
if (!mrbInfo.ToolCSV.ToUpper().Equals("NA")) {
foreach (var lotInfo in lotNumbers) {
bool existingLotUpdated;
Lot l = new Lot();
l.LotNumber = lotInfo.LotNo;
if (lotInfo.LotDispo.Length == 1) {
l.DispoType = lotInfo.LotDispo[0];
}
l.MRBNumber = mrbNumber;
mrbDMO.InsertLot(l, true, out existingLotUpdated);
// cannot do the check below , because what if the parent lot had splits after the prior lot split analysis
if (!mrbDMO.InsertLotSplitsAffectedByIncident(mrbNumber, l.LotNumber, mrbInfo.ToolCSV, mrbInfo.IssueStartDate, mrbInfo.IssueEndDate)) {
warnings.AppendFormat("Lot number {0} is not affected by these tools and issue start/end time.\n Uploaded without Lot Genealogy tracing", l.LotNumber);
}
}
// Not required - Will be using each lot's Insert Date time stamp,
// as lot could be added using search functionality
// UpdateLastLotSplitAnalysisTime(mrbNumber);
} else {
// RJK - 12/17
// Only find the child Splits when a Tool or a list of Tools is provided
foreach (var lotInfo in lotNumbers) {
bool existingLotUpdated;
Lot l = new Lot();
l.LotNumber = lotInfo.LotNo;
if (lotInfo.LotDispo.Length == 1) {
l.DispoType = lotInfo.LotDispo[0];
}
l.MRBNumber = mrbNumber;
// do not insert any new lots when importing from excel
mrbDMO.InsertLot(l, true, out existingLotUpdated);
}
}
#endif
FileInfo f = new(physicalPath);
if (f.Exists)
f.Delete();
return physicalPath;
}
}

View File

@ -0,0 +1,49 @@
using System.IO;
using Fab2ApprovalSystem.DMO;
using Fab2ApprovalSystem.Models;
namespace Fab2ApprovalSystem.Misc;
public class PartsRequestHelper {
public static void SendEmailNotification(AppSettings appSettings, string username, string subject, int prNumber, string toEmail, string emailTemplate) {
string senderName = "Parts Request";
EmailNotification en = new(appSettings, subject);
string[] emailparams = new string[5];
emailparams[0] = prNumber.ToString();
emailparams[1] = prNumber.ToString();
emailparams[2] = GlobalVars.hostURL;
emailparams[3] = "Parts Request";
emailparams[4] = username;
string userEmail = toEmail;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
}
public static void AttachSave(AppSettings appSettings, PartsRequestDMO partsRequestDMO, int prNumber, int userId, string fullFileName, Stream stream) {
// Some browsers send file names with full path.
// We are only interested in the file name.
var fileName = Path.GetFileName(fullFileName);
string prFolderPath = appSettings.AttachmentFolder + "PartsRequest\\" + prNumber.ToString();
DirectoryInfo di = new(prFolderPath);
if (!di.Exists)
di.Create();
var physicalPath = Path.Combine(prFolderPath, fileName);
using (FileStream fileStream = new(physicalPath, FileMode.Create, FileAccess.Write)) {
stream.CopyTo(fileStream);
}
PartsRequestAttachment attach = new() {
PRNumber = prNumber,
FileName = fileName,
UserID = userId,
};
partsRequestDMO.InsertAttachment(attach);
}
}

View File

@ -0,0 +1,26 @@
using Fab2ApprovalSystem.Models;
namespace Fab2ApprovalSystem.Misc;
public class TrainingHelper {
public static void NotifyTrainee(AppSettings appSettings, int userId, int assignmentId, int ecnId, string title, string recipient) {
string emailSentList = "";
string subject = string.Empty;
string userEmail = string.Empty;
string senderName = "ECN Training";
string emailTemplate = "ECNTrainingAssigned.txt";
subject = "ECN# " + ecnId + " - Training Assignment Notice - " + title;
EmailNotification en = new(appSettings, subject);
userEmail = recipient;
string[] emailparams = new string[4];
emailparams[0] = assignmentId.ToString();
emailparams[1] = ecnId.ToString();
emailparams[2] = GlobalVars.hostURL;
en.SendNotificationEmail(emailTemplate, GlobalVars.SENDER_EMAIL, senderName, userEmail, null, subject, emailparams);
}
}

View File

@ -18,9 +18,7 @@ public class Zipper {
FileStream fsOut = File.Create(outPathname);
ZipOutputStream zipStream = new(fsOut);
zipStream.SetLevel(3); //0-9, 9 being the highest level of compression
//zipStream.Password = password; // optional. Null is the same as not setting. Required if using AES.
zipStream.SetLevel(3); // 0-9, 9 being the highest level of compression
// This setting will strip the leading part of the folder path in the entries, to
// make the entries relative to the starting folder.

View File

@ -57,15 +57,12 @@ public class FTP {
#endregion
#region Constructors
/// <summary>
/// Constructor
/// </summary>
public FTP() {
server = null;
user = null;
pass = null;
port = 21;
passive_mode = true; // #######################################
passive_mode = true;
main_sock = null;
main_ipEndPoint = null;
listening_sock = null;
@ -77,18 +74,13 @@ public class FTP {
timeout = 10000; // 10 seconds
messages = "";
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="server">Server to connect to</param>
/// <param name="user">Account to login as</param>
/// <param name="pass">Account password</param>
public FTP(string server, string user, string pass) {
this.server = server;
this.user = user;
this.pass = pass;
port = 21;
passive_mode = true; // #######################################
passive_mode = true;
main_sock = null;
main_ipEndPoint = null;
listening_sock = null;
@ -100,19 +92,13 @@ public class FTP {
timeout = 10000; // 10 seconds
messages = "";
}
/// <summary>
/// Constructor
/// </summary>
/// <param name="server">Server to connect to</param>
/// <param name="port">Port server is listening on</param>
/// <param name="user">Account to login as</param>
/// <param name="pass">Account password</param>
public FTP(string server, int port, string user, string pass) {
this.server = server;
this.user = user;
this.pass = pass;
this.port = port;
passive_mode = true; // #######################################
passive_mode = true;
main_sock = null;
main_ipEndPoint = null;
listening_sock = null;
@ -275,7 +261,6 @@ public class FTP {
messages = "";
while (true) {
//buf = GetLineFromBucket();
buf = GetLineFromBucket();
#if (FTP_DEBUG)
@ -570,8 +555,8 @@ public class FTP {
SendCommand("LIST");
ReadResponse();
//FILIPE MADUREIRA.
//Added response 125
// FILIPE MADUREIRA.
// Added response 125
switch (response) {
case 125:
case 150:
@ -589,13 +574,10 @@ public class FTP {
// so the code doesn't hang if there is
// no data comming.
if (msecs_passed > (timeout / 10)) {
//CloseDataSocket();
//throw new Exception("Timed out waiting on server to respond.");
//FILIPE MADUREIRA.
//If there are no files to list it gives timeout.
//So I wait less time and if no data is received, means that there are no files
break;//Maybe there are no files
// FILIPE MADUREIRA.
// If there are no files to list it gives timeout.
// So I wait less time and if no data is received, means that there are no files
break; // Maybe there are no files
}
}
@ -626,8 +608,7 @@ public class FTP {
ArrayList list = new();
foreach (string f in List()) {
//FILIPE MADUREIRA
//In Windows servers it is identified by <DIR>
// FILIPE MADUREIRA
if ((f.Length > 0)) {
if ((f[0] != 'd') && (f.ToUpper().IndexOf("<DIR>") < 0))
list.Add(f);
@ -636,6 +617,7 @@ public class FTP {
return list;
}
/// <summary>
/// Gets a directory list only
/// </summary>
@ -644,8 +626,8 @@ public class FTP {
ArrayList list = new();
foreach (string f in List()) {
//FILIPE MADUREIRA
//In Windows servers it is identified by <DIR>
// FILIPE MADUREIRA
// In Windows servers it is identified by <DIR>
if (f.Length > 0) {
if ((f[0] == 'd') || (f.ToUpper().IndexOf("<DIR>") >= 0))
list.Add(f);
@ -685,7 +667,7 @@ public class FTP {
if (input.Length < 14)
throw new ArgumentException("Input Value for ConvertFTPDateToDateTime method was too short.");
//YYYYMMDDhhmmss":
// YYYYMMDDhhmmss":
int year = Convert.ToInt16(input.Substring(0, 4));
int month = Convert.ToInt16(input.Substring(4, 2));
int day = Convert.ToInt16(input.Substring(6, 2));
@ -700,7 +682,7 @@ public class FTP {
/// </summary>
/// <returns>The working directory</returns>
public string GetWorkingDirectory() {
//PWD - print working directory
// PWD - print working directory
Connect();
SendCommand("PWD");
ReadResponse();
@ -710,7 +692,7 @@ public class FTP {
string pwd;
try {
pwd = responseStr.Substring(responseStr.IndexOf("\"", 0) + 1);//5);
pwd = responseStr.Substring(responseStr.IndexOf("\"", 0) + 1);
pwd = pwd.Substring(0, pwd.LastIndexOf("\""));
pwd = pwd.Replace("\"\"", "\""); // directories with quotes in the name come out as "" from the server
} catch (Exception ex) {
@ -719,6 +701,7 @@ public class FTP {
return pwd;
}
/// <summary>
/// Change to another directory on the ftp server
/// </summary>