FrmInitializeF.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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 sErrMsg;
  240. bool bConnect = false;
  241. try
  242. {
  243. IdFtp->Connect();
  244. //IdFtp->ChangeDir("VIDEO");
  245. IdFtp->IOHandler->DefStringEncoding = TIdTextEncoding::UTF8;//IndyTextEncoding(949);
  246. bConnect = true;
  247. IdFtp->TransferType = ftBinary;
  248. }
  249. catch (EIdSocketError &exSock)
  250. {
  251. sErrMsg = exSock.Message;
  252. sErrMsg = StringReplace(sErrMsg, "\r\n", " ", TReplaceFlags() << rfReplaceAll);
  253. Application->MessageBox(sErrMsg.c_str(), FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  254. return false;
  255. }
  256. catch (Exception &e)
  257. {
  258. sErrMsg = e.Message;
  259. sErrMsg = StringReplace(sErrMsg, "\r\n", " ", TReplaceFlags() << rfReplaceAll);
  260. Application->MessageBox(sErrMsg.c_str(), FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  261. return false;
  262. }
  263. return bConnect;
  264. }
  265. //---------------------------------------------------------------------------
  266. bool __fastcall TFrmInitialize::VmsFtpFileDownload(String AOrgFile, String ADstFile)
  267. {
  268. String sErrMsg;
  269. try
  270. {
  271. IdFtp->TransferType = ftBinary;
  272. IdFtp->Get(AOrgFile, ADstFile, false);
  273. }
  274. catch (EIdSocketError &exSock)
  275. {
  276. sErrMsg = exSock.Message;
  277. sErrMsg = StringReplace(sErrMsg, "\r\n", " ", TReplaceFlags() << rfReplaceAll);
  278. Application->MessageBox(sErrMsg.c_str(), FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  279. return false;
  280. }
  281. catch (Exception &e)
  282. {
  283. sErrMsg = e.Message;
  284. sErrMsg = StringReplace(sErrMsg, "\r\n", " ", TReplaceFlags() << rfReplaceAll);
  285. Application->MessageBox(sErrMsg.c_str(), FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL);
  286. return false;
  287. }
  288. return true;
  289. }
  290. //---------------------------------------------------------------------------
  291. void __fastcall TFrmInitialize::VmsFtpDisconnect()
  292. {
  293. if (IdFtp->Connected())
  294. {
  295. IdFtp->Abort();
  296. IdFtp->Quit();
  297. IdFtp->Disconnect();
  298. }
  299. }
  300. //---------------------------------------------------------------------------
  301. bool __fastcall TFrmInitialize::DownloadVmsVideoFiles()
  302. {
  303. String sQry;
  304. TADOQuery *pADO = NULL;
  305. TItsCode *ftpCode = ItsCodeManager->FLists.Find("VMFTP");
  306. if (ftpCode != NULL) {
  307. TItsSubCode *pSubCode = ftpCode->FSubLists.Find("1");
  308. if (pSubCode != NULL) {
  309. g_AppCfg.vmsFtp.SERVER = pSubCode->CMMN_CD_KOR_NM.Trim();
  310. }
  311. pSubCode = ftpCode->FSubLists.Find("2");
  312. if (pSubCode != NULL) {
  313. g_AppCfg.vmsFtp.PORT = pSubCode->CMMN_CD_KOR_NM.Trim().ToIntDef(21);
  314. }
  315. pSubCode = ftpCode->FSubLists.Find("3");
  316. if (pSubCode != NULL) {
  317. g_AppCfg.vmsFtp.PASSIVE = pSubCode->CMMN_CD_KOR_NM.Trim() == "1" ? true : false;
  318. }
  319. pSubCode = ftpCode->FSubLists.Find("4");
  320. if (pSubCode != NULL) {
  321. g_AppCfg.vmsFtp.USER = pSubCode->CMMN_CD_KOR_NM.Trim();
  322. }
  323. pSubCode = ftpCode->FSubLists.Find("5");
  324. if (pSubCode != NULL) {
  325. g_AppCfg.vmsFtp.PSWD = pSubCode->CMMN_CD_KOR_NM.Trim();
  326. }
  327. }
  328. sQry = "SELECT SYMBLIB_NMBR, SYMB_FILE_NM, \r\n"
  329. " SYMB_IMAG_TYPE, IMAG_SIZE \r\n"
  330. " FROM TB_VMS_SYMB_LIB \r\n"
  331. " WHERE SYMBLIB_NMBR BETWEEN 5000 AND 5999 \r\n"
  332. " AND SYMB_TYPE = 'SBT3' \r\n"
  333. " AND DEL_YN = 'N' \r\n";
  334. ForceDirectories(g_sVideoDir.c_str());
  335. if (!VmsFtpConnect()) return false;
  336. bool bRes = false;
  337. try
  338. {
  339. try
  340. {
  341. pADO = new TADOQuery(NULL);
  342. pADO->Close();
  343. pADO->Connection = ITSDb_GetConnection();
  344. ITSDb_SQLText(pADO, sQry);
  345. ITSDb_SQLOpen(pADO);
  346. for( ; !pADO->Eof; pADO->Next())
  347. {
  348. String SYMB_FILE_NM = pADO->FieldByName("SYMBLIB_NMBR")->AsString;
  349. String SYMB_FILE_EXT = pADO->FieldByName("SYMB_IMAG_TYPE")->AsString;
  350. int IMAG_SIZE = pADO->FieldByName("IMAG_SIZE")->AsInteger;
  351. String ftpFileName = SYMB_FILE_NM + "." + SYMB_FILE_EXT;
  352. String strmFileName = g_sVideoDir + ftpFileName;
  353. if (!IsVmsFileExist(strmFileName, IMAG_SIZE))
  354. {
  355. VmsFtpFileDownload(ftpFileName, strmFileName);
  356. }
  357. }
  358. bRes = true;
  359. }
  360. catch(EDatabaseError &E)
  361. {
  362. DBERRORMSG("TFrmInitialize::DownloadVmsVideoFiles", String(E.ClassName()), E.Message, sQry);
  363. throw Exception(String(E.ClassName()) + E.Message);
  364. }
  365. catch(Exception &e)
  366. {
  367. DBERRORMSG("TFrmInitialize::DownloadVmsVideoFiles", String(e.ClassName()), e.Message, sQry);
  368. throw Exception(String(e.ClassName()) + e.Message);
  369. }
  370. }
  371. __finally
  372. {
  373. if (pADO)
  374. {
  375. pADO->Close();
  376. delete pADO;
  377. }
  378. VmsFtpDisconnect();
  379. }
  380. return bRes;
  381. }
  382. //---------------------------------------------------------------------------
  383. bool __fastcall TFrmInitialize::IsVmsFileExist(String fileName, int fileSize)
  384. {
  385. if (!FileExists(fileName))
  386. {
  387. return false;
  388. }
  389. int nFileSize = ITSUtil_GetFileSize(fileName);
  390. return nFileSize == fileSize;
  391. }
  392. //---------------------------------------------------------------------------