/// <summary> /// Validates the Daily 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> /// <param name="AMinDateTime">The earliest allowable date.</param> /// <param name="AMaxDateTime">The latest allowable date.</param> public static void ValidateDailyExchangeRate(object AContext, ADailyExchangeRateRow ARow, ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict, DateTime AMinDateTime, DateTime AMaxDateTime) { 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[ADailyExchangeRateTable.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 and must be in range ValidationColumn = ARow.Table.Columns[ADailyExchangeRateTable.ColumnDateEffectiveFromId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TSharedValidationControlHelper.IsNotInvalidDate(ARow.DateEffectiveFrom, ValidationControlsData.ValidationControlLabel, AVerificationResultCollection, true, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); if (VerificationResult == null) { if ((AMinDateTime > DateTime.MinValue) && (AMaxDateTime < DateTime.MaxValue)) { // Check that the date is in range VerificationResult = TDateChecks.IsDateBetweenDates(ARow.DateEffectiveFrom, AMinDateTime, AMaxDateTime, ValidationControlsData.ValidationControlLabel, TDateBetweenDatesCheckType.dbdctUnspecific, TDateBetweenDatesCheckType.dbdctUnspecific, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } else if (AMaxDateTime < DateTime.MaxValue) { VerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(ARow.DateEffectiveFrom, AMaxDateTime, ValidationControlsData.ValidationControlLabel, Ict.Common.StringHelper.DateToLocalizedString(AMaxDateTime), AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } else if (AMinDateTime > DateTime.MinValue) { VerificationResult = TDateChecks.FirstGreaterOrEqualThanSecondDate(ARow.DateEffectiveFrom, AMinDateTime, ValidationControlsData.ValidationControlLabel, Ict.Common.StringHelper.DateToLocalizedString(AMinDateTime), AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } } } // Time must not be negative (indicating an error) ValidationColumn = ARow.Table.Columns[ADailyExchangeRateTable.ColumnTimeEffectiveFromId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TTimeChecks.IsValidIntegerTime(ARow.TimeEffectiveFrom, ValidationControlsData.ValidationControlLabel, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } }
/// <summary> /// Validates the Daily 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="AMinDateTime">The earliest allowable date.</param> /// <param name="AMaxDateTime">The latest allowable date.</param> /// <param name="AIgnoreZeroRateCheck">If true a zero rate will be allowed. This will be the case when the Daily Exchange Rate screen is modal.</param> /// <param name="ALedgerTableRef">A ledger table containg the available ledgers and their base currencies</param> /// <param name="AEarliestAccountingPeriodStartDate">The earliest accounting period start date in all the active ledgers</param> /// <param name="ALatestAccountingPeriodEndDate">The latest accounting period end date in all the active ledgers</param> public static void ValidateDailyExchangeRate(object AContext, ADailyExchangeRateRow ARow, ref TVerificationResultCollection AVerificationResultCollection, DateTime AMinDateTime, DateTime AMaxDateTime, bool AIgnoreZeroRateCheck, ALedgerTable ALedgerTableRef, DateTime AEarliestAccountingPeriodStartDate, DateTime ALatestAccountingPeriodEndDate) { DataColumn ValidationColumn; TVerificationResult VerificationResult; // Don't validate deleted DataRows if (ARow.RowState == DataRowState.Deleted) { return; } // RateOfExchange must be positive (definitely not zero unless in modal mode) ValidationColumn = ARow.Table.Columns[ADailyExchangeRateTable.ColumnRateOfExchangeId]; if (true) { if (AIgnoreZeroRateCheck) { VerificationResult = TNumericalChecks.IsPositiveOrZeroDecimal(ARow.RateOfExchange, String.Empty, AContext, ValidationColumn); } else { 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 and must be in range ValidationColumn = ARow.Table.Columns[ADailyExchangeRateTable.ColumnDateEffectiveFromId]; if (true) { VerificationResult = TValidationControlHelper.IsNotInvalidDate(ARow.DateEffectiveFrom, String.Empty, AVerificationResultCollection, true, AContext, ValidationColumn); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult); if (VerificationResult == null) { if ((AMinDateTime > DateTime.MinValue) && (AMaxDateTime < DateTime.MaxValue)) { // Check that the date is in range VerificationResult = TDateChecks.IsDateBetweenDates(ARow.DateEffectiveFrom, AMinDateTime, AMaxDateTime, String.Empty, TDateBetweenDatesCheckType.dbdctUnspecific, TDateBetweenDatesCheckType.dbdctUnspecific, AContext, ValidationColumn); } else if (AMaxDateTime < DateTime.MaxValue) { VerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(ARow.DateEffectiveFrom, AMaxDateTime, String.Empty, Ict.Common.StringHelper.DateToLocalizedString(AMaxDateTime), AContext, ValidationColumn); if ((VerificationResult == null) && (ARow.RowState == DataRowState.Added)) { // even without a specific minimum date it should not be too far back if (ARow.DateEffectiveFrom < AEarliestAccountingPeriodStartDate) { VerificationResult = new TScreenVerificationResult(AContext, ValidationColumn, Catalog.GetString( "The date is before the start of the earliest current accounting period of any active ledger."), TResultSeverity.Resv_Noncritical); } } } else if (AMinDateTime > DateTime.MinValue) { VerificationResult = TDateChecks.FirstGreaterOrEqualThanSecondDate(ARow.DateEffectiveFrom, AMinDateTime, String.Empty, Ict.Common.StringHelper.DateToLocalizedString(AMinDateTime), AContext, ValidationColumn); if ((VerificationResult == null) && (ARow.RowState == DataRowState.Added)) { // even without a specific maximum date it should not be too far ahead if (ARow.DateEffectiveFrom > ALatestAccountingPeriodEndDate) { VerificationResult = new TScreenVerificationResult(AContext, ValidationColumn, Catalog.GetString( "The date is after the end of the latest forwarding period of any active ledger."), TResultSeverity.Resv_Noncritical); } } } else if ((AMinDateTime == DateTime.MinValue) && (AMaxDateTime == DateTime.MaxValue) && (ARow.RowState == DataRowState.Added)) { // even without a specific maximum date it should not be too far ahead if (ARow.DateEffectiveFrom > ALatestAccountingPeriodEndDate) { VerificationResult = new TScreenVerificationResult(AContext, ValidationColumn, Catalog.GetString( "The date is after the end of the latest forwarding period of any active ledger."), TResultSeverity.Resv_Noncritical); } // even without a specific minimum date it should not be too far back else if (ARow.DateEffectiveFrom < AEarliestAccountingPeriodStartDate) { VerificationResult = new TScreenVerificationResult(AContext, ValidationColumn, Catalog.GetString( "The date is before the start of the earliest current accounting period of any active ledger."), TResultSeverity.Resv_Noncritical); } } // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult); } } // Time must not be negative (indicating an error) ValidationColumn = ARow.Table.Columns[ADailyExchangeRateTable.ColumnTimeEffectiveFromId]; if (true) { VerificationResult = TTimeChecks.IsValidIntegerTime(ARow.TimeEffectiveFrom, String.Empty, AContext, ValidationColumn); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult); } if (true) { // These tests are for the GUI only ValidationColumn = ARow.Table.Columns[ADailyExchangeRateTable.ColumnToCurrencyCodeId]; if (true) { // One of the currencies should be the base currency of one of the ledgers if (ARow.RowState == DataRowState.Added) { // Only do this test if the To Currency ComboBox is enabled 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); } } } }