home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1997 May
/
Pcwk0597.iso
/
borland
/
cb
/
setup
/
cbuilder
/
data.z
/
MAINPRNT.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1997-02-28
|
5KB
|
132 lines
//---------------------------------------------------------------------------
// Borland C++Builder
// Copyright (c) 1987, 1997 Borland International Inc. All Rights Reserved.
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop
#include "mainprnt.h"
#include "custrpt.h"
#include "preview.h"
#include "qrycust.h"
#include "Datamod.h"
#include "OrderRpt.h"
#include "Invoice.h"
#include "PickRep.h"
//---------------------------------------------------------------------------
#pragma resource "*.dfm"
TMainPrintForm *MainPrintForm;
//---------------------------------------------------------------------------
__fastcall TMainPrintForm::TMainPrintForm(TComponent* Owner)
: TForm(Owner)
{
ReportCombo->ItemIndex=0;
OrientationCombo->ItemIndex=0;
PreviewCombo->ItemIndex=0;
}
//---------------------------------------------------------------------------
void __fastcall TMainPrintForm::PrintBtnClick(TObject *Sender)
{
aReport->Print();
}
//---------------------------------------------------------------------
void __fastcall TMainPrintForm::ShowPreview()
{
PrevForm->ShowModal();
}//---------------------------------------------------------------------------
#pragma warn -aus
bool TMainPrintForm::PickReport()
{
bool reportSet = false;
switch( ReportCombo->ItemIndex) {
case 0 : //Customer Report
aReport=CustReportForm->CustomerReport;
reportSet = true;
break;
case 1 : //Order History Report
if (QueryCustDlg->ShowModal() == mrOk)
try
{
MastData->OrdQuery->Close();
MastData->OrdQuery->Params->Items[0]->AsDateTime = QueryCustDlg->FromDate;
MastData->OrdQuery->Params->Items[1]->AsDateTime = QueryCustDlg->ToDate;
MastData->OrdQuery->Open();
// Any records in the result set?
if (MastData->OrdQuery->Bof && MastData->OrdQuery->Eof) {
ShowMessage("No records were found in the given range.");
return false;
}
else {
aReport=OrdersReportForm->OrdersReport;
reportSet = true;
}
}
catch(...)
{
ShowMessage("Could not find order in given range.");
reportSet = false;
}
break;
case 2 : //Choose an order for which to print invoice
if (PickOrdDlg->ShowModal() == mrOk)
try
{
int OrderNumber = 0;
OrderNumber =PickOrdDlg->OrderNumber;
if(OrderNumber) {
MastData->InvoiceQuery->Close();
MastData->InvoiceQuery->Params->Items[0]->AsInteger = OrderNumber;
MastData->InvoiceQuery->Open();
// Any records in the result set?
if (MastData->InvoiceQuery->Bof && MastData->InvoiceQuery->Eof){
ShowMessage("The requested record was not found.");
return false;
}
else {
aReport=InvoiceReportForm->InvoiceReport;
reportSet = true;
}
}
else {
ShowMessage("The requested record was not found.");
return false;
}
}
catch(...)
{
ShowMessage("Unable to find requested record.");
reportSet = false;
}
break;
}/*switch*/
aReport->DisplayPrintDialog =PrintDialogChk->Checked;
if (OrientationCombo->ItemIndex==0 )
aReport->Orientation=poPortrait;
else
aReport->Orientation=poLandscape;
return reportSet;
}
#pragma warn .aus
//---------------------------------------------------------------------------
void __fastcall TMainPrintForm::PreviewBtnClick(TObject *Sender)
{
if( PickReport())
aReport->Preview();
}
//---------------------------------------------------------------------------
void __fastcall TMainPrintForm::PreviewComboClick(TObject *Sender)
{
if (PreviewCombo->ItemIndex==0) //use default ShowPreview()
QRPrinter->OnPreview=NULL;
else //or assign overloaded ShowPreview()
QRPrinter->OnPreview = ShowPreview;
}
//---------------------------------------------------------------------------
void __fastcall TMainPrintForm::CancelBtnClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------