You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
600 lines
21 KiB
600 lines
21 KiB
using System;
|
|
using System.Collections;
|
|
using System.Data;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using QMFrameWork.WebUI.Attribute;
|
|
using QMFrameWork.Data;
|
|
using QMFrameWork.Common.Serialization;
|
|
using QMAPP.Common.Web.Util;
|
|
using QMAPP.Common.Web.Controllers;
|
|
using QMFrameWork.WebUI.DataSource;
|
|
using QMAPP.Entity.Sys;
|
|
using QMAPP.Entity.Sys.Entity;
|
|
using QMAPP.Web.Models.Sys;
|
|
|
|
namespace QMAPP.Web.Controllers
|
|
{
|
|
/// <summary>
|
|
/// 机构管理控制器
|
|
/// </summary>
|
|
[SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)]
|
|
public class OrgaizationController : QController
|
|
{
|
|
#region 加载机构列表
|
|
|
|
/// <summary>
|
|
/// 加载机构列表
|
|
/// </summary>
|
|
/// <returns>结果</returns>
|
|
[HandleException]
|
|
public ActionResult OrgaizationList()
|
|
{
|
|
OrgaizationModel seachModel = new OrgaizationModel();
|
|
|
|
TryGetSelectBuffer<OrgaizationModel>(out seachModel);
|
|
seachModel.rownumbers = false;
|
|
seachModel.url = "/Orgaization/GetList";
|
|
|
|
return View("OrgaizationList", seachModel);
|
|
}
|
|
/// <summary>
|
|
/// 获取组织机构列表
|
|
/// </summary>
|
|
/// <param name="callBack">是否回调</param>
|
|
/// <returns>组织机构列表</returns>
|
|
[HandleException]
|
|
public ActionResult GetList(bool? callBack)
|
|
{
|
|
List<OrgaizationModel> users = new List<OrgaizationModel>();
|
|
OrgaizationModel seachModel = null;
|
|
DataPage page = new DataPage();
|
|
Orgaization condition = null;
|
|
try
|
|
{
|
|
//获取查询对象
|
|
seachModel = GetModel<OrgaizationModel>();
|
|
|
|
#region 获取缓存值
|
|
if (callBack != null)
|
|
{
|
|
TryGetSelectBuffer<OrgaizationModel>(out seachModel);
|
|
}
|
|
else
|
|
{
|
|
//保存搜索条件
|
|
SetSelectBuffer<OrgaizationModel>(seachModel);
|
|
}
|
|
|
|
#endregion
|
|
|
|
//获取前台分页控件的分页大小
|
|
page = this.GetDataPage(seachModel);
|
|
|
|
condition = CopyToModel<Orgaization, OrgaizationModel>(seachModel);
|
|
|
|
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
|
|
page = agent.InvokeServiceFunction<DataPage>("OrgaizationManageBLL_GetList", condition, page);
|
|
|
|
DataGridResult<Orgaization> result = new DataGridResult<Orgaization>(
|
|
JsonConvertHelper.GetDeserialize<List<Orgaization>>(page.Result.ToString()), page.RecordCount);
|
|
|
|
return Content(result.GetJsonSource());
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 编辑
|
|
|
|
/// <summary>
|
|
/// 编辑载入
|
|
/// </summary>
|
|
/// <returns>处理结果</returns>
|
|
[HandleException]
|
|
public ActionResult OrgaizationEdit()
|
|
{
|
|
OrgaizationModel model = new OrgaizationModel();
|
|
string OrgaID = Request.Params["OrgaID"];
|
|
Orgaization orga = new Orgaization();
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(OrgaID) == false)
|
|
{
|
|
//修改获取原数据
|
|
orga.OrgaID = OrgaID;
|
|
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
|
|
orga=agent.InvokeServiceFunction<Orgaization>("OrgaizationManageBLL_Get", orga);
|
|
if (orga != null)
|
|
{
|
|
model = CopyToModel<OrgaizationModel, Orgaization>(orga);
|
|
model.CkACTIVATEFLG = orga.ACTIVATEFLG=="1"?true:false;
|
|
model.isEdit = "true";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
model.CkACTIVATEFLG = true;
|
|
}
|
|
return View(model);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#region 组织机构树
|
|
/// <summary>
|
|
/// 组织机构树
|
|
/// </summary>
|
|
/// <returns>处理结果</returns>
|
|
[HandleException]
|
|
public ActionResult OrgaizationTree()
|
|
{
|
|
OrgaizationModel model = new OrgaizationModel();
|
|
model.OrgaID = Request.Form["OrgaID"].Split(new Char[] { ',' })[0].ToString();
|
|
model.OrgaDESC = Request.Form["OrgaDESC"];
|
|
model.isEdit = Request.Form["isEdit"];
|
|
model.UpdateTime = Convert.ToDateTime(Request.Form["UpdateTime"]);
|
|
model.CreateTime = Convert.ToDateTime(Request.Form["CreateTime"]);
|
|
model.CreateUser = Request.Form["CreateUser"];
|
|
return View(model);
|
|
}
|
|
|
|
public ActionResult GetTreeData()
|
|
{
|
|
//OrgaizationManageBLL orgaBll = BLLFactory.CreateBLL<OrgaizationManageBLL>();
|
|
|
|
List<TreeNodeResult> list = new List<TreeNodeResult>();
|
|
OrgaizationModel orgaModel = new OrgaizationModel();
|
|
Orgaization orga = new Orgaization();
|
|
orga.OrgaParent = "0";
|
|
|
|
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
|
|
orgaModel.OrgaList = agent.InvokeServiceFunction<List<Orgaization>>("OrgaizationManageBLL_GetSubTreeList", orga);
|
|
|
|
//添加第一级机构
|
|
foreach (Orgaization child in orgaModel.OrgaList)
|
|
{
|
|
TreeNodeResult treenode = new TreeNodeResult();
|
|
treenode.Tid = child.OrgaID.ToString();
|
|
treenode.Ttext = child.OrgaDESC.ToString();
|
|
|
|
//添加子机构
|
|
this.BuildChildItems(child, treenode, list);
|
|
list.Add(treenode);
|
|
}
|
|
|
|
return Content(TreeNodeResult.GetResultJosnS(list.ToArray()));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建子组织机构
|
|
/// </summary>
|
|
/// <param name="parentNode">父节点</param>
|
|
/// <param name="childPowers">子权限</param>
|
|
private void BuildChildItems(Orgaization orga, TreeNodeResult tnr, List<TreeNodeResult> list)
|
|
{
|
|
Orgaization corga = new Orgaization();
|
|
OrgaizationModel corgaModel = new OrgaizationModel();
|
|
corga.OrgaParent = orga.OrgaID;
|
|
|
|
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
|
|
corgaModel.OrgaList = agent.InvokeServiceFunction<List<Orgaization>>("OrgaizationManageBLL_GetSubTreeLis", corga);
|
|
|
|
if (corgaModel.OrgaList.Count > 0)
|
|
{
|
|
|
|
foreach (Orgaization child in corgaModel.OrgaList)
|
|
{
|
|
TreeNodeResult cTreeNode = new TreeNodeResult();
|
|
cTreeNode.Tid = child.OrgaID.ToString();
|
|
cTreeNode.Ttext = child.OrgaDESC.ToString();
|
|
|
|
tnr.AddchildNode(cTreeNode);
|
|
|
|
//添加子菜单
|
|
this.BuildChildItems(child, cTreeNode, list);
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
[HttpPost]
|
|
public ActionResult SaveTree()
|
|
{
|
|
OrgaizationModel model = new OrgaizationModel();
|
|
model.OrgaID = Request.Form["OrgaID"];
|
|
model.OrgaDESC = Request.Form["OrgaDESC"];
|
|
model.OrgaParent = Request.Form["selectKey"].Split(new Char[] { ':' })[0].ToString();
|
|
model.OrgaParentDESC = Request.Form["selectKey"].Split(new Char[] { ':' })[1].ToString();
|
|
model.isEdit = Request.Form["isEdit"];
|
|
model.UpdateTime = Convert.ToDateTime(Request.Form["UpdateTime"]);
|
|
model.CreateTime = Convert.ToDateTime(Request.Form["CreateTime"]);
|
|
model.CreateUser = Request.Form["CreateUser"];
|
|
return View("OrgaizationEdit",model);
|
|
}
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 保存
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns>处理结果</returns>
|
|
[HttpPost]
|
|
[HandleException]
|
|
public ActionResult OrgaizationSave(OrgaizationModel saveModel)
|
|
{
|
|
Orgaization orga = null;
|
|
try
|
|
{
|
|
orga = CopyToModel<Orgaization, OrgaizationModel>(saveModel);
|
|
orga.ACTIVATEFLG = saveModel.CkACTIVATEFLG == true ? "1" : "0";
|
|
|
|
|
|
//处理所选权限
|
|
string[] Authoritys = null;
|
|
if (saveModel.SelectedPowers != null)
|
|
{
|
|
Authoritys = saveModel.SelectedPowers.Split(":".ToArray());
|
|
orga.OrgaAuthorityList = new List<OrgaizationAuthority>();
|
|
foreach (string authority in Authoritys)
|
|
{
|
|
orga.OrgaAuthorityList.Add(new OrgaizationAuthority
|
|
{
|
|
AuthorityID = authority,
|
|
});
|
|
}
|
|
}
|
|
|
|
//处理所选角色
|
|
string[] roles = null;
|
|
if (saveModel.SelectedRoles != null)
|
|
{
|
|
roles = saveModel.SelectedRoles.Split(":".ToArray());
|
|
orga.RoleList = new List<T_QM_ORGANROLE>();
|
|
foreach (string roleID in roles)
|
|
{
|
|
orga.RoleList.Add(new T_QM_ORGANROLE
|
|
{
|
|
ROLEID = roleID,
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
|
|
|
|
if (string.IsNullOrEmpty(saveModel.isEdit) == true)
|
|
{
|
|
//新增
|
|
orga.IsUpdate = false;
|
|
}
|
|
else
|
|
{
|
|
//修改
|
|
orga.IsUpdate = true;
|
|
}
|
|
bool isExist = agent.InvokeServiceFunction<bool>("OrgaizationManageBLL_ExistsOrga", orga);
|
|
if (isExist)
|
|
{
|
|
|
|
SetMessage("当前保存的组织机构信息已经存在,请修改!");
|
|
return View("OrgaizationEdit", saveModel);
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(saveModel.isEdit) == true)
|
|
{
|
|
//新增
|
|
agent.InvokeServiceFunction("OrgaizationManageBLL_Insert", orga);
|
|
}
|
|
else
|
|
{
|
|
//修改
|
|
agent.InvokeServiceFunction("OrgaizationManageBLL_Update", orga);
|
|
}
|
|
|
|
return this.GetJsViewResult(string.Format("parent.List(1);parent.showTitle('{0}');parent.closeAppWindow1();"
|
|
, AppResource.SaveMessge));
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 角色信息树
|
|
/// <summary>
|
|
/// 角色信息树
|
|
/// </summary>
|
|
/// <returns>处理结果</returns>
|
|
public ActionResult GetTreeRoles()
|
|
{
|
|
List<TreeNodeResult> list = new List<TreeNodeResult>();
|
|
Role role = new Role();
|
|
PowerUtil pu = new PowerUtil();
|
|
pu.OwnRoles = new List<Role>();
|
|
string organID = Request.QueryString["organID"];
|
|
Orgaization organ = new Orgaization();
|
|
try
|
|
{
|
|
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
|
|
if (string.IsNullOrEmpty(organID) == false)
|
|
{
|
|
//获取角色信息
|
|
organ.OrgaID = organID;
|
|
organ = agent.InvokeServiceFunction<Orgaization>("OrgaizationManageBLL_GetOrganRoleList", organ);
|
|
}
|
|
else
|
|
{
|
|
organ = new Orgaization();
|
|
organ.RoleList = new List<T_QM_ORGANROLE>();
|
|
role.Roles = new List<Role>();
|
|
}
|
|
|
|
//获取角色信息列表
|
|
role = agent.InvokeServiceFunction<Role>("RoleManageBLL_GetAll");
|
|
|
|
foreach (Role singlerole in role.Roles)
|
|
{
|
|
TreeNodeResult node = new TreeNodeResult();
|
|
node.Tid = singlerole.RoleID;
|
|
node.Ttext = singlerole.RoleDESC;
|
|
|
|
bool exists = organ.RoleList.Exists(p => p.ROLEID == singlerole.RoleID);
|
|
|
|
node.TChecked = exists;
|
|
|
|
list.Add(node);
|
|
}
|
|
return Content(TreeNodeResult.GetResultJosnS(list.ToArray()));
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 权限信息树
|
|
|
|
|
|
///// <summary>
|
|
///// 权限信息树
|
|
///// </summary>
|
|
///// <returns>处理结果</returns>
|
|
//public ActionResult GetTreePowers()
|
|
//{
|
|
// List<TreeNodeResult> list = new List<TreeNodeResult>();
|
|
// List<PowerInfo> powers = null;
|
|
// PowerUtil pu = new PowerUtil();
|
|
// pu.OwnPowers = new List<PowerInfo>();
|
|
// string orgaID = Request.Params["orgaID"];
|
|
// try
|
|
// {
|
|
// if (string.IsNullOrEmpty(orgaID) == false)
|
|
// {
|
|
// //获取组织机构信息
|
|
// Orgaization o = new Orgaization();
|
|
// o.OrgaID = orgaID;
|
|
// OrgaizationManageBLL orgaBll = BLLFactory.CreateBLL<OrgaizationManageBLL>();
|
|
// o = orgaBll.GetOrgaAuthorityList(o);
|
|
|
|
|
|
// foreach (OrgaizationAuthority power in o.OrgaAuthorityList)
|
|
// {
|
|
// pu.OwnPowers.Add(new PowerInfo { PowerID = power.AuthorityID });
|
|
// }
|
|
// }
|
|
|
|
// //获取当前登录系统的用户,全部权限信息
|
|
// powers = pu.GetAllPowerInfos(MvcApplication.PhysicsRootPath + @"App_Data\Power.xml");
|
|
|
|
// foreach (PowerInfo info in powers)
|
|
// {
|
|
// TreeNodeResult node = new TreeNodeResult();
|
|
// node.Tid = info.PowerID;
|
|
// node.Ttext = info.PowerDes;
|
|
// //循环已经存在的权限,
|
|
// foreach (PowerInfo selected in pu.OwnPowers)
|
|
// {
|
|
// //如果当前权限在选中范围内,结束循环,否者继续
|
|
// if (selected.PowerID == info.PowerID)
|
|
// {
|
|
// info.Selected = true;
|
|
// break;
|
|
// }
|
|
// else
|
|
// {
|
|
// info.Selected = false;
|
|
// }
|
|
// }
|
|
// node.TChecked = info.Selected;
|
|
// //添加子权限
|
|
// this.BuildChildItems(node, info.ChildPowers, pu);
|
|
|
|
// list.Add(node);
|
|
// }
|
|
// return Content(TreeNodeResult.GetResultJosnS(list.ToArray()));
|
|
// }
|
|
// catch (Exception ex)
|
|
// {
|
|
// throw ex;
|
|
// }
|
|
//}
|
|
///// <summary>
|
|
///// 创建子权限
|
|
///// </summary>
|
|
///// <param name="parentNode">父节点</param>
|
|
///// <param name="childPowers">子权限</param>
|
|
///// <param name="pu">已经选中的权限列表</param>
|
|
//private void BuildChildItems(TreeNodeResult parentNode, List<PowerInfo> childPowers, PowerUtil pu)
|
|
//{
|
|
// foreach (PowerInfo info in childPowers)
|
|
// {
|
|
// TreeNodeResult node = new TreeNodeResult();
|
|
// node.Tid = info.PowerID;
|
|
// node.Ttext = info.PowerDes;
|
|
// //循环已经存在的权限,
|
|
// foreach (PowerInfo selected in pu.OwnPowers)
|
|
// {
|
|
// //如果当前权限在选中范围内,结束循环,否者继续
|
|
// if (selected.PowerID == info.PowerID)
|
|
// {
|
|
// info.Selected = true;
|
|
// break;
|
|
// }
|
|
// else
|
|
// {
|
|
// info.Selected = false;
|
|
// }
|
|
// }
|
|
// node.TChecked = info.Selected;
|
|
|
|
// if (info.ChildPowers != null)
|
|
// {
|
|
// //添加子权限
|
|
// this.BuildChildItems(node, info.ChildPowers, pu);
|
|
// }
|
|
// parentNode.AddchildNode(node);
|
|
|
|
// }
|
|
//}
|
|
|
|
#endregion
|
|
|
|
#region 删除
|
|
|
|
/// <summary>
|
|
/// 删除组织机构
|
|
/// </summary>
|
|
/// <returns>结果</returns>
|
|
[HttpPost]
|
|
[HandleException]
|
|
public ActionResult OrgaizationDelete()
|
|
{
|
|
string selectKey = Request.Form["selectKey"];
|
|
string[] arraydata = selectKey.Split(":".ToCharArray());
|
|
ArrayList alist = new ArrayList();
|
|
try
|
|
{
|
|
for (int i = 0; i < arraydata.Length; i++)
|
|
{
|
|
alist.Add(arraydata[i]);
|
|
}
|
|
|
|
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
|
|
int count = agent.InvokeServiceFunction<int>("OrgaizationManageBLL_BatchDelete", alist);
|
|
|
|
if (alist.Count != count)
|
|
{
|
|
if (count == 0)
|
|
{
|
|
SetMessage("选中的机构已激活,无法删除。");
|
|
}
|
|
else
|
|
{
|
|
SetMessage(string.Format("删除完成(其中存在{0}个已激活的机构,无法删除)。", alist.Count - count));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
SetMessage(AppResource.DeleteMessage);
|
|
}
|
|
|
|
return OrgaizationList();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 导出excel
|
|
|
|
/// <summary>
|
|
/// 导出excel
|
|
/// </summary>
|
|
/// <returns>结果</returns>
|
|
[HttpPost]
|
|
[HandleException]
|
|
public ActionResult ExportExcel()
|
|
{
|
|
OrgaizationModel seachModel = null;
|
|
Orgaization condition = null;
|
|
DataTable exportDt = new DataTable();
|
|
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
|
|
PowerUtil pu = new PowerUtil();
|
|
string selectKey = Request.Form["selectKey"];
|
|
try
|
|
{
|
|
//获取查询对象
|
|
seachModel = GetModel<OrgaizationModel>();
|
|
condition = CopyToModel<Orgaization, OrgaizationModel>(seachModel);
|
|
|
|
//获取数据
|
|
exportDt = agent.InvokeServiceFunction<DataTable>("OrgaizationManageBLL_GetExportData", condition);
|
|
|
|
if (selectKey != "")
|
|
{
|
|
DataView dv = new DataView(exportDt);
|
|
string strWhere = "";
|
|
string[] list = selectKey.Split(":".ToCharArray());
|
|
foreach (string OrgaID in list)
|
|
{
|
|
strWhere += " OrgaID='" + OrgaID + "' or";
|
|
}
|
|
if (strWhere != "")
|
|
{
|
|
strWhere = strWhere.Remove((strWhere.Length - 2), 2);
|
|
}
|
|
dv.RowFilter = strWhere;
|
|
exportDt = dv.ToTable();
|
|
}
|
|
|
|
exportDt.Columns.Add("CREATEDATESHOW");
|
|
exportDt.Columns.Add("UPDATEDATESHOW");
|
|
|
|
foreach (DataRow dr in exportDt.Rows)
|
|
{
|
|
if (dr["CREATEDATE"] != null)
|
|
{
|
|
dr["CREATEDATESHOW"] = Convert.ToDateTime(dr["CREATEDATE"]).ToString("yyyy-MM-dd HH:mm:ss");
|
|
}
|
|
if (dr["UPDATEDATE"] != null)
|
|
{
|
|
dr["UPDATEDATESHOW"] = Convert.ToDateTime(dr["UPDATEDATE"]).ToString("yyyy-MM-dd HH:mm:ss");
|
|
}
|
|
}
|
|
|
|
//导出
|
|
QMFrameWork.WebUI.Util.IEFileTool efTool = new QMFrameWork.WebUI.Util.IEFileTool();
|
|
return efTool.GetExcelFileResult("OrganList", "机构信息.xls", exportDt);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
|