FrmVmsCamViewerF.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "ITSSkinF.h"
  4. #pragma hdrstop
  5. #include "FrmVmsCamViewerF.h"
  6. #include "FrmCameraViewF.h"
  7. #include "CDSCctvF.h"
  8. #include "CDSVmsCtlrF.h"
  9. #include "VMSVIEWMF.h"
  10. #include "DMDbF.h"
  11. //---------------------------------------------------------------------------
  12. //---------------------------------------------------------------------------
  13. #pragma package(smart_init)
  14. #pragma link "cxButtons"
  15. #pragma link "cxContainer"
  16. #pragma link "cxControls"
  17. #pragma link "cxEdit"
  18. #pragma link "cxGraphics"
  19. #pragma link "cxLookAndFeelPainters"
  20. #pragma link "cxLookAndFeels"
  21. #pragma link "cxPC"
  22. #pragma link "cxPCdxBarPopupMenu"
  23. #pragma link "cxProgressBar"
  24. #pragma link "dxSkinsCore"
  25. #pragma link "dxSkinscxPCPainter"
  26. #pragma link "dxSkinBlue"
  27. #pragma link "dxSkinsForm"
  28. #pragma link "dxSkinBlack"
  29. #pragma link "XNSSDKDEVICELib_OCX"
  30. #pragma resource "*.dfm"
  31. TFrmVmsCamViewer *FrmVmsCamViewer = NULL;
  32. //---------------------------------------------------------------------------
  33. __fastcall TFrmVmsCamViewer::TFrmVmsCamViewer(TComponent* Owner)
  34. : TForm(Owner)//TdxCustomRibbonForm(Owner)//TForm(Owner)
  35. {
  36. //DoubleBuffered = true;
  37. g_AppCfg.lMainWinHandle = (long)Handle;
  38. ITSSkin_Initialize(Application, "EN");
  39. ITSSkin_Load(this);
  40. ITSSkin_Caption(false);
  41. CMM_LoadForm(g_sFormsDir, this);
  42. SetColorScheme(g_AppCfg.sSkinName);
  43. TsList01->Visible = false;
  44. TsList01->TabVisible = false;
  45. PnlBack->ParentColor = false;
  46. PnlBack->Color = clBlack;
  47. PnlBack->Font->Color = clWhite;
  48. FMonitoringType = enMonitoringCamera;
  49. IsFormResizing = false;
  50. FOldWidth = Width;
  51. FOldHeight= Height;
  52. FCurrPage = NULL;
  53. PgCamera->OnPageChanging = NULL;
  54. }
  55. //---------------------------------------------------------------------------
  56. void __fastcall TFrmVmsCamViewer::FormCreate(TObject *Sender)
  57. {
  58. Application->ShowMainForm = false;
  59. try {
  60. Application->Icon->LoadFromResourceName(((unsigned int)HInstance), "MAINICON");
  61. } catch(...) { ShowMessage("LoadFromResourceName failed"); }
  62. Application->ShowMainForm = true;
  63. }
  64. //---------------------------------------------------------------------------
  65. void __fastcall TFrmVmsCamViewer::FormShow(TObject *Sender)
  66. {
  67. Application->ProcessMessages();
  68. Samsung.bInit = false;
  69. Samsung.hDevice = 0;
  70. Refresh();
  71. TmrShow->Enabled = true;
  72. //FormInit();
  73. }
  74. //---------------------------------------------------------------------------
  75. void __fastcall TFrmVmsCamViewer::FormClose(TObject *Sender, TCloseAction &Action)
  76. {
  77. CommClose();
  78. Action = caFree;
  79. }
  80. //---------------------------------------------------------------------------
  81. void __fastcall TFrmVmsCamViewer::CommClose()
  82. {
  83. try
  84. {
  85. ITSSkin_Term();
  86. CMM_SaveForm(g_sFormsDir, this);
  87. }
  88. catch(Exception &e)
  89. {
  90. }
  91. }
  92. //---------------------------------------------------------------------------
  93. void __fastcall TFrmVmsCamViewer::SetColorScheme(String ASkinName)
  94. {
  95. dxSkinController1->SkinName = ASkinName;
  96. dxSkinController1->Refresh();
  97. }
  98. //---------------------------------------------------------------------------
  99. void __fastcall TFrmVmsCamViewer::TmrShowTimer(TObject *Sender)
  100. {
  101. TmrShow->Enabled = false;
  102. FormInit();
  103. }
  104. //---------------------------------------------------------------------------
  105. void __fastcall TFrmVmsCamViewer::FormInit()
  106. {
  107. PnlProgress->Left = (this->Width - PnlProgress->Width) / 2;
  108. PnlProgress->Top = (this->Height - PnlProgress->Height) / 2;
  109. PnlProgress->Top -= 50;
  110. PnlProgress->Visible = true;
  111. PgCamera->Visible = true;
  112. Application->ShowMainForm = false;
  113. PgCamera->Visible = false;
  114. DMDb->SetConnectString(g_AppCfg.itsdb.sProvider, g_AppCfg.itsdb.sServerName, g_AppCfg.itsdb.sUserName, g_AppCfg.itsdb.sPassword);
  115. if (!DMDb->Connect())
  116. {
  117. #ifdef ENG
  118. Application->MessageBox(L"Database connection failed.\r\n\r\nPlease restart the program.",
  119. L"Database connection error !!!",
  120. MB_OK|MB_ICONERROR);
  121. #else
  122. Application->MessageBox(L"데이터베이스 연결에 실패하였습니다.\r\n\r\n프로그램을 다시 시작하십시요.",
  123. L"데이터베이스 연결 오류!!!",
  124. MB_OK|MB_ICONERROR);
  125. #endif
  126. PnlProgress->Visible = false;
  127. return;
  128. }
  129. PbLoadMap->Properties->Text = "기본 정보 로딩 중...";
  130. Application->ProcessMessages();
  131. PbLoadMap->Position = 20;
  132. XCctvManager = new TXCctvManager();
  133. XViewManager = new TXViewManager();
  134. ItsCodeManager = new TItsCodeManager();
  135. ItsCodeManager->LoadFromDb(DMDb->GetConnection());
  136. VmsManager = new TVmsCtlrManager();
  137. VmsManager->LoadVmsSize(DMDb->GetConnection());
  138. VmsManager->LoadFromDb(DMDb->GetConnection());
  139. #ifdef ENG
  140. PbLoadMap->Properties->Text = "Initialize default monitoring screen...";
  141. #else
  142. PbLoadMap->Properties->Text = "기본 모니터링 화면 초기화...";
  143. #endif
  144. Application->ProcessMessages();
  145. PbLoadMap->Position = 40;
  146. InitMonitoringForm();
  147. #ifdef ENG
  148. PbLoadMap->Properties->Text = "Displaying monitoring screen...";
  149. #else
  150. PbLoadMap->Properties->Text = "모니터링 화면 조회중...";
  151. #endif
  152. Application->ProcessMessages();
  153. PbLoadMap->Position = 60;
  154. XCctvManager->LoadFromDb(DMDb->GetConnection());
  155. XViewManager->LoadFromDb(DMDb->GetConnection());
  156. #ifdef ENG
  157. PbLoadMap->Properties->Text = "Configuring monitoring screen...";
  158. #else
  159. PbLoadMap->Properties->Text = "모니터링 화면 구성중...";
  160. #endif
  161. Application->ProcessMessages();
  162. PbLoadMap->Position = 100;
  163. CreateMonitoringScreen();
  164. DMDb->Close();;
  165. PnlBack->ParentColor = true;
  166. PgCamera->Visible = true;
  167. BtnMonitoringMngr->Visible = true;
  168. PnlProgress->Visible = false;
  169. }
  170. //---------------------------------------------------------------------------
  171. void __fastcall TFrmVmsCamViewer::InitMonitoringForm()
  172. {
  173. String sQry;
  174. TADOQuery *pADO = NULL;
  175. sQry = "SELECT COUNT(1) AS CNT \r\n"
  176. " FROM TB_VMS_MONITORING \r\n"
  177. " WHERE MONITORING_TYPE = :p01 \r\n";
  178. try
  179. {
  180. int nString(0), nFigure(0), nFormSeq(0);
  181. VmsManager->FLists.Lock();
  182. try
  183. {
  184. pADO = new TADOQuery(NULL);
  185. pADO->Close();
  186. pADO->Connection = DMDb->GetConnection();
  187. DMDb->SQLText(pADO, sQry);
  188. DMDb->SQLBind(pADO, "p01", String(FMonitoringType));
  189. DMDb->SQLOpen(pADO);
  190. int nFormCnt = pADO->FieldByName("CNT")->AsInteger;
  191. if (nFormCnt > 0) return;
  192. sQry = "INSERT INTO TB_VMS_MONITORING ( \r\n"
  193. " MONITORING_TYPE, \r\n"
  194. " MONITORING_NM, \r\n"
  195. " MONITORING_SEQ, \r\n"
  196. " VMS_CTLR_NMBR \r\n"
  197. " ) \r\n"
  198. " VALUES ( \r\n"
  199. " :p01, \r\n"
  200. " :p02, \r\n"
  201. " :p03, \r\n"
  202. " :p04 \r\n"
  203. " ) \r\n";
  204. DMDb->SQLText(pADO, sQry);
  205. FOR_STL(TVmsCtlr*, pObj, VmsManager->FLists)
  206. {
  207. if (pObj->DEL_YN == "Y") continue;
  208. String sFormName = "VMS All";
  209. if (pObj->VMS_USAG_TYPE_CD == "VUTN") //문자식
  210. {
  211. nFormSeq = ++nString;
  212. }
  213. else
  214. if (pObj->VMS_USAG_TYPE_CD == "VUTP") //도형식
  215. {
  216. sFormName = "VMS All";
  217. nFormSeq = ++nFigure;
  218. }
  219. else continue;
  220. DMDb->SQLBind(pADO, "p01", String(FMonitoringType));
  221. DMDb->SQLBind(pADO, "p02", sFormName);
  222. DMDb->SQLBind(pADO, "p03", String(nFormSeq));
  223. DMDb->SQLBind(pADO, "p04", String(pObj->VMS_CTLR_NMBR));
  224. DMDb->SQLExec(pADO);
  225. }
  226. }
  227. catch(EDatabaseError &E)
  228. {
  229. throw Exception(String(E.ClassName()) + E.Message);
  230. }
  231. catch(Exception &e)
  232. {
  233. throw Exception(String(e.ClassName()) + e.Message);
  234. }
  235. }
  236. __finally
  237. {
  238. if (pADO)
  239. {
  240. pADO->Close();
  241. delete pADO;
  242. }
  243. VmsManager->FLists.UnLock();
  244. }
  245. }
  246. //---------------------------------------------------------------------------
  247. void __fastcall TFrmVmsCamViewer::ApplicationEvents1Minimize(TObject *Sender)
  248. {
  249. //영상표출을 정지한다.
  250. }
  251. //---------------------------------------------------------------------------
  252. void __fastcall TFrmVmsCamViewer::ApplicationEvents1Restore(TObject *Sender)
  253. {
  254. //영상표출을 재상영한다.
  255. RecalFormSize();
  256. }
  257. //---------------------------------------------------------------------------
  258. void __fastcall TFrmVmsCamViewer::FormResize(TObject *Sender)
  259. {
  260. if (IsFormResizing == false)
  261. {
  262. RecalFormSize();
  263. }
  264. }
  265. //---------------------------------------------------------------------------
  266. void __fastcall TFrmVmsCamViewer::WMEnterSizeMove(TMessage &Msg)
  267. {
  268. IsFormResizing = true;
  269. }
  270. //---------------------------------------------------------------------------
  271. void __fastcall TFrmVmsCamViewer::WMExitSizeMove(TMessage &Msg)
  272. {
  273. IsFormResizing = false;
  274. RecalFormSize();
  275. }
  276. //---------------------------------------------------------------------------
  277. void __fastcall TFrmVmsCamViewer::RecalFormSize()
  278. {
  279. #if 0
  280. int nNewW = PgCamera->Width;
  281. int nNewH = PgCamera->Height;
  282. #else
  283. int nNewW = Width;
  284. int nNewH = Height;
  285. #endif
  286. if (nNewW == FOldWidth && nNewH == FOldHeight)
  287. {
  288. return;
  289. }
  290. Application->ProcessMessages();
  291. FOldWidth = nNewW;
  292. FOldHeight= nNewH;
  293. try
  294. {
  295. for (int ii = 0 ; ii < PgCamera->PageCount; ii++)
  296. {
  297. TcxTabSheet *pSheet = PgCamera->Pages[ii];
  298. if (!pSheet) continue;
  299. TXView *pObj = (TXView*)pSheet->Tag;
  300. if (pObj)
  301. {
  302. pObj->FForm->Left = 0;
  303. pObj->FForm->Top = 0;
  304. pObj->FForm->Width = pSheet->Width;
  305. pObj->FForm->Height= pSheet->Height;
  306. pObj->FForm->RecalFormSize();
  307. }
  308. }
  309. }
  310. catch(...)
  311. {
  312. }
  313. }
  314. //---------------------------------------------------------------------------
  315. void __fastcall TFrmVmsCamViewer::CreateMonitoringScreen()
  316. {
  317. try
  318. {
  319. LockWindowUpdate(Handle);
  320. PgCamera->OnPageChanging = NULL;
  321. for (int ii = PgCamera->PageCount-1; ii >= 1 ; ii--)
  322. {
  323. TcxTabSheet *pSheet = PgCamera->Pages[ii];
  324. if (pSheet)
  325. {
  326. //TXView *pObj = (TXView*)pSheet->Tag;
  327. //if (pObj) pObj->FForm->Stop();
  328. delete pSheet;
  329. }
  330. }
  331. if (XViewManager->FLists.Size() == 0)
  332. {
  333. TXView *pObj = new TXView();
  334. pObj->Id = 0;
  335. pObj->Name = " -Empty- ";
  336. pObj->Layout = 1;
  337. pObj->Selected = 0;
  338. XViewManager->FLists.Push(pObj->Id, pObj);
  339. }
  340. int nActivePage = 1;
  341. TcxTabSheet *pActiveSheet = NULL;
  342. FOR_STL(TXView*, pObj, XViewManager->FLists)
  343. {
  344. TcxTabSheet *pSheet = new TcxTabSheet(PgCamera);
  345. pSheet->PageControl = PgCamera;
  346. pSheet->Caption = " " + pObj->Name + " ";
  347. #if 0
  348. if (pObj->Selected >= 0)
  349. nActivePage = pObj->Selected;
  350. #endif
  351. if (!pActiveSheet)
  352. {
  353. pActiveSheet = pSheet;
  354. }
  355. pSheet->Tag = (int)pObj;
  356. pObj->FForm = new TFrmCameraView(this, pSheet, pObj);
  357. pObj->FForm->FView = pObj;
  358. pObj->FForm->Parent = pSheet;
  359. pObj->FForm->FSheet = pSheet;
  360. pObj->FForm->Left = 0;
  361. pObj->FForm->Top = 0;
  362. pObj->FForm->Width = pSheet->Width;
  363. pObj->FForm->Height= pSheet->Height;
  364. pObj->FForm->Show();
  365. pObj->FForm->Layout = pObj->Layout;
  366. }
  367. //PgCamera->ActivePageIndex = nActivePage;
  368. if (pActiveSheet)
  369. {
  370. PgCamera->ActivePage = pActiveSheet;
  371. }
  372. FCurrPage = PgCamera->ActivePage;
  373. if (FCurrPage)
  374. {
  375. TXView *pObj = (TXView*)FCurrPage->Tag;
  376. if (pObj) pObj->FForm->Play();
  377. }
  378. PgCamera->OnPageChanging = PgCameraPageChanging;
  379. }
  380. __finally
  381. {
  382. LockWindowUpdate(0);
  383. }
  384. }
  385. //---------------------------------------------------------------------------
  386. void __fastcall TFrmVmsCamViewer::BtnMonitoringMngrClick(TObject *Sender)
  387. {
  388. if (!DMDb->Connect())
  389. {
  390. #ifdef ENG
  391. Application->MessageBox(L"Database connection failed.\r\n\r\nPlease restart the program.",
  392. L"Database connection error !!!",
  393. MB_OK|MB_ICONERROR);
  394. #else
  395. Application->MessageBox(L"데이터베이스 연결에 실패하였습니다.\r\n\r\n프로그램을 다시 시작하십시요.",
  396. L"데이터베이스 연결 오류!!!",
  397. MB_OK|MB_ICONERROR);
  398. #endif
  399. return;
  400. }
  401. TVMSVIEWM *pForm = new TVMSVIEWM(this);
  402. pForm->FMonitoringType = FMonitoringType;
  403. pForm->ShowModal();
  404. bool bUpdate = pForm->FUpdate;
  405. if(pForm)
  406. {
  407. delete pForm;
  408. pForm = NULL;
  409. }
  410. if (bUpdate)
  411. {
  412. XViewManager->LoadFromDb(DMDb->GetConnection());
  413. CreateMonitoringScreen();
  414. }
  415. DMDb->Close();
  416. EdFocus->SetFocus();
  417. }
  418. //---------------------------------------------------------------------------
  419. void __fastcall TFrmVmsCamViewer::PgCameraPageChanging(TObject *Sender, TcxTabSheet *NewPage,
  420. bool &AllowChange)
  421. {
  422. if (FCurrPage)
  423. {
  424. TXView *pObj = (TXView*)FCurrPage->Tag;
  425. if (pObj) pObj->FForm->Stop();
  426. }
  427. FCurrPage = NewPage;
  428. TXView *pObj = (TXView*)FCurrPage->Tag;
  429. if (pObj) pObj->FForm->Play();
  430. }
  431. //---------------------------------------------------------------------------