FrmVmsMsgF.cpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "ITSDbF.h"
  4. #include "ITSUtilF.h"
  5. #include "AppGlobalF.h"
  6. #include "ITSLangTransF.h"
  7. #pragma hdrstop
  8. #include "FrmVmsMsgF.h"
  9. //---------------------------------------------------------------------------
  10. #pragma package(smart_init)
  11. #pragma link "cxContainer"
  12. #pragma link "cxControls"
  13. #pragma link "cxEdit"
  14. #pragma link "cxGraphics"
  15. #pragma link "cxLabel"
  16. #pragma link "cxLookAndFeelPainters"
  17. #pragma link "cxLookAndFeels"
  18. #pragma link "dxSkinBlack"
  19. #pragma link "dxSkinBlue"
  20. #pragma link "dxSkinsCore"
  21. #pragma resource "*.dfm"
  22. TFrmVmsMsg *FrmVmsMsg;
  23. //---------------------------------------------------------------------------
  24. __fastcall TFrmVmsMsg::TFrmVmsMsg(TComponent* Owner, TItsVms *AObj)
  25. : TForm(Owner)
  26. {
  27. LangTrans->Translate(this, ITSDb_GetConnection());
  28. FObj = AObj;
  29. FQryHour = -1;
  30. FQryMin = -1;
  31. for (int ii = 0; ii < MAX_VMSPHASE; ii++)
  32. {
  33. FVmsImage[ii] = new TImage(this);
  34. FVmsImage[ii]->Visible = false;
  35. FInterval[ii] = 1;
  36. }
  37. FPhaseCnt = 0;
  38. pADO->Connection = ITSDb_GetConnection();
  39. SetVmsForm();
  40. }
  41. //---------------------------------------------------------------------------
  42. void __fastcall TFrmVmsMsg::FormClose(TObject *Sender, TCloseAction &Action)
  43. {
  44. Action = caFree;
  45. }
  46. //---------------------------------------------------------------------------
  47. void __fastcall TFrmVmsMsg::FormShow(TObject *Sender)
  48. {
  49. TmrShow->Enabled = true;
  50. }
  51. //---------------------------------------------------------------------------
  52. void __fastcall TFrmVmsMsg::TmrShowTimer(TObject *Sender)
  53. {
  54. TmrShow->Enabled = false;
  55. if (FObj)
  56. {
  57. Caption = FObj->VMS_CTLR_ID + ": " + FObj->VMS_NM;
  58. }
  59. TmrVmsMsgDisp->Interval = 100;
  60. TmrVmsMsgDisp->Enabled = true;
  61. }
  62. //---------------------------------------------------------------------------
  63. void __fastcall TFrmVmsMsg::SetVmsForm()
  64. {
  65. if (!FObj) return;
  66. int nW = PnlVmsMsgDisp->Width;
  67. int nH = PnlVmsMsgDisp->Height;
  68. nH = FObj->HEIGHT;
  69. nW = FObj->WIDTH;
  70. ClientWidth = nW;
  71. ClientHeight= nH + PnlOffer->Height;
  72. PnlVmsMsgDisp->Width = nW;
  73. PnlVmsMsgDisp->Height = nH;
  74. ImgForm->Width = nW;
  75. ImgForm->Height = nH;
  76. ImgForm->Picture->Bitmap->Width = nW;
  77. ImgForm->Picture->Bitmap->Height= nH;
  78. PnlVmsMsgDisp->ParentColor = false;
  79. PnlVmsMsgDisp->Color = clBlack;
  80. ImgForm->Left = 0;
  81. ImgForm->Top = 0;
  82. }
  83. //---------------------------------------------------------------------------
  84. void __fastcall TFrmVmsMsg::ClearVmsForm()
  85. {
  86. TCanvas *pCanvas = ImgForm->Canvas;
  87. try {
  88. pCanvas->Lock();
  89. try {
  90. pCanvas->Pen->Color = clWhite;
  91. pCanvas->Pen->Width = 0;
  92. pCanvas->Pen->Style = psClear;
  93. pCanvas->Brush->Style = bsSolid;
  94. pCanvas->Brush->Color = clBlack;
  95. pCanvas->Rectangle(0, 0, ImgForm->Width, ImgForm->Height);
  96. } catch(...) { }
  97. } __finally {
  98. ImgForm->Refresh();
  99. pCanvas->Unlock();
  100. }
  101. }
  102. //---------------------------------------------------------------------------
  103. void __fastcall TFrmVmsMsg::TmrVmsMsgDispTimer(TObject *Sender)
  104. {
  105. TmrVmsMsgDisp->Enabled = false;
  106. PnlOffer->Caption = " " + lblTm->Caption + ":";
  107. PnlOffer->Font->Color = clBlack;
  108. bool bQry = false;
  109. if (FQryMin < 0)
  110. {
  111. bQry = true;
  112. FQryMin = StrToInt(Now().FormatString("nn"));
  113. if ((FQryMin % 5) == 0)
  114. FQryMin--;
  115. }
  116. else
  117. {
  118. int nCurMin = StrToInt(Now().FormatString("nn"));
  119. int nCurSec = StrToInt(Now().FormatString("ss"));
  120. if ((nCurMin % 5) == 0 && nCurSec >= 45)
  121. {
  122. if (FQryMin != nCurMin)
  123. {
  124. FQryMin = nCurMin;
  125. bQry = true;
  126. }
  127. }
  128. }
  129. if (bQry)
  130. {
  131. SelectVmsForm();
  132. if (FPhaseCnt == 0)
  133. {
  134. PnlVmsMsgDisp->ParentColor = false;
  135. PnlVmsMsgDisp->Color = clBlack;
  136. ImgForm->Visible = false;
  137. }
  138. else
  139. {
  140. ImgForm->Visible = true;
  141. }
  142. }
  143. else
  144. {
  145. if (FDispIndex >= FPhaseCnt)
  146. {
  147. FDispIndex = 0;
  148. }
  149. }
  150. int nInterval = 5; //5초
  151. try
  152. {
  153. if (FDispIndex < FPhaseCnt)
  154. {
  155. nInterval = FInterval[FDispIndex];
  156. try
  157. {
  158. ClearVmsForm();
  159. ImgForm->Picture->Assign(FVmsImage[FDispIndex]->Picture);
  160. //Caption = FObj->VMS_CTLR_ID + ": " + FObj->VMS_NM + " [" + String(FDispIndex+1) + "/" + String(FPhaseCnt) + "]";
  161. } catch(...) {}
  162. PnlOffer->Caption = " " + lblTm->Caption + ": " + ITSUtil_FormatStr(FOfferTime[FDispIndex], STR_DATETIME) + " [" + String(FDispIndex+1) + "/" + String(FPhaseCnt) + "]";
  163. if (FOffer[FDispIndex])
  164. PnlOffer->Font->Color = clBlack;
  165. else
  166. PnlOffer->Font->Color = clRed;
  167. FDispIndex++;
  168. }
  169. }
  170. catch(...)
  171. {
  172. }
  173. TmrVmsMsgDisp->Interval = nInterval * 1000;
  174. TmrVmsMsgDisp->Enabled = true;
  175. }
  176. //---------------------------------------------------------------------------
  177. void __fastcall TFrmVmsMsg::SelectVmsForm()
  178. {
  179. bool bImage = false;
  180. String sQry;
  181. FDispIndex= 0;
  182. FPhaseCnt = 0;
  183. if (!FObj)
  184. {
  185. return;
  186. }
  187. sQry = "SELECT A.VMS_CTLR_NMBR, A.PHASE, A.DSPL_HH, A.DNLD_YN, \r\n"
  188. " A.VMS_MSG_DSPL_MTHD_CD, A.TRFC_SITU_TYPE_CD, A.DSPL_DT, \r\n"
  189. " TO_CHAR(SYSDATE - 6/1440, 'YYYYMMDDHH24MISS') AS SVC_DT, \r\n"
  190. " A.VMS_DSPL_MSG_IMAG \r\n"
  191. " FROM TB_VMS_DSPL_PRST A, \r\n"
  192. " (SELECT VMS_CTLR_NMBR, MAX(DSPL_DT) AS DSPL_DT \r\n"
  193. " FROM TB_VMS_DSPL_PRST \r\n"
  194. " GROUP BY VMS_CTLR_NMBR) B \r\n"
  195. " WHERE A.VMS_CTLR_NMBR = :p01 \r\n"
  196. " AND A.VMS_CTLR_NMBR = B.VMS_CTLR_NMBR \r\n"
  197. " AND A.DSPL_DT = B.DSPL_DT \r\n"
  198. " ORDER BY A.VMS_CTLR_NMBR, A.PHASE \r\n";
  199. try
  200. {
  201. pADO->Connection = ITSDb_GetConnection();
  202. ITSDb_SQLText(pADO, sQry);
  203. ITSDb_SQLBind(pADO, "p01", FObj->VMS_CTLR_NMBR);
  204. ITSDb_SQLOpen(pADO);
  205. for( ; !pADO->Eof; pADO->Next())
  206. {
  207. if (FPhaseCnt >= MAX_VMSPHASE) break;
  208. String DSPL_DT = pADO->FieldByName("DSPL_DT")->AsString;
  209. String SVC_DT = pADO->FieldByName("SVC_DT")->AsString;
  210. String DNLD_YN = pADO->FieldByName("DNLD_YN")->AsString;
  211. if (DSPL_DT >= SVC_DT)
  212. {
  213. FOffer[FPhaseCnt] = true;
  214. }
  215. else
  216. {
  217. FOffer[FPhaseCnt] = false;
  218. }
  219. if (DNLD_YN == "N") FOffer[FPhaseCnt] = false;
  220. FOfferTime[FPhaseCnt] = DSPL_DT;
  221. FInterval[FPhaseCnt] = pADO->FieldByName("DSPL_HH")->AsInteger;
  222. #if 1
  223. if (FInterval[FPhaseCnt] <= 0) FInterval[FPhaseCnt] = 3;
  224. if (FInterval[FPhaseCnt] >= 10) FInterval[FPhaseCnt] = 10;
  225. #else
  226. if (FInterval[FPhaseCnt] < 1 || FInterval[FPhaseCnt] > 5)
  227. {
  228. FInterval[FPhaseCnt] = 3;
  229. }
  230. #endif
  231. TStream *pStream = NULL;
  232. pStream = pADO->CreateBlobStream(pADO->FieldByName("VMS_DSPL_MSG_IMAG"), bmRead);
  233. TImage *pImage = FVmsImage[FPhaseCnt];
  234. try
  235. {
  236. try {
  237. pImage->Canvas->Lock();
  238. pStream->Position = 0;
  239. pImage->Picture->Bitmap->LoadFromStream(pStream);
  240. FPhaseCnt++;
  241. } catch(...) {}
  242. }__finally{
  243. pImage->Canvas->Unlock();
  244. if (pStream) delete pStream;
  245. }
  246. }
  247. ITSDb_SQLClose(pADO);
  248. }
  249. catch(EDatabaseError &E)
  250. {
  251. throw Exception(String(E.ClassName()) + E.Message);
  252. }
  253. catch(...)
  254. {
  255. throw Exception(FrmLang->lblDbErr->Caption);//"알수없는 오류가 발생하였습니다.");
  256. }
  257. }
  258. //---------------------------------------------------------------------------
  259. void __fastcall TFrmVmsMsg::FormDestroy(TObject *Sender)
  260. {
  261. TmrVmsMsgDisp->Enabled = false;
  262. try {
  263. for (int ii = 0; ii < MAX_VMSPHASE; ii++)
  264. {
  265. if (FVmsImage[ii]) delete FVmsImage[ii];
  266. }
  267. if (FObj) FObj->FData1 = NULL;
  268. } catch(...) {}
  269. }
  270. //---------------------------------------------------------------------------