EchoTex_Payroll/HRM.DA/DA/Attendance/HolidayCalendarDA.cs

206 lines
8.3 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35.DataAccess;
using System.Data;
using HRM.BO;
using Ease.Core.DataAccess;
namespace HRM.DA
{
#region HolidayCalendarDA
internal class HolidayCalendarDA
{
#region Constructor
private HolidayCalendarDA()
{
}
#endregion
#region Insert function
internal static void Insert(TransactionContext tc, HolidayCalendar item)
{
tc.ExecuteNonQuery(
"INSERT INTO HolidayCalendar(HolidayCalendarID, Type, Description, HolidayDate, LocationID, WeeklyHolidayType, CreatedBy, CreatedDate)" +
" VALUES(%n, %n, %s, %d, %n, %n, %n, %d)", item.ID, item.Type, item.Description, item.HolidayDate,
item.LocationID, DataReader.GetNullValue(item.WeeklyHolidayType),
item.CreatedBy, item.CreatedDate);
}
#endregion
internal static IDataReader GetByDate(TransactionContext tc, DateTime dDate)
{
return tc.ExecuteReader("SELECT * FROM HolidayCalendar WHERE HolidayDate=%d", dDate);
}
#region Update function
internal static void Update(TransactionContext tc, HolidayCalendar item)
{
tc.ExecuteNonQuery(
"UPDATE HolidayCalendar SET Type=%n, Description=%s, HolidayDate=%d, LocationID=%n, WeeklyHolidayType=%n, ModifiedBy=%n, ModifiedDate=%d" +
" WHERE HolidayCalendarID=%n", item.Type, item.Description, item.HolidayDate,
item.LocationID, DataReader.GetNullValue(item.WeeklyHolidayType),
item.ModifiedBy, item.ModifiedDate, item.ID);
}
#endregion
#region Get Function
internal static IDataReader Get(TransactionContext tc)
{
return tc.ExecuteReader("SELECT * FROM HolidayCalendar");
}
internal static IDataReader GetWeeklyHoliDay(TransactionContext tc)
{
return tc.ExecuteReader("SELECT * FROM holidaycalendar WHERE locationid IS NULL");
}
internal static IDataReader GetHoliDayByLocation(TransactionContext tc, int nLocID)
{
return tc.ExecuteReader("SELECT * FROM holidaycalendar WHERE type=2 OR locationid=%n", nLocID);
}
internal static IDataReader GetWeeklyAndLocHoliday(TransactionContext tc, int? nLocID)
{
if (nLocID != null)
{
return tc.ExecuteReader(@"WITH cte AS(
SELECT createdby,createddate,holidaycalendarid,description,holidaydate,TYPE,locationid,modifiedby,modifieddate,weeklyholidaytype
,row_number()over(PARTITION BY HolidayDate ORDER BY TYPE) AS sn
FROM holidaycalendar
WHERE locationid=%n Or Type in(1,2) )
SELECT * FROM cte WHERE sn = 1", nLocID);
//return tc.ExecuteReader("SELECT * FROM holidaycalendar WHERE type=2 OR locationid=%n", nLocID);
}
else
{
return tc.ExecuteReader("SELECT * FROM holidaycalendar WHERE type=2 OR (locationid is null)");
}
//return tc.ExecuteReader("SELECT * FROM holidaycalendar WHERE locationid IS NULL OR type=2 OR locationid=%n", nLocID);
}
internal static IDataReader GetHoliDays(TransactionContext tc, int nLocID)
{
string sql = string.Empty;
if (nLocID > 0)
{
// Gets the All Holidays(national and location wise weekly). Take only 1 input for overlapping/same days
sql = SQLParser.MakeSQL(@"WITH cte AS(
SELECT createdby,createddate,holidaycalendarid,description,holidaydate,TYPE,locationid,modifiedby,modifieddate,weeklyholidaytype
,row_number()over(PARTITION BY HolidayDate ORDER BY TYPE) AS sn
FROM holidaycalendar
WHERE locationid=%n OR TYPE = 2)
SELECT * FROM cte WHERE sn = 1", nLocID);
return tc.ExecuteReader(sql);
}
else
{
// Gets the All Holidays(national and entire company Weekly). Take only 1 input for overlapping/same days
sql = SQLParser.MakeSQL("SELECT * FROM holidaycalendar WHERE locationid is null");
}
return tc.ExecuteReader(sql);
}
internal static IDataReader GetNationalHolidays(TransactionContext tc)
{
string sql = string.Empty;
sql = SQLParser.MakeSQL(@"WITH cte AS(
SELECT createdby,createddate,holidaycalendarid,description,holidaydate,TYPE,locationid,modifiedby,modifieddate,weeklyholidaytype
,row_number()over(PARTITION BY HolidayDate ORDER BY TYPE) AS sn
FROM holidaycalendar
WHERE TYPE = 2)
SELECT * FROM cte WHERE sn = 1");
return tc.ExecuteReader(sql);
}
internal static IDataReader Get(TransactionContext tc, int nID)
{
return tc.ExecuteReader("SELECT * FROM HolidayCalendar WHERE HolidayCalendarID=%n", nID);
}
internal static int GetTotalMonthlyHolidays(TransactionContext tc, DateTime firstDateOfMonth, DateTime lastDateOfMonth)
{
int totalMonthlyHolidays = 0;
object holidays = tc.ExecuteScalar("SELECT Count(*) FROM HolidayCalendar WHERE HoliDayDate BETWEEN %d AND %d", firstDateOfMonth, lastDateOfMonth);
if (holidays != DBNull.Value)
{
totalMonthlyHolidays = Convert.ToInt32(holidays);
}
return totalMonthlyHolidays;
}
internal static int GetTotalMonthlyHolidays(TransactionContext tc, int loactionNumber,
DateTime firstDateOfMonth, DateTime lastDateOfMonth)
{
int totalMonthlyHolidays = 0;
object holidays =
tc.ExecuteScalar(
"SELECT Count(*) FROM HolidayCalendar WHERE HoliDayDate >= %d AND HoliDayDate <= %d AND LocationID=%n",
firstDateOfMonth, lastDateOfMonth, loactionNumber);
if (holidays != DBNull.Value)
{
totalMonthlyHolidays = Convert.ToInt32(holidays);
}
return totalMonthlyHolidays;
}
public static double GetNoofHoliday(TransactionContext tc)
{
object ob;
ob = tc.ExecuteScalar("SELECT COUNT(HolidayCalendarID) FROM HolidayCalendar");
return ob == DBNull.Value ? 0 : Convert.ToDouble(ob);
}
public static IDataReader GetbyMonthRange(TransactionContext tc, int nLocationID, DateTime dStartDate,
DateTime dEndDate)
{
return tc.ExecuteReader(
"Select * from HolidayCalendar where LocationID=%n AND HolidayDate between %d and %d order by HolidayDate",
nLocationID, dStartDate, dEndDate);
//Old Query
//return tc.ExecuteReader("Select * from HolidayCalendar where LocationID is null OR LocationID=%n AND HolidayDate between %d and %d order by HolidayDate" , nLocationID , dStartDate , dEndDate);
}
public static IDataReader GetbyDateRange(TransactionContext tc, DateTime dStartDate, DateTime dEndDate)
{
return tc.ExecuteReader(
"Select * from HolidayCalendar where HolidayDate between %d and %d order by HolidayDate", dStartDate,
dEndDate);
}
#endregion
#region Delete function
internal static void Delete(TransactionContext tc, int nID)
{
tc.ExecuteNonQuery("DELETE FROM HolidayCalendar WHERE HolidayCalendarID=%n", nID);
}
internal static void DeleteAll(TransactionContext tc)
{
tc.ExecuteNonQuery("DELETE FROM HolidayCalendar");
}
internal static void DeleteAll(TransactionContext tc, int nYear)
{
//tc.ExecuteNonQuery("DELETE FROM HolidayCalendar where EXTRACT(YEAR FROM HolidayDate)=%n", nYear); // This is for oracle
tc.ExecuteNonQuery("DELETE FROM [HolidayCalendar] where Year(HolidayDate)=%n", nYear);
}
#endregion
}
#endregion
}