EchoTex_Payroll/HRM.MailNotificationProcess/frmMailNotificationProcess.cs

698 lines
35 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using HRM.BO;
using HRM.BO.Configuration;
using HRM.DA;
using Microsoft.Extensions.Configuration;
namespace HRM.MailNotificationProcess
{
public partial class frmMailNotificationProcess : Form
{
bool schedularStatus = false;
bool triggerStatus = false;
EmailSettings emailSettings = new EmailSettings();
SchedularSetupProcess oSchedularSetupProcess = new SchedularSetupProcess();
MailNotificationProcessConfiguration oMailNotificationProcessConfiguration = new MailNotificationProcessConfiguration();
List<SchedularSetup> oSchedularSetups = null;
//Thread mainThread = null;
//Thread anniversaryThread = null;
//Thread birthdayThread = null;
//Thread lastDayAbsentThread = null;
//Thread CurrentDayAbsentThread = null;
//Thread weeklyAbsentThread = null;
//Thread MonthlyAbsentThread = null;
//Thread previousDayApprovedLeaveEntryThread = null;
//Thread pendignListThread = null;
//Thread previousDayAbsentThread = null;
public frmMailNotificationProcess()
{
InitializeComponent();
MailSenderSetup();
RefreshList();
}
private void MailSenderSetup()
{
var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json");
IConfiguration Configuration = builder.Build();
Configuration.GetSection("EmailSettings").Bind(emailSettings);
Configuration.GetSection("MailNotificationProcess").Bind(oMailNotificationProcessConfiguration);
Text = oMailNotificationProcessConfiguration.ProjectName + " " + Text;
}
private void RefreshList()
{
int serial = 1;
oSchedularSetups = new SchedularSetupService().Get(EnumStatus.Active);
lvwNotificationProcess.Items.Clear();
ListViewItem[] LI = new ListViewItem[oSchedularSetups.Count];
foreach (SchedularSetup oSchedularSetup in oSchedularSetups)
{
LI[serial - 1] = new ListViewItem(new[] { serial.ToString(), oSchedularSetup.Title, oSchedularSetup.Status.ToString(), oSchedularSetup.StartAt.ToString("yyyy-MM-dd HH:mm:ss") })
{
Tag = oSchedularSetup
};
serial++;
}
lvwNotificationProcess.Items.AddRange(LI);
}
private void Log(string message)
{
using (StreamWriter writer = File.AppendText("log.txt"))
{
writer.WriteLine("[" + DateTime.Now.ToString("dd-MMM-yyyy hh:mm:ss tt") + "] - " + message);
writer.Flush();
writer.Close();
}
}
private void RunMailer()
{
int? empID = null;
int uploadID;
int? itemid;
int? payrolltypeid;
int? userid;
DateTime selectedDate = DateTime.Today;
RegularDataUploadService regUpload = new RegularDataUploadService();
List<UploadErrorOrSuccess> errorOrSuccessList = new List<UploadErrorOrSuccess>();
DataUploadColumnDefinition oColumnDefination = new DataUploadColumnDefinition();
var testSFTPInterface = new SFTPInterface();
if (lvwNotificationProcess.CheckedItems.Count > 0)
{
oSchedularSetupProcess = new SchedularSetupProcess(emailSettings, oMailNotificationProcessConfiguration);
foreach (var item in lvwNotificationProcess.CheckedItems)
{
SchedularSetup tempSchedularSetup = (SchedularSetup)((ListViewItem)item).Tag;
switch (tempSchedularSetup.Type)
{
case EnumSchedularType.Birthday:
if (oSchedularSetupProcess.waitTheThread(tempSchedularSetup.StartAt))
{
Thread birthdayThread = new Thread(() => oSchedularSetupProcess.BirthdayNofication(tempSchedularSetup));
birthdayThread.Start();
}
break;
case EnumSchedularType.Work_Aniversary:
if (oSchedularSetupProcess.waitTheThread(tempSchedularSetup.StartAt))
{
Thread anniversaryThread = new Thread(() => oSchedularSetupProcess.AnniversaryNofication(tempSchedularSetup));
anniversaryThread.Start();
}
break;
case EnumSchedularType.Daily_Attendance_Report:
if (oSchedularSetupProcess.waitTheThread(tempSchedularSetup.StartAt))
{
//Thread CurrentDayAbsentThread = new Thread(() => oSchedularSetupProcess.DailyAttendanceNofication(tempSchedularSetup));
//CurrentDayAbsentThread.Start();
}
break;
case EnumSchedularType.Previous_Day_Attendance_Report:
if (oSchedularSetupProcess.waitTheThread(tempSchedularSetup.StartAt))
{
//Thread lastDayAbsentThread = new Thread(() => oSchedularSetupProcess.PreviousDayAttendanceNofication(tempSchedularSetup));
//lastDayAbsentThread.Start();
}
break;
case EnumSchedularType.Previous_Weekly_Attendance_Report:
if (oSchedularSetupProcess.waitTheThread(tempSchedularSetup.StartAt))
{
//Thread weeklyAbsentThread = new Thread(() => oSchedularSetupProcess.PreviousWeekAttendanceNotification(tempSchedularSetup));
//weeklyAbsentThread.Start();
}
break;
case EnumSchedularType.Previous_Monthly_Attendance_Report:
if (oSchedularSetupProcess.waitTheThread(tempSchedularSetup.StartAt))
{
//Thread MonthlyAbsentThread = new Thread(() => oSchedularSetupProcess.PreviousMonthAttendanceNotification(tempSchedularSetup));
// MonthlyAbsentThread.Start();
}
break;
case EnumSchedularType.Previous_Day_Approved_LeaveEntry_Report:
if (oSchedularSetupProcess.waitTheThread(tempSchedularSetup.StartAt))
{
Thread previousDayApprovedLeaveEntryThread = new Thread(() => oSchedularSetupProcess.PreviousDayApprovedLeaveNofication(tempSchedularSetup));
previousDayApprovedLeaveEntryThread.Start();
}
break;
case EnumSchedularType.Pending_Approval:
if (oSchedularSetupProcess.waitTheThread(tempSchedularSetup.StartAt))
{
Thread pendignListThread = new Thread(() => oSchedularSetupProcess.PendingListNotification(tempSchedularSetup));
pendignListThread.Start();
}
break;
case EnumSchedularType.Yesterday_Absent_Notification_Self:
if (oSchedularSetupProcess.waitTheThread(tempSchedularSetup.StartAt))
{
Thread previousDayAbsentThread = new Thread(() => oSchedularSetupProcess.PreviousDayAbsentNotificationForEmp(tempSchedularSetup));
previousDayAbsentThread.Start();
}
break;
case EnumSchedularType.Yesterday_Absent_Notification_LM:
if (oSchedularSetupProcess.waitTheThread(tempSchedularSetup.StartAt))
{
Thread previousDayAbsentThreadLm = new Thread(() => oSchedularSetupProcess.PreviousDayAbsentNotificationForLM(tempSchedularSetup));
previousDayAbsentThreadLm.Start();
}
break;
case EnumSchedularType.LiFung_Leave_upload:
if (oSchedularSetupProcess.waitTheThread(tempSchedularSetup.StartAt))
{
LiFung_Leave(tempSchedularSetup);
}
#region commented LifungLeave upload
//uploadID = 55;
//itemid = null;
//payrolltypeid = 1;
//userid = 1;
//selectedDate = DateTime.Today;
//regUpload = new RegularDataUploadService();
//errorOrSuccessList = new List<UploadErrorOrSuccess>();
//testSFTPInterface = new SFTPInterface();
//List<MailNotificationHistory> oMailNotificationHistoryList = new List<MailNotificationHistory>();
//try
//{
// var files = testSFTPInterface.DownloadFile();
// oColumnDefination = new DataUploadColumnDefinationService().GetColumnDefinition(uploadID, itemid, (int)payrolltypeid);
// foreach (var filePath in files)
// {
// using (var fileStream = new FileStream(filePath, FileMode.Open))
// {
// errorOrSuccessList = regUpload.UploadData(uploadID, oColumnDefination, fileStream
// , (int)payrolltypeid, (int)userid, itemid, selectedDate);
// }
// }
// if(errorOrSuccessList.Count ==0)
// {
// MailNotificationHistory scc = new MailNotificationHistory();
// scc.Status = true;
// scc.Description = "Successfully upload leave file, pelase check leave report";
// oMailNotificationHistoryList.Add(scc);
// }
// else
// {
// errorOrSuccessList.ForEach(x =>
// {
// MailNotificationHistory scc = new MailNotificationHistory();
// scc.Status = false;
// scc.Description = x.Message.Length > 258 ? x.Message.Substring(1, 256) : x.Message;
// oMailNotificationHistoryList.Add(scc);
// });
// }
//}
//catch (Exception ex)
//{
// MailNotificationHistory errr = new MailNotificationHistory();
// errr.Description = ex.Message.Length > 258 ? ex.Message.Substring(1, 256) : ex.Message;
// oMailNotificationHistoryList.Add(errr);
//}
//// save oMailNotificationHistoryList
//new SchedularSetupService().SaveMailHistory(oMailNotificationHistoryList);
#endregion
break;
case EnumSchedularType.MonthlyAttendanceSummaryLM:
if (oSchedularSetupProcess.waitTheThread(tempSchedularSetup.StartAt))
{
Thread MonthlyAttendanceSummaryLMThread = new Thread(() => oSchedularSetupProcess.MonthlyAttendanceSummaryForLM(tempSchedularSetup));
MonthlyAttendanceSummaryLMThread.Start();
}
break;
case EnumSchedularType.AttendanceAutoProcess:
if (oSchedularSetupProcess.waitTheThread(tempSchedularSetup.StartAt))
{
Thread MonthlyAttendanceSummaryLMThread = new Thread(() => oSchedularSetupProcess.AttendanceAutoProcess(tempSchedularSetup));
MonthlyAttendanceSummaryLMThread.Start();
}
break;
default:
break;
}
Log(Enum.GetName(typeof(EnumSchedularType), tempSchedularSetup.Type) + " Staged at - " + tempSchedularSetup.StartAt.ToString("dd-MMM-yyyy hh:mm:ss tt"));
}
}
}
private void RunMailerTest()
{
int? empID = null;
int uploadID;
int? itemid;
int? payrolltypeid;
int? userid;
DateTime selectedDate = DateTime.Today;
RegularDataUploadService regUpload = new RegularDataUploadService();
List<UploadErrorOrSuccess> errorOrSuccessList = new List<UploadErrorOrSuccess>();
DataUploadColumnDefinition oColumnDefination = new DataUploadColumnDefinition();
var testSFTPInterface = new SFTPInterface();
if (lvwNotificationProcess.CheckedItems.Count > 0)
{
oSchedularSetupProcess = new SchedularSetupProcess(emailSettings, oMailNotificationProcessConfiguration);
foreach (var item in lvwNotificationProcess.CheckedItems)
{
SchedularSetup tempSchedularSetup = (SchedularSetup)((ListViewItem)item).Tag;
switch (tempSchedularSetup.Type)
{
case EnumSchedularType.Birthday:
if (oSchedularSetupProcess.waitTheThread(tempSchedularSetup.StartAt))
{
Thread birthdayThread = new Thread(() => oSchedularSetupProcess.BirthdayNofication(tempSchedularSetup));
birthdayThread.Start();
}
break;
case EnumSchedularType.Work_Aniversary:
if (oSchedularSetupProcess.waitTheThread(tempSchedularSetup.StartAt))
{
Thread anniversaryThread = new Thread(() => oSchedularSetupProcess.AnniversaryNofication(tempSchedularSetup));
anniversaryThread.Start();
}
break;
case EnumSchedularType.Daily_Attendance_Report:
if (oSchedularSetupProcess.waitTheThread(tempSchedularSetup.StartAt))
{
//Thread CurrentDayAbsentThread = new Thread(() => oSchedularSetupProcess.DailyAttendanceNofication(tempSchedularSetup));
//CurrentDayAbsentThread.Start();
}
break;
case EnumSchedularType.Previous_Day_Attendance_Report:
if (oSchedularSetupProcess.waitTheThread(tempSchedularSetup.StartAt))
{
//Thread lastDayAbsentThread = new Thread(() => oSchedularSetupProcess.PreviousDayAttendanceNofication(tempSchedularSetup));
//lastDayAbsentThread.Start();
}
break;
case EnumSchedularType.Previous_Weekly_Attendance_Report:
if (oSchedularSetupProcess.waitTheThread(tempSchedularSetup.StartAt))
{
//Thread weeklyAbsentThread = new Thread(() => oSchedularSetupProcess.PreviousWeekAttendanceNotification(tempSchedularSetup));
//weeklyAbsentThread.Start();
}
break;
case EnumSchedularType.Previous_Monthly_Attendance_Report:
if (oSchedularSetupProcess.waitTheThread(tempSchedularSetup.StartAt))
{
//Thread MonthlyAbsentThread = new Thread(() => oSchedularSetupProcess.PreviousMonthAttendanceNotification(tempSchedularSetup));
// MonthlyAbsentThread.Start();
}
break;
case EnumSchedularType.Previous_Day_Approved_LeaveEntry_Report:
if (oSchedularSetupProcess.waitTheThread(tempSchedularSetup.StartAt))
{
Thread previousDayApprovedLeaveEntryThread = new Thread(() => oSchedularSetupProcess.PreviousDayApprovedLeaveNofication(tempSchedularSetup));
previousDayApprovedLeaveEntryThread.Start();
}
break;
case EnumSchedularType.Pending_Approval:
if (oSchedularSetupProcess.waitTheThread(tempSchedularSetup.StartAt))
{
Thread pendignListThread = new Thread(() => oSchedularSetupProcess.PendingListNotification(tempSchedularSetup));
pendignListThread.Start();
}
break;
case EnumSchedularType.Yesterday_Absent_Notification_Self:
Thread previousDayAbsentThread = new Thread(() => oSchedularSetupProcess.PreviousDayAbsentNotificationForEmp(tempSchedularSetup));
previousDayAbsentThread.Start();
break;
case EnumSchedularType.Yesterday_Absent_Notification_LM:
Thread previousDayAbsentThreadLm = new Thread(() => oSchedularSetupProcess.PreviousDayAbsentNotificationForLM(tempSchedularSetup));
previousDayAbsentThreadLm.Start();
break;
case EnumSchedularType.LiFung_Leave_upload:
LiFung_Leave(tempSchedularSetup);
#region commented LifungLeave upload
//uploadID = 55;
//itemid = null;
//payrolltypeid = 1;
//userid = 1;
//selectedDate = DateTime.Today;
//regUpload = new RegularDataUploadService();
//errorOrSuccessList = new List<UploadErrorOrSuccess>();
//testSFTPInterface = new SFTPInterface();
//List<MailNotificationHistory> oMailNotificationHistoryList = new List<MailNotificationHistory>();
//try
//{
// var files = testSFTPInterface.DownloadFile();
// oColumnDefination = new DataUploadColumnDefinationService().GetColumnDefinition(uploadID, itemid, (int)payrolltypeid);
// foreach (var filePath in files)
// {
// using (var fileStream = new FileStream(filePath, FileMode.Open))
// {
// errorOrSuccessList = regUpload.UploadData(uploadID, oColumnDefination, fileStream
// , (int)payrolltypeid, (int)userid, itemid, selectedDate);
// }
// }
// if(errorOrSuccessList.Count ==0)
// {
// MailNotificationHistory scc = new MailNotificationHistory();
// scc.Status = true;
// scc.Description = "Successfully upload leave file, pelase check leave report";
// oMailNotificationHistoryList.Add(scc);
// }
// else
// {
// errorOrSuccessList.ForEach(x =>
// {
// MailNotificationHistory scc = new MailNotificationHistory();
// scc.Status = false;
// scc.Description = x.Message.Length > 258 ? x.Message.Substring(1, 256) : x.Message;
// oMailNotificationHistoryList.Add(scc);
// });
// }
//}
//catch (Exception ex)
//{
// MailNotificationHistory errr = new MailNotificationHistory();
// errr.Description = ex.Message.Length > 258 ? ex.Message.Substring(1, 256) : ex.Message;
// oMailNotificationHistoryList.Add(errr);
//}
//// save oMailNotificationHistoryList
//new SchedularSetupService().SaveMailHistory(oMailNotificationHistoryList);
#endregion
break;
case EnumSchedularType.MonthlyAttendanceSummaryLM:
Thread MonthlyAttendanceSummaryLMThread = new Thread(() => oSchedularSetupProcess.MonthlyAttendanceSummaryForLM(tempSchedularSetup));
MonthlyAttendanceSummaryLMThread.Start();
break;
case EnumSchedularType.AttendanceAutoProcess:
Thread AttendanceAutoProcessThread = new Thread(() => oSchedularSetupProcess.AttendanceAutoProcess(tempSchedularSetup));
AttendanceAutoProcessThread.Start();
break;
default:
break;
}
Log(Enum.GetName(typeof(EnumSchedularType), tempSchedularSetup.Type) + " Staged at - " + tempSchedularSetup.StartAt.ToString("dd-MMM-yyyy hh:mm:ss tt"));
}
}
}
private void btnStart_Click(object sender, EventArgs e)
{
try
{
if (schedularStatus == false)
{
schedularStatus = true;
lvwNotificationProcess.Enabled = false;
btnStart.Text = "Stop";
if (oMailNotificationProcessConfiguration.IsTest)
{
Log("Initiated (Test Mode)");
RunMailer();
}
else
{
Log("Initiated (Normal Mode)");
timerTriggerStart.Interval = oMailNotificationProcessConfiguration.TriggerInterval;
timerTriggerStart.Enabled = true;
timerTriggerStart.Start();
}
}
else
{
lvwNotificationProcess.Enabled = true;
schedularStatus = false;
btnStart.Text = "Start";
timerTriggerStart.Enabled = false;
timerTriggerStart.Stop();
Log("Stopped");
//if (anniversaryThread != null && anniversaryThread.ThreadState == ThreadState.Running) anniversaryThread.Abort();
//if (birthdayThread != null && birthdayThread.ThreadState == ThreadState.Running) birthdayThread.Abort();
//if (lastDayAbsentThread != null && lastDayAbsentThread.ThreadState == ThreadState.Running) lastDayAbsentThread.Abort();
//if (CurrentDayAbsentThread != null && CurrentDayAbsentThread.ThreadState == ThreadState.Running) CurrentDayAbsentThread.Abort();
//if (weeklyAbsentThread != null && weeklyAbsentThread.ThreadState == ThreadState.Running) weeklyAbsentThread.Abort();
//if (MonthlyAbsentThread != null && MonthlyAbsentThread.ThreadState == ThreadState.Running) MonthlyAbsentThread.Abort();
//if (pendignListThread != null && pendignListThread.ThreadState == ThreadState.Running) pendignListThread.Abort();
//if (previousDayAbsentThread != null && previousDayAbsentThread.ThreadState == ThreadState.Running) previousDayAbsentThread.Abort();
//if (previousDayApprovedLeaveEntryThread != null && previousDayApprovedLeaveEntryThread.ThreadState == ThreadState.Running) previousDayApprovedLeaveEntryThread.Abort();
//if (mainThread != null && mainThread.ThreadState == ThreadState.Running) mainThread.Abort();
}
}
catch (Exception)
{
}
}
private void timerTriggerStart_Tick(object sender, EventArgs e)
{
if (DateTime.Now.Hour == oMailNotificationProcessConfiguration.TriggerTime.Hour && triggerStatus == false)
{
triggerStatus = true;
Log("Triggered");
RunMailer();
if (oMailNotificationProcessConfiguration.TriggerTime.Hour == 7)
{
oMailNotificationProcessConfiguration.TriggerTime.AddHours(2);
}
else
{
oMailNotificationProcessConfiguration.TriggerTime.AddHours(-2);
}
}
else if (DateTime.Now.Hour != oMailNotificationProcessConfiguration.TriggerTime.Hour && triggerStatus == true)
{
triggerStatus = false;
}
}
public void startScheduler()
{
if (DateTime.Now.Hour == oMailNotificationProcessConfiguration.TriggerTime.Hour && triggerStatus == false)
{
triggerStatus = true;
Log("Triggered");
RunMailer();
}
else if (DateTime.Now.Hour != oMailNotificationProcessConfiguration.TriggerTime.Hour && triggerStatus == true)
{
triggerStatus = false;
}
}
private void btnRun_Click(object sender, EventArgs e)
{
//oSchedularSetupProcess.PreviousDayAbsentNotificationForEmp(tempSchedularSetup);
}
private void btnTest_Click(object sender, EventArgs e)
{
try
{
if (schedularStatus == false)
{
schedularStatus = true;
lvwNotificationProcess.Enabled = false;
btnStart.Text = "Stop";
Log("Initiated (Test Mode)");
RunMailerTest();
}
else
{
lvwNotificationProcess.Enabled = true;
schedularStatus = false;
btnStart.Text = "Start";
timerTriggerStart.Enabled = false;
timerTriggerStart.Stop();
Log("Stopped");
//if (anniversaryThread != null && anniversaryThread.ThreadState == ThreadState.Running) anniversaryThread.Abort();
//if (birthdayThread != null && birthdayThread.ThreadState == ThreadState.Running) birthdayThread.Abort();
//if (lastDayAbsentThread != null && lastDayAbsentThread.ThreadState == ThreadState.Running) lastDayAbsentThread.Abort();
//if (CurrentDayAbsentThread != null && CurrentDayAbsentThread.ThreadState == ThreadState.Running) CurrentDayAbsentThread.Abort();
//if (weeklyAbsentThread != null && weeklyAbsentThread.ThreadState == ThreadState.Running) weeklyAbsentThread.Abort();
//if (MonthlyAbsentThread != null && MonthlyAbsentThread.ThreadState == ThreadState.Running) MonthlyAbsentThread.Abort();
//if (pendignListThread != null && pendignListThread.ThreadState == ThreadState.Running) pendignListThread.Abort();
//if (previousDayAbsentThread != null && previousDayAbsentThread.ThreadState == ThreadState.Running) previousDayAbsentThread.Abort();
//if (previousDayApprovedLeaveEntryThread != null && previousDayApprovedLeaveEntryThread.ThreadState == ThreadState.Running) previousDayApprovedLeaveEntryThread.Abort();
//if (mainThread != null && mainThread.ThreadState == ThreadState.Running) mainThread.Abort();
}
}
catch (Exception)
{
}
//if (schedularStatus == false)
//{
// schedularStatus = true;
// lvwNotificationProcess.Enabled = false;
// btnStart.Text = "Stop";
// if (oMailNotificationProcessConfiguration.IsTest)
// {
// Log("Initiated (Test Mode)");
// if (lvwNotificationProcess.CheckedItems.Count > 0)
// {
// oSchedularSetupProcess = new SchedularSetupProcess(emailSettings, oMailNotificationProcessConfiguration);
// foreach (var item in lvwNotificationProcess.CheckedItems)
// {
// SchedularSetup tempSchedularSetup = (SchedularSetup)((ListViewItem)item).Tag;
// if (tempSchedularSetup.Type == EnumSchedularType.Yesterday_Absent_Notification_Self)
// {
// oSchedularSetupProcess.PreviousDayAbsentNotificationForEmp(tempSchedularSetup);
// }
// else if (tempSchedularSetup.Type == EnumSchedularType.LiFung_Leave_upload)
// {
// LiFung_Leave(tempSchedularSetup);
// }
// }
// }
// else
// {
// Log("Initiated (Normal Mode)");
// timerTriggerStart.Interval = oMailNotificationProcessConfiguration.TriggerInterval;
// timerTriggerStart.Enabled = true;
// timerTriggerStart.Start();
// }
// }
//}
//SchedularSetup tempSchedularSetup = (SchedularSetup)((ListViewItem)item).Tag;
//oSchedularSetupProcess.PreviousDayAbsentNotificationForEmp(tempSchedularSetup);
}
#region LiFungLeave
private void LiFung_Leave(SchedularSetup tempSchedularSetup)
{
int? empID = null;
int uploadID;
int? itemid;
int? payrolltypeid;
int? userid;
DateTime selectedDate = DateTime.Today;
RegularDataUploadService regUpload = new RegularDataUploadService();
List<UploadErrorOrSuccess> errorOrSuccessList = new List<UploadErrorOrSuccess>();
DataUploadColumnDefinition oColumnDefination = new DataUploadColumnDefinition();
var testSFTPInterface = new SFTPInterface();
uploadID = 55;
itemid = null;
payrolltypeid = 1;
userid = 1;
selectedDate = DateTime.Today;
regUpload = new RegularDataUploadService();
errorOrSuccessList = new List<UploadErrorOrSuccess>();
testSFTPInterface = new SFTPInterface();
List<MailNotificationHistory> oMailNotificationHistoryList = new List<MailNotificationHistory>();
try
{
var files = testSFTPInterface.DownloadFile();
oColumnDefination = new DataUploadColumnDefinationService().GetColumnDefinition(uploadID, itemid, (int)payrolltypeid);
foreach (var filePath in files)
{
using (var fileStream = new FileStream(filePath, FileMode.Open))
{
errorOrSuccessList = regUpload.UploadData(uploadID, oColumnDefination, fileStream
, (int)payrolltypeid, (int)userid, itemid, selectedDate);
}
if (errorOrSuccessList.Count == 0)
{
MailNotificationHistory scc = new MailNotificationHistory();
scc.Status = true;
scc.NotificationType = tempSchedularSetup.Type;
scc.Description = "Successfully upload leave file, pelase check leave report";
oMailNotificationHistoryList.Add(scc);
}
else
{
errorOrSuccessList.ForEach(x =>
{
MailNotificationHistory scc = new MailNotificationHistory();
scc.EmployeeNo = x.EmployeeNo;
scc.Status = false;
scc.NotificationType = tempSchedularSetup.Type;
scc.Description = x.Message.Length > 255 ? x.Message.Substring(0, 256) : x.Message;
oMailNotificationHistoryList.Add(scc);
});
}
}
}
catch (Exception ex)
{
MailNotificationHistory errr = new MailNotificationHistory();
errr.NotificationType = tempSchedularSetup.Type;
errr.Status = false;
errr.Description = ex.Message.Length > 258 ? ex.Message.Substring(1, 256) : ex.Message;
oMailNotificationHistoryList.Add(errr);
}
// save oMailNotificationHistoryList
new SchedularSetupService().SaveMailHistory(oMailNotificationHistoryList);
tempSchedularSetup.LastExecuteDateTime = DateTime.Now;
SchedularSetupService oSchedularSetupService = new SchedularSetupService();
oSchedularSetupService.Save(tempSchedularSetup);
}
#endregion
private void lvwNotificationProcess_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}