/// <summary> /// Determines which address is the 'Best Address' of a Partner, and returns the PPartnerLocation record which is the /// 'Best Address'. /// </summary> /// <remarks>There are two similar shared Methods in Namespace Ict.Petra.Server.MPartner.Common.Calculations, /// both called 'DetermineBestAddress' which work by passing in the PartnerLocations of a Partner in an Argument /// and which return a <see cref="TLocationPK" />. As those Methods don't access the database, these Methods /// can be used client-side as well!</remarks> /// <param name="APartnerKey">PartnerKey of the Partner whose addresses should be checked.</param> /// <param name="APartnerLocationDR">PPartnerLocation Record that is the record that is the Location of the 'Best Address'.</param> /// <param name="ADataBase">An instantiated <see cref="TDataBase" /> object, or null (default = null). If null /// gets passed then the Method executes DB commands with a new Database connection</param> /// <returns>A <see cref="TLocationPK" /> which points to the 'Best Address'. If no 'Best Address' was found, /// SiteKey and LocationKey of this instance will be both -1.</returns> public static TLocationPK DetermineBestAddress(Int64 APartnerKey, out PPartnerLocationRow APartnerLocationDR, TDataBase ADataBase = null) { TLocationPK ReturnValue = new TLocationPK(); PPartnerLocationTable PartnerLocationDT; Boolean NewTransaction; TDataBase db = DBAccess.Connect("DetermineBestAddress", ADataBase); TDBTransaction ReadTransaction = db.GetNewOrExistingTransaction( MCommonConstants.CACHEABLEDT_ISOLATIONLEVEL, out NewTransaction); try { PartnerLocationDT = PPartnerLocationAccess.LoadViaPPartner(APartnerKey, ReadTransaction); ReturnValue = Ict.Petra.Server.MPartner.Common.Calculations.DetermineBestAddress(PartnerLocationDT); APartnerLocationDR = (PPartnerLocationRow)PartnerLocationDT.Rows.Find(new object[] { APartnerKey, ReturnValue.SiteKey, ReturnValue.LocationKey }); } finally { if (NewTransaction) { ReadTransaction.Commit(); TLogging.LogAtLevel(7, "ServerCalculations.DetermineBestAddress: commited own transaction."); } } return(ReturnValue); }
/// create a new person public static PPersonRow CreateNewPerson(PartnerEditTDS AMainDS, Int64 AFamilyKey, Int32 ALocationKey, string AFirstName, string ATitle, int AFamilyID) { PPartnerRow PartnerRow = CreateNewPartner(AMainDS); PartnerRow.PartnerClass = MPartnerConstants.PARTNERCLASS_PERSON; PartnerRow.PartnerShortName = AFamilyKey.ToString() + ", " + AFirstName + ", " + ATitle; PPersonRow PersonRow = AMainDS.PPerson.NewRowTyped(); PersonRow.PartnerKey = PartnerRow.PartnerKey; PersonRow.FamilyKey = AFamilyKey; PersonRow.FamilyName = AFamilyKey.ToString(); PersonRow.FirstName = AFirstName; PersonRow.FamilyId = AFamilyID; PersonRow.Title = ATitle; AMainDS.PPerson.Rows.Add(PersonRow); PPartnerLocationRow PartnerLocationRow = AMainDS.PPartnerLocation.NewRowTyped(); PartnerLocationRow.SiteKey = DomainManager.GSiteKey; PartnerLocationRow.PartnerKey = PartnerRow.PartnerKey; PartnerLocationRow.LocationKey = ALocationKey; PartnerLocationRow.TelephoneNumber = PersonRow.PartnerKey.ToString(); AMainDS.PPartnerLocation.Rows.Add(PartnerLocationRow); return(PersonRow); }
/// <summary> /// Determines which address is the 'Best Address' of a Partner, and returns the PPartnerLocation record which is the /// 'Best Address'. /// </summary> /// <remarks>There are two similar shared Methods in Namespace Ict.Petra.Shared.MPartner.Calculations, /// both called 'DetermineBestAddress' which work by passing in the PartnerLocations of a Partner in an Argument /// and which return a <see cref="TLocationPK" />. As those Methods don't access the database, these Methods /// can be used client-side as well!</remarks> /// <param name="APartnerKey">PartnerKey of the Partner whose addresses should be checked.</param> /// <param name="APartnerLocationDR">PPartnerLocation Record that is the record that is the Location of the 'Best Address'.</param> /// <returns>A <see cref="TLocationPK" /> which points to the 'Best Address'. If no 'Best Address' was found, /// SiteKey and LocationKey of this instance will be both -1.</returns> public static TLocationPK DetermineBestAddress(Int64 APartnerKey, out PPartnerLocationRow APartnerLocationDR) { TLocationPK ReturnValue = new TLocationPK(); PPartnerLocationTable PartnerLocationDT; Boolean NewTransaction; TDBTransaction ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction( Ict.Petra.Server.MCommon.MCommonConstants.CACHEABLEDT_ISOLATIONLEVEL, TEnforceIsolationLevel.eilMinimum, out NewTransaction); try { PartnerLocationDT = PPartnerLocationAccess.LoadViaPPartner(APartnerKey, ReadTransaction); ReturnValue = Ict.Petra.Shared.MPartner.Calculations.DetermineBestAddress(PartnerLocationDT); APartnerLocationDR = (PPartnerLocationRow)PartnerLocationDT.Rows.Find(new object[] { APartnerKey, ReturnValue.SiteKey, ReturnValue.LocationKey }); } finally { if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); TLogging.LogAtLevel(7, "ServerCalculations.DetermineBestAddress: commited own transaction."); } } return(ReturnValue); }
/// <summary> /// Determines which address is the 'Best Address' of a Partner, and returns the PPartnerLocation record which is the /// 'Best Address'. /// </summary> /// <remarks>There are two similar shared Methods in Namespace Ict.Petra.Shared.MPartner.Calculations, /// both called 'DetermineBestAddress' which work by passing in the PartnerLocations of a Partner in an Argument /// and which return a <see cref="TLocationPK" />. As those Methods don't access the database, these Methods /// can be used client-side as well!</remarks> /// <param name="APartnerKey">PartnerKey of the Partner whose addresses should be checked.</param> /// <param name="APartnerLocationDR">PPartnerLocation Record that is the record that is the Location of the 'Best Address'.</param> /// <returns>A <see cref="TLocationPK" /> which points to the 'Best Address'. If no 'Best Address' was found, /// SiteKey and LocationKey of this instance will be both -1.</returns> public static TLocationPK DetermineBestAddress(Int64 APartnerKey, out PPartnerLocationRow APartnerLocationDR) { TLocationPK ReturnValue = new TLocationPK(); PPartnerLocationTable PartnerLocationDT; Boolean NewTransaction; TDBTransaction ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction( Ict.Petra.Server.MCommon.MCommonConstants.CACHEABLEDT_ISOLATIONLEVEL, TEnforceIsolationLevel.eilMinimum, out NewTransaction); try { PartnerLocationDT = PPartnerLocationAccess.LoadViaPPartner(APartnerKey, ReadTransaction); ReturnValue = Ict.Petra.Shared.MPartner.Calculations.DetermineBestAddress(PartnerLocationDT); APartnerLocationDR = (PPartnerLocationRow)PartnerLocationDT.Rows.Find(new object[] { APartnerKey, ReturnValue.SiteKey, ReturnValue.LocationKey }); } finally { if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); TLogging.LogAtLevel(7, "ServerCalculations.DetermineBestAddress: commited own transaction."); } } return ReturnValue; }
/// <summary> /// Sets up test location rows /// </summary> /// <param name="APartnerKey"></param> /// <param name="DateEffective"></param> /// <param name="GoodUntil"></param> /// <param name="Mailing"></param> /// <param name="Street"></param> /// <param name="AMainDS"></param> public void CreateNewLocation(Int64 APartnerKey, DateTime DateEffective, DateTime?GoodUntil, bool Mailing, string Street, PartnerEditTDS AMainDS) { // avoid duplicate addresses: StreetName contains the partner key PLocationRow LocationRow = AMainDS.PLocation.NewRowTyped(); LocationRow.SiteKey = DomainManager.GSiteKey; LocationRow.LocationKey = LocationKey++; LocationRow.StreetName = APartnerKey.ToString() + " " + Street; LocationRow.PostalCode = "LO2 2CX"; LocationRow.City = "London"; LocationRow.CountryCode = "99"; AMainDS.PLocation.Rows.Add(LocationRow); PPartnerLocationRow PartnerLocationRow = AMainDS.PPartnerLocation.NewRowTyped(); PartnerLocationRow.SiteKey = LocationRow.SiteKey; PartnerLocationRow.PartnerKey = APartnerKey; PartnerLocationRow.LocationKey = LocationRow.LocationKey; PartnerLocationRow.DateEffective = DateEffective; PartnerLocationRow.DateGoodUntil = GoodUntil; PartnerLocationRow.SendMail = Mailing; AMainDS.PPartnerLocation.Rows.Add(PartnerLocationRow); }
public void TestSaveNewPartnerWithExistingLocation() { TDataBase db = DBAccess.Connect("TestSaveNewPartnerWithExistingLocation"); TDBTransaction Transaction = db.BeginTransaction(IsolationLevel.Serializable); TPartnerEditUIConnector connector = new TPartnerEditUIConnector(db); PartnerEditTDS MainDS = new PartnerEditTDS(); PPartnerRow PartnerRow = TCreateTestPartnerData.CreateNewFamilyPartner(MainDS, db); TCreateTestPartnerData.CreateNewLocation(PartnerRow.PartnerKey, MainDS); DataSet ResponseDS = new PartnerEditTDS(); TVerificationResultCollection VerificationResult; TSubmitChangesResult result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult); Transaction.Commit(); CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResult, "There was a critical error when saving:"); Assert.AreEqual(TSubmitChangesResult.scrOK, result, "saving the first partner with a location"); Int32 LocationKey = MainDS.PLocation[0].LocationKey; MainDS = new PartnerEditTDS(); Transaction = db.BeginTransaction(IsolationLevel.Serializable); PartnerRow = TCreateTestPartnerData.CreateNewFamilyPartner(MainDS, db); PPartnerLocationRow PartnerLocationRow = MainDS.PPartnerLocation.NewRowTyped(); PartnerLocationRow.SiteKey = DomainManager.GSiteKey; PartnerLocationRow.PartnerKey = PartnerRow.PartnerKey; PartnerLocationRow.LocationKey = LocationKey; MainDS.PPartnerLocation.Rows.Add(PartnerLocationRow); ResponseDS = new PartnerEditTDS(); result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult); Transaction.Commit(); CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResult, "There was a critical error when saving:"); TDBTransaction ReadTransaction = new TDBTransaction(); db.ReadTransaction( ref ReadTransaction, delegate { PPartnerTable PartnerAtAddress = PPartnerAccess.LoadViaPLocation( DomainManager.GSiteKey, LocationKey, ReadTransaction); Assert.AreEqual(2, PartnerAtAddress.Rows.Count, "there should be two partners at this location"); }); }
/// <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); }
public static Boolean VerifyPartnerAtLocation(Int64 APartnerKey, TLocationPK ALocationKey, out bool AAddressNeitherCurrentNorMailing) { AAddressNeitherCurrentNorMailing = true; TDBTransaction ReadTransaction; Boolean NewTransaction; PPartnerLocationTable PartnerLocationTable; Boolean ReturnValue = true; ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, out NewTransaction); try { PartnerLocationTable = PPartnerLocationAccess.LoadByPrimaryKey(APartnerKey, ALocationKey.SiteKey, ALocationKey.LocationKey, ReadTransaction); } finally { if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); } } if (PartnerLocationTable.Rows.Count == 0) { ReturnValue = false; } else { PPartnerLocationRow Row = (PPartnerLocationRow)PartnerLocationTable.Rows[0]; // check if the partner location is either current or if it is a mailing address if ((Row.DateEffective > DateTime.Today) || (!Row.SendMail) || ((Row.DateGoodUntil != null) && (Row.DateGoodUntil < DateTime.Today))) { AAddressNeitherCurrentNorMailing = true; } else { AAddressNeitherCurrentNorMailing = false; } ReturnValue = true; } return(ReturnValue); }
private void WriteLocation(PLocationRow ALocationRow, PPartnerLocationRow APartnerLocationRow, TLocationPK ABestAddressPK) { string PhoneNumber; string EmailAddress; string FaxNumber; Write(ALocationRow.IsSiteKeyNull() ? 0 : ALocationRow.SiteKey); Write(ALocationRow.IsLocalityNull() ? "" : ALocationRow.Locality); Write(ALocationRow.IsStreetNameNull() ? "" : ALocationRow.StreetName); Write(ALocationRow.IsAddress3Null() ? "" : ALocationRow.Address3); WriteLine(); Write(ALocationRow.IsCityNull() ? "" : ALocationRow.City); Write(ALocationRow.IsCountyNull() ? "" : ALocationRow.County); Write(ALocationRow.IsPostalCodeNull() ? "" : ALocationRow.PostalCode); Write(ALocationRow.IsCountryCodeNull() ? "" : ALocationRow.CountryCode); WriteLine(); Write(APartnerLocationRow.IsDateEffectiveNull() ? "?" : APartnerLocationRow.DateEffective.Value.ToString(DATEFORMAT)); Write(APartnerLocationRow.IsDateGoodUntilNull() ? "?" : APartnerLocationRow.DateGoodUntil.Value.ToString(DATEFORMAT)); Write(APartnerLocationRow.IsLocationTypeNull() ? "" : APartnerLocationRow.LocationType); Write(APartnerLocationRow.IsSendMailNull() ? false : APartnerLocationRow.SendMail); if ((APartnerLocationRow.LocationKey == ABestAddressPK.LocationKey) && (APartnerLocationRow.SiteKey == ABestAddressPK.SiteKey)) { // For the Location that is the 'Best Address' of the Partner we export 'Primary Phone Number', // 'Primary E-mail Address' and the 'Fax Number'. // They are exported for backwards compatibility as part of the 'Location' information as that is the only // place where the data was/is stored (and was/is seen and was/is maintained by the user) in Petra 2.x! TContactDetailsAggregate.GetPrimaryEmailAndPrimaryPhoneAndFax(APartnerLocationRow.PartnerKey, out PhoneNumber, out EmailAddress, out FaxNumber); Write(EmailAddress ?? String.Empty); Write(PhoneNumber ?? String.Empty); Write(0); // Phone Extensions are no longer kept in the Contact Details scheme so we can't export them... Write(FaxNumber ?? String.Empty); Write(0); // Fax Extensions are no longer kept in the Contact Details scheme so we can't export them... } else { // For any Location that isn't the 'Best Address' of the Partner: Export empty data for EmailAddress, // PhoneNumber, (Phone) Extension, Fax and Fax Extension. Write(String.Empty); Write(String.Empty); Write(0); Write(String.Empty); Write(0); } WriteLine(); }
private static void CreateAddress(ref PartnerEditTDS AMainDS, TApplicationFormData APartnerData, Int64 ANewPartnerKey) { // the webform prevents adding empty addresses // for children and staff, we do not require to enter an address if (APartnerData.street == null) { PPartnerLocationRow emptyPartnerLocation = AMainDS.PPartnerLocation.NewRowTyped(true); emptyPartnerLocation.SiteKey = 0; emptyPartnerLocation.LocationKey = 0; emptyPartnerLocation.PartnerKey = ANewPartnerKey; emptyPartnerLocation.SendMail = false; emptyPartnerLocation.DateEffective = DateTime.Now; emptyPartnerLocation.LocationType = "HOME"; emptyPartnerLocation.EmailAddress = APartnerData.email; AMainDS.PPartnerLocation.Rows.Add(emptyPartnerLocation); return; } // TODO: avoid duplicate addresses, reuse existing locations PLocationRow location = AMainDS.PLocation.NewRowTyped(true); location.LocationKey = (AMainDS.PLocation.Rows.Count + 1) * -1; location.SiteKey = 0; location.CountryCode = APartnerData.country; location.County = APartnerData.county; location.StreetName = APartnerData.street; location.City = APartnerData.city; location.PostalCode = APartnerData.postcode; AMainDS.PLocation.Rows.Add(location); PPartnerLocationRow partnerlocation = AMainDS.PPartnerLocation.NewRowTyped(true); partnerlocation.SiteKey = 0; partnerlocation.LocationKey = location.LocationKey; partnerlocation.PartnerKey = ANewPartnerKey; partnerlocation.SendMail = true; partnerlocation.DateEffective = DateTime.Now; partnerlocation.LocationType = "HOME"; partnerlocation.EmailAddress = APartnerData.email; partnerlocation.TelephoneNumber = APartnerData.phone; partnerlocation.MobileNumber = APartnerData.mobilephone; AMainDS.PPartnerLocation.Rows.Add(partnerlocation); }
/// <summary> /// Private method used by ExportPartners(). /// For the given partnerKey, updates given references countryCode and siteKey. /// If there is no location for the given partnerKey, leaves them as they are. /// </summary> /// <param name="MainDS">Reference to the already filled Datastructure</param> /// <param name="partnerKey"></param> /// <param name="countryCode"></param> /// <param name="siteKey"></param> /// <returns> /// True: if a location was found for given key and the countryCode /// and siteKey were updated. False otherwise. /// </returns> private static bool UpdateCountryAndSiteForGivenPK( PartnerEditTDS MainDS, long partnerKey, ref string countryCode /* default could be "" */, ref Int64 siteKey /* default could be -1 */ ) { bool retval = false; // Find partnerLocation for given partner_key DataView partnerLocationView = MainDS.PPartnerLocation.DefaultView; partnerLocationView.RowFilter = PPartnerLocationTable.GetPartnerKeyDBName() + " = " + partnerKey.ToString(); if (partnerLocationView.Count > 0) { // partnerLocation: links one partner to possibly several Locations // Just get the first one for now (and disregard the others). // TODO: could determine the best address and use that PPartnerLocationRow partnerLocationRow = (PPartnerLocationRow)partnerLocationView[0].Row; DataView locationView = MainDS.PLocation.DefaultView; locationView.RowFilter = PLocationTable.GetSiteKeyDBName() + "=" + partnerLocationRow.SiteKey.ToString() + " AND " + PLocationTable.GetLocationKeyDBName() + "=" + partnerLocationRow.LocationKey.ToString(); if (locationView.Count > 0) { PLocationRow locationRow = (PLocationRow)locationView[0].Row; countryCode = locationRow.CountryCode; siteKey = locationRow.SiteKey; retval = true; } else // if there is a partner_location, there has _got_ to be the corresponding location { throw new Exception("Error in application: I can't find the Location with LocationKey " + partnerLocationRow.LocationKey.ToString() + " (Sitekey " + partnerLocationRow.SiteKey.ToString() + ")" ); } } return(retval); }
/// create a new location public static void CreateNewLocation(Int64 APartnerKey, PartnerEditTDS AMainDS) { // avoid duplicate addresses: StreetName contains the partner key PLocationRow LocationRow = AMainDS.PLocation.NewRowTyped(); LocationRow.SiteKey = DomainManager.GSiteKey; LocationRow.LocationKey = -1; LocationRow.StreetName = APartnerKey.ToString() + " Nowhere Lane"; LocationRow.PostalCode = "LO2 2CX"; LocationRow.City = "London"; LocationRow.CountryCode = "99"; AMainDS.PLocation.Rows.Add(LocationRow); PPartnerLocationRow PartnerLocationRow = AMainDS.PPartnerLocation.NewRowTyped(); PartnerLocationRow.SiteKey = LocationRow.SiteKey; PartnerLocationRow.PartnerKey = APartnerKey; PartnerLocationRow.LocationKey = LocationRow.LocationKey; AMainDS.PPartnerLocation.Rows.Add(PartnerLocationRow); }
/// <summary> /// Determines which address is the 'Best Address' of a Partner, and returns the PLocation record which the /// 'Best Address' is pointing to. /// </summary> /// <remarks>There are two similar shared Methods in Namespace Ict.Petra.Server.MPartner.Common.Calculations, /// both called 'DetermineBestAddress' which work by passing in the PartnerLocations of a Partner in an Argument /// and which return a <see cref="TLocationPK" />. As those Methods don't access the database, these Methods /// can be used client-side as well!</remarks> /// <param name="APartnerKey">PartnerKey of the Partner whose addresses should be checked.</param> /// <param name="APartnerLocationDR">PPartnerLocation Record that is the record that is the Location of the 'Best Address'.</param> /// <param name="ALocationDR">PLocation Record that the 'Best Address' is pointing to.</param> /// <param name="ADataBase">An instantiated <see cref="TDataBase" /> object, or null (default = null). If null /// gets passed then the Method executes DB commands with a new Database connection</param> /// <returns>A <see cref="TLocationPK" /> which points to the 'Best Address'. If no 'Best Address' was found, /// SiteKey and LocationKey of this instance will be both -1.</returns> public static TLocationPK DetermineBestAddress(Int64 APartnerKey, out PPartnerLocationRow APartnerLocationDR, out PLocationRow ALocationDR, TDataBase ADataBase = null) { PLocationTable LocationDT; TLocationPK BestLocation = new TLocationPK(); Boolean NewTransaction; APartnerLocationDR = null; ALocationDR = null; BestLocation = DetermineBestAddress(APartnerKey, out APartnerLocationDR); TDataBase db = DBAccess.Connect("DetermineBestAddress", ADataBase); TDBTransaction ReadTransaction = db.GetNewOrExistingTransaction( MCommonConstants.CACHEABLEDT_ISOLATIONLEVEL, out NewTransaction); try { LocationDT = PLocationAccess.LoadByPrimaryKey(BestLocation.SiteKey, BestLocation.LocationKey, ReadTransaction); if (LocationDT.Rows.Count > 0) { ALocationDR = LocationDT[0]; } } finally { if (NewTransaction) { ReadTransaction.Commit(); TLogging.LogAtLevel(7, "ServerCalculations.DetermineBestAddress: commited own transaction."); } } return(BestLocation); }
/// <summary> /// Determines which address is the 'Best Address' of a Partner, and returns the PLocation record which the /// 'Best Address' is pointing to. /// </summary> /// <remarks>There are two similar shared Methods in Namespace Ict.Petra.Shared.MPartner.Calculations, /// both called 'DetermineBestAddress' which work by passing in the PartnerLocations of a Partner in an Argument /// and which return a <see cref="TLocationPK" />. As those Methods don't access the database, these Methods /// can be used client-side as well!</remarks> /// <param name="APartnerKey">PartnerKey of the Partner whose addresses should be checked.</param> /// <param name="APartnerLocationDR">PPartnerLocation Record that is the record that is the Location of the 'Best Address'.</param> /// <param name="ALocationDR">PLocation Record that the 'Best Address' is pointing to.</param> /// <returns>A <see cref="TLocationPK" /> which points to the 'Best Address'. If no 'Best Address' was found, /// SiteKey and LocationKey of this instance will be both -1.</returns> public static TLocationPK DetermineBestAddress(Int64 APartnerKey, out PPartnerLocationRow APartnerLocationDR, out PLocationRow ALocationDR) { PLocationTable LocationDT; TLocationPK BestLocation = new TLocationPK(); Boolean NewTransaction; APartnerLocationDR = null; ALocationDR = null; BestLocation = DetermineBestAddress(APartnerKey, out APartnerLocationDR); TDBTransaction ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction( Ict.Petra.Server.MCommon.MCommonConstants.CACHEABLEDT_ISOLATIONLEVEL, TEnforceIsolationLevel.eilMinimum, out NewTransaction); try { LocationDT = PLocationAccess.LoadByPrimaryKey(BestLocation.SiteKey, BestLocation.LocationKey, ReadTransaction); if (LocationDT.Rows.Count > 0) { ALocationDR = LocationDT[0]; } } finally { if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); TLogging.LogAtLevel(7, "ServerCalculations.DetermineBestAddress: commited own transaction."); } } return(BestLocation); }
private void WriteLocation(PLocationRow ALocationRow, PPartnerLocationRow APartnerLocationRow) { Write(ALocationRow.IsSiteKeyNull() ? 0 : ALocationRow.SiteKey); Write(ALocationRow.IsLocalityNull() ? "" : ALocationRow.Locality); Write(ALocationRow.IsStreetNameNull() ? "" : ALocationRow.StreetName); Write(ALocationRow.IsAddress3Null() ? "" : ALocationRow.Address3); WriteLine(); Write(ALocationRow.IsCityNull() ? "" : ALocationRow.City); Write(ALocationRow.IsCountyNull() ? "" : ALocationRow.County); Write(ALocationRow.IsPostalCodeNull() ? "" : ALocationRow.PostalCode); Write(ALocationRow.IsCountryCodeNull() ? "" : ALocationRow.CountryCode); WriteLine(); Write(APartnerLocationRow.IsDateEffectiveNull() ? "?" : APartnerLocationRow.DateEffective.Value.ToString(DATEFORMAT)); Write(APartnerLocationRow.IsDateGoodUntilNull() ? "?" : APartnerLocationRow.DateGoodUntil.Value.ToString(DATEFORMAT)); Write(APartnerLocationRow.IsLocationTypeNull() ? "" : APartnerLocationRow.LocationType); Write(APartnerLocationRow.IsSendMailNull() ? false : APartnerLocationRow.SendMail); Write(APartnerLocationRow.IsEmailAddressNull() ? "" : APartnerLocationRow.EmailAddress); Write(APartnerLocationRow.IsTelephoneNumberNull() ? "" : APartnerLocationRow.TelephoneNumber); Write(APartnerLocationRow.IsExtensionNull() ? 0 : APartnerLocationRow.Extension); Write(APartnerLocationRow.IsFaxNumberNull() ? "" : APartnerLocationRow.FaxNumber); Write(APartnerLocationRow.IsFaxExtensionNull() ? 0 : APartnerLocationRow.FaxExtension); WriteLine(); }
/// <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); }
/// <summary> /// Find the best address of a partner /// </summary> /// <param name="APartnerKey">Partner key</param> /// <param name="ASituation">describing the current state of the report generator</param> /// <param name="AAddressRow">best address</param> /// <returns>true if a best address was found, otherwise false</returns> public static bool GetPartnerBestAddressRow(long APartnerKey, TRptSituation ASituation, out PPartnerLocationRow AAddressRow) { bool FoundBestAddress = false; AAddressRow = null; PPartnerLocationTable PartnerLocationTable; PartnerLocationTable = new PPartnerLocationTable(); // add special column BestAddress and Icon PartnerLocationTable.Columns.Add(new System.Data.DataColumn("BestAddress", typeof(Boolean))); PartnerLocationTable.Columns.Add(new System.Data.DataColumn("Icon", typeof(Int32))); // find all locations of the partner, put it into a dataset PartnerLocationTable = PPartnerLocationAccess.LoadViaPPartner(APartnerKey, ASituation.GetDatabaseConnection().Transaction); // uses Ict.Petra.Shared.MPartner.Calculations.pas, DetermineBestAddress Calculations.DeterminePartnerLocationsDateStatus(PartnerLocationTable, DateTime.Today); Calculations.DetermineBestAddress(PartnerLocationTable); foreach (PPartnerLocationRow row in PartnerLocationTable.Rows) { // find the row with BestAddress = 1 if (Convert.ToInt32(row["BestAddress"]) == 1) { AAddressRow = row; FoundBestAddress = true; } } return FoundBestAddress; }
/// <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"); }
/// <summary> /// Returns the Primary Key of the Location and the Location and PartnerLocation DataRows /// of the 'Best Address' of a Partner. /// </summary> /// <param name="APartnerKey">PartnerKey of the Partner for which the 'Best Address' /// should be loaded for.</param> /// <param name="ABestAddressPK">Primary Key of the 'Best Address' Location</param> /// <param name="ALocationDR">DataRow containing the 'Best Address' Location</param> /// <param name="APartnerLocationDR">DataRow containing the 'Best Address' PartnerLocation</param> /// <returns>False if an invalid PartnerKey was passed in or if Petra Security /// denied access to the Partner or if Location/PartnerLocation Data could not be loaded for the /// Partner, otherwise true.</returns> public static bool GetPartnersBestLocationData(Int64 APartnerKey, out TLocationPK ABestAddressPK, out PLocationRow ALocationDR, out PPartnerLocationRow APartnerLocationDR) { TDBTransaction ReadTransaction; Boolean NewTransaction; PPartnerLocationTable PartnerLocationDT; PLocationTable LocationDT; ALocationDR = null; APartnerLocationDR = null; ABestAddressPK = null; if (APartnerKey > 0) { ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction( IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, out NewTransaction); try { if (TMailing.GetPartnerLocations(APartnerKey, false, true, true, true, out PartnerLocationDT)) { TLogging.LogAtLevel(8, "TMailing.GetPartnersBestLocationData: processing " + PartnerLocationDT.Rows.Count.ToString() + " Locations..."); if (PartnerLocationDT.Rows.Count > 1) { Calculations.DeterminePartnerLocationsDateStatus(PartnerLocationDT, DateTime.Today); ABestAddressPK = Calculations.DetermineBestAddress(PartnerLocationDT); } else if (PartnerLocationDT.Rows.Count == 1) { ABestAddressPK = new TLocationPK(PartnerLocationDT[0].SiteKey, PartnerLocationDT[0].LocationKey); } else { return false; } // TLogging.LogAtLevel(8, "TMailing.GetPartnersBestLocationData: BestAddressPK: " + ABestAddressPK.SiteKey.ToString() + ", " + ABestAddressPK.LocationKey.ToString()); APartnerLocationDR = (PPartnerLocationRow)PartnerLocationDT.Rows.Find( new object[] { APartnerKey, ABestAddressPK.SiteKey, ABestAddressPK.LocationKey }); LocationDT = TPPartnerAddressAggregate.LoadByPrimaryKey( ABestAddressPK.SiteKey, ABestAddressPK.LocationKey, ReadTransaction); if (LocationDT != null) { ALocationDR = LocationDT[0]; } else { return false; } return true; } else { return false; } } finally { if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); TLogging.LogAtLevel(8, "TMailing.GetPartnersBestLocationData: committed own transaction."); } } } else { return false; } }
/// <summary> /// </summary> /// <param name="APartnerLocationRow"></param> /// <param name="APartnerKey"></param> /// <param name="AAddressAddedOrChangedPromotionDT"></param> /// <param name="AReadTransaction"></param> /// <param name="AUpdatePartnerLocations"></param> /// <param name="AUpdatePartnerLocationOtherPersons"></param> /// <param name="AChangePromotionParametersDT"></param> /// <returns></returns> private static Boolean CheckPartnerLocationChange(PPartnerLocationRow APartnerLocationRow, Int64 APartnerKey, ref PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable AAddressAddedOrChangedPromotionDT, TDBTransaction AReadTransaction, out Boolean AUpdatePartnerLocations, out Int64[, ] AUpdatePartnerLocationOtherPersons, ref PartnerAddressAggregateTDSChangePromotionParametersTable AChangePromotionParametersDT) { Boolean ReturnValue; DataView AddressAddedOrChangedPromotionDV; StringCollection ChangedDetails; string[] ChangeSomeArray; PartnerAddressAggregateTDSAddressAddedOrChangedPromotionRow AddressAddedOrChangedRow; OdbcParameter[] ParametersArray; DataSet PersonsLocationReferencesDS; DataRow OtherPartnerLocationReferenceRow; Int32 Counter; Int32 Counter2; Int32 Counter3; PartnerAddressAggregateTDSChangePromotionParametersRow PartnerLocationChangePromotionRow; DataView AChangePromotionParametersDV; AUpdatePartnerLocations = false; AUpdatePartnerLocationOtherPersons = new Int64[0, 0]; // TLogging.LogAtLevel(9, "CheckPartnerLocationChange for Location " + APartnerLocationRow.LocationKey.ToString() + // ": AAddressAddedOrChangedPromotionDT.Rows.Count: " + AAddressAddedOrChangedPromotionDT.Rows.Count.ToString()); // Check if there is a Parameter Row for the LocationKey we are looking at AddressAddedOrChangedPromotionDV = new DataView(AAddressAddedOrChangedPromotionDT, PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetSiteKeyDBName() + " = " + APartnerLocationRow[PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetSiteKeyDBName(), DataRowVersion.Original].ToString() + " AND " + PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetLocationKeyDBName() + " = " + APartnerLocationRow[PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetLocationKeyDBName(), DataRowVersion.Original].ToString() + " AND " + PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetPartnerLocationChangeDBName() + " = true", "", DataViewRowState.CurrentRows); // APartnerLocationRow.SiteKey.ToString // APartnerLocationRow.LocationKey.ToString // No, there isn't one therefore create one (if necessary) if (AddressAddedOrChangedPromotionDV.Count == 0) { /* * Check if one ore more of specific PartnerLocation Data-holding fields * were changed */ if (CheckHasPartnerLocationPromotionDetailChanged(APartnerLocationRow, out ChangedDetails)) { if (PPersonAccess.CountViaPFamily(APartnerKey, AReadTransaction) > 0) { // TLogging.LogAtLevel(9, "CheckPartnerLocationChange: PartnerLocation with LocationKey " + APartnerLocationRow.LocationKey.ToString() + // ": certain fields have been changed and there are Family Members to which they can be promoted!"); #region Build AddressAddedOrChangedPromotion DataTable AAddressAddedOrChangedPromotionDT = new PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable( MPartnerConstants.ADDRESSADDEDORCHANGEDPROMOTION_TABLENAME); AddressAddedOrChangedRow = AAddressAddedOrChangedPromotionDT.NewRowTyped(false); AddressAddedOrChangedRow.SiteKey = Convert.ToInt64(APartnerLocationRow[PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetSiteKeyDBName(), DataRowVersion.Original]); // APartnerLocationRow.SiteKey; AddressAddedOrChangedRow.LocationKey = Convert.ToInt32(APartnerLocationRow[PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetLocationKeyDBName(), DataRowVersion.Original]); // APartnerLocationRow.LocationKey; AddressAddedOrChangedRow.PartnerKey = APartnerKey; AddressAddedOrChangedRow.LocationChange = false; AddressAddedOrChangedRow.PartnerLocationChange = true; AddressAddedOrChangedRow.LocationAdded = false; AddressAddedOrChangedRow.ChangedFields = StringHelper.StrMerge(ChangedDetails, '|'); // TLogging.LogAtLevel(9, "CheckPartnerLocationChange: ChangedFields String: " + AddressAddedOrChangedRow.ChangedFields.ToString() + // " (ChangedDetails.Count /4: " + Convert.ToInt16(ChangedDetails.Count / 4.0).ToString() + ')'); AddressAddedOrChangedRow.AnswerProcessedClientSide = false; AddressAddedOrChangedRow.AnswerProcessedServerSide = false; AAddressAddedOrChangedPromotionDT.Rows.Add(AddressAddedOrChangedRow); #endregion #region Build ChangePromotionParameters DataTable AChangePromotionParametersDT = new PartnerAddressAggregateTDSChangePromotionParametersTable( MPartnerConstants.ADDRESSCHANGEPROMOTIONPARAMETERS_TABLENAME); // Load data for all PERSONs of the FAMILY ParametersArray = new OdbcParameter[1]; ParametersArray[0] = new OdbcParameter("", OdbcType.Decimal, 10); ParametersArray[0].Value = (System.Object)(APartnerKey); PersonsLocationReferencesDS = DBAccess.GDBAccessObj.Select( "SELECT PUB_" + PPartnerLocationTable.GetTableDBName() + '.' + PPartnerLocationTable.GetPartnerKeyDBName() + ", " + PPartnerLocationTable.GetSiteKeyDBName() + ", " + PPartnerLocationTable.GetLocationKeyDBName() + ", " + PPartnerTable.GetPartnerShortNameDBName() + ", " + PPartnerTable.GetPartnerClassDBName() + ", " + PPartnerLocationTable.GetTelephoneNumberDBName() + ", " + PPartnerLocationTable.GetExtensionDBName() + ", " + PPartnerLocationTable.GetFaxNumberDBName() + ", " + PPartnerLocationTable.GetFaxExtensionDBName() + ", " + PPartnerLocationTable.GetAlternateTelephoneDBName() + ", " + PPartnerLocationTable.GetMobileNumberDBName() + ", " + PPartnerLocationTable.GetEmailAddressDBName() + ", " + PPartnerLocationTable.GetUrlDBName() + ", " + PPartnerLocationTable.GetSendMailDBName() + ", " + PPartnerLocationTable.GetDateEffectiveDBName() + ", " + PPartnerLocationTable.GetDateGoodUntilDBName() + ", " + PPartnerLocationTable.GetLocationTypeDBName() + ' ' + "FROM PUB_" + PPersonTable.GetTableDBName() + ", PUB_" + PPartnerLocationTable.GetTableDBName() + ", PUB_" + PPartnerTable.GetTableDBName() + ' ' + "WHERE PUB_" + PPersonTable.GetTableDBName() + '.' + PPersonTable.GetFamilyKeyDBName() + " = ? " + "AND PUB_" + PPartnerLocationTable.GetTableDBName() + '.' + PPartnerLocationTable.GetPartnerKeyDBName() + " = PUB_" + PPersonTable.GetTableDBName() + '.' + PPersonTable.GetPartnerKeyDBName() + ' ' + "AND PUB_" + PPartnerTable.GetTableDBName() + '.' + PPartnerTable.GetPartnerKeyDBName() + " = PUB_" + PPersonTable.GetTableDBName() + '.' + PPersonTable.GetPartnerKeyDBName( ) + ' ' + "ORDER BY PUB_" + PPersonTable.GetTableDBName() + '.' + PPersonTable.GetFamilyIdDBName() + " ASC, PUB_" + PPartnerLocationTable.GetTableDBName() + '.' + PPartnerLocationTable.GetSendMailDBName() + " DESC", "PersonsLocationReferences", AReadTransaction, ParametersArray); // Insert data into the ChangePromotionParameters DataTable for (Counter = 0; Counter <= PersonsLocationReferencesDS.Tables[0].Rows.Count - 1; Counter += 1) { OtherPartnerLocationReferenceRow = PersonsLocationReferencesDS.Tables[0].Rows[Counter]; PartnerLocationChangePromotionRow = AChangePromotionParametersDT.NewRowTyped(false); PartnerLocationChangePromotionRow.PartnerKey = Convert.ToInt64(OtherPartnerLocationReferenceRow[PPartnerLocationTable.GetPartnerKeyDBName()]); PartnerLocationChangePromotionRow.SiteKey = Convert.ToInt64(OtherPartnerLocationReferenceRow[PPartnerLocationTable.GetSiteKeyDBName()]); PartnerLocationChangePromotionRow.LocationKey = Convert.ToInt32(OtherPartnerLocationReferenceRow[PPartnerLocationTable.GetLocationKeyDBName()]); PartnerLocationChangePromotionRow.PartnerShortName = OtherPartnerLocationReferenceRow[PPartnerTable.GetPartnerShortNameDBName()].ToString(); PartnerLocationChangePromotionRow.PartnerClass = OtherPartnerLocationReferenceRow[PPartnerTable.GetPartnerClassDBName()].ToString(); PartnerLocationChangePromotionRow.TelephoneNumber = OtherPartnerLocationReferenceRow[PPartnerLocationTable.GetTelephoneNumberDBName()].ToString(); PartnerLocationChangePromotionRow.Extension = Convert.ToInt32(OtherPartnerLocationReferenceRow[PPartnerLocationTable.GetExtensionDBName()]); PartnerLocationChangePromotionRow.FaxNumber = OtherPartnerLocationReferenceRow[PPartnerLocationTable.GetFaxNumberDBName()].ToString(); PartnerLocationChangePromotionRow.FaxExtension = Convert.ToInt32(OtherPartnerLocationReferenceRow[PPartnerLocationTable.GetFaxExtensionDBName()]); PartnerLocationChangePromotionRow.AlternateTelephone = OtherPartnerLocationReferenceRow[PPartnerLocationTable.GetAlternateTelephoneDBName()].ToString(); PartnerLocationChangePromotionRow.MobileNumber = OtherPartnerLocationReferenceRow[PPartnerLocationTable.GetMobileNumberDBName()].ToString(); PartnerLocationChangePromotionRow.EmailAddress = OtherPartnerLocationReferenceRow[PPartnerLocationTable.GetEmailAddressDBName()].ToString(); PartnerLocationChangePromotionRow.Url = OtherPartnerLocationReferenceRow[PPartnerLocationTable.GetUrlDBName()].ToString(); PartnerLocationChangePromotionRow.SendMail = Convert.ToBoolean(OtherPartnerLocationReferenceRow[PPartnerLocationTable.GetSendMailDBName()]); if (!OtherPartnerLocationReferenceRow.IsNull(PPartnerLocationTable.GetDateEffectiveDBName())) { PartnerLocationChangePromotionRow.DateEffective = Convert.ToDateTime(OtherPartnerLocationReferenceRow[PPartnerLocationTable.GetDateEffectiveDBName()]); } if (!OtherPartnerLocationReferenceRow.IsNull(PPartnerLocationTable.GetDateGoodUntilDBName())) { PartnerLocationChangePromotionRow.DateGoodUntil = Convert.ToDateTime(OtherPartnerLocationReferenceRow[PPartnerLocationTable.GetDateGoodUntilDBName()]); } PartnerLocationChangePromotionRow.LocationType = OtherPartnerLocationReferenceRow[PPartnerLocationTable.GetLocationTypeDBName()].ToString(); // Add the SiteKey and LocationKey of the currently processed // PartnerLocation record. This is necessary to be able to filter on the // rows at a later stage on Client side and Server side! PartnerLocationChangePromotionRow.SiteKeyOfEditedRecord = Convert.ToInt64(APartnerLocationRow[PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetSiteKeyDBName(), DataRowVersion.Original]); // APartnerLocationRow.SiteKey; PartnerLocationChangePromotionRow.LocationKeyOfEditedRecord = Convert.ToInt32(APartnerLocationRow[PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable. GetLocationKeyDBName(), DataRowVersion.Original]); // APartnerLocationRow.LocationKey; AChangePromotionParametersDT.Rows.Add(PartnerLocationChangePromotionRow); } // TLogging.LogAtLevel(9, "CheckPartnerLocationChange: Location " + APartnerLocationRow.LocationKey.ToString() + // ": inserted PartnerLocation data of " + AChangePromotionParametersDT.Rows.Count.ToString() + // " PERSON''s of that FAMILY into AChangePromotionParametersDT!"); #endregion } } ReturnValue = true; } else { // AAddressAddedOrChangedPromotionDT was passed in, holding parameters for the LocationKey we are looking at AddressAddedOrChangedRow = (PartnerAddressAggregateTDSAddressAddedOrChangedPromotionRow)AddressAddedOrChangedPromotionDV[0].Row; if (AddressAddedOrChangedRow.UserAnswer == "CHANGE-NONE") { // TLogging.LogAtLevel(9, "CheckPartnerLocationChange: AAddressAddedOrChangedPromotionDT tells me to UPDATE NONE of the Persons with the changes that were made to the PartnerLocation."); // No processing necessary! AddressAddedOrChangedRow.AnswerProcessedClientSide = true; AddressAddedOrChangedRow.AcceptChanges(); ReturnValue = true; } else if (AddressAddedOrChangedRow.UserAnswer.StartsWith("CHANGE-SOME")) { // TLogging.LogAtLevel(9, "CheckPartnerLocationChange: AAddressAddedOrChangedPromotionDT tells me to UPDATE SOME Persons with the changes that were made to the PartnerLocation."); AUpdatePartnerLocations = true; // Parse the UserAnswer. It's format is 'CHANGESOME:PartnerKey1,SiteKey1,LocationKey1;PartnerKey2,SiteKey2,LocationKey2;PartnerKeyN,SiteKeyN,LocationKeyN' ChangeSomeArray = AddressAddedOrChangedRow.UserAnswer.Split(":,;".ToCharArray()); /* * Build the AUpdatePartnerLocationOtherPersons array from the UserAnswer * to signal to calling procedure that the changes that were made to the * PartnerLocation that we are processing should be * taken over to all the Person's PartnerLocations contained in the Array. */ AUpdatePartnerLocationOtherPersons = new Int64[Convert.ToInt32((ChangeSomeArray.Length - 1) / 3.0), 3]; // Counter: ' 1': don't include 'CHANGESOME' array entry, '/ 3' each entry consists of three strings: Counter = 1; Counter2 = 0; while (Counter < AUpdatePartnerLocationOtherPersons.GetLength(0) * 3) { // store PartnerKey AUpdatePartnerLocationOtherPersons[Counter2, 0] = Convert.ToInt64(ChangeSomeArray[Counter]); // TLogging.LogAtLevel(9, "CheckPartnerLocationChange: PartnerKey[" + Counter2.ToString() + "]: " + // AUpdatePartnerLocationOtherPersons[Counter2, 0].ToString()); // store SiteKey AUpdatePartnerLocationOtherPersons[Counter2, 1] = Convert.ToInt32(ChangeSomeArray[Counter + 1]); // TLogging.LogAtLevel(9, "CheckPartnerLocationChange: SiteKey[" + Counter2.ToString() + "]: " + // AUpdatePartnerLocationOtherPersons[Counter2, 1].ToString()); // store LocationKey AUpdatePartnerLocationOtherPersons[Counter2, 2] = Convert.ToInt32(ChangeSomeArray[Counter + 2]); // TLogging.LogAtLevel(9, "CheckPartnerLocationChange: LocationKey[" + Counter2.ToString() + "]: " + // AUpdatePartnerLocationOtherPersons[Counter2, 2].ToString()); // position Counter to next 'record' of PartnerKey, SiteKey and LocationKey Counter = Counter + 3; Counter2 = Counter2 + 1; } AddressAddedOrChangedRow.AnswerProcessedClientSide = true; AddressAddedOrChangedRow.AcceptChanges(); ReturnValue = true; } else if (AddressAddedOrChangedRow.UserAnswer == "CHANGE-ALL") { // TLogging.LogAtLevel(9, "CheckPartnerLocationChange: AAddressAddedOrChangedPromotionDT tells me to UPDATE ALL Persons with the changes that were made to the PartnerLocation."); AUpdatePartnerLocations = true; /* * Build the AUpdatePartnerLocationOtherPersons array from * AChangePromotionParametersDT to signal to calling procedure that the * changes that were made to the PartnerLocation that we are processing * should be taken over to all the Person's PartnerLocations contained in * the Array. */ // Process only AChangePromotionParametersDT rows that are for the current // SiteKey and LocationKey! // TLogging.LogAtLevel(9, "CheckPartnerLocationChange: AChangePromotionParametersDT.Rows.Count: " + // AChangePromotionParametersDT.Rows.Count.ToString()); AChangePromotionParametersDV = new DataView(AChangePromotionParametersDT, PartnerAddressAggregateTDSChangePromotionParametersTable.GetSiteKeyOfEditedRecordDBName() + " = " + Convert.ToInt64(APartnerLocationRow[PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetSiteKeyDBName(), DataRowVersion.Original]).ToString() + " AND " + PartnerAddressAggregateTDSChangePromotionParametersTable.GetLocationKeyOfEditedRecordDBName() + " = " + Convert.ToInt32(APartnerLocationRow[PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetLocationKeyDBName(), DataRowVersion.Original]).ToString(), "", DataViewRowState.CurrentRows); // APartnerLocationRow.SiteKey.ToString // APartnerLocationRow.LocationKey.ToString // TLogging.LogAtLevel(9, "CheckPartnerLocationChange: AChangePromotionParametersDV.Count: " + AChangePromotionParametersDV.Count.ToString()); AUpdatePartnerLocationOtherPersons = new Int64[AChangePromotionParametersDV.Count, 3]; for (Counter3 = 0; Counter3 <= AChangePromotionParametersDV.Count - 1; Counter3 += 1) { // store PartnerKey AUpdatePartnerLocationOtherPersons[Counter3, 0] = ((PartnerAddressAggregateTDSChangePromotionParametersRow)(AChangePromotionParametersDV[Counter3].Row)).PartnerKey; // store SiteKey AUpdatePartnerLocationOtherPersons[Counter3, 1] = ((PartnerAddressAggregateTDSChangePromotionParametersRow)(AChangePromotionParametersDV[Counter3].Row)).SiteKey; // store LocationKey AUpdatePartnerLocationOtherPersons[Counter3, 2] = ((PartnerAddressAggregateTDSChangePromotionParametersRow)(AChangePromotionParametersDV[Counter3].Row)).LocationKey; } AddressAddedOrChangedRow.AnswerProcessedClientSide = true; AddressAddedOrChangedRow.AcceptChanges(); ReturnValue = true; } else if (AddressAddedOrChangedRow.UserAnswer == "CANCEL") { // TLogging.LogAtLevel(9, "CheckPartnerLocationChange: AAddressAddedOrChangedPromotionDT tells me to CANCEL the changing of the PartnerLocation."); AddressAddedOrChangedRow.AnswerProcessedClientSide = true; AddressAddedOrChangedRow.AcceptChanges(); ReturnValue = false; } else { // TLogging.LogAtLevel(9, "CheckPartnerLocationChange: AAddressAddedOrChangedPromotionDT holds unexpected UserAnswer: " + // AddressAddedOrChangedRow.UserAnswer + "! Aborting operation!!!"); AddressAddedOrChangedRow.AnswerProcessedClientSide = true; AddressAddedOrChangedRow.AcceptChanges(); ReturnValue = false; } } return ReturnValue; }
public static bool SavePartner(PartnerEditTDS AMainDS, List <string> ASubscriptions, List <string> APartnerTypes, bool ASendMail, string ADefaultEmailAddress, string ADefaultPhoneMobile, string ADefaultPhoneLandline, out TVerificationResultCollection AVerificationResult) { List <string> Dummy1, Dummy2; string Dummy3, Dummy4, Dummy5; PartnerEditTDS SaveDS; AVerificationResult = new TVerificationResultCollection(); if (AMainDS.PPartner[0].ModificationId == DateTime.MinValue) { // this is a new partner SaveDS = AMainDS; if (SaveDS.PPartner[0].PartnerKey == -1) { SaveDS.PPartner[0].PartnerKey = NewPartnerKey(); } if (SaveDS.PFamily.Count > 0) { SaveDS.PFamily[0].PartnerKey = SaveDS.PPartner[0].PartnerKey; } else if (SaveDS.PPerson.Count > 0) { SaveDS.PPerson[0].PartnerKey = SaveDS.PPartner[0].PartnerKey; } else if (SaveDS.PChurch.Count > 0) { SaveDS.PChurch[0].PartnerKey = SaveDS.PPartner[0].PartnerKey; } else if (SaveDS.POrganisation.Count > 0) { SaveDS.POrganisation[0].PartnerKey = SaveDS.PPartner[0].PartnerKey; } PPartnerLocationRow partnerlocation = SaveDS.PPartnerLocation.NewRowTyped(); partnerlocation.PartnerKey = SaveDS.PPartner[0].PartnerKey; partnerlocation.LocationKey = SaveDS.PLocation[0].LocationKey; partnerlocation.SiteKey = SaveDS.PLocation[0].SiteKey; partnerlocation.SendMail = ASendMail; SaveDS.PPartnerLocation.Rows.Add(partnerlocation); } else { SaveDS = GetPartnerDetails(AMainDS.PPartner[0].PartnerKey, out Dummy1, out Dummy2, out Dummy3, out Dummy4, out Dummy5); DataUtilities.CopyDataSet(AMainDS, SaveDS); } List <string> ExistingPartnerTypes = new List <string>(); foreach (PPartnerTypeRow partnertype in SaveDS.PPartnerType.Rows) { if (!APartnerTypes.Contains(partnertype.TypeCode)) { partnertype.Delete(); } else { ExistingPartnerTypes.Add(partnertype.TypeCode); } } // add new partner types foreach (string partnertype in APartnerTypes) { if (!ExistingPartnerTypes.Contains(partnertype)) { PPartnerTypeRow partnertypeRow = SaveDS.PPartnerType.NewRowTyped(); partnertypeRow.PartnerKey = AMainDS.PPartner[0].PartnerKey; partnertypeRow.TypeCode = partnertype; SaveDS.PPartnerType.Rows.Add(partnertypeRow); } } List <string> ExistingSubscriptions = new List <string>(); foreach (PSubscriptionRow subscription in SaveDS.PSubscription.Rows) { if (!ASubscriptions.Contains(subscription.PublicationCode)) { subscription.Delete(); } else { ExistingSubscriptions.Add(subscription.PublicationCode); } } // add new subscriptions foreach (string subscription in ASubscriptions) { if (!ExistingSubscriptions.Contains(subscription)) { PSubscriptionRow subscriptionRow = SaveDS.PSubscription.NewRowTyped(); subscriptionRow.PartnerKey = AMainDS.PPartner[0].PartnerKey; subscriptionRow.PublicationCode = subscription; subscriptionRow.ReasonSubsGivenCode = "FREE"; SaveDS.PSubscription.Rows.Add(subscriptionRow); } } bool foundDefaultEmailAddress = false; bool foundDefaultPhoneLandLine = false; bool foundDefaultMobileLandLine = false; foreach (PPartnerAttributeRow partnerattr in SaveDS.PPartnerAttribute.Rows) { if (partnerattr.AttributeType == MPartnerConstants.ATTR_TYPE_EMAIL) { partnerattr.Value = ADefaultEmailAddress; foundDefaultEmailAddress = true; } else if (partnerattr.AttributeType == MPartnerConstants.ATTR_TYPE_PHONE) { partnerattr.Value = ADefaultPhoneLandline; foundDefaultPhoneLandLine = true; } else if (partnerattr.AttributeType == MPartnerConstants.ATTR_TYPE_MOBILE_PHONE) { partnerattr.Value = ADefaultPhoneMobile; foundDefaultMobileLandLine = true; } } if (!foundDefaultEmailAddress) { PPartnerAttributeRow partnerattr = SaveDS.PPartnerAttribute.NewRowTyped(); partnerattr.PartnerKey = SaveDS.PPartner[0].PartnerKey; partnerattr.AttributeType = MPartnerConstants.ATTR_TYPE_EMAIL; partnerattr.Value = ADefaultEmailAddress; partnerattr.Index = 0; SaveDS.PPartnerAttribute.Rows.Add(partnerattr); } if (!foundDefaultPhoneLandLine) { PPartnerAttributeRow partnerattr = SaveDS.PPartnerAttribute.NewRowTyped(); partnerattr.PartnerKey = SaveDS.PPartner[0].PartnerKey; partnerattr.AttributeType = MPartnerConstants.ATTR_TYPE_PHONE; partnerattr.Value = ADefaultPhoneLandline; partnerattr.Index = 0; SaveDS.PPartnerAttribute.Rows.Add(partnerattr); } if (!foundDefaultMobileLandLine) { PPartnerAttributeRow partnerattr = SaveDS.PPartnerAttribute.NewRowTyped(); partnerattr.PartnerKey = SaveDS.PPartner[0].PartnerKey; partnerattr.AttributeType = MPartnerConstants.ATTR_TYPE_MOBILE_PHONE; partnerattr.Value = ADefaultPhoneMobile; partnerattr.Index = 0; SaveDS.PPartnerAttribute.Rows.Add(partnerattr); } // TODO: either reuse Partner Edit UIConnector // or check for changed partner key, or changed Partner Class, etc. // set Partner Short Name if (SaveDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_PERSON) { SaveDS.PPartner[0].PartnerShortName = Calculations.DeterminePartnerShortName( SaveDS.PPerson[0].FamilyName, SaveDS.PPerson[0].Title, SaveDS.PPerson[0].FirstName, SaveDS.PPerson[0].MiddleName1); } else if (SaveDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_FAMILY) { // check if we have a valid family name if (SaveDS.PFamily[0].FamilyName.Trim().Length == 0) { AVerificationResult.Add(new TVerificationResult("error", "Please specify the family name", "", "MaintainPartners.ErrMissingFamilyName", TResultSeverity.Resv_Critical)); return(false); } // check if we have a valid title if (SaveDS.PFamily[0].Title.Trim().Length == 0) { AVerificationResult.Add(new TVerificationResult("error", "Please specify the title", "", "MaintainPartners.ErrMissingTitle", TResultSeverity.Resv_Critical)); return(false); } SaveDS.PPartner[0].PartnerShortName = Calculations.DeterminePartnerShortName( SaveDS.PFamily[0].FamilyName, SaveDS.PFamily[0].Title, SaveDS.PFamily[0].FirstName); } else if (SaveDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_UNIT) { SaveDS.PPartner[0].PartnerShortName = SaveDS.PUnit[0].UnitName; } else if (SaveDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_ORGANISATION) { // check if we have a valid organisation name if (SaveDS.POrganisation[0].OrganisationName.Trim().Length == 0) { AVerificationResult.Add(new TVerificationResult("error", "Please specify the organisation name", "", "MaintainPartners.ErrMissingOrganisationName", TResultSeverity.Resv_Critical)); return(false); } SaveDS.PPartner[0].PartnerShortName = SaveDS.POrganisation[0].OrganisationName; } else if (SaveDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_BANK) { SaveDS.PPartner[0].PartnerShortName = SaveDS.PBank[0].BranchName; } // change legacy addresses. create a new separate location for each partner if (SaveDS.PLocation[0].LocationKey == 0) { PLocationRow location = SaveDS.PLocation.NewRowTyped(); DataUtilities.CopyAllColumnValues(SaveDS.PLocation[0], location); location.SiteKey = DomainManager.GSiteKey; location.LocationKey = -1; SaveDS.PLocation.Rows.Clear(); SaveDS.PLocation.Rows.Add(location); PPartnerLocationRow plocation = SaveDS.PPartnerLocation.NewRowTyped(); DataUtilities.CopyAllColumnValues(SaveDS.PPartnerLocation[0], plocation); plocation.LocationKey = -1; plocation.SiteKey = DomainManager.GSiteKey; SaveDS.PPartnerLocation[0].Delete(); SaveDS.PPartnerLocation.Rows.Add(plocation); } // check if we have a valid country code if (SaveDS.PLocation[0].CountryCode.Trim().Length == 0) { AVerificationResult.Add(new TVerificationResult("error", "The country code is missing", TResultSeverity.Resv_Critical)); return(false); } TDBTransaction Transaction = new TDBTransaction(); bool WrongCountryCode = false; DBAccess.ReadTransaction(ref Transaction, delegate { WrongCountryCode = !PCountryAccess.Exists(SaveDS.PLocation[0].CountryCode, Transaction); }); if (WrongCountryCode) { AVerificationResult.Add(new TVerificationResult("error", "The country code does not match a country", TResultSeverity.Resv_Critical)); return(false); } DataSet ResponseDS = new PartnerEditTDS(); TPartnerEditUIConnector uiconnector = new TPartnerEditUIConnector(SaveDS.PPartner[0].PartnerKey); try { TSubmitChangesResult result = uiconnector.SubmitChanges( ref SaveDS, ref ResponseDS, out AVerificationResult); return(result == TSubmitChangesResult.scrOK); } catch (Exception e) { TLogging.Log(e.ToString()); AVerificationResult.Add(new TVerificationResult("error", e.Message, TResultSeverity.Resv_Critical)); return(false); } }
/// <summary> /// Determines which address is the 'Best Address' of a Partner, and returns the PLocation record which the /// 'Best Address' is pointing to. /// </summary> /// <remarks>There are two similar shared Methods in Namespace Ict.Petra.Shared.MPartner.Calculations, /// both called 'DetermineBestAddress' which work by passing in the PartnerLocations of a Partner in an Argument /// and which return a <see cref="TLocationPK" />. As those Methods don't access the database, these Methods /// can be used client-side as well!</remarks> /// <param name="APartnerKey">PartnerKey of the Partner whose addresses should be checked.</param> /// <param name="APartnerLocationDR">PPartnerLocation Record that is the record that is the Location of the 'Best Address'.</param> /// <param name="ALocationDR">PLocation Record that the 'Best Address' is pointing to.</param> /// <returns>A <see cref="TLocationPK" /> which points to the 'Best Address'. If no 'Best Address' was found, /// SiteKey and LocationKey of this instance will be both -1.</returns> public static TLocationPK DetermineBestAddress(Int64 APartnerKey, out PPartnerLocationRow APartnerLocationDR, out PLocationRow ALocationDR) { PLocationTable LocationDT; TLocationPK BestLocation = new TLocationPK(); Boolean NewTransaction; APartnerLocationDR = null; ALocationDR = null; BestLocation = DetermineBestAddress(APartnerKey, out APartnerLocationDR); TDBTransaction ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction( Ict.Petra.Server.MCommon.MCommonConstants.CACHEABLEDT_ISOLATIONLEVEL, TEnforceIsolationLevel.eilMinimum, out NewTransaction); try { LocationDT = PLocationAccess.LoadByPrimaryKey(BestLocation.SiteKey, BestLocation.LocationKey, ReadTransaction); if (LocationDT.Rows.Count > 0) { ALocationDR = LocationDT[0]; } } finally { if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); TLogging.LogAtLevel(7, "ServerCalculations.DetermineBestAddress: commited own transaction."); } } return BestLocation; }
/// <summary> /// Allows adding of a new Location of a FAMILY Partner to all PERSONS of that /// FAMILY. /// /// @comment Must only be called for Partners of Partner Class FAMILY - the /// function does no checks on that and will fail for other Partner Classes! /// </summary> /// <returns>void</returns> private static TSubmitChangesResult PerformLocationFamilyMemberPropagationChecks(PPartnerLocationRow APartnerLocationRow, ref PartnerAddressAggregateTDS AResponseDS, TDBTransaction ASubmitChangesTransaction, Int64 APartnerKey, String APartnerClass, ref PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable AAddressAddedPromotionDT, ref PPartnerLocationTable APartnerLocationTable, PartnerAddressAggregateTDSSimilarLocationParametersTable AExistingLocationParametersDT, TLocationPK[, ] ALocationReUseKeyMapping, out Boolean APerformPropagation, ref TVerificationResultCollection AVerificationResult) { // TLogging.LogAtLevel(9, "PerformLocationFamilyMemberPropagationChecks for LocationKey: " + APartnerLocationRow.LocationKey.ToString() + // "; AAddressAddedPromotionDT.Rows.Count: " + AAddressAddedPromotionDT.Rows.Count.ToString()); APerformPropagation = false; TLocationPK SubmittedLocationPK = DetermineReplacedLocationPK(APartnerLocationRow, ALocationReUseKeyMapping); TLocationPK LocationPK = DetermineReplacedLocationPK(APartnerLocationRow, AExistingLocationParametersDT); if (CheckFamilyMemberPropagation(APartnerLocationRow, APartnerKey, APartnerClass, ref AAddressAddedPromotionDT, LocationPK, ASubmitChangesTransaction)) { // Check if there is a Parameter Row for the LocationKey we are looking at DataView PropagateLocationParametersDV = new DataView(AAddressAddedPromotionDT, PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetSiteKeyDBName() + " = " + LocationPK.SiteKey.ToString() + " AND " + PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetLocationKeyDBName() + " = " + LocationPK.LocationKey.ToString() + " AND " + PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetLocationAddedDBName() + " = true AND " + PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetAnswerProcessedClientSideDBName() + " = false", "", DataViewRowState.CurrentRows); if (PropagateLocationParametersDV.Count > 0) { // TLogging.LogAtLevel(9, "PerformLocationFamilyMemberPropagationChecks: Location " + APartnerLocationRow.LocationKey.ToString() + ": found Family Members, decision on propagation is needed."); /* * More information is needed (usually via user interaction) * -> stop processing here and return parameters * (usually used for UI interaction) */ if (AResponseDS == null) { // TLogging.LogAtLevel(9, "PerformLocationFamilyMemberPropagationChecks: Creating AResponseDS."); AResponseDS = new PartnerAddressAggregateTDS(MPartnerConstants.PARTNERADDRESSAGGREGATERESPONSE_DATASET); } // TLogging.LogAtLevel(9, "PerformLocationFamilyMemberPropagationChecks: AAddressAddedPromotionDT.Rows.Count: " + AAddressAddedPromotionDT.Rows.Count.ToString()); AResponseDS.Merge(AAddressAddedPromotionDT); // TLogging.LogAtLevel(9, "PerformLocationFamilyMemberPropagationChecks: Merged AAddressAddedPromotionDT into AResponseDS."); // TLogging.LogAtLevel(9, "PerformLocationFamilyMemberPropagationChecks: PerformLocationFamilyMemberPropagationChecks: AResponseDS.Tables[" + // MPartnerConstants.ADDRESSADDEDORCHANGEDPROMOTION_TABLENAME + "].Rows.Count: " + // AResponseDS.Tables[MPartnerConstants.EXISTINGLOCATIONPARAMETERS_TABLENAME].Rows.Count.ToString()); return TSubmitChangesResult.scrInfoNeeded; } else { // TLogging.LogAtLevel(9, "PerformLocationFamilyMemberPropagationChecks: Location " + APartnerLocationRow.LocationKey.ToString() + ": found Family Members and new Location should be propagated to them!"); /* * Family Members were found and the new Location should be added to all * of them! */ APerformPropagation = true; // Load all Persons of the Family PPersonTable FamilyPersonsDT = PPersonAccess.LoadViaPFamily(APartnerKey, ASubmitChangesTransaction); // Find PPartnerLocation row of the Family that we should process PPartnerLocationRow FamilyPartnerLocationRow = (PPartnerLocationRow)APartnerLocationTable.Rows.Find( new System.Object[] { APartnerKey, APartnerLocationRow.SiteKey, APartnerLocationRow.LocationKey }); if (FamilyPartnerLocationRow != null) { for (int Counter = 0; Counter <= FamilyPersonsDT.Rows.Count - 1; Counter += 1) { PPersonRow ProcessedPersonRow = FamilyPersonsDT[Counter]; // TLogging.LogAtLevel(9, "PerformLocationFamilyMemberPropagationChecks: Person " + ProcessedPersonRow.PartnerKey.ToString() + ": checking..."); // Check if Person doesn't already have the Location if (!PPartnerLocationAccess.Exists(ProcessedPersonRow.PartnerKey, SubmittedLocationPK.SiteKey, SubmittedLocationPK.LocationKey, ASubmitChangesTransaction)) { /* * PartnerLocation records for family members are added to APartnerLocationTable for easier data handling and * will be removed again after SubmitChanges of whole dataset but before returning to client as otherwise * they would confusingly show up on client side. */ // Make sure record is not added more than once to APartnerLocationTable (in case it is not yet in database). if (APartnerLocationTable.Rows.Find(new System.Object[] { ProcessedPersonRow.PartnerKey, SubmittedLocationPK.SiteKey, SubmittedLocationPK.LocationKey }) == null) { // TLogging.LogAtLevel(9, "PerformLocationFamilyMemberPropagationChecks: Person " + ProcessedPersonRow.PartnerKey.ToString() + // ": adding Location " + SubmittedLocationPK.LocationKey.ToString() + "..."); // Add a copy of the PartnerLocation data to the Person PPartnerLocationRow AddPartnerLocationRow = APartnerLocationTable.NewRowTyped(false); AddPartnerLocationRow.ItemArray = DataUtilities.DestinationSaveItemArray(AddPartnerLocationRow, FamilyPartnerLocationRow); AddPartnerLocationRow.PartnerKey = ProcessedPersonRow.PartnerKey; AddPartnerLocationRow.SiteKey = SubmittedLocationPK.SiteKey; AddPartnerLocationRow.LocationKey = SubmittedLocationPK.LocationKey; APartnerLocationTable.Rows.Add(AddPartnerLocationRow); /* * If this Person has an PartnerLocation with LocationKey 0 (this * means that this was the only PartnerLocation so far), delete the * PartnerLocation with LocationKey 0. */ if (PPartnerLocationAccess.Exists(ProcessedPersonRow.PartnerKey, SubmittedLocationPK.SiteKey, 0, ASubmitChangesTransaction)) { // TLogging.LogAtLevel(9, "PerformLocationFamilyMemberPropagationChecks: Person " + ProcessedPersonRow.PartnerKey.ToString() + ": had Location 0 assigned, deleting it."); PPartnerLocationAccess.DeleteByPrimaryKey(ProcessedPersonRow.PartnerKey, APartnerLocationRow.SiteKey, 0, ASubmitChangesTransaction); } } } else { // TLogging.LogAtLevel(9, "PerformLocationFamilyMemberPropagationChecks: Person " + ProcessedPersonRow.PartnerKey.ToString() + // ": already has Location " + SubmittedLocationPK.LocationKey.ToString() + " assigned."); } } } else { throw new EOPAppException( "TPPartnerAddressAggregate.PerformLocationFamilyMemberPropagationChecks: PPartnerLocation record for Family is missing"); } } } else { // TLogging.LogAtLevel(9, "PerformLocationFamilyMemberPropagationChecks: Location " + SubmittedLocationPK.LocationKey.ToString() + // ": Family either has no Family Members, or no propagation of the new Location is wanted. New Location will therefore only be added to the FAMILY."); /* * Family either has no Family Members, or it has Members, but the decision * was made that the new PartnerLocation should not be added to the Family * Members. * The new Location will therefore only be added to the FAMILY. */ } return TSubmitChangesResult.scrOK; }
/// <summary> /// todoComment /// </summary> /// <param name="APartnerLocationRow"></param> /// <param name="APartnerKey"></param> /// <param name="ASubmitChangesTransaction"></param> private static void MakeSureLocation0SavingIsAllowed(PPartnerLocationRow APartnerLocationRow, Int64 APartnerKey, TDBTransaction ASubmitChangesTransaction) { DataRow[] ChangePartnerLocationKeyRows; PPartnerLocationTable PartnerLocationTable; // PPartnerLocation with LocationKey 0 must only be allowed to get // saved if the Partner indeed has no other PartnerLocations! // Check in the inmemory PartnerLocation Table first... PartnerLocationTable = (PPartnerLocationTable)APartnerLocationRow.Table; ChangePartnerLocationKeyRows = PartnerLocationTable.Select( PPartnerLocationTable.GetPartnerKeyDBName() + " = " + APartnerKey.ToString() + " AND " + PPartnerLocationTable.GetLocationKeyDBName() + " <> 0", "", DataViewRowState.CurrentRows); // TLogging.LogAtLevel(8, "MakeSureLocation0SavingIsAllowed: ChangePartnerLocationKeyRows Length: " + Convert.ToInt16(ChangePartnerLocationKeyRows.Length).ToString()); if (ChangePartnerLocationKeyRows.Length == 0) { // now check in the DB as well if (!CheckHasPartnerOtherPartnerLocations(0, APartnerKey, ASubmitChangesTransaction)) { // TLogging.LogAtLevel(8, "MakeSureLocation0SavingIsAllowed: CheckHasPartnerOtherPartnerLocations found no other Locations."); if (PPartnerLocationAccess.Exists(APartnerKey, APartnerLocationRow.SiteKey, 0, ASubmitChangesTransaction)) { throw new EOPAppException( "A new PPartnerLocation DataRow with LocationKey 0 was added, but the Partner already has a PPartnerLocation with LocationKey 0"); } else { // PPartnerLocation with LocationKey 0 may get saved! // TLogging.LogAtLevel(8, "MakeSureLocation0SavingIsAllowed: PPartnerLocation with LocationKey 0 was added and will be saved."); } } } else { throw new EOPAppException( "A new PPartnerLocation DataRow with LocationKey 0 was added, but the Partner already has a PPartnerLocation with LocationKey 0"); } }
/// <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); }
public void TestNewPartnerWithLocation0() { TPartnerEditUIConnector connector = new TPartnerEditUIConnector(); PartnerEditTDS MainDS = new PartnerEditTDS(); PPartnerRow PartnerRow = TCreateTestPartnerData.CreateNewFamilyPartner(MainDS); PPartnerLocationRow PartnerLocationRow = MainDS.PPartnerLocation.NewRowTyped(); PartnerLocationRow.SiteKey = DomainManager.GSiteKey; PartnerLocationRow.PartnerKey = PartnerRow.PartnerKey; PartnerLocationRow.LocationKey = 0; MainDS.PPartnerLocation.Rows.Add(PartnerLocationRow); DataSet ResponseDS = new PartnerEditTDS(); TVerificationResultCollection VerificationResult; TSubmitChangesResult result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult); CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResult, "There was a critical error when saving:"); Assert.AreEqual(TSubmitChangesResult.scrOK, result, "Create a partner with location 0"); TCreateTestPartnerData.CreateNewLocation(PartnerRow.PartnerKey, MainDS); // remove location 0, same is done in csharp\ICT\Petra\Client\MCommon\logic\UC_PartnerAddresses.cs TUCPartnerAddressesLogic::AddRecord // Check if record with PartnerLocation.LocationKey = 0 is around > delete it DataRow PartnerLocationRecordZero = MainDS.PPartnerLocation.Rows.Find(new object[] { PartnerRow.PartnerKey, DomainManager.GSiteKey, 0 }); if (PartnerLocationRecordZero != null) { DataRow LocationRecordZero = MainDS.PLocation.Rows.Find(new object[] { DomainManager.GSiteKey, 0 }); if (LocationRecordZero != null) { LocationRecordZero.Delete(); } PartnerLocationRecordZero.Delete(); } ResponseDS = new PartnerEditTDS(); result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult); CommonNUnitFunctions.EnsureNullOrOnlyNonCriticalVerificationResults(VerificationResult, "There was a critical error when saving:"); Assert.AreEqual(TSubmitChangesResult.scrOK, result, "Replace location 0 of partner"); Assert.AreEqual(1, MainDS.PPartnerLocation.Rows.Count, "the partner should only have one location in the dataset"); // get all addresses of the partner TDBTransaction ReadTransaction = null; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, ref ReadTransaction, delegate { PPartnerLocationTable testPartnerLocations = PPartnerLocationAccess.LoadViaPPartner(PartnerRow.PartnerKey, ReadTransaction); Assert.AreEqual(1, testPartnerLocations.Rows.Count, "the partner should only have one location"); Assert.Greater(testPartnerLocations[0].LocationKey, 0, "TPartnerEditUIConnector SubmitChanges returns valid location key"); }); }
/// <summary> /// generate the partners from a text file that was generated with Benerator /// </summary> /// <param name="AInputBeneratorFile"></param> public static void GenerateOrganisationPartners(string AInputBeneratorFile) { PartnerEditTDS MainDS = new PartnerEditTDS(); AApSupplierTable supplierTable = new AApSupplierTable(); // AlanP: May 2016 - We may no longer need the UTF8 because the method now automatically discovers the encoding even with no BOM XmlDocument doc = TCsv2Xml.ParseCSVFile2Xml(AInputBeneratorFile, ",", Encoding.UTF8); XmlNode RecordNode = doc.FirstChild.NextSibling.FirstChild; Int32 NumberOfPartnerKeysReserved = 100; Int64 NextPartnerKey = TNewPartnerKey.ReservePartnerKeys(-1, ref NumberOfPartnerKeysReserved); while (RecordNode != null) { if (NumberOfPartnerKeysReserved == 0) { NumberOfPartnerKeysReserved = 100; NextPartnerKey = TNewPartnerKey.ReservePartnerKeys(-1, ref NumberOfPartnerKeysReserved); } long OrgPartnerKey = NextPartnerKey; NextPartnerKey++; NumberOfPartnerKeysReserved--; POrganisationRow organisationRecord = MainDS.POrganisation.NewRowTyped(); organisationRecord.PartnerKey = OrgPartnerKey; organisationRecord.OrganisationName = TXMLParser.GetAttribute(RecordNode, "OrganisationName"); MainDS.POrganisation.Rows.Add(organisationRecord); PPartnerRow PartnerRow = MainDS.PPartner.NewRowTyped(); PartnerRow.PartnerKey = organisationRecord.PartnerKey; PartnerRow.PartnerClass = MPartnerConstants.PARTNERCLASS_ORGANISATION; PartnerRow.StatusCode = MPartnerConstants.PARTNERSTATUS_ACTIVE; PartnerRow.PartnerShortName = organisationRecord.OrganisationName; PartnerRow.AddresseeTypeCode = MPartnerConstants.ADDRESSEETYPE_ORGANISATION; MainDS.PPartner.Rows.Add(PartnerRow); PLocationRow locationRow = MainDS.PLocation.NewRowTyped(); locationRow.SiteKey = 0; // DomainManager.GSiteKey; locationRow.LocationKey = (MainDS.PLocation.Count + 1) * -1; locationRow.StreetName = TXMLParser.GetAttribute(RecordNode, "Addr2"); locationRow.PostalCode = TXMLParser.GetAttribute(RecordNode, "PostCode"); locationRow.City = TXMLParser.GetAttribute(RecordNode, "City"); locationRow.County = TXMLParser.GetAttribute(RecordNode, "Province"); locationRow.CountryCode = TXMLParser.GetAttribute(RecordNode, "CountryCode"); MainDS.PLocation.Rows.Add(locationRow); PPartnerLocationRow organisationLocationRow = MainDS.PPartnerLocation.NewRowTyped(); organisationLocationRow.PartnerKey = PartnerRow.PartnerKey; organisationLocationRow.LocationKey = locationRow.LocationKey; organisationLocationRow.SiteKey = locationRow.SiteKey; organisationLocationRow.LocationType = MPartnerConstants.LOCATIONTYPE_BUSINESS; organisationLocationRow.SendMail = true; if (TXMLParser.GetAttribute(RecordNode, "IsSupplier") == "yes") { AApSupplierRow supplierRow = supplierTable.NewRowTyped(true); supplierRow.PartnerKey = organisationRecord.PartnerKey; supplierRow.CurrencyCode = TXMLParser.GetAttribute(RecordNode, "Currency"); if (supplierRow.CurrencyCode == "GBP") { supplierRow.DefaultBankAccount = "6210"; } else { supplierRow.DefaultBankAccount = "6200"; } supplierRow.DefaultApAccount = "9100"; supplierRow.DefaultCostCentre = (FLedgerNumber * 100).ToString("0000"); supplierRow.DefaultExpAccount = "4200"; supplierTable.Rows.Add(supplierRow); } MainDS.PPartnerLocation.Rows.Add(organisationLocationRow); RecordNode = RecordNode.NextSibling; } TDataBase db = DBAccess.Connect("GenerateOrganisationPartners"); TDBTransaction Transaction = new TDBTransaction(); bool SubmitOK = false; db.WriteTransaction( ref Transaction, ref SubmitOK, delegate { PartnerEditTDSAccess.SubmitChanges(MainDS, db); AApSupplierAccess.SubmitChanges(supplierTable, Transaction); SubmitOK = true; }); db.CloseDBConnection(); }
/// <summary> /// todoComment /// /// @comment Must only be called for Partners of Partner Class FAMILY - the /// function does no checks on that and will fail for other Partner Classes! /// </summary> /// <param name="APartnerLocationRow"></param> /// <param name="APartnerKey"></param> /// <param name="AResponseDS"></param> /// <param name="ASubmitChangesTransaction"></param> /// <param name="AAddressChangedPromotionDT"></param> /// <param name="AChangeLocationParametersDT"></param> /// <param name="APartnerLocationTable"></param> /// <param name="AVerificationResult"></param> /// <returns></returns> private static TSubmitChangesResult PerformPartnerLocationChangeChecks(PPartnerLocationRow APartnerLocationRow, Int64 APartnerKey, ref PartnerAddressAggregateTDS AResponseDS, TDBTransaction ASubmitChangesTransaction, ref PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable AAddressChangedPromotionDT, ref PartnerAddressAggregateTDSChangePromotionParametersTable AChangeLocationParametersDT, ref PPartnerLocationTable APartnerLocationTable, ref TVerificationResultCollection AVerificationResult) { TSubmitChangesResult ReturnValue; DataView PropagateLocationParametersDV; DataView PropagateLocationParametersProcessedDV; Boolean UpdatePartnerLocations; Int64[, ] UpdatePartnerLocationOtherPersons; OdbcParameter[] ParametersArray; DataSet PartnerLocationModifyDS; StringCollection ChangedFieldsColl; String[] ChangedFieldsArr; Int32 Counter; Int32 Counter2; Int32 Counter3; Int32 Counter4; PPartnerLocationTable PartnerLocationModificationDT; // TLogging.LogAtLevel(9, "PerformPartnerLocationChangeChecks: AAddressChangedPromotionDT.Rows.Count: " + AAddressChangedPromotionDT.Rows.Count.ToString()); UpdatePartnerLocations = false; if (CheckPartnerLocationChange(APartnerLocationRow, APartnerKey, ref AAddressChangedPromotionDT, ASubmitChangesTransaction, out UpdatePartnerLocations, out UpdatePartnerLocationOtherPersons, ref AChangeLocationParametersDT)) { // Check if there is a Parameter Row for the LocationKey we are looking at PropagateLocationParametersDV = new DataView(AAddressChangedPromotionDT, PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetSiteKeyDBName() + " = " + APartnerLocationRow[PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetSiteKeyDBName(), DataRowVersion.Original].ToString() + " AND " + PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetLocationKeyDBName() + " = " + APartnerLocationRow[PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetLocationKeyDBName(), DataRowVersion.Original].ToString() + " AND " + PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetPartnerLocationChangeDBName() + " = true AND " + PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetAnswerProcessedClientSideDBName() + " = false", "", DataViewRowState.CurrentRows); // APartnerLocationRow.SiteKey.ToString // APartnerLocationRow.LocationKey.ToString if (PropagateLocationParametersDV.Count > 0) { // TLogging.LogAtLevel(9, "PerformPartnerLocationChangeChecks: PartnerLocation " + APartnerLocationRow.LocationKey.ToString() + // ": PartnerLocation has been changed, decision on propagation is needed."); /* * More information is needed (usually via user interaction) * -> stop processing here and return parameters * (usually used for UI interaction) */ if (AResponseDS == null) { // TLogging.LogAtLevel(9, "PerformPartnerLocationChangeChecks: Creating AResponseDS."); AResponseDS = new PartnerAddressAggregateTDS(MPartnerConstants.PARTNERADDRESSAGGREGATERESPONSE_DATASET); } // TLogging.LogAtLevel(9, "PerformPartnerLocationChangeChecks: AAddressAddedPromotionDT.Rows.Count: " + AAddressChangedPromotionDT.Rows.Count.ToString()); AResponseDS.Merge(AAddressChangedPromotionDT); // TLogging.LogAtLevel(9, "PerformPartnerLocationChangeChecks: Merged AAddressAddedPromotionDT into AResponseDS."); AResponseDS.Merge(AChangeLocationParametersDT); // TLogging.LogAtLevel(9, "PerformPartnerLocationChangeChecks: Merged ChangePromotionParametersDT into AResponseDS."); // TLogging.LogAtLevel(9, "PerformPartnerLocationChangeChecks: AResponseDS.Tables[" + MPartnerConstants.ADDRESSADDEDORCHANGEDPROMOTION_TABLENAME + // "].Rows.Count: " + AResponseDS.Tables[MPartnerConstants.ADDRESSADDEDORCHANGEDPROMOTION_TABLENAME].Rows.Count.ToString()); ReturnValue = TSubmitChangesResult.scrInfoNeeded; return ReturnValue; } else { /* * NOTE: If there are no Family Members, CheckPartnerLocationChange will * return true, but the PropagateLocationParametersDV.Count will be 0, so * the processing will also go here and find UpdatePartnerLocations false * (default assigned at beginning), so nothing will happen. */ if (UpdatePartnerLocations) { // TLogging.LogAtLevel(9, "PerformPartnerLocationChangeChecks: User made his/her choice regarding PartnerLocation Change promotion; now processing..."); /* * User made his/her choice regarding PartnerLocation Change promotion; * now process it */ // TLogging.LogAtLevel(9, "PerformPartnerLocationChangeChecks: Updated FAMILY PartnerLocation " + APartnerLocationRow.LocationKey.ToString() + // ": changes should be assigned to " + Convert.ToInt32(UpdatePartnerLocationOtherPersons.GetLength(0)).ToString() + " PartnerLocations of PERSONs..."); PartnerLocationModifyDS = null; // Find associated Parameter Row PropagateLocationParametersProcessedDV = new DataView( AAddressChangedPromotionDT, PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetSiteKeyDBName() + " = " + APartnerLocationRow[PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetSiteKeyDBName(), DataRowVersion.Original].ToString() + " AND " + PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetLocationKeyDBName() + " = " + APartnerLocationRow[PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetLocationKeyDBName(), DataRowVersion.Original].ToString() + " AND " + PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetPartnerLocationChangeDBName() + " = true AND " + PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetAnswerProcessedClientSideDBName() + " = true", "", DataViewRowState.CurrentRows); // APartnerLocationRow.SiteKey.ToString // APartnerLocationRow.LocationKey.ToString /* * Create a Collection by splitting String 'ChangedFields' from the * Parameter Row. * The String contains: DBName, Label, OriginalValue, CurrentValue for * each changed DataColumn. */ ChangedFieldsColl = StringHelper.StrSplit(((PartnerAddressAggregateTDSAddressAddedOrChangedPromotionRow) PropagateLocationParametersProcessedDV[0]. Row).ChangedFields, "|"); ChangedFieldsArr = new String[(Convert.ToInt16(ChangedFieldsColl.Count / 4.0))]; // TLogging.LogAtLevel(9, "PerformPartnerLocationChangeChecks: Length(ChangedFieldsArr): " + Convert.ToInt16(ChangedFieldsArr.Length).ToString()); Counter = 0; Counter2 = 0; // Build array that contains just the DB names of the changed fields while (Counter2 <= ChangedFieldsArr.Length - 1) { ChangedFieldsArr[Counter2] = ChangedFieldsColl[Counter]; // position Counter to next DB Field name Counter = Counter + 4; Counter2 = Counter2 + 1; } /* * Load data for each Person's PartnerLocation to which the changes to * the Family's PartnerLocation should be taken over and apply the change. */ PartnerLocationModifyDS = new DataSet(); PartnerLocationModifyDS.Tables.Add(new PPartnerLocationTable(PPartnerLocationTable.GetTableName())); for (Counter3 = 0; Counter3 <= UpdatePartnerLocationOtherPersons.GetLength(0) - 1; Counter3 += 1) { ParametersArray = new OdbcParameter[3]; ParametersArray[0] = new OdbcParameter("", OdbcType.Decimal, 10); ParametersArray[0].Value = (System.Object)(UpdatePartnerLocationOtherPersons[Counter3, 0]); ParametersArray[1] = new OdbcParameter("", OdbcType.Decimal, 10); ParametersArray[1].Value = (System.Object)(UpdatePartnerLocationOtherPersons[Counter3, 1]); ParametersArray[2] = new OdbcParameter("", OdbcType.Int); ParametersArray[2].Value = (System.Object)(UpdatePartnerLocationOtherPersons[Counter3, 2]); PartnerLocationModifyDS = DBAccess.GDBAccessObj.Select(PartnerLocationModifyDS, "SELECT * " + "FROM PUB_" + PPartnerLocationTable.GetTableDBName() + ' ' + "WHERE " + PPartnerLocationTable.GetPartnerKeyDBName() + " = ? " + "AND " + PPartnerLocationTable.GetSiteKeyDBName() + " = ? " + "AND " + PPartnerLocationTable.GetLocationKeyDBName() + " = ?", PPartnerLocationTable.GetTableName(), ASubmitChangesTransaction, ParametersArray); PartnerLocationModificationDT = ((PPartnerLocationTable)PartnerLocationModifyDS.Tables[0]); // Take over defined Columns' contents (only those Columns containing // changes) of the FAMILY's PartnerLocation to the loaded // PartnerLocation for (Counter4 = 0; Counter4 <= ChangedFieldsArr.Length - 1; Counter4 += 1) { PartnerLocationModificationDT[0][ChangedFieldsArr[Counter4]] = APartnerLocationRow[ChangedFieldsArr[Counter4]]; // TLogging.LogAtLevel(9, "PerformPartnerLocationChangeChecks: Changes to Column " + ChangedFieldsArr[Counter4].ToString() + // " taken over for LocationKey " + PartnerLocationModificationDT[0][PPartnerLocationTable.GetLocationKeyDBName()].ToString()); } // Submit the changes of the processed Person's PartnerLocation record to the DB PPartnerLocationAccess.SubmitChanges(PartnerLocationModificationDT, ASubmitChangesTransaction); // Don't keep the Person's PPartnerLocation in memory that we just processed! PartnerLocationModifyDS.Tables[0].Rows.Clear(); } } } ReturnValue = TSubmitChangesResult.scrOK; } else { // TLogging.LogAtLevel(9, "PerformPartnerLocationChangeChecks: Location " + APartnerLocationRow.LocationKey.ToString() + ": User cancelled the selection - stopping the whole saving process!"); /* * User cancelled the selection - stop the whole saving process! */ AVerificationResult.Add(new TVerificationResult("Partner-specific Address Data Change Promotion: Information", "No changes were saved because the Partner-specific Address Data Promotion dialog was cancelled by the user.", "Saving cancelled by user", "", TResultSeverity.Resv_Noncritical)); ReturnValue = TSubmitChangesResult.scrError; } return ReturnValue; }
/// <summary> /// todoComment /// </summary> /// <param name="ADataRow"></param> /// <param name="AChangedDetails"></param> /// <returns></returns> private static Boolean CheckHasPartnerLocationPromotionDetailChanged(PPartnerLocationRow ADataRow, out StringCollection AChangedDetails) { Boolean ReturnValue; AChangedDetails = new StringCollection(); if (ADataRow.HasVersion(DataRowVersion.Original)) { /* * Check if one ore more of specific PartnerLocation Data-holding fields * values were changed. * If a field's value was changed, record the Field's DB Name, the Label of * the Field (as shown on the screen), the Original value and the Current * (new) value. */ // Check 'TelephoneNumber' if ((TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetTelephoneNumberDBName(), DataRowVersion.Original)).ToString() != (TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetTelephoneNumberDBName(), DataRowVersion.Current)).ToString()) { AChangedDetails.Add(PPartnerLocationTable.GetTelephoneNumberDBName()); AChangedDetails.Add(TTypedDataTable.GetLabel(PPartnerLocationTable.TableId, PPartnerLocationTable.ColumnTelephoneNumberId)); AChangedDetails.Add(TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetTelephoneNumberDBName(), DataRowVersion.Original).ToString()); AChangedDetails.Add(TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetTelephoneNumberDBName(), DataRowVersion.Current).ToString()); } // Check 'Extension' if ((TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetExtensionDBName(), DataRowVersion.Original)).ToString() != (TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetExtensionDBName(), DataRowVersion.Current)).ToString()) { AChangedDetails.Add(PPartnerLocationTable.GetExtensionDBName()); AChangedDetails.Add(TTypedDataTable.GetLabel(PPartnerLocationTable.TableId, PPartnerLocationTable.ColumnExtensionId)); AChangedDetails.Add(TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetExtensionDBName(), DataRowVersion.Original).ToString()); AChangedDetails.Add(TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetExtensionDBName(), DataRowVersion.Current).ToString()); } // Check 'FaxNumber' if ((TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetFaxNumberDBName(), DataRowVersion.Original)).ToString() != (TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetFaxNumberDBName(), DataRowVersion.Current)).ToString()) { AChangedDetails.Add(PPartnerLocationTable.GetFaxNumberDBName()); AChangedDetails.Add(TTypedDataTable.GetLabel(PPartnerLocationTable.TableId, PPartnerLocationTable.ColumnFaxNumberId)); AChangedDetails.Add(TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetFaxNumberDBName(), DataRowVersion.Original).ToString()); AChangedDetails.Add(TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetFaxNumberDBName(), DataRowVersion.Current).ToString()); } // Check 'FaxExtension' if ((TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetFaxExtensionDBName(), DataRowVersion.Original)).ToString() != (TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetFaxExtensionDBName(), DataRowVersion.Current)).ToString()) { AChangedDetails.Add(PPartnerLocationTable.GetFaxExtensionDBName()); AChangedDetails.Add(TTypedDataTable.GetLabel(PPartnerLocationTable.TableId, PPartnerLocationTable.ColumnFaxExtensionId)); AChangedDetails.Add(TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetFaxExtensionDBName(), DataRowVersion.Original).ToString()); AChangedDetails.Add(TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetFaxExtensionDBName(), DataRowVersion.Current).ToString()); } // Check 'AlternateTelephone' if ((TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetAlternateTelephoneDBName(), DataRowVersion.Original)).ToString() != (TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetAlternateTelephoneDBName(), DataRowVersion.Current)).ToString()) { AChangedDetails.Add(PPartnerLocationTable.GetAlternateTelephoneDBName()); AChangedDetails.Add(TTypedDataTable.GetLabel(PPartnerLocationTable.TableId, PPartnerLocationTable.ColumnAlternateTelephoneId)); AChangedDetails.Add(TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetAlternateTelephoneDBName(), DataRowVersion.Original).ToString()); AChangedDetails.Add(TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetAlternateTelephoneDBName(), DataRowVersion.Current).ToString()); } // Check 'MobileNumber' if ((TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetMobileNumberDBName(), DataRowVersion.Original)).ToString() != (TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetMobileNumberDBName(), DataRowVersion.Current)).ToString()) { AChangedDetails.Add(PPartnerLocationTable.GetMobileNumberDBName()); AChangedDetails.Add(TTypedDataTable.GetLabel(PPartnerLocationTable.TableId, PPartnerLocationTable.ColumnMobileNumberId)); AChangedDetails.Add(TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetMobileNumberDBName(), DataRowVersion.Original).ToString()); AChangedDetails.Add(TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetMobileNumberDBName(), DataRowVersion.Current).ToString()); } // Check 'EmailAddress' if ((TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetEmailAddressDBName(), DataRowVersion.Original)).ToString() != (TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetEmailAddressDBName(), DataRowVersion.Current)).ToString()) { AChangedDetails.Add(PPartnerLocationTable.GetEmailAddressDBName()); AChangedDetails.Add(TTypedDataTable.GetLabel(PPartnerLocationTable.TableId, PPartnerLocationTable.ColumnEmailAddressId)); AChangedDetails.Add(TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetEmailAddressDBName(), DataRowVersion.Original).ToString()); AChangedDetails.Add(TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetEmailAddressDBName(), DataRowVersion.Current).ToString()); } // Check 'Url' if ((TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetUrlDBName(), DataRowVersion.Original)).ToString() != (TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetUrlDBName(), DataRowVersion.Current)).ToString()) { AChangedDetails.Add(PPartnerLocationTable.GetUrlDBName()); AChangedDetails.Add(TTypedDataTable.GetLabel(PPartnerLocationTable.TableId, PPartnerLocationTable.ColumnUrlId)); AChangedDetails.Add(TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetUrlDBName(), DataRowVersion.Original).ToString()); AChangedDetails.Add(TTypedDataAccess.GetSafeValue(ADataRow, PPartnerLocationTable.GetUrlDBName(), DataRowVersion.Current).ToString()); } // Result will be true if at least one field's value was changed ReturnValue = AChangedDetails.Count != 0; /* * if (ReturnValue) * { * TLogging.LogAtLevel(9, "CheckHasPartnerLocationPromotionDetailChanged: " + Convert.ToInt16(AChangedDetails.Count / 4.0).ToString() + " promotable Location Detail(s) has/have got changed."); * } * else * { * TLogging.LogAtLevel(9, "CheckHasPartnerLocationPromotionDetailChanged: NO promotable Location Detail has got changed."); * } */ } else { /* * There is no Original data to access. This means it is a new DataRow. * -> report it as *not* being changed */ ReturnValue = false; // TLogging.LogAtLevel(9, "CheckHasPartnerLocationPromotionDetailChanged: PPartnerLocationRow is new and not being seen as changed."); } return ReturnValue; }
/// <summary> /// generate the partners from a text file that was generated with Benerator /// </summary> /// <param name="AInputBeneratorFile"></param> public static void GenerateOrganisationPartners(string AInputBeneratorFile) { PartnerEditTDS MainDS = new PartnerEditTDS(); AApSupplierTable supplierTable = new AApSupplierTable(); XmlDocument doc = TCsv2Xml.ParseCSV2Xml(AInputBeneratorFile, ",", Encoding.UTF8); XmlNode RecordNode = doc.FirstChild.NextSibling.FirstChild; Int32 NumberOfPartnerKeysReserved = 100; Int64 NextPartnerKey = TNewPartnerKey.ReservePartnerKeys(-1, ref NumberOfPartnerKeysReserved); while (RecordNode != null) { if (NumberOfPartnerKeysReserved == 0) { NumberOfPartnerKeysReserved = 100; NextPartnerKey = TNewPartnerKey.ReservePartnerKeys(-1, ref NumberOfPartnerKeysReserved); } long OrgPartnerKey = NextPartnerKey; NextPartnerKey++; NumberOfPartnerKeysReserved--; POrganisationRow organisationRecord = MainDS.POrganisation.NewRowTyped(); organisationRecord.PartnerKey = OrgPartnerKey; organisationRecord.OrganisationName = TXMLParser.GetAttribute(RecordNode, "OrganisationName"); MainDS.POrganisation.Rows.Add(organisationRecord); PPartnerRow PartnerRow = MainDS.PPartner.NewRowTyped(); PartnerRow.PartnerKey = organisationRecord.PartnerKey; PartnerRow.PartnerClass = MPartnerConstants.PARTNERCLASS_ORGANISATION; PartnerRow.StatusCode = MPartnerConstants.PARTNERSTATUS_ACTIVE; PartnerRow.PartnerShortName = organisationRecord.OrganisationName; PartnerRow.AddresseeTypeCode = MPartnerConstants.ADDRESSEETYPE_ORGANISATION; MainDS.PPartner.Rows.Add(PartnerRow); PLocationRow locationRow = MainDS.PLocation.NewRowTyped(); locationRow.SiteKey = 0; // DomainManager.GSiteKey; locationRow.LocationKey = (MainDS.PLocation.Count + 1) * -1; locationRow.StreetName = TXMLParser.GetAttribute(RecordNode, "Addr2"); locationRow.PostalCode = TXMLParser.GetAttribute(RecordNode, "PostCode"); locationRow.City = TXMLParser.GetAttribute(RecordNode, "City"); locationRow.County = TXMLParser.GetAttribute(RecordNode, "Province"); locationRow.CountryCode = TXMLParser.GetAttribute(RecordNode, "CountryCode"); MainDS.PLocation.Rows.Add(locationRow); PPartnerLocationRow organisationLocationRow = MainDS.PPartnerLocation.NewRowTyped(); organisationLocationRow.PartnerKey = PartnerRow.PartnerKey; organisationLocationRow.LocationKey = locationRow.LocationKey; organisationLocationRow.SiteKey = locationRow.SiteKey; organisationLocationRow.LocationType = MPartnerConstants.LOCATIONTYPE_BUSINESS; organisationLocationRow.SendMail = true; if (TXMLParser.GetAttribute(RecordNode, "IsSupplier") == "yes") { AApSupplierRow supplierRow = supplierTable.NewRowTyped(true); supplierRow.PartnerKey = organisationRecord.PartnerKey; supplierRow.CurrencyCode = TXMLParser.GetAttribute(RecordNode, "Currency"); if (supplierRow.CurrencyCode == "GBP") { supplierRow.DefaultBankAccount = "6210"; } else { supplierRow.DefaultBankAccount = "6200"; } supplierRow.DefaultApAccount = "9100"; supplierRow.DefaultCostCentre = (FLedgerNumber * 100).ToString("0000"); supplierRow.DefaultExpAccount = "4200"; supplierTable.Rows.Add(supplierRow); } MainDS.PPartnerLocation.Rows.Add(organisationLocationRow); RecordNode = RecordNode.NextSibling; } PartnerEditTDSAccess.SubmitChanges(MainDS); AApSupplierAccess.SubmitChanges(supplierTable, null); }
/// <summary> /// Returns the Primary Key of the Location and the Location and PartnerLocation DataRows /// of the 'Best Address' of a Partner. /// </summary> /// <param name="APartnerKey">PartnerKey of the Partner for which the 'Best Address' /// should be loaded for.</param> /// <param name="ABestAddressPK">Primary Key of the 'Best Address' Location</param> /// <param name="ALocationDR">DataRow containing the 'Best Address' Location</param> /// <param name="APartnerLocationDR">DataRow containing the 'Best Address' PartnerLocation</param> /// <param name="ADataBase">An instantiated <see cref="TDataBase" /> object, or null (default = null). If null /// gets passed then the Method executes DB commands with the 'globally available' /// <see cref="DBAccess.GDBAccessObj" /> instance, otherwise with the instance that gets passed in with this /// Argument!</param> /// <returns>False if an invalid PartnerKey was passed in or if Petra Security /// denied access to the Partner or if Location/PartnerLocation Data could not be loaded for the /// Partner, otherwise true.</returns> public static bool GetPartnersBestLocationData(Int64 APartnerKey, out TLocationPK ABestAddressPK, out PLocationRow ALocationDR, out PPartnerLocationRow APartnerLocationDR, TDataBase ADataBase = null) { TDBTransaction ReadTransaction; Boolean NewTransaction; PPartnerLocationTable PartnerLocationDT; PLocationTable LocationDT; ALocationDR = null; APartnerLocationDR = null; ABestAddressPK = null; if (APartnerKey > 0) { ReadTransaction = DBAccess.GetDBAccessObj(ADataBase).GetNewOrExistingTransaction( IsolationLevel.ReadCommitted, TEnforceIsolationLevel.eilMinimum, out NewTransaction); try { if (TMailing.GetPartnerLocations(APartnerKey, false, true, true, true, out PartnerLocationDT, ADataBase)) { TLogging.LogAtLevel(8, "TMailing.GetPartnersBestLocationData: processing " + PartnerLocationDT.Rows.Count.ToString() + " Locations..."); if (PartnerLocationDT.Rows.Count > 1) { Calculations.DeterminePartnerLocationsDateStatus(PartnerLocationDT, DateTime.Today); ABestAddressPK = Calculations.DetermineBestAddress(PartnerLocationDT); } else if (PartnerLocationDT.Rows.Count == 1) { ABestAddressPK = new TLocationPK(PartnerLocationDT[0].SiteKey, PartnerLocationDT[0].LocationKey); } else { return(false); } // TLogging.LogAtLevel(8, "TMailing.GetPartnersBestLocationData: BestAddressPK: " + ABestAddressPK.SiteKey.ToString() + ", " + ABestAddressPK.LocationKey.ToString()); APartnerLocationDR = (PPartnerLocationRow)PartnerLocationDT.Rows.Find( new object[] { APartnerKey, ABestAddressPK.SiteKey, ABestAddressPK.LocationKey }); LocationDT = TPPartnerAddressAggregate.LoadByPrimaryKey( ABestAddressPK.SiteKey, ABestAddressPK.LocationKey, ReadTransaction); if (LocationDT != null) { ALocationDR = LocationDT[0]; } else { return(false); } return(true); } else { return(false); } } finally { if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); TLogging.LogAtLevel(8, "TMailing.GetPartnersBestLocationData: committed own transaction."); } } } else { return(false); } }
/// <summary> /// create PPartnerLocation records for the FAMILY partner, and all the PERSON records of this family /// </summary> public static void GenerateAddressForFamily(XmlNode ACurrentNode, PFamilyRow AFamilyRow, PartnerEditTDS AMainDS) { PLocationRow locationRow = AMainDS.PLocation.NewRowTyped(); locationRow.SiteKey = 0; // DomainManager.GSiteKey; locationRow.LocationKey = (AMainDS.PLocation.Count + 1) * -1; locationRow.StreetName = TXMLParser.GetAttribute(ACurrentNode, "Addr2"); locationRow.PostalCode = TXMLParser.GetAttribute(ACurrentNode, "PostCode"); locationRow.City = TXMLParser.GetAttribute(ACurrentNode, "City"); locationRow.County = TXMLParser.GetAttribute(ACurrentNode, "Province"); locationRow.CountryCode = TXMLParser.GetAttribute(ACurrentNode, "CountryCode"); AMainDS.PLocation.Rows.Add(locationRow); PPartnerLocationRow familyLocationRow = AMainDS.PPartnerLocation.NewRowTyped(); familyLocationRow.PartnerKey = AFamilyRow.PartnerKey; familyLocationRow.LocationKey = locationRow.LocationKey; familyLocationRow.SiteKey = locationRow.SiteKey; familyLocationRow.LocationType = MPartnerConstants.LOCATIONTYPE_HOME; familyLocationRow.SendMail = true; AMainDS.PPartnerLocation.Rows.Add(familyLocationRow); DataView FamilyView = new DataView(AMainDS.PPerson); FamilyView.RowFilter = PPersonTable.GetFamilyKeyDBName() + " = " + AFamilyRow.PartnerKey.ToString(); FamilyView.Sort = PPersonTable.GetFamilyIdDBName(); // for each person, also create a location record for (int countPerson = 0; countPerson < FamilyView.Count; countPerson++) { PPersonRow personRow = (PPersonRow)FamilyView[countPerson].Row; PPartnerLocationRow personLocationRow = AMainDS.PPartnerLocation.NewRowTyped(); personLocationRow.PartnerKey = personRow.PartnerKey; personLocationRow.LocationKey = familyLocationRow.LocationKey; personLocationRow.SiteKey = familyLocationRow.SiteKey; personLocationRow.LocationType = MPartnerConstants.LOCATIONTYPE_HOME; personLocationRow.SendMail = true; AMainDS.PPartnerLocation.Rows.Add(personLocationRow); string prefix = "Male"; if (countPerson == 1) { prefix = "Female"; } else if (countPerson > 1) { prefix = "Child" + (countPerson - 1).ToString(); } personLocationRow.EmailAddress = TXMLParser.GetAttribute(ACurrentNode, prefix + "Email"); // set email of first person for whole family if (countPerson == 0) { familyLocationRow.EmailAddress = personLocationRow.EmailAddress; } } }
private static void GenerateRegistrationOffices(string ACountryName, Int64 APartnerKey, string ACountryCode) { if (PUnitAccess.Exists(APartnerKey, null)) { TLogging.Log("Office with key " + APartnerKey.ToString() + " already exists."); return; } PartnerEditTDS MainDS = new PartnerEditTDS(); PPartnerRow partnerRow = MainDS.PPartner.NewRowTyped(true); partnerRow.PartnerKey = APartnerKey; partnerRow.PartnerShortName = ACountryName; partnerRow.PartnerClass = MPartnerConstants.PARTNERCLASS_UNIT; partnerRow.StatusCode = MPartnerConstants.PARTNERSTATUS_ACTIVE; partnerRow.AddresseeTypeCode = MPartnerConstants.ADDRESSEETYPE_ORGANISATION; MainDS.PPartner.Rows.Add(partnerRow); PUnitRow unitRow = MainDS.PUnit.NewRowTyped(true); unitRow.PartnerKey = partnerRow.PartnerKey; unitRow.UnitName = partnerRow.PartnerShortName; unitRow.CountryCode = ACountryCode; unitRow.UnitTypeCode = MPartnerConstants.UNIT_TYPE_FIELD; MainDS.PUnit.Rows.Add(unitRow); PLocationRow locationRow = MainDS.PLocation.NewRowTyped(); locationRow.SiteKey = partnerRow.PartnerKey; locationRow.LocationKey = 0; locationRow.StreetName = "No valid address on file"; locationRow.CountryCode = ACountryCode; MainDS.PLocation.Rows.Add(locationRow); PPartnerLocationRow partnerlocationRow = MainDS.PPartnerLocation.NewRowTyped(); partnerlocationRow.PartnerKey = partnerRow.PartnerKey; partnerlocationRow.SiteKey = locationRow.SiteKey; partnerlocationRow.LocationKey = locationRow.LocationKey; MainDS.PPartnerLocation.Rows.Add(partnerlocationRow); PPartnerTypeRow partnertypeRow = MainDS.PPartnerType.NewRowTyped(); partnertypeRow.PartnerKey = partnerRow.PartnerKey; partnertypeRow.TypeCode = MPartnerConstants.PARTNERTYPE_LEDGER; MainDS.PPartnerType.Rows.Add(partnertypeRow); UmUnitStructureRow unitStructureRow = MainDS.UmUnitStructure.NewRowTyped(); unitStructureRow.ParentUnitKey = 1000000; unitStructureRow.ChildUnitKey = partnerRow.PartnerKey; MainDS.UmUnitStructure.Rows.Add(unitStructureRow); PartnerEditTDSAccess.SubmitChanges(MainDS); string sqlInsertModule = String.Format("INSERT INTO PUB_{0}({1}, {2}) VALUES ('REG-{3:0000000000}','Registration {4}')", SModuleTable.GetTableDBName(), SModuleTable.GetModuleIdDBName(), SModuleTable.GetModuleNameDBName(), APartnerKey, ACountryName); string sqlInsertModulePermissions = String.Format("INSERT INTO PUB_{0}({1}, {2}, {3}) VALUES ('DEMO', 'REG-{4:0000000000}',true)", SUserModuleAccessPermissionTable.GetTableDBName(), SUserModuleAccessPermissionTable.GetUserIdDBName(), SUserModuleAccessPermissionTable.GetModuleIdDBName(), SUserModuleAccessPermissionTable.GetCanAccessDBName(), APartnerKey); TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable); try { DBAccess.GDBAccessObj.ExecuteNonQuery(sqlInsertModule, Transaction); DBAccess.GDBAccessObj.ExecuteNonQuery(sqlInsertModulePermissions, Transaction); DBAccess.GDBAccessObj.CommitTransaction(); } catch (Exception e) { TLogging.Log(e.ToString()); DBAccess.GDBAccessObj.RollbackTransaction(); } }
public static bool SavePartner(PartnerEditTDS AMainDS, List <string> ASubscriptions, List <string> APartnerTypes, bool ASendMail, string ADefaultEmailAddress, string ADefaultPhoneMobile, string ADefaultPhoneLandline, out TVerificationResultCollection AVerificationResult) { List <string> Dummy1, Dummy2; string Dummy3, Dummy4, Dummy5; PartnerEditTDS SaveDS; AVerificationResult = new TVerificationResultCollection(); if (AMainDS.PPartner[0].ModificationId == DateTime.MinValue) { // this is a new partner SaveDS = AMainDS; if (SaveDS.PPartner[0].PartnerKey == -1) { SaveDS.PPartner[0].PartnerKey = NewPartnerKey(); } if (SaveDS.PFamily.Count > 0) { SaveDS.PFamily[0].PartnerKey = SaveDS.PPartner[0].PartnerKey; } else if (SaveDS.PPerson.Count > 0) { SaveDS.PPerson[0].PartnerKey = SaveDS.PPartner[0].PartnerKey; } else if (SaveDS.PChurch.Count > 0) { SaveDS.PChurch[0].PartnerKey = SaveDS.PPartner[0].PartnerKey; } else if (SaveDS.POrganisation.Count > 0) { SaveDS.POrganisation[0].PartnerKey = SaveDS.PPartner[0].PartnerKey; } PPartnerLocationRow partnerlocation = SaveDS.PPartnerLocation.NewRowTyped(); partnerlocation.PartnerKey = SaveDS.PPartner[0].PartnerKey; partnerlocation.LocationKey = SaveDS.PLocation[0].LocationKey; partnerlocation.SiteKey = SaveDS.PLocation[0].SiteKey; partnerlocation.SendMail = ASendMail; SaveDS.PPartnerLocation.Rows.Add(partnerlocation); } else { SaveDS = GetPartnerDetails(AMainDS.PPartner[0].PartnerKey, out Dummy1, out Dummy2, out Dummy3, out Dummy4, out Dummy5); DataUtilities.CopyDataSet(AMainDS, SaveDS); } List <string> ExistingPartnerTypes = new List <string>(); foreach (PPartnerTypeRow partnertype in SaveDS.PPartnerType.Rows) { if (!APartnerTypes.Contains(partnertype.TypeCode)) { partnertype.Delete(); } else { ExistingPartnerTypes.Add(partnertype.TypeCode); } } // add new partner types foreach (string partnertype in APartnerTypes) { if (!ExistingPartnerTypes.Contains(partnertype)) { PPartnerTypeRow partnertypeRow = SaveDS.PPartnerType.NewRowTyped(); partnertypeRow.PartnerKey = AMainDS.PPartner[0].PartnerKey; partnertypeRow.TypeCode = partnertype; SaveDS.PPartnerType.Rows.Add(partnertypeRow); } } List <string> ExistingSubscriptions = new List <string>(); foreach (PSubscriptionRow subscription in SaveDS.PSubscription.Rows) { if (!ASubscriptions.Contains(subscription.PublicationCode)) { subscription.Delete(); } else { ExistingSubscriptions.Add(subscription.PublicationCode); } } // add new subscriptions foreach (string subscription in ASubscriptions) { if (!ExistingSubscriptions.Contains(subscription)) { PSubscriptionRow subscriptionRow = SaveDS.PSubscription.NewRowTyped(); subscriptionRow.PartnerKey = AMainDS.PPartner[0].PartnerKey; subscriptionRow.PublicationCode = subscription; subscriptionRow.ReasonSubsGivenCode = "FREE"; SaveDS.PSubscription.Rows.Add(subscriptionRow); } } bool foundDefaultEmailAddress = false; bool foundDefaultPhoneLandLine = false; bool foundDefaultMobileLandLine = false; foreach (PPartnerAttributeRow partnerattr in SaveDS.PPartnerAttribute.Rows) { if (partnerattr.AttributeType == MPartnerConstants.ATTR_TYPE_EMAIL) { partnerattr.Value = ADefaultEmailAddress; foundDefaultEmailAddress = true; } else if (partnerattr.AttributeType == MPartnerConstants.ATTR_TYPE_PHONE) { partnerattr.Value = ADefaultPhoneLandline; foundDefaultPhoneLandLine = true; } else if (partnerattr.AttributeType == MPartnerConstants.ATTR_TYPE_MOBILE_PHONE) { partnerattr.Value = ADefaultPhoneMobile; foundDefaultMobileLandLine = true; } } if (!foundDefaultEmailAddress) { PPartnerAttributeRow partnerattr = SaveDS.PPartnerAttribute.NewRowTyped(); partnerattr.PartnerKey = SaveDS.PPartner[0].PartnerKey; partnerattr.AttributeType = MPartnerConstants.ATTR_TYPE_EMAIL; partnerattr.Value = ADefaultEmailAddress; SaveDS.PPartnerAttribute.Rows.Add(partnerattr); } if (!foundDefaultPhoneLandLine) { PPartnerAttributeRow partnerattr = SaveDS.PPartnerAttribute.NewRowTyped(); partnerattr.PartnerKey = SaveDS.PPartner[0].PartnerKey; partnerattr.AttributeType = MPartnerConstants.ATTR_TYPE_PHONE; partnerattr.Value = ADefaultPhoneLandline; SaveDS.PPartnerAttribute.Rows.Add(partnerattr); } if (!foundDefaultMobileLandLine) { PPartnerAttributeRow partnerattr = SaveDS.PPartnerAttribute.NewRowTyped(); partnerattr.PartnerKey = SaveDS.PPartner[0].PartnerKey; partnerattr.AttributeType = MPartnerConstants.ATTR_TYPE_MOBILE_PHONE; partnerattr.Value = ADefaultPhoneMobile; SaveDS.PPartnerAttribute.Rows.Add(partnerattr); } // TODO: either reuse Partner Edit UIConnector // or check for changed partner key, or changed Partner Class, etc. // set Partner Short Name if (SaveDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_PERSON) { SaveDS.PPartner[0].PartnerShortName = Calculations.DeterminePartnerShortName( SaveDS.PPerson[0].FamilyName, SaveDS.PPerson[0].Title, SaveDS.PPerson[0].FirstName, SaveDS.PPerson[0].MiddleName1); } else if (SaveDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_FAMILY) { SaveDS.PPartner[0].PartnerShortName = Calculations.DeterminePartnerShortName( SaveDS.PFamily[0].FamilyName, SaveDS.PFamily[0].Title, SaveDS.PFamily[0].FirstName); } else if (SaveDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_UNIT) { SaveDS.PPartner[0].PartnerShortName = SaveDS.PUnit[0].UnitName; } else if (SaveDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_ORGANISATION) { SaveDS.PPartner[0].PartnerShortName = SaveDS.POrganisation[0].OrganisationName; } else if (SaveDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_BANK) { SaveDS.PPartner[0].PartnerShortName = SaveDS.PBank[0].BranchName; } // TODO: check if location 0 (no address) was changed. we don't want to overwrite that // alternative: check if somebody else uses that location, and split the locations. or ask if others should be updated??? if (SaveDS.PLocation[0].RowState == DataRowState.Modified && SaveDS.PLocation[0].LocationKey == 0) { TLogging.Log("we cannot update addresses of people with location 0"); AVerificationResult.Add(new TVerificationResult("error", "we cannot update addresses of people with location 0", TResultSeverity.Resv_Critical)); return(false); } DataSet ResponseDS = new PartnerEditTDS(); TPartnerEditUIConnector uiconnector = new TPartnerEditUIConnector(SaveDS.PPartner[0].PartnerKey); try { TSubmitChangesResult result = uiconnector.SubmitChanges( ref SaveDS, ref ResponseDS, out AVerificationResult); return(result == TSubmitChangesResult.scrOK); } catch (Exception e) { TLogging.Log(e.ToString()); AVerificationResult.Add(new TVerificationResult("error", e.Message, TResultSeverity.Resv_Critical)); return(false); } }
public static bool SavePartner(PartnerEditTDS AMainDS, List <string> ASubscriptions, List <string> APartnerTypes) { List <string> Dummy1, Dummy2; string Dummy3, Dummy4, Dummy5; PartnerEditTDS SaveDS; if (AMainDS.PPartner[0].ModificationId == DateTime.MinValue) { // this is a new partner SaveDS = AMainDS; if (SaveDS.PPartner[0].PartnerKey == -1) { SaveDS.PPartner[0].PartnerKey = NewPartnerKey(); } if (SaveDS.PFamily.Count > 0) { SaveDS.PFamily[0].PartnerKey = SaveDS.PPartner[0].PartnerKey; } else if (SaveDS.PPerson.Count > 0) { SaveDS.PPerson[0].PartnerKey = SaveDS.PPartner[0].PartnerKey; } else if (SaveDS.PChurch.Count > 0) { SaveDS.PChurch[0].PartnerKey = SaveDS.PPartner[0].PartnerKey; } else if (SaveDS.POrganisation.Count > 0) { SaveDS.POrganisation[0].PartnerKey = SaveDS.PPartner[0].PartnerKey; } PPartnerLocationRow partnerlocation = SaveDS.PPartnerLocation.NewRowTyped(); partnerlocation.PartnerKey = SaveDS.PPartner[0].PartnerKey; partnerlocation.LocationKey = SaveDS.PLocation[0].LocationKey; partnerlocation.SiteKey = SaveDS.PLocation[0].SiteKey; SaveDS.PPartnerLocation.Rows.Add(partnerlocation); } else { SaveDS = GetPartnerDetails(AMainDS.PPartner[0].PartnerKey, out Dummy1, out Dummy2, out Dummy3, out Dummy4, out Dummy5); DataUtilities.CopyDataSet(AMainDS, SaveDS); } List <string> ExistingPartnerTypes = new List <string>(); foreach (PPartnerTypeRow partnertype in SaveDS.PPartnerType.Rows) { if (!APartnerTypes.Contains(partnertype.TypeCode)) { partnertype.Delete(); } else { ExistingPartnerTypes.Add(partnertype.TypeCode); } } // add new partner types foreach (string partnertype in APartnerTypes) { if (!ExistingPartnerTypes.Contains(partnertype)) { PPartnerTypeRow partnertypeRow = SaveDS.PPartnerType.NewRowTyped(); partnertypeRow.PartnerKey = AMainDS.PPartner[0].PartnerKey; partnertypeRow.TypeCode = partnertype; SaveDS.PPartnerType.Rows.Add(partnertypeRow); } } List <string> ExistingSubscriptions = new List <string>(); foreach (PSubscriptionRow subscription in SaveDS.PSubscription.Rows) { if (!ASubscriptions.Contains(subscription.PublicationCode)) { subscription.Delete(); } else { ExistingSubscriptions.Add(subscription.PublicationCode); } } // add new subscriptions foreach (string subscription in ASubscriptions) { if (!ExistingSubscriptions.Contains(subscription)) { PSubscriptionRow subscriptionRow = SaveDS.PSubscription.NewRowTyped(); subscriptionRow.PartnerKey = AMainDS.PPartner[0].PartnerKey; subscriptionRow.PublicationCode = subscription; subscriptionRow.ReasonSubsGivenCode = "FREE"; SaveDS.PSubscription.Rows.Add(subscriptionRow); } } // TODO: either reuse Partner Edit UIConnector // or check for changed partner key, or changed Partner Class, etc. // set Partner Short Name if (SaveDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_PERSON) { SaveDS.PPartner[0].PartnerShortName = Calculations.DeterminePartnerShortName( SaveDS.PPerson[0].FamilyName, SaveDS.PPerson[0].Title, SaveDS.PPerson[0].FirstName, SaveDS.PPerson[0].MiddleName1); } else if (SaveDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_FAMILY) { SaveDS.PPartner[0].PartnerShortName = Calculations.DeterminePartnerShortName( SaveDS.PFamily[0].FamilyName, SaveDS.PFamily[0].Title, SaveDS.PFamily[0].FirstName); } else if (SaveDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_UNIT) { SaveDS.PPartner[0].PartnerShortName = SaveDS.PUnit[0].UnitName; } else if (SaveDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_ORGANISATION) { SaveDS.PPartner[0].PartnerShortName = SaveDS.POrganisation[0].OrganisationName; } else if (SaveDS.PPartner[0].PartnerClass == MPartnerConstants.PARTNERCLASS_BANK) { SaveDS.PPartner[0].PartnerShortName = SaveDS.PBank[0].BranchName; } // TODO: check if location 0 (no address) was changed. we don't want to overwrite that // alternative: check if somebody else uses that location, and split the locations. or ask if others should be updated??? if (SaveDS.PLocation[0].RowState == DataRowState.Modified && SaveDS.PLocation[0].LocationKey == 0) { TLogging.Log("we cannot update addresses of people with location 0"); return(false); } PartnerEditTDSAccess.SubmitChanges(SaveDS); return(true); }
/// <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); }
/// <summary> /// todoComment /// </summary> /// <param name="APartnerLocationRow"></param> /// <param name="APartnerKey"></param> /// <param name="APartnerClass"></param> /// <param name="AAddressAddedOrChangedPromotionDT"></param> /// <param name="ALocationPK"></param> /// <param name="AReadTransaction"></param> /// <returns></returns> private static Boolean CheckFamilyMemberPropagation(PPartnerLocationRow APartnerLocationRow, Int64 APartnerKey, String APartnerClass, ref PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable AAddressAddedOrChangedPromotionDT, TLocationPK ALocationPK, TDBTransaction AReadTransaction) { Boolean ReturnValue; DataView AddressAddedOrChangedPromotionDV; PartnerAddressAggregateTDSAddressAddedOrChangedPromotionRow AddressAddedOrChangedRow; Boolean FoundFamilyMembers; // TLogging.LogAtLevel(9, "CheckFamilyMemberPropagation for Location " + APartnerLocationRow.LocationKey.ToString() + // ": AAddressAddedOrChangedPromotionDT.Rows.Count: " + AAddressAddedOrChangedPromotionDT.Rows.Count.ToString()); // TLogging.LogAtLevel(9, "CheckFamilyMemberPropagation: ALocationPK.LocationKey: " + ALocationPK.LocationKey.ToString()); // Check if there is a Parameter Row for the LocationKey we are looking at AddressAddedOrChangedPromotionDV = new DataView(AAddressAddedOrChangedPromotionDT, PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetSiteKeyDBName() + " = " + ALocationPK.SiteKey.ToString() + " AND " + PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetLocationKeyDBName() + " = " + ALocationPK.LocationKey.ToString() + " AND " + PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetLocationAddedDBName() + " = true AND " + PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetUserAnswerDBName() + " <> ''''", "", DataViewRowState.CurrentRows); // No, there isn't one: perform DB check if (AddressAddedOrChangedPromotionDV.Count == 0) { if (PPersonAccess.CountViaPFamily(APartnerKey, AReadTransaction) > 0) { FoundFamilyMembers = true; } else { FoundFamilyMembers = false; } if (FoundFamilyMembers) { // Create a Parameter Row // TLogging.LogAtLevel(9, "CheckFamilyMemberPropagation: Location " + APartnerLocationRow.LocationKey.ToString() + ": Partner is Family and has Family Members!"); AAddressAddedOrChangedPromotionDT = new PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable( MPartnerConstants.ADDRESSADDEDORCHANGEDPROMOTION_TABLENAME); AddressAddedOrChangedRow = AAddressAddedOrChangedPromotionDT.NewRowTyped(false); AddressAddedOrChangedRow.SiteKey = ALocationPK.SiteKey; AddressAddedOrChangedRow.LocationKey = ALocationPK.LocationKey; AddressAddedOrChangedRow.LocationAdded = true; AddressAddedOrChangedRow.LocationChange = false; AddressAddedOrChangedRow.AnswerProcessedClientSide = false; AddressAddedOrChangedRow.AnswerProcessedServerSide = false; AAddressAddedOrChangedPromotionDT.Rows.Add(AddressAddedOrChangedRow); ReturnValue = true; } else { // TLogging.LogAtLevel(9, "CheckFamilyMemberPropagation: Location " + APartnerLocationRow.LocationKey.ToString() + ": found no Family Members."); ReturnValue = false; } } else { // AAddressAddedOrChangedPromotionDT was passed in, holding parameters for the LocationKey we are looking at AddressAddedOrChangedRow = (PartnerAddressAggregateTDSAddressAddedOrChangedPromotionRow)AddressAddedOrChangedPromotionDV[0].Row; if (AddressAddedOrChangedRow.UserAnswer == "YES") { // TLogging.LogAtLevel(9, "CheckFamilyMemberPropagation: AAddressAddedOrChangedPromotionDT tells me to propagate the new Location to all Family Members."); AddressAddedOrChangedRow.AnswerProcessedClientSide = true; AddressAddedOrChangedRow.AcceptChanges(); ReturnValue = true; } else { // TLogging.LogAtLevel(9, "CheckFamilyMemberPropagation: AAddressAddedOrChangedPromotionDT tells me NOT to propagate the new Location."); AddressAddedOrChangedRow.AnswerProcessedClientSide = true; AddressAddedOrChangedRow.AcceptChanges(); ReturnValue = false; } } return ReturnValue; }
/// <summary> /// todoComment /// </summary> /// <param name="APartnerLocationRow"></param> /// <param name="AAddressAddedPromotionDT"></param> private static void ModifyAddressAddedOrChangedParameters(PPartnerLocationRow APartnerLocationRow, ref PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable AAddressAddedPromotionDT) { DataView AddressAddedOrChangedParametersDV; PartnerAddressAggregateTDSAddressAddedOrChangedPromotionRow AddressAddedOrChangedRow; // TLogging.LogAtLevel(9, "ModifyAddressAddedOrChangedParameters: Looking for ExistingLocationParameters with LocationKey " + APartnerLocationRow.LocationKey.ToString()); /* if DEBUGMODE * if (TLogging.DL >= 8) * { * for (int TmpRowCounter = 0; TmpRowCounter <= AAddressAddedPromotionDT.Rows.Count - 1; TmpRowCounter += 1) * { * TLogging.Log("Checking Row: " + TmpRowCounter.ToString()); * TLogging.Log( * "ModifyAddressAddedOrChangedParameters: AAddressAddedPromotionDT.Row[" + TmpRowCounter.ToString() + ".RowState: " + * (Enum.GetName(typeof(DataRowState), AAddressAddedPromotionDT.Rows[TmpRowCounter].RowState))); * TLogging.Log( * "ModifyAddressAddedOrChangedParameters: before searching: Row[" + TmpRowCounter.ToString() + "]: PLocationKey: " + * AAddressAddedPromotionDT[TmpRowCounter][PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetLocationKeyDBName(), * DataRowVersion.Current].ToString() + "; PSiteKey: " + * AAddressAddedPromotionDT[TmpRowCounter][PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetSiteKeyDBName(), * DataRowVersion.Current].ToString() + "; RowState: " + * (Enum.GetName(typeof(DataRowState), AAddressAddedPromotionDT.Rows[TmpRowCounter].RowState))); * } * } */ // Check if there is a Parameter Row for the LocationKey we are looking at AddressAddedOrChangedParametersDV = new DataView(AAddressAddedPromotionDT, PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetSiteKeyDBName() + " = " + Convert.ToInt64(APartnerLocationRow[PLocationTable.GetSiteKeyDBName(), DataRowVersion.Current]).ToString() + " AND " + PartnerAddressAggregateTDSAddressAddedOrChangedPromotionTable.GetLocationKeyDBName() + " = " + Convert.ToInt32(APartnerLocationRow[PLocationTable.GetLocationKeyDBName(), DataRowVersion.Current]).ToString(), "", DataViewRowState.CurrentRows); // There is a row like that: replace SiteKey and LocationKey! if (AddressAddedOrChangedParametersDV.Count != 0) { AddressAddedOrChangedRow = (PartnerAddressAggregateTDSAddressAddedOrChangedPromotionRow)AddressAddedOrChangedParametersDV[0].Row; // TLogging.LogAtLevel(9, "ModifyAddressAddedOrChangedParameters: Exchanging LocationKey " + AddressAddedOrChangedRow.LocationKey.ToString() + // " with LocationKey " + APartnerLocationRow.LocationKey.ToString()); AddressAddedOrChangedRow.SiteKey = APartnerLocationRow.SiteKey; AddressAddedOrChangedRow.LocationKey = APartnerLocationRow.LocationKey; } }
private void ShowDetailsManual(PPartnerLocationRow ARow) { // Determine current Location Key and enable/disable buttons if ((ARow != null) && (ARow.RowState != DataRowState.Deleted)) { if (ARow.LocationKey == 0) { pnlDetails.Enabled = false; btnDelete.Enabled = false; } else { pnlDetails.Enabled = true; btnDelete.Enabled = true; } } ApplySecurity(); SetAddressFieldOrder(); }
/// <summary> /// For all members of the Family: if they have a PartnerLocation mapped to the /// same Location as the Family then update the DateGoodUntil column. /// /// @comment Must only be called for Partners of Partner Class FAMILY - the /// function does no checks on that and will fail for other Partner Classes! /// /// </summary> /// <param name="AFamilyPartnerKey">PartnerKey of the Family</param> /// <param name="APartnerLocationDR">PartnerLocation DataRow of the Family</param> /// <param name="ASubmitChangesTransaction">Running transaction in which the DB commands /// will be enlisted</param> private static void PromoteToFamilyMembersDateGoodUntilChange(Int64 AFamilyPartnerKey, PPartnerLocationRow APartnerLocationDR, TDBTransaction ASubmitChangesTransaction) { StringCollection RequiredColumns; PPersonTable FamilyPersonsDT; PPartnerLocationTable PartnerLocationDT; PPartnerLocationTable PartnerLocationSubmitDT; PPartnerLocationRow PartnerLocationSubmitDR; Int16 Counter; FamilyPersonsDT = GetFamilyMemberPartnerKeys(AFamilyPartnerKey, ASubmitChangesTransaction); PartnerLocationSubmitDT = new PPartnerLocationTable(); RequiredColumns = new StringCollection(); RequiredColumns.Add(PPartnerLocationTable.GetModificationIdDBName()); /* * For all members of the Family: if they have a PartnerLocation mapped to the * same Location as the Family then update the DateGoodUntil column */ // TLogging.LogAtLevel(9, "PromoteToFamilyMembersDateGoodUntilChange for Location " + APartnerLocationDR.LocationKey.ToString() + ": Family has " + FamilyPersonsDT.Rows.Count.ToString() + " members."); for (Counter = 0; Counter <= FamilyPersonsDT.Rows.Count - 1; Counter += 1) { // Load ModificationId for the PartnerLocation of each Person (otherwise we // will run into optimistic locking problems!) PartnerLocationDT = PPartnerLocationAccess.LoadByPrimaryKey( FamilyPersonsDT[Counter].PartnerKey, APartnerLocationDR.SiteKey, APartnerLocationDR.LocationKey, RequiredColumns, ASubmitChangesTransaction); /* * Check that found Person has PartnerLocation that is mapped to the same * Location than the one that the PartnerLocation of the Family that we are * processing is mapped to */ if (PartnerLocationDT.Rows.Count != 0) { // Build row to be able to update that PartnerLocation PartnerLocationSubmitDR = PartnerLocationSubmitDT.NewRowTyped(false); PartnerLocationSubmitDR.PartnerKey = FamilyPersonsDT[Counter].PartnerKey; PartnerLocationSubmitDR.SiteKey = APartnerLocationDR.SiteKey; PartnerLocationSubmitDR.LocationKey = APartnerLocationDR.LocationKey; PartnerLocationSubmitDR.ModificationId = PartnerLocationDT[0].ModificationId; PartnerLocationSubmitDT.Rows.Add(PartnerLocationSubmitDR); // Change its DateGoodUntil column to match the Family's PartnerLocation DateGoodUntil column if (!APartnerLocationDR.IsDateGoodUntilNull()) { // Make this row unchanged so that SubmitChanges later picks up a changed // DataRow, and not a new DataRow. PartnerLocationSubmitDR.AcceptChanges(); // Now change DateGoodUntil PartnerLocationSubmitDR.DateGoodUntil = APartnerLocationDR.DateGoodUntil; } else { // Change DataRow to a dummy value to make Null different to what was // there before PartnerLocationSubmitDR.DateGoodUntil = DateTime.MinValue; PartnerLocationSubmitDR.AcceptChanges(); // Now change DateGoodUntil PartnerLocationSubmitDR.SetDateGoodUntilNull(); } // Get PartnerLocation data of just processed Person out of memory! PartnerLocationDT.Rows.Clear(); } } /* * Save changes to DateGoodUntil columns if PartnerLocation of any FamilyMember got changed. */ if (PartnerLocationSubmitDT.Rows.Count > 0) { // Submit the changes to the DB PPartnerLocationAccess.SubmitChanges(PartnerLocationSubmitDT, ASubmitChangesTransaction); } }
/// <summary> /// return an XmlDocument with all partner info; /// the partners are grouped by class, country, status, and sitekey /// </summary> /// <returns></returns> public static string ExportPartners() { PartnerEditTDS MainDS = new PartnerEditTDS(); LoadDataFromDB(ref MainDS); // Group partners into categories. // // A partner's category is defined by his: class, country, status, and sitekey // It is stored as a string e.g. "FAMILY,DE,ACTIVE,0". // SortedList <string, List <long> > PartnerCategories = GroupPartnersIntoCategories(MainDS); // create XML structure for each category XmlDocument PartnerData = TYml2Xml.CreateXmlDocument(); XmlNode rootNode = PartnerData.FirstChild.NextSibling; Int32 groupCounter = 0; foreach (string category in PartnerCategories.Keys) { // get category data groupCounter++; XmlElement groupNode = PartnerData.CreateElement("PartnerGroup" + groupCounter.ToString()); rootNode.AppendChild(groupNode); Int32 partnerCounter = 0; string[] categoryDetails = category.Split(new char[] { ',' }); // may want to skip the categories with sitekey = -1 // right now, we still export them and ignore the partners 0 and 1000000 later groupNode.SetAttribute("class", categoryDetails[0]); groupNode.SetAttribute("Country", categoryDetails[1]); groupNode.SetAttribute("status", categoryDetails[2]); groupNode.SetAttribute("SiteKey", categoryDetails[3]); List <long> partnerKeys = PartnerCategories[category]; foreach (long partnerKey in partnerKeys) { if ((partnerKey != 0) && (partnerKey != 1000000)) // skip organization root and the 0 when exporting { MainDS.PPartner.DefaultView.RowFilter = PPartnerTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); PPartnerRow partnerRow = (PPartnerRow)MainDS.PPartner.DefaultView[0].Row; PFamilyRow familyRow = null; if (partnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_FAMILY) { MainDS.PFamily.DefaultView.RowFilter = PFamilyTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); familyRow = (PFamilyRow)MainDS.PFamily.DefaultView[0].Row; } PPersonRow personRow = null; if (partnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_PERSON) { MainDS.PPerson.DefaultView.RowFilter = PPersonTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); personRow = (PPersonRow)MainDS.PPerson.DefaultView[0].Row; } POrganisationRow organisationRow = null; if (partnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_ORGANISATION) { MainDS.POrganisation.DefaultView.RowFilter = POrganisationTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); organisationRow = (POrganisationRow)MainDS.POrganisation.DefaultView[0].Row; } PUnitRow unitRow = null; UmUnitStructureRow unitStructureRow = null; if (partnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_UNIT) { MainDS.PUnit.DefaultView.RowFilter = PUnitTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); unitRow = (PUnitRow)MainDS.PUnit.DefaultView[0].Row; MainDS.UmUnitStructure.DefaultView.RowFilter = UmUnitStructureTable.GetChildUnitKeyDBName() + " = " + partnerKey.ToString(); long numParents = MainDS.UmUnitStructure.DefaultView.Count; if (numParents == 1) { unitStructureRow = (UmUnitStructureRow)MainDS.UmUnitStructure.DefaultView[0].Row; } else { throw new Exception( "Units must have exactly one ParentUnit. " + "The unit with partnerKey " + partnerKey.ToString() + " has " + numParents.ToString() + "."); } } PBankRow BankRow = null; if (partnerRow.PartnerClass == MPartnerConstants.PARTNERCLASS_BANK) { MainDS.PBank.DefaultView.RowFilter = PBankTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); BankRow = (PBankRow)MainDS.PBank.DefaultView[0].Row; } partnerCounter++; XmlElement partnerNode = PartnerData.CreateElement("Partner" + partnerCounter.ToString()); groupNode.AppendChild(partnerNode); partnerNode.SetAttribute("PartnerKey", partnerRow.PartnerKey.ToString()); //groupNode.SetAttribute("ShortName", partnerRow.PartnerShortName.ToString()); if (personRow != null) { partnerNode.SetAttribute("FirstName", personRow.FirstName.ToString()); partnerNode.SetAttribute("LastName", personRow.FamilyName.ToString()); partnerNode.SetAttribute("Title", personRow.Title.ToString()); } else if (familyRow != null) { partnerNode.SetAttribute("FirstName", familyRow.FirstName.ToString()); partnerNode.SetAttribute("LastName", familyRow.FamilyName.ToString()); partnerNode.SetAttribute("Title", familyRow.Title.ToString()); } else if (organisationRow != null) { partnerNode.SetAttribute("Name", organisationRow.OrganisationName.ToString()); } else if (unitRow != null) { partnerNode.SetAttribute("Name", unitRow.UnitName.ToString()); partnerNode.SetAttribute("UnitTypeCode", unitRow.UnitTypeCode.ToString()); if (unitStructureRow != null) { partnerNode.SetAttribute("ParentUnitKey", unitStructureRow.ParentUnitKey.ToString()); } } if (BankRow != null) { partnerNode.SetAttribute("BranchName", BankRow.BranchName); partnerNode.SetAttribute("BranchCode", BankRow.BranchCode); partnerNode.SetAttribute("BranchBic", BankRow.Bic); partnerNode.SetAttribute("EpFormatFile", BankRow.EpFormatFile); } partnerNode.SetAttribute("CreatedAt", partnerRow.DateCreated.Value.ToString("yyyy-MM-dd HH:mm:ss")); // special types string specialTypes = ""; MainDS.PPartnerType.DefaultView.RowFilter = PPartnerTypeTable.GetPartnerKeyDBName() + "=" + partnerKey.ToString(); foreach (DataRowView rv in MainDS.PPartnerType.DefaultView) { if (specialTypes.Length > 0) { specialTypes += ", "; } specialTypes += ((PPartnerTypeRow)rv.Row).TypeCode; } if (specialTypes.Length > 0) { partnerNode.SetAttribute("SpecialTypes", specialTypes); } // addresses DataView partnerLocationView = MainDS.PPartnerLocation.DefaultView; partnerLocationView.RowFilter = PPartnerLocationTable.GetPartnerKeyDBName() + " = " + partnerRow.PartnerKey.ToString() + "AND " + PPartnerLocationTable.GetLocationKeyDBName() + " <> 0 "; // ignore invalid addresses Int32 addressCounter = 0; foreach (DataRowView rv in partnerLocationView) { XmlElement addressNode = PartnerData.CreateElement("Address" + (addressCounter > 0 ? addressCounter.ToString() : "")); addressCounter++; partnerNode.AppendChild(addressNode); PPartnerLocationRow partnerLocationRow = (PPartnerLocationRow)rv.Row; DataView locationView = MainDS.PLocation.DefaultView; locationView.RowFilter = PLocationTable.GetSiteKeyDBName() + "=" + partnerLocationRow.SiteKey.ToString() + " AND " + PLocationTable.GetLocationKeyDBName() + "=" + partnerLocationRow.LocationKey.ToString(); if (locationView.Count > 0) { PLocationRow locationRow = (PLocationRow)locationView[0].Row; addressNode.SetAttribute("Street", locationRow.StreetName); addressNode.SetAttribute("City", locationRow.City); addressNode.SetAttribute("PostCode", locationRow.PostalCode); } addressNode.SetAttribute("Email", partnerLocationRow.EmailAddress); addressNode.SetAttribute("Phone", partnerLocationRow.TelephoneNumber); addressNode.SetAttribute("MobilePhone", partnerLocationRow.MobileNumber); } // TODO: notes // TODO: This doesn't export as much data as it should? } } } return(TXMLParser.XmlToString(PartnerData)); }
/// <summary> /// create PPartnerLocation records for the FAMILY partner, and all the PERSON records of this family /// </summary> public static void GenerateAddressForFamily(XmlNode ACurrentNode, PFamilyRow AFamilyRow, PartnerEditTDS AMainDS) { PLocationRow locationRow = AMainDS.PLocation.NewRowTyped(); locationRow.SiteKey = 0; // DomainManager.GSiteKey; locationRow.LocationKey = (AMainDS.PLocation.Count + 1) * -1; locationRow.StreetName = TXMLParser.GetAttribute(ACurrentNode, "Addr2"); locationRow.PostalCode = TXMLParser.GetAttribute(ACurrentNode, "PostCode"); locationRow.City = TXMLParser.GetAttribute(ACurrentNode, "City"); locationRow.County = TXMLParser.GetAttribute(ACurrentNode, "Province"); locationRow.CountryCode = TXMLParser.GetAttribute(ACurrentNode, "CountryCode"); AMainDS.PLocation.Rows.Add(locationRow); PPartnerLocationRow familyLocationRow = AMainDS.PPartnerLocation.NewRowTyped(); familyLocationRow.PartnerKey = AFamilyRow.PartnerKey; familyLocationRow.LocationKey = locationRow.LocationKey; familyLocationRow.SiteKey = locationRow.SiteKey; familyLocationRow.LocationType = MPartnerConstants.LOCATIONTYPE_HOME; familyLocationRow.SendMail = true; string gender = TXMLParser.GetAttribute(ACurrentNode, "familySituation"); Random r = new Random(); string email = TXMLParser.GetAttribute(ACurrentNode, "FemaleEmail"); if ((gender == "singleMan") || ((gender == "family") && (r.Next(2) == 0))) { email = TXMLParser.GetAttribute(ACurrentNode, "MaleEmail"); } if (email.Length > 0) { PPartnerAttributeRow partnerAttributeRow = AMainDS.PPartnerAttribute.NewRowTyped(); partnerAttributeRow.PartnerKey = AFamilyRow.PartnerKey; partnerAttributeRow.AttributeType = MPartnerConstants.ATTR_TYPE_EMAIL; partnerAttributeRow.Index = 0; partnerAttributeRow.Primary = true; partnerAttributeRow.Value = email; AMainDS.PPartnerAttribute.Rows.Add(partnerAttributeRow); partnerAttributeRow = AMainDS.PPartnerAttribute.NewRowTyped(); partnerAttributeRow.PartnerKey = AFamilyRow.PartnerKey; partnerAttributeRow.AttributeType = MPartnerConstants.ATTR_TYPE_PARTNERS_PRIMARY_CONTACT_METHOD; partnerAttributeRow.Index = 9999; partnerAttributeRow.Primary = false; partnerAttributeRow.Value = MPartnerConstants.ATTR_TYPE_EMAIL; AMainDS.PPartnerAttribute.Rows.Add(partnerAttributeRow); } AMainDS.PPartnerLocation.Rows.Add(familyLocationRow); DataView FamilyView = new DataView(AMainDS.PPerson); FamilyView.RowFilter = PPersonTable.GetFamilyKeyDBName() + " = " + AFamilyRow.PartnerKey.ToString(); FamilyView.Sort = PPersonTable.GetFamilyIdDBName(); // for each person, also create a location record for (int countPerson = 0; countPerson < FamilyView.Count; countPerson++) { PPersonRow personRow = (PPersonRow)FamilyView[countPerson].Row; PPartnerLocationRow personLocationRow = AMainDS.PPartnerLocation.NewRowTyped(); personLocationRow.PartnerKey = personRow.PartnerKey; personLocationRow.LocationKey = familyLocationRow.LocationKey; personLocationRow.SiteKey = familyLocationRow.SiteKey; personLocationRow.LocationType = MPartnerConstants.LOCATIONTYPE_HOME; personLocationRow.SendMail = false; AMainDS.PPartnerLocation.Rows.Add(personLocationRow); } }
// get data from screen and ammend/add to dataset private void GetDataFromControlsManual(PcConferenceRow ARow) { PcConferenceRow ConferenceData = (PcConferenceRow)FMainDS.PcConference.Rows[0]; PPartnerLocationRow PartnerLocationData = (PPartnerLocationRow)FMainDS.PPartnerLocation.Rows[0]; PUnitRow UnitData = (PUnitRow)FMainDS.PUnit.Rows[0]; // do not save currency if it is blank but instead change the combo box to display original value if (cmbCurrency.GetSelectedString() != "") { ConferenceData.CurrencyCode = cmbCurrency.GetSelectedString(); UnitData.OutreachCostCurrencyCode = cmbCurrency.GetSelectedString(); } else { cmbCurrency.SetSelectedString(ConferenceData.CurrencyCode); } ConferenceData.Start = dtpStartDate.Date; ConferenceData.End = dtpEndDate.Date; PartnerLocationData.DateEffective = dtpStartDate.Date; PartnerLocationData.DateGoodUntil = dtpEndDate.Date; // get data from radio buttons and check button for PcConferenceOption string[] OptionTypeCodes = { "COST_PER_NIGHT", "COST_PER_DAY", "ADD_ACCOMM_COST_FOR_TOTAL" }; Boolean[] OptionSet = { rbtNight.Checked, rbtDay.Checked, chkAddAccommodationCosts.Checked }; for (int i = 0; i < 3; i++) { DataRow RowExists = FMainDS.PcConferenceOption.Rows.Find(new object[] { FPartnerKey, OptionTypeCodes[i] }); // create new row if needed if ((RowExists == null) && OptionSet[i]) { PcConferenceOptionRow RowToAdd = FMainDS.PcConferenceOption.NewRowTyped(true); RowToAdd.ConferenceKey = FPartnerKey; RowToAdd.OptionTypeCode = OptionTypeCodes[i]; RowToAdd.OptionSet = true; FMainDS.PcConferenceOption.Rows.Add(RowToAdd); } // update existing record else if ((RowExists != null) && OptionSet[i]) { ((PcConferenceOptionRow)RowExists).OptionSet = true; } // delete existing record if discount is 0 else if ((RowExists != null) && !OptionSet[i]) { RowExists.Delete(); } } // reset the Accommodation text boxs to 0 if no longer needed if (!chkAddAccommodationCosts.Checked) { txtSpecialRolePreAccommodation.NumberValueInt = 0; txtVolunteerPreAccommodation.NumberValueInt = 0; txtParticipantPreAccommodation.NumberValueInt = 0; txtSpecialRoleAccommodation.NumberValueInt = 0; txtVolunteerAccommodation.NumberValueInt = 0; txtSpecialRoleCampaignAccommodation.NumberValueInt = 0; } // get data from discount text boxes for PcDiscount string[, ] Discounts = { { "ROLE", "CONFERENCE", "PRE", txtSpecialRolePreAttendance.Text.TrimEnd(new char[] { ' ', '%' }) }, { "VOL", "CONFERENCE", "PRE", txtVolunteerPreAttendance.Text.TrimEnd(new char[] { ' ', '%' }) }, { "OTHER", "CONFERENCE", "PRE", txtParticipantPreAttendance.Text.TrimEnd(new char[] { ' ', '%' }) }, { "ROLE", "CONFERENCE", "CONF", txtSpecialRoleAttendance.Text.TrimEnd(new char[] { ' ', '%' }) }, { "VOL", "CONFERENCE", "CONF", txtVolunteerAttendance.Text.TrimEnd(new char[] { ' ', '%' }) }, { "ROLE", "CONFERENCE", "POST", txtSpecialRoleCampaignAttendance.Text.TrimEnd(new char[] { ' ', '%' }) }, { "ROLE", "ACCOMMODATION", "PRE", txtSpecialRolePreAccommodation.Text.TrimEnd(new char[] { ' ', '%' }) }, { "VOL", "ACCOMMODATION", "PRE", txtVolunteerPreAccommodation.Text.TrimEnd(new char[] { ' ', '%' }) }, { "OTHER", "ACCOMMODATION", "PRE", txtParticipantPreAccommodation.Text.TrimEnd(new char[] { ' ', '%' }) }, { "ROLE", "ACCOMMODATION", "CONF", txtSpecialRoleAccommodation.Text.TrimEnd(new char[] { ' ', '%' }) }, { "VOL", "ACCOMMODATION", "CONF", txtVolunteerAccommodation.Text.TrimEnd(new char[] { ' ', '%' }) }, { "ROLE", "ACCOMMODATION", "POST", txtSpecialRoleCampaignAccommodation.Text.TrimEnd(new char[] { ' ', '%' }) } }; for (int i = 0; i < 12; i++) { DataRow RowExists = FMainDS.PcDiscount.Rows.Find(new object[] { FPartnerKey, Discounts[i, 0], Discounts[i, 1], Discounts[i, 2], -1 }); if (Discounts[i, 3] == "") { Discounts[i, 3] = "0"; } // create new row if needed if ((RowExists == null) && (Convert.ToInt32(Discounts[i, 3]) != 0)) { PcDiscountRow RowToAdd = FMainDS.PcDiscount.NewRowTyped(true); RowToAdd.ConferenceKey = FPartnerKey; RowToAdd.DiscountCriteriaCode = Discounts[i, 0]; RowToAdd.CostTypeCode = Discounts[i, 1]; RowToAdd.Validity = Discounts[i, 2]; RowToAdd.UpToAge = -1; RowToAdd.Percentage = true; RowToAdd.Discount = Convert.ToInt32(Discounts[i, 3]); FMainDS.PcDiscount.Rows.Add(RowToAdd); } // update existing record else if ((RowExists != null) && (Convert.ToInt32(Discounts[i, 3]) != 0)) { ((PcDiscountRow)RowExists).Discount = Convert.ToInt32(Discounts[i, 3]); } // delete existing record if discount is 0 else if ((RowExists != null) && (Convert.ToInt32(Discounts[i, 3]) == 0)) { RowExists.Delete(); } } }
private void GetDetailDataFromControlsManual(PPartnerLocationRow ARow) { }
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; } }