EchoTex_Payroll/HRM.DA/Service/Workflow/WFSetupService.cs

645 lines
22 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using System;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core.Utility;
using System.Collections.Generic;
using HRM.BO;
using System.Data;
using Ease.Core;
using System.Linq;
namespace HRM.DA
{
public class WFSetupService : ServiceTemplate, IWFSetupService
{
#region Constructor
public WFSetupService()
{
}
#endregion
#region WFSetup
#region WFSetup Mapping
private void MapObject(WFSetup wfSetup, DataReader oReader)
{
base.SetObjectID(wfSetup, (oReader.GetInt32("WFSETUPID").Value));
wfSetup.WFTypeId = oReader.GetInt32("WFTYPEID", 0);
wfSetup.CreatedBy = oReader.GetInt32("CREATEDBY", 0);
wfSetup.CreatedDate = oReader.GetDateTime("CREATEDDATE").Value;
wfSetup.ModifiedBy = oReader.GetInt32("MODIFIEDBY", 0);
wfSetup.ModifiedDate = oReader.GetDateTime("MODIFIEDDATE");
wfSetup.Sequence = oReader.GetInt32("SEQUENCENO").Value;
this.SetObjectState(wfSetup, Ease.Core.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 Insert
public int Save(WFSetup wfSetup)
{
TransactionContext tc = null;
try
{
List<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));
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 = null; // 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));
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));
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));
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));
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));
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(int 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(int id)
{
WFSetup oWFSetup = null;
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));
oRule.WFRuleDeatilDesignations = this.CreateWFRuleDDObject(drd);
drd.Close();
DataReader drdnode = new DataReader(WFSetupDA.Get4WFRuleNode(tc, oRule.ID));
oRule.WFRuleDetailNodes = this.CreateWFRuleNodeObject(drdnode);
drdnode.Close();
DataReader drdnos = new DataReader(WFSetupDA.Get4WFRuleDetailOS(tc, oRule.WFSetupId, oRule.ID));
oRule.WFRuleDeatilOSs = this.CreateWFRuleDetailOSObject(drdnos);
drdnos.Close();
DataReader drmanual =
new DataReader(WFSetupDA.Get4WFRuleDetailManual(tc, oRule.WFSetupId, oRule.ID));
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
}
return oWFSetup;
}
public WFSetup GetByWFTypeID(int nType)
{
WFSetup oWFSetup = null;
#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));
oItem.WFRuleDeatilDesignations = CreateWFRuleDDObject(oReader);
oReader.Close();
oReader = new DataReader(WFSetupDA.Get4WFRuleDetailOS(tc, oWFSetup.ID, oItem.ID));
oItem.WFRuleDeatilOSs = CreateWFRuleDetailOSObject(oReader);
oReader.Close();
oReader = new DataReader(WFSetupDA.Get4WFRuleNode(tc, oItem.ID));
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
return oWFSetup;
}
public List<WFSetup> Get()
{
List<WFSetup> wfSetups = null;
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
}
return wfSetups;
}
public List<WFRuleDetailDesignation> Get4WFRuleDD(int id)
{
List<WFRuleDetailDesignation> wfRuleDDs = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(WFSetupDA.Get4WFRuleDD(tc, id));
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
}
return wfRuleDDs;
}
public List<WFRuleDetailNode> Get4WFRuleNode(int id)
{
List<WFRuleDetailNode> wfRuleDns = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(WFSetupDA.Get4WFRuleNode(tc, id));
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
}
return wfRuleDns;
}
public List<WFSetupRule> Get4WFSetupRule(int id)
{
List<WFSetupRule> wfSetupRs = null;
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
}
return wfSetupRs;
}
public List<WFRuleDetailOS> Get4WFRuleDetailOS(int id)
{
List<WFRuleDetailOS> wfRDOSs = null;
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
}
return wfRDOSs;
}
public List<WFRuleDetailManual> Get4WFRuleDetailManual(int id)
{
List<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.GetInt32("WFSETUPRULEID").Value));
//wfSetupRule.Name = oReader.GetString("Name");
wfSetupRule.WFSetupId = oReader.GetInt32("WFSETUPID", 0);
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.GetInt32("AUTONOTIFICATIONNODE", 0);
wfSetupRule.FinalDestinationNode = oReader.GetInt32("FINALDESTINATIONNODE", 0);
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.Core.ObjectState.Saved);
}
protected List<WFSetupRule> CreateWFSetupRuleObject(DataReader oReader)
{
List<WFSetupRule> wfSetupRules = new List<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.GetInt32("WFRULEDETAILID").Value));
wfDetailDesig.DesignationId = oReader.GetInt32("DESIGNATIONID", 0);
wfDetailDesig.WfSetupId = oReader.GetInt32("WFSETUPID", 0);
wfDetailDesig.WfSetupRuleId = oReader.GetInt32("WFSETUPRULEID", 0);
wfDetailDesig.SequenceId = oReader.GetInt32("SEQUENCEID").Value;
this.SetObjectState(wfDetailDesig, Ease.Core.ObjectState.Saved);
}
protected List<WFRuleDetailDesignation> CreateWFRuleDDObject(DataReader oReader)
{
List<WFRuleDetailDesignation> wfDetailDesigs = new List<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.GetInt32("WFRULEDNODEID").Value));
wfRuleNode.NodeId = oReader.GetInt32("NODEID", 0);
wfRuleNode.WfSetupId = oReader.GetInt32("WFSETUPID", 0);
wfRuleNode.WfSetupRuleId = oReader.GetInt32("WFSETUPRULEID", 0);
wfRuleNode.SequenceId = oReader.GetInt32("SEQUENCEID").Value;
this.SetObjectState(wfRuleNode, Ease.Core.ObjectState.Saved);
}
protected List<WFRuleDetailNode> CreateWFRuleNodeObject(DataReader oReader)
{
List<WFRuleDetailNode> wfRuleNodes = new List<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.GetInt32("WFRULEDETAILID").Value));
wfRuleDOS.OsID = oReader.GetInt32("OSID", 0);
wfRuleDOS.WfSetupId = oReader.GetInt32("WFSETUPID", 0);
wfRuleDOS.WfSetupRuleId = oReader.GetInt32("WFSETUPRULEID", 0);
wfRuleDOS.SequenceId = oReader.GetInt32("SEQUENCEID").Value;
this.SetObjectState(wfRuleDOS, Ease.Core.ObjectState.Saved);
}
protected List<WFRuleDetailOS> CreateWFRuleDetailOSObject(DataReader oReader)
{
List<WFRuleDetailOS> wfRuleDOSs = new List<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.GetInt32("WFRULEDETAILID").Value));
wfRuleManual.ObjectID = oReader.GetInt32("ObjectId").Value;
wfRuleManual.RuleType = (enumWFRuleManual)oReader.GetInt32("RuleType");
wfRuleManual.WfSetupId = oReader.GetInt32("WFSETUPID", 0);
wfRuleManual.WfSetupRuleId = oReader.GetInt32("WFSETUPRULEID", 0);
wfRuleManual.SequenceId = oReader.GetInt32("SEQUENCEID").Value;
this.SetObjectState(wfRuleManual, Ease.Core.ObjectState.Saved);
}
protected List<WFRuleDetailManual> CreateWFRuleDetailManualObject(DataReader oReader)
{
List<WFRuleDetailManual> wfRuleDOSs = new List<WFRuleDetailManual>();
while (oReader.Read())
{
WFRuleDetailManual wfRuleDOS = new WFRuleDetailManual();
MapWFRuleDetailManual(wfRuleDOS, oReader);
wfRuleDOSs.Add(wfRuleDOS);
}
return wfRuleDOSs;
}
#endregion
}
}