コード例 #1
0
        public static string FormatHtmlReceipt(
            String ADonorShortName,
            Int64 ADonorKey,
            TPartnerClass ADonorClass,
            String AGiftCurrency,
            string ALocalCountryCode,
            AGiftTable AGiftsThisDonor,
            string AHTMLTemplateFilename,
            TDBTransaction ATransaction)
        {
            SortedList <string, List <string> > FormValues = new SortedList <string, List <string> >();

            // These are the fields that can be printed in the letter:
            FormValues.Add("AdresseeShortName", new List <string>());
            FormValues.Add("AdresseeTitle", new List <string>());
            FormValues.Add("AdresseeFirstName", new List <string>());
            FormValues.Add("AdresseeFamilyName", new List <string>());
            FormValues.Add("AdresseeStreetAddress", new List <string>());
            FormValues.Add("AdresseeAddress3", new List <string>());
            FormValues.Add("AdresseeCity", new List <string>());
            FormValues.Add("AdresseePostCode", new List <string>());
            FormValues.Add("AdresseeCountry", new List <string>());
            FormValues.Add("FormattedAddress", new List <string>());

            FormValues.Add("DateToday", new List <string>());

            FormValues.Add("DateEntered", new List <string>());
            FormValues.Add("GiftAmount", new List <string>());
            FormValues.Add("GiftCurrency", new List <string>());
            FormValues.Add("GiftTxd", new List <string>());
            FormValues.Add("RecipientShortName", new List <string>());
            FormValues.Add("MotivationDetail", new List <string>());
            FormValues.Add("Reference", new List <string>());
            FormValues.Add("DonorComment", new List <string>());

            FormValues.Add("GiftTotalAmount", new List <string>());
            FormValues.Add("GiftTotalCurrency", new List <string>());
            FormValues.Add("TxdTotal", new List <string>());
            FormValues.Add("NonTxdTotal", new List <string>());


            // Donor Name:
            FormValues["AdresseeShortName"].Add(ADonorShortName);

            if (ADonorClass == TPartnerClass.PERSON)
            {
                PPersonTable Tbl = PPersonAccess.LoadByPrimaryKey(ADonorKey, ATransaction);

                if (Tbl.Rows.Count > 0)
                {
                    FormValues["AdresseeTitle"].Add(Tbl[0].Title);
                    FormValues["AdresseeFirstName"].Add(Tbl[0].FirstName);
                    FormValues["AdresseeFamilyName"].Add(Tbl[0].FamilyName);
                }
            }
            else if (ADonorClass == TPartnerClass.FAMILY)
            {
                PFamilyTable Tbl = PFamilyAccess.LoadByPrimaryKey(ADonorKey, ATransaction);

                if (Tbl.Rows.Count > 0)
                {
                    FormValues["AdresseeTitle"].Add(Tbl[0].Title);
                    FormValues["AdresseeFirstName"].Add(Tbl[0].FirstName);
                    FormValues["AdresseeFamilyName"].Add(Tbl[0].FamilyName);
                }
            }
            else
            {
                FormValues["AdresseeFamilyName"].Add(ADonorShortName);
            }

            FormValues["DateToday"].Add(DateTime.Now.ToString("dd MMMM yyyy"));

            // Donor Adress:
            PLocationTable        Location;
            PPartnerLocationTable PartnerLocation;
            string CountryName;
            string EmailAddress;

            if (TAddressTools.GetBestAddress(ADonorKey, out Location, out PartnerLocation, out CountryName, out EmailAddress, ATransaction))
            {
                PLocationRow LocRow = Location[0];
                FormValues["AdresseeStreetAddress"].Add(LocRow.StreetName);
                FormValues["AdresseeAddress3"].Add(LocRow.Address3);
                FormValues["AdresseeCity"].Add(LocRow.City);
                FormValues["AdresseePostCode"].Add(LocRow.PostalCode);

                if (LocRow.CountryCode != ALocalCountryCode)  // Don't add the Donor's country if it's also my country:
                {
                    FormValues["AdresseeCountry"].Add(CountryName);
                }
                else
                {
                    LocRow.CountryCode = "";
                }

                FormValues["FormattedAddress"].Add(Calculations.DetermineLocationString(LocRow,
                                                                                        Calculations.TPartnerLocationFormatEnum.plfHtmlLineBreak));
            }

            decimal GiftTotal   = 0;
            decimal TxdTotal    = 0;
            decimal NonTxdTotal = 0;

            // Details per gift:
            foreach (AGiftRow GiftRow in AGiftsThisDonor.Rows)
            {
                String           DateEntered   = GiftRow.DateEntered.ToString("dd MMM yyyy");
                String           GiftReference = GiftRow.Reference;
                AGiftDetailTable DetailTbl     = AGiftDetailAccess.LoadViaAGift(
                    GiftRow.LedgerNumber, GiftRow.BatchNumber, GiftRow.GiftTransactionNumber, ATransaction);

                foreach (AGiftDetailRow DetailRow in DetailTbl.Rows)
                {
                    FormValues["Reference"].Add(GiftReference);
                    FormValues["DateEntered"].Add(DateEntered);
                    GiftReference = "";                         // Date and Reference are one-per-gift, not per detail
                    DateEntered   = "";                         // so if this gift has several details, I'll blank the subsequent lines.

                    string DonorComment = "";
                    FormValues["GiftAmount"].Add(StringHelper.FormatUsingCurrencyCode(DetailRow.GiftTransactionAmount, AGiftCurrency));
                    FormValues["GiftCurrency"].Add(AGiftCurrency);
                    FormValues["MotivationDetail"].Add(DetailRow.MotivationDetailCode);
                    GiftTotal += DetailRow.GiftTransactionAmount;

                    if (DetailRow.TaxDeductible)
                    {
                        FormValues["GiftTxd"].Add("Y");
                        TxdTotal += DetailRow.GiftTransactionAmount;
                    }
                    else
                    {
                        FormValues["GiftTxd"].Add(" ");
                        NonTxdTotal += DetailRow.GiftTransactionAmount;
                    }

                    // Recipient Short Name:
                    PPartnerTable RecipientTbl = PPartnerAccess.LoadByPrimaryKey(DetailRow.RecipientKey, ATransaction);

                    if (RecipientTbl.Rows.Count > 0)
                    {
                        String ShortName = Calculations.FormatShortName(RecipientTbl[0].PartnerShortName, eShortNameFormat.eReverseShortname);
                        FormValues["RecipientShortName"].Add(ShortName);
                    }

                    if (DetailRow.CommentOneType == "Donor")
                    {
                        DonorComment += DetailRow.GiftCommentOne;
                    }

                    if (DetailRow.CommentTwoType == "Donor")
                    {
                        if (DonorComment != "")
                        {
                            DonorComment += "\r\n";
                        }

                        DonorComment += DetailRow.GiftCommentTwo;
                    }

                    if (DetailRow.CommentThreeType == "Donor")
                    {
                        if (DonorComment != "")
                        {
                            DonorComment += "\r\n";
                        }

                        DonorComment += DetailRow.GiftCommentThree;
                    }

                    if (DonorComment != "")
                    {
                        DonorComment = "Comment: " + DonorComment;
                    }

                    FormValues["DonorComment"].Add(DonorComment);
                } // foreach GiftDetail
            }     // foreach Gift

            FormValues["GiftTotalAmount"].Add(StringHelper.FormatUsingCurrencyCode(GiftTotal, AGiftCurrency));
            FormValues["GiftTotalCurrency"].Add(AGiftCurrency);
            FormValues["TxdTotal"].Add(StringHelper.FormatUsingCurrencyCode(TxdTotal, AGiftCurrency));
            FormValues["NonTxdTotal"].Add(StringHelper.FormatUsingCurrencyCode(NonTxdTotal, AGiftCurrency));

            return(TFormLettersTools.PrintSimpleHTMLLetter(AHTMLTemplateFilename, FormValues));
        }
コード例 #2
0
        public static Boolean MergedPartnerDetails(Int64 AMergedPartnerPartnerKey,
                                                   out String AMergedPartnerPartnerShortName,
                                                   out TPartnerClass AMergedPartnerPartnerClass,
                                                   out Int64 AMergedIntoPartnerKey,
                                                   out String AMergedIntoPartnerShortName,
                                                   out TPartnerClass AMergedIntoPartnerClass,
                                                   out String AMergedBy,
                                                   out DateTime AMergeDate)
        {
            TDBTransaction     ReadTransaction;
            Boolean            NewTransaction;
            StringCollection   RequiredColumns;
            PPartnerTable      MergedPartnerTable;
            PPartnerTable      PartnerMergedIntoTable;
            PPartnerMergeTable PartnerMergeTable;
            Boolean            ReturnValue = false;

            // Initialise out Arguments
            AMergedPartnerPartnerShortName = "";
            AMergedPartnerPartnerClass     = TPartnerClass.FAMILY; // Default. This is not really correct but the best compromise if PartnerKey is 0 or Partner isn't found since we have an enum here.
            AMergedIntoPartnerKey          = -1;
            AMergedIntoPartnerShortName    = "";
            AMergedIntoPartnerClass        = TPartnerClass.FAMILY; // Default. This is not really correct but the best compromise if PartnerKey is 0 or Partner isn't found since we have an enum here.
            AMergedBy  = "";
            AMergeDate = DateTime.MinValue;

            if (AMergedPartnerPartnerKey != 0)
            {
                /*
                 * First we look up the Partner that was Merged to get some details of it.
                 */

                // only some fields are needed
                RequiredColumns = new StringCollection();
                RequiredColumns.Add(PPartnerTable.GetPartnerShortNameDBName());
                RequiredColumns.Add(PPartnerTable.GetStatusCodeDBName());
                RequiredColumns.Add(PPartnerTable.GetPartnerClassDBName());

                ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted,
                                                                                    TEnforceIsolationLevel.eilMinimum,
                                                                                    out NewTransaction);

                try
                {
                    MergedPartnerTable = PPartnerAccess.LoadByPrimaryKey(
                        AMergedPartnerPartnerKey, RequiredColumns, ReadTransaction, null, 0, 0);

                    if (MergedPartnerTable.Rows.Count == 0)
                    {
                        ReturnValue = false;
                    }
                    else
                    {
                        if (SharedTypes.StdPartnerStatusCodeStringToEnum(
                                MergedPartnerTable[0].StatusCode) != TStdPartnerStatusCode.spscMERGED)
                        {
                            ReturnValue = false;
                        }
                        else
                        {
                            AMergedPartnerPartnerShortName = MergedPartnerTable[0].PartnerShortName;
                            AMergedPartnerPartnerClass     = SharedTypes.PartnerClassStringToEnum(MergedPartnerTable[0].PartnerClass);

                            /*
                             * Now we look up the Partner that was Merged in the PartnerMerge DB Table
                             * to get the information about the Merged-Into Partner.
                             */
                            PartnerMergeTable = PPartnerMergeAccess.LoadByPrimaryKey(AMergedPartnerPartnerKey, ReadTransaction);

                            if (PartnerMergeTable.Rows.Count == 0)
                            {
                                /*
                                 * Although we didn't find the Merged Partner in the PartnerMerge
                                 * DB Table it is still a valid, Merged Partner, so we return true
                                 * in this case.
                                 */
                                ReturnValue = true;
                            }
                            else
                            {
                                /*
                                 * Now we look up the Merged-Into Partner to get some details of it.
                                 */
                                PartnerMergedIntoTable = PPartnerAccess.LoadByPrimaryKey(
                                    PartnerMergeTable[0].MergeTo, RequiredColumns,
                                    ReadTransaction, null, 0, 0);

                                if (PartnerMergedIntoTable.Rows.Count == 0)
                                {
                                    ReturnValue = false;
                                }
                                else
                                {
                                    AMergedIntoPartnerKey       = PartnerMergeTable[0].MergeTo;
                                    AMergedBy                   = PartnerMergeTable[0].MergedBy;
                                    AMergeDate                  = PartnerMergeTable[0].MergeDate.Value;
                                    AMergedIntoPartnerShortName = PartnerMergedIntoTable[0].PartnerShortName;
                                    AMergedIntoPartnerClass     = SharedTypes.PartnerClassStringToEnum(PartnerMergedIntoTable[0].PartnerClass);

                                    ReturnValue = true;
                                }
                            }
                        }
                    }
                }
                finally
                {
                    if (NewTransaction)
                    {
                        DBAccess.GDBAccessObj.CommitTransaction();
                        TLogging.LogAtLevel(7, "TPartnerServerLookups.MergedPartnerDetails: committed own transaction.");
                    }
                }
            }

            return(ReturnValue);
        }
コード例 #3
0
        public static Boolean GetRecentlyUsedPartners(int AMaxPartnersCount,
                                                      ArrayList APartnerClasses,
                                                      out Dictionary <long, string> ARecentlyUsedPartners)
        {
            TDBTransaction ReadTransaction;
            Boolean        NewTransaction;

            ARecentlyUsedPartners = new Dictionary <long, string>();

            TLogging.LogAtLevel(9, "TPartnerServerLookups.GetRecentlyUsedPartner called!");

            PRecentPartnersTable RecentPartnersDT = new PRecentPartnersTable();

            ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted,
                                                                                TEnforceIsolationLevel.eilMinimum,
                                                                                out NewTransaction);

            // Load the recently used partners from this user
            try
            {
                RecentPartnersDT = PRecentPartnersAccess.LoadViaSUser(UserInfo.GUserInfo.UserID, ReadTransaction);
            }
            finally
            {
                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.CommitTransaction();
                    TLogging.LogAtLevel(7, "TPartnerServerLookups.GetRecentUsedPartners: committed own transaction.");
                }
            }

            PPartnerTable PartnerDT = new PPartnerTable();

            // Sort the users by date and time they have been last used

            System.Data.DataRow[] RecentPartnerRows = RecentPartnersDT.Select("",
                                                                              TTypedDataTable.GetLabel(PRecentPartnersTable.TableId, PRecentPartnersTable.ColumnwhenDateId) + " DESC, " +
                                                                              TTypedDataTable.GetLabel(PRecentPartnersTable.TableId, PRecentPartnersTable.ColumnwhenTimeId) + " DESC");

            for (int Counter = 0; Counter < RecentPartnersDT.Rows.Count; ++Counter)
            {
                PRecentPartnersRow RecentPartnerRow = (PRecentPartnersRow)RecentPartnerRows[Counter];

                ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(
                    IsolationLevel.ReadCommitted,
                    TEnforceIsolationLevel.eilMinimum,
                    out NewTransaction);

                // Get the partner name from the recently used partner
                try
                {
                    PartnerDT = PPartnerAccess.LoadByPrimaryKey(RecentPartnerRow.PartnerKey, ReadTransaction);
                }
                finally
                {
                    if (NewTransaction)
                    {
                        DBAccess.GDBAccessObj.CommitTransaction();
                        TLogging.LogAtLevel(7, "TPartnerServerLookups.GetRecentUsedPartners: committed own transaction.");
                    }
                }

                if (PartnerDT.Rows.Count > 0)
                {
                    /* Check the partner class.
                     * If we want this partner then add it to the ARecentlyUsedPartners list
                     * otherwise skip it.
                     */

                    PPartnerRow PartnerRow = (PPartnerRow)PartnerDT.Rows[0];

                    foreach (Object CurrentPartnerClass in APartnerClasses)
                    {
                        string TmpString = CurrentPartnerClass.ToString();

                        if ((TmpString == "*") ||
                            (TmpString == PartnerRow.PartnerClass))
                        {
                            // String contains Name and type like this: J. Miller (type FAMILY)
                            ARecentlyUsedPartners.Add(PartnerRow.PartnerKey,
                                                      PartnerRow.PartnerShortName + " (type " + PartnerRow.PartnerClass + ")");
                        }
                    }
                }

                if (ARecentlyUsedPartners.Count >= AMaxPartnersCount)
                {
                    break;
                }
            }

            return(true);
        }
