389 lines
10 KiB
C#
389 lines
10 KiB
C#
|
using System;
|
|||
|
using Ease.Core.Model;
|
|||
|
using Ease.Core.DataAccess;
|
|||
|
using Ease.Core.Utility;
|
|||
|
using System.Collections.Generic;
|
|||
|
using HRM.BO;
|
|||
|
|
|||
|
namespace HRM.DA
|
|||
|
{
|
|||
|
#region Asset Service
|
|||
|
|
|||
|
public class AssetService : ServiceTemplate, IAssetService
|
|||
|
{
|
|||
|
public AssetService()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
#region MapObject For Asset
|
|||
|
|
|||
|
private void MapObject(Asset oAsset, DataReader oReader)
|
|||
|
{
|
|||
|
base.SetObjectID(oAsset, oReader.GetInt32("AssetID").Value);
|
|||
|
oAsset.Code = oReader.GetString("Code");
|
|||
|
oAsset.Name = oReader.GetString("Name");
|
|||
|
oAsset.Description = oReader.GetString("Description");
|
|||
|
oAsset.Section = oReader.GetString("Section");
|
|||
|
oAsset.AssignUserNo1 = oReader.GetString("AssignUserNo1");
|
|||
|
oAsset.AssignUserNo2 = oReader.GetString("AssignUserNo2");
|
|||
|
//oAsset.BuyTime = oReader.GetDateTime("BuyTime").Value;
|
|||
|
oAsset.Remarks = oReader.GetString("Remarks",null);
|
|||
|
oAsset.IsLinemanager = oReader.GetBoolean("IsLinemanager").GetValueOrDefault();
|
|||
|
oAsset.BuyPrice = oReader.GetDouble("BuyPrice").Value;
|
|||
|
|
|||
|
//oAsset.DefaultItem = (bool)oReader.GetBoolean("DefaultItem");
|
|||
|
oAsset.AssetType = (EnumAssetInventoryType)oReader.GetInt32("AssetType");
|
|||
|
oAsset.AssetCategoryId = oReader.GetInt32("AssetCategoryId",0);
|
|||
|
oAsset.WarrentyDays = oReader.GetInt32("WarrentyDays", 0);
|
|||
|
oAsset.IsSerailItem = oReader.GetBoolean("IsSerailItem").GetValueOrDefault();
|
|||
|
oAsset.CreatedBy = oReader.GetInt32("CreatedBy").Value;
|
|||
|
oAsset.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|||
|
oAsset.ModifiedBy = oReader.GetInt32("ModifiedBy").GetValueOrDefault();
|
|||
|
oAsset.ModifiedDate = oReader.GetDateTime("ModifiedDate").GetValueOrDefault();
|
|||
|
this.SetObjectState(oAsset, Ease.Core.ObjectState.Saved);
|
|||
|
}
|
|||
|
|
|||
|
protected override T CreateObject<T>(DataReader oReader)
|
|||
|
{
|
|||
|
Asset oAsset = new Asset();
|
|||
|
MapObject(oAsset, oReader);
|
|||
|
return oAsset as T;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Service Implemantation
|
|||
|
|
|||
|
public Asset Get(int id)
|
|||
|
{
|
|||
|
Asset oAsset = null;
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(AssetDA.Get(tc, id));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oAsset = this.CreateObject<Asset>(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 oAsset;
|
|||
|
}
|
|||
|
|
|||
|
public Asset Get(string name)
|
|||
|
{
|
|||
|
Asset oAsset = null;
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(AssetDA.Get(tc, name));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oAsset = this.CreateObject<Asset>(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 oAsset;
|
|||
|
}
|
|||
|
|
|||
|
public List<Asset> Get(Employee oEmployee, EnumAssetInventoryType assetType, bool defaultItem)
|
|||
|
{
|
|||
|
List<Asset> Assets = new List<Asset>();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(AssetDA.Get(tc, oEmployee, assetType, defaultItem));
|
|||
|
Assets = this.CreateObjects<Asset>(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 Assets;
|
|||
|
}
|
|||
|
|
|||
|
public List<Asset> Get(Employee oEmployee)
|
|||
|
{
|
|||
|
List<Asset> Assets = new List<Asset>();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(AssetDA.Get(tc, oEmployee));
|
|||
|
Assets = this.CreateObjects<Asset>(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 Assets;
|
|||
|
}
|
|||
|
|
|||
|
public List<Asset> Get(EnumAssetInventoryType assetType)
|
|||
|
{
|
|||
|
List<Asset> Assets = new List<Asset>();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(AssetDA.Get(tc, assetType));
|
|||
|
Assets = this.CreateObjects<Asset>(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 Assets;
|
|||
|
}
|
|||
|
|
|||
|
public List<Asset> GetLineManagerItem()
|
|||
|
{
|
|||
|
List<Asset> Assets = new List<Asset>();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(AssetDA.GetLineManagerItem(tc));
|
|||
|
Assets = this.CreateObjects<Asset>(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 Assets;
|
|||
|
}
|
|||
|
|
|||
|
public List<Asset> Get()
|
|||
|
{
|
|||
|
List<Asset> assets = new List<Asset>();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(AssetDA.Get(tc));
|
|||
|
assets = this.CreateObjects<Asset>(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 assets;
|
|||
|
}
|
|||
|
|
|||
|
public int Save(Asset oAsset)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
if (oAsset.IsNew)
|
|||
|
{
|
|||
|
int id = tc.GenerateID("Asset", "AssetID");
|
|||
|
base.SetObjectID(oAsset, (id));
|
|||
|
if (oAsset.Code == string.Empty)
|
|||
|
oAsset.Code = GlobalFunctionService.GetMaxCode(tc, "Asset", "Code");
|
|||
|
AssetDA.Insert(tc, oAsset);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
AssetDA.Update(tc, oAsset);
|
|||
|
}
|
|||
|
|
|||
|
return oAsset.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 string GetNextCode()
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
string _code = "";
|
|||
|
string parentCode = string.Empty;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
_code = GlobalFunctionService.GetMaxCode(tc, "Asset", "Code");
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return _code;
|
|||
|
}
|
|||
|
|
|||
|
public void UpdateAssetSpecification(TransactionContext tc,AssetSerial oAssetSerial)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
AssetDA.UpdateAssetSpecification(tc, oAssetSerial);
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public void Delete(int id)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
AssetDA.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();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|