FastReport 主子表关系

代码中只需要绑定主表的数据就可以,子表的数据会通过报表中的关连关系自动到数据库中带出。

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;
		}
	}
}
相关推荐
yngsqq3 分钟前
c#使用高版本8.0步骤
java·前端·c#
hccee3 小时前
C# IO文件操作
开发语言·c#
广煜永不挂科5 小时前
Devexpress.Dashboard的调用二义性
c#·express
初九之潜龙勿用7 小时前
C#校验画布签名图片是否为空白
开发语言·ui·c#·.net
吾与谁归in8 小时前
【C#设计模式(13)——代理模式(Proxy Pattern)】
设计模式·c#·代理模式
吾与谁归in8 小时前
【C#设计模式(14)——责任链模式( Chain-of-responsibility Pattern)】
设计模式·c#·责任链模式
神仙别闹9 小时前
基于C#和Sql Server 2008实现的(WinForm)订单生成系统
开发语言·c#
向宇it19 小时前
【unity小技巧】unity 什么是反射?反射的作用?反射的使用场景?反射的缺点?常用的反射操作?反射常见示例
开发语言·游戏·unity·c#·游戏引擎
九鼎科技-Leo19 小时前
什么是 WPF 中的依赖属性?有什么作用?
windows·c#·.net·wpf
Heaphaestus,RC20 小时前
【Unity3D】获取 GameObject 的完整层级结构
unity·c#