コード例 #4
0
        /// <summary>
        /// Retrieves data that will be shown on the 'Overview' UserControl and adds it to <paramref name="AIndividualDataDS" />.
        /// </summary>
        /// <param name="APartnerKey">PartnerKey of the Person to load data for.</param>
        /// <param name="AIndividualDataDS">Typed DataSet of Type <see cref="IndividualDataTDS" />. Needs to be instantiated already!</param>
        /// <param name="AReadTransaction">Open Database transaction.</param>
        /// <returns>void</returns>
        private static void BuildSummaryData(Int64 APartnerKey, ref IndividualDataTDS AIndividualDataDS, TDBTransaction AReadTransaction)
        {
            string StrNotAvailable = Catalog.GetString("Not Available");
            IndividualDataTDSSummaryDataTable     SummaryDT;
            IndividualDataTDSSummaryDataRow       SummaryDR;
            IndividualDataTDSMiscellaneousDataRow MiscellaneousDataDR = AIndividualDataDS.MiscellaneousData[0];
            PPersonTable           PPersonDT;
            PPersonRow             PersonDR = null;
            PmPassportDetailsTable PassportDetailsDT;
            PmStaffDataTable       PmStaffDataDT;
            PmStaffDataRow         PmStaffDataDR     = null;
            PmJobAssignmentTable   PmJobAssignmentDT = null;
            PUnitTable             PUnitDT           = null;
            PmJobAssignmentRow     PmJobAssignmentDR;
            IndividualDataTDSJobAssignmentStaffDataCombinedRow JobAssiStaffDataCombDR;
            int                       JobAssiStaffDataCombKey = 0;
            TCacheable                CommonCacheable         = new TCacheable();
            TPartnerCacheable         PartnerCacheable        = new TPartnerCacheable();
            string                    MaritalStatusDescr;
            StringCollection          PassportColumns;
            string                    Nationalities;
            PPartnerRelationshipTable PartnerRelationshipDT;
            PPartnerTable             PartnerDT;
            PPartnerRow               PartnerDR = null;
            PLocationRow              LocationDR;
            PPartnerLocationRow       PartnerLocationDR;
            string                    PhoneNumber;
            string                    EmailAddress;
            Int64                     ChurchPartnerKey;

            SummaryDT = new IndividualDataTDSSummaryDataTable();
            SummaryDR = SummaryDT.NewRowTyped(false);

            SummaryDR.PartnerKey = APartnerKey;

            #region Person Info

            PPersonDT = PPersonAccess.LoadByPrimaryKey(APartnerKey, AReadTransaction);

            if (PPersonDT.Rows.Count == 1)
            {
                PersonDR = (PPersonRow)PPersonDT.Rows[0];
            }

            if (PersonDR != null)
            {
                SummaryDR.DateOfBirth = PersonDR.DateOfBirth;
                SummaryDR.Gender      = PersonDR.Gender;

                MaritalStatusDescr = PartnerCodeHelper.GetMaritalStatusDescription(
                    @PartnerCacheable.GetCacheableTable, PersonDR.MaritalStatus);

                if (MaritalStatusDescr != String.Empty)
                {
                    MaritalStatusDescr = " - " + MaritalStatusDescr;
                }

                SummaryDR.MaritalStatus = PersonDR.MaritalStatus + MaritalStatusDescr;
            }
            else
            {
                SummaryDR.SetDateOfBirthNull();
                SummaryDR.Gender        = StrNotAvailable;
                SummaryDR.MaritalStatus = StrNotAvailable;
            }

            #region Nationalities

            PassportColumns = StringHelper.StrSplit(
                PmPassportDetailsTable.GetDateOfIssueDBName() + "," +
                PmPassportDetailsTable.GetDateOfExpirationDBName() + "," +
                PmPassportDetailsTable.GetPassportNationalityCodeDBName() + "," +
                PmPassportDetailsTable.GetMainPassportDBName(), ",");

            PassportDetailsDT = PmPassportDetailsAccess.LoadViaPPerson(APartnerKey,
                                                                       PassportColumns, AReadTransaction, null, 0, 0);

            Nationalities = Ict.Petra.Shared.MPersonnel.Calculations.DeterminePersonsNationalities(
                @CommonCacheable.GetCacheableTable, PassportDetailsDT);

            if (Nationalities != String.Empty)
            {
                SummaryDR.Nationalities = Nationalities;
            }
            else
            {
                SummaryDR.Nationalities = StrNotAvailable;
            }

            #endregion

            #region Phone and Email (from 'Best Address')

            if (TContactDetailsAggregate.GetPrimaryEmailAndPrimaryPhone(APartnerKey, out PhoneNumber, out EmailAddress))
            {
                SummaryDR.PrimaryPhoneNumber  = PhoneNumber ?? StrNotAvailable;
                SummaryDR.PrimaryEmailAddress = EmailAddress ?? StrNotAvailable;
            }
            else
            {
                SummaryDR.PrimaryPhoneNumber  = StrNotAvailable;
                SummaryDR.PrimaryEmailAddress = StrNotAvailable;
            }

            #endregion

            #endregion

            #region Commitments/Jobs

            PmStaffDataDT = PmStaffDataAccess.LoadViaPPerson(APartnerKey, AReadTransaction);
            MiscellaneousDataDR.ItemsCountCommitmentPeriods = PmStaffDataDT.Rows.Count;

            // First check if the PERSON has got any Commitments
            if (PmStaffDataDT.Rows.Count > 0)
            {
                foreach (DataRow DR in PmStaffDataDT.Rows)
                {
                    JobAssiStaffDataCombDR            = AIndividualDataDS.JobAssignmentStaffDataCombined.NewRowTyped(false);
                    JobAssiStaffDataCombDR.Key        = JobAssiStaffDataCombKey++;
                    JobAssiStaffDataCombDR.PartnerKey = APartnerKey;

                    PmStaffDataDR = (PmStaffDataRow)DR;

                    if (!(PmStaffDataDR.IsReceivingFieldNull()) &&
                        (PmStaffDataDR.ReceivingField != 0))
                    {
                        PUnitDT = PUnitAccess.LoadByPrimaryKey(PmStaffDataDR.ReceivingField, AReadTransaction);

                        JobAssiStaffDataCombDR.FieldKey  = PmStaffDataDR.ReceivingField;
                        JobAssiStaffDataCombDR.FieldName = PUnitDT[0].UnitName;
                    }
                    else
                    {
                        JobAssiStaffDataCombDR.FieldKey  = 0;
                        JobAssiStaffDataCombDR.FieldName = "[None]";
                    }

                    JobAssiStaffDataCombDR.Position = PmStaffDataDR.JobTitle;
                    JobAssiStaffDataCombDR.FromDate = PmStaffDataDR.StartOfCommitment;
                    JobAssiStaffDataCombDR.ToDate   = PmStaffDataDR.EndOfCommitment;

                    AIndividualDataDS.JobAssignmentStaffDataCombined.Rows.Add(JobAssiStaffDataCombDR);
                }
            }
            else
            {
                // The PERSON hasn't got any Commitments, therefore check if the PERSON has any Job Assignments

                PmJobAssignmentDT = PmJobAssignmentAccess.LoadViaPPartner(APartnerKey, AReadTransaction);

                if (PmJobAssignmentDT.Rows.Count > 0)
                {
                    foreach (DataRow DR in PmJobAssignmentDT.Rows)
                    {
                        JobAssiStaffDataCombDR            = AIndividualDataDS.JobAssignmentStaffDataCombined.NewRowTyped(false);
                        JobAssiStaffDataCombDR.Key        = JobAssiStaffDataCombKey++;
                        JobAssiStaffDataCombDR.PartnerKey = APartnerKey;

                        PmJobAssignmentDR = (PmJobAssignmentRow)DR;

                        if (PmJobAssignmentDR.UnitKey != 0)
                        {
                            PUnitDT = PUnitAccess.LoadByPrimaryKey(PmJobAssignmentDR.UnitKey, AReadTransaction);

                            JobAssiStaffDataCombDR.FieldKey  = PmJobAssignmentDR.UnitKey;
                            JobAssiStaffDataCombDR.FieldName = PUnitDT[0].UnitName;
                        }
                        else
                        {
                            JobAssiStaffDataCombDR.FieldKey  = 0;
                            JobAssiStaffDataCombDR.FieldName = "[None]";
                        }

                        JobAssiStaffDataCombDR.Position = PmJobAssignmentDR.PositionName;
                        JobAssiStaffDataCombDR.FromDate = PmJobAssignmentDR.FromDate;
                        JobAssiStaffDataCombDR.ToDate   = PmJobAssignmentDR.ToDate;

                        AIndividualDataDS.JobAssignmentStaffDataCombined.Rows.Add(JobAssiStaffDataCombDR);
                    }
                }
            }

            #endregion

            #region Church Info

            SummaryDR.ChurchName                           = StrNotAvailable;
            SummaryDR.ChurchAddress                        = StrNotAvailable;
            SummaryDR.ChurchPrimaryPhoneNumber             = StrNotAvailable;
            SummaryDR.ChurchPastor                         = StrNotAvailable;
            SummaryDR.ChurchPastorsPrimaryPhoneNumber      = StrNotAvailable;
            SummaryDR.NumberOfShownSupportingChurchPastors = 0;

            // Find SUPPCHURCH Relationship
            PartnerRelationshipDT = PPartnerRelationshipAccess.LoadUsingTemplate(new TSearchCriteria[] {
                new TSearchCriteria(PPartnerRelationshipTable.GetRelationKeyDBName(), APartnerKey),
                new TSearchCriteria(PPartnerRelationshipTable.GetRelationNameDBName(), "SUPPCHURCH")
            },
                                                                                 AReadTransaction);

            SummaryDR.NumberOfShownSupportingChurches = PartnerRelationshipDT.Rows.Count;

            if (PartnerRelationshipDT.Rows.Count > 0)
            {
                ChurchPartnerKey = PartnerRelationshipDT[0].PartnerKey;

                // Load Church Partner
                PartnerDT = PPartnerAccess.LoadByPrimaryKey(ChurchPartnerKey, AReadTransaction);

                if (PartnerDT.Rows.Count > 0)
                {
                    PartnerDR = PartnerDT[0];

                    // Church Name
                    if (PartnerDR.PartnerShortName != String.Empty)
                    {
                        SummaryDR.ChurchName = PartnerDR.PartnerShortName;
                    }

                    #region Church Address and Phone

                    ServerCalculations.DetermineBestAddress(PartnerRelationshipDT[0].PartnerKey, out PartnerLocationDR, out LocationDR);

                    if (LocationDR != null)
                    {
                        SummaryDR.ChurchAddress = Calculations.DetermineLocationString(LocationDR,
                                                                                       Calculations.TPartnerLocationFormatEnum.plfCommaSeparated);
                    }

                    if (TContactDetailsAggregate.GetPrimaryPhoneNumber(PartnerRelationshipDT[0].PartnerKey,
                                                                       out PhoneNumber))
                    {
                        SummaryDR.ChurchPrimaryPhoneNumber = PhoneNumber ?? StrNotAvailable;
                    }
                    else
                    {
                        SummaryDR.ChurchPrimaryPhoneNumber = StrNotAvailable;
                    }

                    #endregion

                    #region Pastor

                    // Find PASTOR Relationship
                    PartnerRelationshipDT.Rows.Clear();
                    PartnerRelationshipDT = PPartnerRelationshipAccess.LoadUsingTemplate(new TSearchCriteria[] {
                        new TSearchCriteria(PPartnerRelationshipTable.GetPartnerKeyDBName(), ChurchPartnerKey),
                        new TSearchCriteria(PPartnerRelationshipTable.GetRelationNameDBName(), "PASTOR")
                    },
                                                                                         AReadTransaction);

                    SummaryDR.NumberOfShownSupportingChurchPastors = PartnerRelationshipDT.Rows.Count;

                    if (PartnerRelationshipDT.Rows.Count > 0)
                    {
                        // Load PASTOR Partner
                        PartnerDT = PPartnerAccess.LoadByPrimaryKey(PartnerRelationshipDT[0].RelationKey, AReadTransaction);

                        if (PartnerDT.Rows.Count > 0)
                        {
                            PartnerDR = PartnerDT[0];

                            // Pastor's Name
                            if (PartnerDR.PartnerShortName != String.Empty)
                            {
                                SummaryDR.ChurchPastor = PartnerDR.PartnerShortName;
                            }

                            #region Pastor's Phone

                            if (TContactDetailsAggregate.GetPrimaryPhoneNumber(PartnerRelationshipDT[0].RelationKey,
                                                                               out PhoneNumber))
                            {
                                SummaryDR.ChurchPastorsPrimaryPhoneNumber = PhoneNumber ?? StrNotAvailable;
                            }
                            else
                            {
                                SummaryDR.ChurchPastorsPrimaryPhoneNumber = StrNotAvailable;
                            }

                            #endregion
                        }
                    }

                    #endregion
                }
            }

            #endregion

            // Add Summary DataRow to Summary DataTable
            SummaryDT.Rows.Add(SummaryDR);

            // Add Row to 'SummaryData' DataTable in Typed DataSet 'IndividualDataTDS'
            AIndividualDataDS.Merge(SummaryDT);
        }
コード例 #5
0
ファイル: Partner.Export.cs プロジェクト: merbst/openpetra
        /// <summary>
        /// Load all the data of a partner into a TDS
        /// </summary>
        public static PartnerImportExportTDS ExportPartner(Int64 APartnerKey, TPartnerClass?APartnerClass = null)
        {
            PartnerImportExportTDS MainDS = new PartnerImportExportTDS();

            TDBTransaction Transaction = null;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum,
                                                                      ref Transaction,
                                                                      delegate
            {
                PPartnerAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);

                // APartnerClass is optional but if it was not provided we need to assign to it now
                if (APartnerClass == null)
                {
                    APartnerClass = SharedTypes.PartnerClassStringToEnum(MainDS.PPartner[0].PartnerClass);
                }

                if (APartnerClass == TPartnerClass.CHURCH)
                {
                    PChurchAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                }
                else if (APartnerClass == TPartnerClass.FAMILY)
                {
                    PFamilyAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);

                    PPartnerGiftDestinationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                }
                else if (APartnerClass == TPartnerClass.PERSON)
                {
                    PPersonAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);

                    PmPersonalDataAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                    PmPassportDetailsAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
                    PmDocumentAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                    PmDocumentTypeAccess.LoadAll(MainDS, Transaction);
                    PmPersonQualificationAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
                    PmSpecialNeedAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
                    PmPastExperienceAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
                    PmPersonLanguageAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
                    PmPersonAbilityAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
                    PmStaffDataAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
                    PmJobAssignmentAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                    PmPersonEvaluationAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
                    PmPersonSkillAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);

                    PmGeneralApplicationAccess.LoadViaPPersonPartnerKey(MainDS, APartnerKey, Transaction);
                    PtApplicationTypeAccess.LoadAll(MainDS, Transaction);
                    PmShortTermApplicationAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
                    PmYearProgramApplicationAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction);
                }
                else if (APartnerClass == TPartnerClass.ORGANISATION)
                {
                    POrganisationAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                }
                else if (APartnerClass == TPartnerClass.UNIT)
                {
                    PUnitAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);

                    UmUnitStructureAccess.LoadViaPUnitChildUnitKey(MainDS, APartnerKey, Transaction);
                    UmUnitAbilityAccess.LoadViaPUnit(MainDS, APartnerKey, Transaction);
                    UmUnitLanguageAccess.LoadViaPUnit(MainDS, APartnerKey, Transaction);
                    UmUnitCostAccess.LoadViaPUnit(MainDS, APartnerKey, Transaction);
                    UmJobAccess.LoadViaPUnit(MainDS, APartnerKey, Transaction);
                    UmJobRequirementAccess.LoadViaPUnit(MainDS, APartnerKey, Transaction);
                    UmJobLanguageAccess.LoadViaPUnit(MainDS, APartnerKey, Transaction);
                    UmJobQualificationAccess.LoadViaPUnit(MainDS, APartnerKey, Transaction);
                }
                else if (APartnerClass == TPartnerClass.VENUE)
                {
                    PVenueAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);

                    PcBuildingAccess.LoadViaPVenue(MainDS, APartnerKey, Transaction);
                    PcRoomAccess.LoadViaPVenue(MainDS, APartnerKey, Transaction);
                }

                PPartnerAttributeAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);

                PLocationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                PPartnerLocationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);

                PPartnerCommentAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                PPartnerTypeAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                PPartnerInterestAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                PInterestAccess.LoadAll(MainDS, Transaction);
            });

            return(MainDS);
        }
コード例 #6
0
        /// <summary>
        /// Get the missing information of a short term application partner.
        /// This could be Passport, Date of Birth, Gender, Mother Tongue, Emergency Contact, Event, Travel information
        /// </summary>
        /// <param name="APartnerKey">Partner Key</param>
        /// <param name="AApplicationKey">Application Key</param>
        /// <param name="ARegistrationOffice">Registration Office</param>
        /// <returns>String of all the missing informations for this partner and application</returns>
        private String GetMissingInfo(Int64 APartnerKey, int AApplicationKey, Int64 ARegistrationOffice)
        {
            String MissingInfo = "";
            PmPassportDetailsTable      PassportTable;
            PPersonTable                PersonTable;
            PPartnerTable               PartnerTable;
            PPartnerRelationshipTable   PartnerRelationshipTable;
            PmShortTermApplicationTable ShortTermApplicationTable;

            // Check for passport Details
            PassportTable = PmPassportDetailsAccess.LoadViaPPerson(APartnerKey, situation.GetDatabaseConnection().Transaction);
            bool PassportDetailMissing = true;

            for (int Counter = 0; Counter < PassportTable.Rows.Count; ++Counter)
            {
                PmPassportDetailsRow row = (PmPassportDetailsRow)PassportTable.Rows[Counter];

                if (row.FullPassportName.Length > 0)
                {
                    PassportDetailMissing = false;
                }
            }

            if (PassportDetailMissing)
            {
                MissingInfo += " Passport Details,";
            }

            // Check for Date of Birth and Gender
            PersonTable = PPersonAccess.LoadByPrimaryKey(APartnerKey, situation.GetDatabaseConnection().Transaction);

            if (PassportTable.Rows.Count == 0)
            {
                MissingInfo += " Date of Birth, Gender,";
            }
            else
            {
                PPersonRow PersonRow = (PPersonRow)PersonTable.Rows[0];

                if (PersonRow.IsDateOfBirthNull())
                {
                    MissingInfo += " Date of Birth,";
                }

                if (PersonRow.Gender == "Unknown")
                {
                    MissingInfo += " Gender,";
                }
            }

            // Check for mother tongue
            PartnerTable = PPartnerAccess.LoadByPrimaryKey(APartnerKey, situation.GetDatabaseConnection().Transaction);

            if (PassportTable.Rows.Count == 0)
            {
                MissingInfo += " Mother Tongue,";
            }
            else if (((PPartnerRow)PartnerTable.Rows[0]).LanguageCode == "99")
            {
                MissingInfo += " Mother Tongue,";
            }

            // Check for partner relationship
            PartnerRelationshipTable = PPartnerRelationshipAccess.LoadViaPPartnerRelationKey(APartnerKey,
                                                                                             situation.GetDatabaseConnection().Transaction);

            bool HasEmergencyContact = false;

            for (int Counter = 0; Counter < PartnerRelationshipTable.Rows.Count; ++Counter)
            {
                PPartnerRelationshipRow Row = (PPartnerRelationshipRow)PartnerRelationshipTable.Rows[Counter];

                if (Row.PartnerKey == 0)
                {
                    continue;
                }

                if ((Row.RelationName == "PAREND") ||
                    (Row.RelationName == "GUARDIAN") ||
                    (Row.RelationName == "RELATIVE") ||
                    (Row.RelationName == "EMER-1") ||
                    (Row.RelationName == "EMER-2") ||
                    (Row.RelationName == "NOK-OTHER"))
                {
                    HasEmergencyContact = true;
                    break;
                }
            }

            if (!HasEmergencyContact)
            {
                MissingInfo += " Emergency Contact,";
            }

            // Check for Event and Travel information
            ShortTermApplicationTable = PmShortTermApplicationAccess.LoadByPrimaryKey(APartnerKey,
                                                                                      AApplicationKey, ARegistrationOffice, situation.GetDatabaseConnection().Transaction);

            bool HasEvent      = false;
            bool HasTravelInfo = false;

            for (int Counter = 0; Counter < ShortTermApplicationTable.Rows.Count; ++Counter)
            {
                PmShortTermApplicationRow Row = (PmShortTermApplicationRow)ShortTermApplicationTable.Rows[Counter];

                if (Row.ConfirmedOptionCode != "")
                {
                    HasEvent = true;
                }

                if ((!Row.IsArrivalNull()) &&
                    (!Row.IsDepartureNull()))
                {
                    HasTravelInfo = true;
                }
            }

            if (!HasEvent)
            {
                MissingInfo += " Event,";
            }

            if (!HasTravelInfo)
            {
                MissingInfo += "Travel Information,";
            }

            // remove the last ,
            if (MissingInfo.Length > 0)
            {
                MissingInfo.Remove(MissingInfo.Length - 1);
            }

            return(MissingInfo);
        }
