EchoTex_Payroll/HRM.DA/DA/Basic/DepartmentDA.cs

133 lines
5.0 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using HRM.BO;
using Ease.Core.DataAccess;
using System.Data;
namespace HRM.DA
{
internal class DepartmentDA
{
private DepartmentDA()
{
}
#region Insert function
internal static void Insert(TransactionContext tc, Department item)
{
tc.ExecuteNonQuery(
"INSERT INTO Department(DepartmentID, code, description, parentID, parentsID, CreatedBy, CreationDate, SequenceNo, Status,TIRE, CostCenter,PayrollTypeID)" +
" VALUES(%n, %s, %s, %n, %s, %n, %d, %n, %n,%n, %s,%n)", item.ID, item.Code, item.Name, item.ParentID,
item.ParentsID, item.CreatedBy,
item.CreatedDate, item.Sequence, item.Status, item.Tier, item.CostCenter, item.PayrollTypeID);
}
#endregion
#region Update function
internal static void Update(TransactionContext tc, Department item)
{
string sql = string.Empty;
sql = SQLParser.MakeSQL(
@"UPDATE Department SET code=%s, description=%s, parentID=%n, parentsID=%s, ModifiedBy=%n, ModifiedDate=%d, SequenceNo=%n, Status=%n,TIRE=%n, CostCenter=%s
WHERE DepartmentID=%n", item.Code, item.Name, item.ParentID, item.ParentsID, item.ModifiedBy,
item.ModifiedDate, item.Sequence, item.Status, item.Tier, item.CostCenter, item.ID);
tc.ExecuteNonQuery(sql);
}
internal static void UpdateCode(TransactionContext tc, Department item, string sCode)
{
string sSQL = SQLParser.MakeSQL("UPDATE Department Set code = %s Where DepartmentID = %n", sCode, item.ID);
tc.ExecuteNonQuery(sSQL);
}
internal static void UpdateCostCenter(TransactionContext tc, Department item)
{
string sSQL = SQLParser.MakeSQL("UPDATE Department Set CostCenter = %s Where DepartmentID = %n",
item.CostCenter.Trim(), item.ID);
tc.ExecuteNonQuery(sSQL);
}
#endregion
#region GetFunction
internal static IDataReader GetParent(TransactionContext tc, EnumStatus status, int payrollTypeID)
{
if (EnumStatus.Active == status || EnumStatus.Inactive == status)
{
string sql =
SQLParser.MakeSQL(
"SELECT * FROM Department Where parentid is null and Status=%n Order By DESCRIPTION", status,
payrollTypeID);
return tc.ExecuteReader(sql);
}
else
{
return tc.ExecuteReader("SELECT * FROM Department Where parentid is null Order By DESCRIPTION",
payrollTypeID);
}
}
internal static IDataReader Get(TransactionContext tc, EnumStatus status, int payrollTypeID)
{
if (EnumStatus.Active == status || EnumStatus.Inactive == status)
{
return tc.ExecuteReader(
@"SELECT d.* FROM Department d where d.status=%n and d.PayrollTypeID=%n order by d.Description",
status, payrollTypeID);
}
else
{
return tc.ExecuteReader(
@"SELECT d.* FROM Department d Where d.PayrollTypeID=%n order by d.Description", payrollTypeID);
}
}
internal static IDataReader GetAllDepartment(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 Department %q order by Description", sqlClause);
}
internal static IDataReader Get(TransactionContext tc, int ID)
{
return tc.ExecuteReader("SELECT * FROM Department WHERE DepartmentID=%n", ID);
}
internal static IDataReader GetByDeptIds(TransactionContext tc, string deptIds)
{
return tc.ExecuteReader("SELECT * FROM Department where departmentId IN (%q)", deptIds);
}
internal static IDataReader GetAll(TransactionContext tc)
{
return tc.ExecuteReader("SELECT * FROM Department");
}
#endregion
internal static void Delete(TransactionContext tc, int ID)
{
tc.ExecuteNonQuery("DELETE FROM Department WHERE DepartmentID=%n", ID);
}
}
}