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.Windows.Forms; using System.Data; namespace Payroll.BO { #region Role [Serializable] public class Role : BasicBaseObject { #region Cache Store private static Cache _cache = new Cache(typeof(Role)); #endregion #region Constructor public Role() { _code = string.Empty; _name = string.Empty; _roleType = EnumSystemType.Desktop; _isDefault = false; _description = string.Empty; _authorizedBy = null; _authorizedDate = DateTime.MinValue; _ComputerName = ""; _ApprovedComputerName = ""; _status = EnumStatus.Active; } #region Input validator public string[] InputValidator() { string[] sErrorString = new string[2]; if (this.Name == "") { sErrorString[0] = "Description can not be empty"; sErrorString[1] = "Description"; return sErrorString; } if (this.Code == "") { sErrorString[0] = "Code can not be empty"; sErrorString[1] = "Code"; return sErrorString; } if (IsValidForDefault() == false) { sErrorString[0] = "already defined default role"; sErrorString[1] = "IsDefault"; return sErrorString; } sErrorString = null; return sErrorString; } private bool IsValidForDefault() { ObjectsTemplate orles = Role.Get(EnumStatus.Regardless, this.RoleType); if (!this.IsDefault) { return true; } else { foreach (Role orole in orles) { if (orole.IsDefault == true) { if (orole.ID != this.ID) { return false; } else if (orole.ID == this.ID) { return true; } } } return true; } } #endregion #endregion #region Properties #region isDefault : bool private bool _isDefault; public bool IsDefault { get { return _isDefault; } set { _isDefault = value; } } #endregion #region Role Type : int private EnumSystemType _roleType; public EnumSystemType RoleType { get { //if (_roleType == null) return ((Role)Role.Get(this.ID)).RoleType; return _roleType; } set { _roleType = value; } } #endregion private string _ApprovedComputerName; public string ApprovedComputerName { get { return _ApprovedComputerName; } set { base.OnPropertyChange("ApprovedComputerName", _ApprovedComputerName, value); _ApprovedComputerName = value; } } private string _ComputerName; public string ComputerName { get { return _ComputerName; } set { base.OnPropertyChange("ComputerName", _ComputerName, value); _ComputerName = value; } } #region name : string private string _name; public string Name { get { return _name; } set { base.OnPropertyChange("name", _name, value); _name = value; } } #endregion #region Code : string private string _code; public string Code { get { return _code; } set { base.OnPropertyChange("Code", _code, value); _code = value; } } #endregion #region AuthorizedBy : ID private ID _authorizedBy; public ID AuthorizedBy { get { return _authorizedBy; } set { base.OnPropertyChange("AuthorizedBy", _authorizedBy, value); _authorizedBy = value; } } #endregion #region AuthorizedDate : DateTime private DateTime? _authorizedDate; public DateTime? AuthorizedDate { get { return _authorizedDate; } set { base.OnPropertyChange("AuthorizedDate", _authorizedDate, value); _authorizedDate = value; } } #endregion #region Description : string private string _description; public string Description { get { return _description; } set { base.OnPropertyChange("Description", _description, value); _description = value; } } #endregion #region Service Factory IRoleService : IRoleService internal static IRoleService Service { get { return Services.Factory.CreateService(typeof(IRoleService)); } } #endregion #endregion #region Functions public static Role Get(ID nID) { Role oRole = null; #region Cache Header oRole = (Role)_cache["Get", nID]; if (oRole != null) return oRole; #endregion oRole = Role.Service.Get(nID); #region Cache Footer _cache.Add(oRole, "Get", nID); #endregion return oRole; } public static DataSet GetRoleAudit(int type, DateTime fromDate, DateTime ToDate) { DataSet ds = null; try { ds = Service.GetRoleAudit(type, fromDate, ToDate); } catch (Exception e) { throw new Exception(e.Message, e); } return ds; } public static DataSet GetRolePermissionRoot(int nRoleID) { DataSet ds = null; try { ds = Service.GetRolePermissionRoot(nRoleID); } catch (Exception e) { throw new Exception(e.Message, e); } return ds; } public static ObjectsTemplate Get(EnumStatus status) { #region Cache Header ObjectsTemplate roles = _cache["Get", status] as ObjectsTemplate; if (roles != null) return roles; #endregion try { roles = Service.Get(status); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(roles, "Get", status); #endregion return roles; } public static ObjectsTemplate Get(EnumStatus status, EnumSystemType type) { #region Cache Header ObjectsTemplate roles = _cache["Get", status, type] as ObjectsTemplate; if (roles != null) return roles; #endregion try { roles = Service.Get(status, type); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(roles, "Get", status, type); #endregion return roles; } public static ObjectsTemplate GetDesktopRole(EnumStatus status) { #region Cache Header ObjectsTemplate roles = _cache["Get", status] as ObjectsTemplate; if (roles != null) return roles; #endregion try { roles = Service.GetDesktopRole(status); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(roles, "Get", status); #endregion return roles; } public static ObjectsTemplate GetWebRole(EnumStatus status) { #region Cache Header ObjectsTemplate roles = _cache["Get", status] as ObjectsTemplate; if (roles != null) return roles; #endregion try { roles = Service.GetWebRole(status); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(roles, "Get", status); #endregion return roles; } public static ObjectsTemplate GetRole() { #region Cache Header ObjectsTemplate roles = _cache["Get"] as ObjectsTemplate; if (roles != null) return roles; #endregion try { roles = Service.GetRole(); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(roles, "Get"); #endregion return roles; } public ID Save() { this.SetAuditTrailProperties(); return Role.Service.Save(this); } public void Delete(ID id) { Role.Service.Delete(id); } #endregion public static Object Check(EnumSystemType type) { Object myObject = Role.Service.Check(type); return myObject; } public static ObjectsTemplate GetAllRole() { ObjectsTemplate roles = new ObjectsTemplate(); try { roles = Service.GetAllRole(); } catch (ServiceException e) { throw new Exception(e.Message, e); } return roles; } } #endregion #region IRole Service public interface IRoleService { Role Get(ID id); ObjectsTemplate Get(EnumStatus status, EnumSystemType type); ObjectsTemplate GetDesktopRole(EnumStatus status); ObjectsTemplate GetWebRole(EnumStatus status); ObjectsTemplate GetRole(); ID Save(Role item); void Delete(ID id); Object Check(EnumSystemType type); ObjectsTemplate Get(EnumStatus status); ObjectsTemplate GetAllRole(); DataSet GetRoleAudit(int type, DateTime fromDate, DateTime ToDate); DataSet GetRolePermissionRoot(int nRoleID); } #endregion }