コード例 #7
0
        public static void ExportGifts(int ALedgerNumber,
                                       string ACostCentre,
                                       string AAcctCode,
                                       string AMonthName,
                                       int APeriodNumber,
                                       DateTime APeriodStartDate,
                                       DateTime APeriodEndDate,
                                       string ACurrencySelect,
                                       int AIchNumber,
                                       DataTable AExportDataTable,
                                       TVerificationResultCollection AVerificationResult)
        {
            /* Define local variables */
            bool    FirstLoopFlag         = true;
            Int32   LastRecipKey          = 0;
            string  LastGroup             = string.Empty;
            string  LastDetail            = string.Empty;
            string  LastDetailDesc        = string.Empty;
            decimal IndividualDebitTotal  = 0;
            decimal IndividualCreditTotal = 0;

            string ExportDescription = string.Empty;
            Int32  tmpLastRecipKey   = 0;
            string tmpLastGroup      = string.Empty;
            string tmpLastDetail     = string.Empty;

            //Find and total each gift transaction

            TDBTransaction DBTransaction = null;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                                                                      TEnforceIsolationLevel.eilMinimum,
                                                                      ref DBTransaction,
                                                                      delegate
            {
                String IchNumberFilter = "";

                if (AIchNumber > 0)
                {
                    IchNumberFilter = " AND GiftDetail.a_ich_number_i = " + AIchNumber;
                }

                String Query = "SELECT " +
                               " GiftDetail.a_ledger_number_i, " +
                               " GiftDetail.a_batch_number_i, " +
                               " GiftDetail.a_gift_transaction_number_i, " +
                               " GiftDetail.a_detail_number_i, " +
                               " GiftDetail.a_gift_amount_n, " +
                               " GiftDetail.a_gift_amount_intl_n, " +
                               " GiftDetail.a_motivation_group_code_c, " +
                               " GiftDetail.a_motivation_detail_code_c, " +
                               " GiftDetail.p_recipient_key_n, " +
                               " Gift.a_gift_status_c, " +
                               " MotiviationDetail.a_motivation_detail_desc_c, " +
                               " GiftBatch.a_batch_description_c " +
                               " FROM " +
                               " public.a_gift_detail AS GiftDetail, " +
                               " public.a_gift_batch AS GiftBatch, " +
                               " public.a_motivation_detail AS MotiviationDetail, " +
                               " public.a_gift AS Gift " +
                               " WHERE " +
                               " GiftDetail.a_ledger_number_i = GiftBatch.a_ledger_number_i  " +
                               " AND GiftDetail.a_batch_number_i = GiftBatch.a_batch_number_i  " +
                               " AND GiftDetail.a_ledger_number_i = MotiviationDetail.a_ledger_number_i  " +
                               " AND GiftDetail.a_motivation_group_code_c = MotiviationDetail.a_motivation_group_code_c  " +
                               " AND GiftDetail.a_motivation_detail_code_c = MotiviationDetail.a_motivation_detail_code_c  " +
                               " AND GiftDetail.a_ledger_number_i = Gift.a_ledger_number_i  " +
                               " AND GiftDetail.a_batch_number_i = Gift.a_batch_number_i  " +
                               " AND GiftDetail.a_gift_transaction_number_i = Gift.a_gift_transaction_number_i  " +
                               " AND GiftDetail.a_ledger_number_i = " + ALedgerNumber +
                               " AND GiftDetail.a_cost_centre_code_c = '" + ACostCentre + "'" +
                               IchNumberFilter +
                               " AND GiftBatch.a_batch_status_c = '" + MFinanceConstants.BATCH_POSTED + "'" +
                               " AND GiftBatch.a_gl_effective_date_d >= " + APeriodStartDate.ToString("#yyyy-MM-dd#") +
                               " AND GiftBatch.a_gl_effective_date_d <= " + APeriodEndDate.ToString("#yyyy-MM-dd#") +
                               " AND MotiviationDetail.a_account_code_c = '" + AAcctCode + "'" +
                               " ORDER BY " +
                               " GiftDetail.p_recipient_key_n ASC, " +
                               " GiftDetail.a_motivation_group_code_c ASC, " +
                               " GiftDetail.a_motivation_detail_code_c ASC;";


                DataTable TmpTable = DBAccess.GDBAccessObj.SelectDT(Query, "table", DBTransaction);

                foreach (DataRow Row in TmpTable.Rows)
                {
                    /* Print totals etc. found for last recipient */
                    /* Only do after first loop due to last recipient key check */

                    tmpLastRecipKey = Convert.ToInt32(Row["p_recipient_key_n"]);
                    tmpLastGroup    = Row["a_motivation_group_code_c"].ToString();
                    tmpLastDetail   = Row["a_motivation_detail_code_c"].ToString();

                    if (!FirstLoopFlag &&
                        ((tmpLastRecipKey != LastRecipKey) ||
                         (tmpLastGroup != LastGroup) ||
                         (tmpLastDetail != LastDetail)
                        )
                        )
                    {
                        if ((IndividualCreditTotal != 0) ||
                            (IndividualDebitTotal != 0))
                        {
                            if (LastRecipKey != 0)
                            {
                                /* Find partner short name details */
                                PPartnerTable PartnerTable = PPartnerAccess.LoadByPrimaryKey(LastRecipKey, DBTransaction);
                                PPartnerRow PartnerRow     = (PPartnerRow)PartnerTable.Rows[0];

                                LastDetailDesc += " : " + PartnerRow.PartnerShortName;

                                ExportDescription = ALedgerNumber.ToString() + AMonthName + ":" + LastDetailDesc;
                            }
                            else
                            {
                                AMotivationGroupTable MotivationGroupTable = AMotivationGroupAccess.LoadByPrimaryKey(ALedgerNumber,
                                                                                                                     LastGroup,
                                                                                                                     DBTransaction);
                                AMotivationGroupRow MotivationGroupRow = (AMotivationGroupRow)MotivationGroupTable.Rows[0];

                                ExportDescription = ALedgerNumber.ToString() + AMonthName + ":" +
                                                    MotivationGroupRow.MotivationGroupDescription.TrimEnd(
                                    new Char[] { (' ') }) + "," + LastDetailDesc;
                            }

                            //Add data to export table
                            DataRow DR = (DataRow)AExportDataTable.NewRow();

                            DR[0] = ACostCentre;
                            DR[1] = ConvertAccount(AAcctCode);
                            DR[2] = ExportDescription;
                            DR[3] = "ICH-" + APeriodNumber.ToString("00");
                            DR[4] = APeriodEndDate;
                            DR[5] = IndividualDebitTotal;
                            DR[6] = IndividualCreditTotal;

                            AExportDataTable.Rows.Add(DR);

                            /* Reset total */
                            IndividualDebitTotal  = 0;
                            IndividualCreditTotal = 0;
                        }
                    }

                    if (ACurrencySelect == MFinanceConstants.CURRENCY_BASE)
                    {
                        Decimal GiftAmount = Convert.ToDecimal(Row["a_gift_amount_n"]);

                        if (GiftAmount < 0)
                        {
                            IndividualDebitTotal -= GiftAmount;
                        }
                        else
                        {
                            IndividualCreditTotal += GiftAmount;
                        }
                    }
                    else
                    {
                        Decimal IntlGiftAmount = Convert.ToDecimal(Row["a_gift_amount_intl_n"]);

                        if (IntlGiftAmount < 0)
                        {
                            IndividualDebitTotal -= IntlGiftAmount;
                        }
                        else
                        {
                            IndividualCreditTotal += IntlGiftAmount;
                        }
                    }

                    /* Set loop variables */
                    LastRecipKey   = tmpLastRecipKey;
                    LastGroup      = tmpLastGroup;
                    LastDetail     = tmpLastDetail;
                    LastDetailDesc = Convert.ToString(Row["a_motivation_detail_desc_c"]);
                    FirstLoopFlag  = false;
                }     // foreach

                /* Print totals etc. found for last recipient */
                /* Only do after first loop due to last recipient key check */
                if (!FirstLoopFlag && ((IndividualCreditTotal != 0) || (IndividualDebitTotal != 0)))
                {
                    if (LastRecipKey != 0)
                    {
                        /* Find partner short name details */
                        PPartnerTable PartnerTable = PPartnerAccess.LoadByPrimaryKey(LastRecipKey, DBTransaction);
                        PPartnerRow PartnerRow     = (PPartnerRow)PartnerTable.Rows[0];

                        LastDetailDesc += ":" + PartnerRow.PartnerShortName;

                        ExportDescription = ALedgerNumber.ToString() + AMonthName + ":" + LastDetailDesc;
                    }
                    else
                    {
                        AMotivationGroupTable MotivationGroupTable =
                            AMotivationGroupAccess.LoadByPrimaryKey(ALedgerNumber, LastGroup, DBTransaction);
                        AMotivationGroupRow MotivationGroupRow = (AMotivationGroupRow)MotivationGroupTable.Rows[0];


                        ExportDescription = ALedgerNumber.ToString() + AMonthName + ":" +
                                            MotivationGroupRow.MotivationGroupDescription.TrimEnd() + "," + LastDetailDesc;
                    }

                    //Add rows to export table
                    DataRow DR = (DataRow)AExportDataTable.NewRow();

                    DR[0] = ACostCentre;
                    DR[1] = ConvertAccount(AAcctCode);
                    DR[2] = ExportDescription;
                    DR[3] = "ICH-" + APeriodNumber.ToString("00");
                    DR[4] = APeriodEndDate;;
                    DR[5] = IndividualDebitTotal;
                    DR[6] = IndividualCreditTotal;

                    AExportDataTable.Rows.Add(DR);
                }
            });     // Get NewOrExisting AutoReadTransaction
        } // Export Gifts
コード例 #8
0
        public static Boolean GetMotivationGroupAndDetail(Int64 APartnerKey,
                                                          ref String AMotivationGroup,
                                                          ref String AMotivationDetail)
        {
            Boolean PartnerKeyIsValid = false;

            if (APartnerKey != 0)
            {
                AMotivationGroup = MFinanceConstants.MOTIVATION_GROUP_GIFT;

                string MotivationDetail = AMotivationDetail;

                TDBTransaction readTransaction = null;
                DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                                                                          TEnforceIsolationLevel.eilMinimum,
                                                                          ref readTransaction,
                                                                          delegate
                {
                    PPartnerTable myPPartnerTable =
                        PPartnerAccess.LoadByPrimaryKey(APartnerKey, readTransaction);

                    if (myPPartnerTable.Rows.Count == 1)
                    {
                        // Entry for partnerKey is valid
                        PartnerKeyIsValid      = true;
                        PPartnerRow partnerRow = (PPartnerRow)myPPartnerTable.Rows[0];

                        // Change motivationDetail if ColumnPartnerClass is UNIT
                        if (partnerRow.PartnerClass.Equals(MPartnerConstants.PARTNERCLASS_UNIT))
                        {
                            // AND KEY-MIN
                            PUnitTable pUnitTable =
                                PUnitAccess.LoadByPrimaryKey(APartnerKey, readTransaction);

                            if (pUnitTable.Rows.Count == 1)
                            {
                                PUnitRow unitRow = (PUnitRow)pUnitTable.Rows[0];

                                if (unitRow.UnitTypeCode.Equals(MPartnerConstants.UNIT_TYPE_KEYMIN))
                                {
                                    MotivationDetail = MFinanceConstants.GROUP_DETAIL_KEY_MIN;
                                }
                                else
                                {
                                    MotivationDetail =
                                        TSystemDefaults.GetSystemDefault(SharedConstants.SYSDEFAULT_DEFAULTFIELDMOTIVATION,
                                                                         MFinanceConstants.GROUP_DETAIL_FIELD);

                                    // if system default is empty then set to FIELD
                                    if (string.IsNullOrEmpty(MotivationDetail))
                                    {
                                        MotivationDetail = MFinanceConstants.GROUP_DETAIL_FIELD;
                                    }
                                }
                            }
                        }
                        else
                        {
                            MotivationDetail = MFinanceConstants.GROUP_DETAIL_SUPPORT;
                        }
                    }
                });

                AMotivationDetail = MotivationDetail;
            }

            return(PartnerKeyIsValid);
        }
