home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 May / VPR9705A.ISO / VPR_DATA / PROGRAM / CBTRIAL / SETUP / DATA.Z / EDORDERS.CPP < prev    next >
C/C++ Source or Header  |  1997-02-14  |  6KB  |  159 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 "edorders.h"
  10. #include "Datamod.h"
  11. #include "srchdlg.h"
  12. #include "pickdate.h"
  13. //---------------------------------------------------------------------------
  14. #pragma resource "*.dfm"
  15. TEdOrderForm *EdOrderForm;
  16. const char * DataSetStates[]={"Not active", "Browsing", "Editing", "Inserting", "", "", "", "", ""};
  17. const int HelpTopicEdit = 2;
  18. const int HelpTopicBrowse = 3;
  19. //---------------------------------------------------------------------------
  20. __fastcall TEdOrderForm::TEdOrderForm(TComponent* Owner)
  21.     : TForm(Owner)
  22. {
  23. }
  24.  
  25. void TEdOrderForm::Enter()
  26. {
  27.   MastData->OrdersSource->OnStateChange = OrdersSourceStateChange;
  28.   try
  29.   {
  30.     MastData->Orders->Open();
  31.     MastData->Orders->Insert();
  32.     ShowModal();
  33.   }
  34.   catch(...)  {
  35.     MastData->OrdersSource->OnStateChange = NULL;
  36.     return;
  37.   }
  38.   MastData->OrdersSource->OnStateChange = NULL;
  39. }
  40.  
  41. void TEdOrderForm::Edit(double OrderNo)
  42. {
  43.   MastData->OrdersSource->OnStateChange = OrdersSourceStateChange;
  44.   try
  45.   {
  46.     TLocateOptions  flags;
  47.     MastData->Orders->Open();
  48.     MastData->Orders->Locate("OrderNo", OrderNo, flags);
  49.     ShowModal();
  50.   }
  51.   catch (...)
  52.   {
  53.       MastData->OrdersSource->OnStateChange = NULL;
  54.       return;
  55.   }
  56.   MastData->OrdersSource->OnStateChange = NULL;
  57. }
  58.  
  59.  
  60. //---------------------------------------------------------------------------
  61. void __fastcall TEdOrderForm::ItemsGridEnter(TObject *Sender)
  62. {
  63.   ActiveSource->DataSet = MastData->Items;
  64. }
  65. //---------------------------------------------------------------------------
  66. // Update the mode indicator when the state of the "Active" datasource
  67. // (Orders or Items) changes.
  68. void __fastcall TEdOrderForm::ActiveSourceStateChange(TObject *Sender)
  69. {
  70.  // with ActiveSource do
  71.     if (ActiveSource->DataSet != NULL)
  72.     {
  73.       char MIcaption[80];
  74.       sprintf(MIcaption,"%s: %s",ActiveSource->DataSet->Name.c_str(),DataSetStates[ActiveSource->State]);
  75.       ModeIndicator->Caption=AnsiString(MIcaption);
  76.     }
  77.     if (ActiveSource->State==dsEdit || ActiveSource->State==dsInsert || ActiveSource->State==dsSetKey)
  78.     {
  79.       HelpContext = HelpTopicEdit;
  80.       ModeIndicator->Font->Color = clRed;
  81.     }
  82.     else
  83.     {
  84.       HelpContext = HelpTopicBrowse;
  85.       ModeIndicator->Font->Color = clBlue;
  86.     }
  87. }
  88. //---------------------------------------------------------------------------
  89. void __fastcall TEdOrderForm::ItemsGridExit(TObject *Sender)
  90. {
  91.   ActiveSource->DataSet = MastData->Orders;
  92. }
  93. //---------------------------------------------------------------------------
  94. void __fastcall TEdOrderForm::CancelBtnClick(TObject *Sender)
  95. {
  96.   MastData->OrdersAfterCancel(MastData->Orders);
  97. }
  98. //---------------------------------------------------------------------------
  99. void __fastcall TEdOrderForm::PostBtnClick(TObject *Sender)
  100. {
  101.   MastData->Orders->Post();
  102. }
  103. //---------------------------------------------------------------------------
  104. // Clicking on the PartNo button in the grid brings up PickPartNo dialog
  105. void __fastcall TEdOrderForm::PickPartNo(TObject *Sender)
  106. {
  107.   if (ItemsGrid->SelectedField == MastData->ItemsPartNo) //PartNo column only
  108.   {
  109.     if (MastData->ItemsPartNo->Value)
  110.       SearchDlg->PartNo = MastData->ItemsPartNo->Value;     //start with current PartNo
  111.     if (SearchDlg->ShowModalParts() == mrOk)
  112.     {
  113.       MastData->Items->Edit();
  114.       MastData->ItemsPartNo->Value = SearchDlg->PartNo;
  115.     }
  116.   }
  117. }
  118. //---------------------------------------------------------------------------
  119. // Browse a calendar to pick an invoice date
  120. void __fastcall TEdOrderForm::PickDate(TObject *Sender)
  121. {
  122.   BrDateForm->Date = MastData->OrdersSaleDate->Value;     //start with current date
  123.   if (BrDateForm->ShowModal() == mrOk)
  124.   {
  125.     MastData->Orders->Edit();
  126.     MastData->OrdersSaleDate->Value = BrDateForm->Date;
  127.     SaleDateEdit->SelectAll();
  128.   }
  129. }
  130. //---------------------------------------------------------------------------
  131. void __fastcall TEdOrderForm::PrintBtnClick(TObject *Sender)
  132. {
  133.   if(Confirm("Print image of this form window?"))
  134.     Print();
  135. }
  136. //---------------------------------------------------------------------------
  137. // Enable or disable buttons as needed when the state of the orders table changes
  138. void __fastcall TEdOrderForm::OrdersSourceStateChange(TObject * Sender)
  139. {
  140.   PostBtn->Enabled   = ((MastData->Orders->State==dsEdit) ||
  141.                         (MastData->Orders->State==dsInsert) ||
  142.                                 (MastData->Orders->State==dsSetKey));
  143.   CancelBtn->Enabled = PostBtn->Enabled;
  144.   CloseBtn->Enabled  = (MastData->Orders->State==dsBrowse);
  145. }
  146. //---------------------------------------------------------------------------
  147. void __fastcall TEdOrderForm::FormCloseQuery(TObject *Sender, bool &CanClose)
  148. {
  149.   CanClose = MastData->DataSetApplyUpdates(MastData->Orders, ModalResult == mrOk);
  150. }
  151. //---------------------------------------------------------------------------
  152. void __fastcall TEdOrderForm::SoldByComboKeyPress(TObject *Sender, char &Key)
  153. {
  154.   if (!((int)Key==13 || (int)Key==27))
  155.     Key = '0';
  156. }
  157. //---------------------------------------------------------------------------
  158.  
  159.