CEL_Payroll/Payroll.BO/Users/Role.cs

484 lines
12 KiB
C#
Raw Normal View History

2024-09-17 14:30:13 +06:00
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<Role> 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<string>("ApprovedComputerName", _ApprovedComputerName, value);
_ApprovedComputerName = value;
}
}
private string _ComputerName;
public string ComputerName
{
get { return _ComputerName; }
set
{
base.OnPropertyChange<string>("ComputerName", _ComputerName, value);
_ComputerName = value;
}
}
#region name : string
private string _name;
public string Name
{
get { return _name; }
set
{
base.OnPropertyChange<string>("name", _name, value);
_name = value;
}
}
#endregion
#region Code : string
private string _code;
public string Code
{
get { return _code; }
set
{
base.OnPropertyChange<string>("Code", _code, value);
_code = value;
}
}
#endregion
#region AuthorizedBy : ID
private ID _authorizedBy;
public ID AuthorizedBy
{
get { return _authorizedBy; }
set
{
base.OnPropertyChange<ID>("AuthorizedBy", _authorizedBy, value);
_authorizedBy = value;
}
}
#endregion
#region AuthorizedDate : DateTime
private DateTime? _authorizedDate;
public DateTime? AuthorizedDate
{
get { return _authorizedDate; }
set
{
base.OnPropertyChange<DateTime>("AuthorizedDate", _authorizedDate, value);
_authorizedDate = value;
}
}
#endregion
#region Description : string
private string _description;
public string Description
{
get { return _description; }
set
{
base.OnPropertyChange<string>("Description", _description, value);
_description = value;
}
}
#endregion
#region Service Factory IRoleService : IRoleService
internal static IRoleService Service
{
get { return Services.Factory.CreateService<IRoleService>(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<Role> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<Role> roles = _cache["Get", status] as ObjectsTemplate<Role>;
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<Role> Get(EnumStatus status, EnumSystemType type)
{
#region Cache Header
ObjectsTemplate<Role> roles = _cache["Get", status, type] as ObjectsTemplate<Role>;
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<Role> GetDesktopRole(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<Role> roles = _cache["Get", status] as ObjectsTemplate<Role>;
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<Role> GetWebRole(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<Role> roles = _cache["Get", status] as ObjectsTemplate<Role>;
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<Role> GetRole()
{
#region Cache Header
ObjectsTemplate<Role> roles = _cache["Get"] as ObjectsTemplate<Role>;
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<Role> GetAllRole()
{
ObjectsTemplate<Role> roles = new ObjectsTemplate<Role>();
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<Role> Get(EnumStatus status, EnumSystemType type);
ObjectsTemplate<Role> GetDesktopRole(EnumStatus status);
ObjectsTemplate<Role> GetWebRole(EnumStatus status);
ObjectsTemplate<Role> GetRole();
ID Save(Role item);
void Delete(ID id);
Object Check(EnumSystemType type);
ObjectsTemplate<Role> Get(EnumStatus status);
ObjectsTemplate<Role> GetAllRole();
DataSet GetRoleAudit(int type, DateTime fromDate, DateTime ToDate);
DataSet GetRolePermissionRoot(int nRoleID);
}
#endregion
}