using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using QMFrameWork.WebUI.DataSource; using QMFrameWork.WebUI.Attribute; using QMAPP.Web.Models.Sys; using QMFrameWork.WebUI.Menu; using QMAPP.Common.Web.Util; using System.Text; using QMFrameWork.Common.MLanguage; using System.Configuration; using QMAPP.Common.Web.Controllers; using QMFrameWork.Data; using QMAPP.Entity.Sys; using System.Xml.Linq; using System.Reflection; using System.Web.Mvc.Html; using System.Web.Script.Serialization; using Newtonsoft.Json; using System.IO; using QMFrameWork.Common.Serialization; namespace QMAPP.Web.Controllers { /// /// 在线帮助控制器类 /// public class OnLineHelpController : QController { /// /// 当前菜单名称 /// private string _currentMenuName = string.Empty; /// /// 帮助页面名称,针对menu菜单的Action标签 /// private string _currentPageName = string.Empty; /// /// 帮助model名称,针对menu的菜单ViewModel标签 /// private string _currentModelName = string.Empty; /// /// 编辑帮助信息,将页面级在线帮助传入view /// /// 菜单id /// 结果 [HandleException] public ActionResult Edit(string menuId) { //获取页面级帮助 GetProgramVMType(menuId); OnLineHelpModel pageModel = new OnLineHelpModel(); OnlineHelp helpInfo = new OnlineHelp(); helpInfo.MENUID = menuId; helpInfo.KIND = "P";//页面级标志为“P” helpInfo.PAGENAME = _currentPageName; helpInfo.MODELNAME = _currentModelName; if (!string.IsNullOrEmpty(menuId)) { QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); helpInfo = agent.InvokeServiceFunction("OnlineHelpBLL_Get", helpInfo); pageModel = CopyToModel(helpInfo); pageModel.PAGENAME = _currentPageName; pageModel.MODELNAME = _currentModelName; } try { return View(pageModel); } catch (Exception ex) { throw ex; } } /// /// 获取页面级帮助信息 /// /// 菜单ID /// 返回页面帮助信息 public string GetPageHelp(string menuId) { string ret =""; OnLineHelpModel pageModel = new OnLineHelpModel(); OnlineHelp helpInfo = new OnlineHelp(); helpInfo.MENUID = menuId; helpInfo.KIND = "P";//页面级标志为“P” helpInfo.PAGENAME = _currentPageName; helpInfo.MODELNAME = _currentModelName; if (!string.IsNullOrEmpty(menuId)) { QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); helpInfo = agent.InvokeServiceFunction("OnlineHelpBLL_Get", helpInfo); pageModel = CopyToModel(helpInfo); pageModel.PAGENAME = _currentPageName; pageModel.MODELNAME = _currentModelName; ret = pageModel.HELPCONTENT; } return ret; } /// /// 获取字段级帮助集合的json字符串 /// /// 菜单ID /// public string GetColumnHelps(string menuId) { List model = new List(); if (!string.IsNullOrEmpty(menuId)) { System.Type viewModelT = GetProgramVMType(menuId); List columns = new List(); if (viewModelT != null) { //生成字段明细数据 PropertyInfo[] pArray = viewModelT.GetProperties(); //以及存在的字段级帮助集合 List existHelps = new List(); //查询条件 OnlineHelp conditon = new OnlineHelp(); conditon.MENUID = menuId; conditon.KIND = "C";//字段级帮助标识为“C” QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); existHelps = agent.InvokeServiceFunction>("OnlineHelpBLL_GetList", conditon); foreach (PropertyInfo item in pArray) { object[] attrs = item.GetCustomAttributes(typeof(QMFrameWork.WebUI.Attribute.InputTypeAttribute), false); foreach (object attr in attrs) { QMFrameWork.WebUI.Attribute.InputTypeAttribute attrItem = (QMFrameWork.WebUI.Attribute.InputTypeAttribute)attr; if (attrItem.DataType == QMFrameWork.WebUI.inputType.text) { OnlineHelp fieldModel = new OnlineHelp(); fieldModel.PAGENAME = _currentPageName; fieldModel.COLUMNANME = item.Name; fieldModel.MENUID = menuId; fieldModel.MODELNAME = _currentModelName; fieldModel.KIND = "C";//字段级帮助标记为“C” OnlineHelp tempHelp = new OnlineHelp(); tempHelp = existHelps.Find(p => p.COLUMNANME == fieldModel.COLUMNANME); if (tempHelp != null) { fieldModel.HELPCONTENT = tempHelp.HELPCONTENT; fieldModel.PID = tempHelp.PID; fieldModel.PAGENAME = _currentPageName; fieldModel.MODELNAME = _currentModelName; } else { fieldModel.HELPCONTENT = string.Empty; fieldModel.PID = string.Empty; } model.Add(fieldModel); } } } } } JavaScriptSerializer js = new JavaScriptSerializer(); string ret = js.Serialize(model); return ret; } #region 保存 /// /// 保存页面级帮助 /// /// 页面级帮助信息 /// [ValidateInput(false)] public ActionResult SavePageHelp(OnLineHelpModel saveModel) { OnlineHelp helpInfo = new OnlineHelp(); List items = new List(); JavaScriptSerializer js = new JavaScriptSerializer(); List colHelpInfos = js.Deserialize>(saveModel.FieldsJson); if (colHelpInfos != null && colHelpInfos.Count > 0) { items.AddRange(colHelpInfos); } int r = 0; try { helpInfo = CopyToModel(saveModel); QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent(); if (string.IsNullOrEmpty(saveModel.PID) == false) { //修改 helpInfo.PID = saveModel.PID; } helpInfo.MODELNAME = (saveModel.MODELNAME==null? "":saveModel.MODELNAME); helpInfo.PAGENAME = (saveModel.PAGENAME == null ? "" : saveModel.PAGENAME); helpInfo.COLUMNANME = string.Empty; helpInfo.KIND = "P"; helpInfo.HELPCONTENT = saveModel.HELPCONTENT; items.Add(helpInfo); r = agent.InvokeServiceFunction("OnlineHelpBLL_Save", items); if (string.IsNullOrEmpty(saveModel.PID)) { helpInfo = agent.InvokeServiceFunction("OnlineHelpBLL_Get", helpInfo); if (!string.IsNullOrEmpty(helpInfo.PID)) { saveModel = CopyToModel(helpInfo); SetPIDMessage(saveModel.PID); } } //保存成功 SetMessage(AppResource.SaveMessge); return View("Edit", saveModel); } catch (Exception ex) { throw ex; } } #endregion #region 树 /// /// 菜单信息转化为树形控件数据格式,并返回 /// /// 返回结果 public ActionResult GetTreeMenuDatas() { List list = new List(); MenuHelper helper = new MenuHelper(); List menus = helper.GetMenuInfos(); for (int i = 0; i < menus.Count; i++) { TreeNodeResult treenode = new TreeNodeResult(); treenode.Tid = menus[i].MenuID.ToString(); treenode.Ttext = menus[i].MenuDes.ToString(); for (int j = 0; j < menus[i].ChildMenus.Count; j++) { TreeNodeResult cTreeNode = new TreeNodeResult(); cTreeNode.Tid = menus[i].ChildMenus[j].MenuID.ToString(); cTreeNode.Ttext = menus[i].ChildMenus[j].MenuDes.ToString(); treenode.AddchildNode(cTreeNode); } list.Add(treenode); } return Content(TreeNodeResult.GetResultJosnS(list.ToArray())); } #endregion #region 浏览帮助 /// /// 帮助浏览 /// /// public ActionResult ViewHelp() { OnLineHelpModel ret = new OnLineHelpModel(); if (Request.Params["menuID"] != null) { ret.MENUID = Request.Params["menuID"].ToString(); } else { ret.MENUID = ""; } return View("ViewPageHelp",ret); } /// /// 页面级帮助浏览 /// /// 帮助信息model /// public ActionResult ViewPageHelp(OnLineHelpModel model) { return View(model); } #endregion #region 获取列表 /// /// 加载列表 /// /// 结果 [HandleException] public ActionResult List() { OnLineHelpModel seachModel = new OnLineHelpModel(); return View("List", seachModel); } #endregion #region xml数据读取功能 /// /// 获取查询模块对应ViewModel类型 /// /// 程序名 /// ViewModel类型 public Type GetProgramVMType(string menuId) { if (!string.IsNullOrEmpty(menuId)) { string prgListName = System.Web.HttpContext.Current.Server.MapPath(HttpRuntime.AppDomainAppVirtualPath) + "App_Data\\Menu.xml"; string viewModel = string.Empty; string dllName = string.Empty; try { XElement xel = XElement.Load(prgListName); var datas = from x in xel.Descendants("MenuItem") select x; foreach (XElement d in datas) { if (d.Attribute("MenuID").Value == menuId) { if (d.Attribute("ViewModel") != null) { viewModel = d.Attribute("ViewModel").Value; string[] tempStrs=viewModel.Split(".".ToArray()); if(tempStrs.Length>0) { _currentModelName = tempStrs[tempStrs.Length - 1]; } } if (d.Attribute("Action") != null) { _currentPageName = d.Attribute("Action").Value; string[] tempStrs = _currentPageName.Split("/".ToArray()); if (tempStrs.Length > 0) { _currentPageName = tempStrs[tempStrs.Length - 1]; } } if (string.IsNullOrEmpty(d.Attribute("MenuDes").Value)) { dllName = @"HelpInfoDll\QMAPP.Web.dll"; } else { _currentMenuName = d.Attribute("MenuDes").Value; string systemName = d.Attribute("SystemID").Value; switch (systemName) { case "MainData": dllName = @"HelpInfoDll\QMAPP.MD.Web.dll"; break; case "PLP": dllName = @"HelpInfoDll\QMAPP.PLP.Web.dll"; break; case "KB": dllName = @"HelpInfoDll\QMAPP.KB.Web.dll"; break; case "Report": dllName = @"HelpInfoDll\QMAPP.Report.Web.dll"; break; case "Main": dllName = @"HelpInfoDll\QMAPP.Web.dll"; break; } } break; } } if (viewModel == "") { //throw new Exception("未对该程序模块进行相应配置。"); } Assembly asse = Assembly.LoadFile(QController.PhysicsRootPath + dllName); Type t = asse.GetType(viewModel); return t; } catch (Exception ex) { //throw new Exception("未对该程序模块进行相应配置。"); return null; } } else { return null; } } #endregion /// /// 更新前端PID /// /// public void SetPIDMessage(string pMessage) { ViewData["SetPagePID"] = pMessage; } } }