// 添加到设计界面 private void toolStripMenuItem1_Click(object sender, EventArgs e) { if (tvw.SelectedNode != null) { string schemaName = tvw.SelectedNode.Text; MySQLSchema mysqlSchema = _SelectedFields.Find(t => t.tbname.Equals(schemaName, StringComparison.CurrentCultureIgnoreCase)); if (splitContainer1.Panel1.Controls.Find(mysqlSchema.tbnick, false).Length > 0) { return; } UC_Table uctable = new UC_Table(mysqlSchema); uctable.Name = mysqlSchema.tbnick; uctable.Close += Uctable_Close; uctable.ClickField += Uctable_ClickField; uctable.AddJoin += Uctable_AddJoin; splitContainer1.Panel1.Controls.Add(uctable); if (uctable.IsAccessible == false) { uctable.BringToFront(); } BuildSelect(); AddSubMenu(); } }
private void Uctable_ClickField(string tbname, string fieldname, bool clicked) { // 更新选择状态 MySQLSchema mysqlSchema = _SelectedFields.Find(t => t.tbname.Equals(tbname, StringComparison.CurrentCultureIgnoreCase)); mysqlSchema.tbfields.Find(x => x.FieldName.Equals(fieldname, StringComparison.CurrentCultureIgnoreCase)).Checked = clicked; Application.DoEvents(); BuildSQL(); }
public UC_Table(MySQLSchema mysqlSchema) { InitializeComponent(); this.mysqlSchema = mysqlSchema; this.tipInfo.Text = mysqlSchema.tbname + "(" + mysqlSchema.tbnick + ")"; int flagPos = this.tipInfo.Text.IndexOf("("); if (flagPos != -1) { this.tipInfo.LinkArea = new LinkArea(flagPos + 1, this.tipInfo.Text.Length - flagPos - 2); } checkedListBox1.Items.Clear(); foreach (MySQLField sqlField in mysqlSchema.tbfields) { checkedListBox1.Items.Add(sqlField.FieldName); } }
private void tvw_AfterSelect(object sender, TreeViewEventArgs e) { mysqlFields.Clear(); tbx_TableName.Text = e.Node.Text; dt.Rows.Clear(); //dgv.Rows.Clear(); MySqlConnection dbConn = new MySqlConnection(); try { dbConn.ConnectionString = getConnectionString(); dbConn.Open(); string schemaName = e.Node.Text; MySqlCommand dbCmd = new MySqlCommand(); dbCmd.CommandText = "SHOW full COLUMNS FROM " + schemaName; dbCmd.Connection = dbConn; MySqlDataAdapter dbAdapter = new MySqlDataAdapter(dbCmd); dbAdapter.Fill(dt); dt.TableName = Guid.NewGuid().ToString().Replace("-", ""); dgv.DataSource = dt; List <MySQLField> _addFields = new List <MySQLField>(); foreach (DataRow row in dt.Rows) { MySQLField field = new MySQLField(); field.FieldName = row["field"].ToString(); field.Type = row["type"].ToString(); field.Key = row["key"].ToString(); field.Comment = row["comment"].ToString(); mysqlFields.Add(field); _addFields.Add(field); } if (_SelectedFields.Exists(t => t.tbname.Equals(schemaName, StringComparison.CurrentCultureIgnoreCase)) == false) { string tpnick = "a"; //NickIndex index = nickIndex.Find(t => t.Name.Equals(schemaName)); //if(index == null) { // index = new NickIndex(); // index.Name = schemaName; // index.Index = newNickIndex++; // nickIndex.Add(index); //} //tpnick += index.Index; MySQLSchema mysqlSchema = new MySQLSchema(); mysqlSchema.tbname = schemaName; mysqlSchema.tbnick = tpnick; mysqlSchema.tbfields = _addFields; _SelectedFields.Add(mysqlSchema); } //if(_SelectedFields.ContainsKey(e.Node.Text)== false) { // _SelectedFields.Add(e.Node.Text,_addFields); //} //if(e.Node.Tag == null) { // e.Node.Tag = mysqlFields; //} } catch (Exception exc) { Console.WriteLine(exc.ToString()); } finally { dbConn.Close(); dbConn = null; } if (tabControl2.SelectedTab == tp_selectBuilder && e.Node.Level >= 1) { contextMenuStrip1.Show(tvw, tvw.PointToClient(MousePosition)); } }