C#自动代码生成器
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
C#自动代码生成器
自动生成数据表和实体类
namespace SQLApplicationAutoGeneratiTool
{
public partial class Form1 : Form
{
string[] strArray = { "int", "string", "decimal", "bool", "char", "object", "double", "float", "DateTime" };
String path = @"..\..\..\类文件\";
public Form1()
{
InitializeComponent();
}
private void 新增文本框ToolStripMenuItem_Click(object sender, EventArgs e)
{
ShengChengKongJian();
}
private void ShengChengKongJian()
{
ComboBox cobm = new ComboBox();
for (int i = 0; i < strArray.Count(); i++)
{
cobm.Items.Add(strArray[i]);
}
TextBox textbox = new TextBox();
this.flowLayoutPanel1.Controls.Add(cobm);
this.flowLayoutPanel2.Controls.Add(textbox);
}
StringBuilder stbd = null;
List
private void button1_Click(object sender, EventArgs e)
{
if (comboBox1.Text.Trim() == "")
{
MessageBox.Show("类名不能为空");
return;
}
stbd = new StringBuilder("using System;");
strbldList.Add(stbd);
stbd = new StringBuilder("using System.Collections.Generic;");
strbldList.Add(stbd);
stbd = new StringBuilder("using System.Linq;");
strbldList.Add(stbd);
stbd = new StringBuilder("using System.Text;");
strbldList.Add(stbd);
stbd = new StringBuilder("using System.Data;");
strbldList.Add(stbd);
stbd = new StringBuilder("using System.Data.SqlClient;");
strbldList.Add(stbd);
stbd = new StringBuilder("using System.Windows.Forms;");
strbldList.Add(stbd);
stbd = new StringBuilder("namespace HospitalInformationManagmentSystem");
strbldList.Add(stbd);
stbd = new StringBuilder("{");
strbldList.Add(stbd);
stbd = new StringBuilder(" /* 作者:大理大学软件教研室杜老师"); strbldList.Add(stbd);
stbd = new StringBuilder(" * 日期:" + dateTimePicker1.Text.Trim()); strbldList.Add(stbd);
stbd = new StringBuilder(" * 版权:大理大学");
strbldList.Add(stbd);
stbd = new StringBuilder(" * 你可以免费使用或修改以下代码,但请保留版权信息,否则将追究相关责任");
strbldList.Add(stbd);
stbd = new StringBuilder(" */");
strbldList.Add(stbd);
stbd = new StringBuilder(" public class ");
stbd.Append(comboBox1.Text.Trim());
strbldList.Add(stbd);
stbd = new StringBuilder(" {");
strbldList.Add(stbd);
stbd = new StringBuilder(" #region 属性");
strbldList.Add(stbd);
for (int i = 0; i < flowLayoutPanel1.Controls.Count; i++)
{
StringBuilder std = new StringBuilder(" private ");
std.Append((flowLayoutPanel1.Controls[i]).Text.Trim());
std.Append(" ");
std.Append(flowLayoutPanel2.Controls[i].Text.Trim());
std.Append(";");
strbldList.Add(std);
}
string shuX = "";
string st = "";
string s1 = "";
for (int i = 0; i < flowLayoutPanel1.Controls.Count; i++)
{
shuX = " public " + flowLayoutPanel1.Controls[i].Text.Trim() + " _" + flowLayoutPanel2.Controls[i].Text.Trim();
st = " set {" + flowLayoutPanel2.Controls[i].Text.Trim() + "= value; }";
s1 = " get { return " + flowLayoutPanel2.Controls[i].Text.Trim() + ";}";
stbd = new StringBuilder(shuX);
strbldList.Add(stbd);
stbd = new StringBuilder(" {");
strbldList.Add(stbd);
stbd = new StringBuilder(st);
strbldList.Add(stbd);
stbd = new StringBuilder(s1);
strbldList.Add(stbd);
stbd = new StringBuilder(" }");
strbldList.Add(stbd);
}
stbd = new StringBuilder(" #endregion 属性");
strbldList.Add(stbd);
stbd = new StringBuilder(" HIMSSqlConnection sqlcon = new HIMSSqlConnection();"); strbldList.Add(stbd);
stbd = new StringBuilder(" ///
strbldList.Add(stbd);
stbd = new StringBuilder(" /// 增加一条记录");
strbldList.Add(stbd);
stbd = new StringBuilder(" /// ");
strbldList.Add(stbd);