public async Task <IActionResult> CodeGenerateJson(BaseConfigModel baseConfig, string Code)
        {
            TData <List <KeyValue> > obj = new TData <List <KeyValue> >();

            if (!GlobalContext.SystemConfig.Debug)
            {
                obj.Message = "请在本地开发模式时使用代码生成";
            }
            else
            {
                SingleTableTemplate template = new SingleTableTemplate();
                List <KeyValue>     result   = await template.CreateCode(baseConfig, HttpUtility.UrlDecode(Code));

                obj.Result = result;
                obj.Tag    = 1;
            }
            return(Json(obj));
        }
        public async Task <ActionResult> GetBaseConfigJson(string keyValue)
        {
            BaseConfigModel data = new BaseConfigModel();

            string tableDescription = string.Empty;
            List <TableFieldInfo> tDataTableField = await _service.GetTableFieldList(keyValue);

            var columnList = tDataTableField.Where(p => !BaseField.BaseFieldList.Contains(p.TableColumn) && p.TableIdentity != "Y").Select(p => new { p.TableColumn, p.Remark }).ToList();
            Dictionary <string, string> dic = new Dictionary <string, string>();

            foreach (var item in columnList)
            {
                dic.Add(item.TableColumn, string.IsNullOrEmpty(item.Remark) ? item.TableColumn : item.Remark);
            }
            string serverPath = GlobalContext.HostingEnvironment.ContentRootPath;

            data = new SingleTableTemplate(_context).GetBaseConfig(serverPath, _logService.currentuser.UserName, keyValue, tableDescription, dic);
            return(Content(data.ToJson()));
        }
        public async Task <IActionResult> CodePreviewJson(BaseConfigModel baseConfig)
        {
            TData <object> obj = new TData <object>();

            if (string.IsNullOrEmpty(baseConfig.OutputConfig.OutputModule))
            {
                obj.Message = "请选择输出到的模块";
            }
            else
            {
                SingleTableTemplate            template = new SingleTableTemplate();
                TData <List <TableFieldInfo> > objTable = await databaseTableBLL.GetTableFieldList(baseConfig.TableName);

                DataTable dt                 = DataTableHelper.ListToDataTable(objTable.Data); // 用DataTable类型,避免依赖
                string    codeEntity         = template.BuildEntity(baseConfig, dt);
                string    codePartialEntity  = template.BuildPartialEntity(baseConfig, dt);
                string    codeEntityParam    = template.BuildEntityParam(baseConfig);
                string    codeService        = template.BuildService(baseConfig, dt);
                string    codePartialService = template.BuildPartialService(baseConfig, dt);
                string    codeBusiness       = template.BuildBusiness(baseConfig);
                string    codeController     = template.BuildController(baseConfig);
                string    codeIndex          = template.BuildIndex(baseConfig);
                string    codeForm           = template.BuildForm(baseConfig);
                string    codeMenu           = template.BuildMenu(baseConfig);

                var json = new
                {
                    CodeEntity         = HttpUtility.HtmlEncode(codeEntity),
                    CodePartialEntity  = HttpUtility.HtmlEncode(codePartialEntity),
                    CodeEntityParam    = HttpUtility.HtmlEncode(codeEntityParam),
                    CodeService        = HttpUtility.HtmlEncode(codeService),
                    CodePartialService = HttpUtility.HtmlEncode(codePartialService),
                    CodeBusiness       = HttpUtility.HtmlEncode(codeBusiness),
                    CodeController     = HttpUtility.HtmlEncode(codeController),
                    CodeIndex          = HttpUtility.HtmlEncode(codeIndex),
                    CodeForm           = HttpUtility.HtmlEncode(codeForm),
                    CodeMenu           = HttpUtility.HtmlEncode(codeMenu)
                };
                obj.Data = json;
                obj.Tag  = 1;
            }
            return(Json(obj));
        }
