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.
134 lines
6.5 KiB
C#
134 lines
6.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Windows.Forms;
|
|
using GenerateClass.Util;
|
|
using JinianNet.JNTemplate;
|
|
|
|
namespace GenerateClass
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
{
|
|
this.txt_tablename.Items.AddRange(DbUtil.GetTableName().ToArray());
|
|
this.txt_tablename.TextUpdate += (childSender, childE) => {
|
|
string str = this.txt_tablename.Text; //获取输入内容
|
|
List<string> sList = DbUtil.GetTableName(str); //存放数据库查询结果
|
|
//提前下拉,以显示搜索结果(必须要在添加项之前下拉,否则会将第一项自动添加到编辑框内 覆盖掉输入的内容)
|
|
this.txt_tablename.DroppedDown = true; //显示下拉列表,但是显示后鼠标指针就不见了
|
|
Cursor.Current = Cursors.Default; //将指针显示出来
|
|
//在表中已录入名字中寻找包含输入内容的项 有则添加到comboBox项中
|
|
this.txt_tablename.Items.Clear();
|
|
this.txt_tablename.Items.AddRange(sList.ToArray());
|
|
this.txt_tablename.Select(this.txt_tablename.Text.Length, 0);
|
|
};
|
|
|
|
}
|
|
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 namespaceName = namespace_name.Text.Trim();//名称空间名称
|
|
List<Dictionary<string, string>> filedInfos = DbUtil.getTableInfo(tbname, textBox3.Text.Trim());
|
|
using (StreamReader reader = new StreamReader(@".\Template\ModelFile.template"))
|
|
{
|
|
string fileContent = reader.ReadToEnd();
|
|
var template = Engine.CreateTemplate(fileContent);
|
|
template.Set("namespace_name", namespaceName);
|
|
template.Set("table_comment", DbUtil.GetTableComment(tbname));
|
|
template.Set("sql_table_name", tbname);
|
|
template.Set("table_name", DbUtil.GenerateClassName(tbname));
|
|
template.Set("filedInfos", filedInfos);
|
|
template.SetStaticType("string", typeof(string));
|
|
var result = template.Render();
|
|
this.txt_ret.Text = result;
|
|
DbUtil.openFile(tbname, result);
|
|
}
|
|
|
|
}
|
|
private void fillDgv1Template()
|
|
{
|
|
string tbname = txt_tablename.Text.Trim();//要生成的表名
|
|
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"))
|
|
{
|
|
string fileContent = reader.ReadToEnd();
|
|
var template = Engine.CreateTemplate(fileContent);
|
|
template.Set("table_comment", DbUtil.GetTableComment(tbname));
|
|
template.Set("sql_table_name", tbname);
|
|
template.Set("table_name", DbUtil.GenerateClassName(tbname));
|
|
template.Set("dgv_name", dgvName);
|
|
template.Set("filedInfos", filedInfos);
|
|
template.Set("timeFiledStr", DbUtil.joinList(timeFileds));
|
|
template.SetStaticType("string", typeof(string));
|
|
var result = template.Render();
|
|
this.textBox1.Text = result;
|
|
}
|
|
}
|
|
private void fillDgv2Template()
|
|
{
|
|
string tbname = txt_tablename.Text.Trim();//要生成的表名
|
|
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"))
|
|
{
|
|
string fileContent = reader.ReadToEnd();
|
|
var template = Engine.CreateTemplate(fileContent);
|
|
template.Set("table_comment", DbUtil.GetTableComment(tbname));
|
|
template.Set("sql_table_name", tbname);
|
|
template.Set("table_name", DbUtil.GenerateClassName(tbname));
|
|
template.Set("dgv_name", dgvName);
|
|
template.Set("isGenOperationColumn", isGenOperationColumn.Checked);
|
|
template.Set("timeFiledStr", DbUtil.joinList(timeFileds));
|
|
template.SetStaticType("string", typeof(string));
|
|
var result = template.Render();
|
|
this.textBox1.Text = result;
|
|
}
|
|
}
|
|
private void fillDgv3Template()
|
|
{
|
|
string tbname = txt_tablename.Text.Trim();//要生成的表名
|
|
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"))
|
|
{
|
|
string fileContent = reader.ReadToEnd();
|
|
var template = Engine.CreateTemplate(fileContent);
|
|
template.Set("table_comment", DbUtil.GetTableComment(tbname));
|
|
template.Set("sql_table_name", tbname);
|
|
template.Set("table_name", DbUtil.GenerateClassName(tbname));
|
|
template.Set("dgv_name", dgvName);
|
|
template.Set("filedInfos", filedInfos);
|
|
template.Set("isGenOperationColumn", isGenOperationColumn.Checked);
|
|
template.Set("timeFiledStr", DbUtil.joinList(timeFileds));
|
|
template.SetStaticType("string", typeof(string));
|
|
var result = template.Render();
|
|
this.textBox1.Text = result;
|
|
}
|
|
}
|
|
}
|
|
}
|