/// <summary>
        /// Load data from db.
        /// Data is held in variable MainDS.PPartner and then MainDS.PLocation, PFamilyAccess etc...
        /// The latter is to get the additional information not present in PPartner but in dependent tables.
        /// </summary>
        /// <param name="MainDS">
        /// The Datastructure which is filled with the data from the DB.
        /// It should be empty initially.
        /// </param>
        private static void LoadDataFromDB(ref PartnerEditTDS MainDS)
        {
            TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable);

            try
            {
                PPartnerAccess.LoadAll(MainDS, Transaction);
                TLogging.LogAtLevel(TLogging.DEBUGLEVEL_TRACE, "Read Partners from Database : " + MainDS.PPartner.Rows.Count.ToString());
                TLogging.LogAtLevel(TLogging.DEBUGLEVEL_TRACE, "Now reading additional data for each Partner:");

                foreach (PPartnerRow partnerRow in MainDS.PPartner.Rows)
                {
                    long partnerKey = partnerRow.PartnerKey;
                    PLocationAccess.LoadViaPPartner(MainDS, partnerKey, Transaction);
                    PPartnerLocationAccess.LoadViaPPartner(MainDS, partnerKey, Transaction);
                    PPartnerTypeAccess.LoadViaPPartner(MainDS, partnerKey, Transaction);
                    PPersonAccess.LoadViaPPartner(MainDS, partnerKey, Transaction);
                    PFamilyAccess.LoadViaPPartner(MainDS, partnerKey, Transaction);
                    POrganisationAccess.LoadViaPPartnerPartnerKey(MainDS, partnerKey, Transaction);
                    PUnitAccess.LoadViaPPartnerPartnerKey(MainDS, partnerKey, Transaction);
                    UmUnitStructureAccess.LoadViaPUnitChildUnitKey(MainDS, partnerKey, Transaction);
                    PBankAccess.LoadViaPPartnerPartnerKey(MainDS, partnerKey, Transaction);
                }

                if (TLogging.DebugLevel >= TLogging.DEBUGLEVEL_TRACE)
                {
                    TLogging.Log("All in all:");
                    SortedList <string, int> sortedtables = new SortedList <string, int>();
                    sortedtables.Add("PLocation", MainDS.PLocation.Count);
                    sortedtables.Add("PPartnerLocation", MainDS.PPartnerLocation.Count);
                    sortedtables.Add("PPartnerType", MainDS.PPartnerType.Count);
                    sortedtables.Add("PPerson", MainDS.PPerson.Count);
                    sortedtables.Add("PFamily", MainDS.PFamily.Count);
                    sortedtables.Add("POrganisation", MainDS.POrganisation.Count);

                    foreach (KeyValuePair <string, int /*TTypedDataTable*/> pair  in sortedtables)
                    {
                        TLogging.Log(pair.Key + " : " + pair.Value.ToString());
                    }
                }
            }
            catch (Exception e)
            {
                TLogging.Log("ExportPartners: " + e.Message);
            }

            DBAccess.GDBAccessObj.RollbackTransaction();
        }
Exemple #2
0
        public static bool DeleteAllPartners(
            out TVerificationResultCollection AVerificationResult)
        {
            string ErrorMsg = String.Empty;
            TVerificationResultCollection VerificationResult = new TVerificationResultCollection();

            List <Int64> PartnersToDelete = new List <Int64>();

            TDBTransaction Transaction = new TDBTransaction();

            DBAccess.ReadTransaction(ref Transaction,
                                     delegate
            {
                PPartnerTable partners = PPartnerAccess.LoadAll(Transaction);

                foreach (PPartnerRow row in partners.Rows)
                {
                    if (row.PartnerClass == "FAMILY" || row.PartnerClass == "ORGANISATION")
                    {
                        if (!TPartnerWebConnector.CanPartnerBeDeleted(row.PartnerKey, out ErrorMsg, Transaction.DataBaseObj))
                        {
                            VerificationResult.Add(new TVerificationResult("error", ErrorMsg + " " + row.PartnerKey.ToString(), TResultSeverity.Resv_Critical));
                            break;
                        }

                        PartnersToDelete.Add(row.PartnerKey);
                    }
                }
            });

            if (VerificationResult.HasCriticalErrors)
            {
                AVerificationResult = new TVerificationResultCollection(VerificationResult);
                return(false);
            }

            Transaction = new TDBTransaction();
            bool Submit = false;

            DBAccess.WriteTransaction(ref Transaction,
                                      ref Submit,
                                      delegate
            {
                foreach (Int64 PartnerKey in PartnersToDelete)
                {
                    if (!TPartnerWebConnector.DeletePartner(PartnerKey, out VerificationResult, Transaction.DataBaseObj))
                    {
                        break;
                    }
                }

                if (!VerificationResult.HasCriticalErrors)
                {
                    Submit = true;
                }
            });

            if (VerificationResult.HasCriticalErrors)
            {
                AVerificationResult = new TVerificationResultCollection(VerificationResult);
                return(false);
            }

            AVerificationResult = new TVerificationResultCollection();
            return(true);
        }