Ejemplo n.º 1
0
        protected static object GetFieldValue(DataType fieldType, object value)
        {
            DateTime date;

            switch (fieldType)
            {
            case DataType.Date:
                if (value is DateTime)
                {
                    return(value);
                }
                date = BusinessDomain.GetDateValue((string)value);
                if (date != DateTime.MinValue)
                {
                    return(date);
                }
                break;

            case DataType.DateTime:
                if (value is DateTime)
                {
                    return(value);
                }
                date = BusinessDomain.GetDateTimeValue((string)value);
                if (date != DateTime.MinValue)
                {
                    return(date);
                }
                break;

            case DataType.Quantity:
                if (IsNumeric(value))
                {
                    return(value);
                }
                double dbl;
                if (Quantity.TryParseExpression((string)value, out dbl))
                {
                    return(dbl);
                }
                break;

            case DataType.CurrencyIn:
                if (IsNumeric(value))
                {
                    return(value);
                }
                if (Currency.TryParseExpression((string)value, out dbl, PriceType.Purchase))
                {
                    return(dbl);
                }
                break;

            case DataType.CurrencyOut:
                if (IsNumeric(value))
                {
                    return(value);
                }
                if (Currency.TryParseExpression((string)value, out dbl))
                {
                    return(dbl);
                }
                break;

            case DataType.Currency:
                if (IsNumeric(value))
                {
                    return(value);
                }
                if (Currency.TryParseExpression((string)value, out dbl, PriceType.Unknown))
                {
                    return(dbl);
                }
                break;

            case DataType.Percent:
                if (IsNumeric(value))
                {
                    return(value);
                }
                if (Percent.TryParseExpression((string)value, out dbl))
                {
                    return(dbl);
                }
                break;

            case DataType.Id:
            case DataType.UserId:
            case DataType.DocumentNumber:
            case DataType.OperationType:
            case DataType.DocumentType:
            case DataType.PriceGroupType:
            case DataType.BasePaymentType:
            case DataType.PaymentType:
            case DataType.PartnerType:
            case DataType.ItemType:
            case DataType.UserAccessLevel:
            case DataType.TurnoverType:
            case DataType.TurnoverDirection:
            case DataType.Sign:
            case DataType.PaymentMode:
            case DataType.DateTimeInterval:
                if (IsNumeric(value))
                {
                    return(value);
                }
                if (Number.TryParseExpression((string)value, out dbl))
                {
                    return(dbl);
                }
                break;

            default:
                return(string.IsNullOrWhiteSpace((string)value) ? null : value);
            }

            return(null);
        }