using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.CoreV35.DataAccess; using System.Data; using System.Data.SqlClient; using HRM.BO; using Ease.Core.DataAccess; namespace HRM.DA { internal class BadliDailyRecruitDA { #region Constructor private BadliDailyRecruitDA() { } #endregion #region Insert function internal static void Insert(TransactionContext tc, BadliDailyRecruit item) { tc.ExecuteNonQuery( "INSERT INTO BadliDailyRecruit(BadliDailyRecruitID, EmployeeID, DepartmentID, ShiftID, AccessCardNo, EntryDate, CreatedBy, CreationDate, InTime, OutTime, Status, RecommendedBy, OTHOURS, CHANGEDOTHOURS, OTREMARKS, BenefitRemarks, IsPaid, WorkPlanGroupID, WorkDayType, PaymentCode, IsPaymentCompleted)" + " VALUES(%n, %n, %n, %n, %s, %d, %n, %d, %D, %D, %n, %s, %n, %n, %s, %s, %n, %n, %n, %s, %n)", item.ID, item.EmployeeID, item.DepartmentID, item.ShiftID, item.AccessCardNo, item.EntryDate, item.CreatedBy, item.CreatedDate, item.InTime, item.OutTime, item.Status, item.RecommendedBy, item.OTHours, item.ChangedOTHours, item.OTRemarks, item.BenefitRemarks, item.IsPaid, item.WorkPlanGroupID, item.WorkDayType, item.PaymentCode, item.IsPaymentCompleted); } #endregion #region Update function internal static void Update(TransactionContext tc, BadliDailyRecruit item) { tc.ExecuteNonQuery( "UPDATE BadliDailyRecruit SET EmployeeID=%n, DepartmentID=%n, ShiftID=%n, AccessCardNo=%s, EntryDate=%d, MODIFIEDBY=%n, MODIFIEDDATE=%d, InTime=%D, OutTime=%D, Status=%n, RecommendedBy=%s, OTHOURS=%n, CHANGEDOTHOURS=%n, OTREMARKS=%s, BenefitRemarks=%s, IsPaid =%n, WorkPlanGroupID=%n, WorkDayType=%n, PaymentCode=%s, IsPaymentCompleted=%n " + " WHERE BadliDailyRecruitID=%n", item.EmployeeID, item.DepartmentID, item.ShiftID, item.AccessCardNo, item.EntryDate, item.ModifiedBy, item.ModifiedDate, item.InTime, item.OutTime, item.Status, item.RecommendedBy, item.OTHours, item.ChangedOTHours, item.OTRemarks, item.BenefitRemarks, item.IsPaid, item.WorkPlanGroupID, item.WorkDayType, item.PaymentCode, item.IsPaymentCompleted, item.ID); } #endregion #region Get Function internal static IDataReader Get(TransactionContext tc) { return tc.ExecuteReader("SELECT * FROM BadliDailyRecruit Order By DepartmentID asc"); } internal static IDataReader GetByShift(TransactionContext tc, int shiftId) { return tc.ExecuteReader("SELECT * FROM BadliDailyRecruit Where ShiftID=%n", shiftId); } internal static IDataReader GetByDepartment(TransactionContext tc, int departmentID) { return tc.ExecuteReader("SELECT * FROM BadliDailyRecruit Where DepartmentID=%n", departmentID); } internal static IDataReader GetByDepartment(TransactionContext tc, string departmentName, DateTime EntryDate) { if (departmentName == string.Empty) { return tc.ExecuteReader("SELECT * FROM BadliDailyRecruit Where EntryDate=%d", EntryDate); } else { string sql = SQLParser.MakeSQL(@"SELECT b.* FROM BADLIDAILYRECRUIT b INNER JOIN DEPARTMENT d ON d.DEPARTMENTID = b.DEPARTMENTID WHERE b.ENTRYDATE = %d AND LOWER(d.DESCRIPTION) LIKE %s", EntryDate, ('%' + departmentName + '%')); return tc.ExecuteReader(@"SELECT b.* FROM BADLIDAILYRECRUIT b INNER JOIN DEPARTMENT d ON d.DEPARTMENTID = b.DEPARTMENTID WHERE b.ENTRYDATE = %d AND LOWER(d.DESCRIPTION) LIKE %s", EntryDate, ('%' + departmentName + '%')); } } internal static IDataReader Get(TransactionContext tc, DateTime fromdate, DateTime toDate) { return tc.ExecuteReader( "SELECT b.* FROM BadliDailyRecruit b Inner join Employee e on E.EmployeeID= b.Employeeid WHERE b.EntryDate Between %d AND %d Order by e.Employeeno asc", fromdate, toDate); } internal static IDataReader Get(TransactionContext tc, DateTime fromdate, DateTime toDate, int departmentID, int shiftID, int relayID, EnumBadliStatus status, bool hasStatus) { string subQuery = string.Empty; if (departmentID != 0) { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("b.DepartmentID =%n", departmentID); } if (relayID != 0) { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("b.ShiftID =%n", relayID); } if (shiftID != 0) { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("b.WorkPlanGroupID =%n", shiftID); } if (hasStatus) { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("b.Status =%n", status); } subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("b.EntryDate Between %d AND %d", fromdate, toDate); return tc.ExecuteReader( "SELECT b.* FROM BadliDailyRecruit b Inner join Employee e on E.EmployeeID= b.Employeeid %q Order by e.Employeeno asc", subQuery); } internal static IDataReader Get(TransactionContext tc, DateTime fromdate, DateTime toDate, int departmentID, int shiftID, int relayID) { string subQuery = string.Empty; if (departmentID != null) { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("b.DepartmentID =%n", departmentID); } if (relayID != null) { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("b.ShiftID =%n", relayID); } if (shiftID != null) { subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("b.WorkPlanGroupID =%n", shiftID); } subQuery = SQLParser.TagSQL(subQuery) + SQLParser.MakeSQL("b.EntryDate Between %d AND %d", fromdate, toDate); return tc.ExecuteReader( "SELECT b.* FROM BadliDailyRecruit b Inner join Employee e on E.EmployeeID= b.Employeeid %q Order by e.Employeeno asc", subQuery); } internal static IDataReader Get(TransactionContext tc, string empIds, DateTime fromdate, DateTime toDate) { return tc.ExecuteReader( "SELECT b.* FROM BadliDailyRecruit b Inner join Employee e on E.EmployeeID= b.Employeeid WHERE b.EmployeeId in (%q) AND b.EntryDate Between %d AND %d Order by b.EntryDate, e.Employeeno asc", empIds, fromdate, toDate); } internal static IDataReader GetAllUnAssignedFrom(TransactionContext tc, DateTime FromDate) { return tc.ExecuteReader( "SELECT * FROM BadliDailyRecruit where Status=%n and EntryDate>=%d Order by InTime asc ", EnumBadliStatus.Not_Assigned, FromDate); } internal static IDataReader Get(TransactionContext tc, DateTime entryDate) { return tc.ExecuteReader("SELECT * FROM BadliDailyRecruit WHERE EntryDate=%d", entryDate); } internal static IDataReader Get(TransactionContext tc, string empIds, DateTime entryDate) { return tc.ExecuteReader( "SELECT * FROM BadliDailyRecruit WHERE EntryDate=%d AND EmployeeId in (%q) Order By EntryDate Asc", entryDate, empIds); } internal static DataSet GetBadliDepartmentWiseWorkDay(TransactionContext tc, string ids, DateTime fromdate, DateTime todate) { DataSet dSet = new DataSet(); try { string sSQL = SQLParser.MakeSQL( @"SELECT e.EMPLOYEENO, e.NAME, d.DESCRIPTION Department, wg.NAME ActualShift, count(DISTINCT b.ENTRYDATE) AS WorkedDays,count(b.SHIFTID) AS WorkedShifts, (count(b.SHIFTID) - count(DISTINCT b.ENTRYDATE)) variance FROM BADLIDAILYRECRUIT b INNER JOIN EMPLOYEE e ON e.EMPLOYEEID=b.EMPLOYEEID INNER JOIN DEPARTMENT d ON d.DEPARTMENTID=b.DEPARTMENTID INNER JOIN EMPLOYEEWORKPLANSETUP ewps ON ewps.EMPLOYEEID=b.EMPLOYEEID INNER JOIN WORKPLANGROUP wg ON wg.WORKPLANGROUPID= ewps.WORKPLANGROUPID INNER JOIN SHIFT s ON s.SHIFTID=b.SHIFTID WHERE b.ENTRYDATE BETWEEN %d AND %d AND b.ISPAID=1 and b.EmployeeID in (%q) GROUP BY e.EMPLOYEENO, e.NAME, d.DESCRIPTION, wg.NAME ORDER BY e.EMPLOYEENO asc", fromdate, todate, ids); dSet = tc.ExecuteDataSet(sSQL); } catch (Exception ex) { throw new Exception(ex.Message); } return dSet; } internal static DataSet GetAllBadliLineManager(TransactionContext tc) { DataSet dSet = new DataSet(); try { string sSQL = SQLParser.MakeSQL( @"SELECT DISTINCT RecommendedBy FROM BADLIDAILYRECRUIT b WHERE b.RECOMMENDEDBY IS NOT null"); dSet = tc.ExecuteDataSet(sSQL); } catch (Exception ex) { throw new Exception(ex.Message); } return dSet; } internal static IDataReader Get(TransactionContext tc, int empId, DateTime EntryDate, EnumBadliStatus status) { return tc.ExecuteReader( "SELECT * FROM BadliDailyRecruit WHERE EmployeeID=%n and EntryDate=%d AND Status=%n", empId, EntryDate, status); } #endregion #region Delete function internal static void Delete(TransactionContext tc, int nID) { tc.ExecuteNonQuery("DELETE FROM BadliDailyRecruit WHERE BadliDailyRecruitID=%n", nID); } internal static void Delete(TransactionContext tc, int empID, DateTime entryDate, int workPlanGroupID, int shiftID) { tc.ExecuteNonQuery( "DELETE FROM BadliDailyRecruit WHERE EmployeeID=%n AND EntryDate =%d AND WorkplanGroupID=%n AND SHiftID=%n", empID, entryDate, workPlanGroupID, shiftID); } internal static void UndoDepart(TransactionContext tc, BadliDailyRecruit item) { string sSql1 = SQLParser.MakeSQL( "UPDATE BadliDailyRecruit SET Status=%n, IsPaid =%n, PaymentCode=%s, CHANGEDOTHOURS=0, OTHOURS=0 Where BadliDailyRecruitID=%n", item.Status, item.IsPaid, item.PaymentCode, item.ID); string sSql2 = SQLParser.MakeSQL("Delete From BADLIPAYMENT Where BADLIDAILYRECRUITID =%n", item.ID); tc.ExecuteNonQuery(sSql1); tc.ExecuteNonQuery(sSql2); } internal static bool IsExist(TransactionContext tc, int empId, DateTime entryDate, int workPlanGroupID, int shiftID) { bool Exist = false; Object obj = tc.ExecuteScalar( "Select COUNT (*) FROM BadliDailyRecruit WHERE EmployeeID=%n AND EntryDate =%d AND WorkplanGroupID=%n AND SHiftID=%n", empId, entryDate, workPlanGroupID, shiftID); Exist = Convert.ToInt32(obj) > 0 ? true : false; return Exist; } #endregion } }