CEL_Payroll/Payroll.Service/Basic/DA/CategoryDA.cs
2024-09-17 14:30:13 +06:00

108 lines
3.7 KiB
C#

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 CategoryDA
internal class CategoryDA
{
#region Constructor
private CategoryDA() { }
#endregion
#region Insert function
internal static void Insert(TransactionContext tc, Category item)
{
tc.ExecuteNonQuery("INSERT INTO Category(CategoryID, code, description, CreatedBy, CreationDate, SequenceNo, Status,WagesType)" +
" VALUES(%n, %s, %s, %n, %d, %n, %n,%n)", item.ID.Integer, item.Code, item.Name, item.CreatedBy.Integer, item.CreatedDate, item.Sequence, item.Status, (int)item.WagesType);
}
#endregion
#region Update function
internal static void Update(TransactionContext tc, Category item)
{
tc.ExecuteNonQuery("UPDATE Category SET code=%s, description=%s, ModifiedBy=%n, ModifiedDate=%d, SequenceNo=%n, Status=%n,WagesType=%n" +
" WHERE CategoryID=%n", item.Code, item.Name, item.ModifiedBy.Integer, item.ModifiedDate, item.Sequence, item.Status,(int)item.WagesType, item.ID.Integer);
}
#endregion
#region Get Function
internal static IDataReader Get(TransactionContext tc,EnumStatus status)
{
if (EnumStatus.Active == status || EnumStatus.Inactive == status)
{
return tc.ExecuteReader("SELECT * FROM Category where Status=%n Order By SequenceNo", status);
}
else
{
return tc.ExecuteReader("SELECT * FROM Category Order By SequenceNo");
}
}
internal static IDataReader Get(TransactionContext tc, ID nID)
{
return tc.ExecuteReader("SELECT * FROM Category WHERE CategoryID=%n", nID.Integer);
}
internal static IDataReader Get(TransactionContext tc)
{
return tc.ExecuteReader("SELECT * FROM Category");
}
#endregion
#region Delete function
internal static void Delete(TransactionContext tc, ID nID)
{
tc.ExecuteNonQuery("UPDATE [Category] SET CreatedBy=%n,ModifiedBy=%n Where CategoryID=%n", Payroll.BO.User.CurrentUser.ID.Integer, Payroll.BO.User.CurrentUser.ID.Integer, nID.Integer);
tc.ExecuteNonQuery("DELETE FROM [Category] WHERE CategoryID=%n", nID.Integer);
}
#endregion
internal static DataSet GetAgeRange(TransactionContext tc, int fromyear, int toyear)
{
DataSet rootDataset = new DataSet();
DataSet tempdataset = new DataSet();
try
{
string query = SQLParser.MakeSQL(@"Select Count(EmployeeID)as ManagementStaff,(Select Count(EmployeeID)
from Employee where CategoryID=2 and DATEDIFF(YEAR,BIRTHDATE,GETDATE()) between %n and %n)as NonManagementStaff
from Employee
where CategoryID=1 and DATEDIFF(YEAR,BIRTHDATE,GETDATE()) between %n and %n ",
fromyear,toyear,fromyear,toyear);
tempdataset = tc.ExecuteDataSet(query);
tempdataset.Tables[0].TableName = "AgeRange";
rootDataset.Tables.Add(tempdataset.Tables[0].Copy());
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return rootDataset;
}
}
#endregion
}