IHS00201F.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. #include "ITSLangTransF.h"
  9. #pragma hdrstop
  10. #include "IHS00201F.h"
  11. //---------------------------------------------------------------------------
  12. #pragma package(smart_init)
  13. #pragma link "cxButtons"
  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. TIHS00201 *IHS00201 = NULL;
  39. //---------------------------------------------------------------------------
  40. __fastcall TIHS00201::TIHS00201(TComponent* Owner, HWND hHandle, int ARptType, String ASystId, String sFrom, String sTo, String ATitle)
  41. : TForm(Owner)
  42. {
  43. LangTrans->Translate(this, ITSDb_GetConnection());
  44. ITSSkin_Load(this);
  45. CMM_LoadForm(g_sFormsDir, this);
  46. FParent = hHandle;
  47. FStDateTime = sFrom;
  48. FEdDateTime = sTo;
  49. FRptType = ARptType;
  50. FSystId = ASystId;
  51. FTitle = ATitle;
  52. Caption = Caption;//"프로세스 상태이력";
  53. }
  54. //---------------------------------------------------------------------------
  55. __fastcall TIHS00201::~TIHS00201(void)
  56. {
  57. }
  58. //--------------------------------------------------------------------------
  59. /*
  60. * form 초기화
  61. *
  62. * arguments
  63. *
  64. * return
  65. * void
  66. */
  67. void __fastcall TIHS00201::FormInit()
  68. {
  69. ADOQry->Connection = ITSDb_GetConnection();
  70. m_pGDC = TvList->DataController;
  71. TvList->OptionsView->NoDataToDisplayInfoText = FrmLang->lblNoInfo->Caption;//"<프로세스 상태이력 정보>";
  72. LblSearch->Caption = FTitle;
  73. }
  74. //---------------------------------------------------------------------------
  75. /*
  76. * form을 보여줄때 호출되는 event 메서드이다.
  77. * arguments
  78. * Sender : event handler 객체
  79. * return
  80. * void
  81. */
  82. void __fastcall TIHS00201::FormShow(TObject *Sender)
  83. {
  84. FormInit();
  85. Refresh();
  86. TmrShow->Enabled = true;
  87. }
  88. //---------------------------------------------------------------------------
  89. /*
  90. * 닫기버튼 이나 x버튼 클릭시 공통으로 처리하는 로직이들어간다..
  91. * Form과 DataModule class를 delete시킨다.
  92. * arguments
  93. *
  94. * return
  95. * void
  96. */
  97. void __fastcall TIHS00201::CommClose()
  98. {
  99. CMM_SaveForm(g_sFormsDir, this);
  100. //IHS00201 = NULL;
  101. }
  102. //---------------------------------------------------------------------------
  103. /*
  104. * 최초 1회 수행되는 타이머 이벤트
  105. * arguments
  106. * Sender : event handler 객체
  107. * return
  108. * void
  109. */
  110. void __fastcall TIHS00201::TmrShowTimer(TObject *Sender)
  111. {
  112. TmrShow->Enabled = false;
  113. Application->ProcessMessages();
  114. SelHistory();
  115. }
  116. //---------------------------------------------------------------------------
  117. /*
  118. * Refresh Data Event Function
  119. * arguments
  120. *
  121. * return
  122. * void
  123. */
  124. void __fastcall TIHS00201::SelHistory()
  125. {
  126. TSqlCursor sqlCrs;
  127. String sQry;
  128. TADOQuery *pADO = ADOQry;
  129. sQry = "SELECT X.CRTN_IDX, X.HHMM, Y.SYST_ID, Y.SYST_NM, Y.CRTN_DT, Y.SYST_STTS_CD, Y.RMRK \r\n"
  130. " FROM (SELECT ROWNUM AS CRTN_IDX, \r\n"
  131. " TO_CHAR(TRUNC(SYSDATE)+((LEVEL-1)*5)/1440, 'HH24:MI') AS HHMM \r\n"
  132. " FROM DUAL \r\n"
  133. " CONNECT BY LEVEL <= 288 )X, \r\n"
  134. " (SELECT A.SYST_ID, A.SYST_NM, B.CRTN_DT, TRUNC((B.CHOUR * 60 + B.CMIN) / 5, 0)+1 AS CRTN_IDX, B.SYST_STTS_CD, B.RMRK \r\n"
  135. " FROM TB_UNIT_SYST A, \r\n"
  136. " (SELECT SYST_ID, CRTN_DT, \r\n"
  137. " TO_NUMBER(SUBSTR(CRTN_DT, 9, 2)) AS CHOUR, TO_NUMBER(SUBSTR(CRTN_DT, 11, 2)) AS CMIN, \r\n"
  138. " SYST_STTS_CD, RMRK \r\n"
  139. " FROM TB_UNIT_SYST_STTS_HS \r\n"
  140. " WHERE SYST_ID = :p02 \r\n"
  141. " AND CRTN_DT BETWEEN :p03 AND :p04 \r\n"
  142. " ) B \r\n"
  143. " WHERE A.SYST_ID = :p01 \r\n"
  144. " AND A.SYST_ID = B.SYST_ID) Y \r\n"
  145. " WHERE X.CRTN_IDX = Y.CRTN_IDX(+) \r\n"
  146. " ORDER BY X.CRTN_IDX \r\n";
  147. try
  148. {
  149. ITSDb_SQLText(pADO, sQry);
  150. ITSDb_SQLBind(pADO, "p01", FSystId);
  151. ITSDb_SQLBind(pADO, "p02", FSystId);
  152. ITSDb_SQLBind(pADO, "p03", FStDateTime);
  153. ITSDb_SQLBind(pADO, "p04", FEdDateTime);
  154. ITSDb_SQLOpen(pADO);
  155. DspHistory();
  156. }
  157. catch(EDatabaseError &E)
  158. {
  159. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  160. DBERRORMSG(Caption, String(E.ClassName()), E.Message, sQry);
  161. throw Exception(String(E.ClassName()) + E.Message);
  162. }
  163. catch(Exception &exception)
  164. {
  165. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  166. DBERRORMSG(Caption, String(exception.ClassName()), exception.Message, sQry);
  167. throw Exception(String(exception.ClassName()) + exception.Message);
  168. }
  169. }
  170. //---------------------------------------------------------------------------
  171. void __fastcall TIHS00201::DspHistory()
  172. {
  173. TADOQuery *pADO = ADOQry;
  174. try
  175. {
  176. CMM_ClearGridTableView(TvList);
  177. int nRow = 0;
  178. try {
  179. TvList->BeginUpdate();
  180. for( ; !pADO->Eof; pADO->Next(), nRow++)
  181. {
  182. nRow = m_pGDC->AppendRecord();
  183. m_pGDC->Values[nRow][Column01->Index] = pADO->FieldByName("CRTN_IDX")->AsString;
  184. m_pGDC->Values[nRow][Column02->Index] = pADO->FieldByName("HHMM")->AsString;
  185. String sCrtDt = VarToStr(pADO->FieldByName("CRTN_DT")->AsString);
  186. if (sCrtDt.IsEmpty())
  187. m_pGDC->Values[nRow][Column03->Index] = "---";
  188. else
  189. m_pGDC->Values[nRow][Column03->Index] = ITSUtil_StrToTime(sCrtDt);
  190. String sStatus = VarToStr(pADO->FieldByName("SYST_STTS_CD")->AsString);
  191. m_pGDC->Values[nRow][Column05->Index] = sStatus;
  192. if (sStatus == "SPS0") sStatus = cxLabel1->Caption;//"알 수 없음";
  193. else if (sStatus == "SPS1") sStatus = cxLabel1->Caption;//"실행중";
  194. else if (sStatus == "SPS2") sStatus = cxLabel1->Caption;//"시작";
  195. else if (sStatus == "SPS3") sStatus = cxLabel1->Caption;//"종료";
  196. else if (sStatus == "SPS4") sStatus = cxLabel1->Caption;//"오류 발생";
  197. m_pGDC->Values[nRow][Column04->Index] = sStatus;
  198. }
  199. }
  200. __finally
  201. {
  202. if (pADO)
  203. {
  204. pADO->Close();
  205. delete pADO;
  206. }
  207. TvList->EndUpdate();
  208. //CxList->SetFocus();
  209. LblRecords->Caption = FormatFloat("##,##0", m_pGDC->RecordCount) + FrmLang->lblEA->Caption;//" 건";
  210. String sEnd = FrmLang->lblQrySel->Caption + " [" + LblRecords->Caption + "]";//"데이터 " + LblRecords->Caption + " 이 조회 되었습니다.";
  211. Application->MessageBox(sEnd.c_str(),
  212. FrmLang->lblQryEnd->Caption.c_str(),//L"데이터 조회 완료",
  213. MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
  214. }
  215. }
  216. catch(EDatabaseError &E)
  217. {
  218. throw Exception(String(E.ClassName()) + E.Message);
  219. }
  220. catch(...)
  221. {
  222. throw Exception(FrmLang->lblDbErr->Caption);//"알수없는 오류가 발생하였습니다.");
  223. }
  224. }
  225. //---------------------------------------------------------------------------
  226. void __fastcall TIHS00201::OnMessage(TMessage &Msg)
  227. {
  228. switch (Msg.Msg)
  229. {
  230. case WM_PARAM_DATABASE:
  231. if (WP_DB_SELECT_OK == Msg.WParam)
  232. {
  233. //ShowMessage("Select Ok");
  234. }
  235. break;
  236. }
  237. }
  238. //---------------------------------------------------------------------------
  239. void __fastcall TIHS00201::BtnExlSaveClick(TObject *Sender)
  240. {
  241. TcxGrid *pGrid = CxList;
  242. TcxGridTableView *pView = TvList;
  243. String sTitle= Caption;//"프로세스상태이력";
  244. CMM_ExportToExcelFile(sTitle, pGrid, pView, this);
  245. }
  246. //---------------------------------------------------------------------------
  247. void __fastcall TIHS00201::FormClose(TObject *Sender, TCloseAction &Action)
  248. {
  249. POST_MSG(FParent, WM_SUBFORM_CLOSE, 0, 0);
  250. CommClose();
  251. //IHS00201 = NULL;
  252. }
  253. //---------------------------------------------------------------------------
  254. void __fastcall TIHS00201::TvListCustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
  255. bool &ADone)
  256. {
  257. if (AViewInfo)
  258. {
  259. String sStatus = AViewInfo->GridRecord->DisplayTexts[Column05->Index];
  260. if (sStatus == "SPS0") ACanvas->Brush->Color = clOlive;
  261. else if (sStatus == "SPS1") ACanvas->Brush->Color = clLime;
  262. else if (sStatus == "SPS2") ACanvas->Brush->Color = clLime;
  263. else if (sStatus == "SPS3") ACanvas->Brush->Color = clRed;
  264. else if (sStatus == "SPS4") ACanvas->Brush->Color = clRed;
  265. }
  266. }
  267. //---------------------------------------------------------------------------
  268. void __fastcall TIHS00201::FormDestroy(TObject *Sender)
  269. {
  270. CommClose();
  271. }
  272. //---------------------------------------------------------------------------