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

206 lines
4.9 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 Country
[Serializable]
public class Country : BasicBaseObject
{
#region Cache Store
private static Cache _cache = new Cache(typeof(Country));
#endregion
#region constructor
public Country()
{
_code = string.Empty;
_name = string.Empty;
_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 Service Factory ICountryService : ICountryService
internal static ICountryService Service
{
get { return Services.Factory.CreateService<ICountryService>(typeof(ICountryService)); }
}
#endregion
#endregion
#region Function
public static Country Get(ID nID)
{
Country oCountry = null;
#region Cache Header
oCountry = (Country)_cache["Get", nID];
if (oCountry != null)
return oCountry;
#endregion
oCountry = Country.Service.Get(nID);
#region Cache Footer
_cache.Add(oCountry, "Get", nID);
#endregion
return oCountry;
}
public static Country Get(string sCode)
{
Country oCountry = null;
#region Cache Header
oCountry = (Country)_cache["Get", sCode];
if (oCountry != null)
return oCountry;
#endregion
oCountry = Country.Service.Get(sCode);
#region Cache Footer
_cache.Add(oCountry, "Get", sCode);
#endregion
return oCountry;
}
public static ObjectsTemplate<Country> Get()
{
#region cache header
ObjectsTemplate<Country> countries = _cache["Get"] as ObjectsTemplate<Country>;
if (countries != null)
return countries;
#endregion
try
{
countries = Service.Get();
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region cache footer
_cache.Add(countries, "Get");
#endregion
return countries;
}
public static ObjectsTemplate<Country> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<Country> countries = _cache["Get", status] as ObjectsTemplate<Country>;
if (countries != null)
return countries;
#endregion
try
{
countries = Service.Get(status);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(countries, "Get", status);
#endregion
return countries;
}
public ID Save()
{
this.SetAuditTrailProperties();
return Country.Service.Save(this);
}
public void Delete(ID id)
{
Country.Service.Delete(id);
}
#endregion
}
#endregion
#region ICountry Service
public interface ICountryService
{
Country Get(ID id);
Country Get(string sCode);
ObjectsTemplate<Country> Get();
ObjectsTemplate<Country> Get(EnumStatus status);
ID Save(Country item);
void Delete(ID id);
}
#endregion
}