CEL_Payroll/Payroll.Service/Workflow/Service/WFSetupService.cs
2024-09-17 14:30:13 +06:00

673 lines
25 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35;
using Payroll.BO;
using Ease.CoreV35.Model;
using Ease.CoreV35.DataAccess;
using Ease.CoreV35.Caching;
using System.Data;
namespace Payroll.Service
{
public class WFSetupService : ServiceTemplate, IWFSetupService
{
#region Cache Store
Cache _cache = new Cache(typeof(WFSetup));
Cache _cache_WFSetupRule = new Cache(typeof(WFSetupRule));
Cache _cache_WFDetailDesignation = new Cache(typeof(WFRuleDetailDesignation));
Cache _cache_WFRuleDetailOS = new Cache(typeof(WFRuleDetailOS));
Cache _cache_WFRuleNode = new Cache(typeof(WFRuleDetailNode));
#endregion
#region Constructor
public WFSetupService()
{ }
#endregion
#region WFSetup
#region WFSetup Mapping
private void MapObject(WFSetup wfSetup, DataReader oReader)
{
base.SetObjectID(wfSetup, oReader.GetID("WFSETUPID"));
wfSetup.WFTypeId = oReader.GetID("WFTYPEID");
wfSetup.CreatedBy = oReader.GetID("CREATEDBY");
wfSetup.CreatedDate = oReader.GetDateTime("CREATEDDATE").Value;
wfSetup.ModifiedBy = oReader.GetID("MODIFIEDBY");
wfSetup.ModifiedDate = oReader.GetDateTime("MODIFIEDDATE");
wfSetup.Sequence = oReader.GetInt32("SEQUENCENO").Value;
this.SetObjectState(wfSetup, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
WFSetup wfSetup = new WFSetup();
MapObject(wfSetup, oReader);
return wfSetup as T;
}
protected WFSetup CreateObject(DataReader oReader)
{
WFSetup wfSetup = new WFSetup();
MapObject(wfSetup, oReader);
return wfSetup;
}
#endregion
#region Service Implementation
#region Save
public ID Save(WFSetup wfSetup)
{
TransactionContext tc = null;
try
{
ObjectsTemplate<WFSetupRule> oSetupRules = null;
if (wfSetup.IsNew == false) oSetupRules = this.Get4WFSetupRule(wfSetup.ID);
tc = TransactionContext.Begin(true);
int id = 0;
if (wfSetup.IsNew)
{
id = tc.GenerateID("WFSETUP", "WFSETUPID");
base.SetObjectID(wfSetup, ID.FromInteger(id));
WFSetupDA.Insert(tc, wfSetup);
}
else
{
WFSetupDA.Update(tc, wfSetup);
WFSetupDA.DeleteWFRuleDetailDesignation(tc, wfSetup.ID);
WFSetupDA.DeleteWFRuleDetailOS(tc, wfSetup.ID);
WFSetupDA.DeleteWFRuleDetailNode(tc, wfSetup.ID);
WFSetupDA.DeleteWFRuleDetailManual(tc, wfSetup.ID);
if (oSetupRules != null && oSetupRules.Count > 0)
{
foreach (WFSetupRule oRule in oSetupRules)
{
WFSetupRule odeletedRule = wfSetup.WFSetupRules.GetItem(oRule.ID);
if (odeletedRule == null) WFSetupDA.DeleteWFSetupRulebyRuleID(tc, oRule.ID);
}
}
}
foreach (WFSetupRule wfSetupRule in wfSetup.WFSetupRules)
{
if (wfSetupRule.IsNew)
{
id = tc.GenerateID("WFSETUPRULE", "WFSETUPRULEID");
wfSetupRule.WFSetupId = wfSetup.ID;
base.SetObjectID(wfSetupRule, ID.FromInteger(id));
WFSetupDA.InsertWFSetupRule(tc, wfSetupRule);
}
else
{
WFSetupDA.UpdateWFSetupRule(tc, wfSetupRule);
}
if (wfSetupRule.WFRuleType == EnumWFRuleType.Designation)
{
foreach (WFRuleDetailDesignation wfDetailDesig in wfSetupRule.WFRuleDeatilDesignations)
{
id = tc.GenerateID("WFRDDESIGNATION", "WFRULEDETAILID");
wfDetailDesig.WfSetupId = wfSetup.ID;
wfDetailDesig.WfSetupRuleId = wfSetupRule.ID;
base.SetObjectID(wfDetailDesig, ID.FromInteger(id));
WFSetupDA.InsertWFRuleDetailDesignation(tc, wfDetailDesig);
}
}
if (wfSetupRule.WFRuleType == EnumWFRuleType.OrganizationStructure)
{
foreach (WFRuleDetailOS wfRuleDOS in wfSetupRule.WFRuleDeatilOSs)
{
id = tc.GenerateID("WFRDETAILOS", "WFRULEDETAILID");
wfRuleDOS.WfSetupId = wfSetup.ID;
wfRuleDOS.WfSetupRuleId = wfSetupRule.ID;
base.SetObjectID(wfRuleDOS, ID.FromInteger(id));
WFSetupDA.InsertRuleDetailOS(tc, wfRuleDOS);
}
}
if (wfSetupRule.WFRuleType == EnumWFRuleType.FixedOGNode)
{
foreach (WFRuleDetailNode wfRuleNode in wfSetupRule.WFRuleDetailNodes)
{
id = tc.GenerateID("WFRULEDNODE", "WFRULEDNODEID");
wfRuleNode.WfSetupId = wfSetup.ID;
wfRuleNode.WfSetupRuleId = wfSetupRule.ID;
base.SetObjectID(wfRuleNode, ID.FromInteger(id));
WFSetupDA.InsertRuleDetailNode(tc, wfRuleNode);
}
}
if (wfSetupRule.WFRuleType == EnumWFRuleType.Manual)
{
foreach (WFRuleDetailManual wfRulemn in wfSetupRule.WFRuleDetailManual)
{
id = tc.GenerateID("WFRuleManual", "WFRULEDETAILID");
wfRulemn.WfSetupId = wfSetup.ID;
wfRulemn.WfSetupRuleId = wfSetupRule.ID;
base.SetObjectID(wfRulemn, ID.FromInteger(id));
WFSetupDA.InsertRuleManual(tc, wfRulemn);
}
}
}
tc.End();
return wfSetup.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
#region Delete
public void Delete(ID id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
WFSetupDA.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
#region Get
public WFSetup Get(ID id)
{
WFSetup oWFSetup = new WFSetup();
#region Cache Header
oWFSetup = _cache["Get", id] as WFSetup;
if (oWFSetup != null)
return oWFSetup;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(WFSetupDA.Get(tc, id));
if (oreader.Read())
{
oWFSetup = this.CreateObject<WFSetup>(oreader);
}
oreader.Close();
if (oWFSetup != null && oWFSetup.IsNew == false)
{
DataReader dr = new DataReader(WFSetupDA.Get4WFSetupRule(tc, id));
oWFSetup.WFSetupRules = this.CreateWFSetupRuleObject(dr);
dr.Close();
foreach (WFSetupRule oRule in oWFSetup.WFSetupRules)
{
DataReader drd = new DataReader(WFSetupDA.Get4WFRuleDD(tc, oRule.ID.Integer));
oRule.WFRuleDeatilDesignations = this.CreateWFRuleDDObject(drd);
drd.Close();
DataReader drdnode = new DataReader(WFSetupDA.Get4WFRuleNode(tc, oRule.ID.Integer));
oRule.WFRuleDetailNodes = this.CreateWFRuleNodeObject(drdnode);
drdnode.Close();
DataReader drdnos = new DataReader(WFSetupDA.Get4WFRuleDetailOS(tc, oRule.WFSetupId.Integer, oRule.ID.Integer));
oRule.WFRuleDeatilOSs = this.CreateWFRuleDetailOSObject(drdnos);
drdnos.Close();
DataReader drmanual = new DataReader(WFSetupDA.Get4WFRuleDetailManual(tc, oRule.WFSetupId.Integer, oRule.ID.Integer));
oRule.WFRuleDetailManual = this.CreateWFRuleDetailManualObject(drmanual);
drmanual.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(oWFSetup, "Get", id);
#endregion
return oWFSetup;
}
public WFSetup GetByWFTypeID(ID nType)
{
WFSetup oWFSetup = new WFSetup();
#region Cache Header
oWFSetup = (WFSetup)_cache["GetByWFTypeID", nType];
if (oWFSetup != null)
return oWFSetup;
#endregion
#region WF Setup
TransactionContext tc = null;
try
{
DataReader oReader = null;
tc = TransactionContext.Begin();
oReader = new DataReader(WFSetupDA.Get(tc, nType));
if (oReader.Read())
oWFSetup = CreateObject(oReader);
oReader.Close();
if (oWFSetup != null)
{
oReader = new DataReader(WFSetupDA.Get4WFSetupRule(tc, oWFSetup.ID));
oWFSetup.WFSetupRules = CreateWFSetupRuleObject(oReader);
oReader.Close();
if (oWFSetup.WFSetupRules != null)
{
foreach (WFSetupRule oItem in oWFSetup.WFSetupRules)
{
oReader = new DataReader(WFSetupDA.Get4WFRuleDD(tc, oItem.ID.Integer));
oItem.WFRuleDeatilDesignations = CreateWFRuleDDObject(oReader);
oReader.Close();
oReader = new DataReader(WFSetupDA.Get4WFRuleDetailOS(tc, oWFSetup.ID.Integer, oItem.ID.Integer));
oItem.WFRuleDeatilOSs = CreateWFRuleDetailOSObject(oReader);
oReader.Close();
oReader = new DataReader(WFSetupDA.Get4WFRuleNode(tc, oItem.ID.Integer));
oItem.WFRuleDetailNodes = CreateWFRuleNodeObject(oReader);
oReader.Close();
}
}
}
tc.End();
}
catch (ServiceException ex)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(ex);
throw new ServiceException("Failed to Get Work Flow Setup");
#endregion
}
#endregion
#region Cache Footer
_cache.Add(oWFSetup, "GetByWFTypeID", nType);
#endregion
return oWFSetup;
}
public ObjectsTemplate<WFSetup> Get()
{
#region Cache Header
ObjectsTemplate<WFSetup> wfSetups = _cache["Get"] as ObjectsTemplate<WFSetup>;
if (wfSetups != null)
return wfSetups;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(WFSetupDA.Get(tc));
wfSetups = this.CreateObjects<WFSetup>(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(wfSetups, "Get");
#endregion
return wfSetups;
}
public ObjectsTemplate<WFRuleDetailDesignation> Get4WFRuleDD(ID id)
{
#region Cache Header
ObjectsTemplate<WFRuleDetailDesignation> wfRuleDDs = _cache["Get4WFRuleDD", id] as ObjectsTemplate<WFRuleDetailDesignation>;
if (wfRuleDDs != null)
return wfRuleDDs;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(WFSetupDA.Get4WFRuleDD(tc, id.Integer));
wfRuleDDs = this.CreateWFRuleDDObject(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(wfRuleDDs, "Get4WFRuleDD", id);
#endregion
return wfRuleDDs;
}
public ObjectsTemplate<WFRuleDetailNode> Get4WFRuleNode(ID id)
{
#region Cache Header
ObjectsTemplate<WFRuleDetailNode> wfRuleDns = _cache["Get4WFRuleNode", id] as ObjectsTemplate<WFRuleDetailNode>;
if (wfRuleDns != null)
return wfRuleDns;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(WFSetupDA.Get4WFRuleNode(tc, id.Integer));
wfRuleDns = this.CreateWFRuleNodeObject(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(wfRuleDns, "Get4WFRuleNode", id);
#endregion
return wfRuleDns;
}
public ObjectsTemplate<WFSetupRule> Get4WFSetupRule(ID id)
{
#region Cache Header
ObjectsTemplate<WFSetupRule> wfSetupRs = _cache["Get4WFSetupRule", id] as ObjectsTemplate<WFSetupRule>;
if (wfSetupRs != null)
return wfSetupRs;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(WFSetupDA.Get4WFSetupRule(tc, id));
wfSetupRs = this.CreateWFSetupRuleObject(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(wfSetupRs, "Get4WFSetupRule", id);
#endregion
return wfSetupRs;
}
public ObjectsTemplate<WFRuleDetailOS> Get4WFRuleDetailOS(ID id)
{
#region Cache Header
ObjectsTemplate<WFRuleDetailOS> wfRDOSs = _cache["Get4WFRuleDetailOS", id] as ObjectsTemplate<WFRuleDetailOS>;
if (wfRDOSs != null)
return wfRDOSs;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(WFSetupDA.Get4WFRuleDetailOS(tc, id));
wfRDOSs = this.CreateWFRuleDetailOSObject(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(wfRDOSs, "Get4WFRuleDetailOS", id);
#endregion
return wfRDOSs;
}
public ObjectsTemplate<WFRuleDetailManual> Get4WFRuleDetailManual(ID id)
{
ObjectsTemplate<WFRuleDetailManual> wfRDOSs = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(WFSetupDA.Get4WFRuleDetailManual(tc, id));
wfRDOSs = this.CreateWFRuleDetailManualObject(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 wfRDOSs;
}
#endregion
#endregion
#endregion
#region WFSetupRule Mapping
private void MapWFSetupRuleObject(WFSetupRule wfSetupRule, DataReader oReader)
{
base.SetObjectID(wfSetupRule, oReader.GetID("WFSETUPRULEID"));
//wfSetupRule.Name = oReader.GetString("Name");
wfSetupRule.WFSetupId = oReader.GetID("WFSETUPID");
wfSetupRule.StAuthorityLevel = oReader.GetInt32("STAUTHORITYLEVEL").Value;
wfSetupRule.Priority = oReader.GetInt32("PRIORITY").Value;
wfSetupRule.WFRuleType = (EnumWFRuleType)oReader.GetInt32("WFRULETYPE");
wfSetupRule.LevelDepth = oReader.GetInt32("LEVELDEPTH").Value;
wfSetupRule.ReqAppAll = oReader.GetBoolean("REQAPPALL").Value;
wfSetupRule.AutoNotificationNode = oReader.GetID("AUTONOTIFICATIONNODE");
wfSetupRule.FinalDestinationNode = oReader.GetID("FINALDESTINATIONNODE");
wfSetupRule.IsRAuthority = (bool)oReader.GetBoolean("RAUTHORITY");
//wfSetupRule.CreatedBy = oReader.GetID("CREATEDBY");
//wfSetupRule.CreatedDate = oReader.GetDateTime("CREATEDDATE").Value;
//wfSetupRule.ModifiedBy = oReader.GetID("MODIFIEDBY");
//wfSetupRule.ModifiedDate = oReader.GetDateTime("MODIFIEDDATE");
this.SetObjectState(wfSetupRule, Ease.CoreV35.ObjectState.Saved);
}
protected ObjectsTemplate<WFSetupRule> CreateWFSetupRuleObject(DataReader oReader)
{
ObjectsTemplate<WFSetupRule> wfSetupRules = new ObjectsTemplate<WFSetupRule>();
while (oReader.Read())
{
WFSetupRule wfSetupRule = new WFSetupRule();
MapWFSetupRuleObject(wfSetupRule, oReader);
wfSetupRules.Add(wfSetupRule);
}
return wfSetupRules;
}
#endregion
#region WFRuleDetailDesignation Mapping
private void MapWFRuleDDObject(WFRuleDetailDesignation wfDetailDesig, DataReader oReader)
{
base.SetObjectID(wfDetailDesig, oReader.GetID("WFRULEDETAILID"));
wfDetailDesig.DesignationId = oReader.GetID("DESIGNATIONID");
wfDetailDesig.WfSetupId = oReader.GetID("WFSETUPID");
wfDetailDesig.WfSetupRuleId = oReader.GetID("WFSETUPRULEID");
wfDetailDesig.SequenceId = oReader.GetInt32("SEQUENCEID").Value;
this.SetObjectState(wfDetailDesig, Ease.CoreV35.ObjectState.Saved);
}
protected ObjectsTemplate<WFRuleDetailDesignation> CreateWFRuleDDObject(DataReader oReader)
{
ObjectsTemplate<WFRuleDetailDesignation> wfDetailDesigs = new ObjectsTemplate<WFRuleDetailDesignation>();
while (oReader.Read())
{
WFRuleDetailDesignation wfDetailDesig = new WFRuleDetailDesignation();
MapWFRuleDDObject(wfDetailDesig, oReader);
wfDetailDesigs.Add(wfDetailDesig);
}
return wfDetailDesigs;
}
#endregion
#region WFRuleDetailNode Mapping
private void MapWFRuleDetailNodeObject(WFRuleDetailNode wfRuleNode, DataReader oReader)
{
base.SetObjectID(wfRuleNode, oReader.GetID("WFRULEDNODEID"));
wfRuleNode.NodeId = oReader.GetID("NODEID");
wfRuleNode.WfSetupId = oReader.GetID("WFSETUPID");
wfRuleNode.WfSetupRuleId = oReader.GetID("WFSETUPRULEID");
wfRuleNode.SequenceId = oReader.GetInt32("SEQUENCEID").Value;
this.SetObjectState(wfRuleNode, Ease.CoreV35.ObjectState.Saved);
}
protected ObjectsTemplate<WFRuleDetailNode> CreateWFRuleNodeObject(DataReader oReader)
{
ObjectsTemplate<WFRuleDetailNode> wfRuleNodes = new ObjectsTemplate<WFRuleDetailNode>();
while (oReader.Read())
{
WFRuleDetailNode wfRuleNode = new WFRuleDetailNode();
MapWFRuleDetailNodeObject(wfRuleNode, oReader);
wfRuleNodes.Add(wfRuleNode);
}
return wfRuleNodes;
}
#endregion
#region WFRuleDetailOS Mapping
private void MapWFRuleDetailOSObject(WFRuleDetailOS wfRuleDOS, DataReader oReader)
{
base.SetObjectID(wfRuleDOS, oReader.GetID("WFRULEDETAILID"));
wfRuleDOS.OsID = oReader.GetID("OSID");
wfRuleDOS.WfSetupId = oReader.GetID("WFSETUPID");
wfRuleDOS.WfSetupRuleId = oReader.GetID("WFSETUPRULEID");
wfRuleDOS.SequenceId = oReader.GetInt32("SEQUENCEID").Value;
this.SetObjectState(wfRuleDOS, Ease.CoreV35.ObjectState.Saved);
}
protected ObjectsTemplate<WFRuleDetailOS> CreateWFRuleDetailOSObject(DataReader oReader)
{
ObjectsTemplate<WFRuleDetailOS> wfRuleDOSs = new ObjectsTemplate<WFRuleDetailOS>();
while (oReader.Read())
{
WFRuleDetailOS wfRuleDOS = new WFRuleDetailOS();
MapWFRuleDetailOSObject(wfRuleDOS, oReader);
wfRuleDOSs.Add(wfRuleDOS);
}
return wfRuleDOSs;
}
#endregion
#region WFRuleDetailOS Mapping
private void MapWFRuleDetailManual(WFRuleDetailManual wfRuleManual, DataReader oReader)
{
base.SetObjectID(wfRuleManual, oReader.GetID("WFRULEDETAILID"));
wfRuleManual.ObjectID = oReader.GetInt32("ObjectId").Value;
wfRuleManual.RuleType = (enumWFRuleManual)oReader.GetInt32("RuleType");
wfRuleManual.WfSetupId = oReader.GetID("WFSETUPID");
wfRuleManual.WfSetupRuleId = oReader.GetID("WFSETUPRULEID");
wfRuleManual.SequenceId = oReader.GetInt32("SEQUENCEID").Value;
this.SetObjectState(wfRuleManual, Ease.CoreV35.ObjectState.Saved);
}
protected ObjectsTemplate<WFRuleDetailManual> CreateWFRuleDetailManualObject(DataReader oReader)
{
ObjectsTemplate<WFRuleDetailManual> wfRuleDOSs = new ObjectsTemplate<WFRuleDetailManual>();
while (oReader.Read())
{
WFRuleDetailManual wfRuleDOS = new WFRuleDetailManual();
MapWFRuleDetailManual(wfRuleDOS, oReader);
wfRuleDOSs.Add(wfRuleDOS);
}
return wfRuleDOSs;
}
#endregion
}
}