コード例 #1
0
        /// <summary>
        /// Validates the event (short term) application record of a Person.
        /// </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>
        /// <returns>void</returns>
        public static void ValidateEventApplicationManual(object AContext, PmShortTermApplicationRow ARow,
            ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict)
        {
            DataColumn ValidationColumn;
            TValidationControlsData ValidationControlsData;
            TVerificationResult VerificationResult;

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

            // 'Event' must be a Partner of Class 'UNIT' and must not be 0
            ValidationColumn = ARow.Table.Columns[PmShortTermApplicationTable.ColumnStConfirmedOptionId];

            if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                if (ARow.IsStConfirmedOptionNull())
                {
                    VerificationResult = new TScreenVerificationResult(new TVerificationResult(AContext,
                            ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_PARTNERKEY_INVALID_NOTNULL,
                                new string[] { ValidationControlsData.ValidationControlLabel })),
                        ValidationColumn, ValidationControlsData.ValidationControl);
                }
                else
                {
                    VerificationResult = TSharedPartnerValidation_Partner.IsValidUNITPartner(
                        ARow.StConfirmedOption, false, THelper.NiceValueDescription(
                            ValidationControlsData.ValidationControlLabel) + " must be set correctly.",
                        AContext, ValidationColumn, ValidationControlsData.ValidationControl);
                }

                // Since the validation can result in different ResultTexts we need to remove any validation result manually as a call to
                // AVerificationResultCollection.AddOrRemove wouldn't remove a previous validation result with a different
                // ResultText!
                AVerificationResultCollection.Remove(ValidationColumn);
                AVerificationResultCollection.AddAndIgnoreNullValue(VerificationResult);
            }

            // 'Charged Field' must be a Partner of Class 'UNIT'
            //
            // HOWEVER, 'null' is a perfectly valid value for 'Charged Field' (according to WolfgangB).
            // If it is null then we must not call TSharedPartnerValidation_Partner.IsValidUNITPartner
            // as the attempt to retrieve 'ARow.StFieldCharged' would result in
            // 'System.Data.StrongTypingException("Error: DB null", null)'!!!
            if (!ARow.IsStFieldChargedNull())
            {
                ValidationColumn = ARow.Table.Columns[PmShortTermApplicationTable.ColumnStFieldChargedId];

                if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
                {
                    VerificationResult = TSharedPartnerValidation_Partner.IsValidUNITPartner(
                        ARow.StFieldCharged, true, THelper.NiceValueDescription(
                            ValidationControlsData.ValidationControlLabel) + " must be set correctly.",
                        AContext, ValidationColumn, ValidationControlsData.ValidationControl);

                    // Since the validation can result in different ResultTexts we need to remove any validation result manually as a call to
                    // AVerificationResultCollection.AddOrRemove wouldn't remove a previous validation result with a different
                    // ResultText!
                    AVerificationResultCollection.Remove(ValidationColumn);
                    AVerificationResultCollection.AddAndIgnoreNullValue(VerificationResult);
                }
            }

            // 'Arrival Method' must not be unassignable
            ValidationColumn = ARow.Table.Columns[PmShortTermApplicationTable.ColumnTravelTypeToCongCodeId];

            if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                PtTravelTypeTable TravelTypeTable;
                PtTravelTypeRow TravelTypeRow = null;

                VerificationResult = null;

                if (!ARow.IsTravelTypeToCongCodeNull())
                {
                    TravelTypeTable = (PtTravelTypeTable)TSharedDataCache.TMPersonnel.GetCacheablePersonnelTableDelegate(
                        TCacheablePersonTablesEnum.TransportTypeList);
                    TravelTypeRow = (PtTravelTypeRow)TravelTypeTable.Rows.Find(ARow.TravelTypeToCongCode);

                    // 'Arrival Method' must not be unassignable
                    if ((TravelTypeRow != null)
                        && TravelTypeRow.UnassignableFlag
                        && (TravelTypeRow.IsUnassignableDateNull()
                            || (TravelTypeRow.UnassignableDate <= DateTime.Today)))
                    {
                        // if 'Arrival Method' is unassignable then check if the value has been changed or if it is a new record
                        if (TSharedValidationHelper.IsRowAddedOrFieldModified(ARow, PmShortTermApplicationTable.GetTravelTypeToCongCodeDBName()))
                        {
                            VerificationResult = new TScreenVerificationResult(new TVerificationResult(AContext,
                                    ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_VALUEUNASSIGNABLE_WARNING,
                                        new string[] { ValidationControlsData.ValidationControlLabel, ARow.TravelTypeToCongCode })),
                                ValidationColumn, ValidationControlsData.ValidationControl);
                        }
                    }
                }

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

            // 'Departure Method' must not be unassignable
            ValidationColumn = ARow.Table.Columns[PmShortTermApplicationTable.ColumnTravelTypeFromCongCodeId];

            if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                PtTravelTypeTable TravelTypeTable;
                PtTravelTypeRow TravelTypeRow = null;

                VerificationResult = null;

                if (!ARow.IsTravelTypeFromCongCodeNull())
                {
                    TravelTypeTable = (PtTravelTypeTable)TSharedDataCache.TMPersonnel.GetCacheablePersonnelTableDelegate(
                        TCacheablePersonTablesEnum.TransportTypeList);
                    TravelTypeRow = (PtTravelTypeRow)TravelTypeTable.Rows.Find(ARow.TravelTypeFromCongCode);

                    // 'Departure Method' must not be unassignable
                    if ((TravelTypeRow != null)
                        && TravelTypeRow.UnassignableFlag
                        && (TravelTypeRow.IsUnassignableDateNull()
                            || (TravelTypeRow.UnassignableDate <= DateTime.Today)))
                    {
                        // if 'Departure Method' is unassignable then check if the value has been changed or if it is a new record
                        if (TSharedValidationHelper.IsRowAddedOrFieldModified(ARow, PmShortTermApplicationTable.GetTravelTypeFromCongCodeDBName()))
                        {
                            VerificationResult = new TScreenVerificationResult(new TVerificationResult(AContext,
                                    ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_VALUEUNASSIGNABLE_WARNING,
                                        new string[] { ValidationControlsData.ValidationControlLabel, ARow.TravelTypeFromCongCode })),
                                ValidationColumn, ValidationControlsData.ValidationControl);
                        }
                    }
                }

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

            // 'Departure Date' must be later than 'Arrival Date'
            ValidationColumn = ARow.Table.Columns[PmShortTermApplicationTable.ColumnDepartureId];

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

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

            // 'Arrival Hour' must be between 0 and 24
            ValidationColumn = ARow.Table.Columns[PmShortTermApplicationTable.ColumnArrivalHourId];

            if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                VerificationResult = TNumericalChecks.IsInRange(ARow.ArrivalHour, 0, 24,
                    Catalog.GetString("Arrival Hour"),
                    AContext, ValidationColumn, ValidationControlsData.ValidationControl);

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

            // 'Arrival Minute' must be between 0 and 59
            ValidationColumn = ARow.Table.Columns[PmShortTermApplicationTable.ColumnArrivalMinuteId];

            if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                VerificationResult = TNumericalChecks.IsInRange(ARow.ArrivalMinute, 0, 59,
                    Catalog.GetString("Arrival Minute"),
                    AContext, ValidationColumn, ValidationControlsData.ValidationControl);

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

            // 'Departure Hour' must be between 0 and 24
            ValidationColumn = ARow.Table.Columns[PmShortTermApplicationTable.ColumnDepartureHourId];

            if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                VerificationResult = TNumericalChecks.IsInRange(ARow.DepartureHour, 0, 24,
                    Catalog.GetString("Departure Hour"),
                    AContext, ValidationColumn, ValidationControlsData.ValidationControl);

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

            // 'Departure Minute' must be between 0 and 59
            ValidationColumn = ARow.Table.Columns[PmShortTermApplicationTable.ColumnDepartureMinuteId];

            if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                VerificationResult = TNumericalChecks.IsInRange(ARow.DepartureMinute, 0, 59,
                    Catalog.GetString("Departure Minute"),
                    AContext, ValidationColumn, ValidationControlsData.ValidationControl);

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

            // 'Arrival Point' must not be unassignable
            ValidationColumn = ARow.Table.Columns[PmShortTermApplicationTable.ColumnArrivalPointCodeId];

            if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                PtArrivalPointTable ArrivalPointTable;
                PtArrivalPointRow ArrivalPointRow;

                VerificationResult = null;

                if ((!ARow.IsArrivalPointCodeNull())
                    && (ARow.ArrivalPointCode != String.Empty))
                {
                    ArrivalPointTable = (PtArrivalPointTable)TSharedDataCache.TMPersonnel.GetCacheablePersonnelTable(
                        TCacheablePersonTablesEnum.ArrivalDeparturePointList);
                    ArrivalPointRow = (PtArrivalPointRow)ArrivalPointTable.Rows.Find(ARow.ArrivalPointCode);

                    // 'Arrival Point' must not be unassignable
                    if ((ArrivalPointRow != null)
                        && ArrivalPointRow.UnassignableFlag
                        && (ArrivalPointRow.IsUnassignableDateNull()
                            || (ArrivalPointRow.UnassignableDate <= DateTime.Today)))
                    {
                        // if 'Contact' is unassignable then check if the value has been changed or if it is a new record
                        if (TSharedValidationHelper.IsRowAddedOrFieldModified(ARow, PmShortTermApplicationTable.GetArrivalPointCodeDBName()))
                        {
                            VerificationResult = new TScreenVerificationResult(new TVerificationResult(AContext,
                                    ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_VALUEUNASSIGNABLE_WARNING,
                                        new string[] { ValidationControlsData.ValidationControlLabel, ARow.ArrivalPointCode })),
                                ValidationColumn, ValidationControlsData.ValidationControl);
                        }
                    }
                }

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

            // 'Departure Point' must not be unassignable
            ValidationColumn = ARow.Table.Columns[PmShortTermApplicationTable.ColumnDeparturePointCodeId];

            if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                PtArrivalPointTable ArrivalPointTable;
                PtArrivalPointRow ArrivalPointRow;

                VerificationResult = null;

                if ((!ARow.IsDeparturePointCodeNull())
                    && (ARow.DeparturePointCode != String.Empty))
                {
                    ArrivalPointTable = (PtArrivalPointTable)TSharedDataCache.TMPersonnel.GetCacheablePersonnelTable(
                        TCacheablePersonTablesEnum.ArrivalDeparturePointList);
                    ArrivalPointRow = (PtArrivalPointRow)ArrivalPointTable.Rows.Find(ARow.DeparturePointCode);

                    // 'Arrival Point' must not be unassignable
                    if ((ArrivalPointRow != null)
                        && ArrivalPointRow.UnassignableFlag
                        && (ArrivalPointRow.IsUnassignableDateNull()
                            || (ArrivalPointRow.UnassignableDate <= DateTime.Today)))
                    {
                        // if 'Arrival Point' is unassignable then check if the value has been changed or if it is a new record
                        if (TSharedValidationHelper.IsRowAddedOrFieldModified(ARow, PmShortTermApplicationTable.GetDeparturePointCodeDBName()))
                        {
                            VerificationResult = new TScreenVerificationResult(new TVerificationResult(AContext,
                                    ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_VALUEUNASSIGNABLE_WARNING,
                                        new string[] { ValidationControlsData.ValidationControlLabel, ARow.DeparturePointCode })),
                                ValidationColumn, ValidationControlsData.ValidationControl);
                        }
                    }
                }

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

            //TODO: if arrival   hour == 24 then arrival   minute must be 0
            //TODO: if departure hour == 24 then departure minute must be 0

            //TODO: make sure that no other application already exists for this event and this person
        }