using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.CoreV35.Caching; using Ease.CoreV35.DataAccess; using Payroll.Service.Basic.DA; using Ease.CoreV35.Model; using Payroll.BO; namespace Payroll.Service.Basic.Service { [Serializable] class MonthlyWorkingHourService : ServiceTemplate, IMonthlyWorkingHourService { #region Private functions and declaration Cache _cache = new Cache(typeof(MonthlyWorkingHour)); #endregion #region Constructor public MonthlyWorkingHourService() { } #endregion private void MapObject(MonthlyWorkingHour oMonthlyWorkingHour, DataReader dr) { base.SetObjectID(oMonthlyWorkingHour, dr.GetID("MonthlyWorkingHourID")); oMonthlyWorkingHour.WorkingMonth = dr.GetDateTime("WorkingMonth").Value; oMonthlyWorkingHour.RegularHour = dr.GetDouble("RegularHour").Value; oMonthlyWorkingHour.SpecialHour = dr.GetDouble("SpecialHour").Value; oMonthlyWorkingHour.CreatedBy = dr.GetID("CreatedBy"); oMonthlyWorkingHour.CreatedDate = dr.GetDateTime("CreatedDate").Value; oMonthlyWorkingHour.EmployeeID = dr.GetID("EmployeeID"); this.SetObjectState(oMonthlyWorkingHour, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { MonthlyWorkingHour oMonthlyWorkingHour = new MonthlyWorkingHour(); MapObject(oMonthlyWorkingHour, oReader); return oMonthlyWorkingHour as T; } protected MonthlyWorkingHour CreateObject(DataReader oReader) { MonthlyWorkingHour oMonthlyWorkingHour = new MonthlyWorkingHour(); MapObject(oMonthlyWorkingHour, oReader); return oMonthlyWorkingHour; } #region Service Implemetation public ID Save(MonthlyWorkingHour oMonthlyWorkingHour) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oMonthlyWorkingHour.IsNew) { int id = tc.GenerateID("MonthlyWorkingHour", "MonthlyWorkingHourID"); base.SetObjectID(oMonthlyWorkingHour, ID.FromInteger(id)); MonthlyWorkingHourDA.Insert(tc, oMonthlyWorkingHour); } else { MonthlyWorkingHourDA.Update(tc, oMonthlyWorkingHour); } tc.End(); return oMonthlyWorkingHour.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void Delete(ID id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); MonthlyWorkingHourDA.Delete(tc, id); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void Delete( TransactionContext tc, MonthlyWorkingHour item) { try { MonthlyWorkingHourDA.Delete(tc,item); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public MonthlyWorkingHour Get(ID id) { MonthlyWorkingHour oMonthlyWorkingHour = new MonthlyWorkingHour(); #region Cache Header oMonthlyWorkingHour = _cache["Get", id] as MonthlyWorkingHour; if (oMonthlyWorkingHour != null) return oMonthlyWorkingHour; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(MonthlyWorkingHourDA.Get(tc, id)); if (oreader.Read()) { oMonthlyWorkingHour = this.CreateObject(oreader); } oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } #region Cache Footer _cache.Add(oMonthlyWorkingHour, "Get", id); #endregion return oMonthlyWorkingHour; } public ObjectsTemplate Get(DateTime date) { #region Cache Header ObjectsTemplate aMonthlyWorkingHour = _cache["Get"] as ObjectsTemplate; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(MonthlyWorkingHourDA.Get(tc,date)); aMonthlyWorkingHour = this.CreateObjects(dr); dr.Close(); tc.End(); } catch (Exception e) { } #region Cache Footer _cache.Add(aMonthlyWorkingHour, "Get"); #endregion return aMonthlyWorkingHour; } public ObjectsTemplate Get() { ObjectsTemplate aMonthlyWorkingHour = new ObjectsTemplate(); #region Cache Header aMonthlyWorkingHour = _cache["Get"] as ObjectsTemplate; if (aMonthlyWorkingHour != null) return aMonthlyWorkingHour; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(MonthlyWorkingHourDA.Get(tc)); aMonthlyWorkingHour = this.CreateObjects(dr); dr.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } #region Cache Footer _cache.Add(aMonthlyWorkingHour, "Get"); #endregion return aMonthlyWorkingHour; } public void Save(ObjectsTemplate items) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); //foreach(MonthlyWorkingHour mwh in items) //{ this.Delete(tc, items[0]); //} int id = tc.GenerateID("MonthlyWorkingHour", "MonthlyWorkingHourID"); foreach (MonthlyWorkingHour item in items) { base.SetObjectID(item, ID.FromInteger(id)); item.CreatedBy = Payroll.BO.User.CurrentUser.ID; item.CreatedDate = DateTime.Today; MonthlyWorkingHourDA.Insert(tc, item); id++; } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public bool IsExist(MonthlyWorkingHour MonthlyWorkingHour) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); bool result = true; result = MonthlyWorkingHourDA.IsExist(tc, MonthlyWorkingHour); return result; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } finally { if (tc != null) { tc.End(); } } } #endregion } }