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

236 lines
5.7 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;
using System.Data;
namespace Payroll.BO
{
#region Bonus
[Serializable]
public class Bonus : BasicBaseObject
{
#region Cache Store
private static Cache _cache = new Cache(typeof(Bonus));
#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 Bonus()
{
_code = string.Empty;
_name = string.Empty;
_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 Service Factory IBonusService : IBonusService
internal static IBonusService Service
{
get { return Services.Factory.CreateService<IBonusService>(typeof(IBonusService)); }
}
#endregion
#endregion
#region Functions
public static Bonus Get(ID nID)
{
Bonus oBonus = null;
#region Cache Header
oBonus = (Bonus)_cache["Get", nID];
if (oBonus != null)
return oBonus;
#endregion
oBonus = Bonus.Service.Get(nID);
#region Cache Footer
_cache.Add(oBonus, "Get", nID);
#endregion
return oBonus;
}
public static ObjectsTemplate<Bonus> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<Bonus> bonus = _cache["Get",status] as ObjectsTemplate<Bonus>;
if (bonus != null)
return bonus;
#endregion
try
{
bonus = Service.Get(status);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(bonus, "Get",status);
#endregion
return bonus;
}
public static DataTable GetOldBonus()
{
#region Cache Header
DataTable dtBonuses = _cache["GetOldBonus"] as DataTable;
if (dtBonuses != null)
return dtBonuses;
#endregion
try
{
dtBonuses = Service.GetOldBonus(SystemInformation.CurrentSysInfo.PayrollTypeID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(dtBonuses, "GetOldBonus");
#endregion
return dtBonuses;
}
public static ObjectsTemplate<Bonus> GetActiveProccessedBonus(DateTime bonusMonth)
{
ObjectsTemplate<Bonus> bonuses = new ObjectsTemplate<Bonus>();
try
{
bonuses = Service.GetActiveProccessedBonus(SystemInformation.CurrentSysInfo.PayrollTypeID.Integer, bonusMonth);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
return bonuses;
}
public static DataTable GetOldActiveProccessedBonus(DateTime bonusMonth)
{
DataTable dtbonuses = null;
try
{
dtbonuses = Service.GetOldActiveProccessedBonus(SystemInformation.CurrentSysInfo.PayrollTypeID.Integer, bonusMonth);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
return dtbonuses;
}
public string GetNextCode()
{
return Bonus.Service.GetNextCode();
}
public ID Save()
{
this.SetAuditTrailProperties();
return Bonus.Service.Save(this);
}
public void Delete(ID id)
{
Bonus.Service.Delete(id);
}
#endregion
}
#endregion
#region IBonus Service
public interface IBonusService
{
Bonus Get(ID id);
ObjectsTemplate<Bonus> Get(EnumStatus status);
DataTable GetOldBonus(ID payrollTypeID);
ObjectsTemplate<Bonus> GetActiveProccessedBonus(int payrollTypeID, DateTime bonusMonth);
DataTable GetOldActiveProccessedBonus(int payrollTypeID, DateTime bonusMonth);
ID Save(Bonus item);
void Delete(ID id);
string GetNextCode();
}
#endregion
}