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

266 lines
7.2 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 Leave Entry
[Serializable]
public class LeaveYear : BasicBaseObject
{
#region Cache Store
private static Cache _cache = new Cache(typeof(LeaveYear));
#endregion
#region Constructor
public LeaveYear()
{
_name = "";
_startDate = DateTime.Now.Date;
_endDate = DateTime.Now.Date;
_benYearStartDate = DateTime.Now.Date;
_benYearEndDate = DateTime.Now.Date;
_IsEnded = false;
_IsCurrent = false;
_status = EnumStatus.Inactive;
}
#endregion
#region Properties
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
private DateTime _startDate;
public DateTime StartDate
{
get { return _startDate; }
set { _startDate = value; }
}
private DateTime _endDate;
public DateTime EndDate
{
get { return _endDate; }
set { _endDate = value; }
}
private DateTime _benYearStartDate;
public DateTime BenYearStartDate
{
get { return _benYearStartDate; }
set { _benYearStartDate = value; }
}
private DateTime _benYearEndDate;
public DateTime BenYearEndDate
{
get { return _benYearEndDate; }
set { _benYearEndDate = value; }
}
private bool _IsEnded;
public bool IsEnded
{
get { return _IsEnded; }
set { _IsEnded = value; }
}
private bool _IsCurrent;
public bool IsCurrent
{
get { return _IsCurrent; }
set { _IsCurrent = value; }
}
#endregion
#region Methods
public string[] InputValidator()
{
DateTime dt1 = this.StartDate;
DateTime dt2 = this.EndDate;
LeaveYear currentYear = GetCurrentYear();
string[] sErrorString = new string[2];
if (currentYear != null)
{
DateTime dtt1 = currentYear.StartDate;
DateTime dtt2 = currentYear.EndDate;
if (this.IsCurrent == true && currentYear != null)
{
if (dt1 != dtt1 && dt2 != dtt2)
{
sErrorString[0] = "More than one current year is not allowed";
sErrorString[1] = "IsCurrent";
return sErrorString;
}
}
}
sErrorString = null;
return sErrorString;
}
public int CountCurrentYear()
{
int curYear = 0;
curYear = LeaveYear.Service.CountCurrentYear();
return curYear;
}
public LeaveYear Get(ID id)
{
LeaveYear oLeaveYear = null;
#region Cache Header
oLeaveYear = (LeaveYear)_cache["Get", id.Integer];
if (oLeaveYear != null)
{
return oLeaveYear;
}
#endregion
oLeaveYear = LeaveYear.Service.Get(id);
#region Cache Footer
_cache.Add(oLeaveYear, "Get", id.Integer);
#endregion
return oLeaveYear;
}
public static LeaveYear GetCurrentYear()
{
LeaveYear oLeaveYear = null;
oLeaveYear = LeaveYear.Service.GetCurrentYear();
return oLeaveYear;
}
public static LeaveYear GetCurrentYear(string year)
{
LeaveYear oLeaveYear = null;
oLeaveYear = LeaveYear.Service.GetCurrentYear(year);
return oLeaveYear;
}
public static LeaveYear LastLeaveYear(LeaveYear oCurrYear)
{
ObjectsTemplate<LeaveYear> olYears = LeaveYear.Service.Get();
foreach (LeaveYear oItem in olYears)
{
if (oItem.EndDate.AddDays(1) == oCurrYear.StartDate)
{
return oItem;
}
}
return null;
}
public LeaveYear GetIDByName(string sLeaveYear)
{
LeaveYear oLeaveayear = null;
#region Cache Header
oLeaveayear = (LeaveYear)_cache["Get", sLeaveYear];
if (oLeaveayear != null)
return oLeaveayear;
#endregion
oLeaveayear = LeaveYear.Service.GetIDByName(sLeaveYear);
#region Cache Footer
_cache.Add(oLeaveayear, "Get", sLeaveYear);
#endregion
return oLeaveayear;
}
public ID Save()
{
this.Name = this.StartDate.ToString("dd MMM yyyy") + " - " + this.EndDate.ToString("dd MMM yyyy");
this.IsEnded = false;
this.SetAuditTrailProperties();
return LeaveYear.Service.Save(this);
}
public void Delete(ID id)
{
LeaveYear.Service.Delete(id);
}
#endregion
#region Collection Methods
public static ObjectsTemplate<LeaveYear> Get()
{
#region Cache Header
ObjectsTemplate<LeaveYear> oLeaveYears = _cache["Get"] as ObjectsTemplate<LeaveYear>;
if (oLeaveYears != null)
return oLeaveYears;
#endregion
oLeaveYears = LeaveYear.Service.Get();
#region Cache Footer
_cache.Add(oLeaveYears, "Get");
#endregion
return oLeaveYears;
}
public static ObjectsTemplate<LeaveYear> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<LeaveYear> leaveYears = _cache["Get", status] as ObjectsTemplate<LeaveYear>;
if (leaveYears != null)
return leaveYears;
#endregion
try
{
leaveYears = Service.Get(status);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(leaveYears, "Get", status);
#endregion
return leaveYears;
}
#endregion
#region Service Factory
internal static ILeaveYearService Service
{
get { return Services.Factory.CreateService<ILeaveYearService>(typeof(ILeaveYearService)); }
}
#endregion
}
#endregion
#region ILeaveYear Service
public interface ILeaveYearService
{
LeaveYear Get(ID id);
LeaveYear GetCurrentYear(string year);
ObjectsTemplate<LeaveYear> Get();
ObjectsTemplate<LeaveYear> Get(EnumStatus status);
ID Save(LeaveYear oLeaveYear);
void Delete(ID id);
int CountCurrentYear();
LeaveYear GetCurrentYear();
//void UpdateYearEndValue();
LeaveYear GetIDByName(string sLeaveYear);
}
#endregion
}