CEL_Payroll/Payroll.BO/Basic/Department.cs

585 lines
14 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 Department
[Serializable]
public class Department : BasicBaseObject
{
#region Cache Store
private static Cache _cache = new Cache(typeof(Department));
#endregion
#region Constructor
#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.RCCode == "")
{
sErrorString[0] = "RC can not be empty";
sErrorString[1] = "RCCode";
return sErrorString;
}
if (this.Name == "")
{
sErrorString[0] = "Description can not be empty";
sErrorString[1] = "Description";
return sErrorString;
}
sErrorString = null;
return sErrorString;
}
#endregion
public Department()
{
_code = string.Empty;
_rCCode = string.Empty;
_name = string.Empty;
_parentID = null;
_parentsID = string.Empty;
_tier = 1;
_parent = null;
_Childs = null;
_status = EnumStatus.Active;
}
#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 RCCode : string
private string _rCCode;
public string RCCode
{
get { return _rCCode; }
set
{
base.OnPropertyChange<string>("rccode", _rCCode, value);
_rCCode = 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 parentsID : string
private string _parentsID;
public string ParentsID
{
get { return _parentsID; }
set
{
base.OnPropertyChange<string>("ParentsID", _parentsID, value);
_parentsID = value;
}
}
#endregion
#region parent : Department
private Department _parent;
public Department Parent
{
get
{
if (_parent == null && !_parentID.IsUnassigned && _parentID.Integer > 0)
{
_parent = Department.Get(_parentID);
}
return this._parent;
}
set
{
_parent = value;
}
}
#endregion
#region Childs : Department
private ObjectsTemplate<Department> _Childs;
public ObjectsTemplate<Department> Childs
{
get
{
if (_Childs == null && !this.ID.IsUnassigned && this.ID.Integer > 0)
{
_Childs = Department.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 = Department.GetChilds(this.ID);
if (_Childs != null)
{
foreach(Department dpt in _Childs)
{
pChilds.Add(dpt);
}
}
}
return pChilds;
}
}
#endregion
#region Tier : int
private int _tier;
public int Tier
{
get { return _tier; }
set
{
base.OnPropertyChange<int>("Tier", _tier, value);
_tier = value;
}
}
#endregion
#region Service Factory IDepartmentService : IDepartmentService
internal static IDepartmentService Service
{
get { return Services.Factory.CreateService<IDepartmentService>(typeof(IDepartmentService)); }
}
#endregion
#endregion
#region Functions
public string GetNextCode(int nteir, int ParentId)
{
if (nteir == 1 && ParentId == 0)
{
return Department.Service.GetNextCode(nteir);
}
else
{
return Department.Service.GetNextCode(nteir, GetParentCode(ParentId));
}
}
public string GetParentCode(int parentId)
{
return Department.Service.Get(ID.FromInteger(parentId)).Code.ToString();
}
public static DataSet GetForTree()
{
DataSet ds = null;
try
{
ds = Service.GetForTree();
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
return ds;
}
public static Department Get(ID nID)
{
Department oDepartment = null;
#region Cache Header
oDepartment = (Department)_cache["Get", nID];
if (oDepartment != null)
return oDepartment;
#endregion
oDepartment = Department.Service.Get(nID);
#region Cache Footer
_cache.Add(oDepartment, "Get", nID);
#endregion
return oDepartment;
}
public static ObjectsTemplate<Department> GetParentLessChilds()
{
#region Cache Header
ObjectsTemplate<Department> departments = _cache["GetParentLessChilds"] as ObjectsTemplate<Department>;
if (departments != null)
return departments;
#endregion
try
{
departments = Service.GetParentLessChilds();
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(departments, "GetParentLessChilds");
#endregion
return departments;
}
public static ObjectsTemplate<Department> GetChilds(ID parentID)
{
#region Cache Header
ObjectsTemplate<Department> departments = _cache["GetChilds", parentID] as ObjectsTemplate<Department>;
if (departments != null)
return departments;
#endregion
try
{
departments = Service.GetChield(parentID);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(departments, "GetChilds", parentID);
#endregion
return departments;
}
public static Department Get(string sCode)
{
Department oDepartment = null;
#region Cache Header
oDepartment = (Department)_cache["Get", sCode];
if (oDepartment != null)
return oDepartment;
#endregion
oDepartment = Department.Service.Get(sCode);
#region Cache Footer
_cache.Add(oDepartment, "Get", sCode);
#endregion
return oDepartment;
}
public static ObjectsTemplate<Department> GetByTier(int tier, int id)
{
#region Cache Header
ObjectsTemplate<Department> departments = _cache["GetByTier", tier] as ObjectsTemplate<Department>;
if (departments != null)
return departments;
#endregion
try
{
departments = Service.GetByTier(tier, id);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(departments, "GetByTier", tier);
#endregion
return departments;
}
public static ObjectsTemplate<Department> GetByTier(int tier)
{
#region Cache Header
ObjectsTemplate<Department> departments = _cache["GetByTier", tier] as ObjectsTemplate<Department>;
if (departments != null)
return departments;
#endregion
try
{
departments = Service.GetByTier(tier);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(departments, "GetByTier", tier);
#endregion
return departments;
}
public static ObjectsTemplate<Department> Get()
{
#region Cache Header
ObjectsTemplate<Department> departments = _cache["Get"] as ObjectsTemplate<Department>;
if (departments != null)
return departments;
#endregion
try
{
departments = Service.Get();
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(departments, "Get");
#endregion
return departments;
}
public static ObjectsTemplate<Department> GetBySalaryMonthAndRCCode(DateTime salaryMonth)
{
#region Cache Header
ObjectsTemplate<Department> departments = _cache["Get"] as ObjectsTemplate<Department>;
if (departments != null)
return departments;
#endregion
try
{
departments = Service.GetBySalaryMonthAndRCCode(salaryMonth);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(departments, "Get");
#endregion
return departments;
}
public static ObjectsTemplate<Department> GetParents(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<Department> departments = _cache["GetParents",status] as ObjectsTemplate<Department>;
if (departments != null)
return departments;
#endregion
try
{
departments = Service.GetParents(status);
}
catch (ServiceException e)
{
throw new Exception(e.Message, e);
}
#region Cache Footer
_cache.Add(departments, "GetParents",status);
#endregion
return departments;
}
public ID Save()
{
this.SetAuditTrailProperties();
return Department.Service.Save(this);
}
public void Delete(ID id)
{
Department.Service.Delete(id);
}
public static DataSet GetDepartmentWiseManpower(string sParam)
{
DataSet ds = null;
try
{
ds = Service.GetDepartmentWiseManpower(sParam);
}
catch (Exception e)
{
throw new Exception(e.Message, e);
}
return ds;
}
public static DataSet GetRCCodeBySalaryMonth(DateTime salaryMonth)
{
DataSet ds = null;
try
{
ds = Service.GetRCCodeBySalaryMonth(salaryMonth);
}
catch (Exception e)
{
throw new Exception(e.Message, e);
}
return ds;
}
public static DataSet GetAllChilds(ID parentID)
{
DataSet ds = null;
try
{
ds = Service.GetAllChilds(parentID);
}
catch (Exception e)
{
throw new Exception(e.Message, e);
}
return ds;
}
#endregion
}
#endregion
#region IDepartment Service
public interface IDepartmentService
{
Department Get(ID id);
ObjectsTemplate<Department> Get();
DataSet GetRCCodeBySalaryMonth(DateTime salaryMonth);
ObjectsTemplate<Department> GetBySalaryMonthAndRCCode(DateTime salaryMonth);
ObjectsTemplate<Department> GetChield(ID parentID);
ObjectsTemplate<Department> GetParents(EnumStatus status);
ObjectsTemplate<Department> GetByTier(int tier, int id);
ObjectsTemplate<Department> GetByTier(int tier);
ID Save(Department item);
void Delete(ID id);
Department Get(string sCode);
ObjectsTemplate<Department> GetParentLessChilds();
string GetNextCode(int tier, string parentcode);
string GetNextCode(int nteir);
DataSet GetForTree();
DataSet GetAllChilds(ID parentID);
DataSet GetDepartmentWiseManpower(string sParam);
}
#endregion
}