コード例 #9
0
ファイル: Gift.gui.tools.cs プロジェクト: Kingefosa/openpetra
        public static Boolean GetMotivationGroupAndDetail(Int64 APartnerKey,
                                                          ref String AMotivationGroup,
                                                          ref String AMotivationDetail)
        {
            Boolean PartnerKeyIsValid = false;

            if (APartnerKey != 0)
            {
                string MotivationGroup  = MFinanceConstants.MOTIVATION_GROUP_GIFT;
                string MotivationDetail = AMotivationDetail;

                TDBTransaction readTransaction = null;
                DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted,
                                                                          TEnforceIsolationLevel.eilMinimum,
                                                                          ref readTransaction,
                                                                          delegate
                {
                    PPartnerTable myPPartnerTable =
                        PPartnerAccess.LoadByPrimaryKey(APartnerKey, readTransaction);

                    if (myPPartnerTable.Rows.Count == 1)
                    {
                        // Entry for partnerKey is valid
                        PartnerKeyIsValid      = true;
                        PPartnerRow partnerRow = (PPartnerRow)myPPartnerTable.Rows[0];

                        // Change motivationDetail if ColumnPartnerClass is UNIT
                        if (partnerRow.PartnerClass.Equals(MPartnerConstants.PARTNERCLASS_UNIT))
                        {
                            // AND KEY-MIN

                            bool KeyMinFound = false;

                            // first check if a motivation detail is linked to this potential key min
                            AMotivationDetailTable MotivationDetailTable = AMotivationDetailAccess.LoadViaPPartner(APartnerKey, readTransaction);

                            if ((MotivationDetailTable != null) && (MotivationDetailTable.Rows.Count > 0))
                            {
                                foreach (AMotivationDetailRow Row in MotivationDetailTable.Rows)
                                {
                                    if (Row.MotivationStatus)
                                    {
                                        MotivationGroup  = MotivationDetailTable[0].MotivationGroupCode;
                                        MotivationDetail = MotivationDetailTable[0].MotivationDetailCode;

                                        KeyMinFound = true;
                                        break;
                                    }
                                }
                            }

                            // second check to see if this is a key min
                            if (!KeyMinFound)
                            {
                                PUnitTable pUnitTable =
                                    PUnitAccess.LoadByPrimaryKey(APartnerKey, readTransaction);

                                if (pUnitTable.Rows.Count == 1)
                                {
                                    PUnitRow unitRow = (PUnitRow)pUnitTable.Rows[0];

                                    if (unitRow.UnitTypeCode.Equals(MPartnerConstants.UNIT_TYPE_KEYMIN))
                                    {
                                        MotivationDetail = MFinanceConstants.GROUP_DETAIL_KEY_MIN;
                                    }
                                    else
                                    {
                                        MotivationDetail =
                                            TSystemDefaults.GetSystemDefault(SharedConstants.SYSDEFAULT_DEFAULTFIELDMOTIVATION,
                                                                             MFinanceConstants.GROUP_DETAIL_FIELD);

                                        // if system default is empty then set to FIELD
                                        if (string.IsNullOrEmpty(MotivationDetail))
                                        {
                                            MotivationDetail = MFinanceConstants.GROUP_DETAIL_FIELD;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            MotivationDetail = MFinanceConstants.GROUP_DETAIL_SUPPORT;
                        }
                    }
                });

                AMotivationGroup  = MotivationGroup;
                AMotivationDetail = MotivationDetail;
            }

            return(PartnerKeyIsValid);
        }
コード例 #10
0
        public static void ExportGifts(int ALedgerNumber,
                                       string ACostCentre,
                                       string AAcctCode,
                                       string AMonthName,
                                       int APeriodNumber,
                                       DateTime APeriodStartDate,
                                       DateTime APeriodEndDate,
                                       string ACurrencySelect,
                                       int AIchNumber,
                                       ref DataTable AExportDataTable,
                                       ref TVerificationResultCollection AVerificationResult)
        {
            /* Define local variables */
            bool   FirstLoopFlag  = true;
            Int32  LastRecipKey   = 0;          //FORMAT "9999999999"
            string LastGroup      = string.Empty;
            string LastDetail     = string.Empty;
            string LastDetailDesc = string.Empty; //FORMAT "X(15)"
            // string CurrentYearTotals = string.Empty;
            decimal IndividualDebitTotal  = 0;    //FORMAT "->>>,>>>,>>>,>>9.99"
            decimal IndividualCreditTotal = 0;    //FORMAT "->>>,>>>,>>>,>>9.99"

            string ExportDescription = string.Empty;
            Int32  tmpLastRecipKey   = 0;
            string tmpLastGroup      = string.Empty;
            string tmpLastDetail     = string.Empty;

            //Export Gifts gi3200-1.i
            //Find and total each gift transaction
            string SQLStmt = TDataBase.ReadSqlFile("ICH.HOSAExportGiftsInner.sql");

            //Begin the transaction
            bool NewTransaction = false;

            TDBTransaction DBTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted, out NewTransaction);

            OdbcParameter parameter;

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

            parameter       = new OdbcParameter("LedgerNumber", OdbcType.Int);
            parameter.Value = ALedgerNumber;
            parameters.Add(parameter);
            parameter       = new OdbcParameter("CostCentre", OdbcType.VarChar);
            parameter.Value = ACostCentre;
            parameters.Add(parameter);
            parameter       = new OdbcParameter("ICHNumber", OdbcType.Int);
            parameter.Value = AIchNumber;
            parameters.Add(parameter);
            parameter       = new OdbcParameter("BatchStatus", OdbcType.VarChar);
            parameter.Value = MFinanceConstants.BATCH_POSTED;
            parameters.Add(parameter);
            parameter       = new OdbcParameter("StartDate", OdbcType.DateTime);
            parameter.Value = APeriodStartDate;
            parameters.Add(parameter);
            parameter       = new OdbcParameter("EndDate", OdbcType.DateTime);
            parameter.Value = APeriodEndDate;
            parameters.Add(parameter);
            parameter       = new OdbcParameter("AccountCode", OdbcType.VarChar);
            parameter.Value = AAcctCode;
            parameters.Add(parameter);

            DataTable TmpTable = DBAccess.GDBAccessObj.SelectDT(SQLStmt, "table", DBTransaction, parameters.ToArray());

            foreach (DataRow untypedTransRow in TmpTable.Rows)
            {
                /* Print totals etc. found for last recipient */
                /* Only do after first loop due to last recipient key check */

                tmpLastRecipKey = Convert.ToInt32(untypedTransRow[8]);  //a_gift_detail.p_recipient_key_n
                tmpLastGroup    = untypedTransRow[6].ToString();        //a_motivation_detail.a_motivation_group_code_c
                tmpLastDetail   = untypedTransRow[7].ToString();        //a_motivation_detail.a_motivation_detail_code_c

                if (!FirstLoopFlag &&
                    ((tmpLastRecipKey != LastRecipKey) ||
                     (tmpLastGroup != LastGroup) ||
                     (tmpLastDetail != LastDetail)
                    )
                    )
                {
                    if ((IndividualCreditTotal != 0) ||
                        (IndividualDebitTotal != 0))
                    {
                        if (LastRecipKey != 0)
                        {
                            /* Find partner short name details */
                            PPartnerTable PartnerTable = PPartnerAccess.LoadByPrimaryKey(LastRecipKey, DBTransaction);
                            PPartnerRow   PartnerRow   = (PPartnerRow)PartnerTable.Rows[0];

                            LastDetailDesc += " : " + PartnerRow.PartnerShortName;

                            ExportDescription = ALedgerNumber.ToString() + AMonthName + ":" + LastDetailDesc;
                        }
                        else
                        {
                            AMotivationGroupTable MotivationGroupTable = AMotivationGroupAccess.LoadByPrimaryKey(ALedgerNumber,
                                                                                                                 LastGroup,
                                                                                                                 DBTransaction);
                            AMotivationGroupRow MotivationGroupRow = (AMotivationGroupRow)MotivationGroupTable.Rows[0];

                            ExportDescription = ALedgerNumber.ToString() + AMonthName + ":" +
                                                MotivationGroupRow.MotivationGroupDescription.TrimEnd(new Char[] { (' ') }) + "," + LastDetailDesc;
                        }

                        //Add data to export table
                        DataRow DR = (DataRow)AExportDataTable.NewRow();

                        DR[0] = ACostCentre;
                        DR[1] = ConvertAccount(AAcctCode);
                        DR[2] = ExportDescription;
                        DR[3] = "ICH-" + APeriodNumber.ToString("00");
                        DR[4] = APeriodEndDate;
                        DR[5] = IndividualDebitTotal;
                        DR[6] = IndividualCreditTotal;

                        AExportDataTable.Rows.Add(DR);

                        /* Reset total */
                        IndividualDebitTotal  = 0;
                        IndividualCreditTotal = 0;
                    }
                }

                if (ACurrencySelect == MFinanceConstants.CURRENCY_BASE)
                {
                    Decimal GiftAmount = Convert.ToDecimal(untypedTransRow[4]);          //a_gift_detail.a_gift_amount_n

                    if (GiftAmount < 0)
                    {
                        IndividualDebitTotal -= GiftAmount;
                    }
                    else
                    {
                        IndividualCreditTotal += GiftAmount;
                    }
                }
                else
                {
                    Decimal IntlGiftAmount = Convert.ToDecimal(untypedTransRow[5]);          //a_gift_detail.a_gift_amount_intl_n

                    if (IntlGiftAmount < 0)
                    {
                        IndividualDebitTotal -= IntlGiftAmount;
                    }
                    else
                    {
                        IndividualCreditTotal += IntlGiftAmount;
                    }
                }

                /* Set loop variables */
                LastRecipKey   = tmpLastRecipKey;
                LastGroup      = tmpLastGroup;
                LastDetail     = tmpLastDetail;
                LastDetailDesc = Convert.ToString(untypedTransRow[10]);         //a_motivation_detail.a_motivation_detail_desc_c
                FirstLoopFlag  = false;
            } // foreach

            /* Print totals etc. found for last recipient */
            /* Only do after first loop due to last recipient key check */
            if (!FirstLoopFlag && ((IndividualCreditTotal != 0) || (IndividualDebitTotal != 0)))
            {
                if (LastRecipKey != 0)
                {
                    /* Find partner short name details */
                    PPartnerTable PartnerTable = PPartnerAccess.LoadByPrimaryKey(LastRecipKey, DBTransaction);
                    PPartnerRow   PartnerRow   = (PPartnerRow)PartnerTable.Rows[0];

                    LastDetailDesc += ":" + PartnerRow.PartnerShortName;

                    ExportDescription = ALedgerNumber.ToString() + AMonthName + ":" + LastDetailDesc;
                }
                else
                {
                    AMotivationGroupTable MotivationGroupTable = AMotivationGroupAccess.LoadByPrimaryKey(ALedgerNumber, LastGroup, DBTransaction);
                    AMotivationGroupRow   MotivationGroupRow   = (AMotivationGroupRow)MotivationGroupTable.Rows[0];


                    ExportDescription = ALedgerNumber.ToString() + AMonthName + ":" +
                                        MotivationGroupRow.MotivationGroupDescription.TrimEnd() + "," + LastDetailDesc;
                }

                //Add rows to export table
                DataRow DR = (DataRow)AExportDataTable.NewRow();

                DR[0] = ACostCentre;
                DR[1] = ConvertAccount(AAcctCode);
                DR[2] = ExportDescription;
                DR[3] = "ICH-" + APeriodNumber.ToString("00");
                DR[4] = APeriodEndDate;;
                DR[5] = IndividualDebitTotal;
                DR[6] = IndividualCreditTotal;

                AExportDataTable.Rows.Add(DR);
            }

            if (NewTransaction)
            {
                DBAccess.GDBAccessObj.RollbackTransaction();
            }
        }
コード例 #11
0
        public static void GenerateHOSAReports(int ALedgerNumber,
                                               int APeriodNumber,
                                               int AIchNumber,
                                               string ACurrencySelect,
                                               out TVerificationResultCollection AVerificationResult
                                               )
        {
            AVerificationResult = new TVerificationResultCollection();

            //Begin the transaction
            bool NewTransaction = false;

            TDBTransaction    DBTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted, out NewTransaction);
            ALedgerTable      ALedger       = ALedgerAccess.LoadByPrimaryKey(ALedgerNumber, DBTransaction);
            AJournalTable     AJournal      = new AJournalTable();
            ATransactionTable ATransaction  = new ATransactionTable();
            ACostCentreTable  ACostCentre   = new ACostCentreTable();

            try
            {
#if TODO
                ALedgerRow LedgerRow = PostingDS.ALedger[0];
                //Find the Ledger Name = Partner Short Name
                PPartnerTable PartnerTable = PPartnerAccess.LoadByPrimaryKey(LedgerRow.PartnerKey, DBTransaction);
                PPartnerRow   PartnerRow   = (PPartnerRow)PartnerTable.Rows[0];
                string        LedgerName   = PartnerRow.PartnerShortName;
#endif

                //
                // Load the Journals, and Transactions for this period:
                String JournalQuery = "SELECT PUB_a_journal.* FROM PUB_a_batch, PUB_a_journal WHERE " +
                                      "PUB_a_batch.a_ledger_number_i = " + ALedgerNumber +
                                      " AND PUB_a_batch.a_batch_year_i = " + ALedger[0].CurrentFinancialYear +
                                      " AND PUB_a_batch.a_batch_period_i = " + APeriodNumber +
                                      " AND PUB_a_batch.a_batch_status_c = 'Posted'" +
                                      " AND PUB_a_batch.a_ledger_number_i = PUB_a_journal.a_ledger_number_i" +
                                      " AND PUB_a_batch.a_batch_number_i = PUB_a_journal.a_batch_number_i";

                DBAccess.GDBAccessObj.SelectDT(AJournal, JournalQuery, DBTransaction);

                String TransactionQuery = "SELECT PUB_a_transaction.* FROM PUB_a_batch, PUB_a_transaction WHERE " +
                                          "PUB_a_batch.a_ledger_number_i = " + ALedgerNumber +
                                          " AND PUB_a_batch.a_batch_year_i = " + ALedger[0].CurrentFinancialYear +
                                          " AND PUB_a_batch.a_batch_period_i = " + APeriodNumber +
                                          " AND PUB_a_batch.a_batch_status_c = 'Posted'" +
                                          " AND PUB_a_batch.a_ledger_number_i = PUB_a_transaction.a_ledger_number_i" +
                                          " AND PUB_a_batch.a_batch_number_i = PUB_a_transaction.a_batch_number_i";

                DBAccess.GDBAccessObj.SelectDT(ATransaction, TransactionQuery, DBTransaction);

                String CostCentreQuery = "SELECT * FROM a_cost_centre WHERE " +
                                         ACostCentreTable.GetLedgerNumberDBName() + " = " + ALedgerNumber +
                                         " AND " + ACostCentreTable.GetPostingCostCentreFlagDBName() + " = True" +
                                         " AND " + ACostCentreTable.GetCostCentreTypeDBName() + " LIKE '" + MFinanceConstants.FOREIGN_CC_TYPE + "'" +
                                         " ORDER BY " + ACostCentreTable.GetCostCentreCodeDBName();

                DBAccess.GDBAccessObj.SelectDT(ACostCentre, CostCentreQuery, DBTransaction);

                //Iterate through the cost centres
                foreach (ACostCentreRow CostCentreRow in ACostCentre.Rows)
                {
                    bool TransactionExists = false;

                    //Iterate through the journals
                    foreach (AJournalRow JournalRow in AJournal.Rows)
                    {
                        int BatchNumber   = JournalRow.BatchNumber;
                        int JournalNumber = JournalRow.JournalNumber;

#if TODO
                        String TransFilter =
                            ATransactionTable.GetBatchNumberDBName() + " = " + BatchNumber.ToString() +
                            " AND " + ATransactionTable.GetJournalNumberDBName() + " = " + JournalNumber.ToString() +
                            " AND " + ATransactionTable.GetCostCentreCodeDBName() + " = '" + CostCentreRow.CostCentreCode + "'" +
                            " AND (" + ATransactionTable.GetIchNumberDBName() + " = 0" +
                            "      OR " + ATransactionTable.GetIchNumberDBName() + " = " + AIchNumber.ToString() +
                            ")";

                        DataRow[] FoundTransRows = BatchDS.ATransaction.Select(TransFilter);

                        foreach (DataRow untypedTransRow in FoundTransRows)
                        {
                            ATransactionRow TransactionRow = (ATransactionRow)untypedTransRow;

                            TransactionExists = true;

                            string DefaultData = ALedgerNumber.ToString() + "," +
                                                 LedgerName + "," +
                                                 APeriodNumber.ToString() + "," +
                                                 APeriodNumber.ToString() + "," +
                                                 CostCentreRow.CostCentreCode + "," +
                                                 "" + "," +
                                                 "" + "," +
                                                 "" + "," +
                                                 "A" + "," +
                                                 LedgerRow.CurrentFinancialYear.ToString() + "," +
                                                 LedgerRow.CurrentPeriod.ToString() + "," +
                                                 MFinanceConstants.MAX_PERIODS.ToString() + "," +
                                                 "h" + "," +
                                                 ACurrency + "," +
                                                 AIchNumber.ToString();

                            string ReportTitle = "Home Office Stmt of Acct: " + CostCentreRow.CostCentreName;

                            //call code for gl2120p.p Produces Account Detail, Analysis Attribute and HOSA Reprint reports.

                            /* RUN sm9000.w ("gl2120p.p",
                             *                               lv_report_title_c,
                             *                               lv_default_data_c).*/
                            //TODO: call code to produce reports
                            break;
                        }
#endif

                        if (TransactionExists)
                        {
                            //only need to run above code once for 1 transaction per cost centre code
                            break;     //goto next cost centre else try next journal
                        }
                    }
                }

                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.RollbackTransaction();
                }
            }
            catch (Exception Exp)
            {
                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.RollbackTransaction();
                }

                TLogging.Log(Exp.Message);
                TLogging.Log(Exp.StackTrace);

                throw;
            }
        }
