123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #include "ITSDbF.h"
- #include "ITSUtilF.h"
- #include "AppGlobalF.h"
- #include "ITSLangTransF.h"
- #pragma hdrstop
- #include "FrmVmsMsgF.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma link "cxContainer"
- #pragma link "cxControls"
- #pragma link "cxEdit"
- #pragma link "cxGraphics"
- #pragma link "cxLabel"
- #pragma link "cxLookAndFeelPainters"
- #pragma link "cxLookAndFeels"
- #pragma link "dxSkinBlack"
- #pragma link "dxSkinBlue"
- #pragma link "dxSkinsCore"
- #pragma resource "*.dfm"
- TFrmVmsMsg *FrmVmsMsg;
- //---------------------------------------------------------------------------
- __fastcall TFrmVmsMsg::TFrmVmsMsg(TComponent* Owner, TItsVms *AObj)
- : TForm(Owner)
- {
- LangTrans->Translate(this, ITSDb_GetConnection());
- FObj = AObj;
- FQryHour = -1;
- FQryMin = -1;
- for (int ii = 0; ii < MAX_VMSPHASE; ii++)
- {
- FVmsImage[ii] = new TImage(this);
- FVmsImage[ii]->Visible = false;
- FInterval[ii] = 1;
- }
- FPhaseCnt = 0;
- pADO->Connection = ITSDb_GetConnection();
- SetVmsForm();
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmVmsMsg::FormClose(TObject *Sender, TCloseAction &Action)
- {
- Action = caFree;
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmVmsMsg::FormShow(TObject *Sender)
- {
- TmrShow->Enabled = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmVmsMsg::TmrShowTimer(TObject *Sender)
- {
- TmrShow->Enabled = false;
- if (FObj)
- {
- Caption = FObj->VMS_CTLR_ID + ": " + FObj->VMS_NM;
- }
- TmrVmsMsgDisp->Interval = 100;
- TmrVmsMsgDisp->Enabled = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmVmsMsg::SetVmsForm()
- {
- if (!FObj) return;
- int nW = PnlVmsMsgDisp->Width;
- int nH = PnlVmsMsgDisp->Height;
- nH = FObj->HEIGHT;
- nW = FObj->WIDTH;
- ClientWidth = nW;
- ClientHeight= nH + PnlOffer->Height;
- PnlVmsMsgDisp->Width = nW;
- PnlVmsMsgDisp->Height = nH;
- ImgForm->Width = nW;
- ImgForm->Height = nH;
- ImgForm->Picture->Bitmap->Width = nW;
- ImgForm->Picture->Bitmap->Height= nH;
- PnlVmsMsgDisp->ParentColor = false;
- PnlVmsMsgDisp->Color = clBlack;
- ImgForm->Left = 0;
- ImgForm->Top = 0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmVmsMsg::ClearVmsForm()
- {
- TCanvas *pCanvas = ImgForm->Canvas;
- try {
- pCanvas->Lock();
- try {
- pCanvas->Pen->Color = clWhite;
- pCanvas->Pen->Width = 0;
- pCanvas->Pen->Style = psClear;
- pCanvas->Brush->Style = bsSolid;
- pCanvas->Brush->Color = clBlack;
- pCanvas->Rectangle(0, 0, ImgForm->Width, ImgForm->Height);
- } catch(...) { }
- } __finally {
- ImgForm->Refresh();
- pCanvas->Unlock();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmVmsMsg::TmrVmsMsgDispTimer(TObject *Sender)
- {
- TmrVmsMsgDisp->Enabled = false;
- PnlOffer->Caption = " " + lblTm->Caption + ":";
- PnlOffer->Font->Color = clBlack;
- bool bQry = false;
- if (FQryMin < 0)
- {
- bQry = true;
- FQryMin = StrToInt(Now().FormatString("nn"));
- if ((FQryMin % 5) == 0)
- FQryMin--;
- }
- else
- {
- int nCurMin = StrToInt(Now().FormatString("nn"));
- int nCurSec = StrToInt(Now().FormatString("ss"));
- if ((nCurMin % 5) == 0 && nCurSec >= 45)
- {
- if (FQryMin != nCurMin)
- {
- FQryMin = nCurMin;
- bQry = true;
- }
- }
- }
- if (bQry)
- {
- SelectVmsForm();
- if (FPhaseCnt == 0)
- {
- PnlVmsMsgDisp->ParentColor = false;
- PnlVmsMsgDisp->Color = clBlack;
- ImgForm->Visible = false;
- }
- else
- {
- ImgForm->Visible = true;
- }
- }
- else
- {
- if (FDispIndex >= FPhaseCnt)
- {
- FDispIndex = 0;
- }
- }
- int nInterval = 5; //5초
- try
- {
- if (FDispIndex < FPhaseCnt)
- {
- nInterval = FInterval[FDispIndex];
- try
- {
- ClearVmsForm();
- ImgForm->Picture->Assign(FVmsImage[FDispIndex]->Picture);
- //Caption = FObj->VMS_CTLR_ID + ": " + FObj->VMS_NM + " [" + String(FDispIndex+1) + "/" + String(FPhaseCnt) + "]";
- } catch(...) {}
- PnlOffer->Caption = " " + lblTm->Caption + ": " + ITSUtil_FormatStr(FOfferTime[FDispIndex], STR_DATETIME) + " [" + String(FDispIndex+1) + "/" + String(FPhaseCnt) + "]";
- if (FOffer[FDispIndex])
- PnlOffer->Font->Color = clBlack;
- else
- PnlOffer->Font->Color = clRed;
- FDispIndex++;
- }
- }
- catch(...)
- {
- }
- TmrVmsMsgDisp->Interval = nInterval * 1000;
- TmrVmsMsgDisp->Enabled = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmVmsMsg::SelectVmsForm()
- {
- bool bImage = false;
- String sQry;
- FDispIndex= 0;
- FPhaseCnt = 0;
- if (!FObj)
- {
- return;
- }
- sQry = "SELECT A.VMS_CTLR_NMBR, A.PHASE, A.DSPL_HH, A.DNLD_YN, \r\n"
- " A.VMS_MSG_DSPL_MTHD_CD, A.TRFC_SITU_TYPE_CD, A.DSPL_DT, \r\n"
- " TO_CHAR(SYSDATE - 6/1440, 'YYYYMMDDHH24MISS') AS SVC_DT, \r\n"
- " A.VMS_DSPL_MSG_IMAG \r\n"
- " FROM TB_VMS_DSPL_PRST A, \r\n"
- " (SELECT VMS_CTLR_NMBR, MAX(DSPL_DT) AS DSPL_DT \r\n"
- " FROM TB_VMS_DSPL_PRST \r\n"
- " GROUP BY VMS_CTLR_NMBR) B \r\n"
- " WHERE A.VMS_CTLR_NMBR = :p01 \r\n"
- " AND A.VMS_CTLR_NMBR = B.VMS_CTLR_NMBR \r\n"
- " AND A.DSPL_DT = B.DSPL_DT \r\n"
- " ORDER BY A.VMS_CTLR_NMBR, A.PHASE \r\n";
- try
- {
- pADO->Connection = ITSDb_GetConnection();
- ITSDb_SQLText(pADO, sQry);
- ITSDb_SQLBind(pADO, "p01", FObj->VMS_CTLR_NMBR);
- ITSDb_SQLOpen(pADO);
- for( ; !pADO->Eof; pADO->Next())
- {
- if (FPhaseCnt >= MAX_VMSPHASE) break;
- String DSPL_DT = pADO->FieldByName("DSPL_DT")->AsString;
- String SVC_DT = pADO->FieldByName("SVC_DT")->AsString;
- String DNLD_YN = pADO->FieldByName("DNLD_YN")->AsString;
- if (DSPL_DT >= SVC_DT)
- {
- FOffer[FPhaseCnt] = true;
- }
- else
- {
- FOffer[FPhaseCnt] = false;
- }
- if (DNLD_YN == "N") FOffer[FPhaseCnt] = false;
- FOfferTime[FPhaseCnt] = DSPL_DT;
- FInterval[FPhaseCnt] = pADO->FieldByName("DSPL_HH")->AsInteger;
- #if 1
- if (FInterval[FPhaseCnt] <= 0) FInterval[FPhaseCnt] = 3;
- if (FInterval[FPhaseCnt] >= 10) FInterval[FPhaseCnt] = 10;
- #else
- if (FInterval[FPhaseCnt] < 1 || FInterval[FPhaseCnt] > 5)
- {
- FInterval[FPhaseCnt] = 3;
- }
- #endif
- TStream *pStream = NULL;
- pStream = pADO->CreateBlobStream(pADO->FieldByName("VMS_DSPL_MSG_IMAG"), bmRead);
- TImage *pImage = FVmsImage[FPhaseCnt];
- try
- {
- try {
- pImage->Canvas->Lock();
- pStream->Position = 0;
- pImage->Picture->Bitmap->LoadFromStream(pStream);
- FPhaseCnt++;
- } catch(...) {}
- }__finally{
- pImage->Canvas->Unlock();
- if (pStream) delete pStream;
- }
- }
- ITSDb_SQLClose(pADO);
- }
- catch(EDatabaseError &E)
- {
- throw Exception(String(E.ClassName()) + E.Message);
- }
- catch(...)
- {
- throw Exception(FrmLang->lblDbErr->Caption);//"알수없는 오류가 발생하였습니다.");
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TFrmVmsMsg::FormDestroy(TObject *Sender)
- {
- TmrVmsMsgDisp->Enabled = false;
- try {
- for (int ii = 0; ii < MAX_VMSPHASE; ii++)
- {
- if (FVmsImage[ii]) delete FVmsImage[ii];
- }
- if (FObj) FObj->FData1 = NULL;
- } catch(...) {}
- }
- //---------------------------------------------------------------------------
|