476 lines
14 KiB
C#
476 lines
14 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Ease.CoreV35.Model;
|
|
using Payroll.BO;
|
|
using Ease.CoreV35.Caching;
|
|
using Ease.CoreV35.DataAccess;
|
|
using Payroll.Service.Attendence.DA;
|
|
using Payroll.BO;
|
|
using System.Data;
|
|
using System.Globalization;
|
|
|
|
namespace Payroll.Service.Attendence.Service
|
|
{
|
|
#region AttnRawData Service
|
|
|
|
[Serializable]
|
|
public class AttnRawDataService : ServiceTemplate, IAttnRawDataService
|
|
{
|
|
#region Private functions and declaration
|
|
Cache _cache = new Cache(typeof(AttnRawData));
|
|
|
|
#endregion
|
|
|
|
#region Constructor and Object Mapping
|
|
|
|
public AttnRawDataService() { }
|
|
|
|
private void MapObject(AttnRawData oAttnRawData, DataReader oReader)
|
|
{
|
|
oAttnRawData.CardID = oReader.GetID("CardID");
|
|
oAttnRawData.EmployeeID = oReader.GetID("EmployeeID");
|
|
oAttnRawData.CardNo = oReader.GetString("CardNo");
|
|
oAttnRawData.PunchTime = oReader.GetDateTime("PunchTime").Value;
|
|
oAttnRawData.EntryMode = (EnumEntryMode)oReader.GetInt32("EntryMode").Value;
|
|
oAttnRawData.DeviceIPAddress = oReader.GetString("DeviceIPAddress");
|
|
oAttnRawData.DeviceNo = oReader.GetString("DeviceNo");
|
|
//this.SetObjectState(oAttnRawData, Ease.CoreV35.ObjectState.Saved);
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
AttnRawData oAttnRawData = new AttnRawData();
|
|
MapObject(oAttnRawData, oReader);
|
|
return oAttnRawData as T;
|
|
}
|
|
|
|
protected AttnRawData CreateObject(DataReader oReader)
|
|
{
|
|
AttnRawData oAttnRawData = new AttnRawData();
|
|
MapObject(oAttnRawData, oReader);
|
|
return oAttnRawData;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Service implementation
|
|
|
|
#region Get
|
|
|
|
public AttnRawData Get(ID id)
|
|
{
|
|
AttnRawData oAttnRawData = new AttnRawData();
|
|
#region Cache Header
|
|
oAttnRawData = _cache["Get", id] as AttnRawData;
|
|
if (oAttnRawData != null)
|
|
return oAttnRawData;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(AttnRawDataDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oAttnRawData = this.CreateObject<AttnRawData>(oreader);
|
|
}
|
|
oreader.Close();
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
#region Cache Footer
|
|
_cache.Add(oAttnRawData, "Get", id);
|
|
#endregion
|
|
return oAttnRawData;
|
|
}
|
|
|
|
public ObjectsTemplate<AttnRawData> Get()
|
|
{
|
|
#region Cache Header
|
|
ObjectsTemplate<AttnRawData> attnRawDatas = _cache["Get"] as ObjectsTemplate<AttnRawData>;
|
|
if (attnRawDatas != null)
|
|
return attnRawDatas;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(AttnRawDataDA.Get(tc));
|
|
attnRawDatas = this.CreateObjects<AttnRawData>(dr);
|
|
dr.Close();
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
#region Cache Footer
|
|
_cache.Add(attnRawDatas, "Get");
|
|
#endregion
|
|
return attnRawDatas;
|
|
}
|
|
|
|
public ObjectsTemplate<AttnRawData> Get(DateTime fromDate, DateTime toDate)
|
|
{
|
|
#region Cache Header
|
|
ObjectsTemplate<AttnRawData> attnRawDatas = _cache["Get", fromDate, toDate] as ObjectsTemplate<AttnRawData>;
|
|
if (attnRawDatas != null)
|
|
return attnRawDatas;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(AttnRawDataDA.Get(tc, fromDate, toDate));
|
|
attnRawDatas = this.CreateObjects<AttnRawData>(dr);
|
|
dr.Close();
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
#region Cache Footer
|
|
_cache.Add(attnRawDatas, "Get", fromDate, toDate);
|
|
#endregion
|
|
return attnRawDatas;
|
|
}
|
|
|
|
public bool IsDataExist(DateTime datefrom, DateTime dateto)
|
|
{
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
bool bresult = AttnRawDataDA.IsDataExist(tc, datefrom, dateto);
|
|
tc.End();
|
|
return bresult;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public DataTable GetCoatsData()
|
|
{
|
|
DateTime maxDate = new DateTime(1901,1,1);
|
|
DataSet coatsDataset = null;
|
|
TransactionContext tc = null;
|
|
TransactionContext tc2 = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
maxDate = AttnRawDataDA.GetRawDataMaxDateTime(tc);
|
|
|
|
tc.End();
|
|
|
|
ConnectionContext ctx = new ConnectionContext("serviceHandlercoats");
|
|
tc2 = TransactionContext.Begin(ctx);
|
|
|
|
coatsDataset = AttnRawDataDA.GetCoatsRawData(tc2, maxDate);
|
|
|
|
tc2.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
if (tc2 != null)
|
|
tc2.HandleError();
|
|
ExceptionLog.Write(e);
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
return coatsDataset.Tables[0];
|
|
}
|
|
|
|
public DataTable GetInOutData(DateTime startDate,DateTime endDate, int employeeID)
|
|
{
|
|
|
|
DataSet attenDataset = null;
|
|
TransactionContext tc = null;
|
|
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
attenDataset = AttnRawDataDA.GetInOutData(tc,startDate,endDate, employeeID);
|
|
|
|
tc.End();
|
|
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
return attenDataset.Tables[0];
|
|
}
|
|
|
|
public DataSet GetEmployeeNo(DateTime workdate)
|
|
{
|
|
DataSet employeeNo = null;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
employeeNo = AttnRawDataDA.GetEmployeeNo(tc, workdate);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
|
|
}
|
|
return employeeNo;
|
|
}
|
|
|
|
public void RunScriptCollectRawData()
|
|
{
|
|
TransactionContext tc = null;
|
|
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
tc.CommandTimeOut = 48000;
|
|
tc.ExecuteNonQuery(CommandType.StoredProcedure, "spCollectRawData");
|
|
|
|
tc.End();
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Save
|
|
|
|
public ID Save(AttnRawData oAttnRawData)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oAttnRawData.IsNew)
|
|
{
|
|
int id = tc.GenerateID("AttnRawData", "AttnRawDataID");
|
|
base.SetObjectID(oAttnRawData, ID.FromInteger(id));
|
|
AttnRawDataDA.Insert(tc, oAttnRawData);
|
|
}
|
|
else
|
|
{
|
|
// AttnRawDataDA.Update(tc, oAttnRawData);
|
|
}
|
|
tc.End();
|
|
return oAttnRawData.ID;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
public void Save(ObjectsTemplate<AttnRawData> attnRawDatas)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
int id = tc.GenerateID("AttnRawData", "AttnRawDataID");
|
|
|
|
foreach (AttnRawData item in attnRawDatas)
|
|
{
|
|
base.SetObjectID(item, ID.FromInteger(id));
|
|
AttnRawDataDA.Insert(tc, item);
|
|
id++;
|
|
}
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
public void Save(ObjectsTemplate<AttnRawData> attnRawDatas, DataTable rawData, ObjectsTemplate<Employee> employees)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
AttnRawData at = new AttnRawData();
|
|
tc = TransactionContext.Begin(true);
|
|
|
|
#region Data_Preparation
|
|
|
|
foreach (DataRow dr in rawData.Rows)
|
|
{
|
|
string cardNo = Convert.ToString(dr["CardNo"]);
|
|
AccessCard accCard = new AccessCardService().Get(cardNo, tc);
|
|
if (accCard != null)
|
|
{
|
|
foreach (Employee emp in employees)
|
|
{
|
|
if (accCard.ID == emp.CardID)
|
|
{
|
|
at = new AttnRawData();
|
|
at.CardID = accCard.ID;
|
|
at.CardNo = accCard.CardNumber;
|
|
at.EmployeeID = emp.ID;
|
|
at.PunchTime = Convert.ToDateTime(dr["Time"]);
|
|
|
|
attnRawDatas.Add(at);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
foreach (AttnRawData item in attnRawDatas)
|
|
{
|
|
int id = tc.GenerateID("AttnRawData", "AttnRawDataID");
|
|
base.SetObjectID(item, ID.FromInteger(id));
|
|
AttnRawDataDA.Insert(tc, item);
|
|
}
|
|
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Delete
|
|
|
|
public void Delete(ID id)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
//AttnRawDataDA.Delete(tc, id);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
public void Delete(DateTime fromTime)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
AttnRawDataDA.Delete(tc, fromTime);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
#endregion
|
|
}
|
|
|
|
#endregion
|
|
}
|