FrmVmsMsgF.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "ITSDbF.h"
  4. #include "ITSUtilF.h"
  5. #include "AppGlobalF.h"
  6. #include "ITSLangTransF.h"
  7. #include "ITS_OPLibF.h"
  8. #pragma hdrstop
  9. #include "FrmVmsMsgF.h"
  10. //---------------------------------------------------------------------------
  11. #pragma package(smart_init)
  12. #pragma link "cxContainer"
  13. #pragma link "cxControls"
  14. #pragma link "cxEdit"
  15. #pragma link "cxGraphics"
  16. #pragma link "cxLabel"
  17. #pragma link "cxLookAndFeelPainters"
  18. #pragma link "cxLookAndFeels"
  19. #pragma link "dxSkinBlack"
  20. #pragma link "dxSkinBlue"
  21. #pragma link "dxSkinsCore"
  22. #pragma link "FFBaseComponent"
  23. #pragma link "FFBasePlay"
  24. #pragma link "FFPlay"
  25. #pragma link "dxSkinMcSkin"
  26. #pragma resource "*.dfm"
  27. #define LICENSE_KEY "FSXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX-XXXXXXXX"
  28. TFrmVmsMsg *FrmVmsMsg;
  29. //---------------------------------------------------------------------------
  30. __fastcall TFrmVmsMsg::TFrmVmsMsg(TComponent* Owner, TVmsCtlr *AObj)
  31. : TForm(Owner)
  32. {
  33. LangTrans->Translate(this, ITSDb_GetConnection());
  34. FObj = AObj;
  35. FQryHour = -1;
  36. FQryMin = -1;
  37. for (int ii = 0; ii < INT_VMS_MAX_FORM; ii++)
  38. {
  39. FVmsImage[ii] = new TImage(this);
  40. FVmsImage[ii]->Visible = false;
  41. FInterval[ii] = 1;
  42. }
  43. FPhaseCnt = 0;
  44. FFormQuery = false;
  45. pADO->Connection = ITSDb_GetConnection();
  46. SetVmsForm();
  47. String sAVILibDir = g_sAppDir + "LibAV";
  48. FFPlayer1->SetLicenseKey(LICENSE_KEY);
  49. FFPlayer1->DisableFPUExceptions();
  50. if (!FFPlayer1->LoadAVLib(sAVILibDir))
  51. {
  52. #if 0
  53. if (g_sLang != "kr") Application->MessageBox(L"Stream display library load failed.", L"Stream display fail", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  54. else Application->MessageBox(L"영상표출 라이브러리를 로드하지 못하였습니다.", L"영상표출 오류", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  55. #endif
  56. }
  57. }
  58. //---------------------------------------------------------------------------
  59. void __fastcall TFrmVmsMsg::FormClose(TObject *Sender, TCloseAction &Action)
  60. {
  61. TmrTicker->Enabled = false;
  62. TmrVmsMsgDisp->Enabled = false;
  63. if (FFPlayer1->ScreenHandle != NULL)
  64. {
  65. FFPlayer1->Stop(true);
  66. PostMessage(FFPlayer1->ScreenHandle, CM_INVALIDATE, 0, 0);
  67. UpdateWindow(FFPlayer1->ScreenHandle);
  68. FFPlayer1->ScreenHandle = NULL;
  69. }
  70. Action = caFree;
  71. }
  72. //---------------------------------------------------------------------------
  73. void __fastcall TFrmVmsMsg::FormShow(TObject *Sender)
  74. {
  75. TmrShow->Enabled = true;
  76. }
  77. //---------------------------------------------------------------------------
  78. void __fastcall TFrmVmsMsg::TmrShowTimer(TObject *Sender)
  79. {
  80. TmrShow->Enabled = false;
  81. if (FObj)
  82. {
  83. Caption = FObj->CTLR_ID + ": " + FObj->NAME;
  84. }
  85. TmrVmsMsgDisp->Interval = 100;
  86. TmrVmsMsgDisp->Enabled = true;
  87. }
  88. //---------------------------------------------------------------------------
  89. void __fastcall TFrmVmsMsg::SetVmsForm()
  90. {
  91. if (!FObj) return;
  92. int nW = PnlVmsMsgDisp->Width;
  93. int nH = PnlVmsMsgDisp->Height;
  94. nH = FObj->HEIGHT;
  95. nW = FObj->WIDTH;
  96. ClientWidth = nW;
  97. ClientHeight= nH + PnlOffer->Height;
  98. PnlVmsMsgDisp->Width = nW;
  99. PnlVmsMsgDisp->Height = nH;
  100. ImgForm->Width = nW;
  101. ImgForm->Height = nH;
  102. ImgForm->Picture->Bitmap->Width = nW;
  103. ImgForm->Picture->Bitmap->Height= nH;
  104. PnlVmsMsgDisp->ParentColor = false;
  105. PnlVmsMsgDisp->Color = clBlack;
  106. ImgForm->Left = 0;
  107. ImgForm->Top = 0;
  108. }
  109. //---------------------------------------------------------------------------
  110. void __fastcall TFrmVmsMsg::ClearVmsForm()
  111. {
  112. TCanvas *pCanvas = ImgForm->Canvas;
  113. try {
  114. pCanvas->Lock();
  115. try {
  116. pCanvas->Pen->Color = clWhite;
  117. pCanvas->Pen->Width = 0;
  118. pCanvas->Pen->Style = psClear;
  119. pCanvas->Brush->Style = bsSolid;
  120. pCanvas->Brush->Color = clBlack;
  121. pCanvas->Rectangle(0, 0, ImgForm->Width, ImgForm->Height);
  122. } catch(...) { }
  123. } __finally {
  124. ImgForm->Refresh();
  125. pCanvas->Unlock();
  126. }
  127. }
  128. //---------------------------------------------------------------------------
  129. void __fastcall TFrmVmsMsg::VmsFormReload()
  130. {
  131. FFormQuery = true;
  132. TmrVmsMsgDisp->Interval = 500;
  133. TmrVmsMsgDisp->Enabled = true;
  134. }
  135. //---------------------------------------------------------------------------
  136. void __fastcall TFrmVmsMsg::TmrVmsMsgDispTimer(TObject *Sender)
  137. {
  138. TmrVmsMsgDisp->Enabled = false;
  139. TmrTicker->Enabled = false;
  140. LblTicker->Caption = " - ";
  141. if (FFPlayer1->ScreenHandle != NULL)
  142. {
  143. FFPlayer1->Stop(true);
  144. PostMessage(FFPlayer1->ScreenHandle, CM_INVALIDATE, 0, 0);
  145. UpdateWindow(FFPlayer1->ScreenHandle);
  146. FFPlayer1->ScreenHandle = NULL;
  147. ImgForm->Visible = true;
  148. }
  149. PnlOffer->Caption = " " + lblTm->Caption + ":";
  150. PnlOffer->Font->Color = clBlack;
  151. bool bQry = false;
  152. if (FQryMin < 0)
  153. {
  154. bQry = true;
  155. FQryMin = StrToInt(Now().FormatString("nn"));
  156. if ((FQryMin % 5) == 0)
  157. FQryMin--;
  158. }
  159. else
  160. {
  161. int nCurMin = StrToInt(Now().FormatString("nn"));
  162. int nCurSec = StrToInt(Now().FormatString("ss"));
  163. if ((nCurMin % 5) == 0 && nCurSec >= 45)
  164. {
  165. if (FQryMin != nCurMin)
  166. {
  167. FQryMin = nCurMin;
  168. bQry = true;
  169. }
  170. }
  171. }
  172. if (bQry || FFormQuery)
  173. {
  174. SelectVmsForm();
  175. if (FPhaseCnt == 0)
  176. {
  177. PnlVmsMsgDisp->ParentColor = false;
  178. PnlVmsMsgDisp->Color = clBlack;
  179. ImgForm->Visible = false;
  180. }
  181. else
  182. {
  183. ImgForm->Visible = true;
  184. }
  185. }
  186. else
  187. {
  188. if (FDispIndex >= FPhaseCnt)
  189. {
  190. FDispIndex = 0;
  191. }
  192. }
  193. int nInterval = 5; //5초
  194. try
  195. {
  196. if (FDispIndex < FPhaseCnt)
  197. {
  198. nInterval = FInterval[FDispIndex];
  199. FCycle = nInterval;
  200. try
  201. {
  202. ClearVmsForm();
  203. ImgForm->Picture->Assign(FVmsImage[FDispIndex]->Picture);
  204. //Caption = FObj->CTLR_ID + ": " + FObj->NAME + " [" + String(FDispIndex+1) + "/" + String(FPhaseCnt) + "]";
  205. } catch(...) {}
  206. PnlOffer->Caption = " " + lblTm->Caption + ": " + APP_FormatStr(FOfferTime[FDispIndex], STR_DATETIME) + " [" + String(FDispIndex+1) + "/" + String(FPhaseCnt) + "]";
  207. if (FOffer[FDispIndex])
  208. PnlOffer->Font->Color = clBlack;
  209. else
  210. PnlOffer->Font->Color = clRed;
  211. #if 0
  212. if (FVMS_SCH_FORM_TYPE[FDispIndex] == eSchTp_video ||
  213. FVMS_SCH_FORM_TYPE[FDispIndex] == eSchTp_stream )
  214. {
  215. FFPlayer1->AspectRatio = -1;
  216. FFPlayer1->TryOpen(FVMS_DSPL_MSG_TXT[FDispIndex].Trim(), PnlForm->Handle);
  217. ImgForm->Visible = false;
  218. }
  219. #endif
  220. FDispIndex++;
  221. }
  222. }
  223. catch(...)
  224. {
  225. }
  226. FFormQuery = false;
  227. LblTicker->Caption = " " + String(FCycle) + " ";
  228. TmrTicker->Enabled = true;
  229. TmrVmsMsgDisp->Interval = nInterval * 1000;
  230. TmrVmsMsgDisp->Enabled = true;
  231. }
  232. //---------------------------------------------------------------------------
  233. void __fastcall TFrmVmsMsg::SelectVmsForm()
  234. {
  235. bool bImage = false;
  236. String sQry;
  237. FDispIndex= 0;
  238. FPhaseCnt = 0;
  239. if (!FObj)
  240. {
  241. return;
  242. }
  243. sQry = "SELECT A.*, \r\n"
  244. " TO_CHAR(SYSDATE - 8/1440, 'YYYYMMDDHH24MISS') AS SVC_DT \r\n"
  245. " FROM TB_VMS_DSPL_PRST A, \r\n"
  246. " (SELECT VMS_CTLR_NMBR, MAX(DSPL_DT) AS DSPL_DT \r\n"
  247. " FROM TB_VMS_DSPL_PRST \r\n"
  248. " GROUP BY VMS_CTLR_NMBR) B \r\n"
  249. " WHERE A.VMS_CTLR_NMBR = :p01 \r\n"
  250. " AND A.VMS_CTLR_NMBR = B.VMS_CTLR_NMBR \r\n"
  251. " AND A.DSPL_DT = B.DSPL_DT \r\n"
  252. " ORDER BY A.VMS_CTLR_NMBR, A.PHASE \r\n";
  253. try
  254. {
  255. pADO->Connection = ITSDb_GetConnection();
  256. ITSDb_SQLText(pADO, sQry);
  257. ITSDb_SQLBind(pADO, "p01", FObj->CTLR_NMBR);
  258. ITSDb_SQLOpen(pADO);
  259. for( ; !pADO->Eof; pADO->Next())
  260. {
  261. if (FPhaseCnt >= INT_VMS_MAX_FORM) break;
  262. String DSPL_DT = pADO->FieldByName("DSPL_DT")->AsString;
  263. String SVC_DT = pADO->FieldByName("SVC_DT")->AsString;
  264. String DNLD_YN = "Y";//pADO->FieldByName("DNLD_YN")->AsString;
  265. if (DSPL_DT >= SVC_DT)
  266. {
  267. FOffer[FPhaseCnt] = true;
  268. }
  269. else
  270. {
  271. FOffer[FPhaseCnt] = false;
  272. }
  273. if (DNLD_YN == "N") FOffer[FPhaseCnt] = false;
  274. FOfferTime[FPhaseCnt] = DSPL_DT;
  275. FVMS_SCH_FORM_TYPE[FPhaseCnt] = pADO->FieldByName("VMS_SCH_FORM_TYPE")->AsInteger;
  276. FVMS_DSPL_MSG_TXT[FPhaseCnt] = "";
  277. if (FVMS_SCH_FORM_TYPE[FPhaseCnt] == eSchTp_video ||
  278. FVMS_SCH_FORM_TYPE[FPhaseCnt] == eSchTp_stream )
  279. {
  280. FVMS_DSPL_MSG_TXT[FPhaseCnt] = pADO->FieldByName("VMS_DSPL_MSG_TXT")->AsString.Trim();
  281. }
  282. FInterval[FPhaseCnt] = pADO->FieldByName("DSPL_HH")->AsInteger;
  283. if (FInterval[FPhaseCnt] <= 0) FInterval[FPhaseCnt] = 3;
  284. //if (FInterval[FPhaseCnt] >= 10) FInterval[FPhaseCnt] = 10;
  285. TStream *pStream = NULL;
  286. pStream = pADO->CreateBlobStream(pADO->FieldByName("VMS_DSPL_MSG_IMAG"), bmRead);
  287. TImage *pImage = FVmsImage[FPhaseCnt];
  288. try
  289. {
  290. try {
  291. pImage->Canvas->Lock();
  292. pStream->Position = 0;
  293. pImage->Picture->Bitmap->LoadFromStream(pStream);
  294. FPhaseCnt++;
  295. } catch(...) {}
  296. }__finally{
  297. pImage->Canvas->Unlock();
  298. if (pStream) delete pStream;
  299. }
  300. }
  301. ITSDb_SQLClose(pADO);
  302. }
  303. catch(EDatabaseError &E)
  304. {
  305. throw Exception(String(E.ClassName()) + E.Message);
  306. }
  307. catch(...)
  308. {
  309. throw Exception(FrmLang->lblDbErr->Caption);//"알수없는 오류가 발생하였습니다.");
  310. }
  311. }
  312. //---------------------------------------------------------------------------
  313. void __fastcall TFrmVmsMsg::SelectVmsForm_HANTE()
  314. {
  315. bool bImage = false;
  316. String sQry;
  317. FDispIndex= 0;
  318. FPhaseCnt = 0;
  319. if (!FObj)
  320. {
  321. return;
  322. }
  323. sQry = "SELECT VMS_CTLR_NMBR, DSPL_DT, \r\n"
  324. " VMS_DSPL_MSG_IMAG, NVL(DSPL_HH, 2) AS DSPL_HH \r\n"
  325. " FROM TB_VMS_DSPL_PRST \r\n"
  326. " WHERE VMS_CTLR_NMBR = :p01 \r\n"
  327. " AND DSPL_DT >= TO_CHAR(SYSDATE-5/1440, 'YYYYMMDDHH24MISS') \r\n";
  328. try
  329. {
  330. pADO->Connection = ITSDb_GetConnection();
  331. ITSDb_SQLText(pADO, sQry);
  332. ITSDb_SQLBind(pADO, "p01", FObj->CTLR_NMBR);
  333. ITSDb_SQLOpen(pADO);
  334. for( ; !pADO->Eof; pADO->Next())
  335. {
  336. if (FPhaseCnt >= INT_VMS_MAX_FORM) break;
  337. FInterval[FPhaseCnt] = pADO->FieldByName("DSPL_HH")->AsInteger;
  338. if (FInterval[FPhaseCnt] < 1 || FInterval[FPhaseCnt] > 5)
  339. {
  340. FInterval[FPhaseCnt] = 3;
  341. }
  342. TStream *pStream = NULL;
  343. pStream = pADO->CreateBlobStream(pADO->FieldByName("VMS_DSPL_MSG_IMAG"), bmRead);
  344. TImage *pImage = FVmsImage[FPhaseCnt];
  345. try
  346. {
  347. try {
  348. pImage->Canvas->Lock();
  349. pStream->Position = 0;
  350. pImage->Picture->Bitmap->LoadFromStream(pStream);
  351. FPhaseCnt++;
  352. } catch(...) {}
  353. }__finally{
  354. pImage->Canvas->Unlock();
  355. if (pStream) delete pStream;
  356. }
  357. }
  358. ITSDb_SQLClose(pADO);
  359. }
  360. catch(EDatabaseError &E)
  361. {
  362. throw Exception(String(E.ClassName()) + E.Message);
  363. }
  364. catch(...)
  365. {
  366. throw Exception("알수없는 오류가 발생하였습니다.");
  367. }
  368. }
  369. //---------------------------------------------------------------------------
  370. void __fastcall TFrmVmsMsg::FormDestroy(TObject *Sender)
  371. {
  372. TmrVmsMsgDisp->Enabled = false;
  373. try {
  374. for (int ii = 0; ii < INT_VMS_MAX_FORM; ii++)
  375. {
  376. if (FVmsImage[ii]) delete FVmsImage[ii];
  377. }
  378. if (FObj) {
  379. FObj->FData2 = NULL;
  380. FObj->FData3 = NULL;
  381. }
  382. } catch(...) {}
  383. }
  384. //---------------------------------------------------------------------------
  385. void __fastcall TFrmVmsMsg::TmrTickerTimer(TObject *Sender)
  386. {
  387. TmrTicker->Enabled = false;
  388. FCycle--;
  389. LblTicker->Caption = " " + String(FCycle) + " ";
  390. if (FCycle > 0) TmrTicker->Enabled = true;
  391. }
  392. //---------------------------------------------------------------------------
  393. void __fastcall TFrmVmsMsg::FFPlayer1State(TObject *Sender, TPlayState APlayState)
  394. {
  395. switch(APlayState)
  396. {
  397. case Ffbasecomponent::psPlay:
  398. case Ffbasecomponent::psResume:
  399. break;
  400. case Ffbasecomponent::psPause:
  401. case Ffbasecomponent::psStep:
  402. break;
  403. case Ffbasecomponent::psStop:
  404. if (FFPlayer1->ScreenHandle != NULL)
  405. {
  406. PostMessage(FFPlayer1->ScreenHandle, CM_INVALIDATE, 0, 0);
  407. UpdateWindow(FFPlayer1->ScreenHandle);
  408. FFPlayer1->ScreenHandle = NULL;
  409. }
  410. break;
  411. case Ffbasecomponent::psEnd:
  412. {
  413. FFPlayer1->Stop(true);
  414. PostMessage(FFPlayer1->ScreenHandle, CM_INVALIDATE, 0, 0);
  415. UpdateWindow(FFPlayer1->ScreenHandle);
  416. FFPlayer1->ScreenHandle = NULL;
  417. }
  418. break;
  419. }
  420. }
  421. //---------------------------------------------------------------------------