|
|
@ -1,8 +1,19 @@
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
|
|
using System.Data;
|
|
|
|
|
|
|
|
using System.Data.SqlTypes;
|
|
|
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
|
|
using System.Globalization;
|
|
|
|
using System.IO;
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
|
|
using GenerateClass.Util;
|
|
|
|
using GenerateClass.Util;
|
|
|
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
using JinianNet.JNTemplate;
|
|
|
|
using JinianNet.JNTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
namespace GenerateClass
|
|
|
|
namespace GenerateClass
|
|
|
@ -13,6 +24,7 @@ namespace GenerateClass
|
|
|
|
{
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
InitializeComponent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.txt_tablename.Items.AddRange(DbUtil.GetTableName().ToArray());
|
|
|
|
this.txt_tablename.Items.AddRange(DbUtil.GetTableName().ToArray());
|
|
|
@ -27,37 +39,53 @@ namespace GenerateClass
|
|
|
|
this.txt_tablename.Items.AddRange(sList.ToArray());
|
|
|
|
this.txt_tablename.Items.AddRange(sList.ToArray());
|
|
|
|
this.txt_tablename.Select(this.txt_tablename.Text.Length, 0);
|
|
|
|
this.txt_tablename.Select(this.txt_tablename.Text.Length, 0);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
Engine.Configure((options) => {
|
|
|
|
|
|
|
|
options.OutMode = OutMode.Auto;
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void modelGen_Click(object sender, EventArgs e)
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
fillModelTemplate();
|
|
|
|
fillTemplate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void dgvGen1_Click(object sender, EventArgs e)
|
|
|
|
|
|
|
|
{
|
|
|
|
private void fillTemplate()
|
|
|
|
fillDgv1Template();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void dgvGen2_Click(object sender, EventArgs e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
fillDgv2Template();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void dgvGen3_Click(object sender, EventArgs e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
fillDgv3Template();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void fillModelTemplate()
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string tbname = txt_tablename.Text.Trim();//要生成的表名
|
|
|
|
string tbname = txt_tablename.Text.Trim();//要生成的表名
|
|
|
|
string namespaceName = namespace_name.Text.Trim();//名称空间名称
|
|
|
|
string namespaceName = namespace_name.Text.Trim();//名称空间名称
|
|
|
|
List<Dictionary<string, string>> filedInfos = DbUtil.getTableInfo(tbname, textBox3.Text.Trim());
|
|
|
|
DataTable dt = null;
|
|
|
|
|
|
|
|
if (textBox3.Text.Trim() == "")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dt = DbUtil.GetDbTableInfo(tbname);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dt = DbHelperMySQL.Query(textBox3.Text.Trim());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
List<Dictionary<string, string>> filedInfos = new List<Dictionary<string, string>>();
|
|
|
|
|
|
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var dict = new Dictionary<string, string>();
|
|
|
|
|
|
|
|
var Name = dt.Rows[i]["Name"].ToString();
|
|
|
|
|
|
|
|
var COMMENT = dt.Rows[i]["COMMENT"].ToString();
|
|
|
|
|
|
|
|
var KeyType = dt.Rows[i]["KeyType"].ToString();
|
|
|
|
|
|
|
|
var Nullable = dt.Rows[i]["Nullable"].ToString();
|
|
|
|
|
|
|
|
Type type = DbUtil.DbTypeStr_To_CsharpType(dt.Rows[i]["Type"].ToString());
|
|
|
|
|
|
|
|
dict["sql_field_name"] = Name;
|
|
|
|
|
|
|
|
dict["field_name"] = DbUtil.ToCamelCase(Name);
|
|
|
|
|
|
|
|
dict["type_name"] = type.Name;
|
|
|
|
|
|
|
|
dict["comment"] = COMMENT;
|
|
|
|
|
|
|
|
dict["is_primary_key"] = (String.IsNullOrEmpty(KeyType) ? "false" : "true");
|
|
|
|
|
|
|
|
dict["is_nullable"] = (String.IsNullOrEmpty(KeyType) && !("NULL".Equals(Nullable)) ? "true" : "false");
|
|
|
|
|
|
|
|
filedInfos.Add(dict);
|
|
|
|
|
|
|
|
}
|
|
|
|
using (StreamReader reader = new StreamReader(@".\Template\ModelFile.template"))
|
|
|
|
using (StreamReader reader = new StreamReader(@".\Template\ModelFile.template"))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string fileContent = reader.ReadToEnd();
|
|
|
|
string fileContent = reader.ReadToEnd();
|
|
|
|
var template = Engine.CreateTemplate(fileContent);
|
|
|
|
var template = Engine.CreateTemplate(fileContent);
|
|
|
|
template.Set("namespace_name", namespaceName);
|
|
|
|
template.Set("namespace_name", namespaceName);
|
|
|
|
template.Set("table_comment", DbUtil.GetTableComment(tbname));
|
|
|
|
template.Set("table_comment", DbUtil.GetTableComment(tbname));
|
|
|
|
template.Set("sql_table_name", tbname);
|
|
|
|
template.Set("sql_table_name", DbUtil.GenerateClassName(tbname));
|
|
|
|
template.Set("table_name", DbUtil.GenerateClassName(tbname));
|
|
|
|
template.Set("table_name", tbname);
|
|
|
|
template.Set("filedInfos", filedInfos);
|
|
|
|
template.Set("filedInfos", filedInfos);
|
|
|
|
template.SetStaticType("string", typeof(string));
|
|
|
|
template.SetStaticType("string", typeof(string));
|
|
|
|
var result = template.Render();
|
|
|
|
var result = template.Render();
|
|
|
@ -66,68 +94,229 @@ namespace GenerateClass
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void fillDgv1Template()
|
|
|
|
|
|
|
|
|
|
|
|
private void fillStr() {
|
|
|
|
|
|
|
|
//string constr = txt_constr.Text.Trim();//数据库链接字符串
|
|
|
|
|
|
|
|
txt_ret.Text = "";
|
|
|
|
|
|
|
|
string tbname = txt_tablename.Text.Trim();//要生成的表名
|
|
|
|
|
|
|
|
if (tbname.Equals("请选择") || tbname.Equals(""))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
MessageBox.Show("请选择表");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
string namespaceName = namespace_name.Text.Trim();
|
|
|
|
|
|
|
|
DataTable dt = null;
|
|
|
|
|
|
|
|
if (textBox3.Text.Trim() == "")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dt = DbUtil.GetDbTableInfo(tbname);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dt = DbHelperMySQL.Query(textBox3.Text.Trim());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var infoStr = "";
|
|
|
|
|
|
|
|
infoStr += "using System;\n" +
|
|
|
|
|
|
|
|
"using NCA_MES_Models.CommonUtils.DB.DBAttribute;\n\n";
|
|
|
|
|
|
|
|
infoStr += $"namespace {namespaceName} \n{{\n\n";
|
|
|
|
|
|
|
|
infoStr += "\t/// <summary>" + "\n" +
|
|
|
|
|
|
|
|
$"\t/// {DbUtil.GetTableComment(tbname)}\n" +
|
|
|
|
|
|
|
|
"\t/// </summary>" + "\n" +
|
|
|
|
|
|
|
|
$"\t[TableName(\"{tbname}\")]\n" +
|
|
|
|
|
|
|
|
$"\tpublic class {DbUtil.GenerateClassName(tbname)}: DBBaseModel<{DbUtil.GenerateClassName(tbname)}>\n\t{{";
|
|
|
|
|
|
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var Name = dt.Rows[i]["Name"].ToString();
|
|
|
|
|
|
|
|
var Type = dt.Rows[i]["Type"].ToString();
|
|
|
|
|
|
|
|
var IsNullable = dt.Rows[i]["COMMENT"].ToString();
|
|
|
|
|
|
|
|
var KeyType = dt.Rows[i]["KeyType"].ToString();
|
|
|
|
|
|
|
|
var Nullable = dt.Rows[i]["Nullable"].ToString();
|
|
|
|
|
|
|
|
Type type = DbUtil.DbTypeStr_To_CsharpType(Type);
|
|
|
|
|
|
|
|
infoStr += "\t\n\n\t" + "/// <summary>" +
|
|
|
|
|
|
|
|
"\t\n\t" + $"///{IsNullable}" +
|
|
|
|
|
|
|
|
"\t\n\t" + "/// </summary>" +
|
|
|
|
|
|
|
|
(String.IsNullOrEmpty(KeyType) ? "" : "\n\t[TableId]") +
|
|
|
|
|
|
|
|
(String.IsNullOrEmpty(KeyType) && !("NULL".Equals(Nullable)) ? "\n\t[NotEmpty]" : "") +
|
|
|
|
|
|
|
|
"\t\n\t" + $"[TableField(\"{Name}\",\"{IsNullable}\")]" +
|
|
|
|
|
|
|
|
"\t\n\t" + $"public {type.Name} {DbUtil.ToCamelCase(Name)} {{ get; set; }}";
|
|
|
|
|
|
|
|
//加注释记得引用using
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
infoStr += "\n\t}";
|
|
|
|
|
|
|
|
infoStr += "\n}";
|
|
|
|
|
|
|
|
this.txt_ret.Text = infoStr;
|
|
|
|
|
|
|
|
DbUtil.openFile(tbname, infoStr);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string tbname = txt_tablename.Text.Trim();//要生成的表名
|
|
|
|
string tbname = txt_tablename.Text.Trim();//要生成的表名
|
|
|
|
string dgvName = textBox2.Text.Trim(); //dgv空间名称
|
|
|
|
if (tbname.Equals("请选择") || tbname.Equals(""))
|
|
|
|
List<Dictionary<string, string>> filedInfos = DbUtil.getTableInfo(tbname, textBox3.Text.Trim());
|
|
|
|
|
|
|
|
List<string> timeFileds = DbUtil.getTimeFields(filedInfos);
|
|
|
|
|
|
|
|
using (StreamReader reader = new StreamReader(@".\Template\DataGridView_1.template"))
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string fileContent = reader.ReadToEnd();
|
|
|
|
MessageBox.Show("请选择表");
|
|
|
|
var template = Engine.CreateTemplate(fileContent);
|
|
|
|
return;
|
|
|
|
template.Set("table_comment", DbUtil.GetTableComment(tbname));
|
|
|
|
};
|
|
|
|
template.Set("sql_table_name", tbname);
|
|
|
|
DataTable dt = null;
|
|
|
|
template.Set("table_name", DbUtil.GenerateClassName(tbname));
|
|
|
|
if (textBox3.Text.Trim() == "")
|
|
|
|
template.Set("dgv_name", dgvName);
|
|
|
|
{
|
|
|
|
template.Set("filedInfos", filedInfos);
|
|
|
|
dt = DbUtil.GetDbTableInfo(tbname);
|
|
|
|
template.Set("timeFiledStr", DbUtil.joinList(timeFileds));
|
|
|
|
}
|
|
|
|
template.SetStaticType("string", typeof(string));
|
|
|
|
else
|
|
|
|
var result = template.Render();
|
|
|
|
{
|
|
|
|
this.textBox1.Text = result;
|
|
|
|
dt = DbHelperMySQL.Query(textBox3.Text.Trim());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
string uidatagridview = textBox2.Text.Trim();
|
|
|
|
|
|
|
|
textBox1.Text = "";
|
|
|
|
|
|
|
|
textBox1.Text += $"DataTable data = DbHelperMySQL.Query(\"select * from {tbname}\");\n";
|
|
|
|
|
|
|
|
textBox1.Text += "this."+ uidatagridview + ".DataSource = new BindingSource {DataSource = data};\n";
|
|
|
|
|
|
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var Name = dt.Rows[i]["Name"].ToString();
|
|
|
|
|
|
|
|
textBox1.Text += $"var {Name}Column = {uidatagridview}.Columns[\"{Name}\"];\n";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var Name = dt.Rows[i]["Name"].ToString();
|
|
|
|
|
|
|
|
var IsNullable = dt.Rows[i]["COMMENT"].ToString();
|
|
|
|
|
|
|
|
textBox1.Text += $"{Name}Column.HeaderText = \"{IsNullable}\";\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
textBox1.Text += $" {uidatagridview}.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.ColumnHeader;\n";
|
|
|
|
|
|
|
|
textBox1.Text += $" {uidatagridview}.AutoGenerateColumns = true;\n";
|
|
|
|
|
|
|
|
// textBox1.Text += $" {uidatagridview}.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void fillDgv2Template()
|
|
|
|
|
|
|
|
|
|
|
|
private void button3_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string tbname = txt_tablename.Text.Trim();//要生成的表名
|
|
|
|
string tbname = txt_tablename.Text.Trim();//要生成的表名
|
|
|
|
string dgvName = textBox2.Text.Trim(); //dgv空间名称
|
|
|
|
if (tbname.Equals("请选择") || tbname.Equals(""))
|
|
|
|
List<string> timeFileds = DbUtil.getTimeFields(DbUtil.getTableInfo(tbname, textBox3.Text.Trim()));
|
|
|
|
|
|
|
|
using (StreamReader reader = new StreamReader(@".\Template\DataGridView_2.template"))
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string fileContent = reader.ReadToEnd();
|
|
|
|
MessageBox.Show("请选择表");
|
|
|
|
var template = Engine.CreateTemplate(fileContent);
|
|
|
|
return;
|
|
|
|
template.Set("table_comment", DbUtil.GetTableComment(tbname));
|
|
|
|
};
|
|
|
|
template.Set("sql_table_name", tbname);
|
|
|
|
DataTable dt = null;
|
|
|
|
template.Set("table_name", DbUtil.GenerateClassName(tbname));
|
|
|
|
if (textBox3.Text.Trim() == "")
|
|
|
|
template.Set("dgv_name", dgvName);
|
|
|
|
{
|
|
|
|
template.Set("isGenOperationColumn", isGenOperationColumn.Checked);
|
|
|
|
dt = DbUtil.GetDbTableInfo(tbname);
|
|
|
|
template.Set("timeFiledStr", DbUtil.joinList(timeFileds));
|
|
|
|
|
|
|
|
template.SetStaticType("string", typeof(string));
|
|
|
|
|
|
|
|
var result = template.Render();
|
|
|
|
|
|
|
|
this.textBox1.Text = result;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
dt = DbHelperMySQL.Query(textBox3.Text.Trim());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
string uidatagridview = textBox2.Text.Trim();
|
|
|
|
|
|
|
|
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";
|
|
|
|
|
|
|
|
textBox1.Text += "for (int i = 0; i < dt.Rows.Count; i++){\n" +
|
|
|
|
|
|
|
|
" 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 = \"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 = \"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 " +
|
|
|
|
|
|
|
|
$"this.{uidatagridview}.RightToLeft = RightToLeft.Yes;\r\n" +
|
|
|
|
|
|
|
|
"cols.Reverse();\r\n" +
|
|
|
|
|
|
|
|
"}\r\n" +
|
|
|
|
|
|
|
|
$"this.{uidatagridview}.Columns.AddRange(cols.ToArray());\r\n\r\n" +
|
|
|
|
|
|
|
|
$"if (this.{uidatagridview}.Columns.Count > 0)\r\n" +
|
|
|
|
|
|
|
|
$"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}.DataSource = data;\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void fillDgv3Template()
|
|
|
|
|
|
|
|
|
|
|
|
private void button4_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string tbname = txt_tablename.Text.Trim();//要生成的表名
|
|
|
|
string tbname = txt_tablename.Text.Trim();//要生成的表名
|
|
|
|
string dgvName = textBox2.Text.Trim(); //dgv空间名称
|
|
|
|
if (tbname.Equals("请选择") || tbname.Equals(""))
|
|
|
|
List<Dictionary<string, string>> filedInfos = DbUtil.getTableInfo(tbname, textBox3.Text.Trim());
|
|
|
|
|
|
|
|
List<string> timeFileds = DbUtil.getTimeFields(filedInfos);
|
|
|
|
|
|
|
|
using (StreamReader reader = new StreamReader(@".\Template\DataGridView_3.template"))
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
string fileContent = reader.ReadToEnd();
|
|
|
|
MessageBox.Show("请选择表");
|
|
|
|
var template = Engine.CreateTemplate(fileContent);
|
|
|
|
return;
|
|
|
|
template.Set("table_comment", DbUtil.GetTableComment(tbname));
|
|
|
|
};
|
|
|
|
template.Set("sql_table_name", tbname);
|
|
|
|
DataTable dt = null;
|
|
|
|
template.Set("table_name", DbUtil.GenerateClassName(tbname));
|
|
|
|
if (textBox3.Text.Trim() == "") dt = DbUtil.GetDbTableInfo(tbname);
|
|
|
|
template.Set("dgv_name", dgvName);
|
|
|
|
else dt = DbHelperMySQL.Query(textBox3.Text.Trim());
|
|
|
|
template.Set("filedInfos", filedInfos);
|
|
|
|
string uidatagridview = textBox2.Text.Trim();
|
|
|
|
template.Set("isGenOperationColumn", isGenOperationColumn.Checked);
|
|
|
|
textBox1.Text = $"this.{uidatagridview}.AutoGenerateColumns = false;";
|
|
|
|
template.Set("timeFiledStr", DbUtil.joinList(timeFileds));
|
|
|
|
textBox1.Text += "List<DataGridViewColumn> cols = new List<DataGridViewColumn>();\n\n";
|
|
|
|
template.SetStaticType("string", typeof(string));
|
|
|
|
var list = new List<string>();
|
|
|
|
var result = template.Render();
|
|
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
|
|
this.textBox1.Text = result;
|
|
|
|
{
|
|
|
|
|
|
|
|
var Name = dt.Rows[i]["Name"].ToString();
|
|
|
|
|
|
|
|
var IsNullable = dt.Rows[i]["COMMENT"].ToString();
|
|
|
|
|
|
|
|
Type type = DbUtil.DbTypeStr_To_CsharpType(dt.Rows[i]["Type"].ToString());
|
|
|
|
|
|
|
|
if(type.Name== "DateTime") list.Add(Name);
|
|
|
|
|
|
|
|
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\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* textBox1.Text += "DataGridViewButtonColumn editBtn = new DataGridViewButtonColumn();\r\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 = \"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 " +
|
|
|
|
|
|
|
|
$"this.{uidatagridview}.RightToLeft = RightToLeft.Yes;\r\n" +
|
|
|
|
|
|
|
|
"cols.Reverse();\r\n" +
|
|
|
|
|
|
|
|
"}\r\n" +
|
|
|
|
|
|
|
|
$"this.{uidatagridview}.Columns.AddRange(cols.ToArray());\r\n\r\n" +
|
|
|
|
|
|
|
|
$"if (this.{uidatagridview}.Columns.Count > 0)\r\n" +
|
|
|
|
|
|
|
|
$"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}.DataSource = data;\n";
|
|
|
|
|
|
|
|
if (list.Count > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
textBox1.Text += $@"
|
|
|
|
|
|
|
|
DateTimePicker dtp = new DateTimePicker();
|
|
|
|
|
|
|
|
convertBeginDgv.Controls.Add(dtp);
|
|
|
|
|
|
|
|
dtp.Visible = false;
|
|
|
|
|
|
|
|
dtp.TextChanged += (sender, e) => convertBeginDgv.CurrentCell.Value = dtp.Value.ToString(""yyyy-MM-dd"");
|
|
|
|
|
|
|
|
dtp.CloseUp += (sender, e) => dtp.Visible = false;
|
|
|
|
|
|
|
|
convertBeginDgv.CellClick += (sender, e) => {{
|
|
|
|
|
|
|
|
if (e.ColumnIndex == -1 || e.RowIndex == -1) return;
|
|
|
|
|
|
|
|
DataGridView dgv = (sender as DataGridView);
|
|
|
|
|
|
|
|
if (new List<string>() {{
|
|
|
|
|
|
|
|
{DbUtil.joinList(list)}
|
|
|
|
|
|
|
|
}}.Contains(dgv.Columns[e.ColumnIndex].Name))
|
|
|
|
|
|
|
|
{{
|
|
|
|
|
|
|
|
var _Recatngle = dgv.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);
|
|
|
|
|
|
|
|
dtp.Size = _Recatngle.Size;
|
|
|
|
|
|
|
|
dtp.Location = _Recatngle.Location;
|
|
|
|
|
|
|
|
dtp.Visible = true;
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
else dtp.Visible = false;
|
|
|
|
|
|
|
|
}};
|
|
|
|
|
|
|
|
convertBeginDgv.Scroll += (sender, e) => dtp.Visible = false;
|
|
|
|
|
|
|
|
convertBeginDgv.SizeChanged += (sender, e) => {{ if (dtp.Visible) dtp.Visible = false; }};";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|