AVIH0701F.cpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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 "AVIH0701F.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. #define USE_MTCH_RATE 0
  39. TAVIH0701 *AVIH0701 = NULL;
  40. //---------------------------------------------------------------------------
  41. __fastcall TAVIH0701::TAVIH0701(TComponent* Owner, HWND hHandle, String sFrom, String sTo, String sIdList)
  42. : TForm(Owner)
  43. {
  44. ITSSkin_Load(this);
  45. CMM_LoadForm(g_sFormsDir, this);
  46. FParent = hHandle;
  47. FStDateTime = sFrom;
  48. FEdDateTime = sTo;
  49. FIdList = sIdList;
  50. Caption = "AVI-구간 소통상황 이력";
  51. #if !USE_MTCH_RATE
  52. Column06->Visible = false;
  53. Column06->VisibleForCustomization = false;
  54. #endif
  55. }
  56. //---------------------------------------------------------------------------
  57. __fastcall TAVIH0701::~TAVIH0701(void)
  58. {
  59. }
  60. //--------------------------------------------------------------------------
  61. /*
  62. * form 초기화
  63. *
  64. * arguments
  65. *
  66. * return
  67. * void
  68. */
  69. void __fastcall TAVIH0701::FormInit()
  70. {
  71. ADOQry->Connection = ITSDb_GetConnection();
  72. m_pGDC = TvList->DataController;
  73. TvList->OptionsView->NoDataToDisplayInfoText = FrmLang->lblNoInfo->Caption;//"<AVI-구간 소통상황 이력 정보>";
  74. //TvList->ViewInfo->GroupByBoxViewInfo->Text = "그룹핑할 필드의 헤더를 이곳으로 드래그 하세요";
  75. LblSearch->Caption = "검색조건: " + FStDateTime.SubString(1, 12) + " ~ " + FEdDateTime.SubString(1, 12);
  76. }
  77. //---------------------------------------------------------------------------
  78. /*
  79. * form을 보여줄때 호출되는 event 메서드이다.
  80. * arguments
  81. * Sender : event handler 객체
  82. * return
  83. * void
  84. */
  85. void __fastcall TAVIH0701::FormShow(TObject *Sender)
  86. {
  87. FormInit();
  88. Refresh();
  89. TmrShow->Enabled = true;
  90. }
  91. //---------------------------------------------------------------------------
  92. /*
  93. * 닫기버튼 이나 x버튼 클릭시 공통으로 처리하는 로직이들어간다..
  94. * Form과 DataModule class를 delete시킨다.
  95. * arguments
  96. *
  97. * return
  98. * void
  99. */
  100. void __fastcall TAVIH0701::CommClose()
  101. {
  102. CMM_SaveForm(g_sFormsDir, this);
  103. //AVIH0701 = NULL;
  104. }
  105. //---------------------------------------------------------------------------
  106. /*
  107. * 최초 1회 수행되는 타이머 이벤트
  108. * arguments
  109. * Sender : event handler 객체
  110. * return
  111. * void
  112. */
  113. void __fastcall TAVIH0701::TmrShowTimer(TObject *Sender)
  114. {
  115. TmrShow->Enabled = false;
  116. Application->ProcessMessages();
  117. SelHistory();
  118. }
  119. //---------------------------------------------------------------------------
  120. void __fastcall TAVIH0701::ChkExpandClick(TObject *Sender)
  121. {
  122. CMM_ExpandCollapseChk(TvList, ChkExpand->Checked);
  123. }
  124. //---------------------------------------------------------------------------
  125. /*
  126. * Refresh Data Event Function
  127. * arguments
  128. *
  129. * return
  130. * void
  131. */
  132. void __fastcall TAVIH0701::SelHistory()
  133. {
  134. TSqlCursor sqlCrs;
  135. String sQry;
  136. TADOQuery *pADO = ADOQry;
  137. sQry = "SELECT A.AVI_SECT_NMBR, B.AVI_SECT_NM, A.CRTN_DT, A.TFVL, \r\n"
  138. " A.TRVL_SPED, A.DATA_NUM, A.MTCH_RATE \r\n"
  139. " FROM TB_AVI_SECT_TRAF A, TB_AVI_SECT_MSTR B \r\n"
  140. " WHERE A.CRTN_DT BETWEEN :p01 AND :p02 \r\n"
  141. " AND B.AVI_SECT_NMBR IN(" + FIdList + ") \r\n"
  142. " AND A.AVI_SECT_NMBR = B.AVI_SECT_NMBR \r\n"
  143. " ORDER BY A.AVI_SECT_NMBR, A.CRTN_DT \r\n";
  144. try
  145. {
  146. ITSDb_SQLText(pADO, sQry);
  147. ITSDb_SQLBind(pADO, "p01", FStDateTime);
  148. ITSDb_SQLBind(pADO, "p02", FEdDateTime);
  149. ITSDb_SQLOpen(pADO);
  150. DspHistory();
  151. }
  152. catch(EDatabaseError &E)
  153. {
  154. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  155. DBERRORMSG(Caption, String(E.ClassName()), E.Message, sQry);
  156. throw Exception(String(E.ClassName()) + E.Message);
  157. }
  158. catch(Exception &exception)
  159. {
  160. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  161. DBERRORMSG(Caption, String(exception.ClassName()), exception.Message, sQry);
  162. throw Exception(String(exception.ClassName()) + exception.Message);
  163. }
  164. }
  165. //---------------------------------------------------------------------------
  166. void __fastcall TAVIH0701::DspHistory()
  167. {
  168. TADOQuery *pADO = ADOQry;
  169. try
  170. {
  171. TcxGridChartSeries *pChart = NULL;
  172. CMM_ClearGridTableView(TvList);
  173. int nRow = 0;
  174. int nDataCnt = 0;
  175. try {
  176. TvList->BeginUpdate();
  177. nDataCnt = pADO->RecordCount;
  178. m_pGDC->RecordCount = nDataCnt;
  179. for( ; !pADO->Eof; pADO->Next(), nRow++)
  180. {
  181. m_pGDC->Values[nRow][Column00->Index] = pADO->FieldByName("AVI_SECT_NMBR")->AsString;
  182. m_pGDC->Values[nRow][Column01->Index] = pADO->FieldByName("AVI_SECT_NM")->AsString;
  183. m_pGDC->Values[nRow][Column02->Index] = ITSUtil_StrToDateTime(pADO->FieldByName("CRTN_DT")->AsString).FormatString(STR_DATETIME); //TODO
  184. m_pGDC->Values[nRow][Column03->Index] = pADO->FieldByName("TFVL")->AsString;
  185. m_pGDC->Values[nRow][Column04->Index] = pADO->FieldByName("TRVL_SPED")->AsString;
  186. m_pGDC->Values[nRow][Column05->Index] = pADO->FieldByName("DATA_NUM")->AsString;
  187. #if USE_MTCH_RATE
  188. m_pGDC->Values[nRow][Column06->Index] = pADO->FieldByName("MTCH_RATE")->AsString;
  189. #endif
  190. }
  191. }
  192. __finally
  193. {
  194. if (pADO)
  195. {
  196. pADO->Close();
  197. }
  198. TvList->EndUpdate();
  199. //CxList->SetFocus();
  200. LblRecords->Caption = FormatFloat("##,##0", m_pGDC->RecordCount) + " 건";
  201. String sEnd = "데이터 " + LblRecords->Caption + " 이 조회 되었습니다.";
  202. Application->MessageBox(sEnd.c_str(), L"데이터 조회 완료", MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
  203. }
  204. }
  205. catch(EDatabaseError &E)
  206. {
  207. throw Exception(String(E.ClassName()) + E.Message);
  208. }
  209. catch(...)
  210. {
  211. throw Exception(FrmLang->lblDbErr->Caption);//"알수없는 오류가 발생하였습니다.");
  212. }
  213. }
  214. //---------------------------------------------------------------------------
  215. void __fastcall TAVIH0701::OnMessage(TMessage &Msg)
  216. {
  217. switch (Msg.Msg)
  218. {
  219. case WM_PARAM_DATABASE:
  220. if (WP_DB_SELECT_OK == Msg.WParam)
  221. {
  222. //ShowMessage("Select Ok");
  223. }
  224. break;
  225. }
  226. }
  227. //---------------------------------------------------------------------------
  228. void __fastcall TAVIH0701::BtnExlSaveClick(TObject *Sender)
  229. {
  230. TcxGrid *pGrid = CxList;
  231. TcxGridTableView *pView = TvList;
  232. String sTitle = "AVI-구간 소통상황이력";
  233. CMM_ExportToExcelFile(sTitle, pGrid, pView, this);
  234. }
  235. //---------------------------------------------------------------------------
  236. void __fastcall TAVIH0701::FormClose(TObject *Sender, TCloseAction &Action)
  237. {
  238. POST_MSG(FParent, WM_SUBFORM_CLOSE, 0, 0);
  239. CommClose();
  240. //AVIH0701 = NULL;
  241. }
  242. //---------------------------------------------------------------------------