private void btnPrint_Click(object sender, RoutedEventArgs e) { if (_receipt != null) { string reportPath = @".\Reports\Receipt.rdlc"; List <Model.ReceiptForPrinting> receipts = new ReceiptsLogic().GetReceiptForPrinting(_receipt); DeductImproveCostComfirmBox confirmBox = new DeductImproveCostComfirmBox(); confirmBox.WindowStartupLocation = WindowStartupLocation.Manual; confirmBox.Top = Mouse.GetPosition(null).Y - 200; confirmBox.Left = Mouse.GetPosition(null).X; if (confirmBox.ShowDialog() == false) { reportPath = @".\Reports\ReceiptDeductImproveCost.rdlc"; foreach (var r in receipts) { r.GrandTotalText = ThaiBahtTextUtil.ThaiBahtText(Convert.ToDecimal(r.GrandTotal) - r.ImproveCost); } } ReportPreviewer rp = new ReportPreviewer(); rp.SetDataSet("ReceiptDataSet", receipts); rp.SetReportPath(reportPath); rp.ShowDialog(); } }
private void btnDelete_Click(object sender, RoutedEventArgs e) { try { var selectedReceipt = dgReceipts.SelectedItem != null ? new ReceiptsLogic().GetReceipt((dgReceipts.SelectedItem as Model.ReceiptDataGridView).ReceiptId) : null; if (selectedReceipt != null) { if (MessageBox.Show("ยืนยันที่จะลบข้อมูลใบแจ้งหนี้ " + selectedReceipt.ReceiptNo, "ยืนยันการลบข้อมูล", MessageBoxButton.OKCancel, MessageBoxImage.Warning) == MessageBoxResult.OK) { ReceiptsLogic l = new ReceiptsLogic(); l.DeleteReceipt(selectedReceipt); selectedReceipt.Invoice.Paid = false; new InvoicesLogic().SetInvoicePaidStatus(selectedReceipt.Invoice); SearchReceipt(); } } else { MessageBox.Show("กรุณาเลือกข้อมูลที่จะลบ", "เกิดข้อผิดพลาด", MessageBoxButton.OK, MessageBoxImage.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "เกิดข้อผิดพลาด", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void btnPrint_Click(object sender, RoutedEventArgs e) { try { bool deductImproveCost = false; int reportMonth = cbbMonth.SelectedIndex + 1; int reportYear = int.Parse(cbbYear.SelectedItem.ToString()); DateTime fromDate = new DateTime(reportYear - 543, reportMonth, 1); DateTime toDate = fromDate.AddMonths(1).AddDays(-1); List <Model.ReceiptForPrinting> printReceipts = new List <Model.ReceiptForPrinting>(); ReportPreviewer rp = new ReportPreviewer(); string reportPath = @".\Reports\Receipt.rdlc"; Receipt.DeductImproveCostComfirmBox confirmBox = new Receipt.DeductImproveCostComfirmBox(); confirmBox.WindowStartupLocation = WindowStartupLocation.Manual; confirmBox.Top = Mouse.GetPosition(null).Y; confirmBox.Left = Mouse.GetPosition(null).X; if (confirmBox.ShowDialog() == false) { reportPath = @".\Reports\ReceiptDeductImproveCost.rdlc"; deductImproveCost = true; } BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += (o, ea) => { List <Model.Receipt> receipts = new ReceiptsLogic().GetReceipts(fromDate, toDate, Global.CurrentApartment.ApartmentId); foreach (var r in receipts) { List <Model.ReceiptForPrinting> printedReceipt = new ReceiptsLogic().GetReceiptForPrinting(r); if (deductImproveCost) { foreach (var pr in printedReceipt) { pr.GrandTotalText = ThaiBahtTextUtil.ThaiBahtText(Convert.ToDecimal(pr.GrandTotal) - pr.ImproveCost); } } printReceipts.AddRange(printedReceipt); } }; worker.RunWorkerCompleted += (o, ea) => { rp.SetDataSet("ReceiptDataSet", printReceipts); rp.SetReportPath(reportPath); rp.ShowDialog(); loadingPanel.IsBusy = false; }; loadingPanel.IsBusy = true; worker.RunWorkerAsync(); } catch (Exception ex) { MessageBox.Show(ex.Message, "เกิดข้อผิดพลาด", MessageBoxButton.OK, MessageBoxImage.Error); } }