using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Mvc.Html; using QMFrameWork.Common.Serialization; using QMFrameWork.Data; using QMFrameWork.WebUI.Util; using QMFrameWork.WebUI.Attribute; using QMFrameWork.WebUI.DataSource; using QMAPP.Entity.Sys.Entity; using QMAPP.Entity.Sys; using QMAPP.Common.Web.Controllers; using QMAPP.Common.Web.Models; using QMAPP.Web.Models.Sys; using QMAPP.Common.Web.Util; using QMAPP.ServicesAgent; namespace QMAPP.Web.Controllers { /// /// 委托授权 /// public class EntrustController : QController { #region 列表页面加载 /// /// 列表页面加载 /// /// 结果 [HandleException] public ActionResult List(bool? callBack) { UserEntrustModel seachModel = new UserEntrustModel(); if (callBack == true) TryGetSelectBuffer(out seachModel); seachModel.rownumbers = false; seachModel.url = "/Entrust/GetList"; return View("UserEntrustList", seachModel); } /// /// 获取列表数据 /// /// 是否回调 /// 用户列表 [HandleException] public ActionResult GetList(bool? callBack) { UserEntrustModel seachModel = null; DataPage page = new DataPage(); UserEntrust condition = null; try { //获取查询对象 seachModel = GetModel(); #region 获取缓存值 if (callBack != null) { TryGetSelectBuffer(out seachModel); } else { //保存搜索条件 SetSelectBuffer(seachModel); } #endregion //获取前台分页设置信息 page = this.GetDataPage(seachModel); condition = CopyToModel(seachModel); if (string.IsNullOrEmpty(seachModel.STARTDATE) == false) { condition.STARTTIME = DateTime.Parse(seachModel.STARTDATE); } if (string.IsNullOrEmpty(seachModel.ENDDATE) == false) { condition.STARTTIME = DateTime.Parse(seachModel.ENDDATE); } QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); page = agent.InvokeServiceFunction("UserEntrustBLL_GetList", condition, page); DataGridResult result = new DataGridResult(); result.Total = page.RecordCount; result.Rows = JsonConvertHelper.GetDeserialize>(page.Result.ToString()); return Content(result.GetJsonSource()); } catch (Exception ex) { throw ex; } } #endregion #region 编辑载入 /// /// 编辑载入 /// /// 处理结果 [HandleException] public ActionResult Edit() { UserEntrustModel model = new UserEntrustModel(); string id = Request.QueryString["id"]; UserEntrust info = new UserEntrust(); try { if (string.IsNullOrEmpty(id) == false) { //修改获取原数据 info.PID = id; QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); info = agent.InvokeServiceFunction("UserEntrustBLL_Get",info); model = CopyToModel(info); } return View("UserEntrustEdit", model); } catch (Exception ex) { throw ex; } } #endregion #region 保存 /// /// 保存 /// /// /// 处理结果 [HttpPost] [HandleException] public ActionResult Save(UserEntrustModel saveModel) { UserEntrust info = null; try { info=CopyToModel(saveModel); info.AuthorityList = saveModel.SelectedPowers; QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); if (string.IsNullOrEmpty(info.PID) == true) { //新增 agent.InvokeServiceFunction("UserEntrustBLL_Insert", info); } else { //修改 agent.InvokeServiceFunction("UserEntrustBLL_Update", info); } return this.GetJsViewResult(string.Format("parent.List(1);parent.showTitle('{0}');parent.closeAppWindow1();" , AppResource.SaveMessge)); } catch (Exception ex) { throw ex; } } #endregion #region 删除 /// /// 删除用户 /// /// 结果 [HttpPost] [HandleException] public ActionResult Delete() { string selectKey = Request.Form["selectKey"]; string[] list = selectKey.Split(":".ToCharArray()); ArrayList infos = new ArrayList(); QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); try { //删除 foreach (string id in list) { infos.Add(id); } agent.InvokeServiceFunction("UserEntrustBLL_DeleteList", infos); SetMessage(AppResource.DeleteMessage); return List(true); } catch (Exception ex) { throw ex; } } #endregion #region 权限信息树 /// /// 权限信息树 /// /// 处理结果 public ActionResult GetTreePowers() { List list = new List(); List allPowers = null; PowerUtil pu = new PowerUtil(); List userPowers=new List(); pu.OwnPowers = new List(); string userID = Request.Params["userID"]; string id = Request.Params["id"]; try { if (string.IsNullOrEmpty(userID) == true) { return Content(TreeNodeResult.GetResultJosnS(list.ToArray())); } if (string.IsNullOrEmpty(id) == false) { UserEntrust ue = new UserEntrust(); ue.PID = id; ue.ENTRUSTUSERID = userID; //获取委托授权信息 QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); ue = agent.InvokeServiceFunction("UserEntrustBLL_Get", ue); //设置代理权限 foreach (UserAuthority power in ue.EUAuthoritys) { userPowers.Add(power.AuthorityID); } //设置已授权权限 foreach (T_QM_ENTRUSTAUTHORITY power in ue.Authoritys) { pu.OwnPowers.Add(new PowerInfo { PowerID = power.AUTHORITYID }); } } else { //获取用户信息 User info = new User(); info.UserID = userID; QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); info = agent.InvokeServiceFunction("UserManageBLL_Get", info); //设置代理权限 foreach (UserAuthority power in info.Authoritys) { userPowers.Add(power.AuthorityID); } } //获取当前登录系统的用户,全部权限信息 allPowers = new List(); List files = new List { "Main" }; //List files = new List { "Main", "MainData", "Report" }; foreach (string f in files) { List powers = pu.GetAllPowerInfos(MvcApplication.PhysicsRootPath + @"App_Data\"+f+"Power.xml"); allPowers.AddRange(powers); } allPowers = allPowers.Where(p => userPowers.IndexOf(p.PowerID) >= 0).ToList(); foreach (PowerInfo info in allPowers) { TreeNodeResult node = new TreeNodeResult(); node.Tid = info.PowerID; node.Ttext = info.PowerDes; node.TChecked = info.Selected; //添加子权限 this.BuildChildItems(node, info.ChildPowers, pu); list.Add(node); } return Content(TreeNodeResult.GetResultJosnS(list.ToArray())); } catch (Exception ex) { throw ex; } } /// /// 创建子权限 /// /// 父节点 /// 子权限 /// 已经选中的权限列表 private void BuildChildItems(TreeNodeResult parentNode, List childPowers, PowerUtil pu) { foreach (PowerInfo info in childPowers) { TreeNodeResult node = new TreeNodeResult(); node.Tid = info.PowerID; node.Ttext = info.PowerDes; node.TChecked = info.Selected; if (info.ChildPowers != null) { //添加子权限 this.BuildChildItems(node, info.ChildPowers, pu); } parentNode.AddchildNode(node); } } #endregion #region 业务权限设置页面加载 [HandleException] public ActionResult SetBusiPower() { UserEntrustPowerModel model = new UserEntrustPowerModel(); string id = Request.QueryString["id"]; UserEntrustBusiPower info = new UserEntrustBusiPower(); int seq = 0; if (string.IsNullOrEmpty(id) == false) { //修改获取原数据 info.PID = id; QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); info = agent.InvokeServiceFunction("UserEntrustBLL_GetBusiInfo", info); model = CopyToModel(info); //仓库权限 DateGridResult corpResult = new DateGridResult(); corpResult.Total = info.CorpPowers.Count; corpResult.Rows = new List(); seq = 1; model.SelectedCorp = ""; foreach (UserCorpPower corp in info.CorpPowers) { model.SelectedCorp += "," + corp.CORPID; corpResult.Rows.Add(new UserCorpModel { Seq = seq, CORPID = corp.CORPID, CORPCODE = corp.CORPCODE, CORPNAME = corp.CORPNAME, DeleteAction = "deleteCorp('" + corp.CORPID + "')" }); seq++; } if (model.SelectedCorp != "") model.SelectedCorp = model.SelectedCorp.Substring(1); model.CorpList = corpResult.GetJsonSource(); //路线权限 DateGridResult lineResult = new DateGridResult(); lineResult.Total = info.LinePowers.Count; lineResult.Rows = new List(); seq = 1; foreach (UserLinePower line in info.LinePowers) { lineResult.Rows.Add(new UserLineModel { Seq = seq, CORPID = line.CORPID, CORPNAME = line.CORPNAME, LINEID = line.LINEID, LINENO = line.LINENO, LINENAME = line.LINENAME, DeleteAction = "deleteLine('" + line.LINEID + "')" }); seq++; } model.LineList = lineResult.GetJsonSource(); //零件类别权限 DateGridResult matSortResult = new DateGridResult(); matSortResult.Total = info.MatSortPowers.Count; matSortResult.Rows = new List(); seq = 1; foreach (UserMatSortPower matSort in info.MatSortPowers) { matSortResult.Rows.Add(new UserMatSortModel { Seq = seq, MATSORTID = matSort.MATSORTID, MATSORTNO = matSort.MATSORTNO, MATSORTNAME = matSort.MATSORTNAME, DeleteAction = "deleteMatSort('" + matSort.MATSORTID + "')" }); seq++; } model.MatSortList = matSortResult.GetJsonSource(); //要货地权限 DateGridResult reqPlaceResult = new DateGridResult(); reqPlaceResult.Total = info.ReqPlacePowers.Count; reqPlaceResult.Rows = new List(); seq = 1; foreach (UserReqPlacePower reqPlace in info.ReqPlacePowers) { reqPlaceResult.Rows.Add(new UserReqPlaceModel { Seq = seq, PLACEDISID = reqPlace.PLACEDISID, PLACEDISNO = reqPlace.PLACEDISNO, DESCRIBE_SITE = reqPlace.DESCRIBE_SITE, DeleteAction = "deleteReqPlace('" + reqPlace.PLACEDISID + "')" }); seq++; } model.RequestPlaceList = reqPlaceResult.GetJsonSource(); //发货地权限 DateGridResult sendPlaceResult = new DateGridResult(); sendPlaceResult.Total = info.SendPlacePowers.Count; sendPlaceResult.Rows = new List(); seq = 1; foreach (UserSendPlacePower sendPlace in info.SendPlacePowers) { sendPlaceResult.Rows.Add(new UserSendPlaceModel { Seq = seq, SENDPLACEID = sendPlace.SENDPLACEID, SENDPLACENO = sendPlace.SENDPLACENO, SENDPLACENAME = sendPlace.SENDPLACENAME, DeleteAction = "deleteSendPlace('" + sendPlace.SENDPLACEID + "')" }); seq++; } model.SendPlaceList = sendPlaceResult.GetJsonSource(); } return View(model); } #endregion #region 保存业务权限 /// /// 保存业务权限 /// /// 业务权限信息 /// [ValidateInput(false)] [HandleException] public ActionResult BusiPowerSave(UserEntrustPowerModel model) { List corps = null; List lines = null; List matSorts = null; List reqPlaces = null; List sendPlaces = null; ServiceAgent wcfAgent = this.GetServiceAgent(); UserEntrustBusiPower info = new UserEntrustBusiPower(); try { info = CopyToModel(model); info.BusinessPowers = new List(); //绑定仓库权限 corps = JsonConvertHelper.GetDeserialize>(model.CorpList); foreach (UserCorpModel corp in corps) { ParaAuthorityPort c = new ParaAuthorityPort(); c.PARATYPE = "1"; c.PARAVALUE = corp.CORPID; info.BusinessPowers.Add(c); } //绑定路线权限 lines = JsonConvertHelper.GetDeserialize>(model.LineList); foreach (UserLineModel line in lines) { ParaAuthorityPort l = new ParaAuthorityPort(); l.PARATYPE = "2"; l.PARAVALUE = line.LINEID; info.BusinessPowers.Add(l); } //绑定零件类别权限 matSorts = JsonConvertHelper.GetDeserialize>(model.MatSortList); foreach (UserMatSortModel matSort in matSorts) { ParaAuthorityPort m = new ParaAuthorityPort(); m.PARATYPE = "3"; m.PARAVALUE = matSort.MATSORTID; info.BusinessPowers.Add(m); } //绑定要货地权限 reqPlaces = JsonConvertHelper.GetDeserialize>(model.RequestPlaceList); foreach (UserReqPlaceModel reqPlace in reqPlaces) { ParaAuthorityPort m = new ParaAuthorityPort(); m.PARATYPE = "4"; m.PARAVALUE = reqPlace.PLACEDISID; info.BusinessPowers.Add(m); } //绑定发货地权限 sendPlaces = JsonConvertHelper.GetDeserialize>(model.SendPlaceList); foreach (UserSendPlaceModel sendPlace in sendPlaces) { ParaAuthorityPort m = new ParaAuthorityPort(); m.PARATYPE = "5"; m.PARAVALUE = sendPlace.SENDPLACEID; info.BusinessPowers.Add(m); } wcfAgent.InvokeServiceFunction("UserEntrustBLL_SaveBusinessPower", info); return this.GetJsViewResult(string.Format("parent.List(1);parent.showTitle('{0}');parent.closeAppWindow1();" , AppResource.SaveMessge)); } catch (Exception ex) { throw ex; } } #endregion #region 导出excel /// /// 导出excel /// /// 结果 [HttpPost] [HandleException] public ActionResult ExportExcel() { UserEntrustModel seachModel = null; UserEntrust condition = null; DataTable exportDt = new DataTable(); ServiceAgent wcfAgent = this.GetServiceAgent(); PowerUtil pu = new PowerUtil(); string selectKey = Request.Form["selectKey"]; try { //获取查询对象 seachModel = GetModel(); condition = CopyToModel(seachModel); //获取数据 exportDt = wcfAgent.InvokeServiceFunction("UserEntrustBLL_GetExportData", condition); //根据所选信息进行导出 if (!String.IsNullOrEmpty(selectKey)) { DataView dv = new DataView(exportDt); string strWhere = ""; string[] list = selectKey.Split(":".ToCharArray()); foreach (string ID in list) { strWhere += " PID='" + ID + "' or"; } if (strWhere != "") { strWhere = strWhere.Remove((strWhere.Length - 2), 2); } dv.RowFilter = strWhere; exportDt = dv.ToTable(); } //设置导出的时间格式. exportDt.Columns.Add("CREATEDATESHOW"); exportDt.Columns.Add("UPDATEDATESHOW"); exportDt.Columns.Add("STARTTIMESHOW"); exportDt.Columns.Add("ENDTIMESHOW"); 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"); } if (dr["STARTTIME"] != null) { dr["STARTTIMESHOW"] = Convert.ToDateTime(dr["STARTTIME"]).ToString("yyyy-MM-dd hh:mm:ss"); } if (dr["ENDTIME"] != null) { dr["ENDTIMESHOW"] = Convert.ToDateTime(dr["ENDTIME"]).ToString("yyyy-MM-dd hh:mm:ss"); } } //导出 QMFrameWork.WebUI.Util.IEFileTool efTool = new QMFrameWork.WebUI.Util.IEFileTool(); return efTool.GetExcelFileResult("EntrustList", "委托信息.xls", exportDt); } catch (Exception ex) { throw ex; } } #endregion } }