コード例 #12
0
ファイル: Gift.gui.tools.cs プロジェクト: weiplanet/openpetra
        public static Boolean GetMotivationGroupAndDetailForPartner(Int64 APartnerKey,
                                                                    ref String AMotivationGroup,
                                                                    ref String AMotivationDetail)
        {
            Boolean PartnerKeyIsValid = false;

            if (APartnerKey != 0)
            {
                string motivationGroup  = MFinanceConstants.MOTIVATION_GROUP_GIFT;
                string motivationDetail = AMotivationDetail;

                TDBTransaction readTransaction = new TDBTransaction();
                TDataBase      db = DBAccess.Connect("GetMotivationGroupAndDetailForPartner");

                db.ReadTransaction(
                    ref readTransaction,
                    delegate
                {
                    PPartnerTable myPPartnerTable = PPartnerAccess.LoadByPrimaryKey(APartnerKey, readTransaction);

                    if (myPPartnerTable.Rows.Count == 1)
                    {
                        // partnerKey is valid
                        PartnerKeyIsValid      = true;
                        PPartnerRow partnerRow = myPPartnerTable[0];

                        // Change motivationDetail if PartnerClass is UNIT
                        if (partnerRow.PartnerClass.Equals(MPartnerConstants.PARTNERCLASS_UNIT))
                        {
                            // AND KEY-MIN
                            bool KeyMinFound = false;

                            // first check if a specific motivation detail is linked to this partner
                            AMotivationDetailTable MotivationDetailTable
                                = AMotivationDetailAccess.LoadViaPPartner(APartnerKey, readTransaction);

                            if ((MotivationDetailTable != null) && (MotivationDetailTable.Rows.Count > 0))
                            {
                                foreach (AMotivationDetailRow Row in MotivationDetailTable.Rows)
                                {
                                    if (Row.MotivationStatus)
                                    {
                                        motivationGroup  = MotivationDetailTable[0].MotivationGroupCode;
                                        motivationDetail = MotivationDetailTable[0].MotivationDetailCode;

                                        KeyMinFound = true;
                                        break;     // Go with the first entry found.
                                    }
                                }
                            }

                            if (!KeyMinFound)
                            {
                                // Is this is a key min, or a field?
                                PUnitTable pUnitTable = PUnitAccess.LoadByPrimaryKey(APartnerKey, readTransaction);

                                if (pUnitTable.Rows.Count == 1)
                                {
                                    PUnitRow unitRow = pUnitTable[0];

                                    switch (unitRow.UnitTypeCode)
                                    {
                                    case MPartnerConstants.UNIT_TYPE_AREA:
                                    case MPartnerConstants.UNIT_TYPE_FUND:
                                    case MPartnerConstants.UNIT_TYPE_FIELD:
                                        motivationDetail = MFinanceConstants.GROUP_DETAIL_FIELD;
                                        break;

                                    case MPartnerConstants.UNIT_TYPE_KEYMIN:
                                        motivationDetail = MFinanceConstants.GROUP_DETAIL_KEY_MIN;
                                        break;

                                    case MPartnerConstants.UNIT_TYPE_COUNTRY:
                                    case MPartnerConstants.UNIT_TYPE_CONFERENCE:
                                    case MPartnerConstants.UNIT_TYPE_OTHER:
                                    case MPartnerConstants.UNIT_TYPE_ROOT:
                                    case MPartnerConstants.UNIT_TYPE_TEAM:
                                    case MPartnerConstants.UNIT_TYPE_WORKING_GROUP:
                                    default:
                                        motivationDetail = MFinanceConstants.GROUP_DETAIL_SUPPORT;
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            motivationDetail = MFinanceConstants.GROUP_DETAIL_SUPPORT;
                        }
                    }
                });

                db.CloseDBConnection();

                AMotivationGroup  = motivationGroup;
                AMotivationDetail = motivationDetail;
            }

            return(PartnerKeyIsValid);
        }
コード例 #13
0
        /// <summary>
        /// First loads the extractTable needed. Goes throught all the Partners in the extract,  If the partner already has the subscription, returns all those partners back to client.  If the partner doesn't have the subscription, saves this
        /// subscription to those partners.
        /// </summary>
        /// <returns>void</returns>
        private void SubmitChangesInternal()
        {
            TDBTransaction       SubmitChangesTransaction = null;
            TSubmitChangesResult SubmissionResult         = TSubmitChangesResult.scrNothingToBeSaved;
            MExtractTable        ExtractDT;
            PSubscriptionTable   SubscriptionTable;

            PPartnerTable    PartnerTable;
            Int32            RowCounter;
            Int32            PartnersInExtract;
            StringCollection RequiredColumns;
            StringCollection RequiredColumns2;

            if (FInspectDT != null)
            {
                // Initialisations
                FVerificationResult = new TVerificationResultCollection();
                ExtractDT           = new MExtractTable();
                SubscriptionTable   = new PSubscriptionTable();
                FSubmissionDT       = SubscriptionTable.Clone();
                ((TTypedDataTable)FSubmissionDT).InitVars();
                PartnerTable    = new PPartnerTable();
                RequiredColumns = new StringCollection();
                RequiredColumns.Add(MExtractTable.GetPartnerKeyDBName());
                RequiredColumns2 = new StringCollection();
                RequiredColumns2.Add(PPartnerTable.GetPartnerKeyDBName());
                RequiredColumns2.Add(PPartnerTable.GetPartnerShortNameDBName());
                RowCounter = 0;

                // Set up asynchronous execution
                TProgressTracker.SetCurrentState(FProgressID, "Checking Partners' Subscriptions...", 0.0m);


                DBAccess.GDBAccessObj.BeginAutoTransaction(IsolationLevel.Serializable, ref SubmitChangesTransaction,
                                                           ref SubmissionResult,
                                                           delegate
                {
                    try
                    {
                        //                  TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: loading Subscriptions for ExtractID " + FExtractID.ToString() + "...");
                        ExtractDT         = MExtractAccess.LoadViaMExtractMaster(FExtractID, RequiredColumns, SubmitChangesTransaction);
                        PartnersInExtract = ExtractDT.Rows.Count;
                        //                  TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: ExtractID has " + PartnersInExtract.ToString() + " Partners.");

                        // Go throught all the Partners in the extract
                        foreach (MExtractRow ExtractRow in ExtractDT.Rows)
                        {
                            RowCounter = RowCounter + 1;

                            // Calculate how much Partners we have checked. Let all Partners be a maximum of 70%.
                            TProgressTracker.SetCurrentState(
                                FProgressID,
                                string.Empty,
                                Convert.ToInt16((((double)RowCounter / (double)PartnersInExtract) * 100) * (MAX_PERCENTAGE_CHECKS / 100.0)));
                            TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: loadbyPrimaryKey");

                            SubscriptionTable = PSubscriptionAccess.LoadByPrimaryKey(
                                FInspectDT[0].PublicationCode,
                                ExtractRow.PartnerKey,
                                SubmitChangesTransaction);

                            // if the Partner does not yet have the subscription, add the subscription to this partner.
                            if (SubscriptionTable.Rows.Count == 0)
                            {
                                TLogging.LogAtLevel(
                                    7,
                                    "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: will add Subscription to Partner with PartnerKey "
                                    +
                                    ExtractRow.PartnerKey.ToString());
                                FInspectDT[0].PartnerKey = ExtractRow.PartnerKey;
                                TLogging.LogAtLevel(7,
                                                    "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: importing Row into FSubmissionDT...");
                                FSubmissionDT.ImportRow(FInspectDT[0]);
                            }
                            else
                            {
                                // The partner already has this Subscription: add the partner to the ResponseTable
                                //                          TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: won't add Subscription to Partner with PartnerKey " + ExtractRow.PartnerKey.ToString());
                                PartnerTable = PPartnerAccess.LoadByPrimaryKey(ExtractRow.PartnerKey, RequiredColumns2, SubmitChangesTransaction);

                                if (FResponseDT == null)
                                {
                                    FResponseDT = PartnerTable.Clone();
                                }

                                FResponseDT.ImportRow(PartnerTable[0]);
                            }
                        }

                        TLogging.LogAtLevel(7,
                                            "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: Finished checking Partner's Subscriptions.");

                        if (FSubmissionDT.Rows.Count > 0)
                        {
                            // Submit the Partners with new Subscriptions to the PSubscription Table.
                            TProgressTracker.SetCurrentState(
                                FProgressID,
                                "Adding Subscriptions to " + FSubmissionDT.Rows.Count.ToString() + " Partners...",
                                MAX_PERCENTAGE_CHECKS);
                            //                      TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: " + FAsyncExecProgress.ProgressInformation);

                            PSubscriptionAccess.SubmitChanges((PSubscriptionTable)FSubmissionDT, SubmitChangesTransaction);
                        }
                        else
                        {
                            TLogging.LogAtLevel(
                                7,
                                "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: no Subscriptions were added to Partners because all the Partners in the Extract already had this Subscription.");
                        }

                        SubmissionResult = TSubmitChangesResult.scrOK;
                    }
                    catch (Exception Exp)
                    {
                        TLogging.LogAtLevel(7,
                                            "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: Exception occured, Transaction will get ROLLED BACK. Exception: "
                                            +
                                            Exp.ToString());

                        SubmissionResult = TSubmitChangesResult.scrError;
                        FSubmitResult    = SubmissionResult;
                        FSubmitException = Exp;
                        TProgressTracker.CancelJob(FProgressID);

                        return;
                    }
                });
            }

            // if no values at response table, it needs to be created. If not creates, will raise exeption at client side.
            if (FResponseDT == null)
            {
                FResponseDT = new DataTable();
            }

            TProgressTracker.FinishJob(FProgressID);
            FSubmitResult = SubmissionResult;
        }
コード例 #14
0
        private static PartnerDetails GetDonor(Int64 APartnerKey)
        {
            if (DonorList.ContainsKey(APartnerKey))
            {
                return(DonorList[APartnerKey]);
            }

            PartnerDetails Ret        = new PartnerDetails();
            PPartnerTable  PartnerTbl = PPartnerAccess.LoadByPrimaryKey(APartnerKey, FTransaction);

            if (PartnerTbl.Rows.Count > 0)
            {
                PPartnerRow PartnerRow = PartnerTbl[0];

                Ret.LastName  = PartnerRow.PartnerShortName;
                Ret.Anonymous = PartnerRow.AnonymousDonor;

                if (PartnerRow.PartnerClass == "PERSON")
                {
                    PPersonTable PersonTbl = PPersonAccess.LoadByPrimaryKey(APartnerKey, FTransaction);

                    if (PersonTbl.Rows.Count > 0)
                    {
                        PPersonRow PersonRow = PersonTbl[0];
                        Ret.FirstName = PersonRow.FirstName;
                        Ret.LastName  = PersonRow.FamilyName;
                        Ret.Class     = "PERSON";
                    }
                }

                if (PartnerRow.PartnerClass == "FAMILY")
                {
                    PFamilyTable FamilyTbl = PFamilyAccess.LoadByPrimaryKey(APartnerKey, FTransaction);

                    if (FamilyTbl.Rows.Count > 0)
                    {
                        PFamilyRow FamilyRow = FamilyTbl[0];
                        Ret.FirstName = FamilyRow.FirstName;
                        Ret.LastName  = FamilyRow.FamilyName;
                        Ret.Class     = "FAMILY";
                    }
                }

                PPartnerLocationRow PartnerLocationRow;
                TLocationPK         LocationKey = ServerCalculations.DetermineBestAddress(APartnerKey, out PartnerLocationRow);

                if (LocationKey.LocationKey != -1)
                {
                    Ret.Email     = PartnerLocationRow.EmailAddress;
                    Ret.Telephone = PartnerLocationRow.TelephoneNumber;
                    PLocationTable LocationTbl = PLocationAccess.LoadByPrimaryKey(PartnerLocationRow.SiteKey,
                                                                                  PartnerLocationRow.LocationKey,
                                                                                  FTransaction);

                    if (LocationTbl.Rows.Count > 0)
                    {
                        PLocationRow LocationRow = LocationTbl[0];
                        Ret.Address = Calculations.DetermineLocationString(LocationRow, Calculations.TPartnerLocationFormatEnum.plfCommaSeparated);
                    }
                }
            }

            DonorList.Add(APartnerKey, Ret);
            return(Ret);
        }
コード例 #15
0
ファイル: Gift.cs プロジェクト: Kingefosa/openpetra
        /// <summary>
        /// get more details of the last gift of the partner
        /// </summary>
        /// <param name="APartnerKey"></param>
        /// <param name="ALastGiftDate"></param>
        /// <param name="ALastGiftAmount"></param>
        /// <param name="ALastGiftGivenToPartnerKey"></param>
        /// <param name="ALastGiftRecipientLedger"></param>
        /// <param name="ALastGiftCurrencyCode"></param>
        /// <param name="ALastGiftDisplayFormat"></param>
        /// <param name="ALastGiftGivenToShortName"></param>
        /// <param name="ALastGiftRecipientLedgerShortName"></param>
        /// <param name="ARestrictedOrConfidentialGiftAccessDenied"></param>
        /// <returns></returns>
        public static Boolean GetLastGiftDetails(Int64 APartnerKey,
                                                 out DateTime ALastGiftDate,
                                                 out decimal ALastGiftAmount,
                                                 out Int64 ALastGiftGivenToPartnerKey,
                                                 out Int64 ALastGiftRecipientLedger,
                                                 out String ALastGiftCurrencyCode,
                                                 out String ALastGiftDisplayFormat,
                                                 out String ALastGiftGivenToShortName,
                                                 out String ALastGiftRecipientLedgerShortName,
                                                 out Boolean ARestrictedOrConfidentialGiftAccessDenied)
        {
            DataSet          LastGiftDS;
            AGiftDetailTable GiftDetailDT;
            SGroupGiftTable  GroupGiftDT;
            SUserGroupTable  UserGroupDT;
            AGiftRow         GiftDR;
            AGiftBatchRow    GiftBatchDR;
            AGiftDetailRow   GiftDetailDR;
            ACurrencyRow     CurrencyDR;
            Int16            Counter;
            Boolean          AccessToGift = false;

            DataRow[] FoundUserGroups;

            ALastGiftAmount                           = 0;
            ALastGiftCurrencyCode                     = "";
            ALastGiftDisplayFormat                    = "";
            ALastGiftDate                             = DateTime.MinValue;
            ALastGiftGivenToPartnerKey                = 0;
            ALastGiftGivenToShortName                 = "";
            ALastGiftRecipientLedger                  = 0;
            ALastGiftRecipientLedgerShortName         = "";
            ARestrictedOrConfidentialGiftAccessDenied = false;

            DateTime tmpLastGiftDate                             = ALastGiftDate;
            decimal  tmpLastGiftAmount                           = ALastGiftAmount;
            Int64    tmpLastGiftGivenToPartnerKey                = ALastGiftGivenToPartnerKey;
            Int64    tmpLastGiftRecipientLedger                  = ALastGiftRecipientLedger;
            String   tmpLastGiftCurrencyCode                     = ALastGiftCurrencyCode;
            String   tmpLastGiftDisplayFormat                    = ALastGiftDisplayFormat;
            String   tmpLastGiftGivenToShortName                 = ALastGiftGivenToShortName;
            String   tmpLastGiftRecipientLedgerShortName         = ALastGiftRecipientLedgerShortName;
            Boolean  tmpRestrictedOrConfidentialGiftAccessDenied = ARestrictedOrConfidentialGiftAccessDenied;

            if ((!UserInfo.GUserInfo.IsTableAccessOK(TTableAccessPermission.tapINQUIRE, AGiftTable.GetTableDBName())))
            {
                // User hasn't got access to a_gift Table in the DB
                return(false);
            }

            // Set up temp DataSet
            LastGiftDS = new DataSet("LastGiftDetails");
            LastGiftDS.Tables.Add(new AGiftTable());
            LastGiftDS.Tables.Add(new AGiftBatchTable());
            LastGiftDS.Tables.Add(new AGiftDetailTable());
            LastGiftDS.Tables.Add(new ACurrencyTable());
            LastGiftDS.Tables.Add(new PPartnerTable());

            TDBTransaction Transaction  = null;
            bool           SubmissionOK = true;

            // Important: The IsolationLevel here needs to correspond with the IsolationLevel in the
            // Ict.Petra.Server.MPartner.Partner.UIConnectors.TPartnerEditUIConnector.LoadData Method
            // as otherwise the attempt of taking-out of a DB Transaction here will lead to Bug #4167!
            DBAccess.GDBAccessObj.GetNewOrExistingAutoTransaction(IsolationLevel.ReadCommitted,
                                                                  TEnforceIsolationLevel.eilMinimum, ref Transaction, ref SubmissionOK,
                                                                  delegate
            {
                try
                {
                    try
                    {
                        AGiftAccess.LoadViaPPartner(LastGiftDS, APartnerKey, null, Transaction,
                                                    StringHelper.InitStrArr(new String[] { "ORDER BY", AGiftTable.GetDateEnteredDBName() + " DESC" }), 0, 1);
                    }
                    catch (ESecurityDBTableAccessDeniedException)
                    {
                        // User hasn't got access to a_gift Table in the DB
                        return;
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }

                    if (LastGiftDS.Tables[AGiftTable.GetTableName()].Rows.Count == 0)
                    {
                        // Partner hasn't given any Gift so far
                        return;
                    }

                    // Get the last gift
                    GiftDR = ((AGiftTable)LastGiftDS.Tables[AGiftTable.GetTableName()])[0];

                    if (GiftDR.Restricted)
                    {
                        AccessToGift = false;
                        GroupGiftDT  = SGroupGiftAccess.LoadViaAGift(
                            GiftDR.LedgerNumber,
                            GiftDR.BatchNumber,
                            GiftDR.GiftTransactionNumber,
                            Transaction);
                        UserGroupDT = SUserGroupAccess.LoadViaSUser(UserInfo.GUserInfo.UserID, Transaction);

                        // Loop over all rows of GroupGiftDT
                        for (Counter = 0; Counter <= GroupGiftDT.Rows.Count - 1; Counter += 1)
                        {
                            // To be able to view a Gift, ReadAccess must be granted
                            if (GroupGiftDT[Counter].ReadAccess)
                            {
                                // Find out whether the user has a row in s_user_group with the
                                // GroupID of the GroupGift row
                                FoundUserGroups =
                                    UserGroupDT.Select(SUserGroupTable.GetGroupIdDBName() + " = '" + GroupGiftDT[Counter].GroupId + "'");

                                if (FoundUserGroups.Length != 0)
                                {
                                    // Access to gift can be granted
                                    AccessToGift = true;
                                    continue;

                                    // don't evaluate further GroupGiftDT rows
                                }
                            }
                        }
                    }
                    else
                    {
                        AccessToGift = true;
                    }

                    if (AccessToGift)
                    {
                        tmpLastGiftDate = GiftDR.DateEntered;

                        // Console.WriteLine('GiftDR.LedgerNumber: ' + GiftDR.LedgerNumber.ToString + '; ' +
                        // 'GiftDR.BatchNumber:  ' + GiftDR.BatchNumber.ToString);
                        // Load Gift Batch
                        AGiftBatchAccess.LoadByPrimaryKey(LastGiftDS, GiftDR.LedgerNumber, GiftDR.BatchNumber,
                                                          StringHelper.InitStrArr(new String[] { AGiftBatchTable.GetCurrencyCodeDBName() }), Transaction, null, 0, 0);

                        if (LastGiftDS.Tables[AGiftBatchTable.GetTableName()].Rows.Count != 0)
                        {
                            GiftBatchDR             = ((AGiftBatchRow)LastGiftDS.Tables[AGiftBatchTable.GetTableName()].Rows[0]);
                            tmpLastGiftCurrencyCode = GiftBatchDR.CurrencyCode;

                            // Get Currency
                            ACurrencyAccess.LoadByPrimaryKey(LastGiftDS, GiftBatchDR.CurrencyCode, Transaction);

                            if (LastGiftDS.Tables[ACurrencyTable.GetTableName()].Rows.Count != 0)
                            {
                                CurrencyDR = (ACurrencyRow)(LastGiftDS.Tables[ACurrencyTable.GetTableName()].Rows[0]);
                                tmpLastGiftCurrencyCode  = CurrencyDR.CurrencyCode;
                                tmpLastGiftDisplayFormat = CurrencyDR.DisplayFormat;
                            }
                            else
                            {
                                tmpLastGiftCurrencyCode  = "";
                                tmpLastGiftDisplayFormat = "";
                            }
                        }
                        else
                        {
                            // missing Currency
                            tmpLastGiftCurrencyCode  = "";
                            tmpLastGiftDisplayFormat = "";
                        }

                        // Load Gift Detail
                        AGiftDetailAccess.LoadViaAGift(LastGiftDS,
                                                       GiftDR.LedgerNumber,
                                                       GiftDR.BatchNumber,
                                                       GiftDR.GiftTransactionNumber,
                                                       StringHelper.InitStrArr(new String[] { AGiftDetailTable.GetGiftTransactionAmountDBName(),
                                                                                              AGiftDetailTable.GetRecipientKeyDBName(),
                                                                                              AGiftDetailTable.
                                                                                              GetRecipientLedgerNumberDBName(),
                                                                                              AGiftDetailTable.GetConfidentialGiftFlagDBName() }),
                                                       Transaction,
                                                       null,
                                                       0,
                                                       0);
                        GiftDetailDT = (AGiftDetailTable)LastGiftDS.Tables[AGiftDetailTable.GetTableName()];

                        if (GiftDetailDT.Rows.Count != 0)
                        {
                            if (GiftDR.LastDetailNumber > 1)
                            {
                                // Gift is a Split Gift
                                tmpLastGiftAmount = 0;

                                for (Counter = 0; Counter <= GiftDetailDT.Rows.Count - 1; Counter += 1)
                                {
                                    GiftDetailDR = (AGiftDetailRow)GiftDetailDT.Rows[Counter];

                                    // Check for confidential gift and whether the current user is allowed to see it
                                    if (GiftDetailDR.ConfidentialGiftFlag)
                                    {
                                        if (!((UserInfo.GUserInfo.IsInGroup(SharedConstants.PETRAGROUP_FINANCE2)) ||
                                              (UserInfo.GUserInfo.IsInGroup(SharedConstants.PETRAGROUP_FINANCE3))))
                                        {
                                            // User isn't allowed to see the gift
                                            tmpRestrictedOrConfidentialGiftAccessDenied = true;
                                            tmpLastGiftAmount = 0;
                                            return;
                                        }
                                    }

                                    tmpLastGiftAmount = tmpLastGiftAmount + GiftDetailDR.GiftTransactionAmount;
                                }

                                tmpLastGiftGivenToShortName         = "";
                                tmpLastGiftRecipientLedgerShortName = "";
                                tmpLastGiftGivenToPartnerKey        = -1;
                                tmpLastGiftRecipientLedger          = -1;
                            }
                            else
                            {
                                // Gift isn't a Split Gift
                                GiftDetailDR = (AGiftDetailRow)GiftDetailDT.Rows[0];

                                // Check for confidential gift and whether the current user is allowed to see it
                                if (GiftDetailDR.ConfidentialGiftFlag)
                                {
                                    if (!((UserInfo.GUserInfo.IsInGroup(SharedConstants.PETRAGROUP_FINANCE2)) ||
                                          (UserInfo.GUserInfo.IsInGroup(SharedConstants.PETRAGROUP_FINANCE3))))
                                    {
                                        // User isn't allowed to see the gift
                                        tmpRestrictedOrConfidentialGiftAccessDenied = true;
                                        return;
                                    }
                                }

                                tmpLastGiftAmount            = GiftDetailDR.GiftTransactionAmount;
                                tmpLastGiftGivenToPartnerKey = GiftDetailDR.RecipientKey;

                                // Get Partner ShortName
                                PPartnerAccess.LoadByPrimaryKey(LastGiftDS, GiftDetailDR.RecipientKey,
                                                                StringHelper.InitStrArr(new String[] { PPartnerTable.GetPartnerShortNameDBName() }), Transaction, null, 0, 0);

                                if (LastGiftDS.Tables[PPartnerTable.GetTableName()].Rows.Count != 0)
                                {
                                    tmpLastGiftGivenToShortName =
                                        ((PPartnerRow)(LastGiftDS.Tables[PPartnerTable.GetTableName()].Rows[0])).PartnerShortName;
                                }
                                else
                                {
                                    // missing Partner
                                    tmpLastGiftGivenToShortName = "";
                                }

                                // Get rid of last record because we are about to select again into the same DataTable...
                                LastGiftDS.Tables[PPartnerTable.GetTableName()].Rows.Clear();

                                // Get Recipient Ledger
                                PPartnerAccess.LoadByPrimaryKey(LastGiftDS, GiftDetailDR.RecipientLedgerNumber,
                                                                StringHelper.InitStrArr(new String[] { PPartnerTable.GetPartnerShortNameDBName() }), Transaction, null, 0, 0);

                                if (LastGiftDS.Tables[PPartnerTable.GetTableName()].Rows.Count != 0)
                                {
                                    tmpLastGiftRecipientLedgerShortName =
                                        ((PPartnerRow)(LastGiftDS.Tables[PPartnerTable.GetTableName()].Rows[0])).PartnerShortName;
                                }
                                else
                                {
                                    // missing Ledger
                                    tmpLastGiftRecipientLedgerShortName = "";
                                }
                            }
                        }
                        else
                        {
                            // missing Gift Detail
                            tmpLastGiftAmount                   = 0;
                            tmpLastGiftGivenToShortName         = "";
                            tmpLastGiftRecipientLedgerShortName = "";
                            tmpLastGiftGivenToPartnerKey        = -1;
                            tmpLastGiftRecipientLedger          = -1;
                        }
                    }
                    else
                    {
                        // Gift is a restriced Gift and the current user isn't allowed to see it
                        tmpRestrictedOrConfidentialGiftAccessDenied = true;
                    }
                }
                finally
                {
                    TLogging.LogAtLevel(7, "TGift.GetLastGiftDetails: committed own transaction.");
                }
            });

            ALastGiftDate                             = tmpLastGiftDate;
            ALastGiftAmount                           = tmpLastGiftAmount;
            ALastGiftGivenToPartnerKey                = tmpLastGiftGivenToPartnerKey;
            ALastGiftRecipientLedger                  = tmpLastGiftRecipientLedger;
            ALastGiftCurrencyCode                     = tmpLastGiftCurrencyCode;
            ALastGiftDisplayFormat                    = tmpLastGiftDisplayFormat;
            ALastGiftGivenToShortName                 = tmpLastGiftGivenToShortName;
            ALastGiftRecipientLedgerShortName         = tmpLastGiftRecipientLedgerShortName;
            ARestrictedOrConfidentialGiftAccessDenied = tmpRestrictedOrConfidentialGiftAccessDenied;

            return(AccessToGift);
        }
コード例 #16
0
        /// <summary>
        /// Retrieves 'Rest' of Partner Information data.
        /// </summary>
        /// <param name="APartnerDR">DataRow that contains the Partner data.</param>
        /// <param name="APartnerInfoDS" >Typed PartnerInfoTDS DataSet</param>
        /// <param name="AReadTransaction" >Open DB Transaction.</param>
        private static void RestInternal(PPartnerRow APartnerDR,
                                         ref PartnerInfoTDS APartnerInfoDS,
                                         TDBTransaction AReadTransaction)
        {
            PartnerInfoTDSPartnerAdditionalInfoRow PartnerInfoDR;
            TPartnerClass PartnerClass;
            DateTime      LastContactDate;
            PPersonTable  PersonDT;
            PPartnerTable FamilyPartnerDT;
            Int64         PartnerKey = APartnerDR.PartnerKey;

            /*
             * Load Special Types
             */
            PPartnerTypeAccess.LoadViaPPartner(APartnerInfoDS, PartnerKey, AReadTransaction);


            /*
             * Load Subscriptions
             */
            PSubscriptionAccess.LoadViaPPartnerPartnerKey(APartnerInfoDS, PartnerKey, AReadTransaction);


            #region Populate PartnerAdditionalInfo Table

            if (APartnerInfoDS.PartnerAdditionalInfo.Rows.Count == 0)
            {
                PartnerInfoDR = APartnerInfoDS.PartnerAdditionalInfo.NewRowTyped(false);
            }
            else
            {
                PartnerInfoDR = APartnerInfoDS.PartnerAdditionalInfo[0];
            }

            if (!APartnerDR.IsCommentNull())
            {
                PartnerInfoDR.Notes = APartnerDR.Comment.Trim();
            }

            if (!APartnerDR.IsDateCreatedNull())
            {
                PartnerInfoDR.DateCreated = APartnerDR.DateCreated;
            }

            if (!APartnerDR.IsDateModifiedNull())
            {
                PartnerInfoDR.DateModified = APartnerDR.DateModified;
            }

            if (!APartnerDR.IsLanguageCodeNull())
            {
                PartnerInfoDR.MainLanguages = APartnerDR.LanguageCode;
            }

            if (!APartnerDR.IsPreviousNameNull())
            {
                PartnerInfoDR.PreviousName = APartnerDR.PreviousName;
            }

            // Determination of Last Contact Date
            TMailroom.GetLastContactDate(PartnerKey, out LastContactDate, AReadTransaction.DataBaseObj);
            PartnerInfoDR.LastContact = LastContactDate;


            /*
             * Special Data according to Partner Class
             */
            PartnerClass = SharedTypes.PartnerClassStringToEnum(APartnerDR.PartnerClass);

            switch (PartnerClass)
            {
            case TPartnerClass.PERSON:
                PersonDT = PPersonAccess.LoadByPrimaryKey(APartnerDR.PartnerKey, AReadTransaction);

                if (PersonDT != null)
                {
                    if (!PersonDT[0].IsDateOfBirthNull())
                    {
                        PartnerInfoDR.DateOfBirth = PersonDT[0].DateOfBirth;
                    }

                    // Get Family Members info
                    APartnerInfoDS.Merge(GetFamilyMembers(PersonDT[0].FamilyKey, AReadTransaction));


                    // Get Family Partner info
                    FamilyPartnerDT = PPartnerAccess.LoadByPrimaryKey(PersonDT[0].FamilyKey, AReadTransaction);

                    if (FamilyPartnerDT != null)
                    {
                        PartnerInfoDR.Family    = FamilyPartnerDT[0].PartnerShortName;
                        PartnerInfoDR.FamilyKey = FamilyPartnerDT[0].PartnerKey;
                    }

                    // Get the Languages of a Person from Personnel
                    PartnerInfoDR.AdditionalLanguages = GetPersonLanguagesFromPersonnel(
                        APartnerDR.PartnerKey, PartnerInfoDR.MainLanguages, AReadTransaction);
                }

                break;

            case TPartnerClass.FAMILY:

                // Get Family Members info
                APartnerInfoDS.Merge(GetFamilyMembers(PartnerKey, AReadTransaction));
                break;

            case TPartnerClass.UNIT:

                // Get Unit structure info
                APartnerInfoDS.Merge(GetUnitStructure(PartnerKey, AReadTransaction));

                break;
            }

            // Get Partners' PartnerAttributes
            PartnerAttributesInternal(PartnerKey, ref APartnerInfoDS, false, AReadTransaction);
            // TODO: Apply Contact Details Security

            if (APartnerInfoDS.PartnerAdditionalInfo.Rows.Count == 0)
            {
                APartnerInfoDS.PartnerAdditionalInfo.Rows.Add(PartnerInfoDR);
            }

            #endregion
        }
コード例 #17
0
        /// <summary>
        /// Get recursively all the child units of a unit and puts them into the
        /// results list.
        /// </summary>
        /// <param name="AUnitKey">Parent unit to get the child unit from</param>
        /// <param name="AChildLevel">Indicates how deep we are in the recursion</param>
        /// <param name="AWithOutreaches">Indicates if outreaches and conferences should
        /// be included in the result</param>
        /// <param name="AChildRow">the number of the row</param>
        /// <returns>False if the parent unit is not active.
        /// Otherwise true</returns>
        private bool GetChildUnits(long AUnitKey, int AChildLevel, bool AWithOutreaches, ref int AChildRow)
        {
            UmUnitStructureTable UnitStructure;
            PUnitTable           UnitTable;
            PPartnerTable        PartnerTable;
            UUnitTypeTable       UnitType;

            PartnerTable = PPartnerAccess.LoadByPrimaryKey(AUnitKey, situation.GetDatabaseConnection().Transaction);

            if ((PartnerTable.Rows.Count > 0) &&
                (((PPartnerRow)PartnerTable.Rows[0]).StatusCode != "ACTIVE"))
            {
                return(false);
            }

            string PreceedingWhiteSpaces = new string(' ', AChildLevel * 2);

            UnitStructure = UmUnitStructureAccess.LoadViaPUnitParentUnitKey(AUnitKey, situation.GetDatabaseConnection().Transaction);

            // Add this unit to the results
            UnitTable = PUnitAccess.LoadByPrimaryKey(AUnitKey, situation.GetDatabaseConnection().Transaction);

            if (UnitTable.Rows.Count > 0)
            {
                PUnitRow UnitRow = (PUnitRow)UnitTable.Rows[0];

                string UnitTypeName = UnitRow.UnitTypeCode;

                UnitType = UUnitTypeAccess.LoadByPrimaryKey(UnitRow.UnitTypeCode, situation.GetDatabaseConnection().Transaction);

                if (UnitType.Rows.Count > 0)
                {
                    UnitTypeName = ((UUnitTypeRow)UnitType.Rows[0]).UnitTypeName;
                }

                string UnitKeyString = FormatAsUnitKey(UnitRow.PartnerKey);

                TVariant[] Header =
                {
                    new TVariant(), new TVariant(), new TVariant(), new TVariant()
                };
                TVariant[] Description =
                {
                    new TVariant(), new TVariant()
                };
                TVariant[] Columns =
                {
                    new TVariant(PreceedingWhiteSpaces + UnitKeyString),
                    new TVariant(PreceedingWhiteSpaces + UnitTypeName),
                    new TVariant(PreceedingWhiteSpaces + UnitRow.UnitName),
                    new TVariant(UnitRow.PartnerKey)
                };

                situation.GetResults().AddRow(0, AChildRow++, true, 1, "", "", false,
                                              Header, Description, Columns);
            }

            //
            // Add the children to the results
            //

            SortedList <string, long> ChildList = new SortedList <string, long>();

            AChildLevel++;

            foreach (DataRow Row in UnitStructure.Rows)
            {
                // Add the name and the key into a sorted list
                // so we can sort the result alphabetically
                long ChildUnitKey = (long)Row[UmUnitStructureTable.GetChildUnitKeyDBName()];

                if (ChildUnitKey == AUnitKey)
                {
                    continue;
                }

                UnitTable = PUnitAccess.LoadByPrimaryKey(ChildUnitKey, situation.GetDatabaseConnection().Transaction);

                if (UnitTable.Rows.Count < 1)
                {
                    continue;
                }

                PUnitRow UnitRow = (PUnitRow)UnitTable.Rows[0];

                string UnitName     = UnitRow.UnitName;
                string UnitTypeName = UnitRow.UnitTypeCode;

                if (!AWithOutreaches &&
                    ((UnitTypeName.StartsWith("GA")) ||
                     (UnitTypeName.StartsWith("GC")) ||
                     (UnitTypeName.StartsWith("TN")) ||
                     (UnitTypeName.StartsWith("TS"))))
                {
                    continue;
                }

                // use as key UnitName (for sorting) plus UnitKey so that it is
                // unique. We might have two units with the same name
                ChildList.Add(UnitName + ChildUnitKey.ToString(), ChildUnitKey);
            }

            foreach (KeyValuePair <string, long> kvp in ChildList)
            {
                GetChildUnits(kvp.Value, AChildLevel, AWithOutreaches, ref AChildRow);
            }

            return(true);
        }
コード例 #18
0
ファイル: UnitHierarchy.cs プロジェクト: lxhelp/openpetra
        public static ArrayList GetUnitHeirarchy()
        {
            const Int64 THE_ORGANISATION = 1000000;

            ArrayList Ret = new ArrayList();

            TDBTransaction Transaction = null;

            DBAccess.GDBAccessObj.BeginAutoReadTransaction(IsolationLevel.ReadCommitted, ref Transaction,
                                                           delegate
            {
                PPartnerTable PartnerTbl         = PPartnerAccess.LoadViaPPartnerClasses("UNIT", Transaction);
                PartnerTbl.DefaultView.RowFilter = "p_status_code_c <> 'MERGED'";
                PartnerTbl.DefaultView.Sort      = PPartnerTable.GetPartnerKeyDBName();

                PUnitTable UnitTbl           = PUnitAccess.LoadAll(Transaction);
                UUnitTypeTable UnitTypeTbl   = UUnitTypeAccess.LoadAll(Transaction);
                UnitTypeTbl.DefaultView.Sort = UUnitTypeTable.GetUnitTypeCodeDBName();

                UmUnitStructureTable HierarchyTbl = UmUnitStructureAccess.LoadAll(Transaction);
                HierarchyTbl.DefaultView.Sort     = UmUnitStructureTable.GetChildUnitKeyDBName();

                UnitTbl.DefaultView.Sort         = PUnitTable.GetPartnerKeyDBName();
                UnitHierarchyNode RootNode       = new UnitHierarchyNode();
                UnitHierarchyNode UnassignedNode = new UnitHierarchyNode();

                RootNode.MyUnitKey     = THE_ORGANISATION;
                RootNode.ParentUnitKey = THE_ORGANISATION;
                RootNode.Description   = "The Organisation";
                RootNode.TypeCode      = "Root";

                Int32 RootUnitIdx = UnitTbl.DefaultView.Find(THE_ORGANISATION);

                if (RootUnitIdx >= 0)
                {
                    RootNode.Description = ((PUnitRow)UnitTbl.DefaultView[RootUnitIdx].Row).UnitName;
                    UnitTbl.DefaultView.Delete(RootUnitIdx);
                }

                Ret.Add(RootNode);

                UnassignedNode.MyUnitKey     = 0;
                UnassignedNode.ParentUnitKey = 0;
                UnassignedNode.Description   = Catalog.GetString("Unassigned Units");
                Ret.Add(UnassignedNode);

                foreach (DataRowView rv in UnitTbl.DefaultView)
                {
                    PUnitRow UnitRow = (PUnitRow)rv.Row;

                    if (PartnerTbl.DefaultView.Find(UnitRow.PartnerKey) < 0)
                    {
                        // skip all merged units
                        continue;
                    }

                    UnitHierarchyNode Node = new UnitHierarchyNode();
                    Node.Description       = UnitRow.UnitName + " " + UnitRow.Description;

                    if (Node.Description == "")
                    {
                        Node.Description = "[" + UnitRow.PartnerKey.ToString("D10") + "]";
                    }

                    Node.MyUnitKey = UnitRow.PartnerKey;

                    //
                    // Retrieve parent..
                    Int32 HierarchyTblIdx = HierarchyTbl.DefaultView.Find(Node.MyUnitKey);

                    if (HierarchyTblIdx >= 0)
                    {
                        Node.ParentUnitKey = ((UmUnitStructureRow)HierarchyTbl.DefaultView[HierarchyTblIdx].Row).ParentUnitKey;
                    }
                    else
                    {
                        Node.ParentUnitKey = UnassignedNode.MyUnitKey;
                    }

                    //
                    // Retrieve TypeCode..
                    Int32 TypeTblIndex = UnitTypeTbl.DefaultView.Find(UnitRow.UnitTypeCode);

                    if (TypeTblIndex >= 0)
                    {
                        Node.TypeCode = ((UUnitTypeRow)UnitTypeTbl.DefaultView[TypeTblIndex].Row).UnitTypeName;
                    }
                    else
                    {
                        Node.TypeCode = "Type: " + UnitRow.UnitTypeCode;
                    }

                    Ret.Add(Node);
                }
            });

            return(Ret);
        }
コード例 #19
0
        /// <summary>
        /// Add the address details of the supporting church of a partner to the results
        /// </summary>
        /// <param name="APartnerKey">The partner key of whom the supporting church details should be added</param>
        /// <returns></returns>
        private bool GetChurch(Int64 APartnerKey)
        {
            PPartnerRelationshipTable RelationshipTable;
            PPartnerTable             ChurchTable;
            string PhoneNumber;
            string EmailAddress;

            Dictionary <String, String> GatheredResults = new Dictionary <String, String>();

            PPartnerRelationshipRow TemplateRow = new PPartnerRelationshipTable().NewRowTyped(false);

            TemplateRow.RelationKey  = APartnerKey;
            TemplateRow.RelationName = "SUPPCHURCH";

            RelationshipTable = PPartnerRelationshipAccess.LoadUsingTemplate(TemplateRow, situation.GetDatabaseConnection().Transaction);

            bool IsFirstAddress = true;

            foreach (PPartnerRelationshipRow Row in RelationshipTable.Rows)
            {
                ChurchTable = PPartnerAccess.LoadByPrimaryKey(Row.PartnerKey, situation.GetDatabaseConnection().Transaction);

                if (ChurchTable.Rows.Count < 1)
                {
                    continue;
                }

                PPartnerLocationRow PartnerLocationRow;
                PLocationTable      LocationTable;

                if (!TRptUserFunctionsPartner.GetPartnerBestAddressRow(Row.PartnerKey, situation, out PartnerLocationRow))
                {
                    continue;
                }

                LocationTable = PLocationAccess.LoadByPrimaryKey(PartnerLocationRow.SiteKey,
                                                                 PartnerLocationRow.LocationKey, situation.GetDatabaseConnection().Transaction);

                if (LocationTable.Rows.Count < 1)
                {
                    continue;
                }

                if (IsFirstAddress)
                {
                    GatheredResults.Add("Church-Name", ((PPartnerRow)ChurchTable.Rows[0]).PartnerShortName);
                }
                else
                {
                    GatheredResults["Church-Name"] += ", " + ((PPartnerRow)ChurchTable.Rows[0]).PartnerShortName + " ";
                }

                // Add this church address to the results
                // the variables will be something like Church-PostalCode, Church-StreetName

                // get the location details into the parameters
                foreach (DataColumn col in LocationTable.Columns)
                {
                    if (IsFirstAddress)
                    {
                        GatheredResults.Add("Church-" + StringHelper.UpperCamelCase(col.ColumnName, true, true),
                                            LocationTable.Rows[0][col.ColumnName].ToString());
                    }
                    else
                    {
                        GatheredResults["Church-" + StringHelper.UpperCamelCase(col.ColumnName, true, true)] +=
                            ", " + LocationTable.Rows[0][col.ColumnName].ToString();
                    }
                }

                if (IsFirstAddress)
                {
                    // also put the phone number and email etc into the parameters
                    TContactDetailsAggregate.GetPrimaryEmailAndPrimaryPhone(Row.PartnerKey,
                                                                            out PhoneNumber, out EmailAddress);

                    // Add Calculation Parameter for 'Primary Email Address' (String.Empty is supplied if the Partner hasn't got one)
                    situation.GetParameters().AddCalculationParameter("Church-EmailAddress",
                                                                      new TVariant(EmailAddress ?? String.Empty));

                    // Add Calculation Parameter for 'Primary Phone Number' (String.Empty is supplied if the Partner hasn't got one)
                    situation.GetParameters().AddCalculationParameter("Church-Telephone",
                                                                      new TVariant(PhoneNumber ?? String.Empty));

                    // At present we no longer support the reporting of the following, so we set those Calculation Parameters to String.Empty
                    GatheredResults.Add("Church-FaxNumber", String.Empty);
                    GatheredResults.Add("Church-MobileNumber", String.Empty);
                    GatheredResults.Add("Church-AlternateTelephone", String.Empty);
                }

                IsFirstAddress = false;
            }

            if (IsFirstAddress)
            {
                situation.GetParameters().RemoveVariable("Church-Telephone");
                situation.GetParameters().RemoveVariable("Church-FaxNumber");
                situation.GetParameters().RemoveVariable("Church-EmailAddress");
                situation.GetParameters().RemoveVariable("Church-MobileNumber");
                situation.GetParameters().RemoveVariable("Church-AlternateTelephone");
                situation.GetParameters().RemoveVariable("Church-Name");
                situation.GetParameters().RemoveVariable("Church-Locality");
                situation.GetParameters().RemoveVariable("Church-Address3");
                situation.GetParameters().RemoveVariable("Church-City");
                situation.GetParameters().RemoveVariable("Church-CountryCode");
                situation.GetParameters().RemoveVariable("Church-County");
                situation.GetParameters().RemoveVariable("Church-PostalCode");
                situation.GetParameters().RemoveVariable("Church-StreetName");
            }
            else
            {
                foreach (KeyValuePair <String, String> kvp in GatheredResults)
                {
                    situation.GetParameters().Add(kvp.Key, new TVariant(kvp.Value));
                }
            }

            return(true);
        }
コード例 #20
0
ファイル: Common.cs プロジェクト: merbst/openpetra
        /// <summary>
        /// this checks if the new key is still available,
        /// and makes sure it will not be used as a default key anymore
        /// </summary>
        /// <param name="AFieldPartnerKey"></param>
        /// <param name="AOriginalDefaultKey">this has been previously retrieved from GetNewPartnerKey</param>
        /// <param name="ANewPartnerKey">the user proposes this key for a new partner; the function can change it and return a valid value, or -1</param>
        /// <returns>whether or not ANewPartnerKey has a valid new partner key;
        /// if it cannot be assigned, the function returns false, and ANewPartnerKey is -1
        /// </returns>
        public static bool SubmitNewPartnerKey(System.Int64 AFieldPartnerKey, System.Int64 AOriginalDefaultKey, ref System.Int64 ANewPartnerKey)
        {
            bool                ReturnValue = true;
            TDBTransaction      ReadTransaction1;
            TDBTransaction      ReadTransaction2;
            TDBTransaction      WriteTransaction;
            Boolean             NewTransaction1;
            Boolean             NewTransaction2;
            Boolean             NewTransaction3;
            PPartnerLedgerTable PartnerLedgerDT;

            System.Int64 CurrentDefaultPartnerKey;

            if (ANewPartnerKey == AOriginalDefaultKey)
            {
                // The user has selected the default
                ReadTransaction1 = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.RepeatableRead,
                                                                                     TEnforceIsolationLevel.eilMinimum, out NewTransaction1);

                try
                {
                    // Fetch the partner ledger record to update the last key

                    PartnerLedgerDT          = PPartnerLedgerAccess.LoadByPrimaryKey(AFieldPartnerKey, ReadTransaction1);
                    CurrentDefaultPartnerKey = PartnerLedgerDT[0].PartnerKey + PartnerLedgerDT[0].LastPartnerId + 1;

                    if (ANewPartnerKey != CurrentDefaultPartnerKey)
                    {
                        // Someone else has updated this since, so we will use the new default
                        ANewPartnerKey = CurrentDefaultPartnerKey;
                    }

                    // Now check that this does not exist, and increment until we
                    // find one which does not
                    while (PPartnerAccess.Exists(ANewPartnerKey, ReadTransaction1))
                    {
                        ANewPartnerKey = ANewPartnerKey + 1;
                    }
                }
                finally
                {
                    if (NewTransaction1)
                    {
                        DBAccess.GDBAccessObj.CommitTransaction();

                        if (TLogging.DebugLevel >= TLogging.DEBUGLEVEL_TRACE)
                        {
                            Console.WriteLine("TNewPartnerKey.SubmitNewPartnerKey: committed own transaction.");
                        }
                    }
                }

                PartnerLedgerDT[0].LastPartnerId = (int)(ANewPartnerKey - PartnerLedgerDT[0].PartnerKey);

                WriteTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.Serializable,
                                                                                     TEnforceIsolationLevel.eilMinimum, out NewTransaction2);

                try
                {
                    PPartnerLedgerAccess.SubmitChanges(PartnerLedgerDT, WriteTransaction);

                    if (NewTransaction2)
                    {
                        DBAccess.GDBAccessObj.CommitTransaction();
                    }
                }
                catch (Exception Exc)
                {
                    TLogging.Log("An Exception occured during the submission of a new PartnerKey:" + Environment.NewLine + Exc.ToString());

                    if (NewTransaction2)
                    {
                        DBAccess.GDBAccessObj.RollbackTransaction();
                    }

                    throw;
                }
            }
            // end of: The user has selected the default
            else
            {
                ReadTransaction2 = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.RepeatableRead,
                                                                                     TEnforceIsolationLevel.eilMinimum, out NewTransaction3);

                try
                {
                    // check if the Partner Key is already being used
                    if (PPartnerAccess.Exists(ANewPartnerKey, ReadTransaction2))
                    {
                        ANewPartnerKey = -1;
                        ReturnValue    = false;
                    }
                }
                finally
                {
                    if (NewTransaction3)
                    {
                        DBAccess.GDBAccessObj.CommitTransaction();

                        if (TLogging.DebugLevel >= TLogging.DEBUGLEVEL_TRACE)
                        {
                            Console.WriteLine("TNewPartnerKey.SubmitNewPartnerKey: committed own transaction.");
                        }
                    }
                }
            }

            return(ReturnValue);
        }
