Beispiel #1
0
        public ArgumentWindow()
        {
            InitializeComponent();

            GenerateArgument = new GenerateArgument {
                ProjectName = string.Empty, FilePath = string.Empty
            };
            ReadGenerateArgumentFile();
        }
        public void Generate(TableInfo table, GenerateArgument argument)
        {
            using (var fs = new FileStream(GetFullFilePath(table.TableName, GenerateArgument.InterfaceFilePath, argument.FilePath), FileMode.Create))
                using (var sw = new StreamWriter(fs, Encoding.UTF8))
                {
                    #region using

                    sw.WriteLine("using System.Collections.Generic;");
                    sw.WriteLine("using {0}.Infrastructure;", argument.ProjectName);
                    sw.WriteLine("using {0}.Service.Dto;", argument.ProjectName);
                    sw.WriteLine("using {0}.Service.QueryParam;", argument.ProjectName);

                    sw.WriteLine();

                    #endregion

                    sw.WriteLine("namespace {0}.{1}", argument.ProjectName, GenerateArgument.InterfaceNamespaceTemp);
                    sw.WriteLine("{");
                    sw.WriteLine("    /// <summary>");
                    sw.WriteLine("    /// {0}服务接口", table.Comment);
                    sw.WriteLine("    /// </summary>");
                    sw.WriteLine("    public interface I{0}Service", table.TableName);
                    sw.WriteLine("    {");
                    sw.WriteLine("        /// <summary>");
                    sw.WriteLine("        /// 新增{0}", table.Comment);
                    sw.WriteLine("        /// </summary>");
                    sw.WriteLine("        /// <param name=\"model\"></param>");
                    sw.WriteLine("        void Add{0}({0}Dto model);", table.TableName);
                    sw.WriteLine();
                    sw.WriteLine("        /// <summary>");
                    sw.WriteLine("        /// 修改{0}", table.Comment);
                    sw.WriteLine("        /// </summary>");
                    sw.WriteLine("        /// <param name=\"model\"></param>");
                    sw.WriteLine("        void Update{0}({0}Dto model);", table.TableName);
                    sw.WriteLine();
                    sw.WriteLine("        /// <summary>");
                    sw.WriteLine("        /// 获取{0}", table.Comment);
                    sw.WriteLine("        /// </summary>");
                    sw.WriteLine("        /// <param name=\"id\"></param>");
                    sw.WriteLine("        {0}Dto Get{0}(int id);", table.TableName);
                    sw.WriteLine();
                    sw.WriteLine("        /// <summary>");
                    sw.WriteLine("        /// 删除{0}", table.Comment);
                    sw.WriteLine("        /// </summary>");
                    sw.WriteLine("        /// <param name=\"id\"></param>");
                    sw.WriteLine("        void Delete{0}(int id);", table.TableName);
                    sw.WriteLine();
                    sw.WriteLine("        /// <summary>");
                    sw.WriteLine("        /// 获取{0}分页列表", table.Comment);
                    sw.WriteLine("        /// </summary>");
                    sw.WriteLine("        /// <param name=\"paramter\"></param>");
                    sw.WriteLine("        PageList<{0}Dto> Get{0}PageList(QueryParamterBase<{0}QueryParam> paramter);", table.TableName);
                    sw.WriteLine("    }");
                    sw.Write("}");
                    sw.Flush();
                }
        }
        public void Generate(TableInfo table, GenerateArgument argument)
        {
            using (var fs = new FileStream(GetFullFilePath(table.TableName, GenerateArgument.DtoFilePath, argument.FilePath), FileMode.Create))
                using (var sw = new StreamWriter(fs, Encoding.UTF8))
                {
                    #region using

                    sw.WriteLine("using System;");

                    sw.WriteLine();

                    #endregion

                    sw.WriteLine("namespace {0}.{1}", argument.ProjectName, GenerateArgument.DtoNamespaceTemp);
                    sw.WriteLine("{");
                    sw.WriteLine("    /// <summary>");
                    sw.WriteLine("    /// {0}Dto", table.Comment);
                    sw.WriteLine("    /// </summary>");

                    sw.WriteLine("    public class {0}Dto", table.TableName);
                    sw.WriteLine("    {");

                    #region 属性

                    var flag = false;
                    foreach (var columnInfo in table.ColumnInfos)
                    {
                        if (flag)
                        {
                            sw.WriteLine();
                        }
                        sw.WriteLine("        /// <summary>");
                        sw.WriteLine("        /// {0}", string.IsNullOrEmpty(columnInfo.Comment) && columnInfo.Code == table.PrimaryKeyCode ? "主键" : columnInfo.Comment);
                        sw.WriteLine("        /// </summary>");

                        sw.WriteLine("        public {0} {1} {2} get; set; {3}", columnInfo.GetColumnType(), columnInfo.Code, "{", "}");

                        if (!flag)
                        {
                            flag = true;
                        }
                    }

                    #endregion

                    sw.WriteLine("    }");
                    sw.Write("}");
                    sw.Flush();
                }
        }
