home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 April / Chip_1997-04_cd.bin / prezent / cb / data.z / MAINPRNT.CPP < prev    next >
C/C++ Source or Header  |  1997-01-16  |  5KB  |  128 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl\vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "mainprnt.h"
  6. #include "custrpt.h"
  7. #include "preview.h"
  8. #include "qrycust.h"
  9. #include "Datamod.h"
  10. #include "OrderRpt.h"
  11. #include "Invoice.h"
  12. #include "PickRep.h"
  13. //---------------------------------------------------------------------------
  14. #pragma resource "*.dfm"
  15. TMainPrintForm *MainPrintForm;
  16. //---------------------------------------------------------------------------
  17. __fastcall TMainPrintForm::TMainPrintForm(TComponent* Owner)
  18.     : TForm(Owner)
  19. {
  20.   ReportCombo->ItemIndex=0;
  21.   OrientationCombo->ItemIndex=0;
  22.   PreviewCombo->ItemIndex=0;
  23. }
  24. //---------------------------------------------------------------------------
  25. void __fastcall TMainPrintForm::PrintBtnClick(TObject *Sender)
  26. {
  27.  aReport->Print();
  28. }
  29. //---------------------------------------------------------------------
  30. void __fastcall TMainPrintForm::ShowPreview()
  31. {
  32.   PrevForm->ShowModal();
  33. }//---------------------------------------------------------------------------
  34. #pragma warn -aus
  35. bool TMainPrintForm::PickReport()
  36. {
  37.   bool reportSet = false;
  38.   switch( ReportCombo->ItemIndex) {
  39.          case   0 :  //Customer Report
  40.             aReport=CustReportForm->CustomerReport;
  41.               reportSet = true;
  42.               break;
  43.          case   1 :  //Order History Report
  44.              if (QueryCustDlg->ShowModal() == mrOk)
  45.                try
  46.                {
  47.                  MastData->OrdQuery->Close();
  48.                  MastData->OrdQuery->Params->Items[0]->AsDateTime = QueryCustDlg->FromDate;
  49.                  MastData->OrdQuery->Params->Items[1]->AsDateTime = QueryCustDlg->ToDate;
  50.                  MastData->OrdQuery->Open();
  51.                  // Any records in the result set?
  52.                  if (MastData->OrdQuery->Bof && MastData->OrdQuery->Eof) {
  53.                    ShowMessage("No records were found in the given range.");
  54.                    return false;
  55.                  }
  56.                  else  {
  57.                    aReport=OrdersReportForm->OrdersReport;
  58.                      reportSet = true;
  59.                  }
  60.                }
  61.                catch(...)
  62.                {
  63.                  ShowMessage("Could not find order in given range.");
  64.                  reportSet = false;
  65.                }
  66.              break;
  67.          case   2 :     //Choose an order for which to print invoice
  68.              if (PickOrdDlg->ShowModal() == mrOk)
  69.                try
  70.                {
  71.                  int OrderNumber = 0;
  72.                  OrderNumber =PickOrdDlg->OrderNumber;
  73.                  if(OrderNumber)  {
  74.                    MastData->InvoiceQuery->Close();
  75.                    MastData->InvoiceQuery->Params->Items[0]->AsInteger = OrderNumber;
  76.                    MastData->InvoiceQuery->Open();
  77.                    // Any records in the result set?
  78.                    if (MastData->InvoiceQuery->Bof && MastData->InvoiceQuery->Eof){
  79.                      ShowMessage("The requested record was not found.");
  80.                      return false;
  81.                    }
  82.                    else {
  83.                      aReport=InvoiceReportForm->InvoiceReport;
  84.                       reportSet = true;
  85.                    }
  86.                  }
  87.                  else {
  88.                      ShowMessage("The requested record was not found.");
  89.                      return false;
  90.                  }
  91.                }
  92.                catch(...)
  93.                {
  94.                  ShowMessage("Unable to find requested record.");
  95.                  reportSet = false;
  96.                }
  97.              break;
  98.        }
  99.   aReport->DisplayPrintDialog =PrintDialogChk->Checked;
  100.   if (OrientationCombo->ItemIndex==0 )
  101.         aReport->Orientation=poPortrait;
  102.   else
  103.      aReport->Orientation=poLandscape;
  104.   return reportSet;
  105. }
  106. #pragma warn .aus
  107. //---------------------------------------------------------------------------
  108. void __fastcall TMainPrintForm::PreviewBtnClick(TObject *Sender)
  109. {
  110.  if( PickReport())
  111.    aReport->Preview();
  112. }
  113. //---------------------------------------------------------------------------
  114. void __fastcall TMainPrintForm::PreviewComboClick(TObject *Sender)
  115. {
  116.    if   (PreviewCombo->ItemIndex==0)    //use default ShowPreview()
  117.         QRPrinter->OnPreview=NULL;
  118.    else                                 //or assign overloaded ShowPreview()
  119.            QRPrinter->OnPreview = ShowPreview;
  120. }
  121. //---------------------------------------------------------------------------
  122. void __fastcall TMainPrintForm::CancelBtnClick(TObject *Sender)
  123. {
  124.  Close();
  125. }
  126. //---------------------------------------------------------------------------
  127.  
  128.