public virtual object GetQueryData(HttpContext context) { YZRequest request = new YZRequest(context); String datasourceName = request.GetString("DataSource", null); String query = request.GetString("Query"); QueryParameterCollection queryParams = JArray.Parse(request.GetString("QueryParams")).ToObject <QueryParameterCollection>(); YZClientParamCollection @params = JArray.Parse(Encoding.UTF8.GetString(Convert.FromBase64String(request.GetString("params", YZJsonHelper.Base64EmptyJArray)))).ToObject <YZClientParamCollection>(); bool clientCursor = request.GetBool("clientCursor", false); //应用查询条件 BPMDBParameterCollection finallyParams = queryParams.CreateNullDBParameters(); foreach (BPMDBParameter @param in finallyParams) { YZClientParam clientParam = @params.TryGetItem(@param.Name); if (clientParam != null && clientParam.value != null) { @param.Value = clientParam.value; } } FlowDataTable table = new FlowDataTable(); int rowcount; using (BPMConnection cn = new BPMConnection()) { cn.WebOpen(); table.Load(cn, BPMCommandType.Query, query, finallyParams, clientCursor, request.Start, request.Limit, out rowcount); } return(new { total = rowcount, children = table.ToDataTable() }); }
public virtual JObject GetReportData(HttpContext context) { YZRequest request = new YZRequest(context); string path = request.GetString("path"); string viewName = request.GetString("viewName", null); string outputType = request.GetString("outputType", ""); YZClientParamCollection runtimeParams = JArray.Parse(Encoding.UTF8.GetString(Convert.FromBase64String(request.GetString("params", YZJsonHelper.Base64EmptyJArray)))).ToObject <YZClientParamCollection>(); //获得数据 Report report; ReportView view; DataTable dataTable; int rowcount; using (BPMConnection cn = new BPMConnection()) { cn.WebOpen(); //获得报表定义 report = Report.Open(cn, path); if (String.IsNullOrEmpty(viewName)) { view = report.DefaultView; } else { view = report.Views.TryGetItem(viewName); } string srcdata = request.GetString("srcdata", null); if (String.IsNullOrEmpty(srcdata)) { BPMDBParameterCollection selectParameters = report.QueryParameters.CreateNullDBParameters(); //应用查询条件 foreach (BPMDBParameter selectParam in selectParameters) { YZClientParam clientParam = runtimeParams.TryGetItem(selectParam.Name); if (clientParam != null && clientParam.value != null) { selectParam.Value = clientParam.value; } } cn.RequestParams["sortstring"] = request.GetSortString(""); cn.UpdateRequestParams(); //获得数据 FlowDataTable ftable = new FlowDataTable(); ftable.Load(cn, BPMCommandType.Report, path, selectParameters, report.ClientCursor, request.Start, request.Limit, out rowcount); dataTable = ftable.ToDataTable(); } else { dataTable = JArray.Parse(Encoding.UTF8.GetString(Convert.FromBase64String(srcdata))).ToObject <DataTable>(); rowcount = request.GetInt32("total"); } } //将数据转化为Json集合 JObject rv = new JObject(); rv[YZJsonProperty.total] = rowcount; rv["srcdata"] = Convert.ToBase64String(Encoding.UTF8.GetBytes(JArray.FromObject(dataTable).ToString(Formatting.None, YZJsonHelper.Converters))); JArray children = new JArray(); rv.Add("children", children); //不管是什么view都要给数据 foreach (DataRow row in dataTable.Rows) { JObject item = new JObject(); children.Add(item); foreach (DataColumn column in dataTable.Columns) { object value = row[column.ColumnName]; item[column.ColumnName] = JToken.FromObject(value); if (NameCompare.EquName(column.ColumnName, "TaskID") && (value is int)) { item["Token"] = YZSecurityHelper.GenTaskAccessToken((int)value); } //为任务链接生成Token ReportColumnInfo colInfo = report.ReportColumnInfos.TryGetItem(column.ColumnName); if (colInfo != null && colInfo.LinkType == ReportLinkType.Task) { ParameterFill paramFill = colInfo.ParametersFill.TryGetItem("@TaskID"); if (paramFill != null) { int linktoTaskID; if (Int32.TryParse(Convert.ToString(row[paramFill.FillWith]), out linktoTaskID)) { item[column.ColumnName + "Token"] = YZSecurityHelper.GenTaskAccessToken((int)linktoTaskID); } } } } } if (String.Compare(outputType, "Export", true) != 0) { if (view is ReportMSChartView) { this.ApplyMSChartData(request, rv, view as ReportMSChartView, dataTable); } if (view is ReportExcelView) { this.ApplyExcelData(request, rv, view as ReportExcelView, dataTable, runtimeParams); } } return(rv); }