/// <summary> /// Calls the normal ShowData() Method and then performs the rest of the /// setting up of the data that is shown in the screen. /// </summary> /// <returns>void</returns> private void SpecialShowData() { ShowData((PPersonRow)FMainDS.PPerson.Rows[0]); // Check for unexpected condition... if (FMainDS.SummaryData.Rows.Count == 0) { MessageBox.Show("FMainDS.SummaryData holds NO ROWS!", DEV_FIX); } // Show note about multiple Churches/Pastors, if applicable SetupMultipleRecordsInfoText(); // Setup Jobs/Commitments Grid DataView myDataView = FMainDS.JobAssignmentStaffDataCombined.DefaultView; myDataView.AllowNew = false; myDataView.Sort = PmJobAssignmentTable.GetFromDateDBName() + " DESC"; grdDetails.DataSource = new DevAge.ComponentModel.BoundDataView(myDataView); // Record current 'Best Address' and it's Phone Number and Email Address of the PERSON if (FMainDS.Tables[PartnerEditTDSPPartnerLocationTable.GetTableName()] != null) { DetermineAddressComponents(out FPhoneOfPerson, out FEmailOfPerson); } // Record current relationship(s) that are supporting Church(es) of the PERSON if (FMainDS.Tables[PPartnerRelationshipTable.GetTableName()] != null) { DetermineChurchRelationships(out FSupportingChurchesPartnerKeys); } }
/// <summary> /// check the validity of each location and update the icon of each location (current address, old address, future address) /// </summary> /// <param name="APartnerLocationsDT">the datatable to check</param> /// <param name="ADateToCheck"></param> public static void DeterminePartnerLocationsDateStatus(DataTable APartnerLocationsDT, DateTime ADateToCheck) { System.DateTime pDateEffective; System.DateTime pDateGoodUntil; /* * Add custom DataColumn if its not part of the DataTable yet */ if (!APartnerLocationsDT.Columns.Contains(PARTNERLOCATION_ICON_COLUMN)) { APartnerLocationsDT.Columns.Add(new System.Data.DataColumn(PARTNERLOCATION_ICON_COLUMN, typeof(Int32))); } /* * Loop over all DataRows and determine their 'Date Status'. The result is then * stored in the 'Icon' DataColumn. */ foreach (DataRow pRow in APartnerLocationsDT.Rows) { if (pRow.RowState != DataRowState.Deleted) { bool Unchanged = pRow.RowState == DataRowState.Unchanged; pDateEffective = TSaveConvert.ObjectToDate(pRow[PPartnerLocationTable.GetDateEffectiveDBName()]); pDateGoodUntil = TSaveConvert.ObjectToDate( pRow[PPartnerLocationTable.GetDateGoodUntilDBName()], TNullHandlingEnum.nhReturnHighestDate); // Current Address: Icon = 1, // Future Address: Icon = 2, // Expired Address: Icon = 3. if ((pDateEffective <= ADateToCheck) && ((pDateGoodUntil >= ADateToCheck) || (pDateGoodUntil == new DateTime(9999, 12, 31)))) { pRow[PartnerEditTDSPPartnerLocationTable.GetIconDBName()] = ((object)1); } else if (pDateEffective > ADateToCheck) { pRow[PartnerEditTDSPPartnerLocationTable.GetIconDBName()] = ((object)2); } else { pRow[PartnerEditTDSPPartnerLocationTable.GetIconDBName()] = ((object)3); } if (Unchanged) { // We do not want changing the Icon column to enable save. So revert row status to original. pRow.AcceptChanges(); } } } }
/// <summary> /// Update extra location specific fields in table APartnerLocationTable /// </summary> /// <param name="ALocationTable">Table containing location records to be used to update APartnerLocation records</param> /// <param name="APartnerLocationTable">Table to be updated with Location specific information</param> /// <returns></returns> public static void SyncPartnerEditTDSPartnerLocation(PLocationTable ALocationTable, PartnerEditTDSPPartnerLocationTable APartnerLocationTable) { DataRow Row; PLocationRow LocationRow; foreach (PartnerEditTDSPPartnerLocationRow PartnerLocationRow in APartnerLocationTable.Rows) { Row = ALocationTable.Rows.Find(new Object[] { PartnerLocationRow.SiteKey, PartnerLocationRow.LocationKey }); if (Row != null) { LocationRow = (PLocationRow)Row; PartnerLocationRow.LocationLocality = LocationRow.Locality; PartnerLocationRow.LocationStreetName = LocationRow.StreetName; PartnerLocationRow.LocationAddress3 = LocationRow.Address3; PartnerLocationRow.LocationCity = LocationRow.City; PartnerLocationRow.LocationCounty = LocationRow.County; PartnerLocationRow.LocationPostalCode = LocationRow.PostalCode; PartnerLocationRow.LocationCountryCode = LocationRow.CountryCode; PartnerLocationRow.LocationCreatedBy = LocationRow.CreatedBy; if (!LocationRow.IsDateCreatedNull()) { PartnerLocationRow.LocationDateCreated = (DateTime)LocationRow.DateCreated; } PartnerLocationRow.LocationModifiedBy = LocationRow.ModifiedBy; if (!LocationRow.IsDateModifiedNull()) { PartnerLocationRow.LocationDateModified = (DateTime)LocationRow.DateModified; } } } }
/// <summary> /// Returns the PLocationRow of the 'Best Address'. /// </summary> /// <remarks>One of the 'DetermineBestAddress' Methods must have been run before on the PartnerLocation /// Table that gets passed in in the <paramref name="APartnerLocationDT" /> Argument!!!</remarks> /// <param name="APartnerLocationDT">Typed PartnerLocation Table that was already processed by one of the /// 'DetermineBestAddress' Methods.</param> /// <param name="ALocationDT">Location Table that contains all Location records that are referenced in /// <paramref name="APartnerLocationDT" />.</param> /// <returns>Location Row of the 'Best Address'.</returns> public static PLocationRow FindBestAddressLocation(PartnerEditTDSPPartnerLocationTable APartnerLocationDT, PLocationTable ALocationDT) { PartnerEditTDSPPartnerLocationRow CheckDR; string NameOfBestAddrColumn = PartnerEditTDSPPartnerLocationTable.GetBestAddressDBName(); var BestLocationPK = new TLocationPK(-1, -1); PLocationRow BestLocationDR; for (int Counter = 0; Counter < APartnerLocationDT.Count; Counter++) { CheckDR = APartnerLocationDT[Counter]; if (CheckDR[NameOfBestAddrColumn] == ((object)1)) { BestLocationPK = new TLocationPK(CheckDR.SiteKey, CheckDR.LocationKey); } } if ((BestLocationPK.SiteKey == -1) && (BestLocationPK.LocationKey == -1)) { throw new EOPAppException( "FindBestAddressLocation Method was unable to determine the 'Best Address' (PPartnerLocation error)! (Was 'DetermineBestAddress' run before?)"); } BestLocationDR = (PLocationRow)ALocationDT.Rows.Find( new object[] { BestLocationPK.SiteKey, BestLocationPK.LocationKey }); if (BestLocationDR == null) { throw new EOPAppException( "FindBestAddressLocation Method was unable to determine the 'Best Address' (PLocation error)! (Was 'DetermineBestAddress' run before?)"); } return(BestLocationDR); }
/// <summary> /// Update extra location specific fields in table APartnerLocationTable /// </summary> /// <param name="ALocationTable">Table containing location records to be used to update APartnerLocation records</param> /// <param name="APartnerLocationTable">Table to be updated with Location specific information</param> /// <returns></returns> public static void SyncPartnerEditTDSPartnerLocation(PLocationTable ALocationTable, PartnerEditTDSPPartnerLocationTable APartnerLocationTable) { DataRow Row; PLocationRow LocationRow; foreach (PartnerEditTDSPPartnerLocationRow PartnerLocationRow in APartnerLocationTable.Rows) { Row = ALocationTable.Rows.Find(new Object[] { PartnerLocationRow.SiteKey, PartnerLocationRow.LocationKey }); if (Row != null) { LocationRow = (PLocationRow)Row; PartnerLocationRow.LocationLocality = LocationRow.Locality; PartnerLocationRow.LocationStreetName = LocationRow.StreetName; PartnerLocationRow.LocationAddress3 = LocationRow.Address3; PartnerLocationRow.LocationCity = LocationRow.City; PartnerLocationRow.LocationCounty = LocationRow.County; PartnerLocationRow.LocationPostalCode = LocationRow.PostalCode; PartnerLocationRow.LocationCountryCode = LocationRow.CountryCode; PartnerLocationRow.LocationCreatedBy = LocationRow.CreatedBy; if (!LocationRow.IsDateCreatedNull()) { PartnerLocationRow.LocationDateCreated = (DateTime)LocationRow.DateCreated; } PartnerLocationRow.LocationModifiedBy = LocationRow.ModifiedBy; if (!LocationRow.IsDateModifiedNull()) { PartnerLocationRow.LocationDateModified = (DateTime)LocationRow.DateModified; } } } }
/// <summary> /// Update extra location specific fields in table APartnerLocationTable /// </summary> /// <param name="ALocationDT">Table containing location records to be used to update APartnerLocation records.</param> /// <param name="APartnerLocationDT">Table to be updated with Location specific information.</param> /// <param name="AMakePLocationRecordUnchanged">Set to true to make the PLocation Record unchanged /// (by calling .AcceptChanges() on it).</param> public static void SyncPartnerEditTDSPartnerLocation(PLocationTable ALocationDT, PartnerEditTDSPPartnerLocationTable APartnerLocationDT, bool AMakePLocationRecordUnchanged = false) { foreach (PartnerEditTDSPPartnerLocationRow PartnerLocationRow in APartnerLocationDT.Rows) { SyncPartnerEditTDSPartnerLocation(ALocationDT, PartnerLocationRow, AMakePLocationRecordUnchanged); } }
/// <summary> /// Determines which address is the 'Best Address' of a Partner, and marks it in the DataColumn 'BestAddress'. /// </summary> /// <remarks>There are convenient overloaded server-side Methods, Ict.Petra.Server.MPartner.ServerCalculations.DetermineBestAddress, /// which work by specifying the PartnerKey of a Partner in an Argument.</remarks> /// <param name="APartnerLocationsDT">DataTable containing the addresses of a Partner.</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(DataTable APartnerLocationsDT) { TLocationPK ReturnValue; DataRow[] OrderedRows; System.Int32 CurrentRow; System.Int32 BestRow; System.Int16 FirstRowAddrOrder; bool FirstRowMailingAddress; System.DateTime BestRowDate; System.DateTime TempDate; CurrentRow = 0; BestRow = 0; bool Unchanged = false; TLogging.LogAtLevel(8, "Calculations.DetermineBestAddress: processing " + APartnerLocationsDT.Rows.Count.ToString() + " rows..."); if (APartnerLocationsDT == null) { throw new ArgumentException("Argument APartnerLocationsDT must not be null"); } if (!APartnerLocationsDT.Columns.Contains(PARTNERLOCATION_BESTADDR_COLUMN)) { DeterminePartnerLocationsDateStatus(APartnerLocationsDT, DateTime.Today); } /* * Add custom DataColumn if its not part of the DataTable yet */ if (!APartnerLocationsDT.Columns.Contains(PARTNERLOCATION_BESTADDR_COLUMN)) { APartnerLocationsDT.Columns.Add(new System.Data.DataColumn(PARTNERLOCATION_BESTADDR_COLUMN, typeof(Boolean))); } /* * Order tables' rows: first all records with p_send_mail_l = true, these are ordered * ascending by Icon, then all records with p_send_mail_l = false, these are ordered * ascending by Icon. */ OrderedRows = APartnerLocationsDT.Select(APartnerLocationsDT.DefaultView.RowFilter, PPartnerLocationTable.GetSendMailDBName() + " DESC, " + PartnerEditTDSPPartnerLocationTable.GetIconDBName() + " ASC", DataViewRowState.CurrentRows); if (OrderedRows.Length > 1) { FirstRowAddrOrder = Convert.ToInt16(OrderedRows[0][PartnerEditTDSPPartnerLocationTable.GetIconDBName()]); FirstRowMailingAddress = Convert.ToBoolean(OrderedRows[0][PPartnerLocationTable.GetSendMailDBName()]); // determine pBestRowDate if (FirstRowAddrOrder != 3) { BestRowDate = TSaveConvert.ObjectToDate(OrderedRows[CurrentRow][PPartnerLocationTable.GetDateEffectiveDBName()]); } else { BestRowDate = TSaveConvert.ObjectToDate(OrderedRows[CurrentRow][PPartnerLocationTable.GetDateGoodUntilDBName()]); } // iterate through the sorted rows for (CurrentRow = 0; CurrentRow <= OrderedRows.Length - 1; CurrentRow += 1) { Unchanged = OrderedRows[CurrentRow].RowState == DataRowState.Unchanged; // reset any row that might have been marked as 'best' before OrderedRows[CurrentRow][PartnerEditTDSPPartnerLocationTable.GetBestAddressDBName()] = ((object)0); // We do not want changing the BestAddress column to enable save. So revert row status to original. if (Unchanged) { OrderedRows[CurrentRow].AcceptChanges(); } // determine pTempDate if (FirstRowAddrOrder != 3) { TempDate = TSaveConvert.ObjectToDate(OrderedRows[CurrentRow][PPartnerLocationTable.GetDateEffectiveDBName()]); } else { TempDate = TSaveConvert.ObjectToDate(OrderedRows[CurrentRow][PPartnerLocationTable.GetDateGoodUntilDBName()]); } // still the same ADDR_ORDER than the ADDR_ORDER of the first row and // still the same Mailing Address than the Mailing Address flag of the first row > proceed if ((Convert.ToInt16(OrderedRows[CurrentRow][PartnerEditTDSPPartnerLocationTable.GetIconDBName()]) == FirstRowAddrOrder) && (Convert.ToBoolean(OrderedRows[CurrentRow][PPartnerLocationTable.GetSendMailDBName()]) == FirstRowMailingAddress)) { switch (FirstRowAddrOrder) { case 1: case 3: // find the Row with the highest p_date_effective_d (or p_date_good_until_d) date if (TempDate > BestRowDate) { BestRowDate = TempDate; BestRow = CurrentRow; } break; case 2: // find the Row with the lowest p_date_effective_d date if (TempDate < BestRowDate) { BestRowDate = TempDate; BestRow = CurrentRow; } break; } } } Unchanged = OrderedRows[0].RowState == DataRowState.Unchanged; // mark the location that was determined to be the 'best' OrderedRows[BestRow][PartnerEditTDSPPartnerLocationTable.GetBestAddressDBName()] = ((object)1); // We do not want changing the BestAddress column to enable save. So revert row status to original. if (Unchanged) { OrderedRows[0].AcceptChanges(); } ReturnValue = new TLocationPK(Convert.ToInt64(OrderedRows[BestRow][PLocationTable.GetSiteKeyDBName()]), Convert.ToInt32(OrderedRows[BestRow][PLocationTable.GetLocationKeyDBName()])); } else { if (OrderedRows.Length == 1) { Unchanged = OrderedRows[0].RowState == DataRowState.Unchanged; // mark the only location to be the 'best' OrderedRows[0][PartnerEditTDSPPartnerLocationTable.GetBestAddressDBName()] = ((object)1); // We do not want changing the BestAddress column to enable save. So revert row status to original. if (Unchanged) { OrderedRows[0].AcceptChanges(); } ReturnValue = new TLocationPK(Convert.ToInt64(OrderedRows[0][PLocationTable.GetSiteKeyDBName()]), Convert.ToInt32(OrderedRows[0][PLocationTable.GetLocationKeyDBName()])); } else { ReturnValue = new TLocationPK(); } } return(ReturnValue); }
/// <summary> /// Determines the 'Best Address' of the PERSON and its Phone Number and Email Address. /// </summary> /// <param name="APhoneNumberOfPerson">Phone Number of the PERSON in international format.</param> /// <param name="AEmailAddressOfPerson">Email Address of the PERSON.</param> /// <returns><see cref="Ict.Petra.Shared.MPartner.TLocationPK" /> pointing to the 'Best Address' of the PERSON.</returns> private TLocationPK DetermineAddressComponents(out string APhoneNumberOfPerson, out string AEmailAddressOfPerson) { TLocationPK ReturnValue = Ict.Petra.Shared.MPartner.Calculations.DetermineBestAddress( FMainDS.Tables[PartnerEditTDSPPartnerLocationTable.GetTableName()]); DataRow BestPartnerLocationDR; DataRow BestLocationDR; string TelephoneNumber; string Extension; string CountryCode; // Initialise out Arguments APhoneNumberOfPerson = null; AEmailAddressOfPerson = null; BestPartnerLocationDR = FMainDS.Tables[PartnerEditTDSPPartnerLocationTable.GetTableName()].Rows.Find(new object[] { FMainDS.PPerson[0].PartnerKey, ReturnValue.SiteKey, ReturnValue.LocationKey }); if (BestPartnerLocationDR != null) { BestLocationDR = FMainDS.Tables[PLocationTable.GetTableName()].Rows.Find(new object[] { ReturnValue.SiteKey, ReturnValue.LocationKey }); if (!BestPartnerLocationDR.IsNull(PPartnerLocationTable.GetTelephoneNumberDBName())) { TelephoneNumber = (string)BestPartnerLocationDR[PPartnerLocationTable.GetTelephoneNumberDBName()]; } else { TelephoneNumber = String.Empty; } if (!BestPartnerLocationDR.IsNull(PPartnerLocationTable.GetExtensionDBName())) { Extension = ((int)BestPartnerLocationDR[PPartnerLocationTable.GetExtensionDBName()]).ToString(); } else { Extension = String.Empty; } if (!BestLocationDR.IsNull(PLocationTable.GetCountryCodeDBName())) { CountryCode = (string)BestLocationDR[PLocationTable.GetCountryCodeDBName()]; } else { CountryCode = String.Empty; } APhoneNumberOfPerson = Ict.Petra.Shared.MPartner.Calculations.FormatIntlPhoneNumber( TelephoneNumber, Extension, CountryCode, @TDataCache.GetCacheableDataTableFromCache); if (!BestPartnerLocationDR.IsNull(PPartnerLocationTable.GetEmailAddressDBName())) { AEmailAddressOfPerson = (string)BestPartnerLocationDR[PPartnerLocationTable.GetEmailAddressDBName()]; } else { AEmailAddressOfPerson = String.Empty; } } else { MessageBox.Show("Unexpected condition: 'Best Address of PERSON is null'", DEV_FIX); } return(ReturnValue); }
/// <summary> /// Called when data got saved in the screen. Performs a check whether reloading /// of the 'SummaryData' is necessary to reflect changes that were done elsewhere /// in the Partner Edit screen and which just got saved. /// </summary> /// <returns>void</returns> public void CheckForRefreshOfDisplayedData(bool AJobAndStaffDataGridNeedsRefresh) { bool RefreshNecessary = false; string PhoneOfPerson; string EmailOfPerson; if (!AJobAndStaffDataGridNeedsRefresh) { Int64[] SupportingChurchesPartnerKeys = new long[0]; if (FMainDS.Tables[PartnerEditTDSPPartnerLocationTable.GetTableName()] != null) { // Check for change of 'Best Address' and it's Phone Number and Email Address DetermineAddressComponents(out PhoneOfPerson, out EmailOfPerson); if (PhoneOfPerson != null) { if ((PhoneOfPerson != FPhoneOfPerson) || (EmailOfPerson != FEmailOfPerson)) { RefreshNecessary = true; } } } if (FMainDS.Tables[PPartnerRelationshipTable.GetTableName()] != null) { // Check for change in supporting Church/es relationship(s) DetermineChurchRelationships(out SupportingChurchesPartnerKeys); if ((FSupportingChurchesPartnerKeys == null) || (FSupportingChurchesPartnerKeys.Length != SupportingChurchesPartnerKeys.Length)) { RefreshNecessary = true; } else { for (int Counter = 0; Counter < SupportingChurchesPartnerKeys.Length; Counter++) { if (SupportingChurchesPartnerKeys[Counter] != FSupportingChurchesPartnerKeys[Counter]) { RefreshNecessary = true; } } } } } else { RefreshNecessary = true; } if (RefreshNecessary) { // Call WebConnector to retrieve SummaryData afresh! IndividualDataTDS FillDS = new IndividualDataTDS(); FillDS.Merge(FMainDS.MiscellaneousData); TRemote.MPersonnel.Person.DataElements.WebConnectors.GetSummaryData(FMainDS.PPerson[0].PartnerKey, ref FillDS); FMainDS.SummaryData.Rows.Clear(); FMainDS.Merge(FillDS.SummaryData); FMainDS.JobAssignmentStaffDataCombined.Rows.Clear(); FMainDS.Merge(FillDS.JobAssignmentStaffDataCombined); // Refresh the displayed data SpecialShowData(); } }