Beispiel #1
0
        public void AddWarning(MdpImportWarning message)
        {
            if (_warnings == null)
            {
                _warnings = new ArrayList();
            }

            _warnings.Add(message);
        }
Beispiel #2
0
        public void AddWarning(MdpImportWarning message)
        {
            if (_warnings == null)
                _warnings = new ArrayList();

            _warnings.Add(message);
        }
Beispiel #3
0
        protected virtual object ConvertToFile(object value, MetaDataType dest, string destFieldName, int rowIndex, out MdpImportWarning[] warnings)
        {
            warnings = null;
            if (OnConvertToFile != null)
            {
                MetaObjectResolverEventArgs e = new MetaObjectResolverEventArgs(value, destFieldName, dest);

                OnConvertToFile(this, e);

                warnings = e.Warnings;

                return e.Value;
            }
            else return null;
        }
Beispiel #4
0
        protected virtual object ConvertDataType(Type source, MetaDataType destination, object value, string destFieldName, bool allowNull, int rowIndex, out MdpImportWarning[] warnings)
        {
            warnings = null;
            switch (destination)
            {
                case MetaDataType.BigInt:
                    return Convert.ChangeType(value, typeof(Int64));
                case MetaDataType.Binary:
                case MetaDataType.Image:
                case MetaDataType.VarBinary:
                    return Convert.ChangeType(value, typeof(byte[]));	// TODO: does it work?
                case MetaDataType.Bit:
                case MetaDataType.Boolean:
                    switch (value.ToString().ToLower())
                    {
                        case "true":
                            return true;
                        case "false":
                            return false;
                        default:
                            try
                            {
                                return (int.Parse(value.ToString()) != 0);
                            }
                            catch
                            {
                            }
                            return false;
                    }
                case MetaDataType.Char:
                case MetaDataType.NChar:
                case MetaDataType.NText:
                case MetaDataType.NVarChar:
                case MetaDataType.UniqueIdentifier:
                case MetaDataType.Text:
                case MetaDataType.VarChar:
                case MetaDataType.Sysname:
                case MetaDataType.ShortString:
                case MetaDataType.LongString:
                case MetaDataType.Url:
                case MetaDataType.Email:
                case MetaDataType.LongHtmlString:
                    return value.ToString();
                case MetaDataType.DateTime:
                    return Convert.ChangeType(value, typeof(DateTime));
                case MetaDataType.Decimal:
                case MetaDataType.Numeric:
                    return Convert.ChangeType(value, typeof(Decimal));
                case MetaDataType.Money:
                case MetaDataType.SmallMoney:							// TODO:?? + temporal code for currency symbol
                    if (value is string)
                        return Convert.ChangeType(value.ToString().TrimStart('$'), typeof(Decimal));
                    else
                        return Convert.ChangeType(value, typeof(Decimal));
                case MetaDataType.Float:
                    return Convert.ChangeType(value, typeof(Double));
                case MetaDataType.Int:
                case MetaDataType.Integer:
                    return Convert.ChangeType(value, typeof(Int32));
                case MetaDataType.Real:
                    return Convert.ChangeType(value, typeof(Single));
                case MetaDataType.SmallDateTime:
                    return Convert.ChangeType(value, typeof(DateTime));		// TODO:??
                case MetaDataType.SmallInt:
                    return Convert.ChangeType(value, typeof(Int16));
                case MetaDataType.TinyInt:
                    return Convert.ChangeType(value, typeof(Byte));
                case MetaDataType.Date:
                    return Convert.ChangeType(value, typeof(DateTime));
                case MetaDataType.DictionaryMultivalue:
                case MetaDataType.EnumMultivalue:
                    value = ConvertToDictionary(value, destination, destFieldName, rowIndex, out warnings);
                    if (value == null && !allowNull)
                        throw new Mediachase.MetaDataPlus.Import.InvalidCastException(destination.ToString(), source.ToString());
                    break;
                case MetaDataType.DictionarySingleValue:
                case MetaDataType.EnumSingleValue:
                    value = ConvertToDictionary(value, destination, destFieldName, rowIndex, out warnings);
                    if (value == null && !allowNull)
                        throw new Mediachase.MetaDataPlus.Import.InvalidCastException(destination.ToString(), source.ToString());
                    break;
                case MetaDataType.File:
                case MetaDataType.ImageFile:
                    value = ConvertToFile(value, destination, destFieldName, rowIndex, out warnings);
                    if (value == null && !allowNull)
                        throw new Mediachase.MetaDataPlus.Import.InvalidCastException(destination.ToString(), source.ToString());
                    break;
                default:
                    throw new Mediachase.MetaDataPlus.Import.InvalidCastException(destination.ToString(), source.ToString());

            }
            return value;
        }