Example #1
0
		public static IList<TableOperator> LoadOPList(Config config, Action<TableEntity> process) {
			string xmlFile = "".GetMapPath() + config.Project + ".xml";
			bool xmlExist = FileDirectory.FileExists(xmlFile);
			IList<TableEntity> list = TableFactory.GetTable();
			foreach (TableEntity entity in list) {
				process(entity);
				if (!xmlExist) config.OPList.Add(new TableOperator() { Table = entity.Name });
				else {
					Xml2 xml = new Xml2(xmlFile);
					string[] attrs = xml.GetAttr("root//Table[@Name='" + entity.Name + "']", "Name|Insert|Update|Delete|IsExistByID|SelectByID|SelectPageList|SelectListByFK|SelectListByAll|Entity|UpdateAndInsert").Split('|');
					if (attrs[0].IsNullEmpty()) {
						config.OPList.Add(new TableOperator() { Table = entity.Name });
						var info = config.OPList[config.OPList.Count - 1];
						xml.AddNode("root", "Table", "Name|Entity|Insert|Update|Delete|IsExistByID|SelectByID|SelectPageList|SelectListByFK|SelectListByAll|UpdateAndInsert", "{0}|{9}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{10}".FormatWith(
							info.Table, info.Insert.ToString().ToLower(), info.Update.ToString().ToLower(), info.DeleteByID.ToString().ToLower(),
							info.IsExistByID.ToString().ToLower(), info.SelectByID.ToString().ToLower(), info.SelectPageList.ToString().ToLower(),
							info.SelectListByFK.ToString().ToLower(), info.SelectListByAll.ToString().ToLower(), info.Entity.ToString().ToLower(),
							info.UpdateAndInsert.ToString().ToLower()
						));
						xml.Save();
					} else {
						config.OPList.Add(new TableOperator() {
							Table = entity.Name,
							Insert = attrs[1] == "true" ? true : false,
							Update = attrs[2] == "true" ? true : false,
							DeleteByID = attrs[3] == "true" ? true : false,
							IsExistByID = attrs[4] == "true" ? true : false,
							SelectByID = attrs[5] == "true" ? true : false,
							SelectPageList = attrs[6] == "true" ? true : false,
							SelectListByFK = attrs[7] == "true" ? true : false,
							SelectListByAll = attrs[8] == "true" ? true : false,
							Entity = attrs[9] == "true" ? true : false,
							UpdateAndInsert = attrs[10] == "true" ? true : false,
						});
					}
					xml.Close();
				}
			}
			if (!xmlExist) TableStructureFactory.CreateXML(xmlFile, config.OPList);
			return config.OPList;
		}
