private void ValidateDataDetailsManual(AFrequencyRow ARow) { TVerificationResultCollection VerificationResultCollection = FPetraUtilsObject.VerificationResultCollection; TSharedValidation_CacheableDataTables.ValidateFrequencySetupManual(this, ARow, ref VerificationResultCollection, FPetraUtilsObject.ValidationControlsDict); }
private void NewRowManual(ref AFrequencyRow ARow) { string newName = Catalog.GetString("NEWCODE"); Int32 countNewDetail = 0; if (FMainDS.AFrequency.Rows.Find(new object[] { newName }) != null) { while (FMainDS.AFrequency.Rows.Find(new object[] { newName + countNewDetail.ToString() }) != null) { countNewDetail++; } newName += countNewDetail.ToString(); } ARow.FrequencyCode = newName; }
public void TestDeleteFamily() { DataSet ResponseDS = new PartnerEditTDS(); TVerificationResultCollection VerificationResult; String TextMessage; Boolean CanDeletePartner; PPartnerRow FamilyPartnerRow; PFamilyRow FamilyRow; PPersonRow PersonRow; TSubmitChangesResult result; Int64 PartnerKey; TPartnerEditUIConnector connector = new TPartnerEditUIConnector(); PartnerEditTDS MainDS = new PartnerEditTDS(); FamilyPartnerRow = TCreateTestPartnerData.CreateNewFamilyPartner(MainDS); result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult); Assert.AreEqual(TSubmitChangesResult.scrOK, result, "Create family record"); // check if Family partner can be deleted (still needs to be possible at this point) CanDeletePartner = TPartnerWebConnector.CanPartnerBeDeleted(FamilyPartnerRow.PartnerKey, out TextMessage); if (TextMessage.Length > 0) { TLogging.Log(TextMessage); } Assert.IsTrue(CanDeletePartner); // add a person to the family which means the family is not allowed to be deleted any longer FamilyRow = (PFamilyRow)MainDS.PFamily.Rows[0]; FamilyRow.FamilyMembers = true; TCreateTestPartnerData.CreateNewLocation(FamilyPartnerRow.PartnerKey, MainDS); result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult); Assert.AreEqual(TSubmitChangesResult.scrOK, result, "create new location"); PartnerEditTDS PersonDS = new PartnerEditTDS(); PersonRow = TCreateTestPartnerData.CreateNewPerson(PersonDS, FamilyPartnerRow.PartnerKey, MainDS.PLocation[0].LocationKey, "Adam", "Mr", 0); PersonRow.FamilyKey = FamilyPartnerRow.PartnerKey; result = connector.SubmitChanges(ref PersonDS, ref ResponseDS, out VerificationResult); Assert.AreEqual(TSubmitChangesResult.scrOK, result, "create person record"); CanDeletePartner = TPartnerWebConnector.CanPartnerBeDeleted(FamilyPartnerRow.PartnerKey, out TextMessage); if (TextMessage.Length > 0) { TLogging.Log(TextMessage); } Assert.IsTrue(!CanDeletePartner); // create new family and create subscription given as gift from this family: not allowed to be deleted FamilyPartnerRow = TCreateTestPartnerData.CreateNewFamilyPartner(MainDS); PPublicationTable PublicationTable = PPublicationAccess.LoadByPrimaryKey("TESTPUBLICATION", DBAccess.GDBAccessObj.Transaction); if (PublicationTable.Count == 0) { // first check if frequency "Annual" exists and if not then create it if (!AFrequencyAccess.Exists("Annual", DBAccess.GDBAccessObj.Transaction)) { // set up details (e.g. bank account) for this Bank so deletion is not allowed AFrequencyTable FrequencyTable = new AFrequencyTable(); AFrequencyRow FrequencyRow = FrequencyTable.NewRowTyped(); FrequencyRow.FrequencyCode = "Annual"; FrequencyRow.FrequencyDescription = "Annual Frequency"; FrequencyTable.Rows.Add(FrequencyRow); AFrequencyAccess.SubmitChanges(FrequencyTable, DBAccess.GDBAccessObj.Transaction); } // now add the publication "TESTPUBLICATION" PPublicationRow PublicationRow = PublicationTable.NewRowTyped(); PublicationRow.PublicationCode = "TESTPUBLICATION"; PublicationRow.FrequencyCode = "Annual"; PublicationTable.Rows.Add(PublicationRow); PPublicationAccess.SubmitChanges(PublicationTable, DBAccess.GDBAccessObj.Transaction); } // make sure that "reason subscription given" exists if (!PReasonSubscriptionGivenAccess.Exists("FREE", DBAccess.GDBAccessObj.Transaction)) { // set up details (e.g. bank account) for this Bank so deletion is not allowed PReasonSubscriptionGivenTable ReasonTable = new PReasonSubscriptionGivenTable(); PReasonSubscriptionGivenRow ReasonRow = ReasonTable.NewRowTyped(); ReasonRow.Code = "FREE"; ReasonRow.Description = "Free Subscription"; ReasonTable.Rows.Add(ReasonRow); PReasonSubscriptionGivenAccess.SubmitChanges(ReasonTable, DBAccess.GDBAccessObj.Transaction); } // now add the publication "TESTPUBLICATION" to the first family record and indicate it was a gift from newly created family record PSubscriptionRow SubscriptionRow = MainDS.PSubscription.NewRowTyped(); SubscriptionRow.PublicationCode = "TESTPUBLICATION"; SubscriptionRow.PartnerKey = FamilyRow.PartnerKey; // link subscription with original family SubscriptionRow.GiftFromKey = FamilyPartnerRow.PartnerKey; // indicate that subscription is a gift from newly created family SubscriptionRow.ReasonSubsGivenCode = "FREE"; MainDS.PSubscription.Rows.Add(SubscriptionRow); result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult); Assert.AreEqual(TSubmitChangesResult.scrOK, result, "add publication to family record"); // this should now not be allowed since partner record has a subscription linked to it CanDeletePartner = TPartnerWebConnector.CanPartnerBeDeleted(FamilyPartnerRow.PartnerKey, out TextMessage); if (TextMessage.Length > 0) { TLogging.Log(TextMessage); } Assert.IsTrue(!CanDeletePartner); // now test actual deletion of Family partner FamilyPartnerRow = TCreateTestPartnerData.CreateNewFamilyPartner(MainDS); PartnerKey = FamilyPartnerRow.PartnerKey; result = connector.SubmitChanges(ref MainDS, ref ResponseDS, out VerificationResult); Assert.AreEqual(TSubmitChangesResult.scrOK, result, "create family record"); // 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> /// Validates the Setup Frequency screen data. /// </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> public static void ValidateFrequencySetupManual(object AContext, AFrequencyRow ARow, ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict) { DataColumn ValidationColumn; TValidationControlsData ValidationControlsData; TVerificationResult VerificationResult; bool bFoundNegativeValue = false; // Don't validate deleted DataRows if (ARow.RowState == DataRowState.Deleted) { return; } // 'NumberOfYears' cannot be negative ValidationColumn = ARow.Table.Columns[AFrequencyTable.ColumnNumberOfYearsId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TNumericalChecks.IsPositiveOrZeroInteger(ARow.NumberOfYears, ValidationControlsData.ValidationControlLabel, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition/removal to/from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); bFoundNegativeValue |= (VerificationResult != null); } // 'NumberOfMonths' cannot be negative ValidationColumn = ARow.Table.Columns[AFrequencyTable.ColumnNumberOfMonthsId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TNumericalChecks.IsPositiveOrZeroInteger(ARow.NumberOfMonths, ValidationControlsData.ValidationControlLabel, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition/removal to/from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); bFoundNegativeValue |= (VerificationResult != null); } // 'NumberOfDays' cannot be negative ValidationColumn = ARow.Table.Columns[AFrequencyTable.ColumnNumberOfDaysId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TNumericalChecks.IsPositiveOrZeroInteger(ARow.NumberOfDays, ValidationControlsData.ValidationControlLabel, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition/removal to/from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); bFoundNegativeValue |= (VerificationResult != null); } // 'NumberOfHours' cannot be negative ValidationColumn = ARow.Table.Columns[AFrequencyTable.ColumnNumberOfHoursId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TNumericalChecks.IsPositiveOrZeroInteger(ARow.NumberOfHours, ValidationControlsData.ValidationControlLabel, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition/removal to/from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); bFoundNegativeValue |= (VerificationResult != null); } // 'NumberOfMinutes' cannot be negative ValidationColumn = ARow.Table.Columns[AFrequencyTable.ColumnNumberOfMinutesId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TNumericalChecks.IsPositiveOrZeroInteger(ARow.NumberOfMinutes, ValidationControlsData.ValidationControlLabel, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition/removal to/from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); bFoundNegativeValue |= (VerificationResult != null); } // Finally, having checked that no single box is negative, at least one of the boxes (any box) must be a positive number // So our test is going to fail if the sum of the boxes is 0 and we did not get any negatives // We pick the first box and invalidate that, because this is only one error despite all boxes being 0. // This does mean that the tooltip will only pop up if the focus is associated with this one box, but the validation will still work. // It will not be possible to leave this record. ValidationColumn = ARow.Table.Columns[AFrequencyTable.ColumnNumberOfYearsId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { // Check for success as a positive integer in TotalOfBoxes // If we had a negative number anywhere we always make this test pass, because that is a more serious error int TotalOfBoxes = ARow.NumberOfYears + ARow.NumberOfMonths + ARow.NumberOfDays + ARow.NumberOfHours + ARow.NumberOfMinutes; if (bFoundNegativeValue) { TotalOfBoxes = 1; } VerificationResult = TNumericalChecks.IsPositiveInteger(TotalOfBoxes, ValidationControlsData.ValidationControlLabel, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition/removal to/from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); if (VerificationResult != null) { // Over-ride the message as follows... string msg = String.Format(Catalog.GetString( "A quantity of time must be defined for the '{0}' frequency."), ARow.FrequencyDescription); VerificationResult.OverrideResultText(msg); } } }