Esempio n. 1
0
        public string BuildEntity(BaseConfigModel baseConfigModel, DataTable dt)
        {
            // 读取模板
            var sb = ReadTemplet("Entity", baseConfigModel);

            #region 描述

            var describe = new StringBuilder();
            SetClassDescription("实体类", baseConfigModel, describe);
            sb = sb.Replace("{描述}", describe.ToString());

            #endregion

            #region 类名

            sb = sb.Replace("{类名}", baseConfigModel.FileConfig.EntityName);

            #endregion

            #region 表名称

            sb = sb.Replace("{表名称}", baseConfigModel.TableName);

            #endregion

            #region 字段

            var tableColum = new StringBuilder();
            var column     = string.Empty;
            var remark     = string.Empty;
            var datatype   = string.Empty;
            foreach (DataRow dr in dt.Rows)
            {
                column   = dr["TableColumn"].ToString();
                remark   = dr["Remark"].ToString();
                datatype = dr["Datatype"].ToString();
                datatype = TableMappingHelper.GetPropertyDatatype(datatype);
                tableColum.AppendLine("        /// <summary>");
                tableColum.AppendLine("        /// " + remark);
                tableColum.AppendLine("        /// </summary>");
                switch (datatype)
                {
                case "long?":
                    tableColum.AppendLine("        [JsonConverter(typeof(StringJsonConverter))]");
                    break;

                case "DateTime?":
                    tableColum.AppendLine("        [JsonConverter(typeof(DateTimeJsonConverter))]");
                    break;
                }

                tableColum.AppendLine("        public " + datatype + " " + column + " { get; set; }");
            }

            sb = sb.Replace("{字段}", tableColum.ToString());

            #endregion

            return(sb.ToString());
        }
Esempio n. 2
0
        public string BuildService(BaseConfigModel baseConfigModel, DataTable dt)
        {
            // 读取模板
            var sb = ReadTemplet("Service", baseConfigModel);

            #region 描述

            var describe = new StringBuilder();
            SetClassDescription("服务类", baseConfigModel, describe);
            sb = sb.Replace("{描述}", describe.ToString());

            #endregion

            #region 类名

            sb = sb.Replace("{类名}", baseConfigModel.FileConfig.ServiceName);

            #endregion

            #region 表名称

            sb = sb.Replace("{表名称}", baseConfigModel.TableName);

            #endregion

            #region 实体类名

            sb = sb.Replace("{实体类名}", baseConfigModel.FileConfig.EntityName);
            sb = sb.Replace("{驼峰实体类名}", TextHelper.StrFirstCharToLower(baseConfigModel.FileConfig.EntityName));

            #endregion

            #region 查询类名

            sb = sb.Replace("{查询类名}", baseConfigModel.FileConfig.EntityParamName.Replace("Param", "ListParam"));

            #endregion

            #region 查询条件

            var condition = new StringBuilder();
            if (baseConfigModel.PageIndex.SearchField != null)
            {
                foreach (var serachStr in baseConfigModel.PageIndex.SearchField)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        var column   = dr["TableColumn"].ToString();
                        var remark   = dr["Remark"].ToString();
                        var datatype = dr["Datatype"].ToString();
                        if (column == serachStr)
                        {
                            condition.AppendLine("            // " + remark);
                            datatype = TableMappingHelper.GetPropertyDatatype(datatype);
                            switch (datatype)
                            {
                            case "long?":
                            case "int?":
                            case "decimal?":
                            case "DateTime?":
                            case "bool?":
                                condition.AppendLine("            if (param." + column + ".HasValue)");
                                condition.AppendLine("                query = query.Where(p => p." + column +
                                                     " == param." + column + ");");
                                break;

                            case "string":
                                condition.AppendLine("            if (!string.IsNullOrEmpty(param." + column + "))");
                                condition.AppendLine("                query = query.Where(p => p." + column +
                                                     ".Contains(param." + column + "));");
                                break;
                            }

                            break;
                        }
                    }
                }
            }

            sb = sb.Replace("{查询条件}", condition.ToString());

            #endregion

            return(sb.ToString());
        }
