using System; using System.Data; using Ease.Core.Model; using Ease.Core.DataAccess; using Ease.Core; using System.Collections.Generic; using Ease.Core.Utility; using HRM.BO; using HRM.DA; //using HRM.BO.Fund; namespace HRM.DA.Fund { public class ProcessActivityService : ServiceTemplate { public ProcessActivityService() { } private void MapObject(ProcessActivity ProcessActivity, DataReader dr) { base.SetObjectID(ProcessActivity, dr.GetInt32("ActivityID").Value); ProcessActivity.Serial = dr.GetInt32("Serial").Value; ProcessActivity.ProjectID = dr.GetInt32("ProjectID").Value; ProcessActivity.ProcessID = dr.GetInt32("ProcessID").Value; ProcessActivity.Description = dr.GetString("Description"); ProcessActivity.ActivityRelatedTo = dr.GetInt32("ActivityRelatedTo").Value; ProcessActivity.RelatedValue = dr.GetInt32("RelatedValue").Value; ProcessActivity.CreatedBy = dr.GetInt32("CreatedBy").Value; ProcessActivity.CreatedDate = dr.GetDateTime("CreatedDate").Value; ProcessActivity.ModifiedBy = dr.GetInt32("ModifiedBy").Value != null ? dr.GetInt32("ModifiedBy").Value : (0); ProcessActivity.ModifiedDate = dr.GetDateTime("ModifiedDate") != null ? dr.GetDateTime("ModifiedDate") : DateTime.MinValue; base.SetObjectState(ProcessActivity, ObjectState.Saved); } protected override T CreateObject(DataReader dr) { ProcessActivity ProcessActivity = new ProcessActivity(); MapObject(ProcessActivity, dr); return ProcessActivity as T; } private ProcessActivity CreateObject(DataReader oReader) { ProcessActivity oProcessActivity = new ProcessActivity(); MapObject(oProcessActivity, oReader); return oProcessActivity; } private List CreateObjects(IDataReader oReader) { List oProcessActivitys = new List(); DataReader oreader = new DataReader(oReader); while (oreader.Read()) { ProcessActivity oItem = CreateObject(oreader); oProcessActivitys.Add(oItem); } return oProcessActivitys; } #region Service Implementation #region GetMaxSerial public int GetMaxSerial() { int maxSerial = 0; TransactionContext tc = null; try { tc = TransactionContext.Begin(); maxSerial = ProcessActivityDA.GetMaxSerial(tc); } catch (Exception e) { throw e; } return maxSerial; } #endregion #region Insert public bool Save(ProcessActivity processActivity) { //string serviceName = "FM.Services." + processActivity.SupportObjType.Name + "Service"; //string sPath = Application.StartupPath + @"\FM.Services.dll"; //Assembly oAssembly = Assembly.LoadFile(sPath); //Type tempService = oAssembly.GetType(serviceName, true); //ConstructorInfo cInfo = tempService.GetConstructor(new Type[] { }); //object oSerInstance = cInfo.Invoke(null); //MethodInfo mInfo = tempService.GetMethod("UpdateActivityInfo", BindingFlags.Instance|BindingFlags.Public| BindingFlags.NonPublic);//null ,new Type[] { typeof(TransactionContext), typeof(Ease.CoreV35.Model.ID), typeof(Ease.CoreV35.Model.ID) }, null); //MethodInfo mInfo = tempService.GetMethod("UpdateActivityInfo", BindingFlags.NonPublic,null ,new Type[] { typeof(TransactionContext), typeof(Ease.CoreV35.Model.ID), typeof(Ease.CoreV35.Model.ID) }, null); TransactionContext tc = null; bool flag = false; try { tc = TransactionContext.Begin(true); ActivityVoucherSetupService activitySetupService = new ActivityVoucherSetupService(); if (processActivity.IsNew) { int id = tc.GenerateID("ProcessActivity", "ActivityID"); base.SetObjectID(processActivity, (id)); ProcessActivityDA.Insert(tc, processActivity); } else { processActivity.ModifiedBy = processActivity.CreatedBy; processActivity.ModifiedDate = DateTime.Now; ProcessActivityDA.Update(tc, processActivity); } foreach (ActivityVoucherSetup oNVS in processActivity.VoucherSetupCol) { if (oNVS.IsNew) { int setupID = tc.GenerateID("ActivityVoucherSetup", "SetupID"); base.SetObjectID(oNVS, (setupID)); oNVS.Status = EnumVoucherSetupStatus.Active; oNVS.CreatedBy = oNVS.CreatedBy; oNVS.CreatedDate = DateTime.Now; oNVS.ActivityID = processActivity.ID; ActivityVoucherSetupDA.Insert(tc, oNVS); } } tc.End(); flag = true; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return flag; } #endregion #region UpdatePosition public void UpdatePosition(List processActivitys) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach (ProcessActivity item in processActivitys) { ProcessActivityDA.UpdatePosition(tc, item); } tc.End(); } catch (Exception e) { throw new ServiceException("Failed to update position ProcessActivity", e); } } #endregion #region Delete public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ProcessActivityDA.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(By ID) public ProcessActivity Get(int ID) { #region Cache Header ProcessActivity ProcessActivity = new ProcessActivity(); if (ProcessActivity != null) return ProcessActivity; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); IDataReader dr = ProcessActivityDA.Get(tc, ID); DataReader oreader = new DataReader(dr); ProcessActivity = CreateObject(oreader); 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 #endregion return ProcessActivity; } #endregion #region GetbyProjectID(By ID) public List GetbyProjectID(int ID) { #region Cache Header List ProcessActivity = new List(); if (ProcessActivity != null) return ProcessActivity; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); IDataReader dr = ProcessActivityDA.GetbyProjectID(tc, ID); ProcessActivity = 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 } #region Cache Footer #endregion return ProcessActivity; } #endregion #region GetbyProcessID(By ID) public List GetbyProcessID(int ID) { #region Cache Header List ProcessActivity = new List(); if (ProcessActivity != null) return ProcessActivity; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); IDataReader dr = ProcessActivityDA.GetbyProcessID(tc, ID); ProcessActivity = 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 } #region Cache Footer #endregion return ProcessActivity; } #endregion #region GetbyProjectProcessID(By ID) public List GetbyProjectProcessID(int Projectid, int Processid) { #region Cache Header List ProcessActivity = new List(); if (ProcessActivity != null) return ProcessActivity; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); IDataReader dr = ProcessActivityDA.GetbyProjectProcessID(tc, Projectid, Processid); ProcessActivity = 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 } #region Cache Footer #endregion return ProcessActivity; } #endregion #region Get() public List Getbyfundtype(int fundtypeid) { #region Cache Header List ProcessActivitys = new List(); if (ProcessActivitys != null) return ProcessActivitys; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); IDataReader dr = ProcessActivityDA.Get(tc, fundtypeid); ProcessActivitys = 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 } #region Cache Footer #endregion return ProcessActivitys; } #endregion #region GetTable public DataTable GetTable(int fundtypeid) { DataTable dTbl = new DataTable("ProcessActivitys"); TransactionContext tc = null; try { tc = TransactionContext.Begin(); IDataReader ir = ProcessActivityDA.Get(tc, fundtypeid); dTbl.Load(ir); ir.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 dTbl; } #endregion #endregion } }