home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 April / Chip_1997-04_cd.bin / prezent / cb / data.z / EDORDERS.CPP < prev    next >
C/C++ Source or Header  |  1997-01-16  |  5KB  |  155 lines

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