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 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); }