/// ------------------------------------------------------------------------------------ /// <summary> /// When the binding helper gets to writing field values to the metadata file, we need /// to make sure the English values for male and female are written to the file, not /// the localized values for male and female (which is what is in the gender combo box). /// </summary> /// ------------------------------------------------------------------------------------ private void HandleBinderTranslateBoundValueBeingSaved(object sender, TranslateBoundValueBeingSavedArgs args) { if (args.BoundControl == _gender) { args.NewValue = (_gender.SelectedIndex == 0 ? "Male" : "Female"); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// When the binding helper gets to writing field values to the metadata file, we need /// to make sure the English values for male and female are written to the file, not /// the localized values for male and female (which is what is in the gender combo box). /// </summary> /// ------------------------------------------------------------------------------------ private void HandleBinderTranslateBoundValueBeingSaved(object sender, TranslateBoundValueBeingSavedArgs args) { if (args.BoundControl == _participants) { var participantNames = FieldInstance.GetMultipleValuesFromText(_participants.Text).ToArray(); for (int index = 0; index < participantNames.Length; index++) { var person = _personInformant.GetPersonByNameOrCode(participantNames[index]); if (person != null) { participantNames[index] = person.Id; } } args.NewValue = FieldInstance.GetTextFromMultipleValues(participantNames); } }
/// ------------------------------------------------------------------------------------ private void HandleValidatingControl(object sender, CancelEventArgs e) { var ctrl = (Control)sender; var key = _makeIdFromControlName(ctrl); var box = ctrl as CheckBox; var combo = ctrl as ComboBox; string newValue = null; var gotNewValueFromDelegate = false; if (TranslateBoundValueBeingSaved != null) { var args = new TranslateBoundValueBeingSavedArgs(ctrl); TranslateBoundValueBeingSaved(this, args); newValue = args.NewValue; gotNewValueFromDelegate = (newValue != null); } if (!gotNewValueFromDelegate) { if (box != null) { newValue = box.Checked ? "true" : "false"; } else if ((combo != null) && (combo.SelectedItem != null)) { newValue = combo.SelectedValue == null?combo.SelectedItem.ToString() : combo.SelectedValue.ToString(); } else if (key != "date") { newValue = ctrl.Text.Trim(); } else { //NB: we're doing a plain old-fashioned "parse" here because the editor is showing // it in the user's local culture, that's fine. But internally, we want to deal // only in DateTimes where possible, and in ISO8601 where strings are necessary. if (ctrl is DatePicker) { newValue = ((DatePicker)ctrl).GetISO8601DateValueOrNull(); } else { newValue = DateTime.Parse(newValue, CultureInfo.CurrentCulture).ToISO8601TimeFormatDateOnlyString(); } } } // Don't bother doing anything if the old value is the same as the new value. var oldValue = ComponentFile.GetStringValue(key, null); if (oldValue != null && oldValue == newValue) { return; } string failureMessage = null; ComponentFile.MetadataValueChanged -= HandleValueChangedOutsideBinder; // SP-742: Save changes before renaming the file ("Could not find a part of the path 'C:\...\NameOf.session'.") if (_componentFileIdControl == ctrl) { SaveNow(); } newValue = (_componentFileIdControl == ctrl ? ComponentFile.TryChangeChangeId(newValue, out failureMessage) : ComponentFile.SetStringValue(key, newValue)); ComponentFile.MetadataValueChanged += HandleValueChangedOutsideBinder; if (!gotNewValueFromDelegate && key != "date" && box == null) { ctrl.Text = newValue; } if (failureMessage != null) { SIL.Reporting.ErrorReport.NotifyUserOfProblem(failureMessage); } //enchance: don't save so often, leave it to some higher level if (_componentFileIdControl != ctrl) { SaveNow(); } }