- namespace JSviewerDatasource
- {
- public class Startup1
- {
- public static string EmbeddedReportsPrefix = "JSdatasource";
- string ReportName = "";
- public object GetReport(string P)//获取报表名称和报表参数,进行一个对应的报表名称和参数的分割
- {
- string reportName = P.Split(';')[0];//报表名称;
- string parameter1 = P.Split(';')[1];//参数1;
- string parameter2 = P.Split(';')[2];//参数2;
- PageReport rep = new PageReport();
- string path = System.Web.Hosting.HostingEnvironment.MapPath("~/");
- rep.Load(new FileInfo(@"" + path + "Reports/" + reportName));
- //rep.Report.ReportParameters[0].DefaultValue.Values.Add("111");
- return rep.Report;
- }
- public void Configuration(IAppBuilder app)
- {
-
- app.UseReporting(settings =>
- {
- settings.UseCompression = true;
- settings.UseCustomStore(GetReport);//使用UseCustomStore来自定义一些需要的值
- //settings.UseFileStore(new DirectoryInfo(String.Format(@"{0}.\Reports", HttpRuntime.AppDomainAppPath)));
- settings.LocateDataSource = args =>
- {
- DataTable dt = new DataTable();
- string name = ReportName;
- if (args.DataSet.Query.DataSourceName == "DataSource1")
- {
- if (args.DataSet.Name == "DataSet2")
- {
- string fp = "D://照片//报表水印.png";
- //byte[] a = File.ReadAllBytes(@"D:\照片\报表水印.png");
-
- byte[] a = SaveImage(fp);
- MemoryStream stream = new MemoryStream(a);
- BitmapImage bmp = new BitmapImage();
- bmp.BeginInit();//初始化
- bmp.StreamSource = stream;//设置源
- bmp.EndInit();//初始化结束
- dt.Columns.Add("产品编号");
- dt.Columns.Add("产品名称");
- dt.Columns.Add("单价");
- dt.Columns.Add("库存量");
- dt.Columns.Add("产地");
- dt.Columns.Add("图片", typeof(byte[]));//二进制流的形式,默认不设置是字符串类型,绑定不同数据类型的值,需要进行对应的属性设置。
- dt.Rows.Add("A001", "苹果", 10, 300, "中国", a);
- }
- }
- return dt;
- };
- });
- }
- public byte[] SaveImage(String path)
- {
- string aa = string.Empty;
- FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
- //将图片以文件流的形式进行保存
- BinaryReader br = new BinaryReader(fs);
- byte[] imgBytesIn = br.ReadBytes((int)fs.Length); //将流读入到字节数组中
- return imgBytesIn;
- }
- }
- }
复制代码
|