示例#1
0
        public ReportForm(Report report, IReportBuilder rb)
        {
            InitializeComponent();
            this.report = report;
//            AddExtension(reportViewer, "HTML4", "HTML4", typeof(Microsoft.ReportingServices.Rendering.HtmlRenderer.Html40RenderingExtension));
            AddRenderingExtensions();

            base.Text = "־עקוע - " + report.name;
            reportViewer.LocalReport.DisplayName = report.name;

            if (report.embeddedResource.Trim().Length > 0)
            {
                Assembly assembly = Assembly.GetAssembly(typeof(IReportBuilder));
                using (Stream stream = assembly.GetManifestResourceStream(report.embeddedResource))
                {
                    reportViewer.LocalReport.LoadReportDefinition(stream);
                }

/*				using (Stream stream = assembly.GetManifestResourceStream("HospitalDepartment.Reports.PrescriptionsSubreport.rdlc"))
 *                              {
 *                                      reportViewer.LocalReport.LoadSubreportDefinition("PrescriptionsSubreport", stream);
 *                              }*/
            }
            else
            {
                reportViewer.LocalReport.ReportPath = PathUtils.BaseDirectory + report.path;
            }

            Dictionary <string, object> dataSources = rb.GetDataSources();

            if (dataSources != null)
            {
                foreach (string dsName in dataSources.Keys)
                {
                    reportViewer.LocalReport.DataSources.Add(new ReportDataSource(dsName, dataSources[dsName]));
                }
            }

            Dictionary <string, string> parameters = rb.GetParameters();

            if (parameters != null)
            {
                ReportParameterInfoCollection            coll = reportViewer.LocalReport.GetParameters();
                Dictionary <string, ReportParameterInfo> dict = new Dictionary <string, ReportParameterInfo>(coll.Count);
                foreach (ReportParameterInfo pi in coll)
                {
                    dict.Add(pi.Name, pi);
                }

                List <ReportParameter> reportParams = new List <ReportParameter>();
                foreach (string key in parameters.Keys)
                {
                    if (dict.ContainsKey(key))
                    {
                        string val = parameters[key];
                        if (val == null)
                        {
                            val = "";
                        }
                        ReportParameter rp = new ReportParameter(key, val);
                        reportParams.Add(rp);
                    }
                }
                reportViewer.LocalReport.SetParameters(reportParams);
            }
        }