home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / borland / cb / setup / cbuilder / data.z / ADRU1.CPP < prev    next >
C/C++ Source or Header  |  1997-02-28  |  9KB  |  259 lines

  1. //----------------------------------------------------------------------------
  2. //Borland C++Builder
  3. //Copyright (c) 1987, 1997 Borland International Inc. All Rights Reserved.
  4. //----------------------------------------------------------------------------
  5. //---------------------------------------------------------------------
  6. // CUSTOMER CONTACT BROWSER DEMO v.01
  7. //
  8. // Key Points:
  9. //
  10. // 1. Simple 1-Many join on a single field.
  11. // 2. Parameterized Query.
  12. // 3. Binding of parameters in code at runtime.
  13. // 4. Dataset navigation in code.
  14. // 5. Usefull implimentation of DataSet OnStateChange and State property.
  15. //
  16. // Pending Issues:
  17. //
  18. // 1. Tab order
  19. // 2. Control Names
  20. // 3. Hot Keys of labels related to "Orders" controls
  21. //
  22. //
  23. //    Modifications:
  24. //
  25. //---------------------------------------------------------------------
  26. #include <vcl.h>
  27. #pragma hdrstop
  28.  
  29. #include "adru1.h"
  30. //---------------------------------------------------------------------
  31. #pragma resource "*.dfm"
  32. TForm1 *Form1;
  33. //---------------------------------------------------------------------
  34. __fastcall TForm1::TForm1(TComponent *Owner)
  35.   : TForm(Owner)
  36. {
  37. }
  38. //---------------------------------------------------------------------
  39. void __fastcall TForm1::BitBtn1Click(TObject* /*Sender*/)
  40. {    Close();
  41. }
  42. //----------------------------------------------------------------------------
  43. void __fastcall TForm1::TabControl1Change(TObject* /*Sender*/)
  44. {    char cParam[3] = {'A','%',0};
  45.      AnsiString  sParam = (AnsiString)"paramVar1";
  46.      cParam[0] = (char)(65+TabControl1->TabIndex);
  47.      Query1->Cancel();    Table1->Cancel();
  48.      Table1->Close();     Query1->Close();
  49.      Query1->ParamByName(sParam)->AsString = (AnsiString)cParam;
  50.      Query1->Open();      Table1->Open();
  51.      EnableDisableCsNav();
  52.      EnableDisableOrNav();
  53. }
  54.  
  55. //----------------------------------------------------------------------------
  56. void __fastcall TForm1::FirstCustClick(TObject* /*Sender*/)
  57. {    Query1->First(); EnableDisableCsNav();
  58. }
  59. //----------------------------------------------------------------------------
  60. void __fastcall TForm1::PriorCustClick(TObject* /*Sender*/)
  61. {    Query1->Prior(); EnableDisableCsNav();
  62. }
  63. //----------------------------------------------------------------------------
  64. void __fastcall TForm1::NextCustClick(TObject* /*Sender*/)
  65. {    Query1->Next(); EnableDisableCsNav();
  66. }
  67. //----------------------------------------------------------------------------
  68. void __fastcall TForm1::LastCustClick(TObject* /*Sender*/)
  69. {    Query1->Last(); EnableDisableCsNav();
  70. }
  71. //----------------------------------------------------------------------------
  72. void __fastcall TForm1::EditCustClick(TObject* /*Sender*/)
  73. {    Query1->Edit();
  74. }
  75. //----------------------------------------------------------------------------
  76. void __fastcall TForm1::PostCustClick(TObject* /*Sender*/)
  77. {    Query1->Post();
  78. }
  79. //----------------------------------------------------------------------------
  80. void __fastcall TForm1::CancelCustClick(TObject* /*Sender*/)
  81. {    Query1->Cancel();
  82. }
  83. //----------------------------------------------------------------------------
  84. void __fastcall TForm1::FormClose(TObject* /*Sender*/,
  85.      TCloseAction & /*Action*/)
  86. {    Table1->Cancel();  Table1->Close();
  87.      Query1->Cancel();  Query1->Close();
  88. }
  89. //----------------------------------------------------------------------------
  90. void __fastcall TForm1::FormCreate(TObject* /*Sender*/)
  91. {    Table1->Open();
  92.      Query1->Open();
  93.      EnableDisableOrNav();
  94.      EnableDisableCsNav();
  95. }
  96. //----------------------------------------------------------------------------
  97. void __fastcall TForm1::CancelOrdersClick(TObject* /*Sender*/)
  98. {    Table1->Cancel();
  99. }
  100. //----------------------------------------------------------------------------
  101. void __fastcall TForm1::PostOrdersClick(TObject* /*Sender*/)
  102. {    Table1->Post();
  103. }
  104. //----------------------------------------------------------------------------
  105. void __fastcall TForm1::EditOrdersClick(TObject* /*Sender*/)
  106. {    Table1->Edit();
  107. }
  108. //----------------------------------------------------------------------------
  109. void __fastcall TForm1::LastOrdersClick(TObject* /*Sender*/)
  110. {    Table1->Last(); EnableDisableOrNav();
  111. }
  112. //----------------------------------------------------------------------------
  113. void __fastcall TForm1::NextOrdersClick(TObject* /*Sender*/)
  114. {    Table1->Next(); EnableDisableOrNav();
  115. }
  116. //----------------------------------------------------------------------------
  117. void __fastcall TForm1::PriorOrdersClick(TObject* /*Sender*/)
  118. {    Table1->Prior(); EnableDisableOrNav();
  119. }
  120. //----------------------------------------------------------------------------
  121. void __fastcall TForm1::FirstOrdersClick(TObject* /*Sender*/)
  122. {    Table1->First(); EnableDisableOrNav();
  123. }
  124. //----------------------------------------------------------------------------
  125. void __fastcall TForm1::EnableDisableOrNav()
  126. {
  127.      FirstOrders->Enabled = (!Table1->Bof ? True : False );
  128.      PriorOrders->Enabled = (!Table1->Bof ? True : False );
  129.      NextOrders->Enabled  = (!Table1->Eof ? True : False );
  130.      LastOrders->Enabled  = (!Table1->Eof ? True : False );
  131.  
  132. }
  133. //----------------------------------------------------------------------------
  134. void __fastcall TForm1::EnableDisableCsNav()
  135. {
  136.      FirstCust->Enabled = (!Query1->Bof ? True : False );
  137.      PriorCust->Enabled = (!Query1->Bof ? True : False );
  138.      NextCust->Enabled  = (!Query1->Eof ? True : False );
  139.      LastCust->Enabled  = (!Query1->Eof ? True : False );
  140. }
  141. //----------------------------------------------------------------------------
  142. void __fastcall TForm1::DataSource1StateChange(TObject* /*Sender*/)
  143. {    switch(Query1->State) {
  144.         case dsInactive   : {
  145.              EditCust->Enabled = False;
  146.              PostCust->Enabled = False;
  147.              CancelCust->Enabled = False;
  148.              break;
  149.         }
  150.         case dsBrowse     : {
  151.              EditCust->Enabled = True;
  152.              PostCust->Enabled = False;
  153.              CancelCust->Enabled = False;
  154.              break;
  155.         }
  156.         case dsEdit       : {
  157.              EditCust->Enabled = False;
  158.              PostCust->Enabled = True;
  159.              CancelCust->Enabled = True;
  160.              break;
  161.         }
  162.         case dsInsert     : {
  163.              EditCust->Enabled = False;
  164.              PostCust->Enabled = False;
  165.              CancelCust->Enabled = False;
  166.              break;
  167.         }
  168.         case dsSetKey     : {
  169.              EditCust->Enabled = False;
  170.              PostCust->Enabled = True;
  171.              CancelCust->Enabled = False;
  172.              break;
  173.         }
  174.         case dsCalcFields : {
  175.              EditCust->Enabled = False;
  176.              PostCust->Enabled = False;
  177.              CancelCust->Enabled = False;
  178.              break;
  179.         }
  180.         case dsUpdateNew  : {
  181.              EditCust->Enabled = False;
  182.              PostCust->Enabled = False;
  183.              CancelCust->Enabled = False;
  184.              break;
  185.         }
  186.         case dsUpdateOld  : {
  187.              EditCust->Enabled = False;
  188.              PostCust->Enabled = False;
  189.              CancelCust->Enabled = False;
  190.              break;
  191.         }
  192.         case dsFilter     : {
  193.              EditCust->Enabled = False;
  194.              PostCust->Enabled = False;
  195.              CancelCust->Enabled = False;
  196.              break;
  197.         }
  198.      }
  199. }
  200. //----------------------------------------------------------------------------
  201. void __fastcall TForm1::DataSource2StateChange(TObject* /*Sender*/)
  202. {    switch(Table1->State) {
  203.         case dsInactive   : {
  204.              EditOrders->Enabled = False;
  205.              PostOrders->Enabled = False;
  206.              CancelOrders->Enabled = False;
  207.              break;
  208.         }
  209.         case dsBrowse     : {
  210.              EditOrders->Enabled = True;
  211.              PostOrders->Enabled = False;
  212.              CancelOrders->Enabled = False;
  213.              break;
  214.         }
  215.         case dsEdit       : {
  216.              EditOrders->Enabled = False;
  217.              PostOrders->Enabled = True;
  218.              CancelOrders->Enabled = True;
  219.              break;
  220.         }
  221.         case dsInsert     : {
  222.              EditOrders->Enabled = False;
  223.              PostOrders->Enabled = False;
  224.              CancelOrders->Enabled = False;
  225.              break;
  226.         }
  227.         case dsSetKey     : {
  228.              EditOrders->Enabled = False;
  229.              PostOrders->Enabled = True;
  230.              CancelOrders->Enabled = False;
  231.              break;
  232.         }
  233.         case dsCalcFields : {
  234.              EditOrders->Enabled = False;
  235.              PostOrders->Enabled = False;
  236.              CancelOrders->Enabled = False;
  237.              break;
  238.         }
  239.         case dsUpdateNew  : {
  240.              EditOrders->Enabled = False;
  241.              PostOrders->Enabled = False;
  242.              CancelOrders->Enabled = False;
  243.              break;
  244.         }
  245.         case dsUpdateOld  : {
  246.              EditOrders->Enabled = False;
  247.              PostOrders->Enabled = False;
  248.              CancelOrders->Enabled = False;
  249.              break;
  250.         }
  251.         case dsFilter     : {
  252.              EditOrders->Enabled = False;
  253.              PostOrders->Enabled = False;
  254.              CancelOrders->Enabled = False;
  255.              break;
  256.         }
  257.      }
  258. }
  259.