CEL_Payroll/Payroll.BO/Organogram/Skill.cs

340 lines
7.9 KiB
C#
Raw 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;
using System.Data;
namespace Payroll.BO
{
#region Skill
[Serializable]
public class Skill : BasicBaseObject
{
#region Cache Store
private static Cache _cache = new Cache(typeof(Skill));
#endregion
#region Constructor
public Skill()
{
_code = string.Empty;
_name = string.Empty;
_parentID = null;
_value = string.Empty;
_tier = 1;
}
#endregion
#region Properties
#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 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 parentID : ID
private ID _parentID;
public ID ParentID
{
get { return _parentID; }
set
{
base.OnPropertyChange<ID>("parentID", _parentID, value);
_parentID = value;
}
}
#endregion
#region Property value : string
protected string _value;
public string Value
{
get { return _value; }
set { _value = value; }
}
#endregion
#region Tier : int
private int _tier;
public int Tier
{
get { return _tier; }
set
{
base.OnPropertyChange<int>("Tier", _tier, value);
_tier = value;
}
}
#endregion
private ObjectsTemplate<Skill> _Childs;
public ObjectsTemplate<Skill> Childs
{
get
{
if (_Childs == null && !this.ID.IsUnassigned && this.ID.Integer > 0)
{
_Childs = Skill.GetChilds(this.ID);
}
return _Childs;
}
set
{
_Childs = value;
}
}
public ObjectsTemplate<ObjectTemplate> PickerChilds
{
get
{
ObjectsTemplate<ObjectTemplate> pChilds = new ObjectsTemplate<ObjectTemplate>();
if (_Childs == null && !this.ID.IsUnassigned && this.ID.Integer > 0)
{
_Childs = Skill.GetChilds(this.ID);
if (_Childs != null)
{
foreach (Skill oItem in _Childs)
{
pChilds.Add(oItem);
}
}
}
return pChilds;
}
}
#region Service Factory ISkillService : ISkillService
internal static ISkillService Service
{
get { return Services.Factory.CreateService<ISkillService>(typeof(ISkillService)); }
}
#endregion
#endregion
#region Functions
public ID Save()
{
try
{
if(this.IsNew)
{
if (IsExists(this.Code))
{
throw new ServiceException("Code already exists");
}
}
base.SetAuditTrailProperties();
return Skill.Service.Save(this);
}
catch (ServiceException e)
{
throw new ServiceException(e.Message, e);
}
}
public void Delete(ID id)
{
Skill.Service.Delete(id);
}
public static Skill Get(ID nID)
{
Skill oSkill = null;
#region Cache Header
oSkill = (Skill)_cache["Get", nID];
if (oSkill != null)
return oSkill;
#endregion
oSkill = Skill.Service.Get(nID);
#region Cache Footer
_cache.Add(oSkill, "Get", nID);
#endregion
return oSkill;
}
public static ObjectsTemplate<Skill> Get()
{
#region Cache Header
ObjectsTemplate<Skill> oSkill = _cache["Get"] as ObjectsTemplate<Skill>;
if (oSkill != null)
return oSkill;
#endregion
try
{
oSkill = Service.Get();
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(oSkill, "Get");
#endregion
return oSkill;
}
public static ObjectsTemplate<Skill> GetParents(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<Skill> skills = _cache["GetParents", status] as ObjectsTemplate<Skill>;
if (skills != null)
return skills;
#endregion
try
{
skills = Service.GetParents(status);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(skills, "GetParents", status);
#endregion
return skills;
}
public static ObjectsTemplate<Skill> GetChilds(ID parentID)
{
#region Cache Header
ObjectsTemplate<Skill> skills = _cache["GetChilds"] as ObjectsTemplate<Skill>;
if (skills != null)
return skills;
#endregion
try
{
skills = Service.GetChilds(parentID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(skills, "GetChilds");
#endregion
return skills;
}
private bool IsExists(string Code)
{
try
{
bool isExists = false;
if (this.Code != null && this.Value.ToUpper() != Code.ToUpper())
{
isExists = Skill.Service.IsExists(Code);
}
return isExists;
}
catch (ServiceException e)
{
throw new ServiceException(e.Message, e);
}
}
#endregion
}
#endregion
#region ISkill Service
public interface ISkillService
{
ID Save(Skill item);
void Delete(ID id);
Skill Get(ID id);
ObjectsTemplate<Skill> Get();
ObjectsTemplate<Skill> GetParents(EnumStatus status);
ObjectsTemplate<Skill> GetChilds(ID parentID);
bool IsExists(string Code);
}
#endregion
}