You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
235 lines
13 KiB
C#
235 lines
13 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace GenerateClass.Util
|
|
{
|
|
internal class OldInfo
|
|
{
|
|
/*private void fillDgv3Str()
|
|
{
|
|
string tbname = txt_tablename.Text.Trim();//要生成的表名
|
|
if (tbname.Equals("请选择") || tbname.Equals(""))
|
|
{
|
|
MessageBox.Show("请选择表");
|
|
return;
|
|
};
|
|
DataTable dt = null;
|
|
if (textBox3.Text.Trim() == "") dt = DbUtil.GetDbTableInfo(tbname);
|
|
else dt = DbHelperMySQL.Query(textBox3.Text.Trim());
|
|
string uidatagridview = textBox2.Text.Trim();
|
|
textBox1.Text = $"this.{uidatagridview}.AutoGenerateColumns = false;";
|
|
textBox1.Text += "List<DataGridViewColumn> cols = new List<DataGridViewColumn>();\n\n";
|
|
var list = new List<string>();
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
{
|
|
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; }};";
|
|
}
|
|
|
|
}*/
|
|
/* private void fillDgv2Str()
|
|
{
|
|
string tbname = txt_tablename.Text.Trim();//要生成的表名
|
|
if (tbname.Equals("请选择") || tbname.Equals(""))
|
|
{
|
|
MessageBox.Show("请选择表");
|
|
return;
|
|
};
|
|
DataTable dt = null;
|
|
if (textBox3.Text.Trim() == "")
|
|
{
|
|
dt = DbUtil.GetDbTableInfo(tbname);
|
|
}
|
|
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 fillDgv1Str()
|
|
{
|
|
string tbname = txt_tablename.Text.Trim();//要生成的表名
|
|
if (tbname.Equals("请选择") || tbname.Equals(""))
|
|
{
|
|
MessageBox.Show("请选择表");
|
|
return;
|
|
};
|
|
DataTable dt = null;
|
|
if (textBox3.Text.Trim() == "")
|
|
{
|
|
dt = DbUtil.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";
|
|
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";
|
|
}*/
|
|
|
|
/* private void fillModelStr()
|
|
{
|
|
//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);
|
|
}*/
|
|
}
|
|
}
|