Example #1
0
        /// <summary>
        /// Handles the ReportViewer.Drillthrough event. Add the data for the drillthrough report here.
        /// </summary>
        private void ReportViewer1_Drillthrough(object sender, DrillthroughEventArgs e)
        {
            LocalReport report = (LocalReport)e.Report;

            // Supply a DataTable corresponding to each drillthrough report dataset
            // The dataset name must match the name defined in the drillthrough report
            report.DataSources.Add(new ReportDataSource(report.GetDataSourceNames()[0], LoadOrderDetailsData()));
        }
Example #2
0
        private void FillData(NameValueCollection parameters)
        {
            foreach (var dsName in _localReport.GetDataSourceNames())
            {
                _localReport.DataSources.Add(GetDataSource(dsName, parameters));
            }
            List <ReportParameter> prms = new List <ReportParameter>();

            foreach (var pi in _localReport.GetParameters())
            {
                var      key   = parameters.AllKeys.FirstOrDefault(p => p.ToLower() == pi.Name.ToLower());
                string[] value = null;
                if (!string.IsNullOrEmpty(key))
                {
                    value = parameters.GetValues(key) ?? new string[] { "" };
                    prms.Add(new ReportParameter(pi.Name, value));
                }
            }
            _localReport.SetParameters(prms);
        }
Example #3
0
        public void PrintRpt()
        {
            LocalReport report = new LocalReport();

            try
            {
                string strFilePath = _rptPath;
                report.ReportPath = strFilePath;

                IList <string> lisDs = report.GetDataSourceNames();
                foreach (string strds in lisDs)
                {
                    string strTableName = _dsTableKey == string.Empty ? strds : _dsTableKey + "-" + strds;
                    if (!_dsDataSource.Tables.Contains(strTableName))
                    {
                        continue;
                    }

                    if (report.DataSources[strds] == null || report.DataSources[strds].Value == null)
                    {
                        report.DataSources.Add(new ReportDataSource(strds, _dsDataSource.Tables[strTableName]));
                    }
                    else
                    {
                        report.DataSources[strds].Value = null;
                        report.DataSources[strds].Value = _dsDataSource.Tables[strTableName];
                    }
                }
            }
            catch (Exception err)
            {
                throw new Exception("打印出错:" + err.InnerException.Message);
            }

            Export(report);

            m_currentPageIndex = 0;
            Print();
        }
Example #4
0
        /// <summary>
        /// Prints a local report wihthout ReportViewer when the "Print Local Report" button is pressed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonPrintLocal_Click(object sender, EventArgs e)
        {
            LocalReport         report   = null;
            DataSet             dataSet  = null;
            ReportPrintDocument printdoc = null;

            try
            {
                // Create a LocalReport object directly
                report            = new LocalReport();
                report.ReportPath = @"..\..\Report1.rdlc";

                // Add report data sources
                dataSet = new DataSet();
                dataSet.ReadXml(@"..\..\data.xml");
                report.DataSources.Add(new ReportDataSource(report.GetDataSourceNames()[0], dataSet.Tables[0]));

                // Print the report using the ReportPrintDocument class (see ReportPrintDocument.cs)
                printdoc = new ReportPrintDocument(report);
                printdoc.Print();
            }
            finally
            {
                if (report != null)
                {
                    report.Dispose();
                }
                if (dataSet != null)
                {
                    dataSet.Dispose();
                }
                if (printdoc != null)
                {
                    printdoc.Dispose();
                }
            }
        }
Example #5
0
        public void PrintLabel(char type, int id)
        {
            LocalReport report = new LocalReport();

            // Set report path (*)
            report.ReportPath = Properties.Settings.Default.LabelReportFile;

            // Set report parameters (*)
            ReportParameter input1 = new ReportParameter("Type", "1");
            ReportParameter input2 = new ReportParameter("Id", "1");

            report.SetParameters(new ReportParameter[] { input1, input2 });

            // Hook everything up and render the report.
            DataSet data = this.GetJewelryLabelReportDataSource(type, id);

            report.DataSources.Add(new ReportDataSource(report.GetDataSourceNames()[0], data.Tables[0]));

            // Set printer page settings (*)
            string deviceInfo =
                "<DeviceInfo>" +
                "  <OutputFormat>EMF</OutputFormat>" +
                "  <PageWidth>2.3125in</PageWidth>" +
                "  <PageHeight>4in</PageHeight>" +
                "  <MarginTop>0in</MarginTop>" +
                "  <MarginLeft>0in</MarginLeft>" +
                "  <MarginRight>0in</MarginRight>" +
                "  <MarginBottom>0in</MarginBottom>" +
                "</DeviceInfo>";

            ExportReportToStreams(report, deviceInfo);

            _currentPage = 0;
            Print(Properties.Settings.Default.LabelPrinterName);
            report.Dispose();
            data.Dispose();
        }
