From 40dba923790f8dca1af0340ec9271c298fccf778 Mon Sep 17 00:00:00 2001 From: "yubaolee@163.com" Date: Mon, 27 Nov 2017 16:55:52 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E8=B0=83=E6=95=B4html=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CodeSmith/EF/CSharp/Web/Application.cst | 138 +++++++++++++++++++++++ CodeSmith/EF/CSharp/Web/Controller.cst | 110 ++++++++++++++++++ CodeSmith/EF/CSharp/Web/Index.cshtml.cst | 105 +++++++++++++++++ CodeSmith/EF/CSharp/Web/Util.cs | 24 ++++ CodeSmith/EF/CSharp/WebGenerate.cst | 115 +++++++++++++++++++ 5 files changed, 492 insertions(+) create mode 100644 CodeSmith/EF/CSharp/Web/Application.cst create mode 100644 CodeSmith/EF/CSharp/Web/Controller.cst create mode 100644 CodeSmith/EF/CSharp/Web/Index.cshtml.cst create mode 100644 CodeSmith/EF/CSharp/Web/Util.cs create mode 100644 CodeSmith/EF/CSharp/WebGenerate.cst diff --git a/CodeSmith/EF/CSharp/Web/Application.cst b/CodeSmith/EF/CSharp/Web/Application.cst new file mode 100644 index 00000000..8425cd7b --- /dev/null +++ b/CodeSmith/EF/CSharp/Web/Application.cst @@ -0,0 +1,138 @@ +<%-- +Name: Database Table Properties +Author: yubaolee +Description: Create a list of properties from a database table +--%> +<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="False" Description="应用层" %> +<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %> +<%@ Property Name="NeedViewModel" Type="Boolean" Category="Context" Default="False" Description="是否需要ViewModel" %> +<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %> +<%@ Assembly Name="SchemaExplorer" %> +<%@ Import Namespace="SchemaExplorer" %> + + +<%if(NeedViewModel){ %> +using OpenAuth.App.ViewModel; +<%} %> +using OpenAuth.Domain; +using OpenAuth.Domain.Interface; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenAuth.App +{ + public class <%=ModuleName%>ManagerApp + { + private I<%=ModuleName%>Repository _repository; + private IOrgRepository _orgRepository; + + public <%=ModuleName%>ManagerApp(I<%=ModuleName%>Repository repository, + IOrgRepository orgRepository) + { + _repository = repository; + _orgRepository = orgRepository; + } + + public int Get<%=GetModelName()%>CntInOrg(int orgId) + { + if (orgId == 0) + { + return _repository.Find(null).Count(); + } + else + { + return _repository.Get<%=GetModelName()%>CntInOrgs(GetSubOrgIds(orgId)); + } + } + + public List<<%=GetModelName()%>> LoadAll() + { + return _repository.Find(null).ToList(); + } + + /// + /// 加载一个节点下面的一个或全部<%=GetModelName()%>s + /// + public dynamic Load(int orgId, int pageindex, int pagesize) + { + IEnumerable<<%=ModuleName%>> <%=ModuleName%>s; + int total = 0; + if (orgId == 0) + { + <%=ModuleName%>s = _repository.Load<%=ModuleName%>s(pageindex, pagesize); + total = _repository.GetCount(); + } + else + { + <%=ModuleName%>s = _repository.LoadInOrgs(pageindex, pagesize,GetSubOrgIds(orgId)); + total = _repository.Get<%=ModuleName%>CntInOrgs(orgId); + } + <%if(NeedViewModel){ %> + var <%=ModuleName%>views = new List<<%=ModuleName%>View>(); + foreach (var <%=ModuleName%> in <%=ModuleName%>s) + { + <%=ModuleName%>View uv = <%=ModuleName%>; + uv.Organizations = string.Join(",", _orgRepository.LoadBy<%=ModuleName%>(<%=ModuleName%>.Id).Select(u => u.Name).ToList()); + <%=ModuleName%>views.Add(uv); + } + <%} %> + + return new + { + total = total, + list = <%=GetModelName()%>s, + pageCurrent = pageindex + }; + } + + /// + /// 获取当前节点的所有下级节点 + /// + private int[] GetSubOrgIds(int orgId) + { + var org = _orgRepository.FindSingle(u => u.Id == orgId); + var orgs = _orgRepository.Find(u => u.CascadeId.Contains(org.CascadeId)).Select(u => u.Id).ToArray(); + return orgs; + } + + public <%=GetModelName()%> Find(int id) + { + var <%=ModuleName.ToLower()%> = _repository.FindSingle(u => u.Id == id); + if (<%=ModuleName.ToLower()%> == null) return new <%=GetModelName()%>(); + + return <%=ModuleName.ToLower() %>; + } + + public void Delete(int id) + { + _repository.Delete(id); + } + + public void AddOrUpdate(<%=GetModelName()%> model) + { + <%=ModuleName%> <%=ModuleName.ToLower()%> = new <%=ModuleName%>(); + model.CopyTo(<%=ModuleName.ToLower()%>); + + if (<%=ModuleName.ToLower()%>.Id == 0) + { + _repository.Add(<%=ModuleName.ToLower()%>); + } + else + { + _repository.Update(<%=ModuleName.ToLower()%>); + } + + } + + + } +} \ No newline at end of file diff --git a/CodeSmith/EF/CSharp/Web/Controller.cst b/CodeSmith/EF/CSharp/Web/Controller.cst new file mode 100644 index 00000000..c4352691 --- /dev/null +++ b/CodeSmith/EF/CSharp/Web/Controller.cst @@ -0,0 +1,110 @@ +<%-- +Name: Database Table Properties +Author: yubaolee +Description: Create a list of properties from a database table +--%> +<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="False" Description="控制器" %> +<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %> +<%@ Property Name="NeedViewModel" Type="Boolean" Category="Context" Default="False" Description="是否需要ViewModel" %> +<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %> +<%@ Assembly Name="SchemaExplorer" %> +<%@ Import Namespace="SchemaExplorer" %> + + +using System; +using System.Web.Mvc; +using Infrastructure; +using OpenAuth.App; +<%if(NeedViewModel){ %> +using OpenAuth.App.ViewModel; +<%} %> +using OpenAuth.Domain; + +namespace OpenAuth.Mvc.Controllers +{ + public class <%=ModuleName%>ManagerController : BaseController + { + private <%=ModuleName%>ManagerApp _app; + + public <%=ModuleName%>ManagerController() + { + _app = AutofacExt.GetFromFac<<%=ModuleName%>ManagerApp>(); + } + + // + // GET: /UserManager/ + public ActionResult Index() + { + return View(); + } + + public ActionResult Add(int id = 0) + { + return View(_app.Find(id)); + } + + //添加或修改<%=ModuleName %> + [HttpPost] + public string Add(<%=GetModelName()%> model) + { + try + { + _app.AddOrUpdate(model); + + } + catch (Exception ex) + { + BjuiResponse.statusCode = "300"; + BjuiResponse.message = ex.Message; + } + return JsonHelper.Instance.Serialize(BjuiResponse); + } + + /// + /// 加载节点下面的所有<%=ModuleName %>s + /// + public string Load(int parentId, int pageCurrent = 1, int pageSize = 30) + { + return JsonHelper.Instance.Serialize(_app.Load(parentId, pageCurrent, pageSize)); + } + + public string LoadForTree() + { + var models = _app.LoadAll(); + //添加根节点 + models.Add(new <%=ModuleName %> + { + Id = 0, + ParentId = -1, + Name = "根结点", + CascadeId = "0" + }); + return JsonHelper.Instance.Serialize(models); + } + + public string Delete(int Id) + { + try + { + _app.Delete(Id); + } + catch (Exception e) + { + BjuiResponse.statusCode = "300"; + BjuiResponse.message = e.Message; + } + + return JsonHelper.Instance.Serialize(BjuiResponse); + } + + + } +} \ No newline at end of file diff --git a/CodeSmith/EF/CSharp/Web/Index.cshtml.cst b/CodeSmith/EF/CSharp/Web/Index.cshtml.cst new file mode 100644 index 00000000..99e232d5 --- /dev/null +++ b/CodeSmith/EF/CSharp/Web/Index.cshtml.cst @@ -0,0 +1,105 @@ +<%-- +Name: 列表页面 +Author: yubaolee +Description: 列表页面 +--%> +<%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Encoding="utf-8" Description="添加模块" %> +<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" +Description="连接的数据库" %> +<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %> + +<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %> +<%@ Assembly Name="SchemaExplorer" %> +<%@ Import Namespace="SchemaExplorer" %> +<%@ Assembly Src="Util.cs" %> +<%@ Import Namespace="Util" %> + +@section header +{ + +} + + +
+ + + + + + <% foreach (ColumnSchema column in this.SourceTable.Columns) {%> + + <% }%> + + + +
<%=Tools.GetDescription(column)%>
+
+ + + + + + + + + diff --git a/CodeSmith/EF/CSharp/Web/Util.cs b/CodeSmith/EF/CSharp/Web/Util.cs new file mode 100644 index 00000000..0ebb0882 --- /dev/null +++ b/CodeSmith/EF/CSharp/Web/Util.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using CodeSmith.Engine; +using SchemaExplorer; + +namespace Util{ + public class Tools{ + public static String GetDescription(ColumnSchema column) { //得到字段的描述 + if(string.IsNullOrEmpty(column.Description)) + return column.Name; + else + return column.Description; + } + + public static bool NeedCascade(TableSchema SourceTable){ //判断表中是否需要下拉选择树 + return SourceTable.Columns.Contains("ParentId") + || SourceTable.Columns.Contains("CascadeId") ; + } + } +} \ No newline at end of file diff --git a/CodeSmith/EF/CSharp/WebGenerate.cst b/CodeSmith/EF/CSharp/WebGenerate.cst new file mode 100644 index 00000000..d8b00750 --- /dev/null +++ b/CodeSmith/EF/CSharp/WebGenerate.cst @@ -0,0 +1,115 @@ +<%@ Template Language="C#" TargetLanguage="Text" Debug="True" OutputType="None" %> + +<%@ Assembly Name="SchemaExplorer" %> +<%@ Assembly Name="CodeSmith.CustomProperties" %> + +<%@ Assembly Name="Mono.Cecil" Path="..\Common" %> +<%@ Assembly Name="ICSharpCode.NRefactory" Path="..\Common" %> +<%@ Assembly Name="ICSharpCode.NRefactory.CSharp" Path="..\Common" %> + +<%@ Assembly Src="Internal\Model.cs" %> +<%@ Assembly Src="Internal\Extensions.cs" %> +<%@ Assembly Src="Internal\Generator.cs" %> +<%@ Assembly Src="Internal\Parser.cs" %> + +<%@ Import Namespace="System.Collections.Generic" %> +<%@ Import Namespace="System.IO" %> +<%@ Import Namespace="System.Linq" %> +<%@ Import Namespace="System.Text" %> +<%@ Import Namespace="System.Text.RegularExpressions" %> + +<%@ Import Namespace="SchemaMapper" %> + +<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" +Description="连接的数据库" %> +<%@ Property Name="ModuleName" + Type="System.String" + Description="模块名称,如:User"%> +<%@ Property Name="directory" + Type="System.String" + Default=".\" + Optional="True" + Description="代码生成路径" + Editor="System.Windows.Forms.Design.FolderNameEditor, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" %> + +<%@ Property Name="NeedViewModel" + Type="Boolean" + Category="5.Customization" + Default="False" + Optional="True" + Description="是否需要ViewModel" %> + + +<%@ Register Name="ApplicationGenerateClass" + Template="Web\Application.cst" + MergeProperties="False" %> +<%@ Register Name="HtmlGenerateClass" + Template="Web\Index.cshtml.cst" + MergeProperties="False" %> +Generating Entities ... +<% Generate(); %> + + \ No newline at end of file From 69fdbef881d3b50d401b2e7a3e32f56a2b3d350b Mon Sep 17 00:00:00 2001 From: "yubaolee@163.com" Date: Mon, 27 Nov 2017 16:56:45 +0800 Subject: [PATCH 2/6] ru --- CodeSmith/EF/CSharp/Internal/Context.Generated.cst | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/CodeSmith/EF/CSharp/Internal/Context.Generated.cst b/CodeSmith/EF/CSharp/Internal/Context.Generated.cst index e2220fce..df3d3a21 100644 --- a/CodeSmith/EF/CSharp/Internal/Context.Generated.cst +++ b/CodeSmith/EF/CSharp/Internal/Context.Generated.cst @@ -77,14 +77,7 @@ namespace <%= ContextNamespace %> public System.Data.Entity.<%= InterfaceMode ? "I" : "" %>DbSet<<%= p.ClassName.ToSafeName() %>> <%= p.ContextName.ToSafeName() %> { get; set; } <% } // foreach %> - protected override void OnModelCreating(DbModelBuilder modelBuilder) - { -<% foreach(var p in EntityContext.Entities) { %> - modelBuilder.Configurations.Add(new <%= p.MappingName.ToSafeName() %>()); -<% } // foreach %> - - InitializeMapping(modelBuilder); - } + <% if (InterfaceMode) { %> System.Data.Entity.IDbSet IDbContext.Set() From 64756cfd3105c4e51f2bc9c5c9bf8fcff2d76093 Mon Sep 17 00:00:00 2001 From: "yubaolee@163.com" Date: Mon, 27 Nov 2017 17:00:15 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CodeSmith/{EF => }/CSharp/Entity.cst | 0 .../CSharp/Internal/Context.Generated.cst | 0 .../CSharp/Internal/Entity.Generated.cst | 142 +++++----- .../{EF => }/CSharp/Internal/Extensions.cs | 0 .../{EF => }/CSharp/Internal/Generator.cs | 0 .../CSharp/Internal/Mapping.Generated.cst | 0 CodeSmith/{EF => }/CSharp/Internal/Model.cs | 0 CodeSmith/{EF => }/CSharp/Internal/Parser.cs | 0 CodeSmith/{ => CSharp/Web}/Application.cst | 0 CodeSmith/{ => CSharp/Web}/Controller.cst | 0 .../Web/Index.cshtml.1.cst} | 4 +- .../{EF => }/CSharp/Web/Index.cshtml.cst | 0 CodeSmith/{EF => }/CSharp/Web/Util.cs | 0 CodeSmith/{EF => }/CSharp/WebGenerate.cst | 0 .../Common/ICSharpCode.NRefactory.CSharp.dll | Bin .../Common/ICSharpCode.NRefactory.dll | Bin CodeSmith/{EF => }/Common/Mono.Cecil.dll | Bin CodeSmith/EF/CSharp/Web/Application.cst | 138 ---------- CodeSmith/EF/CSharp/Web/Controller.cst | 110 -------- CodeSmith/IRepository.cst | 28 -- CodeSmith/NoCascadeIndex.cshtml.cst | 112 -------- CodeSmith/Repository.cst | 49 ---- CodeSmith/Util.cs | 24 -- CodeSmith/editDlg.js.cst | 251 ------------------ 24 files changed, 74 insertions(+), 784 deletions(-) rename CodeSmith/{EF => }/CSharp/Entity.cst (100%) rename CodeSmith/{EF => }/CSharp/Internal/Context.Generated.cst (100%) rename CodeSmith/{EF => }/CSharp/Internal/Entity.Generated.cst (97%) rename CodeSmith/{EF => }/CSharp/Internal/Extensions.cs (100%) rename CodeSmith/{EF => }/CSharp/Internal/Generator.cs (100%) rename CodeSmith/{EF => }/CSharp/Internal/Mapping.Generated.cst (100%) rename CodeSmith/{EF => }/CSharp/Internal/Model.cs (100%) rename CodeSmith/{EF => }/CSharp/Internal/Parser.cs (100%) rename CodeSmith/{ => CSharp/Web}/Application.cst (100%) rename CodeSmith/{ => CSharp/Web}/Controller.cst (100%) rename CodeSmith/{Index.cshtml.cst => CSharp/Web/Index.cshtml.1.cst} (98%) rename CodeSmith/{EF => }/CSharp/Web/Index.cshtml.cst (100%) rename CodeSmith/{EF => }/CSharp/Web/Util.cs (100%) rename CodeSmith/{EF => }/CSharp/WebGenerate.cst (100%) rename CodeSmith/{EF => }/Common/ICSharpCode.NRefactory.CSharp.dll (100%) rename CodeSmith/{EF => }/Common/ICSharpCode.NRefactory.dll (100%) rename CodeSmith/{EF => }/Common/Mono.Cecil.dll (100%) delete mode 100644 CodeSmith/EF/CSharp/Web/Application.cst delete mode 100644 CodeSmith/EF/CSharp/Web/Controller.cst delete mode 100644 CodeSmith/IRepository.cst delete mode 100644 CodeSmith/NoCascadeIndex.cshtml.cst delete mode 100644 CodeSmith/Repository.cst delete mode 100644 CodeSmith/Util.cs delete mode 100644 CodeSmith/editDlg.js.cst diff --git a/CodeSmith/EF/CSharp/Entity.cst b/CodeSmith/CSharp/Entity.cst similarity index 100% rename from CodeSmith/EF/CSharp/Entity.cst rename to CodeSmith/CSharp/Entity.cst diff --git a/CodeSmith/EF/CSharp/Internal/Context.Generated.cst b/CodeSmith/CSharp/Internal/Context.Generated.cst similarity index 100% rename from CodeSmith/EF/CSharp/Internal/Context.Generated.cst rename to CodeSmith/CSharp/Internal/Context.Generated.cst diff --git a/CodeSmith/EF/CSharp/Internal/Entity.Generated.cst b/CodeSmith/CSharp/Internal/Entity.Generated.cst similarity index 97% rename from CodeSmith/EF/CSharp/Internal/Entity.Generated.cst rename to CodeSmith/CSharp/Internal/Entity.Generated.cst index 632d50d9..d387ffed 100644 --- a/CodeSmith/EF/CSharp/Internal/Entity.Generated.cst +++ b/CodeSmith/CSharp/Internal/Entity.Generated.cst @@ -1,72 +1,72 @@ -<%@ Template Language="C#" TargetLanguage="C#" Debug="True" Encoding="UTF-8" %> - -<%@ Assembly Src="Model.cs" %> -<%@ Assembly Src="Extensions.cs" %> - -<%@ Import Namespace="System.Collections.Generic" %> -<%@ Import Namespace="System.Linq" %> -<%@ Import Namespace="System.Text" %> -<%@ Import Namespace="System.Text.RegularExpressions" %> - -<%@ Import Namespace="SchemaMapper" %> - -<%@ Property Name="Entity" - Type="SchemaMapper.Entity" %> - -<%@ Property Name="EntityNamespace" - Type="System.String" %> -//------------------------------------------------------------------------------ -// -// This code was generated by a CodeSmith Template. -// -// DO NOT MODIFY contents of this file. Changes to this -// file will be lost if the code is regenerated. -// Author:Yubao Li -// -//------------------------------------------------------------------------------ -using System; -using System.Collections.Generic; -using System.Text; - -namespace <%= EntityNamespace %> -{ - /// - /// <%= Entity.Description %> - /// - public partial class <%= Entity.ClassName.ToSafeName() %> : Entity - { - public <%= Entity.ClassName.ToSafeName() %>() - { -<% foreach(var p in Entity.Properties) { - if(p.IsPrimaryKey ==true) continue; - string type = p.SystemType.ToNullableType(p.IsNullable == true); - if(type =="int" || type=="decimal") - Response.WriteLine(" this."+p.PropertyName.ToSafeName()+"= 0;"); - else if(type =="string") - Response.WriteLine(" this."+p.PropertyName.ToSafeName()+"= string.Empty;"); - else if(type.ToLower().Contains("datetime")) - Response.WriteLine(" this."+p.PropertyName.ToSafeName()+"= DateTime.Now;"); - } // foreach %> -<% foreach(var r in Entity.Relationships.Where(e => e.ThisCardinality == Cardinality.Many)) { %> - <%= r.ThisPropertyName.ToSafeName() %> = new List<<%= r.OtherEntity.ToSafeName() %>>(); -<% } // foreach %> - } - -<% foreach(var p in Entity.Properties) { - if(p.IsPrimaryKey ==true) continue; - %> - /// - /// <%=p.Description %> - /// - public <%= p.SystemType.ToNullableType(p.IsNullable == true) %> <%= p.PropertyName.ToSafeName() %> { get; set; } -<% } // foreach %> - -<% foreach(var r in Entity.Relationships) { %> -<% if(r.ThisCardinality == Cardinality.Many) { %> - public virtual ICollection<<%= r.OtherEntity.ToSafeName() %>> <%= r.ThisPropertyName.ToSafeName() %> { get; set; } -<% } else { %> - public virtual <%= r.OtherEntity.ToSafeName() %> <%= r.ThisPropertyName.ToSafeName() %> { get; set; } -<% } %> -<% } // foreach %> - } +<%@ Template Language="C#" TargetLanguage="C#" Debug="True" Encoding="UTF-8" %> + +<%@ Assembly Src="Model.cs" %> +<%@ Assembly Src="Extensions.cs" %> + +<%@ Import Namespace="System.Collections.Generic" %> +<%@ Import Namespace="System.Linq" %> +<%@ Import Namespace="System.Text" %> +<%@ Import Namespace="System.Text.RegularExpressions" %> + +<%@ Import Namespace="SchemaMapper" %> + +<%@ Property Name="Entity" + Type="SchemaMapper.Entity" %> + +<%@ Property Name="EntityNamespace" + Type="System.String" %> +//------------------------------------------------------------------------------ +// +// This code was generated by a CodeSmith Template. +// +// DO NOT MODIFY contents of this file. Changes to this +// file will be lost if the code is regenerated. +// Author:Yubao Li +// +//------------------------------------------------------------------------------ +using System; +using System.Collections.Generic; +using System.Text; + +namespace <%= EntityNamespace %> +{ + /// + /// <%= Entity.Description %> + /// + public partial class <%= Entity.ClassName.ToSafeName() %> : Entity + { + public <%= Entity.ClassName.ToSafeName() %>() + { +<% foreach(var p in Entity.Properties) { + if(p.IsPrimaryKey ==true) continue; + string type = p.SystemType.ToNullableType(p.IsNullable == true); + if(type =="int" || type=="decimal") + Response.WriteLine(" this."+p.PropertyName.ToSafeName()+"= 0;"); + else if(type =="string") + Response.WriteLine(" this."+p.PropertyName.ToSafeName()+"= string.Empty;"); + else if(type.ToLower().Contains("datetime")) + Response.WriteLine(" this."+p.PropertyName.ToSafeName()+"= DateTime.Now;"); + } // foreach %> +<% foreach(var r in Entity.Relationships.Where(e => e.ThisCardinality == Cardinality.Many)) { %> + <%= r.ThisPropertyName.ToSafeName() %> = new List<<%= r.OtherEntity.ToSafeName() %>>(); +<% } // foreach %> + } + +<% foreach(var p in Entity.Properties) { + if(p.IsPrimaryKey ==true) continue; + %> + /// + /// <%=p.Description %> + /// + public <%= p.SystemType.ToNullableType(p.IsNullable == true) %> <%= p.PropertyName.ToSafeName() %> { get; set; } +<% } // foreach %> + +<% foreach(var r in Entity.Relationships) { %> +<% if(r.ThisCardinality == Cardinality.Many) { %> + public virtual ICollection<<%= r.OtherEntity.ToSafeName() %>> <%= r.ThisPropertyName.ToSafeName() %> { get; set; } +<% } else { %> + public virtual <%= r.OtherEntity.ToSafeName() %> <%= r.ThisPropertyName.ToSafeName() %> { get; set; } +<% } %> +<% } // foreach %> + } } \ No newline at end of file diff --git a/CodeSmith/EF/CSharp/Internal/Extensions.cs b/CodeSmith/CSharp/Internal/Extensions.cs similarity index 100% rename from CodeSmith/EF/CSharp/Internal/Extensions.cs rename to CodeSmith/CSharp/Internal/Extensions.cs diff --git a/CodeSmith/EF/CSharp/Internal/Generator.cs b/CodeSmith/CSharp/Internal/Generator.cs similarity index 100% rename from CodeSmith/EF/CSharp/Internal/Generator.cs rename to CodeSmith/CSharp/Internal/Generator.cs diff --git a/CodeSmith/EF/CSharp/Internal/Mapping.Generated.cst b/CodeSmith/CSharp/Internal/Mapping.Generated.cst similarity index 100% rename from CodeSmith/EF/CSharp/Internal/Mapping.Generated.cst rename to CodeSmith/CSharp/Internal/Mapping.Generated.cst diff --git a/CodeSmith/EF/CSharp/Internal/Model.cs b/CodeSmith/CSharp/Internal/Model.cs similarity index 100% rename from CodeSmith/EF/CSharp/Internal/Model.cs rename to CodeSmith/CSharp/Internal/Model.cs diff --git a/CodeSmith/EF/CSharp/Internal/Parser.cs b/CodeSmith/CSharp/Internal/Parser.cs similarity index 100% rename from CodeSmith/EF/CSharp/Internal/Parser.cs rename to CodeSmith/CSharp/Internal/Parser.cs diff --git a/CodeSmith/Application.cst b/CodeSmith/CSharp/Web/Application.cst similarity index 100% rename from CodeSmith/Application.cst rename to CodeSmith/CSharp/Web/Application.cst diff --git a/CodeSmith/Controller.cst b/CodeSmith/CSharp/Web/Controller.cst similarity index 100% rename from CodeSmith/Controller.cst rename to CodeSmith/CSharp/Web/Controller.cst diff --git a/CodeSmith/Index.cshtml.cst b/CodeSmith/CSharp/Web/Index.cshtml.1.cst similarity index 98% rename from CodeSmith/Index.cshtml.cst rename to CodeSmith/CSharp/Web/Index.cshtml.1.cst index a5b3c345..d2a7c4c2 100644 --- a/CodeSmith/Index.cshtml.cst +++ b/CodeSmith/CSharp/Web/Index.cshtml.1.cst @@ -100,4 +100,6 @@ Description="连接的数据库" %> - \ No newline at end of file + + + diff --git a/CodeSmith/EF/CSharp/Web/Index.cshtml.cst b/CodeSmith/CSharp/Web/Index.cshtml.cst similarity index 100% rename from CodeSmith/EF/CSharp/Web/Index.cshtml.cst rename to CodeSmith/CSharp/Web/Index.cshtml.cst diff --git a/CodeSmith/EF/CSharp/Web/Util.cs b/CodeSmith/CSharp/Web/Util.cs similarity index 100% rename from CodeSmith/EF/CSharp/Web/Util.cs rename to CodeSmith/CSharp/Web/Util.cs diff --git a/CodeSmith/EF/CSharp/WebGenerate.cst b/CodeSmith/CSharp/WebGenerate.cst similarity index 100% rename from CodeSmith/EF/CSharp/WebGenerate.cst rename to CodeSmith/CSharp/WebGenerate.cst diff --git a/CodeSmith/EF/Common/ICSharpCode.NRefactory.CSharp.dll b/CodeSmith/Common/ICSharpCode.NRefactory.CSharp.dll similarity index 100% rename from CodeSmith/EF/Common/ICSharpCode.NRefactory.CSharp.dll rename to CodeSmith/Common/ICSharpCode.NRefactory.CSharp.dll diff --git a/CodeSmith/EF/Common/ICSharpCode.NRefactory.dll b/CodeSmith/Common/ICSharpCode.NRefactory.dll similarity index 100% rename from CodeSmith/EF/Common/ICSharpCode.NRefactory.dll rename to CodeSmith/Common/ICSharpCode.NRefactory.dll diff --git a/CodeSmith/EF/Common/Mono.Cecil.dll b/CodeSmith/Common/Mono.Cecil.dll similarity index 100% rename from CodeSmith/EF/Common/Mono.Cecil.dll rename to CodeSmith/Common/Mono.Cecil.dll diff --git a/CodeSmith/EF/CSharp/Web/Application.cst b/CodeSmith/EF/CSharp/Web/Application.cst deleted file mode 100644 index 8425cd7b..00000000 --- a/CodeSmith/EF/CSharp/Web/Application.cst +++ /dev/null @@ -1,138 +0,0 @@ -<%-- -Name: Database Table Properties -Author: yubaolee -Description: Create a list of properties from a database table ---%> -<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="False" Description="应用层" %> -<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %> -<%@ Property Name="NeedViewModel" Type="Boolean" Category="Context" Default="False" Description="是否需要ViewModel" %> -<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %> -<%@ Assembly Name="SchemaExplorer" %> -<%@ Import Namespace="SchemaExplorer" %> - - -<%if(NeedViewModel){ %> -using OpenAuth.App.ViewModel; -<%} %> -using OpenAuth.Domain; -using OpenAuth.Domain.Interface; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace OpenAuth.App -{ - public class <%=ModuleName%>ManagerApp - { - private I<%=ModuleName%>Repository _repository; - private IOrgRepository _orgRepository; - - public <%=ModuleName%>ManagerApp(I<%=ModuleName%>Repository repository, - IOrgRepository orgRepository) - { - _repository = repository; - _orgRepository = orgRepository; - } - - public int Get<%=GetModelName()%>CntInOrg(int orgId) - { - if (orgId == 0) - { - return _repository.Find(null).Count(); - } - else - { - return _repository.Get<%=GetModelName()%>CntInOrgs(GetSubOrgIds(orgId)); - } - } - - public List<<%=GetModelName()%>> LoadAll() - { - return _repository.Find(null).ToList(); - } - - /// - /// 加载一个节点下面的一个或全部<%=GetModelName()%>s - /// - public dynamic Load(int orgId, int pageindex, int pagesize) - { - IEnumerable<<%=ModuleName%>> <%=ModuleName%>s; - int total = 0; - if (orgId == 0) - { - <%=ModuleName%>s = _repository.Load<%=ModuleName%>s(pageindex, pagesize); - total = _repository.GetCount(); - } - else - { - <%=ModuleName%>s = _repository.LoadInOrgs(pageindex, pagesize,GetSubOrgIds(orgId)); - total = _repository.Get<%=ModuleName%>CntInOrgs(orgId); - } - <%if(NeedViewModel){ %> - var <%=ModuleName%>views = new List<<%=ModuleName%>View>(); - foreach (var <%=ModuleName%> in <%=ModuleName%>s) - { - <%=ModuleName%>View uv = <%=ModuleName%>; - uv.Organizations = string.Join(",", _orgRepository.LoadBy<%=ModuleName%>(<%=ModuleName%>.Id).Select(u => u.Name).ToList()); - <%=ModuleName%>views.Add(uv); - } - <%} %> - - return new - { - total = total, - list = <%=GetModelName()%>s, - pageCurrent = pageindex - }; - } - - /// - /// 获取当前节点的所有下级节点 - /// - private int[] GetSubOrgIds(int orgId) - { - var org = _orgRepository.FindSingle(u => u.Id == orgId); - var orgs = _orgRepository.Find(u => u.CascadeId.Contains(org.CascadeId)).Select(u => u.Id).ToArray(); - return orgs; - } - - public <%=GetModelName()%> Find(int id) - { - var <%=ModuleName.ToLower()%> = _repository.FindSingle(u => u.Id == id); - if (<%=ModuleName.ToLower()%> == null) return new <%=GetModelName()%>(); - - return <%=ModuleName.ToLower() %>; - } - - public void Delete(int id) - { - _repository.Delete(id); - } - - public void AddOrUpdate(<%=GetModelName()%> model) - { - <%=ModuleName%> <%=ModuleName.ToLower()%> = new <%=ModuleName%>(); - model.CopyTo(<%=ModuleName.ToLower()%>); - - if (<%=ModuleName.ToLower()%>.Id == 0) - { - _repository.Add(<%=ModuleName.ToLower()%>); - } - else - { - _repository.Update(<%=ModuleName.ToLower()%>); - } - - } - - - } -} \ No newline at end of file diff --git a/CodeSmith/EF/CSharp/Web/Controller.cst b/CodeSmith/EF/CSharp/Web/Controller.cst deleted file mode 100644 index c4352691..00000000 --- a/CodeSmith/EF/CSharp/Web/Controller.cst +++ /dev/null @@ -1,110 +0,0 @@ -<%-- -Name: Database Table Properties -Author: yubaolee -Description: Create a list of properties from a database table ---%> -<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="False" Description="控制器" %> -<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %> -<%@ Property Name="NeedViewModel" Type="Boolean" Category="Context" Default="False" Description="是否需要ViewModel" %> -<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %> -<%@ Assembly Name="SchemaExplorer" %> -<%@ Import Namespace="SchemaExplorer" %> - - -using System; -using System.Web.Mvc; -using Infrastructure; -using OpenAuth.App; -<%if(NeedViewModel){ %> -using OpenAuth.App.ViewModel; -<%} %> -using OpenAuth.Domain; - -namespace OpenAuth.Mvc.Controllers -{ - public class <%=ModuleName%>ManagerController : BaseController - { - private <%=ModuleName%>ManagerApp _app; - - public <%=ModuleName%>ManagerController() - { - _app = AutofacExt.GetFromFac<<%=ModuleName%>ManagerApp>(); - } - - // - // GET: /UserManager/ - public ActionResult Index() - { - return View(); - } - - public ActionResult Add(int id = 0) - { - return View(_app.Find(id)); - } - - //添加或修改<%=ModuleName %> - [HttpPost] - public string Add(<%=GetModelName()%> model) - { - try - { - _app.AddOrUpdate(model); - - } - catch (Exception ex) - { - BjuiResponse.statusCode = "300"; - BjuiResponse.message = ex.Message; - } - return JsonHelper.Instance.Serialize(BjuiResponse); - } - - /// - /// 加载节点下面的所有<%=ModuleName %>s - /// - public string Load(int parentId, int pageCurrent = 1, int pageSize = 30) - { - return JsonHelper.Instance.Serialize(_app.Load(parentId, pageCurrent, pageSize)); - } - - public string LoadForTree() - { - var models = _app.LoadAll(); - //添加根节点 - models.Add(new <%=ModuleName %> - { - Id = 0, - ParentId = -1, - Name = "根结点", - CascadeId = "0" - }); - return JsonHelper.Instance.Serialize(models); - } - - public string Delete(int Id) - { - try - { - _app.Delete(Id); - } - catch (Exception e) - { - BjuiResponse.statusCode = "300"; - BjuiResponse.message = e.Message; - } - - return JsonHelper.Instance.Serialize(BjuiResponse); - } - - - } -} \ No newline at end of file diff --git a/CodeSmith/IRepository.cst b/CodeSmith/IRepository.cst deleted file mode 100644 index e8f31b2d..00000000 --- a/CodeSmith/IRepository.cst +++ /dev/null @@ -1,28 +0,0 @@ -<%-- -Name: Database Table Properties -Author: yubaolee -Description: Create a list of properties from a database table ---%> -<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="False" Description="创建包含组织机构的接口" %> -<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %> -<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %> -<%@ Assembly Name="SchemaExplorer" %> -<%@ Import Namespace="SchemaExplorer" %> - -using System.Collections.Generic; -using System.Linq; - -namespace OpenAuth.Domain.Interface -{ - public interface I<%=ModuleName%>Repository :IRepository<<%=ModuleName%>> - { - IEnumerable<<%=ModuleName%>> Load<%=ModuleName%>s(int pageindex, int pagesize); - - IEnumerable<<%=ModuleName%>> LoadInOrgs(params int[] orgId); - int Get<%=ModuleName%>CntInOrgs(params int[] orgIds); - IEnumerable<<%=ModuleName%>> LoadInOrgs(int pageindex, int pagesize, params int[] orgIds); - - void Delete(int id); - - } -} \ No newline at end of file diff --git a/CodeSmith/NoCascadeIndex.cshtml.cst b/CodeSmith/NoCascadeIndex.cshtml.cst deleted file mode 100644 index 96627b47..00000000 --- a/CodeSmith/NoCascadeIndex.cshtml.cst +++ /dev/null @@ -1,112 +0,0 @@ -<%-- -Name: Database Table Properties -Author: yubaolee -Description: 没有树状导航的datagrid ---%> -<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="True" Description="Create a list of properties from database table." %> -<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="Table that the object is based on." %> -<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %> -<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %> -<%@ Assembly Name="SchemaExplorer" %> -<%@ Import Namespace="SchemaExplorer" %> - -@{ - string _prefix = "<%=ModuleName%>"; - var _treeId = _prefix + "Tree"; - var _gridId = _prefix + "Grid"; - var _treeDetail = _prefix + "Detail"; -} - -@{ Html.RenderAction("MenuHeader", "Home");} -
-
-
-
-
- - diff --git a/CodeSmith/Repository.cst b/CodeSmith/Repository.cst deleted file mode 100644 index aeb7ccb9..00000000 --- a/CodeSmith/Repository.cst +++ /dev/null @@ -1,49 +0,0 @@ -<%-- -Name: 数据访问 -Author: yubaolee -Description: ---%> -<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="False" Description="数据访问" %> -<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %> -<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %> -<%@ Assembly Name="SchemaExplorer" %> -<%@ Import Namespace="SchemaExplorer" %> -using System.Collections.Generic; -using System.Linq; -using OpenAuth.Domain; -using OpenAuth.Domain.Interface; - -namespace OpenAuth.Repository -{ - public class <%=ModuleName%>Repository :BaseRepository<<%=ModuleName%>>, I<%=ModuleName%>Repository - { - - public IEnumerable<<%=ModuleName%>> Load<%=ModuleName%>s(int pageindex, int pagesize) - { - return Context.<%=ModuleName%>s.OrderBy(u => u.Id).Skip((pageindex - 1) * pagesize).Take(pagesize); - } - - public IEnumerable<<%=ModuleName%>> LoadInOrgs(params int[] orgId) - { - var result = from <%=ModuleName.ToLower()%> in Context.<%=ModuleName%>s where orgId.Contains(<%=ModuleName.ToLower()%>.Id) - select <%=ModuleName.ToLower()%>; - return result; - - } - - public int Get<%=ModuleName%>CntInOrgs(params int[] orgIds) - { - return LoadInOrgs(orgIds).Count(); - } - - public IEnumerable<<%=ModuleName%>> LoadInOrgs(int pageindex, int pagesize, params int[] orgIds) - { - return LoadInOrgs(orgIds).OrderBy(u =>u.Id).Skip((pageindex -1)*pagesize).Take(pagesize); - } - - public void Delete(int id) - { - Delete(u =>u.Id == id); - } - } -} diff --git a/CodeSmith/Util.cs b/CodeSmith/Util.cs deleted file mode 100644 index 0ebb0882..00000000 --- a/CodeSmith/Util.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Text; -using CodeSmith.Engine; -using SchemaExplorer; - -namespace Util{ - public class Tools{ - public static String GetDescription(ColumnSchema column) { //得到字段的描述 - if(string.IsNullOrEmpty(column.Description)) - return column.Name; - else - return column.Description; - } - - public static bool NeedCascade(TableSchema SourceTable){ //判断表中是否需要下拉选择树 - return SourceTable.Columns.Contains("ParentId") - || SourceTable.Columns.Contains("CascadeId") ; - } - } -} \ No newline at end of file diff --git a/CodeSmith/editDlg.js.cst b/CodeSmith/editDlg.js.cst deleted file mode 100644 index 03a58515..00000000 --- a/CodeSmith/editDlg.js.cst +++ /dev/null @@ -1,251 +0,0 @@ -<%-- -Name: 编辑修改JS -Author: yubaolee -Description: 编辑修改JS ---%> -<%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Encoding="utf-8" Description="添加模块" %> -<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" -Description="连接的数据库" %> -<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %> -<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %> -<%@ Assembly Name="SchemaExplorer" %> -<%@ Import Namespace="SchemaExplorer" %> -<%@ Assembly Src="Util.cs" %> -<%@ Import Namespace="Util" %> - - -//grid列表模块 -function MainGrid() { - var url = '/<%=ModuleName%>/Load?parentId='; - var selectedId = 0; //ztree选中的模块 - this.maingrid = $('#maingrid').datagrid({ - showToolbar: false, - filterThead: false, - target: $(this), - columns: [ - <% foreach (ColumnSchema column in this.SourceTable.Columns) { %> - { - name: '<%=column.Name%>', - label: '<%=Tools.GetDescription(column)%>', - width: 100 - <%if(column.IsPrimaryKeyMember){ %> - , hide: true - <%} %> - <%else if(CSharpAlias[column.SystemType.FullName] == "bool") {%> - ,align: 'center', - items: [{ 'false': '否' }, { 'true': '是' }], - <%} %> - <%else if(CSharpAlias[column.SystemType.FullName] == "int") {%> - , align: 'center', - items: [{ '0': '默认' }, { '1': '状态1' }], - <%} %> - }, - <% } %> - ], - dataUrl: url + selectedId, - fullGrid: true, - showLinenumber: true, - showCheckboxcol: true, - paging: true, - filterMult: false, - showTfoot: false, - height: '100%' - }); - this.reload = function (id) { - if (id != undefined) selectedId = id; - this.maingrid.datagrid('reload', { dataUrl: url+ selectedId }); - }; -}; -MainGrid.prototype = new Grid(); -var list = new MainGrid(); - -//左边分类导航树 -var ztree = function () { - var url = '/<%=ModuleName%>/LoadForTree'; - var setting = { - view: { selectedMulti: false }, - data: { - key: { - name: 'Name', - title: 'Name' - }, - simpleData: { - enable: true, - idKey: 'Id', - pIdKey: 'ParentId', - rootPId: 'null' - } - }, - callback: { onClick: zTreeOnClick } - }; - $.getJSON(url, function (json) { - $.fn.zTree.init($("#tree"), setting, json).expandAll(true); - }); - function zTreeOnClick(event, treeId, treeNode) { - list.reload(treeNode.Id); - } - - return { - reload:function() { - $.getJSON(url, function (json) { - $.fn.zTree.init($("#tree"), setting, json).expandAll(true); - }); - } - } -}(); - -<%if(Tools.NeedCascade(SourceTable)){ %> -//编辑时,选择上级弹出的树 -var parentTree = function () { - var nameDom = "#ParentName"; - var idDom = "#ParentId"; - var zTreeObj; - var setting = { - view: { - selectedMulti: false - }, - check: { - enable: true, - chkStyle: "radio", //单选 - radioType: "all" - }, - data: { - key: { - name: 'Name', - title: 'Name' - }, - simpleData: { - enable: true, - idKey: 'Id', - pIdKey: 'ParentId', - rootPId: 'null' - } - }, - callback: { - onClick: zTreeOnClick, - onCheck: zTreeCheck - } - }; - - function zTreeCheck(event, treeId, treeNode) { - var nodes = zTreeObj.getCheckedNodes(true); - var ids = nodes.map(function (e) { return e.Id; }).join(","); - var names = nodes.map(function (e) { return e.Name; }).join(","); - - $(nameDom).val(names); - $(idDom).val(ids); - } - function zTreeOnClick(event, treeId, treeNode) { - zTreeObj.checkNode(treeNode, !treeNode.checked, true, true); - event.preventDefault(); - } - - return { - show:function() { - $.getJSON('/<%=ModuleName%>/LoadForTree', function (json) { - zTreeObj = $.fn.zTree.init($('#j_select_tree1'), setting, json); - var orgstr = $(idDom).val(); - var name = ''; - if (orgstr != '') { - var nodeIds = orgstr.split(','); - $.each(nodeIds, function () { - var node = zTreeObj.getNodeByParam("Id", this, null); - name += ',' + node.Name; - zTreeObj.checkNode(node, true, true); - }); - $(nameDom).val(name.substr(1)); //显示名称 - } - zTreeObj.expandAll(true); - }); - } - }; -}(); -<%} %> - -//添加(编辑)对话框 -var editDlg = function () { - var update = false; - var show = function () { - BJUI.dialog({ id: 'editDlg', title: '编辑对话框', target: '#editDlg' }); - $("#btnSave").on("click", function() { - editDlg.save(); - }); - } - return { - add: function () { //弹出添加 - update = false; - show(); - $.CurrentDialog.find("form")[0].reset(); //reset方法只能通过dom调用 - $("#Id").val(0); - - <%if(Tools.NeedCascade(SourceTable)){ - Response.WriteLine("parentTree.show();"); - }%> - }, - update: function (ret) { //弹出编辑框 - update = true; - show(); - <% foreach (ColumnSchema column in this.SourceTable.Columns) { %> - <%if(column.IsPrimaryKeyMember){%> - $('#<%=column.Name%>').val(ret.<%=column.Name%>); - <%}else if(CSharpAlias[column.SystemType.FullName] == "bool") {%> - $('#<%=column.Name%>').selectpicker('val', ret.<%=column.Name%>?"true":"false"); - <%}else if(CSharpAlias[column.SystemType.FullName] == "int") {%> - $('#<%=column.Name%>').selectpicker('val', ret.<%=column.Name%>); - <%} else{ %> - $('#<%=column.Name%>').val(ret.<%=column.Name%>); - <%} %> - <% } %> - <%if(Tools.NeedCascade(SourceTable)){ - Response.WriteLine("parentTree.show();"); - }%> - }, - save: function() { //编辑-->保存 - $('#editForm').isValid(function (v) { - if (!v) return; //验证没通过 - $("#editForm").bjuiajax('ajaxForm', { - reload: false, - callback:function(json) { - list.reload(); - ztree.reload(); - } - }); - }); - } - }; -}(); - -//删除 -function del() { - var selected = list.getSelectedObj(); - if (selected == null) return; - - $.getJSON('/<%=ModuleName%>/Delete?Id=' + selected.Id, function (data) { - if (data.statusCode == "200") { - list.reload(); - ztree.reload(); - } - else { - $(this).alertmsg('warn', data.message); - } - }); -} - -//自定义的编辑按钮 -function edit() { - var selected = list.getSelectedObj(); - if (selected == null) { - return; - } - editDlg.update(selected); -} - -function add() { - editDlg.add(); -} - -function refresh() { - list.reload(); -} - -//@@ sourceURL=<%=ModuleName%>.js \ No newline at end of file From 65cc53456efcb8b06c3c8d18ad10d8fa08c7162d Mon Sep 17 00:00:00 2001 From: "yubaolee@163.com" Date: Mon, 27 Nov 2017 17:40:25 +0800 Subject: [PATCH 4/6] ru --- CodeSmith/CSharp/Web/Index.cshtml.1.cst | 105 ------------------------ CodeSmith/CSharp/Web/Index.cshtml.cst | 2 +- CodeSmith/CSharp/WebGenerate.cst | 33 ++++++-- 3 files changed, 27 insertions(+), 113 deletions(-) delete mode 100644 CodeSmith/CSharp/Web/Index.cshtml.1.cst diff --git a/CodeSmith/CSharp/Web/Index.cshtml.1.cst b/CodeSmith/CSharp/Web/Index.cshtml.1.cst deleted file mode 100644 index d2a7c4c2..00000000 --- a/CodeSmith/CSharp/Web/Index.cshtml.1.cst +++ /dev/null @@ -1,105 +0,0 @@ -<%-- -Name: 列表页面 -Author: yubaolee -Description: 列表页面 ---%> -<%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Encoding="utf-8" Description="添加模块" %> -<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" -Description="连接的数据库" %> -<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %> -<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %> -<%@ Assembly Name="SchemaExplorer" %> -<%@ Import Namespace="SchemaExplorer" %> -<%@ Assembly Src="Util.cs" %> -<%@ Import Namespace="Util" %> -@{ - Layout = "~/Views/Shared/_BjuiLayout.cshtml"; -} - -@{ Html.RenderAction("MenuHeader", "Home");} -
-
-
-
    -
    - -
    -
    -
    -
    -
    - - - - - - - - diff --git a/CodeSmith/CSharp/Web/Index.cshtml.cst b/CodeSmith/CSharp/Web/Index.cshtml.cst index 99e232d5..628af601 100644 --- a/CodeSmith/CSharp/Web/Index.cshtml.cst +++ b/CodeSmith/CSharp/Web/Index.cshtml.cst @@ -100,6 +100,6 @@ Description="连接的数据库" %>
    - + diff --git a/CodeSmith/CSharp/WebGenerate.cst b/CodeSmith/CSharp/WebGenerate.cst index d8b00750..f294d04a 100644 --- a/CodeSmith/CSharp/WebGenerate.cst +++ b/CodeSmith/CSharp/WebGenerate.cst @@ -34,7 +34,6 @@ Description="连接的数据库" %> <%@ Property Name="NeedViewModel" Type="Boolean" - Category="5.Customization" Default="False" Optional="True" Description="是否需要ViewModel" %> @@ -46,6 +45,9 @@ Description="连接的数据库" %> <%@ Register Name="HtmlGenerateClass" Template="Web\Index.cshtml.cst" MergeProperties="False" %> +<%@ Register Name="JSGenerateClass" + Template="Web\index.js.cst" + MergeProperties="False" %> Generating Entities ... <% Generate(); %> @@ -58,14 +60,18 @@ Generating Entities ... if (!Directory.Exists(directory)) //根目录 Directory.CreateDirectory(directory); - if (!Directory.Exists(directory +"/views")) //视图根文件夹 + if (!Directory.Exists(directory +"/views")) //视图根文件夹 Directory.CreateDirectory(directory +"/views"); + + if (!Directory.Exists(directory +"/js")) //js根目录 + Directory.CreateDirectory(directory +"/js"); - if (!Directory.Exists(directory +"/views/"+ModuleName)) //视图文件夹 - Directory.CreateDirectory(directory +"/views/"+ModuleName); + if (!Directory.Exists(directory +"/views/"+ModuleName +"Manager")) //视图文件夹 + Directory.CreateDirectory(directory +"/views/"+ModuleName +"Manager"); CreateApplicationClass(); CreateHtmlClass(); + CreateJSClass(); this.RegisterReference("System.Configuration"); this.RegisterReference("System.Data"); @@ -77,7 +83,7 @@ Generating Entities ... Response.WriteLine("Generate Time: " + watch.ElapsedMilliseconds + " ms"); } - //创建APP层 + //创建APP层,如UserApp.cs public void CreateApplicationClass() { ApplicationGenerateClass generatedClass = this.Create(); @@ -95,13 +101,13 @@ Generating Entities ... generatedClass.RenderToFile(generatedFile, generatedFile, true); } - //创建视图 + //创建视图,如views/Users/index.html public void CreateHtmlClass() { HtmlGenerateClass generatedClass = this.Create(); this.CopyPropertiesTo(generatedClass); - generatedFile = Path.GetFullPath(directory) + "/views/"+ModuleName+"/" + "index.cshtml"; + string generatedFile = Path.GetFullPath(directory) + "/views/"+ModuleName+"Manager/" + "index.cshtml"; generatedClass.ModuleName = ModuleName; generatedClass.SourceTable = SourceTable; @@ -110,6 +116,19 @@ Generating Entities ... generatedClass.RenderToFile(generatedFile, generatedFile, true); } + //创建视图,如js/userManager.js + public void CreateJSClass() + { + JSGenerateClass generatedClass = this.Create(); + this.CopyPropertiesTo(generatedClass); + string generatedFile = Path.GetFullPath(directory) + "/js/"+ModuleName+"Manager.js"; + + generatedClass.ModuleName = ModuleName; + generatedClass.SourceTable = SourceTable; + + Response.WriteLine(generatedFile); + generatedClass.RenderToFile(generatedFile, generatedFile, true); + } \ No newline at end of file From 5346f5eb4d6dbb5bc135253d80740ac33cc6de24 Mon Sep 17 00:00:00 2001 From: "yubaolee@163.com" Date: Tue, 28 Nov 2017 13:47:24 +0800 Subject: [PATCH 5/6] ru --- CodeSmith/CSharp/Web/index.js.cst | 166 ++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 CodeSmith/CSharp/Web/index.js.cst diff --git a/CodeSmith/CSharp/Web/index.js.cst b/CodeSmith/CSharp/Web/index.js.cst new file mode 100644 index 00000000..72e8807a --- /dev/null +++ b/CodeSmith/CSharp/Web/index.js.cst @@ -0,0 +1,166 @@ +<%-- +Name: 主JS界面 +Author: yubaolee +--%> +<%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Encoding="utf-8" Description="添加模块" %> +<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %> + +<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %> +<%@ Assembly Name="SchemaExplorer" %> +<%@ Import Namespace="SchemaExplorer" %> +<%@ Assembly Src="Util.cs" %> +<%@ Import Namespace="Util" %> + +layui.config({ + base: "/js/" +}).use(['form','vue', 'ztree', 'layer', 'jquery', 'table','droptree','openauth'], function () { + var form = layui.form, + //layer = (parent == undefined || parent.layer === undefined )? layui.layer : parent.layer, + layer = layui.layer, + $ = layui.jquery; + var table = layui.table; + var openauth = layui.openauth; + layui.droptree("/UserSession/GetOrgs", "#Organizations", "#OrganizationIds"); + + //主列表加载,可反复调用进行刷新 + var config= {}; //table的参数,如搜索key,点击tree的id + var mainList = function (options) { + if (options != undefined) { + $.extend(config, options); + } + table.reload('mainList', { + url: '/<%=ModuleName%>Manager/Load', + where: config + }); + } + //左边树状机构列表 + var ztree = function () { + var url = '/UserSession/GetOrgs'; + var zTreeObj; + var setting = { + view: { selectedMulti: false }, + data: { + key: { + name: 'Name', + title: 'Name' + }, + simpleData: { + enable: true, + idKey: 'Id', + pIdKey: 'ParentId', + rootPId: 'null' + } + }, + callback: { + onClick: function (event, treeId, treeNode) { + mainList({ orgId: treeNode.Id }); + } + } + }; + var load = function () { + $.getJSON(url, function (json) { + zTreeObj = $.fn.zTree.init($("#tree"), setting, json); + mainList({ orgId: json[0].Id }); + zTreeObj.expandAll(true); + }); + }; + load(); + return { + reload: load + } + }(); + + //添加(编辑)对话框 + var editDlg = function() { + var vm = new Vue({ + el: "#formEdit" + }); + var update = false; //是否为更新 + var show = function (data) { + var title = update ? "编辑信息" : "添加"; + layer.open({ + title: title, + area: ["500px", "400px"], + type: 1, + content: $('#divEdit'), + success: function() { + vm.$set('$data', data); + }, + end: mainList + }); + var url = "/<%=ModuleName%>Manager/Add"; + if (update) { + url = "/<%=ModuleName%>Manager/Update"; //暂时和添加一个地址 + } + //提交数据 + form.on('submit(formSubmit)', + function(data) { + $.post(url, + data.field, + function(data) { + layer.msg(data.Message); + }, + "json"); + return false; + }); + } + return { + add: function() { //弹出添加 + update = false; + show({ + Id: '' + }); + }, + update: function(data) { //弹出编辑框 + update = true; + show(data); + } + }; + }(); + + //监听表格内部按钮 + table.on('tool(list)', function (obj) { + var data = obj.data; + if (obj.event === 'detail') { //查看 + layer.msg('ID:' + data.Id + ' 的查看操作'); + } + }); + + + //监听页面主按钮操作 + var active = { + btnDel: function () { //批量删除 + var checkStatus = table.checkStatus('mainList') + , data = checkStatus.data; + openauth.del("/<%=ModuleName%>Manager/Delete", + data.map(function (e) { return e.Id; }), + mainList); + } + , btnAdd: function () { //添加 + editDlg.add(); + } + , btnEdit: function () { //编辑 + var checkStatus = table.checkStatus('mainList') + , data = checkStatus.data; + if (data.length != 1) { + layer.msg("请选择编辑的行,且同时只能编辑一行"); + return; + } + editDlg.update(data[0]); + } + + , search: function () { //搜索 + mainList({ key: $('#key').val() }); + } + , btnRefresh: function() { + mainList(); + } + }; + + $('.toolList .layui-btn').on('click', function () { + var type = $(this).data('type'); + active[type] ? active[type].call(this) : ''; + }); + + //监听页面主按钮操作 end +}) \ No newline at end of file From 742df41a61bd6a9dc1676a68a3fa311a2948eaaa Mon Sep 17 00:00:00 2001 From: "yubaolee@163.com" Date: Tue, 28 Nov 2017 13:47:40 +0800 Subject: [PATCH 6/6] ru --- CodeSmith/CSharp/Web/Index.cshtml.cst | 2 +- CodeSmith/CSharp/WebGenerate.cst | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CodeSmith/CSharp/Web/Index.cshtml.cst b/CodeSmith/CSharp/Web/Index.cshtml.cst index 628af601..4705c8e6 100644 --- a/CodeSmith/CSharp/Web/Index.cshtml.cst +++ b/CodeSmith/CSharp/Web/Index.cshtml.cst @@ -28,7 +28,7 @@ Description="连接的数据库" %> @Html.Action("MenuHeader", "Home") @* - + *@ diff --git a/CodeSmith/CSharp/WebGenerate.cst b/CodeSmith/CSharp/WebGenerate.cst index f294d04a..f02fbc9a 100644 --- a/CodeSmith/CSharp/WebGenerate.cst +++ b/CodeSmith/CSharp/WebGenerate.cst @@ -20,8 +20,12 @@ <%@ Import Namespace="SchemaMapper" %> -<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" -Description="连接的数据库" %> +<%@ Property Name="SourceTable" +Type="SchemaExplorer.TableSchema" +Category="Context" +Description="连接的数据库" +OnChanged="OnSourceDatabaseChanged"%> + <%@ Property Name="ModuleName" Type="System.String" Description="模块名称,如:User"%> @@ -83,7 +87,7 @@ Generating Entities ... Response.WriteLine("Generate Time: " + watch.ElapsedMilliseconds + " ms"); } - //创建APP层,如UserApp.cs + //创建APP层,如UserManagerApp.cs public void CreateApplicationClass() { ApplicationGenerateClass generatedClass = this.Create(); @@ -125,10 +129,18 @@ Generating Entities ... string generatedFile = Path.GetFullPath(directory) + "/js/"+ModuleName+"Manager.js"; generatedClass.ModuleName = ModuleName; - generatedClass.SourceTable = SourceTable; Response.WriteLine(generatedFile); generatedClass.RenderToFile(generatedFile, generatedFile, true); } + + //更换数据源时,改变ModuleName + private void OnSourceDatabaseChanged(object sender, EventArgs e) + { + if (SourceTable == null) + return; + ModuleName = SourceTable.Name; + } + \ No newline at end of file