using System; using System.Windows; using System.Windows.Input; using System.Data; using Microsoft.Reporting.WinForms; using SSWMS.Common; namespace SSWMS.Client { public partial class StaticsReportWPF : AvalonDock.DocumentContent { private ReportViewer report; public StaticsReportWPF() { InitializeComponent(); Grid_Loaded(null, null); } private void Grid_Loaded(object sender, RoutedEventArgs e) { this.report = this.windowsFormsHost1.Child as ReportViewer; this.report.PrinterSettings.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins(10, 20, 10, 20); this.report.ZoomMode = ZoomMode.FullPage; this.btnReset_Click(null, null); } private void GetReportData() { String sTitle = String.Empty; String sRdlc = String.Empty; String sDs = String.Empty; DataTable dt = new DataTable(); String q_sql = String.Empty; switch (this.cmbReportType.SelectedIndex) { case 0: sTitle = "入出库汇总表"; sRdlc = "SSWMS.Client.REPORT.REPORT_GOODS_INOUT.rdlc"; sDs = "GOODS_INOUT"; q_sql = "select (case GOODS_CLASS when 'AStock' then '托盘' else '物料' end) as GOODS_CLASS,GOODS_CODE,GOODS_NAME," + "cast(sum(case MANAGE_TYPE when 'In' then RECORD_LIST_QUANTITY else 0 end) as int) as IN_QUANTITY," + "cast(sum(case MANAGE_TYPE when 'Out' then RECORD_LIST_QUANTITY else 0 end) as int) as OUT_QUANTITY from V_RECORD_MANAGE" + " where GOODS_CLASS<>'空托盘' and MANAGE_END_TIME>='" + this.datePickerFrom.Value.ToString("yyyy-MM-dd HH:mm:ss") + "' and MANAGE_END_TIME<='" + this.datePickerTo.Value.ToString("yyyy-MM-dd HH:mm:ss") + "' group by GOODS_CLASS,GOODS_CODE,GOODS_NAME order by GOODS_CLASS,GOODS_CODE"; dt = WCFChannel._I_BaseService.GetDataTable(q_sql); break; case 1: sTitle = "库存汇总表"; sRdlc = "SSWMS.Client.REPORT.REPORT_GOODS_STORAGE.rdlc"; sDs = "GOODS_STORAGE"; dt = WCFChannel._I_BaseService.GetDataTable( "select (case GOODS_CLASS when 'AStock' then '托盘' else '物料' end) as GOODS_CLASS,GOODS_CODE,GOODS_NAME,QUANTITY from V_STORAGE_LIST_TOTAL order by GOODS_CLASS,GOODS_CODE"); break; } this.report.LocalReport.ReportEmbeddedResource = sRdlc; this.report.LocalReport.SetParameters(new ReportParameter[] { new ReportParameter("ParaTitle", sTitle) }); this.report.LocalReport.DataSources.Clear(); this.report.LocalReport.DataSources.Add(new ReportDataSource(sDs, dt)); this.report.LocalReport.DisplayName = sTitle; this.report.RefreshReport(); } private void btnQuery_Click(object sender, RoutedEventArgs e) { if (-1 == this.cmbReportType.SelectedIndex) { MessageDialog.ShowException("请选择报表类型"); return; } if (string.IsNullOrEmpty(this.datePickerFrom.Text)|| string.IsNullOrEmpty(this.datePickerTo.Text)) { MessageDialog.ShowException("请选择日期"); return; } try { MainWindow.mainWin.Cursor = Cursors.Wait; GetReportData(); MainWindow.mainWin.Cursor = Cursors.Arrow; } catch (Exception ex) { MainWindow.mainWin.Cursor = Cursors.Arrow; MessageDialog.ShowException(ex); } } private void btnReset_Click(object sender, RoutedEventArgs e) { this.cmbReportType.SelectedIndex = 0; this.datePickerFrom.CustomFormat = "yyyy-MM-dd HH:mm:ss"; this.datePickerFrom.Format = System.Windows.Forms.DateTimePickerFormat.Custom; this.datePickerFrom.Value = Convert.ToDateTime(StringUtils.GetCurrentDay() + " 00:00:00"); this.datePickerTo.CustomFormat = "yyyy-MM-dd HH:mm:ss"; this.datePickerTo.Format = System.Windows.Forms.DateTimePickerFormat.Custom; this.datePickerTo.Value = Convert.ToDateTime(StringUtils.GetNextDay() + " 00:00:00"); } } }