526 lines
15 KiB
C#
526 lines
15 KiB
C#
using System;
|
|
using Ease.Core.Model;
|
|
using Ease.Core.DataAccess;
|
|
using Ease.Core.Utility;
|
|
using System.Collections.Generic;
|
|
using HRM.BO;
|
|
using System.Data;
|
|
|
|
namespace HRM.DA
|
|
{
|
|
public class AssetInventoryService : ServiceTemplate, IAssetInventoryService
|
|
{
|
|
public AssetInventoryService()
|
|
{
|
|
}
|
|
|
|
#region MapObject For AssetInventory
|
|
|
|
private void MapObject(AssetInventory oAssetInventory, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oAssetInventory, (oReader.GetInt32("AssetInventoryID").Value));
|
|
oAssetInventory.AssetID = (oReader.GetInt32("AssetID").Value);
|
|
oAssetInventory.ReceiveEmployeeID = (oReader.GetInt32("AllocatedUserID").Value);
|
|
oAssetInventory.AssignedDate = oReader.GetDateTime("AllocationDate").Value;
|
|
oAssetInventory.AssignedRemarks = oReader.GetString("AllocationRemarks");
|
|
oAssetInventory.AssignUserID = (oReader.GetInt32("AllocatorUserID").Value);
|
|
oAssetInventory.IsEmpConfirmed = oReader.GetBoolean("IsEmpConfirmed").GetValueOrDefault();
|
|
oAssetInventory.empConfirmDate =
|
|
oReader.GetDateTime("EmpConfirmationDate").GetValueOrDefault(DateTime.MinValue);
|
|
oAssetInventory.EmpConfirmRemarks = oReader.GetString("EmpConfirmationRemarks");
|
|
oAssetInventory.RetainUserID = oReader.GetInt32("RetainUserID", 0);
|
|
oAssetInventory.RetainDate = oReader.GetDateTime("RetainDate").GetValueOrDefault(DateTime.MinValue);
|
|
oAssetInventory.RetainRemarks = oReader.GetString("RetainRemarks");
|
|
oAssetInventory.IsEmpRetained = oReader.GetBoolean("IsEmpRetained").GetValueOrDefault();
|
|
oAssetInventory.CreatedBy = oReader.GetInt32("CreatedBy", 0);
|
|
oAssetInventory.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|
oAssetInventory.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
|
|
oAssetInventory.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|
oAssetInventory.Amount = oReader.GetDouble("Amount").Value;
|
|
this.SetObjectState(oAssetInventory, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
AssetInventory oAssetInventory = new AssetInventory();
|
|
MapObject(oAssetInventory, oReader);
|
|
return oAssetInventory as T;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Service Implemantation
|
|
|
|
public AssetInventory Get(int id)
|
|
{
|
|
AssetInventory oAssetInventory = null;
|
|
|
|
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
|
|
}
|
|
|
|
return oAssetInventory;
|
|
}
|
|
|
|
public List<AssetInventory> Get()
|
|
{
|
|
List<AssetInventory> AssetInventorys = null;
|
|
|
|
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
|
|
}
|
|
|
|
return AssetInventorys;
|
|
}
|
|
|
|
public List<AssetInventory> GetAllAsset(int assignedUserID, int assignUserID)
|
|
{
|
|
List<AssetInventory> AssetInventorys = new List<AssetInventory>();
|
|
|
|
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
|
|
}
|
|
|
|
|
|
return AssetInventorys;
|
|
}
|
|
|
|
public List<AssetInventory> GetAllAssets(int assignedUserID)
|
|
{
|
|
List<AssetInventory> AssetInventorys = new List<AssetInventory>();
|
|
|
|
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
|
|
}
|
|
|
|
|
|
return AssetInventorys;
|
|
}
|
|
|
|
public List<AssetInventory> GetEmpAssignedNotReceiveConfirm(int employeeid)
|
|
{
|
|
List<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 List<AssetInventory> GetAllAsset(int assignedUserID)
|
|
{
|
|
List<AssetInventory> AssetInventorys = new List<AssetInventory>();
|
|
|
|
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
|
|
}
|
|
|
|
|
|
return AssetInventorys;
|
|
}
|
|
|
|
public List<AssetInventory> GetReceivedItems(int assignUserID)
|
|
{
|
|
List<AssetInventory> AssetInventorys = new List<AssetInventory>();
|
|
|
|
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
|
|
}
|
|
|
|
|
|
return AssetInventorys;
|
|
}
|
|
|
|
public List<AssetInventory> GetAssets(int assignedUserID, bool isEmpConfirmed, int assignUserID)
|
|
{
|
|
List<AssetInventory> AssetInventorys = new List<AssetInventory>();
|
|
|
|
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
|
|
}
|
|
|
|
|
|
return AssetInventorys;
|
|
}
|
|
|
|
public DataSet GetAssetsClearance(int receivedEmpID)
|
|
{
|
|
DataSet assets = new DataSet();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
assets = AssetInventoryDA.GetAssetsClearance(tc, receivedEmpID);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return assets;
|
|
}
|
|
|
|
public List<AssetInventory> GetReturnedItems(int assignUserID)
|
|
{
|
|
List<AssetInventory> AssetInventorys = new List<AssetInventory>();
|
|
|
|
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
|
|
}
|
|
|
|
return AssetInventorys;
|
|
}
|
|
|
|
public int Save(AssetInventory oAssetInventory)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oAssetInventory.IsNew)
|
|
{
|
|
int id = tc.GenerateID("AssetInventory", "AssetInventoryID");
|
|
base.SetObjectID(oAssetInventory, (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 int 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 int 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(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(List<AssetInventory> assetInventories)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (assetInventories.Count > 0)
|
|
{
|
|
AssetInventoryDA.Delete(tc, assetInventories[0].ReceiveEmployeeID,
|
|
assetInventories[0].AssignUserID);
|
|
foreach (AssetInventory assetItem in assetInventories)
|
|
{
|
|
if (assetItem.IsNew)
|
|
{
|
|
int id = tc.GenerateID("AssetInventory", "AssetInventoryID");
|
|
base.SetObjectID(assetItem, 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
|
|
}
|
|
} |