FrmDbPrgressF.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "FrmDbPrgressF.h"
  5. #include "WindowMsgF.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma link "cxContainer"
  9. #pragma link "cxControls"
  10. #pragma link "cxEdit"
  11. #pragma link "cxGraphics"
  12. #pragma link "cxLookAndFeelPainters"
  13. #pragma link "cxLookAndFeels"
  14. #pragma link "cxProgressBar"
  15. #pragma link "dxSkinBlack"
  16. #pragma link "dxSkinBlue"
  17. #pragma link "dxSkinsCore"
  18. #pragma resource "*.dfm"
  19. //TFrmDbProgress *FrmDbProgress = NULL;
  20. //---------------------------------------------------------------------------
  21. __fastcall TDBThread::TDBThread()
  22. : TThread(true)
  23. {
  24. FreeOnTerminate = true;
  25. //Priority = tpTimeCritical;
  26. Priority = tpNormal;
  27. }
  28. //---------------------------------------------------------------------------
  29. void __fastcall TDBThread::SetQry(TADOQuery *adoQry, TForm *AForm)
  30. {
  31. m_ADOQry = adoQry;
  32. FParentForm = AForm;
  33. //Resume();
  34. }
  35. //---------------------------------------------------------------------------
  36. void __fastcall TDBThread::Execute()
  37. {
  38. try
  39. {
  40. m_ADOQry->Open();
  41. POST_MSG(FParentForm->Handle, WM_PARAM_DATABASE, WP_DB_SELECT_OK, 0);
  42. } catch(...)
  43. {
  44. POST_MSG(FParentForm->Handle, WM_PARAM_DATABASE, WP_DB_SELECT_ERROR, 0);
  45. }
  46. }
  47. //---------------------------------------------------------------------------
  48. //---------------------------------------------------------------------------
  49. __fastcall TFrmDbProgress::TFrmDbProgress(TComponent* Owner)
  50. : TForm(Owner)
  51. {
  52. //SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
  53. m_pThrDb = NULL;
  54. }
  55. //---------------------------------------------------------------------------
  56. void __fastcall TFrmDbProgress::FormShow(TObject *Sender)
  57. {
  58. Application->ProcessMessages();
  59. Refresh();
  60. Application->ProcessMessages();
  61. Refresh();
  62. Application->ProcessMessages();
  63. }
  64. //---------------------------------------------------------------------------
  65. void __fastcall TFrmDbProgress::btnCancelClick(TObject *Sender)
  66. {
  67. Close();
  68. }
  69. //---------------------------------------------------------------------------
  70. void __fastcall TFrmDbProgress::Init(String sCaption, int nMax, bool bCancel/*=false*/, bool bTimer/*=false*/)
  71. {
  72. Caption = sCaption;
  73. //PbProgress->Properties->Text = sCaption;
  74. PbProgress->Properties->Min = 0;
  75. PbProgress->Properties->Max = nMax;
  76. PbProgress->Position = 0;
  77. if (bCancel)
  78. {
  79. btnCancel->Enabled = true;
  80. Height = 112;//PbProgress->Top + PbProgress->Height + 30;
  81. }
  82. else
  83. {
  84. btnCancel->Enabled = false;
  85. Height = 80;//PbProgress->Top + PbProgress->Height + 30;
  86. }
  87. FParentForm = (TForm*)this->Owner;
  88. FParentForm->Enabled = false;
  89. int nTop = FParentForm->Top + (FParentForm->Height / 2) - Height;
  90. int nLeft= FParentForm->Left+ ((FParentForm->Width-Width) / 2);
  91. this->Top = nTop;
  92. this->Left= nLeft;
  93. Refresh();
  94. TmrProgress->Enabled = bTimer;
  95. Application->ProcessMessages();
  96. }
  97. //---------------------------------------------------------------------------
  98. void __fastcall TFrmDbProgress::Step(String sText, int nPos)
  99. {
  100. Label1->Caption = sText;
  101. PbProgress->Properties->Text = sText;
  102. PbProgress->Position = nPos;
  103. Refresh();
  104. Application->ProcessMessages();
  105. Application->ProcessMessages();
  106. }
  107. //---------------------------------------------------------------------------
  108. void __fastcall TFrmDbProgress::TmrProgressTimer(TObject *Sender)
  109. {
  110. int nPos = PbProgress->Position + 1;
  111. if (nPos > PbProgress->Properties->Max) nPos = 10;
  112. Step(PbProgress->Properties->Text, nPos);
  113. }
  114. //---------------------------------------------------------------------------
  115. void __fastcall TFrmDbProgress::SetQry(TADOQuery *adoQry)
  116. {
  117. m_pThrDb = new TDBThread;
  118. m_pThrDb->SetQry(adoQry, FParentForm);
  119. m_pThrDb->Resume();
  120. }
  121. //---------------------------------------------------------------------------
  122. void __fastcall TFrmDbProgress::FormClose(TObject *Sender, TCloseAction &Action)
  123. {
  124. TmrProgress->Enabled = false;
  125. try {
  126. if (m_pThrDb)
  127. {
  128. m_pThrDb->Terminate();
  129. }
  130. m_pThrDb = NULL;
  131. } catch(...) {}
  132. }
  133. //---------------------------------------------------------------------------
  134. void __fastcall TFrmDbProgress::TermThread()
  135. {
  136. try {
  137. if (m_pThrDb)
  138. {
  139. m_pThrDb->Terminate();
  140. }
  141. } catch(...) {}
  142. }
  143. //---------------------------------------------------------------------------