using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using System; using System.Collections.Generic; using System.Data; using System.Linq; using HRM.BO; namespace HRM.DA { #region GL Service public class GLService : ServiceTemplate //, IGLService { #region Private functions and declaration public GLService() { } private void MapObject(GL oGL, DataReader oReader) { base.SetObjectID(oGL, oReader.GetInt32("GLID").Value); oGL.GLCode = oReader.GetString("GLCode"); oGL.GLDescription = oReader.GetString("GLDescription"); oGL.GLType = (EnumGLType)oReader.GetInt32("GLType"); oGL.GLHeadType = (EnumGLHeadType)oReader.GetInt32("GLHeadType"); oGL.OwnerID = oReader.GetInt32("OwnerID").Value; oGL.TierNo = oReader.GetInt32("TierNo").Value; oGL.PositionNo = oReader.GetInt32("PositionNo").Value; oGL.LegacyCode = oReader.GetString("LegacyCode"); oGL.IsActive = oReader.GetBoolean("IsActive").Value; oGL.CreatedBy = oReader.GetInt32("CreatedBy").Value; oGL.CreateDate = oReader.GetDateTime("CreateDate").Value; oGL.Modifiedby = oReader.GetInt32("Modifiedby").Value; oGL.ModifiedDate = oReader.GetDateTime("ModifiedDate").Value; this.SetObjectState(oGL, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { GL oGL = new GL(); MapObject(oGL, oReader); return oGL as T; } protected GL CreateObject(DataReader oReader) { GL oGL = new GL(); MapObject(oGL, oReader); return oGL; } //private GLs CreateObjects(IDataReader oReader) //{ // GLs oGLs = new GLs(); // NullHandler oreader = new NullHandler(oReader); // while (oReader.Read()) // { // GL oItem = CreateObject(oreader); // oGLs.Add(oItem); // } // return oGLs; //} #endregion #region Service implementation //private string getBottomMostChildKeys(GL gl) //{ // string bmcks = string.Empty; // GL children = gl.Children; // if (children.Count == 0) return gl.ID.ToString(); // else // { // foreach (GL c in children) // { // bmcks += "," + getBottomMostChildKeys(c); // } // bmcks = bmcks.Substring(1); // return bmcks; // } //} //public bool IsTranExist(int gLID) //{ // bool exist = false; // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(true); // GL gl = new GL(); // gl = gl.Get(ID.FromInteger(gLID)); // string bottomMostChildKeys = getBottomMostChildKeys(gl); // exist = GLDA.IsTranExist(tc, bottomMostChildKeys); // tc.End(); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // throw new ServiceException(e.Message, e); // #endregion // } // return exist; //} public GL Get(int id) { GL oGL = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(GLDA.Get(tc, id)); if (oreader.Read()) { oGL = 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 oGL; } internal GL Get(TransactionContext tc, int id) { GL oGL = null; try { DataReader oreader = new DataReader(GLDA.Get(tc, id)); if (oreader.Read()) { oGL = this.CreateObject(oreader); } oreader.Close(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oGL; } public GL Get(string code, int tierNO) { GL oGL = null; TransactionContext tc = null; try { DataReader oreader = new DataReader(GLDA.Get(tc, code, tierNO)); if (oreader.Read()) { oGL = this.CreateObject(oreader); } oreader.Close(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oGL; } public GL Get(string code) { GL oGL = null; TransactionContext tc = null; try { DataReader oreader = new DataReader(GLDA.Get(tc, code)); if (oreader.Read()) { oGL = this.CreateObject(oreader); } oreader.Close(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oGL; } public GL GetOwner(int nOwnerID) { GL oGL = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(GLDA.GetOwner(tc, nOwnerID)); if (oreader.Read()) { oGL = this.CreateObject(oreader); } oreader.Close(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oGL; } public List Get() { List oGLs = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GLDA.Get(tc)); oGLs = 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 oGLs; } public List GetByTier(int tierNo) { List oGLs = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GLDA.GetByTierNo(tc, tierNo)); oGLs = 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 oGLs; } //internal GLs Get(TransactionContext tc, int tierNo) //{ // GLs gls = null; // #region CacheHeader // gls = (GLs)_cache["Get", tierNo]; // if (gls != null) // return gls; // #endregion // try // { // IDataReader reader = GLDA.GetByTierNo(tc, tierNo); // gls = CreateObjects(reader); // reader.Close(); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException("Failed to Get GLs", e); // #endregion // } // #region CacheFooter // _cache.Add(gls, "Get", tierNo); // #endregion // return gls; //} public List GetRoot() { List oGLs = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GLDA.GetRoot(tc)); oGLs = 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 oGLs; } public List GetByOwnerID(int nOwnerID) { List oGLs = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GLDA.GetByOwnerID(tc, nOwnerID)); oGLs = 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 oGLs; } //internal GLs GetByOwnerID(TransactionContext tc, ID nOwnerID) //{ // GLs oGLs = new GLs(); // try // { // tc = TransactionContext.Begin(true); // IDataReader oReader = GLDA.GetByOwnerID(tc, nOwnerID.Integer); // oGLs = CreateObjects(oReader); // oReader.Close(); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException("Failed to Get GL", e); // #endregion // } // return oGLs; //} public List Get(EnumGLType glType, int tierNo) { List oGLs = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GLDA.Get(tc, glType, tierNo)); oGLs = 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 oGLs; } public List Get(EnumGLHeadType gLHeadType, int tierNo) { List oGLs = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GLDA.Get(tc, gLHeadType, tierNo)); oGLs = 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 oGLs; } public List GetByGLHeadType(EnumGLHeadType gLHeadType) { List oGLs = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GLDA.GetByGLHeadType(tc, gLHeadType)); oGLs = 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 oGLs; } public List GetBySearch(string sSearch) { List oGLs = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GLDA.GetBySearch(tc, sSearch)); oGLs = 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 oGLs; } public List GetPostingLevelGL(int nGLID) { List oGLs = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GLDA.GetPostingLevelGL(tc, nGLID)); oGLs = 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 oGLs; } public int Save(GL oGL) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oGL.IsNew) { int id = tc.GenerateID("GL", "GLID"); base.SetObjectID(oGL, id); GLDA.Insert(tc, oGL); } else { GLDA.Update(tc, oGL); } tc.End(); return oGL.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } //public void UpdateChildGL(TransactionContext tc, GL ochildGL, GL parentGL) //{ // GL oPrevGL = new GL(); // IDataReader oreader = GLDA.Get(tc, ochildGL.ID.Integer); // NullHandler oReaders = new NullHandler(oreader); // if (oreader.Read()) // { // oPrevGL = CreateObject(oReaders); // } // oreader.Close(); // GLChangeHistory oGLChangeHistory = new GLChangeHistory(); // this.SetObjectID(oGLChangeHistory, ID.FromInteger(GLChangeHistoryDA.GetNewID(tc))); // oGLChangeHistory.GLID = oPrevGL.ID; // oGLChangeHistory.GLCode = oPrevGL.GLCode; // oGLChangeHistory.GLDescription = oPrevGL.GLDescription; // oGLChangeHistory.GLType = oPrevGL.GLType; // oGLChangeHistory.GLHeadType = oPrevGL.GLHeadType; // oGLChangeHistory.OwnerID = oPrevGL.OwnerID; // oGLChangeHistory.PositionNo = oPrevGL.PositionNo; // oGLChangeHistory.TierNo = oPrevGL.TierNo; // oGLChangeHistory.LegacyCode = oPrevGL.LegacyCode; // oGLChangeHistory.CreatedBy = oPrevGL.CreatedBy; // oGLChangeHistory.CreateDate = oPrevGL.CreateDate; // oGLChangeHistory.Modifiedby = oPrevGL.Modifiedby; // oGLChangeHistory.ModifiedDate = oPrevGL.ModifiedDate; // oGLChangeHistory.IsActive = oPrevGL.IsActive; // GLChangeHistoryDA.Insert(tc, oGLChangeHistory); // String sOwnCode = string.Empty; // if (oPrevGL.GLCode.Length == SystemConfig.GetGLLevelActualLength(oPrevGL.TierNo)) // { // sOwnCode = ochildGL.GLCode.Substring(parentGL.GLCode.Length); // ochildGL.GLCode = parentGL.GLCode + sOwnCode; // } // else // { // sOwnCode = ochildGL.GLCode.Substring(ochildGL.GLCode.Length - SystemConfig.GetGLLevelCodeLength(ochildGL.TierNo)); // ochildGL.GLCode = parentGL.GLCode + sOwnCode; // } // GLDA.Update(tc, ochildGL); //} //public void UpdateGL(TransactionContext tc, GL oGL) //{ // try // { // GLs oChildGLs = new GLs(); // IDataReader oReader = GLDA.GetByOwnerID(tc, oGL.ID.Integer); // oChildGLs = CreateObjects(oReader); // oReader.Close(); // if (oChildGLs.Count > 0) // { // foreach (GL oItem in oChildGLs) // { // UpdateChildGL(tc, oItem, oGL); // UpdateGL(tc, oItem); // } // } // else // { // //********************************GL Change History********************************** // GL oPrevGL = new GL(); // IDataReader oreader = GLDA.Get(tc, oGL.ID.Integer); // NullHandler oReaders = new NullHandler(oreader); // if (oreader.Read()) // { // oPrevGL = CreateObject(oReaders); // } // oreader.Close(); // GLChangeHistory oGLChangeHistory = new GLChangeHistory(); // this.SetObjectID(oGLChangeHistory, ID.FromInteger(GLChangeHistoryDA.GetNewID(tc))); // oGLChangeHistory.GLID = oPrevGL.ID; // oGLChangeHistory.GLCode = oPrevGL.GLCode; // oGLChangeHistory.GLDescription = oPrevGL.GLDescription; // oGLChangeHistory.GLType = oPrevGL.GLType; // oGLChangeHistory.GLHeadType = oPrevGL.GLHeadType; // oGLChangeHistory.OwnerID = oPrevGL.OwnerID; // oGLChangeHistory.PositionNo = oPrevGL.PositionNo; // oGLChangeHistory.TierNo = oPrevGL.TierNo; // oGLChangeHistory.LegacyCode = oPrevGL.LegacyCode; // oGLChangeHistory.CreatedBy = oPrevGL.CreatedBy; // oGLChangeHistory.CreateDate = oPrevGL.CreateDate; // oGLChangeHistory.Modifiedby = oPrevGL.Modifiedby; // oGLChangeHistory.ModifiedDate = oPrevGL.ModifiedDate; // oGLChangeHistory.IsActive = oPrevGL.IsActive; // GLChangeHistoryDA.Insert(tc, oGLChangeHistory); // GL Owner = new GL(); // IDataReader oreaderw = GLDA.Get(tc, oGL.OwnerID.Integer); // NullHandler oReaderw = new NullHandler(oreaderw); // if (oreaderw.Read()) // { // Owner = CreateObject(oReaderw); // } // oreaderw.Close(); // String sOwnCode;//, sParentCode; // sOwnCode = oGL.GLCode.Substring(Owner.GLCode.Length); // oGL.GLCode = Owner.GLCode + sOwnCode; // GLDA.Update(tc, oGL); // } // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException("Failed to Update GL ", e); // #endregion // } //} //public void UpdatePositionNo(GL firstGL, GL secondGL) //{ // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(true); // UpdatePositionNo(tc, firstGL.ID.Integer, firstGL.PositionNo); // UpdatePositionNo(tc, secondGL.ID.Integer, secondGL.PositionNo); // tc.End(); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // throw new ServiceException(e.Message, e); // #endregion // } //} //public void UpdateHeadType(GLs gLs) //{ // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(true); // foreach (GL gL in gLs) // { // GLDA.UpdateHeaType(tc, gL); // } // tc.End(); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // throw new ServiceException(e.Message, e); // #endregion // } //} #region Private Functions private void UpdatePositionNo(TransactionContext tc, int glID, int positionNo) { GLDA.UpdatePositionNo(tc, glID, positionNo); } #endregion public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); GLDA.Delete(tc, id); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to Delete " + e.Message); #endregion } } //public DataSet GetCOA() //{ // TransactionContext tc = null; // DataSet COAds = new DataSet(); // try // { // tc = TransactionContext.Begin(true); // for (int tierCount = 1; tierCount <= SystemConfig.GLLevel; tierCount++) // { // //COAds.Tables.Add(SystemConfig.GetGLLevelName(tierCount)); // if (tierCount > 1) // { // COAds.Tables.Add(GLDA.GetByTierNoDS(tc, tierCount).Tables[0].Copy()); // COAds.Tables[tierCount - 1].TableName = SystemConfig.GetGLLevelName(tierCount); // COAds.Tables[tierCount - 1].PrimaryKey = new DataColumn[] { COAds.Tables[tierCount - 1].Columns[SystemConfig.GetGLLevelName(tierCount) + " Code"] }; // } // else if (tierCount == 1) // { // COAds.Tables.Add(GLDA.GetByTierNoDSControl(tc, tierCount).Tables[0].Copy()); // COAds.Tables[tierCount - 1].TableName = SystemConfig.GetGLLevelName(tierCount); // COAds.Tables[tierCount - 1].PrimaryKey = new DataColumn[] { COAds.Tables[tierCount - 1].Columns[SystemConfig.GetGLLevelName(tierCount) + " Code"] }; // } // } // COAds.Tables.Add(GLDA.GetByTierNoDS(tc).Tables[0].Copy()); // COAds.Tables[SystemConfig.GLLevel].TableName = "Subsidiary"; // COAds.Tables[SystemConfig.GLLevel].PrimaryKey = new DataColumn[] { COAds.Tables[SystemConfig.GLLevel].Columns["Subsidiary Code"], COAds.Tables[SystemConfig.GLLevel].Columns["Parent Code"] }; // tc.End(); // DataRelation rel; // rel = new DataRelation("Groups", // COAds.Tables["Control"].Columns["Control Code"], // COAds.Tables["Group"].Columns["Parent Code"]); // COAds.Relations.Add(rel); // rel = new DataRelation("Sub Groups", // COAds.Tables["Group"].Columns["Group Code"], // COAds.Tables["Sub Group"].Columns["Parent Code"]); // COAds.Relations.Add(rel); // rel = new DataRelation("Posting Heads", // COAds.Tables["Sub Group"].Columns["Sub Group Code"], // COAds.Tables["Posting Head"].Columns["Parent Code"]); // COAds.Relations.Add(rel); // rel = new DataRelation("Subsidiaries", // COAds.Tables["Posting Head"].Columns["Posting Head Code"], // COAds.Tables["Subsidiary"].Columns["Parent Code"]); // COAds.Relations.Add(rel); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException("Failed to GetCOA", e); // #endregion // } // return COAds; //} public List GetOrdrByDesc(EnumGLType glType, int tierNo) { List oGLs = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GLDA.GetOrdrByDesc(tc, glType, tierNo)); oGLs = 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 oGLs; } public List GetOrdrByDesc(EnumGLHeadType gLHeadType, int tierNo) { List oGLs = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GLDA.GetOrdrByDesc(tc, gLHeadType, tierNo)); oGLs = 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 oGLs; } public List GetBySearchOrdrByDesc(string sSearch) { List oGLs = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GLDA.GetBySearchOrdrByDesc(tc, sSearch)); oGLs = 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 oGLs; } public List GetOrdrByDesc() { List oGLs = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GLDA.GetOrdrByDesc(tc)); oGLs = 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 oGLs; } public List GetOrdrByDesc(int tierNo) { List oGLs = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GLDA.GetByTierNoOrdrByDesc(tc, tierNo)); oGLs = 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 oGLs; } #endregion } #endregion }