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 EmployeeOutsideDutyDA internal class EmployeeOutsideDutyDA { #region Constructor private EmployeeOutsideDutyDA() { } #endregion #region Insert function internal static void Insert(TransactionContext tc, EmployeeOutsideDuty item) { tc.ExecuteNonQuery("INSERT INTO EmployeeOutsideDuty(EmployeeOutsideDutyID, EmployeeID, EntryDate, StartDate, EndDate, Comments, OutsideDutyID, CreatedBy, CreatedDate)" + " VALUES(%n, %n, %d, %D, %D, %s, %n, %n, %d)", item.ID.Integer, item.EmployeeID.Integer, item.EntryDate, item.StartDate, item.EndDate, item.Comments, item.OutsideDutyID.Integer, item.CreatedBy.Integer, item.CreatedDate); } #endregion #region Update function internal static void Update(TransactionContext tc, EmployeeOutsideDuty item) { tc.ExecuteNonQuery("UPDATE EmployeeOutsideDuty SET EmployeeID=%n, EntryDate=%d, StartDate=%D, EndDate=%D, Comments=%s, OutsideDutyID=%n, ModifiedBy=%n, ModifiedDate=%d" + " WHERE EmployeeOutsideDutyID=%n", item.EmployeeID.Integer, item.EntryDate, item.StartDate, item.EndDate, item.Comments, item.OutsideDutyID.Integer, item.ModifiedBy.Integer, item.ModifiedDate, item.ID.Integer); } #endregion #region Get Function internal static IDataReader Get(TransactionContext tc) { return tc.ExecuteReader("SELECT * FROM EmployeeOutsideDuty"); } internal static IDataReader Get(TransactionContext tc, ID nID) { return tc.ExecuteReader("SELECT * FROM EmployeeOutsideDuty WHERE EmployeeOutsideDutyID=%n", nID.Integer); } internal static IDataReader GetByEmpID(TransactionContext tc, ID empID) { return tc.ExecuteReader("SELECT * FROM EmployeeOutsideDuty WHERE EmployeeID=%n", empID.Integer); } internal static IDataReader Get(TransactionContext tc, DateTime attnDate) { return tc.ExecuteReader("SELECT * FROM EmployeeOutsideDuty WHERE %d >= CAST(StartDate AS date) AND %d <= CAST(EndDate AS date)", attnDate, attnDate); } #endregion #region Delete function internal static void Delete(TransactionContext tc, ID nID) { tc.ExecuteNonQuery("DELETE FROM [EmployeeOutsideDuty] WHERE EmployeeOutsideDutyID=%n", nID.Integer); } #endregion #region IsExist internal static bool IsOutsideDutyAvailable(TransactionContext tc, DateTime startDate, DateTime endDate, ID empID) { bool isExist = false; string sql = SQLParser.MakeSQL("SELECT Count(*) from EmployeeOutsideDuty where EmployeeID=%n AND (StartDate>=%d AND EndDate<=%d OR %d between StartDate AND EndDate OR %d between StartDate AND EndDate)", empID.Integer, startDate, endDate, startDate, endDate); object obj = tc.ExecuteScalar(sql); isExist = Convert.ToInt32(obj) > 0 ? true : false; return isExist; } #endregion } #endregion }