516 lines
18 KiB
C#
516 lines
18 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using Ease.Core.DataAccess;
|
|||
|
using Ease.Core.Model;
|
|||
|
using HRM.BO;
|
|||
|
using Ease.Core.Utility;
|
|||
|
using System.Data.SqlClient;
|
|||
|
using System.Data;
|
|||
|
using Ease.Core.DataAccess.SQL;
|
|||
|
|
|||
|
namespace HRM.DA
|
|||
|
{
|
|||
|
#region WFRuleService
|
|||
|
|
|||
|
public class WFRuleService : ServiceTemplate, IWFRuleService
|
|||
|
{
|
|||
|
public WFRuleService()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
#region Map of WFRule
|
|||
|
|
|||
|
private void MapObject(WFRule oWFRule, DataReader oReader)
|
|||
|
{
|
|||
|
oWFRule.WFRuleID = oReader.GetInt32("WFRuleID") == null ? 0 : oReader.GetInt32("WFRuleID").Value;
|
|||
|
oWFRule.ID = oWFRule.WFRuleID;
|
|||
|
|
|||
|
oWFRule.WFTypeID = oReader.GetInt32("WFTYPEID") == null ? 0 : oReader.GetInt32("WFTYPEID").Value;
|
|||
|
oWFRule.Weightage = oReader.GetInt32("Weightage") == null ? 0 : oReader.GetInt32("Weightage").Value;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
protected override T CreateObject<T>(DataReader oReader)
|
|||
|
{
|
|||
|
WFRule wfSetup = new WFRule();
|
|||
|
MapObject(wfSetup, oReader);
|
|||
|
return wfSetup as T;
|
|||
|
}
|
|||
|
|
|||
|
protected WFRule CreateObject(DataReader oReader)
|
|||
|
{
|
|||
|
WFRule oWFRule = new WFRule();
|
|||
|
MapObject(oWFRule, oReader);
|
|||
|
return oWFRule;
|
|||
|
}
|
|||
|
|
|||
|
private List<WFRule> CreateObjects(DataReader dr)
|
|||
|
{
|
|||
|
List<WFRule> list = new List<WFRule>();
|
|||
|
while (dr.Read())
|
|||
|
{
|
|||
|
WFRule ot = this.CreateObject(dr);
|
|||
|
list.Add(ot);
|
|||
|
}
|
|||
|
|
|||
|
return list;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Map of WorkflowType
|
|||
|
|
|||
|
//private void MapObjectWorkflowType(WFType oWorkflowType, DataReader oReader)
|
|||
|
//{
|
|||
|
// oWorkflowType.ID = oReader.GetInt32("WorkflowTypeID") == null
|
|||
|
// ? 0
|
|||
|
// : oReader.GetInt32("WorkflowTypeID").Value;
|
|||
|
// oWorkflowType.Name = oReader.GetString("Name");
|
|||
|
// oWorkflowType.Description = oReader.GetString("Description");
|
|||
|
// oWorkflowType.StatusUpdateTable = oReader.GetString("STATUSUPDATETABLE");
|
|||
|
// oWorkflowType.StatusUpdateColumn = oReader.GetInt32("STATUSUPDATECOLUMN") == null
|
|||
|
// ? 0
|
|||
|
// : oReader.GetInt32("STATUSUPDATECOLUMN").Value;
|
|||
|
// oWorkflowType.WebPageLink = oReader.GetString("WEBPAGELINK");
|
|||
|
// oWorkflowType.StatusUpdateTablePK = oReader.GetInt32("STATUSUPDATETABLEPK") == null
|
|||
|
// ? 0
|
|||
|
// : oReader.GetInt32("STATUSUPDATETABLEPK").Value;
|
|||
|
// oWorkflowType.SourceObjectName = oReader.GetString("SourceObjectName");
|
|||
|
//}
|
|||
|
|
|||
|
//private WFType CreateObjectWorkflowType(DataReader oReader)
|
|||
|
//{
|
|||
|
// WFType oWorkflowType = new WFType();
|
|||
|
// this.MapObjectWorkflowType(oWorkflowType, oReader);
|
|||
|
// return oWorkflowType;
|
|||
|
//}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Map of WFRuleManual
|
|||
|
|
|||
|
private void MapObjectWFRuleStep(WFRule.WFStep oWFRuleManual, DataReader oReader)
|
|||
|
{
|
|||
|
oWFRuleManual.wfruleStepID =
|
|||
|
oReader.GetInt32("WFRuleStepID") == null ? 0 : oReader.GetInt32("WFRuleStepID").Value;
|
|||
|
oWFRuleManual.wfruleID = oReader.GetInt32("WFRuleID") == null ? 0 : oReader.GetInt32("WFRuleID").Value;
|
|||
|
oWFRuleManual.StepNo = oReader.GetInt32("StepNo").Value;
|
|||
|
// oWFRuleManual.description = oReader.GetString("description");
|
|||
|
oWFRuleManual.Operator = oReader.GetInt32("Operator") == null
|
|||
|
? EnumwfLogicOperator.No_Operator
|
|||
|
: (EnumwfLogicOperator)oReader.GetInt32("Operator").Value;
|
|||
|
oWFRuleManual.ListActionFieldName = oReader.GetString("ListActionFieldName");
|
|||
|
oWFRuleManual.Amount = oReader.GetInt32("Amount") == null ? 0 : oReader.GetInt32("Amount").Value;
|
|||
|
oWFRuleManual.Action = oReader.GetInt32("Action") == null
|
|||
|
? EnumwfLogicAction.NextStep
|
|||
|
: (EnumwfLogicAction)oReader.GetInt32("Action").Value;
|
|||
|
oWFRuleManual.GoToStepNo =
|
|||
|
oReader.GetInt32("GoToStepNo") == null ? 0 : oReader.GetInt32("GoToStepNo").Value;
|
|||
|
oWFRuleManual.RecomendationEmpID = oReader.GetInt32("RecomendationEmpID") == null
|
|||
|
? 0
|
|||
|
: oReader.GetInt32("RecomendationEmpID").Value;
|
|||
|
oWFRuleManual.RecomendationListFieildID = oReader.GetString("RecomendationListFieildID");
|
|||
|
|
|||
|
oWFRuleManual.NofityAll = oReader.GetBoolean("NofityAll", false);
|
|||
|
oWFRuleManual.AlwaysNotifyToInitiator = oReader.GetBoolean("AlwaysNotifyToInitiator", true);
|
|||
|
oWFRuleManual.ApproveWithinDays = oReader.GetInt32("ApproveWithinDays", int.MinValue);
|
|||
|
oWFRuleManual.FieldNamesforMail = oReader.GetString("FieldNamesforMail", string.Empty);
|
|||
|
oWFRuleManual.MailBeforeApproveDays = oReader.GetInt32("MailBeforeApproveDays", int.MinValue);
|
|||
|
}
|
|||
|
|
|||
|
private WFRule.WFStep CreateObjectWFRuleStep(DataReader oReader)
|
|||
|
{
|
|||
|
WFRule.WFStep oWFRuleManual = new WFRule.WFStep();
|
|||
|
this.MapObjectWFRuleStep(oWFRuleManual, oReader);
|
|||
|
return oWFRuleManual;
|
|||
|
}
|
|||
|
|
|||
|
private List<WFRule.WFStep> CreateObjectWFRuleSteps(DataReader dr)
|
|||
|
{
|
|||
|
List<WFRule.WFStep> list = new List<WFRule.WFStep>();
|
|||
|
while (dr.Read())
|
|||
|
{
|
|||
|
WFRule.WFStep ot = this.CreateObjectWFRuleStep(dr);
|
|||
|
list.Add(ot);
|
|||
|
}
|
|||
|
|
|||
|
return list;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
#region Map of WFRule
|
|||
|
|
|||
|
private void MapObjectWFRuleActor(WFRule.WFStep.WFStepActor actor, DataReader oReader)
|
|||
|
{
|
|||
|
actor.WFRuleID = oReader.GetInt32("WFRuleID") == null ? 0 : oReader.GetInt32("WFRuleID").Value;
|
|||
|
actor.WFStepID = oReader.GetInt32("WFStepID").Value;
|
|||
|
actor.WFStepActorID = oReader.GetInt32("WFStepActorID").Value;
|
|||
|
|
|||
|
actor.WFActorType = oReader.GetInt32("WFActorType") == null
|
|||
|
? EnumWFActorType.Not_Defined
|
|||
|
: (EnumWFActorType)oReader.GetInt32("WFActorType").Value;
|
|||
|
actor.ObjectID = oReader.GetInt32("ObjectID", int.MinValue);
|
|||
|
actor.StepName = oReader.GetString("WFStepActorID", string.Empty);
|
|||
|
actor.ListFieldName = oReader.GetString("ListFieldName", string.Empty);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
protected WFRule.WFStep.WFStepActor CreateObjectwfRuleActor(DataReader oReader)
|
|||
|
{
|
|||
|
WFRule.WFStep.WFStepActor oWFRule = new WFRule.WFStep.WFStepActor();
|
|||
|
MapObjectWFRuleActor(oWFRule, oReader);
|
|||
|
return oWFRule;
|
|||
|
}
|
|||
|
|
|||
|
private List<WFRule.WFStep.WFStepActor> CreateObjectWFRuleStepActors(DataReader dr)
|
|||
|
{
|
|||
|
List<WFRule.WFStep.WFStepActor> list = new List<WFRule.WFStep.WFStepActor>();
|
|||
|
while (dr.Read())
|
|||
|
{
|
|||
|
WFRule.WFStep.WFStepActor ot = this.CreateObjectwfRuleActor(dr);
|
|||
|
list.Add(ot);
|
|||
|
}
|
|||
|
|
|||
|
return list;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Map of WFRuleCategory
|
|||
|
|
|||
|
public WFType GetWorkFlowType(int typeid)
|
|||
|
{
|
|||
|
WFType WorkflowType = null;
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader dr = new DataReader(tc.ExecuteReader("Select *from wftype where WFtypeID=%n", typeid));
|
|||
|
//WorkflowTypes = this.CreateObjects<WFRule.GetWorkFlow>(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 WorkflowType;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Service implementation of WFRule
|
|||
|
|
|||
|
|
|||
|
public WFRule Get(int id)
|
|||
|
{
|
|||
|
WFRule oWFRule = new WFRule();
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
oWFRule = this.Get(tc, id);
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return oWFRule;
|
|||
|
|
|||
|
}
|
|||
|
public WFRule Get(TransactionContext tc, int id)
|
|||
|
{
|
|||
|
WFRule oWFRule = new WFRule();
|
|||
|
try
|
|||
|
{
|
|||
|
DataReader oreader = new DataReader(tc.ExecuteReader("select *from wfrule where WFruleid=%n", id));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oWFRule = this.CreateObject(oreader);
|
|||
|
}
|
|||
|
|
|||
|
oreader.Close();
|
|||
|
|
|||
|
// Get WFRule.WorkflowType
|
|||
|
if (oWFRule != null)
|
|||
|
{
|
|||
|
DataReader oinc = new DataReader(tc.ExecuteReader("select *from wfruleStep where wfruleID=%n", id));
|
|||
|
oWFRule.Steps = this.CreateObjectWFRuleSteps(oinc);
|
|||
|
oinc.Close();
|
|||
|
|
|||
|
DataReader oactors =
|
|||
|
new DataReader(tc.ExecuteReader("select *from wfruleStepActor where WFRuleID=%n", id));
|
|||
|
List<WFRule.WFStep.WFStepActor> stepActors = this.CreateObjectWFRuleStepActors(oactors);
|
|||
|
oactors.Close();
|
|||
|
|
|||
|
if (stepActors != null && stepActors.Count != 0)
|
|||
|
{
|
|||
|
foreach (WFRule.WFStep item in oWFRule.Steps)
|
|||
|
item.Actors = stepActors.Where(x => x.WFStepID == item.wfruleStepID).ToList();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
throw new Exception(e.Message);
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return oWFRule;
|
|||
|
}
|
|||
|
|
|||
|
public DataTable getAllRules()
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataSet odataset = tc.ExecuteDataSet(
|
|||
|
@"select *from WfRule, workflowType where wfRule.WorkFlowType=WorkFlowtype.WorkflowTypeid
|
|||
|
");
|
|||
|
if (odataset != null && odataset.Tables.Count > 0)
|
|||
|
return odataset.Tables[0];
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public List<WFRule> GetRules(int wftypeid)
|
|||
|
{
|
|||
|
List<WFRule> oWFRules = null;
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
oWFRules = this.GetRules(tc,wftypeid);
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return oWFRules;
|
|||
|
}
|
|||
|
public List<WFRule> GetRules(TransactionContext tc, int wftypeid)
|
|||
|
{
|
|||
|
List<WFRule> oWFRules = null;
|
|||
|
try
|
|||
|
{
|
|||
|
DataReader dr = new DataReader(tc.ExecuteReader("select *from wfrule where wftypeid=%n", wftypeid));
|
|||
|
oWFRules = this.CreateObjects(dr);
|
|||
|
dr.Close();
|
|||
|
|
|||
|
if(oWFRules !=null)
|
|||
|
{
|
|||
|
oWFRules.ForEach(x =>
|
|||
|
{
|
|||
|
DataReader oinc = new DataReader(tc.ExecuteReader("select *from wfruleStep where wfruleID=%n", x.ID));
|
|||
|
x.Steps = this.CreateObjectWFRuleSteps(oinc);
|
|||
|
oinc.Close();
|
|||
|
|
|||
|
DataReader oactors =
|
|||
|
new DataReader(tc.ExecuteReader("select *from wfruleStepActor where WFRuleID=%n", x.ID));
|
|||
|
List<WFRule.WFStep.WFStepActor> stepActors = this.CreateObjectWFRuleStepActors(oactors);
|
|||
|
oactors.Close();
|
|||
|
|
|||
|
if (stepActors != null && stepActors.Count != 0)
|
|||
|
{
|
|||
|
foreach (WFRule.WFStep item in x.Steps)
|
|||
|
item.Actors = stepActors.Where(x => x.WFStepID == item.wfruleStepID).ToList();
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return oWFRules;
|
|||
|
}
|
|||
|
|
|||
|
public List<WFRule> Get()
|
|||
|
{
|
|||
|
List<WFRule> oWFRules = null;
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader dr = new DataReader(tc.ExecuteReader("select *from wfrule"));
|
|||
|
oWFRules = this.CreateObjects(dr);
|
|||
|
dr.Close();
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return oWFRules;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public void Delete(int ruleid)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
tc.ExecuteNonQuery("delete from WFRuleStepActor where wfruleid=%n", ruleid);
|
|||
|
tc.ExecuteNonQuery("delete from wfruleStep where wfruleid=%n", ruleid);
|
|||
|
tc.ExecuteNonQuery("delete from wfrule where wfruleid=%n", ruleid);
|
|||
|
|
|||
|
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public int Save(WFRule wfRule)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
|
|||
|
#region save parent-class
|
|||
|
|
|||
|
if (wfRule.IsNew)
|
|||
|
{
|
|||
|
|
|||
|
int newID = tc.GenerateID("WFRule", "WFRuleID");
|
|||
|
tc.ExecuteNonQuery(@"Insert into WFRULE
|
|||
|
(WFRuleID, WFTypeID,Weightage,WFAdminEmpID,delayDaysToNofityAdmin,delayDaysToNotifyInitiator,CreatedBy,CreatedDate)
|
|||
|
Values(%n, %n, %n, %n, %n, %n, %n, %d)", newID, wfRule.WFTypeID
|
|||
|
, wfRule.Weightage, wfRule.WFAdminEmpID, wfRule.delayDaysToNofityAdmin,
|
|||
|
wfRule.delayDaysToNotifyInitiator, wfRule.CreatedBy, wfRule.CreatedDate);
|
|||
|
|
|||
|
wfRule.ID = newID;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
tc.ExecuteNonQuery("delete from WFRuleStepActor where wfruleid=%n", wfRule.WFRuleID);
|
|||
|
tc.ExecuteNonQuery("delete from wfruleStep where wfruleid=%n", wfRule.WFRuleID);
|
|||
|
|
|||
|
}
|
|||
|
foreach (var step in wfRule.Steps)
|
|||
|
{
|
|||
|
step.wfruleID = wfRule.ID;
|
|||
|
int newID = tc.GenerateID("WFRuleStep", "WFRuleStepID");
|
|||
|
|
|||
|
tc.ExecuteNonQuery(@"Insert into WFRuleStep
|
|||
|
(WFRuleStepID, WFRuleID, StepNo, ReqAppAll,ListActionFieldName,Amount,Operator,Action
|
|||
|
,GoToStepNo,RecomendationEmpID,RecomendationListFieildID,ApproveWithinDays,MailBeforeApproveDays,
|
|||
|
AlwaysNotifyToInitiator,NofityAll,AddtionalNotifyEmpID,AdditionalText,FieldNamesforMail)
|
|||
|
Values(%n, %n, %n, %b, %s, %n, %n, %n
|
|||
|
,%n,%n, %n, %n, %n,
|
|||
|
%b, %b,%n, %s, %s)",
|
|||
|
newID, step.wfruleID, step.StepNo, step.ReqAppAll, step.ListActionFieldName, step.Amount,
|
|||
|
step.Operator, step.Action
|
|||
|
, step.GoToStepNo, step.RecomendationEmpID, step.RecomendationListFieildID,
|
|||
|
step.ApproveWithinDays, step.MailBeforeApproveDays
|
|||
|
, step.AlwaysNotifyToInitiator, step.NofityAll, step.AddtionalNotifyEmpID,
|
|||
|
step.AdditionalText, step.FieldNamesforMail);
|
|||
|
step.wfruleStepID = newID;
|
|||
|
foreach (var actor in step.Actors)
|
|||
|
{
|
|||
|
actor.WFRuleID = wfRule.ID;
|
|||
|
actor.WFStepID = step.wfruleStepID;
|
|||
|
|
|||
|
newID = tc.GenerateID("WFRuleStepActor", "WFStepActorID");
|
|||
|
|
|||
|
tc.ExecuteNonQuery(@"Insert into WFRuleStepActor
|
|||
|
(WFStepActorID, WFRuleID, WFStepID, WFActorType, ObjectID,ListFieldName)
|
|||
|
Values(%n, %n, %n, %n, %n, %s)",
|
|||
|
newID, actor.WFRuleID, actor.WFStepID,
|
|||
|
actor.WFActorType, actor.ObjectID, actor.ListFieldName);
|
|||
|
actor.WFStepActorID = newID;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
|
|||
|
#region save all sub-class
|
|||
|
|
|||
|
// save WorkflowType
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return wfRule.WFRuleID;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|