CEL_Payroll/Payroll.Service/Leave/DA/LeaveYearDA.cs
2024-09-17 14:30:13 +06:00

112 lines
4.7 KiB
C#

using System;
using Payroll.BO;
using System.Data;
using System.Linq;
using Ease.CoreV35.Model;
using System.Data.SqlClient;
using Ease.CoreV35.DataAccess;
using System.Collections.Generic;
using Ease.CoreV35.DataAccess.SQL;
namespace Payroll.Service
{
class LeaveYearDA
{
#region Constructor
public LeaveYearDA() { }
#endregion
#region Insert function
public static void Insert(TransactionContext tc, LeaveYear oItem)
{
tc.ExecuteNonQuery("INSERT INTO LeaveYear(LeaveYearID, Name, StartDate,EndDate,IsCurrent, IsEnded,CreatedBy, CreatedDate, SequenceNo, Status)" +
" VALUES(%n, %s, %d, %d,%b, %b, %n, %d,%n, %n)", oItem.ID.Integer, oItem.Name, oItem.StartDate, oItem.EndDate, oItem.IsCurrent, oItem.IsEnded, DataReader.GetNullValue(oItem.CreatedBy.Integer), DataReader.GetNullValue(oItem.CreatedDate), oItem.Sequence, oItem.Status);
}
#endregion
#region Update function
public static void Update(TransactionContext tc, LeaveYear oItem)
{
tc.ExecuteNonQuery("UPDATE LeaveYear SET Name=%s, StartDate=%d, EndDate=%d, IsCurrent=%n, IsEnded=%n,CreatedBy=%n, CreatedDate=%d, ModifiedBy=%n, ModifiedDate=%d, SequenceNo=%n, Status=%n" +
" WHERE LeaveYearID=%n", oItem.Name, oItem.StartDate, oItem.EndDate, oItem.IsCurrent, oItem.IsEnded, DataReader.GetNullValue(oItem.CreatedBy, IDType.Integer), DataReader.GetNullValue(oItem.CreatedDate), DataReader.GetNullValue(oItem.ModifiedBy, IDType.Integer), DataReader.GetNullValue(oItem.ModifiedDate), oItem.Sequence, oItem.Status, oItem.ID.Integer);
}
//public static void UpdateYearEndValue(TransactionContext tc)
//{
// bool status = true;
// bool newStatus = false;
// //nProcessYear = LeaveEntry.getJulyJuneLeaveYear(nProcessYear);
// tc.ExecuteReader("Update LeaveYear set ISCURRENT=%b,ISENDED=%b WHERE ISCURRENT=%b AND ISENDED=%b", newStatus, status, status,newStatus);
//}
public static void UpdateCurrYearStatus(TransactionContext tc, LeaveYear leaveYear)
{
tc.ExecuteNonQuery("Update LeaveYear set ISCURRENT=%b,ISENDED=%b WHERE LeaveYearID=%n", leaveYear.IsCurrent, false, leaveYear.ID.Integer);
}
public static void UpdateYearEndStatus(TransactionContext tc, LeaveYear leaveYear)
{
tc.ExecuteNonQuery("Update LeaveYear set ISENDED=%b WHERE LeaveYearID=%n", leaveYear.IsEnded, leaveYear.ID.Integer);
}
#endregion
#region ID Generation function
public static int GetNewID(TransactionContext tc)
{
return tc.GenerateID("LeaveYear", "LeaveYearID");
}
#endregion
#region Get Function
internal static IDataReader Get(TransactionContext tc, EnumStatus status)
{
if (EnumStatus.Active == status || EnumStatus.Inactive == status)
{
return tc.ExecuteReader("SELECT * FROM LeaveYear Where Status=%n Order By SequenceNo", status);
}
else
{
return tc.ExecuteReader("SELECT * FROM LeaveYear Order By SequenceNo");
}
}
public static IDataReader Get(TransactionContext tc, int leaveYearID)
{
return tc.ExecuteReader("SELECT * FROM LeaveYear where LeaveYearID=%n", leaveYearID);
}
public static IDataReader Get(TransactionContext tc)
{
return tc.ExecuteReader("SELECT * FROM LeaveYear order by StartDate DESC");
}
public static int CountCurrentYear(TransactionContext tc)
{
object obj = new object();
obj = tc.ExecuteScalar("SELECT count(*) FROM LeaveYear WHERE ISCURRENT=%n", 1);
return (Convert.ToInt32(obj));
}
public static IDataReader GetCurrentYear(TransactionContext tc)
{
bool status = true;
//nProcessYear = LeaveEntry.getJulyJuneLeaveYear(nProcessYear);
return tc.ExecuteReader("SELECT * FROM LeaveYear WHERE ISCURRENT=%b", status);
}
public static IDataReader GetCurrentYear(TransactionContext tc, string year)
{
return tc.ExecuteReader("SELECT * FROM LeaveYear WHERE NAME=%s", year);
}
public static IDataReader GetIDByName(TransactionContext tc, string sLeaveYear)
{
return tc.ExecuteReader("SELECT * FROM LeaveYear WHERE NAME=%s", sLeaveYear);
}
#endregion
#region Delete function
public static void Delete(TransactionContext tc, int leaveYearID)
{
tc.ExecuteNonQuery("DELETE FROM LeaveYear WHERE LeaveYearID=%n", leaveYearID);
}
#endregion
}
}