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

447 lines
11 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;
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<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 ParentID : ID
private ID _parentID;
public ID ParentID
{
get { return _parentID; }
set
{
base.OnPropertyChange<ID>("ParentID", _parentID, value);
_parentID = 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 Tier : int
private int _tier;
public int Tier
{
get { return _tier; }
set
{
base.OnPropertyChange<int>("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<Location> _Childs;
public ObjectsTemplate<Location> 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<Location> GetChilds(ID parentID)
{
#region Cache Header
ObjectsTemplate<Location> locations = _cache["GetChilds", parentID] as ObjectsTemplate<Location>;
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<ObjectTemplate> PickerChilds
{
get
{
ObjectsTemplate<ObjectTemplate> pChilds = new ObjectsTemplate<ObjectTemplate>();
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<ILocationService>(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<Location> Get()
{
#region Cache Header
ObjectsTemplate<Location> locations = _cache["Get"] as ObjectsTemplate<Location>;
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<Location> GetParents(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<Location> locations = _cache["GetParents"] as ObjectsTemplate<Location>;
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<Location> GetByTier(int tier)
{
#region Cache Header
ObjectsTemplate<Location> locations = _cache["GetByTier", tier] as ObjectsTemplate<Location>;
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<Location> Get(EnumStatus sts)
{
ObjectsTemplate<Location> locations = null;
try
{
locations = Service.Get(sts);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
return locations;
}
public static ObjectsTemplate<Location> GetForJV(DateTime dSalaryMonth)
{
ObjectsTemplate<Location> 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<Location> Get();
ObjectsTemplate<Location> GetParents(EnumStatus status);
ObjectsTemplate<Location> GetByTier(int tier);
ID Save(Location item);
void Delete(ID id);
ObjectsTemplate<Location> GetChield(ID parentID);
Location Get(string sCode);
ObjectsTemplate<Location> Get(EnumStatus sts);
ObjectsTemplate<Location> GetForJV(DateTime dJVMonth, ID PayrollTypeID);
string GetNextCode(int tier, string parentcode);
string GetNextCode(int nteir);
}
#endregion
}