DSRM050MF.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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 "DSRM050MF.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. TDSRM050M *DSRM050M = NULL;
  42. //---------------------------------------------------------------------------
  43. __fastcall TDSRM050M::TDSRM050M(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 TDSRM050M::CommClose()
  54. {
  55. try
  56. {
  57. CMM_SaveForm(g_sFormsDir, this);
  58. }
  59. catch(...)
  60. {
  61. }
  62. }
  63. //---------------------------------------------------------------------------
  64. void __fastcall TDSRM050M::FormCreate(TObject *Sender)
  65. {
  66. //
  67. }
  68. //---------------------------------------------------------------------------
  69. void __fastcall TDSRM050M::FormShow(TObject *Sender)
  70. {
  71. Refresh();
  72. Application->ProcessMessages();
  73. TmrShow->Enabled = true;
  74. }
  75. //---------------------------------------------------------------------------
  76. void __fastcall TDSRM050M::LoadLocalSkin()
  77. {
  78. }
  79. //---------------------------------------------------------------------------
  80. void __fastcall TDSRM050M::TmrShowTimer(TObject *Sender)
  81. {
  82. TmrShow->Enabled = false;
  83. BtnSearchClick(NULL);
  84. }
  85. //---------------------------------------------------------------------------
  86. void __fastcall TDSRM050M::FormClose(TObject *Sender, TCloseAction &Action)
  87. {
  88. try {
  89. CommClose();
  90. DSRM050M = NULL;
  91. Action = caFree;
  92. } catch(...) {}
  93. }
  94. //---------------------------------------------------------------------------
  95. void __fastcall TDSRM050M::OnMainFormMessage(TMessage &Msg)
  96. {
  97. }
  98. //---------------------------------------------------------------------------
  99. void __fastcall TDSRM050M::Refreshtatus(bool ARealtime/*=false*/)
  100. {
  101. String sQry;
  102. TADOQuery *pADO = NULL;
  103. sQry = "SELECT B.ID AS CTLR_NMBR, B.RSE_ID AS CTLR_ID, B.ISTL_LCTN_NM, \r\n"
  104. " (CASE WHEN CLCT_DT <= TO_CHAR(SYSDATE - 5/1440, 'YYYYMMDDHH24MISS') \r\n"
  105. " THEN 'Y' ELSE 'N' END) AS COMMERR, \r\n"
  106. " A.* \r\n"
  107. " FROM TB_RSE_STTS_PNST A, TB_RSE_MSTR B \r\n"
  108. " WHERE A.ID(+) = B.ID \r\n"
  109. " AND B.DEL_YN = 'N' \r\n"
  110. " ORDER BY B.ID \r\n";
  111. CMM_ClearGridTableView(TvList);
  112. try
  113. {
  114. int nRow;
  115. TvList->BeginUpdate();
  116. try
  117. {
  118. pADO = new TADOQuery(NULL);
  119. pADO->Close();
  120. pADO->Connection = ITSDb_GetConnection();
  121. pADO->SQL->Clear();
  122. pADO->SQL->Text = sQry;
  123. pADO->Prepared = true;
  124. pADO->Open();
  125. for( ; !pADO->Eof; pADO->Next())
  126. {
  127. nRow = TvList->DataController->AppendRecord();
  128. TvList->DataController->Values[nRow][ColNmbr->Index] = pADO->FieldByName("CTLR_NMBR")->AsInteger;
  129. TvList->DataController->Values[nRow][ColId->Index] = pADO->FieldByName("CTLR_ID")->AsString;
  130. TvList->DataController->Values[nRow][ColName->Index] = pADO->FieldByName("ISTL_LCTN_NM")->AsString;
  131. TvList->DataController->Values[nRow][ColCtrlS->Index] = pADO->FieldByName("COMMERR")->AsString;
  132. String CLCT_DT = pADO->FieldByName("CLCT_DT")->AsString;
  133. if (CLCT_DT != "")
  134. {
  135. TvList->DataController->Values[nRow][ColUpdtDt->Index] = ITSUtil_StrToDateTime(CLCT_DT).FormatString(STR_DATETIME);
  136. String sDevcStts = pADO->FieldByName("CNTL_DEVC_STTS")->AsString;
  137. String sCmncStts = pADO->FieldByName("CMNC_STTS")->AsString;
  138. String sAtn1Stts = pADO->FieldByName("ATN_1_STTS")->AsString;
  139. String sAtn2Stts = pADO->FieldByName("ATN_2_STTS")->AsString;
  140. String sAtn3Stts = pADO->FieldByName("ATN_3_STTS")->AsString;
  141. String sAtn4Stts = pADO->FieldByName("ATN_4_STTS")->AsString;
  142. String sAtn1Mtns = pADO->FieldByName("ATN_1_MTNS")->AsString;
  143. if (sCmncStts == "0") sCmncStts = "정상";
  144. else if (sCmncStts == "1") sCmncStts = "장애";
  145. else if (sCmncStts == "2") sCmncStts = "정보 없음";
  146. if (sDevcStts == "0") sDevcStts = "정상";
  147. else if (sDevcStts == "1") sDevcStts = "문열림";
  148. else if (sDevcStts == "2") sDevcStts = "팬동작";
  149. else if (sDevcStts == "3") sDevcStts = "내부온도 이상";
  150. else if (sDevcStts == "4") sDevcStts = "정보 없음";
  151. if (sAtn1Stts == "0") sAtn1Stts = "정상";
  152. else if (sAtn1Stts == "1") sAtn1Stts = "장애";
  153. else if (sAtn1Stts == "2") sAtn1Stts = "정보 없음";
  154. if (sAtn1Mtns == "0") sAtn1Mtns = "송출종료";
  155. else if (sAtn1Mtns == "1") sAtn1Mtns = "송출개시";
  156. else if (sAtn1Mtns == "2") sAtn1Mtns = "유지보수 근무개시";
  157. else if (sAtn1Mtns == "3") sAtn1Mtns = "정보 없음";
  158. if (sCmncStts != "정상")
  159. {
  160. sDevcStts = "?";
  161. sAtn1Stts = "?";
  162. sAtn1Mtns = "?";
  163. }
  164. TvList->DataController->Values[nRow][ColCommS->Index] = sCmncStts;
  165. TvList->DataController->Values[nRow][ColDoorS->Index] = sDevcStts;
  166. TvList->DataController->Values[nRow][ColFanS->Index] = sAtn1Stts;
  167. TvList->DataController->Values[nRow][ColHeaterS->Index] = sAtn1Mtns;
  168. }
  169. else
  170. {
  171. TvList->DataController->Values[nRow][ColUpdtDt->Index] = lblUnknown->Caption;
  172. TvList->DataController->Values[nRow][ColCommS->Index] = lblUnknown->Caption;
  173. TvList->DataController->Values[nRow][ColDoorS->Index] = lblUnknown->Caption;
  174. TvList->DataController->Values[nRow][ColFanS->Index] = lblUnknown->Caption;
  175. TvList->DataController->Values[nRow][ColHeaterS->Index] = lblUnknown->Caption;
  176. TvList->DataController->Values[nRow][ColTemp->Index] = lblUnknown->Caption;
  177. TvList->DataController->Values[nRow][ColCtrlS->Index] = "Y";
  178. }
  179. }
  180. }
  181. catch(EDatabaseError &E)
  182. {
  183. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  184. DBERRORMSG("TDSRM050M::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("TDSRM050M::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 TDSRM050M::RefreshData()
  206. {
  207. try
  208. {
  209. LockWindowUpdate(Handle);
  210. Refreshtatus();
  211. }
  212. __finally
  213. {
  214. LockWindowUpdate(0);
  215. }
  216. }
  217. //---------------------------------------------------------------------------
  218. void __fastcall TDSRM050M::BtnSearchClick(TObject *Sender)
  219. {
  220. RefreshData();
  221. }
  222. //---------------------------------------------------------------------------
  223. void __fastcall TDSRM050M::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 TDSRM050M::BtnCloseClick(TObject *Sender)
  252. {
  253. Close();
  254. }
  255. //---------------------------------------------------------------------------
  256. void __fastcall TDSRM050M::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 TDSRM050M::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. //---------------------------------------------------------------------------