Beispiel #4
0
        public void Generate(TableInfo table, GenerateArgument argument)
        {
            using (var fs = new FileStream(GetFullFilePath(table.TableName, GenerateArgument.QueryParamFilePath, argument.FilePath), FileMode.Create))
                using (var sw = new StreamWriter(fs, Encoding.UTF8))
                {
                    #region using

                    sw.WriteLine("using System.Linq;");
                    sw.WriteLine("using {0}.Data.Entity;", argument.ProjectName);
                    sw.WriteLine();

                    #endregion

                    sw.WriteLine("namespace {0}.{1}", argument.ProjectName, GenerateArgument.QueryParamNamespaceTemp);
                    sw.WriteLine("{");
                    sw.WriteLine("    /// <summary>");
                    sw.WriteLine("    /// {0}查询参数", table.Comment);
                    sw.WriteLine("    /// </summary>");
                    sw.WriteLine("    public class {0}QueryParam", table.TableName);
                    sw.WriteLine("    {");
                    sw.WriteLine("        /// <summary>");
                    sw.WriteLine("        /// {0}查询参数", table.Comment);
                    sw.WriteLine("        /// </summary>");
                    sw.WriteLine("        public string Filter { get; set; }");
                    sw.WriteLine("    }");
                    sw.WriteLine();
                    sw.WriteLine("    /// <summary>");
                    sw.WriteLine("    /// {0}查询扩展", table.Comment);
                    sw.WriteLine("    /// </summary>");
                    sw.WriteLine("    public static class {0}QueryExtensions", table.TableName);
                    sw.WriteLine("    {");
                    sw.WriteLine("        /// <summary>");
                    sw.WriteLine("        /// 查询扩展");
                    sw.WriteLine("        /// </summary>");
                    sw.WriteLine("        /// <param name=\"source\"></param>");
                    sw.WriteLine("        /// <param name=\"param\"></param>");
                    sw.WriteLine("        /// <returns></returns>");
                    sw.WriteLine("        public static IQueryable<{0}> Where(this IQueryable<{0}> source, {0}QueryParam param)", table.TableName);
                    sw.WriteLine("        {");
                    sw.WriteLine("            if (param == null) return source;");
                    sw.WriteLine("            return source;");
                    sw.WriteLine("        }");
                    sw.WriteLine("    }");
                    sw.Write("}");
                    sw.Flush();
                }
        }
        public void Generate(TableInfo table, GenerateArgument argument)
        {
            using (var fs =
                       new FileStream(
                           GetFullFilePath(table.TableName, GenerateArgument.EntityFilePath, argument.FilePath),
                           FileMode.Create))
                using (var sw = new StreamWriter(fs, Encoding.UTF8))
                {
                    #region using

                    sw.WriteLine("using System;");
                    if (table.ChildTableInfos != null && table.ChildTableInfos.Count > 0)
                    {
                        sw.WriteLine("using System.Collections.Generic;");
                    }
                    sw.WriteLine();

                    #endregion

                    sw.WriteLine("namespace {0}.{1}", argument.ProjectName, GenerateArgument.EntityNamespaceTemp);
                    sw.WriteLine("{");
                    sw.WriteLine("    /// <summary>");
                    sw.WriteLine("    /// {0}", table.Comment);
                    sw.WriteLine("    /// </summary>");

                    sw.WriteLine("    public class {0}", table.TableName);
                    sw.WriteLine("    {");

                    #region 属性

                    var flag = false;
                    foreach (var columnInfo in table.ColumnInfos)
                    {
                        if (flag)
                        {
                            sw.WriteLine();
                        }
                        sw.WriteLine("        /// <summary>");
                        sw.WriteLine("        /// {0}",
                                     string.IsNullOrEmpty(columnInfo.Comment) && columnInfo.Code == table.PrimaryKeyCode
                                                        ? "主键"
                                                        : columnInfo.Comment);
                        sw.WriteLine("        /// </summary>");

                        sw.WriteLine("        public {0} {1} {2} get; set; {3}", columnInfo.GetColumnType(),
                                     columnInfo.Code, "{", "}");

                        if (!flag)
                        {
                            flag = true;
                        }
                    }

                    foreach (var referenceTable in table.ReferenceTableInfos)
                    {
                        sw.WriteLine();
                        sw.WriteLine("        /// <summary>");
                        sw.WriteLine("        /// {0}",
                                     string.IsNullOrEmpty(referenceTable.ForeignKey.Comment)
                                                        ? ""
                                                        : referenceTable.ForeignKey.Comment.ToUpper().Replace("ID", ""));
                        sw.WriteLine("        /// </summary>");
                        sw.WriteLine("        public virtual {0} {1} {2} get; set; {3}",
                                     referenceTable.ParentTable.TableName, referenceTable.ParentPropertyName, "{", "}");
                    }

                    if (table.ChildTableInfos != null)
                    {
                        foreach (var childTable in table.ChildTableInfos)
                        {
                            sw.WriteLine();
                            sw.WriteLine("        /// <summary>");
                            sw.WriteLine("        /// {0}集合", childTable.ChildTable.Comment);
                            sw.WriteLine("        /// </summary>");
                            sw.WriteLine("        public virtual ICollection<{0}> {1} {2} get; set; {3}",
                                         childTable.ChildTable.TableName, GetListPropertyName(childTable.ChildPropertyName), "{",
                                         "}");
                        }
                    }

                    #endregion

                    sw.WriteLine("    }");
                    sw.Write("}");
                    sw.Flush();
                }
        }
        public void Generate(TableInfo table, GenerateArgument argument)
        {
            using (var fs =
                       new FileStream(
                           GetFullFilePath(table.TableName, GenerateArgument.ImplementFilePath, argument.FilePath),
                           FileMode.Create))
                using (var sw = new StreamWriter(fs, Encoding.UTF8))
                {
                    #region using

                    sw.WriteLine("using System;");
                    sw.WriteLine("using System.Collections.Generic;");
                    sw.WriteLine("using System.Linq;");
                    sw.WriteLine("using {0}.Data;", argument.ProjectName);
                    sw.WriteLine("using {0}.Data.Entity;", argument.ProjectName);
                    sw.WriteLine("using {0}.Data.Enums;", argument.ProjectName);
                    sw.WriteLine("using {0}.Infrastructure;", argument.ProjectName);
                    sw.WriteLine("using {0}.Infrastructure.Cache;", argument.ProjectName);
                    sw.WriteLine("using {0}.Service.Dto;", argument.ProjectName);
                    sw.WriteLine("using {0}.Service.Interface;", argument.ProjectName);
                    sw.WriteLine("using {0}.Service.QueryParam;", argument.ProjectName);
                    sw.WriteLine("using Microsoft.EntityFrameworkCore;");

                    sw.WriteLine();

                    #endregion

                    sw.WriteLine("namespace {0}.{1}", argument.ProjectName, GenerateArgument.ImplementNamespaceTemp);
                    sw.WriteLine("{");
                    sw.WriteLine("    /// <inheritdoc />");
                    sw.WriteLine("    public class {0}Service : I{0}Service", table.TableName);
                    sw.WriteLine("    {");
                    sw.WriteLine("        private readonly BhDbContext _dbContext;");
                    sw.WriteLine();
                    sw.WriteLine("        /// <inheritdoc />");
                    sw.WriteLine("        public {0}Service(BhDbContext dbContext)", table.TableName);
                    sw.WriteLine("        {");
                    sw.WriteLine("            _dbContext = dbContext;");
                    sw.WriteLine("        }");
                    sw.WriteLine();
                    sw.WriteLine("        /// <inheritdoc />");
                    sw.WriteLine("        public void Add{0}({0}Dto model)", table.TableName);
                    sw.WriteLine("        {");
                    sw.WriteLine("            _dbContext.Set<{0}>().Add(new {0}", table.TableName);
                    sw.WriteLine("            {");

                    var index = 1;
                    var columnsNoPrimaryKey = table.ColumnInfos.Where(t => t.Code != table.PrimaryKeyCode).ToList();

                    foreach (var columnInfo in columnsNoPrimaryKey)
                    {
                        if (columnInfo.Code.ToUpper() != "MODIFYTIME")
                        {
                            if (columnInfo.Code.ToUpper() == "CREATETIME")
                            {
                                sw.WriteLine("                {0} = DateTime.Now{1}", columnInfo.Code, index == columnsNoPrimaryKey.Count ? "" : ",");
                            }
                            else
                            {
                                sw.WriteLine("                {0} = model.{0}{1}", columnInfo.Code, index == columnsNoPrimaryKey.Count ? "" : ",");
                            }
                        }

                        index++;
                    }

                    sw.WriteLine("            });");
                    sw.WriteLine();
                    sw.WriteLine("            _dbContext.SaveChanges();");
                    sw.WriteLine("        }");
                    sw.WriteLine();
                    sw.WriteLine("        /// <inheritdoc />");
                    sw.WriteLine("        public void Update{0}({0}Dto model)", table.TableName);
                    sw.WriteLine("        {");
                    sw.WriteLine("            var {0} = _dbContext.Set<{1}>().Find(model.Id) ??",
                                 GetCamelVarName(table.TableName), table.TableName);
                    sw.WriteLine("            		   throw new BusinessException($\"未能找到id为{0} model.Id }}的{1}信息\");", "{",
                                 table.Comment);
                    sw.WriteLine();

                    foreach (var columnInfo in columnsNoPrimaryKey)
                    {
                        if (columnInfo.Code.ToUpper() != "CREATETIME")
                        {
                            if (columnInfo.Code.ToUpper() == "MODIFYTIME")
                            {
                                sw.WriteLine("            {0}.{1} = DateTime.Now;", GetCamelVarName(table.TableName), columnInfo.Code);
                            }
                            else
                            {
                                sw.WriteLine("            {0}.{1} = model.{1};", GetCamelVarName(table.TableName), columnInfo.Code);
                            }
                        }
                    }

                    sw.WriteLine();
                    sw.WriteLine("            _dbContext.SaveChanges();");
                    sw.WriteLine("        }");
                    sw.WriteLine();
                    sw.WriteLine("        /// <inheritdoc />");
                    sw.WriteLine("        public {0}Dto Get{0}(int id)", table.TableName);
                    sw.WriteLine("        {");
                    sw.WriteLine("            var {0} = _dbContext.Set<{1}>().Find(id) ??",
                                 GetCamelVarName(table.TableName), table.TableName);
                    sw.WriteLine("            		   throw new BusinessException($\"未能找到id为{0} id }}的{1}信息\");", "{",
                                 table.Comment);
                    sw.WriteLine();
                    sw.WriteLine("            return new {0}Dto", table.TableName);
                    sw.WriteLine("            {");

                    index = 1;
                    foreach (var columnInfo in table.ColumnInfos)
                    {
                        sw.WriteLine("                {0} = {1}.{0}{2}", columnInfo.Code, GetCamelVarName(table.TableName), index == table.ColumnInfos.Count ? "" : ",");

                        index++;
                    }

                    sw.WriteLine("            };");
                    sw.WriteLine("        }");
                    sw.WriteLine();
                    sw.WriteLine("        /// <inheritdoc />");
                    sw.WriteLine("        public void Delete{0}(int id)", table.TableName);
                    sw.WriteLine("        {");
                    sw.WriteLine("            var {0} = _dbContext.Set<{1}>().Find(id) ??",
                                 GetCamelVarName(table.TableName), table.TableName);
                    sw.WriteLine("            		   throw new BusinessException($\"未能找到id为{0} id }}的{1}信息\");", "{",
                                 table.Comment);
                    sw.WriteLine();
                    sw.WriteLine("            _dbContext.Set<{0}>().Remove({1});", table.TableName,
                                 GetCamelVarName(table.TableName));
                    sw.WriteLine();
                    sw.WriteLine("            _dbContext.SaveChanges();");
                    sw.WriteLine("        }");
                    sw.WriteLine();
                    sw.WriteLine("        /// <inheritdoc />");
                    sw.WriteLine(
                        "        public PageList<{0}Dto> Get{0}PageList(QueryParamterBase<{0}QueryParam> paramter)",
                        table.TableName);
                    sw.WriteLine("        {");
                    sw.WriteLine("            return _dbContext.Set<{0}>()", table.TableName);
                    sw.WriteLine("                .AsNoTracking()");
                    sw.WriteLine("                .Where(paramter.ExtendParam)");
                    sw.WriteLine("                .Select(t => new {0}Dto", table.TableName);
                    sw.WriteLine("                {");

                    index = 1;
                    foreach (var columnInfo in table.ColumnInfos)
                    {
                        sw.WriteLine("                    {0} = t.{0}{1}", columnInfo.Code, index == table.ColumnInfos.Count ? "" : ",");

                        index++;
                    }

                    sw.WriteLine("                })");
                    sw.WriteLine("                .PageList(paramter);");
                    sw.WriteLine("        }");
                    sw.WriteLine("    }");
                    sw.Write("}");
                    sw.Flush();
                }
        }
        public void Generate(TableInfo table, GenerateArgument argument)
        {
            using (var fs = new FileStream(GetFullFilePath(table.TableName, GenerateArgument.ConfigFilePath, argument.FilePath), FileMode.Create))
                using (var sw = new StreamWriter(fs, Encoding.UTF8))
                {
                    #region using

                    sw.WriteLine("using {0}.Data.Entity;", argument.ProjectName);
                    sw.WriteLine("using Microsoft.EntityFrameworkCore;");
                    sw.WriteLine("using Microsoft.EntityFrameworkCore.Metadata.Builders;");
                    sw.WriteLine();

                    #endregion

                    sw.WriteLine("namespace {0}.{1}", argument.ProjectName, GenerateArgument.ConfigNamespaceTemp);
                    sw.WriteLine("{");

                    sw.WriteLine("    /// <inheritdoc />");
                    sw.WriteLine("    internal class {0}Configuration : IEntityTypeConfiguration<{0}>", table.TableName);
                    sw.WriteLine("    {");

                    sw.WriteLine("        /// <inheritdoc />");
                    sw.WriteLine("        public void Configure(EntityTypeBuilder<{0}> builder)", table.TableName);
                    sw.WriteLine("        {");
                    sw.WriteLine("            builder.ToTable(\"{0}\");", table.TableName);
                    sw.WriteLine("            builder.HasKey(t => t.{0});", table.PrimaryKeyCode);

                    var properties =
                        table.ColumnInfos.Where(t => t.DataType.ToUpper().Contains("TEXT") ||
                                                t.DataType.ToUpper().Contains("VARCHAR") ||
                                                t.DataType.ToUpper().Contains("NUMERIC"));
                    if (properties.Any())
                    {
                        sw.WriteLine();
                        sw.WriteLine("            // Properties");
                        foreach (var info in table.ColumnInfos)
                        {
                            if (info.DataType.ToUpper().Contains("TEXT") && info.Mandatory)
                            {
                                sw.WriteLine("			builder.Property(t => t.{0}).IsRequired();", info.Code);
                                continue;
                            }

                            var requiredStr = info.Mandatory ? ".IsRequired()" : "";

                            if (info.DataType.ToUpper().Contains("VARCHAR"))
                            {
                                if (info.Length > 0 || info.Mandatory)
                                {
                                    if (info.Length == 0)
                                    {
                                        if (info.Mandatory)
                                        {
                                            sw.WriteLine("			builder.Property(t => t.{0}).IsRequired();", info.Code);
                                        }
                                    }
                                    else
                                    {
                                        sw.WriteLine("			builder.Property(t => t.{0}){2}.HasMaxLength({1});",
                                                     info.Code, info.Length, requiredStr);
                                    }
                                }
                                continue;
                            }
                            if (info.DataType.ToUpper().Contains("NUMERIC") || info.DataType.ToUpper().Contains("DECIMAL"))
                            {
                                sw.WriteLine(
                                    "			builder.Property(t => t.{0}){3}.HasColumnType(\"decimal({1}, {2})\");",
                                    info.Code, info.Length, info.Precision, requiredStr);
                            }
                        }
                    }

                    //				sw.WriteLine("            // Table & Column Mappings");

                    //                foreach (var column in table.ColumnInfos)
                    //                {
                    //                    sw.WriteLine("            Property(t => t.{0}).HasColumnName(\"{0}\");", column.Code);
                    //                }

                    if (table.ReferenceTableInfos.Count > 0)
                    {
                        sw.WriteLine();
                        sw.WriteLine("            // Relationships");

                        var flag = false;
                        foreach (var reference in table.ReferenceTableInfos)
                        {
                            if (flag)
                            {
                                sw.WriteLine();
                            }

                            var childTableInfo =
                                reference.ParentTable.ChildTableInfos.FirstOrDefault(
                                    t => t.ChildTable.Id == table.Id && t.ForeignKey.Id == reference.ForeignKey.Id);
                            if (childTableInfo == null)
                            {
                                continue;
                            }

                            sw.WriteLine("            builder.{0}(t => t.{1})", "HasOne", reference.ParentPropertyName);
                            sw.WriteLine("                .WithMany(t => t.{0})", GetListPropertyName(childTableInfo.ChildPropertyName));
                            sw.WriteLine("                .HasForeignKey(d => d.{0});", reference.ForeignKey.Code);

                            flag = true;
                        }
                    }

                    sw.WriteLine("        }");
                    sw.WriteLine("    }");
                    sw.Write("}");
                    //sw.WriteLine();

                    sw.Flush();
                }
        }
        public void Generate(TableInfo table, GenerateArgument argument)
        {
            using (var fs =
                       new FileStream(
                           GetFullFilePath(table.TableName, GenerateArgument.ControllerFilePath, argument.FilePath),
                           FileMode.Create))
                using (var sw = new StreamWriter(fs, Encoding.UTF8))
                {
                    #region using

                    sw.WriteLine("using {0}.Infrastructure;", argument.ProjectName);
                    sw.WriteLine("using {0}.Service.Dto;", argument.ProjectName);
                    sw.WriteLine("using {0}.Service.Interface;", argument.ProjectName);
                    sw.WriteLine("using {0}.Service.QueryParam;", argument.ProjectName);
                    sw.WriteLine("using {0}.Web.Filter;", argument.ProjectName);
                    sw.WriteLine("using Microsoft.AspNetCore.Mvc;");
                    sw.WriteLine("using Microsoft.Extensions.Logging;");

                    sw.WriteLine();

                    #endregion

                    sw.WriteLine("namespace {0}.{1}", argument.ProjectName, GenerateArgument.ControllerNamespaceTemp);
                    sw.WriteLine("{");
                    sw.WriteLine("    public class {0}Controller : BaseController<{0}Controller>", table.TableName);
                    sw.WriteLine("    {");
                    sw.WriteLine("        private readonly I{0}Service _{1}Service;", table.TableName, GetCamelVarName(table.TableName));
                    sw.WriteLine();
                    sw.WriteLine("        public {0}Controller(ILogger<{0}Controller> logger,", table.TableName);
                    sw.WriteLine("            ILoginContext loginContext,");
                    sw.WriteLine("            I{0}Service {1}Service)", table.TableName, GetCamelVarName(table.TableName));
                    sw.WriteLine("            : base(logger, loginContext)");
                    sw.WriteLine("        {");
                    sw.WriteLine("            _{0}Service = {0}Service;", GetCamelVarName(table.TableName));
                    sw.WriteLine("        }");
                    sw.WriteLine();
                    sw.WriteLine("        /// <summary>");
                    sw.WriteLine("        /// {0}列表", table.Comment);
                    sw.WriteLine("        /// </summary>");
                    sw.WriteLine("        /// <returns></returns>");
                    sw.WriteLine("        [Permission(\"Query{0}\")]", table.TableName);
                    sw.WriteLine("        public IActionResult Index()");
                    sw.WriteLine("        {");
                    sw.WriteLine("            ViewBag.AllowAdd = CheckPower(\"Add{0}\");", table.TableName);
                    sw.WriteLine("            ViewBag.AllowEdit = CheckPower(\"Edit{0}\");", table.TableName);
                    sw.WriteLine("            ViewBag.AllowDelete = CheckPower(\"Delete{0}\");", table.TableName);
                    sw.WriteLine();
                    sw.WriteLine("            return PartialView();");
                    sw.WriteLine("        }");
                    sw.WriteLine();
                    sw.WriteLine("        /// <summary>");
                    sw.WriteLine("        /// 获取{0}分页集合", table.Comment);
                    sw.WriteLine("        /// </summary>");
                    sw.WriteLine("        /// <param name=\"paramter\"></param>");
                    sw.WriteLine("        /// <returns></returns>");
                    sw.WriteLine("        [Permission(\"Query{0}\")]", table.TableName);
                    sw.WriteLine("        public IActionResult Get{0}s([FromBody]QueryParamterBase<{0}QueryParam> paramter)", table.TableName);
                    sw.WriteLine("        {");
                    sw.WriteLine("            return ActionHandler(() => _{0}Service.Get{1}PageList(paramter));", GetCamelVarName(table.TableName), table.TableName);
                    sw.WriteLine("        }");
                    sw.WriteLine();
                    sw.WriteLine("        /// <summary>");
                    sw.WriteLine("        /// 新增/修改{0}", table.Comment);
                    sw.WriteLine("        /// </summary>");
                    sw.WriteLine("        /// <param name=\"id\">id为null时表示新增</param>");
                    sw.WriteLine("        /// <returns></returns>");
                    sw.WriteLine("        [Permission(\"Add{0},Edit{0}\")]", table.TableName);
                    sw.WriteLine("        public IActionResult Edit{0}(int? id)", table.TableName);
                    sw.WriteLine("        {");
                    sw.WriteLine("            return PartialView(id);");
                    sw.WriteLine("        }");
                    sw.WriteLine();
                    sw.WriteLine("        /// <summary>");
                    sw.WriteLine("        /// 获取{0}", table.Comment);
                    sw.WriteLine("        /// </summary>");
                    sw.WriteLine("        /// <param name=\"id\"></param>");
                    sw.WriteLine("        /// <returns></returns>");
                    sw.WriteLine("        [Permission(\"Edit{0}\")]", table.TableName);
                    sw.WriteLine("        public IActionResult Get{0}(int id)", table.TableName);
                    sw.WriteLine("        {");
                    sw.WriteLine("            return ActionHandler(() => _{0}Service.Get{1}(id));", GetCamelVarName(table.TableName), table.TableName);
                    sw.WriteLine("        }");
                    sw.WriteLine();
                    sw.WriteLine("        /// <summary>");
                    sw.WriteLine("        /// 新增{0}", table.Comment);
                    sw.WriteLine("        /// </summary>");
                    sw.WriteLine("        /// <param name=\"model\"></param>");
                    sw.WriteLine("        /// <returns></returns>");
                    sw.WriteLine("        [Permission(\"Add{0}\")]", table.TableName);
                    sw.WriteLine("        public IActionResult Add{0}({0}Dto model)", table.TableName);
                    sw.WriteLine("        {");
                    sw.WriteLine("            return ActionHandler(() => _{0}Service.Add{1}(model));", GetCamelVarName(table.TableName), table.TableName);
                    sw.WriteLine("        }");
                    sw.WriteLine();
                    sw.WriteLine("        /// <summary>");
                    sw.WriteLine("        /// 修改{0}", table.Comment);
                    sw.WriteLine("        /// </summary>");
                    sw.WriteLine("        /// <param name=\"model\"></param>");
                    sw.WriteLine("        /// <returns></returns>");
                    sw.WriteLine("        [Permission(\"Edit{0}\")]", table.TableName);
                    sw.WriteLine("        public IActionResult Update{0}({0}Dto model)", table.TableName);
                    sw.WriteLine("        {");
                    sw.WriteLine("            return ActionHandler(() => _{0}Service.Update{1}(model));", GetCamelVarName(table.TableName), table.TableName);
                    sw.WriteLine("        }");
                    sw.WriteLine();
                    sw.WriteLine("        /// <summary>");
                    sw.WriteLine("        /// 删除{0}", table.Comment);
                    sw.WriteLine("        /// </summary>");
                    sw.WriteLine("        /// <param name=\"id\"></param>");
                    sw.WriteLine("        /// <returns></returns>");
                    sw.WriteLine("        [Permission(\"Delete{0}\")]", table.TableName);
                    sw.WriteLine("        public IActionResult Delete{0}(int id)", table.TableName);
                    sw.WriteLine("        {");
                    sw.WriteLine("            return ActionHandler(() => _{0}Service.Delete{1}(id));", GetCamelVarName(table.TableName), table.TableName);
                    sw.WriteLine("        }");
                    sw.WriteLine("    }");
                    sw.Write("}");
                    sw.Flush();
                }
        }
