FrmFacilityAlarmF.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "ITSSkinF.h"
  4. #include "ITSUtilF.h"
  5. #include "ITSDbF.h"
  6. #include "AppGlobalF.h"
  7. #include "ITSLangTransF.h"
  8. #include "ITS_OPLibF.h"
  9. #pragma hdrstop
  10. #include "WindowMsgF.h"
  11. #include "FrmFacilityAlarmF.h"
  12. #include "FrmLinkGradeSetF.h"
  13. #include "CDSNodeF.h"
  14. #include "CDSLinkF.h"
  15. #include "CDSIfscF.h"
  16. #include "CDSRoadF.h"
  17. #include "CDSTrafficGradeF.h"
  18. //---------------------------------------------------------------------------
  19. #pragma package(smart_init)
  20. #pragma link "cxCalc"
  21. #pragma link "cxCheckBox"
  22. #pragma link "cxClasses"
  23. #pragma link "cxContainer"
  24. #pragma link "cxControls"
  25. #pragma link "cxCustomData"
  26. #pragma link "cxData"
  27. #pragma link "cxDataStorage"
  28. #pragma link "cxEdit"
  29. #pragma link "cxFilter"
  30. #pragma link "cxGraphics"
  31. #pragma link "cxGrid"
  32. #pragma link "cxGridCustomTableView"
  33. #pragma link "cxGridCustomView"
  34. #pragma link "cxGridLevel"
  35. #pragma link "cxGridTableView"
  36. #pragma link "cxLabel"
  37. #pragma link "cxLookAndFeelPainters"
  38. #pragma link "cxLookAndFeels"
  39. #pragma link "cxStyles"
  40. #pragma link "cxTextEdit"
  41. #pragma link "dxSkinBlack"
  42. #pragma link "dxSkinBlue"
  43. #pragma link "dxSkinsCore"
  44. #pragma link "dxSkinscxPCPainter"
  45. #pragma link "dxSkinMcSkin"
  46. #pragma resource "*.dfm"
  47. TFrmFacilityAlarm *FrmFacilityAlarm = NULL;
  48. //---------------------------------------------------------------------------
  49. __fastcall TFrmFacilityAlarm::TFrmFacilityAlarm(TComponent* Owner)
  50. : TForm(Owner)
  51. {
  52. Width = 330;
  53. Height= 340;
  54. int nHeight = Height;
  55. int nWidth = Width;
  56. LangTrans->Translate(this, ITSDb_GetConnection());
  57. ITSSkin_Load(this);
  58. CMM_LoadForm(g_sFormsDir, this);
  59. Caption = lblCaption->Caption;//" 시설물 알람";
  60. m_sLinkId = "";
  61. m_nLinkLevel = 0;
  62. }
  63. //---------------------------------------------------------------------------
  64. void __fastcall TFrmFacilityAlarm::FormClose(TObject *Sender, TCloseAction &Action)
  65. {
  66. TmrTimeOut->Enabled = false;
  67. try
  68. {
  69. CMM_SaveForm(g_sFormsDir, this);
  70. }
  71. catch(...)
  72. {
  73. }
  74. Action = caFree;
  75. FrmFacilityAlarm = NULL;
  76. }
  77. //---------------------------------------------------------------------------
  78. void __fastcall TFrmFacilityAlarm::ShowDsrcAlarm()
  79. {
  80. TcxDataController *m_pGDC;
  81. m_pGDC = TvList->DataController;
  82. int nRow = 0;
  83. try
  84. {
  85. TvList->BeginUpdate();
  86. TItsSubCode *pSubCode;
  87. try
  88. {
  89. ItsFacilityManager->FLists.Lock();
  90. FOR_STL(TItsFacility*, pFacility, ItsFacilityManager->FLists)
  91. {
  92. if (pFacility->DEL_YN == "Y") continue;
  93. if (pFacility->FCLT_TYPE != "DSRC") continue;
  94. if (pFacility->FCollCntBase <= pFacility->FCollCntCurr) continue;
  95. nRow = m_pGDC->AppendRecord();
  96. m_pGDC->Values[nRow][Column01->Index] = pFacility->FCLT_TYPE;
  97. if (pFacility->FCLT_TYPE == "PARK")
  98. m_pGDC->Values[nRow][Column11->Index] = "주차장";
  99. else
  100. if (pFacility->FCLT_TYPE == "CCAM")
  101. m_pGDC->Values[nRow][Column11->Index] = "교차로감시";
  102. else
  103. if (pFacility->FCLT_TYPE == "ICAM")
  104. m_pGDC->Values[nRow][Column11->Index] = "돌발상황감시";
  105. else
  106. if (pFacility->FCLT_TYPE == "WCAM")
  107. m_pGDC->Values[nRow][Column11->Index] = "CCTV(웹카메라)";
  108. else
  109. if (pFacility->FCLT_TYPE == "VDS")
  110. {
  111. if (pFacility->FCLT_KIND == "C")
  112. {
  113. m_pGDC->Values[nRow][Column01->Index] = "CRSSVR";
  114. m_pGDC->Values[nRow][Column11->Index] = "교차로분석서버";
  115. }
  116. else
  117. m_pGDC->Values[nRow][Column11->Index] = pFacility->FCLT_TYPE;
  118. }
  119. else
  120. m_pGDC->Values[nRow][Column11->Index] = pFacility->FCLT_TYPE;
  121. m_pGDC->Values[nRow][Column02->Index] = pFacility->FCLT_ID;
  122. m_pGDC->Values[nRow][Column03->Index] = pFacility->FCLT_LCTN;
  123. String sComm = FrmLang->lblClctErr->Caption;//"수집이상";
  124. m_pGDC->Values[nRow][Column04->Index] = sComm;
  125. m_pGDC->Values[nRow][Column05->Index] = pFacility->FDoor;
  126. m_pGDC->Values[nRow][Column06->Index] = "3";//pFacility->FComm;
  127. m_pGDC->Values[nRow][Column07->Index] = pFacility->FDoorStatus;
  128. m_pGDC->Values[nRow][Column08->Index] = String(pFacility->FCollCntCurr);
  129. //m_pGDC->Values[nRow][Column99->Index] = 0;
  130. }
  131. }
  132. __finally
  133. {
  134. ItsFacilityManager->FLists.UnLock();
  135. }
  136. }
  137. __finally
  138. {
  139. TvList->EndUpdate();
  140. TvList->DataController->GotoFirst();
  141. TvList->DataController->FocusedRecordIndex = 0;
  142. }
  143. }
  144. //---------------------------------------------------------------------------
  145. void __fastcall TFrmFacilityAlarm::ShowFacilityAlarm()
  146. {
  147. TmrTimeOut->Enabled = false;
  148. CMM_ClearGridTableView(TvList);
  149. #ifdef USE_DSRC
  150. //ShowDsrcAlarm();
  151. #endif
  152. TItsLayer *pLayer;
  153. TcxDataController *m_pGDC;
  154. m_pGDC = TvList->DataController;
  155. int nRow = 0;
  156. try
  157. {
  158. TvList->BeginUpdate();
  159. TItsSubCode *pSubCode;
  160. try
  161. {
  162. ItsFacilityManager->FLists.Lock();
  163. FOR_STL(TItsFacility*, pFacility, ItsFacilityManager->FLists)
  164. {
  165. if (pFacility->DEL_YN == "Y") continue;
  166. bool bAlarm = false;
  167. String sComm = FrmLang->lblComm0->Caption;//"정상";
  168. String sAlarm = "";
  169. if (pFacility->FComm == str_state_sensor)
  170. {
  171. sComm = "센서이상";
  172. sAlarm = "2";
  173. bAlarm = true;
  174. }
  175. else
  176. if (pFacility->FComm != str_state_normal)
  177. {
  178. sComm = FrmLang->lblComm1->Caption;//"통신이상";
  179. sAlarm = "1";
  180. bAlarm = true;
  181. }
  182. else
  183. {
  184. if (!bAlarm && pFacility->FDoor != str_state_normal)
  185. {
  186. sComm = "도어열림";
  187. sAlarm = "2";
  188. bAlarm = true;
  189. }
  190. if (!bAlarm && pFacility->FCBoxTmpr > g_AppCfg.Temp.AlarmValue)
  191. {
  192. sComm = "온도이상";
  193. sAlarm = "3";
  194. bAlarm = true;
  195. }
  196. if (!bAlarm && pFacility->FCLT_TYPE == "VMS")
  197. {
  198. if (pFacility->Sts01 != str_state_normal || pFacility->Sts02 != str_state_normal)
  199. {
  200. sComm = "전광판/전원꺼짐";
  201. sAlarm = "4";
  202. bAlarm = true;
  203. }
  204. }
  205. if (!bAlarm && pFacility->FCLT_TYPE == "VDS")
  206. {
  207. if (pFacility->FCollError)
  208. {
  209. sComm = "수집이상";
  210. sAlarm = "5";
  211. bAlarm = true;
  212. }
  213. }
  214. }
  215. if (!bAlarm)
  216. {
  217. continue;
  218. }
  219. nRow = m_pGDC->AppendRecord();
  220. pLayer = ItsLayerManager->FLists.Find(pFacility->FCLT_TYPE);
  221. if (pLayer)
  222. {
  223. m_pGDC->Values[nRow][Column11->Index] = pLayer->Name; // FCLT_TYPE VARCHAR(7 BYTE) NOT NULL, '시설물유형';
  224. }
  225. else
  226. {
  227. m_pGDC->Values[nRow][Column11->Index] = pFacility->FCLT_TYPE; // FCLT_TYPE VARCHAR(7 BYTE) NOT NULL, '시설물유형';
  228. }
  229. m_pGDC->Values[nRow][Column01->Index] = pFacility->FCLT_TYPE;
  230. m_pGDC->Values[nRow][Column02->Index] = pFacility->FCLT_ID;
  231. m_pGDC->Values[nRow][Column03->Index] = pFacility->FCLT_LCTN;
  232. m_pGDC->Values[nRow][Column04->Index] = sComm;
  233. m_pGDC->Values[nRow][Column06->Index] = sAlarm;
  234. //m_pGDC->Values[nRow][Column05->Index] = pFacility->FDoor;
  235. //m_pGDC->Values[nRow][Column06->Index] = pFacility->FComm;
  236. //m_pGDC->Values[nRow][Column07->Index] = pFacility->FDoorStatus;
  237. m_pGDC->Values[nRow][Column08->Index] = pFacility->FCBoxTmpr;
  238. //m_pGDC->Values[nRow][Column99->Index] = 0;
  239. }
  240. }
  241. __finally
  242. {
  243. ItsFacilityManager->FLists.UnLock();
  244. }
  245. }
  246. __finally
  247. {
  248. TvList->EndUpdate();
  249. TvList->DataController->GotoFirst();
  250. TvList->DataController->FocusedRecordIndex = 0;
  251. }
  252. TmrTimeOut->Interval = g_AppCfg.Alarm.TimeOut * 1000;
  253. TmrTimeOut->Enabled = true;
  254. }
  255. //---------------------------------------------------------------------------
  256. void __fastcall TFrmFacilityAlarm::Column04CustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
  257. bool &ADone)
  258. {
  259. if (AViewInfo->GridRecord->RecordIndex < 0) return;
  260. Graphics::TBitmap *pBmp = NULL;
  261. pBmp = ImgState1->Picture->Bitmap;
  262. if (!VarIsNull(AViewInfo->GridRecord->DisplayTexts[Column06->Index]))
  263. {
  264. String sCode = AViewInfo->GridRecord->DisplayTexts[Column06->Index];
  265. if (sCode == "1") pBmp = ImgState1->Picture->Bitmap;
  266. else if (sCode == "2") pBmp = ImgState2->Picture->Bitmap;
  267. else if (sCode == "3") pBmp = ImgState3->Picture->Bitmap;
  268. else if (sCode == "4") pBmp = ImgState4->Picture->Bitmap;
  269. else pBmp = ImgState5->Picture->Bitmap;
  270. }
  271. if (!pBmp) return;
  272. pBmp->Transparent = true;
  273. int nW, nH;
  274. nW = nH = 21;
  275. try
  276. {
  277. TColor bBrush = ACanvas->Brush->Color;
  278. if (AViewInfo->GridRecord->Selected)
  279. {
  280. if (AViewInfo->GridRecord->Index % 2 == 0)
  281. {
  282. bBrush = Sender->LookAndFeelPainter->DefaultContentEvenColor();
  283. }
  284. else
  285. {
  286. bBrush = Sender->LookAndFeelPainter->DefaultContentOddColor();
  287. }
  288. }
  289. ACanvas->Brush->Color = bBrush;
  290. TRect rc;
  291. TRect rcOrg = AViewInfo->Bounds;
  292. ACanvas->FillRect(rcOrg);
  293. nW = rcOrg.Bottom - rcOrg.Top - 2;
  294. rc.Top = rcOrg.Top+1;
  295. rc.Bottom = rcOrg.Bottom - 1;
  296. rc.Left = rcOrg.Left + (rcOrg.Width() - nW) / 2;
  297. rc.Right = rc.Left + nW;
  298. ACanvas->Canvas->StretchDraw(rc, pBmp);
  299. //ACanvas->Draw(AViewInfo->ContentBounds.Left, AViewInfo->ContentBounds.Top, pBmp);
  300. ADone = true;
  301. }
  302. catch(...) {}
  303. }
  304. //---------------------------------------------------------------------------
  305. void __fastcall TFrmFacilityAlarm::TmrTimeOutTimer(TObject *Sender)
  306. {
  307. TmrTimeOut->Enabled = false;
  308. if (!g_AppCfg.Alarm.Window)
  309. {
  310. Close();
  311. }
  312. }
  313. //---------------------------------------------------------------------------
  314. void __fastcall TFrmFacilityAlarm::FormShow(TObject *Sender)
  315. {
  316. chkViewAlway->Checked = g_AppCfg.Alarm.Window;
  317. }
  318. //---------------------------------------------------------------------------
  319. void __fastcall TFrmFacilityAlarm::chkViewAlwayClick(TObject *Sender)
  320. {
  321. g_AppCfg.Alarm.Window = chkViewAlway->Checked;
  322. String sWindow = g_AppCfg.Alarm.Window ? "1" : "0";
  323. WriteConfigInfo(g_AppCfg.sConfigFile, "ALARM", "WINDOW", sWindow);
  324. }
  325. //---------------------------------------------------------------------------