home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / borland / cb / setup / cbuilder / data.z / MAINPRNT.CPP < prev    next >
C/C++ Source or Header  |  1997-02-28  |  5KB  |  132 lines

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