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; //using System.Windows.Forms; namespace Payroll.Service { #region Role Service [Serializable] public class RoleService : ServiceTemplate, IRoleService { #region Private functions and declaration Cache _cache = new Cache(typeof(Role)); #endregion public RoleService() { } private EnumSystemType type; private void MapObject(Role oRole, DataReader oReader) { base.SetObjectID(oRole, oReader.GetID("RoleID")); oRole.Code = oReader.GetString("Code"); oRole.Name = oReader.GetString("name"); oRole.Description = oReader.GetString("Description"); oRole.Sequence = oReader.GetInt32("Sequence").Value; oRole.Status = (EnumStatus)oReader.GetInt32("Status").Value; oRole.CreatedBy = oReader.GetID("CreatedBy"); oRole.AuthorizedBy = oReader.GetID("AuthorizedBy"); oRole.AuthorizedDate = oReader.GetDateTime("AuthorizedDate"); oRole.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oRole.RoleType = (EnumSystemType)(oReader.GetInt32("Roletype").Value); oRole.IsDefault = Convert.ToBoolean((oReader.GetInt32("IsDefault").Value)); oRole.ComputerName = oReader.GetString("ComputerName"); oRole.ApprovedComputerName = oReader.GetString("ApprovedComputerName"); //oRole.ModifiedBy = oReader.GetID("ModifiedBy"); //oRole.ModifiedDate = oReader.GetDateTime("ModifiedDate").Value; this.SetObjectState(oRole, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { Role oRole = new Role(); MapObject(oRole, oReader); return oRole as T; } protected Role CreateObject(DataReader oReader) { Role oRole = new Role(); MapObject(oRole, oReader); return oRole; } #region Service implementation public ObjectsTemplate GetAllRole() { ObjectsTemplate roles = new ObjectsTemplate(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(RoleDA.GetAllRole(tc)); roles = 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 } return roles; } public Role Get(ID id) { Role oRole = new Role(); #region Cache Header oRole = _cache["Get", id] as Role; if (oRole != null) return oRole; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(RoleDA.Get(tc, id)); if (oreader.Read()) { oRole = 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(oRole, "Get", id); #endregion return oRole; } public DataSet GetRoleAudit(int type, DateTime fromDate, DateTime ToDate) { DataSet role = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); role = RoleDA.GetRoleAudit(tc, type, fromDate, ToDate); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return role; } public DataSet GetRolePermissionRoot(int nRoleID) { DataSet role = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); role = RoleDA.GetRoleRootPermissionName(tc, nRoleID); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return role; } public ObjectsTemplate Get(EnumStatus status) { #region Cache Header ObjectsTemplate roles = _cache["Get", status] as ObjectsTemplate; if (roles != null) return roles; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(RoleDA.Get(tc, status)); roles = 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(roles, "Get", status); #endregion return roles; } public ObjectsTemplate Get(EnumStatus status, EnumSystemType type) { #region Cache Header ObjectsTemplate roles = _cache["Get", status] as ObjectsTemplate; if (roles != null) return roles; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(RoleDA.Get(tc, status, type)); roles = 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(roles, "Get", status); #endregion return roles; } public ObjectsTemplate GetDesktopRole(EnumStatus status) { #region Cache Header ObjectsTemplate roles = _cache["Get", status] as ObjectsTemplate; if (roles != null) return roles; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); this.type = EnumSystemType.Desktop; DataReader dr = new DataReader(RoleDA.Get(tc, status, EnumSystemType.Desktop)); roles = 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(roles, "Get", status); #endregion return roles; } public ObjectsTemplate GetWebRole(EnumStatus status) { #region Cache Header ObjectsTemplate roles = _cache["Get", status] as ObjectsTemplate; if (roles != null) return roles; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(RoleDA.Get(tc, status, EnumSystemType.Web)); roles = 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(roles, "Get", status); #endregion return roles; } public ObjectsTemplate GetRole() { #region Cache Header ObjectsTemplate roles = _cache["Get"] as ObjectsTemplate; if (roles != null) return roles; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(RoleDA.GetRole(tc)); roles = 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(roles, "Get"); #endregion return roles; } public ID Save(Role oRole) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); //if (oRole.type == EnumSystemType.Desktop) oRole.RoleType = EnumSystemType.Desktop; //else if (oRole.type == EnumSystemType.Web) oRole.RoleType = EnumSystemType.Web; if (oRole.IsNew) { int id = tc.GenerateID("Role", "RoleID"); int seqNo = tc.GenerateID("Role", "Sequence"); oRole.Sequence = seqNo; base.SetObjectID(oRole, ID.FromInteger(id)); RoleDA.Insert(tc, oRole); } else { RoleDA.Update(tc, oRole); } tc.End(); return oRole.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); RoleDA.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 Object Check(EnumSystemType type) { TransactionContext tc = null; Object myObject = null; try { tc = TransactionContext.Begin(true); myObject = RoleDA.Check(tc, type); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return myObject; } #endregion } #endregion }