VMSM010MF.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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 "VMSM010MF.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. TVMSM010M *VMSM010M = NULL;
  42. //---------------------------------------------------------------------------
  43. __fastcall TVMSM010M::TVMSM010M(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 TVMSM010M::CommClose()
  54. {
  55. try
  56. {
  57. CMM_SaveForm(g_sFormsDir, this);
  58. }
  59. catch(...)
  60. {
  61. }
  62. }
  63. //---------------------------------------------------------------------------
  64. void __fastcall TVMSM010M::FormCreate(TObject *Sender)
  65. {
  66. //
  67. }
  68. //---------------------------------------------------------------------------
  69. void __fastcall TVMSM010M::FormShow(TObject *Sender)
  70. {
  71. Refresh();
  72. Application->ProcessMessages();
  73. TmrShow->Enabled = true;
  74. }
  75. //---------------------------------------------------------------------------
  76. void __fastcall TVMSM010M::LoadLocalSkin()
  77. {
  78. }
  79. //---------------------------------------------------------------------------
  80. void __fastcall TVMSM010M::TmrShowTimer(TObject *Sender)
  81. {
  82. TmrShow->Enabled = false;
  83. BtnSearchClick(NULL);
  84. }
  85. //---------------------------------------------------------------------------
  86. void __fastcall TVMSM010M::FormClose(TObject *Sender, TCloseAction &Action)
  87. {
  88. try {
  89. CommClose();
  90. VMSM010M = NULL;
  91. Action = caFree;
  92. } catch(...) {}
  93. }
  94. //---------------------------------------------------------------------------
  95. void __fastcall TVMSM010M::OnMainFormMessage(TMessage &Msg)
  96. {
  97. }
  98. //---------------------------------------------------------------------------
  99. void __fastcall TVMSM010M::Refreshtatus(bool ARealtime/*=false*/)
  100. {
  101. String sQry;
  102. TADOQuery *pADO = NULL;
  103. sQry = "SELECT X.VMS_CTLR_NMBR, X.VMS_CTLR_ID, X.VMS_NM, T.VMS_TYPE_NM, X.OPER_MODE, \r\n"
  104. " Y.UPDT_DT, Y.CMNC_STTS_CD, Y.PWER_STTS_CD, Y.MODL_STTS_CD, \r\n"
  105. " Y.CBOX_DOOR_STTS_CD, Y.FAN_STTS_CD, Y.HETR_STTS_CD, Y.CBOX_TMPR, \r\n"
  106. " Z.SVC_DT, Z.MSG_CNT, \r\n"
  107. " (CASE WHEN Y.UPDT_DT <= TO_CHAR(SYSDATE - 5/1440, 'YYYYMMDDHH24MISS') \r\n"
  108. " THEN 'Y' ELSE 'N' END) AS COMMERR \r\n"
  109. " FROM TB_VMS_TYPE T, \r\n"
  110. " TB_VMS_CTLR X, \r\n"
  111. " TB_VMS_CTLR_STTS Y, \r\n"
  112. " (SELECT A.VMS_CTLR_NMBR, \r\n"
  113. " TO_CHAR(SYSDATE - 8/1440, 'YYYYMMDDHH24MISS') AS SVC_DT, \r\n"
  114. " COUNT(1) AS MSG_CNT \r\n"
  115. " FROM TB_VMS_DSPL_PRST A, \r\n"
  116. " (SELECT VMS_CTLR_NMBR, MAX(DSPL_DT) AS DSPL_DT \r\n"
  117. " FROM TB_VMS_DSPL_PRST \r\n"
  118. " GROUP BY VMS_CTLR_NMBR) B \r\n"
  119. " WHERE A.VMS_CTLR_NMBR = B.VMS_CTLR_NMBR \r\n"
  120. " AND A.DSPL_DT = B.DSPL_DT \r\n"
  121. " GROUP BY A.VMS_CTLR_NMBR) Z \r\n"
  122. " WHERE T.VMS_TYPE_CD = X.VMS_TYPE_CD \r\n"
  123. " AND X.VMS_CTLR_NMBR = Y.VMS_CTLR_NMBR \r\n"
  124. " AND Y.VMS_CTLR_NMBR = Z.VMS_CTLR_NMBR \r\n"
  125. " ORDER BY X.VMS_CTLR_NMBR \r\n";
  126. // " AND Y.UPDT_DT >= TO_CHAR(SYSDATE-2/1440, 'YYYYMMDDHH24MISS') \r\n"
  127. CMM_ClearGridTableView(TvList);
  128. try
  129. {
  130. int nRow;
  131. TvList->BeginUpdate();
  132. try
  133. {
  134. pADO = new TADOQuery(NULL);
  135. pADO->Close();
  136. pADO->Connection = ITSDb_GetConnection();
  137. pADO->SQL->Clear();
  138. pADO->SQL->Text = sQry;
  139. pADO->Prepared = true;
  140. pADO->Open();
  141. for( ; !pADO->Eof; pADO->Next())
  142. {
  143. nRow = TvList->DataController->AppendRecord();
  144. TvList->DataController->Values[nRow][ColNmbr->Index] = pADO->FieldByName("VMS_CTLR_NMBR")->AsInteger;
  145. TvList->DataController->Values[nRow][ColId->Index] = pADO->FieldByName("VMS_CTLR_ID")->AsString;
  146. TvList->DataController->Values[nRow][ColName->Index] = pADO->FieldByName("VMS_NM")->AsString;
  147. TvList->DataController->Values[nRow][ColCtrlS->Index] = pADO->FieldByName("COMMERR")->AsString;
  148. TvList->DataController->Values[nRow][ColTypeNm->Index] = pADO->FieldByName("VMS_TYPE_NM")->AsString;
  149. String OperMode = pADO->FieldByName("OPER_MODE")->AsString;
  150. TvList->DataController->Values[nRow][ColOperMode->Index] = OperMode == "A" ? "자동" : "수동";
  151. TvList->DataController->Values[nRow][ColMsgDt->Index] = pADO->FieldByName("SVC_DT")->AsString;
  152. TvList->DataController->Values[nRow][ColMsgCnt->Index] = pADO->FieldByName("MSG_CNT")->AsString;
  153. String UPDT_DT = pADO->FieldByName("UPDT_DT")->AsString;
  154. if (UPDT_DT != "")
  155. {
  156. TvList->DataController->Values[nRow][ColUpdtDt->Index] = ITSUtil_StrToDateTime(UPDT_DT).FormatString(STR_DATETIME);
  157. //모듈전원상태
  158. String sModl = pADO->FieldByName("MODL_STTS_CD")->AsString;
  159. if (sModl == "MOS0") TvList->DataController->Values[nRow][ColPower->Index] = lblPWS0->Caption;//"켜짐";
  160. else if (sModl == "MOS1") TvList->DataController->Values[nRow][ColPower->Index] = lblPWS1->Caption;//"꺼짐";
  161. else TvList->DataController->Values[nRow][ColPower->Index] = "?";
  162. //전광판
  163. String sModlOnOff = pADO->FieldByName("PWER_STTS_CD")->AsString;
  164. if (sModlOnOff == "MOS0") TvList->DataController->Values[nRow][ColModule->Index] = lblPWS0->Caption;//"켜짐";
  165. else if (sModlOnOff == "MOS1") TvList->DataController->Values[nRow][ColModule->Index] = lblPWS1->Caption;//"꺼짐";
  166. else TvList->DataController->Values[nRow][ColModule->Index] = "?";
  167. String CMNC_STTS_CD = pADO->FieldByName("CMNC_STTS_CD")->AsString;
  168. if (CMNC_STTS_CD == "CMS0") TvList->DataController->Values[nRow][ColCommS->Index] = lblMOS0->Caption;
  169. else
  170. if (CMNC_STTS_CD == "CMS1") TvList->DataController->Values[nRow][ColCommS->Index] = lblMOS1->Caption;
  171. else TvList->DataController->Values[nRow][ColCommS->Index] = lblUnknown->Caption;
  172. //도어
  173. String sDoor = pADO->FieldByName("CBOX_DOOR_STTS_CD")->AsString;
  174. if (sDoor == "CDS0") TvList->DataController->Values[nRow][ColDoorS->Index] = lblCDS0->Caption;//"닫힘";
  175. else if (sDoor == "CDS1") TvList->DataController->Values[nRow][ColDoorS->Index] = lblCDS1->Caption;//"열림";
  176. else TvList->DataController->Values[nRow][ColDoorS->Index] = lblUnknown->Caption;
  177. //팬상태
  178. String sFans = pADO->FieldByName("FAN_STTS_CD")->AsString;
  179. if (sFans == "PAS0") TvList->DataController->Values[nRow][ColFanS->Index] = lblPAS0->Caption;//"동작";
  180. else if (sFans == "PAS1") TvList->DataController->Values[nRow][ColFanS->Index] = lblPAS1->Caption;//"정지";
  181. else TvList->DataController->Values[nRow][ColFanS->Index] = lblUnknown->Caption;
  182. //히터상태
  183. String sHets = pADO->FieldByName("HETR_STTS_CD")->AsString;
  184. if (sHets == "HTS0") TvList->DataController->Values[nRow][ColHeaterS->Index] = lblHTS0->Caption;//"가동";
  185. else if (sHets == "HTS1") TvList->DataController->Values[nRow][ColHeaterS->Index] = lblHTS1->Caption;//"중지";
  186. else TvList->DataController->Values[nRow][ColHeaterS->Index] = lblUnknown->Caption;
  187. //온도
  188. TvList->DataController->Values[nRow][ColTemp->Index] = pADO->FieldByName("CBOX_TMPR")->AsString;
  189. }
  190. else
  191. {
  192. TvList->DataController->Values[nRow][ColUpdtDt->Index] = lblUnknown->Caption;
  193. TvList->DataController->Values[nRow][ColCommS->Index] = lblUnknown->Caption;
  194. TvList->DataController->Values[nRow][ColDoorS->Index] = lblUnknown->Caption;
  195. TvList->DataController->Values[nRow][ColFanS->Index] = lblUnknown->Caption;
  196. TvList->DataController->Values[nRow][ColHeaterS->Index] = lblUnknown->Caption;
  197. TvList->DataController->Values[nRow][ColTemp->Index] = lblUnknown->Caption;
  198. TvList->DataController->Values[nRow][ColCtrlS->Index] = "Y";
  199. }
  200. }
  201. }
  202. catch(EDatabaseError &E)
  203. {
  204. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  205. DBERRORMSG("TVMSM010M::Refreshtatus", String(E.ClassName()), E.Message, sQry);
  206. throw Exception(String(E.ClassName()) + E.Message);
  207. }
  208. catch(Exception &exception)
  209. {
  210. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  211. DBERRORMSG("TVMSM010M::Refreshtatus", String(exception.ClassName()), exception.Message, sQry);
  212. throw Exception(String(exception.ClassName()) + exception.Message);
  213. }
  214. }
  215. __finally
  216. {
  217. if (pADO)
  218. {
  219. pADO->Close();
  220. delete pADO;
  221. }
  222. TvList->EndUpdate();
  223. }
  224. }
  225. //---------------------------------------------------------------------------
  226. void __fastcall TVMSM010M::RefreshData()
  227. {
  228. try
  229. {
  230. LockWindowUpdate(Handle);
  231. Refreshtatus();
  232. }
  233. __finally
  234. {
  235. LockWindowUpdate(0);
  236. }
  237. }
  238. //---------------------------------------------------------------------------
  239. void __fastcall TVMSM010M::BtnSearchClick(TObject *Sender)
  240. {
  241. RefreshData();
  242. }
  243. //---------------------------------------------------------------------------
  244. void __fastcall TVMSM010M::ColCommSCustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
  245. bool &ADone)
  246. {
  247. TColor tColor = ACanvas->Brush->Color;
  248. TColor tFont = clBlack;
  249. try
  250. {
  251. TColor tColor;
  252. String sStatus = AViewInfo->GridRecord->DisplayTexts[AViewInfo->Item->Index];
  253. tColor = ACanvas->Brush->Color;
  254. if (sStatus.Pos(lblUnknown->Caption)) tColor = clGray;
  255. else if (sStatus.Pos(lblMOS1->Caption)) tColor = clRed;
  256. else if (sStatus.Pos(lblCDS1->Caption)) tColor = clYellow;
  257. else if (sStatus.Pos(lblPAS0->Caption)) tColor = clYellow;
  258. else if (sStatus.Pos(lblHTS0->Caption)) tColor = clYellow;
  259. else if (sStatus.Pos(lblPWS0->Caption)) tColor = clLime;
  260. else if (sStatus.Pos(lblPWS1->Caption)) tColor = clRed;
  261. //else if (sStatus.Pos("0")) tColor = clRed;
  262. else tColor = clLime;
  263. ACanvas->SetBrushColor(tColor);
  264. if (tColor == clRed) tFont = clWhite;
  265. ACanvas->Font->Color = tFont;
  266. }
  267. catch(Exception &e)
  268. {
  269. }
  270. }
  271. //---------------------------------------------------------------------------
  272. void __fastcall TVMSM010M::BtnCloseClick(TObject *Sender)
  273. {
  274. Close();
  275. }
  276. //---------------------------------------------------------------------------
  277. void __fastcall TVMSM010M::ColOperModeCustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
  278. bool &ADone)
  279. {
  280. try
  281. {
  282. TColor tColor;
  283. String sVmsMode = AViewInfo->GridRecord->DisplayTexts[AViewInfo->Item->Index];
  284. tColor = ACanvas->Brush->Color;
  285. #if 1
  286. if (sVmsMode == "자동") tColor = clLime;
  287. else if (sVmsMode == "고정") tColor = clFuchsia;
  288. else tColor = clYellow;
  289. #else
  290. if (sVmsMode == FrmLang->lblOperA->Caption.Trim()) tColor = clLime;
  291. else if (sVmsMode == FrmLang->lblOperF->Caption.Trim()) tColor = clFuchsia;
  292. else tColor = clYellow;
  293. #endif
  294. ACanvas->SetBrushColor(tColor);
  295. ACanvas->Font->Color = clBlack;
  296. }
  297. catch(Exception &e)
  298. {
  299. }
  300. #if 0
  301. int nRecordIdx = AViewInfo->GridRecord->RecordIndex;
  302. if (nRecordIdx >= 0)
  303. {
  304. int nIdx = AViewInfo->Item->Index;
  305. String sVmsMode = AViewInfo->GridRecord->DisplayTexts[nIdx];
  306. if (sVmsMode == "고정") ACanvas->Canvas->Brush->Color = clLime;
  307. }
  308. #endif
  309. }
  310. //---------------------------------------------------------------------------
  311. void __fastcall TVMSM010M::ColTempCustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
  312. bool &ADone)
  313. {
  314. try
  315. {
  316. TColor tBrush = ACanvas->Brush->Color;
  317. TColor tFont = ACanvas->Font->Color;
  318. String sValue = AViewInfo->GridRecord->DisplayTexts[AViewInfo->Item->Index];
  319. if (sValue != "-" && sValue.ToIntDef(0) > g_AppCfg.Temp.AlarmValue)
  320. {
  321. tBrush = clFuchsia;
  322. tFont = clWhite;
  323. }
  324. ACanvas->SetBrushColor(tBrush);
  325. ACanvas->Font->Color = tFont;
  326. }
  327. catch(Exception &e)
  328. {
  329. }
  330. }
  331. //---------------------------------------------------------------------------