Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

4 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using GrapeCity.ActiveReports;
  2. using GrapeCity.ActiveReports.Aspnet.Viewer;
  3. using GrapeCity.ActiveReports.PageReportModel;
  4. using GrapeCity.ActiveReports.Rendering;
  5. using Microsoft.Owin;
  6. using Owin;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. using System.IO;
  10. using System.Reflection;
  11. [assembly: OwinStartup(typeof(Learun.Application.Web.Startup1))]
  12. namespace Learun.Application.Web
  13. {
  14. public class Startup1
  15. {
  16. public static string EmbeddedReportsPrefix = "Learun.Application.Web";
  17. public void Configuration(IAppBuilder app)
  18. {
  19. app.UseReporting(settings =>
  20. {
  21. settings.UseCompression = true;
  22. settings.UseCustomStore(GetReport);//使用UseCustomStore来自定义一些需要的值
  23. //settings.UseFileStore(new DirectoryInfo(String.Format(@"{0}.\Reports\", HttpRuntime.AppDomainAppPath)));
  24. //settings.LocateDataSource = GetData;
  25. });
  26. }
  27. public object GetReport(string P)//获取报表名称和报表参数,进行一个对应的报表名称和参数的分割
  28. {
  29. var plist = P.Split('|');
  30. string reportName = plist[0];//报表名称;
  31. PageReport rep = new PageReport();
  32. string path = Assembly.GetExecutingAssembly().CodeBase.Replace("bin/Learun.Application.Web.DLL", "Reports/").Replace("file:///", "");
  33. //string path = System.Web.Hosting.HostingEnvironment.MapPath("~/");
  34. rep.Load(new FileInfo(path + reportName));
  35. int num = 0;
  36. foreach (var item in plist)
  37. {
  38. if (num > 0)
  39. {
  40. AddReportPara("param" + num, item, rep);
  41. }
  42. num++;
  43. }
  44. return rep.Report;
  45. }
  46. /// <summary>
  47. /// 报表参数添加
  48. /// </summary>
  49. /// <param name="name">参数名</param>
  50. /// <param name="value">参数值</param>
  51. /// <param name="rp">报表体</param>
  52. private void AddReportPara(string name, string value, PageReport rep)
  53. {
  54. //如果没有值,报表不会自动运行,所以不能加
  55. if (string.IsNullOrEmpty(value.Trim()))
  56. {
  57. return;
  58. }
  59. Dictionary<string, string> dicParas = new Dictionary<string, string>();
  60. foreach (var item in rep.Report.ReportParameters)
  61. {
  62. if (!dicParas.ContainsKey(item.Name))
  63. {
  64. dicParas.Add(item.Name, item.DefaultValue.Values[0].Expression);
  65. }
  66. }
  67. if (!dicParas.ContainsKey(name))
  68. {
  69. ReportParameter para = new ReportParameter();
  70. para.Name = name;
  71. para.Prompt = name;
  72. para.UsedInQuery = ReportParameterUsedInQuery.True;
  73. para.DataType = ReportParameterDataType.String;
  74. para.DefaultValue.Values.Add(value.Trim());
  75. rep.Report.ReportParameters.Add(para);
  76. }
  77. }
  78. /// <summary>
  79. /// 自定义数据源
  80. /// </summary>
  81. /// <param name="args">报表数据参数</param>
  82. /// <returns></returns>
  83. //public object GetData(LocateDataSourceArgs args)
  84. //{
  85. // Dictionary<string, string> dcFilter = new Dictionary<string, string>();
  86. // DataTable dtData = new DataTable();
  87. // string name = args.Report.Name.ToString();
  88. // string dataSource = args.DataSet.Query.DataSourceName;
  89. // string dataSet = args.DataSet.Name;
  90. // switch (name)
  91. // {
  92. // case "制程工单.rdlx":
  93. // if (args.Report.ReportParameters.Count > 0)
  94. // {
  95. // var id = args.Report.ReportParameters[0].DefaultValue.Values[0].Expression;
  96. // WorkOrderIBLL workOrderIBLL = new WorkOrderBLL();
  97. // dtData = workOrderIBLL.GetPrintItem(id);
  98. // }
  99. // break;
  100. // }
  101. // return dtData;
  102. //}
  103. }
  104. }