Beispiel #4
0
 public async Task <ActionResult> CodeGenerateJson(BaseConfigModel baseConfig, string Code)
 {
     try
     {
         if (!GlobalContext.SystemConfig.Debug)
         {
             throw new System.Exception("请在本地开发模式时使用代码生成");
         }
         else
         {
             SingleTableTemplate template = new SingleTableTemplate(_context);
             await template.CreateCode(baseConfig, HttpUtility.UrlDecode(Code));
         }
         return(await Success("操作成功。", "", ""));
     }
     catch (System.Exception ex)
     {
         return(await Error(ex.Message, "", ""));
     }
 }
 public CodeGeneratorController(IDatabaseTableBLL databaseTableBLL, SingleTableTemplate singleTableTemplate)
 {
     _databaseTableBLL    = databaseTableBLL;
     _singleTableTemplate = singleTableTemplate;
 }
Beispiel #6
0
        public async Task <ActionResult> CodePreviewJson(BaseConfigModel baseConfig)
        {
            try
            {
                List <TableFieldInfo> list = await _service.GetTableFieldList(baseConfig.TableName);

                SingleTableTemplate template = new SingleTableTemplate(_context);
                DataTable           dt       = DataTableHelper.ListToDataTable(list); // 用DataTable类型,避免依赖
                string idcolumn = string.Empty;
                Dictionary <string, string> dic = new Dictionary <string, string>();
                baseConfig.PageIndex.ButtonList = ExtList.removeNull(baseConfig.PageIndex.ButtonList);
                baseConfig.PageIndex.ColumnList = baseConfig.PageIndex.ColumnList.Where(a => a.field != "").ToList();
                baseConfig.PageForm.FieldList.Remove("");
                string idType = "string";
                //扩展删除字段和创建时间字段
                string[] isDeleteMarkFieldNames = new[] { "F_DeleteMark", "IsDelete" };
                string[] createTimeFieldNames   = new[] { "F_CreatorTime", "AddTime" };

                string isDeleteMarkField = "F_DeleteMark";
                string createTimeField   = "F_CreatorTime";
                foreach (DataRow dr in dt.Rows)
                {
                    if (dr["TableIdentity"].ToString() == "Y")
                    {
                        idcolumn = dr["TableColumn"].ToString();
                        string datatype = dr["Datatype"].ToString();
                        datatype = TableMappingHelper.GetPropertyDatatype(datatype);
                        if (datatype == "int?")
                        {
                            idType = "int";
                        }
                        else if (datatype == "long?")
                        {
                            idType = "long";
                        }
                        else
                        {
                            idType = "string";
                        }
                    }
                    string columnName = dr["TableColumn"].ToString();
                    foreach (var isDeleteMarkFieldName in isDeleteMarkFieldNames)
                    {
                        if (string.Compare(isDeleteMarkFieldName, columnName, true) == 0)
                        {
                            isDeleteMarkField = columnName;
                        }
                    }
                    foreach (var createTimeFieldName in createTimeFieldNames)
                    {
                        if (string.Compare(createTimeFieldName, columnName, true) == 0)
                        {
                            createTimeField = columnName;
                        }
                    }
                }


                string codeEntity     = template.BuildEntity(baseConfig, dt, idcolumn);
                string codeService    = template.BuildService(baseConfig, dt, idcolumn, idType, isDeleteMarkField, createTimeField);
                string codeController = template.BuildController(baseConfig, idcolumn, idType);
                string codeIndex      = template.BuildIndex(baseConfig, idcolumn);
                string codeForm       = template.BuildForm(baseConfig);
                string codeDetails    = template.BuildDetails(baseConfig);
                string codeMenu       = template.BuildMenu(baseConfig, idcolumn);
                var    json           = new
                {
                    CodeEntity     = HttpUtility.HtmlEncode(codeEntity),
                    CodeService    = HttpUtility.HtmlEncode(codeService),
                    CodeController = HttpUtility.HtmlEncode(codeController),
                    CodeIndex      = HttpUtility.HtmlEncode(codeIndex),
                    CodeForm       = HttpUtility.HtmlEncode(codeForm),
                    CodeDetails    = HttpUtility.HtmlEncode(codeDetails),
                    CodeMenu       = HttpUtility.HtmlEncode(codeMenu)
                };
                return(Success("操作成功", json));
            }
            catch (System.Exception ex)
            {
                return(Error(ex.Message));
            }
        }