AVIH0301F.cpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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 "AVIH0301F.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 "cxTextEdit"
  33. #pragma link "dxSkinBlack"
  34. #pragma link "dxSkinBlue"
  35. #pragma link "dxSkinsCore"
  36. #pragma link "dxSkinscxPCPainter"
  37. #pragma resource "*.dfm"
  38. TAVIH0301 *AVIH0301 = NULL;
  39. //---------------------------------------------------------------------------
  40. __fastcall TAVIH0301::TAVIH0301(TComponent* Owner, HWND hHandle, String sFrom, String sTo, String sIdList)
  41. : TForm(Owner)
  42. {
  43. ITSSkin_Load(this);
  44. CMM_LoadForm(g_sFormsDir, this);
  45. FParent = hHandle;
  46. FStDateTime = sFrom;
  47. FEdDateTime = sTo;
  48. FIdList = sIdList;
  49. Caption = "AVI-제어기 교통정보 이력";
  50. }
  51. //---------------------------------------------------------------------------
  52. __fastcall TAVIH0301::~TAVIH0301(void)
  53. {
  54. }
  55. //--------------------------------------------------------------------------
  56. /*
  57. * form 초기화
  58. *
  59. * arguments
  60. *
  61. * return
  62. * void
  63. */
  64. void __fastcall TAVIH0301::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 TAVIH0301::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 TAVIH0301::CommClose()
  96. {
  97. CMM_SaveForm(g_sFormsDir, this);
  98. //AVIH0301 = NULL;
  99. }
  100. //---------------------------------------------------------------------------
  101. /*
  102. * 최초 1회 수행되는 타이머 이벤트
  103. * arguments
  104. * Sender : event handler 객체
  105. * return
  106. * void
  107. */
  108. void __fastcall TAVIH0301::TmrShowTimer(TObject *Sender)
  109. {
  110. TmrShow->Enabled = false;
  111. Application->ProcessMessages();
  112. SelHistory();
  113. }
  114. //---------------------------------------------------------------------------
  115. void __fastcall TAVIH0301::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 TAVIH0301::SelHistory()
  128. {
  129. TSqlCursor sqlCrs;
  130. String sQry;
  131. TADOQuery *pADO = ADOQry;
  132. sQry = "SELECT AVI_CTLR_MNGM_NMBR, AVI_DTCT_CHNL_NMBR, CRTN_DT, CRTN_YMD, CRTN_HMS, \r\n"
  133. " TFVL, OCPY_RATE, SPOT_SPED \r\n"
  134. " FROM TB_AVI_CTLR_TRFC \r\n"
  135. " WHERE CRTN_DT BETWEEN :p01 AND :p02 \r\n"
  136. " AND AVI_CTLR_MNGM_NMBR IN(" + FIdList + ") \r\n"
  137. " ORDER BY AVI_CTLR_MNGM_NMBR, AVI_DTCT_CHNL_NMBR, CRTN_DT \r\n";
  138. try
  139. {
  140. ITSDb_SQLText(pADO, sQry);
  141. ITSDb_SQLBind(pADO, "p01", FStDateTime);
  142. ITSDb_SQLBind(pADO, "p02", FEdDateTime);
  143. ITSDb_SQLOpen(pADO);
  144. DspHistory();
  145. }
  146. catch(EDatabaseError &E)
  147. {
  148. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  149. DBERRORMSG(Caption, String(E.ClassName()), E.Message, sQry);
  150. throw Exception(String(E.ClassName()) + E.Message);
  151. }
  152. catch(Exception &exception)
  153. {
  154. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  155. DBERRORMSG(Caption, String(exception.ClassName()), exception.Message, sQry);
  156. throw Exception(String(exception.ClassName()) + exception.Message);
  157. }
  158. }
  159. //---------------------------------------------------------------------------
  160. void __fastcall TAVIH0301::DspHistory()
  161. {
  162. TADOQuery *pADO = ADOQry;
  163. try
  164. {
  165. TcxGridChartSeries *pChart = NULL;
  166. CMM_ClearGridTableView(TvList);
  167. int nRow = 0;
  168. int nDataCnt = 0;
  169. try {
  170. TvList->BeginUpdate();
  171. nDataCnt = pADO->RecordCount;
  172. m_pGDC->RecordCount = nDataCnt;
  173. for( ; !pADO->Eof; pADO->Next(), nRow++)
  174. {
  175. m_pGDC->Values[nRow][Column00->Index] = pADO->FieldByName("AVI_CTLR_MNGM_NMBR")->AsString;
  176. m_pGDC->Values[nRow][Column01->Index] = pADO->FieldByName("AVI_DTCT_CHNL_NMBR")->AsString;
  177. m_pGDC->Values[nRow][Column02->Index] = ITSUtil_StrToDateTime(pADO->FieldByName("CRTN_DT")->AsString).FormatString(STR_DATETIME); //TODO
  178. m_pGDC->Values[nRow][Column03->Index] = pADO->FieldByName("CRTN_YMD")->AsString;
  179. m_pGDC->Values[nRow][Column04->Index] = pADO->FieldByName("CRTN_HMS")->AsString;
  180. m_pGDC->Values[nRow][Column05->Index] = FormatFloat("##,##0", pADO->FieldByName("TFVL")->AsInteger);
  181. m_pGDC->Values[nRow][Column06->Index] = FormatFloat("##0.#0", pADO->FieldByName("OCPY_RATE")->AsFloat);
  182. m_pGDC->Values[nRow][Column07->Index] = pADO->FieldByName("SPOT_SPED")->AsString;
  183. }
  184. }
  185. __finally
  186. {
  187. if (pADO)
  188. {
  189. pADO->Close();
  190. }
  191. TvList->EndUpdate();
  192. //CxList->SetFocus();
  193. LblRecords->Caption = FormatFloat("##,##0", m_pGDC->RecordCount) + " 건";
  194. String sEnd = "데이터 " + LblRecords->Caption + " 이 조회 되었습니다.";
  195. Application->MessageBox(sEnd.c_str(), L"데이터 조회 완료", MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
  196. }
  197. }
  198. catch(EDatabaseError &E)
  199. {
  200. throw Exception(String(E.ClassName()) + E.Message);
  201. }
  202. catch(...)
  203. {
  204. throw Exception(FrmLang->lblDbErr->Caption);//"알수없는 오류가 발생하였습니다.");
  205. }
  206. }
  207. //---------------------------------------------------------------------------
  208. void __fastcall TAVIH0301::OnMessage(TMessage &Msg)
  209. {
  210. switch (Msg.Msg)
  211. {
  212. case WM_PARAM_DATABASE:
  213. if (WP_DB_SELECT_OK == Msg.WParam)
  214. {
  215. //ShowMessage("Select Ok");
  216. }
  217. break;
  218. }
  219. }
  220. //---------------------------------------------------------------------------
  221. void __fastcall TAVIH0301::BtnExlSaveClick(TObject *Sender)
  222. {
  223. TcxGrid *pGrid = CxList;
  224. TcxGridTableView *pView = TvList;
  225. String sTitle = "AVI-제어기 교통정보이력";
  226. CMM_ExportToExcelFile(sTitle, pGrid, pView, this);
  227. }
  228. //---------------------------------------------------------------------------
  229. void __fastcall TAVIH0301::FormClose(TObject *Sender, TCloseAction &Action)
  230. {
  231. POST_MSG(FParent, WM_SUBFORM_CLOSE, 0, 0);
  232. CommClose();
  233. //AVIH0301 = NULL;
  234. }
  235. //---------------------------------------------------------------------------