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 Location [Serializable] public class Location : BasicBaseObject { #region Cache Store private static Cache _cache = new Cache(typeof(Location)); #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; } sErrorString = null; return sErrorString; } #endregion public Location() { _code = string.Empty; _name = string.Empty; _parentID = null; _parentsID = string.Empty; _tier = 1; _parent = null; _Childs = null; _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 ParentID : ID private ID _parentID; public ID ParentID { get { return _parentID; } set { base.OnPropertyChange("ParentID", _parentID, value); _parentID = value; } } #endregion #region parentsID : string private string _parentsID; public string ParentsID { get { return _parentsID; } set { base.OnPropertyChange("parentsID", _parentsID, value); _parentsID = value; } } #endregion #region Tier : int private int _tier; public int Tier { get { return _tier; } set { base.OnPropertyChange("Tier", _tier, value); _tier = value; } } #endregion #region parent : Location private Location _parent; public Location Parent { get { if (_parentID.Integer > 0 && _parent == null) { _parent = new Location(); _parent = Location.Get(_parentID); } return this._parent; } set { _parent = value; } } #endregion #region Chield : Department private ObjectsTemplate _Childs; public ObjectsTemplate Childs { get { if (_Childs == null && !this.ID.IsUnassigned && this.ID.Integer > 0) { _Childs = Location.GetChilds(this.ID); } return _Childs; } set { _Childs = value; } } public static ObjectsTemplate GetChilds(ID parentID) { #region Cache Header ObjectsTemplate locations = _cache["GetChilds", parentID] as ObjectsTemplate; if (locations != null) return locations; #endregion try { locations = Service.GetChield(parentID); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(locations, "GetChilds", parentID); #endregion return locations; } public ObjectsTemplate PickerChilds { get { ObjectsTemplate pChilds = new ObjectsTemplate(); if (_Childs == null && !this.ID.IsUnassigned && this.ID.Integer > 0) { _Childs = Location.GetChilds(this.ID); if (_Childs != null) { foreach (Location dpt in _Childs) { pChilds.Add(dpt); } } } return pChilds; } } #endregion #region Service Factory ILocationService : ILocationService internal static ILocationService Service { get { return Services.Factory.CreateService(typeof(ILocationService)); } } #endregion #endregion #region Functions public string GetNextCode(int nteir, int ParentId) { if (nteir == 1 && ParentId == 0) { return Location.Service.GetNextCode(nteir); } else { return Location.Service.GetNextCode(nteir, GetParentCode(ParentId)); } } public string GetParentCode(int parentId) { return Location.Service.Get(ID.FromInteger(parentId)).Code.ToString(); } public static Location Get(ID nID) { Location oLocation = null; #region Cache Header oLocation = (Location)_cache["Get", nID]; if (oLocation != null) return oLocation; #endregion oLocation = Location.Service.Get(nID); #region Cache Footer _cache.Add(oLocation, "Get", nID); #endregion return oLocation; } public static Location Get(string sCode) { Location oLocation = null; #region Cache Header oLocation = (Location)_cache["Get", sCode]; if (oLocation != null) return oLocation; #endregion oLocation = Location.Service.Get(sCode); #region Cache Footer _cache.Add(oLocation, "Get", sCode); #endregion return oLocation; } public static ObjectsTemplate Get() { #region Cache Header ObjectsTemplate locations = _cache["Get"] as ObjectsTemplate; if (locations != null) return locations; #endregion try { locations = Service.Get(); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(locations, "Get"); #endregion return locations; } public static ObjectsTemplate GetParents(EnumStatus status) { #region Cache Header ObjectsTemplate locations = _cache["GetParents"] as ObjectsTemplate; if (locations != null) return locations; #endregion try { locations = Service.GetParents(status); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(locations, "GetParents"); #endregion return locations; } public static ObjectsTemplate GetByTier(int tier) { #region Cache Header ObjectsTemplate locations = _cache["GetByTier", tier] as ObjectsTemplate; if (locations != null) return locations; #endregion try { locations = Service.GetByTier(tier); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(locations, "GetByTier", tier); #endregion return locations; } public static ObjectsTemplate Get(EnumStatus sts) { ObjectsTemplate locations = null; try { locations = Service.Get(sts); } catch (ServiceException e) { throw new Exception(e.Message, e); } return locations; } public static ObjectsTemplate GetForJV(DateTime dSalaryMonth) { ObjectsTemplate locations = null; try { locations = Service.GetForJV(dSalaryMonth, SystemInformation.CurrentSysInfo.PayrollTypeID); } catch (ServiceException e) { throw new Exception(e.Message, e); } return locations; } public ID Save() { this.SetAuditTrailProperties(); return Location.Service.Save(this); } public void Delete(ID id) { Location.Service.Delete(id); } #endregion } #endregion #region ILocation Service public interface ILocationService { Location Get(ID id); ObjectsTemplate Get(); ObjectsTemplate GetParents(EnumStatus status); ObjectsTemplate GetByTier(int tier); ID Save(Location item); void Delete(ID id); ObjectsTemplate GetChield(ID parentID); Location Get(string sCode); ObjectsTemplate Get(EnumStatus sts); ObjectsTemplate GetForJV(DateTime dJVMonth, ID PayrollTypeID); string GetNextCode(int tier, string parentcode); string GetNextCode(int nteir); } #endregion }