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 Leave [Serializable] public class Leave : BasicBaseObject { #region Cache Store private static Cache _cache = new Cache(typeof(Leave)); #endregion #region Constructor public Leave() { _sCode = ""; _sDescription = ""; _remarksNeeded = false; _isEarnedLeave = false; _status = EnumStatus.Active; } #endregion #region Properties #region Code private string _sCode; public string Code { get { return _sCode; } set { _sCode = value; } } #endregion #region Description private string _sDescription; public string Description { get { return _sDescription; } set { _sDescription = value; } } #endregion #region RemarksNeeded private bool _remarksNeeded; public bool RemarksNeeded { get { return _remarksNeeded; } set { _remarksNeeded = value; } } #endregion #region DependsOnHoliday private bool _DependsOnHoliday; public bool DependsOnHoliday { get { return _DependsOnHoliday; } set { _DependsOnHoliday = value; } } #endregion #region ApplicableFor : ID private EnumGender _applicableFor; public EnumGender ApplicableFor { get { return _applicableFor; } set { _applicableFor = value; } } public bool IsGenderMatch(Employee oEmployee) { if (this.ApplicableFor == oEmployee.Gender || this.ApplicableFor == EnumGender.Other) return true; else return false; } #endregion #region BalanceCalculationRequired private bool _nBalanceCalculation; public bool IsBalanceCalculationNeeded { get { return _nBalanceCalculation; } set { _nBalanceCalculation = value; } } #endregion #region IsEarnedLeave private bool _isEarnedLeave; public bool IsEarnedLeave { get { return _isEarnedLeave; } set { _isEarnedLeave = value; } } #endregion #region AutoLeaveReason private bool _nAutoLeaveReason; public bool AutoLeaveReason { get { return _nAutoLeaveReason; } set { _nAutoLeaveReason = value; } } private bool _isHalfLeave=false; public bool IsHalfDayLeave { get { return _isHalfLeave; } set { _isHalfLeave = value; } } private bool _isCompensatoryLeave = false; public bool IsCompensatoryLeave { get { return _isCompensatoryLeave; } set { _isCompensatoryLeave = value; } } #endregion #endregion public double CalculateTotalDays(DateTime stDate, DateTime endDate, int locationID) { int nTotalDays = 0; int nCount = 0; TimeSpan oSpan = endDate.Subtract(stDate); nTotalDays = oSpan.Days + 1; return (nTotalDays - nCount); } #region Functions 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.Description == "") { sErrorString[0] = "Description can not be empty"; sErrorString[1] = "Description"; return sErrorString; } if (this.IsCompensatoryLeave && this.IsEarnedLeave ) { sErrorString[0] = "Compensatory Leave and Earned Leave cannot be select together."; sErrorString[1] = "Error"; return sErrorString; } if (this.ID.IsUnassigned) { List oLeaves = Leave.Get(EnumStatus.Active); if (this.IsCompensatoryLeave) { Leave oleave = oLeaves.Find(delegate(Leave ol) { return ol.IsCompensatoryLeave == this.IsCompensatoryLeave; }); if (oleave != null) { sErrorString[0] = "Compensatory Leave already created."; sErrorString[1] = "Error"; return sErrorString; } } if (this.IsEarnedLeave) { Leave oleave = oLeaves.Find(delegate(Leave ol) { return ol.IsEarnedLeave == this.IsEarnedLeave; }); if (oleave != null) { sErrorString[0] = "Earned Leave already created."; sErrorString[1] = "Error"; return sErrorString; } } } sErrorString = null; return sErrorString; } public Leave Get(ID nLeaveID) { Leave oLeave = null; #region Cache Header oLeave = (Leave)_cache["Get", nLeaveID]; if (oLeave != null) return oLeave; #endregion oLeave = Leave.Service.Get(nLeaveID); #region Cache Footer _cache.Add(oLeave, "Get", nLeaveID); #endregion return oLeave; } public Leave GetIDByName(string sLeave) { Leave oLeave = null; #region Cache Header oLeave = (Leave)_cache["Get", sLeave]; if (oLeave != null) return oLeave; #endregion oLeave = Leave.Service.GetIDByName(sLeave); #region Cache Footer _cache.Add(oLeave, "Get", sLeave); #endregion return oLeave; } public Leave GetIDByCode(string sLeave) { Leave oLeave = null; #region Cache Header oLeave = (Leave)_cache["Get", sLeave]; if (oLeave != null) return oLeave; #endregion oLeave = Leave.Service.GetIDByCode(sLeave); #region Cache Footer _cache.Add(oLeave, "Get", sLeave); #endregion return oLeave; } public ID Save() { this.SetAuditTrailProperties(); return Leave.Service.Save(this); } public void Delete(ID id) { Leave.Service.Delete(id); } #endregion #region Collection Functions public static ObjectsTemplate Get(string InParameterID) { ObjectsTemplate Leaves = null; Leaves = Leave.Service.Get(InParameterID); return Leaves; } public static ObjectsTemplate Get() { #region Cache Header ObjectsTemplate Leaves = _cache["Get"] as ObjectsTemplate; if (Leaves != null) return Leaves; #endregion Leaves = Leave.Service.Get(); #region Cache Footer _cache.Add(Leaves, "Get"); #endregion return Leaves; } public static ObjectsTemplate Get(EnumStatus status) { #region Cache Header ObjectsTemplate leaves = _cache["Get", status] as ObjectsTemplate; if (leaves != null) return leaves; #endregion try { leaves = Service.Get(status); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(leaves, "Get", status); #endregion return leaves; } public static ObjectsTemplate GetLeaves() { #region Cache Header ObjectsTemplate leaves = _cache["Get"] as ObjectsTemplate; if (leaves != null) return leaves; #endregion try { leaves = Service.GetLeaves(); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(leaves, "Get"); #endregion return leaves; } #endregion #region Service Factory internal static ILeaveService Service { get { return Services.Factory.CreateService(typeof(ILeaveService)); } } #endregion } #endregion #region ILeave Service public interface ILeaveService { Leave Get(ID id); Leave GetIDByName(string sLeave); Leave GetIDByCode(string sLeave); ObjectsTemplate Get(); ObjectsTemplate Get(string InParameterID); ObjectsTemplate Get(EnumStatus status); ID Save(Leave oLeave); void Delete(ID id); ObjectsTemplate GetLeaves(); } #endregion }