AVIH0101F.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #include "ITSSkinF.h"
  4. #include "ITSUtilF.h"
  5. #include "ITSDbF.h"
  6. #include "AppGlobalF.h"
  7. #include "WindowMsgF.h"
  8. #pragma hdrstop
  9. #include "AVIH0101F.h"
  10. //---------------------------------------------------------------------------
  11. #pragma package(smart_init)
  12. #pragma link "cxButtons"
  13. #pragma link "cxCheckBox"
  14. #pragma link "cxClasses"
  15. #pragma link "cxContainer"
  16. #pragma link "cxControls"
  17. #pragma link "cxCustomData"
  18. #pragma link "cxData"
  19. #pragma link "cxDataStorage"
  20. #pragma link "cxEdit"
  21. #pragma link "cxFilter"
  22. #pragma link "cxGraphics"
  23. #pragma link "cxGrid"
  24. #pragma link "cxGridCustomTableView"
  25. #pragma link "cxGridCustomView"
  26. #pragma link "cxGridLevel"
  27. #pragma link "cxGridTableView"
  28. #pragma link "cxLabel"
  29. #pragma link "cxLookAndFeelPainters"
  30. #pragma link "cxLookAndFeels"
  31. #pragma link "cxStyles"
  32. #pragma link "dxSkinBlack"
  33. #pragma link "dxSkinBlue"
  34. #pragma link "dxSkinsCore"
  35. #pragma link "dxSkinscxPCPainter"
  36. #pragma resource "*.dfm"
  37. TAVIH0101 *AVIH0101 = NULL;
  38. //---------------------------------------------------------------------------
  39. __fastcall TAVIH0101::TAVIH0101(TComponent* Owner, HWND hHandle, String sFrom, String sTo, String sIdList)
  40. : TForm(Owner)
  41. {
  42. ITSSkin_Load(this);
  43. CMM_LoadForm(g_sFormsDir, this);
  44. FParent = hHandle;
  45. FStDateTime = sFrom;
  46. FEdDateTime = sTo;
  47. FIdList = sIdList;
  48. Column10->Visible = true;
  49. Caption = "AVI-제어기 상태 이력";
  50. }
  51. //---------------------------------------------------------------------------
  52. __fastcall TAVIH0101::~TAVIH0101(void)
  53. {
  54. }
  55. //--------------------------------------------------------------------------
  56. /*
  57. * form 초기화
  58. *
  59. * arguments
  60. *
  61. * return
  62. * void
  63. */
  64. void __fastcall TAVIH0101::FormInit()
  65. {
  66. ADOQry->Connection = ITSDb_GetConnection();
  67. m_pGDC = TvList->DataController;
  68. TvList->OptionsView->NoDataToDisplayInfoText = FrmLang->lblNoInfo->Caption;//"<AVI-제어기 상태 이력 정보>";
  69. //TvList->ViewInfo->GroupByBoxViewInfo->Text = "그룹핑할 필드의 헤더를 이곳으로 드래그 하세요";
  70. LblSearch->Caption = "검색조건: " + FStDateTime.SubString(1, 12) + " ~ " + FEdDateTime.SubString(1, 12);
  71. }
  72. //---------------------------------------------------------------------------
  73. /*
  74. * form을 보여줄때 호출되는 event 메서드이다.
  75. * arguments
  76. * Sender : event handler 객체
  77. * return
  78. * void
  79. */
  80. void __fastcall TAVIH0101::FormShow(TObject *Sender)
  81. {
  82. FormInit();
  83. Refresh();
  84. TmrShow->Enabled = true;
  85. }
  86. //---------------------------------------------------------------------------
  87. /*
  88. * 닫기버튼 이나 x버튼 클릭시 공통으로 처리하는 로직이들어간다..
  89. * Form과 DataModule class를 delete시킨다.
  90. * arguments
  91. *
  92. * return
  93. * void
  94. */
  95. void __fastcall TAVIH0101::CommClose()
  96. {
  97. CMM_SaveForm(g_sFormsDir, this);
  98. //AVIH0101 = NULL;
  99. }
  100. //---------------------------------------------------------------------------
  101. /*
  102. * 최초 1회 수행되는 타이머 이벤트
  103. * arguments
  104. * Sender : event handler 객체
  105. * return
  106. * void
  107. */
  108. void __fastcall TAVIH0101::TmrShowTimer(TObject *Sender)
  109. {
  110. TmrShow->Enabled = false;
  111. Application->ProcessMessages();
  112. SelHistory();
  113. }
  114. //---------------------------------------------------------------------------
  115. void __fastcall TAVIH0101::ChkExpandClick(TObject *Sender)
  116. {
  117. CMM_ExpandCollapseChk(TvList, ChkExpand->Checked);
  118. }
  119. //---------------------------------------------------------------------------
  120. /*
  121. * Refresh Data Event Function
  122. * arguments
  123. *
  124. * return
  125. * void
  126. */
  127. void __fastcall TAVIH0101::SelHistory()
  128. {
  129. TSqlCursor sqlCrs;
  130. String sQry;
  131. TADOQuery *pADO = ADOQry;
  132. sQry = "SELECT A.AVI_CTLR_MNGM_NMBR, B.AVI_ID, B.AVI_LCTN_NM, A.CRTN_DT, \r\n"
  133. " (SELECT CMMN_CD_KOR_NM FROM TB_CMMN_CD WHERE CMMN_CD = A.CMNC_STTS_CD AND CMMN_CLSF_CD = 'CMS') CMNC_STTS_CD, \r\n"
  134. " (SELECT CMMN_CD_KOR_NM FROM TB_CMMN_CD WHERE CMMN_CD = A.CBOX_DOOR_STTS_CD AND CMMN_CLSF_CD = 'CDS') CBOX_DOOR_STTS_CD, \r\n"
  135. " (SELECT CMMN_CD_KOR_NM FROM TB_CMMN_CD WHERE CMMN_CD = A.FAN_STTS_CD AND CMMN_CLSF_CD = 'PAS') FAN_STTS_CD, \r\n"
  136. " (SELECT CMMN_CD_KOR_NM FROM TB_CMMN_CD WHERE CMMN_CD = A.HETR_STTS_CD AND CMMN_CLSF_CD = 'HTS') HETR_STTS_CD, \r\n"
  137. " (SELECT CMMN_CD_KOR_NM FROM TB_CMMN_CD WHERE CMMN_CD = A.VOLT_STTS_CD AND CMMN_CLSF_CD = 'VTS') VOLT_STTS_CD, \r\n"
  138. " (SELECT CMMN_CD_KOR_NM FROM TB_CMMN_CD WHERE CMMN_CD = A.LAMP_STTS_CD AND CMMN_CLSF_CD = 'LAS') LAMP_STTS_CD, \r\n"
  139. " CBOX_TMPR, CMRA_MTNS_STTS_CD \r\n"
  140. " FROM TB_AVI_CTLR_STTS_HS A, TB_AVI_CTLR B \r\n"
  141. " WHERE A.CRTN_DT BETWEEN :p01 AND :p02 \r\n"
  142. " AND A.AVI_CTLR_MNGM_NMBR = B.AVI_CTLR_MNGM_NMBR \r\n"
  143. " AND B.AVI_CTLR_MNGM_NMBR IN(" + FIdList + ") \r\n"
  144. " ORDER BY A.AVI_CTLR_MNGM_NMBR ASC, A.CRTN_DT DESC \r\n";
  145. try
  146. {
  147. ITSDb_SQLText(pADO, sQry);
  148. ITSDb_SQLBind(pADO, "p01", FStDateTime);
  149. ITSDb_SQLBind(pADO, "p02", FEdDateTime);
  150. ITSDb_SQLOpen(pADO);
  151. DspHistory();
  152. }
  153. catch(EDatabaseError &E)
  154. {
  155. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  156. DBERRORMSG(Caption, String(E.ClassName()), E.Message, sQry);
  157. throw Exception(String(E.ClassName()) + E.Message);
  158. }
  159. catch(Exception &exception)
  160. {
  161. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  162. DBERRORMSG(Caption, String(exception.ClassName()), exception.Message, sQry);
  163. throw Exception(String(exception.ClassName()) + exception.Message);
  164. }
  165. }
  166. //---------------------------------------------------------------------------
  167. void __fastcall TAVIH0101::DspHistory()
  168. {
  169. TADOQuery *pADO = ADOQry;
  170. try
  171. {
  172. TcxGridChartSeries *pChart = NULL;
  173. CMM_ClearGridTableView(TvList);
  174. int nRow = 0;
  175. int nDataCnt = 0;
  176. try {
  177. TvList->BeginUpdate();
  178. nDataCnt = pADO->RecordCount;
  179. m_pGDC->RecordCount = nDataCnt;
  180. for( ; !pADO->Eof; pADO->Next(), nRow++)
  181. {
  182. m_pGDC->Values[nRow][Column00->Index] = pADO->FieldByName("AVI_CTLR_MNGM_NMBR")->AsString;
  183. m_pGDC->Values[nRow][Column11->Index] = pADO->FieldByName("AVI_ID")->AsString;
  184. m_pGDC->Values[nRow][Column01->Index] = ITSUtil_StrToDateTime(pADO->FieldByName("CRTN_DT")->AsString).FormatString(STR_DATETIME); //TODO
  185. m_pGDC->Values[nRow][Column06->Index] = pADO->FieldByName("AVI_LCTN_NM")->AsString;
  186. String sCmnc = pADO->FieldByName("CMNC_STTS_CD")->AsString;
  187. String sDoor = pADO->FieldByName("CBOX_DOOR_STTS_CD")->AsString;
  188. String sFan = pADO->FieldByName("FAN_STTS_CD")->AsString;
  189. String sHetr = pADO->FieldByName("HETR_STTS_CD")->AsString;
  190. String sTmpr = pADO->FieldByName("CBOX_TMPR")->AsString;
  191. String sCmra = pADO->FieldByName("CMRA_MTNS_STTS_CD")->AsString;
  192. String sVolt = pADO->FieldByName("VOLT_STTS_CD")->AsString;
  193. String sLamp = pADO->FieldByName("LAMP_STTS_CD")->AsString;
  194. m_pGDC->Values[nRow][Column02->Index] = sCmnc;
  195. m_pGDC->Values[nRow][Column03->Index] = sDoor;
  196. m_pGDC->Values[nRow][Column04->Index] = sFan;
  197. m_pGDC->Values[nRow][Column05->Index] = sHetr;
  198. m_pGDC->Values[nRow][Column07->Index] = sCmra;
  199. m_pGDC->Values[nRow][Column08->Index] = sVolt;
  200. m_pGDC->Values[nRow][Column09->Index] = sLamp;
  201. m_pGDC->Values[nRow][Column10->Index] = sTmpr;
  202. }
  203. }
  204. __finally
  205. {
  206. if (pADO)
  207. {
  208. pADO->Close();
  209. }
  210. TvList->EndUpdate();
  211. //CxList->SetFocus();
  212. LblRecords->Caption = FormatFloat("##,##0", m_pGDC->RecordCount) + " 건";
  213. String sEnd = "데이터 " + LblRecords->Caption + " 이 조회 되었습니다.";
  214. Application->MessageBox(sEnd.c_str(), L"데이터 조회 완료", MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
  215. }
  216. }
  217. catch(EDatabaseError &E)
  218. {
  219. throw Exception(String(E.ClassName()) + E.Message);
  220. }
  221. catch(...)
  222. {
  223. throw Exception(FrmLang->lblDbErr->Caption);//"알수없는 오류가 발생하였습니다.");
  224. }
  225. }
  226. //---------------------------------------------------------------------------
  227. void __fastcall TAVIH0101::OnMessage(TMessage &Msg)
  228. {
  229. switch (Msg.Msg)
  230. {
  231. case WM_PARAM_DATABASE:
  232. if (WP_DB_SELECT_OK == Msg.WParam)
  233. {
  234. //ShowMessage("Select Ok");
  235. }
  236. break;
  237. }
  238. }
  239. //---------------------------------------------------------------------------
  240. void __fastcall TAVIH0101::BtnExlSaveClick(TObject *Sender)
  241. {
  242. TcxGrid *pGrid = CxList;
  243. TcxGridTableView *pView = TvList;
  244. String sTitle = "AVI-제어기 상태이력";
  245. CMM_ExportToExcelFile(sTitle, pGrid, pView, this);
  246. }
  247. //---------------------------------------------------------------------------
  248. void __fastcall TAVIH0101::FormClose(TObject *Sender, TCloseAction &Action)
  249. {
  250. POST_MSG(FParent, WM_SUBFORM_CLOSE, 0, 0);
  251. CommClose();
  252. //AVIH0101 = NULL;
  253. }
  254. //---------------------------------------------------------------------------
  255. void __fastcall TAVIH0101::Column02CustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
  256. bool &ADone)
  257. {
  258. if( AViewInfo )
  259. {
  260. if(AViewInfo->Text == "정상")
  261. {
  262. ACanvas->Canvas->Font->Color = clTeal;
  263. }
  264. else if(AViewInfo->Text == "장애")
  265. {
  266. ACanvas->Canvas->Font->Color = clFuchsia;
  267. }
  268. else
  269. {
  270. ACanvas->Canvas->Font->Color = clGray;
  271. }
  272. }
  273. }
  274. //---------------------------------------------------------------------------