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; using System.Reflection; namespace HRM.DA { public class WFMovementTranService : ServiceTemplate, IWFMovementTranService { #region Constructor public WFMovementTranService() { } #endregion #region WFMovementTran private void MapObject(WFMovementTran wfMovementTran, DataReader oReader) { base.SetObjectID(wfMovementTran, (oReader.GetInt32("WFMOVEMENTTRANID").Value)); wfMovementTran.FromEmployeeID = oReader.GetInt32("FROMEMPLOYEEID", 0); wfMovementTran.FromNodeID = oReader.GetInt32("FROMNODEID", 0); wfMovementTran.WFTypeID = oReader.GetInt32("WFtypeid", 0); wfMovementTran.WFRuleID = oReader.GetInt32("WFRULEID", 0); wfMovementTran.ObjectID = oReader.GetInt32("OBJECTID", 0); wfMovementTran.IsActive = oReader.GetBoolean("ISACTIVE").Value; wfMovementTran.Senttime = oReader.GetDateTime("SENTTIME").HasValue ? oReader.GetDateTime("SENTTIME").Value : DateTime.MinValue; wfMovementTran.Status = (EnumwfStatus)oReader.GetInt32("WFSTATUS").Value; wfMovementTran.UniqueNumber = oReader.GetInt32("UNIQUENUMBER").Value; wfMovementTran.Remarks = oReader.GetString("REMARKS"); wfMovementTran.Tier = oReader.GetInt32("TIER").Value; wfMovementTran.ObjectDescription = oReader.GetString("OBJECTDESCRIPTION"); this.SetObjectState(wfMovementTran, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { WFMovementTran wfMovementTran = new WFMovementTran(); MapObject(wfMovementTran, oReader); return wfMovementTran as T; } protected WFMovementTran CreateObject(DataReader oReader) { WFMovementTran wfMovementTran = new WFMovementTran(); MapObject(wfMovementTran, oReader); return wfMovementTran; } //protected WFMovementTask CreateWFMovementTaskObject(DataReader oReader) //{ // WFMovementTask wfMTask = new WFMovementTask(); // MapWFMTaskObject(wfMTask, oReader); // return wfMTask; //} #endregion #region WFMovementTask private void MapWFMTaskObject(WFMovementTask wfMTask, DataReader oReader) { base.SetObjectID(wfMTask, (oReader.GetInt32("WFMOVEMENTTASKID").Value)); wfMTask.WFMovementTranID = oReader.GetInt32("WFMOVEMENTTRANID", 0); wfMTask.EmployeeID = oReader.GetInt32("EmployeeID", 0); wfMTask.NodeID = oReader.GetInt32("NODEID", 0); wfMTask.Status = oReader.GetBoolean("STATUS").Value; wfMTask.Remarks = oReader.GetString("REMARKS"); wfMTask.TasksType = (EnumWFNotifyType)oReader.GetInt32("TASKSTYPE").Value; wfMTask.MailSendType = (enumMailSendType)oReader.GetInt32("MAILSENDTYPE").Value; wfMTask.SentTime = oReader.GetDateTime("SENTTIME").HasValue ? oReader.GetDateTime("SENTTIME").Value : DateTime.MinValue; wfMTask.Description = oReader.GetString("DESCRIPTION"); wfMTask.ReceiveStatus = (EnumWFReceiveStatus)oReader.GetInt32("RECEIVESTATUS").Value; this.SetObjectState(wfMTask, Ease.Core.ObjectState.Saved); } protected WFMovementTask CreateWFMovementTaskObject(DataReader oReader) { WFMovementTask wfMTask = new WFMovementTask(); MapWFMTaskObject(wfMTask, oReader); return wfMTask; } protected List CreateWFMovementTaskObjects(DataReader oReader) { List wfMTasks = new List(); while (oReader.Read()) { WFMovementTask wfMTask = new WFMovementTask(); MapWFMTaskObject(wfMTask, oReader); wfMTasks.Add(wfMTask); } return wfMTasks; } #endregion public int GetUniqueNumber(TransactionContext tc) { #region WF Movement int nUniqueNumber = 0; // TransactionContext tc = null; try { // tc = TransactionContext.Begin(); nUniqueNumber = WFMovementTranDA.GetUniqueNumber(tc); // tc.End(); } catch (ServiceException ex) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message); #endregion } #endregion return nUniqueNumber; } public WFMovementTran InitiatorTran(int nUniqueNumber) { WFMovementTran oTran = null; #region WF Movements TransactionContext tc = null; try { tc = TransactionContext.Begin(); int nTranID = WFMovementTranDA.InitialTranID(tc, nUniqueNumber); tc.End(); if (nTranID > 0) { oTran = this.Get((nTranID)); } else { throw new ServiceException("Initiator not found."); } } catch (ServiceException ex) { #region Handle Error if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException("Failed to get Initiator"); #endregion } #endregion return oTran; } public int InitiatorEmpID(TransactionContext tc, int nUniqueNumber) { #region WF Movements int empid=0; try { empid = WFMovementTranDA.InitialEmpID(tc, nUniqueNumber); } catch (ServiceException ex) { #region Handle Error if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException("Failed to get Initiator"); #endregion } #endregion return empid; } public bool IsInitiator(int UnqNumber, int pEmpID) { TransactionContext tc = null; bool rs = false; #region WF Movements int empid = 0; try { tc = TransactionContext.Begin(); empid = WFMovementTranDA.InitialEmpID(tc, UnqNumber); tc.End(); if (empid != -1) { if (empid == pEmpID) { rs = true; } } } catch (ServiceException ex) { #region Handle Error if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException("Failed to get Initiator"); #endregion } #endregion return rs; } public int pendingLoanAndWorkflowCount( int EmpID) { TransactionContext tc = null; int tcount =0; #region WF Movements try { tc = TransactionContext.Begin(); tcount = WFMovementTranDA.pendingLoanAndWorkflowCount(tc, EmpID); tc.End(); } catch (ServiceException ex) { #region Handle Error if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException("Failed to get Initiator"); #endregion } #endregion return tcount; } public OrganogramBasic InitiatorNode(int nUniqueNumber) { OrganogramBasic oNode = null; #region WF Movements TransactionContext tc = null; try { tc = TransactionContext.Begin(); int nTranID = WFMovementTranDA.InitialTranID(tc, nUniqueNumber); tc.End(); if (nTranID > 0) { WFMovementTran oTran = this.Get((nTranID)); oNode = (new OrganogramService()).Get(oTran.FromNodeID); } else { throw new ServiceException("Initiator not found."); } } catch (ServiceException ex) { #region Handle Error if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException("Failed to get Initiator"); #endregion } #endregion return oNode; } #region WFMovementNext private void MapWFMNextObject(WFMovementNext wfMNext, DataReader oReader) { base.SetObjectID(wfMNext, (oReader.GetInt32("WFMOVEMENTNEXTID").Value)); wfMNext.WFMovementTranID = oReader.GetInt32("WFMOVEMENTTRANID", 0); wfMNext.EmployeeID = oReader.GetInt32("EmployeeID", 0); wfMNext.NodeID = oReader.GetInt32("NODEID", 0); wfMNext.Status = (EnumwfStatus)oReader.GetInt32("STATUS").Value; wfMNext.Remarks = oReader.GetString("REMARKS"); wfMNext.Description = oReader.GetString("DESCRIPTION"); wfMNext.ReceiveStatus = (EnumWFReceiveStatus)oReader.GetInt32("RECEIVESTATUS").Value; this.SetObjectState(wfMNext, Ease.Core.ObjectState.Saved); } protected List CreateWFMovementNextObjects(DataReader oReader) { List wfMNexts = new List(); while (oReader.Read()) { WFMovementNext wfMNext = new WFMovementNext(); MapWFMNextObject(wfMNext, oReader); wfMNexts.Add(wfMNext); } return wfMNexts; } #endregion #region Service Implementation #region Insert public void Submit(TransactionContext tc, WFMovementTran PrvMove, WFMovementTran NextMove) { try { #region Update PreviousItem int id; WFMovementTranDA.Update(tc, PrvMove); foreach (WFMovementNext oItem in PrvMove.WFMNexts) { WFMovementTranDA.Update_WFMovementNext(tc, oItem); } #endregion Update PreviousItem if (NextMove.IsNew) { id = tc.GenerateID("WFMOVEMENTTRAN", "WFMOVEMENTTRANID"); this.SetObjectID(NextMove, (id)); WFMovementTranDA.Insert(tc, NextMove); } else { WFMovementTranDA.Update(tc, NextMove); } #region Insert Child foreach (WFMovementNext oWFMovementNext in NextMove.WFMNexts) { if (oWFMovementNext.IsNew) { id = tc.GenerateID("WFMOVEMENTNEXT", "WFMOVEMENTNEXTID"); this.SetObjectID(oWFMovementNext, (id)); oWFMovementNext.WFMovementTranID = NextMove.ID; WFMovementTranDA.Insert(tc, oWFMovementNext); } else { WFMovementTranDA.Update_WFMovementNext(tc, oWFMovementNext); } } if (NextMove.WFMTasks != null) { foreach (WFMovementTask otask in NextMove.WFMTasks) { if (otask.IsNew) { id = tc.GenerateID("WFMOVEMENTTASK", "WFMOVEMENTTASKID"); this.SetObjectID(otask, (id)); otask.WFMovementTranID = NextMove.ID; WFMovementTranDA.Insert(tc, otask); } else { WFMovementTranDA.Update_WFMovementTask(tc, otask); } } } #endregion Insert Child // WFMovementTranDA.UpdateObjectStatus(tc, NextMove); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void UpdateSysNotification(int movementTaskID, bool status) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); WFMovementTranDA.Update_SysNotification(tc, movementTaskID, status); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void Update_MovementNext(int tranID, int newEmployeeID, int empID, string remarks) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); WFMovementTranDA.Update_WFMovementNext(tc, tranID, newEmployeeID, empID, remarks); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public int Save(TransactionContext tc, WFMovementTran wfMTran) { try { Save(wfMTran, tc); return wfMTran.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); //string smessage = "Faliled to save Organogram (table:" + tableName + ") for the Position:(" // + oOrganogram.PositionNo + ") " + oOrganogram.PositionName + ". Error :"; throw new ServiceException(e.Message, e); #endregion } } public void ForceComplete(List otrans) { List owftypes = new WFTypeService().Get(); TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach(WFMovementTran item in otrans) { if (item.Status == EnumwfStatus.Initiate) // for forward { WFMovementTranDA.Update_WFMovementNext(tc, item.ID, item.WFMNexts[0].EmployeeID, item.FromEmployeeID, item.Remarks); } else { WFMovementTranDA.ForceComplete(tc, item.ID, item.Remarks); WFType otype = owftypes.FirstOrDefault(x => x.ID == item.WFTypeID); Assembly assem = Assembly.Load("HRM.DA"); Type t = assem.GetType("HRM.DA." + otype.SourceObjectName + "Service"); var obj = Activator.CreateInstance(t); //return Ok(); string fName = "ForceComplete"; if (item.Status == EnumwfStatus.Reject) fName = "ForceReject"; object[] param; Type[] paramtypes; param = new object[2]; param[0] = tc; param[1] = (int)item.ObjectID; paramtypes = new Type[2]; paramtypes[0] = typeof(TransactionContext); paramtypes[1] = typeof(int); MethodInfo voidMethodInfo = t.GetMethod(fName, paramtypes); object ost = voidMethodInfo.Invoke(obj, param); } } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); //string smessage = "Faliled to save Organogram (table:" + tableName + ") for the Position:(" // + oOrganogram.PositionNo + ") " + oOrganogram.PositionName + ". Error :"; throw new ServiceException(e.Message, e); #endregion } } public int Save(WFMovementTran wfMTran, TransactionContext tc) { try { int id = 0; if (wfMTran.IsNew) { if (wfMTran.UniqueNumber == 0 & wfMTran.Tier == 1) wfMTran.UniqueNumber = WFMovementTranDA.GetUniqueNumber(tc); base.SetObjectID(wfMTran, (id)); id = tc.GenerateID("WFMOVEMENTTRAN", "WFMOVEMENTTRANID"); wfMTran.ID = id; WFMovementTranDA.Insert(tc, wfMTran); } else { WFMovementTranDA.Update(tc, wfMTran); } #region Insert Child foreach (WFMovementNext oWFMovementNext in wfMTran.WFMNexts) { if (oWFMovementNext.IsNew) { id = tc.GenerateID("WFMOVEMENTNEXT", "WFMOVEMENTNEXTID"); this.SetObjectID(oWFMovementNext, (id)); oWFMovementNext.WFMovementTranID = wfMTran.ID; WFMovementTranDA.Insert(tc, oWFMovementNext); } else { oWFMovementNext.StatusUpdateTime = DateTime.Now; WFMovementTranDA.Update_WFMovementNext(tc, oWFMovementNext); } } foreach (WFMovementTask otask in wfMTran.WFMTasks) { if (otask.IsNew) { id = tc.GenerateID("WFMOVEMENTTASK", "WFMOVEMENTTASKID"); this.SetObjectID(otask, (id)); otask.WFMovementTranID = wfMTran.ID; WFMovementTranDA.Insert(tc, otask); } else { WFMovementTranDA.Update_WFMovementTask(tc, otask); } } #endregion Insert Child //if (wfMTran.WFSetup.WFType.SourceObjectName == "LeaveEntry") //{ // int leaveID = wfMTran.ObjectID; // LeaveEntryService lEntryService = new LeaveEntryService(); // LeaveEntry lEntry = lEntryService.Get(tc, leaveID); // DailyAttnProcessService oAtt = new DailyAttnProcessService(); // List _daprocess = oAtt.Get(tc, lEntry.EmpID.ToString(), // lEntry.ApprovedFromDate.Date, lEntry.ApprovedToDate.Date); // int nDays = (int)((lEntry.ApprovedToDate.Date.Ticks - lEntry.ApprovedFromDate.Date.Ticks) / // TimeSpan.TicksPerDay) + 1; // DateTime date = lEntry.ApprovedFromDate.Date; // for (int i = 1; i <= nDays; i++) // { // if (wfMTran.Status == EnumwfStatus.End) // { // DailyAttnProcess dap = _daprocess.Where(o => o.AttnDate == date).FirstOrDefault(); // if (dap != null && dap.AttenType != EnumAttendanceType.WeeklyHoliday && // dap.AttenType != EnumAttendanceType.Holiday) // { // oAtt.UpdateLeave(tc, (lEntry.EmpID), lEntry.LeaveID, date, 1); // } // } // date = date.AddDays(1); // } //} // WFMovementTranDA.UpdateObjectStatus(tc, wfMTran); return wfMTran.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); //string smessage = "Faliled to save Organogram (table:" + tableName + ") for the Position:(" // + oOrganogram.PositionNo + ") " + oOrganogram.PositionName + ". Error :"; throw new ServiceException(e.Message, e); #endregion } } #endregion #region Delete public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); WFMovementTranDA.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 TransactionContext GetTransactionContext(bool openTransaction) { TransactionContext tc = null; try { tc = TransactionContext.Begin(openTransaction); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return tc; } public WFMovementNext GetReceivedWFNext(int wfsetupID, int objectID) { List onext = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(WFMovementTranDA.GetReceivedWFNext(tc, wfsetupID, objectID)); onext = this.CreateWFMovementNextObjects(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 } if (onext == null) return null; else if (onext.Count == 0) return null; else return onext[0]; } public WFMovementTran Get(int id) { WFMovementTran oWFMTran = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); oWFMTran = this.Get(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 } return oWFMTran; } public WFMovementTran Get(TransactionContext tc, int id) { WFMovementTran oWFMTran = null; try { DataReader oreader = new DataReader(WFMovementTranDA.Get(tc, id)); if (oreader.Read()) { oWFMTran = this.CreateObject(oreader); } oreader.Close(); if(oWFMTran !=null) { DataReader dr = new DataReader(WFMovementTranDA.Get4WFMovementNext(tc, oWFMTran.ID)); oWFMTran.WFMNexts = this.CreateWFMovementNextObjects(dr); dr.Close(); dr = new DataReader(WFMovementTranDA.Get4WFMovementTask(tc, oWFMTran.ID)); oWFMTran.WFMTasks = this.CreateWFMovementTaskObjects(dr); dr.Close(); } } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oWFMTran; } public List ReceivedItems(int employeeid) { List wfMovementTrans = new List(); #region WF Movements TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(WFMovementTranDA.ReceivedItems(tc, employeeid)); wfMovementTrans = this.CreateObjects(dr); dr.Close(); tc.End(); } catch (ServiceException ex) { #region Handle Error if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message); #endregion } #endregion return wfMovementTrans; } public DataTable PendingJobsMobile(int employeeid) { DataTable PendingJobsMobile = null; #region WF Movements TransactionContext tc = null; try { tc = TransactionContext.Begin(); PendingJobsMobile = WFMovementTranDA.PendingJobsMobile(tc, employeeid); //DataReader dr = new DataReader(WFMovementTranDA.ReceivedItems(tc, employeeid)); //wfMovementTrans = this.CreateObjects(dr); //dr.Close(); tc.End(); } catch (ServiceException ex) { #region Handle Error if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message); #endregion } #endregion return PendingJobsMobile; } public DataTable GetReceivedItems(int payrolltypeid, int? wftypeid, int? employeeid) { DataTable items = null; #region WF Movements TransactionContext tc = null; try { tc = TransactionContext.Begin(); items =WFMovementTranDA.GetReceivedItems(tc, payrolltypeid, wftypeid, employeeid); tc.End(); } catch (ServiceException ex) { #region Handle Error if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message); #endregion } #endregion return items; } public List GetPendingItems(int employeeid) { List wfMovementTrans = new List(); #region WF Movements TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(WFMovementTranDA.PendingItems(tc, employeeid)); wfMovementTrans = this.CreateObjects(dr); dr.Close(); tc.End(); } catch (ServiceException ex) { #region Handle Error if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message); #endregion } #endregion return wfMovementTrans; } public void ReceivedItems(TransactionContext tc, out List pendingJobs, int employeeid) { WFMovementTran pendingJob = null; pendingJobs = new List(); DataReader reader = new DataReader(WFMovementTranDA.ReceivedItems(tc, employeeid)); while (reader.Read()) { pendingJob = new WFMovementTran(); pendingJob = this.CreateObject(reader); pendingJobs.Add(pendingJob); } reader.Close(); } public void NotificationItems(TransactionContext tc, out List notifications, int employeeid) { DataReader reader = new DataReader(WFMovementTranDA.NotificationItems(tc, employeeid)); notifications = this.CreateWFMovementTaskObjects(reader); reader.Close(); } public List GetNotificationItems(int employeeid) { List wfMovementTrans = new List(); #region WF Movements TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(WFMovementTranDA.NotificationItems(tc, employeeid)); wfMovementTrans = this.CreateWFMovementTaskObjects(dr); dr.Close(); tc.End(); } catch (ServiceException ex) { #region Handle Error if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message); #endregion } #endregion return wfMovementTrans; } public DataSet GetNotificationAndPendingJobCount(int employeeid) { DataSet onotification = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); onotification = WFMovementTranDA.GetNotificationAndPendingJobCount(tc, employeeid); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return onotification; } public DataSet GetNotificationAndPendingJobCount(TransactionContext tc, int employeeid) { DataSet onotification = new DataSet(); try { onotification = WFMovementTranDA.GetNotificationAndPendingJobCount(tc, employeeid); } catch (Exception e) { #region Handle Exception ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return onotification; } public int ReceivedItemsCount(int employeeid) { #region WF Movements TransactionContext tc = null; int nCount = 0; try { tc = TransactionContext.Begin(); nCount = WFMovementTranDA.ReceivedItemsCount(tc, employeeid); tc.End(); } catch (ServiceException ex) { #region Handle Error if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message); #endregion } #endregion return nCount; } public string GetPendingJobNotificationCount(int employeeid) { TransactionContext tc = null; string countString = null; try { tc = TransactionContext.Begin(); countString = WFMovementTranDA.GetPendingJobNotificationCount(tc, employeeid); tc.End(); } catch (ServiceException ex) { #region Handle Error if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message); #endregion } return countString; } public DataTable GetNotification(int employeeid) { #region WF Movements TransactionContext tc = null; DataTable dtNotification = null; try { DataSet dsNotification = null; tc = TransactionContext.Begin(); dsNotification = WFMovementTranDA.GetNotification(tc, employeeid); if (dsNotification != null && dsNotification.Tables.Count > 0) dtNotification = dsNotification.Tables[0]; tc.End(); } catch (ServiceException ex) { #region Handle Error if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message); #endregion } #endregion return dtNotification; } public List GetPendingJob(int employeeid) { #region WF Movements TransactionContext tc = null; DataReader dataReader = null; List items = new List(); try { tc = TransactionContext.Begin(); dataReader = new DataReader(WFMovementTranDA.GetPendingJob(tc, employeeid)); while (dataReader.Read()) { PendingItemDTO item = new PendingItemDTO(); item.Id = dataReader.GetInt32("ID", 0); item.SENTTIME = dataReader.GetDateTime("SENTTIME"); item.Name = dataReader.GetString("Name"); item.ObjectDescription = dataReader.GetString("ObjectDescription"); item.Link = dataReader.GetString("Link"); items.Add(item); } dataReader.Close(); tc.End(); } catch (ServiceException ex) { #region Handle Error if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message); #endregion } #endregion return items; } public int GetNotificationItemCount(int employeeid) { #region WF Movements TransactionContext tc = null; int nCount = 0; try { tc = TransactionContext.Begin(); nCount = WFMovementTranDA.NotificationItemsCount(tc, employeeid); tc.End(); } catch (ServiceException ex) { #region Handle Error if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message); #endregion } #endregion return nCount; } public List Get() { List wfMTrans = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(WFMovementTranDA.Get(tc)); wfMTrans = this.CreateObjects(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 wfMTrans; } public List GetFlowHistories(int? tranID, int? uniqueNumber) { List wfflowHis = new List() ; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oReader = new DataReader(WFMovementTranDA.GetFlowHistory(tc, tranID, uniqueNumber)); while (oReader.Read()) { WFFlowHistory item = new WFFlowHistory(); item.tranID = oReader.GetInt32("WFMOVEMENTTRANID").Value; item.tranDate = oReader.GetDateTime("SENTTIME").Value; item.employeeID = oReader.GetInt32("EmployeeID").Value; item.employeeNo = oReader.GetString("employeeNo"); item.employeeName = oReader.GetString("Name"); item.status = (EnumwfStatus)oReader.GetInt32("STATUS").Value; item.tranStatusString = ((EnumwfStatus)oReader.GetInt32("STATUS")).ToString(); item.remarks = oReader.GetString("REMARKS"); item.StatusUpdateDate = oReader.GetDateTime("StatusUpdateTime"); item.description = oReader.GetString("DESCRIPTION"); wfflowHis.Add(item); } 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 } return wfflowHis; } public List GetFlowHistoriesByObjectID(int? objectId, int wfTypeId, int? employeeId) { List wfflowHis = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oReader = new DataReader(WFMovementTranDA.GetFlowHistoryByObjectId(tc, objectId, wfTypeId, employeeId)); while (oReader.Read()) { WFFlowHistory item = new WFFlowHistory(); item.tranID = oReader.GetInt32("WFMOVEMENTTRANID").Value; item.tranDate = oReader.GetDateTime("SENTTIME").Value; item.employeeID = oReader.GetInt32("EmployeeID").Value; item.employeeNo = oReader.GetString("employeeNo"); item.employeeName = oReader.GetString("Name"); item.status = (EnumwfStatus)oReader.GetInt32("STATUS").Value; item.tranStatusString = ((EnumwfStatus)oReader.GetInt32("STATUS")).ToString(); item.remarks = oReader.GetString("REMARKS"); item.description = oReader.GetString("DESCRIPTION"); wfflowHis.Add(item); } 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 } return wfflowHis; } public string GetApproversName(int tranID, int empid) { try { WFManager om = new HRM.DA.WFManager(); return om.ApproveEmpsNames(tranID, empid); } catch (Exception e) { #region Handle Exception throw new ServiceException(e.Message, e); #endregion } } public List Get4WFMovementTask(int id) { List wfMTasks = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(WFMovementTranDA.Get4WFMovementTask(tc, id)); wfMTasks = this.CreateWFMovementTaskObjects(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 wfMTasks; } public List GetWFMovementTasks() { List wfMTasks = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(WFMovementTranDA.GetWFMovementTasks(tc)); wfMTasks = this.CreateWFMovementTaskObjects(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 wfMTasks; } public List GetAllItems(int nUniqueNumber) { List wfMovementTrans = new List(); #region WF Movements TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(WFMovementTranDA.GetAllItem(tc, nUniqueNumber)); wfMovementTrans = this.CreateObjects(dr); dr.Close(); tc.End(); } catch (ServiceException ex) { #region Handle Error if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message); #endregion } #endregion return wfMovementTrans; } public WFMovementTask GetWFMovementTask(int id) { WFMovementTask wfMTask = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(WFMovementTranDA.GetWFMovementTask(tc, id)); if (oreader.Read()) { wfMTask = this.CreateWFMovementTaskObject(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 } return wfMTask; } public List Get4WFMovementNextWithTranID(int tranid) { List wfMNexts = null; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(WFMovementTranDA.Get4WFMovementNext(tc, tranid)); wfMNexts = this.CreateWFMovementNextObjects(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 wfMNexts; } //public int GetInitiatorEmpID(TransactionContext tc, int tranid) //{ // int emnpid = 0; // try // { // DataReader dr = new DataReader(WFMovementTranDA.Get4WFMovementNext(tc, tranid)); // wfMNexts = this.CreateWFMovementNextObjects(dr); // dr.Close(); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException(e.Message, e); // #endregion // } // return wfMNexts; //} public List Get4WFMovementNext(int UniqueNumber) { List wfMNexts = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(WFMovementTranDA.Get4WFMovementNext(tc, UniqueNumber)); wfMNexts = this.CreateWFMovementNextObjects(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 wfMNexts; } public List GetWFMovementByWFType(int wFTypeID) { List wfMTrans = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(WFMovementTranDA.GetWFMovementByWFType(tc, wFTypeID)); wfMTrans = this.CreateObjects(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 wfMTrans; } public int? GetListFieldApprover(TransactionContext tc,int wFTypeID, int objectid, string listFieldName) { int? itemID = null; try { itemID = WFMovementTranDA.ListFieldActorID(tc, wFTypeID, objectid, listFieldName); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return itemID; } public List GetClaimRequisitionTranItemsForApproval(int employeeID) { List wfMovementTrans = new List(); #region WF Movements TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(WFMovementTranDA.GetClaimRequisitionTranItemsForApproval(tc, employeeID)); wfMovementTrans = this.CreateObjects(dr); dr.Close(); tc.End(); } catch (ServiceException ex) { #region Handle Error if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message); #endregion } #endregion return wfMovementTrans; } public List GetClaimRequisitionTranItemHistory(int claimId, int employeId) { List wfMovementTrans = new List(); #region WF Movements TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oReader = new DataReader(WFMovementTranDA.GetClaimRequisitionTranItemHistory(tc, claimId, employeId)); while (oReader.Read()) { WFFlowHistory item = new WFFlowHistory(); item.tranID = oReader.GetInt32("WFMOVEMENTTRANID").Value; item.tranDate = oReader.GetDateTime("SENTTIME").Value; item.employeeID = oReader.GetInt32("EmployeeID").Value; item.employeeNo = oReader.GetString("employeeNo"); item.employeeName = oReader.GetString("Name"); item.status = (EnumwfStatus)oReader.GetInt32("STATUS").Value; item.remarks = oReader.GetString("REMARKS"); item.description = oReader.GetString("DESCRIPTION"); wfMovementTrans.Add(item); } oReader.Close(); tc.End(); } catch (ServiceException ex) { #region Handle Error if (tc != null) tc.HandleError(); ExceptionLog.Write(ex); throw new ServiceException(ex.Message); #endregion } #endregion return wfMovementTrans; } public WFMovementTran GetWfTranByObjectId(int objectId,int wfTypeId,int wfruleId) { WFMovementTran wfTran = new WFMovementTran(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(WFMovementTranDA.GetWfTranByObjectId(tc, objectId, wfTypeId,wfruleId)); if (oreader.Read()) { wfTran = this.CreateObject(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 } return wfTran; } #endregion } }