using HRM.BO; using Ease.Core.DataAccess; using System.Data; using System; namespace HRM.DA { #region DesignationDA internal class DesignationDA { #region Constructor private DesignationDA() { } #endregion #region Insert function internal static void Insert(TransactionContext tc, Designation item, int payrollTypeID) { tc.ExecuteNonQuery( "INSERT INTO Designation(DesignationID,Code, Name,GradeID, PayrollTypeID, CreatedBy, CreationDate, SequenceNo, Status, NameInBangla)" + " VALUES(%n, %s, %s,%n,%n, %n, %d, %n, %n, %u)", item.ID, item.Code, item.Name, DataReader.GetNullValue(item.GradeID, 0), DataReader.GetNullValue(payrollTypeID, 0), item.CreatedBy, item.CreatedDate, item.Sequence, item.Status, item.NameInBangla); } #endregion #region Update function internal static void Update(TransactionContext tc, Designation item, int payrollTypeID) { tc.ExecuteNonQuery( "UPDATE Designation SET Code=%s, Name=%s,GradeID=%n, PayrollTypeID=%n, ModifiedBy=%n, ModifiedDate=%d, SequenceNo=%n, Status=%n, NameInBangla=%u" + " WHERE DesignationID=%n", item.Code, item.Name, DataReader.GetNullValue(item.GradeID, 0), DataReader.GetNullValue(payrollTypeID, 0), item.ModifiedBy, item.ModifiedDate, item.Sequence, item.Status, item.NameInBangla, item.ID); } #endregion #region Get Function internal static IDataReader Get(TransactionContext tc, EnumStatus status, int payrollTypeID) { if (EnumStatus.Active == status || EnumStatus.Inactive == status) { return tc.ExecuteReader( @"SELECT d.* FROM DESIGNATION d where d.status=%n and d.PayrollTypeID=%n order by d.Name", status, payrollTypeID); } else { return tc.ExecuteReader(@"SELECT d.* FROM DESIGNATION d Where d.PayrollTypeID=%n order by d.Name", payrollTypeID); } } internal static IDataReader GetRelateWithEmpolyee(TransactionContext tc, EnumStatus status, int payrollTypeID) { if (EnumStatus.Active == status || EnumStatus.Inactive == status) { return tc.ExecuteReader(@"SELECT* FROM ( SELECT DISTINCT d.* FROM DESIGNATION d,EMPLOYEE e where d.DESIGNATIONID =e.DESIGNATIONID AND e.PAYROLLTYPEID=%n and d.Status=%n UNION SELECT d.* FROM DESIGNATION d where d.DESIGNATIONID NOT IN (SELECT distinct ISNULL(e.DESIGNATIONID,0) FROM EMPLOYEE e) and d.status=%n) order by Name", payrollTypeID, status, status); } else { return tc.ExecuteReader(@"SELECT * FROM ( SELECT DISTINCT d.* FROM DESIGNATION d,EMPLOYEE e where d.DESIGNATIONID =e.DESIGNATIONID AND e.PAYROLLTYPEID=1 UNION SELECT d.* FROM DESIGNATION d where d.DESIGNATIONID NOT IN (SELECT distinct ISNULL(e.DESIGNATIONID,0) FROM EMPLOYEE e) ) order by Name", payrollTypeID, status); } } internal static IDataReader Get(TransactionContext tc, EnumStatus status, string sIDs, string sTargetPropertyName, int payrollTypeID) { string sCondition = ""; if (sTargetPropertyName != null && sTargetPropertyName != "") sCondition = " AND e." + sTargetPropertyName + " IN(" + sIDs + ") "; if (EnumStatus.Active == status || EnumStatus.Inactive == status) { return tc.ExecuteReader(@" SELECT DISTINCT d.* FROM DESIGNATION d,EMPLOYEE e where d.DESIGNATIONID =e.DESIGNATIONID AND e.PAYROLLTYPEID=%n and d.Status=%n %q order by d.Name", payrollTypeID, status, sCondition); } else { return tc.ExecuteReader(@" SELECT DISTINCT d.* FROM DESIGNATION d,EMPLOYEE e where d.DESIGNATIONID =e.DESIGNATIONID AND e.PAYROLLTYPEID=%n %q order by d.Name", payrollTypeID, sCondition); } } internal static IDataReader Get(TransactionContext tc, int ID) { return tc.ExecuteReader("SELECT * FROM Designation WHERE DesignationID=%n", ID); } internal static IDataReader GetAll(TransactionContext tc) { return tc.ExecuteReader("SELECT * FROM Designation "); } internal static IDataReader GetAll(TransactionContext tc, int payrollTypeID) { return tc.ExecuteReader("SELECT * FROM Designation WHERE PAYROLLTYPEID = %n", payrollTypeID); } internal static IDataReader Get(TransactionContext tc, string sCode, int payrollTypeID) { return tc.ExecuteReader("SELECT * FROM Designation WHERE Code=%s AND PayrollTypeID=%n", sCode, payrollTypeID); } #endregion #region Delete function internal static void Delete(TransactionContext tc, int ID) { tc.ExecuteNonQuery("DELETE FROM Designation WHERE DesignationID=%n", ID); } internal static IDataReader GetByDesignationIDs(TransactionContext tc, string designationIds) { return tc.ExecuteReader("SELECT * FROM Designation WHERE DesignationID IN (%q)", designationIds); } internal static IDataReader GetAllDesignation(TransactionContext tc, int payrollTypeID, EnumStatus status, string code, string name) { string sqlClause = string.Empty; sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("PayrollTypeID = %n", payrollTypeID); if (EnumStatus.Active == status || EnumStatus.Inactive == status) { sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("status = %n", status); } if (!string.IsNullOrWhiteSpace(code)) { sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("Code = %s", code); } if (!string.IsNullOrWhiteSpace(name)) { sqlClause = SQLParser.TagSQL(sqlClause) + SQLParser.MakeSQL("Name LIKE %s", ("%" + name + "%")); } return tc.ExecuteReader("SELECT * FROM Designation %q order by name", sqlClause, payrollTypeID); } #endregion } #endregion }