using System; using System.Data; using Ease.Core.DataAccess; using HRM.BO; namespace HRM.DA { #region EmpLifeCycleDA public class EmpLifeCycleDA { #region Constructor private EmpLifeCycleDA() { } #endregion #region Insert function public static void Insert(TransactionContext tc, EmpLifeCycle item) { tc.ExecuteNonQuery( "INSERT INTO EmpLifeCycle(EmpLifeCycleID,EffectDate,NodeID,GrossSalary,BasicSalary,GradeID,CategoryID,CompanyID,FunctionID,DesignationID,LocationID,DepartmentID,IsConfirm,pFMemberType,IsDiscontinue,IsContinue,EmployeeID,StatusDetailID,Remarks,Description,Status,CreatedBy, CreationDate, SequenceNo,SalaryMonth,IsCurrentMonthIncluded,CostCenterID,GradeSalaryAssesmentID,EmployeeCCID,IncrementNo,PayrollTypeID,ComplainID,PunishmentID)" + " VALUES( %n , %D , %n , %n , %n , %n , %n , %n , %n , %n , %n , %n , %b , %n , %b , %b , %n , %n , %s , %s , %n , %n , %D , %n , %D , %b , %n , %n , %n ,%n, %n,%n,%n )", item.ID, item.EffectDate, item.NodeID, item.GrossSalary, item.BasicSalary, item.GradeID, item.CategoryID, item.CompanyID, item.FunctionID, item.DesignationID, item.LocationID, item.DepartmentID, item.IsConfirm, item.PFMemberType, item.IsDiscontinue, item.IsContinue, item.EmployeeID, item.StatusDetailID, item.Remarks, item.Description, item.EmployeeStatus, DataReader.GetNullValue(item.CreatedBy, 0), item.CreatedDate, item.Sequence, item.SalaryMonth, item.IsCurrentMonthIncluded, item.CostCenterID, item.GradeSalaryAssesmentID, item.EmployeeCCID, item.IncrementNo, DataReader.GetNullValue(item.PayrollTypeID, 0), DataReader.GetNullValue(item.ComplainID,0), DataReader.GetNullValue(item.PunishmentID, 0)); //1 //2 //3 //4 //5 //6 //7 //8 //9 //10 //11 //12 //13 //14 //15 //16 //17 //18 //19 //20 //21 //21 //22 //23 //24 //25 } #endregion #region Update function public static void Update(TransactionContext tc, EmpLifeCycle item) { //tc.ExecuteNonQuery("UPDATE EmpLifeCycle SET Code=%s, Name=%s, ACCOUNTNOFORMAT=%s, ModifiedBy=%n, ModifiedDate=%d, SequenceNo=%n, Status=%n" + //"WHERE EmpLifeCycleID=%n", item.Code, item.Name, item.Accountingformat, item.ModifiedBy, item.ModifiedDate, item.Sequence, item.Status,item.ID); } #endregion #region Get Function internal static IDataReader GetNotYetProcessUptoToday(TransactionContext tc) { string sql = SQLParser.MakeSQL("Select * from EmpLifeCycle where IsProcessed =%b and EffectDate <=%d", false, DateTime.Today); return tc.ExecuteReader(sql); } internal static IDataReader Get(TransactionContext tc, int lifecycleID) { return tc.ExecuteReader("SELECT * FROM EmpLifeCycle where EmpLifeCycleID=%n order by SequenceNo", lifecycleID); } internal static IDataReader GetEmpID(TransactionContext tc, int nEmpID, DateTime effectDate) { return tc.ExecuteReader( "SELECT * FROM EmpLifeCycle where employeeid=%n AND EffectDate<=%d order by SequenceNo", nEmpID, effectDate); } internal static IDataReader GetLastPosition(TransactionContext tc, int nEmpID) { return tc.ExecuteReader( "select * from EmpLifeCycle where employeeid=%n and sequenceno=(select max(sequenceno) from EmpLifeCycle where employeeid=%n AND EffectDate<=%d)", nEmpID, nEmpID, DateTime.Today); } internal static IDataReader Get(TransactionContext tc, EnumStatus status, int payrollTypeID) { if (EnumStatus.Active == status) { return tc.ExecuteReader("SELECT * FROM EmpLifeCycle where Status=%n order by CreationDate", status); } else { return tc.ExecuteReader( "SELECT * FROM EmpLifeCycle where EmployeeID in(select EmployeeID from EMPLOYEE where PAYROLLTYPEID=%n) order by CreationDate", payrollTypeID); } } internal static IDataReader Get(TransactionContext tc, string empIds, int statusDetailsId, DateTime fromDate, DateTime toDate, int payrollTypeId) { return tc.ExecuteReader( "SELECT * FROM EmpLifeCycle Where EmployeeID in (%q) And STATUSDETAILID=%n AND EffectDate Between %d ANd %d order by EffectDate desc", empIds, statusDetailsId, fromDate, toDate); } internal static IDataReader GetEmpID(TransactionContext tc, int employeeID) { return tc.ExecuteReader("SELECT * FROM EmpLifeCycle Where EmployeeID=%n order by EffectDate desc", employeeID); } internal static DataSet GetDesignationChange(TransactionContext tc, DateTime fromDate, DateTime toDate, int payrollTypeId) { return tc.ExecuteDataSet(@"SELECT distinct e.EMPLOYEEID, e.EMPLOYEENO,e.NAME,el.EFFECTDATE,d.NAME Designation, u.LOGINID,el.CREATEDBY,el.CREATIONDATE,el.emplifecycleID , uf.LOGINID AuthorizeBy,f.APPROVEDDATE FROM emplifecycle el INNER JOIN EMPLOYEE e ON e.EMPLOYEEID = el.EMPLOYEEID LEFT JOIN DESIGNATION d ON d.DESIGNATIONID = el.DESIGNATIONID LEFT JOIN USERS u ON u.USERID = el.CREATEDBY LEFT JOIN ApproveFinantialData f ON e.EMPLOYEEID=f.EMPLOYEEID AND el.EMPLIFECYCLEID=f.OBJECTID AND f.FINANATIALDATATYPE=3 AND Year(f.SALARYMONTH)=Year(el.EFFECTDATE) AND MONTH(f.SALARYMONTH)=MONTH(el.EFFECTDATE) LEFT JOIN Users uf ON uf.USERID = f.Approvedby INNER JOIN(SELECT DISTINCT els.EMPLOYEEID, effectdate FROM emplifecycle els, EMPLOYEE es WHERE els.EMPLOYEEID = es.EMPLOYEEID AND CAST(els.EFFECTDATE AS DATE) <> es.joiningdate and EFFECTDATE between %d and %d AND els.DESIGNATIONID IS NOT NULL ) A ON A.Employeeid = el.EMPLOYEEID WHERE el.DESIGNATIONID IS NOT NULL And e.payrollTypeId=%n ORDER BY e.EMPLOYEENO, el.EFFECTDATE desc", fromDate, toDate, payrollTypeId); } //internal static IDataReader Get(TransactionContext tc, DateTime fromEffectDate, DateTime toEffectDate, int eventID) //{ // string sql = string.Empty; // sql = SQLParser.MakeSQL("Select * from EmpLifeCycle Where EffectDate between %d and %d AND StatusDetailID =%n order by EffectDate",fromEffectDate,toEffectDate, eventID); // return tc.ExecuteReader(sql); //} internal static DataSet GetEmpLifecycleServiceRecord(TransactionContext tc, int empId) { string sql = SQLParser.MakeSQL(@" WITH CTE AS ( SELECT EMPLIFECYCLEID, BASICSALARY, GRADEID, DESIGNATIONID, EFFECTDATE, ROW_NUMBER() OVER (ORDER BY EFFECTDATE) AS rn FROM EMPLIFECYCLE WHERE EMPLOYEEID = %n AND (BASICSALARY <> 0 and BASICSALARY IS NOT NULL) AND (GRADEID IS NOT NULL OR DESIGNATIONID IS NOT NULL) ), RecursiveCTE AS ( SELECT EMPLIFECYCLEID, BASICSALARY, GRADEID, DESIGNATIONID, EFFECTDATE, rn, BASICSALARY AS PrevBASICSALARY, GRADEID AS PrevGRADEID, DESIGNATIONID AS PrevDESIGNATIONID FROM CTE WHERE rn = 1 UNION ALL SELECT CTE.EMPLIFECYCLEID, CTE.BASICSALARY, CTE.GRADEID, CTE.DESIGNATIONID, CTE.EFFECTDATE, CTE.rn, CASE WHEN CTE.BASICSALARY IS NOT NULL THEN CTE.BASICSALARY ELSE RecursiveCTE.PrevBASICSALARY END AS PrevBASICSALARY, CASE WHEN CTE.GRADEID IS NOT NULL THEN CTE.GRADEID ELSE RecursiveCTE.PrevGRADEID END AS PrevGRADEID, CASE WHEN CTE.DESIGNATIONID IS NOT NULL THEN CTE.DESIGNATIONID ELSE RecursiveCTE.PrevDESIGNATIONID END AS PrevDESIGNATIONID FROM CTE INNER JOIN RecursiveCTE ON CTE.rn = RecursiveCTE.rn + 1 ) SELECT EMPLIFECYCLEID, --BASICSALARY AS ORG_BASICSALARY, PrevBASICSALARY AS BASICSALARY, --GRADEID AS ORG_GRADEID, --PrevGRADEID AS GRADEID, --DESIGNATIONID AS ORG_DESIGNATIONID, PrevDESIGNATIONID AS DESIGNATIONID, EFFECTDATE FROM RecursiveCTE ORDER BY EFFECTDATE DESC", empId); DataSet excquery = tc.ExecuteDataSet(sql); //int countDesId = 0; //int countBasicSal = 0; //int countGradeId = 0; //if (excquery.Tables.Count > 0 && excquery.Tables[0].Rows.Count > 0) //{ // // Iterate through each row in the DataTable // foreach (DataRow row in excquery.Tables[0].Rows) // { // if (row["DESIGNATIONID"] is DBNull || row["BASICSALARY"] is DBNull || row["BASICSALARY"] is DBNull) // { // if (row["DESIGNATIONID"] is DBNull) // { // countDesId++; // } // if (row["BASICSALARY"] is DBNull) // { // countBasicSal++; // } // if (row["GRADEID"] is DBNull) // { // countGradeId++; // } // } // else // { // int tempDesId = Convert.ToInt32(row["DESIGNATIONID"]); // int tempGradeId = Convert.ToInt32(row["GRADEID"]); // decimal tempSalary = Convert.ToDecimal(row["BASICSALARY"]); // foreach (DataRow nrow in excquery.Tables[0].Rows) // { // // Check the condition and update the DESIGNATIONID if required // if ((nrow["DESIGNATIONID"] is DBNull) && countDesId > 0) // { // // Set the new value for DESIGNATIONID // nrow["DESIGNATIONID"] = tempDesId; // countDesId--; // } // if ((nrow["BASICSALARY"] is DBNull) && countBasicSal > 0) // { // // Set the new value for DESIGNATIONID // nrow["BASICSALARY"] = tempSalary; // countBasicSal--; // } // if ((nrow["GRADEID"] is DBNull) && countGradeId > 0) // { // // Set the new value for DESIGNATIONID // nrow["GRADEID"] = tempGradeId; // countGradeId--; // } // if (countDesId == 0 && countBasicSal == 0 && countGradeId == 0) // { // break; // } // } // } // } //} // Iterate through each DataRow and update DESIGNATIONID with the last non-null DESIGNATIONID value DataTable dataTable = excquery.Tables[0]; int lastNonNullIndex = -1; for (int i = dataTable.Rows.Count - 1; i >= 0; i--) { if (!(dataTable.Rows[i]["DESIGNATIONID"] is DBNull)) { lastNonNullIndex = i; break; } } if (lastNonNullIndex >= 0) { string lastNonNullDesignationID = dataTable.Rows[lastNonNullIndex]["DESIGNATIONID"].ToString(); foreach (DataRow row in dataTable.Rows) { if (row["DESIGNATIONID"] is DBNull) { row["DESIGNATIONID"] = lastNonNullDesignationID; } } } return excquery; } #endregion #region Delete function internal static void Delete(TransactionContext tc, EmpLifeCycle oEmpLifeCycle) { tc.ExecuteNonQuery("DELETE FROM EmpLifeCycle Where EmpLifeCycleID=%n", oEmpLifeCycle.ID); } internal static object GetNodeId(TransactionContext tc, int EmployeeId) { object ovalue = tc.ExecuteScalar("select NodeID from EmpLifeCycle where EmpLifeCycleID=( " + " select Max(EmpLifeCycleId) from EmpLifeCycle where employeeid=%n and NodeID is Not Null)", EmployeeId); if (ovalue != DBNull.Value && ovalue != null) return Convert.ToInt32(ovalue); else return null; } public static void UpdateEmployee(TransactionContext tc, EmpLifeCycle oItem) { // Gross Salary object ovalue; if (oItem.GrossSalary != null && oItem.GrossSalary !=0) { ovalue = tc.ExecuteScalar("select GrossSalary from EmpLifeCycle where EmpLifeCycleID=( " + " select Max(EmpLifeCycleId) from EmpLifeCycle where employeeid=%n and GrossSalary is Not Null)", oItem.EmployeeID); if (ovalue != DBNull.Value) { if (ovalue != null && ovalue != null) tc.ExecuteNonQuery("UPDATE Employee SET GrossSalary= %n WHERE EMPLOYEEID=%n", Convert.ToDouble(ovalue), oItem.EmployeeID); } } if (oItem.BasicSalary != null && oItem.BasicSalary != 0) { //Basic Salary ovalue = tc.ExecuteScalar("select BasicSalary from EmpLifeCycle where EmpLifeCycleID=( " + " select Max(EmpLifeCycleId) from EmpLifeCycle where employeeid=%n and BasicSalary is Not Null)", oItem.EmployeeID); if (ovalue != DBNull.Value) { if (ovalue != null && ovalue != null) tc.ExecuteNonQuery("UPDATE Employee SET BasicSalary= %n WHERE EMPLOYEEID=%n", Convert.ToDouble(ovalue), oItem.EmployeeID); } } ////Category //tc.ExecuteNonQuery("Update Employee Set Employee.BasicSalary =(select BasicSalary from EmpLifeCycle where EmpLifeCycleID=( " // + " select Max(BasicSalary) from EmpLifeCycle where employeeid=%n and BasicSalary is Not Null))", oItem.EmployeeID); //GradeID if (oItem.GradeID !=null && oItem.GradeID != 0) tc.ExecuteNonQuery( "Update Employee Set Employee.GradeID =(select GradeID from EmpLifeCycle where EmpLifeCycleID=( " + " select Max(EmpLifeCycleId) from EmpLifeCycle where employeeid=%n and GradeID is Not Null)) WHERE Employee.EmployeeID=%n", oItem.EmployeeID, oItem.EmployeeID); //Company if (oItem.CompanyID !=null && oItem.CompanyID != 0) tc.ExecuteNonQuery( "Update Employee Set Employee.Companyid =(select Companyid from EmpLifeCycle where EmpLifeCycleID=( " + " select Max(EmpLifeCycleId) from EmpLifeCycle where employeeid=%n and Companyid is Not Null)) WHERE Employee.EmployeeID=%n", oItem.EmployeeID, oItem.EmployeeID); //Functionid if (oItem.FunctionID !=null && oItem.FunctionID != 0) tc.ExecuteNonQuery( "Update Employee Set Employee.Functionid =(select Functionid from EmpLifeCycle where EmpLifeCycleID=( " + " select Max(EmpLifeCycleId) from EmpLifeCycle where employeeid=%n and Functionid is Not Null)) WHERE Employee.EmployeeID=%n", oItem.EmployeeID, oItem.EmployeeID); //Designationid if (oItem.DesignationID !=null && oItem.DesignationID != 0) tc.ExecuteNonQuery( "Update Employee Set Employee.DesignationId =(select DesignationId from EmpLifeCycle where EmpLifeCycleID=( " + " select Max(EmpLifeCycleId) from EmpLifeCycle where employeeid=%n and DesignationId is Not Null)) WHERE Employee.EmployeeID=%n", oItem.EmployeeID, oItem.EmployeeID); //LocationID if (oItem.LocationID !=null && oItem.LocationID != 0) tc.ExecuteNonQuery( "Update Employee Set Employee.LocationID =(select LocationID from EmpLifeCycle where EmpLifeCycleID=( " + " select Max(EmpLifeCycleId) from EmpLifeCycle where employeeid=%n and LocationID is Not Null)) WHERE Employee.EmployeeID=%n", oItem.EmployeeID, oItem.EmployeeID); //Departmentid if (oItem.DepartmentID !=null && oItem.DepartmentID != 0) tc.ExecuteNonQuery( "Update Employee Set Employee.Departmentid =(select Departmentid from EmpLifeCycle where EmpLifeCycleID=( " + " select Max(EmpLifeCycleId) from EmpLifeCycle where employeeid=%n and Departmentid is Not Null)) WHERE Employee.EmployeeID=%n", oItem.EmployeeID, oItem.EmployeeID); //Category if (oItem.CategoryID != null && oItem.CategoryID != 0) { var catItem = tc.ExecuteScalar( @" select Max(EmpLifeCycleId) from EmpLifeCycle where employeeid=%n and CategoryID is Not Null " + " ", oItem.EmployeeID); if (catItem != DBNull.Value) // this is special checking for not null update in employee category table { tc.ExecuteNonQuery( "Update Employee Set Employee.CategoryID =(select CategoryID from EmpLifeCycle where EmpLifeCycleID=( " + " select Max(EmpLifeCycleId) from EmpLifeCycle where employeeid=%n and CategoryID is Not Null)) " + " WHERE Employee.EmployeeID=%n", oItem.EmployeeID, oItem.EmployeeID); } } //IsConfirmed if (oItem.IsConfirm != null) { ovalue = tc.ExecuteScalar("select IsConfirm from EmpLifeCycle where EmpLifeCycleID=( " + " select Max(EmpLifeCycleId) from EmpLifeCycle where employeeid=%n and IsConfirm is Not Null)", oItem.EmployeeID); if (ovalue != DBNull.Value && ovalue != null) { bool isconfirm = Convert.ToBoolean(ovalue); tc.ExecuteNonQuery("UPDATE Employee SET ISCONFIRMED= %b WHERE EMPLOYEEID=%n", isconfirm, oItem.EmployeeID); } else tc.ExecuteNonQuery( "UPDATE Employee SET ISCONFIRMED= %b, dateOfConfirmation=null WHERE EMPLOYEEID=%n", false, oItem.EmployeeID); } if (oItem.PFMemberType != null) { ovalue = tc.ExecuteScalar("select pFMemberType from EmpLifeCycle where EmpLifeCycleID=( " + " select Max(EmpLifeCycleId) from EmpLifeCycle where employeeid=%n and PFMemberType is Not Null)", oItem.EmployeeID); if (ovalue != DBNull.Value && ovalue != null) tc.ExecuteNonQuery("UPDATE Employee SET PFMemberType=1 WHERE EMPLOYEEID=%n", oItem.EmployeeID); } if (oItem.CostCenterID != null && oItem.CostCenterID != 0) { var empccid =tc.ExecuteScalar( "select EmployeeCCID from EmpLifeCycle where EmpLifeCycleID=( " + " select Max(EmpLifeCycleId) from EmpLifeCycle where employeeid=%n " + "and CostCenterID is Not Null)", oItem.EmployeeID); tc.ExecuteNonQuery(@"Update EMPCOSTCENTER Set CurrentCC =%n where ID=%n", true, Convert.ToInt32( empccid)); tc.ExecuteNonQuery( "Update Employee Set Employee.crgid =(select CostCenterID from EmpLifeCycle where EmpLifeCycleID=( " + " select Max(EmpLifeCycleId) from EmpLifeCycle where employeeid=%n and CostCenterID is Not Null)) WHERE Employee.EmployeeID=%n", oItem.EmployeeID, oItem.EmployeeID); } if (oItem.IsContinue != null || oItem.IsDiscontinue != null) { int nContinue = 0; int nDiscontinue = 0; ovalue = tc.ExecuteScalar( " select Max(EmpLifeCycleId) from EmpLifeCycle where employeeid=%n and IsContinue is Not Null", oItem.EmployeeID); if (ovalue != DBNull.Value && ovalue != null) nContinue = Convert.ToInt32(ovalue); ovalue = tc.ExecuteScalar( " select Max(EmpLifeCycleId) from EmpLifeCycle where employeeid=%n and IsDiscontinue is Not Null", oItem.EmployeeID); if (ovalue != DBNull.Value && ovalue != null) nDiscontinue = Convert.ToInt32(ovalue); if (nContinue > 0 || nDiscontinue > 0) { if (nContinue > nDiscontinue) { EmployeeDA.DoContinue(tc, oItem.EmployeeID); } else { ovalue = tc.ExecuteScalar(" select effectDate from EmpLifeCycle where EmpLifeCycleId=%n ", nDiscontinue); DateTime effectDate = Convert.ToDateTime(ovalue); HREmployeeDA.UpdateEndofContact(tc, oItem.EmployeeID, effectDate); ovalue = tc.ExecuteScalar( " select IsCurrentMonthIncluded from EmpLifeCycle where EmpLifeCycleId=%n ", nDiscontinue); bool iscurrMonth = false; if (ovalue != DBNull.Value) iscurrMonth = Convert.ToBoolean(ovalue); ovalue = tc.ExecuteScalar(" select Status from EmpLifeCycle where EmpLifeCycleId=%n ", nDiscontinue); int nStatus = Convert.ToInt32(ovalue); if (iscurrMonth == true) HREmployeeDA.UpdatemiddleOfMonthDiscontinue(tc, oItem.EmployeeID, (EnumEmployeeStatus)nStatus, effectDate); } } else { tc.ExecuteNonQuery("UPDATE Employee SET Status=%n, ENDOFCONTRACTDATE=null WHERE EMPLOYEEID=%n", EnumEmployeeStatus.Waitingforjoin, oItem.EmployeeID); } } } internal static object GetNodeAssignDate(TransactionContext tc, int EmployeeId) { object ovalue = tc.ExecuteScalar("select EffectDate from EmpLifeCycle where EmpLifeCycleID=( " + " select Max(EmpLifeCycleId) from EmpLifeCycle where employeeid=%n and NodeID is Not Null)", EmployeeId); if (ovalue != DBNull.Value) return Convert.ToDateTime(ovalue); else return null; } internal static object GetCrgId(TransactionContext tc, int EmployeeId) { object ovalue = tc.ExecuteScalar("select CostCenterID from EmpLifeCycle where EmpLifeCycleID=( " + " select Max(EmpLifeCycleId) from EmpLifeCycle where employeeid=%n and CostCenterID is Not Null)", EmployeeId); if (ovalue != DBNull.Value) if (ovalue == null) return null; else return Convert.ToInt32(ovalue); else return null; } internal static int GetPrvRCId(TransactionContext tc, int EmployeeId) { //object ovalue = tc.ExecuteScalar("select CostCenterID from EmpLifeCycle where EmpLifeCycleID=( " // + " select Max(EmpLifeCycleId) from EmpLifeCycle where employeeid=%n and CostCenterID is Not Null)", EmployeeId); //if (ovalue != DBNull.Value) // if (ovalue == null) return 0; // else return Convert.ToInt32(ovalue); //else return 0; string sql = SQLParser.MakeSQL(@"select CostCenterID from EmpLifeCycle where sequenceno =(select Max(sequenceno) from EmpLifeCycle where employeeid = %n ) - 1 AND employeeid = %n", EmployeeId, EmployeeId); object ovalue = tc.ExecuteScalar(sql); if (ovalue != DBNull.Value) { if (ovalue == null) return 0; else return Convert.ToInt32(ovalue); } else return 0; } internal static int GetPrvGradeId(TransactionContext tc, int EmployeeId, int gradeID) { //object ovalue = tc.ExecuteScalar("select GradeID from EmpLifeCycle where EmpLifeCycleID=( " // + " select Max(EmpLifeCycleId) from EmpLifeCycle where employeeid=%n and GradeID=%n)", EmployeeId,gradeID); //if (ovalue != DBNull.Value) // if (ovalue == null) return 0; // else return Convert.ToInt32(ovalue); //else return 0; string sql = SQLParser.MakeSQL(@"select GradeID from EmpLifeCycle where sequenceno =(select Max(sequenceno) from EmpLifeCycle where employeeid = %n ) - 1 AND employeeid = %n", EmployeeId, EmployeeId); object ovalue = tc.ExecuteScalar(sql); if (ovalue != DBNull.Value) { if (ovalue == null) return 0; else return Convert.ToInt32(ovalue); } else return 0; } internal static int GetPrvLocationId(TransactionContext tc, int EmployeeId, int locationID) { //object ovalue = tc.ExecuteScalar("select LocationID from EmpLifeCycle where EmpLifeCycleID=( " // + " select Max(EmpLifeCycleId) from EmpLifeCycle where employeeid=%n and LocationID=%n)", EmployeeId, locationID); //if (ovalue != DBNull.Value) // if (ovalue == null) return 0; // else return Convert.ToInt32(ovalue); //else return 0; string sql = SQLParser.MakeSQL(@"select LocationID from EmpLifeCycle where sequenceno =(select Max(sequenceno) from EmpLifeCycle where employeeid = %n ) - 1 AND employeeid = %n", EmployeeId, EmployeeId); object ovalue = tc.ExecuteScalar(sql); if (ovalue != DBNull.Value) { if (ovalue == null) return 0; else return Convert.ToInt32(ovalue); } else return 0; } internal static int GetPrvDesigId(TransactionContext tc, int EmployeeId, int designationID) { object ovalue = tc.ExecuteScalar("select LocationID from EmpLifeCycle where EmpLifeCycleID=( " + " select Max(EmpLifeCycleId) from EmpLifeCycle where employeeid=%n and LocationID=%n)", EmployeeId, designationID); if (ovalue != DBNull.Value) if (ovalue == null) return 0; else return Convert.ToInt32(ovalue); else return 0; } #endregion internal static IDataReader Get(TransactionContext tc, int p, DateTime startDate, DateTime endDate) { string sql = SQLParser.MakeSQL( "Select * from EmpLifeCycle where StatusDetailID =%n and EffectDate between %d and %d ", p, startDate, endDate); return tc.ExecuteReader(sql); } internal static IDataReader GetByDate(TransactionContext tc, DateTime startDate, DateTime endDate, int payrollTypeID) { string sql = SQLParser.MakeSQL( "Select * from EmpLifeCycle where Effectdate between %d and %d AND EmployeeID in(select EmployeeID from EMPLOYEE where PAYROLLTYPEID=%n) order by CreationDate DESC", startDate, endDate, payrollTypeID); return tc.ExecuteReader(sql); } internal static IDataReader GetByCreateDate(TransactionContext tc, DateTime startDate, DateTime endDate, int payrollTypeID) { string sql = SQLParser.MakeSQL( "Select * from EmpLifeCycle where CREATIONDATE between %d and %d AND EmployeeID in(select EmployeeID from EMPLOYEE where PAYROLLTYPEID=%n) order by EffectDate ", startDate, DateTime.Today, payrollTypeID); return tc.ExecuteReader(sql); } internal static int? EmpPrevDesg(TransactionContext tc, int employeeID) { string sql = SQLParser.MakeSQL(@"select DesignationID from EmpLifeCycle where sequenceno =(select Max(sequenceno) from EmpLifeCycle where employeeid = %n ) - 1 AND employeeid = %n", employeeID, employeeID); object ovalue = tc.ExecuteScalar(sql); if (ovalue != DBNull.Value) { if (ovalue == null) return null; else return Convert.ToInt32(ovalue); } else return null; } } #endregion }