mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-08-23 13:06:48 +08:00
完成添加
This commit is contained in:
parent
42f4ed9d7b
commit
4ee0a395e2
@ -68,14 +68,22 @@ namespace OpenAuth.App
|
|||||||
return _repository.Find(u => u.ParentId == orgId);
|
return _repository.Find(u => u.ParentId == orgId);
|
||||||
}
|
}
|
||||||
|
|
||||||
//得到部门的所有子部门
|
/// <summary>
|
||||||
|
/// 得到部门的所有子部门
|
||||||
|
/// <para>如果orgId为0,表示取得所有部门</para>
|
||||||
|
/// </summary>
|
||||||
public IEnumerable<Org> LoadAllChildren(int orgId)
|
public IEnumerable<Org> LoadAllChildren(int orgId)
|
||||||
{
|
{
|
||||||
var org = _repository.FindSingle(u => u.Id == orgId);
|
string cascadeId = "0.";
|
||||||
if (org == null)
|
if (orgId != 0)
|
||||||
throw new Exception("未能找到指定对象信息");
|
{
|
||||||
|
var org = _repository.FindSingle(u => u.Id == orgId);
|
||||||
|
if (org == null)
|
||||||
|
throw new Exception("未能找到指定对象信息");
|
||||||
|
cascadeId = org.CascadeId;
|
||||||
|
}
|
||||||
|
|
||||||
return _repository.Find(u => u.CascadeId.Contains(org.CascadeId) && u.Id != orgId);
|
return _repository.Find(u => u.CascadeId.Contains(cascadeId) && u.Id != orgId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -109,4 +117,4 @@ namespace OpenAuth.App
|
|||||||
|
|
||||||
#endregion 私有方法
|
#endregion 私有方法
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,13 +6,14 @@ using System.Web.Mvc;
|
|||||||
using Infrastructure;
|
using Infrastructure;
|
||||||
using OpenAuth.App;
|
using OpenAuth.App;
|
||||||
using OpenAuth.Domain;
|
using OpenAuth.Domain;
|
||||||
|
using OpenAuth.Mvc.Models;
|
||||||
|
|
||||||
namespace OpenAuth.Mvc.Controllers
|
namespace OpenAuth.Mvc.Controllers
|
||||||
{
|
{
|
||||||
public class OrgManagerController : BaseController
|
public class OrgManagerController : BaseController
|
||||||
{
|
{
|
||||||
private OrgManagerApp _orgApp;
|
private OrgManagerApp _orgApp;
|
||||||
private Response _response = new Response();
|
private BjuiResponse _bjuiResponse = new BjuiResponse();
|
||||||
|
|
||||||
public OrgManagerController()
|
public OrgManagerController()
|
||||||
{
|
{
|
||||||
@ -25,12 +26,39 @@ namespace OpenAuth.Mvc.Controllers
|
|||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 选择上级机构页面
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>ActionResult.</returns>
|
||||||
public ActionResult LookupParent()
|
public ActionResult LookupParent()
|
||||||
{
|
{
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ActionResult AddOrg()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
//添加组织提交
|
||||||
|
[HttpPost]
|
||||||
|
public string AddOrg(Org org)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_orgApp.AddOrg(org);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_bjuiResponse.statusCode = "300";
|
||||||
|
_bjuiResponse.message = ex.Message;
|
||||||
|
}
|
||||||
|
return JsonHelper.Instance.Serialize(_bjuiResponse);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public string LoadOrg()
|
public string LoadOrg()
|
||||||
{
|
{
|
||||||
return JsonHelper.Instance.Serialize(_orgApp.GetAll());
|
return JsonHelper.Instance.Serialize(_orgApp.GetAll());
|
||||||
@ -41,23 +69,28 @@ namespace OpenAuth.Mvc.Controllers
|
|||||||
return JsonHelper.Instance.Serialize(_orgApp.LoadAllChildren(id));
|
return JsonHelper.Instance.Serialize(_orgApp.LoadAllChildren(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public string DelOrg(string json)
|
/// <summary>
|
||||||
|
/// 删除指定ID的组织
|
||||||
|
/// <para>Id为逗号分开的字符串</para>
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>System.String.</returns>
|
||||||
|
public string DelOrg(string Id)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var delObj = JsonHelper.Instance.Deserialize<Org[]>(json);
|
|
||||||
foreach (var obj in delObj)
|
foreach (var obj in Id.Split(','))
|
||||||
{
|
{
|
||||||
_orgApp.DelOrg(obj.Id);
|
_orgApp.DelOrg(int.Parse(obj));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_response.Status = false;
|
_bjuiResponse.statusCode = "300";
|
||||||
_response.Message = e.Message;
|
_bjuiResponse.message = e.Message;
|
||||||
}
|
}
|
||||||
|
|
||||||
return JsonHelper.Instance.Serialize(_response);
|
return JsonHelper.Instance.Serialize(_bjuiResponse);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
57
OpenAuth.Mvc/Models/BJUIResponse.cs
Normal file
57
OpenAuth.Mvc/Models/BJUIResponse.cs
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
// ***********************************************************************
|
||||||
|
// Assembly : OpenAuth.Mvc
|
||||||
|
// Author : yubaolee
|
||||||
|
// Created : 11-05-2015
|
||||||
|
//
|
||||||
|
// Last Modified By : yubaolee
|
||||||
|
// Last Modified On : 11-05-2015
|
||||||
|
// ***********************************************************************
|
||||||
|
// <copyright file="BJUIResponse.cs" company="www.cnblogs.com/yubaolee">
|
||||||
|
// Copyright (c) www.cnblogs.com/yubaolee. All rights reserved.
|
||||||
|
// </copyright>
|
||||||
|
// <summary>B-JUI框架返回</summary>
|
||||||
|
// ***********************************************************************
|
||||||
|
|
||||||
|
namespace OpenAuth.Mvc.Models
|
||||||
|
{
|
||||||
|
public class BjuiResponse
|
||||||
|
{
|
||||||
|
public string statusCode
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public string message
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public string tabid
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool closeCurrent
|
||||||
|
{
|
||||||
|
get; set;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public string forward { get; set; }
|
||||||
|
public string forwardConfirm { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
public BjuiResponse()
|
||||||
|
{
|
||||||
|
statusCode = "200";
|
||||||
|
message = "操作成功";
|
||||||
|
tabid = "";
|
||||||
|
closeCurrent = false;
|
||||||
|
forward = "";
|
||||||
|
forwardConfirm = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -130,6 +130,7 @@
|
|||||||
<DependentUpon>Global.asax</DependentUpon>
|
<DependentUpon>Global.asax</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Models\AccountViewModels.cs" />
|
<Compile Include="Models\AccountViewModels.cs" />
|
||||||
|
<Compile Include="Models\BJUIResponse.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -611,6 +612,7 @@
|
|||||||
<Content Include="Views\Home\Main.cshtml" />
|
<Content Include="Views\Home\Main.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<None Include="Views\OrgManager\AddOrg.cshtml" />
|
||||||
<None Include="Views\OrgManager\LookupParent.cshtml" />
|
<None Include="Views\OrgManager\LookupParent.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
|
47
OpenAuth.Mvc/Views/OrgManager/AddOrg.cshtml
Normal file
47
OpenAuth.Mvc/Views/OrgManager/AddOrg.cshtml
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
|
||||||
|
@{
|
||||||
|
ViewBag.Title = "title";
|
||||||
|
Layout = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="bjui-pageContent">
|
||||||
|
<form action="/OrgManager/AddOrg" class="pageForm" data-toggle="validate">
|
||||||
|
<table class="table table-condensed table-hover">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td align="center"><h3>* 添加</h3></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="Name" class="control-label x90">机构名称:</label>
|
||||||
|
<input type="text" name="Name" id="Name" value=""
|
||||||
|
data-rule="required" size="20">
|
||||||
|
</td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<input id="ParentId" name="ParentId" type="hidden">
|
||||||
|
<label for="ParentName" class="control-label x90">上级机构:</label>
|
||||||
|
<input type="text" name="ParentName" id="ParentName"
|
||||||
|
value="" data-toggle="lookup" data-url="/OrgManager/LookupParent">
|
||||||
|
</td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="Status" class="control-label x85">禁用:</label>
|
||||||
|
<input type="checkbox" name="Status" id="Status" value="true" data-toggle="icheck">
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="bjui-pageFooter">
|
||||||
|
<ul>
|
||||||
|
<li><button type="button" class="btn-close">关闭</button></li>
|
||||||
|
<li><button type="submit" class="btn-green">保存</button></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
@ -5,7 +5,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="ztree-detail" style="margin-left: 225px; width: auto;height: auto">
|
<div id="ztree-detail" style="margin-left: 225px; width: auto;height: auto">
|
||||||
<table id="test-datagrid-array" data-width="100%" data-height="100%" class="table table-bordered"></table>
|
<table id="mainGrid" data-width="100%" data-height="100%" class="table table-bordered"></table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -17,23 +17,30 @@
|
|||||||
});
|
});
|
||||||
//加载数据到datagrid
|
//加载数据到datagrid
|
||||||
function loadDataGrid(data) {
|
function loadDataGrid(data) {
|
||||||
$('#test-datagrid-array').datagrid({
|
//b-jui的datagrid需要重新处理HTML
|
||||||
|
$('#ztree-detail').empty()
|
||||||
|
.append('<table id="mainGrid" data-width="100%" data-height="100%" class="table table-bordered"></table>');
|
||||||
|
$('#mainGrid').datagrid({
|
||||||
gridTitle: '机构列表显示',
|
gridTitle: '机构列表显示',
|
||||||
showToolbar: true,
|
showToolbar: true,
|
||||||
toolbarItem: 'add, edit, refresh, |, del',
|
toolbarItem: 'refresh, |, del',
|
||||||
//toolbarCustom: '<button class=" btn-green" data-icon="plus" type="button">添加</button>' +
|
toolbarCustom: '<a href="/OrgManager/AddOrg" class="btn btn-green" data-icon ="plus" ' +
|
||||||
// '<button class=" btn-green" onclick="editOrg()" data-icon="pencil" type="button">编辑</button>',
|
'data-toggle="dialog" data-id="dialog-mask" data-mask="true">添加</a>' +
|
||||||
|
'<button class=" btn-green" onclick="editOrg()" data-icon="pencil" type="button">编辑</button>',
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
name: 'Id',
|
name: 'Id',
|
||||||
label:'Id',
|
label: 'Id',
|
||||||
hide: true,
|
hide: true
|
||||||
edit:false
|
},
|
||||||
},
|
{
|
||||||
|
name: 'ParentId',
|
||||||
|
label: '上级机构ID',
|
||||||
|
hide: true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'CascadeId',
|
name: 'CascadeId',
|
||||||
label: '唯一标识',
|
label: '唯一标识'
|
||||||
edit:false
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Name',
|
name: 'Name',
|
||||||
@ -41,9 +48,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'ParentName',
|
name: 'ParentName',
|
||||||
label: '上级机构',
|
label: '上级机构'
|
||||||
type: 'lookup',
|
|
||||||
attrs: { 'data-url': 'OrgManager/LookupParent' }
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Status',
|
name: 'Status',
|
||||||
@ -58,12 +63,15 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'CreateTime',
|
name: 'CreateTime',
|
||||||
label: '登记日期'
|
label: '登记日期',
|
||||||
|
type: 'date',
|
||||||
|
pattern: 'yyyy-MM-dd HH:mm:ss'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
data: data,
|
data: data,
|
||||||
addUrl: 'OrgManager/AddOrg',
|
addUrl: 'OrgManager/AddOrg',
|
||||||
delUrl: 'OrgManager/DelOrg',
|
delUrl: 'OrgManager/DelOrg',
|
||||||
|
delPK: "Id",
|
||||||
editUrl: 'OrgManager/EditOrg',
|
editUrl: 'OrgManager/EditOrg',
|
||||||
editMode: 'dialog',
|
editMode: 'dialog',
|
||||||
fullGrid: true,
|
fullGrid: true,
|
||||||
@ -73,10 +81,10 @@
|
|||||||
filterMult: false,
|
filterMult: false,
|
||||||
showTfoot: true,
|
showTfoot: true,
|
||||||
delCallback: function (delResult) {
|
delCallback: function (delResult) {
|
||||||
if (delResult.Status == true)
|
if (delResult.statusCode == "200")
|
||||||
Init(selectedId);
|
Init(selectedId);
|
||||||
else {
|
else {
|
||||||
$(this).alertmsg('warn', delResult.Message);
|
$(this).alertmsg('warn', delResult.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -86,10 +94,10 @@
|
|||||||
$.getJSON('OrgManager/LoadChildren', {
|
$.getJSON('OrgManager/LoadChildren', {
|
||||||
id: treeNode.Id
|
id: treeNode.Id
|
||||||
}, function (json) {
|
}, function (json) {
|
||||||
$('#ztree-detail').empty().append('<table id="test-datagrid-array" data-width="100%" data-height="100%" class="table table-bordered"></table>');
|
|
||||||
loadDataGrid(json);
|
loadDataGrid(json);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function Init(selectedId) {
|
function Init(selectedId) {
|
||||||
var setting = {
|
var setting = {
|
||||||
view: {
|
view: {
|
||||||
@ -114,37 +122,47 @@
|
|||||||
$.getJSON('OrgManager/LoadOrg', function (json) {
|
$.getJSON('OrgManager/LoadOrg', function (json) {
|
||||||
var zTreeObj = $.fn.zTree.init($('#orgTree'), setting, json);
|
var zTreeObj = $.fn.zTree.init($('#orgTree'), setting, json);
|
||||||
zTreeObj.expandAll(true);
|
zTreeObj.expandAll(true);
|
||||||
if (selectedId == 0) {
|
|
||||||
loadDataGrid(json);
|
$.getJSON('OrgManager/LoadChildren', {
|
||||||
} else {
|
id: selectedId
|
||||||
//TODO:设置ztree选中,不过没看到效果..
|
}, function (data) {
|
||||||
var selectedNod = zTreeObj.getNodesByParam('Id', selectedId, null);
|
loadDataGrid(data);
|
||||||
zTreeObj.selectNode(selectedNod, false);
|
});
|
||||||
$.getJSON('OrgManager/LoadChildren', {
|
|
||||||
id: selectedId
|
//TODO:设置ztree选中,不过没看到效果..
|
||||||
}, function (data) {
|
var selectedNod = zTreeObj.getNodesByParam('Id', selectedId, null);
|
||||||
$('#ztree-detail').empty().append('<table id="test-datagrid-array" data-width="100%" data-height="100%" class="table table-bordered"></table>');
|
zTreeObj.selectNode(selectedNod, false);
|
||||||
loadDataGrid(data);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function getSelected() {
|
|
||||||
var selected = $('#test-datagrid-array').data('selectedTrs');
|
//获取勾选的值
|
||||||
if (selected == null) {
|
//column:为从0开始的列标识
|
||||||
|
function getSelected(column) {
|
||||||
|
var selected = $('#mainGrid').data('selectedTrs');
|
||||||
|
if (selected == null || selected.length == 0) {
|
||||||
$(this).alertmsg('warn', '至少选择一个对象', {
|
$(this).alertmsg('warn', '至少选择一个对象', {
|
||||||
displayMode: 'slide',
|
displayMode: 'slide',
|
||||||
title: '重要提示'
|
title: '重要提示'
|
||||||
});
|
});
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return selected;
|
|
||||||
|
var records = new Array();
|
||||||
|
selected.each(function () {
|
||||||
|
records[records.length] = this.children[column].innerText;
|
||||||
|
});
|
||||||
|
|
||||||
|
return records;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//自定义的编辑按钮
|
//自定义的编辑按钮
|
||||||
function editOrg() {
|
function editOrg() {
|
||||||
var selected = getSelected();
|
var selected = getSelected(2);
|
||||||
if (selected == null) return;
|
if (selected == null) return;
|
||||||
|
|
||||||
}
|
}
|
||||||
//@@ sourceURL=orgIndex.js
|
//@@ sourceURL=orgIndex.js
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user