天津投入产出系统后端
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.

463 lines
18 KiB

using System;
using System.Reflection;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using QMFrameWork.Common.Serialization;
using QMFrameWork.Data;
using QMFrameWork.WebUI.Attribute;
using QMFrameWork.WebUI.DataSource;
using QMAPP.Entity.QueryTL;
using QMAPP.Common.Web.Util;
using QMAPP.Common.Web.Models;
namespace QMAPP.Common.Web.Controllers
{
/// <summary>
/// 查询模板控制器
/// 创建者:李炳海
/// 创建日期:2014.8.13
/// </summary>
public class QueryTLController : QController
{
//
// GET: /QueryTL/
#region 查询模板列表
/// <summary>
/// 查询模板列表
/// </summary>
/// <param name="callBack">是否回调</param>
/// <returns>结果</returns>
[HandleException]
public ActionResult QueryTLList()
{
TemplateListModel seachModel = new TemplateListModel();
seachModel.ProgramName = Request.QueryString["programName"];
//获取已应用模板
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
QueryTemplate pt = agent.InvokeServiceFunction<QueryTemplate>("QueryTemplateBLL_GetProgramTemplateBase", seachModel.ProgramName);
if (pt != null)
{
seachModel.TEMPLATEID = pt.TEMPLATEID;
seachModel.TEMPLATENAME = pt.TEMPLATENAME;
}
else
{
seachModel.TEMPLATENAME = "未选择";
}
return View("TemplateList", seachModel);
}
/// <summary>
/// 查询模板列表
/// </summary>
/// <param name="callBack">是否回调</param>
/// <returns>结果</returns>
[HandleException]
public ActionResult QueryTLMyList(bool? callBack)
{
TemplateListModel seachModel = new TemplateListModel();
string programName = Request.QueryString["programName"];
if (callBack == true)
TryGetSelectBuffer<TemplateListModel>(out seachModel);
seachModel.ProgramName = programName;
seachModel.rownumbers = false;
seachModel.url = "/QueryTL/GetList?tlKind=my&programName=" + programName;
return View("TemplateMyList", seachModel);
}
/// <summary>
/// 查询模板列表
/// </summary>
/// <param name="callBack">是否回调</param>
/// <returns>结果</returns>
[HandleException]
public ActionResult QueryTLPubList(bool? callBack)
{
TemplateListModel seachModel = new TemplateListModel();
string programName = Request.QueryString["programName"];
if (callBack == true)
TryGetSelectBuffer<TemplateListModel>(out seachModel);
seachModel.ProgramName = programName;
seachModel.rownumbers = false;
seachModel.url = "/QueryTL/GetList?tlKind=pub&programName=" + programName;
return View("TemplatePubList", seachModel);
}
/// <summary>
/// 获取列表数据
/// </summary>
/// <param name="callBack">是否回调</param>
/// <returns>用户列表</returns>
[HandleException]
public ActionResult GetList(bool? callBack)
{
List<TemplateListModel> users = new List<TemplateListModel>();
TemplateListModel seachModel = null;
DataPage page = new DataPage();
QueryTemplate condition = null;
string tlKind = Request.QueryString["tlKind"];
string programName = Request.QueryString["programName"];
try
{
//获取查询对象
seachModel = GetModel<TemplateListModel>();
#region 获取缓存值
if (callBack != null)
{
TryGetSelectBuffer<TemplateListModel>(out seachModel);
}
else
{
//保存搜索条件
SetSelectBuffer<TemplateListModel>(seachModel);
}
#endregion
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
//获取数据
condition = CopyToModel<QueryTemplate, TemplateListModel>(seachModel);
condition.QUERYPROGRAM = programName;
if (string.IsNullOrEmpty(tlKind) == false && tlKind == "my")
{
//我的模板
condition.CREATEUSER = AccountController.GetLoginInfo().UserID;
}
//获取已应用模板
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
page = agent.InvokeServiceFunction<DataPage>("QueryTemplateBLL_GetList", condition, page);
DataGridResult<QueryTemplate> result = new DataGridResult<QueryTemplate>();
result.Total = page.RecordCount;
result.Rows = (List<QueryTemplate>)page.Result;
return Content(result.GetJsonSource());
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 编辑查询模板
/// <summary>
/// 编辑载入
/// </summary>
/// <returns>处理结果</returns>
[HandleException]
public ActionResult QueryTLEdit()
{
TemplateEditModel model = new TemplateEditModel();
string id = Request.QueryString["id"];
QueryTemplate template = new QueryTemplate();
string programName = Request.QueryString["programName"];
try
{
System.Type viewModelT = new ProgramHelper().GetProgramVMType(programName);
List<DGColumn> columns = QGridView.GetColDefinitions(viewModelT).Where(p => p.Hidden == false).ToList();
string whereList = new ProgramHelper().GetProgramWhereList(programName);
List<DGColumn> whereColumns = QGridView.GetALLColDefinitions(viewModelT).Where(p => whereList.IndexOf("[" + p.ColumnName + "]") >= 0).ToList();
List<TemplateWhereModel> modelWheres = new List<TemplateWhereModel>();
List<TemplateColumnModel> modelColumns = new List<TemplateColumnModel>();
foreach (DGColumn col in whereColumns)
{
modelWheres.Add(new TemplateWhereModel { QUERYCOLUMN = col.ColumnName, QUERYCOLUMNLABEL = col.ColumnTitle, ISDISPLAY = "checked=checked" });
}
foreach (DGColumn col in columns)
{
if (col.Hidden == false)
modelColumns.Add(new TemplateColumnModel
{
COLUMNNAME = col.ColumnName,
COLUMNLABEL = col.ColumnTitle,
WIDTH = col.Width,
CBXFILTERENABLE = "checked=checked",
CBXISFROZEN = "checked=checked",
CBXDISPLAY = "checked=checked",
CBXSOETENABLE = "checked=checked"
});
}
//绑定数据
if (string.IsNullOrEmpty(id) == false)
{
//修改获取原数据
template.TEMPLATEID = id;
//获取已应用模板
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
template = agent.InvokeServiceFunction<QueryTemplate>("QueryTemplateBLL_Get", template);
model = CopyToModel<TemplateEditModel, QueryTemplate>(template);
//设置未排序列
model.UnSorts = columns.Select(t => new TemplateSortModel { COLUMNNAME = t.ColumnName, COLUMNLABEL = t.ColumnTitle }).ToList();
model.EnSorts = new List<TemplateSortModel>();
//设置查询条件
model.Wheres = new List<TemplateWhereModel>();
foreach (TemplateWhereModel item in modelWheres)
{
TemplateWhere find = template.Wheres.Find(p => p.QUERYCOLUMN == item.QUERYCOLUMN);
if (find != null)
{
item.ISDISPLAY = find.ISDISPLAY == "1" ? "checked=checked" : "";
model.Wheres.Add(item);
}
}
//设置列
model.Columns = new List<TemplateColumnModel>();
if (template.Columns.Count > 0)
{
foreach (TemplateColumn item in template.Columns)
{
TemplateColumnModel find = modelColumns.Find(p => p.COLUMNNAME == item.COLUMNNAME);
if (find != null)
{
find.DATAALIGN = item.DATAALIGN;
find.CBXFILTERENABLE = item.FILTERENABLE == "1" ? "checked=checked" : "";
find.CBXISFROZEN = item.ISFROZEN == "1" ? "checked=checked" : "";
find.CBXDISPLAY = item.ISHIDDEN == "1" ? "" : "checked=checked";
find.CBXSOETENABLE = item.SOETENABLE == "1" ? "checked=checked" : "";
find.WIDTH = item.WIDTH;
model.Columns.Add(find);
}
}
}
else
{
model.Columns = modelColumns;
}
//设置已选排序列
model.EnSorts = template.Sorts.Select(t => new TemplateSortModel { COLUMNNAME = t.COLUMNNAME, COLUMNLABEL = "", SORTMODE = t.IFASC == "1" ? "ASC" : "DESC" }).ToList();
foreach (TemplateSortModel sort in model.EnSorts)
{
DGColumn find = columns.Find(p => p.ColumnName == sort.COLUMNNAME);
if (find != null)
{
sort.COLUMNLABEL = find.ColumnTitle;
}
}
model.UnSorts = model.UnSorts.Where(p => model.EnSorts.Exists(t => t.COLUMNNAME == p.COLUMNNAME) == false).ToList();
}
else
{
model.QUERYPROGRAM = programName;
model.ISPUBLISH = "0";
//设置查询条件
model.Wheres = modelWheres;
if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["PageSize"]) == false)
model.PAGESIZE = ConfigurationManager.AppSettings["PageSize"];
else
model.PAGESIZE = "20";
//设置列
model.Columns = modelColumns;
//设置未排序列
model.UnSorts = columns.Select(t => new TemplateSortModel { COLUMNNAME = t.ColumnName, COLUMNLABEL = t.ColumnTitle }).ToList();
model.EnSorts = new List<TemplateSortModel>();
model.CREATEDATE = DateTime.Now;
model.CREATEUSER = AccountController.GetLoginInfo().UserID;
model.CREATEUSERNAME = AccountController.GetLoginInfo().UserName;
}
return View("QueryTLEdit", model);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 编辑载入
/// </summary>
/// <returns>处理结果</returns>
[HandleException]
public ActionResult QueryTLSave(TemplateEditModel model)
{
Dictionary<string, string> setInfos = new Dictionary<string, string>();
QueryTemplate template = new QueryTemplate();
try
{
//接收设置信息
setInfos["whereDisplays"] = Request.Form["WHEREDISPLAY"] == null ? "" : Request.Form["WHEREDISPLAY"];
setInfos["columns"] = Request.Form["COLUMNNAME"] == null ? "" : Request.Form["COLUMNNAME"];
setInfos["columnDisplays"] = Request.Form["COLUMNDISPLAY"] == null ? "" : Request.Form["COLUMNDISPLAY"];
setInfos["columnAligns"] = Request.Form["DATAALIGN"] == null ? "" : Request.Form["DATAALIGN"];
setInfos["columnWidths"] = Request.Form["COLUMNWIDTH"] == null ? "" : Request.Form["COLUMNWIDTH"];
setInfos["columnFrozens"] = Request.Form["COLUMNFROZEN"] == null ? "" : Request.Form["COLUMNFROZEN"];
setInfos["sortColumns"] = Request.Form["SelectedSortColumn"] == null ? "" : Request.Form["SelectedSortColumn"];
System.Type viewModelT = new ProgramHelper().GetProgramVMType(model.QUERYPROGRAM);
#region 显示列设置
List<DGColumn> columns = QGridView.GetColDefinitions(viewModelT);
template.Columns = columns.Select(t => new TemplateColumn { COLUMNNAME = t.ColumnName }).ToList();
#endregion
#region 查询条件设置
string whereList = new ProgramHelper().GetProgramWhereList(model.QUERYPROGRAM);
List<DGColumn> whereColumns = QGridView.GetALLColDefinitions(viewModelT).Where(p => whereList.IndexOf("[" + p.ColumnName + "]") >= 0).ToList();
template.Wheres = whereColumns.Select(t => new TemplateWhere { QUERYCOLUMN = t.ColumnName }).ToList();
#endregion
template.TEMPLATEID = model.TEMPLATEID;
template.TEMPLATENAME = model.TEMPLATENAME;
template.CREATEDATE = model.CREATEDATE;
template.QUERYPROGRAM = model.QUERYPROGRAM;
template.PAGESIZE = int.Parse(model.PAGESIZE);
template.ISPUBLISH = model.ISPUBLISH;
template.CREATEUSER = model.CREATEUSER;
template.REMARK = model.REMARK;
if (string.IsNullOrEmpty(model.TEMPLATEID) == true)
{
//获取已应用模板
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
agent.InvokeServiceFunction<int>("QueryTemplateBLL_Insert", template, setInfos);
}
else
{
template.UPDATEDATE = model.UPDATEDATE;
//获取已应用模板
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
agent.InvokeServiceFunction<int>("QueryTemplateBLL_Update", template, setInfos);
}
return this.GetJsViewResult(string.Format("parent.closeAppWindow1();parent.ListQueryTL('{1}');"
, "保存成功。", model.QUERYPROGRAM));
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 删除查询模板
/// <summary>
/// 删除用户
/// </summary>
/// <returns>结果</returns>
[HttpPost]
[HandleException]
public ActionResult TemplateDelete()
{
string selectKey = Request.Form["selectKey"];
string[] list = selectKey.Split(":".ToCharArray());
try
{
//获取已应用模板
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
agent.InvokeServiceFunction<int>("QueryTemplateBLL_Delete", list.ToList());
SetMessage("删除成功。");
return QueryTLMyList(true);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 取消应用模板
/// <summary>
/// 取消应用模板
/// </summary>
/// <returns></returns>
[HttpPost]
[HandleException]
public ActionResult RemoveTemplate()
{
string templateID = Request.Form["TEMPLATEID"];
string programName = Request.Form["ProgramName"];
ProgramTemplate pt = new ProgramTemplate();
try
{
pt.QUERYPROGRAM = programName;
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
agent.InvokeServiceFunction<int>("QueryTemplateBLL_RemoveQueryTemplate", pt);
return this.GetJsViewResult(string.Format("parent.closeAppWindow1();parent.RemoveTemplate();"
, "取消查询模板。"));
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取分页尺寸
[HandleException]
public ActionResult GetPageSizeList()
{
ComboboxResult model = new ComboboxResult();
model.Add(new ComboboxItem { ID = "20", Text = "20" });
model.Add(new ComboboxItem { ID = "40", Text = "40" });
model.Add(new ComboboxItem { ID = "80", Text = "80" });
return Content(model.ToString());
}
#endregion
}
}