FRAME_FacilityStatusListF.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "ITSSkinF.h"
  4. #include "ITSUtilF.h"
  5. #include "AppGlobalF.h"
  6. #include "ITSLangTransF.h"
  7. #pragma hdrstop
  8. #include "FRAME_FacilityStatusListF.h"
  9. #include "CDSFacilityF.h"
  10. //---------------------------------------------------------------------------
  11. #pragma package(smart_init)
  12. #pragma link "cxButtons"
  13. #pragma link "cxCalc"
  14. #pragma link "cxClasses"
  15. #pragma link "cxControls"
  16. #pragma link "cxCustomData"
  17. #pragma link "cxData"
  18. #pragma link "cxDataStorage"
  19. #pragma link "cxEdit"
  20. #pragma link "cxFilter"
  21. #pragma link "cxGraphics"
  22. #pragma link "cxGrid"
  23. #pragma link "cxGridCustomTableView"
  24. #pragma link "cxGridCustomView"
  25. #pragma link "cxGridLevel"
  26. #pragma link "cxGridTableView"
  27. #pragma link "cxLabel"
  28. #pragma link "cxLookAndFeelPainters"
  29. #pragma link "cxLookAndFeels"
  30. #pragma link "cxStyles"
  31. #pragma link "cxTextEdit"
  32. #pragma link "dxSkinBlack"
  33. #pragma link "dxSkinBlue"
  34. #pragma link "dxSkinsCore"
  35. #pragma link "dxSkinscxPCPainter"
  36. #pragma link "cxContainer"
  37. #pragma resource "*.dfm"
  38. //TFRAMEFacilityStatusList *FRAMEFacilityStatusList;
  39. #define FAC_STATUS 0
  40. //---------------------------------------------------------------------------
  41. __fastcall TFRAMEFacilityStatusList::TFRAMEFacilityStatusList(TComponent* Owner)
  42. : TFrame(Owner)
  43. {
  44. LangTrans->Translate(this, ITSDb_GetConnection());
  45. m_pGDC = TvList->DataController;
  46. TvList->OptionsView->NoDataToDisplayInfoText = FrmLang->lblNoInfo->Caption;//"<시설물 정보가 없습니다>";
  47. FCodeCMS = ItsCodeManager->FLists.Find("CMS");
  48. FCodeCDS = ItsCodeManager->FLists.Find("CDS");
  49. //Column08->Visible = true;
  50. }
  51. //---------------------------------------------------------------------------
  52. void __fastcall TFRAMEFacilityStatusList::UpdateList()
  53. {
  54. CMM_ClearGridTableView(TvList);
  55. int nRow = 0;
  56. try
  57. {
  58. TvList->BeginUpdate();
  59. TItsSubCode *pSubCode;
  60. try
  61. {
  62. ItsFacilityManager->FLists.Lock();
  63. #if FAC_STATUS
  64. TFacilityStatus *pStatus;
  65. ItsFacilityManager->FListStatus.RemoveAll();
  66. #endif
  67. FOR_STL(TItsFacility*, pFacility, ItsFacilityManager->FLists)
  68. {
  69. pFacility->StatusGridIndex = -1;
  70. if (pFacility->DEL_YN == "Y") continue;
  71. nRow = m_pGDC->AppendRecord();
  72. pFacility->StatusGridIndex = nRow;
  73. m_pGDC->Values[nRow][Column01->Index] = pFacility->FCLT_TYPE;
  74. m_pGDC->Values[nRow][Column02->Index] = pFacility->FCLT_ID;
  75. m_pGDC->Values[nRow][Column03->Index] = pFacility->FCLT_LCTN;
  76. String sComm = FrmLang->lblComm0->Caption;//"정상";
  77. if (pFacility->FComm == state_normal) sComm = FrmLang->lblComm0->Caption;//"정상";
  78. else
  79. if (pFacility->FComm == state_error ) sComm = FrmLang->lblComm1->Caption;//"통신이상";
  80. else
  81. if (pFacility->FComm == state_module) sComm = FrmLang->lblComm2->Caption;//"함체문열림";
  82. else
  83. if (pFacility->FComm == state_collect) sComm = FrmLang->lblClctErr->Caption;//"수집이상";
  84. else sComm = FrmLang->lblUnknown->Caption;//"알수없음";
  85. #if FAC_STATUS
  86. pStatus = ItsFacilityManager->FListStatus.Find(pFacility->FCLT_TYPE);
  87. if (!pStatus)
  88. {
  89. pStatus = new TFacilityStatus();
  90. pStatus->Type = pFacility->FCLT_TYPE;
  91. pStatus->Total = 0;
  92. pStatus->Normal = 0;
  93. pStatus->Error = 0;
  94. pStatus->Collect= 0;
  95. ItsFacilityManager->FListStatus.Push(pFacility->FCLT_TYPE, pStatus);
  96. }
  97. pStatus->Total++; /* 전체 갯수를 증가 시킴 */
  98. if (pFacility->FComm == state_error)
  99. {
  100. pStatus->Error++;
  101. }
  102. else
  103. if (pFacility->FComm == state_module)
  104. {
  105. pStatus->Module++;
  106. }
  107. if (pFacility->FCollError)
  108. {
  109. pStatus->Collect++;
  110. }
  111. #endif
  112. try
  113. {
  114. String sValue = pFacility->FCBoxTmpr;
  115. int nValue = 0;
  116. if (sValue != "-")
  117. {
  118. if (TryStrToInt(sValue, nValue))
  119. {
  120. if (nValue > g_AppCfg.Temp.AlarmValue)
  121. {
  122. sComm = FrmLang->lblHamTemp->Caption;//"함체온도";
  123. }
  124. }
  125. }
  126. } catch(...) {}
  127. m_pGDC->Values[nRow][Column04->Index] = sComm;
  128. m_pGDC->Values[nRow][Column05->Index] = pFacility->FDoor;
  129. m_pGDC->Values[nRow][Column06->Index] = pFacility->FComm;
  130. m_pGDC->Values[nRow][Column07->Index] = pFacility->FDoorStatus;
  131. m_pGDC->Values[nRow][Column08->Index] = pFacility->FCBoxTmpr;
  132. //m_pGDC->Values[nRow][Column99->Index] = 0;
  133. }
  134. }
  135. __finally
  136. {
  137. ItsFacilityManager->FLists.UnLock();
  138. }
  139. }
  140. __finally
  141. {
  142. LblRecords->Caption = "("+FormatFloat("##,##0", m_pGDC->FilteredRecordCount) +"/"+FormatFloat("##,##0", m_pGDC->RecordCount) + ")";
  143. TvList->EndUpdate();
  144. TvList->DataController->GotoFirst();
  145. TvList->DataController->FocusedRecordIndex = 0;
  146. }
  147. }
  148. //---------------------------------------------------------------------------
  149. void __fastcall TFRAMEFacilityStatusList::RefreshList()
  150. {
  151. m_pGDC = TvList->DataController;
  152. int nRow = 0;
  153. try
  154. {
  155. TvList->BeginUpdate();
  156. TItsSubCode *pSubCode;
  157. try
  158. {
  159. ItsFacilityManager->FLists.Lock();
  160. #if FAC_STATUS
  161. TFacilityStatus *pStatus;
  162. ItsFacilityManager->FListStatus.RemoveAll();
  163. #endif
  164. FOR_STL(TItsFacility*, pFacility, ItsFacilityManager->FLists)
  165. {
  166. if (pFacility->DEL_YN == "Y") continue;
  167. if (pFacility->StatusGridIndex < 0) continue;
  168. nRow = pFacility->StatusGridIndex;
  169. m_pGDC->Values[nRow][Column01->Index] = pFacility->FCLT_TYPE;
  170. m_pGDC->Values[nRow][Column02->Index] = pFacility->FCLT_ID;
  171. m_pGDC->Values[nRow][Column03->Index] = pFacility->FCLT_LCTN;
  172. String sComm = FrmLang->lblComm0->Caption;//"정상";
  173. if (pFacility->FComm == state_normal) sComm = FrmLang->lblComm0->Caption;//"정상";
  174. else
  175. if (pFacility->FComm == state_error ) sComm = FrmLang->lblComm1->Caption;//"통신이상";
  176. else
  177. if (pFacility->FComm == state_module) sComm = FrmLang->lblComm2->Caption;//"함체문열림";
  178. else
  179. if (pFacility->FComm == state_collect) sComm = FrmLang->lblClctErr->Caption;//"수집이상";
  180. else sComm = FrmLang->lblUnknown->Caption;//"알수없음";
  181. #if FAC_STATUS
  182. pStatus = ItsFacilityManager->FListStatus.Find(pFacility->FCLT_TYPE);
  183. if (!pStatus)
  184. {
  185. pStatus = new TFacilityStatus();
  186. pStatus->Type = pFacility->FCLT_TYPE;
  187. pStatus->Total = 0;
  188. pStatus->Normal = 0;
  189. pStatus->Error = 0;
  190. pStatus->Collect= 0;
  191. ItsFacilityManager->FListStatus.Push(pFacility->FCLT_TYPE, pStatus);
  192. }
  193. pStatus->Total++; /* 전체 갯수를 증가 시킴 */
  194. if (pFacility->FComm == state_error)
  195. {
  196. pStatus->Error++;
  197. }
  198. else
  199. if (pFacility->FComm == state_module)
  200. {
  201. pStatus->Module++;
  202. }
  203. if (pFacility->FCollError)
  204. {
  205. pStatus->Collect++;
  206. }
  207. #endif
  208. try
  209. {
  210. String sValue = pFacility->FCBoxTmpr;
  211. int nValue = 0;
  212. if (sValue != "-")
  213. {
  214. if (TryStrToInt(sValue, nValue))
  215. {
  216. if (nValue > g_AppCfg.Temp.AlarmValue)
  217. {
  218. sComm = FrmLang->lblHamTemp->Caption;//"함체온도";
  219. }
  220. }
  221. }
  222. } catch(...) {}
  223. m_pGDC->Values[nRow][Column04->Index] = sComm;
  224. m_pGDC->Values[nRow][Column05->Index] = pFacility->FDoor;
  225. m_pGDC->Values[nRow][Column06->Index] = pFacility->FComm;
  226. m_pGDC->Values[nRow][Column07->Index] = pFacility->FDoorStatus;
  227. m_pGDC->Values[nRow][Column08->Index] = pFacility->FCBoxTmpr;
  228. }
  229. }
  230. __finally
  231. {
  232. ItsFacilityManager->FLists.UnLock();
  233. }
  234. }
  235. __finally
  236. {
  237. TvList->EndUpdate();
  238. }
  239. }
  240. //---------------------------------------------------------------------------
  241. void __fastcall TFRAMEFacilityStatusList::TvListDataControllerFilterChanged(TObject *Sender)
  242. {
  243. CMM_SetFilterLike(TvList);
  244. LblRecords->Caption = "("+FormatFloat("##,##0", m_pGDC->FilteredRecordCount) +"/"+FormatFloat("##,##0", m_pGDC->RecordCount) + ")";
  245. }
  246. //---------------------------------------------------------------------------
  247. void __fastcall TFRAMEFacilityStatusList::BtnExlSaveClick(TObject *Sender)
  248. {
  249. TcxGrid *pGrid = CxList;
  250. TcxGridTableView *pView = TvList;
  251. String sTitle= lblFileName->Caption;//"시설물통신상태";
  252. CMM_ExportToExcelFile(sTitle, pGrid, pView, (TForm*)this);
  253. }
  254. //---------------------------------------------------------------------------
  255. void __fastcall TFRAMEFacilityStatusList::Column04CustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
  256. bool &ADone)
  257. {
  258. if (AViewInfo->GridRecord->RecordIndex < 0) return;
  259. Graphics::TBitmap *pBmp = NULL;
  260. pBmp = ImgStop->Picture->Bitmap;
  261. if (!VarIsNull(AViewInfo->GridRecord->DisplayTexts[Column06->Index]))
  262. {
  263. String sCode = AViewInfo->GridRecord->DisplayTexts[Column06->Index];
  264. if (sCode == state_normal) pBmp = ImgState0->Picture->Bitmap;
  265. else if (sCode == state_error ) pBmp = ImgState1->Picture->Bitmap;
  266. else if (sCode == state_module) pBmp = ImgState2->Picture->Bitmap;
  267. else if (sCode == state_collect) pBmp = ImgState3->Picture->Bitmap;
  268. else pBmp = ImgState3->Picture->Bitmap;
  269. if (!VarIsNull(AViewInfo->GridRecord->DisplayTexts[Column08->Index]))
  270. {
  271. String sValue = AViewInfo->GridRecord->DisplayTexts[Column08->Index];
  272. int nValue = 0;
  273. if (TryStrToInt(sValue, nValue))
  274. {
  275. if (nValue > g_AppCfg.Temp.AlarmValue)
  276. {
  277. pBmp = ImgModule->Picture->Bitmap;
  278. }
  279. }
  280. }
  281. }
  282. if (!pBmp) return;
  283. pBmp->Transparent = true;
  284. int nW, nH;
  285. nW = nH = 21;
  286. try
  287. {
  288. TColor bBrush = ACanvas->Brush->Color;
  289. if (AViewInfo->GridRecord->Selected)
  290. {
  291. if (AViewInfo->GridRecord->Index % 2 == 0)
  292. {
  293. bBrush = Sender->LookAndFeelPainter->DefaultContentEvenColor();
  294. }
  295. else
  296. {
  297. bBrush = Sender->LookAndFeelPainter->DefaultContentOddColor();
  298. }
  299. }
  300. ACanvas->Brush->Color = bBrush;
  301. TRect rc;
  302. TRect rcOrg = AViewInfo->Bounds;
  303. ACanvas->FillRect(rcOrg);
  304. nW = rcOrg.Bottom - rcOrg.Top - 4;
  305. rc.Top = rcOrg.Top+2;
  306. rc.Bottom = rcOrg.Bottom - 2;
  307. rc.Left = rcOrg.Left + (rcOrg.Width() - nW) / 2;
  308. rc.Right = rc.Left + nW;
  309. ACanvas->Canvas->StretchDraw(rc, pBmp);
  310. //ACanvas->Draw(AViewInfo->ContentBounds.Left, AViewInfo->ContentBounds.Top, pBmp);
  311. ADone = true;
  312. }
  313. catch(...) {}
  314. }
  315. //---------------------------------------------------------------------------
  316. void __fastcall TFRAMEFacilityStatusList::Column05CustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
  317. bool &ADone)
  318. {
  319. #if 0
  320. if (AViewInfo)
  321. {
  322. String sSatus = AViewInfo->GridRecord->DisplayTexts[Column06->Index];
  323. if (sSatus == "CDS0" )
  324. {
  325. ACanvas->Canvas->Font->Color = clBlue;//clTeal;
  326. }
  327. else if(sSatus == "CDS1" )
  328. {
  329. ACanvas->Canvas->Font->Color = clRed;//clFuchsia;
  330. }
  331. else
  332. {
  333. ACanvas->Canvas->Font->Color = clGray;
  334. }
  335. }
  336. #endif
  337. }
  338. //---------------------------------------------------------------------------
  339. void __fastcall TFRAMEFacilityStatusList::Column08CustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
  340. bool &ADone)
  341. {
  342. if (AViewInfo)
  343. {
  344. if (AViewInfo->GridRecord->RecordIndex < 0) return;
  345. if (VarIsNull(AViewInfo->GridRecord->DisplayTexts[Column08->Index])) return;
  346. String sValue = AViewInfo->GridRecord->DisplayTexts[Column08->Index];
  347. int nValue = 0;
  348. if (TryStrToInt(sValue, nValue))
  349. {
  350. if (nValue > g_AppCfg.Temp.AlarmValue)
  351. {
  352. ACanvas->Canvas->Brush->Color = clFuchsia;
  353. ACanvas->Canvas->Font->Color = clBlack;
  354. }
  355. }
  356. }
  357. }
  358. //---------------------------------------------------------------------------