using System; using System.Data; using System.Linq; using Ease.CoreV35; using Ease.CoreV35.Model; using Ease.CoreV35.DataAccess; using System.Collections.Generic; using Payroll.BO; using Ease.CoreV35.Caching; namespace Payroll.Service { #region AutoObject Service [Serializable] public class AutoObjectService : ServiceTemplate, IAutoObjectService { #region Private functions and declaration Cache _cache = new Cache(typeof(AutoObject)); #endregion public AutoObjectService() { } private void MapObject(AutoObject oAutoObject, DataReader oReader) { base.SetObjectID(oAutoObject, oReader.GetID("TableID")); oAutoObject.Name = oReader.GetString("FormName"); oAutoObject.MenuKey = oReader.GetString("MenuKey"); this.SetObjectState(oAutoObject, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { AutoObject oAutoObject = new AutoObject(); MapObject(oAutoObject, oReader); return oAutoObject as T; } protected AutoObject CreateObject(DataReader oReader) { AutoObject oAutoObject = new AutoObject(); MapObject(oAutoObject, oReader); return oAutoObject; } #region Service implementation public AutoObject Get(string sFormName) { AutoObject oAutoObject = new AutoObject(); #region Cache Header oAutoObject = _cache["Get", sFormName] as AutoObject; if (oAutoObject != null) return oAutoObject; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(AutoObjectDA.Get(tc, sFormName)); if (oreader.Read()) { oAutoObject = 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(oAutoObject, "Get", sFormName); #endregion return oAutoObject; } public ID Save(AutoObject oAutoObject) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oAutoObject.IsNew) { int id = tc.GenerateID("AutoObjectName", "AutoObjectID"); base.SetObjectID(oAutoObject, ID.FromInteger(id)); AutoObjectDA.Insert(tc, oAutoObject); } else { AutoObjectDA.Update(tc, oAutoObject); } tc.End(); return oAutoObject.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); AutoObjectDA.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 static DataSet GetInformation(DateTime FromDate,DateTime ToDate,string sTableName) { DataSet ds = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); ds = AutoObjectDA.GetInformation(tc, FromDate, ToDate,sTableName); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return ds; } #endregion } #endregion }