コード例 #21
0
        public static PartnerEditTDS GetPartnerDetails(Int64 APartnerKey,
                                                       out List <string> ASubscriptions,
                                                       out List <string> APartnerTypes,
                                                       out string ADefaultEmailAddress,
                                                       out string ADefaultPhoneMobile,
                                                       out string ADefaultPhoneLandline)
        {
            PartnerEditTDS MainDS               = new PartnerEditTDS();
            List <string>  Subscriptions        = new List <string>();
            List <string>  PartnerTypes         = new List <string>();
            string         DefaultEmailAddress  = String.Empty;
            string         DefaultPhoneMobile   = String.Empty;
            string         DefaultPhoneLandline = String.Empty;

            TDBTransaction Transaction = new TDBTransaction();

            DBAccess.ReadTransaction(ref Transaction,
                                     delegate
            {
                PPartnerAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);

                if (MainDS.PPartner.Rows.Count > 0)
                {
                    switch (MainDS.PPartner[0].PartnerClass)
                    {
                    case MPartnerConstants.PARTNERCLASS_FAMILY:
                        PFamilyAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                        break;

                    case MPartnerConstants.PARTNERCLASS_PERSON:
                        PPersonAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                        break;

                    case MPartnerConstants.PARTNERCLASS_CHURCH:
                        PChurchAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                        break;

                    case MPartnerConstants.PARTNERCLASS_ORGANISATION:
                        POrganisationAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                        break;

                    case MPartnerConstants.PARTNERCLASS_BANK:
                        PBankAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                        break;

                    case MPartnerConstants.PARTNERCLASS_UNIT:
                        PUnitAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                        break;
                    }

                    if (true)
                    {
                        PPartnerLocationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                        PLocationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                    }

                    if (true)
                    {
                        PPartnerRelationshipAccess.LoadViaPPartnerPartnerKey(MainDS, APartnerKey, Transaction);
                    }

                    if (true)
                    {
                        PCountryAccess.LoadAll(MainDS, Transaction);
                    }

                    if (true)
                    {
                        PPublicationAccess.LoadAll(MainDS, Transaction);
                        PSubscriptionAccess.LoadViaPPartnerPartnerKey(MainDS, APartnerKey, Transaction);

                        foreach (PSubscriptionRow subscription in MainDS.PSubscription.Rows)
                        {
                            Subscriptions.Add(subscription.PublicationCode);
                        }
                    }

                    PPartnerStatusAccess.LoadAll(MainDS, Transaction);
                    PTypeAccess.LoadAll(MainDS, Transaction);
                    PPartnerTypeAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);

                    foreach (PPartnerTypeRow partnertype in MainDS.PPartnerType.Rows)
                    {
                        PartnerTypes.Add(partnertype.TypeCode);
                    }

                    PPartnerAttributeAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);

                    foreach (PPartnerAttributeRow partnerattr in MainDS.PPartnerAttribute.Rows)
                    {
                        if (partnerattr.AttributeType == MPartnerConstants.ATTR_TYPE_EMAIL)
                        {
                            DefaultEmailAddress = partnerattr.Value;
                        }
                        else if (partnerattr.AttributeType == MPartnerConstants.ATTR_TYPE_PHONE)
                        {
                            DefaultPhoneLandline = partnerattr.Value;
                        }
                        else if (partnerattr.AttributeType == MPartnerConstants.ATTR_TYPE_MOBILE_PHONE)
                        {
                            DefaultPhoneMobile = partnerattr.Value;
                        }
                    }
                }
            });

            APartnerTypes         = PartnerTypes;
            ASubscriptions        = Subscriptions;
            ADefaultEmailAddress  = DefaultEmailAddress;
            ADefaultPhoneMobile   = DefaultPhoneMobile;
            ADefaultPhoneLandline = DefaultPhoneLandline;

            return(MainDS);
        }
