using Ease.Core.DataAccess; using HRM.BO; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; namespace HRM.DA { internal class UploadedComponentDA { #region Insert function internal static void Insert(TransactionContext tc, UploadedComponent item) { tc.ExecuteNonQuery("INSERT INTO UploadedComponent(UploadedComponentID, SalaryMonth, ComponentID, ComponentType, UploadedBy, UploadedDate, IsDamageManagement)" + " VALUES(%n, %d, %n, %n, %n, %D, %b)", item.ID, item.SalaryMonth, item.ComponentID, (int)(EnumComponentType)item.ComponentType, item.UploadedBy, item.UploadedDate, DataReader.GetNullValue(item.IsDamageManagement)); } internal static void InsertUploadedComponentEmp(TransactionContext tc, UploadedComponentEmp item) { tc.ExecuteNonQuery("INSERT INTO UploadedComponentEmp(UploadedComponentEmpID, UploadedComponentID, EmployeeID, Amount, CreatedDate, Reason, TotalAmount, DeductionMonth, DeductionAmount, Remarks)" + " VALUES(%n, %n, %n, %n, %d, %s, %n, %d, %n, %s)", item.ID, item.UploadedComponentID, item.EmployeeID, item.Amount, item.CreatedDate, DataReader.GetNullValue(item.Reason), DataReader.GetNullValue(item.TotalAmount), DataReader.GetNullValue(item.DeductionMonth), DataReader.GetNullValue(item.DeductionAmount), DataReader.GetNullValue(item.Remarks)); } #endregion #region Get Function public static IDataReader Get(TransactionContext tc, DateTime fromDate, DateTime toDate) { return tc.ExecuteReader("SELECT * FROM UploadedComponent Where UploadedDate Between %d And %d ORDER BY UploadedDate Desc", fromDate, toDate); } internal static DataSet GetByID(TransactionContext tc, int uploadedComponentID) { string sql = SQLParser.MakeSQL(@"Select UC.*, UCE.EmployeeID, UCE.Amount from UploadedComponent As UC Join UploadedComponentEmp As UCE On UCE.UploadedComponentID = UC.UploadedComponentID Where UC.UploadedComponentID = %n Order By UC.UploadedDate", uploadedComponentID); return tc.ExecuteDataSet(sql); } internal static DataSet GetByID_DT(TransactionContext tc, int uploadedComponentID) { string sql = SQLParser.MakeSQL(@" SELECT E.EmployeeNo, E.Name, UCE.Amount FROM UploadedComponent As UC JOIN UploadedComponentEmp As UCE ON UCE.UploadedComponentID = UC.UploadedComponentID JOIN Employee As E ON E.EmployeeID = UCE.EmployeeID WHERE UC.UploadedComponentID = %n ORDER BY UC.UploadedDate", uploadedComponentID); return tc.ExecuteDataSet(sql); } internal static DataSet GetByIDandUploaderID_DT(TransactionContext tc, int uploadedComponentID, int uploaderID) { string sql = SQLParser.MakeSQL(@" SELECT E.EmployeeNo, E.Name, UCE.Amount FROM UploadedComponent As UC JOIN UploadedComponentEmp As UCE ON UCE.UploadedComponentID = UC.UploadedComponentID JOIN Employee As E ON E.EmployeeID = UCE.EmployeeID WHERE UC.UploadedComponentID = %n AND UC.UploadedBy = %n ORDER BY UC.UploadedDate", uploadedComponentID, uploaderID); return tc.ExecuteDataSet(sql); } internal static IDataReader GetUploadedComponentEmp(TransactionContext tc, int componentID) { return tc.ExecuteReader("SELECT * FROM UploadedComponentEmp WHERE UploadedComponentID=%n", componentID); } internal static IDataReader Get(TransactionContext tc, int componentID, int uploaderID, DateTime salaryMonth) { return tc.ExecuteReader("SELECT * FROM UploadedComponent WHERE UploadedBy=%n AND SalaryMonth = %d AND ComponentId=%n", uploaderID, GlobalExtensions.LastDateOfMonth(salaryMonth), componentID); } internal static IDataReader Get(TransactionContext tc, int uploaderID, DateTime salaryMonth) { return tc.ExecuteReader("SELECT * FROM UploadedComponent WHERE UploadedBy=%n AND SalaryMonth = %d", uploaderID, GlobalExtensions.LastDateOfMonth(salaryMonth)); } internal static IDataReader GetByApprover(TransactionContext tc, int approverID, DateTime salaryMonth) { return tc.ExecuteReader("SELECT UCE.* FROM UploadedComponent UCE WHERE EXISTS " + "(SELECT 1 FROM ComponentUploadSetup CUS WHERE CUS.EMPLOYEEID = UCE.UploadedBy AND CUS.ApproverID =%n AND UCE.SalaryMonth =%d);", approverID, GlobalExtensions.LastDateOfMonth(salaryMonth)); } internal static IDataReader GetByApprover(TransactionContext tc, int approverID) { return tc.ExecuteReader("SELECT UCE.* FROM UploadedComponent UCE WHERE EXISTS " + "(SELECT 1 FROM ComponentUploadSetup CUS WHERE CUS.EMPLOYEEID = UCE.UploadedBy AND CUS.ApproverID =%n);", approverID); } internal static DataSet GetByUploaderDT(TransactionContext tc, int empID) { string sql = SQLParser.MakeSQL(@" Select uc.*, e.EmployeeNo, e.Name, comp.DESCRIPTION from UploadedComponent uc inner join COMPONENTUPLOADSETUP comp ON comp.ITEMID = uc.ComponentID AND comp.COMPONENTTYPE = uc.ComponentType AND comp.EMPLOYEEID = uc.UploadedBy left join Employee e on comp.APPROVERID = e.EMPLOYEEID where uc.UploadedBy = %n order by uc.SalaryMonth desc ", empID); return tc.ExecuteDataSet(sql); } #endregion #region Update Function internal static void Update(TransactionContext tc, UploadedComponent item) { tc.ExecuteNonQuery("UPDATE UploadedComponent SET SalaryMonth=%d, ComponentID=%n, ComponentType=%n, ApprovedBy=%n, ApprovedDate=%d" + " WHERE UploadedComponentID=%n", item.SalaryMonth, item.ComponentID, (int)(EnumComponentType)item.ComponentType, item.ApprovedBy, item.ApprovedDate, item.ID); } #endregion #region Delete function internal static void Delete(TransactionContext tc, int uploadedComponentID) { tc.ExecuteNonQuery("DELETE FROM UploadedComponent WHERE UploadedComponentID=%n", uploadedComponentID); } internal static void DeleteUploadedComponentEmp(TransactionContext tc, int nID) { tc.ExecuteNonQuery("DELETE FROM UploadedComponentEmp WHERE UploadedComponentID=%n", nID); } #endregion #region IsExist public static IDataReader GetExistingComponent(TransactionContext tc, int uploaderID, int componentID, EnumComponentType componentType, DateTime salaryMonth) { return tc.ExecuteReader("SELECT * FROM UploadedComponent WHERE UploadedBy=%n AND ComponentID=%n AND ComponentType=%n AND SalaryMonth=%d", uploaderID, componentID, (int)componentType, GlobalExtensions.LastDateOfMonth(salaryMonth)); } #endregion #region ADParameter of the grade /// The allowance/deduction parameter that covers the grade (GP's ADParameterDA.GetADParamByGradeAndAD). internal static IDataReader GetADParamByGradeAndAD(TransactionContext tc, int gradeID, int allowDedID) { return tc.ExecuteReader(@"SELECT A.* FROM ADPARAMETERBASIC A, ADPARAMETERGRADE AG WHERE A.ADPARAMETERID=AG.ADPARAMETERID AND AG.GRADEID=%n AND A.ALLOWDEDUCTID=%n", gradeID, allowDedID); } #endregion } }