private void btnPrint_Click(object sender, RoutedEventArgs e) { try { string reportMonth = cbbMonth.SelectedItem.ToString(); string reportYear = cbbYear.SelectedItem.ToString(); int reportMonthNo = cbbMonth.SelectedIndex + 1; int reportYearNo = int.Parse(reportYear) - 543; List <ReportParameter> parameters = new List <ReportParameter>(); parameters.Add(new ReportParameter("ApartmentName", Global.CurrentApartment.ApartmentName)); parameters.Add(new ReportParameter("ApartmentAddress", Global.CurrentApartment.Address)); parameters.Add(new ReportParameter("ReportYear", reportYear)); parameters.Add(new ReportParameter("ReportMonth", reportMonth)); parameters.Add(cbDeductImproveCost.IsChecked == true ? new ReportParameter("DeductImproveCost", "True") : new ReportParameter("DeductImproveCost", "False")); ReportPreviewer rp = new ReportPreviewer(); BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (o, ea) => { rp.SetDataSet("IncomeSummaryDataSet", new ReceiptsLogic().GetIncomeSummaryRecords(reportMonthNo, reportYearNo, Global.CurrentApartment.ApartmentId)); }; worker.RunWorkerCompleted += (o, ea) => { rp.SetReportPath(@".\Reports\IncomeSummary.rdlc"); rp.SetParameters(parameters); rp.ShowDialog(); loadingPanel.IsBusy = false; }; loadingPanel.IsBusy = true; worker.RunWorkerAsync(); } catch (Exception ex) { MessageBox.Show(ex.Message, "เกิดข้อผิดพลาด", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void btnPrint_Click(object sender, RoutedEventArgs e) { try { string reportMonth = cbbMonth.SelectedItem.ToString(); string reportYear = cbbYear.SelectedItem.ToString(); List <Model.IncomeReportRecord> reportDataSet = new List <Model.IncomeReportRecord>(); DateTime fromDate = new DateTime(int.Parse(reportYear) - 543, cbbMonth.SelectedIndex + 1, 1); DateTime toDate = fromDate.AddMonths(1).AddDays(-1); bool isDeductImproveCost = Convert.ToBoolean(cbDeductImproveCost.IsChecked); ReportPreviewer rp = new ReportPreviewer(); List <ReportParameter> parameters = new List <ReportParameter>(); parameters.Add(new ReportParameter("ReportYear", reportYear)); parameters.Add(new ReportParameter("ReportMonth", reportMonth)); BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (o, ea) => { List <Model.Invoice> invoices = new InvoicesLogic().GetInvoices(fromDate, toDate, Global.CurrentApartment.ApartmentId); foreach (var invoice in invoices) { Decimal electricCost = invoice.EUsedUnit * invoice.EUnit; Decimal waterCost = invoice.WUsedUnit * invoice.WUnit; Decimal total = electricCost + waterCost + invoice.TelCost + invoice.Room.MonthCost + invoice.ImproveCost; Model.IncomeReportRecord rec = new Model.IncomeReportRecord() { RoomNo = invoice.Room.RoomNo, ContactName = invoice.Room.Customer.ContactName, MonthName = reportYear, ElectricCost = electricCost, WaterCost = waterCost, TelephoneCost = invoice.TelCost, MonthCost = invoice.Room.MonthCost, ImproveCost = isDeductImproveCost ? 0 : invoice.ImproveCost, Total = isDeductImproveCost ? (total - invoice.ImproveCost) : total }; reportDataSet.Add(rec); } rp.SetDataSet("IncomeReportDataSet", reportDataSet); }; worker.RunWorkerCompleted += (o, ea) => { rp.SetReportPath(@".\Reports\IncomeReport.rdlc"); rp.SetParameters(parameters); rp.ShowDialog(); loadingPanel.IsBusy = false; }; loadingPanel.IsBusy = true; worker.RunWorkerAsync(); } catch (Exception ex) { MessageBox.Show(ex.Message, "เกิดข้อผิดพลาด", MessageBoxButton.OK, MessageBoxImage.Error); } }