698 lines
20 KiB
C#
698 lines
20 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 Department Service
|
|
[Serializable]
|
|
public class DepartmentService : ServiceTemplate, IDepartmentService
|
|
{
|
|
#region Private functions and declaration
|
|
Cache _cache = new Cache(typeof(Department));
|
|
|
|
#endregion
|
|
public DepartmentService() { }
|
|
|
|
private void MapObject(Department oDepartment, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oDepartment, oReader.GetID("DepartmentID"));
|
|
oDepartment.Code = oReader.GetString("code");
|
|
oDepartment.RCCode = oReader.GetString("rccode");
|
|
oDepartment.Name = oReader.GetString("description");
|
|
oDepartment.ParentID = oReader.GetID("parentID");
|
|
oDepartment.ParentsID = oReader.GetString("parentsID");
|
|
oDepartment.Sequence = oReader.GetInt32("SequenceNo").Value;
|
|
oDepartment.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|
oDepartment.Tier = oReader.GetInt32("TIRE").Value;
|
|
oDepartment.CreatedBy = oReader.GetID("CreatedBy");
|
|
oDepartment.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|
oDepartment.ModifiedBy = oReader.GetID("ModifiedBy");
|
|
oDepartment.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|
this.SetObjectState(oDepartment, Ease.CoreV35.ObjectState.Saved);
|
|
}
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
Department oDepartment = new Department();
|
|
MapObject(oDepartment, oReader);
|
|
return oDepartment as T;
|
|
}
|
|
protected Department CreateObject(DataReader oReader)
|
|
{
|
|
Department oDepartment = new Department();
|
|
MapObject(oDepartment, oReader);
|
|
return oDepartment;
|
|
}
|
|
|
|
#region Service implementation
|
|
|
|
public string GetNextCode(int tier)
|
|
{
|
|
TransactionContext tc = null;
|
|
string _code = "";
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
_code = GlobalFunctionService.GetMaxCode(tc, "department", "codeautogenerate", "Department", "Code", tier);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
return _code;
|
|
}
|
|
|
|
|
|
public string GetNextCode(int _tier, string _parentCode)
|
|
{
|
|
TransactionContext tc = null;
|
|
string _code = "";
|
|
try
|
|
{
|
|
|
|
tc = TransactionContext.Begin();
|
|
_code = GlobalFunctionService.GetMaxCodeofTree(tc, "department", "codeautogenerate", "Department", "Code", _parentCode, _tier);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
return _code;
|
|
}
|
|
|
|
public Department Get(ID id)
|
|
{
|
|
Department oDepartment = new Department();
|
|
#region Cache Header
|
|
oDepartment = _cache["Get", id] as Department;
|
|
if (oDepartment != null)
|
|
return oDepartment;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(DepartmentDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oDepartment = this.CreateObject<Department>(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(oDepartment, "Get", id);
|
|
#endregion
|
|
return oDepartment;
|
|
}
|
|
|
|
|
|
|
|
public Department Get(string sCode)
|
|
{
|
|
Department oDepartment = new Department();
|
|
#region Cache Header
|
|
oDepartment = _cache["Get", sCode] as Department;
|
|
if (oDepartment != null)
|
|
return oDepartment;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(DepartmentDA.Get(tc, sCode));
|
|
if (oreader.Read())
|
|
{
|
|
oDepartment = this.CreateObject<Department>(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(oDepartment, "Get", sCode);
|
|
#endregion
|
|
return oDepartment;
|
|
}
|
|
|
|
public ObjectsTemplate<Department> Get()
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<Department> departments = _cache["Get"] as ObjectsTemplate<Department>;
|
|
if (departments != null)
|
|
return departments;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(DepartmentDA.Get(tc));
|
|
departments = this.CreateObjects<Department>(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(departments, "Get");
|
|
|
|
#endregion
|
|
|
|
return departments;
|
|
}
|
|
|
|
public ObjectsTemplate<Department> GetBySalaryMonthAndRCCode(DateTime salaryMonth)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<Department> departments = _cache["Get"] as ObjectsTemplate<Department>;
|
|
if (departments != null)
|
|
return departments;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(DepartmentDA.GetBySalaryMonthAndRCCode(tc, salaryMonth));
|
|
departments = this.CreateObjects<Department>(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(departments, "Get");
|
|
|
|
#endregion
|
|
|
|
return departments;
|
|
}
|
|
|
|
public ObjectsTemplate<Department> GetChield(ID parentID)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<Department> departments = _cache["Get", parentID] as ObjectsTemplate<Department>;
|
|
if (departments != null)
|
|
return departments;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(DepartmentDA.GetChild(tc, parentID));
|
|
departments = this.CreateObjects<Department>(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(departments, "Get", parentID);
|
|
|
|
#endregion
|
|
|
|
return departments;
|
|
}
|
|
|
|
|
|
|
|
public ObjectsTemplate<Department> GetParentLessChilds()
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<Department> departments = _cache["GetParentLessChilds"] as ObjectsTemplate<Department>;
|
|
if (departments != null)
|
|
return departments;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(DepartmentDA.GetParentLessChilds(tc));
|
|
departments = this.CreateObjects<Department>(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(departments, "GetParentLessChilds");
|
|
|
|
#endregion
|
|
|
|
return departments;
|
|
}
|
|
|
|
|
|
public ObjectsTemplate<Department> GetByTier(int tier, int id)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<Department> departments = _cache["GetByTier", tier, id] as ObjectsTemplate<Department>;
|
|
if (departments != null)
|
|
return departments;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(DepartmentDA.GetByTier(tc, tier, id));
|
|
departments = this.CreateObjects<Department>(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(departments, "GetByTier", tier, id);
|
|
|
|
#endregion
|
|
|
|
return departments;
|
|
}
|
|
|
|
public ObjectsTemplate<Department> GetByTier(int tier)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<Department> departments = _cache["GetByTier", tier] as ObjectsTemplate<Department>;
|
|
if (departments != null)
|
|
return departments;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(DepartmentDA.GetByTier(tc, tier));
|
|
departments = this.CreateObjects<Department>(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(departments, "GetByTier", tier);
|
|
|
|
#endregion
|
|
|
|
return departments;
|
|
}
|
|
|
|
public ObjectsTemplate<Department> GetParents(EnumStatus status)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<Department> departments = _cache["GetParents",status] as ObjectsTemplate<Department>;
|
|
if (departments != null)
|
|
return departments;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(DepartmentDA.GetParents(tc,status));
|
|
departments = this.CreateObjects<Department>(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(departments, "GetParents",status);
|
|
|
|
#endregion
|
|
|
|
return departments;
|
|
}
|
|
|
|
//public ID SaveCode(Department oDepartment, string sCode)
|
|
//{
|
|
// TransactionContext tc = null;
|
|
// try
|
|
// {
|
|
// tc = TransactionContext.Begin(true);
|
|
// DepartmentDA.UpdateCode(tc, oDepartment, sCode);
|
|
// tc.End();
|
|
// return oDepartment.ID;
|
|
// }
|
|
// catch (Exception e)
|
|
// {
|
|
// #region Handle Exception
|
|
// if (tc != null)
|
|
// tc.HandleError();
|
|
// ExceptionLog.Write(e);
|
|
// throw new ServiceException(e.Message, e);
|
|
// #endregion
|
|
// }
|
|
|
|
//}
|
|
|
|
public ID Save(Department oDepartment)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oDepartment.ID.IsUnassigned)
|
|
{
|
|
int id = tc.GenerateID("Department", "DepartmentID");
|
|
base.SetObjectID(oDepartment, ID.FromInteger(id));
|
|
int sequenceId = tc.GenerateID("Department", "SequenceNO");
|
|
|
|
oDepartment.Sequence = sequenceId;
|
|
|
|
DepartmentDA.Insert(tc, oDepartment);
|
|
}
|
|
else
|
|
{
|
|
oDepartment.ModifiedBy = Payroll.BO.User.CurrentUser.ID;
|
|
oDepartment.ModifiedDate = DateTime.Today;
|
|
DepartmentDA.Update(tc, oDepartment);
|
|
}
|
|
tc.End();
|
|
return oDepartment.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);
|
|
DepartmentDA.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
|
|
}
|
|
}
|
|
#endregion
|
|
public DataSet GetForTree()
|
|
{
|
|
TransactionContext tc = null;
|
|
DataSet ds = new DataSet();
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
ds = DepartmentDA.GetForTree(tc);
|
|
|
|
tc.End();
|
|
return ds;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
//For excel Upload
|
|
public static void SaveForUpload(TransactionContext tc, ObjectsTemplate<Department> departments)
|
|
{
|
|
try
|
|
{
|
|
string parentCode = "";
|
|
foreach (Department oDepartment in departments)
|
|
{
|
|
if (oDepartment.IsNew)
|
|
{
|
|
int seqNo = tc.GenerateID("Department", "SequenceNo");
|
|
oDepartment.Sequence = seqNo;
|
|
parentCode = string.Empty;
|
|
|
|
bool isAutoGenerated = ConfigurationManager.GetBoolValue("department", "codeautogenerate", EnumConfigurationType.Logic);
|
|
|
|
if (oDepartment.ParentID != null)
|
|
parentCode = departments.GetItem(oDepartment.ParentID).Code;
|
|
|
|
if (isAutoGenerated == true)
|
|
oDepartment.Code = GlobalFunctionService.GetMaxCodeofTree(tc, "department", "codeautogenerate", "Department", "Code", parentCode, oDepartment.Tier);
|
|
|
|
oDepartment.CreatedBy = User.CurrentUser.ID;
|
|
oDepartment.CreatedDate = DateTime.Now;
|
|
DepartmentDA.Insert(tc, oDepartment);
|
|
}
|
|
else
|
|
{
|
|
oDepartment.ModifiedBy = User.CurrentUser.ID;
|
|
oDepartment.ModifiedDate = DateTime.Now;
|
|
DepartmentDA.Update(tc, oDepartment);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
public DataSet GetDepartmentWiseManpower(string sParam)
|
|
{
|
|
DataSet oSalaryMonthlys = new DataSet();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
oSalaryMonthlys = DepartmentDA.GetDepartmentWiseManpower(tc, sParam);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
return oSalaryMonthlys;
|
|
}
|
|
|
|
public DataSet GetRCCodeBySalaryMonth(DateTime salaryMonth)
|
|
{
|
|
DataSet oSalaryMonthlys = new DataSet();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
oSalaryMonthlys = DepartmentDA.GetRCCodeBySalaryMonth(tc, salaryMonth);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
return oSalaryMonthlys;
|
|
}
|
|
|
|
|
|
public DataSet GetAllChilds(ID parentID)
|
|
{
|
|
DataSet oDeptChilds = new DataSet();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
oDeptChilds = DepartmentDA.GetAllChilds(tc, parentID);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
return oDeptChilds;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|