public static PPartnerTable SharedBankAccountPartners(int ABankingDetailsKey, long APartnerKey)
        {
            PPartnerTable PartnerTable = new PPartnerTable();

            TDBTransaction Transaction = null;

            DBAccess.GDBAccessObj.BeginAutoReadTransaction(IsolationLevel.ReadCommitted,
                                                           ref Transaction,
                                                           delegate
            {
                PPartnerBankingDetailsTable PartnerBankingDetailsTable = PPartnerBankingDetailsAccess.LoadViaPBankingDetails(ABankingDetailsKey,
                                                                                                                             Transaction);

                foreach (PPartnerBankingDetailsRow Row in PartnerBankingDetailsTable.Rows)
                {
                    // if record exists with a different partner key then the Bank Account is shared
                    if (Row.PartnerKey != APartnerKey)
                    {
                        PPartnerRow PartnerRow = (PPartnerRow)PPartnerAccess.LoadByPrimaryKey(Row.PartnerKey, Transaction).Rows[0];

                        PPartnerRow NewRow      = PartnerTable.NewRowTyped(false);
                        NewRow.PartnerKey       = Row.PartnerKey;
                        NewRow.PartnerShortName = PartnerRow.PartnerShortName;
                        PartnerTable.Rows.Add(NewRow);
                    }
                }
            });

            return(PartnerTable);
        }
Ejemplo n.º 2
0
        public static bool NeedMainBankAccount(long AFromPartnerKey, long AToPartnerKey)
        {
            TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted);

            try
            {
                PPartnerBankingDetailsTable FromBankingDetailsTable = PPartnerBankingDetailsAccess.LoadViaPPartner(AFromPartnerKey, Transaction);
                PPartnerBankingDetailsTable ToBankingDetailsTable   = PPartnerBankingDetailsAccess.LoadViaPPartner(AToPartnerKey, Transaction);

                int MainBankAccounts = 0;
                int FromBankAccounts = FromBankingDetailsTable.Rows.Count;
                int ToBankAccounts   = ToBankingDetailsTable.Rows.Count;

                if (FromBankAccounts > 0)
                {
                    foreach (DataRow Row in FromBankingDetailsTable.Rows)
                    {
                        PPartnerBankingDetailsRow FromRow = (PPartnerBankingDetailsRow)Row;

                        if (PBankingDetailsUsageAccess.Exists(AFromPartnerKey, FromRow.BankingDetailsKey, "MAIN", Transaction))
                        {
                            MainBankAccounts += 1;
                        }
                    }
                }

                if (ToBankAccounts > 0)
                {
                    foreach (DataRow Row in ToBankingDetailsTable.Rows)
                    {
                        PPartnerBankingDetailsRow FromRow = (PPartnerBankingDetailsRow)Row;

                        if (PBankingDetailsUsageAccess.Exists(AToPartnerKey, FromRow.BankingDetailsKey, "MAIN", Transaction))
                        {
                            MainBankAccounts += 1;
                        }
                    }
                }

                // if the merged Partner will have more than one bank account and either 0 or 2 of the bank accounts are 'Main' accounts
                // then a new 'Main' account needs to be selected
                if (((FromBankAccounts + ToBankAccounts) > 1) && (MainBankAccounts != 1))
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                TLogging.Log(e.ToString());
            }
            finally
            {
                DBAccess.GDBAccessObj.RollbackTransaction();
                TLogging.LogAtLevel(7, "TMergePartnersWebConnector.OrganisationIsFoundation: rollback own transaction.");
            }

            return(false);
        }
