EchoTex_Payroll/HRM.DA/DA/Organogram/OrganogramEmployeeDA.cs

171 lines
7.0 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Data;
using Ease.Core.DataAccess;
using HRM.BO;
namespace HRM.DA
{
internal class OrganogramEmployeeDA
{
#region Constructor
private OrganogramEmployeeDA()
{
}
#endregion
#region Insert function
internal static void Insert(TransactionContext tc, OrganogramEmployee item)
{
tc.ExecuteNonQuery(
"INSERT INTO OrganEmployee(OrganEmpID,NodeID,EmployeeID,AssignDate,CreatedBy,CreationDate)" +
" VALUES(%n,%n,%n,%d,%n,%d)",
item.ID, item.NodeID, item.EmployeeID, item.AssignDate, item.CreatedBy, item.CreatedDate);
}
internal static void InsertForLifeCycle(TransactionContext tc, OrganogramEmployee item, int nID)
{
tc.ExecuteNonQuery(
"INSERT INTO OrganEmployee(OrganEmpID,NodeID,EmployeeID,AssignDate,CreatedBy,CreationDate)" +
" VALUES(%n,%n,%n,%d,%n,%d)",
nID, item.NodeID, item.EmployeeID, item.AssignDate, item.CreatedBy, item.CreatedDate);
}
#endregion
#region Update function
internal static void Update(TransactionContext tc, OrganogramEmployee item)
{
tc.ExecuteNonQuery(
"UPDATE OrganEmployee SET NodeID=%n, EmployeeID=%n,AssignDate=%d,ModifiedBy=%n,ModifiedDate=%d" +
"WHERE OrganEmpID=%n", item.NodeID, item.EmployeeID, item.AssignDate, item.ModifiedBy,
item.ModifiedDate, item.ID);
}
#endregion
#region Delete function
internal static void Delete(TransactionContext tc, int nID)
{
tc.ExecuteNonQuery("DELETE FROM OrganEmployee Where OrganEmpID=%n", nID);
}
internal static void Delete(TransactionContext tc)
{
tc.ExecuteNonQuery("DELETE FROM OrganEmployee");
}
internal static IDataReader GetOrganogramInfo(TransactionContext tc)
{
return tc.ExecuteReader(
@"select OrganogramID nodeid,ParentID,POSITIONNAME,emp.employeeno,emp.name,emp.employeeid,Tier from organogram org
left outer join organemployee oe on org.OrganogramID=oe.nodeid
left outer join employee emp on oe.employeeid=emp.employeeid order by ParentID");
}
internal static void DeleteByEmp(TransactionContext tc, int employeeid)
{
tc.ExecuteNonQuery("DELETE FROM OrganEmployee Where EmployeeID=%n", employeeid);
}
internal static void DeleteByNode(TransactionContext tc, int nodeid)
{
tc.ExecuteNonQuery("DELETE FROM OrganEmployee Where NodeID=%n", nodeid);
}
#endregion
#region Get Function
internal static IDataReader Get(TransactionContext tc)
{
return tc.ExecuteReader("SELECT * FROM OrganEmployee Order By NodeID");
}
internal static IDataReader Get(TransactionContext tc, int nodeID)
{
return tc.ExecuteReader("SELECT * FROM OrganEmployee Where NodeID=%n", nodeID);
}
internal static IDataReader GetByTier(TransactionContext tc, int tierFrom, int tierTo)
{
string sql =
SQLParser.MakeSQL(
@"SELECT * FROM ORGANEMPLOYEE oe,ORGANOGRAM o WHERE o.ORGANOGRAMID=oe.NODEID AND o.TIER>=%n AND o.TIER<=%n",
tierFrom, tierTo);
return tc.ExecuteReader(sql);
}
internal static IDataReader GetByGrades(TransactionContext tc, string gradeIds)
{
string sql =
SQLParser.MakeSQL(
@"SELECT * FROM ORGANEMPLOYEE oe,ORGANOGRAM o WHERE o.ORGANOGRAMID=oe.NODEID AND o.GRADEID IN(%q)",
gradeIds);
return tc.ExecuteReader(sql);
}
internal static IDataReader GetByEmp(TransactionContext tc, int empID)
{
return tc.ExecuteReader("SELECT * FROM OrganEmployee Where EmployeeID=%n", empID);
}
internal static IDataReader GetByPositionType(TransactionContext tc, EnumOGPositionType enPositionType)
{
string sql = SQLParser.MakeSQL(@"SELECT * FROM OrganEmployee WHERE NodeID in
(SELECT NodeID
FROM OrganPosition
WHERE PositionTypeID In (SELECT OGPositionTypeID
FROM OGPositionType
WHERE OGPositionType = %n))",
(int)enPositionType);
return tc.ExecuteReader(sql);
}
public static void UpdateParentAndTier(TransactionContext tc, OrganogramBasicTemp oItem)
{
tc.ExecuteNonQuery("UPDATE Organogram SET Tier=%n, ParentID=%n"
+ " WHERE OrganogramID=%n", oItem.Tier,
DataReader.GetNullValue(oItem.ParentID, 0), oItem.OrganogramID);
}
public static void UpdateEmployee(TransactionContext tc, OrganogramBasicTemp oItem)
{
tc.ExecuteNonQuery("UPDATE OrganEmployee SET NodeID=%n"
+ " WHERE EmployeeID=%n", DataReader.GetNullValue(oItem.OrganogramID, 0),
oItem.EmployeeID);
}
public static IDataReader getTopHiararchy(TransactionContext tc, int employeeid)
{
return tc.ExecuteReader(@"WITH
cteReports (Organogramid, PositionName ,PARENTID, TIER )
AS
(
SELECT Organogramid, PositionName,PARENTID, organogram.TIER
FROM organogram ,organEmployee
WHERE organogram.ORGANOGRAMID =organEmployee.NODEID and organEmployee.EMPLOYEEID =%n
UNION ALL
SELECT e.Organogramid, e.PositionName, e.PARENTID, e.TIER
FROM organogram e
INNER JOIN cteReports r
ON e.Organogramid = r.PARENTID
)
SELECT
Organogramid, PositionName, tier, ORGANPOSITION.POSITIONTYPEID,
(SELECT PositionName FROM organogram
WHERE Organogramid = cteReports.PARENTID) AS Manager, EMPLOYEEID, OGPOSITIONTYPE
FROM cteReports
left join ORGANPOSITION on cteReports.Organogramid =ORGANPOSITION.nodeid
left join OGPositionType on OGPositionType.OGPOSITIONTYPEID =ORGANPOSITION.POSITIONTYPEID
left JOIN organEmployee oe on oe.NODEID = cteReports.Organogramid
order by cteReports.tier desc", employeeid);
}
#endregion
}
}