/// <summary> /// create PPartnerBankingDetail records for the FAMILY partner /// </summary> public static void GenerateBankDetails(XmlNode ACurrentNode, PFamilyRow AFamilyRow, PartnerEditTDS AMainDS, DataTable ABankKeys) { if (TXMLParser.HasAttribute(ACurrentNode, "bankaccount_bank")) { Int32 BankID = Convert.ToInt32(TXMLParser.GetAttribute(ACurrentNode, "bankaccount_bank")) % ABankKeys.Rows.Count; long BankPartnerKey = Convert.ToInt64(ABankKeys.Rows[BankID].ItemArray[0]); PBankingDetailsRow bankingDetailsRow = AMainDS.PBankingDetails.NewRowTyped(); bankingDetailsRow.BankingDetailsKey = (AMainDS.PBankingDetails.Rows.Count + 1) * -1; bankingDetailsRow.BankKey = BankPartnerKey; bankingDetailsRow.BankAccountNumber = TXMLParser.GetAttribute(ACurrentNode, "bankaccount_account"); bankingDetailsRow.BankingType = MPartnerConstants.BANKINGTYPE_BANKACCOUNT; bankingDetailsRow.AccountName = AFamilyRow.FirstName + " " + AFamilyRow.FamilyName; AMainDS.PBankingDetails.Rows.Add(bankingDetailsRow); PPartnerBankingDetailsRow partnerBankingRow = AMainDS.PPartnerBankingDetails.NewRowTyped(); partnerBankingRow.PartnerKey = AFamilyRow.PartnerKey; partnerBankingRow.BankingDetailsKey = bankingDetailsRow.BankingDetailsKey; AMainDS.PPartnerBankingDetails.Rows.Add(partnerBankingRow); PBankingDetailsUsageRow bankingUsageRow = AMainDS.PBankingDetailsUsage.NewRowTyped(); bankingUsageRow.BankingDetailsKey = bankingDetailsRow.BankingDetailsKey; bankingUsageRow.PartnerKey = AFamilyRow.PartnerKey; bankingUsageRow.Type = MPartnerConstants.BANKINGUSAGETYPE_MAIN; AMainDS.PBankingDetailsUsage.Rows.Add(bankingUsageRow); } }
/// <summary> /// Returns the BankingDetailsKey for the selected row in the grid. /// </summary> public int GetSelectedBankAccount() { DataRowView[] SelectedRow = clbRecords.SelectedDataRowsAsDataRowView; PBankingDetailsRow Row = (PBankingDetailsRow)SelectedRow[0].Row; return(Row.BankingDetailsKey); }
// When a bank account is edited, check if it is shared with any other partners. If it is, display a message informing the user. private void CheckIfRowIsShared(System.Object Sender, EventArgs e) { if ((FPreviouslySelectedDetailRow != LastRowChecked) && (FAccountSharedWith.Rows.Count > 0)) { string EditQuestion = ""; if (FAccountSharedWith.Rows.Count == 1) { EditQuestion = Catalog.GetString("This bank account is currently shared with the following Partner:\n"); } else if (FAccountSharedWith.Rows.Count > 1) { EditQuestion = Catalog.GetString("This bank account is currently shared with the following Partners:\n"); } for (int i = 0; i < FAccountSharedWith.Rows.Count; i++) { // do not allow more than 5 partners to be display. Otherwise message box becomes to long. if (i == 5) { int Remaining = FAccountSharedWith.Rows.Count - i; if (Remaining == 1) { EditQuestion += "\n..." + Catalog.GetString("and 1 other Partner."); } else if (Remaining > 1) { EditQuestion += "\n..." + string.Format(Catalog.GetString("and {0} other Partners."), Remaining); } break; } PPartnerRow Row = (PPartnerRow)FAccountSharedWith.Rows[i]; EditQuestion += "\n" + Row.PartnerShortName + " [" + Row.PartnerKey + "]"; } if (FAccountSharedWith.Rows.Count == 1) { EditQuestion += Catalog.GetString("\n\nChanges to the Bank Account details here will take effect on the other partner's too."); } else if (FAccountSharedWith.Rows.Count > 1) { EditQuestion += Catalog.GetString("\n\nChanges to the Bank Account details here will take effect on the other partners' too."); } MessageBox.Show(EditQuestion, Catalog.GetString("Bank Account is used by another Partner"), MessageBoxButtons.OK, MessageBoxIcon.Information); } LastRowChecked = FPreviouslySelectedDetailRow; }
public void TestDeleteBank() { DataSet ResponseDS = new PartnerEditTDS(); TVerificationResultCollection VerificationResult; String TextMessage; Boolean CanDeletePartner; PPartnerRow BankPartnerRow; TSubmitChangesResult result; Int64 PartnerKey; TPartnerEditUIConnector connector = new TPartnerEditUIConnector(); PartnerEditTDS MainDS = new PartnerEditTDS(); BankPartnerRow = TCreateTestPartnerData.CreateNewBankPartner(MainDS); result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult); Assert.AreEqual(TSubmitChangesResult.scrOK, result, "create bank record"); // check if Bank partner can be deleted (still needs to be possible at this point) CanDeletePartner = TPartnerWebConnector.CanPartnerBeDeleted(BankPartnerRow.PartnerKey, out TextMessage); if (TextMessage.Length > 0) { TLogging.Log(TextMessage); } Assert.IsTrue(CanDeletePartner); // set up details (e.g. bank account) for this Bank so deletion is not allowed PBankingDetailsTable BankingDetailsTable = new PBankingDetailsTable(); PBankingDetailsRow BankingDetailsRow = BankingDetailsTable.NewRowTyped(); BankingDetailsRow.BankKey = BankPartnerRow.PartnerKey; BankingDetailsRow.BankingType = 0; BankingDetailsRow.BankingDetailsKey = Convert.ToInt32(TSequenceWebConnector.GetNextSequence(TSequenceNames.seq_bank_details)); BankingDetailsTable.Rows.Add(BankingDetailsRow); PBankingDetailsAccess.SubmitChanges(BankingDetailsTable, DBAccess.GDBAccessObj.Transaction); // now deletion must not be possible since a bank account is set up for the bank CanDeletePartner = TPartnerWebConnector.CanPartnerBeDeleted(BankPartnerRow.PartnerKey, out TextMessage); if (TextMessage.Length > 0) { TLogging.Log(TextMessage); } Assert.IsTrue(!CanDeletePartner); // now test actual deletion of venue partner BankPartnerRow = TCreateTestPartnerData.CreateNewBankPartner(MainDS); PartnerKey = BankPartnerRow.PartnerKey; result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult); Assert.AreEqual(TSubmitChangesResult.scrOK, result, "create bank partner for deletion"); // check if Venue record is being deleted Assert.IsTrue(TPartnerWebConnector.DeletePartner(PartnerKey, out VerificationResult)); // check that Bank record is really deleted Assert.IsTrue(!TPartnerServerLookups.VerifyPartner(PartnerKey)); }
private void ShowDetailsManual(PBankingDetailsRow ARow) { if (ARow != null) { btnDelete.Enabled = true; pnlDetails.Visible = true; // set chkSavingsAccount if (ARow.BankingType == MPartnerConstants.BANKINGTYPE_SAVINGSACCOUNT) { chkSavingsAccount.Checked = true; } else { chkSavingsAccount.Checked = false; } // BankKey will be 0 for a new bank account if (ARow.BankKey == 0) { cmbBankName.SetSelectedString(""); cmbBankCode.SetSelectedString(""); } else if (FComboBoxesCreated && ((FCurrentBankRow == null) || (ARow.BankKey != FCurrentBankRow.PartnerKey))) { PartnerKeyChanged(ARow.BankKey, "", true); } } if (FPreviouslySelectedDetailRow != null) { // Find any Partners that share this bank account FAccountSharedWith = TRemote.MPartner.Partner.WebConnectors.SharedBankAccountPartners(FPreviouslySelectedDetailRow.BankingDetailsKey, FMainDS.PPartner[0].PartnerKey); } InitAccountSharedWithGrid(); // In theory, the next Method call could be done in Methods NewRowManual; however, NewRowManual runs before // the Row is actually added and this would result in the Count to be one too less, so we do the Method call here, short // of a non-existing 'AfterNewRowManual' Method.... DoRecalculateScreenParts(); }
private void ValidateDataDetailsManual(PBankingDetailsRow ARow) { if (ARow == null) { return; } TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection; if (FTaxDeductiblePercentageEnabled && chkLimitTaxDeductibility.Checked) { // validate dtpTaxDeductibleValidFrom ValidateValidFromDate(); } // obtain the bank's country code (if it exists) string CountryCode = ""; if (lblCountry.Text.Length > 8) { CountryCode = lblCountry.Text.Substring(9); } // validate bank account details TSharedPartnerValidation_Partner.ValidateBankingDetails(this, ARow, FMainDS.PBankingDetails, CountryCode, ref VerificationResultCollection, FValidationControlsDict); // extra validation if (FValidateBankingDetailsExtra) { TSharedPartnerValidation_Partner.ValidateBankingDetailsExtra(this, ARow, ref VerificationResultCollection, FValidationControlsDict); FValidateBankingDetailsExtra = false; } }
/// <summary> /// Extra Validatation for 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="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 ValidateBankingDetailsExtra(object AContext, PBankingDetailsRow ARow, 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 included ValidationColumn = ARow.Table.Columns[PBankingDetailsTable.ColumnBankKeyId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { if (ARow.BankKey == 0) { VerificationResult = new TVerificationResult(AContext, ErrorCodes.GetErrorInfo( PetraErrorCodes.ERR_BANKINGDETAILS_NO_BANK_SELECTED, new string[] { ARow.BankKey.ToString() })); VerificationResult = new TScreenVerificationResult(VerificationResult, ValidationColumn, ValidationControlsData.ValidationControl); } AVerificationResultCollection.AddAndIgnoreNullValue(VerificationResult); } VerificationResult = null; // Account Number and IBAN cannot both be empty ValidationColumn = ARow.Table.Columns[PBankingDetailsTable.ColumnBankAccountNumberId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { if (string.IsNullOrEmpty(ARow.BankAccountNumber) && string.IsNullOrEmpty(ARow.Iban)) { VerificationResult = new TScreenVerificationResult(new TVerificationResult(AContext, ErrorCodes.GetErrorInfo(PetraErrorCodes.ERR_BANKINGDETAILS_MISSING_ACCOUNTNUMBERORIBAN)), ValidationColumn, ValidationControlsData.ValidationControl); } AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } }
/// <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); } }
private static void ParseFinancialDetails(PartnerImportExportTDS AMainDS, XmlNode AFinancialDetailsNode, Int64 APartnerKey, TDBTransaction ATransaction) { if (AFinancialDetailsNode != null) { string BankAccountNumber = TYml2Xml.GetAttributeRecursive(AFinancialDetailsNode, "AccountNumber"); string BankSortCode = TYml2Xml.GetAttributeRecursive(AFinancialDetailsNode, "BankSortCode"); // do we already have a bank with this sort code? Int64 bankPartnerKey = 0; AMainDS.PBank.DefaultView.Sort = PBankTable.GetBranchCodeDBName(); int bankIndex = AMainDS.PBank.DefaultView.Find(BankSortCode); if (bankIndex != -1) { bankPartnerKey = ((PBankRow)AMainDS.PBank.DefaultView[bankIndex].Row).PartnerKey; } if (bankPartnerKey == 0) { string sqlFindBankBySortCode = String.Format("SELECT * FROM PUB_{0} WHERE {1}=?", PBankTable.GetTableDBName(), PBankTable.GetBranchCodeDBName()); OdbcParameter param = new OdbcParameter("branchcode", OdbcType.VarChar); param.Value = BankSortCode; PBankTable bank = new PBankTable(); DBAccess.GDBAccessObj.SelectDT(bank, sqlFindBankBySortCode, ATransaction, new OdbcParameter[] { param }, -1, -1); if (bank.Count > 0) { bankPartnerKey = bank[0].PartnerKey; } } if (bankPartnerKey == 0) { // create a new bank record PBankRow bankRow = AMainDS.PBank.NewRowTyped(true); bankRow.PartnerKey = TImportExportYml.NewPartnerKey; TImportExportYml.NewPartnerKey--; bankRow.BranchCode = BankSortCode; bankRow.BranchName = BankSortCode; AMainDS.PBank.Rows.Add(bankRow); bankPartnerKey = bankRow.PartnerKey; } PBankingDetailsRow bankingDetailsRow = AMainDS.PBankingDetails.NewRowTyped(true); bankingDetailsRow.BankingDetailsKey = (AMainDS.PBankingDetails.Rows.Count + 1) * -1; bankingDetailsRow.BankingType = 0; bankingDetailsRow.BankAccountNumber = BankAccountNumber; bankingDetailsRow.BankKey = bankPartnerKey; AMainDS.PBankingDetails.Rows.Add(bankingDetailsRow); PPartnerBankingDetailsRow partnerBankingDetailsRow = AMainDS.PPartnerBankingDetails.NewRowTyped(true); partnerBankingDetailsRow.PartnerKey = APartnerKey; partnerBankingDetailsRow.BankingDetailsKey = bankingDetailsRow.BankingDetailsKey; AMainDS.PPartnerBankingDetails.Rows.Add(partnerBankingDetailsRow); } }