Esempio n. 3
0
        public string BuildForm(BaseConfigModel baseConfigModel, DataTable dt)
        {
            // 初始化集合
            if (baseConfigModel.PageForm.FieldList == null)
            {
                baseConfigModel.PageForm.FieldList = new List <string>();
            }

            // 读取模板
            var sb = ReadTemplet("Form", baseConfigModel);

            #region 表单代码

            var fieldList = new StringBuilder();
            if (baseConfigModel.PageForm.FieldList.Count > 0)
            {
                var field      = string.Empty;
                var fieldLower = string.Empty;
                var col        = baseConfigModel.PageForm.ShowMode == 1 ? "12" : "6";

                for (var i = 0; i < baseConfigModel.PageForm.FieldList.Count; i++)
                {
                    // 第一个参数做一个必填示范
                    var req  = "";
                    var req2 = " lay-verType=\"tips\" ";
                    if (i == 0)
                    {
                        req  = " layui-form-required";
                        req2 = " lay-verType=\"tips\" lay-verify=\"required\" required ";
                    }

                    field = baseConfigModel.PageForm.FieldList[i];
                    var remark = string.Empty;
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (field == dr["TableColumn"].ToString())
                        {
                            remark = dr["Remark"].ToString();
                            break;
                        }
                    }

                    remark = string.IsNullOrWhiteSpace(remark) ? field : remark;

                    fieldLower = TableMappingHelper.FirstLetterLowercase(field);

                    fieldList.AppendLine("            <div class=\"layui-col-sm" + col + "\">");
                    fieldList.AppendLine("                <div class=\"layui-form-item\">");
                    fieldList.AppendLine("                    <label class=\"layui-form-label" + req + "\">" + remark +
                                         "</label>");
                    fieldList.AppendLine("                    <div class=\"layui-input-block\">");
                    fieldList.AppendLine("                        <input id=\"" + fieldLower + "\" name=\"" + field +
                                         "\" autocomplete=\"off\" type=\"text\" placeholder=\"请输入\" class=\"layui-input\" " +
                                         req2 + " >");
                    fieldList.AppendLine("                    </div>");
                    fieldList.AppendLine("                </div>");
                    fieldList.AppendLine("            </div>");
                }
            }

            sb = sb.Replace("{表单控件}", fieldList.ToString());

            #endregion

            return(sb.ToString());
        }
