Compare commits
2 Commits
806d6d2e9c
...
61b91aaa64
Author | SHA1 | Date | |
---|---|---|---|
61b91aaa64 | |||
a17573e844 |
@ -89,6 +89,7 @@
|
|||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Util\Config.cs" />
|
||||||
<Compile Include="Util\DbHelper.cs" />
|
<Compile Include="Util\DbHelper.cs" />
|
||||||
<Compile Include="Form1.cs">
|
<Compile Include="Form1.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
@ -99,6 +100,7 @@
|
|||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Util\DbUtil.cs" />
|
<Compile Include="Util\DbUtil.cs" />
|
||||||
|
<Compile Include="Util\OldInfo.cs" />
|
||||||
<EmbeddedResource Include="Form1.resx">
|
<EmbeddedResource Include="Form1.resx">
|
||||||
<DependentUpon>Form1.cs</DependentUpon>
|
<DependentUpon>Form1.cs</DependentUpon>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
@ -122,6 +124,15 @@
|
|||||||
<DependentUpon>Settings.settings</DependentUpon>
|
<DependentUpon>Settings.settings</DependentUpon>
|
||||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<None Include="Template\DataGridView_2.template">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Include="Template\DataGridView_1.template">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Include="Template\DataGridView_3.template">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
<None Include="Template\ModelFile.template">
|
<None Include="Template\ModelFile.template">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
86
DatabasetoEntityclass/Form1.Designer.cs
generated
86
DatabasetoEntityclass/Form1.Designer.cs
generated
@ -28,7 +28,7 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.button1 = new System.Windows.Forms.Button();
|
this.modelGen = new System.Windows.Forms.Button();
|
||||||
this.label2 = new System.Windows.Forms.Label();
|
this.label2 = new System.Windows.Forms.Label();
|
||||||
this.txt_ret = new System.Windows.Forms.TextBox();
|
this.txt_ret = new System.Windows.Forms.TextBox();
|
||||||
this.label3 = new System.Windows.Forms.Label();
|
this.label3 = new System.Windows.Forms.Label();
|
||||||
@ -44,22 +44,24 @@
|
|||||||
this.button4 = new System.Windows.Forms.Button();
|
this.button4 = new System.Windows.Forms.Button();
|
||||||
this.textBox3 = new System.Windows.Forms.TextBox();
|
this.textBox3 = new System.Windows.Forms.TextBox();
|
||||||
this.label5 = new System.Windows.Forms.Label();
|
this.label5 = new System.Windows.Forms.Label();
|
||||||
|
this.isGenOperationColumn = new System.Windows.Forms.CheckBox();
|
||||||
|
this.label6 = new System.Windows.Forms.Label();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// button1
|
// modelGen
|
||||||
//
|
//
|
||||||
this.button1.Location = new System.Drawing.Point(81, 322);
|
this.modelGen.Location = new System.Drawing.Point(105, 322);
|
||||||
this.button1.Name = "button1";
|
this.modelGen.Name = "modelGen";
|
||||||
this.button1.Size = new System.Drawing.Size(75, 23);
|
this.modelGen.Size = new System.Drawing.Size(75, 23);
|
||||||
this.button1.TabIndex = 0;
|
this.modelGen.TabIndex = 0;
|
||||||
this.button1.Text = "开始";
|
this.modelGen.Text = "开始";
|
||||||
this.button1.UseVisualStyleBackColor = true;
|
this.modelGen.UseVisualStyleBackColor = true;
|
||||||
this.button1.Click += new System.EventHandler(this.button1_Click);
|
this.modelGen.Click += new System.EventHandler(this.modelGen_Click);
|
||||||
//
|
//
|
||||||
// label2
|
// label2
|
||||||
//
|
//
|
||||||
this.label2.AutoSize = true;
|
this.label2.AutoSize = true;
|
||||||
this.label2.Location = new System.Drawing.Point(296, 16);
|
this.label2.Location = new System.Drawing.Point(357, 16);
|
||||||
this.label2.Name = "label2";
|
this.label2.Name = "label2";
|
||||||
this.label2.Size = new System.Drawing.Size(41, 12);
|
this.label2.Size = new System.Drawing.Size(41, 12);
|
||||||
this.label2.TabIndex = 4;
|
this.label2.TabIndex = 4;
|
||||||
@ -68,16 +70,17 @@
|
|||||||
// txt_ret
|
// txt_ret
|
||||||
//
|
//
|
||||||
this.txt_ret.Font = new System.Drawing.Font("宋体", 11F);
|
this.txt_ret.Font = new System.Drawing.Font("宋体", 11F);
|
||||||
this.txt_ret.Location = new System.Drawing.Point(453, 61);
|
this.txt_ret.Location = new System.Drawing.Point(518, 61);
|
||||||
this.txt_ret.Multiline = true;
|
this.txt_ret.Multiline = true;
|
||||||
this.txt_ret.Name = "txt_ret";
|
this.txt_ret.Name = "txt_ret";
|
||||||
|
this.txt_ret.ScrollBars = System.Windows.Forms.ScrollBars.Both;
|
||||||
this.txt_ret.Size = new System.Drawing.Size(335, 341);
|
this.txt_ret.Size = new System.Drawing.Size(335, 341);
|
||||||
this.txt_ret.TabIndex = 68;
|
this.txt_ret.TabIndex = 68;
|
||||||
//
|
//
|
||||||
// label3
|
// label3
|
||||||
//
|
//
|
||||||
this.label3.AutoSize = true;
|
this.label3.AutoSize = true;
|
||||||
this.label3.Location = new System.Drawing.Point(453, 43);
|
this.label3.Location = new System.Drawing.Point(515, 43);
|
||||||
this.label3.Name = "label3";
|
this.label3.Name = "label3";
|
||||||
this.label3.Size = new System.Drawing.Size(53, 12);
|
this.label3.Size = new System.Drawing.Size(53, 12);
|
||||||
this.label3.TabIndex = 69;
|
this.label3.TabIndex = 69;
|
||||||
@ -85,16 +88,16 @@
|
|||||||
//
|
//
|
||||||
// namespace_name
|
// namespace_name
|
||||||
//
|
//
|
||||||
this.namespace_name.Location = new System.Drawing.Point(131, 86);
|
this.namespace_name.Location = new System.Drawing.Point(118, 86);
|
||||||
this.namespace_name.Name = "namespace_name";
|
this.namespace_name.Name = "namespace_name";
|
||||||
this.namespace_name.Size = new System.Drawing.Size(218, 21);
|
this.namespace_name.Size = new System.Drawing.Size(353, 21);
|
||||||
this.namespace_name.TabIndex = 70;
|
this.namespace_name.TabIndex = 70;
|
||||||
this.namespace_name.Text = "default_namespace";
|
this.namespace_name.Text = "default_namespace";
|
||||||
//
|
//
|
||||||
// lable2
|
// lable2
|
||||||
//
|
//
|
||||||
this.lable2.AutoSize = true;
|
this.lable2.AutoSize = true;
|
||||||
this.lable2.Location = new System.Drawing.Point(67, 91);
|
this.lable2.Location = new System.Drawing.Point(54, 91);
|
||||||
this.lable2.Name = "lable2";
|
this.lable2.Name = "lable2";
|
||||||
this.lable2.Size = new System.Drawing.Size(59, 12);
|
this.lable2.Size = new System.Drawing.Size(59, 12);
|
||||||
this.lable2.TabIndex = 71;
|
this.lable2.TabIndex = 71;
|
||||||
@ -103,7 +106,7 @@
|
|||||||
// txt_tablename
|
// txt_tablename
|
||||||
//
|
//
|
||||||
this.txt_tablename.FormattingEnabled = true;
|
this.txt_tablename.FormattingEnabled = true;
|
||||||
this.txt_tablename.Location = new System.Drawing.Point(343, 12);
|
this.txt_tablename.Location = new System.Drawing.Point(404, 12);
|
||||||
this.txt_tablename.Name = "txt_tablename";
|
this.txt_tablename.Name = "txt_tablename";
|
||||||
this.txt_tablename.Size = new System.Drawing.Size(218, 20);
|
this.txt_tablename.Size = new System.Drawing.Size(218, 20);
|
||||||
this.txt_tablename.TabIndex = 72;
|
this.txt_tablename.TabIndex = 72;
|
||||||
@ -112,15 +115,16 @@
|
|||||||
// textBox1
|
// textBox1
|
||||||
//
|
//
|
||||||
this.textBox1.Font = new System.Drawing.Font("宋体", 11F);
|
this.textBox1.Font = new System.Drawing.Font("宋体", 11F);
|
||||||
this.textBox1.Location = new System.Drawing.Point(455, 425);
|
this.textBox1.Location = new System.Drawing.Point(517, 425);
|
||||||
this.textBox1.Multiline = true;
|
this.textBox1.Multiline = true;
|
||||||
this.textBox1.Name = "textBox1";
|
this.textBox1.Name = "textBox1";
|
||||||
|
this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both;
|
||||||
this.textBox1.Size = new System.Drawing.Size(335, 341);
|
this.textBox1.Size = new System.Drawing.Size(335, 341);
|
||||||
this.textBox1.TabIndex = 73;
|
this.textBox1.TabIndex = 73;
|
||||||
//
|
//
|
||||||
// textBox2
|
// textBox2
|
||||||
//
|
//
|
||||||
this.textBox2.Location = new System.Drawing.Point(142, 469);
|
this.textBox2.Location = new System.Drawing.Point(164, 469);
|
||||||
this.textBox2.Name = "textBox2";
|
this.textBox2.Name = "textBox2";
|
||||||
this.textBox2.Size = new System.Drawing.Size(218, 21);
|
this.textBox2.Size = new System.Drawing.Size(218, 21);
|
||||||
this.textBox2.TabIndex = 74;
|
this.textBox2.TabIndex = 74;
|
||||||
@ -129,7 +133,7 @@
|
|||||||
// label1
|
// label1
|
||||||
//
|
//
|
||||||
this.label1.AutoSize = true;
|
this.label1.AutoSize = true;
|
||||||
this.label1.Location = new System.Drawing.Point(70, 472);
|
this.label1.Location = new System.Drawing.Point(92, 472);
|
||||||
this.label1.Name = "label1";
|
this.label1.Name = "label1";
|
||||||
this.label1.Size = new System.Drawing.Size(65, 12);
|
this.label1.Size = new System.Drawing.Size(65, 12);
|
||||||
this.label1.TabIndex = 75;
|
this.label1.TabIndex = 75;
|
||||||
@ -137,18 +141,18 @@
|
|||||||
//
|
//
|
||||||
// button2
|
// button2
|
||||||
//
|
//
|
||||||
this.button2.Location = new System.Drawing.Point(69, 630);
|
this.button2.Location = new System.Drawing.Point(91, 630);
|
||||||
this.button2.Name = "button2";
|
this.button2.Name = "button2";
|
||||||
this.button2.Size = new System.Drawing.Size(75, 23);
|
this.button2.Size = new System.Drawing.Size(75, 23);
|
||||||
this.button2.TabIndex = 76;
|
this.button2.TabIndex = 76;
|
||||||
this.button2.Text = "生成1";
|
this.button2.Text = "生成1";
|
||||||
this.button2.UseVisualStyleBackColor = true;
|
this.button2.UseVisualStyleBackColor = true;
|
||||||
this.button2.Click += new System.EventHandler(this.button2_Click);
|
this.button2.Click += new System.EventHandler(this.dgvGen1_Click);
|
||||||
//
|
//
|
||||||
// label4
|
// label4
|
||||||
//
|
//
|
||||||
this.label4.AutoSize = true;
|
this.label4.AutoSize = true;
|
||||||
this.label4.Location = new System.Drawing.Point(25, 405);
|
this.label4.Location = new System.Drawing.Point(87, 405);
|
||||||
this.label4.Name = "label4";
|
this.label4.Name = "label4";
|
||||||
this.label4.Size = new System.Drawing.Size(827, 12);
|
this.label4.Size = new System.Drawing.Size(827, 12);
|
||||||
this.label4.TabIndex = 77;
|
this.label4.TabIndex = 77;
|
||||||
@ -157,27 +161,27 @@
|
|||||||
//
|
//
|
||||||
// button3
|
// button3
|
||||||
//
|
//
|
||||||
this.button3.Location = new System.Drawing.Point(176, 630);
|
this.button3.Location = new System.Drawing.Point(198, 630);
|
||||||
this.button3.Name = "button3";
|
this.button3.Name = "button3";
|
||||||
this.button3.Size = new System.Drawing.Size(75, 23);
|
this.button3.Size = new System.Drawing.Size(75, 23);
|
||||||
this.button3.TabIndex = 78;
|
this.button3.TabIndex = 78;
|
||||||
this.button3.Text = "生成2";
|
this.button3.Text = "生成2";
|
||||||
this.button3.UseVisualStyleBackColor = true;
|
this.button3.UseVisualStyleBackColor = true;
|
||||||
this.button3.Click += new System.EventHandler(this.button3_Click);
|
this.button3.Click += new System.EventHandler(this.dgvGen2_Click);
|
||||||
//
|
//
|
||||||
// button4
|
// button4
|
||||||
//
|
//
|
||||||
this.button4.Location = new System.Drawing.Point(285, 630);
|
this.button4.Location = new System.Drawing.Point(307, 630);
|
||||||
this.button4.Name = "button4";
|
this.button4.Name = "button4";
|
||||||
this.button4.Size = new System.Drawing.Size(75, 23);
|
this.button4.Size = new System.Drawing.Size(75, 23);
|
||||||
this.button4.TabIndex = 79;
|
this.button4.TabIndex = 79;
|
||||||
this.button4.Text = "生成3";
|
this.button4.Text = "生成3";
|
||||||
this.button4.UseVisualStyleBackColor = true;
|
this.button4.UseVisualStyleBackColor = true;
|
||||||
this.button4.Click += new System.EventHandler(this.button4_Click);
|
this.button4.Click += new System.EventHandler(this.dgvGen3_Click);
|
||||||
//
|
//
|
||||||
// textBox3
|
// textBox3
|
||||||
//
|
//
|
||||||
this.textBox3.Location = new System.Drawing.Point(858, 344);
|
this.textBox3.Location = new System.Drawing.Point(920, 344);
|
||||||
this.textBox3.Multiline = true;
|
this.textBox3.Multiline = true;
|
||||||
this.textBox3.Name = "textBox3";
|
this.textBox3.Name = "textBox3";
|
||||||
this.textBox3.Size = new System.Drawing.Size(98, 131);
|
this.textBox3.Size = new System.Drawing.Size(98, 131);
|
||||||
@ -186,17 +190,37 @@
|
|||||||
// label5
|
// label5
|
||||||
//
|
//
|
||||||
this.label5.AutoSize = true;
|
this.label5.AutoSize = true;
|
||||||
this.label5.Location = new System.Drawing.Point(840, 322);
|
this.label5.Location = new System.Drawing.Point(902, 322);
|
||||||
this.label5.Name = "label5";
|
this.label5.Name = "label5";
|
||||||
this.label5.Size = new System.Drawing.Size(137, 12);
|
this.label5.Size = new System.Drawing.Size(137, 12);
|
||||||
this.label5.TabIndex = 81;
|
this.label5.TabIndex = 81;
|
||||||
this.label5.Text = "查询字段sql自定义,可空";
|
this.label5.Text = "查询字段sql自定义,可空";
|
||||||
//
|
//
|
||||||
|
// isGenOperationColumn
|
||||||
|
//
|
||||||
|
this.isGenOperationColumn.AutoSize = true;
|
||||||
|
this.isGenOperationColumn.Location = new System.Drawing.Point(256, 538);
|
||||||
|
this.isGenOperationColumn.Name = "isGenOperationColumn";
|
||||||
|
this.isGenOperationColumn.Size = new System.Drawing.Size(15, 14);
|
||||||
|
this.isGenOperationColumn.TabIndex = 82;
|
||||||
|
this.isGenOperationColumn.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// label6
|
||||||
|
//
|
||||||
|
this.label6.AutoSize = true;
|
||||||
|
this.label6.Location = new System.Drawing.Point(89, 538);
|
||||||
|
this.label6.Name = "label6";
|
||||||
|
this.label6.Size = new System.Drawing.Size(161, 12);
|
||||||
|
this.label6.TabIndex = 83;
|
||||||
|
this.label6.Text = "是否生成操作列(生成2和3):";
|
||||||
|
//
|
||||||
// Form1
|
// Form1
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(1084, 778);
|
this.ClientSize = new System.Drawing.Size(1084, 778);
|
||||||
|
this.Controls.Add(this.label6);
|
||||||
|
this.Controls.Add(this.isGenOperationColumn);
|
||||||
this.Controls.Add(this.label5);
|
this.Controls.Add(this.label5);
|
||||||
this.Controls.Add(this.textBox3);
|
this.Controls.Add(this.textBox3);
|
||||||
this.Controls.Add(this.button4);
|
this.Controls.Add(this.button4);
|
||||||
@ -212,7 +236,7 @@
|
|||||||
this.Controls.Add(this.label3);
|
this.Controls.Add(this.label3);
|
||||||
this.Controls.Add(this.txt_ret);
|
this.Controls.Add(this.txt_ret);
|
||||||
this.Controls.Add(this.label2);
|
this.Controls.Add(this.label2);
|
||||||
this.Controls.Add(this.button1);
|
this.Controls.Add(this.modelGen);
|
||||||
this.Name = "Form1";
|
this.Name = "Form1";
|
||||||
this.Text = "Form1";
|
this.Text = "Form1";
|
||||||
this.Load += new System.EventHandler(this.Form1_Load);
|
this.Load += new System.EventHandler(this.Form1_Load);
|
||||||
@ -223,7 +247,7 @@
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private System.Windows.Forms.Button button1;
|
private System.Windows.Forms.Button modelGen;
|
||||||
private System.Windows.Forms.Label label2;
|
private System.Windows.Forms.Label label2;
|
||||||
private System.Windows.Forms.TextBox txt_ret;
|
private System.Windows.Forms.TextBox txt_ret;
|
||||||
private System.Windows.Forms.Label label3;
|
private System.Windows.Forms.Label label3;
|
||||||
@ -239,6 +263,8 @@
|
|||||||
private System.Windows.Forms.Button button4;
|
private System.Windows.Forms.Button button4;
|
||||||
private System.Windows.Forms.TextBox textBox3;
|
private System.Windows.Forms.TextBox textBox3;
|
||||||
private System.Windows.Forms.Label label5;
|
private System.Windows.Forms.Label label5;
|
||||||
|
private System.Windows.Forms.CheckBox isGenOperationColumn;
|
||||||
|
private System.Windows.Forms.Label label6;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,19 +1,8 @@
|
|||||||
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
|
||||||
@ -24,7 +13,6 @@ 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());
|
||||||
@ -39,53 +27,37 @@ 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 button1_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
fillTemplate();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void fillTemplate()
|
}
|
||||||
|
private void modelGen_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
fillModelTemplate();
|
||||||
|
}
|
||||||
|
private void dgvGen1_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
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();//名称空间名称
|
||||||
DataTable dt = null;
|
List<Dictionary<string, string>> filedInfos = DbUtil.getTableInfo(tbname, textBox3.Text.Trim());
|
||||||
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", DbUtil.GenerateClassName(tbname));
|
template.Set("sql_table_name", tbname);
|
||||||
template.Set("table_name", tbname);
|
template.Set("table_name", DbUtil.GenerateClassName(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();
|
||||||
@ -94,229 +66,68 @@ 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();//要生成的表名
|
||||||
if (tbname.Equals("请选择") || tbname.Equals(""))
|
string dgvName = textBox2.Text.Trim(); //dgv空间名称
|
||||||
|
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"))
|
||||||
{
|
{
|
||||||
MessageBox.Show("请选择表");
|
string fileContent = reader.ReadToEnd();
|
||||||
return;
|
var template = Engine.CreateTemplate(fileContent);
|
||||||
};
|
template.Set("table_comment", DbUtil.GetTableComment(tbname));
|
||||||
DataTable dt = null;
|
template.Set("sql_table_name", tbname);
|
||||||
if (textBox3.Text.Trim() == "")
|
template.Set("table_name", DbUtil.GenerateClassName(tbname));
|
||||||
{
|
template.Set("dgv_name", dgvName);
|
||||||
dt = DbUtil.GetDbTableInfo(tbname);
|
template.Set("filedInfos", filedInfos);
|
||||||
|
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 = "";
|
|
||||||
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();//要生成的表名
|
||||||
if (tbname.Equals("请选择") || tbname.Equals(""))
|
string dgvName = textBox2.Text.Trim(); //dgv空间名称
|
||||||
|
List<string> timeFileds = DbUtil.getTimeFields(DbUtil.getTableInfo(tbname, textBox3.Text.Trim()));
|
||||||
|
using (StreamReader reader = new StreamReader(@".\Template\DataGridView_2.template"))
|
||||||
{
|
{
|
||||||
MessageBox.Show("请选择表");
|
string fileContent = reader.ReadToEnd();
|
||||||
return;
|
var template = Engine.CreateTemplate(fileContent);
|
||||||
};
|
template.Set("table_comment", DbUtil.GetTableComment(tbname));
|
||||||
DataTable dt = null;
|
template.Set("sql_table_name", tbname);
|
||||||
if (textBox3.Text.Trim() == "")
|
template.Set("table_name", DbUtil.GenerateClassName(tbname));
|
||||||
{
|
template.Set("dgv_name", dgvName);
|
||||||
dt = DbUtil.GetDbTableInfo(tbname);
|
template.Set("isGenOperationColumn", isGenOperationColumn.Checked);
|
||||||
|
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();//要生成的表名
|
||||||
if (tbname.Equals("请选择") || tbname.Equals(""))
|
string dgvName = textBox2.Text.Trim(); //dgv空间名称
|
||||||
|
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"))
|
||||||
{
|
{
|
||||||
MessageBox.Show("请选择表");
|
string fileContent = reader.ReadToEnd();
|
||||||
return;
|
var template = Engine.CreateTemplate(fileContent);
|
||||||
};
|
template.Set("table_comment", DbUtil.GetTableComment(tbname));
|
||||||
DataTable dt = null;
|
template.Set("sql_table_name", tbname);
|
||||||
if (textBox3.Text.Trim() == "") dt = DbUtil.GetDbTableInfo(tbname);
|
template.Set("table_name", DbUtil.GenerateClassName(tbname));
|
||||||
else dt = DbHelperMySQL.Query(textBox3.Text.Trim());
|
template.Set("dgv_name", dgvName);
|
||||||
string uidatagridview = textBox2.Text.Trim();
|
template.Set("filedInfos", filedInfos);
|
||||||
textBox1.Text = $"this.{uidatagridview}.AutoGenerateColumns = false;";
|
template.Set("isGenOperationColumn", isGenOperationColumn.Checked);
|
||||||
textBox1.Text += "List<DataGridViewColumn> cols = new List<DataGridViewColumn>();\n\n";
|
template.Set("timeFiledStr", DbUtil.joinList(timeFileds));
|
||||||
var list = new List<string>();
|
template.SetStaticType("string", typeof(string));
|
||||||
for (int i = 0; i < dt.Rows.Count; i++)
|
var result = template.Render();
|
||||||
{
|
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; }};";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using GenerateClass.Util;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -14,6 +15,7 @@ namespace GenerateClass
|
|||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
|
Config.GlobalInit();
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
Application.Run(new Form1());
|
Application.Run(new Form1());
|
||||||
|
35
DatabasetoEntityclass/Template/DataGridView_1.template
Normal file
35
DatabasetoEntityclass/Template/DataGridView_1.template
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
DataTable data = DbHelperMySQL.Query("select * from `${sql_table_name}`");
|
||||||
|
this.${dgv_name}.DataSource = new BindingSource {DataSource = data};
|
||||||
|
$foreach(filedInfo in filedInfos)
|
||||||
|
var ${filedInfo["field_name"]}Column = ${dgv_name}.Columns["${filedInfo["sql_field_name"]}"];
|
||||||
|
$end
|
||||||
|
|
||||||
|
$foreach(filedInfo in filedInfos)
|
||||||
|
${filedInfo["field_name"]}Column.HeaderText = "${filedInfo["comment"]}";
|
||||||
|
$end
|
||||||
|
${dgv_name}.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.ColumnHeader;
|
||||||
|
${dgv_name}.AutoGenerateColumns = true;
|
||||||
|
|
||||||
|
$if(timeFiledStr != "")
|
||||||
|
DateTimePicker dtp = new DateTimePicker();
|
||||||
|
${dgv_name}.Controls.Add(dtp);
|
||||||
|
dtp.Visible = false;
|
||||||
|
dtp.TextChanged += (sender, e) => ${dgv_name}.CurrentCell.Value = dtp.Value.ToString("yyyy-MM-dd");
|
||||||
|
dtp.CloseUp += (sender, e) => dtp.Visible = false;
|
||||||
|
${dgv_name}.CellClick += (sender, e) => {
|
||||||
|
if (e.ColumnIndex == -1 || e.RowIndex == -1) return;
|
||||||
|
DataGridView dgv = (sender as DataGridView);
|
||||||
|
if (new List<string>() {
|
||||||
|
${timeFiledStr}
|
||||||
|
}.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;
|
||||||
|
};
|
||||||
|
${dgv_name}.Scroll += (sender, e) => dtp.Visible = false;
|
||||||
|
${dgv_name}.SizeChanged += (sender, e) => { if (dtp.Visible) dtp.Visible = false; };
|
||||||
|
$end
|
65
DatabasetoEntityclass/Template/DataGridView_2.template
Normal file
65
DatabasetoEntityclass/Template/DataGridView_2.template
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
this.${dgv_name}.AutoGenerateColumns = false;
|
||||||
|
string sql = $"SELECT column_name, column_comment from information_schema.COLUMNS where table_name = '${sql_table_name}' ORDER BY ORDINAL_POSITION; ";
|
||||||
|
DataTable dt = DbHelperMySQL.Query(sql);
|
||||||
|
List<DataGridViewColumn> cols = new List<DataGridViewColumn>();
|
||||||
|
for (int i = 0; i < dt.Rows.Count; i++){
|
||||||
|
DataGridViewTextBoxColumn temp = new DataGridViewTextBoxColumn();
|
||||||
|
temp.Name = dt.Rows[i][0].ToString();
|
||||||
|
temp.HeaderText = dt.Rows[i][1].ToString();
|
||||||
|
temp.DataPropertyName= dt.Rows[i][0].ToString();
|
||||||
|
cols.Add(temp);
|
||||||
|
}
|
||||||
|
$if(isGenOperationColumn)
|
||||||
|
DataGridViewButtonColumn editBtn = new DataGridViewButtonColumn();
|
||||||
|
editBtn.HeaderText = "编辑";
|
||||||
|
editBtn.Name = "editBtn";
|
||||||
|
editBtn.Text = "编辑";
|
||||||
|
editBtn.UseColumnTextForButtonValue = true;
|
||||||
|
editBtn.Frozen = true;
|
||||||
|
|
||||||
|
DataGridViewButtonColumn addBtn = new DataGridViewButtonColumn();
|
||||||
|
addBtn.HeaderText = "新增";
|
||||||
|
addBtn.Name = "addBtn";
|
||||||
|
addBtn.Text = "新增";
|
||||||
|
addBtn.UseColumnTextForButtonValue = true;
|
||||||
|
addBtn.Frozen = true;
|
||||||
|
cols.Add(editBtn);
|
||||||
|
cols.Add(addBtn);
|
||||||
|
if (cols.Last().Frozen)
|
||||||
|
{
|
||||||
|
this.${dgv_name}.RightToLeft = RightToLeft.Yes;
|
||||||
|
cols.Reverse();
|
||||||
|
}
|
||||||
|
$end
|
||||||
|
this.${dgv_name}.Columns.AddRange(cols.ToArray());
|
||||||
|
$if(isGenOperationColumn)
|
||||||
|
if (cols.Count > 0)
|
||||||
|
this.${dgv_name}.FirstDisplayedScrollingColumnIndex = cols.Count - 2;
|
||||||
|
$end
|
||||||
|
${dgv_name}.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.ColumnHeader;
|
||||||
|
DataTable data = DbHelperMySQL.Query("select * from ${sql_table_name}");
|
||||||
|
this.${dgv_name}.DataSource = data;
|
||||||
|
|
||||||
|
$if(timeFiledStr != "")
|
||||||
|
DateTimePicker dtp = new DateTimePicker();
|
||||||
|
${dgv_name}.Controls.Add(dtp);
|
||||||
|
dtp.Visible = false;
|
||||||
|
dtp.TextChanged += (sender, e) => ${dgv_name}.CurrentCell.Value = dtp.Value.ToString("yyyy-MM-dd");
|
||||||
|
dtp.CloseUp += (sender, e) => dtp.Visible = false;
|
||||||
|
${dgv_name}.CellClick += (sender, e) => {
|
||||||
|
if (e.ColumnIndex == -1 || e.RowIndex == -1) return;
|
||||||
|
DataGridView dgv = (sender as DataGridView);
|
||||||
|
if (new List<string>() {
|
||||||
|
${timeFiledStr}
|
||||||
|
}.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;
|
||||||
|
};
|
||||||
|
${dgv_name}.Scroll += (sender, e) => dtp.Visible = false;
|
||||||
|
${dgv_name}.SizeChanged += (sender, e) => { if (dtp.Visible) dtp.Visible = false; };
|
||||||
|
$end
|
66
DatabasetoEntityclass/Template/DataGridView_3.template
Normal file
66
DatabasetoEntityclass/Template/DataGridView_3.template
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
this.${dgv_name}.AutoGenerateColumns = false;
|
||||||
|
List<DataGridViewColumn> cols = new List<DataGridViewColumn>();
|
||||||
|
$foreach(filedInfo in filedInfos)
|
||||||
|
|
||||||
|
DataGridViewTextBoxColumn ${filedInfo["field_name"]}Cloumn = new DataGridViewTextBoxColumn();
|
||||||
|
$if(filedInfo["is_primary_key"]=="true")
|
||||||
|
${filedInfo["field_name"]}Cloumn.Visible= false;
|
||||||
|
$end
|
||||||
|
${filedInfo["field_name"]}Cloumn.Name = "${filedInfo["sql_field_name"]}"; ${filedInfo["field_name"]}Cloumn.HeaderText = "${filedInfo["comment"]}";
|
||||||
|
${filedInfo["field_name"]}Cloumn.DataPropertyName = "${filedInfo["sql_field_name"]}"; cols.Add(${filedInfo["field_name"]}Cloumn);
|
||||||
|
$end
|
||||||
|
|
||||||
|
$if(isGenOperationColumn)
|
||||||
|
DataGridViewButtonColumn editBtn = new DataGridViewButtonColumn();
|
||||||
|
editBtn.HeaderText = "编辑";
|
||||||
|
editBtn.Name = "editBtn";
|
||||||
|
editBtn.Text = "编辑";
|
||||||
|
editBtn.UseColumnTextForButtonValue = true;
|
||||||
|
editBtn.Frozen = true;
|
||||||
|
|
||||||
|
DataGridViewButtonColumn addBtn = new DataGridViewButtonColumn();
|
||||||
|
addBtn.HeaderText = "新增";
|
||||||
|
addBtn.Name = "addBtn";
|
||||||
|
addBtn.Text = "新增";
|
||||||
|
addBtn.UseColumnTextForButtonValue = true;
|
||||||
|
addBtn.Frozen = true;
|
||||||
|
cols.Add(editBtn);
|
||||||
|
cols.Add(addBtn);
|
||||||
|
if (cols.Last().Frozen)
|
||||||
|
{
|
||||||
|
this.${dgv_name}.RightToLeft = RightToLeft.Yes;
|
||||||
|
cols.Reverse();
|
||||||
|
}
|
||||||
|
$end
|
||||||
|
this.${dgv_name}.Columns.AddRange(cols.ToArray());
|
||||||
|
$if(isGenOperationColumn)
|
||||||
|
if (cols.Count > 0)
|
||||||
|
this.${dgv_name}.FirstDisplayedScrollingColumnIndex = cols.Count - 2;
|
||||||
|
$end
|
||||||
|
${dgv_name}.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.ColumnHeader;
|
||||||
|
DataTable data = DbHelperMySQL.Query($"select * from ${sql_table_name}");
|
||||||
|
this.${dgv_name}.DataSource = data;
|
||||||
|
|
||||||
|
$if(timeFiledStr != "")
|
||||||
|
DateTimePicker dtp = new DateTimePicker();
|
||||||
|
${dgv_name}.Controls.Add(dtp);
|
||||||
|
dtp.Visible = false;
|
||||||
|
dtp.TextChanged += (sender, e) => ${dgv_name}.CurrentCell.Value = dtp.Value.ToString("yyyy-MM-dd");
|
||||||
|
dtp.CloseUp += (sender, e) => dtp.Visible = false;
|
||||||
|
${dgv_name}.CellClick += (sender, e) => {
|
||||||
|
if (e.ColumnIndex == -1 || e.RowIndex == -1) return;
|
||||||
|
DataGridView dgv = (sender as DataGridView);
|
||||||
|
if (new List<string>() {
|
||||||
|
${timeFiledStr}
|
||||||
|
}.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;
|
||||||
|
};
|
||||||
|
${dgv_name}.Scroll += (sender, e) => dtp.Visible = false;
|
||||||
|
${dgv_name}.SizeChanged += (sender, e) => { if (dtp.Visible) dtp.Visible = false; };
|
||||||
|
$end
|
@ -12,7 +12,7 @@ namespace ${namespace_name}
|
|||||||
$foreach(filedInfo in filedInfos)
|
$foreach(filedInfo in filedInfos)
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///${filedInfo["comment"]}
|
/// ${filedInfo["comment"]}
|
||||||
/// </summary>
|
/// </summary>
|
||||||
$if(filedInfo["is_primary_key"]=="true")
|
$if(filedInfo["is_primary_key"]=="true")
|
||||||
[TableId]
|
[TableId]
|
||||||
|
14
DatabasetoEntityclass/Util/Config.cs
Normal file
14
DatabasetoEntityclass/Util/Config.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using JinianNet.JNTemplate;
|
||||||
|
|
||||||
|
namespace GenerateClass.Util
|
||||||
|
{
|
||||||
|
public class Config
|
||||||
|
{
|
||||||
|
public static void GlobalInit()
|
||||||
|
{
|
||||||
|
Engine.Configure((options) => {
|
||||||
|
options.OutMode = OutMode.Auto;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -24,6 +24,7 @@ namespace GenerateClass.Util
|
|||||||
// 打开文件夹
|
// 打开文件夹
|
||||||
System.Diagnostics.Process.Start(folderPath);
|
System.Diagnostics.Process.Start(folderPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string joinList(List<string> list)
|
public static string joinList(List<string> list)
|
||||||
{
|
{
|
||||||
string str = "";
|
string str = "";
|
||||||
@ -33,6 +34,42 @@ namespace GenerateClass.Util
|
|||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<Dictionary<string, string>> getTableInfo(string tbname, string sql = "")
|
||||||
|
{
|
||||||
|
DataTable dt = null;
|
||||||
|
if (sql == "")
|
||||||
|
dt = DbUtil.GetDbTableInfo(tbname);
|
||||||
|
else
|
||||||
|
dt = DbHelperMySQL.Query(sql);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
return filedInfos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<string> getTimeFields(List<Dictionary<string, string>> filedInfos)
|
||||||
|
{
|
||||||
|
var list = new List<string>();
|
||||||
|
filedInfos.ForEach(info => {
|
||||||
|
if (info["type_name"] == "DateTime") list.Add(info["sql_field_name"]);
|
||||||
|
});
|
||||||
|
return list;
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 根据参数,获取数据表信息
|
/// 根据参数,获取数据表信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
234
DatabasetoEntityclass/Util/OldInfo.cs
Normal file
234
DatabasetoEntityclass/Util/OldInfo.cs
Normal file
@ -0,0 +1,234 @@
|
|||||||
|
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);
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user