private void OnContactTypeChanged(Object sender, EventArgs e) { PPartnerAttributeTypeRow ContactTypeDR; TPartnerAttributeTypeValueKind PreviousValueKind = FValueKind; TPartnerAttributeTypeValueKind ValueKind; var SelectedDetailDR = GetSelectedDetailRow(); // Try to access the selected Detail Row. If the user had just deleted the Row then we must not execute any // further code in this Method. if (SelectedDetailDR == null) { return; } if ((!FSuppressOnContactTypeChangedEvent) && (cmbContactType.Text != String.Empty)) { ContactTypeDR = (PPartnerAttributeTypeRow)cmbContactType.GetSelectedItemsDataRow(); if (!FRunningInsideShowDetails) { // If the user created a new Record and changes Attribute Types: Make sure that the change in the Attribute Type is effected // in the Record immediately, and not just when the user leaves a Control that gets Validated. If this isn't done then the // 'Overall Contact Settings' ComboBoxes whose Items are based on the Rows' Attribute Types won't get updated immediately. SelectedDetailDR.AttributeType = cmbContactType.GetSelectedString(); } SelectCorrespondingCategory(ContactTypeDR); if (Enum.TryParse <TPartnerAttributeTypeValueKind>(ContactTypeDR.AttributeTypeValueKind, out ValueKind)) { FValueKind = ValueKind; switch (FValueKind) { case TPartnerAttributeTypeValueKind.CONTACTDETAIL_GENERAL: btnLaunchHyperlinkFromValue.Visible = false; txtValue.Width = 290; break; case TPartnerAttributeTypeValueKind.CONTACTDETAIL_HYPERLINK: case TPartnerAttributeTypeValueKind.CONTACTDETAIL_HYPERLINK_WITHVALUE: case TPartnerAttributeTypeValueKind.CONTACTDETAIL_EMAILADDRESS: case TPartnerAttributeTypeValueKind.CONTACTDETAIL_SKYPEID: btnLaunchHyperlinkFromValue.Visible = true; txtValue.Width = 256; break; default: btnLaunchHyperlinkFromValue.Visible = false; txtValue.Width = 290; throw new Exception("Invalid value for TPartnerAttributeTypeValueKind"); } } else { // Fallback! FValueKind = TPartnerAttributeTypeValueKind.CONTACTDETAIL_GENERAL; } UpdateValueManual(); if (!FRunningInsideShowDetails) { if (PreviousValueKind != FValueKind) { if (GetSelectedDetailRow().Primary) { GetSelectedDetailRow().Primary = false; UpdateEmailComboItems(cmbPrimaryEMail, true); UpdatePhoneComboItems(cmbPrimaryPhoneForContacting); if (PreviousValueKind == TPartnerAttributeTypeValueKind.CONTACTDETAIL_EMAILADDRESS) { if (!FPrimaryEmailAutoChosen) { MessageBox.Show(Catalog.GetString( "You have changed the Contact Type and the Contact Detail that was an E-Mail Address is no longer one.\r\n" + "As a result, this Contact Detail can no longer be the Primary E-Mail Address! It has therefore been removed from the Primary E-Mail choices."), Catalog.GetString("No Longer Primary E-Mail"), MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { FPrimaryEmailAutoChosen = false; } } else { if (!FPrimaryPhoneAutoChosen) { MessageBox.Show(StrPhoneTypeCanNoLongerBePrimary, StrPhoneTypeCanNoLongerBePrimaryTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { FPrimaryPhoneAutoChosen = false; } } } else { UpdateSystemCategoryOvrlContSettgsCombosRecords(); UpdateEmailComboItemsOfAllEmailCombos(true); UpdatePhoneComboItemsOfAllPhoneCombos(); } } else { // This might seem unnecessary as the 'PreviousValueKind' and 'FValueKind' are the same - // However, it isn't, as 'Fax Numbers' are to be excluded from any Phone ComboBox but // if a user changes between 'Phone' and 'Fax' there is no difference between 'PreviousValueKind' // and 'FValueKind' and yet we need to update the Combo! UpdatePhoneComboItemsOfAllPhoneCombos(); // In case the user had first created a 'Phone' or 'Mobile Phone' record and set it to be Primary, // but then changes his/her mind to make it a 'Fax' record: remove the Primary flag! if (((GetSelectedDetailRow().Primary)) && (PreviousValueKind == TPartnerAttributeTypeValueKind.CONTACTDETAIL_GENERAL) && (!RowHasPhoneAttributeType(SelectedDetailDR))) { SelectedDetailDR.Primary = false; MessageBox.Show(StrPhoneTypeCanNoLongerBePrimary, StrPhoneTypeCanNoLongerBePrimaryTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } } }
/// <summary> /// Validates the Partner Edit screens' Contact Details Tab 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> /// <param name="AValueKind">The PPartnerAttributeType.AttributeValueKind of the DataRow passed in in <paramref name="ARow"/>.</param> public static void ValidateContactDetailsManual(object AContext, PPartnerAttributeRow ARow, ref TVerificationResultCollection AVerificationResultCollection, TValidationControlsDict AValidationControlsDict, TPartnerAttributeTypeValueKind AValueKind) { DataColumn ValidationColumn; TValidationControlsData ValidationControlsData; TVerificationResult VerificationResult = null; // Don't validate deleted DataRows if (ARow.RowState == DataRowState.Deleted) { return; } // 'Value' must not be null ValidationColumn = ARow.Table.Columns[PPartnerAttributeTable.ColumnValueId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TGeneralChecks.ValueMustNotBeNullOrEmptyString(ARow.Value, ValidationControlsData.ValidationControlLabel, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } // If this record is about an E-Mail Contact Detail... if (AValueKind == TPartnerAttributeTypeValueKind.CONTACTDETAIL_EMAILADDRESS) { // ...then the E-mail Address must be in a correct format ValidationColumn = ARow.Table.Columns[PPartnerAttributeTable.ColumnValueId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = TStringChecks.ValidateEmail(ARow.Value, true, AContext, ValidationColumn, ValidationControlsData.ValidationControl); // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } } // 'No Longer Current From Date' must not be a future date if the 'Current' Flag is set to false ValidationColumn = ARow.Table.Columns[PPartnerAttributeTable.ColumnNoLongerCurrentFromId]; if (AValidationControlsDict.TryGetValue(ValidationColumn, out ValidationControlsData)) { VerificationResult = null; if (!ARow.Current) { VerificationResult = TDateChecks.IsCurrentOrPastDate(ARow.NoLongerCurrentFrom, ValidationControlsData.ValidationControlLabel, AContext, ValidationColumn, ValidationControlsData.ValidationControl); } // Handle addition to/removal from TVerificationResultCollection AVerificationResultCollection.Auto_Add_Or_AddOrRemove(AContext, VerificationResult, ValidationColumn); } }