using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; 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; using QMFrameWork.Common.Serialization; using QMAPP.Common.Web.Models; using QMAPP.Entity; using System.Data; namespace QMAPP.Web.Controllers { /// /// 用户管理 /// [SessionState(System.Web.SessionState.SessionStateBehavior.ReadOnly)] public class UserController : QController { #region 用户列表 /// /// 加载用户列表 /// /// 结果 [HandleException] public ActionResult UserList(bool? callBack) { string templateID = Request.QueryString["templateID"]; UserListModel seachModel = new UserListModel(); if (callBack == true) TryGetSelectBuffer(out seachModel); else seachModel.ActivateFlg = "1"; seachModel.rownumbers = false; seachModel.url = "/User/GetList"; //#region 应用查询模板 //seachModel = this.ApplyQueryTemplate("UserList", seachModel, templateID); //#endregion return View("UserList", seachModel); } /// /// 获取用户信息列表 /// /// 是否回调 /// 用户信息列表 [HandleException] public ActionResult GetList(bool? callBack) { UserListModel seachModel = new UserListModel(); DataPage page = new DataPage(); User condition = null; try { //获取查询对象 seachModel.ActivateFlg = "1"; seachModel = GetModel(seachModel); #region 获取缓存值 if (callBack != null) { TryGetSelectBuffer(out seachModel); } else { //保存搜索条件 SetSelectBuffer(seachModel); } #endregion //获取前台分页控件的分页大小 page = this.GetDataPage(seachModel); //获取数据 condition = CopyToModel(seachModel); QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); page = agent.InvokeServiceFunction("UserManageBLL_GetList", condition, page); //转换结果格式 DataGridResult result = new DataGridResult(); result.Total = page.RecordCount; result.Rows = JsonConvertHelper.GetDeserialize>(page.Result.ToString()); //显示用户类别名称 Dictionary utDicts = null; QMFrameWork.Common.Util.ModelDictionaryHandler.TryGetModelDictionary("UserType", out utDicts); foreach (User u in result.Rows) { if (string.IsNullOrEmpty(u.UserType) == true) continue; if (utDicts.ContainsKey(u.UserType) == false) continue; u.UserType = utDicts[u.UserType]; } return Content(result.GetJsonSource()); } catch (Exception ex) { throw ex; } } #endregion #region 编辑 /// /// 编辑载入 /// /// 处理结果 [HandleException] public ActionResult UserEdit() { UserModel model = new UserModel(); string UserID = Request.Params["UserID"]; User user = new User(); try { if (string.IsNullOrEmpty(UserID) == false) { //修改获取原数据 user.UserID = UserID; QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); user = agent.InvokeServiceFunction("UserManageBLL_Get", user); model = CopyToModel(user); if (string.IsNullOrEmpty(model.OrgaID)==false) model.OrgaID = model.OrgaID.Trim(); model.isEdit = "true"; model.CkActivateFlg = user.ActivateFlg == "1" ? true : false; } else { model.PassWord = "qm"; model.RepartPassWord = "qm"; model.UserType = "PU"; model.CkActivateFlg = true; } return View(model); } catch (Exception ex) { throw ex; } } #region 组织机构信息下拉菜单 public ActionResult GetOrgaList() { Orgaization orgaModel = new Orgaization(); List list = new List(); QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); list = agent.InvokeServiceFunction>("UserManageBLL_GetUserOrgaList", ""); ComboboxResult model = new ComboboxResult(); foreach (Orgaization o in list) { model.Add(new ComboboxItem { ID = o.OrgaID, Text = o.OrgaDESC }); } return Content(model.ToString()); } public ActionResult GetOrgaListNew() { Orgaization orgaModel = new Orgaization(); List list = new List(); QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); list = agent.InvokeServiceFunction>("UserManageBLL_GetUserOrgaList", ""); //ComboboxResult model = new ComboboxResult(); //foreach (Orgaization o in list) //{ // model.Add(new ComboboxItem { ID = o.OrgaID, Text = o.OrgaDESC }); //} //return Content(model.ToString()); return Content(QMFrameWork.Common.Serialization.JsonConvertHelper.GetSerializes(list)); } #endregion #region 角色信息树 /// /// 角色信息树 /// /// 处理结果 public ActionResult GetTreeRoles() { List list = new List(); Role role = new Role(); PowerUtil pu = new PowerUtil(); pu.OwnRoles = new List(); //选择的用户编号 string userID = Request.QueryString["userID"]; string organID = Request.QueryString["organID"]; try { if (string.IsNullOrEmpty(organID) == true) { return Content(TreeNodeResult.GetResultJosnS(list.ToArray())); } if (string.IsNullOrEmpty(userID) == true) { userID= AccountController.GetLoginInfo().UserID; } //获取角色信息 User user = new User(); user.UserID = userID; QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); user = agent.InvokeServiceFunction("UserManageBLL_Get", user); if (user != null) { foreach (UserRole userrole in user.Roles) { pu.OwnRoles.Add(new Role { RoleID = userrole.RoleID, RoleDESC = userrole.RoleDESC }); } } //获取所选机构对应角色 role.Roles = agent.InvokeServiceFunction>("RoleManageBLL_GetRolesByOrgan", organID); foreach (Role singlerole in role.Roles) { TreeNodeResult node = new TreeNodeResult(); node.Tid = singlerole.RoleID; node.Ttext = singlerole.RoleDESC; //循环已经存在的角色,如果去的也页面是新建画面 if (string.IsNullOrEmpty(Request.Params["userID"]) != true) { foreach (Role selected in pu.OwnRoles) { //如果当前角色在选中范围内,结束循环,否者继续 if (selected.RoleID == singlerole.RoleID) { singlerole.Selected = true; break; } else { singlerole.Selected = false; } } } node.TChecked = singlerole.Selected; list.Add(node); } return Content(TreeNodeResult.GetResultJosnS(list.ToArray())); } catch (Exception ex) { throw ex; } } #endregion #region 权限信息树 /// /// 权限信息树 /// /// 处理结果 public ActionResult GetTreePowers() { List list = new List(); List powers = null; PowerUtil pu = new PowerUtil(); pu.OwnPowers = new List(); string userID = Request.Params["userID"]; string powerFile = null; string systemID = Request.QueryString["SystemID"]; try { if (string.IsNullOrEmpty(userID) == false) { //获取用户信息 User user = new User(); user.UserID = userID; //UserManageBLL userBll = BLLFactory.CreateBLL(); //user = userBll.Get(user); QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); user = agent.InvokeServiceFunction("UserManageBLL_Get", user); foreach (UserAuthority power in user.OptionAuthority) { pu.OwnPowers.Add(new PowerInfo { PowerID = power.AuthorityID }); } } //获取系统权限信息 if (systemID == null) systemID = "Main"; powerFile = MvcApplication.PhysicsRootPath + @"App_Data\" + systemID + "Power.xml"; powers = pu.GetAllPowerInfos(powerFile); foreach (PowerInfo info in powers) { 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 当前用户所具有的权限信息树 /// /// 当前用户所具有的权限信息树 /// /// 处理结果 public ActionResult GetTreeAllPowers() { List list = new List(); List powers = null; PowerUtil pu = new PowerUtil(); pu.OwnPowers = new List(); string userID = Request.Params["userID"]; //ServiceAgent wcfAgent = this.GetServiceAgent(); try { if (string.IsNullOrEmpty(userID) == false) { //获取用户信息 User user = new User(); user.UserID = userID; //UserManageBLL userBll = BLLFactory.CreateBLL(); //user = userBll.Get(user); QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); user = agent.InvokeServiceFunction("UserManageBLL_Get", user); foreach (UserAuthority power in user.Authoritys) { //如果当前有权限,那么判断当前权限的上级是否在内存中,如果不在那么添加 //------------------2013.11.13 add start------------------------- if (!pu.OwnPowers.Cast().Any(i => i.PowerID == power.AuthorityID.Substring(0, 2) + "000000")) { pu.OwnPowers.Add(new PowerInfo { PowerID = power.AuthorityID.Substring(0, 2) + "000000" }); } if (!pu.OwnPowers.Cast().Any(i => i.PowerID == power.AuthorityID.Substring(0, 4) + "0000")) { pu.OwnPowers.Add(new PowerInfo { PowerID = power.AuthorityID.Substring(0, 4) + "0000" }); } if (!pu.OwnPowers.Cast().Any(i => i.PowerID == power.AuthorityID.Substring(0, 6) + "00")) { pu.OwnPowers.Add(new PowerInfo { PowerID = power.AuthorityID.Substring(0, 6) + "00" }); } //------------------2013.11.13 add end------------------------- pu.OwnPowers.Add(new PowerInfo { PowerID = power.AuthorityID }); pu.OwnPowers = pu.OwnPowers.OrderBy(i => i.PowerID).ToList(); } } //获取当前登录系统的用户,全部权限信息 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; node.TChecked = info.Selected; //添加子权限 this.AllBuildChildItems(node, info.ChildPowers, pu); //如果当前有子权限,那么选择上级权限 if (node.Tchildren.Length > 0) { list.Add(node); } } return Content(TreeNodeResult.GetResultJosnS(list.ToArray())); } catch (Exception ex) { throw ex; } } /// /// 创建当前用户所有的子权限 /// /// 父节点 /// 子权限 /// 已经选中的权限列表 private void AllBuildChildItems(TreeNodeResult parentNode, List 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.AllBuildChildItems(node, info.ChildPowers, pu); } //如果当前子权限被选中,那么输出,否者不输出子权限。 if (node.TChecked) { parentNode.AddchildNode(node); } } } #endregion #region 保存 /// /// 保存 /// /// /// 处理结果 [HttpPost] [HandleException] public ActionResult UserSave(UserModel saveModel) { User user = null; QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); try { user = CopyToModel(saveModel); user.ActivateFlg = saveModel.CkActivateFlg == true ? "1" : "0"; User tmpuser = new User(); if (string.IsNullOrEmpty(saveModel.isEdit) == true) { //tmpuser = userBll.GetLoginUser(user); tmpuser = agent.InvokeServiceFunction("UserManageBLL_GetLoginUser", user); if (tmpuser != null && tmpuser.UserName != "") { SetMessage("当前保存的登陆账号已经存在,请修改!"); return View("UserEdit", saveModel); } } //处理所选角色 string[] roles = null; if (saveModel.SelectedRoles != null) { roles = saveModel.SelectedRoles.Split(":".ToArray()); user.Roles = new List(); foreach (string role in roles) { user.Roles.Add(new UserRole { UserID = user.UserID, RoleID = role, CreateTime = DateTime.Now, UpdateTime = DateTime.Now, CreateUser = AccountController.GetLoginInfo().UserID, UpdateUser = AccountController.GetLoginInfo().UserID }); } } string powerList = ""; powerList += string.IsNullOrEmpty(saveModel.SelectedPowers1) == false ? saveModel.SelectedPowers1 : ""; powerList += string.IsNullOrEmpty(saveModel.SelectedPowers2) == false ? ":" + saveModel.SelectedPowers2 : ""; powerList += string.IsNullOrEmpty(saveModel.SelectedPowers3) == false ? ":" + saveModel.SelectedPowers3 : ""; powerList += string.IsNullOrEmpty(saveModel.SelectedPowers4) == false ? ":" + saveModel.SelectedPowers4 : ""; powerList += string.IsNullOrEmpty(saveModel.SelectedPowers5) == false ? ":" + saveModel.SelectedPowers5 : ""; //处理所选权限 string[] Authoritys = null; user.Authoritys = new List(); if (string.IsNullOrEmpty(powerList)==false) { Authoritys = powerList.Split(":".ToArray()); foreach (string authority in Authoritys) { if (string.IsNullOrEmpty(authority) == true) { continue; } bool isExists = user.Authoritys.Exists(p => p.AuthorityID == authority); if (isExists == true) continue; user.Authoritys.Add(new UserAuthority { UserID = user.UserID, AuthorityID = authority, OrgaID = user.OrgaID, CreateTime = DateTime.Now, UpdateTime = DateTime.Now, CreateUser = AccountController.GetLoginInfo().UserID, UpdateUser = AccountController.GetLoginInfo().UserID }); } } //保存 if (string.IsNullOrEmpty(saveModel.isEdit) == true) { //新增 agent.InvokeServiceFunction("UserManageBLL_Insert", user); } else { //修改 agent.InvokeServiceFunction("UserManageBLL_Update", user); } return this.GetJsViewResult(string.Format("parent.List(1);parent.showTitle('{0}');parent.closeAppWindow1();" , AppResource.SaveMessge)); } catch (Exception ex) { throw ex; } } #endregion #endregion #region 删除 /// /// 删除用户信息 /// /// 结果 [HttpPost] [HandleException] public ActionResult UserDelete() { string selectKey = Request.Form["selectKey"]; string[] arraydata = selectKey.Split(":".ToCharArray()); //UserManageBLL userBll = null; 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("UserManageBLL_BatchDelete", alist); if (alist.Count != count) { if (count == 0) { SetMessage("选中的用户已激活,无法删除。"); } else { SetMessage(string.Format("删除完成(其中存在{0}个已激活的用户,无法删除)。", alist.Count - count)); } } else { SetMessage(AppResource.DeleteMessage); } return UserList(true); } catch (Exception ex) { throw ex; } } #endregion #region 设置密码 /// /// 设置密码载入 /// /// [HandleException] public ActionResult SetPassword() { string userID = Request.QueryString["userID"]; UserModel model = new UserModel(); User user = new User(); List selectRoles = new List(); //UserManageBLL userBll = null; try { if (string.IsNullOrEmpty(userID) == false) { //修改指定用户 user.UserID = userID; } else { //修改当前用户 user.UserID = AccountController.GetLoginInfo().UserID; } //获取原信息 //userBll = BLLFactory.CreateBLL(); //user = userBll.Get(user); QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); user = agent.InvokeServiceFunction("UserManageBLL_Get", user); user.PassWord = null; model = CopyToModel(user); return View(model); } catch (Exception ex) { throw ex; } } /// /// 设置密码 /// /// 用户密码信息 /// [HttpPost] [HandleException] public ActionResult SetPassword(UserModel model) { User user = null; try { user = CopyToModel(model); //userBll = BLLFactory.CreateBLL(); //userBll.SetPassWord(user); QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); agent.InvokeServiceFunction("UserManageBLL_SetPassWord", user); return this.GetJsViewResult(string.Format("parent.showTitle('{0}');parent.closeAppWindow1();", "修改成功。")); } catch (Exception ex) { throw ex; } } #endregion #region 获取用户列表 [HandleException] public ActionResult GetUserList() { try { List list = null; QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); list = agent.InvokeServiceFunction>("UserManageBLL_GetAllUser",new User()); ComboboxResult model = new ComboboxResult(); foreach (User o in list) { model.Add(new ComboboxItem { ID = o.UserID, Text = o.UserName }); } return Content(model.ToString()); } catch (Exception ex) { throw ex; } } #endregion #region 业务权限设置 [HandleException] public ActionResult SetUserBusiPower() { UserPowerModel model = new UserPowerModel(); string userID = Request.Params["userID"]; ServiceAgent wcfAgent = this.GetServiceAgent(); UserBusinessPower info = new UserBusinessPower(); int seq = 0; try { //调用服务获取数据 info.UserID = userID; info = wcfAgent.InvokeServiceFunction("UserManageBLL_GetBusinessPower", 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); } catch (Exception ex) { throw ex; } } #endregion #region 保存业务权限 /// /// 保存业务权限 /// /// 业务权限信息 /// [ValidateInput(false)] [HandleException] public ActionResult UserBusiPowerSave(UserPowerModel model) { List corps = null; List lines = null; List matSorts = null; List reqPlaces = null; List sendPlaces = null; ServiceAgent wcfAgent = this.GetServiceAgent(); UserBusinessPower info = new UserBusinessPower(); try { info = CopyToModel(model); //绑定仓库权限 corps = JsonConvertHelper.GetDeserialize>(model.CorpList); info.CorpPowers = new List(); foreach (UserCorpModel corp in corps) { UserCorpPower c = new UserCorpPower(); c.CORPID = corp.CORPID; info.CorpPowers.Add(c); } //绑定路线权限 lines = JsonConvertHelper.GetDeserialize>(model.LineList); info.LinePowers = new List(); foreach (UserLineModel line in lines) { UserLinePower l = new UserLinePower(); l.LINEID = line.LINEID; l.CORPID = line.CORPID; info.LinePowers.Add(l); } //绑定零件类别权限 matSorts = JsonConvertHelper.GetDeserialize>(model.MatSortList); info.MatSortPowers = new List(); foreach (UserMatSortModel matSort in matSorts) { UserMatSortPower m = new UserMatSortPower(); m.MATSORTID = matSort.MATSORTID; info.MatSortPowers.Add(m); } //绑定要货地权限 reqPlaces = JsonConvertHelper.GetDeserialize>(model.RequestPlaceList); info.ReqPlacePowers = new List(); foreach (UserReqPlaceModel reqPlace in reqPlaces) { UserReqPlacePower m = new UserReqPlacePower(); m.PLACEDISID = reqPlace.PLACEDISID; info.ReqPlacePowers.Add(m); } //绑定发货地权限 sendPlaces = JsonConvertHelper.GetDeserialize>(model.SendPlaceList); info.SendPlacePowers = new List(); foreach (UserSendPlaceModel sendPlace in sendPlaces) { UserSendPlacePower m = new UserSendPlacePower(); m.SENDPLACEID = sendPlace.SENDPLACEID; info.SendPlacePowers.Add(m); } wcfAgent.InvokeServiceFunction("UserManageBLL_SaveBusinessPower", info); return this.GetJsViewResult(string.Format("parent.List(1);parent.showTitle('{0}');parent.closeAppWindow1();" , AppResource.SaveMessge)); } catch (Exception ex) { throw ex; } } #endregion #region 更新路线视图 /// /// 更新路线视图 /// /// 仓库主键 /// public ActionResult UpdateDivLine(string corpID) { UserPowerModel model = new UserPowerModel(); try { model.CorpID = corpID; return PartialView("LineInputUserControl", model); } catch (Exception ex) { throw ex; } } #endregion #region 导出excel /// /// 导出excel /// /// 结果 [HttpPost] [HandleException] public ActionResult ExportExcel() { UserListModel seachModel = null; User condition = null; DataTable exportDt = new DataTable(); QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); PowerUtil pu = new PowerUtil(); string selectKey = Request.Form["selectKey"]; try { //获取查询对象 seachModel = GetModel(); condition = CopyToModel(seachModel); //获取数据 exportDt = agent.InvokeServiceFunction("UserManageBLL_GetExportData", condition); if (selectKey != "") { DataView dv = new DataView(exportDt); string strWhere = ""; string[] list = selectKey.Split(":".ToCharArray()); foreach (string UserID in list) { strWhere += " UserID='" + UserID + "' or"; } if (strWhere != "") { strWhere = strWhere.Remove((strWhere.Length - 2), 2); } dv.RowFilter = strWhere; exportDt = dv.ToTable(); } //导出 QMFrameWork.WebUI.Util.IEFileTool efTool = new QMFrameWork.WebUI.Util.IEFileTool(); return efTool.GetExcelFileResult("UserList", "用户信息.xls", exportDt); } catch (Exception ex) { throw ex; } } #endregion #region 导入excel /// /// 导入excel /// /// 结果 [HttpPost] [HandleException] public ActionResult ImportExcel() { string fileName = Request.Form["fileName"]; ServiceAgent wcfAgent = this.GetServiceAgent(); ImportMessage dtResult = new ImportMessage(); List list = new List(); DataResult serviceResult = null; DataTable tpdt = new DataTable(); try { QMFrameWork.WebUI.Util.IEFileTool efTool = new QMFrameWork.WebUI.Util.IEFileTool(); DataTable dt = null; dt = this.GetTableByExcel("UserList", fileName, dt); #region 去除重复 var query = from t in dt.AsEnumerable() group t by new { t1 = t.Field("LOGINUSERID") } into m select new { LOGINUSERID = m.Key.t1, EMPLOYEENO = m.Last().Field("EMPLOYEENO"), USERNAME = m.Last().Field("USERNAME"), ORGADESC = m.Last().Field("ORGADESC"), USERTYPE = m.Last().Field("USERTYPE"), ACTIVATEFLG = m.Last().Field("ACTIVATEFLG"), TEL = m.Last().Field("TEL"), EMAIL = m.Last().Field("EMAIL"), InfoError = m.Last().Field("InfoError") }; tpdt = dt.Clone(); foreach (var item in query.ToList()) { DataRow dr = tpdt.NewRow(); dr["LOGINUSERID"] = item.LOGINUSERID; dr["EMPLOYEENO"] = item.EMPLOYEENO; dr["USERNAME"] = item.USERNAME; dr["ORGADESC"] = item.ORGADESC; dr["USERTYPE"] = item.USERTYPE; dr["ACTIVATEFLG"] = item.ACTIVATEFLG; dr["TEL"] = item.TEL; dr["EMAIL"] = item.EMAIL; dr["InfoError"] = item.InfoError; tpdt.Rows.Add(dr); } #endregion //转换格式 list = QMFrameWork.Common.Util.BindHelper.ConvertToList(tpdt).ToList(); serviceResult = wcfAgent.InvokeServiceFunction>("UserManageBLL_GetImportData", list); if (serviceResult.Ex != null) { throw serviceResult.Ex; } if (serviceResult.Result.failureNum != 0) { foreach (RowError error in serviceResult.Result.Errors) { tpdt.Rows[error.Key - 1]["InfoError"] = error.Value; } ImportMessageModel model = new ImportMessageModel(); model.InfoName = "User"; model.ReturnUrl = "/User/UserList?callBack=true"; model.Message = serviceResult.Result; model.ErrorDt = tpdt; return new MessageOutputController().OutputImportMessage(model); } else { // 添加:通过消息代码获取资源文件值 李鹏飞 2015-03-20 开始 SetMessage(GetResourceValueByCode(serviceResult.MsgCode) + ",如下:
" + "新增" + serviceResult.Result.insertNum + "条," + "更新" + serviceResult.Result.updateNum + "条" ); // 添加:通过消息代码获取资源文件值 李鹏飞 2015-03-20 结束 return UserList(true); } } catch (Exception ex) { throw ex; } finally { System.IO.File.Delete(MvcApplication.TempPath + fileName); } } #endregion } }