Ejemplo n.º 1
0
        public void LoadTable(SqliteDb newDatabase, string tableName)
        {
            this.Name = tableName;
            this.SetDatabase(newDatabase);

            DataGridTableStyle tableStyle = new DataGridTableStyle();

            tableStyle.MappingName = tableName;
            if (tableName == "TestCase")
            {
                tableStyle.PreferredRowHeight *= 3;
            }
            else if (tableName == "ApiTestResults" || tableName == "HttpTestResults")
            {
                tableStyle.PreferredRowHeight *= 2;
            }

            int gridWidth = 0;

            vm = new SqliteVm(database, true);
            if (vm != null)
            {
                dataTable = new DataTable(tableName);

                string sql   = String.Format("select rowid, * from {0} ;", tableName);
                int    sqErr = vm.Execute(sql);
                int    nCols = vm.NumCols();

                for (int i = 0; i < nCols; i++)
                {
                    string colName = vm.ColumnName(i);
                    string colType = vm.ColumnType(colName);
                    DataGridTextBoxColumn colStyle = new DataGridTextBoxColumn();
                    colStyle.MappingName = colName;
                    colStyle.HeaderText  = colName;

                    switch (colType.ToUpper())
                    {
                    case "INTEGER":
                        dataTable.Columns.Add(colName, typeof(int));
                        colStyle.Width = 60;
                        break;

                    case "REAL":
                        dataTable.Columns.Add(colName, typeof(double));
                        colStyle.Width = 60;
                        break;

                    case "TEXT":
                        dataTable.Columns.Add(colName, typeof(string));
                        colStyle.TextBox.Multiline = true;
                        if (colName == "ParamName" || colName == "ContentType" || colName == "TestType" || colName == "Prerequisite")
                        {
                            colStyle.Width = 100;
                        }
                        else if (colName == "ParamValue")
                        {
                            colStyle.Width = 275;
                        }
                        else
                        {
                            colStyle.Width = 200;
                        }
                        break;

                    case "BLOB":
                        DataColumn col = new DataColumn(colName, typeof(SqlBinary));
                        col.ReadOnly = true;
                        dataTable.Columns.Add(col);
                        colStyle.Width = 150;
                        break;

                    default:
                        colStyle = null;
                        break;
                    }

                    if (colStyle != null)
                    {
                        tableStyle.GridColumnStyles.Add(colStyle);
                        gridWidth += colStyle.Width;
                    }
                }


                //rowid should be readonly
                dataTable.Columns[0].ReadOnly = true;

                // update grid with new cols and width
                dataGrid1.TableStyles.Add(tableStyle);
                dataGrid1.Width = gridWidth;

                while (sqErr == Sqlite.Row)
                {
                    object [] cols = new object[nCols];

                    for (int i = 0; i < nCols; i++)
                    {
                        string colName = vm.ColumnName(i);
                        string colType = vm.ColumnType(colName);
                        switch (colType.ToUpper())
                        {
                        case "INTEGER":
                            int colInt = vm.GetInt(colName);
                            cols[i] = colInt;
                            break;

                        case "REAL":
                            double colDbl = vm.GetDouble(colName);
                            cols[i] = colDbl;
                            break;

                        case "TEXT":
                            string colText = vm.GetString(colName);
                            cols[i] = colText;
                            break;

                        case "BLOB":
                            byte[] bytes = vm.GetBlob(colName).Read();
                            if (bytes != null)
                            {
                                SqlBinary binBlob = new SqlBinary(bytes);
                                cols[i] = binBlob;
                            }
                            else
                            {
                                cols[i] = null;
                            }
                            break;

                        default:
                            break;
                        }
                    }

                    dataTable.Rows.Add(cols);
                    sqErr = vm.NextRow();
                }
            }

            vm.SqlFinalize();
            vm = null;
            dataTable.AcceptChanges();

            dataGrid1.DataSource = dataTable;
            this.Width           = gridWidth + 75;
        }
