Exemple #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Replace comma with correct delimiter in MultiValueDropDownBox. Translate full names
        /// of persons into strings acceptable to show in UI (use "code" instead of Full Name
        /// when available).
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void HandleBinderTranslateBoundValueBeingRetrieved(object sender,
                                                                   TranslateBoundValueBeingRetrievedArgs args)
        {
            if (!(args.BoundControl is MultiValueDropDownBox))
            {
                return;
            }

            if (args.ValueFromFile.Contains(","))
            {
                args.TranslatedValue = args.ValueFromFile.Replace(",", FieldInstance.kDefaultMultiValueDelimiter.ToString(CultureInfo.InvariantCulture));
            }

            if (args.BoundControl == _participants)
            {
                var val = args.TranslatedValue ?? args.ValueFromFile;
                if (!string.IsNullOrEmpty(val))
                {
                    var participantNames = FieldInstance.GetMultipleValuesFromText(val).ToArray();
                    for (int index = 0; index < participantNames.Length; index++)
                    {
                        participantNames[index] = _personInformant.GetUiIdByName(participantNames[index]);
                    }

                    args.TranslatedValue = FieldInstance.GetTextFromMultipleValues(participantNames);
                }
            }
        }
Exemple #2
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Replace comma with correct delimiter in MultiValueDropDownBox. Translate full names
 /// of persons into strings acceptable to show in UI (use "code" instead of Full Name
 /// when available).
 /// </summary>
 /// ------------------------------------------------------------------------------------
 private void HandleBinderTranslateBoundValueBeingRetrieved(object sender,
                                                            TranslateBoundValueBeingRetrievedArgs args)
 {
     if (args.BoundControl is MultiValueDropDownBox)
     {
         if (args.ValueFromFile.Contains(","))
         {
             args.TranslatedValue = args.ValueFromFile.Replace(",",
                                                               FieldInstance.kDefaultMultiValueDelimiter.ToString(CultureInfo.InvariantCulture));
         }
     }
     else if (args.BoundControl == _participants)
     {
         args.TranslatedValue = GetParticipantsWithRolesFromContributions();
     }
 }
Exemple #3
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Instead of letting the binding helper set the gender combo box value from the
 /// value in the file (which will be the English text for male or female), we'll
 /// intercept the process since the text in the gender combo box may have been
 /// localized to non English text.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 private void HandleBinderTranslateBoundValueBeingRetrieved(object sender,
                                                            TranslateBoundValueBeingRetrievedArgs args)
 {
     if (args.BoundControl == _gender)
     {
         // Because of a former bug (SP-847), gender metadata was saved as localized
         // string instead of English, so when retrieving, recognize those versions of the
         // values for "Male" as well.
         string valueFromFile = args.ValueFromFile.Normalize(NormalizationForm.FormD);
         _gender.SelectedIndex = (valueFromFile == "Male" ||
                                  valueFromFile == "Macho" ||
                                  valueFromFile == "Mâle".Normalize(NormalizationForm.FormD) ||
                                  valueFromFile == "Мужской".Normalize(NormalizationForm.FormD) ||
                                  valueFromFile == "男性".Normalize(NormalizationForm.FormD) ? 0 : 1);
         args.Handled = true;
     }
 }
Exemple #4
0
        /// ------------------------------------------------------------------------------------
        private void UpdateControlValueFromField(Control ctrl)
        {
            var key         = _makeIdFromControlName(ctrl);
            var stringValue = ComponentFile.GetStringValue(key, string.Empty);

            try
            {
                if (TranslateBoundValueBeingRetrieved != null)
                {
                    var args = new TranslateBoundValueBeingRetrievedArgs(ctrl, stringValue);
                    TranslateBoundValueBeingRetrieved(this, args);
                    if (args.Handled)
                    {
                        return;
                    }

                    stringValue = (args.TranslatedValue ?? stringValue);
                }

                var box = ctrl as CheckBox;
                if (box != null)
                {
                    bool isChecked;
                    bool.TryParse(stringValue, out isChecked);
                    box.Checked = isChecked;
                }
                else
                {
                    var dtp = ctrl as DatePicker;
                    if (dtp != null)
                    {
                        ctrl.Text = stringValue;
                    }
                    else
                    {
                        ctrl.Text = stringValue;
                    }
                }
            }
            catch (Exception error)
            {
                if (error is AmbiguousDateException)
                {
                    var notesField = ComponentFile.MetaDataFieldValues.FirstOrDefault(f => f.FieldId == "notes");
                    if (notesField == null)
                    {
                        notesField = new FieldInstance("notes", "");
                        ComponentFile.MetaDataFieldValues.Add(notesField);
                    }

                    notesField.Value = notesField.ValueAsString + Environment.NewLine +
                                       String.Format(LocalizationManager.GetString("CommonToMultipleViews.BindingHelper.AmbiguousDateNote",
                                                                                   "***This record had an ambiguous {0}, produced by a bug in an old version of SayMore. The date was \"{1}\". " +
                                                                                   "SayMore has attempted to interpret the date, but might have swapped the day and month. " +
                                                                                   "Please accept our apologies for this error. After you have fixed the date or confirmed that it is correct, please delete this message.",
                                                                                   "Text appended to the note for an element with an ambigous date field value"), key, error.Message);

                    //this will save that new value, and this note
                    HandleValidatingControl(ctrl, new CancelEventArgs());
                    return;
                }

                SIL.Reporting.ErrorReport.NotifyUserOfProblem(
                    new SIL.Reporting.ShowOncePerSessionBasedOnExactMessagePolicy(), error,
                    "SayMore had a problem displaying the {0}, which had a value of {1}." + Environment.NewLine +
                    "Message " + error.Message + Environment.NewLine +
                    "You should report this problem to the developers by clicking 'Details' below.",
                    key, stringValue);
            }
        }