/// <summary>
        /// Need to ensure that the Analysis Attributes grid has all the entries
        /// that are required for the selected account.
        /// There may or may not already be attribute assignments for this transaction.
        /// </summary>
        /// <param name="AGLBatchDS"></param>
        /// <param name="AGLSetupDS">Can be null.  If supplied the code will use this data set to work out the required analysis attributes
        /// without a need to make a server call.  If not supplied the code will make a separate server call for each transaction row.  This may take several seconds.</param>
        /// <param name="ATransactionNumbers"></param>
        public void ReconcileTransAnalysisAttributes(GLBatchTDS AGLBatchDS, GLSetupTDS AGLSetupDS, out string ATransactionNumbers)
        {
            #region Validate Arguments

            if (AGLBatchDS == null)
            {
                throw new EFinanceSystemDataObjectNullOrEmptyException(String.Format(Catalog.GetString("Function:{0} - The GL Batch dataset is null!"),
                        Utilities.GetMethodName(true)));
            }
            else if (AGLSetupDS == null)
            {
                AGLSetupDS = (GLSetupTDS)TRemote.MFinance.GL.WebConnectors.LoadAAnalysisAttributes(FLedgerNumber, false);
            }
            else if ((AGLSetupDS.AAnalysisAttribute == null) || (AGLSetupDS.AAnalysisAttribute.Count == 0))
            {
                AGLSetupDS.Merge(TRemote.MFinance.GL.WebConnectors.LoadAAnalysisAttributes(FLedgerNumber, false));
            }

            #endregion Validate Arguments

            ATransactionNumbers = string.Empty;

            foreach (DataRowView drv in AGLBatchDS.ATransaction.DefaultView)
            {
                ATransactionRow tr = (ATransactionRow)drv.Row;

                if (TransAnalAttrRequiredUpdating(AGLBatchDS, AGLSetupDS, tr.AccountCode, tr.TransactionNumber))
                {
                    ATransactionNumbers += tr.TransactionNumber.ToString() + ", ";
                }
            }
        }
