123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "FrmDbPrgressF.h"
- #include "WindowMsgF.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma link "cxContainer"
- #pragma link "cxControls"
- #pragma link "cxEdit"
- #pragma link "cxGraphics"
- #pragma link "cxLookAndFeelPainters"
- #pragma link "cxLookAndFeels"
- #pragma link "cxProgressBar"
- #pragma link "dxSkinBlack"
- #pragma link "dxSkinBlue"
- #pragma link "dxSkinsCore"
- #pragma resource "*.dfm"
- //TFrmDbProgress *FrmDbProgress = NULL;
- //---------------------------------------------------------------------------
- __fastcall TDBThread::TDBThread()
- : TThread(true)
- {
- FreeOnTerminate = true;
- //Priority = tpTimeCritical;
- Priority = tpNormal;
- }
- //---------------------------------------------------------------------------
- void __fastcall TDBThread::SetQry(TADOQuery *adoQry, TForm *AForm)
- {
- m_ADOQry = adoQry;
- FParentForm = AForm;
- //Resume();
- }
- //---------------------------------------------------------------------------
- void __fastcall TDBThread::Execute()
- {
- try
- {
- m_ADOQry->Open();
- POST_MSG(FParentForm->Handle, WM_PARAM_DATABASE, WP_DB_SELECT_OK, 0);
- } catch(...)
- {
- POST_MSG(FParentForm->Handle, WM_PARAM_DATABASE, WP_DB_SELECT_ERROR, 0);
- }
- }
- //---------------------------------------------------------------------------
- //---------------------------------------------------------------------------
- __fastcall TFrmDbProgress::TFrmDbProgress(TComponent* Owner)
- : TForm(Owner)
- {
- //SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
- m_pThrDb = NULL;
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmDbProgress::FormShow(TObject *Sender)
- {
- Application->ProcessMessages();
- Refresh();
- Application->ProcessMessages();
- Refresh();
- Application->ProcessMessages();
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmDbProgress::btnCancelClick(TObject *Sender)
- {
- Close();
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmDbProgress::Init(String sCaption, int nMax, bool bCancel/*=false*/, bool bTimer/*=false*/)
- {
- Caption = sCaption;
- //PbProgress->Properties->Text = sCaption;
- PbProgress->Properties->Min = 0;
- PbProgress->Properties->Max = nMax;
- PbProgress->Position = 0;
- if (bCancel)
- {
- btnCancel->Enabled = true;
- Height = 112;//PbProgress->Top + PbProgress->Height + 30;
- }
- else
- {
- btnCancel->Enabled = false;
- Height = 80;//PbProgress->Top + PbProgress->Height + 30;
- }
- FParentForm = (TForm*)this->Owner;
- FParentForm->Enabled = false;
- int nTop = FParentForm->Top + (FParentForm->Height / 2) - Height;
- int nLeft= FParentForm->Left+ ((FParentForm->Width-Width) / 2);
- this->Top = nTop;
- this->Left= nLeft;
- Refresh();
- TmrProgress->Enabled = bTimer;
- Application->ProcessMessages();
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmDbProgress::Step(String sText, int nPos)
- {
- Label1->Caption = sText;
- PbProgress->Properties->Text = sText;
- PbProgress->Position = nPos;
- Refresh();
- Application->ProcessMessages();
- Application->ProcessMessages();
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmDbProgress::TmrProgressTimer(TObject *Sender)
- {
- int nPos = PbProgress->Position + 1;
- if (nPos > PbProgress->Properties->Max) nPos = 10;
- Step(PbProgress->Properties->Text, nPos);
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmDbProgress::SetQry(TADOQuery *adoQry)
- {
- m_pThrDb = new TDBThread;
- m_pThrDb->SetQry(adoQry, FParentForm);
- m_pThrDb->Resume();
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmDbProgress::FormClose(TObject *Sender, TCloseAction &Action)
- {
- TmrProgress->Enabled = false;
- try {
- if (m_pThrDb)
- {
- m_pThrDb->Terminate();
- }
- m_pThrDb = NULL;
- } catch(...) {}
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmDbProgress::TermThread()
- {
- try {
- if (m_pThrDb)
- {
- m_pThrDb->Terminate();
- }
- } catch(...) {}
- }
- //---------------------------------------------------------------------------
|