using System; using System.Data; using System.Collections.Generic; using Ease.Core.Model; using Ease.Core.DataAccess; using Ease.Core.Utility; using HRM.BO; namespace HRM.DA { #region OrganogramEmployee Service public class OrganogramEmployeeService : ServiceTemplate, IOrganogramEmployeeService { public OrganogramEmployeeService() { } private void MapObject(OrganogramEmployee oOrganEmp, DataReader oReader) { //base.SetObjectID(oOrganEmp,ID.FromComplex(oReader.GetID("NodeID"),oReader.GetID("EmployeeID"))); base.SetObjectID(oOrganEmp, oReader.GetInt32("OrganEmpID").Value); oOrganEmp.NodeID = oReader.GetInt32("NodeID", 0); oOrganEmp.EmployeeID = oReader.GetInt32("EmployeeID", 0); oOrganEmp.AssignDate = oReader.GetDateTime("AssignDate").Value; oOrganEmp.CreatedBy = oReader.GetInt32("CreatedBy", 0); oOrganEmp.CreatedDate = oReader.GetDateTime("CreationDate").Value; oOrganEmp.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); //oOrganEmp.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oOrganEmp, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { OrganogramEmployee oOrganogramEmployee = new OrganogramEmployee(); MapObject(oOrganogramEmployee, oReader); return oOrganogramEmployee as T; } #region Service implementation public int Save(OrganogramEmployee oOrganogramEmployee) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); Save(tc, oOrganogramEmployee); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oOrganogramEmployee.ID; } public void Save(List OrganEmps) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach (OrganogramEmployee oOrganogramEmployee in OrganEmps) { Save(tc, oOrganogramEmployee); } 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, OrganogramEmployee oOrganogramEmployee) { try { if (oOrganogramEmployee.IsNew) { int id = tc.GenerateID("OrganEmployee", "OrganEmpID"); base.SetObjectID(oOrganogramEmployee, (id)); OrganogramEmployeeDA.Insert(tc, oOrganogramEmployee); } else { OrganogramEmployeeDA.Update(tc, oOrganogramEmployee); } return oOrganogramEmployee.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } //public static void SaveForEmpLIfeCycle(TransactionContext tc, OrganogramEmployee oOrganogramEmployee) //{ // try // { // int id = tc.GenerateID("OrganEmployee", "OrganEmpID"); // OrganogramEmployeeDA.InsertForLifeCycle(tc, oOrganogramEmployee,id); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException(e.Message, e); // #endregion // } //} public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); OrganogramEmployeeDA.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 } } public void Delete() { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); OrganogramEmployeeDA.Delete(tc); 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 DeleteByEmp(TransactionContext tc, int id) { try { OrganogramEmployeeDA.DeleteByEmp(tc, id); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void DeleteByNode(TransactionContext tc, int nodeid) { try { OrganogramEmployeeDA.DeleteByNode(tc, nodeid); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public List GetOrganogramInfo() { DataSet ods = new DataSet(); List oOrgs = new List(); TransactionContext tc = null; int nCount = 1; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramEmployeeDA.GetOrganogramInfo(tc)); while (dr.Read()) { OrganogramBasic org = new OrganogramBasic(); org.ID = Convert.ToInt32(dr.GetInt32(0)); var pid = dr.GetInt32(1); if (pid != null) org.ParentID = (pid); org.PositionName = dr.GetString(2); org.EmployeeNoView = dr.GetString(3); org.EmployeeNameView = dr.GetString(4); // org.EmployeeNameView = Convert.ToInt32(dr.GetInt32(5)); org.Tier = Convert.ToInt32(dr.GetInt32(6)); oOrgs.Add(org); nCount++; } 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 oOrgs; } public List Get(TransactionContext tc, int nodeID) { List oOrganogramEmployee = new List(); try { DataReader dr = new DataReader(OrganogramEmployeeDA.Get(tc, nodeID)); oOrganogramEmployee = this.CreateObjects(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 oOrganogramEmployee; } public List GetByEmp(int empID) { List oOrganogramEmployee = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramEmployeeDA.GetByEmp(tc, empID)); oOrganogramEmployee = 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 oOrganogramEmployee; } public List GetByTier(int tierFrom, int tierTo) { List oOrganogramEmployee = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramEmployeeDA.GetByTier(tc, tierFrom, tierTo)); oOrganogramEmployee = 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 oOrganogramEmployee; } public List GetByGrades(string gradeIds) { List oOrganogramEmployee = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramEmployeeDA.GetByGrades(tc, gradeIds)); oOrganogramEmployee = 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 oOrganogramEmployee; } public List Get(int nodeID) { List oOrganogramEmployee = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramEmployeeDA.Get(tc, nodeID)); oOrganogramEmployee = 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 oOrganogramEmployee; } public List Get() { List oOrganogramEmployee = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramEmployeeDA.Get(tc)); oOrganogramEmployee = 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 oOrganogramEmployee; } public List GetByPositionType(EnumOGPositionType enPositionType) { List oOrganogramEmployee = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramEmployeeDA.GetByPositionType(tc, enPositionType)); oOrganogramEmployee = 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 oOrganogramEmployee; } public List GetByPositionType(TransactionContext tc, EnumOGPositionType enPositionType) { List oOrganogramEmployee = new List(); try { DataReader dr = new DataReader(OrganogramEmployeeDA.GetByPositionType(tc, enPositionType)); oOrganogramEmployee = this.CreateObjects(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 oOrganogramEmployee; } public List getTopHiararchy(TransactionContext tc, int employeeid) { List orgs = new List(); //TransactionContext tc = null; try { //Organogramid, PositionName, tier, POSITIONTYPEID, Manager, EMPLOYEEID, OGPOSITIONTYPE //tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramEmployeeDA.getTopHiararchy(tc, employeeid)); while (dr.Read()) { OrganogramBasicTemp org = new OrganogramBasicTemp(); org.OrganogramID = Convert.ToInt32(dr.GetInt32(0)); org.PositionName = dr.GetString(1); org.Tier = Convert.ToInt32(dr.GetInt32(2)); var pid = dr.GetInt32(3); if (pid != null) org.PositionTypeID =(int) (pid); pid = dr.GetInt32(5); if (pid != null) org.EmployeeID = (int)(pid); pid = dr.GetInt32(6); if (pid != null) org.positionType = (EnumOGPositionType)(pid); orgs.Add(org); } 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 orgs; } #endregion } #endregion }