home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / progs / CB / DATA.Z / GDSDATA.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-16  |  4.3 KB  |  134 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "GdsData.h"
  6. //---------------------------------------------------------------------------
  7. #pragma resource "*.dfm"
  8. TStdDataForm *StdDataForm;
  9. //---------------------------------------------------------------------------
  10. __fastcall TStdDataForm::TStdDataForm(TComponent* Owner)
  11.   : TGDSStdForm(Owner)
  12. {
  13. }
  14. //---------------------------------------------------------------------------
  15. void __fastcall TStdDataForm::FormCreate(TObject *Sender)
  16. {
  17.   FLastDate = EncodeDate(1995, 1, 1);
  18.   FLastAmount = 1000;
  19.   FilterOnRadioGroup->ItemIndex = 0;
  20. }
  21.  
  22. /* Calculate the value of AmountDue. Used in the OnCalcFields
  23.   and OnFilterRecord event handlers. */
  24.  
  25. double __fastcall TStdDataForm::CalcAmountDue(void)
  26. {
  27.   return OrdersItemsTotal->Value * (1.0 + OrdersTaxRate->Value / 100) +
  28.     OrdersFreight->Value - OrdersAmountPaid->Value;
  29. }
  30.  
  31. //---------------------------------------------------------------------
  32. void __fastcall TStdDataForm::FilterOnRadioGroupClick(TObject *Sender)
  33. {
  34.    FilterOnLabel->Caption = Format("Records where %s >=",
  35.        OPENARRAY(TVarRec, (FilterOnRadioGroup->Items[FilterOnRadioGroup->ItemIndex]->Text)));
  36.    switch (FilterOnRadioGroup->ItemIndex)
  37.      {
  38.      case 0:
  39.           Orders->OnFilterRecord = OrdersFilterOnDate;
  40.           FilterCriteria->Text = DateToStr(FLastDate);
  41.         break;
  42.      case 1:
  43.           Orders->OnFilterRecord = OrdersFilterOnAmount;
  44.           FilterCriteria->Text = FloatToStr(FLastAmount);
  45.         break;
  46.      }
  47.    ActiveControl = FilterCriteria;
  48.  
  49.   if (Orders->Filtered) Orders->Refresh();
  50. }
  51.  
  52. /* Convert the FilterCriteria text into a Date or Float.  This value
  53.   will be used in the OnFilterRecord callback instead of using the
  54.   FilterCriteria directly, so that the string does not need to be
  55.   converted each time the event is triggered. */
  56.  
  57. void __fastcall TStdDataForm::ConvertFilterCriteria(void)
  58. {
  59.   if (FilterCriteria->Text != "")
  60.        {
  61.     switch (FilterOnRadioGroup->ItemIndex)
  62.       {
  63.       case 0:
  64.               FLastDate = StrToDate(FilterCriteria->Text);
  65.               break;
  66.       case 1:
  67.               FLastAmount = StrToFloat(FilterCriteria->Text);
  68.               break;
  69.       }
  70.     }
  71.   if (Orders->Filtered) Orders->Refresh();
  72. }
  73.  
  74. //---------------------------------------------------------------------
  75. void __fastcall TStdDataForm::FilterCriteriaExit(TObject *Sender)
  76. {
  77.   ConvertFilterCriteria();
  78. }
  79. //---------------------------------------------------------------------
  80. void __fastcall TStdDataForm::FilterCriteriaKeyPress(TObject *Sender,
  81.       Char &Key)
  82. {
  83.   if (Key == 0x13)
  84.   {
  85.     ConvertFilterCriteria();
  86.     Key = 0x00;
  87.   }
  88. }
  89.  
  90. /* Calculate this order's total on the fly. Include in the dataset
  91.   if its amount is greater than or equal to the specified filter
  92.   criteria. Note that calculated and lookup fields are undefined
  93.   in an OnFilterRecord event handler. */                   
  94. void __fastcall TStdDataForm::OrdersFilterOnAmount(TDataSet * DataSet, Boolean & Accept)
  95. {
  96.   Accept = (CalcAmountDue() >= FLastAmount);
  97. }
  98.  
  99. /* Include this order in the dataset if its date is greater
  100.   than or equal to the specified filter criteria. */
  101. void __fastcall TStdDataForm::OrdersFilterOnDate(TDataSet * DataSet, Boolean & Accept)
  102. {
  103.   Accept = (OrdersSaleDate->Value >= FLastDate);
  104. }
  105.  
  106. void __fastcall TStdDataForm::OrdersCalcFields(TDataSet * DataSet)
  107. {
  108.   OrdersTaxAmount->Value = OrdersItemsTotal->Value * (OrdersTaxRate->Value / 100);
  109.   OrdersAmountDue->Value = CalcAmountDue();
  110. }
  111.  
  112. //---------------------------------------------------------------------
  113. void __fastcall TStdDataForm::FilterCheckBoxClick(TObject *Sender)
  114. {
  115.   ConvertFilterCriteria();
  116.   Orders->Filtered = FilterCheckBox->Checked;
  117.   NextBtn->Enabled = ! FilterCheckBox->Checked;
  118.   PriorBtn->Enabled = ! FilterCheckBox->Checked;
  119. }
  120. //---------------------------------------------------------------------
  121. void __fastcall TStdDataForm::NextBtnClick(TObject *Sender)
  122. {
  123.   ConvertFilterCriteria();
  124.   Orders->FindNext();
  125. }
  126. //---------------------------------------------------------------------
  127. void __fastcall TStdDataForm::PriorBtnClick(TObject *Sender)
  128. {
  129.   ConvertFilterCriteria();
  130.   Orders->FindPrior();
  131. }
  132. //---------------------------------------------------------------------
  133.  
  134.