TAS00801F.cpp 16 KB

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