CEL_Payroll/Payroll.Service/SetupManager/DA/SetupDetailDA.cs

251 lines
9.0 KiB
C#
Raw Normal View History

2024-09-17 14:30:13 +06:00
using System;
using Payroll.BO;
using System.Data;
using System.Linq;
using Ease.CoreV35.Model;
using System.Data.SqlClient;
using Ease.CoreV35.DataAccess;
using System.Collections.Generic;
using Ease.CoreV35.DataAccess.SQL;
namespace Payroll.Service
{
#region SetupDetailDA
internal class SetupDetailDA
{
#region Constructor
private SetupDetailDA() { }
#endregion
#region Insert function
internal static void Insert(TransactionContext tc, SetupDetail item,EnumParameterSetup setup)
{
tc.ExecuteNonQuery("INSERT INTO "+ SetupDetailDA.getSetupTableName(setup) + "(DetailID, SetupID, tranID, tranType)" +
" VALUES(%n, %n, %n, %n)", item.ID.Integer, item.SetupID.Integer, item.TranID.Integer,
item.TranType);
}
#endregion
#region Update function
internal static void Update(TransactionContext tc, SetupDetail item, EnumParameterSetup setup)
{
tc.ExecuteNonQuery("UPDATE " + SetupDetailDA.getSetupTableName(setup) + " SET SetupID=%n, tranID=%n, tranType=%n" +
" WHERE SetupID=%n", item.SetupID, item.TranID, item.TranType, item.ID.Integer);
}
#endregion
#region Get Function
internal static IDataReader Get(TransactionContext tc, EnumParameterSetup setup)
{
return tc.ExecuteReader("SELECT * FROM %q", SetupDetailDA.getSetupTableName(setup));
}
internal static IDataReader Get(TransactionContext tc, ID nID, EnumParameterSetup setup)
{
return tc.ExecuteReader("SELECT * FROM %q WHERE SetupID=%n", getSetupTableName(setup), nID);
}
public static IDataReader GetParameters(TransactionContext tc, int nSetupID, EnumParameterSetup setup)
{
return tc.ExecuteReader("SELECT * FROM %q Where SetupID = %n", getSetupTableName(setup), nSetupID);
}
public static DataSet GetParameters(TransactionContext tc, EnumParameterSetup setup,
List<string> sqlrelations, string INEmpID)
{
string sql = "";
string InSQL = "";
if (INEmpID != "")
{
InSQL = SQLParser.MakeSQL(" AND E.EmployeeID IN (%q)", INEmpID);
}
foreach (string subsql in sqlrelations)
{
sql = sql + SQLParser.MakeSQL("select EmployeeID, SetupID from Employee E, %q SD where "
+ " %q %q", getSetupTableName(setup), subsql, InSQL) + " UNION ";
}
sql = sql.Substring(0, sql.Length - 7);
// sql = sql.Substring(0, sql.Length - 6);
sql = " select DISTINCT EmployeeID, SetupID from ( " + sql + " ) A Order by EmployeeId, SetupID";
return tc.ExecuteDataSet(sql);
}
public static IDataReader GetUsedParameters(TransactionContext tc, EnumParameterSetup setup, int nSetupID, int objectID)
{
return tc.ExecuteReader("Select * from %q Where SetupID IN " +
"(SELECT %q FROM %q WHERE %q =%n AND %q = %n)",
getSetupTableName(setup), getParameterPrimaryKey(setup),
getParameterTableName(setup), getParameterPrimaryKey(setup),
nSetupID, getParameterObjectKey(setup), objectID);
}
public static IDataReader GetUsedParameters(TransactionContext tc, EnumParameterSetup setup, int objectID)
{
string sql = SQLParser.MakeSQL("Select * from %q Where SetupID IN " +
"(SELECT %q FROM %q WHERE %q = %n)",
getSetupTableName(setup), getParameterPrimaryKey(setup),
getParameterTableName(setup),
getParameterObjectKey(setup), objectID);
return tc.ExecuteReader(sql);
}
public static IDataReader GetParameters(TransactionContext tc, EnumParameterSetup setup)
{
return tc.ExecuteReader("SELECT * FROM %q", getSetupTableName(setup));
}
public static DataSet GetTypes(TransactionContext tc, EnumParameterSetup setup)
{
return tc.ExecuteDataSet("SELECT DISTINCT TranType FROM %q ", getSetupTableName(setup));
}
public static DataSet GetParameters(TransactionContext tc,
EnumParameterSetup setup,
EnmSetupManagerTranType type, ID TranID)
{
return tc.ExecuteDataSet("SELECT DISTINCT TranType FROM %q WHERE TranType=%n AND TranID=%n ",
getSetupTableName(setup), (int)type, TranID.Integer);
}
#endregion
public static int GenerateID(TransactionContext tc, EnumParameterSetup setup)
{
int ID = tc.GenerateID(getSetupTableName(setup), "DetailID");
return ID;
}
private static string getSetupTableName(EnumParameterSetup setup)
{
string tablename = "";
switch (setup)
{
case EnumParameterSetup.OT:
tablename = "OTSetupDetail";
break;
case EnumParameterSetup.Bonus:
tablename = "BonusSetupDetail";
break;
case EnumParameterSetup.SalaryDeduct:
tablename = "UaLeaveSetupDetail";
break;
case EnumParameterSetup.Gratuity:
break;
case EnumParameterSetup.Leave :
tablename = "LeaveSetupDetail";
break;
default:
break;
}
return tablename;
}
private static string getParameterTableName(EnumParameterSetup setup)
{
string tablename = "";
switch (setup)
{
case EnumParameterSetup.OT:
tablename = "TERMPARAMETER";
break;
case EnumParameterSetup.Bonus:
tablename = "BONUSPARAMETER";
break;
case EnumParameterSetup.SalaryDeduct:
tablename = "UALeaveParam";
break;
case EnumParameterSetup.Gratuity:
break;
case EnumParameterSetup.Leave:
tablename = "LEAVEPARAMETER";
break;
default:
break;
}
return tablename;
}
private static string getParameterPrimaryKey(EnumParameterSetup setup)
{
string tablename = "";
switch (setup)
{
case EnumParameterSetup.OT:
tablename = "TermParameterID";
break;
case EnumParameterSetup.Bonus:
tablename = "BonusParameterID";
break;
case EnumParameterSetup.SalaryDeduct:
tablename = "UaLeaveParamID";
break;
case EnumParameterSetup.Gratuity:
break;
case EnumParameterSetup.Leave:
tablename = "LEAVEPARAMID";
break;
default:
break;
}
return tablename;
}
private static string getParameterObjectKey(EnumParameterSetup setup)
{
string tablename = "";
switch (setup)
{
case EnumParameterSetup.OT:
tablename = "TERMID";
break;
case EnumParameterSetup.Bonus:
tablename = "BonusID";
break;
case EnumParameterSetup.SalaryDeduct:
tablename = "UaLeaveID";
break;
case EnumParameterSetup.Gratuity:
break;
case EnumParameterSetup.Leave:
tablename = "LEAVEID";
break;
default:
break;
}
return tablename;
}
#region Delete function
internal static void Delete(TransactionContext tc, EnumParameterSetup setup, ID SetupID)
{
tc.ExecuteNonQuery("DELETE FROM %q WHERE SetupID=%n", getSetupTableName(setup), SetupID.Integer);
}
#endregion
internal static IDataReader GetByID(ID parmID, TransactionContext tc)
{
string sql = SQLParser.MakeSQL(@"SELECT * From BonusSetupDetail Where SetupID = %n", parmID.Integer);
return tc.ExecuteReader(sql);
}
internal static IDataReader GetOTDetail(TransactionContext tc, EnumParameterSetup setup, EnmSetupManagerTranType enmSetupManagerTranType)
{
return tc.ExecuteReader("SELECT * FROM %q WHERE TranType=%n", getSetupTableName(setup), (int)enmSetupManagerTranType);
}
}
#endregion
}