Ejemplo n.º 1
0
        private void RefreshTreeTables()
        {
            if (_connection.State != ConnectionState.Open)
            {
                _connection.Open();
            }

            TreeNode root = _treeView.Nodes[0];

            root.Nodes.Clear();

            // Get list of tables and show in tree
            DataTable tables = _connection.GetTables();

            foreach (DataRow row in tables.Rows)
            {
                GarudaPhoenixTable table   = new GarudaPhoenixTable(row);
                TreeNode           nSchema = GetSchemaTreeNode(table.Schema);
                TreeNode           t       = nSchema.Nodes.Add(table.FullName);

                t.Tag                = table;
                t.ImageIndex         = TreeImgNdx.Table;
                t.SelectedImageIndex = t.ImageIndex;
                t.ContextMenuStrip   = _cmsTreeTableMenu;
            }

            root.Expand();

            // Show tables in grid view for now.
            //UpdateDataGrid(tables);
        }
Ejemplo n.º 2
0
        private GarudaPhoenixTable GetTableFromTreeHitTest()
        {
            GarudaPhoenixTable table = null;
            ToolStrip          cms   = _cmsTreeTableMenu;
            Point p       = new Point(cms.Left, cms.Top);
            var   hitTest = _treeView.HitTest(_treeView.PointToClient(p));

            if (hitTest.Node != null)
            {
                table = (GarudaPhoenixTable)hitTest.Node.Tag;
            }

            return(table);
        }
Ejemplo n.º 3
0
 private void _tsmiSelectTop1000_Click(object sender, EventArgs e)
 {
     try
     {
         // Get location of context menu. This cooresponds to the point underwhich
         // is the node we care about.
         GarudaPhoenixTable table = GetTableFromTreeHitTest();
         if (null != table)
         {
             // If there is a node at this location, use it's name for the query.
             QueryView qv = NewQueryViewTab(null, null);
             qv.Text = string.Format("SELECT * FROM {0} LIMIT 1000", table.FullName);
             qv.ExecuteQuery();
         }
     }
     catch (Exception ex)
     {
         HandleException(ex);
     }
 }
Ejemplo n.º 4
0
        private async void _tsmiTableScriptInsert_Click(object sender, EventArgs e)
        {
            try
            {
                // Get location of context menu. This cooresponds to the point underwhich
                // is the node we care about.
                GarudaPhoenixTable table = GetTableFromTreeHitTest();
                if (null != table)
                {
                    string strUpsert = await table.GenerateUpsertStatementAsync(this._connection);

                    // Open a new query view tab and set the text.
                    QueryView qv = NewQueryViewTab(null, null);
                    qv.Text = strUpsert;
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }
Ejemplo n.º 5
0
        private async void _tsmiTableScriptCreate_Click(object sender, EventArgs e)
        {
            try
            {
                // Get location of context menu. This cooresponds to the point underwhich
                // is the node we care about.
                GarudaPhoenixTable table = GetTableFromTreeHitTest();
                if (null != table)
                {
                    DataTable columns = await table.GetColumnsAsync(_connection, true);

                    using (IDbCommand cmd = _connection.CreateCommand())
                    {
                        cmd.CommandText = string.Format("SELECT * FROM {0} LIMIT 0", table.FullName);
                        using (IDataReader dr = cmd.ExecuteReader())
                        {
                            DataTable schemaTable = dr.GetSchemaTable();

                            StringBuilder sbCreate = new StringBuilder();
                            sbCreate.AppendFormat("CREATE TABLE {0} (", table.FullName);
                            sbCreate.AppendLine();
                            for (int i = 0; i < schemaTable.Rows.Count; i++)
                            {
                                DataRow col      = schemaTable.Rows[i];
                                string  dataType = dr.GetDataTypeName(i);
                                string  colName  = col["ColumnName"].ToString();
                                bool    isPK     = table.IsColumnPrimaryKey(columns, colName);

                                if (i > 0)
                                {
                                    sbCreate.AppendLine(",");
                                }

                                // Column name and data type, with size for varchars
                                sbCreate.AppendFormat("\t{0} {1}", colName, dataType);
                                if ("VARCHAR" == dataType)
                                {
                                    sbCreate.AppendFormat("({0})", col["ColumnSize"]);
                                }

                                // Nullable?
                                if (!Convert.ToBoolean(col["AllowDBNull"]))
                                {
                                    sbCreate.AppendFormat(" NOT");
                                }
                                sbCreate.AppendFormat(" NULL");

                                // Primary key?
                                if (isPK)
                                {
                                    sbCreate.Append(" PRIMARY KEY");
                                }
                            }
                            sbCreate.AppendLine();
                            sbCreate.AppendFormat(")");

                            // Open a new query view tab and set the text.
                            QueryView qv = NewQueryViewTab(null, null);
                            qv.Text = sbCreate.ToString();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }