/// <summary> /// Load all the data of a partner into a TDS /// </summary> public static PartnerImportExportTDS ExportPartner(Int64 APartnerKey) { PartnerImportExportTDS MainDS = new PartnerImportExportTDS(); TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.ReadCommitted); PPartnerAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction); PChurchAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction); PFamilyAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction); PPersonAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction); POrganisationAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction); PUnitAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction); PVenueAccess.LoadByPrimaryKey(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); PPartnerGiftDestinationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction); PInterestAccess.LoadAll(MainDS, 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); PmGeneralApplicationAccess.LoadViaPPersonPartnerKey(MainDS, APartnerKey, Transaction); PtApplicationTypeAccess.LoadAll(MainDS, Transaction); PmShortTermApplicationAccess.LoadViaPPerson(MainDS, APartnerKey, Transaction); PmYearProgramApplicationAccess.LoadViaPPerson(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); PcBuildingAccess.LoadViaPVenue(MainDS, APartnerKey, Transaction); PcRoomAccess.LoadViaPVenue(MainDS, APartnerKey, Transaction); DBAccess.GDBAccessObj.RollbackTransaction(); return(MainDS); }
private static PartnerDetails GetRecipient(Int64 APartnerKey) { if (RecipientList.ContainsKey(APartnerKey)) { return(RecipientList[APartnerKey]); } PartnerDetails Ret = new PartnerDetails(); PPartnerTable PartnerTbl = PPartnerAccess.LoadByPrimaryKey(APartnerKey, FTransaction); if (PartnerTbl.Rows.Count > 0) { PPartnerRow PartnerRow = PartnerTbl[0]; Ret.LastName = PartnerRow.PartnerShortName; 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 LocationRow; TLocationPK LocationKey = ServerCalculations.DetermineBestAddress(APartnerKey, out LocationRow); if (LocationKey.LocationKey != -1) { Ret.Email = LocationRow.EmailAddress; } } RecipientList.Add(APartnerKey, Ret); return(Ret); }
public static PartnerEditTDS GetPartnerDetails(Int64 APartnerKey, bool AWithAddressDetails, bool AWithSubscriptions, bool AWithRelationships) { PartnerEditTDS MainDS = new PartnerEditTDS(); TDBTransaction Transaction = null; DBAccess.GDBAccessObj.BeginAutoReadTransaction(IsolationLevel.ReadCommitted, 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; } if (AWithAddressDetails) { PPartnerLocationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction); PLocationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction); } if (AWithRelationships) { PPartnerRelationshipAccess.LoadViaPPartnerPartnerKey(MainDS, APartnerKey, Transaction); } if (AWithSubscriptions) { PSubscriptionAccess.LoadViaPPartnerPartnerKey(MainDS, APartnerKey, Transaction); } } }); return MainDS; }
public static PartnerEditTDS GetPartnerDetails(Int64 APartnerKey, bool AWithAddressDetails, bool AWithSubscriptions, bool AWithRelationships) { PartnerEditTDS MainDS = new PartnerEditTDS(); TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable); PPartnerAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction); if (MainDS.PPartner.Rows.Count == 0) { return(null); } 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; } if (AWithAddressDetails) { PPartnerLocationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction); PLocationAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction); } if (AWithRelationships) { PPartnerRelationshipAccess.LoadViaPPartnerPartnerKey(MainDS, APartnerKey, Transaction); } if (AWithSubscriptions) { PSubscriptionAccess.LoadViaPPartnerPartnerKey(MainDS, APartnerKey, Transaction); } DBAccess.GDBAccessObj.RollbackTransaction(); return(MainDS); }
/// <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 = new TDBTransaction(); DBAccess.ReadTransaction( 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); }
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 = null; DBAccess.GDBAccessObj.BeginAutoReadTransaction(IsolationLevel.ReadCommitted, 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) { 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); }
public static SponsorshipTDS GetChildDetails(Int64 APartnerKey, Int32 ALedgerNumber, bool AWithPhoto, out string ASponsorshipStatus) { SponsorshipTDS MainDS = new SponsorshipTDS(); TDBTransaction Transaction = new TDBTransaction(); DBAccess.ReadTransaction(ref Transaction, delegate { PPartnerAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction); PFamilyAccess.LoadByPrimaryKey(MainDS, APartnerKey, Transaction); PPartnerTypeAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction); PPartnerCommentAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction); PPartnerReminderAccess.LoadViaPPartner(MainDS, APartnerKey, Transaction); if (!AWithPhoto && (MainDS.PFamily.Rows.Count == 1)) { MainDS.PFamily[0].Photo = ""; } int SponsorshipBatchNumber = GetRecurringGiftBatchForSponsorship(ALedgerNumber, Transaction); if (SponsorshipBatchNumber > -1) { ARecurringGiftBatchAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, SponsorshipBatchNumber, Transaction); ARecurringGiftAccess.LoadViaARecurringGiftBatch(MainDS, ALedgerNumber, SponsorshipBatchNumber, Transaction); ARecurringGiftDetailAccess.LoadViaARecurringGiftBatch(MainDS, ALedgerNumber, SponsorshipBatchNumber, Transaction); GiftBatchTDS GiftDS = new GiftBatchTDS(); TGiftTransactionWebConnector.LoadGiftDonorRelatedData(GiftDS, true, ALedgerNumber, SponsorshipBatchNumber, Transaction); for (int i = 0; i < MainDS.ARecurringGiftDetail.Count;) { SponsorshipTDSARecurringGiftDetailRow gdr = MainDS.ARecurringGiftDetail[i]; // drop all recurring gift details, that are not related to this child (RecipientKey) if (gdr.RecipientKey != APartnerKey) { MainDS.ARecurringGiftDetail.Rows.RemoveAt(i); } else { i++; // set the donor key from the appropriate recurring gift MainDS.ARecurringGift.DefaultView.RowFilter = String.Format("{0} = {1}", ARecurringGiftTable.GetGiftTransactionNumberDBName(), gdr.GiftTransactionNumber); // there should be only one row foreach (DataRowView drv in MainDS.ARecurringGift.DefaultView) { ARecurringGiftRow recurrGiftRow = (ARecurringGiftRow)drv.Row; gdr.DonorKey = recurrGiftRow.DonorKey; PPartnerRow donorRow = (PPartnerRow)GiftDS.DonorPartners.Rows.Find(recurrGiftRow.DonorKey); gdr.DonorName = donorRow.PartnerShortName; gdr.CurrencyCode = MainDS.ARecurringGiftBatch[0].CurrencyCode; } } } // drop all unrelated gift rows, that don't have a detail for this child for (int i = 0; i < MainDS.ARecurringGift.Count;) { ARecurringGiftRow gr = MainDS.ARecurringGift[0]; MainDS.ARecurringGiftDetail.DefaultView.RowFilter = String.Format("{0} = {1}", ARecurringGiftDetailTable.GetGiftTransactionNumberDBName(), gr.GiftTransactionNumber); if (MainDS.ARecurringGiftDetail.DefaultView.Count == 0) { MainDS.ARecurringGift.Rows.RemoveAt(i); } else { i++; } } } }); bool isSponsoredChild = false; ASponsorshipStatus = "[N/A]"; foreach (PPartnerTypeRow type in MainDS.PPartnerType.Rows) { if (type.TypeCode == "CHILDREN_HOME" || type.TypeCode == "HOME_BASED" || type.TypeCode == "BOARDING_SCHOOL" || type.TypeCode == "PREVIOUS_CHILD" || type.TypeCode == "CHILD_DIED") { isSponsoredChild = true; } ASponsorshipStatus = type.TypeCode; } if (!isSponsoredChild) { return(new SponsorshipTDS()); } return(MainDS); }
public static String BuildAddressBlock(String AAddressLayoutBlock, TFormDataPartner AFormData, TPartnerClass APartnerClass, TDBTransaction ATransaction) { String AddressBlock = ""; List <String> AddressTokenList = new List <String>(); String AddressLineText = ""; String AddressLineTokenText = ""; Boolean PrintAnyway = false; Boolean CapsOn = false; Boolean UseContact = false; String SpacePlaceholder = ""; PPersonTable PersonTable; PPersonRow PersonRow = null; PFamilyTable FamilyTable; PFamilyRow FamilyRow = null; Int64 ContactPartnerKey = 0; AddressTokenList = BuildTokenListFromAddressLayoutBlock(AAddressLayoutBlock); // initialize values AddressLineText = ""; PrintAnyway = false; foreach (String AddressLineToken in AddressTokenList) { switch (AddressLineToken) { case "[[TitleAndSpace]]": case "[[FirstNameAndSpace]]": case "[[FirstInitialAndSpace]]": case "[[LastNameAndSpace]]": SpacePlaceholder = " "; break; default: SpacePlaceholder = ""; break; } switch (AddressLineToken) { case "[[AcademicTitle]]": if (UseContact) { if (PersonRow != null) { AddressLineText += ConvertIfUpperCase(PersonRow.AcademicTitle, CapsOn); } } else { if (AFormData.GetType() == typeof(TFormDataPerson)) { AddressLineText += ConvertIfUpperCase(((TFormDataPerson)AFormData).AcademicTitle, CapsOn); } } break; case "[[AddresseeType]]": AddressLineText += ConvertIfUpperCase(AFormData.AddresseeType, CapsOn); break; case "[[Address3]]": AddressLineText += ConvertIfUpperCase(AFormData.Address3, CapsOn); break; case "[[CapsOn]]": CapsOn = true; break; case "[[CapsOff]]": CapsOn = false; break; case "[[City]]": AddressLineText += ConvertIfUpperCase(AFormData.City, CapsOn); break; case "[[CountryName]]": AddressLineText += ConvertIfUpperCase(AFormData.CountryName, CapsOn); break; case "[[CountryInLocalLanguage]]": AddressLineText += ConvertIfUpperCase(AFormData.CountryInLocalLanguage, CapsOn); break; case "[[County]]": AddressLineText += ConvertIfUpperCase(AFormData.County, CapsOn); break; case "[[UseContact]]": /* Get the person or family record that is acting as the contact * only applicable to churches and organisations. */ switch (APartnerClass) { case TPartnerClass.CHURCH: PChurchTable ChurchTable; PChurchRow ChurchRow; ChurchTable = PChurchAccess.LoadByPrimaryKey(Convert.ToInt64(AFormData.PartnerKey), ATransaction); if (ChurchTable.Count > 0) { ChurchRow = (PChurchRow)ChurchTable.Rows[0]; if (!ChurchRow.IsContactPartnerKeyNull()) { ContactPartnerKey = ChurchRow.ContactPartnerKey; } } break; case TPartnerClass.ORGANISATION: POrganisationTable OrganisationTable; POrganisationRow OrganisationRow; OrganisationTable = POrganisationAccess.LoadByPrimaryKey(Convert.ToInt64(AFormData.PartnerKey), ATransaction); if (OrganisationTable.Count > 0) { OrganisationRow = (POrganisationRow)OrganisationTable.Rows[0]; if (!OrganisationRow.IsContactPartnerKeyNull()) { ContactPartnerKey = OrganisationRow.ContactPartnerKey; } } break; default: ContactPartnerKey = 0; break; } if (ContactPartnerKey > 0) { PersonTable = PPersonAccess.LoadByPrimaryKey(ContactPartnerKey, ATransaction); if (PersonTable.Count > 0) { PersonRow = (PPersonRow)PersonTable.Rows[0]; } else { FamilyTable = PFamilyAccess.LoadByPrimaryKey(ContactPartnerKey, ATransaction); if (FamilyTable.Count > 0) { FamilyRow = (PFamilyRow)FamilyTable.Rows[0]; } } } UseContact = true; break; case "[[CountryCode]]": AddressLineText += ConvertIfUpperCase(AFormData.CountryCode, CapsOn); break; case "[[Decorations]]": if (UseContact) { if (PersonRow != null) { AddressLineText += ConvertIfUpperCase(PersonRow.Decorations, CapsOn); } } else { if (AFormData.GetType() == typeof(TFormDataPerson)) { AddressLineText += ConvertIfUpperCase(((TFormDataPerson)AFormData).Decorations, CapsOn); } } break; case "[[FirstName]]": case "[[FirstNameAndSpace]]": AddressLineTokenText = ""; if (UseContact) { if (PersonRow != null) { AddressLineTokenText = ConvertIfUpperCase(PersonRow.FirstName, CapsOn); } else if (FamilyRow != null) { AddressLineTokenText = ConvertIfUpperCase(FamilyRow.FirstName, CapsOn); } } else { AddressLineTokenText = ConvertIfUpperCase(AFormData.FirstName, CapsOn); } if ((AddressLineTokenText != null) && (AddressLineTokenText.Length > 0)) { AddressLineText += AddressLineTokenText + SpacePlaceholder; } break; case "[[FirstInitial]]": case "[[FirstInitialAndSpace]]": AddressLineTokenText = ""; if (UseContact) { if (PersonRow != null) { if (PersonRow.FirstName.Length > 0) { AddressLineTokenText = ConvertIfUpperCase(PersonRow.FirstName.Substring(0, 1), CapsOn); } } else if (FamilyRow != null) { if (PersonRow.FirstName.Length > 0) { AddressLineTokenText = ConvertIfUpperCase(FamilyRow.FirstName.Substring(0, 1), CapsOn); } } } else { if (AFormData.FirstName.Length > 0) { AddressLineTokenText = ConvertIfUpperCase(AFormData.FirstName.Substring(0, 1), CapsOn); } } if ((AddressLineTokenText != null) && (AddressLineTokenText.Length > 0)) { AddressLineText += AddressLineTokenText + SpacePlaceholder; } break; case "[[LastName]]": case "[[LastNameAndSpace]]": AddressLineTokenText = ""; if (UseContact) { if (PersonRow != null) { AddressLineTokenText = ConvertIfUpperCase(PersonRow.FamilyName, CapsOn); } else if (FamilyRow != null) { AddressLineTokenText = ConvertIfUpperCase(FamilyRow.FamilyName, CapsOn); } } else { AddressLineTokenText = ConvertIfUpperCase(AFormData.LastName, CapsOn); } if ((AddressLineTokenText != null) && (AddressLineTokenText.Length > 0)) { AddressLineText += AddressLineTokenText + SpacePlaceholder; } break; case "[[Address1]]": AddressLineText += ConvertIfUpperCase(AFormData.Address1, CapsOn); break; case "[[MiddleName]]": if (UseContact) { if (PersonRow != null) { AddressLineText += ConvertIfUpperCase(PersonRow.MiddleName1, CapsOn); } } else { if (AFormData.GetType() == typeof(TFormDataPerson)) { AddressLineText += ConvertIfUpperCase(((TFormDataPerson)AFormData).MiddleName, CapsOn); } } break; case "[[Org/Church]]": /* if the contact person is being printed then might still want the * Organisation or Church name printed. This does it but only if there * is a valid contact. */ if (UseContact) { AddressLineText += ConvertIfUpperCase(AFormData.ShortName, CapsOn); } break; case "[[PartnerKey]]": AddressLineText += ConvertIfUpperCase(AFormData.PartnerKey, CapsOn); break; case "[[ShortName]]": AddressLineText += ConvertIfUpperCase(AFormData.ShortName, CapsOn); break; case "[[LocalName]]": if (AFormData.LocalName != "") { AddressLineText += ConvertIfUpperCase(AFormData.LocalName, CapsOn); } else { AddressLineText += ConvertIfUpperCase(AFormData.ShortName, CapsOn); } break; case "[[PostalCode]]": AddressLineText += ConvertIfUpperCase(AFormData.PostalCode, CapsOn); break; case "[[Enclosures]]": AddressLineText += AFormData.Enclosures; break; case "[[MailingCode]]": AddressLineText += AFormData.MailingCode; break; case "[[Tab]]": AddressLineText += "\t"; break; case "[[Space]]": AddressLineText += " "; break; case "[[AddressStreet2]]": AddressLineText += ConvertIfUpperCase(AFormData.AddressStreet2, CapsOn); break; case "[[Title]]": case "[[TitleAndSpace]]": AddressLineTokenText = ConvertIfUpperCase(AFormData.Title, CapsOn); if ((AddressLineTokenText != null) && (AddressLineTokenText.Length > 0)) { AddressLineText += AddressLineTokenText + SpacePlaceholder; } break; case "[[NoSuppress]]": PrintAnyway = true; break; case "[[LocationKey]]": AddressLineText += AFormData.LocationKey; break; case "[[LineFeed]]": // only add line if not empty and not suppressed if (PrintAnyway || (!PrintAnyway && (AddressLineText.Trim() != ""))) { AddressBlock += AddressLineText + "\r\n"; } // reset values AddressLineText = ""; PrintAnyway = false; break; default: AddressLineText += ConvertIfUpperCase(AddressLineToken, CapsOn); break; } } // this is only for last line if there was no line feed: // only add line if not empty and not suppressed if (PrintAnyway || (!PrintAnyway && (AddressLineText.Trim() != ""))) { AddressBlock += AddressLineText + "\r\n"; } // or just get the element list from cached table (since we need to get different ones depending on country) return(AddressBlock); }
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); }
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)); }
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); }
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; } }