Beispiel #2
0
        public static TSubmitChangesResult SaveGLSetupTDS(
            Int32 ALedgerNumber,
            ref GLSetupTDS AInspectDS,
            out TVerificationResultCollection AVerificationResult)
        {
            //Put first because is required within argument validation
            AVerificationResult = new TVerificationResultCollection();

            #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 (AInspectDS == null)
            {
                return TSubmitChangesResult.scrNothingToBeSaved;
            }

            #endregion Validate Arguments

            TSubmitChangesResult ReturnValue = TSubmitChangesResult.scrOK;

            if ((AInspectDS.ACostCentre != null) && (AInspectDS.AValidLedgerNumber != null))
            {
                // check for removed cost centres, and also delete the AValidLedgerNumber row if there is one for the removed cost centre
                foreach (ACostCentreRow cc in AInspectDS.ACostCentre.Rows)
                {
                    if (cc.RowState == DataRowState.Deleted)
                    {
                        string CostCentreCodeToDelete = cc[ACostCentreTable.ColumnCostCentreCodeId, DataRowVersion.Original].ToString();

                        AInspectDS.AValidLedgerNumber.DefaultView.RowFilter =
                            String.Format("{0}='{1}'",
                                AValidLedgerNumberTable.GetCostCentreCodeDBName(),
                                CostCentreCodeToDelete);

                        foreach (DataRowView rv in AInspectDS.AValidLedgerNumber.DefaultView)
                        {
                            AValidLedgerNumberRow ValidLedgerNumberRow = (AValidLedgerNumberRow)rv.Row;

                            ValidLedgerNumberRow.Delete();
                        }
                    }
                }

                AInspectDS.AValidLedgerNumber.DefaultView.RowFilter = "";
            }

            if (AInspectDS.AAccount != null)
            {
                // check each AAccount row
                foreach (GLSetupTDSAAccountRow acc in AInspectDS.AAccount.Rows)
                {
                    // special treatment of deleted accounts
                    if (acc.RowState == DataRowState.Deleted)
                    {
                        // delete all account properties as well
                        string AccountCodeToDelete = acc[GLSetupTDSAAccountTable.ColumnAccountCodeId, DataRowVersion.Original].ToString();

                        DropAccountProperties(ref AInspectDS, ALedgerNumber, AccountCodeToDelete);
                        DropSuspenseAccount(ref AInspectDS, ALedgerNumber, AccountCodeToDelete);

                        continue;
                    }

                    /* BankAccountFlag */

                    // if the flag has been changed by the client, it will not be null
                    if (!acc.IsBankAccountFlagNull())
                    {
                        if (AInspectDS.AAccountProperty == null)
                        {
                            // because AccountProperty has not been changed on the client, GetChangesTyped will have removed the table
                            // so we need to reload the table from the database
                            AInspectDS.Merge(new AAccountPropertyTable());

                            GLSetupTDS inspectDS = AInspectDS;
                            TDBTransaction transaction = null;

                            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                                TEnforceIsolationLevel.eilMinimum,
                                ref transaction,
                                delegate
                                {
                                    AAccountPropertyAccess.LoadViaALedger(inspectDS, ALedgerNumber, transaction);
                                });
                        }

                        AInspectDS.AAccountProperty.DefaultView.RowFilter =
                            String.Format("{0}='{1}' and {2}='{3}'",
                                AAccountPropertyTable.GetAccountCodeDBName(),
                                acc.AccountCode,
                                AAccountPropertyTable.GetPropertyCodeDBName(),
                                MFinanceConstants.ACCOUNT_PROPERTY_BANK_ACCOUNT);

                        if ((AInspectDS.AAccountProperty.DefaultView.Count == 0) && acc.BankAccountFlag)
                        {
                            AAccountPropertyRow accProp = AInspectDS.AAccountProperty.NewRowTyped(true);
                            accProp.LedgerNumber = acc.LedgerNumber;
                            accProp.AccountCode = acc.AccountCode;
                            accProp.PropertyCode = MFinanceConstants.ACCOUNT_PROPERTY_BANK_ACCOUNT;
                            accProp.PropertyValue = "true";
                            AInspectDS.AAccountProperty.Rows.Add(accProp);
                        }
                        else if (AInspectDS.AAccountProperty.DefaultView.Count == 1)
                        {
                            AAccountPropertyRow accProp = (AAccountPropertyRow)AInspectDS.AAccountProperty.DefaultView[0].Row;

                            if (!acc.BankAccountFlag)
                            {
                                accProp.Delete();
                            }
                            else
                            {
                                accProp.PropertyValue = "true";
                            }
                        }

                        AInspectDS.AAccountProperty.DefaultView.RowFilter = "";
                    }

                    /* SuspenseAccountFlag */

                    // if the flag has been changed by the client, it will not be null
                    if (!acc.IsSuspenseAccountFlagNull())
                    {
                        if (AInspectDS.ASuspenseAccount == null)
                        {
                            // because ASuspenseAccount has not been changed on the client, GetChangesTyped will have removed the table
                            // so we need to reload the table from the database
                            AInspectDS.Merge(new ASuspenseAccountTable());

                            GLSetupTDS inspectDS = AInspectDS;
                            TDBTransaction transaction = null;

                            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                                TEnforceIsolationLevel.eilMinimum,
                                ref transaction,
                                delegate
                                {
                                    ASuspenseAccountAccess.LoadViaALedger(inspectDS, ALedgerNumber, transaction);
                                });
                        }

                        AInspectDS.ASuspenseAccount.DefaultView.RowFilter =
                            String.Format("{0}='{1}'",
                                ASuspenseAccountTable.GetSuspenseAccountCodeDBName(),
                                acc.AccountCode);

                        // create a new suspense account record
                        if ((AInspectDS.ASuspenseAccount.DefaultView.Count == 0) && acc.SuspenseAccountFlag)
                        {
                            ASuspenseAccountRow accProp = AInspectDS.ASuspenseAccount.NewRowTyped(true);
                            accProp.LedgerNumber = acc.LedgerNumber;
                            accProp.SuspenseAccountCode = acc.AccountCode;
                            AInspectDS.ASuspenseAccount.Rows.Add(accProp);
                        }
                        // delete a suspense account record
                        else if (AInspectDS.ASuspenseAccount.DefaultView.Count == 1)
                        {
                            ASuspenseAccountRow accProp = (ASuspenseAccountRow)AInspectDS.ASuspenseAccount.DefaultView[0].Row;

                            if (!acc.SuspenseAccountFlag)
                            {
                                accProp.Delete();
                            }
                        }

                        AInspectDS.ASuspenseAccount.DefaultView.RowFilter = "";
                    }
                }
            }

            if (AInspectDS.AAnalysisType != null)
            {
                if (AInspectDS.AAnalysisType.Rows.Count > 0)
                {
                    ValidateAAnalysisType(ref AVerificationResult, AInspectDS.AAnalysisType);
                    ValidateAAnalysisTypeManual(ref AVerificationResult, AInspectDS.AAnalysisType);

                    if (!TVerificationHelper.IsNullOrOnlyNonCritical(AVerificationResult))
                    {
                        ReturnValue = TSubmitChangesResult.scrError;
                    }
                }
            }

            if (ReturnValue != TSubmitChangesResult.scrError)
            {
                GLSetupTDSAccess.SubmitChanges(AInspectDS);

                if (AInspectDS.AAnalysisAttribute != null)
                {
                    AInspectDS.AAnalysisAttribute.AcceptChanges(); // This may prevent a constraints exception when the dataset is returned and merged.
                }

                ReturnValue = TSubmitChangesResult.scrOK;
            }

            TCacheableTablesManager.GCacheableTablesManager.MarkCachedTableNeedsRefreshing(
                TCacheableFinanceTablesEnum.AccountList.ToString());
            TCacheableTablesManager.GCacheableTablesManager.MarkCachedTableNeedsRefreshing(
                TCacheableFinanceTablesEnum.AnalysisTypeList.ToString());
            TCacheableTablesManager.GCacheableTablesManager.MarkCachedTableNeedsRefreshing(
                TCacheableFinanceTablesEnum.CostCentreList.ToString());
            TCacheableTablesManager.GCacheableTablesManager.MarkCachedTableNeedsRefreshing(
                TCacheableFinanceTablesEnum.SuspenseAccountList.ToString());

            if (AVerificationResult.Count > 0)
            {
                // Downgrade TScreenVerificationResults to TVerificationResults in order to allow
                // Serialisation (needed for .NET Remoting).
                TVerificationResultCollection.DowngradeScreenVerificationResults(AVerificationResult);
            }

            return ReturnValue;
        }