protected override object GenerateCore(Project project, Column column)
        {
            DateTime minimum = Minimum;

            if (this.WellKnownDataType == WellKnownDataType.EndDate)
            {
                DateTime dt;
                if (ConvertUtilities.TryChangeType(project.CurrentRow.GetValue(WellKnownDataType.StartDate), out dt))
                {
                    minimum = dt;
                }
                else if (ConvertUtilities.TryChangeType(project.CurrentRow.GetValue(WellKnownDataType.Date), out dt))
                {
                    minimum = dt;
                }
            }

            var dateTime = Random.NextDateTime(minimum, Maximum);

            if (column.CodeFluentType.DbType == DbType.DateTimeOffset)
            {
                var offset = Random.NextInt32(MinimumOffset, MaximumOffset);
                return(new DateTimeOffset(dateTime, TimeSpan.FromMinutes(offset)));
            }

            return(dateTime);
        }
Esempio n. 2
0
        private Cell AppendCell(Row row, uint rowIndex, uint columnIndex, TableColumn <T> column, T value)
        {
            if (value == null)
            {
                return(null);
            }

            var displayValue = column.GetValue(value);

            if (displayValue == null)
            {
                return(null);
            }

            Cell cell = new Cell();

            cell.CellReference = GetColumnIndex(columnIndex) + rowIndex;

            CellValues datatype;

            if (column.DataType == null)
            {
                datatype = GetDataType(displayValue.GetType());
            }
            else
            {
                datatype = GetDataType(column.DataType);
            }

            switch (datatype)
            {
            case CellValues.Boolean:
                bool boolean;
                if (!ConvertUtilities.TryChangeType(displayValue, column.Culture, out boolean))
                {
                    return(null);
                }

                cell.DataType  = CellValues.Boolean;
                cell.CellValue = new CellValue(BooleanValue.FromBoolean(boolean));
                break;

            case CellValues.Number:
                string number;
                if (!ConvertUtilities.TryChangeType(displayValue, CultureInfo.InvariantCulture, out number))
                {
                    return(null);
                }

                cell.DataType  = CellValues.Number;
                cell.CellValue = new CellValue(number);
                break;

            case CellValues.String:
                string formula;
                if (!ConvertUtilities.TryChangeType(displayValue, column.Culture, out formula))
                {
                    return(null);
                }

                cell.DataType    = CellValues.InlineString;
                cell.CellFormula = new CellFormula(formula);
                break;

            case CellValues.InlineString:
                string text;
                if (!ConvertUtilities.TryChangeType(displayValue, column.Culture, out text))
                {
                    return(null);
                }

                cell.DataType = CellValues.InlineString;
                cell.AppendChild(new InlineString(new Text(text)));
                break;

            case CellValues.Date:
                DateTime datetime;
                if (!ConvertUtilities.TryChangeType(displayValue, column.Culture, out datetime))
                {
                    return(null);
                }

                //cell.DataType = CellValues.Date;
                cell.CellValue  = new CellValue(datetime.ToOADate().ToString(CultureInfo.InvariantCulture));
                cell.StyleIndex = 1;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (column.Format != null)
            {
                cell.StyleIndex = GetStyleIndex(column);
            }

            row.AppendChild(cell);
            return(cell);
        }