zoukankan      html  css  js  c++  java
  • C#直接调用rdl报表生成报表并打印

           private void Run()
            {
                LocalReport report = new LocalReport();
                report.ReportPath = @"F:\SelfSystemPractice\Report\sqlserverreport\sqlserverreport\Report1.rdl";
                string connstr = @"Data Source=WIN-MT5JMJEOHPK;Initial Catalog=Study;Integrated Security=True";
                SqlConnection conn = new SqlConnection(connstr);
                string sql = "select  usercode,username,address from sys_user";
                SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
                DataSet set = new DataSet();
                adapter.Fill(set);

                ReportDataSource DataSeta = new ReportDataSource("DataSet1", set.Tables[0]);
                report.DataSources.Add(DataSeta);

                Export(report);

                m_currentPageIndex = 0;
                Print();
            }
          private void Export(LocalReport report)
            {
                string deviceInfo =
                  "<DeviceInfo>" +
                  "  <OutputFormat>EMF</OutputFormat>" +
                  //"  <PageWidth>2in</PageWidth>" +
                  //"  <PageHeight>20in</PageHeight>" +
                  //"  <MarginTop>0.25in</MarginTop>" +
                  //"  <MarginLeft>0.25in</MarginLeft>" +
                  //"  <MarginRight>0.25in</MarginRight>" +
                  //"  <MarginBottom>0.25in</MarginBottom>" +
                  "</DeviceInfo>";
                Warning[] warnings;
                m_streams = new List<Stream>();
                report.Render("Image", deviceInfo, CreateStream, out warnings);

                foreach (Stream stream in m_streams)
                    stream.Position = 0;
            }
           private void Print()
            {
                const string printerName =
                  "Microsoft XPS Document Writer";

                if (m_streams == null || m_streams.Count == 0)
                    return;

                PrintDocument printDoc = new PrintDocument();
                printDoc.PrinterSettings.PrinterName = printerName;
                if (!printDoc.PrinterSettings.IsValid)
                {
                    string msg = String.Format("Can't find printer \"{0}\".",
                      printerName);
                    Debug.WriteLine(msg);
                    return;
                }
                printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
                printDoc.Print();
            }
            private void PrintPage(object sender, PrintPageEventArgs ev)
            {
                Metafile pageImage =
                  new Metafile(m_streams[m_currentPageIndex]);
                ev.Graphics.DrawImage(pageImage, 0, 0);

                m_currentPageIndex++;
                ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
            }
           private Stream CreateStream(string name, string fileNameExtension,
              Encoding encoding, string mimeType, bool willSeek)
            {
                Stream stream = new FileStream(name + "." + fileNameExtension,
                  FileMode.Create);
                m_streams.Add(stream);
                return stream;
            }

  • 相关阅读:
    cancel_delayed_work和flush_scheduled_work【转】
    linux中断申请之request_threaded_irq【转】
    VELT-0.1.5开发:使用kgdb调试Linux内核【转】
    iOS_第3方类库_BlurAlertView_GPUImage
    一个轻client,多语言支持,去中心化,自己主动负载,可扩展的实时数据写服务的实现方案讨论
    如果数据文件顺序被打乱,你有办法找回正确的文件把数据库打开吗?
    Hibernate级联操作和载入机制(二) cascade and fetch
    UVA 10557 XYZZY
    Arcgis for javascript map操作addLayer具体解释
    64位CentOS上编译 Hadoop 2.2.0
  • 原文地址:https://www.cnblogs.com/ldqwyl/p/2015472.html
Copyright © 2011-2022 走看看