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("code", _code, value); _code = value; } } #endregion #region Name private string _name; public string Name { get { return _name; } set { base.OnPropertyChange("name", _name, value); _name = value; } } #endregion #region OpiType private EnumOpiType _opiType; public EnumOpiType OpiType { get { return _opiType; } set { base.OnPropertyChange("opitype", (short)_opiType, (short)value); _opiType = value; } } #endregion #region Service Factory IOpiItemService : IOpiItemService internal static IOpiItemService Service { get { return Services.Factory.CreateService(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 Get(string opiID) { #region Cache Header ObjectsTemplate opiitems = _cache["Get", opiID] as ObjectsTemplate; 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 Get() { #region Cache Header ObjectsTemplate opiItems = _cache["Get"] as ObjectsTemplate; 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 Get(EnumStatus status) { #region Cache Header ObjectsTemplate opiitems = _cache["Get", status] as ObjectsTemplate; 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 Get(EnumOpiType opiType, EnumStatus status) { #region Cache Header ObjectsTemplate opiitems = _cache["Get", opiType, status] as ObjectsTemplate; 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 Get(string opiID); ObjectsTemplate Get(); ObjectsTemplate Get(EnumStatus status); ObjectsTemplate Get(EnumOpiType opiType, EnumStatus status); ID Save(OpiItem item); string GetNextCode(); void Delete(ID id); } #endregion }