/// <summary> /// Create a Partner and a Person having this FamilyKey, living at this address. /// </summary> /// <param name="AFamilyKey"></param> /// <param name="ALocationKey"></param> /// <param name="ANode"></param> /// <param name="AMainDS"></param> /// <param name="ATransaction"></param> private static Int64 CreateNewPerson(Int64 AFamilyKey, int ALocationKey, XmlNode ANode, ref PartnerImportExportTDS AMainDS, TDBTransaction ATransaction) { AMainDS.PFamily.DefaultView.RowFilter = String.Format("{0}={1}", PFamilyTable.GetPartnerKeyDBName(), AFamilyKey); PFamilyRow FamilyRow = (PFamilyRow)AMainDS.PFamily.DefaultView[0].Row; AMainDS.PPartner.DefaultView.RowFilter = String.Format("{0}={1}", PPartnerTable.GetPartnerKeyDBName(), AFamilyKey); PPartnerRow PartnerRow = (PPartnerRow)AMainDS.PPartner.DefaultView[0].Row; PPartnerRow newPartner = AMainDS.PPartner.NewRowTyped(); AMainDS.PPartner.Rows.Add(newPartner); newPartner.PartnerKey = (AMainDS.PPartner.Rows.Count + 1) * -1; newPartner.PartnerClass = MPartnerConstants.PARTNERCLASS_PERSON; newPartner.AddresseeTypeCode = PartnerRow.AddresseeTypeCode; newPartner.PartnerShortName = PartnerRow.PartnerShortName; newPartner.LanguageCode = PartnerRow.LanguageCode; newPartner.Comment = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_NOTES); newPartner.AcquisitionCode = PartnerRow.AcquisitionCode; newPartner.StatusCode = MPartnerConstants.PARTNERSTATUS_ACTIVE; PPersonRow newPerson = AMainDS.PPerson.NewRowTyped(); AMainDS.PPerson.Rows.Add(newPerson); newPerson.PartnerKey = newPartner.PartnerKey; newPerson.FamilyKey = AFamilyKey; // When this record is imported, newPerson.FamilyId must be unique for this family! newPerson.FirstName = FamilyRow.FirstName; newPerson.FamilyName = FamilyRow.FamilyName; newPerson.Title = FamilyRow.Title; newPerson.Gender = GetGenderCode(ANode); newPerson.MaritalStatus = FamilyRow.MaritalStatus; PPartnerLocationRow newPartnerLocation = AMainDS.PPartnerLocation.NewRowTyped(); AMainDS.PPartnerLocation.Rows.Add(newPartnerLocation); newPartnerLocation.LocationKey = ALocationKey; // This person lives at the same address as the family. newPartnerLocation.SiteKey = 0; newPartnerLocation.PartnerKey = newPartner.PartnerKey; newPartnerLocation.DateEffective = DateTime.Now.Date; newPartnerLocation.LocationType = MPartnerConstants.LOCATIONTYPE_HOME; newPartnerLocation.SendMail = true; newPartnerLocation["p_email_address_c"] = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_EMAIL); // Important: Do not use 'newPartnerLocation.EmailAddress' as this Column will get removed once Contact Details conversion is finished! newPartnerLocation["p_telephone_number_c"] = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_PHONE); // Important: Do not use 'newPartnerLocation.TelephoneNumber' as this Column will get removed once Contact Details conversion is finished! newPartnerLocation["p_mobile_number_c"] = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_MOBILEPHONE); // Important: Do not use 'newPartnerLocation.MobileNumber' as this Column will get removed once Contact Details conversion is finished! AddVerificationResult("Person Record Created.", TResultSeverity.Resv_Status); return(newPerson.PartnerKey); }
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); }
private void ApplySecurity() { if (!UserInfo.GUserInfo.IsTableAccessOK(TTableAccessPermission.tapMODIFY, PPartnerTable.GetTableDBName())) { // need to disable all Fields that are DataBound to p_partner. This continues in the switch statments! // timop: I have disabled all controls. usually you have p_partner modify permissions, or none CustomEnablingDisabling.DisableControlGroup(pnlContent); } switch (SharedTypes.PartnerClassStringToEnum(FPartnerClass)) { case TPartnerClass.PERSON: if (!UserInfo.GUserInfo.IsTableAccessOK(TTableAccessPermission.tapMODIFY, PPersonTable.GetTableDBName())) { // need to disable all Fields that are DataBound to p_partner CustomEnablingDisabling.DisableControl(pnlPerson, cmbPersonAddresseeTypeCode); CustomEnablingDisabling.DisableControl(pnlPerson, chkPersonNoSolicitations); // need to disable all Fields that are DataBound to p_person CustomEnablingDisabling.DisableControlGroup(pnlPerson); cmbPersonAddresseeTypeCode.Focus(); } break; case TPartnerClass.FAMILY: if (!UserInfo.GUserInfo.IsTableAccessOK(TTableAccessPermission.tapMODIFY, PFamilyTable.GetTableDBName())) { // need to disable all Fields that are DataBound to p_partner CustomEnablingDisabling.DisableControl(pnlFamily, cmbFamilyAddresseeTypeCode); CustomEnablingDisabling.DisableControl(pnlFamily, chkFamilyNoSolicitations); // need to disable all Fields that are DataBound to p_family CustomEnablingDisabling.DisableControlGroup(pnlFamily); cmbFamilyAddresseeTypeCode.Focus(); } break; case TPartnerClass.CHURCH: if (!UserInfo.GUserInfo.IsTableAccessOK(TTableAccessPermission.tapMODIFY, PChurchTable.GetTableDBName())) { // need to disable all Fields that are DataBound to p_partner CustomEnablingDisabling.DisableControl(pnlOther2ndLine, cmbOtherAddresseeTypeCode); CustomEnablingDisabling.DisableControl(pnlOther2ndLine, chkOtherNoSolicitations); // need to disable all Fields that are DataBound to p_church CustomEnablingDisabling.DisableControlGroup(pnlOther2ndLine); cmbOtherAddresseeTypeCode.Focus(); } break; case TPartnerClass.ORGANISATION: if (!UserInfo.GUserInfo.IsTableAccessOK(TTableAccessPermission.tapMODIFY, POrganisationTable.GetTableDBName())) { // need to disable all Fields that are DataBound to p_partner CustomEnablingDisabling.DisableControl(pnlOther2ndLine, cmbOtherAddresseeTypeCode); CustomEnablingDisabling.DisableControl(pnlOther2ndLine, chkOtherNoSolicitations); // need to disable all Fields that are DataBound to p_organisation CustomEnablingDisabling.DisableControlGroup(pnlOther2ndLine); cmbOtherAddresseeTypeCode.Focus(); } break; case TPartnerClass.UNIT: if (!UserInfo.GUserInfo.IsTableAccessOK(TTableAccessPermission.tapMODIFY, PUnitTable.GetTableDBName())) { // need to disable all Fields that are DataBound to p_partner CustomEnablingDisabling.DisableControl(pnlOther2ndLine, cmbOtherAddresseeTypeCode); CustomEnablingDisabling.DisableControl(pnlOther2ndLine, chkOtherNoSolicitations); // need to disable all Fields that are DataBound to p_unit CustomEnablingDisabling.DisableControlGroup(pnlOther2ndLine); cmbOtherAddresseeTypeCode.Focus(); } break; case TPartnerClass.BANK: if (!UserInfo.GUserInfo.IsTableAccessOK(TTableAccessPermission.tapMODIFY, PBankTable.GetTableDBName())) { // need to disable all Fields that are DataBound to p_partner CustomEnablingDisabling.DisableControl(pnlOther2ndLine, cmbOtherAddresseeTypeCode); CustomEnablingDisabling.DisableControl(pnlOther2ndLine, chkOtherNoSolicitations); // need to disable all Fields that are DataBound to p_bank CustomEnablingDisabling.DisableControlGroup(pnlOther2ndLine); cmbOtherAddresseeTypeCode.Focus(); } break; case TPartnerClass.VENUE: if (!UserInfo.GUserInfo.IsTableAccessOK(TTableAccessPermission.tapMODIFY, PVenueTable.GetTableDBName())) { // need to disable all Fields that are DataBound to p_partner CustomEnablingDisabling.DisableControl(pnlOther2ndLine, cmbOtherAddresseeTypeCode); CustomEnablingDisabling.DisableControl(pnlOther2ndLine, chkOtherNoSolicitations); // need to disable all Fields that are DataBound to p_venue CustomEnablingDisabling.DisableControlGroup(pnlOther2ndLine); cmbOtherAddresseeTypeCode.Focus(); } break; default: MessageBox.Show(String.Format(Catalog.GetString("Unrecognised Partner Class '{0}'!"), FPartnerClass)); break; } }
/// arrange the panels and controls according to the partner class public void InitialiseUserControl() { FIgnorePartnerStatusChange = false; // Set up ToolTip this.components = new System.ComponentModel.Container(); FTipMain = new System.Windows.Forms.ToolTip(this.components); FTipMain.AutoPopDelay = 4000; FTipMain.InitialDelay = 500; FTipMain.ReshowDelay = 100; BuildValidationControlsDict(); // Ensure that the Worker Field Panel (and thus the Button on it) always comes last in the Tab Order pnlWorkerField.TabIndex = 999; #region Show fields according to Partner Class txtPartnerKey.PartnerClass = FPartnerClass; switch (SharedTypes.PartnerClassStringToEnum(FPartnerClass)) { case TPartnerClass.PERSON: pnlPerson.Visible = true; pnlWorkerField.Visible = true; pnlPerson2ndLine.Visible = true; // Set ToolTips in addition to StatusBar texts for fields to make it clearer what to fill in there... FTipMain.SetToolTip(this.txtPersonTitle, PPersonTable.GetTitleHelp()); FTipMain.SetToolTip(this.txtPersonFirstName, PPersonTable.GetFirstNameHelp()); FTipMain.SetToolTip(this.txtPersonMiddleName, PPersonTable.GetMiddleName1Help()); FTipMain.SetToolTip(this.txtPersonFamilyName, PPersonTable.GetFamilyNameHelp()); txtPersonTitle.TextChanged += new EventHandler(OnAnyDataColumnChanging); txtPersonFirstName.TextChanged += new EventHandler(OnAnyDataColumnChanging); txtPersonMiddleName.TextChanged += new EventHandler(OnAnyDataColumnChanging); txtPersonFamilyName.TextChanged += new EventHandler(OnAnyDataColumnChanging); this.cmbPersonGender.SelectedValueChanged += new System.EventHandler(this.CmbPersonGender_SelectedValueChanged); txtPartnerClass.BackColor = TCommonControlsHelper.PartnerClassPERSONColour; // Ensure that the Text in the first TextBox isn't all selected when the Form is brought up txtPersonTitle.SelectionStart = 0; break; case TPartnerClass.FAMILY: pnlFamily.Visible = true; pnlWorkerField.Visible = true; pnlFamily2ndLine.Visible = true; // Set ToolTips in addition to StatusBar texts for fields to make it clearer what to fill in there... FTipMain.SetToolTip(this.txtFamilyTitle, PFamilyTable.GetTitleHelp()); FTipMain.SetToolTip(this.txtFamilyFirstName, PFamilyTable.GetFirstNameHelp()); FTipMain.SetToolTip(this.txtFamilyFamilyName, PFamilyTable.GetFamilyNameHelp()); txtFamilyTitle.TextChanged += new EventHandler(OnAnyDataColumnChanging); txtFamilyFirstName.TextChanged += new EventHandler(OnAnyDataColumnChanging); txtFamilyFamilyName.TextChanged += new EventHandler(OnAnyDataColumnChanging); // Ensure that the Text in the first TextBox isn't all selected when the Form is brought up txtFamilyTitle.SelectionStart = 0; break; case TPartnerClass.CHURCH: pnlChurch.Visible = true; pnlOther2ndLine.Visible = true; txtChurchName.TextChanged += new EventHandler(OnAnyDataColumnChanging); // Ensure that the Text in the first TextBox isn't all selected when the Form is brought up txtChurchName.SelectionStart = 0; break; case TPartnerClass.ORGANISATION: pnlOrganisation.Visible = true; pnlOther2ndLine.Visible = true; txtOrganisationName.TextChanged += new EventHandler(OnAnyDataColumnChanging); // Ensure that the Text in the first TextBox isn't all selected when the Form is brought up txtOrganisationName.SelectionStart = 0; break; case TPartnerClass.UNIT: pnlUnit.Visible = true; pnlOther2ndLine.Visible = true; txtUnitName.TextChanged += new EventHandler(OnAnyDataColumnChanging); FMainDS.PUnit.ColumnChanging += new DataColumnChangeEventHandler(OnUnitDataColumnChanging); // Ensure that the Text in the first TextBox isn't all selected when the Form is brought up txtUnitName.SelectionStart = 0; break; case TPartnerClass.BANK: pnlBank.Visible = true; pnlOther2ndLine.Visible = true; txtBranchName.TextChanged += new EventHandler(OnAnyDataColumnChanging); // Ensure that the Text in the first TextBox isn't all selected when the Form is brought up txtBranchName.SelectionStart = 0; break; case TPartnerClass.VENUE: pnlVenue.Visible = true; pnlOther2ndLine.Visible = true; txtVenueName.TextChanged += new EventHandler(OnAnyDataColumnChanging); // Ensure that the Text in the first TextBox isn't all selected when the Form is brought up txtVenueName.SelectionStart = 0; break; default: MessageBox.Show(String.Format(Catalog.GetString("Unrecognised Partner Class '{0}'!"), FPartnerClass)); break; } #endregion }
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); }
/// <summary> /// return an XmlDocument with all partner info; /// the partners are grouped by class, country, status, and sitekey /// </summary> /// <returns></returns> public static string ExportPartners() { PartnerEditTDS MainDS = new PartnerEditTDS(); LoadDataFromDB(ref MainDS); // Group partners into categories. // // A partner's category is defined by his: class, country, status, and sitekey // It is stored as a string e.g. "FAMILY,DE,ACTIVE,0". // SortedList <string, List <long> > PartnerCategories = GroupPartnersIntoCategories(MainDS); // create XML structure for each category XmlDocument PartnerData = TYml2Xml.CreateXmlDocument(); XmlNode rootNode = PartnerData.FirstChild.NextSibling; Int32 groupCounter = 0; foreach (string category in PartnerCategories.Keys) { // get category data groupCounter++; XmlElement groupNode = PartnerData.CreateElement("PartnerGroup" + groupCounter.ToString()); rootNode.AppendChild(groupNode); Int32 partnerCounter = 0; string[] categoryDetails = category.Split(new char[] { ',' }); // may want to skip the categories with sitekey = -1 // right now, we still export them and ignore the partners 0 and 1000000 later groupNode.SetAttribute("class", categoryDetails[0]); groupNode.SetAttribute("Country", categoryDetails[1]); groupNode.SetAttribute("status", categoryDetails[2]); groupNode.SetAttribute("SiteKey", categoryDetails[3]); List <long> partnerKeys = PartnerCategories[category]; foreach (long partnerKey in partnerKeys) { if ((partnerKey != 0) && (partnerKey != 1000000)) // skip organization root and the 0 when exporting { MainDS.PPartner.DefaultView.RowFilter = PPartnerTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); PPartnerRow partnerRow = (PPartnerRow)MainDS.PPartner.DefaultView[0].Row; PFamilyRow familyRow = null; if (partnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_FAMILY) { MainDS.PFamily.DefaultView.RowFilter = PFamilyTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); familyRow = (PFamilyRow)MainDS.PFamily.DefaultView[0].Row; } PPersonRow personRow = null; if (partnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_PERSON) { MainDS.PPerson.DefaultView.RowFilter = PPersonTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); personRow = (PPersonRow)MainDS.PPerson.DefaultView[0].Row; } POrganisationRow organisationRow = null; if (partnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_ORGANISATION) { MainDS.POrganisation.DefaultView.RowFilter = POrganisationTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); organisationRow = (POrganisationRow)MainDS.POrganisation.DefaultView[0].Row; } PUnitRow unitRow = null; UmUnitStructureRow unitStructureRow = null; if (partnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_UNIT) { MainDS.PUnit.DefaultView.RowFilter = PUnitTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); unitRow = (PUnitRow)MainDS.PUnit.DefaultView[0].Row; MainDS.UmUnitStructure.DefaultView.RowFilter = UmUnitStructureTable.GetChildUnitKeyDBName() + " = " + partnerKey.ToString(); long numParents = MainDS.UmUnitStructure.DefaultView.Count; if (numParents == 1) { unitStructureRow = (UmUnitStructureRow)MainDS.UmUnitStructure.DefaultView[0].Row; } else { throw new Exception( "Units must have exactly one ParentUnit. " + "The unit with partnerKey " + partnerKey.ToString() + " has " + numParents.ToString() + "."); } } PBankRow BankRow = null; if (partnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_BANK) { MainDS.PBank.DefaultView.RowFilter = PBankTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); BankRow = (PBankRow)MainDS.PBank.DefaultView[0].Row; } partnerCounter++; XmlElement partnerNode = PartnerData.CreateElement("Partner" + partnerCounter.ToString()); groupNode.AppendChild(partnerNode); partnerNode.SetAttribute("PartnerKey", partnerRow.PartnerKey.ToString()); //groupNode.SetAttribute("ShortName", partnerRow.PartnerShortName.ToString()); if (personRow != null) { partnerNode.SetAttribute("FirstName", personRow.FirstName.ToString()); partnerNode.SetAttribute("LastName", personRow.FamilyName.ToString()); partnerNode.SetAttribute("Title", personRow.Title.ToString()); } else if (familyRow != null) { partnerNode.SetAttribute("FirstName", familyRow.FirstName.ToString()); partnerNode.SetAttribute("LastName", familyRow.FamilyName.ToString()); partnerNode.SetAttribute("Title", familyRow.Title.ToString()); } else if (organisationRow != null) { partnerNode.SetAttribute("Name", organisationRow.OrganisationName.ToString()); } else if (unitRow != null) { partnerNode.SetAttribute("Name", unitRow.UnitName.ToString()); partnerNode.SetAttribute("UnitTypeCode", unitRow.UnitTypeCode.ToString()); if (unitStructureRow != null) { partnerNode.SetAttribute("ParentUnitKey", unitStructureRow.ParentUnitKey.ToString()); } } if (BankRow != null) { partnerNode.SetAttribute("BranchName", BankRow.BranchName); partnerNode.SetAttribute("BranchCode", BankRow.BranchCode); partnerNode.SetAttribute("BranchBic", BankRow.Bic); partnerNode.SetAttribute("EpFormatFile", BankRow.EpFormatFile); } partnerNode.SetAttribute("CreatedAt", partnerRow.DateCreated.Value.ToString("yyyy-MM-dd HH:mm:ss")); // special types string specialTypes = ""; MainDS.PPartnerType.DefaultView.RowFilter = PPartnerTypeTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); foreach (DataRowView rv in MainDS.PPartnerType.DefaultView) { if (specialTypes.Length > 0) { specialTypes += ", "; } specialTypes += ((PPartnerTypeRow)rv.Row).TypeCode; } if (specialTypes.Length > 0) { partnerNode.SetAttribute("SpecialTypes", specialTypes); } // addresses DataView partnerLocationView = MainDS.PPartnerLocation.DefaultView; partnerLocationView.RowFilter = PPartnerLocationTable.GetPartnerKeyDBName() + " = " + partnerRow.PartnerKey.ToString() + "AND " + PPartnerLocationTable.GetLocationKeyDBName() + " <> 0 "; // ignore invalid addresses Int32 addressCounter = 0; foreach (DataRowView rv in partnerLocationView) { XmlElement addressNode = PartnerData.CreateElement("Address" + (addressCounter > 0 ? addressCounter.ToString() : "")); addressCounter++; partnerNode.AppendChild(addressNode); PPartnerLocationRow partnerLocationRow = (PPartnerLocationRow)rv.Row; DataView locationView = MainDS.PLocation.DefaultView; locationView.RowFilter = PLocationTable.GetSiteKeyDBName() + "=" + partnerLocationRow.SiteKey.ToString() + " AND " + PLocationTable.GetLocationKeyDBName() + "=" + partnerLocationRow.LocationKey.ToString(); if (locationView.Count > 0) { PLocationRow locationRow = (PLocationRow)locationView[0].Row; addressNode.SetAttribute("Street", locationRow.StreetName); addressNode.SetAttribute("City", locationRow.City); addressNode.SetAttribute("PostCode", locationRow.PostalCode); } addressNode.SetAttribute("Email", partnerLocationRow.EmailAddress); addressNode.SetAttribute("Phone", partnerLocationRow.TelephoneNumber); addressNode.SetAttribute("MobilePhone", partnerLocationRow.MobileNumber); } // TODO: notes // TODO: This doesn't export as much data as it should? } } } return(TXMLParser.XmlToString(PartnerData)); }
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; } }