コード例 #22
0
        public static Boolean VerifyPartnerAndGetDetails(Int64 APartnerKey,
                                                         out String APartnerShortName,
                                                         out TPartnerClass APartnerClass,
                                                         out Boolean AIsMergedPartner,
                                                         out Boolean AUserCanAccessPartner)
        {
            APartnerShortName     = "";
            APartnerClass         = TPartnerClass.FAMILY; // Default. This is not really correct but the best compromise if PartnerKey is 0 or Partner isn't found since we have an enum here.
            AIsMergedPartner      = false;
            AUserCanAccessPartner = false;

            TDBTransaction        ReadTransaction;
            Boolean               NewTransaction;
            StringCollection      RequiredColumns;
            PPartnerTable         PartnerTable;
            Boolean               ReturnValue   = true;
            TStdPartnerStatusCode PartnerStatus = TStdPartnerStatusCode.spscACTIVE;

            // initialise outout Arguments
            if (APartnerKey != 0)
            {
                // only some fields are needed
                RequiredColumns = new StringCollection();
                RequiredColumns.Add(PPartnerTable.GetPartnerShortNameDBName());
                RequiredColumns.Add(PPartnerTable.GetPartnerClassDBName());
                RequiredColumns.Add(PPartnerTable.GetStatusCodeDBName());
                RequiredColumns.Add(PPartnerTable.GetRestrictedDBName());
                RequiredColumns.Add(PPartnerTable.GetUserIdDBName());
                RequiredColumns.Add(PPartnerTable.GetGroupIdDBName());

                ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted,
                                                                                    TEnforceIsolationLevel.eilMinimum,
                                                                                    out NewTransaction);
                try
                {
                    PartnerTable = PPartnerAccess.LoadByPrimaryKey(APartnerKey, RequiredColumns, ReadTransaction, null, 0, 0);
                }
                finally
                {
                    if (NewTransaction)
                    {
                        DBAccess.GDBAccessObj.CommitTransaction();
                        TLogging.LogAtLevel(7, "TPartnerServerLookups.VerifyPartner: committed own transaction.");
                    }
                }

                if (PartnerTable.Rows.Count == 0)
                {
                    ReturnValue = false;
                }
                else
                {
                    // since we loaded by primary key there must just be one partner row
                    APartnerShortName = PartnerTable[0].PartnerShortName;
                    APartnerClass     = SharedTypes.PartnerClassStringToEnum(PartnerTable[0].PartnerClass);
                    PartnerStatus     = SharedTypes.StdPartnerStatusCodeStringToEnum(PartnerTable[0].StatusCode);

                    // check if user can access partner
                    if (Ict.Petra.Server.MPartner.Common.TSecurity.CanAccessPartner(PartnerTable[0]) == TPartnerAccessLevelEnum.palGranted)
                    {
                        AUserCanAccessPartner = true;
                    }

                    // check if partner is merged
                    if (PartnerStatus == TStdPartnerStatusCode.spscMERGED)
                    {
                        AIsMergedPartner = true;
                    }
                    else
                    {
                        AIsMergedPartner = false;
                    }

                    ReturnValue = true;
                }
            }
            else
            {
                // Return result as valid if Partner Key is 0.
                ReturnValue = true;
            }

            return(ReturnValue);
        }
コード例 #23
0
        public static PartnerEditTDS GetPartnerDetails(Int64 APartnerKey,
                                                       out List <string> ASubscriptions,
                                                       out List <string> APartnerTypes,
                                                       out string ADefaultEmailAddress,
                                                       out string ADefaultPhoneMobile,
                                                       out string ADefaultPhoneLandline)
        {
            PartnerEditTDS MainDS               = new PartnerEditTDS();
            List <string>  Subscriptions        = new List <string>();
            List <string>  PartnerTypes         = new List <string>();
            string         DefaultEmailAddress  = String.Empty;
            string         DefaultPhoneMobile   = String.Empty;
            string         DefaultPhoneLandline = String.Empty;

            TDBTransaction Transaction = new TDBTransaction();

            DBAccess.ReadTransaction(ref Transaction,
                                     delegate
            {
                PPartnerAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);

                if (MainDS.PPartner.Rows.Count > 0)
                {
                    switch (MainDS.PPartner[0].PartnerClass)
                    {
                    case MPartnerConstants.PARTNERCLASS_FAMILY:
                        PFamilyAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                        break;

                    case MPartnerConstants.PARTNERCLASS_PERSON:
                        PPersonAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                        break;

                    case MPartnerConstants.PARTNERCLASS_CHURCH:
                        PChurchAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                        break;

                    case MPartnerConstants.PARTNERCLASS_ORGANISATION:
                        POrganisationAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                        break;

                    case MPartnerConstants.PARTNERCLASS_BANK:
                        PBankAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                        break;

                    case MPartnerConstants.PARTNERCLASS_UNIT:
                        PUnitAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction);
                        break;
                    }

                    if (true)
                    {
                        PPartnerLocationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                        PLocationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                    }

                    if (true)
                    {
                        PPartnerRelationshipAccess.LoadViaPPartnerPartnerKey(MainDS, APartnerKey, Transaction);
                    }

                    if (true)
                    {
                        PCountryAccess.LoadAll(MainDS, Transaction);
                    }

                    if (true)
                    {
                        PPublicationAccess.LoadAll(MainDS, Transaction);
                        PSubscriptionAccess.LoadViaPPartnerPartnerKey(MainDS, APartnerKey, Transaction);

                        foreach (PSubscriptionRow subscription in MainDS.PSubscription.Rows)
                        {
                            Subscriptions.Add(subscription.PublicationCode);
                        }
                    }

                    if (true)
                    {
                        PBankingDetailsAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                        PPartnerBankingDetailsAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);
                        PBankingDetailsUsageAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);

                        foreach (PartnerEditTDSPBankingDetailsRow banking in MainDS.PBankingDetails.Rows)
                        {
                            PBankAccess.LoadByPrimaryKey(MainDS, banking.BankKey, Transaction);
                            banking.Bic        = MainDS.PBank[0].Bic;
                            banking.BranchName = MainDS.PBank[0].BranchName;
                            banking.Iban       = FormatIBAN(banking.Iban);
                            MainDS.PBank.Rows.Clear();
                        }

                        foreach (PartnerEditTDSPBankingDetailsRow bd in MainDS.PBankingDetails.Rows)
                        {
                            bd.MainAccount =
                                (MainDS.PBankingDetailsUsage.Rows.Find(
                                     new object[] { APartnerKey, bd.BankingDetailsKey, MPartnerConstants.BANKINGUSAGETYPE_MAIN }) != null);
                        }

                        MainDS.PBankingDetailsUsage.Rows.Clear();
                    }

                    PPartnerStatusAccess.LoadAll(MainDS, Transaction);
                    PTypeRow templateRow   = MainDS.PType.NewRowTyped();
                    templateRow.SystemType = false;
                    templateRow.SetTypeDeletableNull();
                    templateRow.SetDateCreatedNull();
                    PTypeAccess.LoadUsingTemplate(MainDS, templateRow, Transaction);
                    PPartnerTypeAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);

                    foreach (PPartnerTypeRow partnertype in MainDS.PPartnerType.Rows)
                    {
                        PartnerTypes.Add(partnertype.TypeCode);
                    }

                    PPartnerAttributeAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction);

                    foreach (PPartnerAttributeRow partnerattr in MainDS.PPartnerAttribute.Rows)
                    {
                        if (partnerattr.AttributeType == MPartnerConstants.ATTR_TYPE_EMAIL)
                        {
                            DefaultEmailAddress = partnerattr.Value;
                        }
                        else if (partnerattr.AttributeType == MPartnerConstants.ATTR_TYPE_PHONE)
                        {
                            DefaultPhoneLandline = partnerattr.Value;
                        }
                        else if (partnerattr.AttributeType == MPartnerConstants.ATTR_TYPE_MOBILE_PHONE)
                        {
                            DefaultPhoneMobile = partnerattr.Value;
                        }
                    }
                }
            });

            APartnerTypes         = PartnerTypes;
            ASubscriptions        = Subscriptions;
            ADefaultEmailAddress  = DefaultEmailAddress;
            ADefaultPhoneMobile   = DefaultPhoneMobile;
            ADefaultPhoneLandline = DefaultPhoneLandline;

            return(MainDS);
        }
