/// <summary> 解析menu字段</summary> /// <param name="nodeList">xml节点</param> /// <returns>Menu实体列表</returns> private static List <MenuModel> GetMenu(XmlElement nodeList, MenuResponseModel menuResponse) { var menuList = new List <MenuModel>(); XmlNodeList xmlNodeList = nodeList.SelectNodes("menu"); if (xmlNodeList != null) { for (var j = 0; j < xmlNodeList.Count; j++) { var menu = new MenuModel(); var menunode = (XmlElement)xmlNodeList[j]; if (menunode == null) { continue; } menu.id = menunode.GetAttribute("id"); menu.Name = menunode.GetAttribute("name"); menu.Title = menunode.GetAttribute("title"); menu.Url = menunode.GetAttribute("url"); menu.OrderNo = Convert.ToInt32(menunode.GetAttribute("orderNo")); menu.Mtype = Convert.ToInt32(menunode.GetAttribute("mtype")); menu.children = GetMenu(menunode, menuResponse); if (menu.Mtype > 0) { menuList.Add(menu); } string url = GetMenuUrl(menu.Url); if (!string.IsNullOrWhiteSpace(url) && !menuResponse.MenuUrl.ContainsKey(url)) { menuResponse.MenuUrl.Add(url, menu); } } } return(menuList); }
/// <summary> 获取用户信息</summary> /// <param name="request">请求字段</param> /// <param name="message">错误信息</param> /// <returns>响应信息</returns> public MenuResponseModel GetUserInfo(MenuRequest request, out ErrorMessage message) { //var item = HttpUtil.PostResponse(request.ServiceUrl, request.PostUserIdData, "gb2312", "application/x-www-form-urlencoded"); var item = HttpHelper.PostRequest(request.ServiceUrl, request.PostData, 3000, "gb2312"); XmlNodeList userNodes; var root = CheckUserInfo(item, out userNodes, out message);//检查用户数据 if (null == root) { return(null); } var menuResponse = new MenuResponseModel(); var userInfo = new MenuUserModel(); for (var i = 0; i < userNodes.Count; i++) { var result = (XmlElement)userNodes[i]; if (result == null) { continue; } // ReSharper disable PossibleNullReferenceException userInfo.Name = result["userId"].InnerText; userInfo.Name = result["name"].InnerText; userInfo.JobNumber = result["jobNumber"].InnerText; userInfo.Gender = result["gender"].InnerText; userInfo.IdCard = result["IdCard"].InnerText; userInfo.DepartName = result["departName"].InnerText; userInfo.CrtTime = result["crtTime"].InnerText; userInfo.MdfTime = result["mdfTime"].InnerText; userInfo.Enable = result["enable"].InnerText; userInfo.Remark = result["remark"].InnerText; userInfo.DptName = result["dptName"].InnerText; // ReSharper restore PossibleNullReferenceException } return(menuResponse); }
/// <summary>获取用户和菜单信息</summary> /// <param name="request">请求字段</param> /// <param name="message">错误信息</param> /// <returns>响应信息</returns> public MenuResponseModel GetMenuAndUserInfo(MenuRequest request, out ErrorMessage message) { //var item = HttpUtil.PostResponse(request.ServiceUrl, request.PostData, "gb2312", "application/x-www-form-urlencoded"); var item = HttpHelper.PostRequest(request.ServiceUrl, request.PostData, 3000, "gb2312"); XmlNodeList menuNodes; XmlNodeList userNodes; var root = Check(item, out menuNodes, out message, out userNodes);//检查数据 if (null == root) { return(null); } var menuResponse = new MenuResponseModel(); var userInfo = new MenuUserModel(); for (var i = 0; i < userNodes.Count; i++) { var result = (XmlElement)userNodes[i]; if (result == null) { continue; } userInfo.UserId = Convert.ToInt32(result["userId"].InnerText); userInfo.Name = result["name"].InnerText; userInfo.JobNumber = result["jobNumber"].InnerText; userInfo.Gender = result["gender"].InnerText; userInfo.IdCard = result["IdCard"].InnerText; userInfo.DepartName = result["departName"].InnerText; userInfo.DeptId = result["dptid"].InnerText; } var menulist = new List <MenuModel>(); for (var i = 0; i < menuNodes.Count; i++) { var result = (XmlElement)menuNodes[i]; if (result == null) { continue; } XmlNodeList xmlNodeList = result.SelectNodes("menu"); for (var j = 0; j < xmlNodeList.Count; j++) { var menu = new MenuModel(); var menunode = (XmlElement)xmlNodeList[j]; if (menunode == null) { continue; } menu.id = menunode.GetAttribute("id"); menu.Name = menunode.GetAttribute("name"); menu.Title = menunode.GetAttribute("title"); menu.Url = menunode.GetAttribute("url"); menu.OrderNo = Convert.ToInt32(menunode.GetAttribute("orderNo")); menu.children = GetMenu(menunode, menuResponse); menulist.Add(menu); string url = GetMenuUrl(menu.Url); if (!string.IsNullOrWhiteSpace(url) && !menuResponse.MenuUrl.ContainsKey(url)) { menuResponse.MenuUrl.Add(url, menu); } } } message = null; menuResponse.MenuEntity = menulist; menuResponse.UserEntity = userInfo; return(menuResponse); }