Пример #1
0
        /// <summary>
        /// Fired when converting an object to the value specified. Called from method ObjectToValue and IsValidObject
        /// </summary>
        /// <param name="e">The <see cref="ConversionModel.ConvertingObjectEventArgs"/> instance containing the event data.</param>
        /// <exception cref="InvalidConversionException">Thrown when unable to convert object</exception>
        protected virtual void OnConvertingObjectToValue(ConvertingObjectEventArgs e)
        {
            if (convertingObjectToValueHandler != null)
            {
                convertingObjectToValueHandler(this, e);
            }
            if (e.ConvertingStatus == ConvertingStatus.Error)
            {
                throw new InvalidConversionException("Invalid conversion");
            }
            else if (e.ConvertingStatus == ConvertingStatus.Completed)
            {
                return;
            }

            if (e.Value == null)
            {
            }
            else if (e.Value is string) //è importante fare prima il caso stringa per gestire correttamente il null
            {
                string tmp = (string)e.Value;
                if (IsNullString(tmp))
                {
                    e.Value = null;
                }
                else if (e.DestinationType != typeof(string) && IsStringConversionSupported() == false)
                {
                    throw new InvalidConversionException("String conversion not supported for this type of Validator.");
                }
            }
            else if (e.DestinationType.IsAssignableFrom(e.Value.GetType()))
            {
            }
        }
Пример #2
0
        /// <summary>
        /// Convert an object according to the current ValueType of the validator
        /// </summary>
        /// <param name="p_Object"></param>
        /// <returns></returns>
        public object ObjectToValue(object p_Object)
        {
            Type destinationType = ValueType;

            if (destinationType == null && p_Object != null)
            {
                destinationType = p_Object.GetType();
            }

            ConvertingObjectEventArgs l_Converting = new ConvertingObjectEventArgs(p_Object, destinationType);

            OnConvertingObjectToValue(l_Converting);
            if (l_Converting.ConvertingStatus == ConvertingStatus.Error)
            {
                throw new ConversionErrorException(ValueTypeName, ObjectToStringForError(l_Converting.Value));
            }

            if (IsValidValue(l_Converting.Value))
            {
                return(l_Converting.Value);
            }
            else
            {
                throw new ConversionErrorException(ValueTypeName, ObjectToStringForError(l_Converting.Value));
            }
        }
Пример #3
0
        private void p_Validator_ConvertingObjectToValue(object sender, ConvertingObjectEventArgs e)
        {
            if (mSpecialList != null && e.Value != null && e.Value.GetType() == SpecialType)
            {
                if (m_ValueList == null)
                {
                    throw new ApplicationException("ValueList cannot be null");
                }

                //Verifico se fa parte della lista di valori
                int index = m_ValueList.IndexOf(e.Value);
                if (index >= 0)
                {
                    e.Value            = m_ValueList[index];
                    e.ConvertingStatus = ConvertingStatus.Completed;
                }
                else
                {
                    //Verifico se fa parte della lista di oggetti, in questo caso restituisco il valore corrispondente
                    index = mSpecialList.IndexOf(e.Value);
                    if (index >= 0)
                    {
                        e.Value            = m_ValueList[index];
                        e.ConvertingStatus = ConvertingStatus.Completed;
                    }
                    else if (m_bThrowErrorIfNotFound)
                    {
                        e.ConvertingStatus = ConvertingStatus.Error;
                    }
                }
            }
        }
