Beispiel #1
0
        public static FinGenJournalParam GetInstance(IObjectSpace objectSpace)
        {
            FinGenJournalParam result = objectSpace.FindObject <FinGenJournalParam>(null);

            if (result == null)
            {
                result = new FinGenJournalParam(((XPObjectSpace)objectSpace).Session);
                result.Save(); // this will also sync the child objects
            }
            return(result);
        }
Beispiel #2
0
        public static void SyncParamObjects(Session session, FinGenJournalParam genJnlParam)
        {
            // get journal groups that already exist in parameters
            var jnlGroupParams    = genJnlParam.JournalGroupParams;
            var jnlGroupsInParams = jnlGroupParams.Select(p => p.JournalGroup);

            // get journal groups
            var jnlGroupsColl = session.GetObjects(session.GetClassInfo(typeof(FinJournalGroup)),
                                                   null, new SortingCollection(null), 0, false, true);
            var jnlGroups = jnlGroupsColl.Cast <FinJournalGroup>().ToList();

            #region Add to Params
            // get journal groups that don't exist in parameters
            var jnlGroupsToAdd = jnlGroups.Where(jg => !jnlGroupsInParams.Contains(jg));

            // add journal groups to parameters
            foreach (FinJournalGroup jnlGroup in jnlGroupsToAdd)
            {
                var jnlGroupParam = new FinJournalGroupParam(session);
                jnlGroupParam.GenJournalParam = genJnlParam;
                jnlGroupParam.JournalGroup    = jnlGroup;
                jnlGroupParam.Save();
            }
            #endregion

            #region Delete from Params
            // get parameters that don't exist in journal groups
            var jnlGroupParamsToDelete = jnlGroupParams.Where(p => !jnlGroups.Contains(p.JournalGroup));

            while (jnlGroupParamsToDelete.Any())
            {
                var jgp = jnlGroupParamsToDelete.First();
                jgp.Delete();
                jgp.Save();
            }
            #endregion

            genJnlParam.Save();
            session.CommitTransaction();
        }