Esempio n. 4
0
        public BaseConfigModel GetBaseConfig(string path, string tableName, string tableDescription,
                                             List <string> tableFieldList)
        {
            path = GetProjectRootPath(path);

            var defaultField = 2; // 默认显示2个字段

            var baseConfigModel = new BaseConfigModel();

            baseConfigModel.TableName      = tableName;
            baseConfigModel.TableNameUpper = tableName;

            #region FileConfigModel

            baseConfigModel.FileConfig                  = new FileConfigModel();
            baseConfigModel.FileConfig.ClassPrefix      = TableMappingHelper.GetClassNamePrefix(tableName);
            baseConfigModel.FileConfig.ClassDescription = tableDescription;
            baseConfigModel.FileConfig.CreateDate       = DateTime.Now.ToString("yyyy-MM-dd HH:mm");

            baseConfigModel.FileConfig.EntityName      = string.Format("{0}", baseConfigModel.FileConfig.ClassPrefix);
            baseConfigModel.FileConfig.EntityMapName   = string.Format("{0}Map", baseConfigModel.FileConfig.ClassPrefix);
            baseConfigModel.FileConfig.EntityParamName =
                string.Format("{0}Param", baseConfigModel.FileConfig.ClassPrefix);
            baseConfigModel.FileConfig.BusinessName = string.Format("{0}BLL", baseConfigModel.FileConfig.ClassPrefix);
            baseConfigModel.FileConfig.ServiceName  =
                string.Format("{0}Service", baseConfigModel.FileConfig.ClassPrefix);
            baseConfigModel.FileConfig.ControllerName =
                string.Format("{0}Controller", baseConfigModel.FileConfig.ClassPrefix);
            baseConfigModel.FileConfig.PageIndexName =
                string.Format("{0}Index", baseConfigModel.FileConfig.ClassPrefix);
            baseConfigModel.FileConfig.PageFormName = string.Format("{0}Form", baseConfigModel.FileConfig.ClassPrefix);

            #endregion

            #region OutputConfigModel

            baseConfigModel.OutputConfig = new OutputConfigModel();
            baseConfigModel.OutputConfig.OutputModule   = string.Empty;
            baseConfigModel.OutputConfig.OutputEntity   = path;
            baseConfigModel.OutputConfig.OutputBusiness = path;
            baseConfigModel.OutputConfig.OutputWeb      = Path.Combine(path, "YiSha.WebApi");
            var areasModule = Path.Combine(baseConfigModel.OutputConfig.OutputWeb, "Areas");
            if (Directory.Exists(areasModule))
            {
                var areas = Directory.GetDirectories(areasModule).Select(p => Path.GetFileName(p))
                            .Where(p => p != "DemoManage");
                var modules = new List <KeyValue>();
                foreach (var area in areas)
                {
                    modules.Add(new KeyValue
                    {
                        Key   = area,
                        Value = area
                    });
                }

                baseConfigModel.OutputConfig.ModuleList = modules;
            }
            else
            {
                baseConfigModel.OutputConfig.ModuleList = new List <KeyValue>
                {
                    new()
                    {
                        Key   = "TestManage",
                        Value = "TestManage"
                    }
                };
            }

            #endregion

            #region PageIndexModel

            baseConfigModel.PageIndex              = new PageIndexModel();
            baseConfigModel.PageIndex.IsSearch     = 1;
            baseConfigModel.PageIndex.IsPagination = 1;
            baseConfigModel.PageIndex.ButtonList   = new List <string>();
            baseConfigModel.PageIndex.ColumnList   = new List <string>();
            baseConfigModel.PageIndex.ColumnList.AddRange(tableFieldList.Take(defaultField));

            #endregion

            #region PageFormModel

            baseConfigModel.PageForm           = new PageFormModel();
            baseConfigModel.PageForm.ShowMode  = 1;
            baseConfigModel.PageForm.FieldList = new List <string>();
            baseConfigModel.PageForm.FieldList.AddRange(tableFieldList.Take(defaultField));

            #endregion

            baseConfigModel.ClassName = GetClassName(tableName);
            ;

            return(baseConfigModel);
        }
