mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-11-07 18:04:45 +08:00
Merge remote-tracking branch 'remotes/origin/codegenerator-dev' into 4.0
This commit is contained in:
@@ -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<TEntity> IDbContext.Set<TEntity>()
|
||||
105
CodeSmith/CSharp/Web/Index.cshtml.cst
Normal file
105
CodeSmith/CSharp/Web/Index.cshtml.cst
Normal file
@@ -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
|
||||
{
|
||||
<link rel="stylesheet" href="/css/treetable.css" />
|
||||
}
|
||||
<blockquote class="layui-elem-quote news_search toolList">
|
||||
<div class="layui-inline">
|
||||
<div class="layui-input-inline">
|
||||
<input class="layui-input" placeholder="请输入关键字"
|
||||
name="key" id="key" autocomplete="off">
|
||||
</div>
|
||||
<button class="layui-btn" data-type="search">搜索</button>
|
||||
</div>
|
||||
@Html.Action("MenuHeader", "Home")
|
||||
@*<button class="layui-btn " data-type="refresh">刷新</button>
|
||||
<button class="layui-btn " data-type="addData">添加</button>
|
||||
<button class="layui-btn layui-btn-danger" data-type="del">批量删除</button>*@
|
||||
</blockquote>
|
||||
|
||||
<div style="display: flex;">
|
||||
<ul id="tree" class="ztree" style="display: inline-block; width: 180px; padding: 10px; border: 1px solid #ddd; overflow: auto;"></ul>
|
||||
<table class="layui-table"
|
||||
lay-data="{height: 'full-80', page:true, id:'mainList'}"
|
||||
lay-filter="list">
|
||||
<thead>
|
||||
<tr>
|
||||
<th lay-data="{checkbox:true, fixed: true}"></th>
|
||||
<% foreach (ColumnSchema column in this.SourceTable.Columns) {%>
|
||||
<th lay-data="{field:'<%=column.Name%>', width:150}"><%=Tools.GetDescription(column)%></th>
|
||||
<% }%>
|
||||
<th lay-data="{fixed: 'right', width:160, align:'center', toolbar: '#barList'}"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
<script type="text/html" id="barList">
|
||||
<a class="layui-btn layui-btn-primary layui-btn-mini" lay-event="detail">查看</a>
|
||||
</script>
|
||||
|
||||
<!--用户添加/编辑窗口-->
|
||||
<div id="divEdit" style="display: none">
|
||||
<form class="layui-form" action="" id="formEdit">
|
||||
<% foreach (ColumnSchema column in this.SourceTable.Columns) {
|
||||
if(column.IsPrimaryKeyMember){%>
|
||||
<input type="hidden" name="<%=column.Name%>" v-model="<%=column.Name%>" />
|
||||
<%}else if(CSharpAlias[column.SystemType.FullName] == "bool") {%>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><%=Tools.GetDescription(column)%></label>
|
||||
<div class="layui-input-block">
|
||||
<input type="checkbox" name="<%=column.Name%>" v-model="<%=column.Name%>" lay-skin="switch" value="1">
|
||||
</div>
|
||||
</div>
|
||||
<%}else if(CSharpAlias[column.SystemType.FullName] == "int" ) {%>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><%=Tools.GetDescription(column)%></label>
|
||||
<div class="layui-input-block">
|
||||
<input type="radio" name="<%=column.Name%>" value="1" title="value1" checked>
|
||||
<input type="radio" name="<%=column.Name%>" value="0" title="value2">
|
||||
</div>
|
||||
</div>
|
||||
<%} else {%>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><%=Tools.GetDescription(column)%></label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="<%=column.Name%>" v-model="<%=column.Name%>" required lay-verify="required"
|
||||
placeholder="<%=Tools.GetDescription(column)%>" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<%} %>
|
||||
<%} %>
|
||||
|
||||
<%if(Tools.NeedCascade(SourceTable)){ %>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">所属部门</label>
|
||||
<div class="layui-input-block">
|
||||
<input id="Organizations" name="Organizations" v-model="Organizations" required lay-verify="required" class="layui-input" />
|
||||
<input id="OrganizationIds" name="OrganizationIds" v-model="OrganizationIds" required lay-verify="required" type="hidden" />
|
||||
<div id="menuContent" class="menuContent" style="display: none;">
|
||||
<ul id="org" class="ztree"></ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<%} %>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="/layui/layui.js"></script>
|
||||
<script type="text/javascript" src="/js/<%=ModuleName%>Manager.js"></script>
|
||||
|
||||
|
||||
166
CodeSmith/CSharp/Web/index.js.cst
Normal file
166
CodeSmith/CSharp/Web/index.js.cst
Normal file
@@ -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
|
||||
})
|
||||
146
CodeSmith/CSharp/WebGenerate.cst
Normal file
146
CodeSmith/CSharp/WebGenerate.cst
Normal file
@@ -0,0 +1,146 @@
|
||||
<%@ 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="连接的数据库"
|
||||
OnChanged="OnSourceDatabaseChanged"%>
|
||||
|
||||
<%@ 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"
|
||||
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" %>
|
||||
<%@ Register Name="JSGenerateClass"
|
||||
Template="Web\index.js.cst"
|
||||
MergeProperties="False" %>
|
||||
Generating Entities ...
|
||||
<% Generate(); %>
|
||||
|
||||
<script runat="template">
|
||||
public void Generate()
|
||||
{
|
||||
Stopwatch watch = Stopwatch.StartNew();
|
||||
string outputDirectory = Path.GetFullPath(directory);
|
||||
|
||||
if (!Directory.Exists(directory)) //根目录
|
||||
Directory.CreateDirectory(directory);
|
||||
|
||||
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 +"Manager")) //视图文件夹
|
||||
Directory.CreateDirectory(directory +"/views/"+ModuleName +"Manager");
|
||||
|
||||
CreateApplicationClass();
|
||||
CreateHtmlClass();
|
||||
CreateJSClass();
|
||||
|
||||
this.RegisterReference("System.Configuration");
|
||||
this.RegisterReference("System.Data");
|
||||
this.RegisterReference("System.Data.Entity");
|
||||
this.RegisterReference("System.Runtime.Serialization");
|
||||
this.RegisterReference("EntityFramework");
|
||||
|
||||
watch.Stop();
|
||||
Response.WriteLine("Generate Time: " + watch.ElapsedMilliseconds + " ms");
|
||||
}
|
||||
|
||||
//创建APP层,如UserManagerApp.cs
|
||||
public void CreateApplicationClass()
|
||||
{
|
||||
ApplicationGenerateClass generatedClass = this.Create<ApplicationGenerateClass>();
|
||||
this.CopyPropertiesTo(generatedClass);
|
||||
|
||||
string rootDirectory = Path.GetFullPath(directory);
|
||||
|
||||
string generatedFile = ModuleName + "ManagerApp.cs";
|
||||
generatedFile = Path.Combine(rootDirectory, generatedFile);
|
||||
|
||||
generatedClass.ModuleName = ModuleName;
|
||||
generatedClass.NeedViewModel = NeedViewModel;
|
||||
|
||||
Response.WriteLine(generatedFile);
|
||||
generatedClass.RenderToFile(generatedFile, generatedFile, true);
|
||||
}
|
||||
|
||||
//创建视图,如views/Users/index.html
|
||||
public void CreateHtmlClass()
|
||||
{
|
||||
HtmlGenerateClass generatedClass = this.Create<HtmlGenerateClass>();
|
||||
this.CopyPropertiesTo(generatedClass);
|
||||
|
||||
string generatedFile = Path.GetFullPath(directory) + "/views/"+ModuleName+"Manager/" + "index.cshtml";
|
||||
|
||||
generatedClass.ModuleName = ModuleName;
|
||||
generatedClass.SourceTable = SourceTable;
|
||||
|
||||
Response.WriteLine(generatedFile);
|
||||
generatedClass.RenderToFile(generatedFile, generatedFile, true);
|
||||
}
|
||||
|
||||
//创建视图,如js/userManager.js
|
||||
public void CreateJSClass()
|
||||
{
|
||||
JSGenerateClass generatedClass = this.Create<JSGenerateClass>();
|
||||
this.CopyPropertiesTo(generatedClass);
|
||||
|
||||
string generatedFile = Path.GetFullPath(directory) + "/js/"+ModuleName+"Manager.js";
|
||||
|
||||
generatedClass.ModuleName = ModuleName;
|
||||
|
||||
Response.WriteLine(generatedFile);
|
||||
generatedClass.RenderToFile(generatedFile, generatedFile, true);
|
||||
}
|
||||
|
||||
|
||||
//更换数据源时,改变ModuleName
|
||||
private void OnSourceDatabaseChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (SourceTable == null)
|
||||
return;
|
||||
ModuleName = SourceTable.Name;
|
||||
}
|
||||
|
||||
</script>
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,103 +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");}
|
||||
<div class="bjui-pageContent tableContent" style="position: relative">
|
||||
<div class="clearfix">
|
||||
<div style="float: left; width: 220px; overflow: auto;" class="table table-bordered">
|
||||
<ul id="tree" class="ztree"></ul>
|
||||
</div>
|
||||
|
||||
<div id="detail" style="margin-left: 225px;">
|
||||
<table id="maingrid" class="table table-bordered"></table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!--编辑对话框-->
|
||||
<div class="bjui-dialog hidden bjui-dialog-container" id="editDlg" data-noinit="true">
|
||||
<div class="bjui-pageContent">
|
||||
<form action="/<%=ModuleName%>/Add" class="pageForm" data-toggle="validate" data-reload="false" id="editForm">
|
||||
|
||||
<table class="table table-condensed table-hover">
|
||||
<tbody>
|
||||
<% foreach (ColumnSchema column in this.SourceTable.Columns) {
|
||||
if(column.IsPrimaryKeyMember){%>
|
||||
<input type="text" id="<%=column.Name%>" name="<%=column.Name%>" value="" class="hidden" />
|
||||
<%}else if(CSharpAlias[column.SystemType.FullName] == "bool") {%>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="<%=column.Name%>" class="control-label x120"><%=Tools.GetDescription(column)%>:</label>
|
||||
<select name="<%=column.Name%>" id="<%=column.Name%>" data-toggle="selectpicker" data-rule="required">
|
||||
<option value="false">否</option>
|
||||
<option value="true">是</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<%}else if(CSharpAlias[column.SystemType.FullName] == "int" ) {%>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="<%=column.Name%>" class="control-label x120"><%=Tools.GetDescription(column)%>:</label>
|
||||
<select name="<%=column.Name%>" id="<%=column.Name%>" data-toggle="selectpicker" data-rule="required">
|
||||
<option value="0">默认</option>
|
||||
<option value="1">状态1</option>
|
||||
<option value="2">状态2</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<%}else if(CSharpAlias[column.SystemType.FullName].Contains("DateTime")) {%>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="<%=column.Name%>" class="control-label x120"><%=Tools.GetDescription(column)%>:</label>
|
||||
<input type="text" id="<%=column.Name%>" name="<%=column.Name%>" value="" data-toggle="datepicker"/>
|
||||
</td>
|
||||
</tr>
|
||||
<%} else {%>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="<%=column.Name%>" class="control-label x120"><%=Tools.GetDescription(column)%>:</label>
|
||||
<input type="text" id="<%=column.Name%>" name="<%=column.Name%>" value=""/>
|
||||
</td>
|
||||
</tr>
|
||||
<%} %>
|
||||
<%} %>
|
||||
<%if(Tools.NeedCascade(SourceTable)){ %>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="ParentName" class="control-label x120">上级分类:</label>
|
||||
<input id="ParentId" name="ParentId" style="display: none" />
|
||||
<input type="text" name="ParentName" id="ParentName"
|
||||
data-toggle="selectztree" data-tree="#j_select_tree1">
|
||||
<ul id="j_select_tree1" class="ztree hide" data-toggle="ztree"></ul>
|
||||
</td>
|
||||
</tr>
|
||||
<%} %>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
<div class="bjui-pageFooter">
|
||||
<ul>
|
||||
<li><button type="button" class="btn btn-close">关闭</button></li>
|
||||
<li><button type="button" class="btn btn-primary" id="btnSave">保存</button></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="~/BllScripts/grid.js"></script>
|
||||
<script src="~/BllScripts/<%=ModuleName%>.js"></script>
|
||||
@@ -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");}
|
||||
<div class="bjui-pageContent tableContent">
|
||||
<div class="clearfix">
|
||||
<div id="@_treeDetail" style="margin-left: 225px;">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
loadDataGrid();
|
||||
});
|
||||
//加载数据到datagrid
|
||||
function loadDataGrid() {
|
||||
//b-jui的datagrid需要重新处理HTML
|
||||
$('#@_treeDetail').empty()
|
||||
.append('<table id="@_gridId" class="table table-bordered table-hover table-striped table-top"></table>');
|
||||
|
||||
$('#@_gridId').datagrid({
|
||||
showToolbar: false,
|
||||
filterThead: false,
|
||||
columns: [
|
||||
<% foreach (ColumnSchema column in this.SourceTable.Columns) { %>
|
||||
{
|
||||
name: '<%=column.Name%>',
|
||||
label: '<%=column.Description%>',
|
||||
width: 100
|
||||
<%if(column.IsPrimaryKeyMember){ %>
|
||||
, hide: true
|
||||
<%} %>
|
||||
<%else if(CSharpAlias[column.SystemType.FullName] == "System.DateTime") {%>
|
||||
, type: 'date',
|
||||
pattern: 'yyyy-MM-dd HH:mm:ss'
|
||||
<%} %>
|
||||
<%else if(CSharpAlias[column.SystemType.FullName] == "bool") {%>
|
||||
,type: 'select',
|
||||
align: 'center',
|
||||
items: [{ '0': '否' }, { '1': '是' }],
|
||||
<%} %>
|
||||
<%else if(CSharpAlias[column.SystemType.FullName] == "int") {%>
|
||||
,type: 'select',
|
||||
align: 'center',
|
||||
items: [{ '0': '默认' }, { '1': '状态1' }],
|
||||
<%} %>
|
||||
},
|
||||
<% } %>
|
||||
],
|
||||
dataUrl: '<%=ModuleName%>Manager/Load?parentId=' + selectedId,
|
||||
fullGrid: true,
|
||||
showLinenumber: true,
|
||||
showCheckboxcol: true,
|
||||
paging: true,
|
||||
filterMult: false,
|
||||
showTfoot: true,
|
||||
height: '700'
|
||||
});
|
||||
}
|
||||
|
||||
//删除
|
||||
function del<%=ModuleName%>() {
|
||||
var selected = getSelected('#@_gridId',2);
|
||||
if (selected == null) return;
|
||||
|
||||
$.getJSON('<%=ModuleName%>Manager/Delete?Id=' + selected, function (data) {
|
||||
if (data.statusCode == "200")
|
||||
loadDataGrid();
|
||||
else {
|
||||
$(this).alertmsg('warn', data.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//自定义的编辑按钮
|
||||
function edit<%=ModuleName%>() {
|
||||
var selected = getSelected('#@_gridId',2);
|
||||
if (selected == null) return;
|
||||
|
||||
$(this).dialog({
|
||||
id: 'editDialog',
|
||||
url: '/<%=ModuleName%>Manager/Add?id=' + selected,
|
||||
title: '编辑',
|
||||
onClose:function() {
|
||||
refresh<%=ModuleName%>Grid();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function refresh<%=ModuleName%>Grid() {
|
||||
$('#@_gridId').datagrid('refresh');
|
||||
// loadDataGrid();
|
||||
}
|
||||
//@@ sourceURL=<%=ModuleName%>ManagerIndex.js
|
||||
</script>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user