home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / borland / cb / setup / cbuilder / data.z / SRCHDLG.CPP < prev    next >
C/C++ Source or Header  |  1997-02-28  |  4KB  |  100 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 "srchdlg.h"
  10. #include "Datamod.h"
  11. //---------------------------------------------------------------------------
  12. #pragma resource "*.dfm"
  13. TSearchDlg *SearchDlg;
  14. //---------------------------------------------------------------------------
  15. __fastcall TSearchDlg::TSearchDlg(TComponent* Owner)
  16.     : TForm(Owner)
  17. {
  18. }
  19. //---------------------------------------------------------------------------
  20. void __fastcall TSearchDlg::DBGrid1DblClick(TObject *Sender)
  21. {
  22.   ModalResult = mrOk;
  23. }
  24. //---------------------------------------------------------------------------
  25. void __fastcall TSearchDlg::SearchButtonClick(TObject *Sender)
  26. {
  27.   TLocateOptions flags;
  28.   flags << loPartialKey << loCaseInsensitive;
  29.   if (!DataSource->DataSet->Locate(OrderCombo->Text, SearchEd->Text, flags))
  30.       MessageBox(NULL,"No matching record found.", "Information", MB_OK);
  31. }
  32. //---------------------------------------------------------------------------
  33. void __fastcall TSearchDlg::OrderComboChange(TObject *Sender)
  34. {
  35.   SrchFld = DataSource->DataSet->FieldByName(OrderCombo->Text);
  36.   SearchEd->Text = " ";
  37. }
  38. //---------------------------------------------------------------------------
  39. void __fastcall TSearchDlg::SearchEdKeyPress(TObject *Sender, char &Key)
  40. {
  41.   if ((SrchFld!=NULL) && (Key != ' ') &&  !SrchFld->IsValidChar(Key) )
  42.   {
  43.     MessageBeep(0);
  44.     Key = '0';
  45.   }
  46. }
  47. //---------------------------------------------------------------------------
  48. void __fastcall TSearchDlg::SearchEdChange(TObject *Sender)
  49. {
  50.   SearchButton->Enabled =  !SearchEd->Text.IsEmpty();
  51. }
  52. //---------------------------------------------------------------------------
  53. double TSearchDlg::GetCustNo()
  54. {
  55.   return MastData->CustCustNo->Value;
  56. }
  57. //---------------------------------------------------------------------------
  58. void TSearchDlg::SetCustNo(double NewCustNo)
  59. {
  60.   TLocateOptions flags;
  61.   MastData->Cust->Locate("CustNo", NewCustNo, flags);
  62. }
  63. //---------------------------------------------------------------------------
  64. double TSearchDlg::GetPartNo()
  65. {
  66.   return MastData->PartsPartNo->Value;
  67. }
  68. //---------------------------------------------------------------------------
  69. void TSearchDlg::SetPartNo(double NewPartNo)
  70. {
  71.   TLocateOptions flags;
  72.   MastData->Parts->Locate("PartNo", NewPartNo, flags);
  73. }
  74. //---------------------------------------------------------------------------
  75. int TSearchDlg::ShowModalCust()
  76. {
  77.   OrderCombo->Items->Clear();
  78.   OrderCombo->Items->Add("Company");
  79.   OrderCombo->Items->Add("CustNo");
  80.   OrderCombo->ItemIndex = 0;
  81.   DataSource->DataSet = MastData->Cust;
  82.   OrderComboChange(0);
  83.   Caption = "Select a Customer";
  84.   return ShowModal();
  85. }
  86. //---------------------------------------------------------------------------
  87. int TSearchDlg::ShowModalParts()
  88. {
  89.   OrderCombo->Items->Clear();
  90.   OrderCombo->Items->Add("Description");
  91.   OrderCombo->Items->Add("PartNo");
  92.   OrderCombo->ItemIndex = 0;
  93.   DataSource->DataSet = MastData->Parts;
  94.   OrderComboChange(0);
  95.   Caption = "Select a Part";
  96.   return ShowModal();
  97. }
  98. //---------------------------------------------------------------------------
  99.  
  100.