Esempio n. 1
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="e"></param>
        /// <param name="AVerificationResultCollection"></param>
        /// <param name="AVerificationResult"></param>
        public static void VerifyDates(DataColumnChangeEventArgs e,
                                       TVerificationResultCollection AVerificationResultCollection,
                                       out TVerificationResult AVerificationResult)
        {
            AVerificationResult = null;
            DateTime DateGoodUntil = new DateTime();
            DateTime DateEffective = new DateTime();

            try
            {
                if (e.Column.ColumnName == PPartnerLocationTable.GetDateEffectiveDBName())
                {
                    // MessageBox.Show('p_date_effective_d: ' + e.Row['p_date_effective_d', DataRowVersion.Current].ToString);
                    DateEffective = TSaveConvert.ObjectToDate(e.ProposedValue);
                    DateGoodUntil = TSaveConvert.ObjectToDate(e.Row[PPartnerLocationTable.GetDateGoodUntilDBName()]);
                }
                else if (e.Column.ColumnName == PPartnerLocationTable.GetDateGoodUntilDBName())
                {
                    DateEffective = TSaveConvert.ObjectToDate(e.Row[PPartnerLocationTable.GetDateEffectiveDBName()]);
                    DateGoodUntil = TSaveConvert.ObjectToDate(e.ProposedValue);
                }

                // MessageBox.Show('p_date_effective_d: ' + DateEffective.ToString + Environment.NewLine +
                // 'p_date_good_until_d: ' + DateGoodUntil.ToString);
                if (e.Column.ColumnName == PPartnerLocationTable.GetDateEffectiveDBName())
                {
                    AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateEffective, DateGoodUntil, "Valid From", "Valid To");
                }
                else
                {
                    AVerificationResult = TDateChecks.FirstGreaterOrEqualThanSecondDate(DateGoodUntil, DateEffective, "Valid To", "Valid From");
                }

                if (e.Column.ColumnName == PPartnerLocationTable.GetDateEffectiveDBName())
                {
                    // delete any error that might have been there from a verification of the other column
                    AVerificationResultCollection.Remove(PPartnerLocationTable.GetDateGoodUntilDBName());
                }
                else
                {
                    // delete any error that might have been there from a verification of the other column
                    AVerificationResultCollection.Remove(PPartnerLocationTable.GetDateEffectiveDBName());
                }
            }
            catch (Exception Exp)
            {
                MessageBox.Show("Exception occured in TPartnerAddressVerification.VerifyDates: " + Exp.ToString());
            }
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="AContext"></param>
        /// <param name="ARow"></param>
        /// <param name="AVerificationResultCollection"></param>
        public static void ValidateAccountingPeriod(object AContext, AAccountingPeriodRow ARow,
                                                    ref TVerificationResultCollection AVerificationResultCollection)
        {
            DataColumn          ValidationColumn;
            TVerificationResult VerificationResult;

            // 'Period End Date' must be later than 'Period Start Date'
            ValidationColumn = ARow.Table.Columns[AAccountingPeriodTable.ColumnPeriodEndDateId];

            if (true)
            {
                VerificationResult = TDateChecks.FirstGreaterOrEqualThanSecondDate(ARow.PeriodEndDate, ARow.PeriodStartDate,
                                                                                   String.Empty, String.Empty,
                                                                                   AContext, ValidationColumn);

                // Handle addition to/removal from TVerificationResultCollection
                AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult);
            }
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="AContext"></param>
        /// <param name="ARow"></param>
        /// <param name="AVerificationResultCollection"></param>
        /// <param name="AValidationControlsDict"></param>
        public static void ValidateAccountingPeriod(object AContext, AAccountingPeriodRow ARow,
                                                    ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict)
        {
            DataColumn ValidationColumn;
            TValidationControlsData ValidationControlsData;
            TVerificationResult     VerificationResult;

            // 'Period End Date' must be later than 'Period Start Date'
            ValidationColumn = ARow.Table.Columns[AAccountingPeriodTable.ColumnPeriodEndDateId];

            if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                VerificationResult = TDateChecks.FirstGreaterOrEqualThanSecondDate(ARow.PeriodEndDate, ARow.PeriodStartDate,
                                                                                   ValidationControlsData.ValidationControlLabel, ValidationControlsData.SecondValidationControlLabel,
                                                                                   AContext, ValidationColumn, ValidationControlsData.ValidationControl);

                // Handle addition to/removal from TVerificationResultCollection
                AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn);
            }
        }
