564 lines
16 KiB
C#
564 lines
16 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Ease.CoreV35;
|
|
using Ease.CoreV35.Model;
|
|
using Ease.CoreV35.DataAccess;
|
|
using Payroll.BO;
|
|
using Ease.CoreV35.Caching;
|
|
|
|
namespace Payroll.Service
|
|
{
|
|
#region AssetInventory Service
|
|
[Serializable]
|
|
public class AssetInventoryService : ServiceTemplate, IAssetInventoryService
|
|
{
|
|
#region Private functions and declaration
|
|
Cache _cache = new Cache(typeof(AssetInventory));
|
|
#endregion
|
|
public AssetInventoryService() { }
|
|
|
|
#region MapObject For AssetInventory
|
|
private void MapObject(AssetInventory oAssetInventory, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oAssetInventory, oReader.GetID("AssetInventoryID"));
|
|
oAssetInventory.AssetID = oReader.GetID("AssetID");
|
|
oAssetInventory.ReceiveEmployeeID = oReader.GetID("AssignedUserID");
|
|
oAssetInventory.AssignedDate = oReader.GetDateTime("AssignedDate").Value;
|
|
oAssetInventory.AssignedRemarks = oReader.GetString("AssignedRemarks");
|
|
oAssetInventory.AssignUserID = oReader.GetID("AssignUserID");
|
|
oAssetInventory.IsEmpConfirmed = oReader.GetBoolean("IsEmpConfirmed").GetValueOrDefault();
|
|
oAssetInventory.empConfirmDate = oReader.GetDateTime("EmpConfirmDate").GetValueOrDefault(DateTime.MinValue);
|
|
oAssetInventory.EmpConfirmRemarks = oReader.GetString("EmpConfirmRemarks");
|
|
oAssetInventory.RetainUserID = oReader.GetID("RetainUserID").IsUnassigned ? ID.FromInteger(0) : oReader.GetID("RetainUserID");
|
|
oAssetInventory.RetainDate = oReader.GetDateTime("RetainDate").GetValueOrDefault(DateTime.MinValue);
|
|
oAssetInventory.RetainRemarks = oReader.GetString("RetainRemarks");
|
|
oAssetInventory.IsEmpRetained = oReader.GetBoolean("IsEmpRetained").GetValueOrDefault();
|
|
oAssetInventory.CreatedBy = oReader.GetID("CreatedBy");
|
|
oAssetInventory.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|
oAssetInventory.ModifiedBy = oReader.GetID("ModifiedBy");
|
|
oAssetInventory.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|
this.SetObjectState(oAssetInventory, Ease.CoreV35.ObjectState.Saved);
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
AssetInventory oAssetInventory = new AssetInventory();
|
|
MapObject(oAssetInventory, oReader);
|
|
return oAssetInventory as T;
|
|
}
|
|
|
|
protected AssetInventory CreateObject(DataReader oReader)
|
|
{
|
|
AssetInventory oAssetInventory = new AssetInventory();
|
|
MapObject(oAssetInventory, oReader);
|
|
return oAssetInventory;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Service Implemantation
|
|
public AssetInventory Get(ID id)
|
|
{
|
|
AssetInventory oAssetInventory = new AssetInventory();
|
|
#region Cache Header
|
|
oAssetInventory = _cache["Get", id] as AssetInventory;
|
|
if (oAssetInventory != null)
|
|
return oAssetInventory;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(AssetInventoryDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oAssetInventory = this.CreateObject<AssetInventory>(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(oAssetInventory, "Get", id);
|
|
#endregion
|
|
return oAssetInventory;
|
|
}
|
|
|
|
public ObjectsTemplate<AssetInventory> Get()
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<AssetInventory> AssetInventorys = _cache["Get"] as ObjectsTemplate<AssetInventory>;
|
|
if (AssetInventorys != null)
|
|
return AssetInventorys;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(AssetInventoryDA.Get(tc));
|
|
AssetInventorys = this.CreateObjects<AssetInventory>(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(AssetInventorys, "Get");
|
|
|
|
#endregion
|
|
|
|
return AssetInventorys;
|
|
}
|
|
|
|
public ObjectsTemplate<AssetInventory> GetAllAsset(int assignedUserID, int assignUserID)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<AssetInventory> AssetInventorys = _cache["GetAllAsset"] as ObjectsTemplate<AssetInventory>;
|
|
if (AssetInventorys != null)
|
|
return AssetInventorys;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(AssetInventoryDA.GetAllAsset(tc,assignedUserID, assignUserID));
|
|
AssetInventorys = this.CreateObjects<AssetInventory>(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(AssetInventorys, "GetAllAsset");
|
|
|
|
#endregion
|
|
|
|
return AssetInventorys;
|
|
}
|
|
|
|
|
|
|
|
public ObjectsTemplate<AssetInventory> GetEmpAssignedNotReceiveConfirm(int employeeid)
|
|
{
|
|
|
|
|
|
ObjectsTemplate<AssetInventory> AssetInventorys = null;
|
|
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(AssetInventoryDA.GetEmpAssignedNotReceiveConfirm(tc, employeeid));
|
|
AssetInventorys = this.CreateObjects<AssetInventory>(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
|
|
}
|
|
|
|
|
|
|
|
return AssetInventorys;
|
|
}
|
|
|
|
|
|
public ObjectsTemplate<AssetInventory> GetAllAsset(int assignedUserID)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<AssetInventory> AssetInventorys = _cache["GetAllAsset"] as ObjectsTemplate<AssetInventory>;
|
|
if (AssetInventorys != null)
|
|
return AssetInventorys;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(AssetInventoryDA.GetAllAsset(tc, assignedUserID));
|
|
AssetInventorys = this.CreateObjects<AssetInventory>(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(AssetInventorys, "GetAllAsset");
|
|
|
|
#endregion
|
|
|
|
return AssetInventorys;
|
|
}
|
|
|
|
public ObjectsTemplate<AssetInventory> GetReceivedItems(int assignUserID)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<AssetInventory> AssetInventorys = _cache["GetAllAssignedAsset"] as ObjectsTemplate<AssetInventory>;
|
|
if (AssetInventorys != null)
|
|
return AssetInventorys;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(AssetInventoryDA.GetReceivedItems(tc, assignUserID));
|
|
AssetInventorys = this.CreateObjects<AssetInventory>(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(AssetInventorys, "GetAllAssignedAsset");
|
|
|
|
#endregion
|
|
|
|
return AssetInventorys;
|
|
}
|
|
|
|
public ObjectsTemplate<AssetInventory> GetAssets(int assignedUserID, bool isEmpConfirmed, int assignUserID)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<AssetInventory> AssetInventorys = _cache["GetAssets"] as ObjectsTemplate<AssetInventory>;
|
|
if (AssetInventorys != null)
|
|
return AssetInventorys;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(AssetInventoryDA.GetAssets(tc, assignedUserID, isEmpConfirmed, assignUserID));
|
|
AssetInventorys = this.CreateObjects<AssetInventory>(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(AssetInventorys, "GetAllAsset");
|
|
|
|
#endregion
|
|
|
|
return AssetInventorys;
|
|
}
|
|
|
|
public ObjectsTemplate<AssetInventory> GetReturnedItems(int assignUserID )
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<AssetInventory> AssetInventorys = _cache["GetReturnedAssets"] as ObjectsTemplate<AssetInventory>;
|
|
if (AssetInventorys != null)
|
|
return AssetInventorys;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(AssetInventoryDA.GetReturnedItems(tc, assignUserID));
|
|
AssetInventorys = this.CreateObjects<AssetInventory>(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(AssetInventorys, "GetReturnedAssets");
|
|
|
|
#endregion
|
|
|
|
return AssetInventorys;
|
|
}
|
|
|
|
public ID Save(AssetInventory oAssetInventory)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oAssetInventory.IsNew)
|
|
{
|
|
int id = tc.GenerateID("AssetInventory", "AssetInventoryID");
|
|
base.SetObjectID(oAssetInventory, ID.FromInteger(id));
|
|
AssetInventoryDA.Insert(tc, oAssetInventory);
|
|
}
|
|
else
|
|
{
|
|
AssetInventoryDA.Update(tc, oAssetInventory);
|
|
}
|
|
return oAssetInventory.ID;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
finally
|
|
{
|
|
tc.End();
|
|
}
|
|
}
|
|
|
|
public ID UpdateEmpConfirm(AssetInventory oAssetInventory)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
AssetInventoryDA.UpdateEmpConfirm(tc, oAssetInventory);
|
|
return oAssetInventory.ID;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
finally
|
|
{
|
|
tc.End();
|
|
}
|
|
}
|
|
|
|
public ID UpdateRetainAsset(AssetInventory oAssetInventory)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
AssetInventoryDA.UpdateRetainAsset(tc, oAssetInventory);
|
|
return oAssetInventory.ID;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
finally
|
|
{
|
|
tc.End();
|
|
}
|
|
}
|
|
|
|
public void Delete(ID id)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
AssetInventoryDA.Delete(tc, id.Integer);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
finally
|
|
{
|
|
tc.End();
|
|
}
|
|
}
|
|
|
|
public void Delete(int id)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
AssetInventoryDA.Delete(tc, id);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
finally
|
|
{
|
|
tc.End();
|
|
}
|
|
}
|
|
|
|
public void Save(ObjectsTemplate<AssetInventory> assetInventories)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (assetInventories.Count > 0)
|
|
{
|
|
AssetInventoryDA.Delete(tc, assetInventories[0].ReceiveEmployeeID.Integer, assetInventories[0].AssignUserID.Integer);
|
|
foreach(AssetInventory assetItem in assetInventories)
|
|
{
|
|
if (assetItem.IsNew)
|
|
{
|
|
int id = tc.GenerateID("AssetInventory", "AssetInventoryID");
|
|
base.SetObjectID(assetItem, ID.FromInteger(id));
|
|
AssetInventoryDA.Insert(tc, assetItem);
|
|
}
|
|
else
|
|
{
|
|
AssetInventoryDA.Update(tc, assetItem);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
finally
|
|
{
|
|
tc.End();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
#endregion
|
|
}
|