代码中只需要绑定主表的数据就可以,子表的数据会通过报表中的关连关系自动到数据库中带出。
using CloudSaaS.DB.Handler;
using CloudSaaS.Model;
using CloudSaaS.DAL;
using FastReport;
using FastReport.Web;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;namespace FastWeb.Modules.DevelopManages.FBDesigners.Forms.FormHandler
{public partial class FormPrint : System.Web.UI.Page{protected Button ButtonPDF;private int tid;private string flowGuid;private string ReportName;protected void Page_Load(object sender, EventArgs e){string value = base.Request["tid"];this.flowGuid = base.Request["flowGuid"];this.ReportName = base.Request["ReportName"];this.tid = (string.IsNullOrEmpty(value) ? 0 : Convert.ToInt32(value));this.ReportName = (string.IsNullOrEmpty(this.ReportName) ? "Demo" : base.Server.UrlDecode(this.ReportName));this.WebReport1.Prepare();}protected void WebReport1_StartReport(object sender, EventArgs e){Report report = (sender as WebReport).Report;string value = HttpContext.Current.Request.Cookies["tenantID"].Value;string text = this.GetReportPath() + this.ReportName + ".frx";report.Load(text);this.GetTBData(report, this.flowGuid, this.tid, value);}private void GetTBData(Report FReport, string flowGuid, int tid, string tenantId){dalSYSBPMDTABLE dalSYSBPMDTABLE = new dalSYSBPMDTABLE(tenantId);List<SYSBPMDTABLEInfo> list = dalSYSBPMDTABLE.GetLists().FindAll((SYSBPMDTABLEInfo c) => c.CatalogGuid == flowGuid);foreach (SYSBPMDTABLEInfo current in list){string tableName = current.TableName.ToString().Trim();DataSet dataSetByTaskId = this.GetDataSetByTaskId(tableName, tid, tenantId);FReport.RegisterData(dataSetByTaskId);}DataSet dataSetByTaskIdPross = this.GetDataSetByTaskIdPross(tid, tenantId);FReport.RegisterData(dataSetByTaskIdPross);}private string GetReportPath(){string path = "../../../../../CloudSpaces/";string text = this.Page.Server.MapPath(path);string str = "\\";text = text + "Reports" + str;if (!Directory.Exists(text)){Directory.CreateDirectory(text);}return text;}private DataSet GetDataSetByTaskId(string tableName, int taskId, string tenantId){DataSet dataSet = null;if (taskId > 0){StringBuilder stringBuilder = new StringBuilder(" DECLARE @sql VARCHAR(1000) ");stringBuilder.AppendFormat("IF NOT EXISTS (SELECT a.name FROM syscolumns a,sysobjects b WHERE a.id=b.id AND LTRIM(a.name)='GridOrder' AND LTRIM(b.name)='{0}') BEGIN", tableName);stringBuilder.AppendFormat(" SET @sql='select * from {0} with(nolock) where TaskId=''{1}'''", tableName, taskId);stringBuilder.Append(" END");stringBuilder.Append(" Else BEGIN");stringBuilder.AppendFormat(" SET @sql='select * from {0} with(nolock) where TaskId=''{1}'' order by GridOrder'", tableName, taskId);stringBuilder.Append(" END");stringBuilder.Append(" exec(@sql)");dataSet = CloudDB.GetHandler(tenantId).Query(stringBuilder.ToString());if (dataSet.Tables.Count > 0){dataSet.Tables[0].TableName = tableName;}}return dataSet;}private DataSet GetDataSetByTaskIdPross(int taskId, string tenantId){DataSet dataSet = null;if (taskId > 0){StringBuilder stringBuilder = new StringBuilder();stringBuilder.AppendFormat(" SELECT NodeName,OwnerDept,uid=IDENTITY(int,1,1) into #Approvetep FROM SYSBPMISteps with(nolock) \r\n where TaskId={0} order by TaskId,StepId\r\n \r\n select top 0 convert(nvarchar(50),null) A1, convert(nvarchar(50),null) A2,\r\n convert(nvarchar(50),null) A3, convert(nvarchar(50),null) A4,\r\n convert(nvarchar(50),null) A5, convert(nvarchar(50),null) A6,\r\n convert(nvarchar(50),null) A7, convert(nvarchar(50),null) A8 into #ApproveTable\r\n \r\n declare @icount int ,@i int,@jcount int ,@j int\r\n declare @NodeName nvarchar(50),@OwnerName nvarchar(50),@A5 nvarchar(50),@A6 nvarchar(50),@A7 nvarchar(50),@A8 nvarchar(50)\r\n declare @A1 nvarchar(50),@A2 nvarchar(50),@A3 nvarchar(50),@A4 nvarchar(50)\r\n set @icount=(select count(1) from #Approvetep) \r\n set @i=1 \r\n while @i<=@icount \r\n begin\r\n select @NodeName=NodeName,@OwnerName=OwnerDept from #Approvetep where uid=@i \r\n if @i%4=1 begin select @A1=@NodeName,@A2=@OwnerName end\r\n if @i%4=2 begin select @A3=@NodeName,@A4=@OwnerName end\r\n if @i%4=3 begin select @A5=@NodeName,@A6=@OwnerName end\r\n if @i%4=0 \r\n begin \r\n select @A7=@NodeName,@A8=@OwnerName \r\n insert #ApproveTable select @A1,@A2,@A3,@A4,@A5,@A6,@A7,@A8\r\n select @A1='',@A2='',@A3='',@A4='',@A5='',@A6='',@A7='',@A8=''\r\n end\r\n if (@i%4<>0 and @i=@icount)\r\n insert #ApproveTable select @A1,@A2,@A3,@A4,@A5,@A6,@A7,@A8 \r\n set @i=@i+1 \r\n end\r\n\r\n select * from #ApproveTable \r\n drop table #ApproveTable,#Approvetep", taskId);dataSet = CloudDB.GetHandler(tenantId).Query(stringBuilder.ToString());if (dataSet.Tables.Count > 0){dataSet.Tables[0].TableName = "ApproveTable";}}return dataSet;}}
}