CEL_Payroll/Payroll.BO/HRBasic/HRDoc.cs

283 lines
6.5 KiB
C#
Raw Permalink 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 HRDoc
[Serializable]
public class HRDoc : BasicBaseObject
{
#region Cache Store
private static Cache _cache = new Cache(typeof(HRDoc));
#endregion
#region Constructor
public HRDoc()
{
_code = string.Empty;
_name = string.Empty;
_description = string.Empty;
_parentID = null;
}
#endregion
#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] = "Name can not be empty";
sErrorString[1] = "Name";
return sErrorString;
}
sErrorString = null;
return sErrorString;
}
#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 Description : string
private string _description;
public string Description
{
get { return _description; }
set
{
base.OnPropertyChange<string>("description", _description, value);
_description = value;
}
}
#endregion
#region ParentID : ID
private ID _parentID;
public ID ParentID
{
get { return _parentID; }
set
{
base.OnPropertyChange<ID>("parentID", _parentID, value);
_parentID = value;
}
}
//#region EnumStatus : Enum
//private EnumStatus _status;
//public EnumStatus Status
//{
// get { return _status; }
// set
// {
// base.OnPropertyChange<short>("status",(short) _status,(short) value);
// _status = value;
// }
//}
//#endregion
#endregion
#endregion
#region Service Factory IHRDocService : IHRDocService
internal static IHRDocService Service
{
get { return Services.Factory.CreateService<IHRDocService>(typeof(IHRDocService)); }
}
#endregion
#region Functions
public static HRDoc Get(ID nID)
{
HRDoc oHRDoc = null;
#region Cache Header
oHRDoc = (HRDoc)_cache["Get", nID];
if (oHRDoc != null)
return oHRDoc;
#endregion
oHRDoc = HRDoc.Service.Get(nID);
#region Cache Footer
_cache.Add(oHRDoc, "Get", nID);
#endregion
return oHRDoc;
}
public static ObjectsTemplate<HRDoc> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<HRDoc> hrDocs = _cache["Get"] as ObjectsTemplate<HRDoc>;
if (hrDocs != null)
return hrDocs;
#endregion
try
{
hrDocs = Service.Get();
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(hrDocs, "Get");
#endregion
return hrDocs;
}
public static ObjectsTemplate<HRDoc> GetParent(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<HRDoc> hrDocs = _cache["Get"] as ObjectsTemplate<HRDoc>;
if (hrDocs != null)
return hrDocs;
#endregion
try
{
hrDocs = Service.GetParent(status);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(hrDocs, "Get");
#endregion
return hrDocs;
}
public ID Save()
{
base.SetAuditTrailProperties();
return HRDoc.Service.Save(this);
}
public void Delete(ID id)
{
HRDoc.Service.Delete(id);
}
public static ObjectsTemplate<HRDoc> GetChilds(ID parentID)
{
#region Cache Header
ObjectsTemplate<HRDoc> HRDocs = _cache["GetChilds"] as ObjectsTemplate<HRDoc>;
if (HRDocs != null)
return HRDocs;
#endregion
try
{
HRDocs = Service.GetChilds(parentID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(HRDocs, "GetChilds");
#endregion
return HRDocs;
}
private bool IsExists(string Code)
{
try
{
bool isExists = false;
if (this.Code != null)
{
isExists = HRDoc.Service.IsExists(Code);
}
return isExists;
}
catch (ServiceException e)
{
throw new ServiceException(e.Message, e);
}
}
#endregion
}
#endregion
#region IHRDocService Service
public interface IHRDocService
{
HRDoc Get(ID id);
ObjectsTemplate<HRDoc> Get();
ObjectsTemplate<HRDoc> GetParent(EnumStatus status);
ObjectsTemplate<HRDoc> GetChilds(ID parentID);
ID Save(HRDoc item);
void Delete(ID id);
bool IsExists(string Code);
}
#endregion
}