object IEditorDataFilter.Convert(EditorDataFilterConvertArgs args) { switch (args.Direction) { case ConversionDirection.EditorToOwner: case ConversionDirection.EditorToDisplay: args.Handled = true; var state = (CheckState)args.Value; switch (state) { case CheckState.Checked: return("Yes"); case CheckState.Unchecked: return("No"); case CheckState.Indeterminate: return(String.Empty); } break; case ConversionDirection.OwnerToEditor: case ConversionDirection.DisplayToEditor: args.Handled = true; if (args.Value.ToString().ToLower() == "true") { return(CheckState.Checked); } else if (args.Value.ToString().ToLower() == "false") { return(CheckState.Unchecked); } else { return(CheckState.Indeterminate); } } throw new Exception("Invalid value passed into CheckEditorDataFilter.Convert()"); }
public object Convert(EditorDataFilterConvertArgs args) { switch (args.Direction) { case ConversionDirection.EditorToDisplay: args.Handled = true; return args.Value != null ? DateTimeFormatInfo.CurrentInfo.GetMonthName((int)args.Value) : string.Empty; case ConversionDirection.DisplayToEditor: args.Handled = true; if (args.Value != null) { string monthName = args.Value.ToString(); System.Windows.Forms.MessageBox.Show("monthName: " + monthName); if (string.IsNullOrEmpty(monthName)) return null; var monthNames = DateTimeFormatInfo.CurrentInfo.MonthNames; for (var i = 0; i < monthNames.Length; i++) { if (monthNames[i] == monthName) return i++; } } else return null; break; default: return null; } return null; }
/// <summary> /// Converts data between Display (user), Editor and Owner (data source). /// </summary> /// <param name="conversionArgs">Input arguments.</param> /// <returns>Converted data.</returns> public object Convert(EditorDataFilterConvertArgs conversionArgs) { try { switch (conversionArgs.Direction) { case ConversionDirection.EditorToOwner: { // only convert non null values if (conversionArgs.Value != null && !(conversionArgs.Value is DBNull) && conversionArgs.Value is IConvertible) { // get the value from the editor as a decimal var value = System.Convert.ToDecimal(conversionArgs.Value); // let the editor know we handled the conversion conversionArgs.Handled = true; // divide by 100 so we store values from // 0 to 1 in the database // e.g. if the user entered 50 into the // editor, then return .50 to the return value / 100m; } break; } case ConversionDirection.OwnerToEditor: { // only convert non null values if (conversionArgs.Value != null && !(conversionArgs.Value is DBNull) && conversionArgs.Value is IConvertible) { // get the decimal value that the owner has var value = System.Convert.ToDecimal(conversionArgs.Value); // let the editor know we handled the conversion conversionArgs.Handled = true; // multiply by 100. // e.g. if the db has .10 then the user will see and edit 10 return value * 100; } break; } case ConversionDirection.EditorToDisplay: { // only convert non null values if (conversionArgs.Value != null && !(conversionArgs.Value is DBNull) && conversionArgs.Value is IConvertible) { // get the value from the editor as a decimal var value = System.Convert.ToDecimal(conversionArgs.Value); // let the editor know we handled the conversion conversionArgs.Handled = true; // divide by 100 so we store values from // 0 to 1 in the database // e.g. if the user entered 50 into the // editor, then return .50 to the return (value * 100m) + "%"; } break; } } } catch (FormatException ex) { _log.DebugFormat("Errore nella conversione di una percentuale - VALORE DECIMAL NON VALIDO - {0} - value:{1} - azienda:{2}", ex, Gipasoft.Library.Utility.GetMethodDescription(), conversionArgs.Value, Security.Login.Instance.CurrentLogin().Azienda); } catch (Exception ex) { _log.ErrorFormat("Errore nella conversione di una percentuale - {0} - value:{1} - azienda:{2}", ex, Gipasoft.Library.Utility.GetMethodDescription(), conversionArgs.Value, Security.Login.Instance.CurrentLogin().Azienda); } // by default return null. as long as we don't indicate // that we handled the conversion (by setting conversionArgs.Handled // to true), the result will be ignored. return null; }