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("code", _code, value); _code = value; } } #endregion #region name : string private string _name; public string Name { get { return _name; } set { base.OnPropertyChange("name", _name, value); _name = value; } } #endregion #region ProfitCenterName : string private string _profitCenterName; public string ProfitCenterName { get { return _profitCenterName; } set { base.OnPropertyChange("ProfitCenterName", _profitCenterName, value); _profitCenterName = value; } } #endregion #region ParentID : ID private ID _parentID; public ID ParentID { get { return _parentID; } set { base.OnPropertyChange("ParentID", _parentID, value); _parentID = value; } } #endregion #region Tier : int private int _tier; public int Tier { get { return _tier; } set { base.OnPropertyChange("Tier", _tier, value); _tier = value; } } #endregion #region parentsID : string private string _parentsID; public string ParentsID { get { return _parentsID; } set { base.OnPropertyChange("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 _Childs; public ObjectsTemplate Childs { get { if (_Childs == null && !this.ID.IsUnassigned && this.ID.Integer > 0) { _Childs = Costcenter.GetChilds(this.ID); } return _Childs; } set { _Childs = value; } } public ObjectsTemplate PickerChilds { get { ObjectsTemplate pChilds = new ObjectsTemplate(); 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(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 Get() { #region Cache Header ObjectsTemplate costcenters = _cache["Get"] as ObjectsTemplate; 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 Get(EnumStatus status,int tier) { #region Cache Header ObjectsTemplate costcenters = _cache["Get"] as ObjectsTemplate; 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 GetParents(EnumStatus status) { #region Cache Header ObjectsTemplate costcenters = _cache["GetParents",status] as ObjectsTemplate; 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 GetChilds(ID parentID) { #region Cache Header ObjectsTemplate costcenters = _cache["GetChilds"] as ObjectsTemplate; 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 GetByTire(int nTire) { #region Cache Header ObjectsTemplate costcenters = _cache["GetByTire"] as ObjectsTemplate; 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 GetByTireAndProfitCenter(int nTire, string sProfitCenter) { #region Cache Header ObjectsTemplate costcenters = _cache["GetByTireAndProfitCenter", nTire, sProfitCenter] as ObjectsTemplate; 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 Get(); ObjectsTemplate GetParents(EnumStatus status); ObjectsTemplate GetChilds(ID parentID); ObjectsTemplate GetByTire(int nTire); ObjectsTemplate GetByTireAndProfitCenter(int nTire, string sProfitCenter); ID Save(Costcenter item); void Delete(ID id); Costcenter Get(string sCode); ObjectsTemplate Get(EnumStatus status, int tier); } #endregion }