示例#1
0
        /// <summary>
        /// Checks the validity of a bank account number.
        /// This function checks the validity of a bank account number by performing a
        /// country-specific check on the submitted account number.
        /// If a bank partner key is submitted, this function is looking
        /// up the bank's location country - this is convenient since the calling procedure
        /// does not need to know the bank's country in this case.
        /// </summary>
        /// <param name="AAccountNumber">Account number</param>
        /// <param name="ABankCountryCode">Country code of the bank
        /// (optional - needs only to be specified if bank_partner_key_n is not submitted)</param>
        /// <param name="ABankPartnerKey">Parner key of the bank
        /// (optional - needs only to be specified if bank_country_code_c is not submitted)</param>
        /// <returns> -1 = length check failed.
        ///            0 = invalid account number
        ///            1 = valid account number
        ///            2 = probably valid - account number cannot be validated by country-specific check
        ///            3 = account number could not be validated - no country-specific check implemented
        ///            4 = Bank partner could not be found
        /// </returns>
        private int CheckAccountNumber(String AAccountNumber, String ABankCountryCode, String ABankPartnerKey)
        {
            int ReturnValue;
            long PartnerKey = -1;

            ReturnValue = 1;

            PLocationTable LocationTable;
            PPartnerLocationRow PartnerLocationRow;

            if (ABankPartnerKey.Length > 0)
            {
                try
                {
                    PartnerKey = Convert.ToInt64(ABankPartnerKey);
                }
                catch (Exception)
                {
                    ReturnValue = 4;
                    return ReturnValue;
                }
            }

            if ((ABankCountryCode.Length == 0)
                || (ABankCountryCode == "?"))
            {
                if (GetPartnerBestAddressRow(PartnerKey, situation, out PartnerLocationRow))
                {
                    LocationTable = PLocationAccess.LoadByPrimaryKey(PartnerLocationRow.SiteKey,
                        PartnerLocationRow.LocationKey,
                        situation.GetDatabaseConnection().Transaction);

                    if (LocationTable.Rows.Count > 0)
                    {
                        ABankCountryCode = ((PLocationRow)LocationTable.Rows[0]).CountryCode;
                    }
                    else
                    {
                        ReturnValue = 4;
                        return ReturnValue;
                    }
                }
                else
                {
                    ReturnValue = 4;
                    return ReturnValue;
                }
            }

            Ict.Petra.Shared.MFinance.CommonRoutines FinanceRoutines = new Ict.Petra.Shared.MFinance.CommonRoutines();
            return FinanceRoutines.CheckAccountNumber(AAccountNumber, ABankCountryCode);
        }
示例#2
0
        /// <summary>
        /// Validates the Banking Details 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="ABankingDetails">test if there is only one main account</param>
        /// <param name="ACountryCode">Country Code for ARow's corresponding Bank's country</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 ValidateBankingDetails(object AContext, PBankingDetailsRow ARow,
            PBankingDetailsTable ABankingDetails, string ACountryCode,
            ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict)
        {
            DataColumn ValidationColumn;
            TValidationControlsData ValidationControlsData;
            TVerificationResult VerificationResult = null;

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

            // 'BankKey' must be a valid BANK partner
            ValidationColumn = ARow.Table.Columns[PBankingDetailsTable.ColumnBankKeyId];

            if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                if (ARow.BankKey != 0)
                {
                    VerificationResult = IsValidPartner(
                        ARow.BankKey, new TPartnerClass[] { TPartnerClass.BANK }, false, string.Empty,
                        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.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn);
            }

            // validate that there are not multiple main accounts
            ValidationColumn = ARow.Table.Columns[PartnerEditTDSPBankingDetailsTable.ColumnMainAccountId];
            int countMainAccount = 0;

            foreach (PartnerEditTDSPBankingDetailsRow bdrow in ABankingDetails.Rows)
            {
                if (bdrow.RowState != DataRowState.Deleted)
                {
                    if (bdrow.MainAccount)
                    {
                        countMainAccount++;
                    }
                }
            }

            if (countMainAccount > 1)
            {
                // will we ever get here?
                AVerificationResultCollection.Add(
                    new TScreenVerificationResult(
                        new TVerificationResult(
                            AContext,
                            ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_BANKINGDETAILS_ONLYONEMAINACCOUNT)),
                        ((PartnerEditTDSPBankingDetailsTable)ARow.Table).ColumnMainAccount,
                        ValidationControlsData.ValidationControl
                        ));
            }

            VerificationResult = null;

            // validate the account number (if validation exists for bank's country)
            ValidationColumn = ARow.Table.Columns[PBankingDetailsTable.ColumnBankAccountNumberId];

            if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                CommonRoutines Routines = new CommonRoutines();

                if (!string.IsNullOrEmpty(ARow.BankAccountNumber) && (Routines.CheckAccountNumber(ARow.BankAccountNumber, ACountryCode) <= 0))
                {
                    VerificationResult = new TScreenVerificationResult(
                        new TVerificationResult(
                            AContext,
                            ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_ACCOUNTNUMBER_INVALID)),
                        ((PartnerEditTDSPBankingDetailsTable)ARow.Table).ColumnBankAccountNumber,
                        ValidationControlsData.ValidationControl);
                }

                AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn);
            }

            VerificationResult = null;

            // validate the IBAN (if it exists)
            ValidationColumn = ARow.Table.Columns[PBankingDetailsTable.ColumnIbanId];

            if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData))
            {
                AVerificationResultCollection.Remove(ValidationColumn);

                if (!string.IsNullOrEmpty(ARow.Iban) && (CommonRoutines.CheckIBAN(ARow.Iban, out VerificationResult) == false))
                {
                    VerificationResult = new TScreenVerificationResult(
                        new TVerificationResult(AContext, VerificationResult.ResultText, VerificationResult.ResultCode,
                            VerificationResult.ResultSeverity),
                        ValidationColumn, ValidationControlsData.ValidationControl);
                }

                AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn);
            }
        }