TAS00501F.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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 <DateUtils.hpp>
  9. #include "ITSLangTransF.h"
  10. #pragma hdrstop
  11. #include "TAS00501F.h"
  12. //---------------------------------------------------------------------------
  13. #pragma package(smart_init)
  14. #pragma link "cxButtons"
  15. #pragma link "cxCheckBox"
  16. #pragma link "cxClasses"
  17. #pragma link "cxContainer"
  18. #pragma link "cxControls"
  19. #pragma link "cxCustomData"
  20. #pragma link "cxData"
  21. #pragma link "cxDataStorage"
  22. #pragma link "cxEdit"
  23. #pragma link "cxFilter"
  24. #pragma link "cxGraphics"
  25. #pragma link "cxGrid"
  26. #pragma link "cxGridBandedTableView"
  27. #pragma link "cxGridCustomTableView"
  28. #pragma link "cxGridCustomView"
  29. #pragma link "cxGridLevel"
  30. #pragma link "cxGridTableView"
  31. #pragma link "cxLabel"
  32. #pragma link "cxLookAndFeelPainters"
  33. #pragma link "cxLookAndFeels"
  34. #pragma link "cxSplitter"
  35. #pragma link "cxStyles"
  36. #pragma link "dxSkinBlack"
  37. #pragma link "dxSkinBlue"
  38. #pragma link "dxSkinsCore"
  39. #pragma link "dxSkinscxPCPainter"
  40. #pragma resource "*.dfm"
  41. TTAS00501 *TAS00501 = NULL;
  42. //---------------------------------------------------------------------------
  43. __fastcall TTAS00501::TTAS00501(TComponent* Owner, HWND hHandle,
  44. String AAtrdId, String AAtrdNm, String AAtrdId1, String AAtrdNm1, String AQryDay)
  45. : TForm(Owner)
  46. {
  47. LangTrans->Translate(this, ITSDb_GetConnection());
  48. ITSSkin_Load(this);
  49. CMM_LoadForm(g_sFormsDir, this);
  50. FParent = hHandle;
  51. FAtrdId = AAtrdId; //IFSC_ID
  52. FAtrdNm = AAtrdNm; //IFSC_NM
  53. FAtrdId1 = AAtrdId1; //IFSC_ID
  54. FAtrdNm1 = AAtrdNm1; //IFSC_NM
  55. FQryDay = AQryDay; //특수일
  56. FTrfManager = new TDetourTrfManager();
  57. SetQueryDay(FQryDay);
  58. }
  59. //---------------------------------------------------------------------------
  60. __fastcall TTAS00501::~TTAS00501(void)
  61. {
  62. }
  63. //--------------------------------------------------------------------------
  64. /*
  65. * form 초기화
  66. *
  67. * arguments
  68. *
  69. * return
  70. * void
  71. */
  72. void __fastcall TTAS00501::FormInit()
  73. {
  74. ADOQry->Connection = ITSDb_GetConnection();
  75. m_pGDC = TvList->DataController;
  76. TvList->OptionsView->NoDataToDisplayInfoText = FrmLang->lblNoInfo->Caption;//"<우회도로분석 정보>";
  77. LblSearch->Caption = FrmLang->lblQryCond->Caption + FAtrdId + "/" + FAtrdId1 + " [" + FQryDay + "]";
  78. }
  79. //---------------------------------------------------------------------------
  80. /*
  81. * form을 보여줄때 호출되는 event 메서드이다.
  82. * arguments
  83. * Sender : event handler 객체
  84. * return
  85. * void
  86. */
  87. void __fastcall TTAS00501::FormShow(TObject *Sender)
  88. {
  89. FormInit();
  90. Refresh();
  91. TmrShow->Enabled = true;
  92. }
  93. //---------------------------------------------------------------------------
  94. /*
  95. * 닫기버튼 이나 x버튼 클릭시 공통으로 처리하는 로직이들어간다..
  96. * Form과 DataModule class를 delete시킨다.
  97. * arguments
  98. *
  99. * return
  100. * void
  101. */
  102. void __fastcall TTAS00501::CommClose()
  103. {
  104. try
  105. {
  106. delete FTrfManager;
  107. FTrfManager = NULL;
  108. }
  109. catch(Exception &e)
  110. {
  111. }
  112. CMM_SaveForm(g_sFormsDir, this);
  113. //TAS00501 = NULL;
  114. }
  115. //---------------------------------------------------------------------------
  116. /*
  117. * 최초 1회 수행되는 타이머 이벤트
  118. * arguments
  119. * Sender : event handler 객체
  120. * return
  121. * void
  122. */
  123. void __fastcall TTAS00501::TmrShowTimer(TObject *Sender)
  124. {
  125. TmrShow->Enabled = false;
  126. Application->ProcessMessages();
  127. SelHistory1();
  128. SelHistory2();
  129. DspHistory();
  130. }
  131. //---------------------------------------------------------------------------
  132. void __fastcall TTAS00501::ChkExpandClick(TObject *Sender)
  133. {
  134. CMM_ExpandCollapseChk(TvList, ChkExpand->Checked);
  135. }
  136. //---------------------------------------------------------------------------
  137. String __fastcall TTAS00501::GetDayWeek(TDateTime ADay)
  138. {
  139. System::Word week = DayOfWeek(ADay);
  140. //const days: array[1..7] of string = ('일','월','화','수','목','금','토');
  141. String sWeek[8] = { "", "일", "월", "화", "수", "목", "금", "토" };
  142. return " [" + sWeek[week] + "]";
  143. }
  144. //---------------------------------------------------------------------------
  145. void __fastcall TTAS00501::SetQueryDay(String ADay)
  146. {
  147. TDateTime dt, dtTemp;
  148. System::Word Year = (System::Word)ADay.SubString( 1, 4).ToIntDef(2018);
  149. System::Word Month = (System::Word)ADay.SubString( 5, 2).ToIntDef(1);
  150. System::Word Day = (System::Word)ADay.SubString( 7, 2).ToIntDef(1);
  151. dt = EncodeDate(Year, Month, Day);
  152. int nInc = -3;
  153. for (int ii = 0; ii < MAX_QRY_TERM; ii++)
  154. {
  155. FQryDayList[ii] = IncDay(dt, nInc++);
  156. TDetourTrf *pTrf = new TDetourTrf();
  157. pTrf->dtQry = FQryDayList[ii];
  158. pTrf->sQryDay = FQryDayList[ii].FormatString("YYYYMMDD");
  159. pTrf->IFSC_ID = FAtrdId;
  160. FTrfManager->FLists.Push(pTrf->sQryDay, pTrf);
  161. TvList->Bands->Items[ii+1]->Caption = FQryDayList[ii].FormatString("YYYY-MM-DD") + GetDayWeek(FQryDayList[ii]);
  162. }
  163. }
  164. //---------------------------------------------------------------------------
  165. /*
  166. * Refresh Data Event Function
  167. * arguments
  168. *
  169. * return
  170. * void
  171. */
  172. void __fastcall TTAS00501::SelHistory1()
  173. {
  174. #if 0
  175. #endif
  176. }
  177. //---------------------------------------------------------------------------
  178. void __fastcall TTAS00501::SelHistory2()
  179. {
  180. TSqlCursor sqlCrs;
  181. String sQry;
  182. TADOQuery *pADO = ADOQry;
  183. sQry =
  184. "SELECT A.IFSC_ID, A.STAT_DT, \r\n"
  185. " SUBSTR(A.STAT_DT, 1,8) AS STAT_DD, SUBSTR(A.STAT_DT, 9,2) AS STAT_HH, \r\n"
  186. " A.SPED, A.TRVL_HH, \r\n"
  187. " NVL(B.CMTR_GRAD_CD, 'LTC0') AS GRAD \r\n"
  188. " FROM TB_IFSC_HH_STAT A, \r\n"
  189. " TB_CMTR_GRAD_CLSF B, \r\n"
  190. " TB_IFSC C \r\n"
  191. " WHERE A.STAT_DT BETWEEN :p01 AND :p02 \r\n"
  192. " AND A.IFSC_ID IN (:p03, :p04) \r\n"
  193. " AND A.IFSC_ID = C.IFSC_ID \r\n"
  194. " AND B.SECT_GRAD_CD = C.SECT_GRAD_CD \r\n"
  195. " AND (A.SPED >= B.LWST_TRVL_SPED AND A.SPED <= B.HGHS_TRVL_SPED) \r\n";
  196. try
  197. {
  198. ITSDb_SQLText(pADO, sQry);
  199. ITSDb_SQLBind(pADO, "p01", FQryDayList[ 0].FormatString("YYYYMMDD") + "000000");
  200. ITSDb_SQLBind(pADO, "p02", FQryDayList[MAX_QRY_TERM-1].FormatString("YYYYMMDD") + "235959");
  201. ITSDb_SQLBind(pADO, "p03", FAtrdId); //IFSC_ID
  202. ITSDb_SQLBind(pADO, "p04", FAtrdId1); //IFSC_ID
  203. ITSDb_SQLOpen(pADO);
  204. int nIdx, nIfsc;
  205. TDetourTrf *pTrf;
  206. for( ; !pADO->Eof; pADO->Next())
  207. {
  208. pTrf = FTrfManager->FLists.Find(pADO->FieldByName("STAT_DD")->AsString);
  209. if (pTrf == NULL) continue;
  210. nIdx = pADO->FieldByName("STAT_HH")->AsInteger;
  211. if (pADO->FieldByName("IFSC_ID")->AsString == FAtrdId)
  212. nIfsc = 0;
  213. else
  214. nIfsc = 1;
  215. pTrf->INFO[nIfsc][nIdx].SPED = pADO->FieldByName("SPED")->AsString.ToIntDef(0);
  216. pTrf->INFO[nIfsc][nIdx].GRAD = pADO->FieldByName("GRAD")->AsString;
  217. }
  218. pADO->Close();
  219. }
  220. catch(EDatabaseError &E)
  221. {
  222. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  223. DBERRORMSG(Caption, String(E.ClassName()), E.Message, sQry);
  224. throw Exception(String(E.ClassName()) + E.Message);
  225. }
  226. catch(Exception &exception)
  227. {
  228. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  229. DBERRORMSG(Caption, String(exception.ClassName()), exception.Message, sQry);
  230. throw Exception(String(exception.ClassName()) + exception.Message);
  231. }
  232. }
  233. //---------------------------------------------------------------------------
  234. void __fastcall TTAS00501::DspHistory()
  235. {
  236. m_pGDC = TvList->DataController;
  237. try
  238. {
  239. CMM_ClearGridTableView(TvList);
  240. int nRow1 = 0;
  241. int nDataCnt = 0;
  242. int ii;
  243. try
  244. {
  245. TvList->BeginUpdate();
  246. nDataCnt = FTrfManager->FLists.Size();
  247. String sCaption;
  248. int nIdxSped, nIdxGrad;
  249. int nGap;
  250. for (ii = 0; ii < DAY_HOUR; ii++)
  251. {
  252. nRow1 = m_pGDC->AppendRecord();
  253. sCaption.printf(L"%02d", ii);
  254. m_pGDC->Values[nRow1][Col03->Index] = sCaption;
  255. nIdxSped = ColSped->Index;
  256. nIdxGrad = ColGrad->Index;
  257. FOR_STL(TDetourTrf*, pObj, FTrfManager->FLists)
  258. {
  259. m_pGDC->Values[nRow1][nIdxSped++] = pObj->INFO[0][ii].SPED;
  260. m_pGDC->Values[nRow1][nIdxSped++] = pObj->INFO[1][ii].SPED;
  261. nGap = pObj->INFO[0][ii].SPED - pObj->INFO[1][ii].SPED;
  262. if (nGap < 0)
  263. {
  264. sCaption.printf(L"▼ %3d", nGap*-1);
  265. }
  266. else if (nGap > 0)
  267. {
  268. sCaption.printf(L"▲ %3d", nGap);
  269. }
  270. else
  271. {
  272. sCaption = "0";
  273. }
  274. m_pGDC->Values[nRow1][nIdxSped++] = sCaption;
  275. m_pGDC->Values[nRow1][nIdxGrad++] = pObj->INFO[0][ii].GRAD;
  276. m_pGDC->Values[nRow1][nIdxGrad++] = pObj->INFO[1][ii].GRAD;
  277. m_pGDC->Values[nRow1][nIdxGrad++] = pObj->INFO[0][ii].GRAD;
  278. }
  279. }
  280. }
  281. __finally
  282. {
  283. TvList->EndUpdate();
  284. //CxList->SetFocus();
  285. //DrawChart(FAtrdNm + " [" + FQryDay + "]");
  286. LblRecords->Caption = FormatFloat("##,##0", m_pGDC->RecordCount) + FrmLang->lblEA->Caption;//" 건";
  287. String sEnd = FrmLang->lblQrySel->Caption + " [" + LblRecords->Caption + "]";//"데이터 " + LblRecords->Caption + " 이 조회 되었습니다.";
  288. Application->MessageBox(sEnd.c_str(),
  289. FrmLang->lblQryEnd->Caption.c_str(),//L"데이터 조회 완료",
  290. MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
  291. }
  292. }
  293. catch(EDatabaseError &E)
  294. {
  295. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  296. throw Exception(String(E.ClassName()) + E.Message);
  297. }
  298. catch(...)
  299. {
  300. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  301. throw Exception(FrmLang->lblDbErr->Caption);//"알수없는 오류가 발생하였습니다.");
  302. }
  303. }
  304. //---------------------------------------------------------------------------
  305. void __fastcall TTAS00501::DrawChart(String ATitle)
  306. {
  307. TcxGridBandedTableView *pView = NULL;
  308. String sAxisX, sAxisY;
  309. int nAxisY1, nAxisY2, nStColIdx, nEdColIdx, nTotColIdx;
  310. nEdColIdx = 0;
  311. nTotColIdx = -1;
  312. pView = TvList;
  313. nAxisY1 = Col03->Index; //특수일
  314. nAxisY2 = Col04->Index; //구분(화면보이지 않음)
  315. nEdColIdx = TvListColumn29->Index; // 23시
  316. nStColIdx = ColSped->Index; // 00시
  317. /*
  318. * Chart draw
  319. */
  320. try
  321. {
  322. m_pFrmChart->Clear();
  323. if (pView->DataController->RecordCount == 0)
  324. {
  325. return;
  326. }
  327. m_pFrmChart->BeginDraw("", "", "");
  328. m_pFrmChart->DrawChart5_1((TcxGridTableView *)pView, nAxisY1, nAxisY2, nStColIdx, nEdColIdx, nTotColIdx);
  329. m_pFrmChart->EndDraw();
  330. }
  331. catch(...)
  332. {
  333. }
  334. }
  335. //---------------------------------------------------------------------------
  336. void __fastcall TTAS00501::OnMessage(TMessage &Msg)
  337. {
  338. switch (Msg.Msg)
  339. {
  340. case WM_PARAM_DATABASE:
  341. if (WP_DB_SELECT_OK == Msg.WParam)
  342. {
  343. //ShowMessage("Select Ok");
  344. }
  345. break;
  346. }
  347. }
  348. //---------------------------------------------------------------------------
  349. void __fastcall TTAS00501::BtnExlSaveClick(TObject *Sender)
  350. {
  351. TcxGrid *pGrid = CxList;
  352. TcxGridTableView *pView = TvList;
  353. String sTitle= Caption;//"우회도로분석";
  354. CMM_ExportToExcelFile(sTitle, pGrid, pView, this);
  355. }
  356. //---------------------------------------------------------------------------
  357. void __fastcall TTAS00501::FormClose(TObject *Sender, TCloseAction &Action)
  358. {
  359. POST_MSG(FParent, WM_SUBFORM_CLOSE, 0, 0);
  360. CommClose();
  361. //TAS00501 = NULL;
  362. }
  363. //---------------------------------------------------------------------------
  364. void __fastcall TTAS00501::FormDestroy(TObject *Sender)
  365. {
  366. CommClose();
  367. }
  368. //---------------------------------------------------------------------------
  369. void __fastcall TTAS00501::FormCreate(TObject *Sender)
  370. {
  371. m_pFrmChart = new TPlugInChart(this);
  372. m_pFrmChart->Parent = PnlChart;
  373. m_pFrmChart->SetChartInfo("", "시간", "속도");
  374. m_pFrmChart->Show();
  375. }
  376. //---------------------------------------------------------------------------
  377. void __fastcall TTAS00501::ColSpedCustomDrawCell(TcxCustomGridTableView *Sender, TcxCanvas *ACanvas,
  378. TcxGridTableDataCellViewInfo *AViewInfo, bool &ADone)
  379. {
  380. TColor tColor = ACanvas->Brush->Color;
  381. TColor tFont = clBlack;
  382. try
  383. {
  384. if (!VarIsNull(AViewInfo->Value))
  385. {
  386. String sSpd = AViewInfo->Value;
  387. if (sSpd == NULL || sSpd.IsEmpty() || sSpd == "0" || sSpd == "-")
  388. {
  389. tColor = clSilver;
  390. }
  391. else
  392. {
  393. String sGrad = AViewInfo->GridRecord->DisplayTexts[AViewInfo->Item->Index+24];
  394. if (sGrad == "LTC1") tColor = clLime;
  395. else if (sGrad == "LTC2") tColor = clYellow;
  396. else if (sGrad == "LTC3") tColor = clRed;
  397. else tColor = clSilver;
  398. }
  399. }
  400. else
  401. {
  402. tColor = clSilver;
  403. }
  404. if (tColor == clSilver) tFont = tColor;
  405. ACanvas->Font->Color = tFont;
  406. ACanvas->SetBrushColor(tColor);
  407. }
  408. catch(...)
  409. {
  410. }
  411. }
  412. //---------------------------------------------------------------------------
  413. void __fastcall TTAS00501::TvListDiffCustomDrawCell(TcxCustomGridTableView *Sender,
  414. TcxCanvas *ACanvas, TcxGridTableDataCellViewInfo *AViewInfo,
  415. bool &ADone)
  416. {
  417. TColor tColor = ACanvas->Brush->Color;
  418. TColor tFont = clBlack;
  419. try
  420. {
  421. if (!VarIsNull(AViewInfo->Value))
  422. {
  423. String sTmp = AViewInfo->Value;
  424. int sVal = sTmp.ToIntDef(99999);
  425. if (sVal != 99999)
  426. {
  427. if (sVal > 2)
  428. {
  429. tColor = clRed;
  430. }
  431. else
  432. if (sVal < -2)
  433. {
  434. tColor = clFuchsia;
  435. }
  436. else
  437. {
  438. tColor = clLime;
  439. }
  440. }
  441. }
  442. ACanvas->Font->Color = tFont;
  443. ACanvas->SetBrushColor(tColor);
  444. }
  445. catch(...)
  446. {
  447. }
  448. }
  449. //---------------------------------------------------------------------------