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 EmployeeCostCenter [Serializable] public class EmployeeCostCenter : AuditTrailBase { #region Cache Store private static Cache _cache = new Cache(typeof(EmployeeCostCenter)); #endregion #region Constructor public EmployeeCostCenter() { _employeeID = null; _monthDate = DateTime.MinValue; _costCenterID = null; _percentage = 0; _isCurrentCC = false; _tillDate = DateTime.MinValue; _costcenter = null; } #endregion #region Properties #region employeeID : ID private ID _employeeID; public ID EmployeeID { get { return _employeeID; } set { base.OnPropertyChange("employeeID", _employeeID, value); _employeeID = value; } } #endregion #region monthDate : DateTime private DateTime _monthDate; public DateTime MonthDate { get { return _monthDate; } set { base.OnPropertyChange("monthDate", _monthDate, value); _monthDate = value; } } #endregion #region costCenterID : ID private ID _costCenterID; public ID CostCenterID { get { return _costCenterID; } set { base.OnPropertyChange("costCenterID", _costCenterID, value); _costCenterID = value; } } #endregion #region percentage : double private double _percentage; public double Percentage { get { return _percentage; } set { base.OnPropertyChange("percentage", _percentage, value); _percentage = value; } } #endregion #region isCurrentCC : bool private bool _isCurrentCC; public bool IsCurrentCC { get { return _isCurrentCC; } set { base.OnPropertyChange("isCurrentCC", _isCurrentCC, value); _isCurrentCC = value; } } #endregion #region tillDate : DateTime private DateTime _tillDate; public DateTime TillDate { get { return _tillDate; } set { base.OnPropertyChange("tillDate", _tillDate, value); _tillDate = value; } } #endregion #region costcenter : Costcenter private Costcenter _costcenter; public Costcenter Costcenter { get { if (_costCenterID.Integer > 0 && _costcenter == null) { _costcenter = new Costcenter(); _costcenter = Costcenter.Get(_costCenterID); } return this._costcenter; } set { _costcenter = value; } } #endregion #region Service Factory IEmployeeCostCenterService : IEmployeeCostCenterService internal static IEmployeeCostCenterService Service { get { return Services.Factory.CreateService(typeof(IEmployeeCostCenterService)); } } #endregion #endregion #region Functions public static EmployeeCostCenter Get(ID nID) { EmployeeCostCenter oEmployeeCostCenter = null; #region Cache Header oEmployeeCostCenter = (EmployeeCostCenter)_cache["Get", nID]; if (oEmployeeCostCenter != null) return oEmployeeCostCenter; #endregion oEmployeeCostCenter = EmployeeCostCenter.Service.Get(nID); #region Cache Footer _cache.Add(oEmployeeCostCenter, "Get", nID); #endregion return oEmployeeCostCenter; } /// /// Get employee current cost-center(s) involvement /// /// /// public static ObjectsTemplate GetByEmpID(ID employeeid) { #region Cache Header ObjectsTemplate employeeCostCenters = _cache["Get"] as ObjectsTemplate; if (employeeCostCenters != null) return employeeCostCenters; #endregion try { employeeCostCenters = Service.GetByEmpID(employeeid); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(employeeCostCenters, "Get"); #endregion return employeeCostCenters; } /// /// Get all employee's current cost-center involvement /// /// public static ObjectsTemplate Get() { #region Cache Header ObjectsTemplate employeeCostCenters = _cache["Get"] as ObjectsTemplate; if (employeeCostCenters != null) return employeeCostCenters; #endregion try { employeeCostCenters = Service.Get(); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(employeeCostCenters, "Get"); #endregion return employeeCostCenters; } public static ObjectsTemplate Get(ObjectsTemplate empCRGInvolvements, ID employeeID) { ObjectsTemplate empCRGs = null; foreach (EmployeeCostCenter crg in empCRGInvolvements) { if (crg.EmployeeID == employeeID) { if (empCRGs == null) empCRGs = new ObjectsTemplate(); empCRGs.Add(crg); } } return empCRGs; } /// /// get costcenter current involvement all employee(s) /// /// cost center ID /// public static ObjectsTemplate GetByCCID(ID nCCID) { #region Cache Header ObjectsTemplate employeeCostCenters = _cache["Get"] as ObjectsTemplate; if (employeeCostCenters != null) return employeeCostCenters; #endregion try { employeeCostCenters = Service.GetByCCID(nCCID); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(employeeCostCenters, "Get"); #endregion return employeeCostCenters; } public static ObjectsTemplate GetByEmpIDCCID(ID nCCID, ID nEmpID) { #region Cache Header ObjectsTemplate employeeCostCenters = _cache["GetByEmpIDCCID"] as ObjectsTemplate; if (employeeCostCenters != null) return employeeCostCenters; #endregion try { employeeCostCenters = Service.GetByEmpIDCCID(nCCID, nEmpID); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(employeeCostCenters, "Get"); #endregion return employeeCostCenters; } public static DataSet GetEmpCC(DateTime dMonthDate, string sEmpID) { DataSet ds = null; try { ds = Service.GetEmpCC(dMonthDate, sEmpID); } catch (Exception e) { throw new Exception(e.Message, e); } return ds; } public static DataSet GetEmpCCDetails(DateTime dMonthDate, string nEmpID) { DataSet ds = null; try { ds = Service.GetEmpCCDetails(dMonthDate, nEmpID); } catch (Exception e) { throw new Exception(e.Message, e); } return ds; } public static DateTime GetMaxDate(string EmpID, DateTime monthDate) { DateTime dMonthDate; try { dMonthDate = Service.GetMaxDate(EmpID, monthDate); } catch (Exception e) { throw new Exception(e.Message, e); } return dMonthDate; } public static ObjectsTemplateGetByMonthStartEnd(DateTime strt, DateTime end) { return EmployeeCostCenter.Service.GetByMonthStartEnd(strt, end,SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); } public ID Save() { base.SetAuditTrailProperties(); this.IsCurrentCC = true; return EmployeeCostCenter.Service.Save(this); } public void Save(ObjectsTemplate _empCostCenters) { foreach (EmployeeCostCenter item in _empCostCenters) { item.SetAuditTrailProperties(); item.IsCurrentCC = true; } EmployeeCostCenter.Service.Save(_empCostCenters); } public void Delete() { EmployeeCostCenter.Service.Delete(ID); } #endregion } #endregion #region IEmployeeCostCenter Service public interface IEmployeeCostCenterService { EmployeeCostCenter Get(ID id); ObjectsTemplate Get(); ObjectsTemplate GetByEmpID(ID nID); ObjectsTemplate GetByCCID(ID nID); ObjectsTemplate GetByEmpIDCCID(ID nCCID, ID nEmpID); DataSet GetEmpCC(DateTime dMonthDate, string sEmpID); DataSet GetEmpCCDetails(DateTime dMonthDate, string nEmpID); DateTime GetMaxDate(string nEmpID, DateTime monthDate); ID Save(EmployeeCostCenter item); void Save(ObjectsTemplate _empCostCenters); void Delete(ID id); ObjectsTemplate GetByMonthStartEnd(DateTime strt, DateTime end, int payrollTypeID); } #endregion }