CEL_Payroll/Payroll.BO/Basic/Costcenter.cs
2024-09-17 14:30:13 +06:00

465 lines
12 KiB
C#

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;
using System.Data;
namespace Payroll.BO
{
#region Costcenter
[Serializable]
public class Costcenter : BasicBaseObject
{
#region Cache Store
private static Cache _cache = new Cache(typeof(Costcenter));
#endregion
#region Constructor
#region Input validator
public string[] InputValidator()
{
string[] sErrorString = new string[2];
if (this.Code == "")
{
sErrorString[0] = "Code can not be empty";
sErrorString[1] = "Code";
return sErrorString;
}
if (this.Name == "")
{
sErrorString[0] = "Description can not be empty";
sErrorString[1] = "Description";
return sErrorString;
}
if (this.Tier == 0)
{
sErrorString[0] = "Tier can not be Zero";
sErrorString[1] = "Tier";
return sErrorString;
}
sErrorString = null;
return sErrorString;
}
#endregion
public Costcenter()
{
_code = string.Empty;
_name = string.Empty;
_profitCenterName = string.Empty;
_parentID = null;
_parentsID = string.Empty;
_parent = null;
_tier = 1;
_status = EnumStatus.Active;
}
#endregion
#region Properties
#region code : string
private string _code;
public string Code
{
get { return _code; }
set
{
base.OnPropertyChange<string>("code", _code, value);
_code = value;
}
}
#endregion
#region name : string
private string _name;
public string Name
{
get { return _name; }
set
{
base.OnPropertyChange<string>("name", _name, value);
_name = value;
}
}
#endregion
#region ProfitCenterName : string
private string _profitCenterName;
public string ProfitCenterName
{
get { return _profitCenterName; }
set
{
base.OnPropertyChange<string>("ProfitCenterName", _profitCenterName, value);
_profitCenterName = value;
}
}
#endregion
#region ParentID : ID
private ID _parentID;
public ID ParentID
{
get { return _parentID; }
set
{
base.OnPropertyChange<ID>("ParentID", _parentID, value);
_parentID = value;
}
}
#endregion
#region Tier : int
private int _tier;
public int Tier
{
get { return _tier; }
set
{
base.OnPropertyChange<int>("Tier", _tier, value);
_tier = value;
}
}
#endregion
#region parentsID : string
private string _parentsID;
public string ParentsID
{
get { return _parentsID; }
set
{
base.OnPropertyChange<string>("parentsID", _parentsID, value);
_parentsID = value;
}
}
#endregion
#region costCenter : CostCenter
private Costcenter _parent;
public Costcenter Parent
{
get
{
if (_parentID.Integer > 0 && _parent == null)
{
_parent = new Costcenter();
_parent = Costcenter.Get(_parentID);
}
return this._parent;
}
set
{
_parent = value;
}
}
#endregion
#region Chield : Cost Center
private ObjectsTemplate<Costcenter> _Childs;
public ObjectsTemplate<Costcenter> Childs
{
get
{
if (_Childs == null && !this.ID.IsUnassigned && this.ID.Integer > 0)
{
_Childs = Costcenter.GetChilds(this.ID);
}
return _Childs;
}
set
{
_Childs = value;
}
}
public ObjectsTemplate<ObjectTemplate> PickerChilds
{
get
{
ObjectsTemplate<ObjectTemplate> pChilds = new ObjectsTemplate<ObjectTemplate>();
if (_Childs == null && !this.ID.IsUnassigned && this.ID.Integer > 0)
{
_Childs = Costcenter.GetChilds(this.ID);
if (_Childs != null)
{
foreach (Costcenter cc in _Childs)
{
pChilds.Add(cc);
}
}
}
return pChilds;
}
}
#endregion
#region Service Factory ICostcenterService : ICostcenterService
internal static ICostcenterService Service
{
get { return Services.Factory.CreateService<ICostcenterService>(typeof(ICostcenterService)); }
}
#endregion
#endregion
#region Functions
public static Costcenter Get(ID nID)
{
Costcenter oCostcenter = null;
#region Cache Header
oCostcenter = (Costcenter)_cache["Get", nID];
if (oCostcenter != null)
return oCostcenter;
#endregion
oCostcenter = Costcenter.Service.Get(nID);
#region Cache Footer
_cache.Add(oCostcenter, "Get", nID);
#endregion
return oCostcenter;
}
public static Costcenter Get(string sCode)
{
Costcenter oCostcenter = null;
#region Cache Header
oCostcenter = (Costcenter)_cache["Get", sCode];
if (oCostcenter != null)
return oCostcenter;
#endregion
oCostcenter = Costcenter.Service.Get(sCode);
#region Cache Footer
_cache.Add(oCostcenter, "Get", sCode);
#endregion
return oCostcenter;
}
public static ObjectsTemplate<Costcenter> Get()
{
#region Cache Header
ObjectsTemplate<Costcenter> costcenters = _cache["Get"] as ObjectsTemplate<Costcenter>;
if (costcenters != null)
return costcenters;
#endregion
try
{
costcenters = Service.Get();
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(costcenters, "Get");
#endregion
return costcenters;
}
public static ObjectsTemplate<Costcenter> Get(EnumStatus status,int tier)
{
#region Cache Header
ObjectsTemplate<Costcenter> costcenters = _cache["Get"] as ObjectsTemplate<Costcenter>;
if (costcenters != null)
return costcenters;
#endregion
try
{
costcenters = Service.Get(status, tier);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(costcenters, "Get");
#endregion
return costcenters;
}
public static ObjectsTemplate<Costcenter> GetParents(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<Costcenter> costcenters = _cache["GetParents",status] as ObjectsTemplate<Costcenter>;
if (costcenters != null)
return costcenters;
#endregion
try
{
costcenters = Service.GetParents(status);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(costcenters, "GetParents",status);
#endregion
return costcenters;
}
public static ObjectsTemplate<Costcenter> GetChilds(ID parentID)
{
#region Cache Header
ObjectsTemplate<Costcenter> costcenters = _cache["GetChilds"] as ObjectsTemplate<Costcenter>;
if (costcenters != null)
return costcenters;
#endregion
try
{
costcenters = Service.GetChilds(parentID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(costcenters, "GetChilds");
#endregion
return costcenters;
}
public static ObjectsTemplate<Costcenter> GetByTire(int nTire)
{
#region Cache Header
ObjectsTemplate<Costcenter> costcenters = _cache["GetByTire"] as ObjectsTemplate<Costcenter>;
if (costcenters != null)
return costcenters;
#endregion
try
{
costcenters = Service.GetByTire(nTire);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(costcenters, "GetByTire");
#endregion
return costcenters;
}
public static ObjectsTemplate<Costcenter> GetByTireAndProfitCenter(int nTire, string sProfitCenter)
{
#region Cache Header
ObjectsTemplate<Costcenter> costcenters = _cache["GetByTireAndProfitCenter", nTire, sProfitCenter] as ObjectsTemplate<Costcenter>;
if (costcenters != null)
return costcenters;
#endregion
try
{
costcenters = Service.GetByTireAndProfitCenter(nTire, sProfitCenter);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(costcenters, "GetByTireAndProfitCenter", nTire, sProfitCenter);
#endregion
return costcenters;
}
public ID Save()
{
base.SetAuditTrailProperties();
return Costcenter.Service.Save(this);
}
public void Delete(ID id)
{
Costcenter.Service.Delete(id);
}
#endregion
}
#endregion
#region ICostcenter Service
public interface ICostcenterService
{
Costcenter Get(ID id);
ObjectsTemplate<Costcenter> Get();
ObjectsTemplate<Costcenter> GetParents(EnumStatus status);
ObjectsTemplate<Costcenter> GetChilds(ID parentID);
ObjectsTemplate<Costcenter> GetByTire(int nTire);
ObjectsTemplate<Costcenter> GetByTireAndProfitCenter(int nTire, string sProfitCenter);
ID Save(Costcenter item);
void Delete(ID id);
Costcenter Get(string sCode);
ObjectsTemplate<Costcenter> Get(EnumStatus status, int tier);
}
#endregion
}