using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.CoreV35.DataAccess; using Payroll.BO; using Ease.CoreV35.Model; using System.Data; using Payroll.BO; namespace Payroll.Service.Attendence.DA { #region MonthlyWorkPlanDA internal class MonthlyWorkPlanDA { #region Constructor private MonthlyWorkPlanDA() { } #endregion #region Insert function internal static void Insert(TransactionContext tc, MonthlyWorkPlan item) { tc.ExecuteNonQuery("INSERT INTO MonthlyWorkPlan(MonthlyWorkPlanID, EmployeeID, WorkDate, ShiftID, HolidayID, CreatedBy, CreatedDate,Type,WorkPlanGroupID)" + " VALUES(%n, %n, %d, %n, %n, %n, %d, %n, %n)", item.ID.Integer, item.EmployeeID.Integer, item.WorkDate, item.ShiftID.Integer, DataReader.GetNullValue(item.HolidayID, IDType.Integer), item.CreatedBy.Integer, item.CreatedDate, item.Type, DataReader.GetNullValue(item.WorkPlanGroupID, IDType.Integer)); } #endregion #region Update function internal static void Update(TransactionContext tc, MonthlyWorkPlan item) { tc.ExecuteNonQuery("UPDATE MonthlyWorkPlan SET EmployeeID=%n, WorkDate=%d, ShiftID=%n, HolidayID=%n, ModifiedBy=%n, ModifiedDate=%d, Type=%n, WorkPlanGroupID=%n" + " WHERE MonthlyWorkPlanID=%n", item.EmployeeID.Integer, item.WorkDate, DataReader.GetNullValue(item.ShiftID.Integer), DataReader.GetNullValue(item.HolidayID.Integer), item.ModifiedBy.Integer, item.ModifiedDate, item.Type, DataReader.GetNullValue(item.WorkPlanGroupID.Integer), item.ID.Integer); } #endregion #region Get Function internal static IDataReader Get(TransactionContext tc) { return tc.ExecuteReader("SELECT * FROM MonthlyWorkPlan"); } internal static IDataReader Get(TransactionContext tc, DateTime attnDate) { return tc.ExecuteReader("SELECT * FROM MonthlyWorkPlan WHERE WorkDate=%d", attnDate); } internal static IDataReader GetByType(TransactionContext tc, EnumWorkPlanGroup type) { return tc.ExecuteReader("SELECT * FROM MonthlyWorkPlan Where Type=%n", type); } internal static IDataReader GetByDateAndWPGType(TransactionContext tc, DateTime dAssDate, EnumWorkPlanGroup type) { return tc.ExecuteReader("SELECT * FROM MonthlyWorkPlan Where WorkDate=%d AND " + "EmployeeID IN (SELECT EmployeeID FROM EmployeeWorkPlanSetup WHERE WorkPlanGroupID=%n)", dAssDate, type); } internal static IDataReader GetByDateAndGroupID(TransactionContext tc, DateTime dAssDate, ID groupID) { return tc.ExecuteReader("SELECT * FROM MonthlyWorkPlan Where WorkDate BETWEEN %d AND %d and WorkPlanGroupID=%n", GlobalFunctions.FirstDateOfMonth(dAssDate), GlobalFunctions.LastDateOfMonth(dAssDate), groupID.Integer); } internal static IDataReader Get(TransactionContext tc, ID nID) { return tc.ExecuteReader("SELECT * FROM MonthlyWorkPlan WHERE MonthlyWorkPlanID=%n", nID); } internal static IDataReader GetByEmpID(TransactionContext tc, ID nEmpID, DateTime assDate, EnumWorkPlanGroup type) { if (type == EnumWorkPlanGroup.Counter_Clock_1 || type == EnumWorkPlanGroup.Fixed) { return tc.ExecuteReader("SELECT * FROM MonthlyWorkPlan WHERE EmployeeID=%n AND WorkDate=%d AND Type=%n", nEmpID.Integer, assDate, type); } else { return tc.ExecuteReader("SELECT * FROM MonthlyWorkPlan WHERE EmployeeID=%n AND WorkDate=%d AND Type Not in(%n,%n)", nEmpID.Integer, assDate, EnumWorkPlanGroup.Counter_Clock_1, EnumWorkPlanGroup.Fixed); } } internal static IDataReader GetByEmpID(TransactionContext tc, ID nEmpID, DateTime workDate) { //string str = SQLParser.MakeSQL("SELECT * FROM MonthlyWorkPlan WHERE EmployeeID=%n AND WorkDate=%d ", nEmpID.Integer, workDate); return tc.ExecuteReader("SELECT * FROM MonthlyWorkPlan WHERE EmployeeID=%n AND WorkDate=%d ", nEmpID.Integer, workDate); } internal static int DayCount(TransactionContext tc, EnumWorkPlanGroup type) { int count; object obj = tc.ExecuteScalar("SELECT ( SELECT Count(*) FROM MonthlyWorkPlan WHERE Type=%n)/(SELECT count(DISTINCT Employeeid) FROM MonthlyWorkPlan WHERE Type=%n )", type, type); if (obj != null) { count = Convert.ToInt32(obj); } else { count = 0; } return count; } internal static IDataReader GetMonthlyDataByEmp(TransactionContext tc, DateTime dAssDate, EnumWorkPlanGroup type, ID nEmpiD) { return tc.ExecuteReader("SELECT * FROM MonthlyWorkPlan Where WorkDate BETWEEN %d AND %d and Type=%n And EmployeeID=%n", GlobalFunctions.FirstDateOfMonth(dAssDate), GlobalFunctions.LastDateOfMonth(dAssDate), type, nEmpiD.Integer); } internal static DataSet GetMissingEmp(TransactionContext tc, ID groupID, DateTime assignDate) { DataSet missingEmp = new DataSet(); try { string sql = SQLParser.MakeSQL(""); missingEmp = tc.ExecuteDataSet(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return missingEmp; } internal static DataSet GetEmpNotInMonthlyWorkPlan(TransactionContext tc, DateTime assignDate) { DataSet missingEmp = new DataSet(); try { string sql = SQLParser.MakeSQL("select e.employeeno,e.name,g.DESCRIPTION from employee e,GRADES g " + "where e.gradeID = g.GRADEID and e.status=%n and e.employeeid not in (select distinct(EmployeeID) from MonthlyWorkPlan " + "where workdate between %d and %d)", EnumEmployeeStatus.Live, GlobalFunctions.FirstDateOfMonth(assignDate), GlobalFunctions.LastDateOfMonth(assignDate)); missingEmp = tc.ExecuteDataSet(sql); } catch (Exception ex) { throw new Exception(ex.Message); } return missingEmp; } #endregion #region Delete function internal static void Delete(TransactionContext tc, ID nID) { tc.ExecuteNonQuery("DELETE FROM [MonthlyWorkPlan] WHERE MonthlyWorkPlanID=%n", nID.Integer); } internal static void Delete(TransactionContext tc, DateTime dFromDate, DateTime dToDate, EnumWorkPlanGroup type) { tc.ExecuteNonQuery("DELETE FROM MonthlyWorkPlan WHERE WorkDate BETWEEN %d AND %d AND Type=%n", dFromDate, dToDate, type); } internal static void Delete(TransactionContext tc, DateTime dFromDate, DateTime dToDate, ID wpGroupID) { tc.ExecuteNonQuery("DELETE FROM MonthlyWorkPlan WHERE WorkDate BETWEEN %d AND %d AND Type=%n", dFromDate, dToDate, wpGroupID.Integer); } internal static void Delete(TransactionContext tc, DateTime dFromDate, DateTime dToDate) { tc.ExecuteNonQuery("DELETE FROM MonthlyWorkPlan WHERE WorkDate BETWEEN %d AND %d ", dFromDate, dToDate); } internal static void Delete(TransactionContext tc, DateTime assignDate, string empIDs) { tc.ExecuteNonQuery("DELETE FROM MonthlyWorkPlan WHERE WorkDate BETWEEN %d AND %d AND EmployeeID IN(%q)", GlobalFunctions.FirstDateOfMonth(assignDate), GlobalFunctions.LastDateOfMonth(assignDate), empIDs); } #endregion internal static bool IsExist(TransactionContext tc, DateTime dAssDate, ID groupID) { bool isExist = false; string sql = SQLParser.MakeSQL(@"SELECT Count(*) from MonthlyWorkPlan Where WorkDate BETWEEN %d AND %d and WorkPlanGroupID=%n ", GlobalFunctions.FirstDateOfMonth(dAssDate), GlobalFunctions.LastDateOfMonth(dAssDate), groupID.Integer); object obj = tc.ExecuteScalar(sql); if (obj == DBNull.Value) return false; isExist = Convert.ToInt32(obj) > 0 ? true : false; return isExist; } } #endregion }