Esempio n. 5
0
        public string BuildIndex(BaseConfigModel baseConfigModel, DataTable dt)
        {
            #region 初始化集合

            if (baseConfigModel.PageIndex.ButtonList == null)
            {
                baseConfigModel.PageIndex.ButtonList = new List <string>();
            }

            if (baseConfigModel.PageIndex.ColumnList == null)
            {
                baseConfigModel.PageIndex.ColumnList = new List <string>();
            }

            #endregion

            // 读取模板
            var sb = ReadTemplet("Index", baseConfigModel);


            #region 是否启用搜索

            if (baseConfigModel.PageIndex.IsSearch == 1)
            {
                sb = sb.Replace("{启用搜索}", "");
            }
            else
            {
                sb = sb.Replace("{启用搜索}", ".searchbar{ display:none; }");
            }

            #endregion

            #region 是否显示工具栏

            if (baseConfigModel.PageIndex.ButtonList.Where(p => p != "btnSearch").Any())
            {
                if (baseConfigModel.PageIndex.ButtonList.Where(p => p == "btnAdd").Any())
                {
                    sb = sb.Replace("{新增按钮}",
                                    "<a id=\"btnAdd\" class=\"layui-btn layui-btn-sm icon-btn\" lay-event=\"add\"><i class=\"layui-icon\">&#xe654;</i>新增</a>");
                }
                else
                {
                    sb = sb.Replace("{新增按钮}", "");
                }

                if (baseConfigModel.PageIndex.ButtonList.Where(p => p == "btnEdit").Any())
                {
                    sb = sb.Replace("{修改按钮}",
                                    "<a id=\"btnEdit\" class=\"layui-btn layui-btn-warm layui-btn-sm icon-btn\" lay-event=\"edit\"><i class=\"layui-icon\">&#xe642;</i>修改</a>");
                }
                else
                {
                    sb = sb.Replace("{修改按钮}", "");
                }

                if (baseConfigModel.PageIndex.ButtonList.Where(p => p == "btnDelete").Any())
                {
                    sb = sb.Replace("{删除按钮}",
                                    "<a id=\"btnDelete\" class=\"layui-btn layui-btn-danger layui-btn-sm icon-btn\" lay-event=\"del\"><i class=\"layui-icon\">&#xe640;</i>删除</a>");
                }
                else
                {
                    sb = sb.Replace("{删除按钮}", "");
                }
            }

            #endregion

            #region 表格列

            var columnList = new StringBuilder();
            foreach (var column in baseConfigModel.PageIndex.ColumnList)
            {
                var remark = string.Empty;
                foreach (DataRow dr in dt.Rows)
                {
                    if (column == dr["TableColumn"].ToString())
                    {
                        remark = dr["Remark"].ToString();
                        break;
                    }
                }

                remark = string.IsNullOrWhiteSpace(remark) ? column : remark;
                columnList.AppendLine("                    { field: '" + column + "', title: '" + remark +
                                      "', sort: true },");
            }

            sb = sb.Replace("{表格列}", columnList.ToString());

            #endregion

            #region 查询条件

            var condition = new StringBuilder();
            if (baseConfigModel.PageIndex.SearchField != null)
            {
                foreach (var serachStr in baseConfigModel.PageIndex.SearchField)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        var column   = dr["TableColumn"].ToString();
                        var remark   = dr["Remark"].ToString();
                        var datatype = dr["Datatype"].ToString();
                        if (column == serachStr)
                        {
                            if (string.IsNullOrWhiteSpace(remark))
                            {
                                remark = column;
                            }

                            condition.AppendLine("                        <div class=\"layui-inline\">");
                            condition.AppendLine("                            <label class=\"layui-form-label\">" + remark +
                                                 ":</label>");
                            condition.AppendLine("                            <div class=\"layui-input-inline\">");
                            datatype = TableMappingHelper.GetPropertyDatatype(datatype);
                            switch (datatype)
                            {
                            case "long?":
                            case "int?":
                            case "decimal?":
                                condition.AppendLine("                                <input name=\"" + column +
                                                     "\" class=\"layui-input\" placeholder=\"输入\" type=\"number\" />");
                                break;

                            default:
                                condition.AppendLine("                                <input name=\"" + column +
                                                     "\" class=\"layui-input\" placeholder=\"输入\" type=\"text\" />");
                                break;
                            }

                            condition.AppendLine("                            </div>");
                            condition.AppendLine("                        </div>");

                            break;
                        }
                    }
                }
            }

            sb = sb.Replace("{查询条件}", condition.ToString());

            #endregion

            return(sb.ToString());
        }
Esempio n. 6
0
        public string BuildEntityParam(BaseConfigModel baseConfigModel, DataTable dt)
        {
            // 读取模板
            var sb = ReadTemplet("ListParam", baseConfigModel);

            #region 描述

            var describe = new StringBuilder();
            SetClassDescription("实体查询类", baseConfigModel, describe);
            sb = sb.Replace("{描述}", describe.ToString());

            #endregion

            #region 类名

            sb.Replace("{类名}", baseConfigModel.FileConfig.EntityParamName.Replace("Param", "ListParam"));

            #endregion

            #region 字段

            var tableColum = new StringBuilder();

            if (baseConfigModel.PageIndex.SearchField != null)
            {
                foreach (var serachStr in baseConfigModel.PageIndex.SearchField)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        var column   = dr["TableColumn"].ToString();
                        var remark   = dr["Remark"].ToString();
                        var datatype = dr["Datatype"].ToString();
                        if (column == serachStr)
                        {
                            datatype = TableMappingHelper.GetPropertyDatatype(datatype);
                            tableColum.AppendLine("        /// <summary>");
                            tableColum.AppendLine("        /// " + remark);
                            tableColum.AppendLine("        /// </summary>");
                            tableColum.AppendLine("        /// <returns></returns>");
                            switch (datatype)
                            {
                            case "long?":
                                tableColum.AppendLine("        [JsonConverter(typeof(StringJsonConverter))]");
                                break;

                            case "DateTime?":
                                tableColum.AppendLine("        [JsonConverter(typeof(DateTimeJsonConverter))]");
                                break;
                            }

                            tableColum.AppendLine("        public " + datatype + " " + column + " { get; set; }");

                            break;
                        }
                    }
                }
            }

            sb = sb.Replace("{字段}", tableColum.ToString());

            #endregion

            return(sb.ToString());
        }