FrmCctvCtrlF.cpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "ITSSkinF.h"
  4. #include "ITSUtilF.h"
  5. #include "ITSLangTransF.h"
  6. #include "CDSProcessF.h"
  7. #include "CDSCctvCtlrF.h"
  8. #pragma hdrstop
  9. #include "FrmCctvCtrlF.h"
  10. //---------------------------------------------------------------------------
  11. #include "CTV0500MF.h"
  12. //---------------------------------------------------------------------------
  13. #ifndef ULONG_PTR
  14. #define ULONG_PTR unsigned long *
  15. #endif
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <list>
  19. #include <map>
  20. #define STRICT
  21. #include <windows.h>
  22. #include <algorithm>
  23. using std::min;
  24. using std::max;
  25. #include "gdiplus.h"
  26. #include "GdiplusBase.h" //항상 넣어 둔다.
  27. class CGdiPlusStarter
  28. {
  29. private:
  30. ULONG_PTR m_gpToken;
  31. public:
  32. bool m_bSuccess;
  33. CGdiPlusStarter()
  34. {
  35. ::CoInitialize(NULL);
  36. Gdiplus::GdiplusStartupInput gpsi;
  37. m_bSuccess = (Gdiplus::GdiplusStartup(&m_gpToken, &gpsi, NULL) == Gdiplus::Ok);
  38. }
  39. ~CGdiPlusStarter()
  40. {
  41. Gdiplus::GdiplusShutdown(m_gpToken);
  42. ::CoUninitialize();
  43. }
  44. };
  45. CGdiPlusStarter g_gps;
  46. //---------------------------------------------------------------------------
  47. #pragma package(smart_init)
  48. #pragma link "cxClasses"
  49. #pragma link "cxContainer"
  50. #pragma link "cxControls"
  51. #pragma link "cxEdit"
  52. #pragma link "cxGraphics"
  53. #pragma link "cxHint"
  54. #pragma link "cxLabel"
  55. #pragma link "cxLookAndFeelPainters"
  56. #pragma link "cxLookAndFeels"
  57. #pragma link "cxMaskEdit"
  58. #pragma link "cxPC"
  59. #pragma link "cxPCdxBarPopupMenu"
  60. #pragma link "cxSpinEdit"
  61. #pragma link "cxTextEdit"
  62. #pragma link "dxBar"
  63. #pragma link "dxCustomHint"
  64. #pragma link "dxRibbon"
  65. #pragma link "dxRibbonGallery"
  66. #pragma link "dxRibbonSkins"
  67. #pragma link "dxRibbonStatusBar"
  68. #pragma link "dxScreenTip"
  69. #pragma link "dxSkinBlack"
  70. #pragma link "dxSkinBlue"
  71. #pragma link "dxSkinCaramel"
  72. #pragma link "dxSkinChooserGallery"
  73. #pragma link "dxSkinCoffee"
  74. #pragma link "dxSkinDarkRoom"
  75. #pragma link "dxSkinDarkSide"
  76. #pragma link "dxSkinFoggy"
  77. #pragma link "dxSkinGlassOceans"
  78. #pragma link "dxSkiniMaginary"
  79. #pragma link "dxSkinLilian"
  80. #pragma link "dxSkinLiquidSky"
  81. #pragma link "dxSkinLondonLiquidSky"
  82. #pragma link "dxSkinMcSkin"
  83. #pragma link "dxSkinMoneyTwins"
  84. #pragma link "dxSkinOffice2007Black"
  85. #pragma link "dxSkinOffice2007Blue"
  86. #pragma link "dxSkinOffice2007Green"
  87. #pragma link "dxSkinOffice2007Pink"
  88. #pragma link "dxSkinOffice2007Silver"
  89. #pragma link "dxSkinOffice2010Black"
  90. #pragma link "dxSkinOffice2010Blue"
  91. #pragma link "dxSkinOffice2010Silver"
  92. #pragma link "dxSkinsCore"
  93. #pragma link "dxSkinscxPCPainter"
  94. #pragma link "dxSkinsdxBarPainter"
  95. #pragma link "dxSkinsdxRibbonPainter"
  96. #pragma link "dxSkinSeven"
  97. #pragma link "dxSkinsForm"
  98. #pragma link "dxSkinSharp"
  99. #pragma link "dxSkinSilver"
  100. #pragma link "dxSkinStardust"
  101. #pragma link "dxStatusBar"
  102. #pragma link "dxTabbedMDI"
  103. #pragma link "IdAntiFreeze"
  104. #pragma link "IdAntiFreezeBase"
  105. #pragma link "IdBaseComponent"
  106. #pragma link "cxButtons"
  107. #pragma link "cxGroupBox"
  108. #pragma link "ImageBtn"
  109. #pragma link "XNSSDKDEVICELib_OCX"
  110. #pragma link "XNSSDKWINDOWLib_OCX"
  111. #pragma resource "*.dfm"
  112. TFrmCctvCtrl *FrmCctvCtrl = NULL;
  113. //---------------------------------------------------------------------------
  114. __fastcall TFrmCctvCtrl::TFrmCctvCtrl(TComponent* Owner)
  115. : TForm(Owner)//TdxCustomRibbonForm(Owner)//TForm(Owner)
  116. {
  117. //DoubleBuffered = true;
  118. g_AppCfg.lMainWinHandle = (long)Handle;
  119. #if 0
  120. StartJobThread();
  121. while(!PostJobMessage(WM_THREAD, WP_PING)) ;
  122. #endif
  123. Application->OnException = OnAppException;
  124. ::CoInitialize(NULL);
  125. LangTrans->Translate(this, ITSDb_GetConnection());
  126. ITSSkin_Initialize(Application, g_AppCfg.sLang, true, true);
  127. ITSSkin_Load(this);
  128. CMM_LoadForm(g_sFormsDir, this);
  129. #if 0
  130. String sCaption = "";
  131. ReadConfigInfo(g_AppCfg.sConfigFile, "APPLICATION", "CAPTION", sCaption);
  132. ITSSkin_Caption(sCaption == "1" ? true : false);
  133. #endif
  134. SetColorScheme(g_AppCfg.sSkinName);
  135. FCctvServerState = cctv_normal;
  136. ItsProcessManager = new TItsProcessManager();
  137. CctvCtlrManager = new TCctvCtlrManager();
  138. TmrOnShow->Enabled = false;
  139. TmrAppState->Enabled = false;
  140. }
  141. //---------------------------------------------------------------------------
  142. void __fastcall TFrmCctvCtrl::FormCreate(TObject *Sender)
  143. {
  144. /* 레지스터리 등록 IE 최신버전 */
  145. String sExeName = ExtractFileName(Application->ExeName);
  146. UpdateExplorerEmulatorVersion(sExeName);
  147. Application->ShowMainForm = false;
  148. try {
  149. Application->Icon->LoadFromResourceName(((unsigned int)HInstance), "MAINICON");
  150. } catch(...) { ShowMessage("LoadFromResourceName failed"); }
  151. //DeleteLogFiles((PTCHAR)g_sLogDir.c_str(), 30, (PTCHAR)"*.*");
  152. //WindowState = wsMaximized;
  153. // 종료조건이 있는경우..
  154. //Application->Terminate();
  155. //return;
  156. ItsProcessManager->LoadFromDb();
  157. CctvCtlrManager->LoadFromDb();
  158. CctvCtlrManager->LoadStatusFromDb();
  159. CTV0500M = new TCTV0500M(PnlBack);
  160. CTV0500M->FTmrShow = false;;
  161. CTV0500M->Parent = PnlBack;
  162. CTV0500M->Show();
  163. Application->ShowMainForm = true;
  164. Application->OnHint = OnAppHint;
  165. }
  166. //---------------------------------------------------------------------------
  167. bool __fastcall TFrmCctvCtrl::UpdateExplorerEmulatorVersion(String AAppName)
  168. {
  169. TRegistry *reg = new TRegistry(KEY_READ|KEY_WRITE|KEY_WOW64_64KEY);
  170. if (reg == NULL) return false;
  171. String sKey = "SOFTWARE\\Wow6432Node\\Microsoft\\Internet Explorer\\MAIN\\FeatureControl\\FEATURE_BROWSER_EMULATION";
  172. reg->RootKey = HKEY_LOCAL_MACHINE;
  173. if (!reg->KeyExists(sKey))
  174. {
  175. //MessageDlg("Key not found! Created now.", mtInformation, TMsgDlgButtons() << mbOK, 0);
  176. bool bOpenKey = reg->CreateKey(sKey);
  177. //return false;
  178. }
  179. reg->Access = KEY_WRITE;
  180. bool openResult = reg->OpenKey(sKey, true);
  181. if(!openResult)
  182. {
  183. //MessageDlg("Unable to create key! Exiting.", mtError, TMsgDlgButtons() << mbOK, 0);
  184. return false;
  185. }
  186. if (!reg->KeyExists(AAppName))
  187. {
  188. reg->WriteInteger(AAppName, 10000);
  189. }
  190. reg->CloseKey();
  191. reg->Free();
  192. return true;
  193. }
  194. //---------------------------------------------------------------------------
  195. /*
  196. * Form을 보여줄때 호출되는 event 메서드이다.
  197. * arguments
  198. * Sender : event handler 객체
  199. * return
  200. * void
  201. */
  202. void __fastcall TFrmCctvCtrl::FormShow(TObject *Sender)
  203. {
  204. Refresh();
  205. Application->ProcessMessages();
  206. g_AppCfg.lMainWinHandle = (long)Handle;
  207. if (g_pLOGIN)
  208. {
  209. GetUserMenuRight(g_pLOGIN->sUserId, g_pLOGIN->sUserRightId);
  210. }
  211. TmrOnShow->Enabled = true;
  212. }
  213. //---------------------------------------------------------------------------
  214. /*
  215. * 프로그램 기동후 최초에 수행된다.
  216. * arguments
  217. *
  218. * return
  219. * void
  220. */
  221. void __fastcall TFrmCctvCtrl::TmrOnShowTimer(TObject *Sender)
  222. {
  223. Refresh();
  224. TmrOnShow->Enabled = false;
  225. Application->ProcessMessages();
  226. CTV0500M->TmrShow->Enabled = true;
  227. UpdateCctvCommStatus(true);
  228. int nPort = 4602;
  229. TItsProcess *pPrcs = ItsProcessManager->FLists.Find(g_AppCfg.sProcessId);
  230. if (!pPrcs)
  231. {
  232. if (g_AppCfg.sLang == "kr")
  233. {
  234. Application->MessageBox(L"통신프로세스를 초기화 하지 못하였습니다.\r\n환경설정에서 시스템ID를 확인하세요.\r\n프로그램을 종료합니다.",
  235. L"프로그램 통신오류_1", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  236. }
  237. else
  238. {
  239. Application->MessageBox(L"Failed to initialize communication process.\r\nPlease check your system ID in preferences.\r\nExit the program.",
  240. L"Program communication error_1", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  241. }
  242. g_AppCfg.bAppClose = true;
  243. Close();
  244. return;
  245. }
  246. nPort = pPrcs->PRGM_PORT.ToIntDef(4602);
  247. nPort += 1; //VMS운영단말은 DB에 저장되어 있지 않기 때문에 포트번호를 1 증가시켜 통신한다.
  248. int nResult = CComm_Initialize((long)Handle, g_AppCfg.sProcessId, "UOT", nPort, g_AppCfg.sLogDay);
  249. if (VERR_NONE != nResult)
  250. {
  251. if (g_AppCfg.sLang == "kr")
  252. {
  253. Application->MessageBox(L"통신프로세스를 초기화 하지 못하였습니다.\r\n환경설정에서 시스템ID를 확인하세요.\r\n프로그램을 종료합니다.",
  254. L"프로그램 통신오류_1", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  255. }
  256. else
  257. {
  258. Application->MessageBox(L"Failed to initialize communication process.\r\nPlease check your system ID in preferences.\r\nExit the program.",
  259. L"Program communication error_1", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  260. }
  261. g_AppCfg.bAppClose = true;
  262. Close();
  263. return;
  264. }
  265. FOR_STL(TItsProcess*, pObj, ItsProcessManager->FLists)
  266. {
  267. if (pObj->DEL_YN == "Y") continue;
  268. AnsiString sProcessId = AnsiString(pObj->SYST_ID);
  269. AnsiString sSystemTp = AnsiString(pObj->SYST_TYPE);
  270. AnsiString sIpAddress = AnsiString(pObj->SYST_IP_1);
  271. AnsiString sUdpPort = AnsiString(pObj->PRGM_PORT);
  272. if (CComm_AddProcess(sProcessId, sSystemTp, sIpAddress, sUdpPort) >= 0)
  273. {
  274. if ("UOT" == sSystemTp)
  275. {
  276. nPort = sUdpPort.ToIntDef(0);
  277. CComm_AddProcess(sProcessId, sSystemTp, sIpAddress, AnsiString(nPort+2));
  278. }
  279. }
  280. }
  281. if (VERR_NONE != CComm_Open())
  282. {
  283. if (g_AppCfg.sLang == "kr")
  284. {
  285. Application->MessageBox(L"통신프로세스를 초기화 하지 못하였습니다.\r\n환경설정에서 시스템ID를 확인하세요.\r\n프로그램을 종료합니다.",
  286. L"프로그램 통신오류_3", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  287. }
  288. else
  289. {
  290. Application->MessageBox(L"Failed to initialize communication process.\r\nPlease check your system ID in preferences.\r\nExit the program.",
  291. L"Program communication error_3", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  292. }
  293. g_AppCfg.bAppClose = true;
  294. Close();
  295. return;
  296. }
  297. UpdateInterCommStatus(true);
  298. Application->ProcessMessages();
  299. #if 0
  300. if (g_AppCfg.AutoLogout.LogoutExit)
  301. {
  302. Application->MessageBox(L"이전 프로그램은 자동로그아웃으로 종료되었습니다.\r\n프로그램을 실행합니다.",
  303. L"프로그램 실행정보", MB_OK|MB_ICONQUESTION|MB_APPLMODAL);
  304. }
  305. #endif
  306. g_AppCfg.AutoLogout.LogoutExit = false;
  307. TmrAppState->Enabled = true;
  308. TmrPolling->Enabled = true;
  309. TmrCommTimeout->Enabled = true;
  310. INT_VMS_STATE_REQ Req;
  311. memset((char*)&Req, 0x00, sizeof(Req));
  312. Req.Count = 0;
  313. Req.Type = vms_state_all;
  314. CComm_VmsStateReq(&Req);
  315. }
  316. //---------------------------------------------------------------------------
  317. bool __fastcall TFrmCctvCtrl::StartJobThread()
  318. {
  319. #if 0
  320. TThreadPolling *pPollingThread = new TThreadPolling(false);
  321. if (pPollingThread)
  322. {
  323. pPollingThread->OnTerminate = OnPollingThreadDone;
  324. g_AppCfg.thr.pThread = (TThread *)pPollingThread;
  325. g_AppCfg.thr.dwThreadId = pPollingThread->ThreadID;
  326. g_AppCfg.thr.nHandle = pPollingThread->Handle;
  327. //pPollingThread->Resume();
  328. return true;
  329. }
  330. #endif
  331. return false;
  332. }
  333. //---------------------------------------------------------------------------
  334. void __fastcall TFrmCctvCtrl::TerminateJobThread()
  335. {
  336. #if 0
  337. if (g_AppCfg.thr.bRunning)
  338. {
  339. PostJobMessage(WM_THREAD, WM_QUIT);
  340. }
  341. Sleep(500);
  342. try
  343. {
  344. if (g_AppCfg.thr.bRunning)
  345. {
  346. TThreadPolling *pThread = (TThreadPolling *)g_AppCfg.thr.pThread;
  347. pThread->Terminate();
  348. //pThread->WaitFor();
  349. }
  350. g_AppCfg.thr.pThread = NULL;
  351. g_AppCfg.thr.dwThreadId = 0;
  352. g_AppCfg.thr.nHandle = 0;
  353. g_AppCfg.thr.bRunning = false;
  354. }
  355. catch(...)
  356. {
  357. }
  358. #endif
  359. }
  360. //---------------------------------------------------------------------------
  361. void __fastcall TFrmCctvCtrl::FormClose(TObject *Sender, TCloseAction &Action)
  362. {
  363. CommClose();
  364. Action = caFree;
  365. }
  366. //---------------------------------------------------------------------------
  367. void __fastcall TFrmCctvCtrl::CommClose()
  368. {
  369. try
  370. {
  371. CComm_Close();
  372. ITSSkin_Term();
  373. CMM_SaveForm(g_sFormsDir, this);
  374. ::CoUninitialize();
  375. }
  376. catch(...)
  377. {
  378. }
  379. }
  380. //---------------------------------------------------------------------------
  381. void __fastcall TFrmCctvCtrl::TmrAppStateTimer(TObject *Sender)
  382. {
  383. /*
  384. * 타이머가 1초간격으로 응용프로그램의 상태를 체크하고
  385. * 응용프로그램의 상태를 주기적으로 체크하여 필요한 조치를 수행한다.
  386. */
  387. if (g_AppCfg.bAppClose)
  388. {
  389. TmrAppState->Enabled = false;
  390. TmrPolling->Enabled = false;
  391. UserLogout(); // 로그아웃
  392. TerminateJobThread();
  393. ITSDb_Close();
  394. Close(); // 응용프로그램 종료
  395. }
  396. else
  397. {
  398. TmrAppState->Enabled = false;
  399. TmrAppState->Enabled = true;
  400. }
  401. }
  402. //---------------------------------------------------------------------------
  403. void __fastcall TFrmCctvCtrl::UpdateInterCommStatus(bool AOk)
  404. {
  405. int nImgIdx = 8;
  406. if (AOk == false) nImgIdx = 7;
  407. }
  408. //---------------------------------------------------------------------------
  409. void __fastcall TFrmCctvCtrl::UpdateCctvCommStatus(bool ADb)
  410. {
  411. if (ADb)
  412. {
  413. FOR_STL(TItsProcess*, pPrcs, ItsProcessManager->FLists)
  414. {
  415. if (pPrcs->SYST_TYPE == "VMS")
  416. {
  417. if (pPrcs->FCommStatus == "1")
  418. {
  419. FCctvServerState = cctv_normal;
  420. }
  421. else
  422. {
  423. FCctvServerState = cctv_error;
  424. }
  425. break;
  426. }
  427. }
  428. }
  429. int nImgIdx = 8;
  430. if (FCctvServerState == cctv_error) nImgIdx = 7;
  431. }
  432. //---------------------------------------------------------------------------
  433. bool __fastcall TFrmCctvCtrl::GetUserMenuRight(String AUserId, String AUserRight)
  434. {
  435. #if 0
  436. String sQry;
  437. TADOQuery *pADO = NULL;
  438. try
  439. {
  440. sQry = "SELECT OPERSYST_MENU_ID \r\n"
  441. " FROM TB_USER_GROP_MENU_ATHR \r\n"
  442. " WHERE ATHR_YN = 'N' \r\n"
  443. " AND GROP_ID = (SELECT GROP_ID \r\n"
  444. " FROM TB_USER_INFR \r\n"
  445. " WHERE USER_ID = :p01) \r\n";
  446. try
  447. {
  448. pADO = new TADOQuery(NULL);
  449. pADO->Close();
  450. pADO->Connection = ITSDb_GetConnection();
  451. ITSDb_SQLText(pADO, sQry);
  452. ITSDb_SQLBind(pADO, "p01", AUserId);
  453. ITSDb_SQLOpen(pADO);
  454. for( ; !pADO->Eof; pADO->Next())
  455. {
  456. String sMenuId = pADO->FieldByName("OPERSYST_MENU_ID")->AsString;
  457. try
  458. {
  459. int nCompnentCnt = this->ComponentCount;
  460. for (int ii = 0; ii < nCompnentCnt; ii++)
  461. {
  462. String sClassName = this->Components[ii]->ClassName();
  463. if(sClassName == "TdxBarLargeButton")
  464. {
  465. TdxBarLargeButton *pMenu = (TdxBarLargeButton *)this->Components[ii];
  466. if (pMenu->Name == sMenuId)
  467. {
  468. pMenu->Enabled = false;
  469. break;
  470. }
  471. }
  472. }
  473. }
  474. catch(...)
  475. {
  476. }
  477. }
  478. }
  479. catch(EDatabaseError &E)
  480. {
  481. DBERRORLOG("TFrmCctvCtrl::GetUserMenuRight", String(E.ClassName()), E.Message, sQry);
  482. throw Exception(String(E.ClassName()) + E.Message);
  483. }
  484. catch(Exception &e)
  485. {
  486. DBERRORLOG("TFrmCctvCtrl::GetUserMenuRight", String(e.ClassName()), e.Message, sQry);
  487. throw Exception(String(e.ClassName()) + e.Message);
  488. }
  489. }
  490. __finally
  491. {
  492. if (pADO)
  493. {
  494. pADO->Close();
  495. delete pADO;
  496. }
  497. }
  498. #endif
  499. return true;
  500. }
  501. //---------------------------------------------------------------------------
  502. void __fastcall TFrmCctvCtrl::TmrPollingTimer(TObject *Sender)
  503. {
  504. TmrPolling->Enabled = false;
  505. DWORD dwTick = GetTickCount();
  506. if (!g_AppCfg.bAppClose) TmrPolling->Enabled = true;
  507. }
  508. //---------------------------------------------------------------------------
  509. /*
  510. * 작업스레드로 작업 메시지를 전송한다.
  511. * arguments
  512. *
  513. * return
  514. * void
  515. */
  516. bool __fastcall TFrmCctvCtrl::PostJobMessage(UINT nMsg, int WParam/*=0*/, int LParam/*=0*/)
  517. {
  518. int nRes;
  519. //if (g_AppCfg.bDebug) ITSUtil_Trace("PostJobMessage: Msg: %02X, WParam: %02X, LParam: %02X", nMsg, WParam, LParam);
  520. if (g_AppCfg.thr.dwThreadId)
  521. {
  522. for (int ii = 0; ii < 3; ii++)
  523. {
  524. if (PostThreadMessageW(g_AppCfg.thr.dwThreadId, nMsg, WParam, LParam))
  525. {
  526. nRes = 0;
  527. return true;
  528. }
  529. else
  530. {
  531. nRes = GetLastError();
  532. if (ERROR_INVALID_THREAD_ID == nRes)
  533. {
  534. Sleep(500);
  535. continue;
  536. }
  537. }
  538. }
  539. }
  540. return false;
  541. }
  542. //---------------------------------------------------------------------------
  543. void __fastcall TFrmCctvCtrl::SetColorScheme(String ASkinName)
  544. {
  545. dxSkinController1->SkinName = ASkinName;
  546. dxSkinController1->Refresh();
  547. }
  548. //---------------------------------------------------------------------------
  549. void __fastcall TFrmCctvCtrl::TermItsProgram(String AClassName, String AExeName)
  550. {
  551. HWND hExeForm = FindWindow(AClassName.c_str(), NULL);
  552. if (hExeForm)
  553. {
  554. POST_MSG(hExeForm, WM_CLOSE, 0, 0);
  555. }
  556. }
  557. //---------------------------------------------------------------------------
  558. void __fastcall TFrmCctvCtrl::OnAppHint(TObject *Sender)
  559. {
  560. }
  561. //---------------------------------------------------------------------------
  562. void __fastcall TFrmCctvCtrl::OnAppException(TObject *Sender, Exception *exception)
  563. {
  564. if (g_AppCfg.bDebug) ITSUtil_Trace("OnAppException");
  565. String sClassName = (NULL != Sender) ? Sender->ClassName() : String("Unknown_Class");
  566. String sErrMsg = (NULL != exception) ? exception->Message : String("Unknown_Error");
  567. String sError = sClassName + " : " + sErrMsg;
  568. //Application->ShowException(&exception);
  569. Application->NormalizeTopMosts();
  570. Application->MessageBox(sError.c_str(), L"System Error", MB_OK|MB_ICONERROR|MB_APPLMODAL);
  571. Application->RestoreTopMosts();
  572. }
  573. //---------------------------------------------------------------------------
  574. void __fastcall TFrmCctvCtrl::ApplicationEvents1Message(tagMSG &Msg, bool &Handled)
  575. {
  576. switch(Msg.message)
  577. {
  578. case WM_THREAD:
  579. switch(Msg.wParam)
  580. {
  581. case WP_PING:
  582. break;
  583. case WP_PARAM_TRAFFIC:
  584. break;
  585. case WP_DB_SELECT_START:
  586. break;
  587. case WP_DB_SELECT_OK:
  588. case WP_DB_SELECT_ERROR:
  589. case WP_DB_SELECT_CANCEL:
  590. if (Msg.wParam == WP_DB_SELECT_OK)
  591. {
  592. OnRefreshMessage(Msg.wParam, Msg.lParam);
  593. }
  594. break;
  595. }
  596. break;
  597. case WM_DATABASE_REFRESH:
  598. OnDatabaseMessage(Msg.wParam, Msg.lParam);
  599. break;
  600. case WM_PLUGINFORM:
  601. OnRefreshMessage(Msg.wParam, Msg.lParam);
  602. break;
  603. case WM_MOUSEMOVE:
  604. case WM_KEYDOWN:
  605. case WM_KEYUP:
  606. break;
  607. }
  608. }
  609. //---------------------------------------------------------------------------
  610. void __fastcall TFrmCctvCtrl::OnRefreshMessage(WPARAM AWParam, LPARAM ALParam)
  611. {
  612. #if 0
  613. HWND hWnd;
  614. if (AWParam == WP_DB_SELECT_OK)
  615. {
  616. DWORD dwTick = GetTickCount();
  617. #if 0
  618. switch(ALParam)
  619. {
  620. case LP_MSG_00: DebugMsg("<<< Process Status Request Completed."/*"<<< 프로세스 상태 조회 완료"*/); FPollPrcsState.Polling = dwTick; break;
  621. case LP_MSG_01: DebugMsg("<<< VMS Status Request Completed."/*"<<< VMS 상태 조회 완료"*/); FPollVmsState.Polling = dwTick; break;
  622. case LP_MSG_02: DebugMsg("<<< VMS Display Message Request Completed."/*"<<< VMS 표출메시지 조회 완료"*/); FPollVmsMsg.Polling = dwTick; break;
  623. case LP_MSG_03: DebugMsg("<<< Traffic Request Completed."/*"<<< 소통정보 조회 완료"*/); FPollTraffic.Polling = dwTick; break;
  624. case LP_MSG_05: DebugMsg("<<< Incident Request Completed."/*"<<< 돌발정보 조회 완료"*/); FPollIncident.Polling = dwTick; break;
  625. }
  626. #endif
  627. if (ALParam == LP_MSG_00)
  628. {
  629. UpdateCctvCommStatus(true);
  630. }
  631. else
  632. if (ALParam == LP_MSG_02)
  633. {
  634. //RefreshVmsMessage(WM_VMS_FORM_REFRESH);
  635. }
  636. else
  637. if (ALParam == LP_MSG_05)
  638. {
  639. //RefreshVmsMessage(WM_VMS_INCIDENT_REFRESH);
  640. }
  641. else
  642. {
  643. //RefreshVmsMessage(WM_VMS_STATE_REFRESH);
  644. }
  645. }
  646. else
  647. {
  648. LOGERROR("DB Thread failed: %02X[%02X]", ALParam, AWParam);
  649. }
  650. #endif
  651. }
  652. //---------------------------------------------------------------------------
  653. void __fastcall TFrmCctvCtrl::OnDatabaseMessage(WPARAM AWParam, LPARAM ALParam)
  654. {
  655. }
  656. //---------------------------------------------------------------------------
  657. void __fastcall TFrmCctvCtrl::OnUdpDataRecvMessage(TMessage &Msg)
  658. {
  659. #if 0
  660. int nResult;
  661. IPCUDPMESSAGESTRUCT *RcvData = (IPCUDPMESSAGESTRUCT*)Msg.LParam;
  662. INT_SENDER *Sender = &RcvData->Sender;
  663. INT_PACKET *Pkt = &RcvData->Pkt;
  664. INT_HEAD *head = &Pkt->head;
  665. INT_DATA *data = &Pkt->data;
  666. char *pData = &data->Data[2];
  667. BYTE OpCode = (BYTE)data->Data[0];
  668. LOGINFO("*** OPR Client Req: %s.%d", CComm_ulong2ip(Sender->IP), Sender->Port);
  669. String sMsg = "";
  670. String sVmsNmbr = "";
  671. TmrCommTimeout->Enabled = false;
  672. //FCctvServerState = cctv_normal;
  673. UpdateCctvCommStatus(false);
  674. UpdateInterCommStatus(true);
  675. if (head->OPCode == INT_OP_COMM_COMMON)
  676. {
  677. switch(OpCode)
  678. {
  679. case INT_OP_PG_STATE_RES:
  680. {
  681. //DebugMsg("*** VMS Process Stauts Recvieved");//"*** VMS 프로세스 상태정보 수신");
  682. INT_PG_STATE_RES *ARes = (INT_PG_STATE_RES*)pData;
  683. for (int ii = 0; ii < ARes->Count && ii < INT_MAX_PG_STATE; ii++)
  684. {
  685. if (ARes->Unit[ii].Type == INT_ID_VMS_SERVER)
  686. {
  687. FCctvServerState = ARes->Unit[ii].Action;
  688. UpdateCctvCommStatus(false);
  689. FPollPrcsState.Polling = GetTickCount(); //프로세스상태정보 조회 타이머 리셋
  690. break;
  691. }
  692. }
  693. }
  694. break;
  695. case INT_OP_VMS_PARAM_RES:
  696. {
  697. INT_VMS_PARAM_RES *ARes = (INT_VMS_PARAM_RES*)pData;
  698. sMsg = "";
  699. sMsg.printf(L"*** VMS Controller Parameter Received: %d EA", ARes->Count);
  700. //DebugMsg(sMsg);
  701. for (int ii = 0; ii < ARes->Count && ii < INT_MAX_VMS_PARAM; ii++)
  702. {
  703. INT_VMS_PARAM *pVms = &ARes->Unit[ii];
  704. TVmsCtlr *pObj = VmsManager->FLists.Find(String(pVms->VMS_CTLR_NMBR));
  705. if (pObj)
  706. {
  707. pObj->PANL_PWER_MODE = pVms->led; // N NUMBER(3) Y 2 전광판 전원 모드(0x00:꺼짐,0x01:켜짐,0x02:자동,0x09:알수없음)
  708. pObj->FAN_MODE = pVms->fan; // N NUMBER(3) Y 2 FAN 동작모드(0x00:꺼짐,0x01:켜짐,0x02:자동,0x09:알수없음)
  709. pObj->FAN_RUN_TMPR = pVms->fanTmpr; // N NUMBER(3) Y 30 팬 동작 온도
  710. pObj->HETR_MODE = pVms->hetr; // N NUMBER(3) Y 2 히터 동작모드(0x00:꺼짐,0x01:켜짐,0x02:자동,0x09:알수없음)
  711. pObj->HETR_RUN_TMPR = pVms->hetrTmpr; // N NUMBER(3) Y 0 히터 동작 온도
  712. pObj->BRGH_MODE = pVms->brgh; // N NUMBER(3) Y 2 휘도 모드(0x00:주간,0x01:야간,0x00:자동,0x09:알수없음)
  713. pObj->BRGH_CURR_STEP = pVms->brghVal; // N NUMBER(3) Y 40 휘도 현재 단계(0~100)
  714. pObj->BRGH_WEEK_STEP = pVms->brghDay; // N NUMBER(3) Y 64 휘도 주간 단계(0~100)
  715. pObj->BRGH_NGHT_STEP = pVms->brghNight; // N NUMBER(3) Y 48 휘도 야간 단계(0~100)
  716. pObj->ParamResTime.printf(L"%s", pVms->time);
  717. }
  718. else
  719. {
  720. sMsg.printf(L"INT_OP_VMS_PARAM_RES VMS not found: %s", String(pVms->VMS_CTLR_NMBR).c_str());
  721. //DebugMsg(sMsg);
  722. }
  723. }
  724. }
  725. break;
  726. case INT_OP_VMS_STATE_RES:
  727. {
  728. char szVmsNmbr[INT_VMS_MAX_ID+1];
  729. INT_VMS_STATE_RES *ARes = (INT_VMS_STATE_RES*)pData;
  730. sMsg = "";
  731. //sMsg.printf(L"*** VMS 제어기 상태정보 수신: %d EA", ARes->Count);
  732. sMsg.printf(L"*** VMS Controller Status Received: %d EA", ARes->Count);
  733. //DebugMsg(sMsg);
  734. for (int ii = 0; ii < ARes->Count && ii < INT_MAX_VMS_STATE; ii++)
  735. {
  736. sMsg = "";
  737. INT_VMS_STATE *pVms = &ARes->Unit[ii];
  738. sVmsNmbr = String(pVms->VMS_CTLR_NMBR);
  739. TVmsCtlr *pObj = VmsManager->FLists.Find(sVmsNmbr);
  740. if (pObj)
  741. {
  742. VmsStatusCopy(&pObj->WSTATE, pVms);
  743. if (pObj->WSTATE.OprMode == 'A') pObj->OPER_MODE = "A";
  744. else if (pObj->WSTATE.OprMode == 'B') pObj->OPER_MODE = "B";
  745. else pObj->OPER_MODE = "F";
  746. //pObj->VMS_PHSE_CHNG_CYCL = pObj->WSTATE.ScheduledMessageOperatingTime;
  747. #if 0
  748. pObj->VMS_CMNC_ERR_BASS_VAL = pObj->WSTATE.ModuleOperatingTemperature;
  749. pObj->FAN_MTNS_TMPR = pObj->WSTATE.FanOperatingTemperature;
  750. pObj->HETR_MTNS_TMPR = pObj->WSTATE.HeaterOperatingTemperature;
  751. pObj->VMS_MODL_ERR_RATE = pObj->WSTATE.ModuleBasicFailureRate;
  752. pObj->CheckRunState();
  753. #endif
  754. if (pObj->WSTATE.Comm != vms_normal)
  755. {
  756. pObj->VmsMsg->OFFER_YN = false;
  757. }
  758. }
  759. else
  760. {
  761. sMsg.printf(L"INT_OP_VMS_STATE_RES VMS not found: %s", sVmsNmbr.c_str());
  762. //DebugMsg(sMsg);
  763. }
  764. }
  765. //RefreshVmsMessage(WM_VMS_STATE_REFRESH);
  766. FPollVmsState.Polling = GetTickCount();
  767. }
  768. break;
  769. case INT_OP_VMS_FORM_SAVE:
  770. {
  771. FPollVmsMsg.Reset(); //VMS메시지 조회 타이머 리셋
  772. char szDateTime[INT_VMS_MAX_DATETIME+1];
  773. INT_VMS_FORM_SAVE_REQ *AReq = (INT_VMS_FORM_SAVE_REQ*)pData;
  774. sprintf(szDateTime, "%.*s", INT_VMS_MAX_DATETIME, (char*)AReq->Date);
  775. String sDateTime = String(szDateTime);
  776. sMsg = "";
  777. //sMsg.printf(L"*** VMS 폼생성 완료 메시지 수신: %s", sDateTime.c_str());
  778. sMsg.printf(L"*** VMS Form Create Message Received: %s", sDateTime.c_str());
  779. //DebugMsg(sMsg);
  780. }
  781. break;
  782. case INT_OP_VMS_FORM_DOWNLOAD:
  783. {
  784. char szDateTime[INT_VMS_MAX_DATETIME+1];
  785. char szVmsNmbr[INT_VMS_MAX_ID+1];
  786. INT_VMS_FORM_DOWNLOAD_REQ *AReq = (INT_VMS_FORM_DOWNLOAD_REQ*)pData;
  787. //sMsg.printf(L"*** VMS 폼 다운로드 메시지 수신: %d EA", AReq->Count);
  788. sMsg.printf(L"*** VMS Form Download Recieved: %d EA", AReq->Count);
  789. //DebugMsg(sMsg);
  790. for (int ii = 0; ii < AReq->Count && ii < INT_MAX_VMS_FORM_DOWNLOAD; ii++)
  791. {
  792. sMsg = "";
  793. INT_VMS_FORM_DOWNLOAD *pVms = &AReq->Unit[ii];
  794. sprintf(szVmsNmbr, "%.*s", INT_VMS_MAX_ID, (char*)pVms->VmsId);
  795. sprintf(szDateTime, "%.*s", INT_VMS_MAX_DATETIME, (char*)pVms->Date);
  796. sVmsNmbr = String(szVmsNmbr);
  797. String sDateTime = String(szDateTime);
  798. TVmsCtlr *pObj = VmsManager->FLists.Find(sVmsNmbr);
  799. if (pObj)
  800. {
  801. bool bDnLd = (pVms->Result == vms_download_succ) ? true : false;
  802. String sResult = bDnLd ? "Succ" : "Fail";
  803. pObj->VmsMsg->OFFER_DT = sDateTime;
  804. pObj->VmsMsg->OFFER_YN = bDnLd;
  805. for (int kk = 0; kk < pObj->VmsMsg->Total && kk < INT_MAX_VMS_FORM; kk++)
  806. {
  807. pObj->VmsMsg->PHASE[kk].DNLD_YN = bDnLd ? "Y" : "N";
  808. }
  809. //sMsg.printf(L"*** ===> VMS Msg download: %s, %s", pObj->VMS_CTLR_ID.c_str(), sResult.c_str());
  810. //DebugMsg(sMsg);
  811. }
  812. else
  813. {
  814. sMsg.printf(L"*** INT_OP_VMS_FORM_DOWNLOAD VMS not found: %s", sVmsNmbr.c_str());
  815. //DebugMsg(sMsg);
  816. }
  817. }
  818. //RefreshVmsMessage(WM_VMS_STATE_REFRESH);
  819. //RefreshVmsMessage(WM_VMS_FORM_REFRESH);
  820. }
  821. break;
  822. }
  823. }
  824. TmrCommTimeout->Enabled = true;
  825. #endif
  826. }
  827. //---------------------------------------------------------------------------
  828. void __fastcall TFrmCctvCtrl::RefreshCctvMessage(int AMsg, WPARAM AWParam/*=0*/, LPARAM ALParam/*=0*/)
  829. {
  830. }
  831. //---------------------------------------------------------------------------
  832. void __fastcall TFrmCctvCtrl::OnPollingThreadDone(TObject *Sender)
  833. {
  834. LOGINFO("*** Polling thead terminated ***");
  835. g_AppCfg.thr.bRunning = false;
  836. }
  837. //---------------------------------------------------------------------------
  838. void __fastcall TFrmCctvCtrl::TmrCommTimeoutTimer(TObject *Sender)
  839. {
  840. //통신타임아웃
  841. TmrCommTimeout->Enabled = false;
  842. UpdateInterCommStatus(false);
  843. FCctvServerState = cctv_error;
  844. UpdateCctvCommStatus(false);
  845. LOGINFO("xxx CCTV Communication Time out xxx");
  846. }
  847. //---------------------------------------------------------------------------
  848. void __fastcall TFrmCctvCtrl::ApplicationEvents1Restore(TObject *Sender)
  849. {
  850. //화면 재생
  851. }
  852. //---------------------------------------------------------------------------
  853. void __fastcall TFrmCctvCtrl::ApplicationEvents1Minimize(TObject *Sender)
  854. {
  855. //화면 정지
  856. }
  857. //---------------------------------------------------------------------------
  858. void __fastcall TFrmCctvCtrl::ApplicationEvents1SettingChange(TObject *Sender, int Flag,
  859. const UnicodeString Section, int &Result)
  860. {
  861. DateSeparator = '-';
  862. TimeSeparator = ':';
  863. ShortDateFormat = "yyyy-MM-dd";
  864. ShortTimeFormat = "HH:NN:SS";
  865. LongTimeFormat = "HH:NN:SS";
  866. cxFormatController()->BeginUpdate();
  867. cxFormatController()->UseDelphiDateTimeFormats = true;
  868. cxFormatController()->EndUpdate();
  869. cxFormatController()->GetFormats();
  870. cxFormatController()->NotifyListeners();
  871. }
  872. //---------------------------------------------------------------------------
  873. void __fastcall TFrmCctvCtrl::BtnCloseClick(TObject *Sender)
  874. {
  875. Close();
  876. }
  877. //---------------------------------------------------------------------------