public ActionResult PublishModule(string baseInfoJson, ModuleEntity moduleEntity, string moduleButtonListJson, string moduleColumnListJson) { BaseConfigModel baseConfigModel = baseInfoJson.ToObject <BaseConfigModel>(); var urlAddress = "/" + baseConfigModel.OutputAreas + "/" + CommonHelper.DelLastLength(baseConfigModel.ControllerName, 10) + "/" + baseConfigModel.IndexPageName; moduleEntity.SortCode = moduleBLL.GetSortCode(); moduleEntity.IsMenu = 1; moduleEntity.EnabledMark = 1; moduleEntity.Target = "iframe"; moduleEntity.UrlAddress = urlAddress; moduleBLL.SaveForm("", moduleEntity, moduleButtonListJson, moduleColumnListJson); return(Success("发布成功!")); }
/// <summary> /// 读取代码模板 /// </summary> private StringBuilder ReadTemplet(string flag, BaseConfigModel bc) { var item = _codeRepository.AsQueryable().Where(a => a.Flag == flag).FirstOrDefault(); if (item == null) { throw new Exception("找不到相应的模板:" + flag); } var sb = new StringBuilder(item.Code); sb = ReplaceCode(sb, bc); return(sb); }
/// <summary> /// 替换通用字符串 /// </summary> private StringBuilder ReplaceCode(StringBuilder sb, BaseConfigModel baseConfigModel) { // 项目名称 sb = sb.Replace("{项目名称}", projectName); // 命名空间 sb = sb.Replace("{命名空间}", baseConfigModel.OutputConfig.OutputModule); // 类名前缀 sb = sb.Replace("{类名前缀}", baseConfigModel.FileConfig.ClassPrefix); sb = sb.Replace("{驼峰类名前缀}", TextHelper.StrFirstCharToLower(baseConfigModel.FileConfig.ClassPrefix)); return(sb); }
public Startup(IConfiguration configuration, IWebHostEnvironment env) { Configuration = configuration; var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) // .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", optional: true) //.AddJsonFile("appsettings" + "." + env.EnvironmentName + ".json", optional: true, reloadOnChange: true); ; this.Configuration = builder.Build(); BaseConfigModel.SetBaseConfig(Configuration, env.ContentRootPath, env.WebRootPath); }
/// <summary> /// 生成服务文件 /// </summary> /// <param name="baseConfigModel">基本信息</param> /// <param name="strCode">生成代码内容</param> public static void CreateServiceExecution(BaseConfigModel baseConfigModel, string strCode) { var strParam = strCode.ToJObject(); #region 实体类 string entityCode = strParam["entityCode"].ToString(); string entityPath = baseConfigModel.OutputEntity + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.EntityClassName + ".cs"; //if (!System.IO.File.Exists(entityPath)) //{ DirFileHelper.CreateFileContent(entityPath, entityCode); //} #endregion #region 射类 string entitymapCode = strParam["entitymapCode"].ToString(); string entitymapPath = baseConfigModel.OutputMap + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.MapClassName + ".cs"; //if (!System.IO.File.Exists(entitymapPath)) //{ DirFileHelper.CreateFileContent(entitymapPath, entitymapCode); //} #endregion #region 务类 string serviceCode = strParam["serviceCode"].ToString(); string servicePath = baseConfigModel.OutputService + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.ServiceClassName + ".cs"; //if (!System.IO.File.Exists(servicePath)) //{ DirFileHelper.CreateFileContent(servicePath, serviceCode); //} #endregion #region 接口类 string iserviceCode = strParam["iserviceCode"].ToString(); string iservicePath = baseConfigModel.OutputIService + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.IServiceClassName + ".cs"; //if (!System.IO.File.Exists(iservicePath)) //{ DirFileHelper.CreateFileContent(iservicePath, iserviceCode); //} #endregion #region 业务类 string businesCode = strParam["businesCode"].ToString(); string businesPath = baseConfigModel.OutputBusines + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.BusinesClassName + ".cs"; //if (!System.IO.File.Exists(businesPath)) //{ DirFileHelper.CreateFileContent(businesPath, businesCode); //} #endregion }
/// <summary></summary> /// <param name="configuration"></param> public Startup(IConfiguration configuration) { #region 读取配置文件 var location = System.Reflection.Assembly.GetExecutingAssembly().Location; var applicationExeDirectory = Path.GetDirectoryName(location); var builder = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); IConfigurationRoot _Configuration = builder.Build(); BaseConfigModel.SetBaseConfig(_Configuration); Configuration = configuration; #endregion 读取配置文件 }
public ActionResult CreateCode(BaseConfigModel baseConfigModel) { baseConfigModel.DataBaseLinkName = ""; DataBaseLinkEntity dataBaseLinkEntity = new DataBaseLinkBLL().GetEntity(baseConfigModel.DataBaseLinkId); string connectionString = ConfigurationManager.ConnectionStrings["BaseDb"].ConnectionString; if (connectionString != dataBaseLinkEntity.F_DbConnection) { baseConfigModel.DataBaseLinkName = dataBaseLinkEntity.F_DBName; baseConfigModel.DataBaseLinkType = dataBaseLinkEntity.F_DbType; } string[] tableNameLists = baseConfigModel.DataBaseTableName.Split(','); string[] tablePkLists = baseConfigModel.DataBaseTablePK.Split(','); string[] tableDescriptionLists = baseConfigModel.Description.Split(','); ServiceCode default_Template = new ServiceCode(); for (int i = 0; i < tableNameLists.Length; i++) { baseConfigModel.DataBaseTableName = tableNameLists[i]; baseConfigModel.DataBaseTablePK = tablePkLists[i]; baseConfigModel.Description = tableDescriptionLists[i]; baseConfigModel.EntityClassName = tableNameLists[i] + "Entity"; baseConfigModel.MapClassName = tableNameLists[i] + "Map"; baseConfigModel.ServiceClassName = tableNameLists[i] + "Service"; baseConfigModel.IServiceClassName = tableNameLists[i] + "IService"; baseConfigModel.BusinesClassName = tableNameLists[i] + "BLL"; var tableFiled = new DataBaseTableBLL(baseConfigModel.DataBaseLinkId).GetTableFiledList(baseConfigModel.DataBaseLinkId, baseConfigModel.DataBaseTableName); string entitybuilder = default_Template.EntityBuilder(baseConfigModel, DataHelper.ListToDataTable <DataBaseTableFieldEntity>(tableFiled.ToList())); string entitymapbuilder = default_Template.EntityMapBuilder(baseConfigModel); string servicebuilder = default_Template.ServiceBuilder(baseConfigModel); string iservicebuilder = default_Template.IServiceBuilder(baseConfigModel); string businesbuilder = default_Template.BusinesBuilder(baseConfigModel); var jsonData = new { entityCode = entitybuilder, entitymapCode = entitymapbuilder, serviceCode = servicebuilder, iserviceCode = iservicebuilder, businesCode = businesbuilder, }; CreateCodeFile.CreateExecution(baseConfigModel, jsonData.ToJson()); } return(Success("恭喜您,创建成功!")); }
public Startup(IHostingEnvironment env) { this._env = env; //Microsoft.Extensions.PlatformAbstractions.ApplicationEnvironment appEnvironment = PlatformServices.Default.Application; //string ContentRootPath = appEnvironment.ApplicationBasePath; //env.ContentRootPath = ContentRootPath; //env.WebRootPath = ContentRootPath; var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); this.Configuration = builder.Build(); var test = Configuration.ToString(); BaseConfigModel.SetBaseConfig(Configuration, env.ContentRootPath, env.WebRootPath); }
public 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 = template.CreateCode(baseConfig, HttpUtility.UrlDecode(Code)); obj.Result = result; obj.Tag = 1; } return(Json(obj)); }
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)); }
public ActionResult LookCode(BaseConfigModel baseConfigModel) { ServiceCode default_Template = new ServiceCode(); var tableFiled = new DataBaseTableBLL(baseConfigModel.DataBaseLinkId).GetTableFiledList(baseConfigModel.DataBaseLinkId, baseConfigModel.DataBaseTableName); baseConfigModel.DataBaseLinkName = ""; DataBaseLinkEntity dataBaseLinkEntity = new DataBaseLinkBLL().GetEntity(baseConfigModel.DataBaseLinkId); string connectionString = ConfigurationManager.ConnectionStrings["BaseDb"].ConnectionString; if (connectionString != dataBaseLinkEntity.F_DbConnection) { baseConfigModel.DataBaseLinkName = dataBaseLinkEntity.F_DBName; baseConfigModel.DataBaseLinkType = dataBaseLinkEntity.F_DbType; if (ConfigurationManager.ConnectionStrings[dataBaseLinkEntity.F_DBName] == null) { string providerName = "System.Data.SqlClient"; if (dataBaseLinkEntity.F_DbType == "MySql") { providerName = "MySql.Data.MySqlClient"; } else if (dataBaseLinkEntity.F_DbType == "Oracle") { providerName = "Oracle.ManagedDataAccess.Client"; } Config.UpdateOrCreateConnectionString("XmlConfig\\database.config", dataBaseLinkEntity.F_DBName, dataBaseLinkEntity.F_DbConnection, providerName); } } string entitybuilder = default_Template.EntityBuilder(baseConfigModel, DataHelper.ListToDataTable <DataBaseTableFieldEntity>(tableFiled.ToList())); string entitymapbuilder = default_Template.EntityMapBuilder(baseConfigModel); string servicebuilder = default_Template.ServiceBuilder(baseConfigModel); string iservicebuilder = default_Template.IServiceBuilder(baseConfigModel); string businesbuilder = default_Template.BusinesBuilder(baseConfigModel); var jsonData = new { entityCode = entitybuilder, entitymapCode = entitymapbuilder, serviceCode = servicebuilder, iserviceCode = iservicebuilder, businesCode = businesbuilder, }; return(ToJsonResult(jsonData)); }
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 <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 ActionResult LookCode(string baseInfoJson, string gridInfoJson, string gridColumnJson, string formInfoJson, string formFieldJson) { SingleTable default_Template = new SingleTable(); BaseConfigModel baseConfigModel = baseInfoJson.JsonToEntity <BaseConfigModel>(); baseConfigModel.gridModel = gridInfoJson.JsonToEntity <GridModel>(); baseConfigModel.gridColumnModel = gridColumnJson.JsonToList <GridColumnModel>(); baseConfigModel.formModel = formInfoJson.JsonToEntity <FormModel>(); baseConfigModel.formFieldModel = formFieldJson.JsonToList <FormFieldModel>(); var tableFiled = new DataBaseTableBLL().GetTableFiledList(baseConfigModel.Id, baseConfigModel.DataBaseTableName); string entitybuilder = default_Template.EntityBuilder(baseConfigModel, tableFiled.ToList().ListToDataTable <DataBaseTableFieldEntity>()); string entitymapbuilder = default_Template.EntityMapBuilder(baseConfigModel); string servicebuilder = default_Template.ServiceBuilder(baseConfigModel); string iservicebuilder = default_Template.IServiceBuilder(baseConfigModel); string businesbuilder = default_Template.BusinesBuilder(baseConfigModel); string ibusinesbuilder = default_Template.IBusinesBuilder(baseConfigModel); string controllerbuilder = default_Template.ControllerBuilder(baseConfigModel); string indexbuilder = default_Template.IndexBuilder(baseConfigModel); string formbuilder = default_Template.FormBuilder(baseConfigModel); var jsonData = new { entityCode = entitybuilder, entitymapCode = entitymapbuilder, serviceCode = servicebuilder, iserviceCode = iservicebuilder, businesCode = businesbuilder, ibusinesCode = ibusinesbuilder, controllerCode = controllerbuilder, indexCode = indexbuilder, formCode = formbuilder }; return(ToJsonResult(jsonData)); }
public string BuildIBusiness(BaseConfigModel baseConfigModel) { // 读取模板 var sb = ReadTemplet("IBLL", baseConfigModel); #region 描述 var describe = new StringBuilder(); SetClassDescription("业务类", baseConfigModel, describe); sb = sb.Replace("{描述}", describe.ToString()); #endregion #region 类名 sb = sb.Replace("{类名}", baseConfigModel.FileConfig.BusinessName); #endregion #region 数据服务类名 sb = sb.Replace("{数据服务类名}", baseConfigModel.FileConfig.ServiceName); sb = sb.Replace("{驼峰数据服务类名}", TextHelper.StrFirstCharToLower(baseConfigModel.FileConfig.ServiceName)); #endregion #region 实体类名 sb = sb.Replace("{实体类名}", baseConfigModel.FileConfig.EntityName); #endregion #region 查询类名 sb = sb.Replace("{查询类名}", baseConfigModel.FileConfig.EntityParamName.Replace("Param", "ListParam")); #endregion return(sb.ToString()); }
/// <summary> /// 从缓存中获取基本配置信息 /// </summary> /// <returns></returns> public BaseConfigModel GetModelCached() { if (HttpContext.Current != null) { BaseConfigModel model = WebCacheHelper <BaseConfigModel> .Get(CACHEKEY); if (model == null) { model = dal.GetTopModel(); if (model == null) { return(null); } WebCacheHelper.Insert(CACHEKEY, model, new System.Web.Caching.CacheDependency(this.GetDepFile())); } return(model); } else { return(dal.GetTopModel()); } }
public string BuildEntityParam(BaseConfigModel baseConfigModel) { StringBuilder sb = new StringBuilder(); sb.AppendLine("using System;"); sb.AppendLine("using System.Collections.Generic;"); sb.AppendLine("using Newtonsoft.Json;"); sb.AppendLine("using YiSha.Util;"); sb.AppendLine(); sb.AppendLine("namespace YiSha.Model.Param." + baseConfigModel.OutputConfig.OutputModule); sb.AppendLine("{"); SetClassDescription(baseConfigModel, sb); sb.AppendLine(" public class " + baseConfigModel.FileConfig.EntityParamName.Replace("Param", "ListParam")); sb.AppendLine(" {"); sb.AppendLine(" }"); sb.AppendLine("}"); return(sb.ToString()); }
static async Task <int> Main(string[] args) { int maxClientCount = 1; int messageCount = 8; var connectionConfig = BaseConfigModel.GetDefaults(); var identityProvider = UserProvider.GetDefaults(maxClientCount); // Run multiple clients async int currentClientCount = 0; var tasks = new int[maxClientCount] .Select(x => Task.Run <int>(async() => { var identity = identityProvider.AuthIdentities.ElementAt(currentClientCount); var client = new ClientWrapper(connectionConfig, identity, messageCount); ++currentClientCount; try { await client.Connect(); } catch (Exception e) { SocketObject.GlobalLog(e.ToString()); return(-1); } return(client.isSuccess ? 0 : 1); })) .ToList(); await Task.WhenAll(tasks.ToArray()); // Evaluate all clients var failureCount = tasks.Count(x => x.Result != 0); SocketObject.GlobalLog($"Client failures: {failureCount}"); return(failureCount > 0 ? 1 : 0); }
/// <summary> /// 生成列表页 /// </summary> /// <param name="baseConfigModel"></param> /// <returns></returns> public string IndexBuilder(BaseConfigModel baseConfigModel) { var areasUrl = baseConfigModel.OutputAreas + "/" + CommonHelper.DelLastLength(baseConfigModel.ControllerName, 10); StringBuilder sb = new StringBuilder(); sb.Append("@{;\r\n"); sb.Append(" ViewBag.Title = \"列表页面\";\r\n"); sb.Append(" Layout = \"~/Views/Shared/_Index.cshtml\";\r\n"); sb.Append("}\r\n"); sb.Append("<script>;\r\n"); sb.Append(" $(function () {\r\n"); sb.Append(" InitialPage();\r\n"); sb.Append(" GetGrid();\r\n"); sb.Append(" });\r\n"); sb.Append(" //初始化页面\r\n"); sb.Append(" function InitialPage() {\r\n"); sb.Append(" //resize重设布局;\r\n"); sb.Append(" $(window).resize(function (e) {\r\n"); sb.Append(" window.setTimeout(function () {\r\n"); sb.Append(" $('#gridTable').setGridWidth(($('.gridPanel').width()));\r\n"); if (baseConfigModel.gridModel.IsPage == true) { sb.Append(" $('#gridTable').setGridHeight($(window).height() - 136.5);\r\n"); } else { sb.Append(" $('#gridTable').setGridHeight($(window).height() - 108.5);\r\n"); } sb.Append(" }, 200);\r\n"); sb.Append(" e.stopPropagation();\r\n"); sb.Append(" });\r\n"); sb.Append(" }\r\n"); sb.Append(" //加载表格\r\n"); sb.Append(" function GetGrid() {\r\n"); sb.Append(" var selectedRowIndex = 0;\r\n"); sb.Append(" var $gridTable = $('#gridTable');\r\n"); sb.Append(" $gridTable.jqGrid({\r\n"); sb.Append(" autowidth: true,\r\n"); if (baseConfigModel.gridModel.IsPage == true) { sb.Append(" height: $(window).height() - 136.5,\r\n"); sb.Append(" url: \"../../" + areasUrl + "/GetPageListJson\",\r\n"); } else { sb.Append(" height: $(window).height() - 108.5,\r\n"); sb.Append(" url: \"../../" + areasUrl + "/GetListJson\",\r\n"); } sb.Append(" datatype: \"json\",\r\n"); sb.Append(" colModel: [\r\n"); List <GridColumnModel> colModel = baseConfigModel.gridColumnModel; if (colModel != null) { int j = 0; foreach (GridColumnModel entity in colModel) { sb.Append(" { label: '" + entity.label + "', name: '" + entity.name + "', index: '" + entity.name + "', width: " + entity.width + ", align: '" + entity.align + "',sortable: " + entity.sortable.ToString().ToLower() + " " + IsShow_Field(entity.hidden) + " }"); if (j < colModel.Count - 1) { sb.Append(",\r\n"); } j++; } } sb.Append(" ],\r\n"); if (baseConfigModel.gridModel.IsPage == true) { sb.Append(" viewrecords: true,\r\n"); sb.Append(" rowNum: 30,\r\n"); sb.Append(" rowList: [30, 50, 100],\r\n"); sb.Append(" pager: \"#gridPager\",\r\n"); sb.Append(" sortname: '',\r\n"); sb.Append(" sortorder: 'desc',\r\n"); sb.Append(" rownumbers: true,\r\n"); sb.Append(" shrinkToFit: false,\r\n"); sb.Append(" gridview: true,\r\n"); } sb.Append(" onSelectRow: function () {\r\n"); sb.Append(" selectedRowIndex = $('#' + this.id).getGridParam('selrow');\r\n"); sb.Append(" },\r\n"); sb.Append(" gridComplete: function () {\r\n"); sb.Append(" $('#' + this.id).setSelection(selectedRowIndex, false);\r\n"); sb.Append(" }\r\n"); sb.Append(" });\r\n"); sb.Append(" }\r\n"); sb.Append(" //新增\r\n"); sb.Append(" function btn_add() {\r\n"); sb.Append(" dialogOpen({\r\n"); sb.Append(" id: 'Form',\r\n"); sb.Append(" title: '添加" + baseConfigModel.Description + "',\r\n"); sb.Append(" url: '/" + areasUrl + "/" + baseConfigModel.FormPageName + "',\r\n"); sb.Append(" width: '" + baseConfigModel.formModel.width + "px',\r\n"); sb.Append(" height: '" + baseConfigModel.formModel.height + "px',\r\n"); sb.Append(" callBack: function (iframeId) {\r\n"); sb.Append(" top.frames[iframeId].AcceptClick();\r\n"); sb.Append(" }\r\n"); sb.Append(" });\r\n"); sb.Append(" }\r\n"); sb.Append(" //编辑\r\n"); sb.Append(" function btn_edit() {\r\n"); sb.Append(" var keyValue = $('#gridTable').jqGridRowValue('" + baseConfigModel.DataBaseTablePK + "');\r\n"); sb.Append(" if (checkedRow(keyValue)) {\r\n"); sb.Append(" dialogOpen({\r\n"); sb.Append(" id: 'Form',\r\n"); sb.Append(" title: '编辑" + baseConfigModel.Description + "',\r\n"); sb.Append(" url: '/" + areasUrl + "/" + baseConfigModel.FormPageName + "?keyValue=' + keyValue,\r\n"); sb.Append(" width: '" + baseConfigModel.formModel.width + "px',\r\n"); sb.Append(" height: '" + baseConfigModel.formModel.height + "px',\r\n"); sb.Append(" callBack: function (iframeId) {\r\n"); sb.Append(" top.frames[iframeId].AcceptClick();\r\n"); sb.Append(" }\r\n"); sb.Append(" })\r\n"); sb.Append(" }\r\n"); sb.Append(" }\r\n"); sb.Append(" //删除\r\n"); sb.Append(" function btn_delete() {\r\n"); sb.Append(" var keyValue = $('#gridTable').jqGridRowValue('" + baseConfigModel.DataBaseTablePK + "');\r\n"); sb.Append(" if (keyValue) {\r\n"); sb.Append(" $.RemoveForm({\r\n"); sb.Append(" url: '../../" + areasUrl + "/RemoveForm',\r\n"); sb.Append(" param: { keyValue: keyValue },\r\n"); sb.Append(" success: function (data) {\r\n"); sb.Append(" $('#gridTable').trigger('reloadGrid');\r\n"); sb.Append(" }\r\n"); sb.Append(" })\r\n"); sb.Append(" } else {\r\n"); sb.Append(" dialogMsg('请选择需要删除的" + baseConfigModel.Description + "!', 0);\r\n"); sb.Append(" }\r\n"); sb.Append(" }\r\n"); sb.Append("</script>\r\n"); sb.Append("<div class=\"titlePanel\">\r\n"); sb.Append(" <div class=\"title-search\">\r\n"); sb.Append(" <table>\r\n"); sb.Append(" <tr>\r\n"); sb.Append(" <td>\r\n"); sb.Append(" <input id=\"txt_Keyword\" type=\"text\" class=\"form-control\" placeholder=\"请输入要查询关键字\" style=\"width: 200px;\" />\r\n"); sb.Append(" </td>\r\n"); sb.Append(" <td style=\"padding-left: 5px;\">\r\n"); sb.Append(" <a id=\"btn_Search\" class=\"btn btn-primary\"><i class=\"fa fa-search\"></i> 查询</a>\r\n"); sb.Append(" </td>\r\n"); sb.Append(" </tr>\r\n"); sb.Append(" </table>\r\n"); sb.Append(" </div>\r\n"); sb.Append(" <div class=\"toolbar\">\r\n"); sb.Append(" <div class=\"btn-group\">\r\n"); sb.Append(" <a id=\"replace\" class=\"btn btn-default\" onclick=\"reload()\"><i class=\"fa fa-refresh\"></i>刷新</a>\r\n"); sb.Append(" <a id=\"add\" class=\"btn btn-default\" onclick=\"btn_add()\"><i class=\"fa fa-plus\"></i>新增</a>\r\n"); sb.Append(" <a id=\"edit\" class=\"btn btn-default\" onclick=\"btn_edit()\"><i class=\"fa fa-pencil-square-o\"></i>编辑</a>\r\n"); sb.Append(" <a id=\"delete\" class=\"btn btn-default\" onclick=\"btn_delete()\"><i class=\"fa fa-trash-o\"></i>删除</a>\r\n"); sb.Append(" </div>\r\n"); sb.Append(" </div>\r\n"); sb.Append("</div>\r\n"); sb.Append("<div class=\"gridPanel\">\r\n"); sb.Append(" <table id=\"gridTable\"></table>\r\n"); if (baseConfigModel.gridModel.IsPage == true) { sb.Append(" <div id=\"gridPager\"></div>\r\n"); } sb.Append("</div>\r\n"); return(sb.ToString()); }
/// <summary> /// 执行创建文件 /// </summary> /// <param name="baseConfigModel">基本信息</param> /// <param name="strCode">生成代码内容</param> public static void CreateExecution(BaseConfigModel baseConfigModel, string strCode) { var strParam = strCode.ToJObject(); #region 实体类 string entityCode = strParam["entityCode"].ToString(); string entityPath = baseConfigModel.OutputEntity + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.EntityClassName + ".cs"; //if (!System.IO.File.Exists(entityPath)) //{ DirFileHelper.CreateFileContent(entityPath, entityCode); //} #endregion #region 射类 string entitymapCode = strParam["entitymapCode"].ToString(); string entitymapPath = baseConfigModel.OutputMap + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.MapClassName + ".cs"; //if (!System.IO.File.Exists(entitymapPath)) //{ DirFileHelper.CreateFileContent(entitymapPath, entitymapCode); //} #endregion #region 务类 string serviceCode = strParam["serviceCode"].ToString(); string servicePath = baseConfigModel.OutputService + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.ServiceClassName + ".cs"; //if (!System.IO.File.Exists(servicePath)) //{ DirFileHelper.CreateFileContent(servicePath, serviceCode); //} #endregion #region 接口类 string iserviceCode = strParam["iserviceCode"].ToString(); string iservicePath = baseConfigModel.OutputIService + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.IServiceClassName + ".cs"; //if (!System.IO.File.Exists(iservicePath)) //{ DirFileHelper.CreateFileContent(iservicePath, iserviceCode); //} #endregion #region 业务类 string businesCode = strParam["businesCode"].ToString(); string businesPath = baseConfigModel.OutputBusines + "\\" + baseConfigModel.OutputAreas + "\\" + baseConfigModel.BusinesClassName + ".cs"; //if (!System.IO.File.Exists(businesPath)) //{ DirFileHelper.CreateFileContent(businesPath, businesCode); //} #endregion #region 控制器 string controllerCode = strParam["controllerCode"].ToString(); string controllerPath = baseConfigModel.OutputController + "\\Areas\\" + baseConfigModel.OutputAreas + "\\Controllers\\" + baseConfigModel.ControllerName + ".cs"; //if (!System.IO.File.Exists(controllerPath)) //{ DirFileHelper.CreateFileContent(controllerPath, controllerCode); //} #endregion #region 列表页 string indexCode = strParam["indexCode"].ToString(); string indexPath = baseConfigModel.OutputController + "\\Areas\\" + baseConfigModel.OutputAreas + "\\Views\\" + CommonHelper.DelLastLength(baseConfigModel.ControllerName, 10) + "\\" + baseConfigModel.IndexPageName + ".cshtml"; //if (!System.IO.File.Exists(indexPath)) //{ DirFileHelper.CreateFileContent(indexPath, indexCode.Replace("★", " ")); //} #endregion #region 表单页 string formCode = strParam["formCode"].ToString(); string formPath = baseConfigModel.OutputController + "\\Areas\\" + baseConfigModel.OutputAreas + "\\Views\\" + CommonHelper.DelLastLength(baseConfigModel.ControllerName, 10) + "\\" + baseConfigModel.FormPageName + ".cshtml"; //if (!System.IO.File.Exists(formPath)) //{ DirFileHelper.CreateFileContent(formPath, formCode.Replace("★", " ")); //} #endregion }
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)); } }
/// <summary> /// 生成业务类 /// </summary> /// <param name="baseConfigModel"></param> /// <returns></returns> public string BusinesBuilder(BaseConfigModel baseConfigModel) { StringBuilder sb = new StringBuilder(); sb.Append("using LeaRun.Application.Entity." + baseConfigModel.OutputAreas + ";\r\n"); sb.Append("using LeaRun.Application.IService." + baseConfigModel.OutputAreas + ";\r\n"); sb.Append("using LeaRun.Application.Service." + baseConfigModel.OutputAreas + ";\r\n"); sb.Append("using LeaRun.Util.WebControl;\r\n"); sb.Append("using System.Collections.Generic;\r\n"); sb.Append("using System;\r\n\r\n"); sb.Append("namespace LeaRun.Application.Busines." + baseConfigModel.OutputAreas + "\r\n"); sb.Append("{\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// V0.0.1\r\n"); sb.Append(" /// Copyright (c) 2013-2016 聚久信息技术有限公司\r\n"); sb.Append(" /// 创 建:" + baseConfigModel.CreateUser + "\r\n"); sb.Append(" /// 日 期:" + baseConfigModel.CreateDate + "\r\n"); sb.Append(" /// 描 述:" + baseConfigModel.Description + "\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" public class " + baseConfigModel.BusinesClassName + "\r\n"); sb.Append(" {\r\n"); sb.Append(" private " + baseConfigModel.IServiceClassName + " service = new " + baseConfigModel.ServiceClassName + "();\r\n\r\n"); sb.Append(" #region 获取数据\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 获取列表\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"pagination\">分页</param>\r\n"); sb.Append(" /// <param name=\"queryJson\">查询参数</param>\r\n"); sb.Append(" /// <returns>返回分页列表</returns>\r\n"); sb.Append(" public IEnumerable<" + baseConfigModel.EntityClassName + "> GetPageList(Pagination pagination, string queryJson)\r\n"); sb.Append(" {\r\n"); sb.Append(" return service.GetPageList(pagination, queryJson);\r\n"); sb.Append(" }\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 获取列表\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"queryJson\">查询参数</param>\r\n"); sb.Append(" /// <returns>返回列表</returns>\r\n"); sb.Append(" public IEnumerable<" + baseConfigModel.EntityClassName + "> GetList(string queryJson)\r\n"); sb.Append(" {\r\n"); sb.Append(" return service.GetList(queryJson);\r\n"); sb.Append(" }\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 获取实体\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"keyValue\">主键值</param>\r\n"); sb.Append(" /// <returns></returns>\r\n"); sb.Append(" public " + baseConfigModel.EntityClassName + " GetEntity(string keyValue)\r\n"); sb.Append(" {\r\n"); sb.Append(" return service.GetEntity(keyValue);\r\n"); sb.Append(" }\r\n"); sb.Append(" #endregion\r\n\r\n"); sb.Append(" #region 提交数据\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 删除数据\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"keyValue\">主键</param>\r\n"); sb.Append(" public void RemoveForm(string keyValue)\r\n"); sb.Append(" {\r\n"); sb.Append(" try\r\n"); sb.Append(" {\r\n"); sb.Append(" service.RemoveForm(keyValue);\r\n"); sb.Append(" }\r\n"); sb.Append(" catch (Exception)\r\n"); sb.Append(" {\r\n"); sb.Append(" throw;\r\n"); sb.Append(" }\r\n"); sb.Append(" }\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 保存表单(新增、修改)\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"keyValue\">主键值</param>\r\n"); sb.Append(" /// <param name=\"entity\">实体对象</param>\r\n"); sb.Append(" /// <returns></returns>\r\n"); sb.Append(" public void SaveForm(string keyValue, " + baseConfigModel.EntityClassName + " entity)\r\n"); sb.Append(" {\r\n"); sb.Append(" try\r\n"); sb.Append(" {\r\n"); sb.Append(" service.SaveForm(keyValue, entity);\r\n"); sb.Append(" }\r\n"); sb.Append(" catch (Exception)\r\n"); sb.Append(" {\r\n"); sb.Append(" throw;\r\n"); sb.Append(" }\r\n"); sb.Append(" }\r\n"); sb.Append(" #endregion\r\n"); sb.Append(" }\r\n"); sb.Append("}\r\n"); return(sb.ToString()); }
/// <summary> /// 生成实体类 /// </summary> /// <param name="baseConfigModel">基本信息</param> /// <param name="dt">实体字段</param> /// <returns></returns> public string EntityBuilder(BaseConfigModel baseConfigModel, DataTable dt) { StringBuilder sb = new StringBuilder(); sb.Append("using System;\r\n"); sb.Append("using System.ComponentModel.DataAnnotations.Schema;\r\n"); sb.Append("using LeaRun.Application.Code;\r\n\r\n"); sb.Append("namespace LeaRun.Application.Entity." + baseConfigModel.OutputAreas + "\r\n"); sb.Append("{\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 版 本\r\n"); sb.Append(" /// Copyright (c) 2013-2016 聚久信息技术有限公司\r\n"); sb.Append(" /// 创 建:" + baseConfigModel.CreateUser + "\r\n"); sb.Append(" /// 日 期:" + baseConfigModel.CreateDate + "\r\n"); sb.Append(" /// 描 述:" + baseConfigModel.Description + "\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" public class " + baseConfigModel.EntityClassName + " : BaseEntity\r\n"); sb.Append(" {\r\n"); sb.Append(" #region 实体成员\r\n"); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow rowItem in dt.Rows) { string column = rowItem["column"].ToString(); string remark = rowItem["remark"].ToString(); string datatype = CommHelper.FindModelsType(rowItem["datatype"].ToString()); sb.Append(" /// <summary>\r\n"); sb.Append(" /// " + remark + "\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <returns></returns>\r\n");// sb.Append(" [Column(\"" + column.ToUpper() + "\")]\r\n"); sb.Append(" public " + datatype + " " + column + " { get; set; }\r\n"); } } sb.Append(" #endregion\r\n\r\n"); sb.Append(" #region 扩展操作\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 新增调用\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" public override void Create()\r\n"); sb.Append(" {\r\n"); sb.Append(" this." + baseConfigModel.DataBaseTablePK + " = Guid.NewGuid().ToString();\r\n"); sb.Append(" " + IsCreateDate(dt) + "\r\n"); sb.Append(" " + IsCreateUserId(dt) + "\r\n"); sb.Append(" " + IsCreateUserName(dt) + "\r\n"); sb.Append(" }\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 编辑调用\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"keyValue\"></param>\r\n"); sb.Append(" public override void Modify(string keyValue)\r\n"); sb.Append(" {\r\n"); sb.Append(" this." + baseConfigModel.DataBaseTablePK + " = keyValue;\r\n"); sb.Append(" " + IsModifyDate(dt) + "\r\n"); sb.Append(" " + IsModifyUserId(dt) + "\r\n"); sb.Append(" " + IsModifyUserName(dt) + "\r\n"); sb.Append(" }\r\n"); sb.Append(" #endregion\r\n"); sb.Append(" }\r\n"); sb.Append("}"); return(sb.ToString()); }
/// <summary> /// 生成服务类 /// </summary> /// <param name="baseConfigModel"></param> /// <returns></returns> public string ServiceBuilder(BaseConfigModel baseConfigModel) { StringBuilder sb = new StringBuilder(); sb.Append("using LeaRun.Application.Entity." + baseConfigModel.OutputAreas + ";\r\n"); sb.Append("using LeaRun.Application.IService." + baseConfigModel.OutputAreas + ";\r\n"); sb.Append("using LeaRun.Data.Repository;\r\n"); sb.Append("using LeaRun.Util.WebControl;\r\n"); sb.Append("using System.Collections.Generic;\r\n"); sb.Append("using System.Linq;\r\n\r\n"); sb.Append("using LeaRun.Util;\r\n\r\n"); sb.Append("using LeaRun.Util.Extension;\r\n\r\n"); sb.Append("namespace LeaRun.Application.Service." + baseConfigModel.OutputAreas + "\r\n"); sb.Append("{\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// V0.0.1\r\n"); sb.Append(" /// Copyright (c) 2013-2016 聚久信息技术有限公司\r\n"); sb.Append(" /// 创 建:" + baseConfigModel.CreateUser + "\r\n"); sb.Append(" /// 日 期:" + baseConfigModel.CreateDate + "\r\n"); sb.Append(" /// 描 述:" + baseConfigModel.Description + "\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" public class " + baseConfigModel.ServiceClassName + " : RepositoryFactory<" + baseConfigModel.EntityClassName + ">, " + baseConfigModel.IServiceClassName + "\r\n"); sb.Append(" {\r\n"); bool bIsQuery = false; StringBuilder sbQuery = new StringBuilder(); sb.Append(" #region 获取数据\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 获取列表\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"pagination\">分页</param>\r\n"); sb.Append(" /// <param name=\"queryJson\">查询参数</param>\r\n"); sb.Append(" /// <returns>返回分页列表</returns>\r\n"); sb.Append(" public IEnumerable<" + baseConfigModel.EntityClassName + "> GetPageList(Pagination pagination, string queryJson)\r\n"); sb.Append(" {\r\n"); sb.Append(" return this.BaseRepository(\"BaseDb\",\"SqlServer\").FindList(pagination);\r\n"); sb.Append(" }\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 获取列表\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"queryJson\">查询参数</param>\r\n"); sb.Append(" /// <returns>返回列表</returns>\r\n"); sb.Append(" public IEnumerable<" + baseConfigModel.EntityClassName + "> GetList(string queryJson)\r\n"); sb.Append(" {\r\n"); //查询条件 if (bIsQuery) { sb.Append(" var expression = LinqExtensions.True<" + baseConfigModel.EntityClassName + ">();\r\n"); sb.Append(" var queryParam = queryJson.ToJObject();\r\n"); sb.Append(" //查询条件\r\n"); sb.Append(" if (!queryParam[\"condition\"].IsEmpty() && !queryParam[\"keyword\"].IsEmpty())\r\n"); sb.Append(" {\r\n"); sb.Append(" string condition = queryParam[\"condition\"].ToString();\r\n"); sb.Append(" string keyword = queryParam[\"keyword\"].ToString();\r\n"); sb.Append(" switch (condition)\r\n"); sb.Append(" {\r\n"); sb.Append(sbQuery); sb.Append(" default:\r\n"); sb.Append(" break;\r\n"); sb.Append(" }\r\n"); sb.Append(" }\r\n"); sb.Append(" return this.BaseRepository().IQueryable(expression).ToList();\r\n"); } else { sb.Append(" return this.BaseRepository(\"BaseDb\",\"SqlServer\").IQueryable().ToList();\r\n"); } sb.Append(" }\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 获取实体\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"keyValue\">主键值</param>\r\n"); sb.Append(" /// <returns></returns>\r\n"); sb.Append(" public " + baseConfigModel.EntityClassName + " GetEntity(string keyValue)\r\n"); sb.Append(" {\r\n"); sb.Append(" return this.BaseRepository(\"BaseDb\",\"SqlServer\").FindEntity(keyValue);\r\n"); sb.Append(" }\r\n"); sb.Append(" #endregion\r\n\r\n"); sb.Append(" #region 提交数据\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 删除数据\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"keyValue\">主键</param>\r\n"); sb.Append(" public void RemoveForm(string keyValue)\r\n"); sb.Append(" {\r\n"); sb.Append(" this.BaseRepository(\"BaseDb\",\"SqlServer\").Delete(keyValue);\r\n"); sb.Append(" }\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 保存表单(新增、修改)\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"keyValue\">主键值</param>\r\n"); sb.Append(" /// <param name=\"entity\">实体对象</param>\r\n"); sb.Append(" /// <returns></returns>\r\n"); sb.Append(" public void SaveForm(string keyValue, " + baseConfigModel.EntityClassName + " entity)\r\n"); sb.Append(" {\r\n"); sb.Append(" if (!string.IsNullOrEmpty(keyValue))\r\n"); sb.Append(" {\r\n"); sb.Append(" entity.Modify(keyValue);\r\n"); sb.Append(" this.BaseRepository(\"BaseDb\",\"SqlServer\").Update(entity);\r\n"); sb.Append(" }\r\n"); sb.Append(" else\r\n"); sb.Append(" {\r\n"); sb.Append(" entity.Create();\r\n"); sb.Append(" this.BaseRepository(\"BaseDb\",\"SqlServer\").Insert(entity);\r\n"); sb.Append(" }\r\n"); sb.Append(" }\r\n"); sb.Append(" #endregion\r\n"); sb.Append(" }\r\n"); sb.Append("}\r\n"); return(sb.ToString()); }
/// <summary> /// 生成服务接口类 /// </summary> /// <param name="baseConfigModel"></param> /// <returns></returns> public string IServiceBuilder(BaseConfigModel baseConfigModel) { StringBuilder sb = new StringBuilder(); sb.Append("using YaChH.Application.Entity." + baseConfigModel.OutputAreas + ";\r\n"); sb.Append("using YaChH.Util.WebControl;\r\n"); sb.Append("using System.Collections.Generic;\r\n\r\n"); sb.Append("namespace YaChH.Application.IService." + baseConfigModel.OutputAreas + "\r\n"); sb.Append("{\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 版 本 6.1\r\n"); sb.Append(" /// Copyright (c) 2013-2016 北京亚春华信息科技有限公司\r\n"); sb.Append(" /// 创 建:" + baseConfigModel.CreateUser + "\r\n"); sb.Append(" /// 日 期:" + baseConfigModel.CreateDate + "\r\n"); sb.Append(" /// 描 述:" + baseConfigModel.Description + "\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" public interface " + baseConfigModel.IServiceClassName + "\r\n"); sb.Append(" {\r\n"); sb.Append(" #region 获取数据\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 获取列表\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"pagination\">分页</param>\r\n"); sb.Append(" /// <param name=\"queryJson\">查询参数</param>\r\n"); sb.Append(" /// <returns>返回分页列表</returns>\r\n"); sb.Append(" IEnumerable<" + baseConfigModel.EntityClassName + "> GetPageList(Pagination pagination, string queryJson);\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 获取列表\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"queryJson\">查询参数</param>\r\n"); sb.Append(" /// <returns>返回列表</returns>\r\n"); sb.Append(" IEnumerable<" + baseConfigModel.EntityClassName + "> GetList(string queryJson);\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 获取实体\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"keyValue\">主键值</param>\r\n"); sb.Append(" /// <returns></returns>\r\n"); sb.Append(" " + baseConfigModel.EntityClassName + " GetEntity(string keyValue);\r\n"); sb.Append(" #endregion\r\n\r\n"); sb.Append(" #region 提交数据\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 删除数据\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"keyValue\">主键</param>\r\n"); sb.Append(" void RemoveForm(string keyValue);\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 保存表单(新增、修改)\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"keyValue\">主键值</param>\r\n"); sb.Append(" /// <param name=\"entity\">实体对象</param>\r\n"); sb.Append(" /// <returns></returns>\r\n"); sb.Append(" void SaveForm(string keyValue, " + baseConfigModel.EntityClassName + " entity);\r\n"); sb.Append(" #endregion\r\n"); sb.Append(" }\r\n"); sb.Append("}\r\n"); return(sb.ToString()); }
/// <summary> /// 生成表单页 /// </summary> /// <param name="baseConfigModel"></param> /// <returns></returns> public string FormBuilder(BaseConfigModel baseConfigModel) { var areasUrl = baseConfigModel.OutputAreas + "/" + CommonHelper.DelLastLength(baseConfigModel.ControllerName, 10); StringBuilder sb = new StringBuilder(); sb.Append("@{;\r\n"); sb.Append(" ViewBag.Title = \"表单页面\";\r\n"); sb.Append(" Layout = \"~/Views/Shared/_Form.cshtml\";\r\n"); sb.Append("}\r\n"); sb.Append("<script>\r\n"); sb.Append(" var keyValue = request('keyValue');\r\n"); sb.Append(" $(function () {\r\n"); sb.Append(" initControl();\r\n"); sb.Append(" });\r\n"); sb.Append(" //初始化控件\r\n"); sb.Append(" function initControl() {\r\n"); sb.Append(" //获取表单\r\n"); sb.Append(" if (!!keyValue) {\r\n"); sb.Append(" $.SetForm({\r\n"); sb.Append(" url: \"../../" + areasUrl + "/GetFormJson\",\r\n"); sb.Append(" param: { keyValue: keyValue },\r\n"); sb.Append(" success: function (data) {\r\n"); sb.Append(" $(\"#form1\").formDeserialize(data);\r\n"); sb.Append(" }\r\n"); sb.Append(" })\r\n"); sb.Append(" }\r\n"); sb.Append(" }\r\n"); sb.Append(" //保存表单;\r\n"); sb.Append(" function AcceptClick() {\r\n"); sb.Append(" if (!$('#form1').Validform()) {\r\n"); sb.Append(" return false;\r\n"); sb.Append(" }\r\n"); sb.Append(" var postData = $(\"#form1\").formSerialize(keyValue);\r\n"); sb.Append(" $.SaveForm({\r\n"); sb.Append(" url: \"../../" + areasUrl + "/SaveForm?keyValue=\" + keyValue,\r\n"); sb.Append(" param: postData,\r\n"); sb.Append(" loading: \"正在保存数据...\",\r\n"); sb.Append(" success: function () {\r\n"); sb.Append(" $.currentIframe().$(\"#gridTable\").trigger(\"reloadGrid\");\r\n"); sb.Append(" }\r\n"); sb.Append(" })\r\n"); sb.Append(" }\r\n"); sb.Append("</script>\r\n"); sb.Append("<div style=\"margin-top: 20px; margin-right: 30px;\">\r\n"); sb.Append(" <table class=\"form\">\r\n <tr>\r\n"); List <FormFieldModel> fieldModel = baseConfigModel.formFieldModel; if (fieldModel != null) { int clumnIndex = 1;//每行中第几列 foreach (FormFieldModel entity in fieldModel) { if (entity.ControlColspan == 1) { sb.Append(" <td class=\"formTitle\">" + entity.ControlName + "</td>\r\n"); sb.Append(" <td class=\"formValue\" colspan='3'>\r\n " + CreateControl(entity) + "\r\n </td>\r\n"); clumnIndex = 2; } else { sb.Append(" <td class=\"formTitle\">" + entity.ControlName + "</td>\r\n"); sb.Append(" <td class=\"formValue\">\r\n " + CreateControl(entity) + "\r\n </td>\r\n"); } if (baseConfigModel.formModel.FormType == 1) { sb.Append(" </tr>\r\n <tr>\r\n"); } else { if (clumnIndex == 2) { sb.Append(" </tr>\r\n <tr>\r\n"); clumnIndex = 1; } else { clumnIndex = 2; } } } } sb.Remove(sb.Length - 7, 7); sb.Append("\r\n"); sb.Append(" </table>\r\n"); sb.Append("</div>\r\n"); return(sb.ToString()); }
/// <summary> /// 生成控制器 /// </summary> /// <param name="baseConfigModel"></param> /// <returns></returns> public string ControllerBuilder(BaseConfigModel baseConfigModel) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("using {0}.Entity." + baseConfigModel.OutputAreas + ";\r\n", AssTag); sb.AppendFormat("using {0}.Busines." + baseConfigModel.OutputAreas + ";\r\n", AssTag); sb.Append("using BSFramework.Util;\r\n"); sb.Append("using BSFramework.Util.WebControl;\r\n"); sb.Append("using System.Web.Mvc;\r\n\r\n"); sb.AppendFormat("namespace {0}.Web.Areas." + baseConfigModel.OutputAreas + ".Controllers\r\n", AssTag); sb.Append("{\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 描 述:" + baseConfigModel.Description + "\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" public class " + baseConfigModel.ControllerName + " : MvcControllerBase\r\n"); sb.Append(" {\r\n"); sb.Append(" private " + baseConfigModel.BusinesClassName + " " + baseConfigModel.BusinesClassName.ToLower() + " = new " + baseConfigModel.BusinesClassName + "();\r\n\r\n"); sb.Append(" #region 视图功能\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 列表页面\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <returns></returns>\r\n"); sb.Append(" [HttpGet]\r\n"); sb.Append(" public ActionResult " + baseConfigModel.IndexPageName + "()\r\n"); sb.Append(" {\r\n"); sb.Append(" return View();\r\n"); sb.Append(" }\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 表单页面\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <returns></returns>\r\n"); sb.Append(" [HttpGet]\r\n"); sb.Append(" public ActionResult " + baseConfigModel.FormPageName + "()\r\n"); sb.Append(" {\r\n"); sb.Append(" return View();\r\n"); sb.Append(" }\r\n"); sb.Append(" #endregion\r\n\r\n"); sb.Append(" #region 获取数据\r\n"); if (baseConfigModel.gridModel.IsPage == true) { sb.Append(" /// <summary>\r\n"); sb.Append(" /// 获取列表\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"pagination\">分页参数</param>\r\n"); sb.Append(" /// <param name=\"queryJson\">查询参数</param>\r\n"); sb.Append(" /// <returns>返回分页列表Json</returns>\r\n"); sb.Append(" [HttpGet]\r\n"); sb.Append(" public ActionResult GetPageListJson(Pagination pagination, string queryJson)\r\n"); sb.Append(" {\r\n"); sb.Append(" var watch = CommonHelper.TimerStart();\r\n"); sb.Append(" var data = " + baseConfigModel.BusinesClassName.ToLower() + ".GetPageList(pagination, queryJson);\r\n"); sb.Append(" var jsonData = new\r\n"); sb.Append(" {\r\n"); sb.Append(" rows = data,\r\n"); sb.Append(" total = pagination.total,\r\n"); sb.Append(" page = pagination.page,\r\n"); sb.Append(" records = pagination.records,\r\n"); sb.Append(" costtime = CommonHelper.TimerEnd(watch)\r\n"); sb.Append(" };\r\n"); sb.Append(" return ToJsonResult(jsonData);\r\n"); sb.Append(" }\r\n"); } sb.Append(" /// <summary>\r\n"); sb.Append(" /// 获取列表\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"queryJson\">查询参数</param>\r\n"); sb.Append(" /// <returns>返回列表Json</returns>\r\n"); sb.Append(" [HttpGet]\r\n"); sb.Append(" public ActionResult GetListJson(string queryJson)\r\n"); sb.Append(" {\r\n"); sb.Append(" var data = " + baseConfigModel.BusinesClassName.ToLower() + ".GetList(queryJson);\r\n"); sb.Append(" return ToJsonResult(data);\r\n"); sb.Append(" }\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 获取实体 \r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"keyValue\">主键值</param>\r\n"); sb.Append(" /// <returns>返回对象Json</returns>\r\n"); sb.Append(" [HttpGet]\r\n"); sb.Append(" public ActionResult GetFormJson(string keyValue)\r\n"); sb.Append(" {\r\n"); sb.Append(" var data = " + baseConfigModel.BusinesClassName.ToLower() + ".GetEntity(keyValue);\r\n"); sb.Append(" return ToJsonResult(data);\r\n"); sb.Append(" }\r\n"); sb.Append(" #endregion\r\n\r\n"); sb.Append(" #region 提交数据\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 删除数据\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"keyValue\">主键值</param>\r\n"); sb.Append(" /// <returns></returns>\r\n"); sb.Append(" [HttpPost]\r\n"); sb.Append(" [ValidateAntiForgeryToken]\r\n"); sb.Append(" [AjaxOnly]\r\n"); sb.Append(" public ActionResult RemoveForm(string keyValue)\r\n"); sb.Append(" {\r\n"); sb.Append(" " + baseConfigModel.BusinesClassName.ToLower() + ".RemoveForm(keyValue);\r\n"); sb.Append(" return Success(\"删除成功。\");\r\n"); sb.Append(" }\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 保存表单(新增、修改)\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"keyValue\">主键值</param>\r\n"); sb.Append(" /// <param name=\"entity\">实体对象</param>\r\n"); sb.Append(" /// <returns></returns>\r\n"); sb.Append(" [HttpPost]\r\n"); sb.Append(" [ValidateAntiForgeryToken]\r\n"); sb.Append(" [AjaxOnly]\r\n"); sb.Append(" public ActionResult SaveForm(string keyValue, " + baseConfigModel.EntityClassName + " entity)\r\n"); sb.Append(" {\r\n"); sb.Append(" " + baseConfigModel.BusinesClassName.ToLower() + ".SaveForm(keyValue, entity);\r\n"); sb.Append(" return Success(\"操作成功。\");\r\n"); sb.Append(" }\r\n"); sb.Append(" #endregion\r\n"); sb.Append(" }\r\n"); sb.Append("}\r\n"); return(sb.ToString()); }
/// <summary> /// 生成业务类 /// </summary> /// <param name="baseConfigModel"></param> /// <returns></returns> public string BusinesBuilder(BaseConfigModel baseConfigModel) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("using {0}.Entity." + baseConfigModel.OutputAreas + ";\r\n", AssTag); sb.AppendFormat("using {0}.IService." + baseConfigModel.OutputAreas + ";\r\n", AssTag); sb.AppendFormat("using {0}.Service." + baseConfigModel.OutputAreas + ";\r\n", AssTag); sb.Append("using BSFramework.Util.WebControl;\r\n"); sb.Append("using System.Collections.Generic;\r\n"); sb.Append("using System;\r\n\r\n"); sb.AppendFormat("namespace {0}.Busines." + baseConfigModel.OutputAreas + "\r\n", AssTag); sb.Append("{\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 描 述:" + baseConfigModel.Description + "\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" public class " + baseConfigModel.BusinesClassName + "\r\n"); sb.Append(" {\r\n"); sb.Append(" private " + baseConfigModel.IServiceClassName + " service = new " + baseConfigModel.ServiceClassName + "();\r\n\r\n"); sb.Append(" #region 获取数据\r\n"); if (baseConfigModel.gridModel.IsPage == true) { sb.Append(" /// <summary>\r\n"); sb.Append(" /// 获取列表\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"pagination\">分页</param>\r\n"); sb.Append(" /// <param name=\"queryJson\">查询参数</param>\r\n"); sb.Append(" /// <returns>返回分页列表</returns>\r\n"); sb.Append(" public IEnumerable<" + baseConfigModel.EntityClassName + "> GetPageList(Pagination pagination, string queryJson)\r\n"); sb.Append(" {\r\n"); sb.Append(" return service.GetPageList(pagination, queryJson);\r\n"); sb.Append(" }\r\n"); } sb.Append(" /// <summary>\r\n"); sb.Append(" /// 获取列表\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"queryJson\">查询参数</param>\r\n"); sb.Append(" /// <returns>返回列表</returns>\r\n"); sb.Append(" public IEnumerable<" + baseConfigModel.EntityClassName + "> GetList(string queryJson)\r\n"); sb.Append(" {\r\n"); sb.Append(" return service.GetList(queryJson);\r\n"); sb.Append(" }\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 获取实体\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"keyValue\">主键值</param>\r\n"); sb.Append(" /// <returns></returns>\r\n"); sb.Append(" public " + baseConfigModel.EntityClassName + " GetEntity(string keyValue)\r\n"); sb.Append(" {\r\n"); sb.Append(" return service.GetEntity(keyValue);\r\n"); sb.Append(" }\r\n"); sb.Append(" #endregion\r\n\r\n"); sb.Append(" #region 提交数据\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 删除数据\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"keyValue\">主键</param>\r\n"); sb.Append(" public void RemoveForm(string keyValue)\r\n"); sb.Append(" {\r\n"); sb.Append(" try\r\n"); sb.Append(" {\r\n"); sb.Append(" service.RemoveForm(keyValue);\r\n"); sb.Append(" }\r\n"); sb.Append(" catch (Exception)\r\n"); sb.Append(" {\r\n"); sb.Append(" throw;\r\n"); sb.Append(" }\r\n"); sb.Append(" }\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 保存表单(新增、修改)\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"keyValue\">主键值</param>\r\n"); sb.Append(" /// <param name=\"entity\">实体对象</param>\r\n"); sb.Append(" /// <returns></returns>\r\n"); sb.Append(" public void SaveForm(string keyValue, " + baseConfigModel.EntityClassName + " entity)\r\n"); sb.Append(" {\r\n"); sb.Append(" try\r\n"); sb.Append(" {\r\n"); sb.Append(" service.SaveForm(keyValue, entity);\r\n"); sb.Append(" }\r\n"); sb.Append(" catch (Exception)\r\n"); sb.Append(" {\r\n"); sb.Append(" throw;\r\n"); sb.Append(" }\r\n"); sb.Append(" }\r\n"); sb.Append(" #endregion\r\n"); sb.Append(" }\r\n"); sb.Append("}\r\n"); return(sb.ToString()); }
/// <summary> /// 生成实体类 /// </summary> /// <param name="baseConfigModel">基本信息</param> /// <param name="dt">实体字段</param> /// <returns></returns> public string EntityBuilder(BaseConfigModel baseConfigModel, DataTable dt) { string databaseLinkID = baseConfigModel.DataBaseLinkId; DataBaseLinkEntity dataBaseLinkEntity = dataBaseLinkService.GetEntity(databaseLinkID); StringBuilder sb = new StringBuilder(); sb.Append("using System;\r\n"); sb.AppendFormat("using {0}.Code;\r\n", AssTag); sb.Append("using System.ComponentModel.DataAnnotations.Schema;\r\n"); sb.Append("using System.ComponentModel.DataAnnotations;\r\n\r\n"); sb.AppendFormat("namespace {0}.Entity." + baseConfigModel.OutputAreas + "\r\n", AssTag); sb.Append("{\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 描 述:" + baseConfigModel.Description + "\r\n"); sb.Append(" /// </summary>\r\n"); if (dataBaseLinkEntity.DbType == "Oracle") { sb.Append(" [Table(\"" + baseConfigModel.DataBaseTableName.ToUpper() + "\")]\r\n"); } sb.Append(" public class " + baseConfigModel.EntityClassName + " : BaseEntity\r\n"); sb.Append(" {\r\n"); sb.Append(" #region 实体成员\r\n"); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow rowItem in dt.Rows) { string column = rowItem["column_name"].ToString(); string remark = rowItem["remark"].ToString(); string datatype = CommHelper.FindModelsType(rowItem["datatype"].ToString()); sb.Append(" /// <summary>\r\n"); sb.Append(" /// " + remark + "\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <returns></returns>\r\n"); if (dataBaseLinkEntity.DbType == "Oracle") { sb.Append(" [Column(\"" + column.ToUpper() + "\")]\r\n"); } sb.Append(" public " + datatype + " " + column + " { get; set; }\r\n"); } } sb.Append(" #endregion\r\n\r\n"); sb.Append(" #region 扩展操作\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 新增调用\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" public override void Create()\r\n"); sb.Append(" {\r\n"); sb.Append(" this." + baseConfigModel.DataBaseTablePK + " = string.IsNullOrEmpty(Id)?Guid.NewGuid().ToString():Id;\r\n"); sb.Append(" " + IsCreateDate(dt) + ""); sb.Append(" " + IsCreateUserId(dt) + ""); sb.Append(" " + IsCreateUserName(dt) + ""); sb.Append(" this.CreateUserDeptCode = OperatorProvider.Provider.Current().DeptCode;\r\n"); sb.Append(" this.CreateUserOrgCode = OperatorProvider.Provider.Current().OrganizeCode;\r\n"); sb.Append(" }\r\n"); sb.Append(" /// <summary>\r\n"); sb.Append(" /// 编辑调用\r\n"); sb.Append(" /// </summary>\r\n"); sb.Append(" /// <param name=\"keyValue\"></param>\r\n"); sb.Append(" public override void Modify(string keyValue)\r\n"); sb.Append(" {\r\n"); sb.Append(" this." + baseConfigModel.DataBaseTablePK + " = keyValue;\r\n"); sb.Append(" " + IsModifyDate(dt) + ""); sb.Append(" " + IsModifyUserId(dt) + ""); sb.Append(" " + IsModifyUserName(dt) + ""); sb.Append(" }\r\n"); sb.Append(" #endregion\r\n"); sb.Append(" }\r\n"); sb.Append("}"); return(sb.ToString()); }