TAS00901F.cpp 15 KB

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