private void ValidateDataDetailsManual(PmStaffDataRow ARow) { TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection; TSharedPersonnelValidation_Personnel.ValidateCommitmentManual(this, ARow, ref VerificationResultCollection, FValidationControlsDict); }
private void ShowDetailsManual(PmStaffDataRow ARow) { // In theory, the next Method call could be done in Methods NewRowManual; however, NewRowManual runs before // the Row is actually added and this would result in the Count to be one too less, so we do the Method call here, short // of a non-existing 'AfterNewRowManual' Method.... DoRecalculateScreenParts(); }
/// <summary> /// Code to be run after the deletion process /// </summary> /// <param name="ARowToDelete">the row that was/was to be deleted</param> /// <param name="AAllowDeletion">whether or not the user was permitted to delete</param> /// <param name="ADeletionPerformed">whether or not the deletion was performed successfully</param> /// <param name="ACompletionMessage">if specified, is the deletion completion message</param> private void PostDeleteManual(PmStaffDataRow ARowToDelete, bool AAllowDeletion, bool ADeletionPerformed, string ACompletionMessage) { if (ADeletionPerformed) { DoRecalculateScreenParts(); } }
private void NewRowManual(ref PmStaffDataRow ARow) { ARow.Key = Convert.ToInt32(TRemote.MCommon.WebConnectors.GetNextSequence(TSequenceNames.seq_staff_data)); ARow.PartnerKey = FMainDS.PPerson[0].PartnerKey; ARow.ReceivingField = 0; ARow.SetReceivingFieldOfficeNull(); ARow.OfficeRecruitedBy = TSystemDefaults.GetSiteKeyDefault(); ARow.HomeOffice = TSystemDefaults.GetSiteKeyDefault(); ARow.StartOfCommitment = DateTime.Now.Date; }
/// <summary> /// Performs checks to determine whether a deletion of the current /// row is permissable /// </summary> /// <param name="ARowToDelete">the currently selected row to be deleted</param> /// <param name="ADeletionQuestion">can be changed to a context-sensitive deletion confirmation question</param> /// <returns>true if user is permitted and able to delete the current row</returns> private bool PreDeleteManual(PmStaffDataRow ARowToDelete, ref string ADeletionQuestion) { /*Code to execute before the delete can take place*/ ADeletionQuestion = Catalog.GetString("Are you sure you want to delete the current row?"); ADeletionQuestion += String.Format("{0}{0}({1} {2} {3},{0} {4} {5})", Environment.NewLine, lblReceivingField.Text, txtReceivingField.Text, txtReceivingField.LabelText, lblStartDate.Text, dtpStartDate.Date.Value.ToString("dd-MMM-yyyy").ToUpper()); return(true); }
private void UpdateGiftDestinationForSingleCommitment(PmStaffDataRow AEligibleCommitmentRow) { List <PPartnerGiftDestinationRow> ActiveGiftDestinationsWhichCanBeEnded = new List <PPartnerGiftDestinationRow>(); PPartnerGiftDestinationRow GiftDestinationWhichCanBeModified = null; PPartnerGiftDestinationRow GiftDestinationWhichCanBeDeactivated = null; DataRowState RowState = DataRowState.Unchanged; PmStaffDataRow OriginalCommitmentRow = null; // get the rowstate of EligibleCommitmentRow DataRow TempRow = FIndividualDataDS.PmStaffData.Rows.Find(new object[] { AEligibleCommitmentRow.SiteKey, AEligibleCommitmentRow.Key }); if (TempRow != null) { RowState = TempRow.RowState; } else { RowState = DataRowState.Deleted; } // If gift destination records already exist for this partner's family... if ((FInspectDS.PPartnerGiftDestination != null) && (FInspectDS.PPartnerGiftDestination.Rows.Count > 0)) { // Get the original record (before it was edited) if ((RowState == DataRowState.Modified) || (RowState == DataRowState.Deleted)) { OriginalCommitmentRow = (PmStaffDataRow)FOriginalCommitments.Rows.Find( new object[] { AEligibleCommitmentRow.SiteKey, AEligibleCommitmentRow.Key }); } // for a modified row... only changes to recieving field, start data and end date can update the Gift Destination if ((RowState == DataRowState.Modified) && (OriginalCommitmentRow.ReceivingField == AEligibleCommitmentRow.ReceivingField) && (OriginalCommitmentRow.StartOfCommitment == AEligibleCommitmentRow.StartOfCommitment) && (OriginalCommitmentRow.EndOfCommitment == AEligibleCommitmentRow.EndOfCommitment)) { return; } else { CompareCommitmentToGiftDestinations(RowState, AEligibleCommitmentRow, OriginalCommitmentRow, ref GiftDestinationWhichCanBeModified, ref GiftDestinationWhichCanBeDeactivated, ref ActiveGiftDestinationsWhichCanBeEnded); } } DealWithPotentialGiftDestinationUpdates(RowState, AEligibleCommitmentRow, GiftDestinationWhichCanBeModified, GiftDestinationWhichCanBeDeactivated, ActiveGiftDestinationsWhichCanBeEnded); }
/// Determine which (if any) new or modified rows are eligible to update the gift destination private bool GetEligibleRowsForUpdatingGiftDestination(ref PmStaffDataTable AEligibleCommitments) { PmStaffDataRow OriginalCommitmentRow = null; foreach (PmStaffDataRow Row in FIndividualDataDS.PmStaffData.Rows) { // Commitments only trigger changes to Gift Destination if they are new and apply to future dates. if (Row.RowState == DataRowState.Deleted) { // need to temporarily undelete row Row.RejectChanges(); if (Row.IsEndOfCommitmentNull() || (Row.EndOfCommitment >= DateTime.Today)) { AEligibleCommitments.LoadDataRow(Row.ItemArray, true); } Row.Delete(); } else { OriginalCommitmentRow = (PmStaffDataRow)FOriginalCommitments.Rows.Find( new object[] { Row.SiteKey, Row.Key }); if ((Row.RowState != DataRowState.Unchanged) && (Row.IsEndOfCommitmentNull() || (Row.EndOfCommitment >= DateTime.Today) || ((OriginalCommitmentRow != null) && (OriginalCommitmentRow.IsEndOfCommitmentNull() || (OriginalCommitmentRow.EndOfCommitment >= DateTime.Today))))) { AEligibleCommitments.LoadDataRow(Row.ItemArray, true); } } } if (AEligibleCommitments.Rows.Count == 0) { return(false); } return(true); }
/// Ask the user if they want to update the Gift Destination and then make the changes private void DealWithPotentialGiftDestinationUpdates(DataRowState ARowState, PmStaffDataRow AEligibleCommitmentRow, PPartnerGiftDestinationRow AGiftDestinationWhichCanBeModified, PPartnerGiftDestinationRow AGiftDestinationWhichCanBeDeactivated, List <PPartnerGiftDestinationRow> AActiveGiftDestinationsWhichCanBeEnded) { string UnitName = ""; string ActiveGiftDestinations = ""; string EndOfCommitment; bool CreateNewGiftDestination = false; TPartnerClass PartnerClass; // set end date to display to user in messagebox if (AEligibleCommitmentRow.IsEndOfCommitmentNull()) { EndOfCommitment = "'Open Ended'"; } else { EndOfCommitment = AEligibleCommitmentRow.EndOfCommitment.Value.ToShortDateString(); } // get the receiving fields short name TRemote.MPartner.Partner.ServerLookups.WebConnectors.GetPartnerShortName(AEligibleCommitmentRow.ReceivingField, out UnitName, out PartnerClass); UnitName = UnitName + " (" + AEligibleCommitmentRow.ReceivingField + ")"; // if existing active Gift Destination/s can be ended in order to add a Gift Destination for new commitment if (AActiveGiftDestinationsWhichCanBeEnded.Count > 0) { string Message = ""; // get gift destination field's short name foreach (PPartnerGiftDestinationRow Row in AActiveGiftDestinationsWhichCanBeEnded) { string ActiveGiftDestinationName = ""; TRemote.MPartner.Partner.ServerLookups.WebConnectors.GetPartnerShortName( Row.FieldKey, out ActiveGiftDestinationName, out PartnerClass); // add conjunctions if (AActiveGiftDestinationsWhichCanBeEnded.Count > 1) { if (AActiveGiftDestinationsWhichCanBeEnded.IndexOf(Row) == AActiveGiftDestinationsWhichCanBeEnded.Count - 1) { ActiveGiftDestinations += " and "; } else if (AActiveGiftDestinationsWhichCanBeEnded.IndexOf(Row) < AActiveGiftDestinationsWhichCanBeEnded.Count - 1) { ActiveGiftDestinations += ", "; } } ActiveGiftDestinations += "'" + ActiveGiftDestinationName + "' (" + Row.FieldKey + ")"; } // two different messages depending on number of gift destinations that need to be closed if (AActiveGiftDestinationsWhichCanBeEnded.Count == 1) { Message = Catalog.GetString(string.Format( "This Person's Family has an existing Gift Destination record to the field {0} that is active during the period {1} to {2}." + "{3}Would you like to shorten or deactivate this Gift Destination and make this new Commitment to " + "the field '{4}' the active Gift Destination for this period?", ActiveGiftDestinations, AEligibleCommitmentRow.StartOfCommitment.ToShortDateString(), EndOfCommitment, "\n\n", UnitName)); } else { Message = Catalog.GetString(string.Format( "This Person's Family has existing Gift Destination records to the fields {0} that are active during the period {1} to {2}." + "{3}Would you like to shorten or deactivate these Gift Destinations and make this new Commitment to " + "the field '{4}' the active Gift Destination for this period?", ActiveGiftDestinations, AEligibleCommitmentRow.StartOfCommitment.ToShortDateString(), EndOfCommitment, "\n\n", UnitName)); } // offer to end Gift Destination/s and use new commitment instead if (MessageBox.Show(Message, Catalog.GetString("Update Gift Destination"), MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { CreateNewGiftDestination = true; foreach (PPartnerGiftDestinationRow Row in AActiveGiftDestinationsWhichCanBeEnded) { if (Row.DateEffective >= AEligibleCommitmentRow.StartOfCommitment) { // deactivate future gift destinations Row.DateExpires = Row.DateEffective; } else { // shorten older gift destinations if (Row.DateEffective != AEligibleCommitmentRow.StartOfCommitment) { Row.DateExpires = AEligibleCommitmentRow.StartOfCommitment.AddDays(-1); } else { Row.DateExpires = AEligibleCommitmentRow.StartOfCommitment; } } } } } // if an existing gift destination can be updated from a modified commitment else if (AGiftDestinationWhichCanBeModified != null) { // offer to modify this Gift Destination if (MessageBox.Show(Catalog.GetString(string.Format( "This Person's Family has an existing Gift Destination record which matches a modified commitment." + "{0}Would you like to update the Gift Destination record to the field '{1}' " + "for the period {2} to {3}?", "\n\n", UnitName, AEligibleCommitmentRow.StartOfCommitment.ToShortDateString(), EndOfCommitment)), Catalog.GetString("Update Gift Destination"), MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { AGiftDestinationWhichCanBeModified.DateExpires = AEligibleCommitmentRow.EndOfCommitment; } } // if an existing gift destination can be made inactive because of a deleted commitment else if (AGiftDestinationWhichCanBeDeactivated != null) { // offer to deactivate this Gift Destination if (MessageBox.Show(Catalog.GetString(string.Format( "This Person's Family has an existing Gift Destination record which matches a deleted commitment.{0}" + "Would you like to deactivate the Gift Destination record to the field '{1}'" + "for the period {2} to {3}?", "\n\n", UnitName, AEligibleCommitmentRow.StartOfCommitment.ToShortDateString(), EndOfCommitment)), Catalog.GetString("Update Gift Destination"), MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { AGiftDestinationWhichCanBeDeactivated.DateExpires = AGiftDestinationWhichCanBeDeactivated.DateEffective; } } // if there is no active Gift Destination during dates of new commitment else if (ARowState != DataRowState.Deleted) { // offer to create new Gift Destination using new commitment if (MessageBox.Show(Catalog.GetString(string.Format( "This Person's Family does not have an active Gift Destination during the period " + "{0} to {1}.{2}Would you like to make this new Commitment to the field " + "'{3}' the active Gift Destination for this period?", AEligibleCommitmentRow.StartOfCommitment.ToShortDateString(), EndOfCommitment, "\n\n", UnitName)), Catalog.GetString("Update Gift Destination"), MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { CreateNewGiftDestination = true; } } /* create a brand new Gift Destination */ if (CreateNewGiftDestination) { if (FInspectDS.PPartnerGiftDestination == null) { FInspectDS.Merge(new PPartnerGiftDestinationTable()); } // create new Gift Destination PPartnerGiftDestinationRow NewRow = FInspectDS.PPartnerGiftDestination.NewRowTyped(true); NewRow.Key = TRemote.MPartner.Partner.WebConnectors.GetNewKeyForPartnerGiftDestination() + FNewRecords; NewRow.PartnerKey = ((PPersonRow)FInspectDS.PPerson.Rows[0]).FamilyKey; NewRow.FieldKey = AEligibleCommitmentRow.ReceivingField; NewRow.DateEffective = AEligibleCommitmentRow.StartOfCommitment; NewRow.DateExpires = AEligibleCommitmentRow.EndOfCommitment; FInspectDS.PPartnerGiftDestination.Rows.Add(NewRow); FNewRecords++; } }
/// Iterate through each gift destination and compare with commitment record. /// Determine if gift destination can be updated and how. private void CompareCommitmentToGiftDestinations(DataRowState ARowState, PmStaffDataRow AEligibleCommitmentRow, PmStaffDataRow AOriginalCommitmentRow, ref PPartnerGiftDestinationRow AGiftDestinationWhichCanBeModified, ref PPartnerGiftDestinationRow AGiftDestinationWhichCanBeDeactivated, ref List <PPartnerGiftDestinationRow> AActiveGiftDestinationsWhichCanBeEnded) { bool Repeat = true; while (Repeat) { Repeat = false; foreach (PPartnerGiftDestinationRow CurrentRow in FInspectDS.PPartnerGiftDestination.Rows) { // if two records are the same if ((AOriginalCommitmentRow != null) && (AOriginalCommitmentRow.ReceivingField == CurrentRow.FieldKey) && (AOriginalCommitmentRow.StartOfCommitment == CurrentRow.DateEffective) && (AOriginalCommitmentRow.EndOfCommitment == CurrentRow.DateExpires) && (CurrentRow.DateEffective != CurrentRow.DateExpires)) { if ((ARowState == DataRowState.Modified) && (AOriginalCommitmentRow.StartOfCommitment == AEligibleCommitmentRow.StartOfCommitment) && (AOriginalCommitmentRow.ReceivingField == AEligibleCommitmentRow.ReceivingField)) { // if the field and start date have not been changed then we can update the Gift Destination AGiftDestinationWhichCanBeModified = CurrentRow; continue; } else if (ARowState == DataRowState.Deleted) { AGiftDestinationWhichCanBeDeactivated = CurrentRow; return; } } else if (ARowState == DataRowState.Deleted) { continue; } else if (CurrentRow.DateEffective == CurrentRow.DateExpires) { // ignore inactive Gift Destination continue; } if ((AEligibleCommitmentRow.IsEndOfCommitmentNull() && (CurrentRow.IsDateExpiresNull() || (CurrentRow.DateExpires >= AEligibleCommitmentRow.StartOfCommitment))) || !AEligibleCommitmentRow.IsEndOfCommitmentNull() && ((CurrentRow.IsDateExpiresNull() && (CurrentRow.DateEffective <= AEligibleCommitmentRow.EndOfCommitment)) || (!CurrentRow.IsDateExpiresNull() && (((CurrentRow.DateEffective >= AEligibleCommitmentRow.StartOfCommitment) && (CurrentRow.DateEffective <= AEligibleCommitmentRow.EndOfCommitment)) || (CurrentRow.DateExpires >= AEligibleCommitmentRow.StartOfCommitment) && (CurrentRow.DateExpires <= AEligibleCommitmentRow.EndOfCommitment))))) { AActiveGiftDestinationsWhichCanBeEnded.Add(CurrentRow); } } } }
public void TestDeletePerson() { DataSet ResponseDS = new PartnerEditTDS(); TVerificationResultCollection VerificationResult; String TextMessage; Boolean CanDeletePartner; PPartnerRow FamilyPartnerRow; PPartnerRow UnitPartnerRow; PPersonRow PersonRow; TSubmitChangesResult result; Int64 PartnerKey; TPartnerEditUIConnector connector = new TPartnerEditUIConnector(); PartnerEditTDS MainDS = new PartnerEditTDS(); // create new family, location and person FamilyPartnerRow = TCreateTestPartnerData.CreateNewFamilyPartner(MainDS); TCreateTestPartnerData.CreateNewLocation(FamilyPartnerRow.PartnerKey, MainDS); PersonRow = TCreateTestPartnerData.CreateNewPerson(MainDS, FamilyPartnerRow.PartnerKey, MainDS.PLocation[0].LocationKey, "Mike", "Mr", 0); result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult); Assert.AreEqual(TSubmitChangesResult.scrOK, result, "create family and person record"); // check if Family partner can be deleted (still needs to be possible at this point) CanDeletePartner = TPartnerWebConnector.CanPartnerBeDeleted(PersonRow.PartnerKey, out TextMessage); if (TextMessage.Length > 0) { TLogging.Log(TextMessage); } Assert.IsTrue(CanDeletePartner); // add a commitment for the person which means the person is not allowed to be deleted any longer UnitPartnerRow = TCreateTestPartnerData.CreateNewUnitPartner(MainDS); PmStaffDataTable CommitmentTable = new PmStaffDataTable(); PmStaffDataRow CommitmentRow = CommitmentTable.NewRowTyped(); CommitmentRow.Key = Convert.ToInt32(TSequenceWebConnector.GetNextSequence(TSequenceNames.seq_staff_data)); CommitmentRow.PartnerKey = PersonRow.PartnerKey; CommitmentRow.StartOfCommitment = DateTime.Today.Date; CommitmentRow.EndOfCommitment = DateTime.Today.AddDays(90).Date; CommitmentRow.OfficeRecruitedBy = UnitPartnerRow.PartnerKey; CommitmentRow.HomeOffice = UnitPartnerRow.PartnerKey; CommitmentRow.ReceivingField = UnitPartnerRow.PartnerKey; CommitmentTable.Rows.Add(CommitmentRow); result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult); Assert.AreEqual(TSubmitChangesResult.scrOK, result, "create unit to be used in commitment"); PmStaffDataAccess.SubmitChanges(CommitmentTable, DBAccess.GDBAccessObj.Transaction); // this should now not be allowed since person record has a commitment linked to it CanDeletePartner = TPartnerWebConnector.CanPartnerBeDeleted(PersonRow.PartnerKey, out TextMessage); if (TextMessage.Length > 0) { TLogging.Log(TextMessage); } Assert.IsTrue(!CanDeletePartner); // now test actual deletion of Person partner FamilyPartnerRow = TCreateTestPartnerData.CreateNewFamilyPartner(MainDS); TCreateTestPartnerData.CreateNewLocation(FamilyPartnerRow.PartnerKey, MainDS); PersonRow = TCreateTestPartnerData.CreateNewPerson(MainDS, FamilyPartnerRow.PartnerKey, MainDS.PLocation[0].LocationKey, "Mary", "Mrs", 0); PartnerKey = PersonRow.PartnerKey; result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult); Assert.AreEqual(TSubmitChangesResult.scrOK, result, "create family and person record to be deleted"); // check if Family record is being deleted Assert.IsTrue(TPartnerWebConnector.DeletePartner(PartnerKey, out VerificationResult)); // check that Family record is really deleted Assert.IsTrue(!TPartnerServerLookups.VerifyPartner(PartnerKey)); }
/// <summary> /// Retrieves data that will be shown on the 'Overview' UserControl and adds it to <paramref name="AIndividualDataDS" />. /// </summary> /// <param name="APartnerKey">PartnerKey of the Person to load data for.</param> /// <param name="AIndividualDataDS">Typed DataSet of Type <see cref="IndividualDataTDS" />. Needs to be instantiated already!</param> /// <param name="AReadTransaction">Open Database transaction.</param> /// <returns>void</returns> private static void BuildSummaryData(Int64 APartnerKey, ref IndividualDataTDS AIndividualDataDS, TDBTransaction AReadTransaction) { string StrNotAvailable = Catalog.GetString("Not Available"); IndividualDataTDSSummaryDataTable SummaryDT; IndividualDataTDSSummaryDataRow SummaryDR; IndividualDataTDSMiscellaneousDataRow MiscellaneousDataDR = AIndividualDataDS.MiscellaneousData[0]; PPersonTable PPersonDT; PPersonRow PersonDR = null; PmPassportDetailsTable PassportDetailsDT; PmStaffDataTable PmStaffDataDT; PmStaffDataRow PmStaffDataDR = null; PmJobAssignmentTable PmJobAssignmentDT = null; PUnitTable PUnitDT = null; PmJobAssignmentRow PmJobAssignmentDR; IndividualDataTDSJobAssignmentStaffDataCombinedRow JobAssiStaffDataCombDR; int JobAssiStaffDataCombKey = 0; TCacheable CommonCacheable = new TCacheable(); TPartnerCacheable PartnerCacheable = new TPartnerCacheable(); string MaritalStatusDescr; StringCollection PassportColumns; string Nationalities; PPartnerRelationshipTable PartnerRelationshipDT; PPartnerTable PartnerDT; PPartnerRow PartnerDR = null; PLocationRow LocationDR; PPartnerLocationRow PartnerLocationDR; string PhoneNumber; string EmailAddress; Int64 ChurchPartnerKey; SummaryDT = new IndividualDataTDSSummaryDataTable(); SummaryDR = SummaryDT.NewRowTyped(false); SummaryDR.PartnerKey = APartnerKey; #region Person Info PPersonDT = PPersonAccess.LoadByPrimaryKey(APartnerKey, AReadTransaction); if (PPersonDT.Rows.Count == 1) { PersonDR = (PPersonRow)PPersonDT.Rows[0]; } if (PersonDR != null) { SummaryDR.DateOfBirth = PersonDR.DateOfBirth; SummaryDR.Gender = PersonDR.Gender; MaritalStatusDescr = PartnerCodeHelper.GetMaritalStatusDescription( @PartnerCacheable.GetCacheableTable, PersonDR.MaritalStatus); if (MaritalStatusDescr != String.Empty) { MaritalStatusDescr = " - " + MaritalStatusDescr; } SummaryDR.MaritalStatus = PersonDR.MaritalStatus + MaritalStatusDescr; } else { SummaryDR.SetDateOfBirthNull(); SummaryDR.Gender = StrNotAvailable; SummaryDR.MaritalStatus = StrNotAvailable; } #region Nationalities PassportColumns = StringHelper.StrSplit( PmPassportDetailsTable.GetDateOfIssueDBName() + "," + PmPassportDetailsTable.GetDateOfExpirationDBName() + "," + PmPassportDetailsTable.GetPassportNationalityCodeDBName() + "," + PmPassportDetailsTable.GetMainPassportDBName(), ","); PassportDetailsDT = PmPassportDetailsAccess.LoadViaPPerson(APartnerKey, PassportColumns, AReadTransaction, null, 0, 0); Nationalities = Ict.Petra.Shared.MPersonnel.Calculations.DeterminePersonsNationalities( @CommonCacheable.GetCacheableTable, PassportDetailsDT); if (Nationalities != String.Empty) { SummaryDR.Nationalities = Nationalities; } else { SummaryDR.Nationalities = StrNotAvailable; } #endregion #region Phone and Email (from 'Best Address') if (TContactDetailsAggregate.GetPrimaryEmailAndPrimaryPhone(APartnerKey, out PhoneNumber, out EmailAddress)) { SummaryDR.PrimaryPhoneNumber = PhoneNumber ?? StrNotAvailable; SummaryDR.PrimaryEmailAddress = EmailAddress ?? StrNotAvailable; } else { SummaryDR.PrimaryPhoneNumber = StrNotAvailable; SummaryDR.PrimaryEmailAddress = StrNotAvailable; } #endregion #endregion #region Commitments/Jobs PmStaffDataDT = PmStaffDataAccess.LoadViaPPerson(APartnerKey, AReadTransaction); MiscellaneousDataDR.ItemsCountCommitmentPeriods = PmStaffDataDT.Rows.Count; // First check if the PERSON has got any Commitments if (PmStaffDataDT.Rows.Count > 0) { foreach (DataRow DR in PmStaffDataDT.Rows) { JobAssiStaffDataCombDR = AIndividualDataDS.JobAssignmentStaffDataCombined.NewRowTyped(false); JobAssiStaffDataCombDR.Key = JobAssiStaffDataCombKey++; JobAssiStaffDataCombDR.PartnerKey = APartnerKey; PmStaffDataDR = (PmStaffDataRow)DR; if (!(PmStaffDataDR.IsReceivingFieldNull()) && (PmStaffDataDR.ReceivingField != 0)) { PUnitDT = PUnitAccess.LoadByPrimaryKey(PmStaffDataDR.ReceivingField, AReadTransaction); JobAssiStaffDataCombDR.FieldKey = PmStaffDataDR.ReceivingField; JobAssiStaffDataCombDR.FieldName = PUnitDT[0].UnitName; } else { JobAssiStaffDataCombDR.FieldKey = 0; JobAssiStaffDataCombDR.FieldName = "[None]"; } JobAssiStaffDataCombDR.Position = PmStaffDataDR.JobTitle; JobAssiStaffDataCombDR.FromDate = PmStaffDataDR.StartOfCommitment; JobAssiStaffDataCombDR.ToDate = PmStaffDataDR.EndOfCommitment; AIndividualDataDS.JobAssignmentStaffDataCombined.Rows.Add(JobAssiStaffDataCombDR); } } else { // The PERSON hasn't got any Commitments, therefore check if the PERSON has any Job Assignments PmJobAssignmentDT = PmJobAssignmentAccess.LoadViaPPartner(APartnerKey, AReadTransaction); if (PmJobAssignmentDT.Rows.Count > 0) { foreach (DataRow DR in PmJobAssignmentDT.Rows) { JobAssiStaffDataCombDR = AIndividualDataDS.JobAssignmentStaffDataCombined.NewRowTyped(false); JobAssiStaffDataCombDR.Key = JobAssiStaffDataCombKey++; JobAssiStaffDataCombDR.PartnerKey = APartnerKey; PmJobAssignmentDR = (PmJobAssignmentRow)DR; if (PmJobAssignmentDR.UnitKey != 0) { PUnitDT = PUnitAccess.LoadByPrimaryKey(PmJobAssignmentDR.UnitKey, AReadTransaction); JobAssiStaffDataCombDR.FieldKey = PmJobAssignmentDR.UnitKey; JobAssiStaffDataCombDR.FieldName = PUnitDT[0].UnitName; } else { JobAssiStaffDataCombDR.FieldKey = 0; JobAssiStaffDataCombDR.FieldName = "[None]"; } JobAssiStaffDataCombDR.Position = PmJobAssignmentDR.PositionName; JobAssiStaffDataCombDR.FromDate = PmJobAssignmentDR.FromDate; JobAssiStaffDataCombDR.ToDate = PmJobAssignmentDR.ToDate; AIndividualDataDS.JobAssignmentStaffDataCombined.Rows.Add(JobAssiStaffDataCombDR); } } } #endregion #region Church Info SummaryDR.ChurchName = StrNotAvailable; SummaryDR.ChurchAddress = StrNotAvailable; SummaryDR.ChurchPrimaryPhoneNumber = StrNotAvailable; SummaryDR.ChurchPastor = StrNotAvailable; SummaryDR.ChurchPastorsPrimaryPhoneNumber = StrNotAvailable; SummaryDR.NumberOfShownSupportingChurchPastors = 0; // Find SUPPCHURCH Relationship PartnerRelationshipDT = PPartnerRelationshipAccess.LoadUsingTemplate(new TSearchCriteria[] { new TSearchCriteria(PPartnerRelationshipTable.GetRelationKeyDBName(), APartnerKey), new TSearchCriteria(PPartnerRelationshipTable.GetRelationNameDBName(), "SUPPCHURCH") }, AReadTransaction); SummaryDR.NumberOfShownSupportingChurches = PartnerRelationshipDT.Rows.Count; if (PartnerRelationshipDT.Rows.Count > 0) { ChurchPartnerKey = PartnerRelationshipDT[0].PartnerKey; // Load Church Partner PartnerDT = PPartnerAccess.LoadByPrimaryKey(ChurchPartnerKey, AReadTransaction); if (PartnerDT.Rows.Count > 0) { PartnerDR = PartnerDT[0]; // Church Name if (PartnerDR.PartnerShortName != String.Empty) { SummaryDR.ChurchName = PartnerDR.PartnerShortName; } #region Church Address and Phone ServerCalculations.DetermineBestAddress(PartnerRelationshipDT[0].PartnerKey, out PartnerLocationDR, out LocationDR); if (LocationDR != null) { SummaryDR.ChurchAddress = Calculations.DetermineLocationString(LocationDR, Calculations.TPartnerLocationFormatEnum.plfCommaSeparated); } if (TContactDetailsAggregate.GetPrimaryPhoneNumber(PartnerRelationshipDT[0].PartnerKey, out PhoneNumber)) { SummaryDR.ChurchPrimaryPhoneNumber = PhoneNumber ?? StrNotAvailable; } else { SummaryDR.ChurchPrimaryPhoneNumber = StrNotAvailable; } #endregion #region Pastor // Find PASTOR Relationship PartnerRelationshipDT.Rows.Clear(); PartnerRelationshipDT = PPartnerRelationshipAccess.LoadUsingTemplate(new TSearchCriteria[] { new TSearchCriteria(PPartnerRelationshipTable.GetPartnerKeyDBName(), ChurchPartnerKey), new TSearchCriteria(PPartnerRelationshipTable.GetRelationNameDBName(), "PASTOR") }, AReadTransaction); SummaryDR.NumberOfShownSupportingChurchPastors = PartnerRelationshipDT.Rows.Count; if (PartnerRelationshipDT.Rows.Count > 0) { // Load PASTOR Partner PartnerDT = PPartnerAccess.LoadByPrimaryKey(PartnerRelationshipDT[0].RelationKey, AReadTransaction); if (PartnerDT.Rows.Count > 0) { PartnerDR = PartnerDT[0]; // Pastor's Name if (PartnerDR.PartnerShortName != String.Empty) { SummaryDR.ChurchPastor = PartnerDR.PartnerShortName; } #region Pastor's Phone if (TContactDetailsAggregate.GetPrimaryPhoneNumber(PartnerRelationshipDT[0].RelationKey, out PhoneNumber)) { SummaryDR.ChurchPastorsPrimaryPhoneNumber = PhoneNumber ?? StrNotAvailable; } else { SummaryDR.ChurchPastorsPrimaryPhoneNumber = StrNotAvailable; } #endregion } } #endregion } } #endregion // Add Summary DataRow to Summary DataTable SummaryDT.Rows.Add(SummaryDR); // Add Row to 'SummaryData' DataTable in Typed DataSet 'IndividualDataTDS' AIndividualDataDS.Merge(SummaryDT); }
/// Ask the user if they want to update the Gift Destination and then make the changes private void DealWithPotentialGiftDestinationUpdates(DataRowState ARowState, PmStaffDataRow AEligibleCommitmentRow, PPartnerGiftDestinationRow AGiftDestinationWhichCanBeModified, PPartnerGiftDestinationRow AGiftDestinationWhichCanBeDeactivated, List <PPartnerGiftDestinationRow>AActiveGiftDestinationsWhichCanBeEnded) { string UnitName = ""; string ActiveGiftDestinations = ""; string EndOfCommitment; bool CreateNewGiftDestination = false; TPartnerClass PartnerClass; // set end date to display to user in messagebox if (AEligibleCommitmentRow.IsEndOfCommitmentNull()) { EndOfCommitment = "'Open Ended'"; } else { EndOfCommitment = AEligibleCommitmentRow.EndOfCommitment.Value.ToShortDateString(); } // get the receiving fields short name TRemote.MPartner.Partner.ServerLookups.WebConnectors.GetPartnerShortName(AEligibleCommitmentRow.ReceivingField, out UnitName, out PartnerClass); UnitName = UnitName + " (" + AEligibleCommitmentRow.ReceivingField + ")"; // if existing active Gift Destination/s can be ended in order to add a Gift Destination for new commitment if (AActiveGiftDestinationsWhichCanBeEnded.Count > 0) { string Message = ""; // get gift destination field's short name foreach (PPartnerGiftDestinationRow Row in AActiveGiftDestinationsWhichCanBeEnded) { string ActiveGiftDestinationName = ""; TRemote.MPartner.Partner.ServerLookups.WebConnectors.GetPartnerShortName( Row.FieldKey, out ActiveGiftDestinationName, out PartnerClass); // add conjunctions if (AActiveGiftDestinationsWhichCanBeEnded.Count > 1) { if (AActiveGiftDestinationsWhichCanBeEnded.IndexOf(Row) == AActiveGiftDestinationsWhichCanBeEnded.Count - 1) { ActiveGiftDestinations += " and "; } else if (AActiveGiftDestinationsWhichCanBeEnded.IndexOf(Row) < AActiveGiftDestinationsWhichCanBeEnded.Count - 1) { ActiveGiftDestinations += ", "; } } ActiveGiftDestinations += "'" + ActiveGiftDestinationName + "' (" + Row.FieldKey + ")"; } // two different messages depending on number of gift destinations that need to be closed if (AActiveGiftDestinationsWhichCanBeEnded.Count == 1) { Message = Catalog.GetString(string.Format( "This Person's Family has an existing Gift Destination record to the field {0} that is active during the period {1} to {2}." + "{3}Would you like to shorten or deactivate this Gift Destination and make this new Commitment to " + "the field '{4}' the active Gift Destination for this period?", ActiveGiftDestinations, AEligibleCommitmentRow.StartOfCommitment.ToShortDateString(), EndOfCommitment, "\n\n", UnitName)); } else { Message = Catalog.GetString(string.Format( "This Person's Family has existing Gift Destination records to the fields {0} that are active during the period {1} to {2}." + "{3}Would you like to shorten or deactivate these Gift Destinations and make this new Commitment to " + "the field '{4}' the active Gift Destination for this period?", ActiveGiftDestinations, AEligibleCommitmentRow.StartOfCommitment.ToShortDateString(), EndOfCommitment, "\n\n", UnitName)); } // offer to end Gift Destination/s and use new commitment instead if (MessageBox.Show(Message, Catalog.GetString("Update Gift Destination"), MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { CreateNewGiftDestination = true; foreach (PPartnerGiftDestinationRow Row in AActiveGiftDestinationsWhichCanBeEnded) { if (Row.DateEffective >= AEligibleCommitmentRow.StartOfCommitment) { // deactivate future gift destinations Row.DateExpires = Row.DateEffective; } else { // shorten older gift destinations if (Row.DateEffective != AEligibleCommitmentRow.StartOfCommitment) { Row.DateExpires = AEligibleCommitmentRow.StartOfCommitment.AddDays(-1); } else { Row.DateExpires = AEligibleCommitmentRow.StartOfCommitment; } } } } } // if an existing gift destination can be updated from a modified commitment else if (AGiftDestinationWhichCanBeModified != null) { // offer to modify this Gift Destination if (MessageBox.Show(Catalog.GetString(string.Format( "This Person's Family has an existing Gift Destination record which matches a modified commitment." + "{0}Would you like to update the Gift Destination record to the field '{1}' " + "for the period {2} to {3}?", "\n\n", UnitName, AEligibleCommitmentRow.StartOfCommitment.ToShortDateString(), EndOfCommitment)), Catalog.GetString("Update Gift Destination"), MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { AGiftDestinationWhichCanBeModified.DateExpires = AEligibleCommitmentRow.EndOfCommitment; } } // if an existing gift destination can be made inactive because of a deleted commitment else if (AGiftDestinationWhichCanBeDeactivated != null) { // offer to deactivate this Gift Destination if (MessageBox.Show(Catalog.GetString(string.Format( "This Person's Family has an existing Gift Destination record which matches a deleted commitment.{0}" + "Would you like to deactivate the Gift Destination record to the field '{1}'" + "for the period {2} to {3}?", "\n\n", UnitName, AEligibleCommitmentRow.StartOfCommitment.ToShortDateString(), EndOfCommitment)), Catalog.GetString("Update Gift Destination"), MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { AGiftDestinationWhichCanBeDeactivated.DateExpires = AGiftDestinationWhichCanBeDeactivated.DateEffective; } } // if there is no active Gift Destination during dates of new commitment else if (ARowState != DataRowState.Deleted) { // offer to create new Gift Destination using new commitment if (MessageBox.Show(Catalog.GetString(string.Format( "This Person's Family does not have an active Gift Destination during the period " + "{0} to {1}.{2}Would you like to make this new Commitment to the field " + "'{3}' the active Gift Destination for this period?", AEligibleCommitmentRow.StartOfCommitment.ToShortDateString(), EndOfCommitment, "\n\n", UnitName)), Catalog.GetString("Update Gift Destination"), MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { CreateNewGiftDestination = true; } } /* create a brand new Gift Destination */ if (CreateNewGiftDestination) { if (FInspectDS.PPartnerGiftDestination == null) { FInspectDS.Merge(new PPartnerGiftDestinationTable()); } // create new Gift Destination PPartnerGiftDestinationRow NewRow = FInspectDS.PPartnerGiftDestination.NewRowTyped(true); NewRow.Key = TRemote.MPartner.Partner.WebConnectors.GetNewKeyForPartnerGiftDestination() + FNewRecords; NewRow.PartnerKey = ((PPersonRow)FInspectDS.PPerson.Rows[0]).FamilyKey; NewRow.FieldKey = AEligibleCommitmentRow.ReceivingField; NewRow.DateEffective = AEligibleCommitmentRow.StartOfCommitment; NewRow.DateExpires = AEligibleCommitmentRow.EndOfCommitment; FInspectDS.PPartnerGiftDestination.Rows.Add(NewRow); FNewRecords++; } }
private void UpdateGiftDestinationForSingleCommitment(PmStaffDataRow AEligibleCommitmentRow) { List <PPartnerGiftDestinationRow>ActiveGiftDestinationsWhichCanBeEnded = new List <PPartnerGiftDestinationRow>(); PPartnerGiftDestinationRow GiftDestinationWhichCanBeModified = null; PPartnerGiftDestinationRow GiftDestinationWhichCanBeDeactivated = null; DataRowState RowState = DataRowState.Unchanged; PmStaffDataRow OriginalCommitmentRow = null; // get the rowstate of EligibleCommitmentRow DataRow TempRow = FIndividualDataDS.PmStaffData.Rows.Find(new object[] { AEligibleCommitmentRow.SiteKey, AEligibleCommitmentRow.Key }); if (TempRow != null) { RowState = TempRow.RowState; } else { RowState = DataRowState.Deleted; } // If gift destination records already exist for this partner's family... if ((FInspectDS.PPartnerGiftDestination != null) && (FInspectDS.PPartnerGiftDestination.Rows.Count > 0)) { // Get the original record (before it was edited) if ((RowState == DataRowState.Modified) || (RowState == DataRowState.Deleted)) { OriginalCommitmentRow = (PmStaffDataRow)FOriginalCommitments.Rows.Find( new object[] { AEligibleCommitmentRow.SiteKey, AEligibleCommitmentRow.Key }); } CompareCommitmentToGiftDestinations(RowState, AEligibleCommitmentRow, OriginalCommitmentRow, ref GiftDestinationWhichCanBeModified, ref GiftDestinationWhichCanBeDeactivated, ref ActiveGiftDestinationsWhichCanBeEnded); } DealWithPotentialGiftDestinationUpdates(RowState, AEligibleCommitmentRow, GiftDestinationWhichCanBeModified, GiftDestinationWhichCanBeDeactivated, ActiveGiftDestinationsWhichCanBeEnded); }
/// <summary> /// Validates the Commitment data of a Partner. /// </summary> /// <param name="AContext">Context that describes where the data validation failed.</param> /// <param name="ARow">The <see cref="DataRow" /> which holds the the data against which the validation is run.</param> /// <param name="AVerificationResultCollection">Will be filled with any <see cref="TVerificationResult" /> items if /// data validation errors occur.</param> /// <param name="AValidationControlsDict">A <see cref="TValidationControlsDict" /> containing the Controls that /// display data that is about to be validated.</param> /// <returns>void</returns> public static void ValidateCommitmentManual(object AContext, PmStaffDataRow ARow, ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict) { DataColumn ValidationColumn; TValidationControlsData ValidationControlsData; TVerificationResult VerificationResult; // Don't validate deleted DataRows if (ARow.RowState == DataRowState.Deleted) { return; } // 'Receiving Field' must be a Partner of Class 'UNIT' and must not be 0 ValidationColumn = ARow.Table.Columns[PmStaffDataTable.ColumnReceivingFieldId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TSharedPartnerValidation_Partner.IsValidUNITPartner( ARow.ReceivingField, false, THelper.NiceValueDescription( ValidationControlsData.ValidationControlLabel) + " must be set correctly.", AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Since the validation can result in different ResultTexts we need to remove any validation result manually as a call to // AVerificationResultCollection.AddOrRemove wouldn't remove a previous validation result with a different // ResultText! AVerificationResultCollection.Remove(ValidationColumn); AVerificationResultCollection.AddAndIgnoreNullValue(VerificationResult); } // 'Home Office' must be a Partner of Class 'UNIT' ValidationColumn = ARow.Table.Columns[PmStaffDataTable.ColumnHomeOfficeId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TSharedPartnerValidation_Partner.IsValidUNITPartner(ARow.HomeOffice, false, THelper.NiceValueDescription(ValidationControlsData.ValidationControlLabel) + " must be set correctly.", AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Since the validation can result in different ResultTexts we need to remove any validation result manually as a call to // AVerificationResultCollection.AddOrRemove wouldn't remove a previous validation result with a different // ResultText! AVerificationResultCollection.Remove(ValidationColumn); AVerificationResultCollection.AddAndIgnoreNullValue(VerificationResult); } // 'Recruiting Office' must be a Partner of Class 'UNIT' ValidationColumn = ARow.Table.Columns[PmStaffDataTable.ColumnOfficeRecruitedById]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TSharedPartnerValidation_Partner.IsValidUNITPartner(ARow.OfficeRecruitedBy, false, THelper.NiceValueDescription(ValidationControlsData.ValidationControlLabel) + " must be set correctly.", AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Since the validation can result in different ResultTexts we need to remove any validation result manually as a call to // AVerificationResultCollection.AddOrRemove wouldn't remove a previous validation result with a different // ResultText! AVerificationResultCollection.Remove(ValidationColumn); AVerificationResultCollection.AddAndIgnoreNullValue(VerificationResult); } // 'End of Commitment' must be later than 'Start of Commitment' ValidationColumn = ARow.Table.Columns[PmStaffDataTable.ColumnEndOfCommitmentId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TDateChecks.FirstGreaterOrEqualThanSecondDate(ARow.EndOfCommitment, ARow.StartOfCommitment, ValidationControlsData.ValidationControlLabel, ValidationControlsData.SecondValidationControlLabel, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } // 'Status' must have a value ValidationColumn = ARow.Table.Columns[PmStaffDataTable.ColumnStatusCodeId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TStringChecks.StringMustNotBeEmpty(ARow.StatusCode, ValidationControlsData.ValidationControlLabel, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } }
private void NewRowManual(ref PmStaffDataRow ARow) { ARow.Key = Convert.ToInt32(TRemote.MCommon.WebConnectors.GetNextSequence(TSequenceNames.seq_staff_data)); ARow.PartnerKey = FMainDS.PPerson[0].PartnerKey; ARow.ReceivingField = 0; ARow.SetReceivingFieldOfficeNull(); ARow.OfficeRecruitedBy = Convert.ToInt64(TSystemDefaults.GetSystemDefault(SharedConstants.SYSDEFAULT_SITEKEY, "")); ARow.HomeOffice = Convert.ToInt64(TSystemDefaults.GetSystemDefault(SharedConstants.SYSDEFAULT_SITEKEY, "")); ARow.StartOfCommitment = DateTime.Now.Date; }
private void GetDetailDataFromControlsManual(PmStaffDataRow ARow) { //TODO THis is a workaround, where is the input of ReceivingFieldOffice? ARow.ReceivingFieldOffice = Convert.ToInt64(txtReceivingField.Text); }
/// Iterate through each gift destination and compare with commitment record. /// Determine if gift destination can be updated and how. private void CompareCommitmentToGiftDestinations(DataRowState ARowState, PmStaffDataRow AEligibleCommitmentRow, PmStaffDataRow AOriginalCommitmentRow, ref PPartnerGiftDestinationRow AGiftDestinationWhichCanBeModified, ref PPartnerGiftDestinationRow AGiftDestinationWhichCanBeDeactivated, ref List <PPartnerGiftDestinationRow>AActiveGiftDestinationsWhichCanBeEnded) { // only changes to recieving field, start data and end date can update the Gift Destination if ((ARowState == DataRowState.Modified) && (AOriginalCommitmentRow.ReceivingField == AEligibleCommitmentRow.ReceivingField) && (AOriginalCommitmentRow.StartOfCommitment == AEligibleCommitmentRow.StartOfCommitment) && (AOriginalCommitmentRow.EndOfCommitment == AEligibleCommitmentRow.EndOfCommitment)) { return; } bool Repeat = true; while (Repeat) { Repeat = false; foreach (PPartnerGiftDestinationRow CurrentRow in FInspectDS.PPartnerGiftDestination.Rows) { // if two records are the same if ((AOriginalCommitmentRow != null) && (AOriginalCommitmentRow.ReceivingField == CurrentRow.FieldKey) && (AOriginalCommitmentRow.StartOfCommitment == CurrentRow.DateEffective) && (AOriginalCommitmentRow.EndOfCommitment == CurrentRow.DateExpires) && (CurrentRow.DateEffective != CurrentRow.DateExpires)) { if ((ARowState == DataRowState.Modified) && (AOriginalCommitmentRow.StartOfCommitment == AEligibleCommitmentRow.StartOfCommitment) && (AOriginalCommitmentRow.ReceivingField == AEligibleCommitmentRow.ReceivingField)) { // if the field and start date have not been changed then we can update the Gift Destination AGiftDestinationWhichCanBeModified = CurrentRow; continue; } else if (ARowState == DataRowState.Deleted) { AGiftDestinationWhichCanBeDeactivated = CurrentRow; return; } } else if (ARowState == DataRowState.Deleted) { continue; } else if (CurrentRow.DateEffective == CurrentRow.DateExpires) { // ignore inactive Gift Destination continue; } if ((AEligibleCommitmentRow.IsEndOfCommitmentNull() && (CurrentRow.IsDateExpiresNull() || (CurrentRow.DateExpires >= AEligibleCommitmentRow.StartOfCommitment))) || !AEligibleCommitmentRow.IsEndOfCommitmentNull() && ((CurrentRow.IsDateExpiresNull() && (CurrentRow.DateEffective <= AEligibleCommitmentRow.EndOfCommitment)) || (!CurrentRow.IsDateExpiresNull() && (((CurrentRow.DateEffective >= AEligibleCommitmentRow.StartOfCommitment) && (CurrentRow.DateEffective <= AEligibleCommitmentRow.EndOfCommitment)) || (CurrentRow.DateExpires >= AEligibleCommitmentRow.StartOfCommitment) && (CurrentRow.DateExpires <= AEligibleCommitmentRow.EndOfCommitment))))) { AActiveGiftDestinationsWhichCanBeEnded.Add(CurrentRow); } } } }
private static void GenerateCommitmentRecord( XmlNode ACurrentNode, PFamilyRow AFamilyRow, PartnerEditTDS AMainDS, PersonnelTDS APersonnelDS, DataTable AFieldKeys) { DataView FamilyView = new DataView(AMainDS.PPerson); FamilyView.RowFilter = PPersonTable.GetFamilyKeyDBName() + " = " + AFamilyRow.PartnerKey.ToString(); FamilyView.Sort = PPersonTable.GetFamilyIdDBName(); PPersonRow firstPerson = (PPersonRow)FamilyView[0].Row; int FieldID = Convert.ToInt32(TXMLParser.GetAttribute(ACurrentNode, "fieldCommitment")) % AFieldKeys.Rows.Count; long FieldPartnerKey = Convert.ToInt64(AFieldKeys.Rows[FieldID].ItemArray[0]); PPartnerGiftDestinationRow giftDestination = AMainDS.PPartnerGiftDestination.NewRowTyped(); if (NextKeyForGiftDestination == -1) { NextKeyForGiftDestination = TPartnerDataReaderWebConnector.GetNewKeyForPartnerGiftDestination(); } else { NextKeyForGiftDestination++; } giftDestination.Key = NextKeyForGiftDestination; giftDestination.FieldKey = FieldPartnerKey; giftDestination.PartnerKey = AFamilyRow.PartnerKey; giftDestination.PartnerClass = MPartnerConstants.PARTNERCLASS_FAMILY; giftDestination.DateEffective = Convert.ToDateTime(TXMLParser.GetAttribute(ACurrentNode, "startDateCommitment")); PmStaffDataRow staffData = APersonnelDS.PmStaffData.NewRowTyped(); staffData.SiteKey = DomainManager.GSiteKey; staffData.Key = (APersonnelDS.PmStaffData.Count + 1) * -1; staffData.PartnerKey = firstPerson.PartnerKey; staffData.ReceivingField = FieldPartnerKey; // TODO: could add foreign nationals staffData.HomeOffice = DomainManager.GSiteKey; staffData.OfficeRecruitedBy = DomainManager.GSiteKey; staffData.StartOfCommitment = Convert.ToDateTime(TXMLParser.GetAttribute(ACurrentNode, "startDateCommitment")); int LengthCommitment = Convert.ToInt32(TXMLParser.GetAttribute(ACurrentNode, "lengthCommitment")); staffData.StatusCode = "LONG-TERMER"; if (LengthCommitment > 0) { string LengthCommitmentUnit = TXMLParser.GetAttribute(ACurrentNode, "lengthCommitmentUnit"); if (LengthCommitmentUnit == "week") { staffData.StatusCode = "SHORT-TERMER"; staffData.EndOfCommitment = staffData.StartOfCommitment.AddDays(7 * LengthCommitment); } else if (LengthCommitmentUnit == "month") { staffData.StatusCode = "SHORT-TERMER"; staffData.EndOfCommitment = staffData.StartOfCommitment.AddMonths(LengthCommitment); } else if (LengthCommitmentUnit == "year") { if (LengthCommitment < 3) { staffData.StatusCode = "WORKER"; } staffData.EndOfCommitment = staffData.StartOfCommitment.AddYears(LengthCommitment); } } APersonnelDS.PmStaffData.Rows.Add(staffData); giftDestination.DateExpires = staffData.EndOfCommitment; if (AMainDS.PPartnerGiftDestination == null) { AMainDS.PPartnerGiftDestination.Merge(new PPartnerGiftDestinationTable()); } AMainDS.PPartnerGiftDestination.Rows.Add(giftDestination); // TODO depending on start and end date of commitment, set EX-WORKER or no special type yet at all string SpecialType = MPartnerConstants.PARTNERTYPE_WORKER; if (!staffData.IsEndOfCommitmentNull() && (staffData.EndOfCommitment < DateTime.Today)) { SpecialType = MPartnerConstants.PARTNERTYPE_EX_WORKER; } if (SpecialType != string.Empty) { // create special type for family partner PPartnerTypeRow PartnerTypeRow = AMainDS.PPartnerType.NewRowTyped(); PartnerTypeRow.PartnerKey = AFamilyRow.PartnerKey; PartnerTypeRow.TypeCode = SpecialType; AMainDS.PPartnerType.Rows.Add(PartnerTypeRow); // set special type WORKER for the parents for (int countPerson = 0; countPerson < FamilyView.Count && countPerson < 2; countPerson++) { PPersonRow personRow = (PPersonRow)FamilyView[countPerson].Row; // create special type for the person partners PartnerTypeRow = AMainDS.PPartnerType.NewRowTyped(); PartnerTypeRow.PartnerKey = personRow.PartnerKey; PartnerTypeRow.TypeCode = SpecialType; AMainDS.PPartnerType.Rows.Add(PartnerTypeRow); } } }
/// <summary> /// Performs checks to determine whether a deletion of the current /// row is permissable /// </summary> /// <param name="ARowToDelete">the currently selected row to be deleted</param> /// <param name="ADeletionQuestion">can be changed to a context-sensitive deletion confirmation question</param> /// <returns>true if user is permitted and able to delete the current row</returns> private bool PreDeleteManual(PmStaffDataRow ARowToDelete, ref string ADeletionQuestion) { /*Code to execute before the delete can take place*/ ADeletionQuestion = Catalog.GetString("Are you sure you want to delete the current row?"); ADeletionQuestion += String.Format("{0}{0}({1} {2} {3},{0} {4} {5})", Environment.NewLine, lblReceivingField.Text, txtReceivingField.Text, txtReceivingField.LabelText, lblStartDate.Text, dtpStartDate.Date.Value.ToString("dd-MMM-yyyy").ToUpper()); return true; }