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;
		}
	}
}
相关推荐
向宇it2 小时前
【从零开始入门unity游戏开发之——unity篇02】unity6基础入门——软件下载安装、Unity Hub配置、安装unity编辑器、许可证管理
开发语言·unity·c#·编辑器·游戏引擎
yngsqq3 小时前
一键打断线(根据相交点打断)——CAD c# 二次开发
windows·microsoft·c#
TENET信条4 小时前
day53 第十一章:图论part04
开发语言·c#·图论
anlog5 小时前
C#在自定义事件里传递数据
开发语言·c#·自定义事件
向宇it7 小时前
【从零开始入门unity游戏开发之——unity篇01】unity6基础入门开篇——游戏引擎是什么、主流的游戏引擎、为什么选择Unity
开发语言·unity·c#·游戏引擎
仰望大佬0077 小时前
Avalonia实例实战五:Carousel自动轮播图
数据库·microsoft·c#
糖朝7 小时前
c#读取json
c#·json
向宇it12 小时前
【从零开始入门unity游戏开发之——C#篇26】C#面向对象动态多态——接口(Interface)、接口里氏替换原则、密封方法(`sealed` )
java·开发语言·unity·c#·游戏引擎·里氏替换原则
Java Fans16 小时前
C# 中串口读取问题及解决方案
开发语言·c#
盛派网络小助手16 小时前
微信 SDK 更新 Sample,NCF 文档和模板更新,更多更新日志,欢迎解锁
开发语言·人工智能·后端·架构·c#