IFM0000MF.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "ITSSkinF.h"
  4. #include "ITSUtilF.h"
  5. #include "ITSDbF.h"
  6. #include "AppGlobalF.h"
  7. #include "WindowMsgF.h"
  8. #include "CDSFacilityF.h"
  9. #include "CommFlashF.h"
  10. #pragma hdrstop
  11. #include "IFM0000MF.h"
  12. #include "FrmMainF.h"
  13. //---------------------------------------------------------------------------
  14. #pragma package(smart_init)
  15. #pragma link "cxButtons"
  16. #pragma link "cxCalc"
  17. #pragma link "cxCheckBox"
  18. #pragma link "cxClasses"
  19. #pragma link "cxContainer"
  20. #pragma link "cxControls"
  21. #pragma link "cxCustomData"
  22. #pragma link "cxData"
  23. #pragma link "cxDataStorage"
  24. #pragma link "cxDropDownEdit"
  25. #pragma link "cxEdit"
  26. #pragma link "cxFilter"
  27. #pragma link "cxGraphics"
  28. #pragma link "cxGrid"
  29. #pragma link "cxGridCustomTableView"
  30. #pragma link "cxGridCustomView"
  31. #pragma link "cxGridLevel"
  32. #pragma link "cxGridTableView"
  33. #pragma link "cxLabel"
  34. #pragma link "cxLookAndFeelPainters"
  35. #pragma link "cxLookAndFeels"
  36. #pragma link "cxStyles"
  37. #pragma link "cxTextEdit"
  38. #pragma link "dxSkinBlack"
  39. #pragma link "dxSkinBlue"
  40. #pragma link "dxSkinCaramel"
  41. #pragma link "dxSkinCoffee"
  42. #pragma link "dxSkinDarkRoom"
  43. #pragma link "dxSkinDarkSide"
  44. #pragma link "dxSkinFoggy"
  45. #pragma link "dxSkinGlassOceans"
  46. #pragma link "dxSkiniMaginary"
  47. #pragma link "dxSkinLilian"
  48. #pragma link "dxSkinLiquidSky"
  49. #pragma link "dxSkinLondonLiquidSky"
  50. #pragma link "dxSkinMcSkin"
  51. #pragma link "dxSkinMoneyTwins"
  52. #pragma link "dxSkinOffice2007Black"
  53. #pragma link "dxSkinOffice2007Blue"
  54. #pragma link "dxSkinOffice2007Green"
  55. #pragma link "dxSkinOffice2007Pink"
  56. #pragma link "dxSkinOffice2007Silver"
  57. #pragma link "dxSkinOffice2010Black"
  58. #pragma link "dxSkinOffice2010Blue"
  59. #pragma link "dxSkinOffice2010Silver"
  60. #pragma link "dxSkinsCore"
  61. #pragma link "dxSkinscxPCPainter"
  62. #pragma link "dxSkinSeven"
  63. #pragma link "dxSkinSharp"
  64. #pragma link "dxSkinSilver"
  65. #pragma link "dxSkinStardust"
  66. #pragma link "cxGroupBox"
  67. #pragma resource "*.dfm"
  68. TIFM0000M *IFM0000M = NULL;
  69. extern LOGININFO *g_pLOGIN;
  70. //---------------------------------------------------------------------------
  71. __fastcall TIFM0000M::TIFM0000M(TComponent* Owner)
  72. : TForm(Owner)
  73. {
  74. ITSSkin_Load(this);
  75. CMM_LoadForm(g_sFormsDir, this);
  76. FTitle = "시설물상태 현황";
  77. FFacilityType = "";
  78. }
  79. //---------------------------------------------------------------------------
  80. /*
  81. * 닫기버튼 이나 x버튼 클릭시 공통으로 처리하는 로직이들어간다..
  82. * Form과 DataModule class를 delete시킨다.
  83. * arguments
  84. *
  85. * return
  86. * void
  87. */
  88. void __fastcall TIFM0000M::CommClose()
  89. {
  90. try
  91. {
  92. CMM_SaveForm(g_sFormsDir, this);
  93. }
  94. catch(...)
  95. {
  96. }
  97. }
  98. //---------------------------------------------------------------------------
  99. /*
  100. * Form을 보여줄때 호출되는 event 메서드이다.
  101. * arguments
  102. * Sender : event handler 객체
  103. * return
  104. * void
  105. */
  106. void __fastcall TIFM0000M::FormShow(TObject *Sender)
  107. {
  108. Refresh();
  109. FormInit();
  110. TmrShow->Enabled = true;
  111. }
  112. //---------------------------------------------------------------------------
  113. /*
  114. * form 초기화
  115. *
  116. * arguments
  117. *
  118. * return
  119. * void
  120. */
  121. void __fastcall TIFM0000M::FormInit()
  122. {
  123. TvList->OptionsView->NoDataToDisplayInfoText = "<시설물 상태>";
  124. }
  125. //---------------------------------------------------------------------------
  126. /*
  127. * Form이 Show되고 난 후 최초 1회 수행되는 타이머 이벤트
  128. * arguments
  129. * Sender : event handler 객체
  130. * return
  131. * void
  132. */
  133. void __fastcall TIFM0000M::TmrShowTimer(TObject *Sender)
  134. {
  135. TmrShow->Enabled = false;
  136. RefreshData();
  137. }
  138. //---------------------------------------------------------------------------
  139. /*
  140. * Search 버튼 클릭 이벤트 핸들러
  141. * arguments
  142. * Sender : event handler 객체
  143. * return
  144. * void
  145. */
  146. void __fastcall TIFM0000M::BtnSearchClick(TObject *Sender)
  147. {
  148. BtnSearch->Enabled = false;
  149. // 시설물상태정보
  150. FrmMain->FPollStatus01.Reset();
  151. //RefreshData();
  152. }
  153. //---------------------------------------------------------------------------
  154. /*
  155. * Refresh Data Event Function
  156. * arguments
  157. *
  158. * return
  159. * void
  160. */
  161. void __fastcall TIFM0000M::RefreshData()
  162. {
  163. UpdateFacility();
  164. UpdateFacilityStatusTotal();
  165. UpdateFacilityStatus();
  166. BtnSearch->Enabled = true;
  167. }
  168. //---------------------------------------------------------------------------
  169. /*
  170. * Close 버튼 클릭 이벤트 핸들러
  171. * arguments
  172. * Sender : event handler 객체
  173. * return
  174. * void
  175. */
  176. void __fastcall TIFM0000M::BtnCloseClick(TObject *Sender)
  177. {
  178. Close();
  179. }
  180. //---------------------------------------------------------------------------
  181. void __fastcall TIFM0000M::FormClose(TObject *Sender, TCloseAction &Action)
  182. {
  183. CommClose();
  184. IFM0000M = NULL;
  185. Action = caFree;
  186. }
  187. //---------------------------------------------------------------------------
  188. void __fastcall TIFM0000M::UpdateFacility()
  189. {
  190. try
  191. {
  192. TItsSubCode *pSubCode;
  193. try
  194. {
  195. ItsFacilityManager->FLists.Lock();
  196. TFacilityStatus *pStatus;
  197. ItsFacilityManager->FListStatus.RemoveAll();
  198. FOR_STL(TItsFacility*, pFacility, ItsFacilityManager->FLists)
  199. {
  200. pFacility->StatusGridIndex = -1;
  201. if (pFacility->DEL_YN == "Y") continue;
  202. String sComm = "정상";
  203. if (pFacility->FComm == state_normal) sComm = "정상";
  204. else
  205. if (pFacility->FComm == state_error ) sComm = "통신이상";
  206. else
  207. if (pFacility->FComm == state_module) sComm = "함체문열림";
  208. else sComm = "알수없음";
  209. pStatus = ItsFacilityManager->FListStatus.Find(pFacility->FCLT_TYPE);
  210. if (!pStatus)
  211. {
  212. pStatus = new TFacilityStatus();
  213. pStatus->Type = pFacility->FCLT_TYPE;
  214. pStatus->Total = 0;
  215. pStatus->Normal = 0;
  216. pStatus->Error = 0;
  217. pStatus->Collect= 0;
  218. ItsFacilityManager->FListStatus.Push(pFacility->FCLT_TYPE, pStatus);
  219. }
  220. pStatus->Total++; /* 전체 갯수를 증가 시킴 */
  221. if (pFacility->FComm == state_error)
  222. {
  223. pStatus->Error++;
  224. }
  225. else
  226. if (pFacility->FComm == state_module)
  227. {
  228. pStatus->Module++;
  229. }
  230. if (pFacility->FCollError)
  231. {
  232. pStatus->Collect++;
  233. }
  234. try
  235. {
  236. String sValue = pFacility->FCBoxTmpr;
  237. int nValue = 0;
  238. if (TryStrToInt(sValue, nValue))
  239. {
  240. if (nValue > g_AppCfg.Temp.AlarmValue)
  241. {
  242. sComm = "함체온도";
  243. }
  244. }
  245. } catch(...) {}
  246. }
  247. }
  248. __finally
  249. {
  250. ItsFacilityManager->FLists.UnLock();
  251. }
  252. }
  253. __finally
  254. {
  255. }
  256. }
  257. //---------------------------------------------------------------------------
  258. void __fastcall TIFM0000M::UpdateFacilityStatusTotal()
  259. {
  260. int nRow = 0;
  261. try
  262. {
  263. CMM_ClearGridTableView(TvStatus);
  264. TcxDataController *pGDC = TvStatus->DataController;
  265. TvStatus->BeginUpdate();
  266. try
  267. {
  268. FOR_STL(TFacilityStatus*, pStatus, ItsFacilityManager->FListStatus)
  269. {
  270. nRow = pGDC->AppendRecord();
  271. pGDC->Values[nRow][ColType->Index] = pStatus->Type;
  272. if (FFacilityType == "") FFacilityType = pStatus->Type;
  273. String sName = "";
  274. if (pStatus->Type == FAC_CCTV) sName = " CCTV제어기";
  275. else
  276. if (pStatus->Type == FAC_VMS) sName = " VMS제어기";
  277. else
  278. if (pStatus->Type == FAC_VDS) sName = " VDS제어기";
  279. else
  280. if (pStatus->Type == FAC_PVMS) sName = " PIS표출기";
  281. else
  282. if (pStatus->Type == FAC_PVDS) sName = " PIS수집기";
  283. else
  284. if (pStatus->Type == FAC_BIT) sName = " 정류소안내기";
  285. else
  286. if (pStatus->Type == FAC_SIG) sName = " 신호제어기";
  287. pGDC->Values[nRow][ColName->Index] = sName;
  288. pGDC->Values[nRow][ColTotal->Index] = pStatus->Total;
  289. pGDC->Values[nRow][ColNormal->Index] = pStatus->Total - pStatus->Error;
  290. pGDC->Values[nRow][ColFail->Index] = pStatus->Error;
  291. if (pStatus->Type == "VDS" || pStatus->Type == "AVI")
  292. pGDC->Values[nRow][ColModule->Index] = pStatus->Collect;//Module;
  293. else
  294. pGDC->Values[nRow][ColModule->Index] = "-";
  295. }
  296. }
  297. catch(Exception &exception)
  298. {
  299. }
  300. }
  301. __finally
  302. {
  303. TvStatus->EndUpdate();
  304. }
  305. }
  306. //---------------------------------------------------------------------------
  307. void __fastcall TIFM0000M::UpdateFacilityStatus()
  308. {
  309. String sName;
  310. if (FFacilityType == FAC_CCTV) sName = "▶ CCTV제어기 상태";
  311. else
  312. if (FFacilityType == FAC_VMS) sName = "▶ VMS제어기 상태";
  313. else
  314. if (FFacilityType == FAC_VDS) sName = "▶ VDS제어기 상태";
  315. else
  316. if (FFacilityType == FAC_PVMS) sName = "▶ PIS표출기 상태";
  317. else
  318. if (FFacilityType == FAC_PVDS) sName = "▶ PIS수집기 상태";
  319. else
  320. if (FFacilityType == FAC_BIT) sName = "▶ 정류소안내기 상태";
  321. else
  322. if (FFacilityType == FAC_SIG) sName = "▶ 신호제어기 상태";
  323. else sName = "▶ 시설물현황";
  324. grpBox->Caption = sName;
  325. CMM_ClearGridTableView(TvList);
  326. Col02->Visible = false;
  327. Col03->Visible = false;
  328. Col04->Visible = false;
  329. Col05->Visible = false;
  330. Col06->Visible = false;
  331. Col07->Visible = false;
  332. Col08->Visible = false;
  333. Col09->Visible = false;
  334. Col10->Visible = false;
  335. if (FFacilityType == FAC_CCTV ||
  336. FFacilityType == FAC_VMS ||
  337. FFacilityType == FAC_VDS ||
  338. FFacilityType == FAC_AVI )
  339. {
  340. Col02->Visible = true; //함체온도
  341. Col03->Visible = true; //함체문
  342. }
  343. else
  344. if (FFacilityType == FAC_DSRC ||
  345. FFacilityType == FAC_SIG ||
  346. FFacilityType == FAC_PVMS )
  347. {
  348. Col03->Visible = true; //함체문
  349. }
  350. else
  351. if (FFacilityType == FAC_PVDS )
  352. {
  353. Col04->Visible = true; //제어기상태
  354. }
  355. if (FFacilityType == FAC_PVMS )
  356. {
  357. Col05->Visible = true; //전원
  358. Col06->Visible = true; //모듈
  359. Col07->Visible = true; //FAN
  360. Col08->Visible = true; //히터
  361. }
  362. TcxDataController *m_pGDC = TvList->DataController;
  363. int nRow = 0;
  364. try
  365. {
  366. TvList->BeginUpdate();
  367. TItsSubCode *pSubCode;
  368. try
  369. {
  370. ItsFacilityManager->FLists.Lock();
  371. TFacilityStatus *pStatus;
  372. ItsFacilityManager->FListStatus.RemoveAll();
  373. //통신이상인 것들을 먼저 표출한다.
  374. FOR_STL(TItsFacility*, pFacility, ItsFacilityManager->FLists)
  375. {
  376. pFacility->StatusGridIndex = -1;
  377. if (pFacility->DEL_YN == "Y") continue;
  378. if (pFacility->FCLT_TYPE != FFacilityType) continue;
  379. if (pFacility->FComm != state_error ) continue;
  380. nRow = m_pGDC->AppendRecord();
  381. m_pGDC->Values[nRow][ColId->Index] = pFacility->FCLT_ID;
  382. m_pGDC->Values[nRow][ColNm->Index] = pFacility->FCLT_LCTN;
  383. m_pGDC->Values[nRow][Col00->Index] = ITSUtil_FormatStr(pFacility->Sts00, STR_DATETIME);
  384. m_pGDC->Values[nRow][Col01->Index] = "이상";
  385. m_pGDC->Values[nRow][Col02->Index] = "-";
  386. m_pGDC->Values[nRow][Col03->Index] = "-";
  387. m_pGDC->Values[nRow][Col04->Index] = "-";
  388. m_pGDC->Values[nRow][Col05->Index] = "-";
  389. m_pGDC->Values[nRow][Col06->Index] = "-";
  390. m_pGDC->Values[nRow][Col07->Index] = "-";
  391. m_pGDC->Values[nRow][Col08->Index] = "-";
  392. m_pGDC->Values[nRow][Col09->Index] = "-";
  393. m_pGDC->Values[nRow][Col10->Index] = "-";
  394. }
  395. //통신이상이 아닌것들을 표출한다.
  396. FOR_STL(TItsFacility*, pFacility, ItsFacilityManager->FLists)
  397. {
  398. pFacility->StatusGridIndex = -1;
  399. if (pFacility->DEL_YN == "Y") continue;
  400. if (pFacility->FCLT_TYPE != FFacilityType) continue;
  401. if (pFacility->FComm == state_error ) continue;
  402. nRow = m_pGDC->AppendRecord();
  403. m_pGDC->Values[nRow][ColId->Index] = pFacility->FCLT_ID;
  404. m_pGDC->Values[nRow][ColNm->Index] = pFacility->FCLT_LCTN;
  405. m_pGDC->Values[nRow][Col00->Index] = ITSUtil_FormatStr(pFacility->Sts00, STR_DATETIME);
  406. m_pGDC->Values[nRow][Col01->Index] = "정상";
  407. m_pGDC->Values[nRow][Col02->Index] = pFacility->FCBoxTmpr; //함체온도
  408. m_pGDC->Values[nRow][Col03->Index] = pFacility->FDoor == "0" ? "닫힘" : "열림";
  409. m_pGDC->Values[nRow][Col04->Index] = pFacility->Sts01 == "0" ? "정상" : "오류"; //제어기상태
  410. m_pGDC->Values[nRow][Col05->Index] = pFacility->Sts02 == "0" ? "정상" : "오류"; //전원
  411. m_pGDC->Values[nRow][Col06->Index] = pFacility->Sts03 == "0" ? "정상" : "오류"; //모듈
  412. m_pGDC->Values[nRow][Col07->Index] = pFacility->Sts04 == "0" ? "가동" : "중지"; //FAN
  413. m_pGDC->Values[nRow][Col08->Index] = pFacility->Sts05 == "0" ? "가동" : "중지"; //히터
  414. m_pGDC->Values[nRow][Col09->Index] = "-";
  415. m_pGDC->Values[nRow][Col10->Index] = "-";
  416. }
  417. }
  418. __finally
  419. {
  420. ItsFacilityManager->FLists.UnLock();
  421. }
  422. }
  423. __finally
  424. {
  425. TvList->EndUpdate();
  426. TvList->DataController->GotoFirst();
  427. TvList->DataController->FocusedRecordIndex = 0;
  428. }
  429. }
  430. //---------------------------------------------------------------------------
  431. void __fastcall TIFM0000M::ColNameCustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas,
  432. TcxGridTableDataCellViewInfo *AViewInfo, bool &ADone)
  433. {
  434. if (AViewInfo->GridRecord->RecordIndex < 0) return;
  435. ACanvas->Font->Style = TFontStyles() << fsBold;
  436. }
  437. //---------------------------------------------------------------------------
  438. void __fastcall TIFM0000M::ColTotalCustomDrawCell(TcxCustomGridTableView *Sender,
  439. TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
  440. bool &ADone)
  441. {
  442. // 전체
  443. if (AViewInfo->GridRecord->RecordIndex < 0) return;
  444. ACanvas->Font->Style = TFontStyles() << fsBold;
  445. }
  446. //---------------------------------------------------------------------------
  447. void __fastcall TIFM0000M::ColNormalCustomDrawCell(TcxCustomGridTableView *Sender,
  448. TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
  449. bool &ADone)
  450. {
  451. // 정상
  452. if (AViewInfo->GridRecord->RecordIndex < 0) return;
  453. ACanvas->Font->Style = TFontStyles() << fsBold;
  454. }
  455. //---------------------------------------------------------------------------
  456. void __fastcall TIFM0000M::ColFailCustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas,
  457. TcxGridTableDataCellViewInfo *AViewInfo, bool &ADone)
  458. {
  459. // 이상
  460. if (AViewInfo->GridRecord->RecordIndex < 0) return;
  461. ACanvas->Font->Style = TFontStyles() << fsBold;
  462. if (!VarIsNull(AViewInfo->GridRecord->DisplayTexts[ColFail->Index]))
  463. {
  464. String sErr = AViewInfo->GridRecord->DisplayTexts[ColFail->Index];
  465. if (sErr != "0")
  466. {
  467. ACanvas->Font->Color = clRed;
  468. }
  469. }
  470. }
  471. //---------------------------------------------------------------------------
  472. void __fastcall TIFM0000M::TvStatusFocusedRecordChanged(TcxCustomGridTableView *Sender,
  473. TcxCustomGridRecord *APrevFocusedRecord, TcxCustomGridRecord *AFocusedRecord,
  474. bool ANewItemRecordFocusingChanged)
  475. {
  476. int nIndex = TvStatus->DataController->FocusedRecordIndex;
  477. if (nIndex < 0) return;
  478. String sFacilityType = VarToStr(TvStatus->DataController->Values[nIndex][ColType->Index]);
  479. FFacilityType = sFacilityType;
  480. UpdateFacilityStatus();
  481. }
  482. //---------------------------------------------------------------------------
  483. void __fastcall TIFM0000M::Col04CustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas,
  484. TcxGridTableDataCellViewInfo *AViewInfo, bool &ADone)
  485. {
  486. if (AViewInfo->GridRecord->RecordIndex < 0) return;
  487. ACanvas->Font->Style = TFontStyles() << fsBold;
  488. if (AViewInfo)
  489. {
  490. String sInfo = AViewInfo->Text.Trim();
  491. if (sInfo == "이상" ||
  492. sInfo == "오류" ||
  493. sInfo == "장애" ||
  494. sInfo == "열림" )
  495. {
  496. ACanvas->Canvas->Font->Color = clRed;
  497. }
  498. }
  499. }
  500. //---------------------------------------------------------------------------
  501. void __fastcall TIFM0000M::ColIdCustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas,
  502. TcxGridTableDataCellViewInfo *AViewInfo, bool &ADone)
  503. {
  504. if (AViewInfo->GridRecord->RecordIndex < 0) return;
  505. ACanvas->Font->Style = TFontStyles() << fsBold;
  506. if (!VarIsNull(AViewInfo->GridRecord->DisplayTexts[Col01->Index]))
  507. {
  508. String sErr = AViewInfo->GridRecord->DisplayTexts[Col01->Index].Trim();
  509. if (sErr != "정상")
  510. {
  511. ACanvas->Font->Color = clRed;
  512. }
  513. }
  514. }
  515. //---------------------------------------------------------------------------
  516. void __fastcall TIFM0000M::ColNmCustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas,
  517. TcxGridTableDataCellViewInfo *AViewInfo, bool &ADone)
  518. {
  519. if (AViewInfo->GridRecord->RecordIndex < 0) return;
  520. ACanvas->Font->Style = TFontStyles() << fsBold;
  521. }
  522. //---------------------------------------------------------------------------
  523. void __fastcall TIFM0000M::BtnExlSaveClick(TObject *Sender)
  524. {
  525. TcxGrid *pGrid = CxStatus;
  526. TcxGridTableView *pView = TvStatus;
  527. String sTitle= "시설물현황";
  528. CMM_ExportToExcelFile(sTitle, pGrid, pView, (TForm*)this);
  529. }
  530. //---------------------------------------------------------------------------
  531. void __fastcall TIFM0000M::cxButton1Click(TObject *Sender)
  532. {
  533. TcxGrid *pGrid = CxList;
  534. TcxGridTableView *pView = TvList;
  535. String sTitle= grpBox->Caption;
  536. sTitle = StringReplace(sTitle, "▶ ", "", TReplaceFlags() << rfReplaceAll);
  537. CMM_ExportToExcelFile(sTitle, pGrid, pView, (TForm*)this);
  538. }
  539. //---------------------------------------------------------------------------