天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

430 lines
16 KiB

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
{
/// <summary>
/// 在线帮助控制器类
/// </summary>
public class OnLineHelpController : QController
{
/// <summary>
/// 当前菜单名称
/// </summary>
private string _currentMenuName = string.Empty;
/// <summary>
/// 帮助页面名称,针对menu菜单的Action标签
/// </summary>
private string _currentPageName = string.Empty;
/// <summary>
/// 帮助model名称,针对menu的菜单ViewModel标签
/// </summary>
private string _currentModelName = string.Empty;
/// <summary>
/// 编辑帮助信息,将页面级在线帮助传入view
/// </summary>
/// <param name="menuId">菜单id</param>
/// <returns>结果</returns>
[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<OnlineHelp>("OnlineHelpBLL_Get", helpInfo);
pageModel = CopyToModel<OnLineHelpModel, OnlineHelp>(helpInfo);
pageModel.PAGENAME = _currentPageName;
pageModel.MODELNAME = _currentModelName;
}
try
{
return View(pageModel);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 获取页面级帮助信息
/// </summary>
/// <param name="menuId">菜单ID</param>
/// <returns>返回页面帮助信息</returns>
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<OnlineHelp>("OnlineHelpBLL_Get", helpInfo);
pageModel = CopyToModel<OnLineHelpModel, OnlineHelp>(helpInfo);
pageModel.PAGENAME = _currentPageName;
pageModel.MODELNAME = _currentModelName;
ret = pageModel.HELPCONTENT;
}
return ret;
}
/// <summary>
/// 获取字段级帮助集合的json字符串
/// </summary>
/// <param name="menuId">菜单ID</param>
/// <returns></returns>
public string GetColumnHelps(string menuId)
{
List<OnlineHelp> model = new List<OnlineHelp>();
if (!string.IsNullOrEmpty(menuId))
{
System.Type viewModelT = GetProgramVMType(menuId);
List<DGColumn> columns = new List<DGColumn>();
if (viewModelT != null)
{
//生成字段明细数据
PropertyInfo[] pArray = viewModelT.GetProperties();
//以及存在的字段级帮助集合
List<OnlineHelp> existHelps = new List<OnlineHelp>();
//查询条件
OnlineHelp conditon = new OnlineHelp();
conditon.MENUID = menuId;
conditon.KIND = "C";//字段级帮助标识为“C”
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
existHelps = agent.InvokeServiceFunction<List<OnlineHelp>>("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 保存
/// <summary>
/// 保存页面级帮助
/// </summary>
/// <param name="saveModel">页面级帮助信息</param>
/// <returns></returns>
[ValidateInput(false)]
public ActionResult SavePageHelp(OnLineHelpModel saveModel)
{
OnlineHelp helpInfo = new OnlineHelp();
List<OnlineHelp> items = new List<OnlineHelp>();
JavaScriptSerializer js = new JavaScriptSerializer();
List<OnlineHelp> colHelpInfos = js.Deserialize<List<OnlineHelp>>(saveModel.FieldsJson);
if (colHelpInfos != null && colHelpInfos.Count > 0)
{
items.AddRange(colHelpInfos);
}
int r = 0;
try
{
helpInfo = CopyToModel<OnlineHelp, OnLineHelpModel>(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<int>("OnlineHelpBLL_Save", items);
if (string.IsNullOrEmpty(saveModel.PID))
{
helpInfo = agent.InvokeServiceFunction<OnlineHelp>("OnlineHelpBLL_Get", helpInfo);
if (!string.IsNullOrEmpty(helpInfo.PID))
{
saveModel = CopyToModel<OnLineHelpModel, OnlineHelp>(helpInfo);
SetPIDMessage(saveModel.PID);
}
}
//保存成功
SetMessage(AppResource.SaveMessge);
return View("Edit", saveModel);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 树
/// <summary>
/// 菜单信息转化为树形控件数据格式,并返回
/// </summary>
/// <returns>返回结果</returns>
public ActionResult GetTreeMenuDatas()
{
List<TreeNodeResult> list = new List<TreeNodeResult>();
MenuHelper helper = new MenuHelper();
List<MenuInfo> 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 浏览帮助
/// <summary>
/// 帮助浏览
/// </summary>
/// <returns></returns>
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);
}
/// <summary>
/// 页面级帮助浏览
/// </summary>
/// <param name="model">帮助信息model</param>
/// <returns></returns>
public ActionResult ViewPageHelp(OnLineHelpModel model)
{
return View(model);
}
#endregion
#region 获取列表
/// <summary>
/// 加载列表
/// </summary>
/// <returns>结果</returns>
[HandleException]
public ActionResult List()
{
OnLineHelpModel seachModel = new OnLineHelpModel();
return View("List", seachModel);
}
#endregion
#region xml数据读取功能
/// <summary>
/// 获取查询模块对应ViewModel类型
/// </summary>
/// <param name="menuId">程序名</param>
/// <returns>ViewModel类型</returns>
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
/// <summary>
/// 更新前端PID
/// </summary>
/// <param name="pMessage"></param>
public void SetPIDMessage(string pMessage)
{
ViewData["SetPagePID"] = pMessage;
}
}
}