home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / borland / cb / setup / cbuilder / data.z / BRCSTORD.CPP < prev    next >
C/C++ Source or Header  |  1997-02-28  |  5KB  |  123 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 "brcstord.h"
  10. #include "Datamod.h"
  11. #include "qrycust.h"
  12. #include "edcust.h"
  13. #include "edorders.h"
  14. #include "main.h"
  15. //---------------------------------------------------------------------------
  16. #pragma resource "*.dfm"
  17. TBrCustOrdForm *BrCustOrdForm;
  18. //---------------------------------------------------------------------------
  19. __fastcall TBrCustOrdForm::TBrCustOrdForm(TComponent* Owner)
  20.     : TForm(Owner)
  21. {
  22. }
  23. //---------------------------------------------------------------------------
  24. void __fastcall TBrCustOrdForm::CustGridEnter(TObject *Sender)
  25. {
  26.   ActiveSource = MastData->CustMasterSrc;
  27.   CustGrid->Options = CustGrid->Options << dgAlwaysShowSelection;
  28.   OrdersGrid->Options = OrdersGrid->Options >> dgAlwaysShowSelection;
  29. }
  30. //---------------------------------------------------------------------------
  31. void __fastcall TBrCustOrdForm::SetQuery(TObject *Sender)
  32. {
  33.   if (QueryCustDlg->ShowModal() == mrOk)
  34.     ActivateQuery(this);
  35. }
  36. //---------------------------------------------------------------------------
  37. void __fastcall TBrCustOrdForm::ActivateQuery(TObject *Sender)
  38. {
  39.   if (!ActivateBtn->Down)
  40.     MastData->CustMasterSrc->DataSet = MastData->Cust;
  41.   else
  42.   //  with MastData.CustQuery do
  43.     try
  44.     {
  45.       MastData->CustQuery->Close();
  46.       MastData->CustQuery->Params->Items[0]->AsDateTime = QueryCustDlg->FromDate;
  47.       MastData->CustQuery->Params->Items[1]->AsDateTime = QueryCustDlg->ToDate;
  48.       MastData->CustQuery->Open();
  49.       // Any records in the result set?
  50.       if (MastData->CustQuery->Bof && MastData->CustQuery->Eof)
  51.         return;
  52.       MastData->CustMasterSrc->DataSet = MastData->CustQuery;
  53.     }
  54.     catch(...)
  55.     {
  56.       MastData->CustMasterSrc->DataSet = MastData->Cust;
  57.       ActivateBtn->Down = false;
  58.       ShowMessage("No matching records in the specified date range.");
  59.     }
  60. }
  61. //---------------------------------------------------------------------------
  62. void __fastcall TBrCustOrdForm::EditBtnClick(TObject *Sender)
  63. {
  64.   TFloatField *F;
  65.   F = static_cast<TFloatField*>(ActiveSource->DataSet->Fields[0]);
  66.   if (ActiveSource == MastData->CustMasterSrc)
  67.     EdCustForm->Edit(F->Value);
  68.   else  {
  69.     EdOrderForm->Edit(F->Value);
  70.     ActiveSource->DataSet->Refresh();
  71.   }
  72. }
  73. //---------------------------------------------------------------------------
  74. void __fastcall TBrCustOrdForm::CloseBtnClick(TObject *Sender)
  75. {
  76.   Close();
  77. }
  78. //---------------------------------------------------------------------------
  79. void __fastcall TBrCustOrdForm::OrdersGridEnter(TObject *Sender)
  80. {
  81.   ActiveSource = MastData->OrdByCustSrc;
  82.   OrdersGrid->Options = OrdersGrid->Options << dgAlwaysShowSelection;
  83.   CustGrid->Options = CustGrid->Options >> dgAlwaysShowSelection;
  84. }
  85. //---------------------------------------------------------------------------
  86. void TBrCustOrdForm::SetActiveSource(TDataSource *DataSource)
  87. {
  88.   FActiveSource = DataSource;
  89.   Navigator->DataSource = FActiveSource;
  90. }
  91. //---------------------------------------------------------------------------
  92. void TBrCustOrdForm::SetCustNo(double NewCustNo)
  93. {
  94.   TLocateOptions flags;
  95.   MastData->CustMasterSrc->DataSet = MastData->Cust;
  96.   MastData->Cust->Locate("CustNo", NewCustNo, flags);
  97. }
  98. //---------------------------------------------------------------------------
  99. void TBrCustOrdForm::SetOrderNo(double NewOrderNo)
  100. {
  101.   TLocateOptions flags;
  102.   MastData->OrdByCust->Locate("OrderNo", NewOrderNo, flags);
  103. }
  104. //---------------------------------------------------------------------------
  105. double TBrCustOrdForm::GetCustNo()
  106. {
  107.   return MastData->CustMasterSrc->DataSet->Fields[0]->AsFloat;
  108. }
  109. //---------------------------------------------------------------------------
  110. double TBrCustOrdForm::GetOrderNo()
  111. {
  112.   return MastData->OrdByCustOrderNo->Value;
  113. }
  114. //---------------------------------------------------------------------------
  115.  
  116.  
  117. void __fastcall TBrCustOrdForm::FormShow(TObject *Sender)
  118. {
  119.   MastData->Cust->Open();
  120.   MastData->Cust->First();
  121. }
  122. //---------------------------------------------------------------------------
  123.