using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QMFrameWork.Data;
using QMAPP.Entity.QueryTL;
using QMAPP.DAL.QueryTL;
namespace QMAPP.BLL.QueryTL
{
///
/// 查询模板管理
/// 创建者:李炳海
/// 创建日期:2014.8.13
///
public class QueryTemplateBLL:BaseBLL
{
#region 获取查询条件设置
private List GetWhereSets(List wheres, string whereDisplays)
{
List selectWheres = new List();
if (string.IsNullOrEmpty(whereDisplays) == false)
{
selectWheres = whereDisplays.Split(",".ToCharArray()).ToList();
}
foreach (TemplateWhere where in wheres)
{
if (selectWheres.IndexOf(where.QUERYCOLUMN) >= 0)
{
where.ISDISPLAY = "1";
}
else
{
where.ISDISPLAY = "0";
}
}
return wheres;
}
#endregion
#region 获取列显示设置
private List GetColumnSets(List columns, Dictionary setInfos)
{
List list = new List();
List seqs = setInfos["columns"].ToString().Split(",".ToCharArray()).ToList();
List displays = setInfos["columnDisplays"].ToString().Split(",".ToCharArray()).ToList();
List aligns = setInfos["columnAligns"].ToString().Split(",".ToCharArray()).ToList();
List widths = setInfos["columnWidths"].ToString().Split(",".ToCharArray()).ToList();
List frozens = setInfos["columnFrozens"].ToString().Split(",".ToCharArray()).ToList();
for (int i = 0; i < seqs.Count; i++)
{
TemplateColumn col = new TemplateColumn();
col.COLUMNNAME = seqs[i];
col.SEQ = i + 1;
if (displays.IndexOf(col.COLUMNNAME) < 0)
col.ISHIDDEN = "1";
else
col.ISHIDDEN = "0";
col.WIDTH = int.Parse(widths[i]);
col.DATAALIGN = aligns[i];
if (frozens.IndexOf(col.COLUMNNAME) >= 0)
col.ISFROZEN = "1";
else
col.ISFROZEN = "0";
list.Add(col);
}
return list;
}
#endregion
#region 获取排序设置
private List GetSortSets(string selectedSorts)
{
List list = QMFrameWork.Common.Serialization.JsonConvertHelper.GetDeserialize>(selectedSorts);
foreach (TemplateSort sort in list)
{
sort.IFASC = sort.SORTMODE == "ASC" ? "1" : "0";
}
return list;
}
#endregion
#region 新增模板信息
///
/// 新增模板信息
///
/// 模板信息
public void Insert(QueryTemplate templateInfo,Dictionary setInfos)
{
templateInfo.TEMPLATEID = Guid.NewGuid().ToString();
//获取查询条件设置
templateInfo.Wheres = this.GetWhereSets(templateInfo.Wheres, setInfos["whereDisplays"]);
//获取列设置
templateInfo.Columns = this.GetColumnSets(templateInfo.Columns, setInfos);
//获取排序设置
templateInfo.Sorts = this.GetSortSets(setInfos["sortColumns"]);
if (templateInfo.Wheres != null)
{
foreach (TemplateWhere where in templateInfo.Wheres)
{
where.ID = Guid.NewGuid().ToString();
where.TEMPLATEID = templateInfo.TEMPLATEID;
}
}
if (templateInfo.Columns != null)
{
foreach (TemplateColumn column in templateInfo.Columns)
{
column.ID = Guid.NewGuid().ToString();
column.TEMPLATEID = templateInfo.TEMPLATEID;
}
}
if (templateInfo.Sorts != null)
{
foreach (TemplateSort sort in templateInfo.Sorts)
{
sort.ID = Guid.NewGuid().ToString();
sort.TEMPLATEID = templateInfo.TEMPLATEID;
}
}
new QueryTemplateDAL().Insert(templateInfo);
}
#endregion
#region 更新模板信息
///
/// 更新模板信息
///
/// 模板信息
public void Update(QueryTemplate templateInfo, Dictionary setInfos)
{
templateInfo.UPDATEUSER = this.LoginUser.UserID;
//获取查询条件设置
templateInfo.Wheres = this.GetWhereSets(templateInfo.Wheres, setInfos["whereDisplays"]);
//获取列设置
templateInfo.Columns = this.GetColumnSets(templateInfo.Columns, setInfos);
//获取排序设置
templateInfo.Sorts = this.GetSortSets(setInfos["sortColumns"]);
if (templateInfo.Wheres != null)
{
foreach (TemplateWhere where in templateInfo.Wheres)
{
where.ID = Guid.NewGuid().ToString();
where.TEMPLATEID = templateInfo.TEMPLATEID;
}
}
if (templateInfo.Columns != null)
{
foreach (TemplateColumn column in templateInfo.Columns)
{
column.ID = Guid.NewGuid().ToString();
column.TEMPLATEID = templateInfo.TEMPLATEID;
}
}
if (templateInfo.Sorts != null)
{
foreach (TemplateSort sort in templateInfo.Sorts)
{
sort.ID = Guid.NewGuid().ToString();
sort.TEMPLATEID = templateInfo.TEMPLATEID;
}
}
new QueryTemplateDAL().Update(templateInfo);
}
#endregion
#region 删除模板信息
///
/// 删除模板信息
///
/// 模板信息
public void Delete(List list)
{
new QueryTemplateDAL().Delete(list);
}
#endregion
#region 获取模板信息
///
/// 获取模板信息
///
/// 获取条件
/// 模板信息
public QueryTemplate Get(QueryTemplate templateInfo)
{
return new QueryTemplateDAL().Get(templateInfo);
}
#endregion
#region 获取模板列表
///
/// 获取模板列表
///
/// 查询条件
/// 数据页
/// 数据页
public DataPage GetList(QueryTemplate condition, DataPage page)
{
page = new QueryTemplateDAL().GetList(condition, page);
foreach (QueryTemplate template in (List)page.Result)
{
template.ISPUBLISH = template.ISPUBLISH == "1" ? "是" : "否";
}
return page;
}
#endregion
#region 设置查询模板默认模板
///
/// 设置查询模板默认模板
///
/// 用户主键
/// 查询模块
/// 模板主键
public void SetProgramTemplate(ProgramTemplate pt)
{
pt.ID = Guid.NewGuid().ToString();
pt.CREATEUSER = this.LoginUser.UserID;
new QueryTemplateDAL().SetProgramTemplate(pt);
}
#endregion
#region 取消应用查询模板
///
/// 取消应用查询模板
///
/// 需要取消的模板信息
public void RemoveQueryTemplate(ProgramTemplate pt)
{
pt.CREATEUSER = this.LoginUser.UserID;
new QueryTemplateDAL().RemoveQueryTemplate(pt);
}
#endregion
#region 获取查询模板默认模板
///
/// 获取查询模板默认模板基本信息
///
/// 查询模板
/// 模板基本信息
public QueryTemplate GetProgramTemplateBase(string queryProgram)
{
return new QueryTemplateDAL().GetProgramTemplateBase(this.LoginUser.UserID, queryProgram);
}
///
/// 获取查询模板默认模板
///
/// 查询模块
/// 默认模板
public string GetProgramTemplate(string queryProgram)
{
if (this.LoginUser == null)
return "";
return new QueryTemplateDAL().GetProgramTemplate(this.LoginUser.UserID, queryProgram);
}
#endregion
}
}