Esempio n. 1
0
        /// <summary>
        /// Validates the Corporate Exchange Rates screen data.
        /// </summary>
        /// <param name="AContext">Context that describes where the data validation failed.</param>
        /// <param name="ARow">The <see cref="DataRow" /> which holds the the data against which the validation is run.</param>
        /// <param name="AVerificationResultCollection">Will be filled with any <see cref="TVerificationResult" /> items if
        /// data validation errors occur.</param>
        /// <param name="AValidationControlsDict">A <see cref="TValidationControlsDict" /> containing the Controls that
        /// display data that is about to be validated.</param>
        public static void ValidateCorporateExchangeRate(object AContext, ACorporateExchangeRateRow ARow,
                                                         ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict)
        {
            DataColumn ValidationColumn;
            TValidationControlsData ValidationControlsData;
            TVerificationResult     VerificationResult;

            // Don't validate deleted DataRows
            if (ARow.RowState == DataRowState.Deleted)
            {
                return;
            }

            // RateOfExchange must be positive (definitely not zero because we can invert it)
            ValidationColumn = ARow.Table.Columns[ACorporateExchangeRateTable.ColumnRateOfExchangeId];

            if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                VerificationResult = TNumericalChecks.IsPositiveDecimal(ARow.RateOfExchange,
                                                                        ValidationControlsData.ValidationControlLabel,
                                                                        AContext, ValidationColumn, ValidationControlsData.ValidationControl);

                // Handle addition/removal to/from TVerificationResultCollection
                AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn);
            }

            // Date must not be empty
            ValidationColumn = ARow.Table.Columns[ACorporateExchangeRateTable.ColumnDateEffectiveFromId];

            if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                VerificationResult = TDateChecks.IsNotUndefinedDateTime(ARow.DateEffectiveFrom,
                                                                        ValidationControlsData.ValidationControlLabel,
                                                                        true, AContext, ValidationColumn, ValidationControlsData.ValidationControl);

                // Handle addition/removal to/from TVerificationResultCollection
                AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn);
            }

            // Date must be first of month
            ValidationColumn = ARow.Table.Columns[ACorporateExchangeRateTable.ColumnDateEffectiveFromId];

            if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                VerificationResult = TDateChecks.IsNotCorporateDateTime(ARow.DateEffectiveFrom,
                                                                        ValidationControlsData.ValidationControlLabel,
                                                                        AContext, ValidationColumn, ValidationControlsData.ValidationControl);

                // Handle addition/removal to/from TVerificationResultCollection
                AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Validates the Corporate Exchange Rates screen data.
        /// </summary>
        /// <param name="AContext">Context that describes where the data validation failed.</param>
        /// <param name="ARow">The <see cref="DataRow" /> which holds the the data against which the validation is run.</param>
        /// <param name="AVerificationResultCollection">Will be filled with any <see cref="TVerificationResult" /> items if
        /// data validation errors occur.</param>
        /// <param name="ALedgerTableRef">A reference to a ledger table that has contains the ledgers that a client has access to</param>
        /// <param name="AAlternativeFirstDayOfPeriod">An alternative day (apart from 1) that is the start of an accounting period
        /// for at least one of the availbale ledgers</param>
        public static void ValidateCorporateExchangeRate(object AContext, ACorporateExchangeRateRow ARow,
                                                         ref TVerificationResultCollection AVerificationResultCollection,
                                                         ALedgerTable ALedgerTableRef, int AAlternativeFirstDayOfPeriod)
        {
            DataColumn          ValidationColumn;
            TVerificationResult VerificationResult;

            // Don't validate deleted DataRows
            if (ARow.RowState == DataRowState.Deleted)
            {
                return;
            }

            // RateOfExchange must be positive (definitely not zero because we can invert it)
            ValidationColumn = ARow.Table.Columns[ACorporateExchangeRateTable.ColumnRateOfExchangeId];

            if (true)
            {
                VerificationResult = TNumericalChecks.IsPositiveDecimal(ARow.RateOfExchange,
                                                                        String.Empty,
                                                                        AContext, ValidationColumn);

                // Handle addition/removal to/from TVerificationResultCollection
                AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult);
            }

            // Date must not be empty
            ValidationColumn = ARow.Table.Columns[ACorporateExchangeRateTable.ColumnDateEffectiveFromId];

            if (true)
            {
                VerificationResult = TDateChecks.IsNotUndefinedDateTime(ARow.DateEffectiveFrom,
                                                                        String.Empty,
                                                                        true, AContext, ValidationColumn);

                // Handle addition/removal to/from TVerificationResultCollection
                AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult);
            }

            // Date must be first of month or first day in accounting period of a ledger
            ValidationColumn = ARow.Table.Columns[ACorporateExchangeRateTable.ColumnDateEffectiveFromId];

            if (true)
            {
                VerificationResult = null;

                if (AAlternativeFirstDayOfPeriod != 0)
                {
                    // day must be either 1 or AAlternativeFirstDayOfPeriod
                    VerificationResult = TDateChecks.IsNotCorporateDateTime(ARow.DateEffectiveFrom,
                                                                            String.Empty,
                                                                            AContext, ValidationColumn, AAlternativeFirstDayOfPeriod);
                }
                else
                {
                    // when the value is 0 we cannot do validation because there are too many alternatives!
                    // How complicated is this set of ledgers???
                }

                // Handle addition/removal to/from TVerificationResultCollection
                AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult);
            }

            if (true)
            {
                // These tests are for the GUI only
                ValidationColumn = ARow.Table.Columns[ACorporateExchangeRateTable.ColumnToCurrencyCodeId];

                if (true)
                {
                    // One of the currencies should be the base currency of one of the ledgers
                    if ((ARow.RowState == DataRowState.Added) && (ALedgerTableRef != null))
                    {
                        // Only do this test on new rows
                        TScreenVerificationResult vr = null;
                        DataView fromView            = new DataView(ALedgerTableRef, String.Format("{0}='{1}'",
                                                                                                   ALedgerTable.GetBaseCurrencyDBName(), ARow.FromCurrencyCode), String.Empty, DataViewRowState.CurrentRows);

                        if (fromView.Count == 0)
                        {
                            DataView toView = new DataView(ALedgerTableRef, String.Format("{0}='{1}'",
                                                                                          ALedgerTable.GetBaseCurrencyDBName(), ARow.ToCurrencyCode), String.Empty, DataViewRowState.CurrentRows);

                            if (toView.Count == 0)
                            {
                                vr = new TScreenVerificationResult(AContext, ValidationColumn,
                                                                   "One of the currencies should normally be a base currency for one of the Ledgers",
                                                                   TResultSeverity.Resv_Noncritical);
                            }
                        }

                        // Handle addition to/removal from TVerificationResultCollection
                        AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, vr);
                    }
                }
            }
        }