262 lines
9.4 KiB
C#
262 lines
9.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Security;
|
|
using System.IO;
|
|
using System.Net.Mail;
|
|
using System.DirectoryServices;
|
|
using System.DirectoryServices.AccountManagement;
|
|
|
|
namespace Fab2ApprovalSystem.Misc {
|
|
public static class Functions {
|
|
/// <summary>
|
|
/// Writes to the Application Event Log and sends an email notification if appropriate
|
|
/// </summary>
|
|
/// <param name="logtext"></param>
|
|
/// <param name="eventType"></param>
|
|
public static void WriteEvent(string logtext, System.Diagnostics.EventLogEntryType eventType) {
|
|
//#if(!DEBUG)
|
|
EmailNotification en = new EmailNotification();
|
|
EventLog ev = new EventLog("Application");
|
|
ev.Source = "Fab Approval System";
|
|
|
|
try {
|
|
//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
|
|
if (!logtext.Contains("SendEmailNotification()")) {
|
|
//Only send email notifications for Error and Warning level events
|
|
if (eventType == System.Diagnostics.EventLogEntryType.Error)
|
|
en.SendNotificationEmailToAdmin(ev.Source + " - Error Notification", logtext, MailPriority.High);
|
|
//else if (eventType == System.Diagnostics.EventLogEntryType.Warning)
|
|
// SendEmailNotification(ErrorRecipient(), ev.Source + " Warning Event Logged", logtext, NORMAL_PRI);
|
|
}
|
|
} catch {
|
|
//throw;
|
|
} finally {
|
|
ev = null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the FTP Server Name
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static string FTPServer() {
|
|
ConfigurationManager.RefreshSection("appSettings");
|
|
return ConfigurationManager.AppSettings["FTP Server"];
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the FTP User Name
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static string FTPUser() {
|
|
ConfigurationManager.RefreshSection("appSettings");
|
|
return ConfigurationManager.AppSettings["FTP User"];
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns the FTP Password
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static string FTPPassword() {
|
|
ConfigurationManager.RefreshSection("appSettings");
|
|
return ConfigurationManager.AppSettings["FTP Password"];
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static string GetAttachmentFolder() {
|
|
ConfigurationManager.RefreshSection("appSettings");
|
|
return ConfigurationManager.AppSettings["AttachmentFolder"];
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="oldECNNumber"></param>
|
|
/// <param name="newECNNumber"></param>
|
|
public static void CopyAttachments(int oldECNNumber, int newECNNumber) {
|
|
// The Name of the Upload component is "files"
|
|
string oldFolderPath = Functions.GetAttachmentFolder() + "ECN\\" + oldECNNumber.ToString();
|
|
string newFolderPath = Functions.GetAttachmentFolder() + "ECN\\" + newECNNumber.ToString();
|
|
|
|
DirectoryInfo newdi = new DirectoryInfo(newFolderPath);
|
|
|
|
if (!newdi.Exists)
|
|
newdi.Create();
|
|
|
|
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));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="userID"></param>
|
|
/// <param name="pwd"></param>
|
|
/// <returns></returns>
|
|
public static bool NA_ADAuthenticate(string userID, string pwd) {
|
|
|
|
string naContainer = ConfigurationManager.AppSettings["NAContainer"];
|
|
string naDomain = ConfigurationManager.AppSettings["NADomain"];
|
|
try {
|
|
PrincipalContext contextUser = new PrincipalContext(ContextType.Domain,
|
|
naDomain,
|
|
naContainer,
|
|
ContextOptions.Negotiate, userID, pwd);
|
|
|
|
UserPrincipal up = UserPrincipal.FindByIdentity(contextUser, userID);
|
|
if (null == up)
|
|
return false;
|
|
else
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="userID"></param>
|
|
/// <param name="pwd"></param>
|
|
/// <returns></returns>
|
|
public static bool IFX_ADAuthenticate(string userID, string pwd) {
|
|
|
|
string container = ConfigurationManager.AppSettings["IFXContainer"];
|
|
string domain = ConfigurationManager.AppSettings["IFXDomain"];
|
|
try {
|
|
PrincipalContext contextUser = new PrincipalContext(ContextType.Domain,
|
|
domain,
|
|
container,
|
|
ContextOptions.Negotiate, userID, pwd);
|
|
|
|
UserPrincipal up = UserPrincipal.FindByIdentity(contextUser, userID);
|
|
if (null == up)
|
|
return false;
|
|
else
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static string FTPSPNBatch() {
|
|
ConfigurationManager.RefreshSection("appSettings");
|
|
return ConfigurationManager.AppSettings["FTPSPNBatchFileName"];
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static string FTPSPNBatch_Test() {
|
|
ConfigurationManager.RefreshSection("appSettings");
|
|
return ConfigurationManager.AppSettings["FTPSPNBatchFileName_Test"];
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="casection"></param>
|
|
/// <returns></returns>
|
|
public static string CASectionMapper(GlobalVars.CASection casection) {
|
|
switch (casection) {
|
|
case GlobalVars.CASection.Main:
|
|
return "Main";
|
|
|
|
case GlobalVars.CASection.D1:
|
|
return "D1";
|
|
|
|
case GlobalVars.CASection.D2:
|
|
return "D2";
|
|
|
|
case GlobalVars.CASection.D3:
|
|
return "D3";
|
|
|
|
case GlobalVars.CASection.D4:
|
|
return "D4";
|
|
|
|
case GlobalVars.CASection.D5:
|
|
return "D5";
|
|
|
|
case GlobalVars.CASection.D6:
|
|
return "D6";
|
|
|
|
case GlobalVars.CASection.D7:
|
|
return "D7";
|
|
|
|
case GlobalVars.CASection.D8:
|
|
return "D8";
|
|
case GlobalVars.CASection.CF: // CA Findings
|
|
return "CF";
|
|
}
|
|
|
|
return "";
|
|
}
|
|
|
|
public static string DocumentTypeMapper(GlobalVars.DocumentType docType) {
|
|
switch (docType) {
|
|
case GlobalVars.DocumentType.Audit:
|
|
return "Audit";
|
|
case GlobalVars.DocumentType.ChangeControl:
|
|
return "ChangeControl";
|
|
case GlobalVars.DocumentType.CorrectiveAction:
|
|
return "CorrectiveAction";
|
|
case GlobalVars.DocumentType.ECN:
|
|
return "ECN";
|
|
case GlobalVars.DocumentType.EECN:
|
|
return "EECN";
|
|
case GlobalVars.DocumentType.LotDisposition:
|
|
return "LotDisposition";
|
|
case GlobalVars.DocumentType.MRB:
|
|
return "MRB";
|
|
case GlobalVars.DocumentType.TECNCancelledExpired:
|
|
return "TECNCancelledExpired";
|
|
}
|
|
|
|
return "";
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts the CA No to the C00000 format
|
|
/// </summary>
|
|
/// <param name="caNo"></param>
|
|
/// <returns></returns>
|
|
public static string ReturnCANoStringFormat(int caNo) {
|
|
string caNoString = "";
|
|
if (caNo == 0)
|
|
return "";
|
|
caNoString = "C" + caNo.ToString().PadLeft(5, '0');
|
|
return caNoString;
|
|
}
|
|
|
|
public static string ReturnAuditNoStringFormat(int auditNo) {
|
|
string auditNoString = "";
|
|
if (auditNo == 0)
|
|
return "";
|
|
auditNoString = "A" + auditNo.ToString().PadLeft(5, '0');
|
|
return auditNoString;
|
|
}
|
|
|
|
public static string ReturnPartsRequestNoStringFormat(int PRNumber) {
|
|
if (PRNumber == 0)
|
|
return "";
|
|
return String.Format("PR{0:000000}", PRNumber);
|
|
}
|
|
}
|
|
}
|