Exemplo n.º 1
0
        public TableColumn GetNextColumnAfter(TableColumn tc, out bool leftRow)
        {
            bool foundColumn = false;
            leftRow = false;

            foreach (var cg in ColumnGroups)
            {
                foreach (var c in cg.Columns)
                {
                    if (foundColumn)
                    {
                        return c;
                    }

                    if (c.Title == tc.Title)
                    {
                        foundColumn = true;
                    }
                }
            }

            if (foundColumn)
            {
                leftRow = true;
                return ColumnGroups[0].Columns[0];
            }

            throw new Exception("Supplied column is not in list of columns");
        }
Exemplo n.º 2
0
        public void StartTable(TableStructure tableStructure)
        {
            _structure = tableStructure;
            _firstColumn = tableStructure.ColumnGroups.First().Columns.First();

            if (_structure.GetAllColumns().Any(c => c.Title.Length > 0))
            {
                _sw.WriteLine(string.Join(",", _structure.ColumnGroups.SelectMany(cg => cg.Columns).Select(c => c.Title).ToArray()));
            }
        }
Exemplo n.º 3
0
        public static string RenderValue(TableColumn tableColumn, object value)
        {
            if (value == null) return "null";

            if (tableColumn.FormatSpecifier != null)
            {
                Type t = value.GetType();

                if (t == typeof(long))
                {
                    return ((long)value).ToString(tableColumn.FormatSpecifier);
                }

                if (t == typeof(int))
                {
                    return ((int)value).ToString(tableColumn.FormatSpecifier);
                }

                if (t == typeof(float))
                {
                    return ((float)value).ToString(tableColumn.FormatSpecifier);
                }

                if (t == typeof(decimal))
                {
                    return ((decimal)value).ToString(tableColumn.FormatSpecifier);
                }

                if (t == typeof(double))
                {
                    return ((double)value).ToString(tableColumn.FormatSpecifier);
                }

                throw new Exception("Unable to apply format specifier ('" + tableColumn.FormatSpecifier + "') to value of type '" + t.FullName + "'");
            }

            return value.ToString();
        }
Exemplo n.º 4
0
        private string BuildCellCss(TableColumn column)
        {
            if (column.HorizontalAlignment == HorizontalAlignment.Right)
            {
                return "text-align: right;";
            }

            return "";
        }
Exemplo n.º 5
0
        public void WriteCell(TableColumn column, object value)
        {
            string renderedString = TableWriterHelper.RenderValue(column, value);

            _tw.WriteLine("<td style=\"" + BuildCellCss(column) + "\">" + HttpUtility.HtmlEncode(renderedString) + "</td>");
        }
Exemplo n.º 6
0
        public void WriteCell(TableColumn column, object value)
        {
            if (column != _firstColumn)
            {
                _sw.Write(",");
            }

            _sw.Write(value);
        }
Exemplo n.º 7
0
 public void WriteCell(TableColumn column, object value)
 {
     foreach (var target in _targets) target.WriteCell(column, value);
 }
Exemplo n.º 8
0
        public void WriteCell(TableColumn column, object value)
        {
            string renderedString = TableWriterHelper.RenderValue(column, value);

            // If this is the first column in a group other than the first, then write a separator
            if (_structure.ColumnGroups.Skip(1).Any(cg => cg.Columns[0] == column))
            {
                _textWriter.Write(_borderCharacterSet.Vertical);
            }

            // Pad left
            _textWriter.Write("".PadLeft(_cellHorizontalPadding));

            // Write no more than columnWidth characters
            string toWrite = renderedString;

            if (toWrite.Length > column.Width)
            {
                if (column.Width < 3)
                {
                    toWrite = toWrite.Substring(0, column.Width);
                }
                else
                {
                    toWrite = toWrite.Substring(0, column.Width - 3) + "...";
                }
            }

            switch (column.HorizontalAlignment)
            {
                case HorizontalAlignment.Right:
                    _textWriter.Write(toWrite.PadLeft(column.Width));
                    break;
                case HorizontalAlignment.Left:
                    _textWriter.Write(toWrite.PadRight(column.Width));
                    break;
                case HorizontalAlignment.Centre:
                    _textWriter.Write(toWrite.Centre(column.Width));
                    break;
            }

            // Pad right
            _textWriter.Write("".PadLeft(_cellHorizontalPadding));
        }