CEL_Payroll/Payroll.BO/Assets/Asset.cs

470 lines
11 KiB
C#
Raw Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35;
using Ease.CoreV35.Model;
using Ease.CoreV35.Caching;
using System.Data.Linq.Mapping;
namespace Payroll.BO
{
#region Asset
[Serializable]
public class Asset : BasicBaseObject
{
public delegate void ItemChanged();
#region Cache Store
private static Cache _cache = new Cache(typeof(Asset));
#endregion
#region Constructor
public Asset()
{
_sCode = string.Empty;
_sName = string.Empty;
_sdescription = string.Empty;
_buyTime = DateTime.Now;
_sRemarks = string.Empty;
_sIsUsing = false;
_dBuyPrice = 0;
_sSection=string.Empty;
_sAssignUserId1 = null;
_sAssignUserId2 = null;
_status = EnumStatus.Active;
_IsLinemanager = false;
_assetType = EnumAssetInventoryType.Asset;
_defaultItem = false;
}
#endregion
#region Input validator
public string[] InputValidator()
{
string[] sErrorString = new string[2];
if (this.Name == "")
{
sErrorString[0] = "Description can not be empty";
sErrorString[1] = "Description";
return sErrorString;
}
if(this.BuyPrice == 0)
{
sErrorString[0] = "Buy Price can not be empty";
sErrorString[1] = "BuyPrice";
return sErrorString;
}
sErrorString = null;
return sErrorString;
}
#endregion
#region Properties
#region Code : string
private string _sCode;
public string Code
{
get { return _sCode; }
set
{
base.OnPropertyChange<string>("code", _sCode, value);
_sCode = value;
}
}
#endregion
#region Name : string
private string _sName;
public string Name
{
get { return _sName; }
set
{
base.OnPropertyChange<string>("name", _sName, value);
_sName = value;
}
}
#endregion
#region Section : string
private string _sSection;
public string Section
{
get { return _sSection; }
set
{
base.OnPropertyChange<string>("Section", _sSection, value);
_sSection = value;
}
}
#endregion
#region AssignUserNo1 : string
private ID _sAssignUserId1;
public ID AssignUserId1
{
get {
return _sAssignUserId1;
}
set
{
base.OnPropertyChange<ID>("AssignUserId1", _sAssignUserId1, value);
_sAssignUserId1 = value;
}
}
#endregion
#region AssignUserNo2 : string
private ID _sAssignUserId2;
public ID AssignUserId2
{
get { return _sAssignUserId2; }
set
{
base.OnPropertyChange<ID>("AssignUserId2", _sAssignUserId2, value);
_sAssignUserId2 = value;
}
}
#endregion
#region IsLinemanager : bool
private bool _IsLinemanager;
public bool IsLinemanager
{
get { return _IsLinemanager; }
set { _IsLinemanager = value; }
}
#endregion
#region Description : string
private string _sdescription;
public string Description
{
get { return _sdescription; }
set
{
base.OnPropertyChange<string>("Description", _sdescription, value);
_sdescription = value;
}
}
#endregion
#region BuyTime : DateTime
private DateTime _buyTime;
public DateTime BuyTime
{
get { return _buyTime; }
set
{
base.OnPropertyChange<DateTime>("buyTime", _buyTime, value);
_buyTime = value;
}
}
#endregion
#region Remarks : string
private string _sRemarks;
public string Remarks
{
get { return _sRemarks; }
set
{
base.OnPropertyChange<string>("remarks", _sRemarks, value);
_sRemarks = value;
}
}
#endregion
#region IsUsing : Boolean
private bool _sIsUsing;
public bool IsUsing
{
get { return _sIsUsing; }
set
{
base.OnPropertyChange<bool>("isUsing", _sIsUsing, value);
_sIsUsing = value;
}
}
#endregion
#region BuyPrice: Double
private double _dBuyPrice;
public double BuyPrice
{
get { return _dBuyPrice; }
set
{
base.OnPropertyChange<double>("buyPrice", _dBuyPrice, value);
_dBuyPrice = value;
}
}
#endregion
private EnumAssetInventoryType _assetType;
public EnumAssetInventoryType AssetType
{
get
{
return _assetType;
}
set
{
_assetType = value;
}
}
private bool _defaultItem;
public bool DefaultItem
{
get
{
return _defaultItem;
}
set
{
_defaultItem = value;
}
}
private Employee _employee;
public Employee ClearanceEmployee
{
get
{
if (this.AssignUserId1 != null && _employee==null)
_employee = Employee.Get(this.AssignUserId1);
else if (this.AssignUserId2 != null && _employee == null)
_employee = Employee.Get(this.AssignUserId2);
return _employee;
}
}
#endregion
#region Service Factory IAssetService : IAssetService
internal static IAssetService Service
{
get { return Services.Factory.CreateService<IAssetService>(typeof(IAssetService)); }
}
#endregion
#region Functions
public static Asset Get(ID nID)
{
Asset asset = null;
#region Cache Header
asset = (Asset)_cache["Get", nID];
if (asset != null)
return asset;
#endregion
asset = Asset.Service.Get(nID);
#region Cache Footer
_cache.Add(asset, "Get", nID);
#endregion
return asset;
}
public static Asset Get(string name)
{
Asset asset = null;
#region Cache Header
asset = (Asset)_cache["Get", name];
if (asset != null)
return asset;
#endregion
asset = Asset.Service.Get(name);
#region Cache Footer
_cache.Add(asset, "Get", name);
#endregion
return asset;
}
public static ObjectsTemplate<Asset> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<Asset> assets = _cache["Get"] as ObjectsTemplate<Asset>;
if (assets != null)
return assets;
#endregion
try
{
assets = Asset.Service.Get();
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(assets, "Get");
#endregion
return assets;
}
public static ObjectsTemplate<Asset> Get()
{
#region Cache Header
ObjectsTemplate<Asset> assets = _cache["Get"] as ObjectsTemplate<Asset>;
if (assets != null)
return assets;
#endregion
try
{
assets = Asset.Service.Get();
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(assets, "Get");
#endregion
return assets;
}
public ID Save()
{
base.SetAuditTrailProperties();
return Asset.Service.Save(this);
}
public void Delete(ID id)
{
Asset.Service.Delete(id);
}
public static ObjectsTemplate<Asset> Get(EnumAssetInventoryType assetType)
{
ObjectsTemplate<Asset> assets = null;
if (assets != null)
return assets;
try
{
assets = Asset.Service.Get(assetType);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
return assets;
}
public static ObjectsTemplate<Asset> Get(Employee oEmployee, EnumAssetInventoryType assetType, bool defaultItem)
{
ObjectsTemplate<Asset> assets = null;
if (assets != null)
return assets;
try
{
assets = Asset.Service.Get(oEmployee, assetType, defaultItem);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
return assets;
}
public static ObjectsTemplate<Asset> Get(Employee oEmployee, EnumAssetInventoryType assetType)
{
ObjectsTemplate<Asset> assets = null;
if (assets != null)
return assets;
try
{
assets = Asset.Service.Get(oEmployee, assetType);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
return assets;
}
public static ObjectsTemplate<Asset> GetLineManagerItem()
{
ObjectsTemplate<Asset> assets = null;
if (assets != null)
return assets;
try
{
assets = Asset.Service.GetLineManagerItem();
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
return assets;
}
#endregion
}
#endregion
#region IAssetService
public interface IAssetService
{
Asset Get(ID id);
Asset Get(string name);
ObjectsTemplate<Asset> Get();
ObjectsTemplate<Asset> Get(EnumAssetInventoryType assetType);
ObjectsTemplate<Asset> Get(Employee oEmployee, EnumAssetInventoryType assetType, bool defaultItem);
ObjectsTemplate<Asset> Get(Employee oEmployee, EnumAssetInventoryType assetType);
ObjectsTemplate<Asset> GetLineManagerItem();
ID Save(Asset item);
void Delete(ID id);
}
#endregion
}