using System; using System.Data; using Ease.Core.DataAccess; using HRM.BO; namespace HRM.DA { internal class ADParameterDA { #region Constructor private ADParameterDA() { } #endregion #region Insert function internal static void Insert(TransactionContext tc, ADParameter item) { // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 tc.ExecuteNonQuery( "INSERT INTO ADPARAMETERBASIC(ADParameterID, allowDeductID, isForConfirmOnly, flatAmount, percentOfBasic, percentOfGross, GFFlatAmount, GFPercentOfBasic, GFPercentOfGross, minAmount, maxAmount, isCurrentlyActive, TAXABLEPERCENTAGE, ISTAXABLE, ISTaxProjection, IsDependsOnAttendance, IsDependsOnOTHour,ISDEPENDSONSPECIALHOUR, IsWithException, Periodicity, ALLOWORDEDUCT, GENDER, CreatedBy, CreationDate, PAYROLLTYPEID, LASTACTIVATIONDATE,ENTITLETYPE,PercentOfEarnedBasic,IsFractionateApplicable,userid, TaxProjection)" + " VALUES(%n, %n, %b, %n, %n, %n, %n, %n, %n, %n, %n, %b, %n, %b, %b, %b, %b, %n, %b, %n, %n, %n, %n, %d, %n, %D, %n, %n, %n,%n,%n)", item.ID, item.AllowDeductID, item.IsForConfirmOnly, item.FlatAmount, item.PercentOfBasic, item.PercentOfGross, item.GFFlatAmount, item.GFPercentOfBasic, item.GFPercentOfGross, item.MinAmount, item.MaxAmount, item.IsCurrentlyActive, item.TaxablePercentage, item.IsTaxable, item.IsTaxProjection, item.IsDependsOnAttendance, item.IsDependsOnOTHour, item.ISDEPENDSONSPECIALHOUR, item.IsWithException, item.Periodicity, item.AllowOrDeductType, item.Gender, item.CreatedBy, item.CreatedDate, item.PayrollTypeID, DateTime.Now, item.EntitleType, item.PercentOfEarnedBasic, item.IsFractionateApplicable, 1, 0); } internal static void Insert(TransactionContext tc, ADParameter.ADParameterGrade item) { tc.ExecuteNonQuery("INSERT INTO ADPARAMETERGRADE(ADPARAMETERID, GRADEID)" + " VALUES(%n, %n)", item.ADParameterID, item.GradeID); } internal static void Insert(TransactionContext tc, ADParameter.ADParameterDesignation item) { tc.ExecuteNonQuery( @"INSERT INTO ADPARAMETERDESIGNATION(ADPARAMETERDESIGNATINID, ADPARAMETERID, DESIGNATIONID, FLATAMOUNT, PERCENTOFBASIC, PERCENTOFGROSS, CREATEDBY, CREATEDDATE,EffectMonth, ArrearToCalculationMonth) VALUES(%n, %n, %n, %n, %n, %n, %n, %d, %d, %d)", item.ID, item.ADParameterID, item.DesignationID, item.FlatAmount, item.PercentOfBasic, item.PercentOfGross, item.CreatedBy, item.CreatedDate, item.EffectMonth, item.ArrearToCalculationMonth); } #endregion #region Update function internal static void Update(TransactionContext tc, ADParameter item) { tc.ExecuteNonQuery( "UPDATE ADPARAMETERBASIC SET allowDeductID=%n, IsForConfirmOnly=%b, FlatAmount=%n, PercentOfBasic=%n, PercentOfGross=%n, GFFlatAmount=%n, GFPercentOfBasic=%n, GFPercentOfGross=%n, MinAmount=%n, MaxAmount=%n, IsCurrentlyActive=%b, TaxablePercentage=%n, IsTaxable=%b, IsTaxProjection=%b, IsDependsOnAttendance=%b, IsDependsOnOTHour=%b, IsWithException=%b, Periodicity=%n, ALLOWORDEDUCT=%n, Gender=%n, ModifiedBy=%n, ModifiedDate=%d, ENTITLETYPE=%n, PercentOfEarnedBasic=%n, IsFractionateApplicable=%n" + " WHERE ADParameterID=%n", item.AllowDeductID, item.IsForConfirmOnly, item.FlatAmount, item.PercentOfBasic, item.PercentOfGross, item.GFFlatAmount, item.GFPercentOfBasic, item.GFPercentOfGross, item.MinAmount, item.MaxAmount, item.IsCurrentlyActive, item.TaxablePercentage, item.IsTaxable, item.IsTaxProjection, item.IsDependsOnAttendance, item.IsDependsOnOTHour, item.IsWithException, item.Periodicity, item.AllowOrDeductType, item.Gender, item.ModifiedBy, item.ModifiedDate, item.EntitleType, item.PercentOfEarnedBasic, item.IsFractionateApplicable, item.ID); } #endregion #region Get Function internal static IDataReader GetWithPayrollType(TransactionContext tc, EnumStatus status, int payrollTypeID) { if (status == EnumStatus.Regardless) return tc.ExecuteReader("SELECT * FROM ADPARAMETERBASIC Where PAYROLLTYPEID = %n", payrollTypeID); else return tc.ExecuteReader( "SELECT ADPARAMETERBASIC.* FROM ADPARAMETERBASIC, AllowanceDeduction Where AllowanceDeduction.ALLOWDEDUCTID=ADPARAMETERBASIC.AllowDeductID AND ADPARAMETERBASIC.Status=%n AND AllowanceDeduction.PAYROLLTYPEID = %n ORDER BY AllowanceDeduction.SequenceNo", status, payrollTypeID); } internal static IDataReader GetUsedGrades(TransactionContext tc, int allowdeductid) { return tc.ExecuteReader(@"select *from ADPARAMETERGRADE where adparameterid in ( select adparameterid from ADPARAMETERBASIC where allowdeductID = %n)", allowdeductid); } internal static IDataReader GetGrades(TransactionContext tc, int nID) { return tc.ExecuteReader("Select * from ADPARAMETERGRADE Where ADParameterID = %n", nID); } internal static IDataReader GetAllGrades(TransactionContext tc) { return tc.ExecuteReader("Select * from ADPARAMETERGRADE "); } internal static IDataReader Get(TransactionContext tc, int? gradeID, EnumEntitleType nADEmpType, EnumAllowOrDeduct nType, int payrolltypeid) { string sql = SQLParser.MakeSQL(@"SELECT * FROM ADParameterBasic P WHERE P.EntitleType = %n AND AllowOrDeduct = %n AND PAYROLLTYPEID = %n AND P.ADParameterID IN(SELECT DISTINCT ADParameterID FROM ADParameterGrade PD WHERE PD.GradeI.D = %n)", nADEmpType, nType, payrolltypeid, gradeID); return tc.ExecuteReader("SELECT * FROM ADParameterBasic P WHERE P.EntitleType = %n AND AllowOrDeduct = %n AND PAYROLLTYPEID = %n AND P.ADParameterID IN(SELECT DISTINCT ADParameterID FROM ADParameterGrade PD " + " WHERE PD.GradeID = %n)", nADEmpType, nType, payrolltypeid, gradeID); } internal static IDataReader Get(TransactionContext tc, int nID, int payrollTypeID) { return tc.ExecuteReader("SELECT * FROM ADPARAMETERBASIC WHERE ADParameterID=%n AND PAYROLLTYPEID = %n", nID, payrollTypeID); } internal static IDataReader GetDesignations(TransactionContext tc, int nID) { return tc.ExecuteReader("SELECT * FROM ADPARAMETERDESIGNATION WHERE ADParameterID = %n", nID); } internal static IDataReader Get(TransactionContext tc, int gradeID, EnumEntitleType nADEmpType, EnumAllowOrDeduct nType, int payrollTypeID) { // string sql = SQLParser.MakeSQL(@"SELECT * FROM ADPARAMETERBASIC P WHERE P.EntitleType = %n AND AllowOrDeduct = %n AND PAYROLLTYPEID = %n AND P.ADParameterID IN(SELECT DISTINCT ADParameterID FROM ADParameterGrade PD // WHERE PD.GradeI.D = %n)", nADEmpType, nType, SystemInformation.CurrentSysInfo.PayrollTypeID, gradeID); string sql = ""; if (nADEmpType != EnumEntitleType.Regardless) { sql = SQLParser.MakeSQL(@" AND P.EntitleType=%n", nADEmpType); } return tc.ExecuteReader( "SELECT * FROM ADPARAMETERBASIC P WHERE AllowOrDeduct = %n %q AND PAYROLLTYPEID = %n AND P.ADParameterID IN(SELECT DISTINCT ADParameterID FROM ADParameterGrade PD " + " WHERE PD.GradeID = %n)", nType, sql, payrollTypeID, gradeID); } internal static IDataReader Get(TransactionContext tc, EnumStatus status, EnumAllowOrDeduct nType, int payrollTypeId) { if (status == EnumStatus.Regardless) return tc.ExecuteReader( "SELECT * FROM ADPARAMETERBASIC WHERE AllowORDeduct = %n AND PAYROLLTYPEID = %n", nType, payrollTypeId); else return tc.ExecuteReader( "SELECT * FROM ADPARAMETERBASIC WHERE Status=%n AND AllowORDeduct = %n AND PAYROLLTYPEID = %n", status, nType, payrollTypeId); } internal static IDataReader GetDistinct(TransactionContext tc, EnumStatus status, EnumAllowOrDeduct nType, int payrollTypeID) { if (status == EnumStatus.Regardless) return tc.ExecuteReader( "SELECT * FROM ADPARAMETERBASIC Where allowdeductid in (Select distinct allowdeductid from ADPARAMETERBASIC WHERE AllowORDeduct = %n AND PAYROLLTYPEID = %n)", nType, payrollTypeID); else return tc.ExecuteReader( "SELECT * FROM ADPARAMETERBASIC Where allowdeductid in (Select distinct allowdeductid from ADPARAMETERBASIC WHERE Status=%n AND AllowORDeduct = %n AND PAYROLLTYPEID = %n)", status, nType, payrollTypeID); } internal static IDataReader GetShifts(TransactionContext tc, int nID) { return tc.ExecuteReader("Select * from ADPARAMETERSHIFT Where ADParameterID = %n", nID); } internal static IDataReader GetAllShifts(TransactionContext tc) { return tc.ExecuteReader("Select * from ADPARAMETERSHIFT"); } internal static IDataReader Get(TransactionContext tc, EnumStatus status, int nAllowdeducID) { if (EnumStatus.Active == status || EnumStatus.Inactive == status) { return tc.ExecuteReader("SELECT * FROM ADPARAMETERBASIC WHERE Status=%n AND AllowDeductID=%n", status, nAllowdeducID); } else { return tc.ExecuteReader("SELECT * FROM ADPARAMETERBASIC WHERE AllowDeductID=%n", nAllowdeducID); } } #endregion #region Delete function internal static void Delete(TransactionContext tc, int nID) { tc.ExecuteNonQuery("DELETE FROM ADPARAMETERGRADE WHERE ADPARAMETERID=%n", nID); tc.ExecuteNonQuery("DELETE FROM ADPARAMETEREMPLOYEE WHERE ADPARAMETERID=%n", nID); tc.ExecuteNonQuery("DELETE FROM ADPARAMETERBASIC WHERE ADPARAMETERID=%n", nID); } internal static void DeleteGrade(TransactionContext tc, int nID) { tc.ExecuteNonQuery("DELETE FROM ADPARAMETERGRADE WHERE ADParameterID=%n", nID); } internal static void DeletebyAdParamidinDesignation(TransactionContext tc, int nID) { tc.ExecuteNonQuery("DELETE FROM ADPARAMETERDESIGNATION WHERE ADParameterID=%n", nID); } #endregion internal static void ChangeStatus(TransactionContext tc, int id, EnumStatus enumStatus) { string sql = string.Empty; bool IsCurrentlyActive = (enumStatus == EnumStatus.Active) ? true : false; sql = SQLParser.MakeSQL(@"UPDATE ADPARAMETERBASIC SET IsCurrentlyActive=%b, STATUS=%n Where ADParameterID=%n", IsCurrentlyActive, (int)enumStatus, id); tc.ExecuteNonQuery(sql); } } }