vs2015安装rdlc报表模块
控制面板-Microsoft Visual Studio …2005-更改-修改-勾选{Microsoft SQL Server Data Tools},安装即可
private void FrmWholeCarReceipts_Load(object sender, EventArgs e)
{
try
{
// 指定rdlc文件
this.reportViewer1.LocalReport.ReportEmbeddedResource = "AloneSell.Report.OrderRefund.rdlc";
}
catch (Exception ex)
{
Utility.Pub.ShowError("报表加载失败," + ex.Message);
return;
}
this.reportViewer1.LocalReport.DataSources.Clear();
BLL.T_X_BackCarM_BLL bllBack = new BLL.T_X_BackCarM_BLL();
DataTable dt = bllBack.GetList("BackID='" + BackID + "'").Tables[0];
if (dt.Rows.Count <= 0) return;
try
{
Model.T_X_BackCarM_Model m = bllBack.DataTableToList(dt)[0];
BLL.T_X_BeSpeakeCar_BLL bllBS = new BLL.T_X_BeSpeakeCar_BLL();
Model.T_X_BeSpeakeCar_Model mBS = bllBS.GetModel(BackID);
if (mBS == null)
{
Utility.Pub.ShowInfo("订单不存在");
return;
}
string Value1 = mBS.GuestName + " 支付 整车收款 ";
string Value2 = new Money(m.BackMoney, false).ToString() + "(" + m.BackMoney.ToString("f1") + ")";
//添加报表数据源
this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("T_X_BackCarM", dt));
//参数设置
List<ReportParameter> parameterList = new List<ReportParameter>();
parameterList.Add(new ReportParameter("Company", Utility.Pub.Company));
parameterList.Add(new ReportParameter("Value1", Value1));
parameterList.Add(new ReportParameter("Value2", Value2));
this.reportViewer1.LocalReport.SetParameters(parameterList);
this.reportViewer1.RefreshReport();
//设置打印布局模式,显示物理页面大小
this.reportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
//缩放模式为百分比,以100%方式显示
this.reportViewer1.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.Percent;
this.reportViewer1.ZoomPercent = 100;
string _AutoPrint = ConfigFileManage.GetAppKeyValue("ShowPrint");
if (_AutoPrint.Trim() == "否")
{
this.Visible = false;
PPrint();
this.Close();
}
}
catch (Exception ex)
{
Utility.Pub.ShowError("操作失败," + ex.Message);
return;
}
}
#region 报表自打印
private string _reportname = Application.StartupPath + "\\rptOperation.rdlc";//rptBase.rdlc
private DataSet _datasource = null;
private string _autoprint = "";
private IList<Stream> m_streams;
private int m_currentPageIndex;
public void PPrint()
{
try
{
LocalReport report = this.reportViewer1.LocalReport;
Export(report);
m_currentPageIndex = 0;
NBPrint();
if (m_streams != null)
{
foreach (Stream stream in m_streams)
stream.Close();
m_streams = null;
}
}
catch (Exception ex)
{
MessageBox.Show("在打印过程中出现异常! " + ex.Message.ToString());
}
}
private void Export(LocalReport report)
{
//7.5in 3.66in 0 0 0 0 当前设置为A4纵向
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>EMF</OutputFormat>" +
" <PageWidth>20.7cm</PageWidth>" +
" <PageHeight>28cm</PageHeight>" +
" <MarginTop>0in</MarginTop>" +
" <MarginLeft>0in</MarginLeft>" +
" <MarginRight>0in</MarginRight>" +
" <MarginBottom>0in</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 NBPrint()
{
if (m_streams == null || m_streams.Count == 0)
return;
System.Drawing.Printing.PrintDocument printDoc = new System.Drawing.Printing.PrintDocument();
if (!printDoc.PrinterSettings.IsValid)
{
string msg = String.Format("Can't find printer \"{0}\".", "默认打印机!");
MessageBox.Show(msg, "找不到默认打印机");
return;
}
printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
printDoc.Print();
this.Close();
}
private Stream CreateStream(string name, string fileNameExtension, Encoding encoding, string mimeType, bool willSeek)
{
string filenameext = DateTime.Now.Year.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
Stream stream = new FileStream(name + "." + fileNameExtension, FileMode.Create);
m_streams.Add(stream);
return stream;
}
private void PrintPage(object sender, PrintPageEventArgs ev)
{
Metafile pageImage = new Metafile(m_streams[m_currentPageIndex]);
ev.Graphics.DrawImage(pageImage, ev.PageBounds);
m_currentPageIndex++;
ev.HasMorePages = (m_currentPageIndex < m_streams.Count);
}
#endregion