Example #2
0
		public static string GetTableStructCode(Config config, string tableName, string projectName, out string factoryCode, out string sqlCode, bool isView) {
			string title = string.Empty;
			list = GetTableStructure(tableName, out title);

			VelocityHelper entity = new VelocityHelper("\\templates\\{0}\\".FormatWith(config.TemplateName));
			entity.Put("Project", projectName);
			entity.Put("ProjectStartDate", config.ProjectStartDate);
			entity.Put("CopyRight", config.CopyRight);
			entity.Put("TableName", tableName);
			entity.Put("TableNameCN", title);
			entity.Put("Now", DateTime.Now.ToString("yyyy-MM-dd"));
			entity.Put("Fields", list);
			entity.Put("helper", new helper());
			string code = entity.Display("entity.tmp");

			factoryCode = string.Empty; sqlCode = string.Empty;
			var pkInfo = list.Where(p => p.IsPK && p.IsIdentity).FirstOrDefault();
			var currTableOP = config.OPList.Where(p => p.Table == tableName).FirstOrDefault();
			if (!currTableOP.Insert && !currTableOP.Update && !currTableOP.DeleteByID && !currTableOP.SelectByID && !currTableOP.IsExistByID && !currTableOP.SelectListByAll && !currTableOP.SelectListByFK && !currTableOP.SelectPageList && !currTableOP.UpdateAndInsert) return code;
			VelocityHelper factory = new VelocityHelper("\\templates\\{0}\\".FormatWith(config.TemplateName));
			factory.Put("Project", projectName);
			factory.Put("ProjectStartDate", config.ProjectStartDate);
			factory.Put("CacheTime", config.CacheTime);
			factory.Put("DesignPatternExtName", config.DesignPatternExtName);
			factory.Put("CopyRight", config.CopyRight);
			factory.Put("TableName", tableName);
			factory.Put("TableNameCN", title);
			factory.Put("Now", DateTime.Now.ToString("yyyy-MM-dd"));
			factory.Put("Fields", list);
			factory.Put("NoPKFields", list.Where(p => !p.IsPK).ToList());
			factory.Put("PKFields", list.Where(p => p.IsPK).ToList());
			factory.Put("FKFields", list.Where(p => p.IsFK).ToList());
			factory.Put("helper", new helper());
			factory.Put("currTableOP", currTableOP);
			factory.Put("PKInfo", pkInfo);
			factory.Put("isView", isView);
			factoryCode = factory.Display("helper.tmp");
			//MessageBox.Show(list.Where(p => p.IsPK && p.IsIdentity).Count().ToString());

			string dbfile = "".GetMapPath() + "\\templates\\{0}\\db.tmp".FormatWith(config.TemplateName);
			if (FileDirectory.FileExists(dbfile)) {
				VelocityHelper db = new VelocityHelper("\\templates\\{0}\\".FormatWith(config.TemplateName));
				db.Put("Project", projectName);
				db.Put("ProjectStartDate", config.ProjectStartDate);
				db.Put("CacheTime", config.CacheTime);
				db.Put("DesignPatternExtName", config.DesignPatternExtName);
				db.Put("CopyRight", config.CopyRight);
				db.Put("TableName", tableName);
				db.Put("TableNameCN", title);
				db.Put("Now", DateTime.Now.ToString("yyyy-MM-dd"));
				db.Put("Fields", list);
				db.Put("NoPKFields", list.Where(p => !p.IsPK).ToList());
				db.Put("PKFields", list.Where(p => p.IsPK).ToList());
				db.Put("FKFields", list.Where(p => p.IsFK).ToList());
				db.Put("helper", new helper());
				db.Put("currTableOP", currTableOP);
				db.Put("PKInfo", pkInfo);
				db.Put("isView", isView);
				sqlCode = factory.Display("db.tmp");
			}

			if (!string.IsNullOrEmpty(config.AdminPath)) {
				//AdminCode(tableName, tableName.LowerFirstChar2(), projectName, pkInfo.IsNull() || pkInfo.ColumnName.IsNullEmpty() ? false : true, isView, pkInfo.IsNull() || pkInfo.ColumnName.IsNullEmpty() ? string.Empty : pkInfo.ColumnType);

				StringBuilder dbCode = new StringBuilder();
				bool isOnePage = false; int addTotalCount = 0; int pks = 0; int idspks = 0; bool max200 = false; int max200Count = 0;
				string csCode = string.Empty; string aspxCode = string.Empty, entityName = tableName.LowerFirstChar2();
				string folder = (tableName.IndexOf("_") >= 0 ? tableName.Substring(0, tableName.IndexOf("_")) : tableName).ToLower();
				string aspxPath = config.AdminPath + "\\admin\\" + folder + "\\";

				foreach (TableStructureEntity entity2 in list) {
					if (entity2.IsPK) { pks++; };
					if (!max200 && (entity2.Length > 200 || entity2.DBType == "ntext" || entity2.DBType == "text" || entity2.Length <= 0)) max200 = true;
					if (entity2.IsPK && entity2.IsIdentity) { idspks++; };
					if (!entity2.IsIdentity && entity2.IsPK) addTotalCount++;
					if (!entity2.IsIdentity && !entity2.IsPK) addTotalCount++;
					if (entity2.Length > 200 || entity2.DBType == "ntext" || entity2.DBType == "text" || entity2.Length <= 0) max200Count++;
				}
				if (addTotalCount < 6 && !max200) isOnePage = true;
				if (pks > 1) isOnePage = true;
				int height = addTotalCount < 10 ? addTotalCount * 31 + 65 + (110 * max200Count) : ((addTotalCount / 2) + (addTotalCount % 2)) * 31 + 65;

				VelocityHelper manage = new VelocityHelper("\\templates\\{0}\\".FormatWith(config.TemplateName));
				manage.Put("Project", projectName);
				manage.Put("ProjectStartDate", config.ProjectStartDate);
				manage.Put("CopyRight", config.CopyRight);
				manage.Put("TableName", tableName);
				manage.Put("TableNameCN", title);
				manage.Put("Fields", list);
				manage.Put("NoPKFields", list.Where(p => !p.IsPK).ToList());
				manage.Put("PKFields", list.Where(p => p.IsPK).ToList());
				manage.Put("FKFields", list.Where(p => p.IsFK).ToList());
				manage.Put("helper", new helper());
				manage.Put("PKInfo", pkInfo);
				manage.Put("isOnePage", isOnePage);
				manage.Put("PagerSqlEnum", config.PagerSqlEnum);
				manage.Put("PageSize", config.PageSize);
				manage.Put("WinHeight", height);
				aspxCode = manage.Display("manage.tmp");

				VelocityHelper managecs = new VelocityHelper("\\templates\\{0}\\".FormatWith(config.TemplateName));
				managecs.Put("Project", projectName);
				managecs.Put("ProjectStartDate", config.ProjectStartDate);
				managecs.Put("CopyRight", config.CopyRight);
				managecs.Put("TableName", tableName);
				managecs.Put("TableNameCN", title);
				managecs.Put("Fields", list);
				managecs.Put("NoPKFields", list.Where(p => !p.IsPK).ToList());
				managecs.Put("PKFields", list.Where(p => p.IsPK).ToList());
				managecs.Put("FKFields", list.Where(p => p.IsFK).ToList());
				managecs.Put("helper", new helper());
				managecs.Put("PKInfo", pkInfo);
				managecs.Put("isOnePage", isOnePage);
				managecs.Put("PagerSqlEnum", config.PagerSqlEnum);
				managecs.Put("PageSizes", config.PageSize);
				csCode = managecs.Display("manage.cs.tmp");

				FileDirectory.DirectoryCreate(aspxPath);
				FileDirectory.FileDelete(aspxPath + entityName + "Manage.aspx");
				FileDirectory.FileWrite(aspxPath + entityName + "Manage.aspx", aspxCode.ToString());
				FileDirectory.FileDelete(aspxPath + entityName + "Manage.aspx.cs");
				FileDirectory.FileWrite(aspxPath + entityName + "Manage.aspx.cs", csCode.ToString());
				if (!string.IsNullOrEmpty(config.AdminPath) && config.IsAll) {
					dbCode.AppendFormat(string.Format("    <table cellspacing='0' cellpadding='0' style='width: 100%;'><tbody><tr class='MenuItemRow'><td style='width: 7px;' /><td align='RIGHT' style='width: 10px; vertical-align: top;'><div class='IconContainer' style='width: 10px;'></div></td><td style='padding: 0px 9px 0px 5px;'><font class='MenuItemLabel'><a href='#' onclick=\"parent.window.frames[1].location.href='{0}'\" style='text-decoration:none; color:#428eff'>{1}</a></font></td></tr></tbody></table>", "../" + folder + "/" + entityName + "Manage.aspx", (string.IsNullOrEmpty(title) ? tableName : title) + "管理"));
					FileDirectory.FileWrite(config.AdminPath + "\\xml\\db.aspx", dbCode.ToString());
				}
				if (!isOnePage) {
					VelocityHelper add = new VelocityHelper("\\templates\\{0}\\".FormatWith(config.TemplateName));
					add.Put("Project", projectName);
					add.Put("ProjectStartDate", config.ProjectStartDate);
					add.Put("CopyRight", config.CopyRight);
					add.Put("TableName", tableName);
					add.Put("TableNameCN", title);
					add.Put("Fields", list);
					add.Put("NoPKFields", list.Where(p => !p.IsPK).ToList());
					add.Put("PKFields", list.Where(p => p.IsPK).ToList());
					add.Put("FKFields", list.Where(p => p.IsFK).ToList());
					add.Put("helper", new helper());
					add.Put("currTableOP", currTableOP);
					add.Put("PKInfo", pkInfo);
					aspxCode = add.Display("add.tmp");

					VelocityHelper addcs = new VelocityHelper("\\templates\\{0}\\".FormatWith(config.TemplateName));
					addcs.Put("Project", projectName);
					addcs.Put("ProjectStartDate", config.ProjectStartDate);
					addcs.Put("CopyRight", config.CopyRight);
					addcs.Put("TableName", tableName);
					addcs.Put("TableNameCN", title);
					addcs.Put("Fields", list);
					addcs.Put("NoPKFields", list.Where(p => !p.IsPK).ToList());
					addcs.Put("PKFields", list.Where(p => p.IsPK).ToList());
					addcs.Put("FKFields", list.Where(p => p.IsFK).ToList());
					addcs.Put("helper", new helper());
					addcs.Put("currTableOP", currTableOP);
					addcs.Put("PKInfo", pkInfo);
					csCode = addcs.Display("add.cs.tmp");

					FileDirectory.FileDelete(aspxPath + entityName + "Add.aspx");
					FileDirectory.FileWrite(aspxPath + entityName + "Add.aspx", aspxCode.ToString());
					FileDirectory.FileDelete(aspxPath + entityName + "Add.aspx.cs");
					FileDirectory.FileWrite(aspxPath + entityName + "Add.aspx.cs", csCode.ToString());
				}
			}

			return code;
			//return sb.ToString();
		}
Example #3
0
		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);
		}