/// find the current best address for the partner public static bool GetBestAddress(Int64 APartnerKey, out PLocationTable AAddress, out string ACountryNameLocal, TDBTransaction ATransaction, bool AOnlySendMail = false) { AAddress = null; ACountryNameLocal = ""; DataSet PartnerLocationsDS = new DataSet(); PartnerLocationsDS.Tables.Add(new PPartnerLocationTable()); PartnerLocationsDS.Tables.Add(new PCountryTable()); DataTable PartnerLocationTable = PartnerLocationsDS.Tables[PPartnerLocationTable.GetTableName()]; PCountryTable CountryTable = (PCountryTable)PartnerLocationsDS.Tables[PCountryTable.GetTableName()]; CountryTable.DefaultView.Sort = PCountryTable.GetCountryCodeDBName(); // 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 PPartnerLocationAccess.LoadViaPPartner(PartnerLocationsDS, APartnerKey, ATransaction); Calculations.DeterminePartnerLocationsDateStatus(PartnerLocationsDS); Calculations.DetermineBestAddress(PartnerLocationsDS); foreach (PPartnerLocationRow row in PartnerLocationTable.Rows) { if (AOnlySendMail && !Convert.ToBoolean(row[PPartnerLocationTable.GetSendMailDBName()])) { // ignore addresses that are not set for receiving mail. continue; } // find the row with BestAddress = 1 if (Convert.ToInt32(row["BestAddress"]) == 1) { // we also want the post address, need to load the p_location table: AAddress = PLocationAccess.LoadByPrimaryKey(row.SiteKey, row.LocationKey, ATransaction); // watch out for empty country codes if (AAddress[0].CountryCode.Trim().Length > 0) { if (CountryTable.DefaultView.Find(AAddress[0].CountryCode) == -1) { CountryTable.Merge(PCountryAccess.LoadByPrimaryKey(AAddress[0].CountryCode, ATransaction)); } ACountryNameLocal = CountryTable[CountryTable.DefaultView.Find(AAddress[0].CountryCode)].CountryNameLocal; } break; } } return(AAddress != null); }
/// <summary> /// get the best email address that is valid today, with some location details /// </summary> public static string GetBestEmailAddressWithDetails(Int64 APartnerKey, out PLocationTable AAddress, out string ACountryNameLocal) { string EmailAddress = ""; PLocationTable Address = null; string CountryNameLocal = ""; TDBTransaction Transaction = null; DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(IsolationLevel.ReadCommitted, ref Transaction, delegate { DataSet PartnerLocationsDS = new DataSet(); PartnerLocationsDS.Tables.Add(new PPartnerLocationTable()); PartnerLocationsDS.Tables.Add(new PCountryTable()); DataTable PartnerLocationTable = PartnerLocationsDS.Tables[PPartnerLocationTable.GetTableName()]; PCountryTable CountryTable = (PCountryTable)PartnerLocationsDS.Tables[PCountryTable.GetTableName()]; CountryTable.DefaultView.Sort = PCountryTable.GetCountryCodeDBName(); // 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 PPartnerLocationAccess.LoadViaPPartner(PartnerLocationsDS, APartnerKey, Transaction); Ict.Petra.Shared.MPartner.Calculations.DeterminePartnerLocationsDateStatus(PartnerLocationsDS); Ict.Petra.Shared.MPartner.Calculations.DetermineBestAddress(PartnerLocationsDS); foreach (PPartnerLocationRow row in PartnerLocationTable.Rows) { // find the row with BestAddress = 1 if (Convert.ToInt32(row["BestAddress"]) == 1) { if (!row.IsEmailAddressNull()) { EmailAddress = row.EmailAddress; } // we also want the post address, need to load the p_location table: Address = PLocationAccess.LoadByPrimaryKey(row.SiteKey, row.LocationKey, Transaction); if (CountryTable.DefaultView.Find(Address[0].CountryCode) == -1) { CountryTable.Merge(PCountryAccess.LoadByPrimaryKey(Address[0].CountryCode, Transaction)); } CountryNameLocal = CountryTable[CountryTable.DefaultView.Find(Address[0].CountryCode)].CountryNameLocal; } } }); AAddress = Address; ACountryNameLocal = CountryNameLocal; return(EmailAddress); }
/// <summary> /// Get the printable name for this country /// </summary> /// <param name="CountryCode"></param> /// <param name="ATransaction"></param> /// <returns></returns> public static string GetCountryName(string CountryCode, TDBTransaction ATransaction) { PCountryTable Tbl = PCountryAccess.LoadByPrimaryKey(CountryCode, ATransaction); if (Tbl.Rows.Count > 0) { return(Tbl[0].CountryName); } else { return(""); } }
private String GetCountryName(String ACountryCode, ref TRptSituation ASituation) { PCountryTable CountryTable; CountryTable = PCountryAccess.LoadByPrimaryKey(ACountryCode, ASituation.GetDatabaseConnection().Transaction); if (CountryTable.Rows.Count > 0) { return((String)CountryTable.Rows[0][PCountryTable.GetCountryNameDBName()]); } return("Unknown"); }