コード例 #24
0
        private static void ParsePartners(ref PartnerImportExportTDS AMainDS,
                                          XmlNode ACurNode,
                                          TDBTransaction ATransaction,
                                          ref TVerificationResultCollection AVerificationResult)
        {
            XmlNode LocalNode = ACurNode;

            while (LocalNode != null)
            {
                if (LocalNode.Name.StartsWith("PartnerGroup"))
                {
                    ParsePartners(ref AMainDS, LocalNode.FirstChild, ATransaction, ref AVerificationResult);
                }
                else if (LocalNode.Name.StartsWith("Partner"))
                {
                    PPartnerRow PartnerRow        = AMainDS.PPartner.NewRowTyped();
                    Boolean     IsExistingPartner = false;

                    if (!TYml2Xml.HasAttributeRecursive(LocalNode, "SiteKey"))
                    {
                        throw new Exception(Catalog.GetString("Missing SiteKey Attribute"));
                    }

                    if (!TYml2Xml.HasAttributeRecursive(LocalNode, "status"))
                    {
                        throw new Exception(Catalog.GetString("Missing status Attribute"));
                    }

                    // get a new partner key
                    if (TYml2Xml.HasAttribute(LocalNode, "PartnerKey"))
                    {
                        PartnerRow.PartnerKey = Convert.ToInt64(TYml2Xml.GetAttribute(LocalNode, "PartnerKey"));

                        if (PPartnerAccess.Exists(PartnerRow.PartnerKey, ATransaction))
                        {
                            AMainDS.Merge(PPartnerAccess.LoadByPrimaryKey(PartnerRow.PartnerKey, ATransaction));

                            AMainDS.PPartner.DefaultView.RowFilter = String.Format("{0} = '{1}'",
                                                                                   PPartnerTable.GetPartnerKeyDBName(),
                                                                                   PartnerRow.PartnerKey);
                            PartnerRow        = (PPartnerRow)AMainDS.PPartner.DefaultView[0].Row;
                            IsExistingPartner = true;
                        }
                        else
                        {
                            AMainDS.PPartner.Rows.Add(PartnerRow);
                        }
                    }
                    else
                    {
                        PartnerRow.PartnerKey = TImportExportYml.NewPartnerKey;
                        TImportExportYml.NewPartnerKey--;
                    }

                    String PartnerClass = TYml2Xml.GetAttributeRecursive(LocalNode, "class");
                    TLogging.LogAtLevel(TLogging.DEBUGLEVEL_TRACE,
                                        PartnerClass + " " +
                                        LocalNode.Name + " " +
                                        "PartnerKey=" + PartnerRow.PartnerKey
                                        );

                    if (IsExistingPartner && (PartnerClass != PartnerRow.PartnerClass))
                    {
                        throw new Exception(String.Format("Error: Yml contains Existing Partner {0} with a different partner class {1}!",
                                                          PartnerRow.PartnerKey, PartnerClass));
                    }

                    PartnerRow.PartnerClass = PartnerClass;

                    if (PartnerClass == MPartnerConstants.PARTNERCLASS_FAMILY)
                    {
                        PFamilyRow FamilyRow;

                        if (IsExistingPartner)
                        {
                            AMainDS.Merge(PFamilyAccess.LoadByPrimaryKey(PartnerRow.PartnerKey, ATransaction));

                            AMainDS.PFamily.DefaultView.RowFilter = String.Format("{0} = '{1}'",
                                                                                  PFamilyTable.GetPartnerKeyDBName(),
                                                                                  PartnerRow.PartnerKey);
                            FamilyRow = (PFamilyRow)AMainDS.PFamily.DefaultView[0].Row;
                        }
                        else
                        {
                            FamilyRow               = AMainDS.PFamily.NewRowTyped();
                            FamilyRow.PartnerKey    = PartnerRow.PartnerKey;
                            PartnerRow.PartnerClass = MPartnerConstants.PARTNERCLASS_FAMILY;
                            AMainDS.PFamily.Rows.Add(FamilyRow);
                        }

                        FamilyRow.FamilyName = TYml2Xml.GetAttributeRecursive(LocalNode, "LastName");
                        FamilyRow.FirstName  = TYml2Xml.GetAttribute(LocalNode, "FirstName");
                        FamilyRow.Title      = TYml2Xml.GetAttribute(LocalNode, "Title");

                        if (TYml2Xml.HasAttribute(LocalNode, "CreatedAt"))
                        {
                            FamilyRow.DateCreated = Convert.ToDateTime(TYml2Xml.GetAttribute(LocalNode, "CreatedAt"));
                        }

                        PartnerRow.AddresseeTypeCode = MPartnerConstants.PARTNERCLASS_FAMILY;

                        PartnerRow.PartnerShortName =
                            Calculations.DeterminePartnerShortName(FamilyRow.FamilyName, FamilyRow.Title, FamilyRow.FirstName);
                    }

                    if (PartnerClass == MPartnerConstants.PARTNERCLASS_PERSON)
                    {
                        PPersonRow PersonRow;

                        if (IsExistingPartner)
                        {
                            AMainDS.Merge(PPersonAccess.LoadByPrimaryKey(PartnerRow.PartnerKey, ATransaction));

                            AMainDS.PPerson.DefaultView.RowFilter = String.Format("{0} = '{1}'",
                                                                                  PPersonTable.GetPartnerKeyDBName(),
                                                                                  PartnerRow.PartnerKey);
                            PersonRow = (PPersonRow)AMainDS.PPerson.DefaultView[0].Row;
                        }
                        else
                        {
                            PersonRow            = AMainDS.PPerson.NewRowTyped();
                            PersonRow.PartnerKey = PartnerRow.PartnerKey;
                            AMainDS.PPerson.Rows.Add(PersonRow);
                        }

                        PersonRow.FamilyName = TYml2Xml.GetAttributeRecursive(LocalNode, "LastName");
                        PersonRow.FirstName  = TYml2Xml.GetAttribute(LocalNode, "FirstName");
                        PersonRow.Title      = TYml2Xml.GetAttribute(LocalNode, "Title");

                        if (TYml2Xml.HasAttribute(LocalNode, "CreatedAt"))
                        {
                            PersonRow.DateCreated = Convert.ToDateTime(TYml2Xml.GetAttribute(LocalNode, "CreatedAt"));
                        }

                        // PersonRow.Sp
                        PartnerRow.PartnerShortName =
                            Calculations.DeterminePartnerShortName(PersonRow.FamilyName, PersonRow.Title, PersonRow.FirstName);
                    }
                    else if (PartnerClass == MPartnerConstants.PARTNERCLASS_ORGANISATION)
                    {
                        POrganisationRow OrganisationRow;

                        if (IsExistingPartner)
                        {
                            AMainDS.Merge(POrganisationAccess.LoadByPrimaryKey(PartnerRow.PartnerKey, ATransaction));

                            AMainDS.POrganisation.DefaultView.RowFilter = String.Format("{0} = '{1}'",
                                                                                        POrganisationTable.GetPartnerKeyDBName(),
                                                                                        PartnerRow.PartnerKey);
                            OrganisationRow = (POrganisationRow)AMainDS.POrganisation.DefaultView[0].Row;
                        }
                        else
                        {
                            OrganisationRow            = AMainDS.POrganisation.NewRowTyped();
                            OrganisationRow.PartnerKey = PartnerRow.PartnerKey;
                            AMainDS.POrganisation.Rows.Add(OrganisationRow);
                        }

                        OrganisationRow.OrganisationName = TYml2Xml.GetAttributeRecursive(LocalNode, "Name");

                        PartnerRow.PartnerShortName = OrganisationRow.OrganisationName;
                    }
                    else if (PartnerClass == MPartnerConstants.PARTNERCLASS_UNIT)
                    {
                        PUnitRow UnitRow;

                        if (IsExistingPartner)
                        {
                            AMainDS.Merge(PUnitAccess.LoadByPrimaryKey(PartnerRow.PartnerKey, ATransaction));

                            AMainDS.PUnit.DefaultView.RowFilter = String.Format("{0} = '{1}'",
                                                                                PUnitTable.GetPartnerKeyDBName(),
                                                                                PartnerRow.PartnerKey);
                            UnitRow = (PUnitRow)AMainDS.PUnit.DefaultView[0].Row;
                        }
                        else
                        {
                            UnitRow            = AMainDS.PUnit.NewRowTyped();
                            UnitRow.PartnerKey = PartnerRow.PartnerKey;
                            AMainDS.PUnit.Rows.Add(UnitRow);
                        }

                        UnitRow.UnitTypeCode = TYml2Xml.GetAttributeRecursive(LocalNode, "UnitTypeCode");
                        UnitRow.UnitName     = TYml2Xml.GetAttributeRecursive(LocalNode, "Name");

                        if (PartnerRow.PartnerKey < -1)
                        {
                            throw new Exception("Invalid Partner Key or No Partner Key - and no proper handling implemented");
                            // from here...

                            /*
                             * AVerificationResult.Add(new TVerificationResult(
                             *  String.Format(Catalog.GetString("Importing Unit {0}"), UnitRow.UnitName),
                             *  Catalog.GetString("You need to provide a partner key for the unit"),
                             *  TResultSeverity.Resv_Critical));
                             */
                            // ...to here: throws Exception in case of a illegal import file?
                            // The above code must have a glitch
                        }

                        if (!TYml2Xml.HasAttribute(LocalNode, "ParentUnitKey"))
                        {
                            throw new Exception(
                                      "The currently being processed unit (PartnerKey " +
                                      PartnerRow.PartnerKey +
                                      ") requires a ParentUnitKey.");
                        }

                        Int64 ParentKey = Convert.ToInt64(TYml2Xml.GetAttributeRecursive(LocalNode, "ParentUnitKey"));
                        UmUnitStructureRow UnitStructureRow = null;

                        if (IsExistingPartner)
                        {
                            AMainDS.Merge(UmUnitStructureAccess.LoadViaPUnitChildUnitKey(PartnerRow.PartnerKey, ATransaction));

                            AMainDS.UmUnitStructure.DefaultView.RowFilter = String.Format("{0} = '{1}'",
                                                                                          UmUnitStructureTable.GetChildUnitKeyDBName(),
                                                                                          PartnerRow.PartnerKey);

                            if (AMainDS.UmUnitStructure.DefaultView.Count > 0)
                            {
                                UnitStructureRow = (UmUnitStructureRow)AMainDS.UmUnitStructure.DefaultView[0].Row;
                            }
                        }

                        if (UnitStructureRow == null)
                        {
                            UnitStructureRow = AMainDS.UmUnitStructure.NewRowTyped();
                            UnitStructureRow.ParentUnitKey = ParentKey;
                            UnitStructureRow.ChildUnitKey  = PartnerRow.PartnerKey;
                            AMainDS.UmUnitStructure.Rows.Add(UnitStructureRow);
                        }
                        else
                        {
                            UnitStructureRow.ParentUnitKey = ParentKey;
                            UnitStructureRow.ChildUnitKey  = PartnerRow.PartnerKey;
                        }

                        PartnerRow.PartnerShortName = UnitRow.UnitName;
                    }
                    else if (PartnerClass == MPartnerConstants.PARTNERCLASS_BANK)
                    {
                        PBankRow BankRow;

                        if (IsExistingPartner)
                        {
                            AMainDS.Merge(PBankAccess.LoadByPrimaryKey(PartnerRow.PartnerKey, ATransaction));

                            AMainDS.PBank.DefaultView.RowFilter = String.Format("{0} = '{1}'",
                                                                                PBankTable.GetPartnerKeyDBName(),
                                                                                PartnerRow.PartnerKey);
                            BankRow = (PBankRow)AMainDS.PBank.DefaultView[0].Row;
                        }
                        else
                        {
                            BankRow            = AMainDS.PBank.NewRowTyped();
                            BankRow.PartnerKey = PartnerRow.PartnerKey;
                            AMainDS.PBank.Rows.Add(BankRow);
                        }

                        BankRow.BranchName   = TYml2Xml.GetAttribute(LocalNode, "BranchName");
                        BankRow.BranchCode   = TYml2Xml.GetAttribute(LocalNode, "BranchCode");
                        BankRow.Bic          = TYml2Xml.GetAttribute(LocalNode, "BranchBic");
                        BankRow.EpFormatFile = TYml2Xml.GetAttribute(LocalNode, "EpFormatFile");

                        if (TYml2Xml.HasAttribute(LocalNode, "CreatedAt"))
                        {
                            BankRow.DateCreated = Convert.ToDateTime(TYml2Xml.GetAttribute(LocalNode, "CreatedAt"));
                        }
                    }
                    else
                    {
                        /*
                         * throw new Exception(
                         *  "Unknown Partner Class" +
                         *  TYml2Xml.GetAttributeRecursive(LocalNode, "class"));
                         */
                        // TODO AVerificationResult add failing problem: unknown partner class
                    }

                    PartnerRow.StatusCode = TYml2Xml.GetAttributeRecursive(LocalNode, "status");

                    // import special types
                    StringCollection SpecialTypes = StringHelper.StrSplit(TYml2Xml.GetAttributeRecursive(LocalNode, "SpecialTypes"), ",");

                    if (IsExistingPartner)
                    {
                        PPartnerTypeAccess.LoadViaPPartner(AMainDS, PartnerRow.PartnerKey, ATransaction);
                    }

                    foreach (string SpecialType in SpecialTypes)
                    {
                        PPartnerTypeRow PartnerTypeRow = null;
                        AMainDS.PPartnerType.DefaultView.RowFilter = String.Format("{0}={1} AND {2}='{3}'",
                                                                                   PPartnerTypeTable.GetPartnerKeyDBName(),
                                                                                   PartnerRow.PartnerKey,
                                                                                   PPartnerTypeTable.GetTypeCodeDBName(),
                                                                                   SpecialType
                                                                                   );

                        if (AMainDS.PPartnerType.DefaultView.Count > 0)
                        {
                            PartnerTypeRow = (PPartnerTypeRow)AMainDS.PPartnerType.DefaultView[0].Row;
                        }
                        else
                        {
                            PartnerTypeRow            = AMainDS.PPartnerType.NewRowTyped();
                            PartnerTypeRow.PartnerKey = PartnerRow.PartnerKey;
                            PartnerTypeRow.TypeCode   = SpecialType.Trim();
                            AMainDS.PPartnerType.Rows.Add(PartnerTypeRow);
                        }

                        // Check Partner type exists, or create it
                        bool TypeIsKnown = PTypeAccess.Exists(PartnerTypeRow.TypeCode, ATransaction);

                        if (!TypeIsKnown)
                        {
                            Int32 RowIdx = AMainDS.PType.DefaultView.Find(PartnerTypeRow.TypeCode); // I might have created it a second ago..

                            if (RowIdx < 0)
                            {
                                PTypeRow TypeRow = AMainDS.PType.NewRowTyped();
                                TypeRow.TypeCode        = PartnerTypeRow.TypeCode;
                                TypeRow.TypeDescription = "Created from YAML import";
                                AMainDS.PType.Rows.Add(TypeRow);
                            }
                        }
                    }

                    // import subscriptions
                    StringCollection Subscriptions = StringHelper.StrSplit(TYml2Xml.GetAttributeRecursive(LocalNode, "Subscriptions"), ",");

                    foreach (string publicationCode in Subscriptions)
                    {
                        PSubscriptionRow subscription = AMainDS.PSubscription.NewRowTyped();
                        subscription.PartnerKey          = PartnerRow.PartnerKey;
                        subscription.PublicationCode     = publicationCode.Trim();
                        subscription.ReasonSubsGivenCode = "FREE";
                        AMainDS.PSubscription.Rows.Add(subscription);
                    }

                    // import address
                    XmlNode addressNode = TYml2Xml.GetChild(LocalNode, "Address");

                    if ((addressNode == null) || (TYml2Xml.GetAttributeRecursive(addressNode, "Street").Length == 0))
                    {
                        if (!IsExistingPartner)
                        {
                            // add the empty location
                            PPartnerLocationRow partnerlocation = AMainDS.PPartnerLocation.NewRowTyped(true);
                            partnerlocation.SiteKey         = 0;
                            partnerlocation.PartnerKey      = PartnerRow.PartnerKey;
                            partnerlocation.DateEffective   = DateTime.Now;
                            partnerlocation.LocationType    = "HOME";
                            partnerlocation.SendMail        = false;
                            partnerlocation.EmailAddress    = TYml2Xml.GetAttributeRecursive(addressNode, "Email");
                            partnerlocation.TelephoneNumber = TYml2Xml.GetAttributeRecursive(addressNode, "Phone");
                            partnerlocation.MobileNumber    = TYml2Xml.GetAttributeRecursive(addressNode, "MobilePhone");
                            AMainDS.PPartnerLocation.Rows.Add(partnerlocation);
                        }
                    }
                    else
                    {
                        PLocationRow location = AMainDS.PLocation.NewRowTyped(true);
                        location.LocationKey = (AMainDS.PLocation.Rows.Count + 1) * -1;
                        location.SiteKey     = 0;

                        if (!TYml2Xml.HasAttributeRecursive(LocalNode, "Country"))
                        {
                            throw new Exception(Catalog.GetString("Missing Country Attribute"));
                        }

                        location.CountryCode = TYml2Xml.GetAttributeRecursive(addressNode, "Country");
                        location.StreetName  = TYml2Xml.GetAttributeRecursive(addressNode, "Street");
                        location.City        = TYml2Xml.GetAttributeRecursive(addressNode, "City");
                        location.PostalCode  = TYml2Xml.GetAttributeRecursive(addressNode, "PostCode");
                        AMainDS.PLocation.Rows.Add(location);

                        PPartnerLocationRow partnerlocation = AMainDS.PPartnerLocation.NewRowTyped(true);
                        partnerlocation.SiteKey         = 0;
                        partnerlocation.LocationKey     = location.LocationKey;
                        partnerlocation.PartnerKey      = PartnerRow.PartnerKey;
                        partnerlocation.SendMail        = true;
                        partnerlocation.DateEffective   = DateTime.Now;
                        partnerlocation.LocationType    = "HOME";
                        partnerlocation.EmailAddress    = TYml2Xml.GetAttributeRecursive(addressNode, "Email");
                        partnerlocation.TelephoneNumber = TYml2Xml.GetAttributeRecursive(addressNode, "Phone");
                        partnerlocation.MobileNumber    = TYml2Xml.GetAttributeRecursive(addressNode, "MobilePhone");
                        AMainDS.PPartnerLocation.Rows.Add(partnerlocation);
                    }

                    // import finance details (bank account number)
                    XmlNode financialDetailsNode = TYml2Xml.GetChild(LocalNode, "FinancialDetails");

                    ParseFinancialDetails(AMainDS, financialDetailsNode, PartnerRow.PartnerKey, ATransaction);
                }

                LocalNode = LocalNode.NextSibling;
            }
        }