FrmVmsCamViewerF.cpp 14 KB

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