public async Task <TData <object> > CodePreviewJson([FromForm] BaseConfigModel baseConfig)
        {
            var obj = new TData <object>();

            if (string.IsNullOrEmpty(baseConfig.OutputConfig.OutputModule))
            {
                obj.Message = "请选择输出到的模块";
                return(obj);
            }

            var objTable = await _databaseTableBLL.GetTableFieldList(baseConfig.TableName);

            var dt = DataTableHelper.ListToDataTable(objTable.Data); // 用DataTable类型,避免依赖

            var codeEntity      = _singleTableTemplate.BuildEntity(baseConfig, dt);
            var codeEntityParam = _singleTableTemplate.BuildEntityParam(baseConfig, dt);
            var codeService     = _singleTableTemplate.BuildService(baseConfig, dt);
            var codeBusiness    = _singleTableTemplate.BuildBusiness(baseConfig);
            var codeIService    = _singleTableTemplate.BuildIService(baseConfig, dt);
            var codeIBusiness   = _singleTableTemplate.BuildIBusiness(baseConfig);

            var codeController = _singleTableTemplate.BuildController(baseConfig);
            var codeIndex      = _singleTableTemplate.BuildIndex(baseConfig, dt);
            var codeForm       = _singleTableTemplate.BuildForm(baseConfig, dt);

            var json = new
            {
                CodeEntity      = HttpUtility.HtmlEncode(codeEntity),
                CodeEntityParam = HttpUtility.HtmlEncode(codeEntityParam),
                CodeService     = HttpUtility.HtmlEncode(codeService),
                CodeBusiness    = HttpUtility.HtmlEncode(codeBusiness),
                CodeIService    = HttpUtility.HtmlEncode(codeIService),
                CodeIBusiness   = HttpUtility.HtmlEncode(codeIBusiness),
                CodeController  = HttpUtility.HtmlEncode(codeController),
                CodeIndex       = HttpUtility.HtmlEncode(codeIndex),
                CodeForm        = HttpUtility.HtmlEncode(codeForm)
            };

            obj.Data = json;
            obj.Tag  = 1;

            return(obj);
        }
        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));
        }
예제 #3
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));
            }
        }