CTVM010MF.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "AppGlobalF.h"
  4. #include "ITSSkinF.h"
  5. #include "ITSUtilF.h"
  6. #include "ITSLangTransF.h"
  7. #include "ITS_OPLibF.h"
  8. #pragma hdrstop
  9. #include "CTVM010MF.h"
  10. //---------------------------------------------------------------------------
  11. #pragma package(smart_init)
  12. #pragma link "cxButtons"
  13. #pragma link "cxClasses"
  14. #pragma link "cxContainer"
  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 "cxGridBandedTableView"
  24. #pragma link "cxGridCustomTableView"
  25. #pragma link "cxGridCustomView"
  26. #pragma link "cxGridLevel"
  27. #pragma link "cxGridTableView"
  28. #pragma link "cxGroupBox"
  29. #pragma link "cxLabel"
  30. #pragma link "cxLookAndFeelPainters"
  31. #pragma link "cxLookAndFeels"
  32. #pragma link "cxStyles"
  33. #pragma link "cxTextEdit"
  34. #pragma link "dxSkinBlue"
  35. #pragma link "dxSkinsCore"
  36. #pragma link "dxSkinscxPCPainter"
  37. #pragma link "dxSkinBlack"
  38. #pragma link "dxSkinMcSkin"
  39. #pragma link "cxSpinEdit"
  40. #pragma resource "*.dfm"
  41. TCTVM010M *CTVM010M = NULL;
  42. //---------------------------------------------------------------------------
  43. __fastcall TCTVM010M::TCTVM010M(TComponent* Owner)
  44. : TForm(Owner)
  45. {
  46. LangTrans->Translate(this, ITSDb_GetConnection());
  47. ITSSkin_Load(this);
  48. LoadLocalSkin();
  49. FTitle = Caption;
  50. CMM_LoadForm(g_sFormsDir, this);
  51. }
  52. //---------------------------------------------------------------------------
  53. void __fastcall TCTVM010M::CommClose()
  54. {
  55. try
  56. {
  57. CMM_SaveForm(g_sFormsDir, this);
  58. }
  59. catch(...)
  60. {
  61. }
  62. }
  63. //---------------------------------------------------------------------------
  64. void __fastcall TCTVM010M::FormCreate(TObject *Sender)
  65. {
  66. //
  67. }
  68. //---------------------------------------------------------------------------
  69. void __fastcall TCTVM010M::FormShow(TObject *Sender)
  70. {
  71. Refresh();
  72. Application->ProcessMessages();
  73. TmrShow->Enabled = true;
  74. }
  75. //---------------------------------------------------------------------------
  76. void __fastcall TCTVM010M::LoadLocalSkin()
  77. {
  78. }
  79. //---------------------------------------------------------------------------
  80. void __fastcall TCTVM010M::TmrShowTimer(TObject *Sender)
  81. {
  82. TmrShow->Enabled = false;
  83. BtnSearchClick(NULL);
  84. }
  85. //---------------------------------------------------------------------------
  86. void __fastcall TCTVM010M::FormClose(TObject *Sender, TCloseAction &Action)
  87. {
  88. try {
  89. CommClose();
  90. CTVM010M = NULL;
  91. Action = caFree;
  92. } catch(...) {}
  93. }
  94. //---------------------------------------------------------------------------
  95. void __fastcall TCTVM010M::OnMainFormMessage(TMessage &Msg)
  96. {
  97. }
  98. //---------------------------------------------------------------------------
  99. void __fastcall TCTVM010M::Refreshtatus(bool ARealtime/*=false*/)
  100. {
  101. String sQry;
  102. TADOQuery *pADO = NULL;
  103. sQry = "SELECT B.CCTV_MNGM_NMBR AS CCTV_CTLR_NMBR, B.CCTV_CTLR_ID, B.ISTL_LCTN_NM, \r\n"
  104. " (CASE WHEN UPDT_DT <= TO_CHAR(SYSDATE - 5/1440, 'YYYYMMDDHH24MISS') \r\n"
  105. " THEN 'Y' ELSE 'N' END) AS COMMERR, \r\n"
  106. " A.*, B.CCTV_TYPE \r\n"
  107. " FROM TB_CCTV_STTS A, TB_CCTV_CTLR B \r\n"
  108. " WHERE A.CCTV_MNGM_NMBR(+) = B.CCTV_MNGM_NMBR \r\n"
  109. //" AND B.CCTV_TYPE = '1' \r\n"
  110. " ORDER BY B.CCTV_MNGM_NMBR \r\n";
  111. // " AND UPDT_DT >= TO_CHAR(SYSDATE-2/1440, 'YYYYMMDDHH24MISS') \r\n"
  112. CMM_ClearGridTableView(TvList);
  113. try
  114. {
  115. int nRow;
  116. TvList->BeginUpdate();
  117. try
  118. {
  119. pADO = new TADOQuery(NULL);
  120. pADO->Close();
  121. pADO->Connection = ITSDb_GetConnection();
  122. pADO->SQL->Clear();
  123. pADO->SQL->Text = sQry;
  124. pADO->Prepared = true;
  125. pADO->Open();
  126. for( ; !pADO->Eof; pADO->Next())
  127. {
  128. nRow = TvList->DataController->AppendRecord();
  129. TvList->DataController->Values[nRow][ColNmbr->Index] = pADO->FieldByName("CCTV_CTLR_NMBR")->AsInteger;
  130. TvList->DataController->Values[nRow][ColId->Index] = pADO->FieldByName("CCTV_CTLR_ID")->AsString;
  131. TvList->DataController->Values[nRow][ColName->Index] = pADO->FieldByName("ISTL_LCTN_NM")->AsString;
  132. TvList->DataController->Values[nRow][ColCtrlS->Index] = pADO->FieldByName("COMMERR")->AsString;
  133. String UPDT_DT = pADO->FieldByName("UPDT_DT")->AsString;
  134. String CCTV_TYPE = pADO->FieldByName("CCTV_TYPE")->AsString;
  135. TvList->DataController->Values[nRow][ColTypeNm->Index] = CCTV_TYPE;
  136. if (UPDT_DT != "")
  137. {
  138. TvList->DataController->Values[nRow][ColUpdtDt->Index] = ITSUtil_StrToDateTime(UPDT_DT).FormatString(STR_DATETIME);
  139. String CMNC_STTS_CD = pADO->FieldByName("CMNC_STTS_CD")->AsString;
  140. if (CMNC_STTS_CD == "CMS0") TvList->DataController->Values[nRow][ColCommS->Index] = lblMOS0->Caption;
  141. else
  142. if (CMNC_STTS_CD == "CMS1") TvList->DataController->Values[nRow][ColCommS->Index] = lblMOS1->Caption;
  143. else TvList->DataController->Values[nRow][ColCommS->Index] = lblUnknown->Caption;
  144. //도어
  145. String sDoor = pADO->FieldByName("CBOX_DOOR_STTS_CD")->AsString;
  146. if (sDoor == "CDS0") TvList->DataController->Values[nRow][ColDoorS->Index] = lblCDS0->Caption;//"닫힘";
  147. else if (sDoor == "CDS1") TvList->DataController->Values[nRow][ColDoorS->Index] = lblCDS1->Caption;//"열림";
  148. else TvList->DataController->Values[nRow][ColDoorS->Index] = lblUnknown->Caption;
  149. //팬상태
  150. String sFans = pADO->FieldByName("FAN_STTS_CD")->AsString;
  151. if (sFans == "PAS0") TvList->DataController->Values[nRow][ColFanS->Index] = lblPAS0->Caption;//"동작";
  152. else if (sFans == "PAS1") TvList->DataController->Values[nRow][ColFanS->Index] = lblPAS1->Caption;//"정지";
  153. else TvList->DataController->Values[nRow][ColFanS->Index] = lblUnknown->Caption;
  154. //히터상태
  155. String sHets = pADO->FieldByName("HETR_STTS_CD")->AsString;
  156. if (sHets == "HTS0") TvList->DataController->Values[nRow][ColHeaterS->Index] = lblHTS0->Caption;//"가동";
  157. else if (sHets == "HTS1") TvList->DataController->Values[nRow][ColHeaterS->Index] = lblHTS1->Caption;//"중지";
  158. else TvList->DataController->Values[nRow][ColHeaterS->Index] = lblUnknown->Caption;
  159. //온도
  160. TvList->DataController->Values[nRow][ColTemp->Index] = pADO->FieldByName("CBOX_TMPR")->AsString;
  161. }
  162. else
  163. {
  164. TvList->DataController->Values[nRow][ColUpdtDt->Index] = lblUnknown->Caption;
  165. TvList->DataController->Values[nRow][ColCommS->Index] = lblUnknown->Caption;
  166. TvList->DataController->Values[nRow][ColDoorS->Index] = lblUnknown->Caption;
  167. TvList->DataController->Values[nRow][ColFanS->Index] = lblUnknown->Caption;
  168. TvList->DataController->Values[nRow][ColHeaterS->Index] = lblUnknown->Caption;
  169. TvList->DataController->Values[nRow][ColTemp->Index] = lblUnknown->Caption;
  170. TvList->DataController->Values[nRow][ColCtrlS->Index] = "Y";
  171. }
  172. if (CCTV_TYPE != "1")
  173. {
  174. TvList->DataController->Values[nRow][ColDoorS->Index] = "-";
  175. TvList->DataController->Values[nRow][ColFanS->Index] = "-";
  176. TvList->DataController->Values[nRow][ColHeaterS->Index] = "-";
  177. TvList->DataController->Values[nRow][ColTemp->Index] = "-";
  178. }
  179. }
  180. }
  181. catch(EDatabaseError &E)
  182. {
  183. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  184. DBERRORMSG("TCTVM010M::Refreshtatus", String(E.ClassName()), E.Message, sQry);
  185. throw Exception(String(E.ClassName()) + E.Message);
  186. }
  187. catch(Exception &exception)
  188. {
  189. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  190. DBERRORMSG("TCTVM010M::Refreshtatus", String(exception.ClassName()), exception.Message, sQry);
  191. throw Exception(String(exception.ClassName()) + exception.Message);
  192. }
  193. }
  194. __finally
  195. {
  196. if (pADO)
  197. {
  198. pADO->Close();
  199. delete pADO;
  200. }
  201. TvList->EndUpdate();
  202. }
  203. }
  204. //---------------------------------------------------------------------------
  205. void __fastcall TCTVM010M::RefreshData()
  206. {
  207. try
  208. {
  209. LockWindowUpdate(Handle);
  210. Refreshtatus();
  211. }
  212. __finally
  213. {
  214. LockWindowUpdate(0);
  215. }
  216. }
  217. //---------------------------------------------------------------------------
  218. void __fastcall TCTVM010M::BtnSearchClick(TObject *Sender)
  219. {
  220. RefreshData();
  221. }
  222. //---------------------------------------------------------------------------
  223. void __fastcall TCTVM010M::ColCommSCustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
  224. bool &ADone)
  225. {
  226. TColor tColor = ACanvas->Brush->Color;
  227. TColor tFont = clBlack;
  228. try
  229. {
  230. TColor tColor;
  231. String sStatus = AViewInfo->GridRecord->DisplayTexts[AViewInfo->Item->Index];
  232. tColor = ACanvas->Brush->Color;
  233. if (sStatus.Pos(lblUnknown->Caption)) tColor = clGray;
  234. else if (sStatus.Pos(lblMOS1->Caption)) tColor = clRed;
  235. else if (sStatus.Pos(lblPWS0->Caption)) tColor = clYellow;
  236. else if (sStatus.Pos(lblCDS1->Caption)) tColor = clYellow;
  237. else if (sStatus.Pos(lblPAS0->Caption)) tColor = clYellow;
  238. else if (sStatus.Pos(lblHTS0->Caption)) tColor = clYellow;
  239. else if (sStatus.Pos("-")) tColor = tColor;
  240. //else if (sStatus.Pos("0")) tColor = clRed;
  241. else tColor = clLime;
  242. ACanvas->SetBrushColor(tColor);
  243. if (tColor == clRed) tFont = clWhite;
  244. ACanvas->Font->Color = tFont;
  245. }
  246. catch(Exception &e)
  247. {
  248. }
  249. }
  250. //---------------------------------------------------------------------------
  251. void __fastcall TCTVM010M::BtnCloseClick(TObject *Sender)
  252. {
  253. Close();
  254. }
  255. //---------------------------------------------------------------------------
  256. void __fastcall TCTVM010M::ColUpdtDtCustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
  257. bool &ADone)
  258. {
  259. TColor tColor = ACanvas->Brush->Color;
  260. TColor tFont = clBlack;
  261. try
  262. {
  263. String sStts = AViewInfo->GridRecord->DisplayTexts[ColCtrlS->Index];
  264. if (sStts == "Y")
  265. {
  266. tColor = clYellow;
  267. }
  268. ACanvas->Font->Color = tFont;
  269. ACanvas->SetBrushColor(tColor);
  270. }
  271. catch(...)
  272. {
  273. }
  274. }
  275. //---------------------------------------------------------------------------
  276. void __fastcall TCTVM010M::ColTempCustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
  277. bool &ADone)
  278. {
  279. try
  280. {
  281. TColor tBrush = ACanvas->Brush->Color;
  282. TColor tFont = ACanvas->Font->Color;
  283. String sValue = AViewInfo->GridRecord->DisplayTexts[AViewInfo->Item->Index];
  284. if (sValue != "-" && sValue.ToIntDef(0) > g_AppCfg.Temp.AlarmValue)
  285. {
  286. tBrush = clFuchsia;
  287. tFont = clWhite;
  288. }
  289. ACanvas->SetBrushColor(tBrush);
  290. ACanvas->Font->Color = tFont;
  291. }
  292. catch(Exception &e)
  293. {
  294. }
  295. }
  296. //---------------------------------------------------------------------------