|
|
|
@ -4,6 +4,7 @@ using System.IO;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using GenerateClass.Util;
|
|
|
|
|
using JinianNet.JNTemplate;
|
|
|
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
|
|
|
|
|
|
|
|
namespace GenerateClass
|
|
|
|
|
{
|
|
|
|
@ -14,9 +15,25 @@ namespace GenerateClass
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
loadControl();
|
|
|
|
|
}
|
|
|
|
|
private string tableName;
|
|
|
|
|
|
|
|
|
|
#region 加载控件
|
|
|
|
|
private void loadControl()
|
|
|
|
|
{
|
|
|
|
|
loadTableNameControl();
|
|
|
|
|
loadDataBaseNameControl();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 加载表名控件
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void loadTableNameControl()
|
|
|
|
|
{
|
|
|
|
|
this.txt_tablename.Items.AddRange(DbUtil.GetTableName().ToArray());
|
|
|
|
|
this.txt_tablename.TextUpdate += (childSender, childE) => {
|
|
|
|
|
this.txt_tablename.TextUpdate += (childSender, childE) =>
|
|
|
|
|
{
|
|
|
|
|
string str = this.txt_tablename.Text; //获取输入内容
|
|
|
|
|
List<string> sList = DbUtil.GetTableName(str); //存放数据库查询结果
|
|
|
|
|
//提前下拉,以显示搜索结果(必须要在添加项之前下拉,否则会将第一项自动添加到编辑框内 覆盖掉输入的内容)
|
|
|
|
@ -27,24 +44,76 @@ namespace GenerateClass
|
|
|
|
|
this.txt_tablename.Items.AddRange(sList.ToArray());
|
|
|
|
|
this.txt_tablename.Select(this.txt_tablename.Text.Length, 0);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 加载数据库名控件
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void loadDataBaseNameControl()
|
|
|
|
|
{
|
|
|
|
|
this.txt_database.Items.AddRange(DbUtil.GetDataBaseName().ToArray());
|
|
|
|
|
this.txt_database.TextUpdate += (childSender, childE) =>
|
|
|
|
|
{
|
|
|
|
|
string str = this.txt_database.Text; //获取输入内容
|
|
|
|
|
List<string> sList = DbUtil.GetDataBaseName(str); //存放数据库查询结果
|
|
|
|
|
//提前下拉,以显示搜索结果(必须要在添加项之前下拉,否则会将第一项自动添加到编辑框内 覆盖掉输入的内容)
|
|
|
|
|
this.txt_database.DroppedDown = true; //显示下拉列表,但是显示后鼠标指针就不见了
|
|
|
|
|
Cursor.Current = Cursors.Default; //将指针显示出来
|
|
|
|
|
//在表中已录入名字中寻找包含输入内容的项 有则添加到comboBox项中
|
|
|
|
|
this.txt_database.Items.Clear();
|
|
|
|
|
this.txt_database.Items.AddRange(sList.ToArray());
|
|
|
|
|
this.txt_database.Select(this.txt_database.Text.Length, 0);
|
|
|
|
|
this.txt_tablename.Items.Clear();
|
|
|
|
|
};
|
|
|
|
|
this.txt_database.Text = DbHelperMySQL.DbName;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
private void modelGen_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (validateTableName())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
fillModelTemplate();
|
|
|
|
|
}
|
|
|
|
|
private void dgvGen1_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (validateTableName())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
fillDgv1Template();
|
|
|
|
|
}
|
|
|
|
|
private void dgvGen2_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (validateTableName())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
fillDgv2Template();
|
|
|
|
|
}
|
|
|
|
|
private void dgvGen3_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (validateTableName())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
fillDgv3Template();
|
|
|
|
|
}
|
|
|
|
|
private bool validateTableName()
|
|
|
|
|
{
|
|
|
|
|
string tbname = txt_tablename.Text.Trim();//要生成的表名
|
|
|
|
|
if (string.IsNullOrEmpty(tbname))
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("请选择表");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (tableName != tbname)
|
|
|
|
|
{
|
|
|
|
|
MessageBox.Show("请选择正确的表");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
private void fillModelTemplate()
|
|
|
|
|
{
|
|
|
|
|
string tbname = txt_tablename.Text.Trim();//要生成的表名
|
|
|
|
@ -59,6 +128,9 @@ namespace GenerateClass
|
|
|
|
|
template.Set("sql_table_name", tbname);
|
|
|
|
|
template.Set("table_name", DbUtil.GenerateClassName(tbname));
|
|
|
|
|
template.Set("filedInfos", filedInfos);
|
|
|
|
|
template.Set("dataBaseName", DbHelperMySQL.DbName);
|
|
|
|
|
template.Set("isGeneratorValidateClass", isGeneratorValidateClass.Checked);
|
|
|
|
|
template.Set("isGeneratorDynamicTableName", isGeneratorDynamicTableName.Checked);
|
|
|
|
|
template.SetStaticType("string", typeof(string));
|
|
|
|
|
var result = template.Render();
|
|
|
|
|
this.txt_ret.Text = result;
|
|
|
|
@ -82,6 +154,7 @@ namespace GenerateClass
|
|
|
|
|
template.Set("dgv_name", dgvName);
|
|
|
|
|
template.Set("filedInfos", filedInfos);
|
|
|
|
|
template.Set("timeFiledStr", DbUtil.joinList(timeFileds));
|
|
|
|
|
template.Set("dataBaseName", DbHelperMySQL.DbName);
|
|
|
|
|
template.SetStaticType("string", typeof(string));
|
|
|
|
|
var result = template.Render();
|
|
|
|
|
this.textBox1.Text = result;
|
|
|
|
@ -102,6 +175,7 @@ namespace GenerateClass
|
|
|
|
|
template.Set("dgv_name", dgvName);
|
|
|
|
|
template.Set("isGenOperationColumn", isGenOperationColumn.Checked);
|
|
|
|
|
template.Set("timeFiledStr", DbUtil.joinList(timeFileds));
|
|
|
|
|
template.Set("dataBaseName", DbHelperMySQL.DbName);
|
|
|
|
|
template.SetStaticType("string", typeof(string));
|
|
|
|
|
var result = template.Render();
|
|
|
|
|
this.textBox1.Text = result;
|
|
|
|
@ -124,10 +198,29 @@ namespace GenerateClass
|
|
|
|
|
template.Set("filedInfos", filedInfos);
|
|
|
|
|
template.Set("isGenOperationColumn", isGenOperationColumn.Checked);
|
|
|
|
|
template.Set("timeFiledStr", DbUtil.joinList(timeFileds));
|
|
|
|
|
template.Set("dataBaseName", DbHelperMySQL.DbName);
|
|
|
|
|
template.SetStaticType("string", typeof(string));
|
|
|
|
|
var result = template.Render();
|
|
|
|
|
this.textBox1.Text = result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txt_tablename_SelectionChangeCommitted(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// 获取选中的值
|
|
|
|
|
string selectedValue = txt_tablename.SelectedItem.ToString();
|
|
|
|
|
tableName = selectedValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txt_database_SelectionChangeCommitted(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.txt_tablename.Items.Clear();
|
|
|
|
|
// 获取选中的值
|
|
|
|
|
string selectedValue = txt_database.SelectedItem.ToString();
|
|
|
|
|
DbHelperMySQL.DbName = selectedValue;
|
|
|
|
|
this.txt_tablename.SelectedIndex = -1;
|
|
|
|
|
this.txt_tablename.Text = "";
|
|
|
|
|
this.txt_tablename.Items.AddRange(DbUtil.GetTableName().ToArray());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|