CRSM000MF.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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 "ITSLangTransF.h"
  10. #pragma hdrstop
  11. #include "CRSM000MF.h"
  12. #include "FrmMainF.h"
  13. #include "ITS_OPLibF.h"
  14. //---------------------------------------------------------------------------
  15. #pragma package(smart_init)
  16. #pragma link "cxButtons"
  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 "cxEdit"
  25. #pragma link "cxFilter"
  26. #pragma link "cxGraphics"
  27. #pragma link "cxGrid"
  28. #pragma link "cxGridBandedTableView"
  29. #pragma link "cxGridCustomTableView"
  30. #pragma link "cxGridCustomView"
  31. #pragma link "cxGridLevel"
  32. #pragma link "cxGridTableView"
  33. #pragma link "cxGroupBox"
  34. #pragma link "cxLabel"
  35. #pragma link "cxLookAndFeelPainters"
  36. #pragma link "cxLookAndFeels"
  37. #pragma link "cxStyles"
  38. #pragma link "cxTextEdit"
  39. #pragma link "dxSkinBlue"
  40. #pragma link "dxSkinsCore"
  41. #pragma link "dxSkinscxPCPainter"
  42. #pragma link "dxSkinBlack"
  43. #pragma link "dxSkinMcSkin"
  44. #pragma resource "*.dfm"
  45. TCRSM000M *CRSM000M = NULL;
  46. //---------------------------------------------------------------------------
  47. __fastcall TCRSM000M::TCRSM000M(TComponent* Owner)
  48. : TForm(Owner)
  49. {
  50. LangTrans->Translate(this, ITSDb_GetConnection());
  51. ITSSkin_Load(this);
  52. CMM_LoadForm(g_sFormsDir, this);
  53. FTitle = Caption;
  54. FFacilityType = "";
  55. }
  56. //---------------------------------------------------------------------------
  57. void __fastcall TCRSM000M::CommClose()
  58. {
  59. try
  60. {
  61. CMM_SaveForm(g_sFormsDir, this);
  62. }
  63. catch(...)
  64. {
  65. }
  66. }
  67. //---------------------------------------------------------------------------
  68. void __fastcall TCRSM000M::FormShow(TObject *Sender)
  69. {
  70. Refresh();
  71. FormInit();
  72. TmrShow->Enabled = true;
  73. }
  74. //---------------------------------------------------------------------------
  75. void __fastcall TCRSM000M::FormInit()
  76. {
  77. //TvList->OptionsView->NoDataToDisplayInfoText = "<교차로교통량 CCTV 상태현황>";
  78. }
  79. //---------------------------------------------------------------------------
  80. void __fastcall TCRSM000M::TmrShowTimer(TObject *Sender)
  81. {
  82. TmrShow->Enabled = false;
  83. RefreshData();
  84. }
  85. //---------------------------------------------------------------------------
  86. void __fastcall TCRSM000M::BtnSearchClick(TObject *Sender)
  87. {
  88. BtnSearch->Enabled = false;
  89. TmrShow->Enabled = true;
  90. }
  91. //---------------------------------------------------------------------------
  92. void __fastcall TCRSM000M::RefreshData()
  93. {
  94. BtnSearch->Enabled = false;
  95. UpdateFacility();
  96. BtnSearch->Enabled = true;
  97. }
  98. //---------------------------------------------------------------------------
  99. void __fastcall TCRSM000M::BtnCloseClick(TObject *Sender)
  100. {
  101. Close();
  102. }
  103. //---------------------------------------------------------------------------
  104. void __fastcall TCRSM000M::FormClose(TObject *Sender, TCloseAction &Action)
  105. {
  106. CommClose();
  107. CRSM000M = NULL;
  108. Action = caFree;
  109. }
  110. //---------------------------------------------------------------------------
  111. void __fastcall TCRSM000M::UpdateFacility()
  112. {
  113. String sQry;
  114. TADOQuery *pADO = NULL;
  115. #ifdef USE_SC_TBL
  116. #if 0
  117. sQry = "SELECT A.IXR_ID AS CROSS_ID, A.IXR_NM AS CROSS_NAME, A.IXR_TYPE AS CROSS_TYPE, \r\n"
  118. " B.CMRA_ID AS CAM_ID, B.ISTL_LCTN AS CAM_NAME, \r\n"
  119. " TO_CHAR(C.CLCT_DT,'YYYYMMDDHH24MISS') AS CLCT_DATE, \r\n"
  120. " (CASE WHEN NVL(C.CLCT_DT, SYSDATE-60/140) < SYSDATE - 10/1440 \r\n"
  121. " THEN 'N' ELSE 'N' END) AS MISSING, \r\n"
  122. " DECODE(C.CMRA_STTS, 1, '1', '0') AS STATUS \r\n"
  123. " FROM TB_SC_IXR_MNGM A, TB_SC_CMRA_MNGM B, TB_SC_CMRA_STTS C \r\n"
  124. " WHERE A.IXR_ID = B.IXR_ID \r\n"
  125. " AND B.CMRA_ID = C.CMRA_ID(+) \r\n"
  126. " AND A.USE_EN = 1 \r\n"
  127. " AND B.USE_EN = 1 \r\n"
  128. " ORDER BY A.IXR_ID, B.CMRA_ID \r\n";
  129. #else
  130. #if 0
  131. sQry = "SELECT A.IXR_ID AS CROSS_ID, A.IXR_NM AS CROSS_NAME, A.IXR_TYPE AS CROSS_TYPE, \r\n"
  132. " B.CMRA_ID AS CAM_ID, D.DRCT_LCTN AS CAM_NAME, \r\n"
  133. " TO_CHAR(C.CLCT_DT,'YYYYMMDDHH24MISS') AS CLCT_DATE, \r\n"
  134. " (CASE WHEN NVL(C.CLCT_DT, SYSDATE-60/140) < SYSDATE - 10/1440 \r\n"
  135. " THEN 'N' ELSE 'N' END) AS MISSING, \r\n"
  136. " DECODE(C.CMRA_STTS, 1, '1', '0') AS STATUS \r\n"
  137. " FROM TB_SC_IXR_MNGM A, TB_SC_CMRA_MNGM B, TB_SC_CMRA_STTS C, TB_SC_CMRA_DRCT_MNGM D \r\n"
  138. " WHERE A.IXR_ID = B.IXR_ID \r\n"
  139. " AND B.CMRA_ID = C.CMRA_ID(+) \r\n"
  140. " AND A.USE_EN = 1 \r\n"
  141. " AND B.USE_EN = 1 \r\n"
  142. " AND A.IXR_ID = D.IXR_ID \r\n"
  143. " AND B.CMRA_ID = D.CMRA_ID \r\n"
  144. " ORDER BY A.IXR_ID, B.CMRA_ID \r\n";
  145. #else
  146. sQry = "SELECT A.IXR_ID AS CROSS_ID, A.IXR_NM AS CROSS_NAME, A.IXR_TYPE AS CROSS_TYPE, \r\n"
  147. " B.CMRA_ID AS CAM_ID, D.DRCT_LCTN AS CAM_NAME, \r\n"
  148. " C.CLCT_DT AS CLCT_DATE, \r\n"
  149. " (CASE WHEN NVL(TO_DATE(C.CLCT_DT,'YYYYMMDDHH24MISS'), SYSDATE-60/140) < SYSDATE - 10/1440 \r\n"
  150. " THEN 'N' ELSE 'N' END) AS MISSING, \r\n"
  151. " DECODE(C.CMRA_STTS, 1, '1', '0') AS STATUS \r\n"
  152. " FROM TB_SC_IXR_MNGM A, TB_SC_CMRA_MNGM B, TB_SC_CMRA_STTS C, TB_SC_CMRA_DRCT_MNGM D \r\n"
  153. " WHERE A.IXR_ID = B.IXR_ID \r\n"
  154. " AND B.CMRA_ID = C.CMRA_ID(+) \r\n"
  155. " AND A.USE_EN = 1 \r\n"
  156. " AND B.USE_EN = 1 \r\n"
  157. " AND A.IXR_ID = D.IXR_ID \r\n"
  158. " AND B.CMRA_ID = D.CMRA_ID \r\n"
  159. " ORDER BY A.IXR_ID, B.CMRA_ID \r\n";
  160. #endif
  161. #endif
  162. #else
  163. sQry = "SELECT A.CROSS_ID, A.NAME AS CROSS_NAME, A.CROSS_TYPE, \r\n"
  164. " B.CAM_ID, B.NAME AS CAM_NAME, \r\n"
  165. " C.UPDT_DT AS CLCT_DATE, \r\n"
  166. " (CASE WHEN NVL(TO_DATE(C.UPDT_DT, 'YYYYMMDDHH24MISS'), \r\n"
  167. " SYSDATE-60/140) < SYSDATE - 10/1440 \r\n"
  168. " THEN 'Y' ELSE 'N' END) AS MISSING, \r\n"
  169. " DECODE(C.CMNC_STTS_CD, 'CMS0', '1', '0') AS STATUS \r\n"
  170. " FROM TB_CRS A, TB_CRS_CMRA B, TB_CRS_CMRA_STTS C \r\n"
  171. " WHERE A.CROSS_ID = B.CROSS_ID \r\n"
  172. " AND B.CAM_ID = C.CAM_ID(+) \r\n"
  173. " AND A.DEL_YN = 'N' \r\n"
  174. " AND B.DEL_YN = 'N' \r\n"
  175. " ORDER BY A.CROSS_ID, B.CAM_ID \r\n";
  176. #endif
  177. try
  178. {
  179. int nRow = 0;
  180. int nDataCnt = 0;
  181. TcxDataController *pGDC = TvList->DataController;
  182. try
  183. {
  184. pADO = new TADOQuery(NULL);
  185. pADO->Close();
  186. pADO->Connection = ITSDb_GetConnection();
  187. pADO->SQL->Clear();
  188. pADO->SQL->Text = sQry;
  189. pADO->Prepared = true;
  190. pADO->Open();
  191. CMM_ClearGridTableView(TvList);
  192. TvList->BeginUpdate();
  193. nDataCnt = pADO->RecordCount;
  194. pGDC->RecordCount = nDataCnt;
  195. for( ; !pADO->Eof; pADO->Next(), nRow++)
  196. {
  197. String CROSS_ID = pADO->FieldByName("CROSS_ID")->AsString;
  198. String CROSS_NAME = pADO->FieldByName("CROSS_NAME")->AsString;
  199. pGDC->Values[nRow][Col00->Index] = CROSS_ID + ": " + CROSS_NAME;
  200. pGDC->Values[nRow][Col10->Index] = CROSS_ID;
  201. pGDC->Values[nRow][Col01->Index] = CROSS_NAME;
  202. pGDC->Values[nRow][Col15->Index] = pADO->FieldByName("CROSS_TYPE")->AsString;
  203. pGDC->Values[nRow][Col11->Index] = pADO->FieldByName("CAM_ID")->AsString;
  204. pGDC->Values[nRow][Col05->Index] = pADO->FieldByName("CAM_NAME")->AsString;
  205. String CLCT_DATE = pADO->FieldByName("CLCT_DATE")->AsString;
  206. pGDC->Values[nRow][Col06->Index] = APP_FormatStr(CLCT_DATE, STR_DATETIME);
  207. //pGDC->Values[nRow][Col07->Index] = pADO->FieldByName("STATUS")->AsString;
  208. String MISSING = pADO->FieldByName("MISSING")->AsString;
  209. String STATUS = pADO->FieldByName("STATUS")->AsString;
  210. if (MISSING == "Y" || STATUS != "1")
  211. {
  212. pGDC->Values[nRow][Col07->Index] = "이상";
  213. }
  214. else
  215. {
  216. pGDC->Values[nRow][Col07->Index] = "정상";
  217. }
  218. }
  219. }
  220. catch(EDatabaseError &E)
  221. {
  222. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  223. DBERRORMSG("TCRSM000M::UpdateFacility", String(E.ClassName()), E.Message, sQry);
  224. throw Exception(String(E.ClassName()) + E.Message);
  225. }
  226. catch(Exception &e)
  227. {
  228. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  229. DBERRORMSG("TCRSM000M::UpdateFacility", String(e.ClassName()), e.Message, sQry);
  230. throw Exception(String(e.ClassName()) + e.Message);
  231. }
  232. }
  233. __finally
  234. {
  235. if (pADO)
  236. {
  237. pADO->Close();
  238. delete pADO;
  239. }
  240. TvList->EndUpdate();
  241. }
  242. CMM_ExpandCollapseChk(TvList, ChkExpand->Checked);
  243. }
  244. //---------------------------------------------------------------------------
  245. void __fastcall TCRSM000M::BtnExlSaveClick(TObject *Sender)
  246. {
  247. TcxGrid *pGrid = CxList;
  248. TcxGridTableView *pView = TvList;
  249. String sTitle= FTitle;
  250. CMM_ExportToExcelFile(sTitle, pGrid, pView, (TForm*)this);
  251. }
  252. //---------------------------------------------------------------------------
  253. void __fastcall TCRSM000M::ChkExpandClick(TObject *Sender)
  254. {
  255. CMM_ExpandCollapseChk(TvList, ChkExpand->Checked);
  256. }
  257. //---------------------------------------------------------------------------
  258. void __fastcall TCRSM000M::TvListDataControllerFilterChanged(TObject *Sender)
  259. {
  260. CMM_SetFilterLike(TvList);
  261. }
  262. //---------------------------------------------------------------------------
  263. void __fastcall TCRSM000M::Col07CustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas,
  264. TcxGridTableDataCellViewInfo *AViewInfo, bool &ADone)
  265. {
  266. if( AViewInfo )
  267. {
  268. if(AViewInfo->Text == "정상")
  269. {
  270. ACanvas->Canvas->Font->Color = clTeal;
  271. }
  272. //else if(AViewInfo->Text == "통신장애")
  273. //{
  274. // ACanvas->Canvas->Font->Color = clRed;
  275. //}
  276. else if(AViewInfo->Text == "알수없음")
  277. {
  278. ACanvas->Canvas->Font->Color = clGray;
  279. }
  280. else
  281. {
  282. ACanvas->Canvas->Font->Color = clRed;
  283. //ACanvas->Canvas->Font->Color = clFuchsia;
  284. }
  285. }
  286. }
  287. //---------------------------------------------------------------------------
  288. void __fastcall TCRSM000M::Col09CustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas,
  289. TcxGridTableDataCellViewInfo *AViewInfo, bool &ADone)
  290. {
  291. if( AViewInfo )
  292. {
  293. if(AViewInfo->Text == "정상")
  294. {
  295. ACanvas->Canvas->Font->Color = clTeal;
  296. }
  297. else
  298. {
  299. ACanvas->Canvas->Font->Color = clRed;
  300. }
  301. }
  302. }
  303. //---------------------------------------------------------------------------
  304. void __fastcall TCRSM000M::Col26CustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
  305. bool &ADone)
  306. {
  307. if( AViewInfo )
  308. {
  309. if(AViewInfo->Text == "정상")
  310. {
  311. ACanvas->Canvas->Font->Color = clTeal;
  312. }
  313. else
  314. {
  315. ACanvas->Canvas->Font->Color = clRed;
  316. }
  317. }
  318. }
  319. //---------------------------------------------------------------------------
  320. void __fastcall TCRSM000M::Col16CustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
  321. bool &ADone)
  322. {
  323. //앞문/뒷문
  324. if( AViewInfo )
  325. {
  326. if(AViewInfo->Text == "닫힘")
  327. {
  328. ACanvas->Canvas->Font->Color = clTeal;
  329. }
  330. else
  331. {
  332. ACanvas->Canvas->Font->Color = clRed;
  333. }
  334. }
  335. }
  336. //---------------------------------------------------------------------------
  337. void __fastcall TCRSM000M::Col18CustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
  338. bool &ADone)
  339. {
  340. //팬/히터
  341. if( AViewInfo )
  342. {
  343. if(AViewInfo->Text == "중지")
  344. {
  345. ACanvas->Canvas->Font->Color = clTeal;
  346. }
  347. else
  348. {
  349. ACanvas->Canvas->Font->Color = clRed;
  350. }
  351. }
  352. }
  353. //---------------------------------------------------------------------------
  354. void __fastcall TCRSM000M::Col20CustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
  355. bool &ADone)
  356. {
  357. //비디오입력
  358. if( AViewInfo )
  359. {
  360. if(AViewInfo->Text.Pos("정상"))
  361. {
  362. ACanvas->Canvas->Font->Color = clTeal;
  363. }
  364. else
  365. {
  366. ACanvas->Canvas->Font->Color = clRed;
  367. }
  368. }
  369. }
  370. //---------------------------------------------------------------------------
  371. void __fastcall TCRSM000M::Col21CustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
  372. bool &ADone)
  373. {
  374. try
  375. {
  376. TColor tBrush = ACanvas->Brush->Color;
  377. TColor tFont = ACanvas->Font->Color;
  378. String sValue = AViewInfo->GridRecord->DisplayTexts[AViewInfo->Item->Index];
  379. if (sValue != "-" && sValue.ToIntDef(0) > g_AppCfg.Temp.AlarmValue)
  380. {
  381. tBrush = clFuchsia;
  382. tFont = clWhite;
  383. }
  384. ACanvas->SetBrushColor(tBrush);
  385. ACanvas->Font->Color = tFont;
  386. }
  387. catch(Exception &e)
  388. {
  389. }
  390. }
  391. //---------------------------------------------------------------------------