Esempio n. 1
0
        public void SqlBuilderTestString()
        {
            SqlResultBuilder builder = SqlResultBuilder.NewInstance(5);

            builder.SetColumnType(0, "nvarchar");
            builder.SetColumnType(1, "nvarchar");
            builder.SetColumnType(2, "nvarchar");
            builder.SetColumnType(3, "nvarchar");
            builder.SetColumnType(4, "nvarchar");

            builder.SetColumnName(0, "Col-0");
            builder.SetColumnName(1, "Col-1");
            builder.SetColumnName(2, "Col-2");
            builder.SetColumnName(3, "Col-3");
            builder.SetColumnName(4, "Col-4");

            builder.PushRow();
            builder.AddValue("R0-C0");
            builder.AddValue("R0-C1");
            builder.AddValue("R0-C2");
            builder.AddValue("R0-C3");
            builder.AddValue("R0-C4");
            builder.PopRow();

            builder.PushRow();
            builder.AddValue("R1-C0");
            builder.AddValue("R1-C1");
            builder.AddValue("R1-C2");
            builder.AddValue("R1-C3");
            builder.AddValue("R1-C4");
            builder.PopRow();

            builder.PushRow();
            builder.AddValue("R2-C0");
            builder.AddValue("R2-C1");
            builder.AddValue("R2-C2");
            builder.AddValue("R2-C3");
            builder.AddValue("R2-C4");
            builder.PopRow();

            ISqlResultSet result = builder.Build();

            Assert.IsTrue(result.GetColumnCount() == 5, "Column count is not equal to 5!");
            Assert.IsTrue(result.GetRowCount() == 3, "Row count is not equal to 5!");

            for (int i = 0; i < result.GetColumnCount(); i++)
            {
                string expected0 = "Col-" + i;
                string actual0   = result.GetColumnName(i);
                Assert.IsTrue(expected0.Equals(actual0), "Expected value{0}, current value {1}", expected0, actual0);

                for (int j = 0; j < result.GetRowCount(); j++)
                {
                    string actual1   = result.GetValue(i, j).AsString();
                    string expected1 = "R" + j + "-C" + i;
                    Assert.IsTrue(expected1.Equals(actual1), "Expected value{0}, current value {1}", expected1, actual1);
                }
            }
        }
Esempio n. 2
0
        public static SimpleHTMLTable FromSqlResult(ISqlResultSet result, int startRow, int size)
        {
            SimpleHTMLTable table = new SimpleHTMLTable(result.GetColumnCount(), size);

            for (int i = 0; i < table.GetColumnCount(); i++)
            {
                table._columnNames[i] = result.GetColumnName(i);
            }

            for (int i = 0; i < table.GetColumnCount(); i++)
            {
                for (int j = 0; j < size; j++)
                {
                    table._values[j, i] = result.GetValue(i, startRow + j).AsString();
                }
            }
            return(table);
        }
        private Grid CreateGridFromResultSet(ISqlResultSet dataset)
        {
            int columns = dataset.GetColumnCount();
            int rows    = dataset.GetRowCount();

            Grid grid = new Grid();

            for (int i = 0; i < columns; i++)
            {
                grid.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = GridLength.Auto
                });
            }

            for (int i = 0; i < rows + 1; i++)
            {
                grid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });
            }

            Thickness partialThickness = new Thickness(0, 0, 1, 1);
            Thickness topThickness     = new Thickness(0, 1, 1, 1);
            Thickness leftThickness    = new Thickness(1, 0, 1, 1);
            Thickness fullThickness    = new Thickness(1, 1, 1, 1);

            for (int i = 0; i < columns; i++)
            {
                string colName = dataset.GetColumnName(i);
                Border border  = new Border()
                {
                    BorderBrush = Brushes.Black, BorderThickness = i == 0 ? fullThickness : topThickness, Background = Brushes.Gray
                };
                border.SetValue(Grid.ColumnProperty, i);
                border.SetValue(Grid.RowProperty, 0);
                TextBlock textBlock = new TextBlock()
                {
                    Text = colName, Padding = new Thickness(5)
                };
                border.Child = textBlock;
                grid.Children.Add(border);
            }

            for (int i = 0; i < columns; i++)
            {
                for (int j = 0; j < rows; j++)
                {
                    Border border = new Border()
                    {
                        BorderBrush = Brushes.Black, BorderThickness = i == 0 ? leftThickness : partialThickness
                    };
                    border.SetValue(Grid.ColumnProperty, i);
                    border.SetValue(Grid.RowProperty, j + 1);

                    string    text      = dataset.GetValue(i, j).AsString();
                    TextBlock textBlock = new TextBlock()
                    {
                        Text = text, Padding = new Thickness(5)
                    };
                    border.Child = textBlock;
                    grid.Children.Add(border);
                }
            }

            return(grid);
        }