317 lines
11 KiB
C#
317 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using HRM.BO;
|
|
using Ease.Core.DataAccess;
|
|
using Ease.Core.Model;
|
|
using Ease.Core.Utility;
|
|
using System.Data;
|
|
using Microsoft.Data.SqlClient;
|
|
using System.Linq;
|
|
|
|
namespace HRM.DA
|
|
{
|
|
#region Leave Service
|
|
|
|
public class SchedularSetupService : ServiceTemplate, ISchedularSetupService
|
|
{
|
|
public SchedularSetupService()
|
|
{
|
|
}
|
|
|
|
#region Private functions and declaration
|
|
|
|
private void MapObject(SchedularSetup oSchedularSetup, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oSchedularSetup, oReader.GetInt32("SCHEDULERSETUPID").Value);
|
|
oSchedularSetup.Title = oReader.GetString("TITLE");
|
|
oSchedularSetup.StartAt = oReader.GetDateTime("STARTAT", DateTime.MinValue);
|
|
oSchedularSetup.Type = (EnumSchedularType)oReader.GetInt32("TYPE").Value;
|
|
|
|
oSchedularSetup.LastExecuteDateTime = oReader.GetDateTime("LastExecuteDateTime");
|
|
oSchedularSetup.ReportFormat = (EnumSchedularReportFormat)oReader.GetInt32("ReportFormat", (int)EnumSchedularReportFormat.None);
|
|
oSchedularSetup.Status = (EnumStatus)oReader.GetInt32("STATUS").Value;
|
|
oSchedularSetup.MailBody = oReader.GetString("MAILBODY", string.Empty);
|
|
oSchedularSetup.MailSubject = oReader.GetString("MAILSUBJECT", string.Empty);
|
|
oSchedularSetup.ToEmailAddress = oReader.GetString("TOEMAILADDRESS") != null ? oReader.GetString("TOEMAILADDRESS").ToString().Split(",").ToList() : new List<string>();
|
|
oSchedularSetup.OnErrorMail = oReader.GetString("OnErrorMail") != null ? oReader.GetString("OnErrorMail").ToString().Split(",").ToList() : new List<string>();
|
|
this.SetObjectState(oSchedularSetup, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
SchedularSetup oSchedularSetup = new SchedularSetup();
|
|
MapObject(oSchedularSetup, oReader);
|
|
return oSchedularSetup as T;
|
|
}
|
|
|
|
private SchedularSetup CreateObject(DataReader oReader)
|
|
{
|
|
SchedularSetup oSchedularSetup = new SchedularSetup();
|
|
MapObject(oSchedularSetup, oReader);
|
|
return oSchedularSetup;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Service implementation
|
|
|
|
public SchedularSetup Get(int id)
|
|
{
|
|
SchedularSetup oSchedularSetup = new SchedularSetup();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(SchedularSetupDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oSchedularSetup = this.CreateObject<SchedularSetup>(oreader);
|
|
}
|
|
|
|
oreader.Close();
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException("Failed to Get Leave", e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return oSchedularSetup;
|
|
}
|
|
|
|
public List<SchedularSetup> Get()
|
|
{
|
|
List<SchedularSetup> oSchedularSetup = new List<SchedularSetup>();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(SchedularSetupDA.Get(tc));
|
|
oSchedularSetup = this.CreateObjects<SchedularSetup>(dr);
|
|
dr.Close();
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
|
|
return oSchedularSetup;
|
|
}
|
|
|
|
public List<SchedularSetup> Get(EnumStatus status, EnumSchedularType Type, DateTime fromDate, DateTime toDate)
|
|
{
|
|
List<SchedularSetup> oSchedularSetups = new List<SchedularSetup>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(SchedularSetupDA.Get(tc, status, Type, fromDate, toDate));
|
|
oSchedularSetups = this.CreateObjects<SchedularSetup>(dr);
|
|
dr.Close();
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
return oSchedularSetups;
|
|
}
|
|
public List<SchedularSetup> Get(EnumStatus status)
|
|
{
|
|
List<SchedularSetup> oSchedularSetups = new List<SchedularSetup>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(SchedularSetupDA.Get(tc, status));
|
|
oSchedularSetups = this.CreateObjects<SchedularSetup>(dr);
|
|
dr.Close();
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
return oSchedularSetups;
|
|
}
|
|
|
|
public int Save(SchedularSetup oSchedularSetup)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oSchedularSetup.IsNew)
|
|
{
|
|
int id = tc.GenerateID("SchedularSetup", "SchedularSetupID");
|
|
base.SetObjectID(oSchedularSetup, id);
|
|
SchedularSetupDA.Insert(tc, oSchedularSetup);
|
|
}
|
|
else
|
|
{
|
|
SchedularSetupDA.Update(tc, oSchedularSetup);
|
|
}
|
|
|
|
tc.End();
|
|
return oSchedularSetup.ID;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new Exception("Failed to Insert Shchedular. Because " + e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
//public int UpdateStatusAndTime(SchedularSetup oSchedularSetup)
|
|
//{
|
|
// TransactionContext tc = null;
|
|
// try
|
|
// {
|
|
// tc = TransactionContext.Begin(true);
|
|
|
|
// SchedularSetupDA.UpdateStatusAndTime(tc, oSchedularSetup.ID, oSchedularSetup.sh, DateTime.Now);
|
|
|
|
// tc.End();
|
|
// return oSchedularSetup.ID;
|
|
// }
|
|
// catch (Exception e)
|
|
// {
|
|
// #region Handle Exception
|
|
|
|
// if (tc != null)
|
|
// tc.HandleError();
|
|
// ExceptionLog.Write(e);
|
|
// throw new Exception("Failed to Insert Shchedular. Because " + e.Message, e);
|
|
|
|
// #endregion
|
|
// }
|
|
//}
|
|
|
|
public void Delete(int id)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
SchedularSetupDA.Delete(tc, id);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
public void SaveMailHistory(List<MailNotificationHistory> pMailNotificationHistory)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
|
|
try
|
|
{
|
|
int maxId = SchedularSetupDA.GetMailNotificationHistoryMaxId(tc);
|
|
if (pMailNotificationHistory != null && pMailNotificationHistory.Count > 0)
|
|
{
|
|
DataTable MailNotificationHistoryEntryTable = new DataTable("MailNotificationHistory");
|
|
MailNotificationHistoryEntryTable.Columns.Add(new DataColumn("MailNotificationHistoryID", typeof(int)));
|
|
MailNotificationHistoryEntryTable.Columns.Add(new DataColumn("EMPLOYEENO", typeof(string)));
|
|
MailNotificationHistoryEntryTable.Columns.Add(new DataColumn("NOTIFICATIONTYPE", typeof(short)));
|
|
MailNotificationHistoryEntryTable.Columns.Add(new DataColumn("DESCRIPTION", typeof(string)));
|
|
MailNotificationHistoryEntryTable.Columns.Add(new DataColumn("STATUS", typeof(bool)));
|
|
MailNotificationHistoryEntryTable.Columns.Add(new DataColumn("CREATIONDATE", typeof(DateTime)));
|
|
|
|
|
|
foreach (MailNotificationHistory item in pMailNotificationHistory)
|
|
{
|
|
MailNotificationHistoryEntryTable.Rows.Add(
|
|
maxId++,
|
|
item.EmployeeNo,
|
|
(int)item.NotificationType,
|
|
item.Description,
|
|
item.Status,
|
|
DateTime.Now
|
|
);
|
|
}
|
|
|
|
using (SqlBulkCopy bulkCopy = new SqlBulkCopy((SqlConnection)tc.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)tc.Transaction))
|
|
{
|
|
bulkCopy.BulkCopyTimeout = 6000;
|
|
bulkCopy.DestinationTableName = "MailNotificationHistory";
|
|
bulkCopy.WriteToServer(MailNotificationHistoryEntryTable);
|
|
}
|
|
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new Exception("Failed to Insert Shchedular History. Because " + e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
#endregion
|
|
} |