Пример #4
0
        private void p_Validator_ConvertingValueToObject(object sender, ConvertingObjectEventArgs e)
        {
            if (mSpecialList != null && e.DestinationType == SpecialType)
            {
                if (m_ValueList == null)
                {
                    throw new ApplicationException("ValueList cannot be null");
                }

                //Verifico se il valore è presente nella list, in questo caso restituisco l'oggetto associato
                int l_Index = m_ValueList.IndexOf(e.Value);
                if (l_Index >= 0)
                {
                    e.Value            = mSpecialList[l_Index];
                    e.ConvertingStatus = ConvertingStatus.Completed;
                }
                else
                {
                    if (m_bThrowErrorIfNotFound)
                    {
                        e.ConvertingStatus = ConvertingStatus.Error;
                    }
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Fired when converting an object to the value specified. Called from method ObjectToValue and IsValidObject
        /// </summary>
        /// <param name="e">The <see cref="Fr.Medit.MedDataGrid.ConversionModel.ConvertingObjectEventArgs"/> instance containing the event data.</param>
        protected virtual void OnConvertingValueToObject(ConvertingObjectEventArgs e)
        {
            if (convertingValueToObjectHandler != null)
            {
                convertingValueToObjectHandler(this, e);
            }
            if (e.ConvertingStatus == ConvertingStatus.Error)
            {
                throw new MEDDataGridException("Invalid conversion");
            }
            else if (e.ConvertingStatus == ConvertingStatus.Completed)
            {
                return;
            }

            if (e.Value == null)
            {
            }
            else if (e.DestinationType.IsAssignableFrom(e.Value.GetType()))
            {
            }
            else if (e.DestinationType == typeof(string))
            {
                if (IsStringConversionSupported() == false)
                {
                    throw new MEDDataGridException("String conversion not supported for this type of Validator.");
                }
                e.Value = e.Value.ToString();
            }
        }
Пример #6
0
        /// <summary>
        /// Fired when converting a object to the value specified. Called from method ObjectToValue and IsValidObject
        /// </summary>
        /// <param name="e"></param>
        protected override void OnConvertingValueToObject(ConvertingObjectEventArgs e)
        {
            base.OnConvertingValueToObject(e);

            if (e.ConvertingStatus == ConvertingStatus.Error)
            {
                throw new ApplicationException("Invalid conversion");
            }
            else if (e.ConvertingStatus == ConvertingStatus.Completed)
            {
                return;
            }

            if (e.Value == null)
            {
            }
            else if (e.DestinationType.IsAssignableFrom(e.Value.GetType()))
            {
            }
            else if (e.DestinationType == typeof(string) && IsStringConversionSupported() == false)
            {
                throw new ApplicationException("String conversion not supported for this type of Validator.");
            }
            else if (m_TypeConverter != null)
            {
                e.Value = m_TypeConverter.ConvertTo(EmptyTypeDescriptorContext.Empty, CultureInfo, e.Value, e.DestinationType);
            }
        }
Пример #7
0
        /// <summary>
        /// Fired when converting a value to a display string. Called from method ValueToDisplayString
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnConvertingValueToDisplayString(ConvertingObjectEventArgs e)
        {
            if (m_ConvertingValueToDisplayString != null)
            {
                m_ConvertingValueToDisplayString(this, e);
            }

            if (e.ConvertingStatus == ConvertingStatus.Error)
            {
                throw new ConversionErrorException("display String", ObjectToStringForError(e.Value));
            }
            else if (e.ConvertingStatus == ConvertingStatus.Completed)
            {
                return;
            }

            if (e.Value == null)
            {
                e.Value = NullDisplayString;
            }
            else if (IsStringConversionSupported())
            {
                e.Value = ValueToString(e.Value);
            }
            else
            {
                e.Value = e.Value.ToString();
            }
        }
Пример #8
0
        /// <summary>
        /// Convert a value according to the current ValueType to an object with the Type specified. Throw an exception on error.
        /// </summary>
        /// <param name="p_Value"></param>
        /// <param name="p_ReturnObjectType"></param>
        /// <returns></returns>
        public object ValueToObject(object p_Value, Type p_ReturnObjectType)
        {
            if (p_ReturnObjectType == null)
            {
                throw new DevAgeApplicationException("Invalid parameter returnObjectType cannot be null");
            }

            ConvertingObjectEventArgs l_Converting = new ConvertingObjectEventArgs(p_Value, p_ReturnObjectType);

            OnConvertingValueToObject(l_Converting);
            if (l_Converting.ConvertingStatus == ConvertingStatus.Error)
            {
                throw new ConversionErrorException(p_ReturnObjectType.Name, ObjectToStringForError(l_Converting.Value));
            }

            if (l_Converting.Value == null)
            {
                return(null);
            }
            else if (l_Converting.DestinationType.IsAssignableFrom(l_Converting.Value.GetType()))
            {
                return(l_Converting.Value);
            }
            else
            {
                throw new ConversionErrorException(p_ReturnObjectType.Name, ObjectToStringForError(l_Converting.Value));
            }
        }
Пример #9
0
        /// <summary>
        /// Fired when converting a object to the value specified. Called from method ObjectToValue and IsValidObject
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnConvertingObjectToValue(ConvertingObjectEventArgs e)
        {
            if (m_ConvertingObjectToValue != null)
            {
                m_ConvertingObjectToValue(this, e);
            }

            if (e.ConvertingStatus == ConvertingStatus.Error)
            {
                throw new ConversionErrorException(e.DestinationType.Name, ObjectToStringForError(e.Value));
            }
            else if (e.ConvertingStatus == ConvertingStatus.Completed)
            {
                return;
            }

            if (e.Value is string)             //?importante fare prima il caso stringa per gestire correttamente il null
            {
                string tmp = (string)e.Value;
                if (IsNullString(tmp))
                {
                    e.Value = null;
                }
            }
        }
        /// <summary>
        /// Fired when converting an object to the value specified. Called from method ObjectToValue and IsValidObject
        /// </summary>
        /// <param name="e">The <see cref="Fr.Medit.MedDataGrid.ConversionModel.ConvertingObjectEventArgs"/> instance containing the event data.</param>
        protected override void OnConvertingValueToObject(ConvertingObjectEventArgs e)
        {
            if (convertingValueToObjectHandler != null)
            {
                convertingValueToObjectHandler(this, e);
            }
            if (e.ConvertingStatus == ConvertingStatus.Error)
            {
                throw new MEDDataGridException("Invalid conversion");
            }
            else if (e.ConvertingStatus == ConvertingStatus.Completed)
            {
                return;
            }

            if (e.Value == null)
            {
            }
            else if (e.DestinationType.IsAssignableFrom(e.Value.GetType()))
            {
            }
            else if (e.DestinationType == typeof(string) && IsStringConversionSupported() == false)
            {
                // SAA TODO: Deficiency in conversion here.  Add Image->string conversion when image
                // is ligand depiction.
                // Here we just choose not to copy anything because we don't have a conversion.
                e.Value = string.Empty;
            }
            else if (typeConverter != null)
            {
                e.Value = typeConverter.ConvertTo(null, CultureInfo, e.Value, e.DestinationType);
            }
        }
Пример #11
0
        /// <summary>
        /// Fired when converting a value to a display string. Called from method ValueToDisplayString
        /// </summary>
        /// <param name="e">The <see cref="Fr.Medit.MedDataGrid.ConversionModel.ConvertingObjectEventArgs"/> instance containing the event data.</param>
        protected virtual void OnConvertingValueToDisplayString(ConvertingObjectEventArgs e)
        {
            if (convertingValueToDisplayStringHandler != null)
            {
                convertingValueToDisplayStringHandler(this, e);
            }
            if (e.ConvertingStatus == ConvertingStatus.Error)
            {
                throw new MEDDataGridException("Invalid conversion");
            }
            else if (e.ConvertingStatus == ConvertingStatus.Completed)
            {
                return;
            }

            if (e.Value == null)
            {
                e.Value = NullDisplayString;
            }
            else if (IsStringConversionSupported())
            {
                e.Value = ValueToString(e.Value);
            }
            else
            {
                e.Value = e.Value.ToString();
            }
        }
Пример #12
0
 private void p_Validator_ConvertingValueToObject(object sender, ConvertingObjectEventArgs e)
 {
     if (!HasCustomConversion())
     {
         return;
     }
     gridRow.Grid.OnConvertingValueToObject(gridRow, e);
 }
Пример #13
0
        /// <summary>
        /// Fired when converting a object to the value specified. Called from method ObjectToValue and IsValidObject
        /// </summary>
        /// <param name="e"></param>
        protected override void OnConvertingObjectToValue(ConvertingObjectEventArgs e)
        {
            base.OnConvertingObjectToValue(e);

            if (e.ConvertingStatus == ConvertingStatus.Error)
            {
                throw new ApplicationException("Invalid conversion");
            }
            else if (e.ConvertingStatus == ConvertingStatus.Completed)
            {
                return;
            }

            if (e.Value == null)
            {
            }
            else if (e.Value is string)             //?importante fare prima il caso stringa per gestire correttamente il null
            {
                string tmp = (string)e.Value;
                if (IsNullString(tmp))
                {
                    e.Value = null;
                }
                else if (e.DestinationType.IsAssignableFrom(e.Value.GetType()))                 //se la stringa non ?nulla e il tipo di destinazione ?sempre una string allora non faccio nessuna conversione
                {
                }
                else if (IsStringConversionSupported())
                {
                    e.Value = m_TypeConverter.ConvertFromString(EmptyTypeDescriptorContext.Empty, CultureInfo, tmp);
                }
                else
                {
                    throw new ApplicationException("String conversion not supported for this type of Validator.");
                }
            }
            else if (e.DestinationType.IsAssignableFrom(e.Value.GetType()))
            {
            }
            else if (m_TypeConverter != null)
            {
                // For some reason string converter does not allow converting from
                // double to string. So here is just override with simple if statemenet
                if (m_TypeConverter is StringConverter)
                {
                    e.Value = SourceGridConvert.To <string>(e.Value);
                }
                else
                {
                    // otherwise just do normal conversion
                    e.Value = m_TypeConverter.ConvertFrom(EmptyTypeDescriptorContext.Empty, CultureInfo, e.Value);
                }
            }
        }
Пример #14
0
 protected virtual void ConvertingObjectToValue(ConvertingObjectEventArgs e)
 {
     if (e.Value is string)
     {
         double val;
         if (double.TryParse((string)e.Value, out val))
         {
             e.Value            = val;
             e.ConvertingStatus = DevAge.ComponentModel.ConvertingStatus.Completed;
         }
     }
 }
Пример #15
0
        private void p_Validator_ConvertingValueToDisplayString(object sender, ConvertingObjectEventArgs e)
        {
            if (gridRow.NoData)
            {
                e.Value            = null;
                e.ConvertingStatus = ConvertingStatus.Completed;
                return;
            }

            if (!HasCustomConversion())
            {
                return;
            }
            gridRow.Grid.OnConvertingValueToDisplayString(gridRow, e);
            //e.ConvertingStatus = ConvertingStatus.Error;
        }
Пример #16
0
        /// <summary>
        /// Fired when converting a object to the value specified. Called from method ObjectToValue and IsValidObject
        /// </summary>
        /// <param name="e"></param>
        protected virtual void OnConvertingValueToObject(ConvertingObjectEventArgs e)
        {
            if (m_ConvertingValueToObject != null)
            {
                m_ConvertingValueToObject(this, e);
            }

            if (e.ConvertingStatus == ConvertingStatus.Error)
            {
                throw new ConversionErrorException(e.DestinationType.Name, ObjectToStringForError(e.Value));
            }
            else if (e.ConvertingStatus == ConvertingStatus.Completed)
            {
                return;
            }
        }
        /// <summary>
        /// Fired when converting an object to the value specified. Called from method ObjectToValue and IsValidObject
        /// </summary>
        /// <param name="e">The <see cref="ConversionModel.ConvertingObjectEventArgs"/> instance containing the event data.</param>
        /// <exception cref="InvalidConversionException">Thrown when unable to convert object</exception>
        protected override void OnConvertingObjectToValue(ConvertingObjectEventArgs e)
        {
            if (convertingObjectToValueHandler != null)
            {
                convertingObjectToValueHandler(this, e);
            }
            if (e.ConvertingStatus == ConvertingStatus.Error)
            {
                throw new MEDDataGridException("Invalid conversion");
            }
            else if (e.ConvertingStatus == ConvertingStatus.Completed)
            {
                return;
            }

            if (e.Value == null)
            {
            }
            else if (e.Value is string) //è importante fare prima il caso stringa per gestire correttamente il null
            {
                string tmp = (string)e.Value;
                if (IsNullString(tmp))
                {
                    e.Value = null;
                }
                else if (e.DestinationType.IsAssignableFrom(e.Value.GetType())) //se la stringa non è nulla e il tipo di destinazione è sempre una string allora non faccio nessuna conversione
                {
                }
                else if (IsStringConversionSupported())
                {
                    e.Value = typeConverter.ConvertFromString(null, CultureInfo, tmp);
                }
                else
                {
                    throw new MEDDataGridException("String conversion not supported for this type of Validator.");
                }
            }
            else if (e.DestinationType.IsAssignableFrom(e.Value.GetType()))
            {
            }
            else if (typeConverter != null)
            {
                e.Value = typeConverter.ConvertFrom(null, CultureInfo, e.Value);
            }
        }
Пример #18
0
        /// <summary>
        /// Convert an object according to the current ValueType of the validator
        /// </summary>
        /// <param name="p_Object">The object.</param>
        /// <returns></returns>
        /// <exception cref="InvalidConversionException">Thrown when unable to convert object to ValueType</exception>
        public object ObjectToValue(object p_Object)
        {
            ConvertingObjectEventArgs l_Converting = new ConvertingObjectEventArgs(p_Object, valueType);

            OnConvertingObjectToValue(l_Converting);
            if (l_Converting.ConvertingStatus == ConvertingStatus.Error)
            {
                throw new InvalidConversionException("Can not convert object to " + ValueType.Name);
            }

            if (IsValidValue(l_Converting.Value))
            {
                return(l_Converting.Value);
            }
            else
            {
                throw new InvalidConversionException("Can not convert object to " + ValueType.Name);
            }
        }
Пример #19
0
        private void p_Validator_ConvertingValueToObject(object sender, ConvertingObjectEventArgs e)
        {
            if (m_List == null || m_List.Count == 0)
            {
                return;
            }
            int k = FindValue(m_List, m_KeyPropertyName, e.Value);

            if (k >= 0)
            {
                e.Value            = m_List[k];
                e.ConvertingStatus = ConvertingStatus.Completed;
            }
            else
            {
                if (m_bThrowErrorIfNotFound)
                {
                    e.ConvertingStatus = ConvertingStatus.Error;
                }
            }
        }
Пример #20
0
        private void p_Validator_ConvertingValueToObject(object sender, ConvertingObjectEventArgs e)
        {
            if (objectList != null)
            {
                if (valueList == null)
                {
                    throw new MEDDataGridException("ValueList can not be null");
                }

                int l_Index = valueList.IndexOf(e.Value);
                if (l_Index >= 0)
                {
                    e.Value            = objectList[l_Index];
                    e.ConvertingStatus = ConvertingStatus.Completed;
                }
                else if (doThrowErrorIfNotFound)
                {
                    e.ConvertingStatus = ConvertingStatus.Error;
                }
            }
        }
Пример #21
0
        private void p_Validator_ConvertingValueToDisplayString(object sender, ConvertingObjectEventArgs e)
        {
            if (m_List == null || m_List.Count == 0)
            {
                return;
            }
            if (m_gridrow != null && m_gridrow.NoData)
            {
                e.Value            = null;
                e.ConvertingStatus = ConvertingStatus.Completed;
                return;
            }
            int k = FindValue(m_List, m_KeyPropertyName, e.Value);

            if (k < 0)
            {
                k = m_List.IndexOf(e.Value);
            }
            if (k >= 0)
            {
                object o1;
                bool   ret = GetProperty(m_List[k], m_ValuePropertyName, out o1);
                if (ret)
                {
                    e.Value            = o1;
                    e.ConvertingStatus = ConvertingStatus.Completed;
                }
                else if (m_bThrowErrorIfNotFound)
                {
                    e.ConvertingStatus = ConvertingStatus.Error;
                }
            }
            else
            {
                if (m_bThrowErrorIfNotFound)
                {
                    e.ConvertingStatus = ConvertingStatus.Error;
                }
            }
        }
Пример #22
0
		/// <summary>
		/// Fired when converting a object to the value specified. Called from method ObjectToValue and IsValidObject
		/// </summary>
		/// <param name="e"></param>
		protected override void OnConvertingObjectToValue(ConvertingObjectEventArgs e)
		{
			base.OnConvertingObjectToValue(e);

			if (e.ConvertingStatus == ConvertingStatus.Error)
				throw new ApplicationException("Invalid conversion");
			else if (e.ConvertingStatus == ConvertingStatus.Completed)
				return;

			if (e.Value == null)
			{
			}
			else if (e.Value is string) //è importante fare prima il caso stringa per gestire correttamente il null
			{
				string tmp = (string)e.Value;
				if (IsNullString(tmp))
					e.Value = null;
				else if (e.DestinationType.IsAssignableFrom(e.Value.GetType())) //se la stringa non è nulla e il tipo di destinazione è sempre una string allora non faccio nessuna conversione
				{
				}
				else if (IsStringConversionSupported())
					e.Value = m_TypeConverter.ConvertFromString(EmptyTypeDescriptorContext.Empty, CultureInfo, tmp);
				else
					throw new ApplicationException("String conversion not supported for this type of Validator.");
			}
			else if (e.DestinationType.IsAssignableFrom(e.Value.GetType()))
			{
			}
			else if (m_TypeConverter != null)
			{
				// For some reason string converter does not allow converting from
				// double to string. So here is just override with simple if statemenet
				if (m_TypeConverter is StringConverter)
					e.Value = SourceGridConvert.To<string>(e.Value);
				else
					// otherwise just do normal conversion
					e.Value = m_TypeConverter.ConvertFrom(EmptyTypeDescriptorContext.Empty, CultureInfo, e.Value);
			}
		}
Пример #23
0
        /// <summary>
        /// Convert a value according to the current ValueType to an object with the Type specified. Throw an exception on error.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="p_ReturnObjectType">Type of the return object.</param>
        /// <returns></returns>
        public object ValueToObject(object value, Type p_ReturnObjectType)
        {
            ConvertingObjectEventArgs l_Converting = new ConvertingObjectEventArgs(value, p_ReturnObjectType);

            OnConvertingValueToObject(l_Converting);
            if (l_Converting.ConvertingStatus == ConvertingStatus.Error)
            {
                throw new MEDDataGridException("Can not convert value to " + p_ReturnObjectType.Name);
            }

            if (l_Converting.Value == null)
            {
                return(null);
            }
            else if (l_Converting.DestinationType.IsAssignableFrom(l_Converting.Value.GetType()))
            {
                return(l_Converting.Value);
            }
            else
            {
                throw new MEDDataGridException("Can not convert value to " + p_ReturnObjectType.Name);
            }
        }
Пример #24
0
        /// <summary>
        /// Converts a value valid for this validator valuetype to a string representation. The string can not be used for conversion.
        /// If the validator support string conversion this method simply call ValueToString otherwise call Value.ToString()
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public virtual string ValueToDisplayString(object value)
        {
            ConvertingObjectEventArgs convertingArgs = new ConvertingObjectEventArgs(value, typeof(string));

            OnConvertingValueToDisplayString(convertingArgs);
            if (convertingArgs.ConvertingStatus == ConvertingStatus.Error)
            {
                throw new MEDDataGridException("Can not convert value to display string");
            }

            if (convertingArgs.Value == null)
            {
                return(NullDisplayString);
            }
            else if (convertingArgs.Value is string)
            {
                return((string)convertingArgs.Value);
            }
            else
            {
                throw new MEDDataGridException("Can not convert value to display string");
            }
        }
Пример #25
0
        /// <summary>
        /// Converts a value valid for this validator valuetype to a string representation. The string cannot be used for conversion.
        /// If the validator support string conversion this method simply call ValueToString otherwise call Value.ToString()
        /// </summary>
        /// <param name="p_Value"></param>
        /// <returns></returns>
        public virtual string ValueToDisplayString(object p_Value)
        {
            ConvertingObjectEventArgs l_Converting = new ConvertingObjectEventArgs(p_Value, typeof(string));

            OnConvertingValueToDisplayString(l_Converting);
            if (l_Converting.ConvertingStatus == ConvertingStatus.Error)
            {
                throw new ConversionErrorException("display String", ObjectToStringForError(l_Converting.Value));
            }

            if (l_Converting.Value == null)
            {
                return(NullDisplayString);
            }
            else if (l_Converting.Value is string)
            {
                return((string)l_Converting.Value);
            }
            else
            {
                throw new ConversionErrorException("display String", ObjectToStringForError(l_Converting.Value));
            }
        }
Пример #26
0
        private void p_Validator_ConvertingValueToDisplayString(object sender, ConvertingObjectEventArgs e)
        {
            if (m_DisplayStringList != null)
            {
                if (m_ValueList == null)
                {
                    throw new ApplicationException("ValueList cannot be null");
                }

                int l_Index = m_ValueList.IndexOf(e.Value);
                if (l_Index >= 0)
                {
                    e.Value            = m_DisplayStringList[l_Index];
                    e.ConvertingStatus = ConvertingStatus.Completed;
                }
                else
                {
                    if (m_bThrowErrorIfNotFound)
                    {
                        e.ConvertingStatus = ConvertingStatus.Error;
                    }
                }
            }
        }
        /// <summary>
        /// Fired when converting an object to the value specified. Called from method ObjectToValue and IsValidObject
        /// </summary>
        /// <param name="e">The <see cref="Fr.Medit.MedDataGrid.ConversionModel.ConvertingObjectEventArgs"/> instance containing the event data.</param>
        protected override void OnConvertingValueToObject(ConvertingObjectEventArgs e)
        {
            if (convertingValueToObjectHandler != null)
              {
            convertingValueToObjectHandler(this, e);
              }
              if (e.ConvertingStatus == ConvertingStatus.Error)
              {
            throw new MEDDataGridException("Invalid conversion");
              }
              else if (e.ConvertingStatus == ConvertingStatus.Completed)
              {
            return;
              }

              if (e.Value == null)
              {
              }
              else if (e.DestinationType.IsAssignableFrom(e.Value.GetType()))
              {
              }
              else if (e.DestinationType == typeof(string) && IsStringConversionSupported() == false)
              {
            // SAA TODO: Deficiency in conversion here.  Add Image->string conversion when image
            // is ligand depiction.
            // Here we just choose not to copy anything because we don't have a conversion.
            e.Value = string.Empty;
              }
              else if (typeConverter != null)
              {
            e.Value = typeConverter.ConvertTo(null, CultureInfo, e.Value, e.DestinationType);
              }
        }
Пример #28
0
        /// <summary>
        /// Convert an object according to the current ValueType of the validator
        /// </summary>
        /// <param name="p_Object">The object.</param>
        /// <returns></returns>
        /// <exception cref="InvalidConversionException">Thrown when unable to convert object to ValueType</exception>
        public object ObjectToValue(object p_Object)
        {
            ConvertingObjectEventArgs l_Converting = new ConvertingObjectEventArgs(p_Object, valueType);
              OnConvertingObjectToValue(l_Converting);
              if (l_Converting.ConvertingStatus == ConvertingStatus.Error)
              {
            throw new InvalidConversionException("Can not convert object to " + ValueType.Name);
              }

              if (IsValidValue(l_Converting.Value))
              {
            return l_Converting.Value;
              }
              else
              {
            throw new InvalidConversionException("Can not convert object to " + ValueType.Name);
              }
        }
Пример #29
0
        /// <summary>
        /// Convert a value according to the current ValueType to an object with the Type specified. Throw an exception on error.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <param name="p_ReturnObjectType">Type of the return object.</param>
        /// <returns></returns>
        public object ValueToObject(object value, Type p_ReturnObjectType)
        {
            ConvertingObjectEventArgs l_Converting = new ConvertingObjectEventArgs(value, p_ReturnObjectType);
              OnConvertingValueToObject(l_Converting);
              if (l_Converting.ConvertingStatus == ConvertingStatus.Error)
              {
            throw new MEDDataGridException("Can not convert value to " + p_ReturnObjectType.Name);
              }

              if (l_Converting.Value == null)
              {
            return null;
              }
              else if (l_Converting.DestinationType.IsAssignableFrom(l_Converting.Value.GetType()))
              {
            return l_Converting.Value;
              }
              else
              {
            throw new MEDDataGridException("Can not convert value to " + p_ReturnObjectType.Name);
              }
        }
        /// <summary>
        /// Fired when converting an object to the value specified. Called from method ObjectToValue and IsValidObject
        /// </summary>
        /// <param name="e">The <see cref="ConversionModel.ConvertingObjectEventArgs"/> instance containing the event data.</param>
        /// <exception cref="InvalidConversionException">Thrown when unable to convert object</exception>
        protected override void OnConvertingObjectToValue(ConvertingObjectEventArgs e)
        {
            if (convertingObjectToValueHandler != null)
              {
            convertingObjectToValueHandler(this, e);
              }
              if (e.ConvertingStatus == ConvertingStatus.Error)
              {
            throw new MEDDataGridException("Invalid conversion");
              }
              else if (e.ConvertingStatus == ConvertingStatus.Completed)
              {
            return;
              }

              if (e.Value == null)
              {
              }
              else if (e.Value is string) //è importante fare prima il caso stringa per gestire correttamente il null
              {
            string tmp = (string)e.Value;
            if (IsNullString(tmp))
            {
              e.Value = null;
            }
            else if (e.DestinationType.IsAssignableFrom(e.Value.GetType())) //se la stringa non è nulla e il tipo di destinazione è sempre una string allora non faccio nessuna conversione
            {
            }
            else if (IsStringConversionSupported())
            {
              e.Value = typeConverter.ConvertFromString(null, CultureInfo, tmp);
            }
            else
            {
              throw new MEDDataGridException("String conversion not supported for this type of Validator.");
            }
              }
              else if (e.DestinationType.IsAssignableFrom(e.Value.GetType()))
              {
              }
              else if (typeConverter != null)
              {
            e.Value = typeConverter.ConvertFrom(null, CultureInfo, e.Value);
              }
        }
Пример #31
0
		/// <summary>
		/// Convert a value according to the current ValueType to an object with the Type specified. Throw an exception on error.
		/// </summary>
		/// <param name="p_Value"></param>
		/// <param name="p_ReturnObjectType"></param>
		/// <returns></returns>
		public object ValueToObject(object p_Value, Type p_ReturnObjectType)
		{
			if (p_ReturnObjectType == null)
				throw new DevAgeApplicationException("Invalid parameter returnObjectType cannot be null");

			ConvertingObjectEventArgs l_Converting = new ConvertingObjectEventArgs(p_Value, p_ReturnObjectType);
			OnConvertingValueToObject(l_Converting);
			if (l_Converting.ConvertingStatus == ConvertingStatus.Error)
				throw new ConversionErrorException(p_ReturnObjectType.Name, ObjectToStringForError(l_Converting.Value) );

			if (l_Converting.Value == null)
				return null;
			else if (l_Converting.DestinationType.IsAssignableFrom(l_Converting.Value.GetType()))
				return l_Converting.Value;
			else
				throw new ConversionErrorException(p_ReturnObjectType.Name, ObjectToStringForError(l_Converting.Value) );
		}
Пример #32
0
		/// <summary>
		/// Convert an object according to the current ValueType of the validator
		/// </summary>
		/// <param name="p_Object"></param>
		/// <returns></returns>
		public object ObjectToValue(object p_Object)
		{
			Type destinationType = ValueType;
			if (destinationType == null && p_Object != null)
				destinationType = p_Object.GetType();

			ConvertingObjectEventArgs l_Converting = new ConvertingObjectEventArgs(p_Object, destinationType);
			OnConvertingObjectToValue(l_Converting);
			if (l_Converting.ConvertingStatus == ConvertingStatus.Error)
				throw new ConversionErrorException(ValueTypeName, ObjectToStringForError(l_Converting.Value) );

			if (IsValidValue(l_Converting.Value))
				return l_Converting.Value;
			else
				throw new ConversionErrorException(ValueTypeName, ObjectToStringForError(l_Converting.Value) );
		}
Пример #33
0
		private void p_Validator_ConvertingValueToObject(object sender, ConvertingObjectEventArgs e)
		{
			if (mSpecialList != null && e.DestinationType == SpecialType)
			{
				if (m_ValueList == null)
					throw new ApplicationException("ValueList cannot be null");
				
				//Verifico se il valore è presente nella list, in questo caso restituisco l'oggetto associato
				int l_Index = m_ValueList.IndexOf(e.Value);
				if (l_Index >= 0)
				{
					e.Value = mSpecialList[l_Index];
					e.ConvertingStatus = ConvertingStatus.Completed;
				}
				else
				{
					if (m_bThrowErrorIfNotFound)
						e.ConvertingStatus = ConvertingStatus.Error;
				}
			}
		}
Пример #34
0
        /// <summary>
        /// Fired when converting a value to a display string. Called from method ValueToDisplayString
        /// </summary>
        /// <param name="e">The <see cref="Fr.Medit.MedDataGrid.ConversionModel.ConvertingObjectEventArgs"/> instance containing the event data.</param>
        protected virtual void OnConvertingValueToDisplayString(ConvertingObjectEventArgs e)
        {
            if (convertingValueToDisplayStringHandler != null)
              {
            convertingValueToDisplayStringHandler(this, e);
              }
              if (e.ConvertingStatus == ConvertingStatus.Error)
              {
            throw new MEDDataGridException("Invalid conversion");
              }
              else if (e.ConvertingStatus == ConvertingStatus.Completed)
              {
            return;
              }

              if (e.Value == null)
              {
            e.Value = NullDisplayString;
              }
              else if (IsStringConversionSupported())
              {
            e.Value = ValueToString(e.Value);
              }
              else
              {
            e.Value = e.Value.ToString();
              }
        }
Пример #35
0
		/// <summary>
		/// Fired when converting a object to the value specified. Called from method ObjectToValue and IsValidObject
		/// </summary>
		/// <param name="e"></param>
		protected override void OnConvertingValueToObject(ConvertingObjectEventArgs e)
		{
			base.OnConvertingValueToObject(e);

			if (e.ConvertingStatus == ConvertingStatus.Error)
				throw new ApplicationException("Invalid conversion");
			else if (e.ConvertingStatus == ConvertingStatus.Completed)
				return;

			if (e.Value == null)
			{
			}
			else if (e.DestinationType.IsAssignableFrom(e.Value.GetType()))
			{
			}
			else if (e.DestinationType == typeof(string) && IsStringConversionSupported() == false)
			{
				throw new ApplicationException("String conversion not supported for this type of Validator.");
			}
			else if (m_TypeConverter != null)
			{
				e.Value = m_TypeConverter.ConvertTo(EmptyTypeDescriptorContext.Empty, CultureInfo, e.Value, e.DestinationType);
			}
		}
Пример #36
0
		private void p_Validator_ConvertingValueToDisplayString(object sender, ConvertingObjectEventArgs e)
		{
			if (m_DisplayStringList != null)
			{
				if (m_ValueList == null)
					throw new ApplicationException("ValueList cannot be null");
				
				int l_Index = m_ValueList.IndexOf(e.Value);
				if (l_Index >= 0)
				{
					e.Value = m_DisplayStringList[l_Index];
					e.ConvertingStatus = ConvertingStatus.Completed;
				}
				else
				{
					if (m_bThrowErrorIfNotFound)
						e.ConvertingStatus = ConvertingStatus.Error;
				}
			}
		}
Пример #37
0
        /// <summary>
        /// Converts a value valid for this validator valuetype to a string representation. The string can not be used for conversion.
        /// If the validator support string conversion this method simply call ValueToString otherwise call Value.ToString()
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public virtual string ValueToDisplayString(object value)
        {
            ConvertingObjectEventArgs convertingArgs = new ConvertingObjectEventArgs(value, typeof(string));
              OnConvertingValueToDisplayString(convertingArgs);
              if (convertingArgs.ConvertingStatus == ConvertingStatus.Error)
              {
            throw new MEDDataGridException("Can not convert value to display string");
              }

              if (convertingArgs.Value == null)
              {
            return NullDisplayString;
              }
              else if (convertingArgs.Value is string)
              {
            return (string)convertingArgs.Value;
              }
              else
              {
            throw new MEDDataGridException("Can not convert value to display string");
              }
        }
Пример #38
0
		/// <summary>
		/// Fired when converting a value to a display string. Called from method ValueToDisplayString
		/// </summary>
		/// <param name="e"></param>
		protected virtual void OnConvertingValueToDisplayString(ConvertingObjectEventArgs e)
		{
			if (m_ConvertingValueToDisplayString != null)
				m_ConvertingValueToDisplayString(this, e);

			if (e.ConvertingStatus == ConvertingStatus.Error)
				throw new ConversionErrorException("display String", ObjectToStringForError(e.Value));
			else if (e.ConvertingStatus == ConvertingStatus.Completed)
				return;

			if (e.Value == null)
				e.Value = NullDisplayString;
			else if (IsStringConversionSupported())
				e.Value = ValueToString(e.Value);
			else
				e.Value = e.Value.ToString();
		}
Пример #39
0
		/// <summary>
		/// Fired when converting a object to the value specified. Called from method ObjectToValue and IsValidObject
		/// </summary>
		/// <param name="e"></param>
		protected virtual void OnConvertingValueToObject(ConvertingObjectEventArgs e)
		{
			if (m_ConvertingValueToObject != null)
				m_ConvertingValueToObject(this, e);

			if (e.ConvertingStatus == ConvertingStatus.Error)
				throw new ConversionErrorException(e.DestinationType.Name, ObjectToStringForError(e.Value) );
			else if (e.ConvertingStatus == ConvertingStatus.Completed)
				return;
		}
Пример #40
0
		/// <summary>
		/// Fired when converting a object to the value specified. Called from method ObjectToValue and IsValidObject
		/// </summary>
		/// <param name="e"></param>
		protected virtual void OnConvertingObjectToValue(ConvertingObjectEventArgs e)
		{
			if (m_ConvertingObjectToValue != null)
				m_ConvertingObjectToValue(this, e);

			if (e.ConvertingStatus == ConvertingStatus.Error)
				throw new ConversionErrorException(e.DestinationType.Name, ObjectToStringForError(e.Value) );
			else if (e.ConvertingStatus == ConvertingStatus.Completed)
				return;

			if (e.Value is string) //è importante fare prima il caso stringa per gestire correttamente il null
			{
				string tmp = (string)e.Value;
				if (IsNullString(tmp))
					e.Value = null;
			}			
		}
Пример #41
0
		/// <summary>
		/// Converts a value valid for this validator valuetype to a string representation. The string cannot be used for conversion.
		/// If the validator support string conversion this method simply call ValueToString otherwise call Value.ToString()
		/// </summary>
		/// <param name="p_Value"></param>
		/// <returns></returns>
		public virtual string ValueToDisplayString(object p_Value)
		{
			ConvertingObjectEventArgs l_Converting = new ConvertingObjectEventArgs(p_Value, typeof(string));
			OnConvertingValueToDisplayString(l_Converting);
			if (l_Converting.ConvertingStatus == ConvertingStatus.Error)
				throw new ConversionErrorException("display String", ObjectToStringForError(l_Converting.Value) );

			if (l_Converting.Value == null)
				return NullDisplayString;
			else if (l_Converting.Value is string)
				return (string)l_Converting.Value;
			else
				throw new ConversionErrorException("display String", ObjectToStringForError(l_Converting.Value) );
		}
Пример #42
0
        protected override void OnConvertingValueToDisplayString(ConvertingObjectEventArgs e)
        {
            object evalue = e.Value;

            if (evalue == DBNull.Value)
            {
                evalue = null;
            }


            if (Row != null && Row.NoData ||
                string.IsNullOrEmpty(Control.DisplayMember) ||
                string.IsNullOrEmpty(Control.ValueMember))
            {
                //if(Control.IsInUpdateX)

                /*
                 * if (evalue == null)
                 *  //e.Value = this.NullDisplayString;
                 *  e.Value = Control.Text;
                 * else
                 * {
                 *  e.Value = Control.Text;
                 * }*/
                e.Value            = "";
                e.ConvertingStatus = ConvertingStatus.Completed;
                return;
            }


            object item = null;
            object val;
            int    k = -1;

            if (evalue != null)
            {
                k = Control.Items.IndexOf(e.Value);
            }

            if (k < 0)
            {
                k = Utils.FindValue(Control.Items, Control.ValueMember, e.Value);
            }

            if (k >= 0)
            {
                item = Control.Items[k];
            }
            else if (Control.DataSource as IList != null)
            {
                k = Utils.FindValue(Control.DataSource as IList, Control.ValueMember, e.Value);
                if (k >= 0)
                {
                    item = (Control.DataSource as IList)[k];
                }
            }

            if (item != null)
            {
                if (Utils.GetPublicPropertyValue(item, Control.DisplayMember, out val))
                {
                    if (val == null)
                    {
                        e.Value = null;
                    }
                    else
                    {
                        e.Value = val.ToString();
                    }
                    e.ConvertingStatus = ConvertingStatus.Completed;
                    return;
                }
                else
                {
                    e.ConvertingStatus = ConvertingStatus.Error;
                }
            }
            else
            {
                if (evalue == null || (evalue is string && (string)evalue == ""))
                {
                    e.Value            = this.NullString;
                    e.ConvertingStatus = ConvertingStatus.Completed;
                    return;
                }

                e.Value            = "?";
                e.ConvertingStatus = ConvertingStatus.Completed;

                //e.ConvertingStatus = ConvertingStatus.Error;
            }
        }
Пример #43
0
        private void p_Validator_ConvertingValueToObject(object sender, ConvertingObjectEventArgs e)
        {
            if (objectList != null)
              {
            if (valueList == null)
            {
              throw new MEDDataGridException("ValueList can not be null");
            }

            int l_Index = valueList.IndexOf(e.Value);
            if (l_Index >= 0)
            {
              e.Value = objectList[l_Index];
              e.ConvertingStatus = ConvertingStatus.Completed;
            }
            else if (doThrowErrorIfNotFound)
            {
              e.ConvertingStatus = ConvertingStatus.Error;
            }
              }
        }
Пример #44
0
		private void p_Validator_ConvertingObjectToValue(object sender, ConvertingObjectEventArgs e)
		{
			if (mSpecialList != null && e.Value != null && e.Value.GetType() == SpecialType)
			{
				if (m_ValueList == null)
					throw new ApplicationException("ValueList cannot be null");
				
				//Verifico se fa parte della lista di valori
				int index = m_ValueList.IndexOf(e.Value);
				if (index >= 0)
				{
					e.Value = m_ValueList[index];
					e.ConvertingStatus = ConvertingStatus.Completed;
				}
				else
				{
					//Verifico se fa parte della lista di oggetti, in questo caso restituisco il valore corrispondente
					index = mSpecialList.IndexOf(e.Value);
					if (index >= 0)
					{
						e.Value = m_ValueList[index];
						e.ConvertingStatus = ConvertingStatus.Completed;
					}
					else if (m_bThrowErrorIfNotFound)
						e.ConvertingStatus = ConvertingStatus.Error;
				}
			}
		}
Пример #45
0
 public virtual void OnConvertingValueToObject(MyGridRowPropEditorBase sender, ConvertingObjectEventArgs e)
 {
     if (ConvertingValueToObject == null)
     {
         return;
     }
     ConvertingValueToObject(sender, e);
 }
Пример #46
0
        /// <summary>
        /// Fired when converting an object to the value specified. Called from method ObjectToValue and IsValidObject
        /// </summary>
        /// <param name="e">The <see cref="Fr.Medit.MedDataGrid.ConversionModel.ConvertingObjectEventArgs"/> instance containing the event data.</param>
        protected virtual void OnConvertingValueToObject(ConvertingObjectEventArgs e)
        {
            if (convertingValueToObjectHandler != null)
              {
            convertingValueToObjectHandler(this, e);
              }
              if (e.ConvertingStatus == ConvertingStatus.Error)
              {
            throw new MEDDataGridException("Invalid conversion");
              }
              else if (e.ConvertingStatus == ConvertingStatus.Completed)
              {
            return;
              }

              if (e.Value == null)
              {
              }
              else if (e.DestinationType.IsAssignableFrom(e.Value.GetType()))
              {
              }
              else if (e.DestinationType == typeof(string))
              {
            if (IsStringConversionSupported() == false)
            {
              throw new MEDDataGridException("String conversion not supported for this type of Validator.");
            }
            e.Value = e.Value.ToString();
              }
        }
Пример #47
0
        /// <summary>
        /// Fired when converting an object to the value specified. Called from method ObjectToValue and IsValidObject
        /// </summary>
        /// <param name="e">The <see cref="ConversionModel.ConvertingObjectEventArgs"/> instance containing the event data.</param>
        /// <exception cref="InvalidConversionException">Thrown when unable to convert object</exception>
        protected virtual void OnConvertingObjectToValue(ConvertingObjectEventArgs e)
        {
            if (convertingObjectToValueHandler != null)
              {
            convertingObjectToValueHandler(this, e);
              }
              if (e.ConvertingStatus == ConvertingStatus.Error)
              {
            throw new InvalidConversionException("Invalid conversion");
              }
              else if (e.ConvertingStatus == ConvertingStatus.Completed)
              {
            return;
              }

              if (e.Value == null)
              {
              }
              else if (e.Value is string) //è importante fare prima il caso stringa per gestire correttamente il null
              {
            string tmp = (string)e.Value;
            if (IsNullString(tmp))
            {
              e.Value = null;
            }
            else if (e.DestinationType != typeof(string) && IsStringConversionSupported() == false)
            {
              throw new InvalidConversionException("String conversion not supported for this type of Validator.");
            }
              }
              else if (e.DestinationType.IsAssignableFrom(e.Value.GetType()))
              {
              }
        }