Ejemplo n.º 2
0
        public void LoadTable(SqliteDb newDatabase, string tableName)
        {
            this.Name = tableName;
            this.SetDatabase(newDatabase);

            DataGridTableStyle tableStyle = new DataGridTableStyle();
            tableStyle.MappingName = tableName;
            if (tableName == "TestCase")
            {
                tableStyle.PreferredRowHeight *= 3;
            }
            else if (tableName == "ApiTestResults" || tableName == "HttpTestResults")
            {
                tableStyle.PreferredRowHeight *= 2;
            }

            int gridWidth = 0;

            vm = new SqliteVm(database, true);
            if (vm != null)
            {
                dataTable = new DataTable(tableName);

                string sql = String.Format("select rowid, * from {0} ;", tableName);
                int sqErr = vm.Execute(sql);
                int nCols = vm.NumCols();

                for (int i = 0; i<nCols; i++)
                {
                    string colName = vm.ColumnName(i);
                    string colType = vm.ColumnType(colName);
                    DataGridTextBoxColumn colStyle = new DataGridTextBoxColumn();
                    colStyle.MappingName = colName;
                    colStyle.HeaderText = colName;

                    switch (colType.ToUpper())
                    {
                        case "INTEGER":
                            dataTable.Columns.Add(colName, typeof(int));
                            colStyle.Width = 60;
                            break;
                        case "REAL":
                            dataTable.Columns.Add(colName, typeof(double));
                            colStyle.Width = 60;
                            break;
                        case "TEXT":
                            dataTable.Columns.Add(colName, typeof(string));
                            colStyle.TextBox.Multiline = true;
                            if (colName == "ParamName" || colName == "ContentType" || colName == "TestType" || colName == "Prerequisite")
                            {
                                colStyle.Width = 100;
                            }
                            else if (colName == "ParamValue")
                            {
                                colStyle.Width = 275;
                            }
                            else
                            {
                                colStyle.Width = 200;
                            }
                            break;

                        case "BLOB":
                            DataColumn col = new DataColumn(colName, typeof(SqlBinary));
                            col.ReadOnly = true;
                            dataTable.Columns.Add(col);
                            colStyle.Width = 150;
                            break;
                        default:
                            colStyle = null;
                            break;
                    }

                    if (colStyle != null)
                    {
                        tableStyle.GridColumnStyles.Add(colStyle);
                        gridWidth += colStyle.Width;
                    }
                }

                //rowid should be readonly
                dataTable.Columns[0].ReadOnly = true;

                // update grid with new cols and width
                dataGrid1.TableStyles.Add(tableStyle);
                dataGrid1.Width = gridWidth;

                while (sqErr == Sqlite.Row)
                {
                    object [] cols = new object[nCols];

                    for (int i=0; i<nCols; i++)
                    {
                        string colName = vm.ColumnName(i);
                        string colType = vm.ColumnType(colName);
                        switch (colType.ToUpper())
                        {
                            case "INTEGER":
                                int colInt = vm.GetInt(colName);
                                cols[i] = colInt;
                                break;
                            case "REAL":
                                double colDbl = vm.GetDouble(colName);
                                cols[i] = colDbl;
                                break;
                            case "TEXT":
                                string colText = vm.GetString(colName);
                                cols[i] = colText;
                                break;
                            case "BLOB":
                                byte[] bytes = vm.GetBlob(colName).Read();
                                if (bytes != null)
                                {
                                    SqlBinary binBlob = new SqlBinary(bytes);
                                    cols[i] = binBlob;
                                }
                                else
                                {
                                    cols[i] = null;
                                }
                                break;
                            default:
                                break;
                        }
                    }

                    dataTable.Rows.Add(cols);
                    sqErr = vm.NextRow();
                }
            }

            vm.SqlFinalize();
            vm = null;
            dataTable.AcceptChanges();

            dataGrid1.DataSource = dataTable;
            this.Width = gridWidth+75;
        }