CEL_Payroll/Payroll.BO/OPI/OpiItem.cs

271 lines
6.7 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
{
[Serializable]
public enum EnumOpiAvgPayType
{
NONE = 0,
OT = 1,
Allowance = 2,
Deduction = 3
}
#region OpiItem
[Serializable]
public class OpiItem : BasicBaseObject
{
#region Cache Store
private static Cache _cache = new Cache(typeof(OpiItem));
#endregion
#region Constructor
public OpiItem()
{
_code = string.Empty;
_name = string.Empty;
_opiType = EnumOpiType.Provision;
Status = EnumStatus.Active;
}
#endregion
#region Properties
#region Code
private string _code;
public string Code
{
get
{
return _code;
}
set
{
base.OnPropertyChange<string>("code", _code, value);
_code = value;
}
}
#endregion
#region Name
private string _name;
public string Name
{
get
{
return _name;
}
set
{
base.OnPropertyChange<string>("name", _name, value);
_name = value;
}
}
#endregion
#region OpiType
private EnumOpiType _opiType;
public EnumOpiType OpiType
{
get
{
return _opiType;
}
set
{
base.OnPropertyChange<short>("opitype", (short)_opiType, (short)value);
_opiType = value;
}
}
#endregion
#region Service Factory IOpiItemService : IOpiItemService
internal static IOpiItemService Service
{
get
{
return Services.Factory.CreateService<IOpiItemService>(typeof(IOpiItemService));
}
}
#endregion
#endregion
#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.Name == "")
{
sErrorString[0] = "Description can not be empty";
sErrorString[1] = "Description";
return sErrorString;
}
sErrorString = null;
return sErrorString;
}
public string GetNextCode()
{
return OpiItem.Service.GetNextCode();
}
public static OpiItem Get(ID nOpiItemID)
{
OpiItem oOpiItem = null;
#region Cache Header
oOpiItem = (OpiItem)_cache["Get", nOpiItemID];
if (oOpiItem != null)
return oOpiItem;
#endregion
oOpiItem = OpiItem.Service.Get(nOpiItemID);
#region Cache Footer
_cache.Add(oOpiItem, "Get", nOpiItemID);
#endregion
return oOpiItem;
}
internal static ObjectsTemplate<OpiItem> Get(string opiID)
{
#region Cache Header
ObjectsTemplate<OpiItem> opiitems = _cache["Get", opiID] as ObjectsTemplate<OpiItem>;
if (opiitems != null)
return opiitems;
#endregion
try
{
opiitems = Service.Get(opiID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(opiitems, "Get", opiID);
#endregion
return opiitems;
}
public static ObjectsTemplate<OpiItem> Get()
{
#region Cache Header
ObjectsTemplate<OpiItem> opiItems = _cache["Get"] as ObjectsTemplate<OpiItem>;
if (opiItems != null)
return opiItems;
#endregion
try
{
opiItems = Service.Get();
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(opiItems, "Get");
#endregion
return opiItems;
}
public static ObjectsTemplate<OpiItem> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<OpiItem> opiitems = _cache["Get", status] as ObjectsTemplate<OpiItem>;
if (opiitems != null)
return opiitems;
#endregion
try
{
opiitems = Service.Get(status);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(opiitems, "Get", status);
#endregion
return opiitems;
}
public static ObjectsTemplate<OpiItem> Get(EnumOpiType opiType, EnumStatus status)
{
#region Cache Header
ObjectsTemplate<OpiItem> opiitems = _cache["Get", opiType, status] as ObjectsTemplate<OpiItem>;
if (opiitems != null)
return opiitems;
#endregion
try
{
opiitems = Service.Get(opiType, status);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(opiitems, "Get", opiType, status);
#endregion
return opiitems;
}
public ID Save()
{
this.SetAuditTrailProperties();
return OpiItem.Service.Save(this);
}
public void Delete(ID id)
{
if(id.Integer!=21)
OpiItem.Service.Delete(id);
}
#endregion
}
#endregion
#region IOpiItem Service
public interface IOpiItemService
{
OpiItem Get(ID id);
ObjectsTemplate<OpiItem> Get(string opiID);
ObjectsTemplate<OpiItem> Get();
ObjectsTemplate<OpiItem> Get(EnumStatus status);
ObjectsTemplate<OpiItem> Get(EnumOpiType opiType, EnumStatus status);
ID Save(OpiItem item);
string GetNextCode();
void Delete(ID id);
}
#endregion
}