Commit c7248812 authored by 陈航's avatar 陈航

类生成工具添加生成前端列名功能

parent d22ff3e0
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
this.lsbTableInfo = new System.Windows.Forms.ListBox(); this.lsbTableInfo = new System.Windows.Forms.ListBox();
this.txtSearch = new System.Windows.Forms.TextBox(); this.txtSearch = new System.Windows.Forms.TextBox();
this.txtResult = new System.Windows.Forms.TextBox(); this.txtResult = new System.Windows.Forms.TextBox();
this.chkFrontendcolumn = new System.Windows.Forms.CheckBox();
this.toolStrip1.SuspendLayout(); this.toolStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel1.SuspendLayout();
...@@ -138,14 +139,26 @@ ...@@ -138,14 +139,26 @@
this.txtResult.Size = new System.Drawing.Size(448, 370); this.txtResult.Size = new System.Drawing.Size(448, 370);
this.txtResult.TabIndex = 0; this.txtResult.TabIndex = 0;
// //
// chkFrontendcolumn
//
this.chkFrontendcolumn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.chkFrontendcolumn.AutoSize = true;
this.chkFrontendcolumn.Location = new System.Drawing.Point(518, 4);
this.chkFrontendcolumn.Name = "chkFrontendcolumn";
this.chkFrontendcolumn.Size = new System.Drawing.Size(99, 21);
this.chkFrontendcolumn.TabIndex = 8;
this.chkFrontendcolumn.Text = "生成前端列名";
this.chkFrontendcolumn.UseVisualStyleBackColor = true;
this.chkFrontendcolumn.CheckedChanged += new System.EventHandler(this.chkFrontendcolumn_CheckedChanged);
//
// wAutoClass // wAutoClass
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(621, 395); this.ClientSize = new System.Drawing.Size(621, 395);
this.Controls.Add(this.chkFrontendcolumn);
this.Controls.Add(this.splitContainer1); this.Controls.Add(this.splitContainer1);
this.Controls.Add(this.toolStrip1); this.Controls.Add(this.toolStrip1);
this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "wAutoClass"; this.Name = "wAutoClass";
...@@ -172,5 +185,6 @@ ...@@ -172,5 +185,6 @@
private System.Windows.Forms.TextBox txtResult; private System.Windows.Forms.TextBox txtResult;
private System.Windows.Forms.ToolStripButton tsbRefresh; private System.Windows.Forms.ToolStripButton tsbRefresh;
private System.Windows.Forms.ListBox lsbTableInfo; private System.Windows.Forms.ListBox lsbTableInfo;
private System.Windows.Forms.CheckBox chkFrontendcolumn;
} }
} }
\ No newline at end of file
...@@ -91,6 +91,32 @@ namespace Tools.UI ...@@ -91,6 +91,32 @@ namespace Tools.UI
} }
private void lsbTableInfo_SelectedIndexChanged(object sender, EventArgs e) private void lsbTableInfo_SelectedIndexChanged(object sender, EventArgs e)
{
GenerateEntity();
}
private string GetCsharpTypeNameBySqlType(string nSqlTypeName)
{
switch (nSqlTypeName)
{
case "image": return "Image";
case "int": return "int";
case "datetime": return "DateTime";
case "bit": return "bool";
case "varchar": return "string";
case "char": return "char";
default: return "string";
}
}
private void chkFrontendcolumn_CheckedChanged(object sender, EventArgs e)
{
GenerateEntity();
}
/// <summary>
/// 生成所需实体或前端列名
/// </summary>
private void GenerateEntity()
{ {
string strTableName = lsbTableInfo.SelectedItem.ToString(); string strTableName = lsbTableInfo.SelectedItem.ToString();
...@@ -107,6 +133,27 @@ ORDER BY b.column_id; ...@@ -107,6 +133,27 @@ ORDER BY b.column_id;
DataTable dataTable = this._db.GetDataTable(sb.ToString(), "结果列表"); DataTable dataTable = this._db.GetDataTable(sb.ToString(), "结果列表");
sb.Clear(); sb.Clear();
//生成前端列名
if (chkFrontendcolumn.Checked)
{
sb.Append($@"
Colums:
[
");
foreach (DataRow row in dataTable.Rows)
{
sb.Append($@"
{{
label: '{row["Description"]}',
value: '{row["name"]}',
show_overflow_tooltip: true
}},");
}
txtResult.Text = sb.ToString().Substring(0, sb.ToString().Length - 1) + @"
]";
}
else//生成实体类
{
sb.Append($@" sb.Append($@"
/// <summary> /// <summary>
/// {strTableName} /// {strTableName}
...@@ -114,7 +161,7 @@ ORDER BY b.column_id; ...@@ -114,7 +161,7 @@ ORDER BY b.column_id;
public class {strTableName} public class {strTableName}
{{ {{
"); ");
foreach(DataRow row in dataTable.Rows) foreach (DataRow row in dataTable.Rows)
{ {
sb.Append($@" sb.Append($@"
/// <summary> /// <summary>
...@@ -129,19 +176,6 @@ ORDER BY b.column_id; ...@@ -129,19 +176,6 @@ ORDER BY b.column_id;
"); ");
txtResult.Text = sb.ToString(); txtResult.Text = sb.ToString();
} }
private string GetCsharpTypeNameBySqlType(string nSqlTypeName)
{
switch (nSqlTypeName)
{
case "image": return "Image";
case "int": return "int";
case "datetime": return "DateTime";
case "bit": return "bool";
case "varchar": return "string";
case "char": return "char";
default:return "string";
}
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment