|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- using GrapeCity.ActiveReports;
- using GrapeCity.ActiveReports.Aspnet.Viewer;
- using GrapeCity.ActiveReports.PageReportModel;
- using GrapeCity.ActiveReports.Rendering;
- using Microsoft.Owin;
- using Owin;
- using System.Collections.Generic;
- using System.Data;
- using System.IO;
- using System.Reflection;
-
- [assembly: OwinStartup(typeof(Learun.Application.Web.Startup1))]
-
- namespace Learun.Application.Web
- {
- public class Startup1
- {
- public static string EmbeddedReportsPrefix = "Learun.Application.Web";
-
-
- 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 = GetData;
-
- });
-
- }
-
-
-
- public object GetReport(string P)//获取报表名称和报表参数,进行一个对应的报表名称和参数的分割
- {
- var plist = P.Split('|');
- string reportName = plist[0];//报表名称;
- PageReport rep = new PageReport();
-
-
- string path = Assembly.GetExecutingAssembly().CodeBase.Replace("bin/Learun.Application.Web.DLL", "Reports/").Replace("file:///", "");
- //string path = System.Web.Hosting.HostingEnvironment.MapPath("~/");
- rep.Load(new FileInfo(path + reportName));
-
- int num = 0;
- foreach (var item in plist)
- {
- if (num > 0)
- {
- AddReportPara("param" + num, item, rep);
- }
-
- num++;
- }
- return rep.Report;
- }
- /// <summary>
- /// 报表参数添加
- /// </summary>
- /// <param name="name">参数名</param>
- /// <param name="value">参数值</param>
- /// <param name="rp">报表体</param>
- private void AddReportPara(string name, string value, PageReport rep)
- {
- //如果没有值,报表不会自动运行,所以不能加
- if (string.IsNullOrEmpty(value.Trim()))
- {
- return;
- }
-
- Dictionary<string, string> dicParas = new Dictionary<string, string>();
- foreach (var item in rep.Report.ReportParameters)
- {
- if (!dicParas.ContainsKey(item.Name))
- {
- dicParas.Add(item.Name, item.DefaultValue.Values[0].Expression);
- }
- }
-
- if (!dicParas.ContainsKey(name))
- {
- ReportParameter para = new ReportParameter();
- para.Name = name;
- para.Prompt = name;
- para.UsedInQuery = ReportParameterUsedInQuery.True;
- para.DataType = ReportParameterDataType.String;
- para.DefaultValue.Values.Add(value.Trim());
- rep.Report.ReportParameters.Add(para);
- }
- }
-
-
- /// <summary>
- /// 自定义数据源
- /// </summary>
- /// <param name="args">报表数据参数</param>
- /// <returns></returns>
- //public object GetData(LocateDataSourceArgs args)
- //{
- // Dictionary<string, string> dcFilter = new Dictionary<string, string>();
- // DataTable dtData = new DataTable();
- // string name = args.Report.Name.ToString();
- // string dataSource = args.DataSet.Query.DataSourceName;
- // string dataSet = args.DataSet.Name;
- // switch (name)
- // {
- // case "制程工单.rdlx":
- // if (args.Report.ReportParameters.Count > 0)
- // {
- // var id = args.Report.ReportParameters[0].DefaultValue.Values[0].Expression;
- // WorkOrderIBLL workOrderIBLL = new WorkOrderBLL();
- // dtData = workOrderIBLL.GetPrintItem(id);
- // }
- // break;
- // }
- // return dtData;
- //}
- }
- }
|