CEL_Payroll/Payroll.BO/Basic/Designation.cs

252 lines
6.0 KiB
C#
Raw Normal View History

2024-09-17 14:30:13 +06:00
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 Designation
[Serializable]
public class Designation : BasicBaseObject
{
#region Cache Store
private static Cache _cache = new Cache(typeof(Designation));
#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 Designation()
{
_gradeID = null;
_code = string.Empty;
_name = string.Empty;
_status = EnumStatus.Active;
}
#endregion
#region Properties
#region GradeID : ID
private ID _gradeID;
public ID GradeID
{
get { return _gradeID; }
set
{
base.OnPropertyChange<ID>("GradeID", _gradeID, value);
_gradeID = value;
}
}
#endregion
#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 SapDesCodes : ObjectsTemplate<SAPDesignationCode>
private ObjectsTemplate<SAPDesignationCode> _sapDesCodes;
public ObjectsTemplate<SAPDesignationCode> SapDesCodes
{
get { return _sapDesCodes; }
set
{
_sapDesCodes = value;
}
}
#endregion
#region Service Factory IDesignationService : IDesignationService
internal static IDesignationService Service
{
get { return Services.Factory.CreateService<IDesignationService>(typeof(IDesignationService)); }
}
#endregion
#endregion
#region Functions
public string GetNextCode()
{
return Designation.Service.GetNextCode();
}
public static Designation Get(ID nID)
{
Designation oDesignation = null;
#region Cache Header
oDesignation = (Designation)_cache["Get", nID];
if (oDesignation != null)
return oDesignation;
#endregion
oDesignation = Designation.Service.Get(nID);
#region Cache Footer
_cache.Add(oDesignation, "Get", nID);
#endregion
return oDesignation;
}
public static Designation Get(string sCode)
{
Designation oDesignation = null;
#region Cache Header
oDesignation = (Designation)_cache["Get", sCode];
if (oDesignation != null)
return oDesignation;
#endregion
oDesignation = Designation.Service.Get(sCode);
#region Cache Footer
_cache.Add(oDesignation, "Get", sCode);
#endregion
return oDesignation;
}
public static ObjectsTemplate<Designation> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<Designation> designations = _cache["Get",status] as ObjectsTemplate<Designation>;
if (designations != null)
return designations;
#endregion
try
{
designations = Service.Get(status);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(designations, "Get",status);
#endregion
return designations;
}
public static ObjectsTemplate<Designation> GetWithSapCode(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<Designation> designations = _cache["Get", status] as ObjectsTemplate<Designation>;
if (designations != null)
return designations;
#endregion
try
{
designations = Service.GetWithSapCodes(status);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(designations, "Get", status);
#endregion
return designations;
}
public ID Save()
{
this.SetAuditTrailProperties();
return Designation.Service.Save(this);
}
public void Delete(ID id)
{
Designation.Service.Delete(id);
}
#endregion
}
#endregion
#region IDesignation Service
public interface IDesignationService
{
Designation Get(ID id);
ObjectsTemplate<Designation> Get(EnumStatus status);
ObjectsTemplate<Designation> GetWithSapCodes(EnumStatus status);
ID Save(Designation item);
void Delete(ID id);
Designation Get(string sCode);
string GetNextCode();
}
#endregion
}