FrmInitializeF.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "WindowMsgF.h"
  4. #include "CDSCodeF.h"
  5. #include "CDSTrafficGradeF.h"
  6. #include "CDSLayerF.h"
  7. #include "CDSNodeF.h"
  8. #include "CDSLinkF.h"
  9. #include "CDSIfscF.h"
  10. #include "CDSRoadF.h"
  11. #include "CDSFacilityF.h"
  12. #include "CDSProcessF.h"
  13. #include "CDSIncidentF.h"
  14. #include "CDSRepeatCongestF.h"
  15. #include "CDSPrltCtlrF.h"
  16. #include "CDSPrkPlceF.h"
  17. #include "CDSUtisF.h"
  18. #include "CDSCompanyF.h"
  19. #include "CDSColSysF.h"
  20. #include "CDSVilgFrcsF.h"
  21. #include "CDSDatabaseF.h"
  22. #include "ITSLangTransF.h"
  23. #pragma hdrstop
  24. #include "FrmInitializeF.h"
  25. #include "FrmMainF.h"
  26. #include "ITS_OPLibF.h"
  27. //---------------------------------------------------------------------------
  28. #pragma package(smart_init)
  29. #pragma link "cxContainer"
  30. #pragma link "cxControls"
  31. #pragma link "cxEdit"
  32. #pragma link "cxGraphics"
  33. #pragma link "cxLabel"
  34. #pragma link "cxLookAndFeelPainters"
  35. #pragma link "cxLookAndFeels"
  36. #pragma link "cxProgressBar"
  37. #pragma link "dxSkinBlack"
  38. #pragma link "dxSkinBlue"
  39. #pragma link "dxSkinsCore"
  40. #pragma link "IdAntiFreeze"
  41. #pragma link "IdAntiFreezeBase"
  42. #pragma link "IdBaseComponent"
  43. #pragma link "IdComponent"
  44. #pragma link "IdExplicitTLSClientServerBase"
  45. #pragma link "IdFTP"
  46. #pragma link "IdTCPClient"
  47. #pragma link "IdTCPConnection"
  48. #pragma link "dxSkinMcSkin"
  49. #pragma resource "*.dfm"
  50. //TFrmInitialize *FrmInitialize = NULL;
  51. //---------------------------------------------------------------------------
  52. __fastcall TFrmInitialize::TFrmInitialize(TComponent* Owner)
  53. : TForm(Owner)
  54. {
  55. //ADOQry->Connection = ITSDb_GetConnection();
  56. LangTrans->Translate(this, ITSDb_GetConnection());
  57. FTitle = "프로그램 초기화";
  58. }
  59. //---------------------------------------------------------------------------
  60. void __fastcall TFrmInitialize::FormShow(TObject *Sender)
  61. {
  62. Refresh();
  63. TmrShow->Enabled = true;
  64. }
  65. //---------------------------------------------------------------------------
  66. void __fastcall TFrmInitialize::TmrShowTimer(TObject *Sender)
  67. {
  68. TmrShow->Enabled = false;
  69. Application->ProcessMessages();
  70. cxProgressBar1->Properties->Max = 150;
  71. try
  72. {
  73. Application->ProcessMessages();
  74. cxProgressBar1->Position = 5;
  75. Application->ProcessMessages();
  76. if (!ItsLayerManager)
  77. {
  78. ItsLayerManager = new TItsLayerManager();
  79. //ItsLayerManager->LoadFromDb();
  80. }
  81. cxProgressBar1->Position = 10;
  82. LblStatus->Caption = cxLabel1->Caption;//"코드정보 로딩...";
  83. Application->ProcessMessages();
  84. if (!ItsCodeManager)
  85. {
  86. ItsCodeManager = new TItsCodeManager();
  87. ItsCodeManager->LoadFromDb();
  88. }
  89. if (!ItsColSysManager)
  90. {
  91. ItsColSysManager = new TItsColSysManager();
  92. ItsColSysManager->LoadFromDb();
  93. }
  94. cxProgressBar1->Position = 20;
  95. LblStatus->Caption = cxLabel2->Caption;
  96. Application->ProcessMessages();
  97. if (!ItsTrafficGradeManager)
  98. {
  99. ItsTrafficGradeManager = new TItsTrafficGradeManager();
  100. ItsTrafficGradeManager->LoadFromDb();
  101. }
  102. cxProgressBar1->Position = 25;
  103. LblStatus->Caption = cxLabel3->Caption;
  104. Application->ProcessMessages();
  105. if (!ItsVilgFrcsManager)
  106. {
  107. ItsVilgFrcsManager = new TItsVilgFrcsManager();
  108. #if defined(USE_VILG) || defined(USE_ATMP)
  109. #ifdef USE_VILG
  110. ItsVilgFrcsManager->LoadFromDb();
  111. #endif
  112. #ifdef USE_ATMP
  113. ItsVilgFrcsManager->LoadFromDbAtmp();
  114. #endif
  115. FrmMain->PostJobMessage(WM_THREAD, WP_PARAM_TRAFFIC, LP_MSG_WEATHER);
  116. #endif
  117. }
  118. cxProgressBar1->Position = 30;
  119. LblStatus->Caption = cxLabel4->Caption;
  120. Application->ProcessMessages();
  121. if (!ItsNodeManager)
  122. {
  123. ItsNodeManager = new TItsNodeManager();
  124. ItsNodeManager->LoadFromDb();
  125. }
  126. cxProgressBar1->Position = 40;
  127. LblStatus->Caption = cxLabel5->Caption;
  128. //레벨1
  129. Application->ProcessMessages();
  130. if (!ItsLinkManager)
  131. {
  132. ItsLinkManager = new TItsLinkManager();
  133. ItsLinkManager->LoadFromDb();
  134. }
  135. //레벨2
  136. cxProgressBar1->Position = 50;
  137. LblStatus->Caption = cxLabel6->Caption;
  138. Application->ProcessMessages();
  139. if (!ItsIfscManager)
  140. {
  141. ItsIfscManager = new TItsIfscManager();
  142. ItsIfscManager->LoadFromDb();
  143. }
  144. //레벨3
  145. cxProgressBar1->Position = 60;
  146. LblStatus->Caption = cxLabel7->Caption;
  147. Application->ProcessMessages();
  148. if (!ItsRoadManager)
  149. {
  150. ItsRoadManager = new TItsRoadManager();
  151. ItsRoadManager->LoadFromDb();
  152. }
  153. cxProgressBar1->Position = 70;
  154. LblStatus->Caption = cxLabel8->Caption;
  155. Application->ProcessMessages();
  156. if (!ItsRepeatCongestManager)
  157. {
  158. ItsRepeatCongestManager = new TItsRepeatCongestManager();
  159. }
  160. FrmMain->PostJobMessage(WM_THREAD, WP_PARAM_TRAFFIC, LP_MSG_TRAFFIC); //1,2,3레벨 및 반복정체 구간 소통정보 조회
  161. cxProgressBar1->Position = 110;
  162. #if 0
  163. LblStatus->Caption = cxLabel12->Caption;
  164. Application->ProcessMessages();
  165. if (!ItsUtisManager)
  166. {
  167. ItsUtisManager = new TItsUtisManager();
  168. ItsUtisManager->SetCenterId(CenterId);
  169. ItsUtisManager->LoadFromDb();
  170. FrmMain->PostJobMessage(WM_THREAD, WP_PARAM_TRAFFIC, LP_MSG_05);
  171. }
  172. #endif
  173. cxProgressBar1->Position = 110;
  174. LblStatus->Caption = cxLabel13->Caption;
  175. Application->ProcessMessages();
  176. if (!ItsFacilityManager)
  177. {
  178. ItsFacilityManager = new TItsFacilityManager();
  179. ItsFacilityManager->SetCenterId(CenterId);
  180. ItsFacilityManager->LoadFromDb();
  181. }
  182. FrmMain->PostJobMessage(WM_THREAD, WP_PARAM_TRAFFIC, LP_MSG_FACILITY_STTS);
  183. cxProgressBar1->Position = 120;
  184. LblStatus->Caption = cxLabel14->Caption;//"프로세스정보 로딩...";
  185. Application->ProcessMessages();
  186. if (!ItsProcessManager)
  187. {
  188. ItsProcessManager = new TItsProcessManager();
  189. ItsProcessManager->LoadFromDb();
  190. }
  191. FrmMain->PostJobMessage(WM_THREAD, WP_PARAM_TRAFFIC, LP_MSG_PROCESS_STTS);
  192. cxProgressBar1->Position = 130;
  193. LblStatus->Caption = cxLabel15->Caption;
  194. Application->ProcessMessages();
  195. if (!ItsIncidentManager)
  196. {
  197. ItsIncidentManager = new TItsIncidentManager();
  198. }
  199. FrmMain->PostJobMessage(WM_THREAD, WP_PARAM_TRAFFIC, LP_MSG_INCIDENT);
  200. if (!ItsCompanyManager)
  201. {
  202. ItsCompanyManager = new TItsCompanyManager();
  203. }
  204. if (!ItsDatabaseManager)
  205. {
  206. ItsDatabaseManager = new TItsDatabaseManager();
  207. }
  208. #if 0
  209. FrmMain->PostJobMessage(WM_THREAD, WP_PARAM_TRAFFIC, LP_MSG_DATABASE_STTS);
  210. #endif
  211. #if 0
  212. if (!ItsEventManager)
  213. {
  214. ItsEventManager = new TItsEventManager();
  215. ItsEventManager->LoadFromDb();
  216. }
  217. #endif
  218. }
  219. catch(...)
  220. {
  221. }
  222. DownloadVmsVideoFiles();
  223. Close();
  224. }
  225. //---------------------------------------------------------------------------
  226. void __fastcall TFrmInitialize::FormClose(TObject *Sender, TCloseAction &Action)
  227. {
  228. Action = caFree;
  229. }
  230. //---------------------------------------------------------------------------
  231. bool __fastcall TFrmInitialize::VmsFtpConnect()
  232. {
  233. if (g_AppCfg.vmsFtp.SERVER == "") return false;
  234. IdFtp->Host = g_AppCfg.vmsFtp.SERVER;
  235. IdFtp->Port = g_AppCfg.vmsFtp.PORT;
  236. IdFtp->Username = g_AppCfg.vmsFtp.USER;
  237. IdFtp->Password = g_AppCfg.vmsFtp.PSWD;
  238. IdFtp->Passive = g_AppCfg.vmsFtp.PASSIVE;
  239. String sTitle = " VMS FTP 접속 ";
  240. String sErrMsg;
  241. bool bConnect = false;
  242. try
  243. {
  244. IdFtp->Connect();
  245. //IdFtp->ChangeDir("VIDEO");
  246. IdFtp->IOHandler->DefStringEncoding = TIdTextEncoding::UTF8;//IndyTextEncoding(949);
  247. bConnect = true;
  248. IdFtp->TransferType = ftBinary;
  249. }
  250. catch (EIdSocketError &exSock)
  251. {
  252. sErrMsg = exSock.Message;
  253. sErrMsg = StringReplace(sErrMsg, "\r\n", " ", TReplaceFlags() << rfReplaceAll);
  254. Application->MessageBox(sErrMsg.c_str(), sTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  255. return false;
  256. }
  257. catch (Exception &e)
  258. {
  259. sErrMsg = e.Message;
  260. sErrMsg = StringReplace(sErrMsg, "\r\n", " ", TReplaceFlags() << rfReplaceAll);
  261. Application->MessageBox(sErrMsg.c_str(), sTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  262. return false;
  263. }
  264. return bConnect;
  265. }
  266. //---------------------------------------------------------------------------
  267. bool __fastcall TFrmInitialize::VmsFtpFileDownload(String AOrgFile, String ADstFile)
  268. {
  269. String sErrMsg;
  270. try
  271. {
  272. IdFtp->TransferType = ftBinary;
  273. IdFtp->Get(AOrgFile, ADstFile, false);
  274. }
  275. catch (EIdSocketError &exSock)
  276. {
  277. sErrMsg = exSock.Message;
  278. sErrMsg = StringReplace(sErrMsg, "\r\n", " ", TReplaceFlags() << rfReplaceAll);
  279. Application->MessageBox(sErrMsg.c_str(), FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  280. return false;
  281. }
  282. catch (Exception &e)
  283. {
  284. sErrMsg = e.Message;
  285. sErrMsg = StringReplace(sErrMsg, "\r\n", " ", TReplaceFlags() << rfReplaceAll);
  286. Application->MessageBox(sErrMsg.c_str(), FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  287. return false;
  288. }
  289. return true;
  290. }
  291. //---------------------------------------------------------------------------
  292. void __fastcall TFrmInitialize::VmsFtpDisconnect()
  293. {
  294. if (IdFtp->Connected())
  295. {
  296. IdFtp->Abort();
  297. IdFtp->Quit();
  298. IdFtp->Disconnect();
  299. }
  300. }
  301. //---------------------------------------------------------------------------
  302. bool __fastcall TFrmInitialize::DownloadVmsVideoFiles()
  303. {
  304. String sQry;
  305. TADOQuery *pADO = NULL;
  306. TItsCode *ftpCode = ItsCodeManager->FLists.Find("VMFTP");
  307. if (ftpCode != NULL) {
  308. TItsSubCode *pSubCode = ftpCode->FSubLists.Find("1");
  309. if (pSubCode != NULL) {
  310. g_AppCfg.vmsFtp.SERVER = pSubCode->CMMN_CD_KOR_NM.Trim();
  311. }
  312. pSubCode = ftpCode->FSubLists.Find("2");
  313. if (pSubCode != NULL) {
  314. g_AppCfg.vmsFtp.PORT = pSubCode->CMMN_CD_KOR_NM.Trim().ToIntDef(21);
  315. }
  316. pSubCode = ftpCode->FSubLists.Find("3");
  317. if (pSubCode != NULL) {
  318. g_AppCfg.vmsFtp.PASSIVE = pSubCode->CMMN_CD_KOR_NM.Trim() == "1" ? true : false;
  319. }
  320. pSubCode = ftpCode->FSubLists.Find("4");
  321. if (pSubCode != NULL) {
  322. g_AppCfg.vmsFtp.USER = pSubCode->CMMN_CD_KOR_NM.Trim();
  323. }
  324. pSubCode = ftpCode->FSubLists.Find("5");
  325. if (pSubCode != NULL) {
  326. g_AppCfg.vmsFtp.PSWD = pSubCode->CMMN_CD_KOR_NM.Trim();
  327. }
  328. }
  329. sQry = "SELECT SYMBLIB_NMBR, SYMB_FILE_NM, \r\n"
  330. " SYMB_IMAG_TYPE, IMAG_SIZE \r\n"
  331. " FROM TB_VMS_SYMB_LIB \r\n"
  332. " WHERE SYMBLIB_NMBR BETWEEN 5000 AND 5999 \r\n"
  333. " AND SYMB_TYPE = 'SBT3' \r\n"
  334. " AND DEL_YN = 'N' \r\n";
  335. ForceDirectories(g_sVideoDir.c_str());
  336. if (!VmsFtpConnect()) return false;
  337. bool bRes = false;
  338. try
  339. {
  340. try
  341. {
  342. pADO = new TADOQuery(NULL);
  343. pADO->Close();
  344. pADO->Connection = ITSDb_GetConnection();
  345. ITSDb_SQLText(pADO, sQry);
  346. ITSDb_SQLOpen(pADO);
  347. for( ; !pADO->Eof; pADO->Next())
  348. {
  349. String SYMB_FILE_NM = pADO->FieldByName("SYMBLIB_NMBR")->AsString;
  350. String SYMB_FILE_EXT = pADO->FieldByName("SYMB_IMAG_TYPE")->AsString;
  351. int IMAG_SIZE = pADO->FieldByName("IMAG_SIZE")->AsInteger;
  352. String ftpFileName = SYMB_FILE_NM + "." + SYMB_FILE_EXT;
  353. String strmFileName = g_sVideoDir + ftpFileName;
  354. if (!IsVmsFileExist(strmFileName, IMAG_SIZE))
  355. {
  356. VmsFtpFileDownload(ftpFileName, strmFileName);
  357. }
  358. }
  359. bRes = true;
  360. }
  361. catch(EDatabaseError &E)
  362. {
  363. DBERRORMSG("TFrmInitialize::DownloadVmsVideoFiles", String(E.ClassName()), E.Message, sQry);
  364. throw Exception(String(E.ClassName()) + E.Message);
  365. }
  366. catch(Exception &e)
  367. {
  368. DBERRORMSG("TFrmInitialize::DownloadVmsVideoFiles", String(e.ClassName()), e.Message, sQry);
  369. throw Exception(String(e.ClassName()) + e.Message);
  370. }
  371. }
  372. __finally
  373. {
  374. if (pADO)
  375. {
  376. pADO->Close();
  377. delete pADO;
  378. }
  379. VmsFtpDisconnect();
  380. }
  381. return bRes;
  382. }
  383. //---------------------------------------------------------------------------
  384. bool __fastcall TFrmInitialize::IsVmsFileExist(String fileName, int fileSize)
  385. {
  386. if (!FileExists(fileName))
  387. {
  388. return false;
  389. }
  390. int nFileSize = ITSUtil_GetFileSize(fileName);
  391. return nFileSize == fileSize;
  392. }
  393. //---------------------------------------------------------------------------