using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using QMFrameWork.Common.Serialization;
using QMFrameWork.WebUI.Attribute;
using QMAPP.Web.Models.Sys;
using QMFrameWork.Data;
using QMAPP.Entity.Sys;
using QMAPP.Common.Web.Util;
using QMAPP.Common.Web.Controllers;
using QMFrameWork.WebUI.DataSource;
using QMAPP.ServicesAgent;
namespace QMAPP.Web.Controllers
{
public class UserOrgaizationController : QController
{
///
/// 加载用户列表
///
/// 结果
[HandleException]
public ActionResult UserOrgaList()
{
UserOrgaizationModel seachModel = new UserOrgaizationModel();
TryGetSelectBuffer(out seachModel);
seachModel.rownumbers = false;
seachModel.url = "/UserOrgaization/GetList";
return View("UserOrgaizationList", seachModel);
}
///
/// 获取用户信息列表
///
/// 是否回调
/// 用户信息列表
[HandleException]
public ActionResult GetList(bool? callBack)
{
List users = new List();
UserOrgaizationModel seachModel = null;
DataPage page = new DataPage();
User condition = null;
try
{
//获取查询对象
seachModel = GetModel();
#region 获取缓存值
if (callBack != null)
{
TryGetSelectBuffer(out seachModel);
}
else
{
//保存搜索条件
SetSelectBuffer(seachModel);
}
#endregion
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
condition = CopyToModel(seachModel);
if (AccountController.GetLoginInfo().LoginUserID != "admin")
{
condition.Orgas = AccountController.GetLoginInfo().Orgas;
}
condition.CreateUser = AccountController.GetLoginInfo().UserID;
#region 普通三层架构调用
//UserOrgaizationManageBLL UserOrgaizationBll = null;
//UserOrgaizationBll = BLLFactory.CreateBLL();
//page = UserOrgaizationBll.GetList(condition, page);
#endregion
DateGridResult result = new DateGridResult();
result.Total = page.RecordCount;
result.Rows = new List();
#region 普通三层架构调用
List ums= (List)page.Result;
#endregion
List uoml = new List();
foreach (User uom in ums)
{
result.Rows.Add(new UserOrgaizationModel { UserIDPK = uom.UserID, UserID = uom.LoginUserID, UserName = uom.UserName, OrgaID = uom.OrgaID, OrgaDESC = uom.OrgaDESC });
}
return Content(result.GetJsonSource());
}
catch (Exception ex)
{
throw ex;
}
}
#region 单表普通模式
#region 编辑
///
/// 编辑载入
///
/// 处理结果
[HandleException]
public ActionResult UserOrgaEdit()
{
UserOrgaizationModel model = new UserOrgaizationModel();
string UserID = Request.Params["UserID"];
User user = new User();
try
{
if (string.IsNullOrEmpty(UserID) == false)
{
//修改获取原数据
user.UserID = UserID;
#region 普通三层架构调用
//UserOrgaizationManageBLL orgaBll = null;
//orgaBll = BLLFactory.CreateBLL();
//user = orgaBll.Get(user);
#endregion
model = CopyToModel(user);
model.isEdit = "true";
}
return View("UserOrgaizationEdit", model);
}
catch (Exception ex)
{
throw ex;
}
}
#region 组织机构信息树
///
/// 组织机构信息树
///
/// 处理结果
public ActionResult GetTreeOrgas()
{
List list = new List();
Role role = new Role();
PowerUtil pu = new PowerUtil();
pu.OwnRoles = new List();
//选择的用户编号
string userID = Request.Params["userID"];
string orgaID = Request.Params["orgaID"];
ServiceAgent wcfAgent = this.GetServiceAgent();
try
{
if (string.IsNullOrEmpty(userID) == true)
{
userID= AccountController.GetLoginInfo().UserID;
}
//获取组织机构信息
List userorgas = new List();
List orgas = new List();
//取得所有组织机构
#region 普通三层架构调用
//UserManageBLL userBll = BLLFactory.CreateBLL();
//userorgas = userBll.GetUserOrgaList(userID);
#endregion
//取得全部组织机构
#region 普通三层架构调用
//OrgaizationManageBLL userorgaBll = BLLFactory.CreateBLL();
//orgas = userorgaBll.GetAllList();
#endregion
bool Selected = false;
foreach (Orgaization singleorga in orgas)
{
//过滤掉当前人员主组织机构
if (singleorga.OrgaID != orgaID)
{
TreeNodeResult node = new TreeNodeResult();
node.Tid = singleorga.OrgaID;
node.Ttext = singleorga.OrgaDESC;
//循环已经存在的组织机构
foreach (Orgaization selected in userorgas)
{
//如果当前组织机构在选中范围内,结束循环,否则继续
if (selected.OrgaID == singleorga.OrgaID)
{
Selected = true;
break;
}
else
{
Selected = false;
}
}
node.TChecked = Selected;
list.Add(node);
}
}
return Content(TreeNodeResult.GetResultJosnS(list.ToArray()));
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
///
/// 保存
///
///
/// 处理结果
[HttpPost]
[HandleException]
public ActionResult UserOrgaSave(UserOrgaizationModel saveModel)
{
UserOrgaization orgaization = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
try
{
orgaization = CopyToModel(saveModel);
//处理所选组织机构
string[] orgas = null;
if (saveModel.SelectedOrgas != null)
{
orgas = saveModel.SelectedOrgas.Split(":".ToArray());
orgaization.Orgas = new List();
foreach (string orga in orgas)
{
orgaization.Orgas.Add(new UserOrgaization
{
UserID = saveModel.UserID,
OrgaID = orga,
IsMainOgra="0",
CreateTime = DateTime.Now,
UpdateTime = DateTime.Now,
CreateUser = AccountController.GetLoginInfo().UserID,
UpdateUser = AccountController.GetLoginInfo().UserID
});
}
}
//新增
orgaization.CreateUser = AccountController.GetLoginInfo().UserID;
//修改
orgaization.UpdateUser = AccountController.GetLoginInfo().UserID;
#region 普通三层架构调用
//UserOrgaizationManageBLL orgaBll = BLLFactory.CreateBLL();
//orgaBll.Update(orgaization);
#endregion
return this.GetJsViewResult(string.Format("parent.List(1);parent.showTitle('{0}');parent.closeAppWindow1();"
, AppResource.SaveMessge));
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#endregion
#region 组织机构信息下拉菜单
public ActionResult GetOrgaList()
{
//UserManageBLL userBll = BLLFactory.CreateBLL();
Orgaization orgaModel = new Orgaization();
List list = new List();
//list = userBll.GetUserOrgaList("");
ComboboxResult model = new ComboboxResult();
foreach (Orgaization o in list)
{
model.Add(new ComboboxItem { ID = o.OrgaID, Text = o.OrgaDESC });
}
return Content(model.ToString());
}
#endregion
}
}