Beispiel #1
0
        /// <summary>
        /// Notification method activated from Adaptor
        /// </summary>
        /// <param name="aSender">
        /// Object that made change <see cref="System.Object"/>
        /// </param>
        public virtual void GetDataFromDataSource(object aSender)
        {
            string preffix = "";
            string suffix  = "";

            if (Important == true)
            {
                preffix = "<b>";
                suffix  = "</b>";
            }
            // Translate enumeration value
            if ((adaptor.Adaptor.FinalTarget != null) && (Mappings != ""))
            {
                System.Type type = adaptor.Adaptor.Values[0].Value.GetType();
                if (type.IsEnum == true)
                {
                    Array enumValues = Enum.GetValues(type);
                    for (int i = 0; i < enumValues.Length; i++)
                    {
                        if (enumValues.GetValue(i).Equals(adaptor.Value))
                        {
                            string desc = enumValues.GetValue(i).ToString();
                            if ((UseMarkup == true) || (Important == true))
                            {
                                Markup = preffix + enumValues.GetValue(i).GetType().GetField(desc).GetEnumTitle() + suffix;
                            }
                            else
                            {
                                Text = enumValues.GetValue(i).GetType().GetField(desc).GetEnumTitle();
                            }
                        }
                    }
                    return;
                }
            }
            // Translate basic value
            if (adaptor.Value == null)
            {
                Text = "";
            }
            else
            {
                PropertyDescriptionAttribute attr = adaptor.Adaptor.Mapping(0).GetDescription();
                if (attr != null)
                {
                    switch (attr.DataTypeHandler)
                    {
                    case "date":
                        if ((UseMarkup == true) || (Important == true))
                        {
                            Markup = preffix + ((DateTime)adaptor.Value).ToShortDateString() + suffix;
                        }
                        else
                        {
                            Text = ((DateTime)adaptor.Value).ToShortDateString();
                        }
                        break;

                    case "time":
                        if ((UseMarkup == true) || (Important == true))
                        {
                            Markup = preffix + ((DateTime)adaptor.Value).ToShortTimeString() + suffix;
                        }
                        else
                        {
                            Text = ((DateTime)adaptor.Value).ToShortTimeString();
                        }
                        break;

                    case "percent":
                        if ((UseMarkup == true) || (Important == true))
                        {
                            Markup = preffix + TypeConversions.NumberToPercentString(adaptor.Value) + suffix;
                        }
                        else
                        {
                            Text = TypeConversions.NumberToPercentString(adaptor.Value);
                        }
                        break;

                    case "numeric":
                        if ((UseMarkup == true) || (Important == true))
                        {
                            Markup = preffix + TypeConversions.NumberToNumericString(adaptor.Value) + suffix;
                        }
                        else
                        {
                            Text = TypeConversions.NumberToNumericString(adaptor.Value);
                        }
                        break;

                    case "financial":
                        if ((UseMarkup == true) || (Important == true))
                        {
                            Markup = preffix + TypeConversions.NumberToFinancialString(adaptor.Value) + suffix;
                        }
                        else
                        {
                            Text = TypeConversions.NumberToFinancialString(adaptor.Value);
                        }
                        break;

                    case "currency":
                        if ((UseMarkup == true) || (Important == true))
                        {
                            Markup = preffix + TypeConversions.NumberToCurrencyString(adaptor.Value) + suffix;
                        }
                        else
                        {
                            Text = TypeConversions.NumberToCurrencyString(adaptor.Value);
                        }
                        break;

                    default:
                        Text = adaptor.Value.ToString();
                        break;
                    }
                    return;
                }
                if ((UseMarkup == true) || (Important == true))
                {
                    if (TypeValidator.IsString(adaptor.Value.GetType()) == false)
                    {
                        Markup = preffix + adaptor.Value.ToString() + suffix;
                    }
                    else
                    {
                        Markup = preffix + (string)adaptor.Value + suffix;
                    }
                }
                else
                {
                    if (TypeValidator.IsString(adaptor.Value.GetType()) == false)
                    {
                        Text = adaptor.Value.ToString();
                    }
                    else
                    {
                        Text = (string)adaptor.Value;
                    }
                }
            }
        }