using System; using Ease.CoreV35.Caching; using Ease.CoreV35.Model; using System.Data; namespace Payroll.BO { #region Class TrainingSchedule [Serializable] public class TrainingSchedule : AuditTrailBase { #region Cache Store private static Cache _cache = new Cache(typeof(TrainingSchedule)); #endregion #region Constructor public TrainingSchedule() { _trainingID = null; _trainingNatureID = null; _instituteID = null; _startDate = DateTime.MinValue; _endDate = DateTime.MinValue; _cost = 0; _maxParticipants = 0; _enrolledParticipants = 0; _courseOutline = string.Empty; _scheduleStatus = true; _enrolledTrainingEmployees = null; _trainingScheduleDates = null; _tNAnalysisID = null; _isShowInWeb = false; _payrollTypeID = null; _venue = string.Empty; _payrollTypeID = SystemInformation.CurrentSysInfo.PayrollTypeID; } #endregion #region Properties #region Property TrainingID : ID private ID _trainingID; public ID TrainingID { get { return _trainingID; } set { _trainingID = value; } } #endregion #region Property TrainingNatureID : ID private ID _trainingNatureID; public ID TrainingNatureID { get { return _trainingNatureID; } set { _trainingNatureID = value; } } #endregion #region Property InstituteID : ID private ID _instituteID; public ID InstituteID { get { return _instituteID; } set { _instituteID = value; } } #endregion #region Property StartDate : DateTime private DateTime _startDate; public DateTime StartDate { get { return _startDate; } set { _startDate = value; } } #endregion #region Property EndDate : DateTime private DateTime _endDate; public DateTime EndDate { get { return _endDate; } set { _endDate = value; } } #endregion #region Property EnrolledStartDate : DateTime private DateTime _enrolledStartDate; public DateTime EnrolledStartDate { get { return _enrolledStartDate; } set { _enrolledStartDate = value; } } #endregion #region Property EnrolledEndDate : DateTime private DateTime _enrolledEndDate; public DateTime EnrolledEndDate { get { return _enrolledEndDate; } set { _enrolledEndDate = value; } } #endregion #region Property Cost : double private double _cost; public double Cost { get { return _cost; } set { _cost = value; } } #endregion #region Property MaxParticipants : int private int _maxParticipants; public int MaxParticipants { get { return _maxParticipants; } set { _maxParticipants = value; } } #endregion #region Property EnrolledParticipants : int private int _enrolledParticipants; public int EnrolledParticipants { get { return _enrolledParticipants; } set { _enrolledParticipants = value; } } #endregion #region Property CourseOutline : string private string _courseOutline; public string CourseOutline { get { return _courseOutline; } set { _courseOutline = value; } } #endregion #region Property Venue : string private string _venue; public string Venue { get { return _venue; } set { _venue = value; } } #endregion #region Property TrainerDescription : string private string _trainerDescription; public string TrainerDescription { get { return _trainerDescription; } set { _trainerDescription = value; } } #endregion #region Property ScheduleStatus : bool private bool _scheduleStatus; public bool ScheduleStatus { get { return _scheduleStatus; } set { _scheduleStatus = value; } } #endregion #region Property Name : string public string Name { get { return String.Format("{0} From: {1} To: {2}", Training.Get(TrainingID.Integer).Name, StartDate.ToString("dd MMM yyyy"), EndDate.ToString("dd MMM yyyy")); } } #endregion #region Property IsShowInWeb : bool private bool _isShowInWeb; public bool IsShowInWeb { get { return _isShowInWeb; } set { _isShowInWeb = value; } } #endregion #region Property TNAnalysisID : ID private ID _tNAnalysisID; public ID TNAnalysisID { get { return _tNAnalysisID; } set { _tNAnalysisID = value; } } #endregion #region Property PayrollTypeID : ID private ID _payrollTypeID; public ID PayrollTypeID { get { return _payrollTypeID; } set { _payrollTypeID = value; } } #endregion #region Property VenueCost : double private double _venueCost; public double VenueCost { get { return _venueCost; } set { _venueCost = value; } } #endregion #region Property RefreshmentCost : double private double _refreshmentCost; public double RefreshmentCost { get { return _refreshmentCost; } set { _refreshmentCost = value; } } #endregion #region Property TrainerFees : double private double _trainerFees; public double TrainerFees { get { return _trainerFees; } set { _trainerFees = value; } } #endregion #region Property OthesCost : double private double _othesCost; public double OthesCost { get { return _othesCost; } set { _othesCost = value; } } #endregion private Training _training; public Training Training { get { if (_training == null && _trainingID != null) { //_employee = new Employee(); _training = Training.Get(_trainingID.Integer); } return _training; } set { _training = value; } } #region Property TrainingScheduleEmployees : TrainingScheduleEmployee private ObjectsTemplate _enrolledTrainingEmployees; public ObjectsTemplate EnrolledTrainingEmployees { get { if (_enrolledTrainingEmployees == null && !this.ID.IsUnassigned && this.ID.Integer > 0) { _enrolledTrainingEmployees = Service.GetTrainingScheduleEmployees(this.ID); } return _enrolledTrainingEmployees; } set { _enrolledTrainingEmployees = value; } } #endregion #region Property TrainingScheduleDates : TrainingScheduleDate private ObjectsTemplate _trainingScheduleDates; public ObjectsTemplate TrainingScheduleDates { get { if (_trainingScheduleDates == null && !this.ID.IsUnassigned && this.ID.Integer > 0) { _trainingScheduleDates = Service.GetTrainingScheduleDates(this.ID); } return _trainingScheduleDates; } set { _trainingScheduleDates = value; } } #endregion #region Property TrainingScheduleDates : TrainingScheduleDate private ObjectsTemplate _trainingScheduleAttn; public ObjectsTemplate TrainingScheduleAttns { get { if (_trainingScheduleAttn == null && !this.ID.IsUnassigned && this.ID.Integer > 0) { _trainingScheduleAttn =Payroll.BO.TrainingScheduleAttn.GetByTrainingScheduleID(this.ID); } return _trainingScheduleAttn; } set { _trainingScheduleAttn = value; } } #endregion #endregion #region Functions public static TrainingSchedule Get(int nTrainingScheduleID) { TrainingSchedule oTrainingSchedule; #region Cache Header oTrainingSchedule = (TrainingSchedule)_cache["Get", nTrainingScheduleID]; if (oTrainingSchedule != null) return oTrainingSchedule; #endregion oTrainingSchedule = Service.Get(ID.FromInteger(nTrainingScheduleID)); #region Cache Footer _cache.Add(oTrainingSchedule, "Get", nTrainingScheduleID); #endregion return oTrainingSchedule; } public static TrainingScheduleEmployee getScheduleEmp(ID SEmpID) { TrainingScheduleEmployee oTrainingScheduleEmp; #region Cache Header oTrainingScheduleEmp = (TrainingScheduleEmployee)_cache["getScheduleEmp", SEmpID]; if (oTrainingScheduleEmp != null) return oTrainingScheduleEmp; #endregion oTrainingScheduleEmp = Service.getScheduleEmp(SEmpID); #region Cache Footer _cache.Add(oTrainingScheduleEmp, "getScheduleEmp", SEmpID); #endregion return oTrainingScheduleEmp; } public ID Save() { this.SetAuditTrailProperties(); return Service.Save(this); } public ID SaveAttnStatus() { this.SetAuditTrailProperties(); return Service.SaveAttnStatus(this); } public ID SaveTrainingEmp(TrainingScheduleEmployee tEmp) { return Service.SaveTrainingEmp(tEmp); } public void Delete() { TrainingSchedule.Service.Delete(this.ID); } public void DeleteNominatedEmp(ID SEmpID) { TrainingSchedule.Service.DeleteNominatedEmp(SEmpID); } public void updateScheduleEmp(ID SEmpID, int status) { TrainingSchedule.Service.updateScheduleEmp(SEmpID, status); } #endregion #region Collection Functions public static ObjectsTemplate Get() { ObjectsTemplate oTrainingSchedules = null; #region Cache Header oTrainingSchedules = (ObjectsTemplate)_cache["Get"]; if (oTrainingSchedules != null) return oTrainingSchedules; #endregion oTrainingSchedules = Service.Get(Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); #region Cache Footer _cache.Add(oTrainingSchedules, "Get"); #endregion return oTrainingSchedules; } public static ObjectsTemplate GetbyStatus(int status) { ObjectsTemplate oTrainingSchedules = null; #region Cache Header oTrainingSchedules = (ObjectsTemplate)_cache["Get"]; if (oTrainingSchedules != null) return oTrainingSchedules; #endregion oTrainingSchedules = Service.GetbyStatus(status,Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); #region Cache Footer _cache.Add(oTrainingSchedules, "Get"); #endregion return oTrainingSchedules; } public static ObjectsTemplate Get(bool active) { ObjectsTemplate oTrainingSchedules = null; #region Cache Header oTrainingSchedules = (ObjectsTemplate)_cache["Get"]; if (oTrainingSchedules != null) return oTrainingSchedules; #endregion oTrainingSchedules = Service.Get(active,Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); #region Cache Footer _cache.Add(oTrainingSchedules, "Get"); #endregion return oTrainingSchedules; } public static ObjectsTemplate Get(DateTime today) { ObjectsTemplate oTrainingSchedules = null; #region Cache Header oTrainingSchedules = (ObjectsTemplate)_cache["Get"]; if (oTrainingSchedules != null) return oTrainingSchedules; #endregion oTrainingSchedules = Service.Get(today,Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); #region Cache Footer _cache.Add(oTrainingSchedules, "Get"); #endregion return oTrainingSchedules; } public static ObjectsTemplate Get(DateTime fromDate, DateTime toDate, int training) { ObjectsTemplate oTrainingSchedules = null; #region Cache Header oTrainingSchedules = (ObjectsTemplate)_cache["Get"]; if (oTrainingSchedules != null) return oTrainingSchedules; #endregion oTrainingSchedules = Service.Get(fromDate, toDate, training,Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); #region Cache Footer _cache.Add(oTrainingSchedules, "Get"); #endregion return oTrainingSchedules; } public static ObjectsTemplate Get(DateTime fromDate, DateTime toDate, int training, bool active) { ObjectsTemplate oTrainingSchedules = null; #region Cache Header oTrainingSchedules = (ObjectsTemplate)_cache["Get"]; if (oTrainingSchedules != null) return oTrainingSchedules; #endregion oTrainingSchedules = Service.Get(fromDate, toDate, training, active,Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); #region Cache Footer _cache.Add(oTrainingSchedules, "Get"); #endregion return oTrainingSchedules; } public static ObjectsTemplate Get(int training,int TNAID, bool active) { ObjectsTemplate oTrainingSchedules = null; #region Cache Header oTrainingSchedules = (ObjectsTemplate)_cache["Get"]; if (oTrainingSchedules != null) return oTrainingSchedules; #endregion oTrainingSchedules = Service.Get(training,TNAID, active,Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); #region Cache Footer _cache.Add(oTrainingSchedules, "Get"); #endregion return oTrainingSchedules; } public static ObjectsTemplate Get(DateTime today, int EmpID, int status) { ObjectsTemplate oTrainingSchedules = null; #region Cache Header oTrainingSchedules = (ObjectsTemplate)_cache["Get"]; if (oTrainingSchedules != null) return oTrainingSchedules; #endregion oTrainingSchedules = Service.Get(today, EmpID, status,Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); #region Cache Footer _cache.Add(oTrainingSchedules, "Get"); #endregion return oTrainingSchedules; } public static ObjectsTemplate Get(int training, int TNAID) { ObjectsTemplate oTrainingSchedules = null; #region Cache Header oTrainingSchedules = (ObjectsTemplate)_cache["Get"]; if (oTrainingSchedules != null) return oTrainingSchedules; #endregion oTrainingSchedules = Service.Get(training, TNAID,Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); #region Cache Footer _cache.Add(oTrainingSchedules, "Get"); #endregion return oTrainingSchedules; } public static ObjectsTemplate Get(DateTime fromDate, DateTime toDate, bool active) { ObjectsTemplate oTrainingSchedules = null; #region Cache Header oTrainingSchedules = (ObjectsTemplate)_cache["Get"]; if (oTrainingSchedules != null) return oTrainingSchedules; #endregion oTrainingSchedules = Service.Get(fromDate, toDate, active,Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); #region Cache Footer _cache.Add(oTrainingSchedules, "Get"); #endregion return oTrainingSchedules; } public static ObjectsTemplate Get(DateTime fromDate, DateTime toDate) { ObjectsTemplate oTrainingSchedules = null; #region Cache Header oTrainingSchedules = (ObjectsTemplate)_cache["Get"]; if (oTrainingSchedules != null) return oTrainingSchedules; #endregion oTrainingSchedules = Service.Get(fromDate, toDate,Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); #region Cache Footer _cache.Add(oTrainingSchedules, "Get"); #endregion return oTrainingSchedules; } public ObjectsTemplate GetEmployees() { ObjectsTemplate employees = new ObjectsTemplate(); if (EnrolledTrainingEmployees == null || EnrolledTrainingEmployees.Count == 0) return null; foreach (TrainingScheduleEmployee trainingEmployee in _enrolledTrainingEmployees) { Employee employee = null; employee = Employee.Get(trainingEmployee.EmployeeID); employees.Add(employee); } return employees; } public static DataSet Get(string query) { DataSet ds = null; try { ds = Service.Get(query); } catch (ServiceException e) { throw new Exception(e.Message, e); } return ds; } #endregion #region Service Factory internal static ITrainingScheduleService Service { get { return Services.Factory.CreateService(typeof(ITrainingScheduleService)); } } #endregion } #endregion #region Child Classes #region Class TrainingScheduleEmployee [Serializable] public class TrainingScheduleEmployee : BasicBaseObject, IworkflowInterface { #region Cache Store private static Cache _cache = new Cache(typeof(TrainingScheduleEmployee)); #endregion #region Constructor public TrainingScheduleEmployee() { _trainingScheduleID = null; _employeeID = null; _proposedByID = null; _proposedDate = DateTime.MinValue; _scheduleEmpStatus = EnumTSStatus.Requested; _remarks = string.Empty; } #endregion #region Properties #region Property ProposedById :ID private ID _proposedByID; public ID ProposedByID { get { return _proposedByID; } set { _proposedByID = value; } } #endregion #region Property ProposedDate : dateTime private DateTime _proposedDate; public DateTime ProposedDate { get { return _proposedDate; } set { _proposedDate = value; } } #endregion #region Property TrainingScheduleID : ID private ID _trainingScheduleID; public ID TrainingScheduleID { get { return _trainingScheduleID; } set { _trainingScheduleID = value; } } #endregion #region Property EmployeeID : ID private ID _employeeID; public ID EmployeeID { get { return _employeeID; } set { _employeeID = value; } } #endregion #region Property ScheduleStatus : EnumTSStatus private EnumTSStatus _scheduleEmpStatus; public EnumTSStatus ScheduleEmpStatus { get { return _scheduleEmpStatus; } set { _scheduleEmpStatus = value; } } #endregion private Employee _employee; public Employee Employee { get { if (_employee == null && _employeeID != null) { //_employee = new Employee(); _employee = Employee.Get(_employeeID); } return _employee; } set { _employee = value; } } public double GetTrainingCost() { double nAmount = 0; if (this.TrainingSchEmpCosts == null) return 0; foreach (Payroll.BO.TrainingSchEmpCost item in this.TrainingSchEmpCosts) { nAmount = nAmount + item.Amount; } return nAmount; } private TrainingSchedule _trainingSchedule; public TrainingSchedule TrainingSchedule { get { if (_trainingSchedule == null && _trainingScheduleID != null && _trainingScheduleID != null) { //_employee = new Employee(); _trainingSchedule = TrainingSchedule.Get( _trainingScheduleID.Integer); } return _trainingSchedule; } set { _trainingSchedule = value; } } #region Property TrainingSchEmpCost : TrainingSchEmpCost private ObjectsTemplate _trainingSchEmpCosts; public ObjectsTemplate TrainingSchEmpCosts { get { if (_trainingSchEmpCosts == null && !this.ID.IsUnassigned && this.ID.Integer > 0) { _trainingSchEmpCosts = TrainingSchEmpCost.Service.GetByTrainingScheduleEmpID(this.EmployeeID, this.ID); } return _trainingSchEmpCosts; } set { _trainingSchEmpCosts = value; } } #endregion #region Property Remarks : string private string _remarks; public string Remarks { get { return _remarks; } set { _remarks = value; } } #endregion #endregion /// /// this property is used for work flow, which return Training description /// public string ObjectDescription { get { string str = ""; str = " Employee (" + this.Employee.EmployeeNo + ")" + this.Employee.Name + " applied enrollment request for " + this.TrainingSchedule.Training.Name + " on " + this.CreatedDate.ToString("dd MMM yyyy"); return str; } } /// /// this property is used for work flow, it's a constant value /// public ID SetupID { get { return ID.FromInteger(5); } } /// /// this property is used for work flow, which return leave entry id /// public ID ObjectID { get { return this.ID; } } } #endregion #region Class TrainingScheduleDate [Serializable] public class TrainingScheduleDate: BasicBaseObject { #region Cache Store private static Cache _cache = new Cache(typeof(TrainingScheduleDate)); #endregion #region Constructor public TrainingScheduleDate() { _trainingScheduleID = null; _scheduleDate = DateTime.MinValue; _startTime = DateTime.MinValue; _endTime = DateTime.MinValue; _remarks = string.Empty; } #endregion #region Properties #region Property TrainingScheduleID : ID private ID _trainingScheduleID; public ID TrainingScheduleID { get { return _trainingScheduleID; } set { _trainingScheduleID = value; } } #endregion #region Property ScheduleDate : dateTime private DateTime _scheduleDate; public DateTime ScheduleDate { get { return _scheduleDate; } set { _scheduleDate = value; } } #endregion #region Property StartTime : DateTime private DateTime _startTime; public DateTime StartTime { get { return _startTime; } set { _startTime = value; } } #endregion #region Property EndTime : DateTime private DateTime _endTime; public DateTime EndTime { get { return _endTime; } set { _endTime = value; } } #endregion #region Property Remarks : string private string _remarks; public string Remarks { get { return _remarks; } set { _remarks = value; } } #endregion #region Property StartTimeString : String public String StartTimeString { get { if (_startTime != DateTime.MinValue) return _startTime.ToString("hh:mm tt"); return ""; } } #endregion #region Property EndTimeString : String public String EndTimeString { get { if (_endTime != DateTime.MinValue) return _endTime.ToString("hh:mm tt"); return ""; } } #endregion #region Property TrainingScheduleDates : TrainingScheduleDate private ObjectsTemplate _trainingScheduleAttns; public ObjectsTemplate TrainingScheduleAttns { get { if (_trainingScheduleAttns == null && !this.ID.IsUnassigned && this.ID.Integer > 0) { _trainingScheduleAttns = TrainingScheduleAttn.Service.GetByTrainingScheduleDateID(this.ID); } return _trainingScheduleAttns; } set { _trainingScheduleAttns = value; } } #endregion #endregion } #endregion #endregion #region ITrainingSchedule Service public interface ITrainingScheduleService { TrainingSchedule Get(ID id); ObjectsTemplate Get(int payrollTypeID); ObjectsTemplate Get(bool active, int payrollTypeID); ObjectsTemplate Get(DateTime today, int payrollTypeID); ObjectsTemplate Get(DateTime fromDate, DateTime toDate, int training, int payrollTypeID); ObjectsTemplate GetbyStatus(int status, int payrollTypeID); ObjectsTemplate Get(DateTime fromDate, DateTime toDate, int training, bool active, int payrollTypeID); ObjectsTemplate Get(DateTime fromDate, DateTime toDate, int payrollTypeID); ObjectsTemplate Get(DateTime fromDate, DateTime toDate, bool active, int payrollTypeID); ObjectsTemplate Get(DateTime today, int EmpID, int status, int payrollTypeID); ObjectsTemplate Get(int training, int TNAID, bool active, int payrollTypeID); ObjectsTemplate Get(int training, int TNAID, int payrollTypeID); ID Save(TrainingSchedule oTrainingSchedule); void Delete(ID id); void DeleteNominatedEmp(ID SEmpID); void updateScheduleEmp(ID SEmpID, int status); TrainingScheduleEmployee getScheduleEmp(ID SEmpID); ObjectsTemplate GetTrainingScheduleDates(ID trainingScheduleID); ObjectsTemplate GetTrainingScheduleEmployees(ID trainingScheduleID); ID SaveAttnStatus(TrainingSchedule trainingSchedule); DataSet Get(string query); ID SaveTrainingEmp(TrainingScheduleEmployee tEmp); } #endregion }