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

244 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;
namespace Payroll.BO
{
#region class Thana
[Serializable]
public class Thana : BasicBaseObject
{
#region Cache store
private static Cache _cache = new Cache(typeof(Thana));
#endregion
#region constructor
public Thana()
{
_code = string.Empty;
_name = string.Empty;
_districtID = null;
_status = EnumStatus.Active;
}
#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
#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", _code, value);
_name = value;
}
}
#endregion
#region district ID : int
private ID _districtID;
public ID DistrictID
{
get { return _districtID; }
set { _districtID = value; }
}
#endregion
#region Service Factory IThanaService : IThanaService
internal static IThanaService Service
{
get { return Services.Factory.CreateService<IThanaService>(typeof(IThanaService)); }
}
#endregion
#endregion
#region Function
public static Thana Get(ID nID)
{
Thana oThana = null;
#region Cache Header
oThana = (Thana)_cache["Get", nID];
if (oThana != null)
return oThana;
#endregion
oThana = Thana.Service.Get(nID);
#region Cache Footer
_cache.Add(oThana, "Get", nID);
#endregion
return oThana;
}
public static Thana Get(string sCode)
{
Thana oThana = null;
#region Cache Header
oThana = (Thana)_cache["Get", sCode];
if (oThana != null)
return oThana;
#endregion
oThana = Thana.Service.Get(sCode);
#region Cache Footer
_cache.Add(oThana, "Get", sCode);
#endregion
return oThana;
}
public static ObjectsTemplate<Thana> Get()
{
#region cache header
ObjectsTemplate<Thana> thanas = _cache["Get"] as ObjectsTemplate<Thana>;
if (thanas != null)
return thanas;
#endregion
try
{
thanas = Service.Get();
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region cache footer
_cache.Add(thanas, "Get");
#endregion
return thanas;
}
public static ObjectsTemplate<Thana> GetByDistID(ID nDistID)
{
#region Cache Header
ObjectsTemplate<Thana> thanas = _cache["GetByDistID", nDistID] as ObjectsTemplate<Thana>;
if (thanas != null)
return thanas;
#endregion
try
{
thanas = Service.GetByDistID(nDistID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(thanas, "GetByDistID", nDistID);
#endregion
return thanas;
}
public static ObjectsTemplate<Thana> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<Thana> thanas = _cache["Get", status] as ObjectsTemplate<Thana>;
if (thanas != null)
return thanas;
#endregion
try
{
thanas = Service.Get(status);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(thanas, "Get", status);
#endregion
return thanas;
}
public ID Save()
{
this.SetAuditTrailProperties();
return Thana.Service.Save(this);
}
public void Delete(ID id)
{
Thana.Service.Delete(id);
}
#endregion
}
#endregion
#region IThana Service
public interface IThanaService
{
Thana Get(ID id);
Thana Get(string sCode);
ObjectsTemplate<Thana> Get();
ObjectsTemplate<Thana> GetByDistID(ID nDistID);
ObjectsTemplate<Thana> Get(EnumStatus status);
ID Save(Thana item);
void Delete(ID id);
}
#endregion
}