TAS00901F.cpp 15 KB

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