dataGridView1.ReadOnly = true; int count = dataGridView1.RowCount; if (count > 1) { DataGridViewRow dr = dataGridView1.Rows[count - 1]; string sql; if ((string)dataGridView1.Rows[0].Cells[1].Value == "RANGE") sql = "alter table " + this.label1.Text + " add partition (PARTITION " + dr.Cells[2].Value + " VALUES LESS THAN " + dr.Cells[3].Value + ")"; else sql = "alter table " + this.label1.Text + " add partition (PARTITION " + dr.Cells[2].Value + " VALUES IN " + dr.Cells[3].Value + ")"; //Console.WriteLine("=sql====" + sql); this.button4.Text = "新建"; try { cmdupdate(sql); } catch (Exception e2) { MessageBox.Show("分区名或分区值输入错误!"); } } } private void button7_Click(object sender, EventArgs e) { Application.Exit(); } private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { TreeNode tn = e.Node; if (tn.GetNodeCount(false) == 0) { string table = tn.Text; string schemata = tn.Parent.Text; MySqlConnection conn = new MySqlConnection(Common.myConnectionString); conn.Open(); string sqlStr = "SHOW CREATE TABLE "+schemata+"."+table; MySqlDataAdapter Mda = new MySqlDataAdapter(sqlStr, conn); DataSet Ds = new DataSet(); Mda.Fill(Ds, "test1"); string str = Ds.Tables["test1"].Rows[0][1].ToString(); Console.WriteLine(str); string flag = "/*!50100 PARTITION BY "; if (str.IndexOf(flag) == -1) { MessageBox.Show(table+"表没有分区!"); return; } int start = str.IndexOf(flag) + flag.Length; string str2 = str.Substring(start); int end = str2.IndexOf("("); string partType = str2.Substring(0, end - 1); int end2 = str2.IndexOf("\n(PARTITION"); if (end2 == -1) { MessageBox.Show(table + "表不是RANGE或LIST分区!"); return; } String partRow = str2.Substring(end+1,end2-8); str2 = str2.Substring(end2 + 12); //range :test9 //名:strs[0],strs[9x] //范围:strs[4],strs[4+9x] //list :test3 //名:strs[2].strs[2+8x] //范围:strs[5],strs[5+8x] if (partType == "RANGE") { this.label1.Text = schemata + "." + table; string[] strs = str2.Split(' '); int row = strs.Length / 9; this.dataGridView1.AutoGenerateColumns = true; this.dataGridView1.RowCount = row; this.dataGridView1.ColumnCount = 4; Common.headerPart(this.dataGridView1); for (int i = 0; i < row; i++) { dataGridView1.Rows[i].Cells[0].Value = partRow; dataGridView1.Rows[i].Cells[1].Value = partType; dataGridView1.Rows[i].Cells[2].Value = strs[9 * i]; dataGridView1.Rows[i].Cells[3].Value = strs[4 + 9 * i]; } } else if (partType == "LIST") { this.label1.Text = schemata + "." + table; string[] strs = str2.Split(' '); int row = strs.Length / 8 ; this.dataGridView1.AutoGenerateColumns = true; this.dataGridView1.RowCount = row; this.dataGridView1.ColumnCount = 4; Common.headerPart(this.dataGridView1); for (int i = 0; i < row; i++) { dataGridView1.Rows[i].Cells[0].Value = partRow; dataGridView1.Rows[i].Cells[1].Value = partType; dataGridView1.Rows[i].Cells[2].Value = strs[8 * i]; dataGridView1.Rows[i].Cells[3].Value = strs[3 + 8 * i]; } } else { MessageBox.Show(table+"表不是RANGE或LIST分区!"); } } else { tn.Expand(); } } } } public static void headerPart(DataGridView dataGridView1) { dataGridView1.Columns[0].HeaderText = "分区列"; dataGridView1.Columns[1].HeaderText = "分区类型"; dataGridView1.Columns[2].HeaderText = "分区名称"; dataGridView1.Columns[3].HeaderText = "分区值"; }
|