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
{
///
/// 查询模板控制器
/// 创建者:李炳海
/// 创建日期:2014.8.13
///
public class QueryTLController : QController
{
//
// GET: /QueryTL/
#region 查询模板列表
///
/// 查询模板列表
///
/// 是否回调
/// 结果
[HandleException]
public ActionResult QueryTLList()
{
TemplateListModel seachModel = new TemplateListModel();
seachModel.ProgramName = Request.QueryString["programName"];
//获取已应用模板
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
QueryTemplate pt = agent.InvokeServiceFunction("QueryTemplateBLL_GetProgramTemplateBase", seachModel.ProgramName);
if (pt != null)
{
seachModel.TEMPLATEID = pt.TEMPLATEID;
seachModel.TEMPLATENAME = pt.TEMPLATENAME;
}
else
{
seachModel.TEMPLATENAME = "未选择";
}
return View("TemplateList", seachModel);
}
///
/// 查询模板列表
///
/// 是否回调
/// 结果
[HandleException]
public ActionResult QueryTLMyList(bool? callBack)
{
TemplateListModel seachModel = new TemplateListModel();
string programName = Request.QueryString["programName"];
if (callBack == true)
TryGetSelectBuffer(out seachModel);
seachModel.ProgramName = programName;
seachModel.rownumbers = false;
seachModel.url = "/QueryTL/GetList?tlKind=my&programName=" + programName;
return View("TemplateMyList", seachModel);
}
///
/// 查询模板列表
///
/// 是否回调
/// 结果
[HandleException]
public ActionResult QueryTLPubList(bool? callBack)
{
TemplateListModel seachModel = new TemplateListModel();
string programName = Request.QueryString["programName"];
if (callBack == true)
TryGetSelectBuffer(out seachModel);
seachModel.ProgramName = programName;
seachModel.rownumbers = false;
seachModel.url = "/QueryTL/GetList?tlKind=pub&programName=" + programName;
return View("TemplatePubList", seachModel);
}
///
/// 获取列表数据
///
/// 是否回调
/// 用户列表
[HandleException]
public ActionResult GetList(bool? callBack)
{
List users = new List();
TemplateListModel seachModel = null;
DataPage page = new DataPage();
QueryTemplate condition = null;
string tlKind = Request.QueryString["tlKind"];
string programName = Request.QueryString["programName"];
try
{
//获取查询对象
seachModel = GetModel();
#region 获取缓存值
if (callBack != null)
{
TryGetSelectBuffer(out seachModel);
}
else
{
//保存搜索条件
SetSelectBuffer(seachModel);
}
#endregion
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
//获取数据
condition = CopyToModel(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("QueryTemplateBLL_GetList", condition, page);
DataGridResult result = new DataGridResult();
result.Total = page.RecordCount;
result.Rows = (List)page.Result;
return Content(result.GetJsonSource());
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 编辑查询模板
///
/// 编辑载入
///
/// 处理结果
[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 columns = QGridView.GetColDefinitions(viewModelT).Where(p => p.Hidden == false).ToList();
string whereList = new ProgramHelper().GetProgramWhereList(programName);
List whereColumns = QGridView.GetALLColDefinitions(viewModelT).Where(p => whereList.IndexOf("[" + p.ColumnName + "]") >= 0).ToList();
List modelWheres = new List();
List modelColumns = new List();
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("QueryTemplateBLL_Get", template);
model = CopyToModel(template);
//设置未排序列
model.UnSorts = columns.Select(t => new TemplateSortModel { COLUMNNAME = t.ColumnName, COLUMNLABEL = t.ColumnTitle }).ToList();
model.EnSorts = new List();
//设置查询条件
model.Wheres = new List();
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();
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();
model.CREATEDATE = DateTime.Now;
model.CREATEUSER = AccountController.GetLoginInfo().UserID;
model.CREATEUSERNAME = AccountController.GetLoginInfo().UserName;
}
return View("QueryTLEdit", model);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 编辑载入
///
/// 处理结果
[HandleException]
public ActionResult QueryTLSave(TemplateEditModel model)
{
Dictionary setInfos = new Dictionary();
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 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 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("QueryTemplateBLL_Insert", template, setInfos);
}
else
{
template.UPDATEDATE = model.UPDATEDATE;
//获取已应用模板
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
agent.InvokeServiceFunction("QueryTemplateBLL_Update", template, setInfos);
}
return this.GetJsViewResult(string.Format("parent.closeAppWindow1();parent.ListQueryTL('{1}');"
, "保存成功。", model.QUERYPROGRAM));
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 删除查询模板
///
/// 删除用户
///
/// 结果
[HttpPost]
[HandleException]
public ActionResult TemplateDelete()
{
string selectKey = Request.Form["selectKey"];
string[] list = selectKey.Split(":".ToCharArray());
try
{
//获取已应用模板
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
agent.InvokeServiceFunction("QueryTemplateBLL_Delete", list.ToList());
SetMessage("删除成功。");
return QueryTLMyList(true);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 取消应用模板
///
/// 取消应用模板
///
///
[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("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
}
}