CEL_Payroll/Payroll.BO/CarFuel/CarFuelItem.cs

271 lines
7.0 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
{
[Serializable]
public enum EnumCarFuelAvgPayType
{
NONE = 0,
OT = 1,
Allowance = 2,
Deduction = 3
}
#region CarFuelItem
[Serializable]
public class CarFuelItem : BasicBaseObject
{
#region Cache Store
private static Cache _cache = new Cache(typeof(CarFuelItem));
#endregion
#region Constructor
public CarFuelItem()
{
_code = string.Empty;
_name = string.Empty;
_CarFuelType = EnumCarFuelType.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 CarFuelType
private EnumCarFuelType _CarFuelType;
public EnumCarFuelType CarFuelType
{
get
{
return _CarFuelType;
}
set
{
base.OnPropertyChange<short>("CarFueltype", (short)_CarFuelType, (short)value);
_CarFuelType = value;
}
}
#endregion
#region Service Factory ICarFuelItemService : ICarFuelItemService
internal static ICarFuelItemService Service
{
get
{
return Services.Factory.CreateService<ICarFuelItemService>(typeof(ICarFuelItemService));
}
}
#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 CarFuelItem.Service.GetNextCode();
}
public static CarFuelItem Get(ID nCarFuelItemID)
{
CarFuelItem oCarFuelItem = null;
#region Cache Header
oCarFuelItem = (CarFuelItem)_cache["Get", nCarFuelItemID];
if (oCarFuelItem != null)
return oCarFuelItem;
#endregion
oCarFuelItem = CarFuelItem.Service.Get(nCarFuelItemID);
#region Cache Footer
_cache.Add(oCarFuelItem, "Get", nCarFuelItemID);
#endregion
return oCarFuelItem;
}
internal static ObjectsTemplate<CarFuelItem> Get(string CarFuelID)
{
#region Cache Header
ObjectsTemplate<CarFuelItem> CarFuelitems = _cache["Get", CarFuelID] as ObjectsTemplate<CarFuelItem>;
if (CarFuelitems != null)
return CarFuelitems;
#endregion
try
{
CarFuelitems = Service.Get(CarFuelID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(CarFuelitems, "Get", CarFuelID);
#endregion
return CarFuelitems;
}
public static ObjectsTemplate<CarFuelItem> Get()
{
#region Cache Header
ObjectsTemplate<CarFuelItem> CarFuelItems = _cache["Get"] as ObjectsTemplate<CarFuelItem>;
if (CarFuelItems != null)
return CarFuelItems;
#endregion
try
{
CarFuelItems = Service.Get();
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(CarFuelItems, "Get");
#endregion
return CarFuelItems;
}
public static ObjectsTemplate<CarFuelItem> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<CarFuelItem> CarFuelitems = _cache["Get", status] as ObjectsTemplate<CarFuelItem>;
if (CarFuelitems != null)
return CarFuelitems;
#endregion
try
{
CarFuelitems = Service.Get(status);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(CarFuelitems, "Get", status);
#endregion
return CarFuelitems;
}
public static ObjectsTemplate<CarFuelItem> Get(EnumCarFuelType CarFuelType, EnumStatus status)
{
#region Cache Header
ObjectsTemplate<CarFuelItem> CarFuelitems = _cache["Get", CarFuelType, status] as ObjectsTemplate<CarFuelItem>;
if (CarFuelitems != null)
return CarFuelitems;
#endregion
try
{
CarFuelitems = Service.Get(CarFuelType, status);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(CarFuelitems, "Get", CarFuelType, status);
#endregion
return CarFuelitems;
}
public ID Save()
{
this.SetAuditTrailProperties();
return CarFuelItem.Service.Save(this);
}
public void Delete(ID id)
{
if(id.Integer!=21)
CarFuelItem.Service.Delete(id);
}
#endregion
}
#endregion
#region ICarFuelItem Service
public interface ICarFuelItemService
{
CarFuelItem Get(ID id);
ObjectsTemplate<CarFuelItem> Get(string CarFuelID);
ObjectsTemplate<CarFuelItem> Get();
ObjectsTemplate<CarFuelItem> Get(EnumStatus status);
ObjectsTemplate<CarFuelItem> Get(EnumCarFuelType CarFuelType, EnumStatus status);
ID Save(CarFuelItem item);
string GetNextCode();
void Delete(ID id);
}
#endregion
}