Ejemplo n.º 3
0
        public static bool NeedMainBankAccount(long AFromPartnerKey, long AToPartnerKey)
        {
            bool           ReturnValue = false;
            TDBTransaction Transaction = null;

            DBAccess.GDBAccessObj.BeginAutoReadTransaction(IsolationLevel.ReadCommitted,
                                                           ref Transaction,
                                                           delegate
            {
                PPartnerBankingDetailsTable FromBankingDetailsTable = PPartnerBankingDetailsAccess.LoadViaPPartner(AFromPartnerKey, Transaction);
                PPartnerBankingDetailsTable ToBankingDetailsTable   = PPartnerBankingDetailsAccess.LoadViaPPartner(AToPartnerKey, Transaction);

                int MainBankAccounts = 0;
                int FromBankAccounts = FromBankingDetailsTable.Rows.Count;
                int ToBankAccounts   = ToBankingDetailsTable.Rows.Count;

                if (FromBankAccounts > 0)
                {
                    foreach (DataRow Row in FromBankingDetailsTable.Rows)
                    {
                        PPartnerBankingDetailsRow FromRow = (PPartnerBankingDetailsRow)Row;

                        if (PBankingDetailsUsageAccess.Exists(AFromPartnerKey, FromRow.BankingDetailsKey, "MAIN", Transaction))
                        {
                            MainBankAccounts += 1;
                        }
                    }
                }

                if (ToBankAccounts > 0)
                {
                    foreach (DataRow Row in ToBankingDetailsTable.Rows)
                    {
                        PPartnerBankingDetailsRow FromRow = (PPartnerBankingDetailsRow)Row;

                        if (PBankingDetailsUsageAccess.Exists(AToPartnerKey, FromRow.BankingDetailsKey, "MAIN", Transaction))
                        {
                            MainBankAccounts += 1;
                        }
                    }
                }

                // if the merged Partner will have more than one bank account and either 0 or 2 of the bank accounts are 'Main' accounts
                // then a new 'Main' account needs to be selected
                if (((FromBankAccounts + ToBankAccounts) > 1) && (MainBankAccounts != 1))
                {
                    ReturnValue = true;
                }
            });

            return(ReturnValue);
        }
        public static PPartnerTable SharedBankAccountPartners(int ABankingDetailsKey, long APartnerKey)
        {
            TDBTransaction ReadTransaction;
            Boolean        NewTransaction;

            PPartnerTable PartnerTable = new PPartnerTable();

            ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted,
                                                                                TEnforceIsolationLevel.eilMinimum, out NewTransaction);
            try
            {
                PPartnerBankingDetailsTable PartnerBankingDetailsTable = PPartnerBankingDetailsAccess.LoadViaPBankingDetails(ABankingDetailsKey,
                                                                                                                             ReadTransaction);

                foreach (PPartnerBankingDetailsRow Row in PartnerBankingDetailsTable.Rows)
                {
                    // if record exists with a different partner key then the Bank Account is shared
                    if (Row.PartnerKey != APartnerKey)
                    {
                        PPartnerRow PartnerRow = (PPartnerRow)PPartnerAccess.LoadByPrimaryKey(Row.PartnerKey, ReadTransaction).Rows[0];

                        PPartnerRow NewRow = PartnerTable.NewRowTyped(false);
                        NewRow.PartnerKey       = Row.PartnerKey;
                        NewRow.PartnerShortName = PartnerRow.PartnerShortName;
                        PartnerTable.Rows.Add(NewRow);
                    }
                }
            }
            finally
            {
                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.CommitTransaction();
                    TLogging.LogAtLevel(7, "TPartnerDataReaderWebConnector.IsBankingDetailsRowShared: committed own transaction.");
                }
            }

            return(PartnerTable);
        }
Ejemplo n.º 5
0
        private static void FindDonorKeysByBankAccount(BankImportTDS AMainDS)
        {
            if (AMainDS.PBankingDetails.Rows.Count == 0)
            {
                // First collect all IBANs in this statement
                List <string> IBANs = new List <string>();
                foreach (BankImportTDSAEpTransactionRow transaction in AMainDS.AEpTransaction.Rows)
                {
                    if (transaction.Iban.Length > 0)
                    {
                        IBANs.Add(transaction.Iban);
                    }
                }

                // load all banking details by IBAN into AMainDS
                if (IBANs.Count > 0)
                {
                    string sql = "SELECT " + PPartnerBankingDetailsTable.GetPartnerKeyDBName() + " as PartnerKey, " +
                                 "bd.* " +
                                 "FROM " + PBankingDetailsTable.GetTableDBName() + " bd, " + PPartnerBankingDetailsTable.GetTableDBName() + " pbd " +
                                 "WHERE pbd." + PPartnerBankingDetailsTable.GetBankingDetailsKeyDBName() + " = bd." + PBankingDetailsTable.GetBankingDetailsKeyDBName() + " " +
                                 "AND " + BankImportTDSPBankingDetailsTable.GetIbanDBName() + " IN (";

                    List <OdbcParameter> parameters = new List <OdbcParameter>();

                    foreach (string iban in IBANs)
                    {
                        if (parameters.Count > 0)
                        {
                            sql += ",";
                        }
                        sql += "?";
                        OdbcParameter p = new OdbcParameter("IBAN" + parameters.Count.ToString(), OdbcType.VarChar);
                        p.Value = iban;
                        parameters.Add(p);
                    }

                    sql += ")";

                    TDataBase      db          = DBAccess.Connect("FindDonorKeysByBankAccount");
                    TDBTransaction transaction = db.BeginTransaction(IsolationLevel.ReadUncommitted);

                    db.SelectDT(AMainDS.PBankingDetails, sql, transaction, parameters.ToArray());

                    transaction.Rollback();
                    db.CloseDBConnection();
                }
            }

            AMainDS.PBankingDetails.DefaultView.Sort = BankImportTDSPBankingDetailsTable.GetIbanDBName();

            foreach (BankImportTDSAEpTransactionRow transaction in AMainDS.AEpTransaction.Rows)
            {
                // find the donor for this transaction, by his IBAN number
                Int64 DonorKey = GetDonorByIBAN(AMainDS, transaction.Iban);

                if (transaction.Iban.Length == 0)
                {
                    // useful for NUnit testing for csv import: partnerkey in description
                    try
                    {
                        DonorKey = Convert.ToInt64(transaction.Description);
                    }
                    catch (Exception)
                    {
                        DonorKey = -1;
                    }
                }

                transaction.DonorKey = DonorKey;
            }
        }