main
forget_the_bright 1 year ago
parent 1bf10354c1
commit 6c6de70415

@ -78,24 +78,25 @@ namespace WindowsFormsApp1
var list = new List<string>();
txt_ret.Text += "using System;\n" +
"using NCA_MES_Models.CommonUtils.DB.DBAttribute;\n\n";
txt_ret.Text += "namespace "+ namespaceName + "{\n\n";
txt_ret.Text += $"namespace {namespaceName} {{\n\n";
txt_ret.Text += "/// <summary>" + "\n" +
"/// " + GetTableComment(tbname) + "\n"+
$"/// {GetTableComment(tbname)}\n" +
"/// </summary>" + "\n" +
"[TableName(\"" + tbname + "\")]" + "\n"+
"public class " + GenerateClassName(tbname) + " {";
$"[TableName(\"{tbname}\")]\n" +
$"public class {GenerateClassName(tbname)}: DBBaseModel<{GenerateClassName(tbname)}>{{";
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();
Type type = DbTypeStr_To_CsharpType(Type);
//txt_ret.Text += @"/// <summary>" + "\n" + "///" + IsNullable + "\n" + " /// </summary>\n" +""+ " public " + type.Name +" "+ Name + " { get; set; }" + "\n";//不加注释版本
txt_ret.Text += "\n\t" + @"/// <summary>" +
"\n\t" + "///" + IsNullable +
txt_ret.Text += "\n\n\t" + "/// <summary>" +
"\n\t" + $"///{IsNullable}" +
"\n\t" + "/// </summary>" +
"\n\t" + "[TableField(\""+ Name + "\")]" +
"\n\t"+ " public " + type.Name +" "+ ToCamelCase(Name) + " { get; set; }";
(String.IsNullOrEmpty(KeyType)?"":"\n\t[TableId]") +
"\n\t" + $"[TableField(\"{Name}\",\"{IsNullable}\")]" +
"\n\t" + $"public {type.Name} {ToCamelCase(Name)} {{ get; set; }}";
//加注释记得引用using
}
txt_ret.Text += "\n}\n}";
@ -301,9 +302,25 @@ 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);
string sql = @"SELECT
c.COLUMN_NAME AS Name,
c.COLUMN_TYPE AS Type,
c.COLUMN_COMMENT AS Comment,
CASE WHEN CONSTRAINT_NAME = 'PRIMARY' THEN 'PRIMARY KEY' ELSE '' END AS KeyType
FROM
INFORMATION_SCHEMA.COLUMNS c
LEFT JOIN
INFORMATION_SCHEMA.KEY_COLUMN_USAGE k
ON
c.TABLE_SCHEMA = k.TABLE_SCHEMA
AND c.TABLE_NAME = k.TABLE_NAME
AND c.COLUMN_NAME = k.COLUMN_NAME
WHERE
c.TABLE_NAME = '{0}'
ORDER BY
c.ORDINAL_POSITION;";
//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(String.Format(sql, tabname));
return dt;
}
@ -351,6 +368,7 @@ namespace WindowsFormsApp1
{
{ "int", typeof(Int32) },
{ "text", typeof(string) },
{ "enum", typeof(string) },
{ "bigint", typeof(Int64) },
{ "binary", typeof(byte[]) },
{ "bit", typeof(bool) },
@ -371,7 +389,7 @@ namespace WindowsFormsApp1
{ "smallint", typeof(Int16) },
{ "smallmoney", typeof(decimal) },
{ "timestamp", typeof(DateTime) },
{ "tinyint", typeof(byte) },
{ "tinyint", typeof(string) },
{ "varbinary", typeof(byte[]) },
{ "varchar", typeof(string) },
{ "variant", typeof(object) },

Loading…
Cancel
Save