private void frmEntity_Load(object sender, EventArgs e) { //Data.ConnString = WebConfig.GetConn("ConnString"); textBox1.Text = config.Project; config.OPList = TableStructureFactory.LoadOPList(config, entity => { listBox.Items.Add((entity.isView ? "* " : "") + entity.Name, entity.isView ? false : true); }); if (listBox.Items.Count > 0) listBox.SelectedIndex = 0; this.Text = "Entity Tool [{2}] - {1}连接共有{0}个表".FormatWith(listBox.Items.Count, Data.DBType, config.TemplateName); }
public static void Init(bool exit = false) { tables.Clear(); config.OPList = TableStructureFactory.LoadOPList(config, entity => { tables.Add((entity.isView ? "* " : "") + entity.Name); }); Console.Write("Table".PadRight(20, ' ')); Console.Write(" | E "); Console.Write("| I "); Console.Write("| U "); Console.Write("| UI "); Console.Write("| D "); Console.Write("| E "); Console.Write("| S "); Console.Write("| SP "); Console.Write("| FK "); Console.Write("| All "); Console.WriteLine(); WriteLog("-".PadLeft(70, '-')); foreach (string key in tables) { string tabName = key; if (tabName.IndexOf("* ") == 0) { tabName = tabName.Substring(2); } TableOperator to = config.OPList.Where(p => p.Table == tabName).FirstOrDefault(); Console.Write(key.SubString(20, "").PadRight(20, ' ')); Console.Write(" | {0} ", to.Entity ? 1 : 0); Console.Write("| {0} ", to.Insert ? 1 : 0); Console.Write("| {0} ", to.Update ? 1 : 0); Console.Write("| {0} ", to.UpdateAndInsert ? 1 : 0); Console.Write("| {0} ", to.DeleteByID ? 1 : 0); Console.Write("| {0} ", to.IsExistByID ? 1 : 0); Console.Write("| {0} ", to.SelectByID ? 1 : 0); Console.Write("| {0} ", to.SelectPageList ? 1 : 0); Console.Write("| {0} ", to.SelectListByFK ? 1 : 0); Console.Write("| {0} ", to.SelectListByAll ? 1 : 0); Console.WriteLine(); } WriteLog("END"); Input(exit); }
public static void Config(bool exit = false) { config = TableStructureFactory.GetConfig(); WriteLog("EntityTool.exe.config"); WriteLog("======数据库==================================================================="); WriteLog("数据库:{0}", Data.DBType); WriteLog("连接字符串(ConnString):{0}", Data.ConnString); WriteLog("======项目====================================================================="); WriteLog("项目名(Project):{0}", config.Project); WriteLog("作者(Author):{0}", config.Author); WriteLog("项目开始时间(ProjectStartDate):{0}", config.ProjectStartDate); WriteLog("版权(CopyRight):{0}", config.CopyRight); WriteLog("======设计模式================================================================="); WriteLog("设计模式(DesignPattern):{0}", config.DesignPattern); WriteLog("生成代码模板(TemplateName):{0}", config.TemplateName); if (config.DesignPattern == "Model-DAL-BLL") { WriteLog("实体类生成路径(ModelPath):{0}", config.ModelPath); WriteLog("数据操作类生成路径(DALPath):{0}", config.DALPath); WriteLog("数据操作接口生成路径(IDALPath):{0}", config.IDALPath); WriteLog("业务处理类生成路径(BLLPath):{0}", config.BLLPath); } else { WriteLog("设计模式后缀(DesignPatternExtName):{0}", config.DesignPatternExtName); WriteLog("实体类生成路径(EntityPath):{0}", config.EntityPath); WriteLog("工厂类生成路径(FactoryPath):{0}", config.FactoryPath); } WriteLog("数据分页(PagerSqlEnum):{0}", config.PagerSqlEnum); if (!config.AdminPath.IsNullEmpty()) { WriteLog("======后台====================================================================="); WriteLog("后台生成路径(AdminPath):{0}", config.AdminPath); WriteLog("后台分页大小默认(PageSize):{0}", config.PageSize); WriteLog("使用单页(UseOneProject):{0}", config.UseOneProject.ToString()); } WriteLog("END"); Input(exit); }
private void doRun() { if (listBox.Items.Count <= 0) return; string tabName = listBox.Items[listBox.SelectedIndex].ToString(); if (string.IsNullOrEmpty(tabName)) return; bool isView = false; if (tabName.IndexOf("* ") == 0) { tabName = tabName.Substring(2); isView = true; } string dalCode = string.Empty; string idalCode = string.Empty; string bllCode = string.Empty; string sqlCode = string.Empty; string baseCode = string.Empty; if (!string.IsNullOrEmpty(config.ModelPath) && config.OPList[listBox.SelectedIndex].Entity && config.DesignPattern == "Model-DAL-BLL") { tabPage1.Text = textBox1.Text + ".Model." + tabName; textBox.Text = TableStructureFactory.GetTableStructCode(config, tabName, textBox1.Text, out idalCode, out dalCode, out bllCode, out sqlCode, isView); Pub.Class.FileDirectory.DirectoryCreate(config.ModelPath + "\\Model\\"); Pub.Class.FileDirectory.FileDelete(config.ModelPath + "\\Model\\" + tabName + ".cs"); FileDirectory.FileWrite(config.ModelPath + "\\Model\\" + tabName + ".cs", textBox.Text); } if (!string.IsNullOrEmpty(config.EntityPath) && config.OPList[listBox.SelectedIndex].Entity && config.DesignPattern != "Model-DAL-BLL") { tabPage1.Text = textBox1.Text + ".Entity." + tabName; textBox.Text = TableStructureFactory.GetTableStructCode(config, tabName, textBox1.Text, out baseCode, out sqlCode, isView); Pub.Class.FileDirectory.DirectoryCreate(config.EntityPath + "\\Entity\\"); Pub.Class.FileDirectory.FileDelete(config.EntityPath + "\\Entity\\" + tabName + ".cs"); FileDirectory.FileWrite(config.EntityPath + "\\Entity\\" + tabName + ".cs", textBox.Text); } if (config.DesignPattern == "Model-DAL-BLL" && !string.IsNullOrEmpty(config.DALPath) && config.OPList[listBox.SelectedIndex].Entity) { tabPage2.Text = textBox1.Text + "." + config.TemplateName.Split('-')[3] + "DAL." + tabName + "DAL"; textBox2.Text = dalCode; Pub.Class.FileDirectory.DirectoryCreate(config.DALPath + "\\" + config.TemplateName.Split('-')[3] + "DAL" + "\\"); Pub.Class.FileDirectory.FileDelete(config.DALPath + "\\" + config.TemplateName.Split('-')[3] + "DAL" + "\\" + tabName + "DAL.cs"); Pub.Class.FileDirectory.DirectoryCreate(config.IDALPath + "\\IDAL\\"); Pub.Class.FileDirectory.FileDelete(config.IDALPath + "\\IDAL\\I" + tabName + "DAL.cs"); if (!string.IsNullOrEmpty(textBox2.Text.Trim())) { FileDirectory.FileWrite(config.DALPath + "\\" + config.TemplateName.Split('-')[3] + "DAL" + "\\" + tabName + "DAL.cs", textBox2.Text); FileDirectory.FileWrite(config.IDALPath + "\\IDAL\\I" + tabName + "DAL.cs", idalCode); } else { Pub.Class.FileDirectory.FileDelete(config.DALPath + "\\" + config.TemplateName.Split('-')[3] + "DAL" + "\\" + tabName + "DAL.cs"); Pub.Class.FileDirectory.FileDelete(config.IDALPath + "\\IDAL\\I" + tabName + "DAL.cs"); } tabPage3.Text = textBox1.Text + ".BLL." + tabName + "BLL"; textBox3.Text = bllCode; Pub.Class.FileDirectory.DirectoryCreate(config.BLLPath + "\\BLL\\"); Pub.Class.FileDirectory.FileDelete(config.BLLPath + "\\BLL\\" + tabName + "BLL.cs"); if (!string.IsNullOrEmpty(textBox3.Text.Trim())) { FileDirectory.FileWrite(config.BLLPath + "\\BLL\\" + tabName + "BLL.cs", textBox3.Text); sbSqlCode.AppendLine(sqlCode); textBox4.Text = sqlCode; } else { Pub.Class.FileDirectory.FileDelete(config.BLLPath + "\\BLL\\" + tabName + "BLL.cs"); } if (btnStart.Enabled) Clipboard.SetDataObject(textBox.Text); } if (config.DesignPattern != "Model-DAL-BLL" && !string.IsNullOrEmpty(config.FactoryPath) && config.OPList[listBox.SelectedIndex].Entity) { tabPage2.Text = textBox1.Text + "." + config.DesignPatternExtName + "." + tabName + "" + config.DesignPatternExtName + ""; textBox2.Text = baseCode; Pub.Class.FileDirectory.DirectoryCreate(config.FactoryPath + "\\" + config.DesignPatternExtName + "\\"); Pub.Class.FileDirectory.FileDelete(config.FactoryPath + "\\" + config.DesignPatternExtName + "\\" + tabName + "" + config.DesignPatternExtName + ".cs"); if (!string.IsNullOrEmpty(textBox2.Text.Trim())) { FileDirectory.FileWrite(config.FactoryPath + "\\" + config.DesignPatternExtName + "\\" + tabName + "" + config.DesignPatternExtName + ".cs", textBox2.Text); sbSqlCode.AppendLine(sqlCode); textBox3.Text = sqlCode; } else { Pub.Class.FileDirectory.FileDelete(config.FactoryPath + "\\" + config.DesignPatternExtName + "\\" + tabName + "" + config.DesignPatternExtName + ".cs"); } if (btnStart.Enabled) Clipboard.SetDataObject(textBox.Text); } }
public static void Run(bool exit = false) { if (!string.IsNullOrEmpty(config.AdminPath) && config.IsAll) { Pub.Class.FileDirectory.DirectoryCreate(config.AdminPath + "\\xml\\"); Pub.Class.FileDirectory.FileDelete(config.AdminPath + "\\xml\\db.aspx"); FileDirectory.FileWrite(config.AdminPath + "\\xml\\db.aspx", "<div class='MenuTitlebar' style='top: 12px; left: 12px; width: 168px; height: 25px;' title='数据库管理'><table cellspacing='0' cellpadding='0'><tbody><tr style='width: 185px; height: 25px;'><td class='MenuTitlebarLeft_Head' style='width: 13px;'/><td class='MenuTitlebarMiddle_Head' style='width: 130px;'><div class='MenuTitle_Head' style='width: 130px; height: 25px; line-height: 25px;'>数据库管理</div></td><td class='MenuTitlebarRight_Open_Head' style='width: 25px;'/></tr></tbody></table></div>\n\r<div class='MenuBody_Head' style='border-width: 0px 1px 1px; padding: 9px 0px; overflow: hidden; top: 37px; left: 12px; width: 166px; opacity: 1;'>"); } StringBuilder sbSqlCode = new StringBuilder(); tables.Clear(); config.OPList = TableStructureFactory.LoadOPList(config, entity => { tables.Add((entity.isView ? "* " : "") + entity.Name); }); foreach (string key in tables) { string tabName = key; bool isView = false; if (tabName.IndexOf("* ") == 0) { tabName = tabName.Substring(2); isView = true; } TableOperator to = config.OPList.Where(p => p.Table == tabName).FirstOrDefault(); string dalCode = string.Empty; string idalCode = string.Empty; string bllCode = string.Empty; string sqlCode = string.Empty; string baseCode = string.Empty; if (!string.IsNullOrEmpty(config.ModelPath) && to.Entity && config.DesignPattern == "Model-DAL-BLL") { string code = TableStructureFactory.GetTableStructCode(config, tabName, config.Project, out idalCode, out dalCode, out bllCode, out sqlCode, isView); Pub.Class.FileDirectory.DirectoryCreate(config.ModelPath + "\\Model\\"); Pub.Class.FileDirectory.FileDelete(config.ModelPath + "\\Model\\" + tabName + ".cs"); FileDirectory.FileWrite(config.ModelPath + "\\Model\\" + tabName + ".cs", code); } if (!string.IsNullOrEmpty(config.EntityPath) && to.Entity && config.DesignPattern != "Model-DAL-BLL") { string code = TableStructureFactory.GetTableStructCode(config, tabName, config.Project, out baseCode, out sqlCode, isView); Pub.Class.FileDirectory.DirectoryCreate(config.EntityPath + "\\Entity\\"); Pub.Class.FileDirectory.FileDelete(config.EntityPath + "\\Entity\\" + tabName + ".cs"); FileDirectory.FileWrite(config.EntityPath + "\\Entity\\" + tabName + ".cs", code); } if (config.DesignPattern == "Model-DAL-BLL" && !string.IsNullOrEmpty(config.DALPath) && to.Entity) { Pub.Class.FileDirectory.DirectoryCreate(config.DALPath + "\\" + config.TemplateName.Split('-')[3] + "DAL" + "\\"); Pub.Class.FileDirectory.FileDelete(config.DALPath + "\\" + config.TemplateName.Split('-')[3] + "DAL" + "\\" + tabName + "DAL.cs"); Pub.Class.FileDirectory.DirectoryCreate(config.IDALPath + "\\IDAL\\"); Pub.Class.FileDirectory.FileDelete(config.IDALPath + "\\IDAL\\I" + tabName + "DAL.cs"); if (!string.IsNullOrEmpty(dalCode.Trim())) { FileDirectory.FileWrite(config.DALPath + "\\" + config.TemplateName.Split('-')[3] + "DAL" + "\\" + tabName + "DAL.cs", dalCode); FileDirectory.FileWrite(config.IDALPath + "\\IDAL\\I" + tabName + "DAL.cs", idalCode); } else { Pub.Class.FileDirectory.FileDelete(config.DALPath + "\\" + config.TemplateName.Split('-')[3] + "DAL" + "\\" + tabName + "DAL.cs"); Pub.Class.FileDirectory.FileDelete(config.IDALPath + "\\IDAL\\I" + tabName + "DAL.cs"); } Pub.Class.FileDirectory.DirectoryCreate(config.BLLPath + "\\BLL\\"); Pub.Class.FileDirectory.FileDelete(config.BLLPath + "\\BLL\\" + tabName + "BLL.cs"); if (!string.IsNullOrEmpty(bllCode.Trim())) { FileDirectory.FileWrite(config.BLLPath + "\\BLL\\" + tabName + "BLL.cs", bllCode); sbSqlCode.AppendLine(sqlCode); } else { Pub.Class.FileDirectory.FileDelete(config.BLLPath + "\\BLL\\" + tabName + "BLL.cs"); } } if (config.DesignPattern != "Model-DAL-BLL" && !string.IsNullOrEmpty(config.FactoryPath) && to.Entity) { Pub.Class.FileDirectory.DirectoryCreate(config.FactoryPath + "\\" + config.DesignPatternExtName + "\\"); Pub.Class.FileDirectory.FileDelete(config.FactoryPath + "\\" + config.DesignPatternExtName + "\\" + tabName + "" + config.DesignPatternExtName + ".cs"); if (!string.IsNullOrEmpty(baseCode.Trim())) { FileDirectory.FileWrite(config.FactoryPath + "\\" + config.DesignPatternExtName + "\\" + tabName + "" + config.DesignPatternExtName + ".cs", baseCode); sbSqlCode.AppendLine(sqlCode); } else { Pub.Class.FileDirectory.FileDelete(config.FactoryPath + "\\" + config.DesignPatternExtName + "\\" + tabName + "" + config.DesignPatternExtName + ".cs"); } } WriteLog(tabName + " 生成成功!"); } if (!string.IsNullOrEmpty(config.AdminPath) && config.IsAll) { FileDirectory.FileWrite(config.AdminPath + "\\xml\\db.aspx", "</div>"); } if (!string.IsNullOrEmpty(config.DALPath)) { string extFile = Server2.GetMapPath("") + "\\ext\\Sql\\SqlCode.sql"; string extCode = FileDirectory.FileReadAll(extFile, Encoding.UTF8).ToString(); Pub.Class.FileDirectory.DirectoryCreate(Server2.GetMapPath("") + "\\SQLCode\\"); string code = sbSqlCode.ToString() + "\r\n" + extCode; if (code.Trim().Length > 10) { FileDirectory.FileWrite(Server2.GetMapPath("") + "\\SQLCode\\SQLCode" + Rand.RndDateStr() + ".sql", sbSqlCode.ToString() + "\r\n" + extCode); } } WriteLog("共 {0} 张表!", tables.Count); WriteLog("END"); Input(exit); }