FrmVmsMsgF.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  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. FFormClose = false;
  58. }
  59. //---------------------------------------------------------------------------
  60. void __fastcall TFrmVmsMsg::FormClose(TObject *Sender, TCloseAction &Action)
  61. {
  62. FFormClose = true;
  63. TmrTicker->Enabled = false;
  64. TmrVmsMsgDisp->Enabled = false;
  65. if (FFPlayer1->Tag == 1 && FFPlayer1->ScreenHandle != NULL)
  66. {
  67. FFPlayer1->Tag = 0;
  68. if (ImgForm->Visible == false) {
  69. ImgForm->Visible = true;
  70. }
  71. FFPlayer1->Stop(true);
  72. PostMessage(FFPlayer1->ScreenHandle, CM_INVALIDATE, 0, 0);
  73. UpdateWindow(FFPlayer1->ScreenHandle);
  74. FFPlayer1->ScreenHandle = NULL;
  75. Application->ProcessMessages();
  76. }
  77. Application->ProcessMessages();
  78. Action = caFree;
  79. }
  80. //---------------------------------------------------------------------------
  81. void __fastcall TFrmVmsMsg::FormDestroy(TObject *Sender)
  82. {
  83. FFormClose = true;
  84. TmrTicker->Enabled = false;
  85. TmrVmsMsgDisp->Enabled = false;
  86. try {
  87. for (int ii = 0; ii < INT_VMS_MAX_FORM; ii++)
  88. {
  89. if (FVmsImage[ii]) delete FVmsImage[ii];
  90. }
  91. if (FObj) FObj->FData2 = NULL;
  92. } catch(...) {}
  93. }
  94. //---------------------------------------------------------------------------
  95. void __fastcall TFrmVmsMsg::FormShow(TObject *Sender)
  96. {
  97. TmrShow->Enabled = true;
  98. }
  99. //---------------------------------------------------------------------------
  100. void __fastcall TFrmVmsMsg::TmrShowTimer(TObject *Sender)
  101. {
  102. TmrShow->Enabled = false;
  103. if (FObj)
  104. {
  105. Caption = FObj->VMS_CTLR_ID + ": " + FObj->VMS_NM;
  106. }
  107. TmrVmsMsgDisp->Interval = 100;
  108. TmrVmsMsgDisp->Enabled = true;
  109. }
  110. //---------------------------------------------------------------------------
  111. void __fastcall TFrmVmsMsg::SetVmsForm()
  112. {
  113. if (!FObj) return;
  114. int nW = PnlVmsMsgDisp->Width;
  115. int nH = PnlVmsMsgDisp->Height;
  116. nH = FObj->HEIGHT;
  117. nW = FObj->WIDTH;
  118. ClientWidth = nW;
  119. ClientHeight= nH + PnlOffer->Height;
  120. PnlVmsMsgDisp->Width = nW;
  121. PnlVmsMsgDisp->Height = nH;
  122. ImgForm->Width = nW;
  123. ImgForm->Height = nH;
  124. ImgForm->Picture->Bitmap->Width = nW;
  125. ImgForm->Picture->Bitmap->Height= nH;
  126. PnlVmsMsgDisp->ParentColor = false;
  127. PnlVmsMsgDisp->Color = clBlack;
  128. ImgForm->Left = 0;
  129. ImgForm->Top = 0;
  130. }
  131. //---------------------------------------------------------------------------
  132. void __fastcall TFrmVmsMsg::ClearVmsForm()
  133. {
  134. TCanvas *pCanvas = ImgForm->Canvas;
  135. try {
  136. pCanvas->Lock();
  137. try {
  138. pCanvas->Pen->Color = clWhite;
  139. pCanvas->Pen->Width = 0;
  140. pCanvas->Pen->Style = psClear;
  141. pCanvas->Brush->Style = bsSolid;
  142. pCanvas->Brush->Color = clBlack;
  143. pCanvas->Rectangle(0, 0, ImgForm->Width, ImgForm->Height);
  144. } catch(...) { }
  145. } __finally {
  146. ImgForm->Refresh();
  147. pCanvas->Unlock();
  148. }
  149. }
  150. //---------------------------------------------------------------------------
  151. void __fastcall TFrmVmsMsg::VmsFormReload()
  152. {
  153. FFormQuery = true;
  154. TmrVmsMsgDisp->Interval = 500;
  155. TmrVmsMsgDisp->Enabled = true;
  156. }
  157. //---------------------------------------------------------------------------
  158. void __fastcall TFrmVmsMsg::TmrVmsMsgDispTimer(TObject *Sender)
  159. {
  160. TmrVmsMsgDisp->Enabled = false;
  161. TmrTicker->Enabled = false;
  162. LblTicker->Caption = " - ";
  163. #if 1
  164. if (FFPlayer1->Tag == 1 && FFPlayer1->ScreenHandle != NULL)
  165. {
  166. FFPlayer1->Tag = 0;
  167. if (ImgForm->Visible == false) {
  168. ImgForm->Visible = true;
  169. }
  170. FFPlayer1->Stop(true);
  171. PostMessage(FFPlayer1->ScreenHandle, CM_INVALIDATE, 0, 0);
  172. UpdateWindow(FFPlayer1->ScreenHandle);
  173. FFPlayer1->ScreenHandle = NULL;
  174. }
  175. #endif
  176. if (ImgForm->Visible == false) {
  177. ImgForm->Visible = true;
  178. }
  179. PnlOffer->Caption = " " + lblTm->Caption + ":";
  180. PnlOffer->Font->Color = clBlack;
  181. bool bQry = false;
  182. if (FQryMin < 0)
  183. {
  184. bQry = true;
  185. FQryMin = StrToInt(Now().FormatString("nn"));
  186. if ((FQryMin % 5) == 0)
  187. FQryMin--;
  188. }
  189. else
  190. {
  191. int nCurMin = StrToInt(Now().FormatString("nn"));
  192. int nCurSec = StrToInt(Now().FormatString("ss"));
  193. if ((nCurMin % 5) == 0 && nCurSec >= 45)
  194. {
  195. if (FQryMin != nCurMin)
  196. {
  197. FQryMin = nCurMin;
  198. bQry = true;
  199. }
  200. }
  201. }
  202. if (bQry || FFormQuery)
  203. {
  204. SelectVmsForm();
  205. if (FPhaseCnt == 0)
  206. {
  207. PnlVmsMsgDisp->ParentColor = false;
  208. PnlVmsMsgDisp->Color = clBlack;
  209. ImgForm->Visible = false;
  210. }
  211. else
  212. {
  213. ImgForm->Visible = true;
  214. }
  215. }
  216. else
  217. {
  218. if (FDispIndex >= FPhaseCnt)
  219. {
  220. FDispIndex = 0;
  221. }
  222. }
  223. int nInterval = 5; //5초
  224. try
  225. {
  226. if (FDispIndex < FPhaseCnt)
  227. {
  228. nInterval = FInterval[FDispIndex];
  229. FCycle = nInterval;
  230. try
  231. {
  232. ClearVmsForm();
  233. ImgForm->Picture->Assign(FVmsImage[FDispIndex]->Picture);
  234. //Caption = FObj->VMS_CTLR_ID + ": " + FObj->VMS_NM + " [" + String(FDispIndex+1) + "/" + String(FPhaseCnt) + "]";
  235. } catch(...) {}
  236. PnlOffer->Caption = " " + lblTm->Caption + ": " + APP_FormatStr(FOfferTime[FDispIndex], STR_DATETIME) + " [" + String(FDispIndex+1) + "/" + String(FPhaseCnt) + "]";
  237. if (FOffer[FDispIndex])
  238. PnlOffer->Font->Color = clBlack;
  239. else
  240. PnlOffer->Font->Color = clRed;
  241. #if 0
  242. if (FVMS_SCH_FORM_TYPE[FDispIndex] == eSchTp_video ||
  243. FVMS_SCH_FORM_TYPE[FDispIndex] == eSchTp_stream )
  244. {
  245. FPlayer1->Tag = 1;
  246. FFPlayer1->AspectRatio = -1;
  247. if (ImgForm->Visible) ImgForm->Visible = false;
  248. FFPlayer1->TryOpen(FVMS_DSPL_MSG_TXT[FDispIndex].Trim(), PnlForm->Handle);
  249. }
  250. #endif
  251. if (FVMS_SCH_FORM_TYPE[FDispIndex] == eSchTp_video && FVMS_DSPL_MSG_TXT[FDispIndex] != "")
  252. {
  253. FFPlayer1->Tag = 1;
  254. FFPlayer1->AspectRatio = -1;
  255. if (ImgForm->Visible) ImgForm->Visible = false;
  256. FFPlayer1->TryOpen(FVMS_DSPL_MSG_TXT[FDispIndex].Trim(), PnlVmsMsgDisp->Handle);
  257. }
  258. FDispIndex++;
  259. }
  260. }
  261. catch(...)
  262. {
  263. }
  264. FFormQuery = false;
  265. LblTicker->Caption = " " + String(FCycle) + " ";
  266. TmrTicker->Enabled = true;//ImgForm->Visible;
  267. TmrVmsMsgDisp->Interval = (nInterval) * 1000;
  268. TmrVmsMsgDisp->Enabled = ImgForm->Visible;
  269. }
  270. //---------------------------------------------------------------------------
  271. void __fastcall TFrmVmsMsg::TmrTickerTimer(TObject *Sender)
  272. {
  273. TmrTicker->Enabled = false;
  274. FCycle--;
  275. LblTicker->Caption = " " + String(FCycle) + " ";
  276. if (FCycle > 0) {
  277. TmrTicker->Enabled = true;
  278. LblTicker->Refresh();
  279. }
  280. else {
  281. if (FFPlayer1->Tag == 1 && FFPlayer1->ScreenHandle != NULL)
  282. {
  283. FFPlayer1->Tag = 0;
  284. FFPlayer1->Stop(true);
  285. PostMessage(FFPlayer1->ScreenHandle, CM_INVALIDATE, 0, 0);
  286. UpdateWindow(FFPlayer1->ScreenHandle);
  287. FFPlayer1->ScreenHandle = NULL;
  288. TmrVmsMsgDisp->Enabled = false;
  289. TmrVmsMsgDisp->Interval = 100;
  290. TmrVmsMsgDisp->Enabled = true;
  291. if (ImgForm->Visible == false) {
  292. ImgForm->Visible = true;
  293. }
  294. }
  295. }
  296. }
  297. //---------------------------------------------------------------------------
  298. void __fastcall TFrmVmsMsg::SelectVmsForm()
  299. {
  300. bool bImage = false;
  301. String sQry;
  302. FDispIndex= 0;
  303. FPhaseCnt = 0;
  304. if (!FObj)
  305. {
  306. return;
  307. }
  308. #if 0
  309. sQry = "SELECT A.*, \r\n"
  310. " TO_CHAR(SYSDATE - 8/1440, 'YYYYMMDDHH24MISS') AS SVC_DT \r\n"
  311. " FROM TB_VMS_DSPL_PRST A, \r\n"
  312. " (SELECT VMS_CTLR_NMBR, MAX(DSPL_DT) AS DSPL_DT \r\n"
  313. " FROM TB_VMS_DSPL_PRST \r\n"
  314. " GROUP BY VMS_CTLR_NMBR) B \r\n"
  315. " WHERE A.VMS_CTLR_NMBR = :p01 \r\n"
  316. " AND A.VMS_CTLR_NMBR = B.VMS_CTLR_NMBR \r\n"
  317. " AND A.DSPL_DT = B.DSPL_DT \r\n"
  318. " ORDER BY A.VMS_CTLR_NMBR, A.PHASE \r\n";
  319. #else
  320. sQry = "SELECT A.*, \r\n"
  321. " TO_CHAR(SYSDATE - 8/1440, 'YYYYMMDDHH24MISS') AS SVC_DT, \r\n"
  322. " NVL((SELECT ROUND(AVG(PLAY_TM), 0) \r\n"
  323. " FROM TB_VMS_SYMB_LIB \r\n"
  324. " WHERE SYMBLIB_NMBR||'.'||SYMB_IMAG_TYPE = A.VMS_DSPL_MSG_INFO), A.DSPL_HH) AS PLAY_TM \r\n"
  325. " FROM TB_VMS_DSPL_PRST A, \r\n"
  326. " (SELECT VMS_CTLR_NMBR, MAX(DSPL_DT) AS DSPL_DT \r\n"
  327. " FROM TB_VMS_DSPL_PRST \r\n"
  328. " GROUP BY VMS_CTLR_NMBR) B \r\n"
  329. " WHERE A.VMS_CTLR_NMBR = :p01 \r\n"
  330. " AND A.VMS_CTLR_NMBR = B.VMS_CTLR_NMBR \r\n"
  331. " AND A.DSPL_DT = B.DSPL_DT \r\n"
  332. " ORDER BY A.VMS_CTLR_NMBR, A.PHASE \r\n";
  333. #endif
  334. try
  335. {
  336. pADO->Connection = ITSDb_GetConnection();
  337. ITSDb_SQLText(pADO, sQry);
  338. ITSDb_SQLBind(pADO, "p01", FObj->VMS_CTLR_NMBR);
  339. ITSDb_SQLOpen(pADO);
  340. for( ; !pADO->Eof; pADO->Next())
  341. {
  342. if (FPhaseCnt >= INT_VMS_MAX_FORM) break;
  343. String DSPL_DT = pADO->FieldByName("DSPL_DT")->AsString;
  344. String SVC_DT = pADO->FieldByName("SVC_DT")->AsString;
  345. String DNLD_YN = "Y";//pADO->FieldByName("DNLD_YN")->AsString;
  346. if (DSPL_DT >= SVC_DT)
  347. {
  348. FOffer[FPhaseCnt] = true;
  349. }
  350. else
  351. {
  352. FOffer[FPhaseCnt] = false;
  353. }
  354. if (DNLD_YN == "N") FOffer[FPhaseCnt] = false;
  355. FOfferTime[FPhaseCnt] = DSPL_DT;
  356. FVMS_SCH_FORM_TYPE[FPhaseCnt] = pADO->FieldByName("VMS_SCH_FORM_TYPE")->AsInteger;
  357. FInterval[FPhaseCnt] = pADO->FieldByName("DSPL_HH")->AsInteger;
  358. if (FInterval[FPhaseCnt] <= 0) FInterval[FPhaseCnt] = 3;
  359. //if (FInterval[FPhaseCnt] >= 10) FInterval[FPhaseCnt] = 10;
  360. FVMS_DSPL_MSG_TXT[FPhaseCnt] = "";
  361. if (FVMS_SCH_FORM_TYPE[FPhaseCnt] == eSchTp_video)
  362. {
  363. String videoFile = g_sVideoDir + pADO->FieldByName("VMS_DSPL_MSG_INFO")->AsString.Trim();
  364. if (FileExists(videoFile)) {
  365. FVMS_DSPL_MSG_TXT[FPhaseCnt] = videoFile;
  366. }
  367. if (FInterval[FPhaseCnt] <= 5) {
  368. FInterval[FPhaseCnt] = pADO->FieldByName("PLAY_TM")->AsInteger;
  369. }
  370. }
  371. if (FVMS_SCH_FORM_TYPE[FPhaseCnt] == eSchTp_stream)
  372. {
  373. FVMS_DSPL_MSG_TXT[FPhaseCnt] = pADO->FieldByName("VMS_DSPL_MSG_INFO")->AsString.Trim();
  374. }
  375. TStream *pStream = NULL;
  376. pStream = pADO->CreateBlobStream(pADO->FieldByName("VMS_DSPL_MSG_IMAG"), bmRead);
  377. TImage *pImage = FVmsImage[FPhaseCnt];
  378. try
  379. {
  380. try {
  381. pImage->Canvas->Lock();
  382. pStream->Position = 0;
  383. pImage->Picture->Bitmap->LoadFromStream(pStream);
  384. FPhaseCnt++;
  385. } catch(...) {}
  386. }__finally{
  387. pImage->Canvas->Unlock();
  388. if (pStream) delete pStream;
  389. }
  390. }
  391. ITSDb_SQLClose(pADO);
  392. }
  393. catch(EDatabaseError &E)
  394. {
  395. throw Exception(String(E.ClassName()) + E.Message);
  396. }
  397. catch(...)
  398. {
  399. throw Exception(FrmLang->lblDbErr->Caption);//"알수없는 오류가 발생하였습니다.");
  400. }
  401. }
  402. //---------------------------------------------------------------------------
  403. void __fastcall TFrmVmsMsg::SelectVmsForm_HANTE()
  404. {
  405. bool bImage = false;
  406. String sQry;
  407. FDispIndex= 0;
  408. FPhaseCnt = 0;
  409. if (!FObj)
  410. {
  411. return;
  412. }
  413. sQry = "SELECT VMS_CTLR_NMBR, DSPL_DT, \r\n"
  414. " VMS_DSPL_MSG_IMAG, NVL(DSPL_HH, 2) AS DSPL_HH \r\n"
  415. " FROM TB_VMS_DSPL_PRST \r\n"
  416. " WHERE VMS_CTLR_NMBR = :p01 \r\n"
  417. " AND DSPL_DT >= TO_CHAR(SYSDATE-5/1440, 'YYYYMMDDHH24MISS') \r\n";
  418. try
  419. {
  420. pADO->Connection = ITSDb_GetConnection();
  421. ITSDb_SQLText(pADO, sQry);
  422. ITSDb_SQLBind(pADO, "p01", FObj->VMS_CTLR_NMBR);
  423. ITSDb_SQLOpen(pADO);
  424. for( ; !pADO->Eof; pADO->Next())
  425. {
  426. if (FPhaseCnt >= INT_VMS_MAX_FORM) break;
  427. FInterval[FPhaseCnt] = pADO->FieldByName("DSPL_HH")->AsInteger;
  428. if (FInterval[FPhaseCnt] < 1 || FInterval[FPhaseCnt] > 5)
  429. {
  430. FInterval[FPhaseCnt] = 3;
  431. }
  432. TStream *pStream = NULL;
  433. pStream = pADO->CreateBlobStream(pADO->FieldByName("VMS_DSPL_MSG_IMAG"), bmRead);
  434. TImage *pImage = FVmsImage[FPhaseCnt];
  435. try
  436. {
  437. try {
  438. pImage->Canvas->Lock();
  439. pStream->Position = 0;
  440. pImage->Picture->Bitmap->LoadFromStream(pStream);
  441. FPhaseCnt++;
  442. } catch(...) {}
  443. }__finally{
  444. pImage->Canvas->Unlock();
  445. if (pStream) delete pStream;
  446. }
  447. }
  448. ITSDb_SQLClose(pADO);
  449. }
  450. catch(EDatabaseError &E)
  451. {
  452. throw Exception(String(E.ClassName()) + E.Message);
  453. }
  454. catch(...)
  455. {
  456. throw Exception("알수없는 오류가 발생하였습니다.");
  457. }
  458. }
  459. //---------------------------------------------------------------------------
  460. void __fastcall TFrmVmsMsg::FFPlayer1State(TObject *Sender, TPlayState APlayState)
  461. {
  462. switch(APlayState)
  463. {
  464. case Ffbasecomponent::psPlay:
  465. case Ffbasecomponent::psResume:
  466. break;
  467. case Ffbasecomponent::psPause:
  468. case Ffbasecomponent::psStep:
  469. break;
  470. case Ffbasecomponent::psStop:
  471. case Ffbasecomponent::psEnd:
  472. if (FFPlayer1->Tag == 1 && FFPlayer1->ScreenHandle != NULL)
  473. {
  474. FFPlayer1->Tag = 0;
  475. if (ImgForm->Visible == false) {
  476. ImgForm->Visible = true;
  477. }
  478. if (FFormClose == false) {
  479. FFPlayer1->Stop(true);
  480. PostMessage(FFPlayer1->ScreenHandle, CM_INVALIDATE, 0, 0);
  481. UpdateWindow(FFPlayer1->ScreenHandle);
  482. FFPlayer1->ScreenHandle = NULL;
  483. if (TmrVmsMsgDisp->Enabled == false) {
  484. TmrVmsMsgDisp->Interval = 100;
  485. TmrVmsMsgDisp->Enabled = true;
  486. }
  487. }
  488. }
  489. break;
  490. }
  491. }
  492. //---------------------------------------------------------------------------