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;
		}
	}
}
相关推荐
IT技术分享社区5 小时前
C#实战:使用腾讯云识别服务轻松提取火车票信息
开发语言·c#·云计算·腾讯云·共识算法
△曉風殘月〆12 小时前
WPF MVVM入门系列教程(二、依赖属性)
c#·wpf·mvvm
逐·風13 小时前
unity关于自定义渲染、内存管理、性能调优、复杂物理模拟、并行计算以及插件开发
前端·unity·c#
m0_6569747417 小时前
C#中的集合类及其使用
开发语言·c#
九鼎科技-Leo17 小时前
了解 .NET 运行时与 .NET 框架:基础概念与相互关系
windows·c#·.net
九鼎科技-Leo19 小时前
什么是 ASP.NET Core?与 ASP.NET MVC 有什么区别?
windows·后端·c#·asp.net·mvc·.net
.net开发19 小时前
WPF怎么通过RestSharp向后端发请求
前端·c#·.net·wpf
小乖兽技术19 小时前
C#与C++交互开发系列(二十):跨进程通信之共享内存(Shared Memory)
c++·c#·交互·ipc
幼儿园园霸柒柒20 小时前
第七章: 7.3求一个3*3的整型矩阵对角线元素之和
c语言·c++·算法·矩阵·c#·1024程序员节
平凡シンプル1 天前
C# EF 使用
c#