using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.CoreV35.DataAccess; using Payroll.BO; using System.Data; using Ease.CoreV35.Model; namespace Payroll.Service.Attendence.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, CreatedBy, CreatedDate)" + " VALUES(%n, %n, %s, %d, %n, %n, %d)", item.ID.Integer, item.Type, item.Description, item.HolidayDate, DataReader.GetNullValue(item.LocationID, IDType.Integer), item.CreatedBy.Integer, item.CreatedDate); } #endregion #region Update function internal static void Update(TransactionContext tc, HolidayCalendar item) { tc.ExecuteNonQuery("UPDATE HolidayCalendar SET Type=%n, Description=%s, HolidayDate=%d, LocationID=%n, ModifiedBy=%n, ModifiedDate=%d" + " WHERE HolidayCalendarID=%n", item.Type, item.Description, item.HolidayDate, DataReader.GetNullValue(item.LocationID, IDType.Integer), item.ModifiedBy.Integer, item.ModifiedDate, item.ID.Integer); } #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, ID nLocID) { return tc.ExecuteReader("SELECT * FROM holidaycalendar WHERE type=2 OR locationid=%n", nLocID.Integer); } internal static IDataReader GetWeeklyAndLocHoliday(TransactionContext tc, ID nLocID) { return tc.ExecuteReader("SELECT * FROM holidaycalendar WHERE locationid IS NULL OR type=2 OR locationid=%n", nLocID.Integer); } internal static IDataReader Get(TransactionContext tc, ID nID) { return tc.ExecuteReader("SELECT * FROM HolidayCalendar WHERE HolidayCalendarID=%n", nID); } 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 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, ID 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 Year(HolidayDate)=%n",nYear); } #endregion } #endregion }