/*delete table*/ private void deleteDropToolStripMenuItem1_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("Are you sure you want to drop table " + treeView1.SelectedNode.Text, "DROP Table?", MessageBoxButtons.OKCancel); if (dr == DialogResult.OK) { var cmd = new NpgsqlCommand("drop table " + treeView1.SelectedNode.Text + ";", tvc.EsConOnTable2(treeView1.SelectedNode)); cmd.ExecuteNonQuery(); treeView1.SelectedNode.Remove(); this.Refresh(); } else if (dr == DialogResult.Cancel) { } }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { TreeviewController tvc = new TreeviewController(this.treeView1); if (this.treeView1.SelectedNode.Name == "db") { Control.connection.SqlConn.Close(); Control.connection.SqlConn = tvc.EsConOnDataBase(this.treeView1.SelectedNode); } if (this.treeView1.SelectedNode.Name == "sc") { Control.connection.SqlConn.Close(); Control.connection.SqlConn = tvc.EsConOnSchemas(this.treeView1.SelectedNode); String sel_table = "select * from information_schema.tables;"; // Control.background.tableName = this.treeView1.SelectedNode.Text; NpgsqlCommand command = new NpgsqlCommand(sel_table, Control.connection.SqlConn); // Control.connection.SqlConn.Open(); try { command.ExecuteNonQuery(); NpgsqlDataAdapter npgsql = new NpgsqlDataAdapter(sel_table, Control.connection.SqlConn); Control.connection.ds = new DataSet(); npgsql.Fill(Control.connection.ds); //Control.connection.SqlConn.Close(); Control.background2.GetDataGridView1().DataSource = null; Control.background2.GetDataGridView1().EditMode = DataGridViewEditMode.EditOnEnter; Control.background2.GetDataGridView1().DataSource = Control.connection.ds; Control.background2.GetDataGridView1().DataMember = Control.connection.ds.Tables[0].TableName; Control.background2.GetDataGridView1().EnableHeadersVisualStyles = false; Control.background2.GetDataGridView1().ColumnHeadersDefaultCellStyle.Font = new Font("隶书", 9, FontStyle.Italic); Control.background2.GetDataGridView1().ColumnHeadersDefaultCellStyle.ForeColor = Color.Purple; //Control.background2.SetFormerNum(Control.background2.GetDataGridView1().ColumnCount); } catch (Exception ee) { MessageBox.Show("请检查您的指令!\ntips:" + ee.Message); } String sel_table2 = "select * from information_schema.columns;"; // Control.background.tableName = this.treeView1.SelectedNode.Text; NpgsqlCommand command2 = new NpgsqlCommand(sel_table2, Control.connection.SqlConn); // Control.connection.SqlConn.Open(); try { command2.ExecuteNonQuery(); NpgsqlDataAdapter npgsql = new NpgsqlDataAdapter(sel_table2, Control.connection.SqlConn); Control.connection.ds = new DataSet(); npgsql.Fill(Control.connection.ds); //Control.connection.SqlConn.Close(); Control.background2.GetDataGridView2().DataSource = null; Control.background2.GetDataGridView2().EditMode = DataGridViewEditMode.EditOnEnter; Control.background2.GetDataGridView2().DataSource = Control.connection.ds; Control.background2.GetDataGridView2().DataMember = Control.connection.ds.Tables[0].TableName; Control.background2.GetDataGridView2().EnableHeadersVisualStyles = false;//这样就可以使用当前的主题的样式了,这句话十分关键! Control.background2.GetDataGridView2().ColumnHeadersDefaultCellStyle.Font = new Font("隶书", 9, FontStyle.Italic); Control.background2.GetDataGridView2().ColumnHeadersDefaultCellStyle.ForeColor = Color.Purple; //Control.background2.SetFormerNum(Control.background2.GetDataGridView1().ColumnCount); } catch (Exception ee) { MessageBox.Show("请检查您的指令!\ntips:" + ee.Message); } } if (this.treeView1.SelectedNode.Text == "Table") { Control.connection.SqlConn.Close(); Control.connection.SqlConn = tvc.EsConOnTable1(this.treeView1.SelectedNode); // // } if (this.treeView1.SelectedNode.Name == "tb") { Control.connection.SqlConn.Close(); Control.connection.SqlConn = tvc.EsConOnTable2(this.treeView1.SelectedNode); String sel_table = "select * from " + this.treeView1.SelectedNode.Text; Control.background.tableName = this.treeView1.SelectedNode.Text; NpgsqlCommand command = new NpgsqlCommand(sel_table, Control.connection.SqlConn); // Control.connection.SqlConn.Open(); try { command.ExecuteNonQuery(); NpgsqlDataAdapter npgsql = new NpgsqlDataAdapter(sel_table, Control.connection.SqlConn); Control.connection.ds = new DataSet(); npgsql.Fill(Control.connection.ds); //Control.connection.SqlConn.Close(); Control.background.FullFilDataGrid(); //Control.background.GetDataGridView().DataMember = Control.connection.ds.Tables[0].TableName; Control.background.GetDataGridView().EnableHeadersVisualStyles = false;//这样就可以使用当前的主题的样式了,这句话十分关键! Control.background.GetDataGridView().ColumnHeadersDefaultCellStyle.Font = new Font("隶书", 9, FontStyle.Italic); Control.background.GetDataGridView().ColumnHeadersDefaultCellStyle.ForeColor = Color.Purple; Control.background.SetFormerNum(Control.background.GetDataGridView().ColumnCount); } catch (Exception ee) { MessageBox.Show("请检查您的指令!\ntips:" + ee.Message); } } if (this.treeView1.SelectedNode.Name == "con") { Control.connection.SqlConn.Close(); Control.connection.SqlConn = tvc.EsConOnColumn(this.treeView1.SelectedNode); } }