370 lines
11 KiB
C#
370 lines
11 KiB
C#
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 User Service
|
|
[Serializable]
|
|
public class UserService : ServiceTemplate, IUserService
|
|
{
|
|
#region Private functions and declaration
|
|
Cache _cache = new Cache(typeof(User));
|
|
|
|
#endregion
|
|
public UserService() { }
|
|
|
|
private void MapObject(User oUser, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oUser, oReader.GetID("UserID"));
|
|
oUser.LoginID = oReader.GetString("loginID");
|
|
oUser.Name = oReader.GetString("userName");
|
|
oUser.ParentID = oReader.GetID("ownerID");
|
|
oUser.Password = oReader.GetString("password");
|
|
oUser.PasswordHints = oReader.GetString("empPasswordHint");
|
|
oUser.IsForceChangePass = Convert.ToBoolean(oReader.GetInt32("isforcechangepass"));
|
|
oUser.SISU = Convert.ToBoolean(oReader.GetInt32("SISU"));
|
|
oUser.Status = (EnumStatus)Convert.ToInt32(oReader.GetInt32("Status"));
|
|
oUser.UserType = (EnumSystemType)Convert.ToInt32(oReader.GetInt32("UserType"));
|
|
oUser.CreatedDate = oReader.GetDateTime("CreationDate").HasValue ? oReader.GetDateTime("CreationDate").Value : DateTime.MinValue;
|
|
oUser.AuthorizedBy = oReader.GetID("AuthorizedBy");
|
|
oUser.AuthorizedDate = oReader.GetDateTime("AuthorizedDate");
|
|
oUser.LockedWorkStation = oReader.GetString("LockedWorkStation");
|
|
oUser.GroupNumber = oReader.GetInt32("GroupNo").Value;
|
|
oUser.Reason = oReader.GetString("Reason");
|
|
oUser.TempStatus = (EnumStatus)Convert.ToInt32(oReader.GetInt32("TempStatus"));
|
|
oUser.ComputerName = oReader.GetString("ComputerName");
|
|
oUser.ApprovedComputerName = oReader.GetString("ApprovedComputerName");
|
|
this.SetObjectState(oUser, Ease.CoreV35.ObjectState.Saved);
|
|
|
|
}
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
User oUser = new User();
|
|
MapObject(oUser, oReader);
|
|
return oUser as T;
|
|
}
|
|
protected User CreateObject(DataReader oReader)
|
|
{
|
|
User oUser = new User();
|
|
MapObject(oUser, oReader);
|
|
return oUser;
|
|
}
|
|
#region Service implementation
|
|
public User Get(ID id)
|
|
{
|
|
User oUser = new User();
|
|
#region Cache Header
|
|
oUser = _cache["Get", id] as User;
|
|
if (oUser != null)
|
|
return oUser;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(UserDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oUser = this.CreateObject<User>(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(oUser, "Get", id);
|
|
#endregion
|
|
return oUser;
|
|
}
|
|
|
|
public User Get(string sName)
|
|
{
|
|
User oUser = new User();
|
|
#region Cache Header
|
|
oUser = _cache["Get", sName] as User;
|
|
if (oUser != null)
|
|
return oUser;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(UserDA.Get(tc, sName));
|
|
if (oreader.Read())
|
|
{
|
|
oUser = this.CreateObject<User>(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(oUser, "Get", sName);
|
|
#endregion
|
|
return oUser;
|
|
}
|
|
|
|
public User GetByLogINID(string sName, EnumSystemType eSysType)
|
|
{
|
|
User oUser = new User();
|
|
#region Cache Header
|
|
oUser = _cache["GetByLogINID", sName, eSysType] as User;
|
|
if (oUser != null)
|
|
return oUser;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(UserDA.GetByLogInID(tc, sName, eSysType));
|
|
if (oreader.Read())
|
|
{
|
|
oUser = this.CreateObject<User>(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(oUser, "GetByLogINID", sName, eSysType);
|
|
#endregion
|
|
return oUser;
|
|
}
|
|
|
|
public DataSet GetUsers(EnumSystemType type, DateTime fromDate, DateTime ToDate)
|
|
{
|
|
|
|
DataSet role = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
role = UserDA.GetUsers(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 ObjectsTemplate<User> Get(EnumSystemType type)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<User> users = _cache["Get"] as ObjectsTemplate<User>;
|
|
if (users != null)
|
|
return users;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(UserDA.Get(tc, type));
|
|
users = this.CreateObjects<User>(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(users, "Get");
|
|
|
|
#endregion
|
|
|
|
return users;
|
|
}
|
|
|
|
public ID Save(User oUser)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oUser.IsNew)
|
|
{
|
|
int id = tc.GenerateID("Users", "UserID");
|
|
base.SetObjectID(oUser, ID.FromInteger(id));
|
|
UserDA.Insert(tc, oUser);
|
|
}
|
|
else
|
|
{
|
|
UserDA.Update(tc, oUser);
|
|
}
|
|
tc.End();
|
|
return oUser.ID;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
public void Update(User oUser, EnumStatus status)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
UserDA.Update(tc, oUser, status);
|
|
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(ID id)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
UserDA.Delete(tc, id);
|
|
UserRoleDA.DeleteByUserID(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 User GetById(int userID)
|
|
{
|
|
User oUser = new User();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(UserDA.GetByID(tc, userID));
|
|
if (oreader.Read())
|
|
{
|
|
oUser = this.CreateObject<User>(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
|
|
}
|
|
|
|
return oUser;
|
|
}
|
|
|
|
public void SaveAllUsers(ObjectsTemplate<User> oUsers)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
foreach (User usr in oUsers)
|
|
{
|
|
int id = tc.GenerateID("Users", "UserID");
|
|
usr.SetObjectID(id);
|
|
UserDA.Insert(tc, usr);
|
|
//UserDA.Update(tc, usr, usr.Status);
|
|
int i;
|
|
for (i = 0; i < usr.Roles.Count; i++)
|
|
{
|
|
UserRole orole = usr.Roles[i];
|
|
orole.UserID = usr.ID;
|
|
UserRole.SaveSingleUserRole(orole);
|
|
|
|
}
|
|
|
|
}
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
}
|
|
#endregion
|
|
}
|