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

533 lines
23 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ease.PPIC.BO;
using Ease.Core.DataAccess;
using Ease.CoreSL.Model;
using System.Data.SqlClient;
using System.Data;
using Ease.Core.DataAccess.SQL;
namespace Ease.PPIC.DataAccess
{
#region WFMovementTranService
public class WFMovementTranService : ServiceTemplate
{
public WFMovementTranService()
: base("BasicDataService")
{
}
#region Map of WFMovementTran
private void MapObject(WFMovementTran oWFMovementTran, DataReader oReader)
{
oWFMovementTran.WFMovementTranID = oReader.GetInt32("WFMovementTranID") == null ? 0 : oReader.GetInt32("WFMovementTranID").Value;
oWFMovementTran.WfRuleID = oReader.GetInt32("WfRuleID") == null ? 0 : oReader.GetInt32("WfRuleID").Value;
oWFMovementTran.ObjectID = oReader.GetInt32("ObjectID") == null ? 0 : oReader.GetInt32("ObjectID").Value;
oWFMovementTran.WFStatus = (EnumwfStatus)oReader.GetInt32("WFStatus").Value;
oWFMovementTran.UniqueNumber = oReader.GetInt32("UniqueNumber") == null ? 0 : oReader.GetInt32("UniqueNumber").Value;
oWFMovementTran.RuleStepNo = oReader.GetInt32("Tier") == null ? 0 : oReader.GetInt32("Tier").Value;
oWFMovementTran.ObjectDescription = oReader.GetString("ObjectDescription");
// this.SetObjectState(oWFMovementTran, ESOL.Core.ObjectState.Saved);
}
protected WFMovementTran CreateObject(DataReader oReader)
{
WFMovementTran oWFMovementTran = new WFMovementTran();
MapObject(oWFMovementTran, oReader);
return oWFMovementTran;
}
#endregion
#region Map of WFMovementNext
private void MapObjectWFMovementNext(WFMovementTran.WFMovementNext oWFMovementNext, DataReader oReader)
{
oWFMovementNext.WFMovementNextID = oReader.GetInt32("WFMovementNextID") == null ? 0 : oReader.GetInt32("WFMovementNextID").Value;
oWFMovementNext.WFMovementTranID = oReader.GetInt32("WFMovementTranID") == null ? 0 : oReader.GetInt32("WFMovementTranID").Value;
oWFMovementNext.EmployeeID = oReader.GetInt32("EmployeeID") == null ? 0 : oReader.GetInt32("EmployeeID").Value;
oWFMovementNext.Status = (EnumwfStatus)oReader.GetInt32("Status").Value;
oWFMovementNext.Remarks = oReader.GetString("Remarks");
oWFMovementNext.Description = oReader.GetString("Description");
oWFMovementNext.Viewed = oReader.GetBoolean("Viewed").Value;
oWFMovementNext.SequeceNo= oReader.GetInt32("SequeceNo").Value;
oWFMovementNext.ReceiveDateTime = oReader.GetDateTime("Viewed", DateTime.MinValue);
oWFMovementNext.StatusUpdateTime = oReader.GetDateTime("StatusUpdateTime") == null ? DateTime.MinValue : oReader.GetDateTime("StatusUpdateTime").Value;
oWFMovementNext.HaltReason = oReader.GetString("HaltReason");
oWFMovementNext.HaltReasonDatetime = oReader.GetDateTime("HaltReasonDatetime") == null ? DateTime.MinValue : oReader.GetDateTime("HaltReasonDatetime").Value;
oWFMovementNext.AlternateActionEmpID = oReader.GetInt32("AlternateActionEmpID") == null ? 0 : oReader.GetInt32("AlternateActionEmpID").Value;
oWFMovementNext.AlternateActionType = oReader.GetInt32("AlternateActionType") == null ? EnumAlternateActionType.None : (EnumAlternateActionType) oReader.GetInt32("AlternateActionType").Value;
}
private WFMovementTran.WFMovementNext CreateObjectWFMovementNext(DataReader oReader)
{
WFMovementTran.WFMovementNext oWFMovementNext = new WFMovementTran.WFMovementNext();
this.MapObjectWFMovementNext(oWFMovementNext, oReader);
return oWFMovementNext;
}
private List<WFMovementTran.WFMovementNext> CreateObjectWFMovementNexts(DataReader dr)
{
List<WFMovementTran.WFMovementNext> list = new List<WFMovementTran.WFMovementNext>();
while (dr.Read())
{
WFMovementTran.WFMovementNext ot = this.CreateObjectWFMovementNext(dr);
list.Add(ot);
}
return list;
}
#endregion
#region Map of WFAmendment
private void MapObjectWFAmendment(WFMovementTran.WFAmendment oWFAmendment, DataReader oReader)
{
oWFAmendment.WFAmendmentID = oReader.GetInt32("WFAmendmentID") == null ? 0 : oReader.GetInt32("WFAmendmentID").Value;
oWFAmendment.WFMovementTranID = oReader.GetInt32("WFMovementTranID") == null ? 0 : oReader.GetInt32("WFMovementTranID").Value;
oWFAmendment.EmployeeID = oReader.GetInt32("EmployeeID") == null ? 0 : oReader.GetInt32("EmployeeID").Value;
oWFAmendment.AmendmentText = oReader.GetDouble("AmendmentText") == null ? 0 : oReader.GetDouble("AmendmentText").Value;
}
private WFMovementTran.WFAmendment CreateObjectWFAmendment(DataReader oReader)
{
WFMovementTran.WFAmendment oWFAmendment = new WFMovementTran.WFAmendment();
this.MapObjectWFAmendment(oWFAmendment, oReader);
return oWFAmendment;
}
private List<WFMovementTran.WFAmendment> CreateObjectWFAmendments(DataReader dr)
{
List<WFMovementTran.WFAmendment> list = new List<WFMovementTran.WFAmendment>();
while (dr.Read())
{
WFMovementTran.WFAmendment ot = this.CreateObjectWFAmendment(dr);
list.Add(ot);
}
return list;
}
#endregion
#region Map of WFMOVEMENTTASK
private void MapObjectWFMOVEMENTTASK(WFMovementTran.WFMovementTask oWFMOVEMENTTASK, DataReader oReader)
{
oWFMOVEMENTTASK.WFMovementTaskID = oReader.GetInt32("WFMOVEMENTTASKID") == null ? 0 : oReader.GetInt32("WFMOVEMENTTASKID").Value;
oWFMOVEMENTTASK.WFMovementTranID = oReader.GetInt32("WFMovementTranID") == null ? 0 : oReader.GetInt32("WFMovementTranID").Value;
oWFMOVEMENTTASK.EmployeeID = oReader.GetInt32("EMPLOYEEID") == null ? 0 : oReader.GetInt32("EMPLOYEEID").Value;
oWFMOVEMENTTASK.TaskType = (EnumWFTaskType)oReader.GetUInt32("TaskType").Value;
oWFMOVEMENTTASK.WFMovementSequeceNo = oReader.GetInt32("WFMovementSequeceNo", 0);
oWFMOVEMENTTASK.MailSendStatus = oReader.GetBoolean("MAILSENDStatus").Value;
oWFMOVEMENTTASK.Subject = oReader.GetString("Subject");
oWFMOVEMENTTASK.Detail = oReader.GetString("Detail");
oWFMOVEMENTTASK.WebNotificationRead = oReader.GetBoolean("WebNotificationRead", false);
if(oReader.GetDateTime("WebNotificationReadTime") != null)
oWFMOVEMENTTASK.WebNotificationReadTime = oReader.GetDateTime("WebNotificationReadTime", DateTime.MinValue);
oWFMOVEMENTTASK.MailSendStatus = oReader.GetBoolean("MailSendStatus",false);
oWFMOVEMENTTASK.MailSendType = (enumMailSendType) oReader.GetInt32("MailSendType").Value;
if (oReader.GetDateTime("MailSentTime") != null)
oWFMOVEMENTTASK.MailSentTime = oReader.GetDateTime("MailSentTime").Value;
}
private WFMovementTran.WFMovementTask CreateObjectWFMOVEMENTTASK(DataReader oReader)
{
WFMovementTran.WFMovementTask oWFMOVEMENTTASK = new WFMovementTran.WFMovementTask();
this.MapObjectWFMOVEMENTTASK(oWFMOVEMENTTASK, oReader);
return oWFMOVEMENTTASK;
}
private List<WFMovementTran.WFMovementTask> CreateObjectWFMOVEMENTTASKs(DataReader dr)
{
List<WFMovementTran.WFMovementTask> list = new List<WFMovementTran.WFMovementTask>();
while (dr.Read())
{
WFMovementTran.WFMovementTask ot = this.CreateObjectWFMOVEMENTTASK(dr);
list.Add(ot);
}
return list;
}
#endregion
#region Service implementation of WFMovementTran
public WFMovementTran Get(int id)
{
WFMovementTran oWFMovementTran = new WFMovementTran();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(this.ServiceName);
DataReader oreader = new DataReader(tc.ExecuteReader("select *from WFMovementTran where WFMovementTranID=%n", id));
if (oreader.Read())
{
oWFMovementTran = this.CreateObject(oreader);
}
oreader.Close();
// Get WFMovementNexts
if (oWFMovementTran != null)
{
DataReader oinc = new DataReader(tc.ExecuteReader("select *from WFMovementTranNext where WFMovementTranID=%n,id"));
oWFMovementTran.WFMovementNexts = this.CreateObjectWFMovementNexts(oinc);
oinc.Close();
}
//// get WFAmendments
//if (oWFMovementTran != null)
//{
// DataReader oinc = new DataReader(tc.ExecuteReader("",id));
// oWFMovementTran.WFAmendments = this.CreateObjectWFAmendments(oinc);
// oinc.Close();
//}
// get WFMOVEMENTTASKs
if (oWFMovementTran != null)
{
DataReader oinc = new DataReader(tc.ExecuteReader("select *from WFMovementTranTask where WFMovementTranID=%n", id));
oWFMovementTran.WFMOVEMENTTASKs = this.CreateObjectWFMOVEMENTTASKs(oinc);
oinc.Close();
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
#endregion
}
return oWFMovementTran;
}
/// <summary>
/// No need detail
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
public List<WFMovementTran> Search(string query)
{
List<WFMovementTran> WFMovementTrans = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(this.ServiceName);
DataReader dr = new DataReader(tc.ExecuteReader(query));
// WFMovementTrans = this.CreateObjects<WFMovementTran>(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
#endregion
}
return WFMovementTrans;
}
public int Save(WFMovementTran item)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true, this.ServiceName);
if (item.RuleStepNo == 0 && item.UniqueNumber != 0)
item.UniqueNumber = this.GetUniqueNumber(tc);
string procName;
var p = new List<SqlParameter>
{
SqlHelperExtension.CreateInParam("@wftypeid", SqlDbType.VarChar, item.wftypeid),
SqlHelperExtension.CreateInParam("@WfRuleID", SqlDbType.Int, item.WfRuleID),
SqlHelperExtension.CreateInParam("@ObjectID", SqlDbType.Int, item.ObjectID),
SqlHelperExtension.CreateInParam("@WFStatus", SqlDbType.Int, item.WFStatus),
SqlHelperExtension.CreateInParam("@UniqueNumber", SqlDbType.Int, item.UniqueNumber),
SqlHelperExtension.CreateInParam("@RuleStepNo", SqlDbType.VarChar, item.RuleStepNo),
SqlHelperExtension.CreateInParam("@ObjectDescription", SqlDbType.Int, item.ObjectDescription),
SqlHelperExtension.CreateOutParam("@WFMovementTranID", SqlDbType.Int, item.WFMovementTranID),
};
procName = "[dbo].[InsertWFMovementTran]";
tc.ExecuteNonQuery(CommandType.StoredProcedure, procName, p.ToArray());
item.PKID = Convert.ToInt64(p.First(x => x.ParameterName == "@WFMovementTranID").Value);
item.WFMovementTranID = Convert.ToInt32(item.PKID);
foreach (WFMovementTran.WFMovementNext next in item.WFMovementNexts)
{
next.WFMovementTranID = Convert.ToInt32( item.PKID);
var n = new List<SqlParameter>
{
SqlHelperExtension.CreateInParam("@wftypeid", SqlDbType.Int, next.WFMovementTranID),
SqlHelperExtension.CreateInParam("@EmployeeID", SqlDbType.Int, next.EmployeeID),
SqlHelperExtension.CreateInParam("@Status", SqlDbType.Int, next.Status),
SqlHelperExtension.CreateInParam("@Remarks", SqlDbType.VarChar, next.Remarks),
SqlHelperExtension.CreateInParam("@Description", SqlDbType.VarChar, next.Description),
SqlHelperExtension.CreateInParam("@Viewed", SqlDbType.Bit, next.Viewed),
SqlHelperExtension.CreateInParam("@SequeceNo", SqlDbType.Int, next.SequeceNo),
SqlHelperExtension.CreateInParam("@ReceiveDateTime", SqlDbType.DateTime, next.ReceiveDateTime),
SqlHelperExtension.CreateInParam("@viewDateTime", SqlDbType.DateTime, next.viewDateTime),
SqlHelperExtension.CreateInParam("@StatusUpdateTime", SqlDbType.DateTime, next.StatusUpdateTime),
SqlHelperExtension.CreateInParam("@HaltReason", SqlDbType.VarChar, next.HaltReason),
SqlHelperExtension.CreateInParam("@HaltReasonDatetime", SqlDbType.DateTime, next.HaltReasonDatetime),
SqlHelperExtension.CreateInParam("@AlternateActionEmpID", SqlDbType.Int, next.AlternateActionEmpID),
SqlHelperExtension.CreateInParam("@AlternateActionType", SqlDbType.Int, next.AlternateActionType),
SqlHelperExtension.CreateOutParam("@WFMovementNextID", SqlDbType.Int, next.WFMovementNextID),
};
procName = "[dbo].[InsertWFMovementNext]";
tc.ExecuteNonQuery(CommandType.StoredProcedure, procName, n.ToArray());
next.WFMovementNextID = Convert.ToInt32(p.First(x => x.ParameterName == "@WFMovementNextID").Value);
}
foreach (WFMovementTran.WFMovementTask next in item.WFMOVEMENTTASKs)
{
next.WFMovementTranID = Convert.ToInt32(item.PKID);
var n = new List<SqlParameter>
{
SqlHelperExtension.CreateInParam("@WFMovementTranID", SqlDbType.Int, next.WFMovementTranID),
SqlHelperExtension.CreateInParam("@WFMovementSequeceNo", SqlDbType.Int, next.WFMovementSequeceNo),
SqlHelperExtension.CreateInParam("@EmployeeID", SqlDbType.Int, next.EmployeeID),
SqlHelperExtension.CreateInParam("@TaskType", SqlDbType.Int, next.TaskType),
SqlHelperExtension.CreateInParam("@Subject", SqlDbType.VarChar, next.Subject),
SqlHelperExtension.CreateInParam("@Detail", SqlDbType.VarChar, next.Detail),
SqlHelperExtension.CreateInParam("@WebNotificationRead", SqlDbType.Bit, next.WebNotificationRead),
SqlHelperExtension.CreateInParam("@WebNotificationReadTime", SqlDbType.DateTime, next.WebNotificationReadTime),
SqlHelperExtension.CreateInParam("@MailSendStatus", SqlDbType.Int, next.MailSendStatus),
SqlHelperExtension.CreateInParam("@MailSendType", SqlDbType.Int, next.MailSendType),
SqlHelperExtension.CreateInParam("@MailSentTime", SqlDbType.DateTime, next.MailSentTime),
SqlHelperExtension.CreateOutParam("@WFMovementTaskID", SqlDbType.Int, next.WFMovementTaskID),
};
procName = "[dbo].[InsertWFMovementTask]";
tc.ExecuteNonQuery(CommandType.StoredProcedure, procName, n.ToArray());
next.WFMovementTaskID = Convert.ToInt32(p.First(x => x.ParameterName == "@WFMovementTaskID").Value);
}
tc.End();
return item.WFMovementTranID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
#endregion
}
return 0;
}
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true, this.ServiceName);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
#endregion
}
}
#endregion
#region Service implementation of WFMovementNext
public WFMovementTran.WFMovementNext GetWFMovementNext(int id)
{
WFMovementTran.WFMovementNext oWFMovementNext = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(this.ServiceName);
DataReader dr = new DataReader(tc.ExecuteReader("",id));
oWFMovementNext = this.CreateObjectWFMovementNext(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
#endregion
}
return oWFMovementNext;
}
public List<WFMovementTran.WFMovementNext> GetWFMovementNexts(int WFMovementTranID)
{
List<WFMovementTran.WFMovementNext> oWFMovementNexts = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(this.ServiceName);
DataReader dr = new DataReader(tc.ExecuteReader("",WFMovementTranID));
oWFMovementNexts = this.CreateObjectWFMovementNexts(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
#endregion
}
return oWFMovementNexts;
}
#endregion
public int GetUniqueNumber(TransactionContext tc)
{
object nUniqueNumber = 0;
nUniqueNumber = tc.ExecuteScalar("SELECT MAX(UniqueNumber) FROM WFMovementTran ");
if (nUniqueNumber != DBNull.Value)
{
return Convert.ToInt32(nUniqueNumber) + 1;
}
else
{
return 1;
}
}
public static int GetInitiator(TransactionContext tc, int tranid)
{
object oRevertNode;
oRevertNode = tc.ExecuteScalar(@"SELECT wn.employeeid FROM WFMovementTran w,WFMovementNext wn WHERE w.Uniquenumber=("
+ " select ww.Uniquenumber WFMovementTran ww where ww.WFMovementTran=%n) and SequeceNo=1" + "", tranid);
if (oRevertNode == DBNull.Value)
{
return -1;
}
else
{
return Convert.ToInt32(oRevertNode);
}
}
#region Service implementation of WFAmendment
public WFMovementTran.WFAmendment GetWFAmendment(int id)
{
WFMovementTran.WFAmendment oWFAmendment = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(this.ServiceName);
DataReader dr = new DataReader(tc.ExecuteReader("",id));
oWFAmendment = this.CreateObjectWFAmendment(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
#endregion
}
return oWFAmendment;
}
public List<WFMovementTran.WFAmendment> GetWFAmendments(int WFMovementTranID)
{
List<WFMovementTran.WFAmendment> oWFAmendments = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(this.ServiceName);
DataReader dr = new DataReader(tc.ExecuteReader("",WFMovementTranID));
oWFAmendments = this.CreateObjectWFAmendments(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
#endregion
}
return oWFAmendments;
}
#endregion
#region Service implementation of WFMOVEMENTTASK
public WFMovementTran.WFMovementTask GetWFMOVEMENTTASK(int id)
{
WFMovementTran.WFMovementTask oWFMOVEMENTTASK = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(this.ServiceName);
DataReader dr = new DataReader(tc.ExecuteReader("",id));
oWFMOVEMENTTASK = this.CreateObjectWFMOVEMENTTASK(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
#endregion
}
return oWFMOVEMENTTASK;
}
public List<WFMovementTran.WFMovementTask> GetWFMOVEMENTTASKs(int WFMovementTranID)
{
List<WFMovementTran.WFMovementTask> oWFMOVEMENTTASKs = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(this.ServiceName);
DataReader dr = new DataReader(tc.ExecuteReader("",WFMovementTranID));
oWFMOVEMENTTASKs = this.CreateObjectWFMOVEMENTTASKs(dr);
dr.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
#endregion
}
return oWFMOVEMENTTASKs;
}
#endregion
}
#endregion
}