Ejemplo n.º 1
0
        /// <summary>
        /// Convert Min and Max values to string if step type is set to one of the DateTime type
        /// </summary>
        /// <param name="context">Descriptor context.</param>
        /// <param name="culture">Culture information.</param>
        /// <param name="value">Value to convert.</param>
        /// <param name="destinationType">Convertion destination type.</param>
        /// <returns>Converted object.</returns>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if (context != null && context.Instance != null && context.Instance is Axis)
            {
                Axis axis = (Axis)context.Instance;
                if (destinationType == typeof(string))
                {
                    string strValue = DoubleDateNanValueConverter.ConvertDateTimeToString(
                        (double)value,
                        axis.GetAxisValuesType(),
                        axis.InternalIntervalType);

                    if (strValue != null)
                    {
                        return(strValue);
                    }
                }
            }
            return(base.ConvertTo(context, culture, value, destinationType));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Convert Min and Max values from string if step type is set to one of the DateTime type
        /// </summary>
        /// <param name="context">Descriptor context.</param>
        /// <param name="culture">Culture information.</param>
        /// <param name="value">Value to convert from.</param>
        /// <returns>Converted object.</returns>
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            object result          = null;
            bool   convertFromDate = false;
            string stringValue     = value as string;

            // If context interface provided check if we are dealing with DateTime values
            if (context != null && context.Instance != null && context.Instance is Axis)
            {
                Axis axis = (Axis)context.Instance;

                if (stringValue != null)
                {
                    if (axis.InternalIntervalType == DateTimeIntervalType.Auto)
                    {
                        if (axis.GetAxisValuesType() == ChartValueType.DateTime ||
                            axis.GetAxisValuesType() == ChartValueType.Date ||
                            axis.GetAxisValuesType() == ChartValueType.Time ||
                            axis.GetAxisValuesType() == ChartValueType.DateTimeOffset)
                        {
                            convertFromDate = true;
                        }
                    }
                    else
                    {
                        if (axis.InternalIntervalType != DateTimeIntervalType.Number)
                        {
                            convertFromDate = true;
                        }
                    }
                }
            }

            // Try to convert from double string
            try
            {
                result = base.ConvertFrom(context, culture, value);
            }
            catch (ArgumentException)
            {
                result = null;
            }
            catch (NotSupportedException)
            {
                result = null;
            }

            // Try to convert from date/time string
            if (stringValue != null && (convertFromDate || result == null))
            {
                DateTime valueAsDate;
                bool     parseSucceed = DateTime.TryParse(stringValue, CultureInfo.CurrentCulture, DateTimeStyles.None, out valueAsDate);

                if (parseSucceed)
                {
                    return(valueAsDate.ToOADate());
                }
            }

            // Call base converter
            return(base.ConvertFrom(context, culture, value));
        }