127 lines
5.2 KiB
C#
127 lines
5.2 KiB
C#
using HRM.BO;
|
|
using Ease.Core.DataAccess;
|
|
using System;
|
|
using System.Data;
|
|
|
|
namespace HRM.DA
|
|
{
|
|
#region MasterEmailLogDA
|
|
|
|
internal class MasterEmailLogDA
|
|
{
|
|
#region Constructor
|
|
|
|
private MasterEmailLogDA()
|
|
{
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Insert function
|
|
|
|
internal static void Insert(TransactionContext tc, MasterEmailLog item)
|
|
{
|
|
tc.ExecuteNonQuery(
|
|
"INSERT INTO MasterEmailLog(MasterEmailLogID, EmailType, Description, PayrollTypeID, ParameterJson," +
|
|
" TotalCount, SuccessCount, FailedCount, SkippedCount, BatchStatus, StartTime, EndTime," +
|
|
" RetryCount, LastRetryDate, PreserveAttachment, CreatedBy, CreationDate)" +
|
|
" VALUES(%n, %n, %u, %n, %u, %n, %n, %n, %n, %n, %D, %D, %n, %D, %b, %n, %D)",
|
|
item.ID, (int)item.EmailType, item.Description, DataReader.GetNullValue(item.PayrollTypeID),
|
|
item.ParameterJson, item.TotalCount, item.SuccessCount, item.FailedCount, item.SkippedCount,
|
|
(int)item.BatchStatus, item.StartTime, item.EndTime, item.RetryCount, item.LastRetryDate,
|
|
item.PreserveAttachment, item.CreatedBy, item.CreatedDate);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Update function
|
|
|
|
internal static void Update(TransactionContext tc, MasterEmailLog item)
|
|
{
|
|
tc.ExecuteNonQuery(
|
|
"UPDATE MasterEmailLog SET EmailType=%n, Description=%u, PayrollTypeID=%n, ParameterJson=%u," +
|
|
" TotalCount=%n, SuccessCount=%n, FailedCount=%n, SkippedCount=%n, BatchStatus=%n," +
|
|
" StartTime=%D, EndTime=%D, RetryCount=%n, LastRetryDate=%D, PreserveAttachment=%b," +
|
|
" ModifiedBy=%n, ModifiedDate=%D WHERE MasterEmailLogID=%n",
|
|
(int)item.EmailType, item.Description, DataReader.GetNullValue(item.PayrollTypeID),
|
|
item.ParameterJson, item.TotalCount, item.SuccessCount, item.FailedCount, item.SkippedCount,
|
|
(int)item.BatchStatus, item.StartTime, item.EndTime, item.RetryCount, item.LastRetryDate,
|
|
item.PreserveAttachment, DataReader.GetNullValue(item.ModifiedBy), item.ModifiedDate, item.ID);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Writes only the counters and the resulting status. Used after every
|
|
/// batch and every retry so the header never drifts from its details.
|
|
/// </summary>
|
|
internal static void UpdateCounters(TransactionContext tc, int masterEmailLogID, int totalCount,
|
|
int successCount, int failedCount, int skippedCount, EnumEmailBatchStatus batchStatus,
|
|
DateTime? endTime, int? modifiedBy, DateTime modifiedDate)
|
|
{
|
|
tc.ExecuteNonQuery(
|
|
"UPDATE MasterEmailLog SET TotalCount=%n, SuccessCount=%n, FailedCount=%n, SkippedCount=%n," +
|
|
" BatchStatus=%n, EndTime=%D, ModifiedBy=%n, ModifiedDate=%D WHERE MasterEmailLogID=%n",
|
|
totalCount, successCount, failedCount, skippedCount, (int)batchStatus, endTime,
|
|
DataReader.GetNullValue(modifiedBy), modifiedDate, masterEmailLogID);
|
|
}
|
|
|
|
internal static void UpdateRetryStarted(TransactionContext tc, int masterEmailLogID, int modifiedBy,
|
|
DateTime retryDate)
|
|
{
|
|
tc.ExecuteNonQuery(
|
|
"UPDATE MasterEmailLog SET RetryCount = RetryCount + 1, LastRetryDate=%D, BatchStatus=%n," +
|
|
" ModifiedBy=%n, ModifiedDate=%D WHERE MasterEmailLogID=%n",
|
|
retryDate, (int)EnumEmailBatchStatus.Processing, modifiedBy, retryDate, masterEmailLogID);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Get function
|
|
|
|
internal static IDataReader Get(TransactionContext tc, int id)
|
|
{
|
|
return tc.ExecuteReader("SELECT * FROM MasterEmailLog WHERE MasterEmailLogID=%n", id);
|
|
}
|
|
|
|
/// <summary>
|
|
/// History grid. EmailType 0 (None) and a null payrollTypeID both mean
|
|
/// "do not filter on this", so one query serves every screen.
|
|
/// </summary>
|
|
internal static IDataReader Get(TransactionContext tc, EnumEmailType emailType, int? payrollTypeID,
|
|
DateTime fromDate, DateTime toDate)
|
|
{
|
|
string sql = SQLParser.MakeSQL(
|
|
"SELECT ml.*, u.UserName AS CreatedByName FROM MasterEmailLog ml" +
|
|
" LEFT JOIN Users u ON u.UserID = ml.CreatedBy" +
|
|
" WHERE ml.CreationDate >= %D AND ml.CreationDate < %D",
|
|
fromDate.Date, toDate.Date.AddDays(1));
|
|
|
|
if (emailType != EnumEmailType.None)
|
|
{
|
|
sql += SQLParser.MakeSQL(" AND ml.EmailType=%n", (int)emailType);
|
|
}
|
|
|
|
if (payrollTypeID != null)
|
|
{
|
|
sql += SQLParser.MakeSQL(" AND ml.PayrollTypeID=%n", payrollTypeID);
|
|
}
|
|
|
|
sql += " ORDER BY ml.MasterEmailLogID DESC";
|
|
|
|
return tc.ExecuteReader(sql);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Delete function
|
|
|
|
internal static void Delete(TransactionContext tc, int id)
|
|
{
|
|
tc.ExecuteNonQuery("DELETE FROM MasterEmailLog WHERE MasterEmailLogID=%n", id);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
#endregion
|
|
}
|