Exemplo n.º 1
0
        private void BuildView(string viewPath, XDocument doc)
        {
            ConvertCshtml _cs        = new ConvertCshtml(_db);
            int           addressId  = _data.Id;
            int           languageId = _languageId;
            var           review     = _cs.ReviewModel(addressId, languageId);

            review.JsSrc   = @"/Areas/{0}/Views/_js/{1}-{2}.js".ToFormat(_data.AreaName, _data.ControllerName.ToLower(), _data.ActionName.ToLower());
            review.CssHref = @"/Areas/{0}/Views/_css/{1}-{2}.css".ToFormat(_data.AreaName, _data.ControllerName.ToLower(), _data.ActionName.ToLower());
            ContainConfigToCsproj(@"Areas\{0}\Views\_css\{1}-{2}.css".ToFormat(_data.AreaName, _data.ControllerName.ToLower(), _data.ActionName.ToLower()), _solutionDir, _projectName, doc);
            ContainConfigToCsproj(@"Areas\{0}\Views\_js\{1}-{2}.js".ToFormat(_data.AreaName, _data.ControllerName.ToLower(), _data.ActionName.ToLower()), _solutionDir, _projectName, doc);
            string jsPath  = FileSugar.GetMapPath(review.JsSrc);
            string cssPath = FileSugar.GetMapPath(review.CssHref);

            if (FileSugar.IsExistFile(jsPath).IsFalse())
            {
                FileSugar.CreateFile(jsPath);
                FileSugar.WriteFile(jsPath, "///<reference path=\"/_theme/tool/_reference.js\" />", "utf-8");
            }
            if (FileSugar.IsExistFile(cssPath).IsFalse())
            {
                FileSugar.CreateFile(cssPath);
            }
            var viewCode       = GetTemplateCodeByName("view.cshtml", review);
            var languageSuffix = string.Empty;

            if (languageId != 1)
            {
                languageSuffix = $"_{GetLanguageList.Single(it => it.Id == languageId).Suffix}";
            }
            FileSugar.WriteFile(viewPath, viewCode);
            ContainConfigToCsproj(@"Areas\{0}\Views\{1}\{2}{3}.cshtml".ToFormat(_data.AreaName, _data.ControllerName, _data.ActionName, languageSuffix), _solutionDir, _projectName, doc);
        }
Exemplo n.º 2
0
        /// <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;
        }
Exemplo n.º 3
0
        public ApiResult <bool> Exportfile([FromForm] string model, [FromForm] int dbid)
        {
            ApiResult <bool> result = new ApiResult <bool>()
            {
                IsSuccess = true
            };
            var tableDb = base.GetTryDb(dbid);
            var dts     = Export(model, tableDb);
            var bytes   = Table_ToExcel.ExportExcel(dts, "数据库文档.xlsx");
            var url     = FileSugar.MergeUrl(Startup.GetCurrentDirectory(), "excel/数据库文档" + SqlSugar.SnowFlakeSingle.Instance.getID() + ".xlsx");

            FileSugar.CreateFile(url, bytes);
            OpenPath(url);
            return(result);
        }
Exemplo n.º 4
0
 /// <summary>
 /// 写入日志文件
 /// </summary>
 /// <param name="ex"></param>
 public static void WirteExp(Exception ex)
 {
     try
     {
         var logPath = FileSugar.MergeUrl(
             FileSugar.GetMapPath("~/"),
             "log",
             DateTime.Now.ToString("yyyy-MM-dd") + ".txt"
             );
         if (FileSugar.IsExistFile(logPath).IsFalse())
         {
             FileSugar.CreateFile(logPath);
         }
         FileSugar.AppendText(logPath, "***********{0}{1}***********".ToFormat("开始:", DateTime.Now));
         FileSugar.AppendText(logPath, ex.Message);
         FileSugar.AppendText(logPath, "***********{0}***********\r\n".ToFormat("结束"));
     }
     catch
     {
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// 创建实体文件
        /// </summary>
        /// <param name="db"></param>
        /// <param name="fileDirectory"></param>
        /// <param name="nameSpace">命名空间(默认:system)</param>
        /// <param name="tableOrView">是生成视图文件还是表文件,null生成表和视图,true生成表,false生成视图(默认为:null)</param>
        /// <param name="callBack">生成文件后的处理,参数string为实体名</param>
        /// <param name="preAction">生成文件前的处理,参数string为表名</param>
        public void CreateClassFiles(SqlSugarClient db, string fileDirectory, string nameSpace = null, bool?tableOrView = null, Action <string> callBack = null, Action <string> preAction = null)
        {
            var isLog = db.IsEnableLogEvent;

            db.IsEnableLogEvent = false;
            string sql    = SqlSugarTool.GetCreateClassSql(tableOrView);
            var    tables = db.GetDataTable(sql);

            if (tables != null && tables.Rows.Count > 0)
            {
                foreach (DataRow dr in tables.Rows)
                {
                    string tableName = dr["name"].ToString();
                    if (preAction != null)
                    {
                        preAction(tableName);
                    }
                    var currentTable = db.GetDataTable(string.Format(SqlSugarTool.GetSelectTopSql(), GetTableNameWithSchema(db, tableName).GetTranslationSqlName()));
                    if (callBack != null)
                    {
                        var    tableColumns = GetTableColumns(db, tableName);
                        var    classCode    = DataTableToClass(currentTable, tableName, nameSpace, tableColumns);
                        string className    = db.GetClassTypeByTableName(tableName);
                        classCode = classCode.Replace("class " + tableName, "class " + className);
                        FileSugar.CreateFile(fileDirectory.TrimEnd('\\') + "\\" + className + ".cs", classCode, Encoding.UTF8);
                        callBack(className);
                    }
                    else
                    {
                        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;
        }