TAS00801F.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  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 "TAS00801F.h"
  11. //---------------------------------------------------------------------------
  12. #pragma package(smart_init)
  13. #pragma link "cxButtons"
  14. #pragma link "cxCalc"
  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 "cxGridCustomTableView"
  27. #pragma link "cxGridCustomView"
  28. #pragma link "cxGridLevel"
  29. #pragma link "cxGridTableView"
  30. #pragma link "cxLabel"
  31. #pragma link "cxLookAndFeelPainters"
  32. #pragma link "cxLookAndFeels"
  33. #pragma link "cxSplitter"
  34. #pragma link "cxStyles"
  35. #pragma link "cxTextEdit"
  36. #pragma link "dxmdaset"
  37. #pragma link "dxSkinBlue"
  38. #pragma link "dxSkinsCore"
  39. #pragma link "dxSkinscxPCPainter"
  40. #pragma resource "*.dfm"
  41. TTAS00801 *TAS00801 = NULL;
  42. //---------------------------------------------------------------------------
  43. __fastcall TTAS00801::TTAS00801(TComponent* Owner, HWND hHandle,
  44. String AStDay, String AEdDay, String AStHour, String AEdHour, String AWeek, String ADir, String AAtrdNm, int ATable, int AQryType, TVdsCtlrManager* AManager)
  45. : TForm(Owner)
  46. {
  47. LangTrans->Translate(this, ITSDb_GetConnection());
  48. ITSSkin_Load(this);
  49. CMM_LoadForm(g_sFormsDir, this);
  50. FParent = hHandle;
  51. FStDay = AStDay;
  52. FEdDay = AEdDay;
  53. FStHour = AStHour;
  54. FEdHour = AEdHour;
  55. FWeek = AWeek;
  56. FDir = ADir;
  57. FAtrdNm = AAtrdNm;
  58. FTable = ATable;
  59. FQryType = AQryType;
  60. FColumn[ 0] = Column03;
  61. FColumn[ 1] = Column04;
  62. FColumn[ 2] = Column05;
  63. FColumn[ 3] = Column06;
  64. FColumn[ 4] = Column07;
  65. FColumn[ 5] = Column08;
  66. FColumn[ 6] = Column09;
  67. FColumn[ 7] = Column10;
  68. FColumn[ 8] = Column11;
  69. FColumn[ 9] = Column12;
  70. FColumn[10] = Column13;
  71. FColumn[11] = Column14;
  72. FColumn[12] = Column15;
  73. FColumn[13] = Column16;
  74. FColumn[14] = Column17;
  75. int ii = 0;
  76. for (ii = 0; ii < MAX_COLSYS; ii++)
  77. {
  78. FChart[ii] = NULL;
  79. }
  80. ii = 0;
  81. FOR_STL(TItsColSys*, pObj, ItsColSysManager->FLists)
  82. {
  83. if (pObj->USE_YN == "N") continue;
  84. FColumn[ii]->Caption = pObj->CLCT_SYST_NM;
  85. FColumn[ii]->Visible = true;
  86. ii++;
  87. if (ii >= MAX_COLSYS) break;
  88. }
  89. FStatManager = new TStat0080Manager();
  90. FChartManager = new TStat0080ChartManager();
  91. MyManager = AManager;
  92. }
  93. //---------------------------------------------------------------------------
  94. __fastcall TTAS00801::~TTAS00801(void)
  95. {
  96. }
  97. //--------------------------------------------------------------------------
  98. void __fastcall TTAS00801::FormInit()
  99. {
  100. ADOQry->Connection = ITSDb_GetConnection();
  101. m_pGDC = TvList->DataController;
  102. TvList->OptionsView->NoDataToDisplayInfoText = FrmLang->lblNoInfo->Caption;//"<노선별속도분석 정보>";
  103. LblSearch->Caption = FrmLang->lblQryCond->Caption + FStDay + " ~ " + FEdDay;
  104. }
  105. //---------------------------------------------------------------------------
  106. void __fastcall TTAS00801::FormShow(TObject *Sender)
  107. {
  108. FormInit();
  109. Refresh();
  110. TmrShow->Enabled = true;
  111. }
  112. //---------------------------------------------------------------------------
  113. void __fastcall TTAS00801::CommClose()
  114. {
  115. try
  116. {
  117. delete FStatManager;
  118. FStatManager = NULL;
  119. delete FChartManager;
  120. FChartManager = NULL;
  121. }
  122. catch(Exception &e)
  123. {
  124. }
  125. CMM_SaveForm(g_sFormsDir, this);
  126. //TAS00801 = NULL;
  127. }
  128. //---------------------------------------------------------------------------
  129. void __fastcall TTAS00801::TmrShowTimer(TObject *Sender)
  130. {
  131. TmrShow->Enabled = false;
  132. ChkExpand->Visible = false;
  133. Application->ProcessMessages();
  134. CMM_ClearGridTableView(TvList);
  135. try
  136. {
  137. m_pFrmChart->LblOptionName->Caption = "표출구간";
  138. m_pFrmChart->CbOption->Width = 280;
  139. m_pFrmChart->CbOption->Properties->OnChange = NULL;
  140. m_pFrmChart->CbOption->Properties->Items->Clear();
  141. FOR_STL(TVdsLink*, pObj, MyManager->FLinkLists)
  142. {
  143. if (pObj->IsSelected)
  144. {
  145. m_pFrmChart->CbOption->Properties->Items->Add("[" + pObj->LINK_ID + "] " + pObj->STR_NAME + " → " + pObj->END_NAME);
  146. }
  147. }
  148. //m_pFrmChart->CbOption->Properties->Items->Add("시간");
  149. //m_pFrmChart->CbOption->Properties->Items->Add("일자");
  150. m_pFrmChart->CbOption->ItemIndex = 0;
  151. m_pFrmChart->PnlOption->Visible = true;
  152. TvList->BeginUpdate(lsimImmediate);
  153. SelHistory1();
  154. }
  155. __finally
  156. {
  157. TvList->EndUpdate();
  158. ChkExpand->Visible = true;
  159. }
  160. }
  161. //---------------------------------------------------------------------------
  162. void __fastcall TTAS00801::ChkExpandClick(TObject *Sender)
  163. {
  164. CMM_ExpandCollapseChk(TvList, ChkExpand->Checked);
  165. }
  166. //---------------------------------------------------------------------------
  167. String __fastcall TTAS00801::GetDayWeekCode(String ADay)
  168. {
  169. TDateTime dt;
  170. System::Word Year = (System::Word)ADay.SubString( 1, 4).ToIntDef(2018);
  171. System::Word Month = (System::Word)ADay.SubString( 5, 2).ToIntDef(1);
  172. System::Word Day = (System::Word)ADay.SubString( 7, 2).ToIntDef(1);
  173. dt = EncodeDate(Year, Month, Day);
  174. System::Word week = DayOfWeek(dt);
  175. //const days: array[1..7] of string = ('일','월','화','수','목','금','토');
  176. String sWeek[8] = { "", "DTW7", "DTW1", "DTW2", "DTW3", "DTW4", "DTW5", "DTW6" };
  177. return sWeek[week];
  178. }
  179. //---------------------------------------------------------------------------
  180. void __fastcall TTAS00801::SelHistory1()
  181. {
  182. TSqlCursor sqlCrs;
  183. String sQry;
  184. TADOQuery *pADO = ADOQry;
  185. int ii = 0;
  186. String sTemp;
  187. #if 0
  188. String sFetch = "";
  189. ii = 0;
  190. FOR_STL(TItsColSys*, pObj, ItsColSysManager->FLists)
  191. {
  192. if (pObj->USE_YN == "N") continue;
  193. sTemp = ", MAX(DECODE(A.CLCT_SYST_CD, '" + pObj->CLCT_SYST_CD + "', A.SPED, 0)) " + pObj->CLCT_SYST_CD + " \r\n";
  194. sFetch += sTemp;
  195. ii++;
  196. if (ii >= MAX_COLSYS) break;
  197. }
  198. #endif
  199. String sWhere = "";
  200. if (FAtrdNm.IsEmpty())
  201. {
  202. sWhere = "";
  203. }
  204. else
  205. {
  206. sWhere = " AND A.LINK_ID IN (" + FAtrdNm + ")";
  207. }
  208. String sTmp;
  209. sTmp = "SELECT A.*, SUBSTR(A.PRCN_DT, 9, 4) AS PRCN_DT2 \r\n";
  210. sTmp+= " FROM TB_LINK_TRAF_CLCT_HS A \r\n"
  211. " WHERE A.PRCN_DT BETWEEN :p01 \r\n"
  212. " AND :p02 \r\n"
  213. + sWhere;
  214. sQry = "SELECT A.ROAD_NAME, B.NODE_NAME AS F_NAME, C.NODE_NAME AS T_NAME, \r\n";
  215. sQry+= " D.* \r\n";
  216. sQry+= " FROM TB_LINK A, TB_NODE B, TB_NODE C, \r\n";
  217. sQry+= " ( \r\n";
  218. sQry+= sTmp;
  219. sQry+= " ) D \r\n";
  220. sQry+= " WHERE A.LINK_ID = D.LINK_ID \r\n";
  221. sQry+= " AND A.F_NODE_ID = B.NODE_ID \r\n";
  222. sQry+= " AND A.T_NODE_ID = C.NODE_ID \r\n";
  223. sQry+= " ORDER BY A.LINK_ID, PRCN_DT \r\n";
  224. try
  225. {
  226. ITSDb_SQLText(pADO, sQry);
  227. ITSDb_SQLBind(pADO, "p01", FStDay);
  228. ITSDb_SQLBind(pADO, "p02", FEdDay);
  229. ITSDb_SQLOpen(pADO);
  230. dxMemData1->DisableControls();
  231. dxMemData1->Close();
  232. dxMemData1->CreateFieldsFromDataSet(pADO);
  233. dxMemData1->LoadFromDataSet(pADO);
  234. dxMemData1->Open();
  235. dxMemData1->First();
  236. dxMemData1->EnableControls();
  237. pADO->Close();
  238. DspHistory();
  239. m_pFrmChart->CbOption->Properties->OnChange = CbOptionPropertiesChange;
  240. DrawChart("");
  241. }
  242. catch(EDatabaseError &E)
  243. {
  244. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  245. DBERRORMSG(Caption, String(E.ClassName()), E.Message, sQry);
  246. throw Exception(String(E.ClassName()) + E.Message);
  247. }
  248. catch(Exception &exception)
  249. {
  250. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  251. DBERRORMSG(Caption, String(exception.ClassName()), exception.Message, sQry);
  252. throw Exception(String(exception.ClassName()) + exception.Message);
  253. }
  254. }
  255. //---------------------------------------------------------------------------
  256. void __fastcall TTAS00801::DspHistory()
  257. {
  258. m_pGDC = TvList->DataController;
  259. try
  260. {
  261. int nRow = 0;
  262. int nDataCnt = 0;
  263. int ii = 0;
  264. try
  265. {
  266. int nValue = 0;
  267. while(!dxMemData1->Eof)
  268. {
  269. nRow = m_pGDC->AppendRecord();
  270. String LINK_ID = dxMemData1->Fields->FieldByName("LINK_ID")->AsString;
  271. String STAT_HM = dxMemData1->Fields->FieldByName("PRCN_DT2")->AsString;
  272. String sDbDate = dxMemData1->Fields->FieldByName("PRCN_DT")->AsString;
  273. m_pGDC->Values[nRow][Column01->Index] = ITSUtil_FormatStr(sDbDate, STR_DATETIME);
  274. m_pGDC->Values[nRow][Column02->Index] = LINK_ID;
  275. m_pGDC->Values[nRow][ColRoad->Index] = dxMemData1->Fields->FieldByName("ROAD_NAME")->AsString;
  276. m_pGDC->Values[nRow][ColFName->Index] = dxMemData1->Fields->FieldByName("F_NAME")->AsString;
  277. m_pGDC->Values[nRow][ColTName->Index] = dxMemData1->Fields->FieldByName("T_NAME")->AsString;
  278. TStat0080 *pStat = FStatManager->FLists.Find(LINK_ID);
  279. if (!pStat)
  280. {
  281. pStat = new TStat0080();
  282. pStat->LINK_ID = LINK_ID;
  283. FStatManager->FLists.Push(pStat->LINK_ID, pStat);
  284. }
  285. TTraf0080 *pTraf = pStat->FLists.Find(STAT_HM);
  286. if (!pTraf)
  287. {
  288. pTraf = new TTraf0080();
  289. pTraf->STAT_HM = STAT_HM;
  290. pStat->FLists.Push(pTraf->STAT_HM, pTraf);
  291. }
  292. ii = 0;
  293. FOR_STL(TItsColSys*, pObj, ItsColSysManager->FLists)
  294. {
  295. nValue = dxMemData1->Fields->FieldByName(pObj->CLCT_SYST_CD)->AsInteger;
  296. m_pGDC->Values[nRow][FColumn[ii]->Index] = nValue;
  297. TTrafSped *pSped = new TTrafSped();
  298. pSped->CLCT_SYST_CD = pObj->CLCT_SYST_CD;
  299. pSped->SPED = nValue;
  300. pTraf->FLists.Push(pSped->CLCT_SYST_CD, pSped);
  301. ii++;
  302. if (ii >= MAX_COLSYS) break;
  303. }
  304. dxMemData1->Next();
  305. }
  306. }
  307. __finally
  308. {
  309. dxMemData1->Close();
  310. //CxList->SetFocus();
  311. LblRecords->Caption = FormatFloat("##,##0", m_pGDC->RecordCount) + FrmLang->lblEA->Caption;//" 건";
  312. String sEnd = FrmLang->lblQrySel->Caption + " [" + LblRecords->Caption + "]";//"데이터 " + LblRecords->Caption + " 이 조회 되었습니다.";
  313. Application->MessageBox(sEnd.c_str(),
  314. FrmLang->lblQryEnd->Caption.c_str(),//L"데이터 조회 완료",
  315. MB_OK|MB_ICONINFORMATION|MB_APPLMODAL);
  316. }
  317. }
  318. catch(EDatabaseError &E)
  319. {
  320. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  321. //DBERRORMSG(Caption, String(E.ClassName()), E.Message, pADO->SQL->Text);
  322. throw Exception(String(E.ClassName()) + E.Message);
  323. }
  324. catch(Exception &e)
  325. {
  326. ::PostMessage(Application->MainForm->Handle, (UINT)(WM_USER+0xF4), (WPARAM)0xB2, (LPARAM)0xB2);
  327. //DBERRORMSG(Caption, String(e.ClassName()), e.Message, pADO->SQL->Text);
  328. throw Exception(String(e.ClassName()) + e.Message);
  329. }
  330. }
  331. //---------------------------------------------------------------------------
  332. void __fastcall TTAS00801::DrawChart(String ATitle)
  333. {
  334. m_pFrmChart->Clear();
  335. int ii, jj, kk;
  336. SeriesType SrsType;
  337. TColor clSrsColor;
  338. TChartSeries *pSeries;
  339. TCursor cOldCursor= Screen->Cursor;
  340. Screen->Cursor = crHourGlass;
  341. String LINK_ID = APP_GetCode(m_pFrmChart->CbOption);
  342. m_pFrmChart->SetChartInfo(m_pFrmChart->CbOption->Text.Trim(), "시간", "속도");
  343. TStat0080 *pStat = FStatManager->FLists.Find(LINK_ID);
  344. if (!pStat)
  345. {
  346. return;
  347. }
  348. SrsType = (SeriesType)m_pFrmChart->CbChartKind->ItemIndex;
  349. m_pFrmChart->BeginDraw("", "", "");
  350. m_pFrmChart->LstLegend->Items->BeginUpdate();
  351. ii = jj = kk = 0;
  352. try
  353. {
  354. FOR_STL(TItsColSys*, pObj, ItsColSysManager->FLists)
  355. {
  356. if (pObj->USE_YN == "N") continue;
  357. clSrsColor = GetDefaultColor(kk++);
  358. if (clSrsColor == clWhite) clSrsColor = GetDefaultColor(++kk);
  359. if (clSrsColor == clYellow) clSrsColor = GetDefaultColor(++kk);
  360. pSeries = m_pFrmChart->AddSeriesItem(pObj->CLCT_SYST_NM, SrsType, clSrsColor, true);
  361. if (!pSeries) continue;
  362. FOR_STL(TTraf0080*, pTraf, pStat->FLists)
  363. {
  364. TTrafSped *pSped = pTraf->FLists.Find(pObj->CLCT_SYST_CD);
  365. if (!pSped) continue;
  366. //if (pSped->SPED > 0)
  367. {
  368. pSeries->AddY(pSped->SPED, pTraf->STAT_HM);
  369. }
  370. }
  371. }
  372. m_pFrmChart->DbChart->LeftAxis->Minimum = 0;
  373. m_pFrmChart->DbChart->LeftAxis->Maximum = m_pFrmChart->GetActiveMaxY() + 10;
  374. if (m_pFrmChart->DbChart->LeftAxis->Minimum >= m_pFrmChart->DbChart->LeftAxis->Maximum)
  375. {
  376. m_pFrmChart->DbChart->LeftAxis->Maximum = m_pFrmChart->DbChart->LeftAxis->Minimum + 1;
  377. }
  378. }
  379. __finally
  380. {
  381. m_pFrmChart->DbChart->Refresh();
  382. m_pFrmChart->LstLegend->Items->EndUpdate();
  383. m_pFrmChart->EndDraw();
  384. Screen->Cursor = cOldCursor;
  385. }
  386. }
  387. //---------------------------------------------------------------------------
  388. void __fastcall TTAS00801::OnMessage(TMessage &Msg)
  389. {
  390. switch (Msg.Msg)
  391. {
  392. case WM_PARAM_DATABASE:
  393. if (WP_DB_SELECT_OK == Msg.WParam)
  394. {
  395. //ShowMessage("Select Ok");
  396. }
  397. break;
  398. }
  399. }
  400. //---------------------------------------------------------------------------
  401. void __fastcall TTAS00801::BtnExlSaveClick(TObject *Sender)
  402. {
  403. TcxGrid *pGrid = CxList;
  404. TcxGridTableView *pView = TvList;
  405. String sTitle= Caption;//"노선별속도분석";
  406. CMM_ExportToExcelFile(sTitle, pGrid, pView, this);
  407. }
  408. //---------------------------------------------------------------------------
  409. void __fastcall TTAS00801::FormClose(TObject *Sender, TCloseAction &Action)
  410. {
  411. POST_MSG(FParent, WM_SUBFORM_CLOSE, 0, 0);
  412. CommClose();
  413. //TAS00801 = NULL;
  414. }
  415. //---------------------------------------------------------------------------
  416. void __fastcall TTAS00801::FormDestroy(TObject *Sender)
  417. {
  418. CommClose();
  419. }
  420. //---------------------------------------------------------------------------
  421. void __fastcall TTAS00801::FormCreate(TObject *Sender)
  422. {
  423. m_pFrmChart = new TPlugInChart(this);
  424. m_pFrmChart->Parent = PnlChart;
  425. m_pFrmChart->SetChartInfo("", "시간", "속도");
  426. m_pFrmChart->Show();
  427. }
  428. //---------------------------------------------------------------------------
  429. void __fastcall TTAS00801::CbOptionPropertiesChange(TObject *Sender)
  430. {
  431. TcxComboBox *pCombo = (TcxComboBox*)Sender;
  432. DrawChart("");
  433. m_pFrmChart->SetFocus();
  434. }
  435. //---------------------------------------------------------------------------