예제 #1
0
        private static bool CanSubsystemBeDeactivated(Int32 ALedgerNumber, String ASubsystemCode)
        {
            #region Validate Arguments

            if (ALedgerNumber <= 0)
            {
                throw new EFinanceSystemInvalidLedgerNumberException(String.Format(Catalog.GetString(
                            "Function:{0} - The Ledger number must be greater than 0!"),
                        Utilities.GetMethodName(true)), ALedgerNumber);
            }
            else if (ASubsystemCode.Length == 0)
            {
                throw new ArgumentException(String.Format(Catalog.GetString("Function:{0} - The Subsystem code is empty!"),
                        Utilities.GetMethodName(true)));
            }

            #endregion Validate Arguments

            Boolean Result = false;

            TDBTransaction Transaction = null;

            try
            {
                DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                    TEnforceIsolationLevel.eilMinimum, ref Transaction,
                    delegate
                    {
                        if (ASubsystemCode == CommonAccountingSubSystemsEnum.GR.ToString())
                        {
                            // for gift processing don't allow to deactivate if 'Posted' or 'Unposted' gift batches exist
                            AGiftBatchTable TemplateGiftBatchTable;
                            AGiftBatchRow TemplateGiftBatchRow;
                            StringCollection TemplateGiftBatchOperators;

                            TemplateGiftBatchTable = new AGiftBatchTable();
                            TemplateGiftBatchRow = TemplateGiftBatchTable.NewRowTyped(false);
                            TemplateGiftBatchRow.LedgerNumber = ALedgerNumber;
                            TemplateGiftBatchRow.BatchStatus = MFinanceConstants.BATCH_POSTED;
                            TemplateGiftBatchOperators = new StringCollection();
                            TemplateGiftBatchOperators.Add("=");

                            if (AGiftBatchAccess.CountUsingTemplate(TemplateGiftBatchRow, TemplateGiftBatchOperators, Transaction) == 0)
                            {
                                Result = true;
                            }

                            if (!Result)
                            {
                                TemplateGiftBatchRow.BatchStatus = MFinanceConstants.BATCH_UNPOSTED;

                                if (AGiftBatchAccess.CountUsingTemplate(TemplateGiftBatchRow, TemplateGiftBatchOperators, Transaction) == 0)
                                {
                                    Result = true;
                                }
                            }
                        }

                        if (!Result)
                        {
                            AJournalTable TemplateJournalTable;
                            AJournalRow TemplateJournalRow;
                            StringCollection TemplateJournalOperators;

                            TemplateJournalTable = new AJournalTable();
                            TemplateJournalRow = TemplateJournalTable.NewRowTyped(false);
                            TemplateJournalRow.LedgerNumber = ALedgerNumber;
                            TemplateJournalRow.SubSystemCode = ASubsystemCode;
                            TemplateJournalOperators = new StringCollection();
                            TemplateJournalOperators.Add("=");

                            ARecurringJournalTable TemplateRJournalTable;
                            ARecurringJournalRow TemplateRJournalRow;
                            StringCollection TemplateRJournalOperators;

                            TemplateRJournalTable = new ARecurringJournalTable();
                            TemplateRJournalRow = TemplateRJournalTable.NewRowTyped(false);
                            TemplateRJournalRow.LedgerNumber = ALedgerNumber;
                            TemplateRJournalRow.SubSystemCode = ASubsystemCode;
                            TemplateRJournalOperators = new StringCollection();
                            TemplateRJournalOperators.Add("=");

                            // do not allow to deactivate subsystem if journals already exist
                            if ((AJournalAccess.CountUsingTemplate(TemplateJournalRow, TemplateJournalOperators, Transaction) == 0)
                                && (ARecurringJournalAccess.CountUsingTemplate(TemplateRJournalRow, TemplateRJournalOperators, Transaction) == 0))
                            {
                                Result = true;
                            }
                        }
                    });
            }
            catch (Exception ex)
            {
                TLogging.Log(String.Format("Method:{0} - Unexpected error!{1}{1}{2}",
                        Utilities.GetMethodSignature(),
                        Environment.NewLine,
                        ex.Message));
                throw ex;
            }

            return Result;
        }
예제 #2
0
        private static bool CanSubsystemBeDeactivated(Int32 ALedgerNumber, String ASubsystemCode)
        {
            Boolean NewTransaction;
            Boolean Result = false;

            TDBTransaction Transaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted,
                TEnforceIsolationLevel.eilMinimum, out NewTransaction);

            if (ASubsystemCode == CommonAccountingSubSystemsEnum.GR.ToString())
            {
                // for gift processing don't allow to deactivate if 'Posted' or 'Unposted' gift batches exist
                AGiftBatchTable TemplateGiftBatchTable;
                AGiftBatchRow TemplateGiftBatchRow;
                StringCollection TemplateGiftBatchOperators;

                TemplateGiftBatchTable = new AGiftBatchTable();
                TemplateGiftBatchRow = TemplateGiftBatchTable.NewRowTyped(false);
                TemplateGiftBatchRow.LedgerNumber = ALedgerNumber;
                TemplateGiftBatchRow.BatchStatus = MFinanceConstants.BATCH_POSTED;
                TemplateGiftBatchOperators = new StringCollection();
                TemplateGiftBatchOperators.Add("=");

                if (AGiftBatchAccess.CountUsingTemplate(TemplateGiftBatchRow, TemplateGiftBatchOperators, Transaction) == 0)
                {
                    Result = true;
                }

                if (!Result)
                {
                    TemplateGiftBatchRow.BatchStatus = MFinanceConstants.BATCH_UNPOSTED;

                    if (AGiftBatchAccess.CountUsingTemplate(TemplateGiftBatchRow, TemplateGiftBatchOperators, Transaction) == 0)
                    {
                        Result = true;
                    }
                }
            }

            if (!Result)
            {
                AJournalTable TemplateJournalTable;
                AJournalRow TemplateJournalRow;
                StringCollection TemplateJournalOperators;

                TemplateJournalTable = new AJournalTable();
                TemplateJournalRow = TemplateJournalTable.NewRowTyped(false);
                TemplateJournalRow.LedgerNumber = ALedgerNumber;
                TemplateJournalRow.SubSystemCode = ASubsystemCode;
                TemplateJournalOperators = new StringCollection();
                TemplateJournalOperators.Add("=");

                ARecurringJournalTable TemplateRJournalTable;
                ARecurringJournalRow TemplateRJournalRow;
                StringCollection TemplateRJournalOperators;

                TemplateRJournalTable = new ARecurringJournalTable();
                TemplateRJournalRow = TemplateRJournalTable.NewRowTyped(false);
                TemplateRJournalRow.LedgerNumber = ALedgerNumber;
                TemplateRJournalRow.SubSystemCode = ASubsystemCode;
                TemplateRJournalOperators = new StringCollection();
                TemplateRJournalOperators.Add("=");

                // do not allow to deactivate subsystem if journals already exist
                if ((AJournalAccess.CountUsingTemplate(TemplateJournalRow, TemplateJournalOperators, Transaction) == 0)
                    && (ARecurringJournalAccess.CountUsingTemplate(TemplateRJournalRow, TemplateRJournalOperators, Transaction) == 0))
                {
                    Result = true;
                }
            }

            if (NewTransaction)
            {
                DBAccess.GDBAccessObj.RollbackTransaction();
            }

            return Result;
        }