FrmVmsCamViewerF.cpp 14 KB

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