Beispiel #9
0
        public void Generate(TableInfo table, GenerateArgument argument)
        {
            var columnInfos =
                table.ColumnInfos.Where(t =>
                                        t.Code != table.PrimaryKeyCode && t.Code.ToUpper() != "CREATETIME" &&
                                        t.Code.ToUpper() != "MODIFYTIME").ToList();

            using (var fs = new FileStream(GetFullFilePath(table.TableName, GenerateArgument.ViewFilePath, argument.FilePath), FileMode.Create))
                using (var sw = new StreamWriter(fs, Encoding.UTF8))
                {
                    #region html

                    sw.WriteLine("@model int?");
                    sw.WriteLine();
                    sw.WriteLine("<form method=\"get\" class=\"form-horizontal\" id=\"@ViewBag.FormId\" data-form-id=\"@ViewBag.FormId\">");
                    sw.WriteLine();

                    var index = 1;
                    foreach (var columnInfo in columnInfos)
                    {
                        if (index != 1)
                        {
                            sw.WriteLine("    <div class=\"hr-line-dashed\"></div>");
                        }

                        sw.WriteLine("    <div class=\"form-group\">");
                        sw.WriteLine(
                            "        <label class=\"col-sm-2 control-label\"><span style=\"color: red\">*&nbsp;</span>{0}</label>",
                            columnInfo.Comment);
                        sw.WriteLine();
                        sw.WriteLine("        <div class=\"col-sm-10\">");
                        sw.WriteLine(
                            "            <input type=\"text\" id=\"txt-{0}\" name=\"{0}\" class=\"form-control\" placeholder=\"请输入{1}\" />",
                            GetCamelVarName(columnInfo.Code), columnInfo.Comment);
                        sw.WriteLine("        </div>");
                        sw.WriteLine("    </div>");
                        sw.WriteLine();

                        index++;
                    }

                    sw.WriteLine("</form>");
                    sw.WriteLine();

                    #endregion

                    #region script

                    sw.WriteLine("<script>");
                    sw.WriteLine("    $(function () {");
                    sw.WriteLine("        var $win = getSubWinBody('@ViewBag.FormId');");
                    sw.WriteLine("        var winButtons = $win.data('buttons');");
                    sw.WriteLine("        var winEvents = $win.data('winEvents');");
                    sw.WriteLine();
                    sw.WriteLine("        var validator = $('#@ViewBag.FormId').validate({0}", "{");
                    sw.WriteLine("            rules: {");

                    index = 1;
                    foreach (var columnInfo in columnInfos)
                    {
                        sw.WriteLine("                {0}: {1}", GetCamelVarName(columnInfo.Code), "{");
                        sw.WriteLine("                    required: true,");
                        sw.WriteLine("                    maxlength: 20");
                        sw.WriteLine("                {0}{1}", "}", columnInfos.Count != index ? "," : "");

                        index++;
                    }

                    sw.WriteLine("            },");
                    sw.WriteLine("            messages: {0}", "{");

                    index = 1;
                    foreach (var columnInfo in columnInfos)
                    {
                        sw.WriteLine("                {0}: {1}", GetCamelVarName(columnInfo.Code), "{");
                        sw.WriteLine("                    required: '请输入{0}',", columnInfo.Comment);
                        sw.WriteLine("                    maxlength: '{0}长度不能大于20个字符'", columnInfo.Comment);
                        sw.WriteLine("                {0}{1}", "}", columnInfos.Count != index ? "," : "");

                        index++;
                    }

                    sw.WriteLine("            }");
                    sw.WriteLine("        });");
                    sw.WriteLine();

                    sw.WriteLine("        winButtons.save.click = function () {");
                    sw.WriteLine("            var result = $('#@ViewBag.FormId').valid();");
                    sw.WriteLine();
                    sw.WriteLine("            if (result === true) {");
                    sw.WriteLine("                var data = $('#@ViewBag.FormId').frmSerialize();");
                    sw.WriteLine("                data.Id = '@(Model ?? 0)';");
                    sw.WriteLine("                var url = '@(Model.HasValue ? Url.Action(\"Update{0}\") : Url.Action(\"Add{0}\"))';", table.TableName);
                    sw.WriteLine();
                    sw.WriteLine("                $('.ladda-button-save').attr('data-style', 'expand-left');");
                    sw.WriteLine("                var l = $('.ladda-button-save').ladda();");
                    sw.WriteLine();
                    sw.WriteLine("                l.ladda('start');");
                    sw.WriteLine("                bhPost(url, data, l, function () {");
                    sw.WriteLine("                    bhSuccess('保存成功');");
                    sw.WriteLine("                    winEvents.SavedAndClose();");
                    sw.WriteLine("                });");
                    sw.WriteLine("            }");
                    sw.WriteLine("        }");
                    sw.WriteLine();
                    sw.WriteLine("        if (!!'@Model') {");
                    sw.WriteLine("            $('#@ViewBag.FormId').bindData('@Url.Action(\"Get{0}\")', {1});", table.TableName, "{ id: '@Model' }");
                    sw.WriteLine("        }");
                    sw.WriteLine("    });");
                    sw.WriteLine();
                    sw.WriteLine("</script>");

                    #endregion

                    sw.Flush();
                }
        }
