/// <summary> /// 创建SQL实体文件,指定表名 /// </summary> public void CreateClassFilesByTableNames(SqlSugarClient db, string fileDirectory, string nameSpace, params string[] tableNames) { var isLog = db.IsEnableLogEvent; db.IsEnableLogEvent = false; string sql = SqlSugarTool.GetCreateClassSql(null); var tables = db.GetDataTable(sql); if (!FileSugar.IsExistDirectory(fileDirectory)) { FileSugar.CreateDirectory(fileDirectory); } if (tables != null && tables.Rows.Count > 0) { foreach (DataRow dr in tables.Rows) { string tableName = dr["name"].ToString().ToLower(); if (tableNames.Any(it => it.ToLower() == tableName)) { var currentTable = db.GetDataTable(string.Format(SqlSugarTool.GetSelectTopSql(), GetTableNameWithSchema(db, tableName).GetTranslationSqlName())); var tableColumns = GetTableColumns(db, tableName); string className = db.GetClassTypeByTableName(tableName); var classCode = DataTableToClass(currentTable, className, nameSpace, tableColumns); FileSugar.CreateFile(fileDirectory.TrimEnd('\\') + "\\" + className + ".cs", classCode, Encoding.UTF8); } } } db.IsEnableLogEvent = isLog; }
/// <summary> /// 生成area /// </summary> private void BuildArea(string areaDir, string viewsDir, string controllerDomainDir, string areaRegistrationPath, string configPath, XDocument doc) { //创建area if (!FileSugar.IsExistDirectory(areaDir)) { //创建目录 FileSugar.CreateDirectory(areaDir); //创建area FileSugar.CreateDirectory(viewsDir); //创建views FileSugar.CreateDirectory(controllerDomainDir); //创建文件 //创建文件 var areaRegistrationCode = GetTemplateCodeByName("area_gobal.cshtml", new { projectName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name, area = _data.AreaName }); FileSugar.WriteFile(areaRegistrationPath, areaRegistrationCode); ContainFileToCsproj(@"Areas\{0}\{0}AreaRegistration.cs".ToFormat(_data.AreaName), _solutionDir, _projectName, doc); ContainConfigToCsproj(@"Areas\{0}\Views\Web.config".ToFormat(_data.AreaName), _solutionDir, _projectName, doc); } var webConfigCode = GetTemplateCodeByName("area_webConfig.cshtml", new { }); FileSugar.WriteFile(configPath, webConfigCode); }