EchoTex_Payroll/HRM.DA/DA/Attendance/AttnRawDataDA.cs
2024-10-14 10:01:49 +06:00

148 lines
7.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using HRM.BO;
using Ease.Core.DataAccess;
namespace HRM.DA
{
#region AttnRawDataDA
internal class AttnRawDataDA
{
#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), 0), item.EmployeeID,
item.CardNo, item.PunchTime, (int)item.EntryMode, item.DeviceIPAddress, item.DeviceNo);
}
#endregion
internal static IDataReader Get(TransactionContext tc, DateTime fromDate, DateTime toDate, int payrollTypeID)
{
//string sql = SQLParser.MakeSQL(
// "SELECT a.* FROM AttnRawData a Inner join Employee e on e.employeeID=a.employeeID WHERE a.PunchTime between %D AND %D and e.payrollTypeID=%n ORDER BY a.EmployeeID, a.PunchTime asc",
// fromDate, toDate, payrollTypeID);
//string sql = SQLParser.MakeSQL(
// "SELECT a.* FROM AttnRawData a Inner join Employee e on e.employeeID = a.employeeID"
// + " WHERE a.PunchTime between %D AND %D and e.payrollTypeID = %n"
// + " Union"
// + " SELECT null CardID, a.EmpID as EmployeeID, '' CardNo, a.PunchTime PunchTime, a.PunchType EntryMode, '' DeviceIPAddress, '' DeviceNo FROM AttnMobileRawData a "
// + " Inner join Employee e on e.employeeID = a.EmpID "
// + " WHERE a.PunchTime between %D AND %D ORDER BY EmployeeID, PunchTime asc",
// fromDate, toDate, payrollTypeID, fromDate, toDate);
//string sql = SQLParser.MakeSQL(
// "SELECT a.* FROM AttnRawData a "
// + " WHERE a.PunchTime between %D AND %D "
// + " Union"
// + " SELECT null CardID, a.EmpID as EmployeeID, '' CardNo, a.PunchTime PunchTime, a.PunchType EntryMode, '' DeviceIPAddress, '' DeviceNo FROM AttnMobileRawData a "
// + " Inner join Employee e on e.employeeID = a.EmpID "
// + " WHERE a.PunchTime between %D AND %D ORDER BY EmployeeID, PunchTime",
// fromDate, toDate, fromDate, toDate);
string sql = SQLParser.MakeSQL(
"SELECT a.* FROM AttnRawData a Inner join Employee e on e.employeeID = a.EmployeeID WHERE a.PunchTime between "
+ " %D AND %D ", fromDate, toDate);
tc.CommandTimeOut = 6000;
return tc.ExecuteReader(sql);
}
internal static IDataReader GetWithoutMobileRawData(TransactionContext tc, DateTime fromDate, DateTime toDate, int payrollTypeID)
{
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 IDataReader Get(TransactionContext tc, DateTime fromDate, DateTime toDate, string empIDs,
int payrollTypeID)
{
string sql = string.Empty;
if (!string.IsNullOrEmpty(empIDs))
{
sql = SQLParser.MakeSQL(
"SELECT a.* FROM AttnRawData a Inner join Employee e on e.employeeID=a.employeeID WHERE a.PunchTime between %D AND %D and e.payrollTypeID=%n and a.employeeID in (%q) ORDER BY a.EmployeeID, a.PunchTime asc",
fromDate, toDate, payrollTypeID, empIDs);
}
else
{
sql = SQLParser.MakeSQL(
"SELECT a.* FROM AttnRawData a Inner join Employee e on e.employeeID=a.employeeID WHERE a.PunchTime between %D AND %D and e.payrollTypeID=%n ORDER BY a.EmployeeID, a.PunchTime asc",
fromDate, toDate, payrollTypeID, empIDs);
}
return tc.ExecuteReader(sql);
}
//internal static IDataReader Get(TransactionContext tc, DateTime fromDate, DateTime toDate, int payrollTypeID)
//{
// //string sql = SQLParser.MakeSQL("SELECT a.* FROM AttnRawData a Inner join Employee e on e.employeeID=a.employeeID Where e.payrollTypeID=%n and a.PunchTime between %D AND %D ORDER BY a.employeeID, a.PunchTime asc", payrollTypeID, fromDate, toDate);
// string sql = SQLParser.MakeSQL("SELECT e.EmployeeID, a.* FROM DAILYATTNRAWDATA a Inner join Employee e on e.employeeNo=a.employeeNo WHERE a.PunchTime between %D AND %D and e.payrollTypeID=%n ORDER BY a.employeeNo, a.PunchTime asc", fromDate, toDate, payrollTypeID);
// return tc.ExecuteReader(sql);
//}
internal static DataSet GetDataFromClientSqlDB(TransactionContext tc, DateTime maxPunchDate)
{
DataSet rawData = new DataSet();
try
{
string sql = string.Empty;
if (maxPunchDate == DateTime.MinValue)
{
maxPunchDate = new DateTime(2017, 5, 20);
}
sql = SQLParser.MakeSQL(
@"Select bd.punch_date PunchTime, bd.card_no CardNo, bd.terminal MachineNo, bd.reader EntryMode from Badge_Data bd where bd.punch_date > %D and bd.card_no <> '' and bd.card_no is not null order by punch_date asc",
maxPunchDate);
rawData = tc.ExecuteDataSet(sql);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return rawData;
}
internal static void Delete(TransactionContext tc, DateTime fromTime, string empIDs)
{
tc.ExecuteNonQuery("DELETE FROM AttnRawData WHERE PunchTime>=%D and EmployeeID in (%q)", fromTime, empIDs);
}
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
}