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

160 lines
6.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35.DataAccess;
using Payroll.BO;
using System.Data;
using Ease.CoreV35.Model;
namespace Payroll.Service.Attendence.DA
{
#region AttnRawDataDA
internal class AttnRawDataDA
{
#region Constructor
private AttnRawDataDA() { }
#endregion
#region Insert function
internal static void Insert(TransactionContext tc, AttnRawData item)
{
tc.ExecuteNonQuery("INSERT INTO AttnRawData(CardID, EmployeeID, CardNo, PunchTime,EntryMode,DeviceIPAddress,DeviceNo)" +
" VALUES(%n, %n, %s, %D, %n,%s,%s)", DataReader.GetNullValue(item.CardID,IDType.Integer), item.EmployeeID.Integer, item.CardNo, item.PunchTime, (int)item.EntryMode,item.DeviceIPAddress,item.DeviceNo);
}
#endregion
//#region Update function
//internal static void Update(TransactionContext tc, AttnRawData item)
//{
// tc.ExecuteNonQuery("UPDATE AttnRawData SET CardID=%n, EmployeeID=%n, CardNo=%s,PunchTime=%D,EntryMode=%n,DeviceIPAddress=%s,DeviceNo=%s" +
// " WHERE AttnRawDataID=%n", DataReader.GetNullValue(item.CardID, IDType.Integer), item.EmployeeID.Integer, item.CardNo, item.PunchTime, (int)item.EntryMode, item.DeviceIPAddress, item.DeviceNo, item.ID.Integer);
//}
//#endregion
#region Get Function
internal static IDataReader Get(TransactionContext tc)
{
return tc.ExecuteReader("SELECT * FROM AttnRawData");
}
internal static IDataReader Get(TransactionContext tc, ID nID)
{
return tc.ExecuteReader("SELECT * FROM AttnRawData WHERE AttnRawDataID=%n", nID);
}
internal static IDataReader Get(TransactionContext tc, DateTime fromDate, DateTime toDate)
{
string sql = SQLParser.MakeSQL("SELECT * FROM AttnRawData WHERE PunchTime between %D AND %D ORDER BY EmployeeID,PunchTime", fromDate, toDate);
return tc.ExecuteReader(sql);
}
internal static bool IsDataExist(TransactionContext tc, DateTime fromDate, DateTime toDate)
{
string sql = SQLParser.MakeSQL("SELECT Count(*) FROM AttnRawData WHERE PunchTime between %D AND %D ", fromDate, toDate);
object odata = tc.ExecuteScalar(sql);
if (odata == DBNull.Value) return false;
else
{
if (Convert.ToInt32(odata) > 0) return true;
else return false;
}
}
internal static DateTime GetRawDataMaxDateTime(TransactionContext tc)
{
string sql = SQLParser.MakeSQL("SELECT Max(PunchTime) FROM AttnRawData ");
object odata = tc.ExecuteScalar(sql);
if (odata == DBNull.Value)
return new DateTime(1901,1,1);
return Convert.ToDateTime(Convert.ToString(odata));
}
internal static DataSet GetEmployeeNo(TransactionContext tc, DateTime workdate)
{
DataSet employeeNo = new DataSet();
try
{
string sql = SQLParser.MakeSQL("select distinct e.EMPLOYEENO from ATTNRAWDATA a "
+ "inner join Employee e on e.EMPLOYEEID = a.EMPLOYEEID "
+ "where a.EMPLOYEEID not in (select EMPLOYEEID from MONTHLYWORKPLAN "
+ "where workdate=%d)"
+ "AND PunchTime =%d", workdate, workdate);
employeeNo = tc.ExecuteDataSet(sql);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return employeeNo;
}
internal static DataSet GetCoatsRawData(TransactionContext tc, DateTime minDate)
{
DataSet rawData = new DataSet();
try
{
string sql = SQLParser.MakeSQL(@"SELECT * FROM RawCoats where PunchTime>=%d", minDate);
rawData = tc.ExecuteDataSet(sql);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return rawData;
}
internal static DataSet GetInOutData(TransactionContext tc,DateTime startDate, DateTime endDate, int employeeID)
{
DataSet rawData = new DataSet();
try
{
string sql = SQLParser.MakeSQL(@"SELECT COALESCE(InTable.EmployeeID,OutTable.EmployeeID) EmployeeID,COALESCE(InTable.WorkingDate,OutTable.WorkingDate) AttnDate,InTime,OutTime from
(SELECT ard.EmployeeID,Max(CAST(ard.PunchTime AS DATE)) WorkingDate, MIN(ard.PunchTime) InTime
FROM AttnRawData ard WHERE ard.EmployeeID=%n AND entryMode=1 AND CAST(ard.PunchTime AS DATE) BETWEEN %d AND %d GROUP BY CAST(ard.PunchTime AS DATE),EmployeeID) as InTable
Full OUTER JOIN
( SELECT ard.EmployeeID,Max(CAST(ard.PunchTime AS DATE)) WorkingDate, MAX(ard.PunchTime) OutTime
FROM AttnRawData ard WHERE ard.EmployeeID=%n AND entryMode=2 AND CAST(ard.PunchTime AS DATE) BETWEEN %d AND %d GROUP BY CAST(ard.PunchTime AS DATE),EmployeeID) as OutTable
ON
InTable.WorkingDate=OutTable.WorkingDate", employeeID,startDate,endDate, employeeID,startDate,endDate);
rawData = tc.ExecuteDataSet(sql);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return rawData;
}
#endregion
#region Delete function
//internal static void Delete(TransactionContext tc, ID nID)
//{
// tc.ExecuteNonQuery("DELETE FROM [AttnRawData] WHERE AttnRawDataID=%n", nID);
//}
internal static void Delete(TransactionContext tc, DateTime fromTime)
{
tc.ExecuteNonQuery("DELETE FROM AttnRawData WHERE PunchTime>=%D", fromTime);
}
#endregion
}
#endregion
}