CDSFormF.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. //---------------------------------------------------------------------------
  2. #pragma hdrstop
  3. #include "CDSFormF.h"
  4. #include "VmsUtilsF.h"
  5. #include "VMSCommLibF.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. //---------------------------------------------------------------------------
  9. TCDSFormObj::TCDSFormObj()
  10. {
  11. pImage = NULL;
  12. pImage = new TImage(NULL);
  13. }
  14. //---------------------------------------------------------------------------
  15. TCDSFormObj::~TCDSFormObj()
  16. {
  17. Clear();
  18. if (pImage)
  19. {
  20. delete pImage;
  21. pImage = NULL;
  22. }
  23. }
  24. //---------------------------------------------------------------------------
  25. void TCDSFormObj::Clear()
  26. {
  27. if (pImage)
  28. {
  29. pImage->Picture->Bitmap->FreeImage();
  30. pImage->Picture->Assign(NULL);
  31. }
  32. }
  33. //---------------------------------------------------------------------------
  34. //---------------------------------------------------------------------------
  35. TCDSForm::TCDSForm()
  36. {
  37. TrfIfsc = false;
  38. TrfAxis = false;
  39. TrfFixed = false;
  40. IsNewForm = true;
  41. TrfBakImgId = "";
  42. }
  43. //---------------------------------------------------------------------------
  44. TCDSForm::~TCDSForm()
  45. {
  46. Clear();
  47. FLists.RemoveAll();
  48. }
  49. //---------------------------------------------------------------------------
  50. void TCDSForm::Clear()
  51. {
  52. }
  53. //---------------------------------------------------------------------------
  54. //---------------------------------------------------------------------------
  55. TCDSFormManager *CDSFormManager = NULL;
  56. //---------------------------------------------------------------------------
  57. TCDSFormManager::TCDSFormManager()
  58. {
  59. }
  60. //---------------------------------------------------------------------------
  61. TCDSFormManager::~TCDSFormManager()
  62. {
  63. FLists.RemoveAll();
  64. }
  65. //---------------------------------------------------------------------------
  66. int TCDSFormManager::LoadVmsFormInfo(TADOConnection *ADbConn)
  67. {
  68. String sQry;
  69. TADOQuery *pADO = NULL;
  70. TStream *pStream = NULL;
  71. int nSelCnt = 0;
  72. DWORD dwTick = GetTickCount();
  73. SELSTART;
  74. sQry = "SELECT A.VMS_FORM_ID, \r\n"
  75. " A.VMS_TYPE_CD, \r\n"
  76. " A.VMS_FORM_TYPE_CD, \r\n"
  77. " A.VMS_FORM_COLR_CD, \r\n"
  78. " A.VMS_FORM_DSPL_DRCT_CD, \r\n"
  79. " A.VMS_FORM_DSPL_MTHD_CD, \r\n"
  80. " A.SYMB_LIB_NMBR, \r\n"
  81. " TRIM(A.VMS_FORM_NM) AS VMS_FORM_NM, \r\n"
  82. " TRIM(A.VMS_FORM_EXPL) AS VMS_FORM_EXPL, \r\n"
  83. " A.UPDT_DT \r\n"
  84. " FROM TB_VMS_FORM A \r\n";
  85. try
  86. {
  87. TCDSForm *pCDSForm;
  88. try
  89. {
  90. pADO = new TADOQuery(NULL);
  91. pADO->Connection = ADbConn;
  92. SQLText(pADO, sQry, true);
  93. SQLOpen(pADO);
  94. for( ; !pADO->Eof; pADO->Next())
  95. {
  96. AnsiString VMS_FORM_ID = pADO->FieldByName("VMS_FORM_ID")->AsString.Trim();
  97. pCDSForm = FLists.Find(VMS_FORM_ID);
  98. if (!pCDSForm)
  99. {
  100. pCDSForm = new TCDSForm();
  101. pCDSForm->VMS_FORM_ID = VMS_FORM_ID;
  102. CDSFormManager->FLists.Push(pCDSForm->VMS_FORM_ID, pCDSForm);
  103. }
  104. pCDSForm->FLists.RemoveAll();
  105. pCDSForm->TrfBakImgId = ""; //소통정보 배경 이미지 ID
  106. pCDSForm->VMS_TYPE_CD = pADO->FieldByName("VMS_TYPE_CD")->AsString;
  107. pCDSForm->VMS_FORM_TYPE_CD = pADO->FieldByName("VMS_FORM_TYPE_CD")->AsInteger;
  108. pCDSForm->VMS_FORM_COLR_CD = pADO->FieldByName("VMS_FORM_COLR_CD")->AsInteger;
  109. pCDSForm->VMS_FORM_DSPL_DRCT_CD = pADO->FieldByName("VMS_FORM_DSPL_DRCT_CD")->AsInteger;
  110. pCDSForm->VMS_FORM_DSPL_MTHD_CD = pADO->FieldByName("VMS_FORM_DSPL_MTHD_CD")->AsInteger;
  111. pCDSForm->VMS_FORM_NM = pADO->FieldByName("VMS_FORM_NM")->AsString;
  112. pCDSForm->VMS_FORM_EXPL = pADO->FieldByName("VMS_FORM_EXPL")->AsString;
  113. pCDSForm->VMS_FORM_SUB_TYPE_CD = pADO->FieldByName("VMS_FORM_DSPL_DRCT_CD")->AsInteger; // 긴급차량우선신호를 위해 추가함. (e_evehicle_form_type)
  114. pCDSForm->TrfIfsc = false;
  115. pCDSForm->TrfAxis = false;
  116. pCDSForm->TrfFixed = false;
  117. if (pCDSForm->VMS_FORM_EXPL == NULL) {
  118. pCDSForm->VMS_FORM_EXPL = "";
  119. }
  120. AnsiString UPDT_DT = pADO->FieldByName("UPDT_DT")->AsString;
  121. // 정적폼(홍보) 같은 경우 최초 또는 변경되었을 때에만 사용할수 있도록(제어기로 한번만 다운로드 할수 있도록)
  122. // 체크 플래그를 두어 확인할수 있도록 한다.
  123. pCDSForm->IsNewForm = false;
  124. if (pCDSForm->VMS_FORM_TYPE_CD == eFormTp_hongbo && pCDSForm->UPDT_DT != UPDT_DT)
  125. {
  126. pCDSForm->IsNewForm = true;
  127. }
  128. #if 0
  129. if (pCDSForm->VMS_FORM_TYPE_CD == eFormTp_hongbo)
  130. {
  131. //정적인 폼인 경우 폼의 이미지를 파일로 저장해 둔다
  132. pCDSForm->LocalFileName = g_sFtpStaticDir + pCDSForm->VMS_FORM_ID + ".bmp";
  133. pCDSForm->FtpFileName = AnsiString(FTP_STATIC) + "\\" + pCDSForm->VMS_FORM_ID + ".bmp";
  134. // 파일이 존재하지 않거나 업데이트 시각이 다르면 새로 홍보폼 이미지를 생성한다.
  135. if (pCDSForm->UPDT_DT != UPDT_DT || !FileExists(pCDSForm->LocalFileName))
  136. {
  137. AnsiString BackupFileName = pCDSForm->LocalFileName+".bak";
  138. if (FileExists(pCDSForm->LocalFileName))
  139. {
  140. try {
  141. //DeleteFile(pCDSForm->LocalFileName);
  142. MoveFile(pCDSForm->LocalFileName.c_str(), BackupFileName.c_str());
  143. } catch(Exception &) {}
  144. }
  145. try
  146. {
  147. TMemoryStream *Stream1 = (TMemoryStream *)pADO->CreateBlobStream(pADO->FieldByName("VMS_FORM_IMAG"), bmRead);
  148. Stream1->SaveToFile(pCDSForm->LocalFileName);
  149. SAFE_DELETE(Stream1);
  150. }
  151. catch(Exception &e)
  152. {
  153. if (FileExists(BackupFileName))
  154. {
  155. MoveFile(BackupFileName.c_str(), pCDSForm->LocalFileName.c_str());
  156. }
  157. pCDSForm->LocalFileName = "";
  158. pCDSForm->FtpFileName = "";
  159. }
  160. }
  161. }
  162. #endif
  163. pCDSForm->UPDT_DT = UPDT_DT;
  164. nSelCnt++;
  165. }
  166. }
  167. catch(EDatabaseError &E)
  168. {
  169. DBERROR(String(E.ClassName()), E.Message, sQry);
  170. return -1;
  171. }
  172. catch(Exception &e)
  173. {
  174. DBERROR(String(e.ClassName()), e.Message, sQry);
  175. return -1;
  176. }
  177. }
  178. __finally
  179. {
  180. SQLFree(pADO);
  181. }
  182. if (LoadVmsFormObjectInfo(ADbConn) < 0)
  183. {
  184. return -1;
  185. }
  186. SELEND(nSelCnt, dwTick);
  187. if (JOBTIME(dwTick) > g_AppCfg.JobTimeout) {
  188. TIMEDELAY(nSelCnt, dwTick);
  189. }
  190. return nSelCnt;
  191. }
  192. //---------------------------------------------------------------------------
  193. int TCDSFormManager::LoadVmsFormObjectInfo(TADOConnection *ADbConn)
  194. {
  195. String sQry;
  196. TADOQuery *pADO = NULL;
  197. TStream *pStream = NULL;
  198. int nSelCnt = 0;
  199. DWORD dwTick = GetTickCount();
  200. SELSTART;
  201. sQry = "SELECT B.VMS_FORM_ID, \r\n"
  202. " B.VMS_FORM_OBJECT_ID, \r\n"
  203. " B.VMS_FORM_DSPL_ROW, \r\n"
  204. " B.VMS_FORM_DSPL_CLMN, \r\n"
  205. " B.VMS_FORM_OBJECT_TYPE_CD, \r\n"
  206. " B.VMS_FONT_NAME_CD, \r\n"
  207. " B.VMS_FONT_COLR_CD, \r\n"
  208. " B.VMS_FONT_BOLD, \r\n"
  209. " B.VMS_FONT_SIZE, \r\n"
  210. " B.VMS_FONT_ALIGN, \r\n"
  211. " B.VMS_DSPL_TXT, \r\n"
  212. " B.VMS_DSPL_XCRDN, \r\n"
  213. " B.VMS_DSPL_YCRDN, \r\n"
  214. " B.VMS_DSPL_WIDTH, \r\n"
  215. " B.VMS_DSPL_HEIGHT, \r\n"
  216. " B.VMS_DSPL_BLINKING, \r\n"
  217. " B.VMS_DSPL_BKCOLOR, \r\n"
  218. " B.VMS_DSPL_SIZE, \r\n"
  219. " B.TRFC_FILL_CD, \r\n"
  220. " B.SYMB_LIB_NMBR, \r\n"
  221. " B.VMS_IFSC_ID \r\n"
  222. " FROM TB_VMS_FORM A, \r\n"
  223. " TB_VMS_FORM_OBJECT B, \r\n"
  224. " TB_VMS_SYMB_LIB C \r\n"
  225. " WHERE A.VMS_FORM_ID = B.VMS_FORM_ID \r\n"
  226. " AND B.SYMB_LIB_NMBR = C.SYMB_LIB_NMBR(+) \r\n"
  227. " ORDER BY B.VMS_FORM_ID, B.VMS_FORM_OBJECT_ID \r\n";
  228. int notFound = 0;
  229. try
  230. {
  231. TCDSForm *pCDSForm;
  232. TCDSFormObj *pCDSFormObj;
  233. try
  234. {
  235. pADO = new TADOQuery(NULL);
  236. pADO->Connection = ADbConn;
  237. SQLText(pADO, sQry, true);
  238. SQLOpen(pADO);
  239. for( ; !pADO->Eof; pADO->Next())
  240. {
  241. AnsiString sFormId = pADO->FieldByName("VMS_FORM_ID")->AsString.Trim();
  242. pCDSForm = FLists.Find(sFormId);
  243. if (!pCDSForm)
  244. {
  245. MDEBUG("DCOM Not Found Form Object by FormId: %d", sFormId.c_str());
  246. continue;
  247. }
  248. nSelCnt++;
  249. pCDSFormObj = new TCDSFormObj();
  250. pCDSFormObj->VMS_FORM_OBJECT_ID = pADO->FieldByName("VMS_FORM_OBJECT_ID")->AsInteger;
  251. pCDSFormObj->VMS_FORM_ID = pADO->FieldByName("VMS_FORM_ID")->AsString;
  252. pCDSFormObj->VMS_FORM_DSPL_ROW = pADO->FieldByName("VMS_FORM_DSPL_ROW")->AsInteger;
  253. pCDSFormObj->VMS_FORM_DSPL_CLMN = pADO->FieldByName("VMS_FORM_DSPL_CLMN")->AsInteger;
  254. pCDSFormObj->VMS_FORM_OBJECT_TYPE_CD = pADO->FieldByName("VMS_FORM_OBJECT_TYPE_CD")->AsInteger;
  255. pCDSFormObj->VMS_FONT_NAME_CD = pADO->FieldByName("VMS_FONT_NAME_CD")->AsInteger;
  256. pCDSFormObj->VMS_FONT_COLR_CD = pADO->FieldByName("VMS_FONT_COLR_CD")->AsInteger;
  257. pCDSFormObj->VMS_FONT_BOLD = pADO->FieldByName("VMS_FONT_BOLD")->AsInteger;
  258. pCDSFormObj->VMS_FONT_SIZE = pADO->FieldByName("VMS_FONT_SIZE")->AsInteger;
  259. pCDSFormObj->VMS_FONT_ALIGN = pADO->FieldByName("VMS_FONT_ALIGN")->AsInteger;
  260. pCDSFormObj->VMS_DSPL_TXT = pADO->FieldByName("VMS_DSPL_TXT")->AsString;
  261. pCDSFormObj->VMS_DSPL_XCRDN = pADO->FieldByName("VMS_DSPL_XCRDN")->AsInteger;
  262. pCDSFormObj->VMS_DSPL_YCRDN = pADO->FieldByName("VMS_DSPL_YCRDN")->AsInteger;
  263. pCDSFormObj->VMS_DSPL_WIDTH = pADO->FieldByName("VMS_DSPL_WIDTH")->AsInteger;
  264. pCDSFormObj->VMS_DSPL_HEIGHT = pADO->FieldByName("VMS_DSPL_HEIGHT")->AsInteger;
  265. pCDSFormObj->VMS_DSPL_BLINKING = pADO->FieldByName("VMS_DSPL_BLINKING")->AsInteger;
  266. pCDSFormObj->VMS_DSPL_BKCOLOR = pADO->FieldByName("VMS_DSPL_BKCOLOR")->AsInteger;
  267. pCDSFormObj->VMS_DSPL_SIZE = pADO->FieldByName("VMS_DSPL_SIZE")->AsInteger;
  268. pCDSFormObj->TRFC_FILL_CD = pADO->FieldByName("TRFC_FILL_CD")->AsString;
  269. pCDSFormObj->SYMB_LIB_NMBR = pADO->FieldByName("SYMB_LIB_NMBR")->AsString;
  270. pCDSFormObj->VMS_IFSC_ID = pADO->FieldByName("VMS_IFSC_ID")->AsString;
  271. pCDSForm->FLists.Push(pCDSFormObj->VMS_FORM_OBJECT_ID, pCDSFormObj);
  272. int nObjType = pCDSFormObj->VMS_FORM_OBJECT_TYPE_CD;
  273. if (pCDSForm->VMS_FORM_TYPE_CD == eFormtp_figure)
  274. {
  275. //도형식 소통정보 폼인데 구간 소통정보를 하단에 표출하는 경우
  276. //하나의 폼이 여러개의 소통정보를 표출되도록 하기 위함
  277. switch(nObjType)
  278. {
  279. //////////////////////// 20200515 추가함(S)
  280. case 0://, , @문자열
  281. case 1://, , @심볼
  282. case 2://, , @이미지
  283. if (pCDSFormObj->TRFC_FILL_CD == "F")
  284. {
  285. //하단고정일 경우 도형식하단에 표출할 소통정보가 없을 경우 표출하는 정보임
  286. pCDSForm->TrfFixed = true;
  287. }
  288. break;
  289. //////////////////////// 20200515 추가함(E)
  290. case 11://, ' @구간명
  291. case 12://, ' @시점명
  292. case 13://, ' @종점명
  293. case 14://, ' @소통상황
  294. case 15://, ' @통행시간
  295. case 16://, ' @통행속도
  296. case 17://, ' @소통정보이미지
  297. case 18://, ' @지점명
  298. pCDSForm->TrfIfsc = true;
  299. break;
  300. case 93://, ' @축시점명(순환)
  301. case 94://, ' @축종점명(순환)
  302. case 95://, ' @축소통상황(순환)
  303. case 96://, ' @축통행시간(순환)
  304. pCDSForm->TrfAxis = true;
  305. break;
  306. }
  307. }
  308. if (nObjType == 3)
  309. {
  310. pCDSForm->TrfBakImgId = pCDSFormObj->SYMB_LIB_NMBR + "0";
  311. }
  312. if (nObjType == 1 || //심볼
  313. nObjType == 2 || //이미지(파일에서 직접입력한것임)
  314. nObjType == 3 || //소통정보배경이미지
  315. nObjType == 17 || //소통정보이미지1
  316. nObjType == 27 || //소통정보이미지2
  317. nObjType == 37 || //소통정보이미지3
  318. nObjType == 47 || //소통정보이미지4
  319. nObjType == 200 || //동영상이미지
  320. nObjType == 300 ) //스트리밍영상이미지
  321. {
  322. pCDSFormObj->Clear();
  323. //pCDSFormObj->pImage->Picture->Bitmap->PixelFormat = g_AppCfg.PixelFormat;//g_AppCfg.PixelFormat;//pf4bit;
  324. //심볼에서 읽지 않고 폼오브젝트에 있는 이미지를 사용함
  325. #if 1
  326. try
  327. {
  328. TCDSImage *pVmsImg = CDSImageManager->FLists.Find(pCDSFormObj->SYMB_LIB_NMBR+"0");
  329. if (pVmsImg && pVmsImg->IMAG_DATA)
  330. {
  331. pCDSFormObj->pImage->Picture->Bitmap->Assign(pVmsImg->IMAG_DATA->Picture->Bitmap);
  332. }
  333. else
  334. {
  335. if (pCDSFormObj->SYMB_LIB_NMBR == "")
  336. notFound++;
  337. else
  338. MERROR("MAIN LoadVmsFormObjectInfo Symbol Not Found: %s", pCDSFormObj->SYMB_LIB_NMBR.c_str());
  339. }
  340. }
  341. catch(Exception &e)
  342. {
  343. MERROR("MAIN LoadVmsFormObjectInfo Symbol Find Failed: %s, %s, %s", pCDSFormObj->SYMB_LIB_NMBR.c_str(), AnsiString(e.ClassName()).c_str(), AnsiString(e.Message).c_str());
  344. }
  345. #else
  346. TStream *pStream = pADO->CreateBlobStream(pADO->FieldByName("IMAG_DATA"), bmRead);
  347. try
  348. {
  349. if (pStream && pStream->Size > 0)
  350. {
  351. pStream->Position = 0;
  352. AssignBmp(pCDSFormObj->pImage, pStream);
  353. }
  354. }
  355. __finally
  356. {
  357. SAFE_DELETE(pStream);
  358. }
  359. #endif
  360. }
  361. }
  362. if (notFound > 0) {
  363. MERROR("MAIN LoadVmsFormObjectInfo Symbol Not Found: %d EA.", notFound);
  364. }
  365. }
  366. catch(EDatabaseError &E)
  367. {
  368. DBERROR(String(E.ClassName()), E.Message, sQry);
  369. return -1;
  370. }
  371. catch(Exception &e)
  372. {
  373. DBERROR(String(e.ClassName()), e.Message, sQry);
  374. return -1;
  375. }
  376. }
  377. __finally
  378. {
  379. SQLFree(pADO);
  380. }
  381. #if 0
  382. if (0)//g_LogCfg.Debug)
  383. {
  384. FOR_STL(TCDSForm*, pTmp, FormManager->FLists)
  385. {
  386. MDEBUG("DCOM Vms Form: %s, Objects: %d", pTmp->VMS_FORM_ID.c_str(), pTmp->FLists.Size());
  387. }
  388. }
  389. #endif
  390. SELEND(nSelCnt, dwTick);
  391. if (JOBTIME(dwTick) > g_AppCfg.JobTimeout) {
  392. TIMEDELAY(nSelCnt, dwTick);
  393. }
  394. return nSelCnt;
  395. }
  396. //---------------------------------------------------------------------------