Esempio n. 4
0
        /// <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);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// todoComment
        /// </summary>
        /// <param name="e"></param>
        /// <param name="AVerificationResultCollection"></param>
        /// <param name="AVerificationResult"></param>
        /// <param name="FDataColumnComparedTo"></param>
        public static void VerifySubscriptionDates(DataColumnChangeEventArgs e,
                                                   TVerificationResultCollection AVerificationResultCollection,
                                                   out TVerificationResult AVerificationResult,
                                                   out DataColumn FDataColumnComparedTo)
        {
            FDataColumnComparedTo = null;
            AVerificationResult   = null;
            DateTime DateStarted    = new DateTime();
            DateTime DateExpired    = new DateTime();
            DateTime DateRenewed    = new DateTime();
            DateTime DateNoticeSent = new DateTime();
            DateTime DateEnded      = new DateTime();
            DateTime DateFirstSent  = new DateTime();
            DateTime DateLastSent   = new DateTime();
            Boolean  Completed;

            Completed = false;

            if (e.Column.ColumnName == PSubscriptionTable.GetStartDateDBName())
            {
                DateStarted    = TSaveConvert.ObjectToDate(e.ProposedValue);
                DateExpired    = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetExpiryDateDBName()]);
                DateRenewed    = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]);
                DateNoticeSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateNoticeSentDBName()]);
                DateEnded      = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateCancelledDBName()]);
                DateFirstSent  = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetFirstIssueDBName()]);
                DateLastSent   = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetLastIssueDBName()]);
            }

            if (e.Column.ColumnName == PSubscriptionTable.GetExpiryDateDBName())
            {
                DateStarted    = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetStartDateDBName()]);
                DateExpired    = TSaveConvert.ObjectToDate(e.ProposedValue);
                DateRenewed    = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]);
                DateNoticeSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateNoticeSentDBName()]);
                DateEnded      = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateCancelledDBName()]);
                DateFirstSent  = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetFirstIssueDBName()]);
                DateLastSent   = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetLastIssueDBName()]);
            }

            if (e.Column.ColumnName == PSubscriptionTable.GetSubscriptionRenewalDateDBName())
            {
                DateStarted    = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetStartDateDBName()]);
                DateExpired    = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetExpiryDateDBName()]);
                DateRenewed    = TSaveConvert.ObjectToDate(e.ProposedValue);
                DateNoticeSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateNoticeSentDBName()]);
                DateEnded      = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateCancelledDBName()]);
                DateFirstSent  = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetFirstIssueDBName()]);
                DateLastSent   = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetLastIssueDBName()]);
            }

            if (e.Column.ColumnName == PSubscriptionTable.GetDateNoticeSentDBName())
            {
                DateStarted    = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetStartDateDBName()]);
                DateExpired    = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetExpiryDateDBName()]);
                DateRenewed    = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]);
                DateNoticeSent = TSaveConvert.ObjectToDate(e.ProposedValue);
                DateEnded      = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateCancelledDBName()]);
                DateFirstSent  = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetFirstIssueDBName()]);
                DateLastSent   = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetLastIssueDBName()]);
            }

            if (e.Column.ColumnName == PSubscriptionTable.GetDateCancelledDBName())
            {
                DateStarted    = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetStartDateDBName()]);
                DateExpired    = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetExpiryDateDBName()]);
                DateRenewed    = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]);
                DateNoticeSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateNoticeSentDBName()]);
                DateEnded      = TSaveConvert.ObjectToDate(e.ProposedValue);
                DateFirstSent  = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetFirstIssueDBName()]);
                DateLastSent   = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetLastIssueDBName()]);
            }

            if (e.Column.ColumnName == PSubscriptionTable.GetFirstIssueDBName())
            {
                DateStarted    = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetStartDateDBName()]);
                DateExpired    = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetExpiryDateDBName()]);
                DateRenewed    = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]);
                DateNoticeSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateNoticeSentDBName()]);
                DateEnded      = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateCancelledDBName()]);
                DateFirstSent  = TSaveConvert.ObjectToDate(e.ProposedValue);
                DateLastSent   = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetLastIssueDBName()]);
            }

            if (e.Column.ColumnName == PSubscriptionTable.GetLastIssueDBName())
            {
                DateStarted    = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetStartDateDBName()]);
                DateExpired    = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetExpiryDateDBName()]);
                DateRenewed    = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]);
                DateNoticeSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateNoticeSentDBName()]);
                DateEnded      = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateCancelledDBName()]);
                DateFirstSent  = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetFirstIssueDBName()]);
                DateLastSent   = TSaveConvert.ObjectToDate(e.ProposedValue);
            }

            while (!Completed)
            {
                // when the StartDate has changed, do this:
                if (e.Column.ColumnName == PSubscriptionTable.GetStartDateDBName())
                {
                    FDataColumnComparedTo = e.Column;
                    TPartnerSubscriptionVerification.VerifyDatesAgainstStartDate(DateStarted,
                                                                                 DateExpired,
                                                                                 DateRenewed,
                                                                                 DateNoticeSent,
                                                                                 DateEnded,
                                                                                 DateFirstSent,
                                                                                 DateLastSent,
                                                                                 out AVerificationResult,
                                                                                 out Completed);

                    if (Completed == true)
                    {
                        break;
                    }
                }

                if (e.Column.ColumnName == PSubscriptionTable.GetExpiryDateDBName())
                {
                    FDataColumnComparedTo = e.Column;
                    TPartnerSubscriptionVerification.VerifyDatesAgainstStartDate(DateStarted,
                                                                                 DateExpired,
                                                                                 DateRenewed,
                                                                                 DateNoticeSent,
                                                                                 DateEnded,
                                                                                 DateFirstSent,
                                                                                 DateLastSent,
                                                                                 out AVerificationResult,
                                                                                 out Completed);

                    if (Completed == true)
                    {
                        break;
                    }
                }

                if (e.Column.ColumnName == PSubscriptionTable.GetSubscriptionRenewalDateDBName())
                {
                    FDataColumnComparedTo = e.Column;
                    TPartnerSubscriptionVerification.VerifyDatesAgainstStartDate(DateStarted,
                                                                                 DateExpired,
                                                                                 DateRenewed,
                                                                                 DateNoticeSent,
                                                                                 DateEnded,
                                                                                 DateFirstSent,
                                                                                 DateLastSent,
                                                                                 out AVerificationResult,
                                                                                 out Completed);

                    if (Completed == true)
                    {
                        break;
                    }

                    if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateRenewed, DateTime.Today, "Date Renewed", "Today") != null)
                    {
                        AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateRenewed, DateTime.Today, "DateRenewed", "Today");
                        Completed           = true;
                        break;
                    }

                    if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateRenewed, DateExpired, "Date Renewed", "Date Expired") != null)
                    {
                        AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateRenewed, DateExpired, "Date Renewed", "Date Expired");
                        Completed           = true;
                        break;
                    }

                    if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateRenewed, DateNoticeSent, "Date Renewed", "Date Notice Sent") != null)
                    {
                        AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateRenewed,
                                                                                           DateNoticeSent,
                                                                                           "Date Renewed",
                                                                                           "Date Notice Sent");
                        Completed = true;
                        break;
                    }
                }

                if (e.Column.ColumnName == PSubscriptionTable.GetDateNoticeSentDBName())
                {
                    FDataColumnComparedTo = e.Column;
                    TPartnerSubscriptionVerification.VerifyDatesAgainstStartDate(DateStarted,
                                                                                 DateExpired,
                                                                                 DateRenewed,
                                                                                 DateNoticeSent,
                                                                                 DateEnded,
                                                                                 DateFirstSent,
                                                                                 DateLastSent,
                                                                                 out AVerificationResult,
                                                                                 out Completed);

                    if (Completed == true)
                    {
                        break;
                    }
                }

                if (e.Column.ColumnName == PSubscriptionTable.GetDateCancelledDBName())
                {
                    FDataColumnComparedTo = e.Column;
                    TPartnerSubscriptionVerification.VerifyDatesAgainstStartDate(DateStarted,
                                                                                 DateExpired,
                                                                                 DateRenewed,
                                                                                 DateNoticeSent,
                                                                                 DateEnded,
                                                                                 DateFirstSent,
                                                                                 DateLastSent,
                                                                                 out AVerificationResult,
                                                                                 out Completed);

                    if (Completed == true)
                    {
                        break;
                    }

                    if (TDateChecks.FirstLesserThanSecondDate(DateTime.Today, DateEnded, "Today", "Cancelled") != null)
                    {
                        AVerificationResult = TDateChecks.FirstLesserThanSecondDate(DateTime.Today, DateEnded, "Today", "Cancelled");
                        Completed           = true;
                        break;
                    }
                }

                if (e.Column.ColumnName == PSubscriptionTable.GetFirstIssueDBName())
                {
                    FDataColumnComparedTo = e.Column;

                    if (TDateChecks.FirstGreaterOrEqualThanSecondDate(DateLastSent, DateFirstSent, "Last Sent", "First Sent") != null)
                    {
                        AVerificationResult = TDateChecks.FirstGreaterOrEqualThanSecondDate(DateLastSent, DateFirstSent, "Last Sent", "First Sent");
                        Completed           = true;
                        break;
                    }

                    if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateStarted, DateFirstSent, "Date Started", "First Sent") != null)
                    {
                        AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateStarted, DateFirstSent, "Date Started", "First Sent");
                        Completed           = true;
                        break;
                    }

                    if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateFirstSent, DateTime.Today, "First Sent", "today") != null)
                    {
                        AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateFirstSent, DateTime.Today, "First Sent", "today");
                        Completed           = true;
                        break;
                    }
                }

                if (e.Column.ColumnName == PSubscriptionTable.GetLastIssueDBName())
                {
                    FDataColumnComparedTo = e.Column;

                    if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateFirstSent, DateLastSent, "First Sent", "Last Sent") != null)
                    {
                        AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateFirstSent, DateLastSent, "First Sent", "Last Sent");
                        Completed           = true;
                        break;
                    }

                    if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateLastSent, DateTime.Today, "Last Sent", "today") != null)
                    {
                        AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateLastSent, DateTime.Today, "Last Sent", "today");
                        Completed           = true;
                        break;
                    }
                }

                Completed = true;
            }
        }
Esempio n. 6
0
        /// <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);
                    }
                }
            }
        }