using System; using Payroll.BO; using System.Data; using System.Linq; using Ease.CoreV35.Model; using System.Data.SqlClient; using Ease.CoreV35.DataAccess; using System.Collections.Generic; using Ease.CoreV35.DataAccess.SQL; namespace Payroll.Service { #region EmployeePostingDA internal class EmployeePostingDA { #region Constructor private EmployeePostingDA() { } #endregion #region Insert function internal static void Insert(TransactionContext tc, EmployeePosting item) { string sSQL = SQLParser.MakeSQL("INSERT INTO EmployeePosting(HREmpPostingID, employeeID, postingDate, departmentID, locationID, designationID, CreatedBy, CreationDate)" + " VALUES(%n, %n, %d, %n, %n, %n, %n, %d)", item.ID.Integer, item.EmployeeID.Integer, item.EffectDate, item.DepartmentID.Integer, item.LocationID.Integer, item.DesignationID.Integer, DataReader.GetNullValue(item.CreatedBy.Integer), DataReader.GetNullValue(item.CreatedDate)); tc.ExecuteNonQuery(sSQL); } #endregion #region Update function internal static void Update(TransactionContext tc, EmployeePosting item) { string sSQL = SQLParser.MakeSQL("UPDATE EmployeePosting SET employeeID=%n, postingDate=%d, departmentID=%n, locationID=%n, designationID=%n, ModifiedBy=%n, ModifiedDate=%d" + " WHERE HREmpPostingID=%n", item.EmployeeID.Integer, item.EffectDate, item.DepartmentID.Integer, item.LocationID.Integer, item.DesignationID.Integer, DataReader.GetNullValue(item.ModifiedBy.Integer), DataReader.GetNullValue(item.ModifiedDate), item.ID.Integer); tc.ExecuteNonQuery(sSQL); } #endregion #region Get Function internal static IDataReader Get(TransactionContext tc) { return tc.ExecuteReader("SELECT * FROM EmployeePosting"); } internal static DataSet GetEmpCurrentPosting(TransactionContext tc, DateTime EffectDate, int payrollTypeID) { DataSet oEmpPosting = new DataSet(); try { oEmpPosting = tc.ExecuteDataSet("Select Emp.EmployeeID as ID,Emp.EMPLOYEENO,Emp.NAME,Deg.NAME AS CurrentDeg,Dept.description as CurrentDept," + " Loc.description as CurrentLoc," + " EmpPost.postingdate as EffectDate,US.LoginID as CommitedBy,EmpPost.CreationDate as CommitedOn" + " from EMPLOYEE as Emp,department as Dept,LOCATION AS Loc ,USERS as US,DESIGNATION as Deg,employeeposting as EmpPost" + " WHERE Emp.DESIGNATIONID=Deg.DESIGNATIONID" + " AND Emp.departmentid=Dept.departmentid" + " AND Emp.locationid=Loc.locationid" + " and Emp.EmployeeID=EmpPost.EmployeeID" + " AND US.USERID=EmpPost.CreatedBy" + " AND EmpPost.postingdate between %d and %d ANd Emp.PayrollTypeID=%n" + " order by Emp.EMPLOYEENO", GlobalFunctions.FirstDateOfMonth(EffectDate), GlobalFunctions.LastDateOfMonth(EffectDate), payrollTypeID); } catch (Exception ex) { throw new Exception(ex.Message); } return oEmpPosting; } internal static DataSet GetEmpPrvPosting(TransactionContext tc, DateTime EffectDate, int payrollTypeID) { DataSet oEmpPosting = new DataSet(); try { oEmpPosting = tc.ExecuteDataSet("Select Emp.EMPLOYEENO,Emp.NAME,Deg.NAME AS PreviousDeg,Dept.description as PreviousDept," + " Loc.description as PreviousLoc,EmpPost.postingdate as EffectDate,US.UserID as CommitedBy,EmpPost.CreationDate as CommitedOn" + " from EMPLOYEE as Emp,department as Dept,LOCATION AS Loc ,USERS as US,DESIGNATION as Deg,employeeposting as EmpPost" + " WHERE EmpPost.DESIGNATIONID=Deg.DESIGNATIONID" + " AND EmpPost.departmentid=Dept.departmentid" + " AND EmpPost.locationid=Loc.locationid" + " and Emp.EmployeeID=EmpPost.EmployeeID" + " AND US.USERID=EmpPost.CreatedBy" + " AND EmpPost.postingdate < %d ANd Emp.PayrollTypeID=%n" + " order by Emp.EMPLOYEENO", GlobalFunctions.FirstDateOfMonth(EffectDate) , payrollTypeID); } catch (Exception ex) { throw new Exception(ex.Message); } return oEmpPosting; } internal static IDataReader Get(TransactionContext tc, ID nID) { return tc.ExecuteReader("SELECT * FROM EmployeePosting WHERE HREmpPostingID=%n Order By POSTINGDATE", nID.Integer); } internal static IDataReader Get(TransactionContext tc, ID nEmpID, DateTime dEffectDate, int payrollTypeID) { return tc.ExecuteReader(@"Select * from employeeposting where postingdate=(Select MAX(postingdate) from employeeposting where EMPLOYEEID=%n and postingdate<%d) AND EMPLOYEEID=(Select EMPLOYEEID from Employee where EMPLOYEEID=%n and PAYROLLTYPEID=%n) ", nEmpID.Integer, dEffectDate, nEmpID.Integer, payrollTypeID); } internal static IDataReader GetEmpid(TransactionContext tc, ID nID) { return tc.ExecuteReader("SELECT * FROM EmployeePosting WHERE employeeID=%n Order By POSTINGDATE", nID.Integer); } #endregion #region Delete function internal static void Delete(TransactionContext tc, ID nID) { tc.ExecuteNonQuery("DELETE FROM EmployeePosting WHERE HREmpPostingID=%n", nID.Integer); } internal static void DeleteByPostingDate(TransactionContext tc, DateTime postingDate,ID empID) { string sSQL = SQLParser.MakeSQL("Delete from EmployeePosting Where postingdate >= %d and EMPLOYEEID=%n", postingDate, empID.Integer); tc.ExecuteNonQuery(sSQL); } internal static void DeleteAll(TransactionContext tc) { tc.ExecuteNonQuery("DELETE FROM [EmployeePosting]"); } #endregion } #endregion }