home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 May / VPR9705A.ISO / VPR_DATA / PROGRAM / CBTRIAL / SETUP / DATA.Z / CUSTVIEW.CPP < prev    next >
C/C++ Source or Header  |  1997-02-14  |  4KB  |  116 lines

  1. //----------------------------------------------------------------------------
  2. //Borland C++Builder
  3. //Copyright (c) 1987, 1997 Borland International Inc. All Rights Reserved.
  4. //----------------------------------------------------------------------------
  5. //---------------------------------------------------------------------------
  6. #include <vcl.h>
  7. #pragma hdrstop
  8.  
  9. #include "CustView.h"
  10. #include "DM.h"
  11. #include "Filter1.h"
  12. #include "About.h"
  13.  
  14. //---------------------------------------------------------------------------
  15. #pragma resource "*.dfm"
  16. //---------------------------------------------------------------------------
  17. __fastcall TfmCustView::TfmCustView(TComponent* Owner)
  18.   : TForm(Owner)
  19. {
  20. }
  21. //---------------------------------------------------------------------------
  22.  
  23. TfmCustView* fmCustView;
  24.  
  25. // Change the DataSet for the Customer from Query to Table,
  26. // or Table to Query. If a filter is current, set that filter
  27. // to the just-changed DataSet.
  28. //
  29. void __fastcall TfmCustView::rgDataSetClick(TObject *Sender)
  30. {
  31.   TDataSource *src(DM1->CustomerSource);
  32.   AnsiString st;
  33.  
  34.   // Is the other DataSet Filtered? If so, get its filter.
  35.   if (src->DataSet->Filtered)
  36.     st = src->DataSet->Filter;
  37.  
  38.   if (rgDataSet->ItemIndex) {
  39.       if (src->DataSet != DM1->Customer)
  40.         src->DataSet = DM1->Customer;
  41.   }
  42.   else {
  43.       if (src->DataSet != DM1->SQLCustomer)
  44.         src->DataSet = DM1->SQLCustomer;
  45.   }
  46.  
  47.   // Set the Filter of the current DataSet.
  48.   if (st != "") {
  49.     src->DataSet->Filter = st;
  50.     src->DataSet->Filtered = true;
  51.   }
  52. }
  53.  
  54. void __fastcall TfmCustView::SpeedButton1Click(TObject *Sender)
  55. {
  56.   fmFilterFrm->Show();
  57. }
  58.  
  59. // DM1->SQLOrders->Filtered will be true if the box is checked.
  60. //
  61. void __fastcall TfmCustView::cbFilterOrdersClick(TObject *Sender)
  62. {
  63.   DM1->SQLOrders->Filtered = cbFilterOrders->Checked;
  64.  
  65.   // If the number changed while the box is unchecked, DM1->OrdersFilterAmount
  66.   // won't know about it.  The Edit1Change procedure will set the value and
  67.   // apply the filter.
  68.   if (cbFilterOrders->Checked)
  69.     Edit1Change(NULL); // ...to make sure the value is set.
  70. }
  71.  
  72. void __fastcall TfmCustView::About1Click(TObject *Sender)
  73. {
  74.   TfmAboutBox* fmAboutBox(new TfmAboutBox(this));
  75.   fmAboutBox->ShowModal();
  76.   delete fmAboutBox;
  77. }
  78.  
  79. void __fastcall TfmCustView::Edit1Change(TObject *Sender)
  80. {
  81.   // We must insure that Edit1->Text is not blank, or an exception will
  82.   // be thrown when the user clears the contents of the Edit.
  83.  
  84.   if (cbFilterOrders->Checked && Edit1->Text != "") {
  85.     try {
  86.       // Attempt to set the variable on DM1 that holds the filter amount.
  87.       DM1->OrdersFilterAmount = StrToFloat(fmCustView->Edit1->Text);
  88.  
  89.       // Refreshing SQLOrders will cause DM1->SQLOrdersFilterRecord to be
  90.       // called once for each orders record for the current Customer. 
  91.       DM1->SQLOrders->Refresh();
  92.     }
  93.     catch (EConvertError* exc) {
  94.         // This happens before DM1->SQLOrders->Refresh() if the user typed in a
  95.         // non-numeric value, thus preventing it from trying to use an invalid
  96.         // value to filter itself, which would raise an exception once for
  97.         // each record displayed.
  98.         throw Exception("Threshold Amount must be a number.");
  99.     }
  100.   }
  101. }
  102.  
  103. // Set the navigator to the Customer Datasource. 
  104. //
  105. void __fastcall TfmCustView::DBGrid1Enter(TObject *Sender)
  106. {
  107.   DBNavigator1->DataSource = DBGrid1->DataSource;
  108. }
  109.  
  110. //  Set the navigator to the Orders Datasource.
  111. //
  112. void __fastcall TfmCustView::DBGrid2Enter(TObject *Sender)
  113. {
  114.   DBNavigator1->DataSource = DBGrid2->DataSource;
  115. }
  116.