private static void CreateContacts(XmlNode ANode, Int64 APartnerKey, ref PartnerImportExportTDS AMainDS, string Suffix) { string ContactCode = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_CONTACTCODE + Suffix); if (ContactCode.Length > 0) { PartnerImportExportTDSPContactLogRow ContactLogRow = AMainDS.PContactLog.NewRowTyped(); ContactLogRow.ContactCode = ContactCode; ContactLogRow.ContactDate = DateTime.Parse(TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_CONTACTDATE + Suffix)); //DateTime ContactTime = DateTime.Parse(TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_CONTACTTIME + Suffix)); //ContactLogRow.ContactTime = ((ContactTime.Hour * 60) + ContactTime.Minute * 60) + ContactTime.Second; ContactLogRow.Contactor = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_CONTACTOR + Suffix); ContactLogRow.ContactComment = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_CONTACTNOTES + Suffix); ContactLogRow.ContactAttr = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_CONTACTATTR + Suffix); ContactLogRow.ContactDetail = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_CONTACTDETAIL + Suffix); AMainDS.PContactLog.Rows.Add(ContactLogRow); AddVerificationResult("Contact Log Record Created.", TResultSeverity.Resv_Status); var PartnerContactRow = AMainDS.PPartnerContact.NewRowTyped(); PartnerContactRow.PartnerKey = APartnerKey; PartnerContactRow.ContactLogId = ContactLogRow.ContactLogId; AMainDS.PPartnerContact.Rows.Add(PartnerContactRow); AddVerificationResult("Contact Associated with Partner", TResultSeverity.Resv_Status); } }
/// <summary> /// imports partner data from file /// </summary> /// <param name="AXmlPartnerData"></param> /// <param name="AVerificationResult"></param> /// <returns></returns> public static PartnerImportExportTDS ImportPartners(string AXmlPartnerData, out TVerificationResultCollection AVerificationResult) { TDBTransaction ReadTransaction = null; TVerificationResultCollection VerificationResult; VerificationResult = new TVerificationResultCollection(); PartnerImportExportTDS MainDS = new PartnerImportExportTDS(); XmlDocument doc = new XmlDocument(); doc.LoadXml(AXmlPartnerData); XmlNode root = doc.FirstChild.NextSibling.FirstChild; // import partner groups // advantage: can inherit some common attributes, eg. partner class, etc TImportExportYml.NewPartnerKey = -1; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.RepeatableRead, TEnforceIsolationLevel.eilMinimum, ref ReadTransaction, delegate { ParsePartners(ref MainDS, root, ReadTransaction, ref VerificationResult); }); AVerificationResult = VerificationResult; return(MainDS); }
public void TestImportCSV2() { TVerificationResultCollection VerificationResult = null; string doc = String.Empty; using (StreamReader sr = new StreamReader("../../demodata/partners/samplefilepartnerimport2.csv")) { doc = sr.ReadToEnd(); } PartnerImportExportTDS MainDS = TImportExportWebConnector.ImportFromCSVFileReturnDataSet(doc, "dMy", ",", out VerificationResult); if (VerificationResult != null) { Assert.IsFalse(VerificationResult.HasCriticalErrors, "there was an error importing the csv file"); } foreach (PFamilyRow f in MainDS.PFamily.Rows) { Console.WriteLine("Family name : " + f.FamilyName); } // we are currently ignoring UNIT and ORGANISATION partners, only importing the 7 FAMILY partners. // due to the strange format of the file, each row is imported as a separate partner, ending up with 27 invalid partners Assert.AreEqual(7, MainDS.PPartner.Rows.Count); }
/// <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); }
/// <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); }
/// <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 void CreatePartnerAttributes(ref PartnerImportExportTDS AMainDS, TDBTransaction ATransaction) { TPartnerContactDetails_LocationConversionHelper.PartnerAttributeLoadUsingTemplate = PPartnerAttributeAccess.LoadUsingTemplate; TPartnerContactDetails_LocationConversionHelper.SequenceGetter = MCommon.WebConnectors.TSequenceWebConnector.GetNextSequence; TPartnerContactDetails_LocationConversionHelper.ParsePartnerLocationsForContactDetails(AMainDS, ATransaction); }
/// <summary> /// Import data from a CSV file /// </summary> /// <param name="ANode"></param> /// <param name="AReferenceResults"></param> /// <returns></returns> public static PartnerImportExportTDS ImportData(XmlNode ANode, ref TVerificationResultCollection AReferenceResults) { PartnerImportExportTDS ResultDS = new PartnerImportExportTDS(); TPartnerImportCSV.FLocationKey = -1; ResultsCol = AReferenceResults; TDBTransaction ReadTransaction = null; DBAccess.GDBAccessObj.BeginAutoReadTransaction(IsolationLevel.Serializable, ref ReadTransaction, delegate { while (ANode != null) { ResultsContext = "CSV Import"; String PartnerClass = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_PARTNERCLASS).ToUpper(); Int64 PartnerKey = 0; int LocationKey = 0; if (PartnerClass.Length == 0) { PartnerClass = MPartnerConstants.PARTNERCLASS_FAMILY; } if ((PartnerClass == MPartnerConstants.PARTNERCLASS_FAMILY) || (PartnerClass == MPartnerConstants.PARTNERCLASS_PERSON)) { ResultsContext = "CSV Import Family"; PartnerKey = CreateNewFamily(ANode, out LocationKey, ref ResultDS, ReadTransaction); CreateSpecialTypes(ANode, PartnerKey, "SpecialTypeFamily_", ref ResultDS); } if (PartnerClass == MPartnerConstants.PARTNERCLASS_PERSON) { ResultsContext = "CSV Import person"; Int64 PersonKey = CreateNewPerson(PartnerKey, LocationKey, ANode, ref ResultDS, ReadTransaction); CreateShortTermApplication(ANode, PersonKey, ref ResultDS, ReadTransaction); CreateSpecialTypes(ANode, PersonKey, ref ResultDS); CreateSubscriptions(ANode, PersonKey, ref ResultDS); CreateContacts(ANode, PersonKey, ref ResultDS, "_1"); CreateContacts(ANode, PersonKey, ref ResultDS, "_2"); CreatePassport(ANode, PersonKey, ref ResultDS); CreateSpecialNeeds(ANode, PersonKey, ref ResultDS); } ANode = ANode.NextSibling; } CreatePartnerAttributes(ref ResultDS, ReadTransaction); }); return(ResultDS); }
/// <summary> /// Import data from a CSV file /// </summary> /// <param name="ANode"></param> /// <param name="AReferenceResults"></param> /// <returns></returns> public static PartnerImportExportTDS ImportData(XmlNode ANode, ref TVerificationResultCollection AReferenceResults) { PartnerImportExportTDS ResultDS = new PartnerImportExportTDS(); TPartnerImportCSV.FLocationKey = -1; ResultsCol = AReferenceResults; TDBTransaction ReadTransaction = null; DBAccess.GDBAccessObj.BeginAutoReadTransaction(IsolationLevel.Serializable, ref ReadTransaction, delegate { while (ANode != null) { ResultsContext = "CSV Import"; String PartnerClass = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_PARTNERCLASS).ToUpper(); Int64 PartnerKey = 0; int LocationKey = 0; if (PartnerClass.Length == 0) { PartnerClass = MPartnerConstants.PARTNERCLASS_FAMILY; } if ((PartnerClass == MPartnerConstants.PARTNERCLASS_FAMILY) || (PartnerClass == MPartnerConstants.PARTNERCLASS_PERSON)) { ResultsContext = "CSV Import Family"; PartnerKey = CreateNewFamily(ANode, out LocationKey, ref ResultDS, ReadTransaction); CreateSpecialTypes(ANode, PartnerKey, "SpecialTypeFamily_", ref ResultDS); } if (PartnerClass == MPartnerConstants.PARTNERCLASS_PERSON) { ResultsContext = "CSV Import person"; Int64 PersonKey = CreateNewPerson(PartnerKey, LocationKey, ANode, ref ResultDS, ReadTransaction); CreateShortTermApplication(ANode, PersonKey, ref ResultDS, ReadTransaction); CreateSpecialTypes(ANode, PersonKey, ref ResultDS); CreateSubscriptions(ANode, PersonKey, ref ResultDS); CreateContacts(ANode, PersonKey, ref ResultDS, "_1"); CreateContacts(ANode, PersonKey, ref ResultDS, "_2"); CreatePassport(ANode, PersonKey, ref ResultDS); } ANode = ANode.NextSibling; } CreatePartnerAttributes(ref ResultDS, ReadTransaction); }); return ResultDS; }
public void TestImportCSV() { XmlDocument doc = TCsv2Xml.ParseCSVFile2Xml("../../demodata/partners/samplePartnerImport.csv", ";"); TVerificationResultCollection VerificationResult = null; PartnerImportExportTDS MainDS = TImportExportWebConnector.ImportFromCSVFile(TXMLParser.XmlToString(doc), "DMY", out VerificationResult); if (VerificationResult != null) { Assert.IsFalse(VerificationResult.HasCriticalErrors, "there was an error importing the csv file"); } // there should be 2 partners imported Assert.AreEqual(2, MainDS.PPartner.Rows.Count); }
private static void CreatePassport(XmlNode ANode, Int64 APartnerKey, ref PartnerImportExportTDS AMainDS) { string PassportNum = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_PASSPORTNUMBER); if (PassportNum.Length > 0) { PmPassportDetailsRow NewRow = AMainDS.PmPassportDetails.NewRowTyped(); NewRow.PassportNumber = PassportNum; NewRow.PassportDetailsType = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_PASSPORTTYPE); NewRow.PlaceOfBirth = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_PASSPORTPLACEOFBIRTH); NewRow.PassportNationalityCode = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_PASSPORTNATIONALITY); NewRow.PlaceOfIssue = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_PASSPORTPLACEOFISSUE); NewRow.CountryOfIssue = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_PASSPORTCOUNTRYOFISSUE); NewRow.DateOfIssue = DateTime.Parse(TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_PASSPORTDATEOFISSUE)); NewRow.DateOfExpiration = DateTime.Parse(TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_PASSPORTDATEOFEXPIRATION)); AMainDS.PmPassportDetails.Rows.Add(NewRow); AddVerificationResult("Passport Record Created.", TResultSeverity.Resv_Status); } }
public void TestImportCSV_Dates_MDY() { TVerificationResultCollection VerificationResult = null; string doc = String.Empty; using (StreamReader sr = new StreamReader("../../csharp/ICT/Testing/lib/MPartner/SampleData/samplePartnerImport_dates_mdy.csv")) { doc = sr.ReadToEnd(); } PartnerImportExportTDS MainDS = TImportExportWebConnector.ImportFromCSVFileReturnDataSet(doc, "mdy", ";", out VerificationResult); if (VerificationResult != null) { if (VerificationResult.HasCriticalErrors) { Assert.AreEqual(String.Empty, VerificationResult.BuildVerificationResultString(), "there was an error importing the csv file"); } } // there should be 2 partners imported (2 x family) Assert.AreEqual(2, MainDS.PPartner.Rows.Count); Assert.AreEqual(2, MainDS.PFamily.Rows.Count); Assert.AreEqual(new DateTime(1979, 8, 19), MainDS.PFamily[0].DateOfBirth, "date of birth is wrong!"); // Now try with the wrong date format VerificationResult = null; MainDS = TImportExportWebConnector.ImportFromCSVFileReturnDataSet(doc, "dmy", ";", out VerificationResult); Assert.IsNotNull(VerificationResult, "Expected to get errors"); int numErrors = 0; for (int i = 0; i < VerificationResult.Count; i++) { if (VerificationResult[i].ResultSeverity != TResultSeverity.Resv_Status) { numErrors++; } } Assert.AreEqual(2, numErrors, "Wrong number of errors"); }
public void TestImportCSV_Dates_MDY() { TVerificationResultCollection VerificationResult = null; string doc = String.Empty; using (StreamReader sr = new StreamReader("../../demodata/partners/samplePartnerImport_dates_mdy.csv")) { doc = sr.ReadToEnd(); } PartnerImportExportTDS MainDS = TImportExportWebConnector.ImportFromCSVFileReturnDataSet(doc, "mdy", ";", out VerificationResult); if (VerificationResult != null) { Assert.IsFalse(VerificationResult.HasCriticalErrors, "there was an error importing the csv file"); } // there should be 4 partners imported (2 x family + 2 x person) Assert.AreEqual(4, MainDS.PPartner.Rows.Count); Assert.AreEqual(2, MainDS.PmPassportDetails.Rows.Count); Assert.AreEqual(((PmPassportDetailsRow)MainDS.PmPassportDetails.Rows[0]).DateOfIssue, new DateTime(2016, 5, 22), "passport date of issue is wrong!"); // Now try with the wrong date format VerificationResult = null; MainDS = TImportExportWebConnector.ImportFromCSVFileReturnDataSet(doc, "dmy", ";", out VerificationResult); Assert.IsNotNull(VerificationResult, "Expected to get errors"); int numErrors = 0; for (int i = 0; i < VerificationResult.Count; i++) { if (VerificationResult[i].ResultSeverity != TResultSeverity.Resv_Status) { numErrors++; } } Assert.AreEqual(5, numErrors, "Wrong number of errors"); }
private static void CreateSpecialTypes(XmlNode ANode, Int64 APartnerKey, ref PartnerImportExportTDS AMainDS) { // This previous code requires a format that doesn't conform to the documented standard: /* * if (TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_SPECIALTYPES).Length != 0) * { * string specialTypes = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_SPECIALTYPES); * * while (specialTypes.Length > 0) * { * PPartnerTypeRow partnerType = AMainDS.PPartnerType.NewRowTyped(true); * partnerType.PartnerKey = PartnerKey; * partnerType.TypeCode = StringHelper.GetNextCSV(ref specialTypes, ",").Trim().ToUpper(); * AMainDS.PPartnerType.Rows.Add(partnerType); * } * } */ CreateSpecialTypes(ANode, APartnerKey, "SpecialType_", ref AMainDS); }
public void TestImportCSV() { TVerificationResultCollection VerificationResult = null; string doc = String.Empty; using (StreamReader sr = new StreamReader("../../demodata/partners/samplePartnerImport.csv")) { doc = sr.ReadToEnd(); } PartnerImportExportTDS MainDS = TImportExportWebConnector.ImportFromCSVFileReturnDataSet(doc, "DMY", ";", out VerificationResult); if (VerificationResult != null) { Assert.IsFalse(VerificationResult.HasCriticalErrors, "there was an error importing the csv file"); } // there should be 2 partners imported Assert.AreEqual(2, MainDS.PPartner.Rows.Count); }
private static void CreateSubscriptions(XmlNode ANode, Int64 APartnerKey, ref PartnerImportExportTDS AMainDS) { int SubsCount = 0; foreach (XmlAttribute Attr in ANode.Attributes) { if ((Attr.Name.ToLower().IndexOf("subscribe_") == 0) && (Attr.Value.ToLower() == "yes")) { PSubscriptionRow NewRow = AMainDS.PSubscription.NewRowTyped(); NewRow.PartnerKey = APartnerKey; NewRow.PublicationCode = Attr.Name.Substring(10).ToUpper(); AMainDS.PSubscription.Rows.Add(NewRow); SubsCount++; } } if (SubsCount > 0) { AddVerificationResult("Subscriptions Created.", TResultSeverity.Resv_Status); } }
public void TestImportFamily() { string testFile = TAppSettingsManager.GetValue("ExtractTest.file", "../../csharp/ICT/Testing/lib/MPartner/SampleData/sampleExtract.ext"); string SelectedEventCode = TAppSettingsManager.GetValue("ImportPartnerForEventCode", String.Empty); StreamReader reader = new StreamReader(testFile, System.Text.Encoding.GetEncoding(1252)); string[] lines = reader.ReadToEnd().Replace("\r\n", "\n").Replace("\r", "\n").Split(new char[] { '\n' }); reader.Close(); TVerificationResultCollection VerificationResult; TPartnerFileImport importer = new TPartnerFileImport(); PartnerImportExportTDS MainDS = importer.ImportAllData(lines, SelectedEventCode, false, out VerificationResult); CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResult); foreach (PPartnerRow PartnerRow in MainDS.PPartner.Rows) { TLogging.Log(PartnerRow.PartnerKey.ToString() + " " + PartnerRow.PartnerShortName); } // TODO: check if the partners have been imported previously already foreach (PPartnerRow PartnerRow in MainDS.PPartner.Rows) { TLogging.Log(PartnerRow.PartnerKey.ToString() + " " + PartnerRow.PartnerShortName); } try { PartnerImportExportTDSAccess.SubmitChanges(MainDS); } catch (Exception e) { TLogging.Log(e.Message); TLogging.Log(e.StackTrace); Assert.Fail("See log messages"); } Assert.AreEqual(2, MainDS.PPartner.Rows.Count); }
public void TestImportCSV2() { XmlDocument doc = TCsv2Xml.ParseCSVFile2Xml("../../demodata/partners/samplefilepartnerimport2.csv", ","); TVerificationResultCollection VerificationResult = null; Console.WriteLine(TXMLParser.XmlToString(doc)); PartnerImportExportTDS MainDS = TImportExportWebConnector.ImportFromCSVFile(TXMLParser.XmlToString(doc), "dMy", out VerificationResult); if (VerificationResult != null) { Assert.IsFalse(VerificationResult.HasCriticalErrors, "there was an error importing the csv file"); } foreach (PFamilyRow f in MainDS.PFamily.Rows) { Console.WriteLine("Family name : " + f.FamilyName); } // we are currently ignoring UNIT and ORGANISATION partners, only importing the 7 FAMILY partners. // due to the strange format of the file, each row is imported as a separate partner, ending up with 27 invalid partners Assert.AreEqual(7, MainDS.PPartner.Rows.Count); }
private static void CreateSpecialNeeds(XmlNode ANode, Int64 APartnerKey, ref PartnerImportExportTDS AMainDS) { // only create special need record if data exists in import file if (TXMLParser.HasAttribute(ANode, MPartnerConstants.PARTNERIMPORT_VEGETARIAN) || TXMLParser.HasAttribute(ANode, MPartnerConstants.PARTNERIMPORT_MEDICALNEEDS)) { PmSpecialNeedRow NewRow = AMainDS.PmSpecialNeed.NewRowTyped(); NewRow.PartnerKey = APartnerKey; NewRow.MedicalComment = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_MEDICALNEEDS); if (TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_VEGETARIAN).ToLower() == "yes") { NewRow.VegetarianFlag = true; } else { NewRow.VegetarianFlag = false; } AMainDS.PmSpecialNeed.Rows.Add(NewRow); AddVerificationResult("Special Need Record Created.", TResultSeverity.Resv_Status); } }
public void TestImportCSV_Dates_DMY() { XmlDocument doc = TCsv2Xml.ParseCSVFile2Xml("../../demodata/partners/samplePartnerImport_dates_dmy.csv", ";"); TVerificationResultCollection VerificationResult = null; PartnerImportExportTDS MainDS = TImportExportWebConnector.ImportFromCSVFile(TXMLParser.XmlToString(doc), "dmy", out VerificationResult); if (VerificationResult != null) { Assert.IsFalse(VerificationResult.HasCriticalErrors, "there was an error importing the csv file"); } // there should be 4 partners imported (2 x family + 2 x person) Assert.AreEqual(4, MainDS.PPartner.Rows.Count, "Wrong number of partners"); Assert.AreEqual(2, MainDS.PmPassportDetails.Rows.Count, "Wrong number of persons"); Assert.AreEqual(((PmPassportDetailsRow)MainDS.PmPassportDetails.Rows[0]).DateOfIssue, new DateTime(2016, 4, 22), "passport date of issue is wrong!"); // Now try with the wrong date format VerificationResult = null; MainDS = TImportExportWebConnector.ImportFromCSVFile(TXMLParser.XmlToString(doc), "mdy", out VerificationResult); Assert.IsNotNull(VerificationResult, "Expected to get errors"); int numErrors = 0; for (int i = 0; i < VerificationResult.Count; i++) { if (VerificationResult[i].ResultSeverity != TResultSeverity.Resv_Status) { numErrors++; } } Assert.AreEqual(5, numErrors, "Wrong number of errors"); }
/// <summary> /// generate the banks /// </summary> public static void GenerateBanks(string ABankCSVFile) { if (!File.Exists(ABankCSVFile)) { TLogging.Log("there is no bank file " + ABankCSVFile); return; } TLogging.Log("creating banks from file " + ABankCSVFile); XmlDocument doc = TCsv2Xml.ParseCSV2Xml(ABankCSVFile, ","); XmlNode RecordNode = doc.FirstChild.NextSibling.FirstChild; PartnerImportExportTDS PartnerDS = new PartnerImportExportTDS(); Int32 NumberOfPartnerKeysReserved = 100; Int64 NextPartnerKey = TNewPartnerKey.ReservePartnerKeys(-1, ref NumberOfPartnerKeysReserved); while (RecordNode != null) { PBankRow BankRow = PartnerDS.PBank.NewRowTyped(); if (NumberOfPartnerKeysReserved == 0) { NumberOfPartnerKeysReserved = 100; NextPartnerKey = TNewPartnerKey.ReservePartnerKeys(-1, ref NumberOfPartnerKeysReserved); } BankRow.PartnerKey = NextPartnerKey; NextPartnerKey++; NumberOfPartnerKeysReserved--; BankRow.BranchName = TXMLParser.GetAttribute(RecordNode, "Branchname"); BankRow.BranchCode = TXMLParser.GetAttribute(RecordNode, "Branchcode"); BankRow.Bic = TXMLParser.GetAttribute(RecordNode, "Bic"); PartnerDS.PBank.Rows.Add(BankRow); if (PartnerDS.PBank.Rows.Count % 1000 == 0) { TLogging.Log("created bank " + PartnerDS.PBank.Rows.Count.ToString() + " " + BankRow.BranchName); } PPartnerRow PartnerRow = PartnerDS.PPartner.NewRowTyped(); PartnerRow.PartnerKey = BankRow.PartnerKey; PartnerRow.PartnerShortName = BankRow.BranchName; PartnerRow.PartnerClass = MPartnerConstants.PARTNERCLASS_BANK; PartnerRow.StatusCode = MPartnerConstants.PARTNERSTATUS_ACTIVE; PartnerDS.PPartner.Rows.Add(PartnerRow); // add empty location so that the partner can be found in the Partner Find screen PPartnerLocationRow PartnerLocationRow = PartnerDS.PPartnerLocation.NewRowTyped(); PartnerLocationRow.PartnerKey = BankRow.PartnerKey; PartnerLocationRow.LocationKey = 0; PartnerLocationRow.SiteKey = 0; PartnerDS.PPartnerLocation.Rows.Add(PartnerLocationRow); RecordNode = RecordNode.NextSibling; } PartnerDS.ThrowAwayAfterSubmitChanges = true; PartnerImportExportTDSAccess.SubmitChanges(PartnerDS); TLogging.Log("after saving banks"); }
private void AddRoom(Int64 AOrigPartnerKey, Int64 ANewPartnerKey, ref PartnerImportExportTDS ANewPartnerDS) { ImportRecordsByPartnerKey(ANewPartnerDS.PcRoom, FMainDS.PcRoom, PcRoomTable.GetVenueKeyDBName(), AOrigPartnerKey, ANewPartnerKey); }
private void AddBankingDetails(Int64 AOrigPartnerKey, Int64 ANewPartnerKey, ref PartnerImportExportTDS ANewPartnerDS) { FMainDS.PPartnerBankingDetails.DefaultView.Sort = PPartnerBankingDetailsTable.GetPartnerKeyDBName(); int indexPartnerBankingDetails = FMainDS.PPartnerBankingDetails.DefaultView.Find(AOrigPartnerKey); if (indexPartnerBankingDetails != -1) { PPartnerBankingDetailsRow partnerdetailsRow = (PPartnerBankingDetailsRow)FMainDS.PPartnerBankingDetails.DefaultView[indexPartnerBankingDetails].Row; partnerdetailsRow.PartnerKey = ANewPartnerKey; ANewPartnerDS.PPartnerBankingDetails.ImportRow(partnerdetailsRow); // need to copy the associated PBankingDetails as well FMainDS.PBankingDetails.DefaultView.Sort = PBankingDetailsTable.GetBankingDetailsKeyDBName(); PBankingDetailsRow OrigBankingDetailsRow = (PBankingDetailsRow)FMainDS.PBankingDetails.DefaultView[ FMainDS.PBankingDetails.DefaultView.Find(partnerdetailsRow.BankingDetailsKey)].Row; PBankRow bankRow = (PBankRow)FMainDS.PBank.Rows.Find(OrigBankingDetailsRow.BankKey); // create the PBank record as well, if it does not exist yet OrigBankingDetailsRow.BankKey = TRemote.MPartner.Partner.WebConnectors.GetBankBySortCode(bankRow.BranchCode); ANewPartnerDS.PBankingDetails.ImportRow(OrigBankingDetailsRow); } }
/* * private void AddVision(Int64 OrigPartnerKey, Int64 NewPartnerKey, ref PartnerImportExportTDS NewPartnerDS) * { * ImportRecordsByPartnerKey(NewPartnerDS.PmPersonVision, FMainDS.PmPersonVision, * PmPersonVisionTable.GetPartnerKeyDBName(), OrigPartnerKey, NewPartnerKey); * } */ private void AddGiftDestination(Int64 AOrigPartnerKey, Int64 ANewPartnerKey, ref PartnerImportExportTDS ANewPartnerDS) { ImportRecordsByPartnerKey(ANewPartnerDS.PPartnerGiftDestination, FMainDS.PPartnerGiftDestination, PPartnerGiftDestinationTable.GetPartnerKeyDBName(), AOrigPartnerKey, ANewPartnerKey); }
private void AddSpecialNeeds(Int64 AOrigPartnerKey, Int64 ANewPartnerKey, ref PartnerImportExportTDS ANewPartnerDS) { ImportRecordsByPartnerKey(ANewPartnerDS.PmSpecialNeed, FMainDS.PmSpecialNeed, PmSpecialNeedTable.GetPartnerKeyDBName(), AOrigPartnerKey, ANewPartnerKey); }
private void AddProfessionalData(Int64 AOrigPartnerKey, Int64 ANewPartnerKey, ref PartnerImportExportTDS ANewPartnerDS) { ImportRecordsByPartnerKey(ANewPartnerDS.PmPersonQualification, FMainDS.PmPersonQualification, PmPersonQualificationTable.GetPartnerKeyDBName(), AOrigPartnerKey, ANewPartnerKey); }
private void AddPassport(Int64 AOrigPartnerKey, Int64 ANewPartnerKey, ref PartnerImportExportTDS ANewPartnerDS) { ImportRecordsByPartnerKey(ANewPartnerDS.PmPassportDetails, FMainDS.PmPassportDetails, PmPassportDetailsTable.GetPartnerKeyDBName(), AOrigPartnerKey, ANewPartnerKey); }
/// <summary> /// Copy this Partner, and all the data linked to it, from the large DataSet into a new one, /// and send it back to the server for committing. /// /// NOTE: May be called recursively to add parent records before adding children. /// </summary> /// <param name="APartnerRow">Row to import</param> /// <param name="StepAfterImport">Go on to next record afterwards. (Usually true)</param> /// <returns>Partner key of imported record (although no-one cares)</returns> private Int64 CreateOrUpdatePartner(PPartnerRow APartnerRow, Boolean StepAfterImport) { if ((FCurrentNumberOfRecord < 1) || (FCurrentNumberOfRecord > FTotalNumberOfRecords)) { return 0; } if (FImportedUnits.Contains(APartnerRow.PartnerKey)) { return APartnerRow.PartnerKey; } PartnerImportExportTDS NewPartnerDS = new PartnerImportExportTDS(); NewPartnerDS.PPartner.ImportRow(APartnerRow); Int64 OrigPartnerKey = APartnerRow.PartnerKey; Int64 NewPartnerKey = OrigPartnerKey; bool UpdateExistingRecord = false; // If the import file had a negative PartnerKey, I need to create a new one here, // and use it on all the dependent tables. if (OrigPartnerKey < 0) { if (ExistingPartnerKey > 0) // This ExistingPartnerKey has been set by the UseSelectedPerson button. { NewPartnerKey = ExistingPartnerKey; UpdateExistingRecord = true; ExistingPartnerKey = -1; // Don't use this next time! } else { NewPartnerKey = TRemote.MPartner.Partner.WebConnectors.NewPartnerKey(-1); } } if (UpdateExistingRecord) { NewPartnerDS.PPartner[0].PartnerKey = UserSelectedRow.PartnerKey; NewPartnerDS.PPartner[0].DateCreated = UserSelectedRow.DateCreated; NewPartnerDS.PPartner[0].CreatedBy = UserSelectedRow.CreatedBy; NewPartnerDS.PPartner[0].ModificationId = UserSelectedRow.ModificationId; NewPartnerDS.PPartner[0].AcceptChanges(); // This should reset the RowState, allowing me to Update rather than Add } NewPartnerDS.PPartner[0].PartnerKey = NewPartnerKey; if (NewPartnerDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_CHURCH) { ImportRecordsByPartnerKey(NewPartnerDS.PChurch, FMainDS.PChurch, PChurchTable.GetPartnerKeyDBName(), OrigPartnerKey, NewPartnerKey, UpdateExistingRecord); } else if (NewPartnerDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_FAMILY) { // // Before I change the PartnerKey on this PFamily, I need to update any PPerson records that are linked to it, // so that the links will still work... FMainDS.PPerson.DefaultView.RowFilter = String.Format("{0}={1}", PartnerEditTDSPPersonTable.GetFamilyKeyDBName(), OrigPartnerKey); foreach (DataRowView rv in FMainDS.PPerson.DefaultView) { PPersonRow RelatedPerson = (PPersonRow)rv.Row; RelatedPerson.FamilyKey = NewPartnerKey; } ImportRecordsByPartnerKey(NewPartnerDS.PFamily, FMainDS.PFamily, PFamilyTable.GetPartnerKeyDBName(), OrigPartnerKey, NewPartnerKey, UpdateExistingRecord); } else if (NewPartnerDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_PERSON) { ImportRecordsByPartnerKey(NewPartnerDS.PPerson, FMainDS.PPerson, PPersonTable.GetPartnerKeyDBName(), OrigPartnerKey, NewPartnerKey, UpdateExistingRecord); NewPartnerDS.PPerson.DefaultView.RowFilter = String.Format("{0}={1}", PPersonTable.GetPartnerKeyDBName(), NewPartnerKey); Int64 RelatedFamilyKey = ((PPersonRow)NewPartnerDS.PPerson.DefaultView[0].Row).FamilyKey; // If there's an associated PFamily record that I've not imported yet, I could try to do that now, // but it's problematic because it might end up getting imported twice. // Anyway, I should not come to here because the family should have been imported first. if (RelatedFamilyKey < 0) // There's a related family that's not been imported { AddStatus("Import Problem: PPerson record with no related PFamily."); return 0; } } else if (NewPartnerDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_ORGANISATION) { ImportRecordsByPartnerKey(NewPartnerDS.POrganisation, FMainDS.POrganisation, POrganisationTable.GetPartnerKeyDBName(), OrigPartnerKey, NewPartnerKey, UpdateExistingRecord); } else if (NewPartnerDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_UNIT) { ImportRecordsByPartnerKey(NewPartnerDS.PUnit, FMainDS.PUnit, PUnitTable.GetPartnerKeyDBName(), OrigPartnerKey, NewPartnerKey, UpdateExistingRecord); /* * // I'm doing this later, in AddUnitstructure * ImportRecordsByPartnerKey(NewPartnerDS.UmUnitStructure, FMainDS.UmUnitStructure, * UmUnitStructureTable.GetChildUnitKeyDBName(), OrigPartnerKey, NewPartnerKey, UpdateExistingRecord); */ FImportedUnits.Add(NewPartnerKey); /* * // I don't need this at all... * foreach (UmUnitStructureRow UnitStructureRow in NewPartnerDS.UmUnitStructure.Rows) * { * UnitStructureRow.ChildUnitKey = NewPartnerKey; * } */ } else if (NewPartnerDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_VENUE) { ImportRecordsByPartnerKey(NewPartnerDS.PVenue, FMainDS.PVenue, PVenueTable.GetPartnerKeyDBName(), OrigPartnerKey, NewPartnerKey, UpdateExistingRecord); } else if (NewPartnerDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_BANK) { ImportRecordsByPartnerKey(NewPartnerDS.PBank, FMainDS.PBank, PBankTable.GetPartnerKeyDBName(), OrigPartnerKey, NewPartnerKey, UpdateExistingRecord); } // Add special types etc AddAbility(OrigPartnerKey, NewPartnerKey, ref NewPartnerDS); AddApplication(OrigPartnerKey, NewPartnerKey, ref NewPartnerDS); AddAddresses(OrigPartnerKey, NewPartnerKey, ref NewPartnerDS); AddCommentSeq(OrigPartnerKey, NewPartnerKey, ref NewPartnerDS); AddStaffData(OrigPartnerKey, NewPartnerKey, ref NewPartnerDS); AddJobAssignment(OrigPartnerKey, NewPartnerKey, ref NewPartnerDS); AddPmPersonLanguage(OrigPartnerKey, NewPartnerKey, ref NewPartnerDS); AddPreviousExperience(OrigPartnerKey, NewPartnerKey, ref NewPartnerDS); AddPassport(OrigPartnerKey, NewPartnerKey, ref NewPartnerDS); AddPersonalDocument(OrigPartnerKey, NewPartnerKey, ref NewPartnerDS); AddPersonalData(OrigPartnerKey, NewPartnerKey, ref NewPartnerDS); AddProfessionalData(OrigPartnerKey, NewPartnerKey, ref NewPartnerDS); AddPersonalEvaluation(OrigPartnerKey, NewPartnerKey, ref NewPartnerDS); AddSpecialNeeds(OrigPartnerKey, NewPartnerKey, ref NewPartnerDS); AddPartnerType(OrigPartnerKey, NewPartnerKey, ref NewPartnerDS); foreach (PPartnerTypeRow PartnerTypeRow in NewPartnerDS.PPartnerType.Rows) { PartnerTypeRow.PartnerKey = NewPartnerKey; } AddInterest(OrigPartnerKey, NewPartnerKey, ref NewPartnerDS); // AddVision(OrigPartnerKey, NewPartnerKey, ref NewPartnerDS); AddGiftDestination(OrigPartnerKey, NewPartnerKey, ref NewPartnerDS); AddUnitstructure(OrigPartnerKey, NewPartnerKey, ref NewPartnerDS); AddBuilding(OrigPartnerKey, NewPartnerKey, ref NewPartnerDS); AddRoom(OrigPartnerKey, NewPartnerKey, ref NewPartnerDS); AddSubscriptions(OrigPartnerKey, NewPartnerKey, ref NewPartnerDS); AddContacts(OrigPartnerKey, NewPartnerKey, ref NewPartnerDS); AddBankingDetails(OrigPartnerKey, NewPartnerKey, ref NewPartnerDS); TVerificationResultCollection VerificationResult; bool CommitRes = TRemote.MPartner.ImportExport.WebConnectors.CommitChanges(NewPartnerDS, out VerificationResult); AddStatus(FormatVerificationResult("Save Partner: ", VerificationResult)); if (!CommitRes) { String ResultString = ""; foreach (TVerificationResult row in VerificationResult) { if (row.ResultSeverity == TResultSeverity.Resv_Critical) { ResultString += row.ResultContext.ToString() + Environment.NewLine + " " + row.ResultText + Environment.NewLine; } } MessageBox.Show(ResultString, Catalog.GetString("Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); } else { // new record has been created, now load the next record if (StepAfterImport) { NextRecord(); } } return NewPartnerKey; }
private void AddSubscriptions(Int64 AOrigPartnerKey, Int64 ANewPartnerKey, ref PartnerImportExportTDS ANewPartnerDS) { ImportRecordsByPartnerKey(ANewPartnerDS.PSubscription, FMainDS.PSubscription, PSubscriptionTable.GetPartnerKeyDBName(), AOrigPartnerKey, ANewPartnerKey); // I'll also import any related Publication rows. ANewPartnerDS.PSubscription.DefaultView.RowFilter = String.Format("{0} = {1}", PSubscriptionTable.GetPartnerKeyDBName(), ANewPartnerKey); foreach (DataRowView rv in ANewPartnerDS.PSubscription.DefaultView) { PSubscriptionRow Row = (PSubscriptionRow)rv.Row; FMainDS.PPublication.DefaultView.RowFilter = String.Format("{0}='{1}'", PPublicationTable.GetPublicationCodeDBName(), Row.PublicationCode); foreach (DataRowView Pubrv in FMainDS.PPublication.DefaultView) { ANewPartnerDS.PPublication.ImportRow(Pubrv.Row); } } }
private static void CheckSTApplicationRefs(PartnerImportExportTDS MainDS, ref TVerificationResultCollection ReferenceResults, TDBTransaction Transaction) { // Special Applicant: keep a list of them! // Arrival Point: // Transport Type: // Leadership Rating: // PartyType: // PmOutreachRole: All from Short Term Application Rows foreach (PmShortTermApplicationRow rv in MainDS.PmShortTermApplication.Rows) { if ((rv.StSpecialApplicant != "") && (!PtSpecialApplicantAccess.Exists(rv.StSpecialApplicant, Transaction))) { MainDS.PtSpecialApplicant.DefaultView.RowFilter = String.Format("{0}='{1}'", PtSpecialApplicantTable.GetCodeDBName(), rv.StSpecialApplicant); if (MainDS.PtSpecialApplicant.DefaultView.Count == 0) // Check I've not just added this a moment ago.. { AddVerificationResult(ref ReferenceResults, "Adding Special Applicant " + rv.StSpecialApplicant); PtSpecialApplicantRow Row = MainDS.PtSpecialApplicant.NewRowTyped(); Row.Code = rv.StSpecialApplicant; Row.Description = FNewRowDescription; MainDS.PtSpecialApplicant.Rows.Add(Row); } } if ((rv.ArrivalPointCode != "") && (!PtArrivalPointAccess.Exists(rv.ArrivalPointCode, Transaction))) { MainDS.PtArrivalPoint.DefaultView.RowFilter = String.Format("{0}='{1}'", PtArrivalPointTable.GetCodeDBName(), rv.ArrivalPointCode); if (MainDS.PtArrivalPoint.DefaultView.Count == 0) // I've not just added this a moment ago.. { AddVerificationResult(ref ReferenceResults, "Adding new arrival point code '" + rv.ArrivalPointCode + "'"); PtArrivalPointRow Row = MainDS.PtArrivalPoint.NewRowTyped(); Row.Code = rv.ArrivalPointCode; Row.Description = FNewRowDescription; MainDS.PtArrivalPoint.Rows.Add(Row); } } if ((rv.DeparturePointCode != "") && (!PtArrivalPointAccess.Exists(rv.DeparturePointCode, Transaction))) { MainDS.PtArrivalPoint.DefaultView.RowFilter = String.Format("{0}='{1}'", PtArrivalPointTable.GetCodeDBName(), rv.DeparturePointCode); if (MainDS.PtArrivalPoint.DefaultView.Count == 0) // I've not just added this a moment ago.. { AddVerificationResult(ref ReferenceResults, "Adding new arrival point code '" + rv.DeparturePointCode + "'"); PtArrivalPointRow Row = MainDS.PtArrivalPoint.NewRowTyped(); Row.Code = rv.DeparturePointCode; Row.Description = FNewRowDescription; MainDS.PtArrivalPoint.Rows.Add(Row); } } if ((rv.TravelTypeToCongCode != "") && (!PtTravelTypeAccess.Exists(rv.TravelTypeToCongCode, Transaction))) { MainDS.PtTravelType.DefaultView.RowFilter = String.Format("{0}='{1}'", PtTravelTypeTable.GetCodeDBName(), rv.TravelTypeToCongCode); if (MainDS.PtTravelType.DefaultView.Count == 0) // I've not just added this a moment ago.. { AddVerificationResult(ref ReferenceResults, "Adding new Travel Type " + rv.TravelTypeToCongCode); PtTravelTypeRow Row = MainDS.PtTravelType.NewRowTyped(); Row.Code = rv.TravelTypeToCongCode; Row.Description = FNewRowDescription; MainDS.PtTravelType.Rows.Add(Row); } } if ((rv.TravelTypeFromCongCode != "") && (!PtTravelTypeAccess.Exists(rv.TravelTypeFromCongCode, Transaction))) { MainDS.PtTravelType.DefaultView.RowFilter = String.Format("{0}='{1}'", PtTravelTypeTable.GetCodeDBName(), rv.TravelTypeFromCongCode); if (MainDS.PtTravelType.DefaultView.Count == 0) // I've not just added this a moment ago.. { AddVerificationResult(ref ReferenceResults, "Adding new Travel Type " + rv.TravelTypeFromCongCode); PtTravelTypeRow Row = MainDS.PtTravelType.NewRowTyped(); Row.Code = rv.TravelTypeFromCongCode; Row.Description = FNewRowDescription; MainDS.PtTravelType.Rows.Add(Row); } } if ((rv.OutreachRole != "") && (!PtCongressCodeAccess.Exists(rv.OutreachRole, Transaction))) { MainDS.PtCongressCode.DefaultView.RowFilter = String.Format("{0}='{1}'", PtCongressCodeTable.GetCodeDBName(), (rv.OutreachRole)); if (MainDS.PtCongressCode.DefaultView.Count == 0) // Check I've not just added this a moment ago.. { AddVerificationResult(ref ReferenceResults, "Adding new Congress Code " + rv.OutreachRole); PtCongressCodeRow Row = MainDS.PtCongressCode.NewRowTyped(); Row.Code = rv.OutreachRole; Row.Description = FNewRowDescription; MainDS.PtCongressCode.Rows.Add(Row); } } } }
private static void CheckCommitmentStatus(PartnerImportExportTDS MainDS, ref TVerificationResultCollection ReferenceResults, TDBTransaction Transaction) { // Commitment Status Code: I'm not going to add this, but I should inform the user... foreach (PmStaffDataRow rv in MainDS.PmStaffData.Rows) { if ((rv.StatusCode != "") && (!PmCommitmentStatusAccess.Exists(rv.StatusCode, Transaction))) { AddVerificationResult(ref ReferenceResults, "Removing unknown Commitment Status " + rv.StatusCode); rv.StatusCode = ""; /* * TLogging.Log("Adding new commitment status code " + rv.StatusCode); * PmCommitmentStatusRow commitmentStatusRow = MainDS.PmCommitmentStatus.NewRowTyped(); * commitmentStatusRow.Code = rv.StatusCode; * commitmentStatusRow.Desc = NewRowDescription; * MainDS.PmCommitmentStatus.Rows.Add(commitmentStatusRow); */ } } }
private static void CheckApplication(PartnerImportExportTDS MainDS, ref TVerificationResultCollection ReferenceResults, TDBTransaction Transaction) { // The Application must be unique - if it's present already, I can update the existing record. // ApplicationStatus: Application Status must be listed in PtApplicantStatus // ApplicantType: applicants must be of known types // ApplicationType: applications must be of known types for (int RowIdx = 0; RowIdx < MainDS.PmGeneralApplication.Rows.Count; RowIdx++) { PmGeneralApplicationRow GenAppRow = MainDS.PmGeneralApplication[RowIdx]; // Check if this row already exists, using the unique key if (PmGeneralApplicationAccess.Exists(GenAppRow.PartnerKey, GenAppRow.GenAppDate, GenAppRow.AppTypeName, GenAppRow.OldLink, Transaction)) { // If it does, I need to update and not add. PmGeneralApplicationTable Tbl = PmGeneralApplicationAccess.LoadByUniqueKey( GenAppRow.PartnerKey, GenAppRow.GenAppDate, GenAppRow.AppTypeName, GenAppRow.OldLink, Transaction); PmGeneralApplicationRow ExistingRow = Tbl[0]; GenAppRow.AcceptChanges(); GenAppRow.ModificationId = ExistingRow.ModificationId; AddVerificationResult(ref ReferenceResults, "Existing Application record updated."); } if ((GenAppRow.GenApplicationStatus != "") && (!PtApplicantStatusAccess.Exists(GenAppRow.GenApplicationStatus, Transaction))) { MainDS.PtApplicantStatus.DefaultView.RowFilter = String.Format("{0}='{1}'", PtApplicantStatusTable.GetCodeDBName(), GenAppRow.GenApplicationStatus); if (MainDS.PtApplicantStatus.DefaultView.Count == 0) // I've not just added this a moment ago.. { AddVerificationResult(ref ReferenceResults, "Adding new Applicant Status " + GenAppRow.GenApplicationStatus); PtApplicantStatusRow Row = MainDS.PtApplicantStatus.NewRowTyped(); Row.Code = GenAppRow.GenApplicationStatus; Row.Description = FNewRowDescription; MainDS.PtApplicantStatus.Rows.Add(Row); } } if (GenAppRow.IsGenApplicantTypeNull()) { GenAppRow.GenApplicantType = "Gen App"; // This field is scheduled for deletion, but for now it's NOT NULL. } if (GenAppRow.AppTypeName == "") { GenAppRow.AppTypeName = "CONFERENCE"; } if ((GenAppRow.AppTypeName != "") && (!PtApplicationTypeAccess.Exists(GenAppRow.AppTypeName, Transaction))) { MainDS.PtApplicationType.DefaultView.RowFilter = String.Format("{0}='{1}'", PtApplicationTypeTable.GetAppTypeNameDBName(), GenAppRow.AppTypeName); if (MainDS.PtApplicationType.DefaultView.Count == 0) // I've not just added this a moment ago.. { AddVerificationResult(ref ReferenceResults, "Adding new Application Type " + GenAppRow.AppTypeName); PtApplicationTypeRow Row = MainDS.PtApplicationType.NewRowTyped(); Row.AppTypeName = GenAppRow.AppTypeName; Row.AppTypeDescr = FNewRowDescription; MainDS.PtApplicationType.Rows.Add(Row); } } if ((GenAppRow.GenContact1 != "") && (!PtContactAccess.Exists(GenAppRow.GenContact1, Transaction))) { MainDS.PtContact.DefaultView.RowFilter = String.Format("{0}='{1}'", PtContactTable.GetContactNameDBName(), GenAppRow.GenContact1); if (MainDS.PtContact.DefaultView.Count == 0) // I've not just added this a moment ago.. { AddVerificationResult(ref ReferenceResults, "Adding new Contact Name " + GenAppRow.GenContact1); PtContactRow Row = MainDS.PtContact.NewRowTyped(); Row.ContactName = GenAppRow.GenContact1; Row.ContactDescr = FNewRowDescription; MainDS.PtContact.Rows.Add(Row); } } if ((GenAppRow.GenContact2 != "") && (!PtContactAccess.Exists(GenAppRow.GenContact2, Transaction))) { MainDS.PtContact.DefaultView.RowFilter = String.Format("{0}='{1}'", PtContactTable.GetContactNameDBName(), GenAppRow.GenContact2); if (MainDS.PtContact.DefaultView.Count == 0) // I've not just added this a moment ago.. { AddVerificationResult(ref ReferenceResults, "Adding new Contact Name " + GenAppRow.GenContact2); PtContactRow Row = MainDS.PtContact.NewRowTyped(); Row.ContactName = GenAppRow.GenContact2; Row.ContactDescr = FNewRowDescription; MainDS.PtContact.Rows.Add(Row); } } } }
private static void CheckContactRefs(PartnerImportExportTDS MainDS, ref TVerificationResultCollection ReferenceResults, TDBTransaction ATransaction) { //int ContactId = 0; //foreach (PartnerImportExportTDSPPartnerContactRow Row in MainDS.PPartnerContact.Rows) //{ // PPartnerContactTable Tbl = PPartnerContactAccess.LoadByUniqueKey(Row.PartnerKey, Row.ContactDate, Row.ContactTime, ATransaction); // bool HereAlready = false; // if (Tbl.Rows.Count > 0) // I've already imported this.. // { // Row.AcceptChanges(); // This should make the DB update instead of Add // Row.ContactId = Tbl[0].ContactId; // Row.ModificationId = Tbl[0].ModificationId; // HereAlready = true; // } // if (Row.ContactId == 0) // { // Row.ContactId = --ContactId; // } // // The row has custom Attr and Detail fields, which I need to put into the right tables.. // if (!HereAlready && (Row.ContactAttr != "")) // { // AddVerificationResult(ref ReferenceResults, "Adding new contact attribute: " + Row.ContactAttr, TResultSeverity.Resv_Status); // PContactAttributeDetailRow PcadRow = MainDS.PContactAttributeDetail.NewRowTyped(); // PcadRow.ContactAttributeCode = Row.ContactAttr; // PcadRow.ContactAttrDetailCode = Row.ContactDetail; // PcadRow.ContactAttrDetailDescr = FNewRowDescription; // PContactAttributeDetailAccess.AddOrModifyRecord( // PcadRow.ContactAttributeCode, // PcadRow.ContactAttrDetailCode, // MainDS.PContactAttributeDetail, // PcadRow, false, ATransaction); // PPartnerContactAttributeRow PcaRow = MainDS.PPartnerContactAttribute.NewRowTyped(); // PcaRow.ContactId = Row.ContactId; // PcaRow.ContactAttributeCode = Row.ContactAttr; // PcaRow.ContactAttrDetailCode = Row.ContactDetail; // PPartnerContactAttributeAccess.AddOrModifyRecord( // PcaRow.ContactId, // PcaRow.ContactAttributeCode, // PcaRow.ContactAttrDetailCode, // MainDS.PPartnerContactAttribute, // PcaRow, false, ATransaction); // PContactAttributeRow CaRow = MainDS.PContactAttribute.NewRowTyped(); // CaRow.ContactAttributeDescr = FNewRowDescription; // CaRow.ContactAttributeCode = Row.ContactAttr; // PContactAttributeAccess.AddOrModifyRecord( // CaRow.ContactAttributeCode, // MainDS.PContactAttribute, // CaRow, // false, // ATransaction); // } // if (!PMethodOfContactAccess.Exists(Row.ContactCode, ATransaction)) // { // AddVerificationResult(ref ReferenceResults, "Adding new method of contact: " + Row.ContactCode, TResultSeverity.Resv_Status); // PMethodOfContactRow MocRow = MainDS.PMethodOfContact.NewRowTyped(); // MocRow.MethodOfContactCode = Row.ContactCode; // MocRow.Description = FNewRowDescription; // MocRow.ValidMethod = true; // MainDS.PMethodOfContact.Rows.Add(MocRow); // } //} }
private static void CreateShortTermApplication(XmlNode ANode, Int64 APartnerKey, ref PartnerImportExportTDS AMainDS, TDBTransaction ATransaction) { String strEventKey = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_EVENTKEY); long EventKey = -1; if (strEventKey.Length > 0) { try { EventKey = long.Parse(strEventKey); } catch (System.FormatException) { AddVerificationResult("Bad number format in EventKey: " + strEventKey); } if (!PUnitAccess.Exists(EventKey, ATransaction)) { AddVerificationResult("EventKey not known - application cannot be imported: " + EventKey); return; } PmGeneralApplicationRow GenAppRow = AMainDS.PmGeneralApplication.NewRowTyped(); GenAppRow.PartnerKey = APartnerKey; GenAppRow.ApplicationKey = (int)DBAccess.GDBAccessObj.GetNextSequenceValue("seq_application", ATransaction); GenAppRow.OldLink = TSystemDefaults.GetSystemDefault(SharedConstants.SYSDEFAULT_SITEKEY, "") + ";" + GenAppRow.ApplicationKey.ToString(); GenAppRow.RegistrationOffice = DomainManager.GSiteKey; // When this is imported, RegistrationOffice can't be null. GenAppRow.GenAppDate = DateTime.Now; GenAppRow.AppTypeName = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_APPTYPE); GenAppRow.GenApplicationStatus = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_APPSTATUS); GenAppRow.Comment = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_APPCOMMENTS); PmShortTermApplicationRow ShortTermRow = AMainDS.PmShortTermApplication.NewRowTyped(); ShortTermRow.PartnerKey = APartnerKey; ShortTermRow.ApplicationKey = GenAppRow.ApplicationKey; ShortTermRow.RegistrationOffice = GenAppRow.RegistrationOffice; // When this is imported, RegistrationOffice can't be null. ShortTermRow.StBasicOutreachId = "Unused field"; // This field is scheduled for deletion, but NOT NULL now. ShortTermRow.StAppDate = DateTime.Now; ShortTermRow.StApplicationType = GenAppRow.AppTypeName; ShortTermRow.StConfirmedOption = EventKey; String TimeString = ""; try { TimeString = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_ARRIVALDATE); if (TimeString.Length > 0) { ShortTermRow.Arrival = DateTime.Parse(TimeString); } TimeString = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_DEPARTUREDATE); if (TimeString.Length > 0) { ShortTermRow.Departure = DateTime.Parse(TimeString); } } catch (System.FormatException) { AddVerificationResult("Bad date format in Application: " + TimeString); } DateTime TempTime; TimeString = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_ARRIVALTIME); if (TimeString.Length > 0) { try { TempTime = DateTime.Parse(TimeString); ShortTermRow.ArrivalHour = TempTime.Hour; ShortTermRow.ArrivalMinute = TempTime.Minute; } catch (System.FormatException) { AddVerificationResult("Bad time format in Application: " + TimeString); } } TimeString = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_DEPARTURETIME); if (TimeString.Length > 0) { try { TempTime = DateTime.Parse(TimeString); ShortTermRow.DepartureHour = TempTime.Hour; ShortTermRow.DepartureMinute = TempTime.Minute; } catch (System.FormatException) { AddVerificationResult("Bad time format in Application: " + TimeString); } } ShortTermRow.OutreachRole = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_EVENTROLE); String ChargedField = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_CHARGEDFIELD); if (ChargedField.Length > 0) { try { ShortTermRow.StFieldCharged = long.Parse(ChargedField); } catch { AddVerificationResult("Bad number format in ChargedField: " + ChargedField); } } AMainDS.PmGeneralApplication.Rows.Add(GenAppRow); AMainDS.PmShortTermApplication.Rows.Add(ShortTermRow); AddVerificationResult("Application Record Created.", TResultSeverity.Resv_Status); } }
private static void CheckChurchDenomination(PartnerImportExportTDS MainDS, ref TVerificationResultCollection ReferenceResults, TDBTransaction Transaction) { // Denomination: If a church belongs to one, we need to know about it. foreach (PChurchRow rv in MainDS.PChurch.Rows) { if ((rv.DenominationCode != "") & (!PDenominationAccess.Exists(rv.DenominationCode, Transaction))) { AddVerificationResult(ref ReferenceResults, "Adding new Denomination " + rv.DenominationCode); PDenominationRow Row = MainDS.PDenomination.NewRowTyped(); Row.DenominationCode = rv.DenominationCode; Row.DenominationName = FNewRowDescription; MainDS.PDenomination.Rows.Add(Row); } } }
/// <summary> /// generate the units /// </summary> /// <param name="AFieldCSVFile"></param> public static void GenerateFields(string AFieldCSVFile) { XmlDocument doc = TCsv2Xml.ParseCSVFile2Xml(AFieldCSVFile, ","); XmlNode RecordNode = doc.FirstChild.NextSibling.FirstChild; PartnerImportExportTDS PartnerDS = new PartnerImportExportTDS(); GLSetupTDS GLSetupDS = new GLSetupTDS(); PCountryTable CountryTable = null; TDBTransaction Transaction = new TDBTransaction(); DBAccess.ReadTransaction( ref Transaction, delegate { CountryTable = PCountryAccess.LoadAll(Transaction); }); while (RecordNode != null) { PUnitRow UnitRow = PartnerDS.PUnit.NewRowTyped(); long id = 100 + Convert.ToInt64(TXMLParser.GetAttribute(RecordNode, "id")); UnitRow.PartnerKey = id * 1000000; string CountryCode = TXMLParser.GetAttribute(RecordNode, "Name"); UnitRow.UnitName = ((PCountryRow)CountryTable.Rows.Find(CountryCode)).CountryName; UnitRow.UnitTypeCode = "F"; PartnerDS.PUnit.Rows.Add(UnitRow); PPartnerRow PartnerRow = PartnerDS.PPartner.NewRowTyped(); PartnerRow.PartnerKey = UnitRow.PartnerKey; PartnerRow.PartnerShortName = UnitRow.UnitName; PartnerRow.PartnerClass = MPartnerConstants.PARTNERCLASS_UNIT; PartnerRow.StatusCode = MPartnerConstants.PARTNERSTATUS_ACTIVE; PartnerDS.PPartner.Rows.Add(PartnerRow); // add empty location so that the partner can be found in the Partner Find screen PPartnerLocationRow PartnerLocationRow = PartnerDS.PPartnerLocation.NewRowTyped(); PartnerLocationRow.PartnerKey = UnitRow.PartnerKey; PartnerLocationRow.LocationKey = 0; PartnerLocationRow.SiteKey = 0; PartnerDS.PPartnerLocation.Rows.Add(PartnerLocationRow); // create unit hierarchy UmUnitStructureRow UnitStructureRow = PartnerDS.UmUnitStructure.NewRowTyped(); UnitStructureRow.ParentUnitKey = 1000000; UnitStructureRow.ChildUnitKey = UnitRow.PartnerKey; PartnerDS.UmUnitStructure.Rows.Add(UnitStructureRow); // create special type PPartnerTypeRow PartnerTypeRow = PartnerDS.PPartnerType.NewRowTyped(); PartnerTypeRow.PartnerKey = UnitRow.PartnerKey; PartnerTypeRow.TypeCode = MPartnerConstants.PARTNERTYPE_LEDGER; PartnerDS.PPartnerType.Rows.Add(PartnerTypeRow); // create cost centre ACostCentreRow CostCentreRow = GLSetupDS.ACostCentre.NewRowTyped(); CostCentreRow.LedgerNumber = FLedgerNumber; CostCentreRow.CostCentreCode = (id * 100).ToString("0000"); CostCentreRow.CostCentreName = UnitRow.UnitName; CostCentreRow.CostCentreToReportTo = MFinanceConstants.INTER_LEDGER_HEADING; CostCentreRow.CostCentreType = MFinanceConstants.FOREIGN_CC_TYPE; GLSetupDS.ACostCentre.Rows.Add(CostCentreRow); // create foreign ledger, cost centre link validledgernumber AValidLedgerNumberRow ValidLedgerNumber = GLSetupDS.AValidLedgerNumber.NewRowTyped(); ValidLedgerNumber.LedgerNumber = FLedgerNumber; ValidLedgerNumber.PartnerKey = UnitRow.PartnerKey; ValidLedgerNumber.CostCentreCode = CostCentreRow.CostCentreCode; ValidLedgerNumber.IltProcessingCentre = Convert.ToInt64(MFinanceConstants.ICH_COST_CENTRE) * 10000; GLSetupDS.AValidLedgerNumber.Rows.Add(ValidLedgerNumber); RecordNode = RecordNode.NextSibling; } PartnerImportExportTDSAccess.SubmitChanges(PartnerDS); GLSetupTDSAccess.SubmitChanges(GLSetupDS); }
private void AddPersonalDocument(Int64 AOrigPartnerKey, Int64 ANewPartnerKey, ref PartnerImportExportTDS ANewPartnerDS) { ImportRecordsByPartnerKey(ANewPartnerDS.PmDocument, FMainDS.PmDocument, PmDocumentTable.GetPartnerKeyDBName(), AOrigPartnerKey, ANewPartnerKey); }
private static void CreateSpecialTypes(XmlNode ANode, Int64 APartnerKey, String ACSVKey, ref PartnerImportExportTDS AMainDS) { for (int Idx = 1; Idx < 6; Idx++) { String SpecialType = TXMLParser.GetAttribute(ANode, ACSVKey + Idx.ToString()); if (SpecialType.Length > 0) { PPartnerTypeRow partnerType = AMainDS.PPartnerType.NewRowTyped(true); partnerType.PartnerKey = APartnerKey; partnerType.TypeCode = SpecialType; AMainDS.PPartnerType.Rows.Add(partnerType); } } }
private void AddPersonalEvaluation(Int64 AOrigPartnerKey, Int64 ANewPartnerKey, ref PartnerImportExportTDS ANewPartnerDS) { ImportRecordsByPartnerKey(ANewPartnerDS.PmPersonEvaluation, FMainDS.PmPersonEvaluation, PmPersonEvaluationTable.GetPartnerKeyDBName(), AOrigPartnerKey, ANewPartnerKey); }
private void AddApplication(Int64 AOrigPartnerKey, Int64 ANewPartnerKey, ref PartnerImportExportTDS ANewPartnerDS) { ImportRecordsByPartnerKey(ANewPartnerDS.PmGeneralApplication, FMainDS.PmGeneralApplication, PmGeneralApplicationTable.GetPartnerKeyDBName(), AOrigPartnerKey, ANewPartnerKey); ImportRecordsByPartnerKey(ANewPartnerDS.PmShortTermApplication, FMainDS.PmShortTermApplication, PmShortTermApplicationTable.GetPartnerKeyDBName(), AOrigPartnerKey, ANewPartnerKey); ImportRecordsByPartnerKey(ANewPartnerDS.PmYearProgramApplication, FMainDS.PmYearProgramApplication, PmYearProgramApplicationTable.GetPartnerKeyDBName(), AOrigPartnerKey, ANewPartnerKey); }
private void AddInterest(Int64 AOrigPartnerKey, Int64 ANewPartnerKey, ref PartnerImportExportTDS ANewPartnerDS) { ImportRecordsByPartnerKey(ANewPartnerDS.PPartnerInterest, FMainDS.PPartnerInterest, PPartnerInterestTable.GetPartnerKeyDBName(), AOrigPartnerKey, ANewPartnerKey); }
private void AddAddresses(Int64 AOrigPartnerKey, Int64 ANewPartnerKey, ref PartnerImportExportTDS ANewPartnerDS) { FMainDS.PPartnerLocation.DefaultView.RowFilter = String.Format("{0}={1}", PPartnerLocationTable.GetPartnerKeyDBName(), AOrigPartnerKey); foreach (DataRowView rv in FMainDS.PPartnerLocation.DefaultView) { PPartnerLocationRow PartnerLocationRow = (PPartnerLocationRow)rv.Row; bool importingAlready = false; FMainDS.PLocation.DefaultView.RowFilter = String.Format("{0}={1} and {2}={3}", PLocationTable.GetLocationKeyDBName(), PartnerLocationRow.LocationKey, PLocationTable.GetSiteKeyDBName(), PartnerLocationRow.SiteKey); if ((FMainDS.PLocation.DefaultView.Count == 0) && (PartnerLocationRow.LocationKey >= 0)) { PartnerLocationRow.PartnerKey = ANewPartnerKey; // If this PartnerLocation has a real database key or points to location 0, import it anyway! ANewPartnerDS.PPartnerLocation.ImportRow(PartnerLocationRow); } else { foreach (DataRowView NewLocationRv in FMainDS.PLocation.DefaultView) { PLocationRow NewLocation = (PLocationRow)NewLocationRv.Row; // Check address already being imported, comparing StreetName and PostalCode // If I'm already importing it, I'll ignore this row. // (The address may still be already in the database.) foreach (DataRowView plrv in ANewPartnerDS.PLocation.DefaultView) { PLocationRow ExistingLocation = (PLocationRow)plrv.Row; if ( (ExistingLocation.Locality == NewLocation.Locality) && (ExistingLocation.StreetName == NewLocation.StreetName) && (ExistingLocation.PostalCode == NewLocation.PostalCode) ) { importingAlready = true; break; } } if (!importingAlready) // This row is not already on my list { ANewPartnerDS.PLocation.ImportRow(NewLocation); ANewPartnerDS.PPartnerLocation.ImportRow(PartnerLocationRow); // Set the PartnerKey for the new Row int NewRow = ANewPartnerDS.PPartnerLocation.Rows.Count - 1; ANewPartnerDS.PPartnerLocation[NewRow].PartnerKey = ANewPartnerKey;; } } } } }
private void AddUnitstructure(Int64 AOrigPartnerKey, Int64 ANewPartnerKey, ref PartnerImportExportTDS ANewPartnerDS) { bool recordAlreadyExists = false; FMainDS.UmUnitStructure.DefaultView.RowFilter = String.Format("{0}={1}", UmUnitStructureTable.GetChildUnitKeyDBName(), AOrigPartnerKey); if (FMainDS.UmUnitStructure.DefaultView.Count > 0) { UmUnitStructureRow unitStructureRow = (UmUnitStructureRow)FMainDS.UmUnitStructure.DefaultView[0].Row; // only import row if it does not exist yet in the new partner DS if (null != ANewPartnerDS.UmUnitStructure.Rows.Find(new object[] { unitStructureRow.ParentUnitKey, unitStructureRow.ChildUnitKey })) { recordAlreadyExists = true; } } if (!recordAlreadyExists) { ImportRecordsByPartnerKey(ANewPartnerDS.UmUnitStructure, FMainDS.UmUnitStructure, UmUnitStructureTable.GetChildUnitKeyDBName(), AOrigPartnerKey, ANewPartnerKey); } // // I need to import, or have imported, the unit that's the parent of this unit // otherwise the UmUnitStructure record will not save. ANewPartnerDS.UmUnitStructure.DefaultView.Sort = UmUnitStructureTable.GetChildUnitKeyDBName(); Int32 RowIdx = ANewPartnerDS.UmUnitStructure.DefaultView.Find(AOrigPartnerKey); if (RowIdx < 0) // If I can't find the record I've just added, that's pretty bad! { return; } UmUnitStructureRow NewRow = (UmUnitStructureRow)ANewPartnerDS.UmUnitStructure.DefaultView[RowIdx].Row; Int64 ParentKey = NewRow.ParentUnitKey; if (!FImportedUnits.Contains(ParentKey)) { String PartnerShortName; TPartnerClass PartnerClass; Boolean IsMergedPartner; Boolean UserCanAccessPartner; Boolean PartnerExistsInDB = TServerLookup.TMPartner.VerifyPartner(ParentKey, out PartnerShortName, out PartnerClass, out IsMergedPartner, out UserCanAccessPartner); if (!PartnerExistsInDB) // If this partner is not already in the database { FMainDS.PPartner.DefaultView.RowFilter = String.Format("{0}={1}", PPartnerTable.GetPartnerKeyDBName(), ParentKey); // // If there is no parent I can still import this UNIT, // but I'll set the parent to root, and modify the description // if (FMainDS.PPartner.DefaultView.Count == 0) { NewRow.ParentUnitKey = 1000000; ANewPartnerDS.PUnit.DefaultView.Sort = PUnitTable.GetPartnerKeyDBName(); RowIdx = ANewPartnerDS.PUnit.DefaultView.Find(AOrigPartnerKey); PUnitRow UnitRow = (PUnitRow)ANewPartnerDS.PUnit.DefaultView[RowIdx].Row; UnitRow.Description += String.Format("(Prev. parent {0})", ParentKey); } else { PPartnerRow ParentRow = (PPartnerRow)FMainDS.PPartner.DefaultView[0].Row; AddStatus("<Import parent Unit>" + Environment.NewLine); CreateOrUpdatePartner(ParentRow, false); // This is recursive! } } } }
private void AddStaffData(Int64 AOrigPartnerKey, Int64 ANewPartnerKey, ref PartnerImportExportTDS ANewPartnerDS) { ImportRecordsByPartnerKey(ANewPartnerDS.PmStaffData, FMainDS.PmStaffData, PmStaffDataTable.GetPartnerKeyDBName(), AOrigPartnerKey, ANewPartnerKey); }
private void AddBuilding(Int64 AOrigPartnerKey, Int64 ANewPartnerKey, ref PartnerImportExportTDS ANewPartnerDS) { ImportRecordsByPartnerKey(ANewPartnerDS.PcBuilding, FMainDS.PcBuilding, PcBuildingTable.GetVenueKeyDBName(), AOrigPartnerKey, ANewPartnerKey); }
private void AddJobAssignment(Int64 AOrigPartnerKey, Int64 ANewPartnerKey, ref PartnerImportExportTDS ANewPartnerDS) { PmJobAssignmentRow JobAssignmentRow; // add all jobs that exist for any job assignments for this partner FMainDS.PmJobAssignment.DefaultView.RowFilter = String.Format("{0}={1}", PmJobAssignmentTable.GetPartnerKeyDBName(), AOrigPartnerKey); foreach (DataRowView rv in FMainDS.PmJobAssignment.DefaultView) { JobAssignmentRow = (PmJobAssignmentRow)rv.Row; // find the job that exists for the current job assignment for this partner FMainDS.UmJob.DefaultView.RowFilter = String.Format("{0}={1} AND {2}='{3}' AND {4}='{5}' AND {6}={7}", UmJobTable.GetUnitKeyDBName(), JobAssignmentRow.UnitKey, UmJobTable.GetPositionNameDBName(), JobAssignmentRow.PositionName, UmJobTable.GetPositionScopeDBName(), JobAssignmentRow.PositionScope, UmJobTable.GetJobKeyDBName(), JobAssignmentRow.JobKey); foreach (DataRowView rv2 in FMainDS.UmJob.DefaultView) { ANewPartnerDS.UmJob.ImportRow(rv2.Row); } } ImportRecordsByPartnerKey(ANewPartnerDS.PmJobAssignment, FMainDS.PmJobAssignment, PmJobAssignmentTable.GetPartnerKeyDBName(), AOrigPartnerKey, ANewPartnerKey); }
/// <summary> /// Create new partner, family, location and PartnerLocation records in MainDS /// </summary> private static Int64 CreateNewFamily(XmlNode ANode, out int ALocationKey, ref PartnerImportExportTDS AMainDS) { PPartnerRow newPartner = AMainDS.PPartner.NewRowTyped(); AMainDS.PPartner.Rows.Add(newPartner); newPartner.PartnerKey = (AMainDS.PPartner.Rows.Count + 1) * -1; newPartner.PartnerClass = MPartnerConstants.PARTNERCLASS_FAMILY; newPartner.StatusCode = MPartnerConstants.PARTNERSTATUS_ACTIVE; newPartner.Comment = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_NOTESFAMILY); String AcquisitionCode = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_AQUISITION); newPartner.AcquisitionCode = (AcquisitionCode.Length > 0) ? AcquisitionCode : MPartnerConstants.PARTNERIMPORT_AQUISITION_DEFAULT; newPartner.AddresseeTypeCode = MPartnerConstants.ADDRESSEETYPE_DEFAULT; if (TXMLParser.HasAttribute(ANode, MPartnerConstants.PARTNERIMPORT_ADDRESSEE_TYPE)) { newPartner.AddresseeTypeCode = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_ADDRESSEE_TYPE); } else { string gender = GetGenderCode(ANode); if (gender == MPartnerConstants.GENDER_MALE) { newPartner.AddresseeTypeCode = MPartnerConstants.ADDRESSEETYPE_MALE; } else if (gender == MPartnerConstants.GENDER_FEMALE) { newPartner.AddresseeTypeCode = MPartnerConstants.ADDRESSEETYPE_FEMALE; } } if (TXMLParser.HasAttribute(ANode, MPartnerConstants.PARTNERIMPORT_LANGUAGE)) { newPartner.LanguageCode = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_LANGUAGE); } else if (TUserDefaults.HasDefault(MSysManConstants.PARTNER_LANGUAGECODE)) { newPartner.LanguageCode = TUserDefaults.GetStringDefault(MSysManConstants.PARTNER_LANGUAGECODE); } string[] giftReceiptingDefaults = TSystemDefaults.GetSystemDefault("GiftReceiptingDefaults", ",no").Split(new char[] { ',' }); newPartner.ReceiptLetterFrequency = giftReceiptingDefaults[0]; newPartner.ReceiptEachGift = giftReceiptingDefaults[1] == "YES" || giftReceiptingDefaults[1] == "TRUE"; PFamilyRow newFamily = AMainDS.PFamily.NewRowTyped(); AMainDS.PFamily.Rows.Add(newFamily); newFamily.PartnerKey = newPartner.PartnerKey; newFamily.FirstName = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_FIRSTNAME); newFamily.FamilyName = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_FAMILYNAME); newFamily.MaritalStatus = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_MARITALSTATUS); newFamily.Title = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_TITLE); newFamily.MaritalStatus = GetMaritalStatusCode(ANode); newPartner.PartnerShortName = Calculations.DeterminePartnerShortName(newFamily.FamilyName, newFamily.Title, newFamily.FirstName); PLocationRow newLocation = AMainDS.PLocation.NewRowTyped(true); AMainDS.PLocation.Rows.Add(newLocation); newLocation.LocationKey = TPartnerImportCSV.FLocationKey; newLocation.Locality = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_LOCALITY); newLocation.StreetName = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_STREETNAME); newLocation.Address3 = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_ADDRESS); newLocation.PostalCode = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_POSTALCODE); newLocation.City = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_CITY); newLocation.County = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_COUNTY); newLocation.CountryCode = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_COUNTRYCODE); PPartnerLocationRow partnerlocation = AMainDS.PPartnerLocation.NewRowTyped(true); partnerlocation.LocationKey = TPartnerImportCSV.FLocationKey; partnerlocation.SiteKey = 0; partnerlocation.PartnerKey = newPartner.PartnerKey; partnerlocation.DateEffective = DateTime.Now; partnerlocation.LocationType = MPartnerConstants.LOCATIONTYPE_HOME; partnerlocation.SendMail = true; partnerlocation.EmailAddress = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_EMAIL); partnerlocation.TelephoneNumber = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_PHONE); partnerlocation.MobileNumber = TXMLParser.GetAttribute(ANode, MPartnerConstants.PARTNERIMPORT_MOBILEPHONE); AMainDS.PPartnerLocation.Rows.Add(partnerlocation); ALocationKey = TPartnerImportCSV.FLocationKey; TPartnerImportCSV.FLocationKey--; return(newPartner.PartnerKey); }
private void AddPmPersonLanguage(Int64 AOrigPartnerKey, Int64 ANewPartnerKey, ref PartnerImportExportTDS ANewPartnerDS) { ImportRecordsByPartnerKey(ANewPartnerDS.PmPersonLanguage, FMainDS.PmPersonLanguage, PmPersonLanguageTable.GetPartnerKeyDBName(), AOrigPartnerKey, ANewPartnerKey); }
/// <summary> /// Parses certain p_partner_location data columns' content into a data structure that is p_parnter_attribute /// representation. /// </summary> /// <remarks>Similar to code found in \csharp\ICT\BuildTools\DataDumpPetra2\FixData.cs, Method 'FixData', /// in the code section that starts with the comment 'Process p_partner_location records and migrate certain values /// of p_partner_location records to 'Contact Detail' records'.</remarks> /// <param name="AMainDS">Typed DataSet that holds the p_partner_location records that are to be parsed.</param> /// <param name="ATransaction">Instantiated DB Transaction.</param> public static void ParsePartnerLocationsForContactDetails(PartnerImportExportTDS AMainDS, TDBTransaction ATransaction) { DataTable PartnerLocationsDT; DataRow NewPartnerLocationDR; string TelephoneNumber = String.Empty; string FaxNumber = String.Empty; string PhoneExtension; string FaxExtension; // collect the partner classes foreach (PPartnerRow PartnerDR in AMainDS.PPartner.Rows) { TPartnerContactDetails.PartnerClassInformation[PartnerDR.PartnerKey] = PartnerDR.PartnerClass; } SortedList <long, DataTable> PartnerLocationsTables = new SortedList <long, DataTable>(); for (int counter = 0; counter < TPartnerContactDetails.NumberOfTables; counter++) { PartnerLocationsTables[counter] = TPartnerContactDetails.BestAddressHelper.GetNewPPartnerLocationTableInstance(); } TPartnerContactDetails.PartnerLocationRecords = PartnerLocationsTables; foreach (PPartnerLocationRow PartnerLocationDR in AMainDS.PPartnerLocation.Rows) { PartnerLocationsDT = PartnerLocationsTables[Math.Abs(PartnerLocationDR.PartnerKey) % TPartnerContactDetails.NumberOfTables]; // Phone Extension: Ignore if value in the dumped data is either null or 0 if (PartnerLocationDR.IsExtensionNull()) { PhoneExtension = String.Empty; } PhoneExtension = PartnerLocationDR.Extension.ToString(); if (PhoneExtension == "0") { PhoneExtension = String.Empty; } // Fax Extension: Ignore if value in the dumped data is either null or 0 if (PartnerLocationDR.IsFaxExtensionNull()) { FaxExtension = String.Empty; } FaxExtension = PartnerLocationDR.FaxExtension.ToString(); if (FaxExtension == "0") { FaxExtension = String.Empty; } if (!PartnerLocationDR.IsTelephoneNumberNull()) { // Concatenate Phone Number and Phone Extension ONLY if both of them aren't null and Phone Extension isn't 0 either. TelephoneNumber = PartnerLocationDR.TelephoneNumber + PhoneExtension; } if (!PartnerLocationDR.IsFaxNumberNull()) { // Concatenate Fax Number and Fax Extension ONLY if both of them aren't null and Fax Extension isn't 0 either. FaxNumber = PartnerLocationDR.FaxNumber + FaxExtension; } // Create representation of key data of the p_partner_location row and add it to the TPartnerContactDetails.PartnerLocationRecords Data Structure NewPartnerLocationDR = PartnerLocationsDT.NewRow(); NewPartnerLocationDR["p_partner_key_n"] = PartnerLocationDR.PartnerKey; NewPartnerLocationDR["p_site_key_n"] = PartnerLocationDR.SiteKey; NewPartnerLocationDR["p_location_key_i"] = PartnerLocationDR.LocationKey; if (!PartnerLocationDR.IsDateEffectiveNull()) { NewPartnerLocationDR["p_date_effective_d"] = PartnerLocationDR.DateEffective; } else { PartnerLocationDR.SetDateEffectiveNull(); } if (!PartnerLocationDR.IsDateGoodUntilNull()) { NewPartnerLocationDR["p_date_good_until_d"] = PartnerLocationDR.DateGoodUntil; } else { PartnerLocationDR.SetDateGoodUntilNull(); } NewPartnerLocationDR["p_location_type_c"] = PartnerLocationDR.LocationType; NewPartnerLocationDR["p_send_mail_l"] = PartnerLocationDR.SendMail; NewPartnerLocationDR["p_telephone_number_c"] = TelephoneNumber; NewPartnerLocationDR["p_fax_number_c"] = FaxNumber; NewPartnerLocationDR["p_mobile_number_c"] = PartnerLocationDR.MobileNumber; NewPartnerLocationDR["p_alternate_telephone_c"] = PartnerLocationDR.AlternateTelephone; NewPartnerLocationDR["p_email_address_c"] = PartnerLocationDR.EmailAddress; NewPartnerLocationDR["p_url_c"] = PartnerLocationDR.Url; PartnerLocationsDT.Rows.Add(NewPartnerLocationDR); } TPartnerContactDetails.CreateContactDetailsRow = CreatePartnerContactDetailRecord; TPartnerContactDetails.EmptyStringIndicator = String.Empty; TPartnerContactDetails.PartnerAttributeHoldingDataSet = AMainDS; TPartnerContactDetails.PopulatePPartnerAttribute(); Ict.Petra.Shared.MPartner.Calculations.DeterminePartnerContactDetailAttributes(AMainDS.PPartnerAttribute); }
private void AddPreviousExperience(Int64 AOrigPartnerKey, Int64 ANewPartnerKey, ref PartnerImportExportTDS ANewPartnerDS) { ImportRecordsByPartnerKey(ANewPartnerDS.PmPastExperience, FMainDS.PmPastExperience, PmPastExperienceTable.GetPartnerKeyDBName(), AOrigPartnerKey, ANewPartnerKey); }
/// <summary> /// generate the key ministries /// </summary> /// <param name="AKeyMinCSVFile"></param> public static void GenerateKeyMinistries(string AKeyMinCSVFile) { XmlDocument doc = TCsv2Xml.ParseCSVFile2Xml(AKeyMinCSVFile, ","); XmlNode RecordNode = doc.FirstChild.NextSibling.FirstChild; PartnerImportExportTDS PartnerDS = new PartnerImportExportTDS(); TDataBase db = DBAccess.Connect("GenerateKeyMinistries"); TDBTransaction Transaction = db.BeginTransaction(IsolationLevel.ReadCommitted); // get a list of fields (all class UNIT, with unit type F) string sqlGetFieldPartnerKeys = "SELECT p_partner_key_n, p_unit_name_c FROM PUB_p_unit WHERE u_unit_type_code_c = 'F'"; DataTable FieldKeys = db.SelectDT(sqlGetFieldPartnerKeys, "keys", Transaction); Transaction.Rollback(); Int32 NumberOfPartnerKeysReserved = 100; Int64 NextPartnerKey = TNewPartnerKey.ReservePartnerKeys(-1, ref NumberOfPartnerKeysReserved); while (RecordNode != null) { int FieldID = Convert.ToInt32(TXMLParser.GetAttribute(RecordNode, "field")) % FieldKeys.Rows.Count; long FieldPartnerKey = Convert.ToInt64(FieldKeys.Rows[FieldID].ItemArray[0]); PUnitRow UnitRow = PartnerDS.PUnit.NewRowTyped(); if (NumberOfPartnerKeysReserved == 0) { NumberOfPartnerKeysReserved = 100; NextPartnerKey = TNewPartnerKey.ReservePartnerKeys(-1, ref NumberOfPartnerKeysReserved); } long UnitPartnerKey = NextPartnerKey; NextPartnerKey++; NumberOfPartnerKeysReserved--; UnitRow.PartnerKey = UnitPartnerKey; UnitRow.UnitName = FieldKeys.Rows[FieldID].ItemArray[1].ToString() + " - " + TXMLParser.GetAttribute(RecordNode, "KeyMinName"); UnitRow.UnitTypeCode = "KEY-MIN"; PartnerDS.PUnit.Rows.Add(UnitRow); PPartnerRow PartnerRow = PartnerDS.PPartner.NewRowTyped(); PartnerRow.PartnerKey = UnitRow.PartnerKey; PartnerRow.PartnerShortName = UnitRow.UnitName; PartnerRow.PartnerClass = MPartnerConstants.PARTNERCLASS_UNIT; PartnerRow.StatusCode = MPartnerConstants.PARTNERSTATUS_ACTIVE; PartnerDS.PPartner.Rows.Add(PartnerRow); // add empty location so that the partner can be found in the Partner Find screen PPartnerLocationRow PartnerLocationRow = PartnerDS.PPartnerLocation.NewRowTyped(); PartnerLocationRow.PartnerKey = UnitRow.PartnerKey; PartnerLocationRow.LocationKey = 0; PartnerLocationRow.SiteKey = 0; PartnerDS.PPartnerLocation.Rows.Add(PartnerLocationRow); // create unit hierarchy UmUnitStructureRow UnitStructureRow = PartnerDS.UmUnitStructure.NewRowTyped(); UnitStructureRow.ParentUnitKey = FieldPartnerKey; UnitStructureRow.ChildUnitKey = UnitRow.PartnerKey; PartnerDS.UmUnitStructure.Rows.Add(UnitStructureRow); RecordNode = RecordNode.NextSibling; } PartnerImportExportTDSAccess.SubmitChanges(PartnerDS); }
private static void CheckPartnerType(PartnerImportExportTDS MainDS, ref TVerificationResultCollection ReferenceResults, TDBTransaction Transaction) { // PType: In the previous version, unknown types were not imported. foreach (PPartnerTypeRow rv in MainDS.PPartnerType.Rows) { if ((rv.TypeCode != "") && (!PTypeAccess.Exists(rv.TypeCode, Transaction))) { AddVerificationResult(ref ReferenceResults, "Adding new Partner Type " + rv.TypeCode); PTypeRow Row = MainDS.PType.NewRowTyped(); Row.TypeCode = rv.TypeCode; Row.TypeDescription = FNewRowDescription; MainDS.PType.Rows.Add(Row); } } }
/// <summary> /// Display File open dialog box and read file into memory /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OpenFile(System.Object sender, EventArgs e) { if (!FPetraUtilsObject.IsEnabled("actStartImport")) { MessageBox.Show(Catalog.GetString("Please cancel the current import before selecting a different file")); return; } txtPartnerInfo.Text = ""; OpenFileDialog DialogOpen = new OpenFileDialog(); DialogOpen.Filter = Catalog.GetString( "All supported formats|*.yml;*.csv;*.ext|Text file (*.yml)|*.yml|Partner Extract (*.ext)|*.ext|Partner List (*.csv)|.csv"); DialogOpen.FilterIndex = 1; DialogOpen.RestoreDirectory = true; DialogOpen.Title = Catalog.GetString("Select the file for importing partners"); if (DialogOpen.ShowDialog() == DialogResult.OK) { txtFilename.Text = DialogOpen.FileName; TVerificationResultCollection VerificationResult = null; AddStatus(String.Format("Reading {0}\r\n", Path.GetFileName(DialogOpen.FileName))); if (Path.GetExtension(DialogOpen.FileName) == ".yml") { TYml2Xml yml = new TYml2Xml(DialogOpen.FileName); AddStatus(Catalog.GetString("Parsing file. Please wait..\r\n")); FMainDS = TRemote.MPartner.ImportExport.WebConnectors.ImportPartnersFromYml(TXMLParser.XmlToString( yml.ParseYML2XML()), out VerificationResult); } if (Path.GetExtension(DialogOpen.FileName) == ".csv") { // select separator, make sure there is a header line with the column captions/names TDlgSelectCSVSeparator dlgSeparator = new TDlgSelectCSVSeparator(true); Boolean fileCanOpen = dlgSeparator.OpenCsvFile(DialogOpen.FileName); if (!fileCanOpen) { MessageBox.Show(Catalog.GetString("Unable to open file."), Catalog.GetString("Import Partners"), MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } if (dlgSeparator.ShowDialog() == DialogResult.OK) { XmlDocument doc = TCsv2Xml.ParseCSV2Xml(DialogOpen.FileName, dlgSeparator.SelectedSeparator); FMainDS = TRemote.MPartner.ImportExport.WebConnectors.ImportFromCSVFile(TXMLParser.XmlToString(doc), out VerificationResult); } } else if (Path.GetExtension(DialogOpen.FileName) == ".ext") { StreamReader sr = new StreamReader(DialogOpen.FileName, true); string[] FileContent = sr.ReadToEnd().Replace("\r", "").Split(new char[] { '\n' }); sr.Close(); AddStatus(String.Format("{0} lines.\r\n", FileContent.Length)); AddStatus(Catalog.GetString("Parsing file. Please wait..\r\n")); FMainDS = TRemote.MPartner.ImportExport.WebConnectors.ImportFromPartnerExtract(FileContent, out VerificationResult); } AddStatus(FormatVerificationResult("Imported file verification: ", VerificationResult)); if (!TVerificationHelper.IsNullOrOnlyNonCritical(VerificationResult)) { string ErrorMessages = String.Empty; foreach (TVerificationResult verif in VerificationResult) { ErrorMessages += "[" + verif.ResultContext + "] " + verif.ResultTextCaption + ": " + verif.ResultText + Environment.NewLine; } MessageBox.Show(ErrorMessages, Catalog.GetString("Import of partners failed!")); FMainDS = null; return; } AddStatus(String.Format(Catalog.GetString("File read OK ({0} partners) - press Start to import.\r\n"), FMainDS.PPartner.Rows.Count)); } }
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; } }
private void CancelImport(Object sender, EventArgs e) { // todo: cleanly stop the thread during automatic import? if (FThreadAutomaticImport != null) { FNeedUserFeedback = true; return; } FMainDS = null; // TODO: store partner keys of imported partners this.FPetraUtilsObject.EnableAction("actStartImport", true); this.FPetraUtilsObject.EnableAction("actCancelImport", false); }
private void AddAbility(Int64 AOrigPartnerKey, Int64 ANewPartnerKey, ref PartnerImportExportTDS ANewPartnerDS) { ImportRecordsByPartnerKey(ANewPartnerDS.PmPersonAbility, FMainDS.PmPersonAbility, PmPersonAbilityTable.GetPartnerKeyDBName(), AOrigPartnerKey, ANewPartnerKey); }
/// <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); }
private static void ParseFinancialDetails(PartnerImportExportTDS AMainDS, XmlNode AFinancialDetailsNode, Int64 APartnerKey, TDBTransaction ATransaction) { if (AFinancialDetailsNode != null) { string BankAccountNumber = TYml2Xml.GetAttributeRecursive(AFinancialDetailsNode, "AccountNumber"); string BankSortCode = TYml2Xml.GetAttributeRecursive(AFinancialDetailsNode, "BankSortCode"); // do we already have a bank with this sort code? Int64 bankPartnerKey = 0; AMainDS.PBank.DefaultView.Sort = PBankTable.GetBranchCodeDBName(); int bankIndex = AMainDS.PBank.DefaultView.Find(BankSortCode); if (bankIndex != -1) { bankPartnerKey = ((PBankRow)AMainDS.PBank.DefaultView[bankIndex].Row).PartnerKey; } if (bankPartnerKey == 0) { string sqlFindBankBySortCode = String.Format("SELECT * FROM PUB_{0} WHERE {1}=?", PBankTable.GetTableDBName(), PBankTable.GetBranchCodeDBName()); OdbcParameter param = new OdbcParameter("branchcode", OdbcType.VarChar); param.Value = BankSortCode; PBankTable bank = new PBankTable(); DBAccess.GDBAccessObj.SelectDT(bank, sqlFindBankBySortCode, ATransaction, new OdbcParameter[] { param }, -1, -1); if (bank.Count > 0) { bankPartnerKey = bank[0].PartnerKey; } } if (bankPartnerKey == 0) { // create a new bank record PBankRow bankRow = AMainDS.PBank.NewRowTyped(true); bankRow.PartnerKey = TImportExportYml.NewPartnerKey; TImportExportYml.NewPartnerKey--; bankRow.BranchCode = BankSortCode; bankRow.BranchName = BankSortCode; AMainDS.PBank.Rows.Add(bankRow); bankPartnerKey = bankRow.PartnerKey; } PBankingDetailsRow bankingDetailsRow = AMainDS.PBankingDetails.NewRowTyped(true); bankingDetailsRow.BankingDetailsKey = (AMainDS.PBankingDetails.Rows.Count + 1) * -1; bankingDetailsRow.BankingType = 0; bankingDetailsRow.BankAccountNumber = BankAccountNumber; bankingDetailsRow.BankKey = bankPartnerKey; AMainDS.PBankingDetails.Rows.Add(bankingDetailsRow); PPartnerBankingDetailsRow partnerBankingDetailsRow = AMainDS.PPartnerBankingDetails.NewRowTyped(true); partnerBankingDetailsRow.PartnerKey = APartnerKey; partnerBankingDetailsRow.BankingDetailsKey = bankingDetailsRow.BankingDetailsKey; AMainDS.PPartnerBankingDetails.Rows.Add(partnerBankingDetailsRow); } }