Beispiel #10
0
        public void Generate(TableInfo table, GenerateArgument argument)
        {
            using (var fs = new FileStream(GetFullFilePath(table.TableName, GenerateArgument.ViewFilePath, argument.FilePath), FileMode.Create))
                using (var sw = new StreamWriter(fs, Encoding.UTF8))
                {
                    #region html

                    sw.WriteLine("<div class=\"row wrapper border-bottom white-bg page-heading\">");
                    sw.WriteLine("    <div class=\"col-lg-10\">");
                    sw.WriteLine("        <ol class=\"breadcrumb\">");
                    sw.WriteLine("            <li>");
                    sw.WriteLine("                {0}管理", table.Comment);
                    sw.WriteLine("            </li>");
                    sw.WriteLine("            <li class=\"active\">");
                    sw.WriteLine("                <strong>{0}管理</strong>", table.Comment);
                    sw.WriteLine("            </li>");
                    sw.WriteLine("        </ol>");
                    sw.WriteLine("    </div>");
                    sw.WriteLine("</div>");
                    sw.WriteLine();

                    sw.WriteLine("<div class=\"wrapper wrapper-content animated\" id=\"@ViewBag.FormId\" data-form-id=\"@ViewBag.FormId\">");
                    sw.WriteLine("    <div class=\"row\">");
                    sw.WriteLine("        <div class=\"col-xs-12\">");
                    sw.WriteLine("            <div class=\"panel panel-default\" id=\"search-parms\">");
                    sw.WriteLine("                <div class=\"panel-heading accordion-inner\">");
                    sw.WriteLine("                    <div class=\"filters col-sm-10 col-xs-12\">");
                    sw.WriteLine("                        <form class=\"form-horizontal\" id=\"form_filter\">");
                    sw.WriteLine("                            <div class=\"col-xs-12\">");
                    sw.WriteLine("                                <label class=\"filter-caption col-md-4 input-sm\" for=\"txt_filter\"> 关键字</label>");
                    sw.WriteLine("                                <div class=\"filter-input col-md-8\">");
                    sw.WriteLine("                                    <input type=\"text\" id=\"txt_filter\" name=\"filter\" class=\"form-control input-sm\" placeholder=\"名称/描述\" />");
                    sw.WriteLine("                                </div>");
                    sw.WriteLine("                            </div>");
                    sw.WriteLine("                        </form>");
                    sw.WriteLine("                    </div>");
                    sw.WriteLine("                    <div class=\"col-sm-2 col-xs-12 pull-right filter-querybar\">");
                    sw.WriteLine("                        <button class=\"btn btn-primary btn-sm pull-right\" id=\"btn-search\" data-click-name=\"search\">");
                    sw.WriteLine("                            <i class=\"fa fa-search\">查询</i>");
                    sw.WriteLine("                        </button>");
                    sw.WriteLine("                    </div>");
                    sw.WriteLine("                    <div class=\"clearfix\"></div>");
                    sw.WriteLine("                </div>");
                    sw.WriteLine("            </div>");
                    sw.WriteLine("        </div>");
                    sw.WriteLine("        <div class=\"col-xs-12\">");
                    sw.WriteLine("            <table id=\"tb_{0}s\" class=\"bhtable\"></table>", GetCamelVarName(table.TableName));
                    sw.WriteLine("        </div>");
                    sw.WriteLine("    </div>");
                    sw.WriteLine("    <div id=\"toolbar\" class=\"btn-group\">");
                    sw.WriteLine("        @if (ViewBag.AllowAdd ?? false)");
                    sw.WriteLine("        {");
                    sw.WriteLine("            <button id=\"btn_add\" type=\"button\" class=\"btn btn-default\" data-click-name=\"add\">");
                    sw.WriteLine("                <span class=\"glyphicon glyphicon-plus\" aria-hidden=\"true\"></span>新增");
                    sw.WriteLine("            </button>");
                    sw.WriteLine("        }");
                    sw.WriteLine("    </div>");
                    sw.WriteLine("</div>");
                    sw.WriteLine();

                    #endregion

                    #region script

                    sw.WriteLine("<script>");
                    sw.WriteLine("    $(function () {");
                    sw.WriteLine("        var $win = $('#@ViewBag.FormId');");
                    sw.WriteLine("        $('.datepicker', $win).datepicker({");
                    sw.WriteLine("            format: 'yyyy/mm/d'");
                    sw.WriteLine("        });");
                    sw.WriteLine();
                    sw.WriteLine("        $('#tb_{0}s').bootstrapTable({1}", GetCamelVarName(table.TableName), "{");
                    sw.WriteLine("            url: '@Url.Action(\"Get{0}s\")',", table.TableName);
                    sw.WriteLine("            columns: [");

                    foreach (var columnInfo in table.ColumnInfos.Where(t => t.Code != table.PrimaryKeyCode))
                    {
                        sw.WriteLine("                {0} field: '{1}', title: '{2}', sortable: true{3}{4},", "{",
                                     GetCamelVarName(columnInfo.Code), columnInfo.Comment,
                                     IsAlignCenter(columnInfo) ? ", align: 'center'" : "", " }");
                    }

                    sw.WriteLine("                {");
                    sw.WriteLine("                    field: '{0}',", GetCamelVarName(table.PrimaryKeyCode));
                    sw.WriteLine("                    title: '操作',");
                    sw.WriteLine("                    cardVisible: false,");
                    sw.WriteLine("                    align: 'center',");
                    sw.WriteLine("                    formatter: function(data, row, index) {");
                    sw.WriteLine("                        var sOut = '<div>';");
                    sw.WriteLine();
                    sw.WriteLine("                        var edit = '@ViewBag.AllowEdit'.toLowerCase();");
                    sw.WriteLine("                        if (edit === 'true') {");
                    sw.WriteLine("                            sOut += '<button class=\"btn btn-primary  btn-xs\" data-click-name=\"edit\" data-id=\"' + data + '\"><i class=\"glyphicon glyphicon-edit\"></i>编辑</button>';");
                    sw.WriteLine("                        }");
                    sw.WriteLine();
                    sw.WriteLine("                        var del = '@ViewBag.AllowDelete'.toLowerCase();");
                    sw.WriteLine("                        if (del === 'true') {");
                    sw.WriteLine("                            sOut += '<button class=\"btn btn-danger btn-xs\" data-click-name=\"delete\" data-id=\"' + data + '\"><i class=\"glyphicon glyphicon-remove\"></i>删除</button>';");
                    sw.WriteLine("                        }");
                    sw.WriteLine();
                    sw.WriteLine("                        sOut += '</div>';");
                    sw.WriteLine("                        return sOut;");
                    sw.WriteLine("                    }");
                    sw.WriteLine("                }");
                    sw.WriteLine("            ]");
                    sw.WriteLine("        });");
                    sw.WriteLine();
                    sw.WriteLine("        function refreshTable() {");
                    sw.WriteLine("            $('#tb_{0}s', $win).bootstrapTable('refresh');", GetCamelVarName(table.TableName));
                    sw.WriteLine("        }");
                    sw.WriteLine();
                    sw.WriteLine("        $win.on('click', 'button, a', function() {");
                    sw.WriteLine("            if ($(this).has('data-click-name')) {");
                    sw.WriteLine("                var clickName = $(this).attr('data-click-name');");
                    sw.WriteLine("                var id = $(this).attr('data-id');");
                    sw.WriteLine();
                    sw.WriteLine("                switch (clickName) {");
                    sw.WriteLine("                    case 'search':");
                    sw.WriteLine("                        refreshTable();");
                    sw.WriteLine("                        break;");
                    sw.WriteLine("                    case 'add':");
                    sw.WriteLine("                        openDialog('@Url.Action(\"Edit{0}\")', '新增{1}', 700, 'Save', [], refreshTable);", table.TableName, table.Comment);
                    sw.WriteLine("                        break;");
                    sw.WriteLine("                    case 'edit':");
                    sw.WriteLine("                        openDialog('@Url.Action(\"Edit{0}\")?id=' + id, '编辑{1}', 700, 'Save', [], refreshTable);", table.TableName, table.Comment);
                    sw.WriteLine("                        break;");
                    sw.WriteLine("                    case 'delete':");
                    sw.WriteLine("                        bhConfirm({");
                    sw.WriteLine("                            'title': '提示',");
                    sw.WriteLine("                            'text': '确认删除该{0}?',", table.Comment);
                    sw.WriteLine("                            'parms': { Id: id },");
                    sw.WriteLine("                            'fnConfirmCallback': function (parms) {");
                    sw.WriteLine("                                var url = '@Url.Action(\"Delete{0}\")?id=' + parms.Id;", table.TableName);
                    sw.WriteLine("                                bhPost(url, {}, null, function () {");
                    sw.WriteLine("                                    bhSuccess('删除成功');");
                    sw.WriteLine("                                    refreshTable();");
                    sw.WriteLine("                                });");
                    sw.WriteLine("                            }");
                    sw.WriteLine("                        });");
                    sw.WriteLine("                        break;");
                    sw.WriteLine("                }");
                    sw.WriteLine("            }");
                    sw.WriteLine("        });");
                    sw.WriteLine("    });");
                    sw.WriteLine();
                    sw.WriteLine("</script>");

                    #endregion

                    sw.Flush();
                }
        }
 public ProgressWindow(IList <TableInfo> tableInfos, GenerateArgument generateArgument)
 {
     _tableInfos       = tableInfos;
     _generateArgument = generateArgument;
     InitializeComponent();
 }