Example #6
0
        public void PrintPurchasePoliceReport(int purchaseid)
        {
            LocalReport report = new LocalReport();

            // Set report path (*)
            report.ReportPath = Properties.Settings.Default.PurchasePoliceReportFile;

            // Set report parameters (*)
            ReportParameter input1 = new ReportParameter("PurchaseId", "1");

            report.SetParameters(new ReportParameter[] { input1 });

            // Hook everything up and render the report.
            DataSet data = this.GetPurchaseReportDataSource(purchaseid);

            report.DataSources.Add(new ReportDataSource(report.GetDataSourceNames()[0], data.Tables[0]));

            // Set printer page settings (*)
            string deviceInfo =
                "<DeviceInfo>" +
                "  <OutputFormat>EMF</OutputFormat>" +
                "  <PageWidth>8.5in</PageWidth>" +
                "  <PageHeight>5.5in</PageHeight>" +
                "  <MarginTop>0in</MarginTop>" +
                "  <MarginLeft>0in</MarginLeft>" +
                "  <MarginRight>0in</MarginRight>" +
                "  <MarginBottom>0in</MarginBottom>" +
                "</DeviceInfo>";

            ExportReportToStreams(report, deviceInfo);

            _currentPage = 0;
            Print(Properties.Settings.Default.PolicePrinterName);
            report.Dispose();
            data.Dispose();
        }
Example #7
0
        public InfReportOutput Render(InfReportFormat format)
        {
            if (string.IsNullOrWhiteSpace(FileName))
            {
                throw new InvalidOperationException("The report file name property has not been set.");
            }

            if (FileName.StartsWith("/", StringComparison.Ordinal) && HttpContext.Current != null)
            {
                FileName = HttpContext.Current.Server.MapPath(FileName);
            }

            if (!File.Exists(FileName))
            {
                throw new FileNotFoundException("The specified report file name does not exist. Be sure to provide the full path, and set the \"Build Action\" of the report file to \"Content\".", FileName);
            }

            try
            {
                using (var report = new LocalReport())
                {
                    report.ReportPath = FileName;

                    foreach (var dataSourceName in report.GetDataSourceNames())
                    {
                        if (!DataTables.Any(dt => dt.Key.Equals(dataSourceName, StringComparison.OrdinalIgnoreCase)))
                        {
                            var message = string.Format(CultureInfo.InvariantCulture, "No data table has been added for the report data source name \"{0}\".", dataSourceName);
                            throw new InvalidOperationException(message);
                        }
                    }

                    foreach (var parameter in report.GetParameters())
                    {
                        if (!Parameters.Any(p => p.Key.Equals(parameter.Name, StringComparison.OrdinalIgnoreCase)))
                        {
                            var message = string.Format(CultureInfo.InvariantCulture, "No parameter has been added for the report parameter \"{0}\".", parameter.Name);
                            throw new InvalidOperationException(message);
                        }
                    }

                    report.EnableExternalImages = true;
                    report.EnableHyperlinks     = true;
                    report.DataSources.Clear();

                    foreach (var item in DataTables)
                    {
                        report.DataSources.Add(new ReportDataSource(item.Key, item.Value));
                    }

                    foreach (var item in Parameters)
                    {
                        report.SetParameters(new ReportParameter(item.Key, item.Value));
                    }

                    if (!report.IsReadyForRendering)
                    {
                        throw new InvalidOperationException("The report is not ready for rendering. Check that all required data tables and parameters have been added.");
                    }

                    var reportBytes   = new byte[0];
                    var mimeType      = string.Empty;
                    var fileExtension = string.Empty;
                    var encoding      = string.Empty;
                    var streams       = new string[0];
                    var warnings      = new Warning[0];

                    report.Refresh();
                    reportBytes = report.Render(
                        format.ToString(),
                        string.Empty, // device info
                        out mimeType,
                        out encoding,
                        out fileExtension,
                        out streams,
                        out warnings);

                    if (warnings != null && warnings.Length > 0 && warnings.Any(w => w.Severity == Severity.Error))
                    {
                        var message = new StringBuilder();
                        message.Append("The following error(s) occurred during report rendering: ");

                        foreach (var warning in warnings.Where(w => w.Severity == Severity.Error))
                        {
                            message.AppendFormat(
                                CultureInfo.InvariantCulture,
                                "code = \"{0}\"; object name = \"{1}\"; object type = \"{2}\"; message = \"{3}\".",
                                warning.Code,
                                warning.ObjectName,
                                warning.ObjectType,
                                warning.Message);
                        }
                    }

                    return(new InfReportOutput
                    {
                        FileExtension = fileExtension,
                        MimeType = mimeType,
                        Encoding = encoding,
                        ReportBytes = reportBytes
                    });
                }
            }
            catch (Exception ex)
            {
                InfLogger.Log(ex);
                throw;
            }
        }