@ -66,7 +66,15 @@ namespace WindowsFormsApp1
return ;
} ;
string namespaceName = namespace_name . Text . Trim ( ) ;
var dt = GetDbTableInfo ( tbname ) ;
DataTable dt = null ;
if ( textBox3 . Text . Trim ( ) = = "" )
{
dt = GetDbTableInfo ( tbname ) ;
}
else
{
dt = DbHelperMySQL . Query ( textBox3 . Text . Trim ( ) ) ;
}
var list = new List < string > ( ) ;
txt_ret . Text + = "using System;\n" +
"using NCA_MES_Models.CommonUtils.DB.DBAttribute;\n\n" ;
@ -112,7 +120,15 @@ namespace WindowsFormsApp1
MessageBox . Show ( "请选择表" ) ;
return ;
} ;
var dt = GetDbTableInfo ( tbname ) ;
DataTable dt = null ;
if ( textBox3 . Text . Trim ( ) = = "" )
{
dt = GetDbTableInfo ( tbname ) ;
}
else
{
dt = DbHelperMySQL . Query ( textBox3 . Text . Trim ( ) ) ;
}
string uidatagridview = textBox2 . Text . Trim ( ) ;
textBox1 . Text = "" ;
textBox1 . Text + = $"DataTable data = DbHelperMySQL.Query(\" select * from { tbname } \ ");\n" ;
@ -143,9 +159,17 @@ namespace WindowsFormsApp1
MessageBox . Show ( "请选择表" ) ;
return ;
} ;
var dt = GetDbTableInfo ( tbname ) ;
DataTable dt = null ;
if ( textBox3 . Text . Trim ( ) = = "" )
{
dt = GetDbTableInfo ( tbname ) ;
}
else {
dt = DbHelperMySQL . Query ( textBox3 . Text . Trim ( ) ) ;
}
string uidatagridview = textBox2 . Text . Trim ( ) ;
textBox1 . Text = "" ;
textBox1 . Text = $ "this.{uidatagridview}.AutoGenerateColumns = false; ";
textBox1 . Text + = $" string sql = $\" SELECT column_name , column_comment from information_schema . COLUMNS where table_name = ' { tbname } ' ORDER BY ORDINAL_POSITION ; \ ";\r\n" +
$" DataTable dt = DbHelperMySQL.Query(sql);\n" ;
textBox1 . Text + = "List<DataGridViewColumn> cols = new List<DataGridViewColumn>();\n" ;
@ -153,17 +177,19 @@ namespace WindowsFormsApp1
" DataGridViewTextBoxColumn temp = new DataGridViewTextBoxColumn();\n" +
"temp.Name = dt.Rows[i][0].ToString();\n" +
"temp.HeaderText = dt.Rows[i][1].ToString();\n" +
"temp.DataPropertyName= dt.Rows[i][0].ToString();\n" +
"cols.Add(temp);" +
"}\n" ;
textBox1 . Text + = "DataGridViewButtonColumn editBtn = new DataGridViewButtonColumn();\r\n" +
"editBtn.HeaderText = \"编辑\";\r\n" +
"editBtn.Name = \"edit\";\r\n" +
"editBtn.Name = \"editBtn\";\r\n" +
"editBtn.Text = \"编辑\";\r\n" +
"editBtn.UseColumnTextForButtonValue = true;\r\n" +
"editBtn.Frozen = true;\n" ;
textBox1 . Text + = " DataGridViewButtonColumn addBtn = new DataGridViewButtonColumn();\r\n" +
"addBtn.HeaderText = \" 修改 \";\r\n" +
"addBtn.Name = \" editgd \";\r\n" +
"addBtn.Text = \" editgd \";\r\n" +
"addBtn.HeaderText = \" 新增 \";\r\n" +
"addBtn.Name = \" addBtn \";\r\n" +
"addBtn.Text = \" 新增 \";\r\n" +
"addBtn.UseColumnTextForButtonValue = true;\r\n" +
"addBtn.Frozen = true;\n " ;
textBox1 . Text + = "cols.Add(editBtn);\n cols.Add(addBtn);\n" ;
@ -177,23 +203,7 @@ namespace WindowsFormsApp1
$"this.{uidatagridview}.FirstDisplayedScrollingColumnIndex = this.{uidatagridview}.Columns.Count - 2;\n" ;
textBox1 . Text + = $" {uidatagridview}.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.ColumnHeader;\n" ;
textBox1 . Text + = $"DataTable data = DbHelperMySQL.Query(\" select * from { tbname } \ ");\n" ;
textBox1 . Text + = $"this.{uidatagridview}.Rows.AddRange(data.AsEnumerable().Select(row => {{\r\n" +
"DataGridViewRow dataGridViewRow = new DataGridViewRow();\r\n " +
"DataGridViewButtonCell addCell = new DataGridViewButtonCell();\r\n" +
"addCell.Value = \"新增\";\r\n " +
"dataGridViewRow.Cells.Add(addCell);\r\n " +
"DataGridViewButtonCell editCell = new DataGridViewButtonCell();\r\n" +
"editCell.Value = \"修改\";\r\n " +
"dataGridViewRow.Cells.Add(editCell);\r\n " +
"foreach (var item in row.ItemArray.Reverse())\r\n " +
"{\r\n" +
"DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();\r\n" +
"cell.Value = item;\r\n " +
"dataGridViewRow.Cells.Add(cell);\r\n" +
"}\r\n" +
"dataGridViewRow.Height = 40;\r\n" +
"return dataGridViewRow;\r\n" +
"}).ToArray());" ;
textBox1 . Text + = $"this.{uidatagridview}.DataSource = data;\n" ;
}
private void button4_Click ( object sender , EventArgs e )
@ -204,9 +214,18 @@ namespace WindowsFormsApp1
MessageBox . Show ( "请选择表" ) ;
return ;
} ;
var dt = GetDbTableInfo ( tbname ) ;
DataTable dt = null ;
if ( textBox3 . Text . Trim ( ) = = "" )
{
dt = GetDbTableInfo ( tbname ) ;
}
else {
dt = DbHelperMySQL . Query ( textBox3 . Text . Trim ( ) ) ;
}
string uidatagridview = textBox2 . Text . Trim ( ) ;
textBox1 . Text = "" ;
textBox1 . Text = $ "this.{uidatagridview}.AutoGenerateColumns = false; ";
textBox1 . Text + = "List<DataGridViewColumn> cols = new List<DataGridViewColumn>();\n" ;
for ( int i = 0 ; i < dt . Rows . Count ; i + + )
{
@ -215,19 +234,21 @@ namespace WindowsFormsApp1
textBox1 . Text + = $"DataGridViewTextBoxColumn {Name}Cloumn = new DataGridViewTextBoxColumn();\n" ;
textBox1 . Text + = $"{Name}Cloumn.Name = \" { Name } \ ";" +
$"{Name}Cloumn.HeaderText =\" { IsNullable } \ ";" +
$"{Name}Cloumn.DataPropertyName = \" { Name } \ ";" +
$"cols.Add({Name}Cloumn);\n" ;
}
textBox1 . Text + = "DataGridViewButtonColumn editBtn = new DataGridViewButtonColumn();\r\n" +
"editBtn.HeaderText = \"编辑\";\r\n" +
"editBtn.Name = \"edit\";\r\n" +
"editBtn.UseColumnTextForButtonValue = true;\r\n" +
"editBtn.Frozen = true;\n" ;
"editBtn.HeaderText = \"编辑\";\r\n" +
"editBtn.Name = \"editBtn\";\r\n" +
"editBtn.Text = \"编辑\";\r\n" +
"editBtn.UseColumnTextForButtonValue = true;\r\n" +
"editBtn.Frozen = true;\n" ;
textBox1 . Text + = " DataGridViewButtonColumn addBtn = new DataGridViewButtonColumn();\r\n" +
"addBtn.HeaderText = \"修改 \";\r\n" +
"addBtn.Name = \"editgd \";\r\n" +
"addBtn.Text = \"editgd \";\r\n" +
"addBtn.UseColumnTextForButtonValue = true;\r\n" +
"addBtn.Frozen = true;\n " ;
"addBtn.HeaderText = \"新增 \";\r\n" +
"addBtn.Name = \"addBtn \";\r\n" +
"addBtn.Text = \"新增 \";\r\n" +
"addBtn.UseColumnTextForButtonValue = true;\r\n" +
"addBtn.Frozen = true;\n " ;
textBox1 . Text + = "cols.Add(editBtn);\n cols.Add(addBtn);\n" ;
textBox1 . Text + = "if (cols.Last().Frozen)\r\n" +
"{\r\n " +
@ -239,23 +260,24 @@ namespace WindowsFormsApp1
$"this.{uidatagridview}.FirstDisplayedScrollingColumnIndex = this.{uidatagridview}.Columns.Count - 2;\n" ;
textBox1 . Text + = $" {uidatagridview}.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.ColumnHeader;\n" ;
textBox1 . Text + = $"DataTable data = DbHelperMySQL.Query(\" select * from { tbname } \ ");\n" ;
textBox1 . Text + = $"this.{uidatagridview}.Rows.AddRange(data.AsEnumerable().Select(row => {{\r\n" +
"DataGridViewRow dataGridViewRow = new DataGridViewRow();\r\n " +
"DataGridViewButtonCell addCell = new DataGridViewButtonCell();\r\n" +
"addCell.Value = \"新增\";\r\n " +
"dataGridViewRow.Cells.Add(addCell);\r\n " +
"DataGridViewButtonCell editCell = new DataGridViewButtonCell();\r\n" +
"editCell.Value = \"修改\";\r\n " +
"dataGridViewRow.Cells.Add(editCell);\r\n " +
"foreach (var item in row.ItemArray.Reverse())\r\n " +
"{\r\n" +
"DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();\r\n" +
"cell.Value = item;\r\n " +
"dataGridViewRow.Cells.Add(cell);\r\n" +
"}\r\n" +
"dataGridViewRow.Height = 40;\r\n" +
"return dataGridViewRow;\r\n" +
"}).ToArray());" ;
textBox1 . Text + = $"this.{uidatagridview}.DataSource = data;\n" ;
/ * textBox1 . Text + = $"this.{uidatagridview}.Rows.AddRange(data.AsEnumerable().Select(row => {{\r\n" +
"DataGridViewRow dataGridViewRow = new DataGridViewRow();\r\n " +
"DataGridViewButtonCell addCell = new DataGridViewButtonCell();\r\n" +
"addCell.Value = \"新增\";\r\n " +
"dataGridViewRow.Cells.Add(addCell);\r\n " +
"DataGridViewButtonCell editCell = new DataGridViewButtonCell();\r\n" +
"editCell.Value = \"修改\";\r\n " +
"dataGridViewRow.Cells.Add(editCell);\r\n " +
"foreach (var item in row.ItemArray.Reverse())\r\n " +
"{\r\n" +
"DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();\r\n" +
"cell.Value = item;\r\n " +
"dataGridViewRow.Cells.Add(cell);\r\n" +
"}\r\n" +
"dataGridViewRow.Height = 40;\r\n" +
"return dataGridViewRow;\r\n" +
"}).ToArray());" ; * /
}
//订单下拉模糊搜索
@ -279,6 +301,7 @@ namespace WindowsFormsApp1
/// <param name="tabname"></param>
public static DataTable GetDbTableInfo ( string tabname )
{
string str = $"SELECT COLUMN_NAME AS Name, COLUMN_TYPE AS Type,COLUMN_COMMENT AS COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '{tabname}' ORDER BY ORDINAL_POSITION;" ;
var dt = DbHelperMySQL . Query ( str ) ;
return dt ;