/**************************************************************************** * @source : * @description : **************************************************************************** * DATE AUTHOR DESCRIPTION * -------------------------------------------------------------------------- * 2011/12/24 Á¤½ÂÈ£ ÃÖÃÊÀÛ¼º * ****************************************************************************/ //--------------------------------------------------------------------------- #include #include "ITSSkinF.h" #include "ITSUtilF.h" #include "ITSDbF.h" #include "AppGlobalF.h" #include "XiMapUtilF.h" #pragma hdrstop #include "IAN0040MF.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "cxButtons" #pragma link "cxCalc" #pragma link "cxCalendar" #pragma link "cxClasses" #pragma link "cxContainer" #pragma link "cxControls" #pragma link "cxCustomData" #pragma link "cxData" #pragma link "cxDataStorage" #pragma link "cxDropDownEdit" #pragma link "cxEdit" #pragma link "cxFilter" #pragma link "cxGraphics" #pragma link "cxGrid" #pragma link "cxGridCustomTableView" #pragma link "cxGridCustomView" #pragma link "cxGridLevel" #pragma link "cxGridTableView" #pragma link "cxGroupBox" #pragma link "cxLabel" #pragma link "cxLookAndFeelPainters" #pragma link "cxLookAndFeels" #pragma link "cxMaskEdit" #pragma link "cxSpinEdit" #pragma link "cxSplitter" #pragma link "cxStyles" #pragma link "cxTextEdit" #pragma link "cxTimeEdit" #pragma link "cxTrackBar" #pragma link "dxSkinBlack" #pragma link "dxSkinBlue" #pragma link "dxSkinCaramel" #pragma link "dxSkinCoffee" #pragma link "dxSkinDarkRoom" #pragma link "dxSkinDarkSide" #pragma link "dxSkinFoggy" #pragma link "dxSkinGlassOceans" #pragma link "dxSkiniMaginary" #pragma link "dxSkinLilian" #pragma link "dxSkinLiquidSky" #pragma link "dxSkinLondonLiquidSky" #pragma link "dxSkinMcSkin" #pragma link "dxSkinMoneyTwins" #pragma link "dxSkinOffice2007Black" #pragma link "dxSkinOffice2007Blue" #pragma link "dxSkinOffice2007Green" #pragma link "dxSkinOffice2007Pink" #pragma link "dxSkinOffice2007Silver" #pragma link "dxSkinOffice2010Black" #pragma link "dxSkinOffice2010Blue" #pragma link "dxSkinOffice2010Silver" #pragma link "dxSkinsCore" #pragma link "dxSkinscxPCPainter" #pragma link "dxSkinSeven" #pragma link "dxSkinSharp" #pragma link "dxSkinSilver" #pragma link "dxSkinStardust" #pragma link "FRAME_GisMapF" #pragma resource "*.dfm" TIAN0040M *IAN0040M = NULL; //--------------------------------------------------------------------------- __fastcall TIAN0040M::TIAN0040M(TComponent* Owner) : TForm(Owner) { ITSSkin_Load(this); CMM_LoadForm(g_sFormsDir, this); FTitle = "¼ÒÅëÁ¤º¸ À̷ºм®"; //FRAMEGisMap1->GrpTool->Visible = false; FRAMEGisMap1->LbDef->Visible = false; FRAMEGisMap1->ImgRefresh->Visible = false; FRAMEGisMap1->ImgSel->Visible = false; FGisStream = new TMemoryStream(); } //--------------------------------------------------------------------------- /* * ´Ý±â¹öư À̳ª x¹öư Ŭ¸¯½Ã °øÅëÀ¸·Î ó¸®ÇÏ´Â ·ÎÁ÷À̵é¾î°£´Ù.. * Form°ú DataModule class¸¦ delete½ÃŲ´Ù. * arguments * * return * void */ void __fastcall TIAN0040M::CommClose() { try { int ii; FLists.RemoveAll(); if (FGisStream) delete FGisStream; CMM_SaveForm(g_sFormsDir, this); } catch(...) { } } //--------------------------------------------------------------------------- /* * FormÀ» º¸¿©ÁÙ¶§ È£ÃâµÇ´Â event ¸Þ¼­µåÀÌ´Ù. * arguments * Sender : event handler °´Ã¼ * return * void */ void __fastcall TIAN0040M::FormShow(TObject *Sender) { Refresh(); FormInit(); TmrShow->Enabled = true; } //--------------------------------------------------------------------------- /* * form ÃʱâÈ­ * * arguments * * return * void */ void __fastcall TIAN0040M::FormInit() { ADOQry->Connection = ITSDb_GetConnection(); ADOSta->Connection = ITSDb_GetConnection(); m_pGDC = TvList->DataController; TDateTime dtNow = Now() - ((double)3 / (double)24); DtStDate->Date = dtNow; DtEdDate->Date = Now(); DtStTime->EditValue = dtNow.FormatString("hh"); dtNow = Now() - ((double)2 / (double)24); DtEdTime->EditValue = dtNow.FormatString("hh"); } //--------------------------------------------------------------------------- /* * FormÀÌ ShowµÇ°í ³­ ÈÄ ÃÖÃÊ 1ȸ ¼öÇàµÇ´Â ŸÀÌ¸Ó À̺¥Æ® * arguments * Sender : event handler °´Ã¼ * return * void */ void __fastcall TIAN0040M::TmrShowTimer(TObject *Sender) { TmrShow->Enabled = false; if (TmrShow->Tag == 1) { int nIndex = m_pGDC->FocusedRecordIndex; if (nIndex < 0) { cxTrackBar1->Position = 0; FStatTime = ""; BtnPlay->Enabled = true; BtnStop->Enabled = false; BtnSearch->Enabled = true; return; } if (m_pGDC->FocusedRecordIndex + 1 == m_pGDC->RecordCount) { cxTrackBar1->Position = 0; FStatTime = ""; BtnPlay->Enabled = true; BtnStop->Enabled = false; BtnSearch->Enabled = true; return; } m_pGDC->FocusedRecordIndex++; nIndex = m_pGDC->FocusedRecordIndex; FSimIndex = nIndex; cxTrackBar1->Position = nIndex; FStatTime = VarToStr(m_pGDC->Values[nIndex][Column04->Index]); cxGroupBox1->Caption = "¢º ¼ÒÅëÁ¤º¸ Ç¥Ãâ - " + VarToStr(m_pGDC->Values[nIndex][Column02->Index]); SelStatisticsHistory(FStatTime); BtnPlay->Enabled = false; BtnStop->Enabled = true; TmrShow->Interval = SeRefreshSec->Value * 1000; TmrShow->Enabled = true; } else { FRAMEGisMap1->LinkLevel = 2; FRAMEGisMap1->LoadGisMap(); FLayerIdx = FRAMEGisMap1->GetLayerIndex(); if (FLayerIdx >= 0) { TStream *pStream = FRAMEGisMap1->xsrvrMap->GetLayerAttSTM(FLayerIdx); if (pStream) { FGisStream->LoadFromStream(pStream); } } } } //--------------------------------------------------------------------------- /* * Search ¹öư Ŭ¸¯ À̺¥Æ® Çڵ鷯 * arguments * Sender : event handler °´Ã¼ * return * void */ void __fastcall TIAN0040M::BtnSearchClick(TObject *Sender) { FStDateTime = DtStDate->Date.FormatString("yyyymmdd") + DtStTime->Time.FormatString("hh"); FEdDateTime = DtEdDate->Date.FormatString("yyyymmdd") + DtEdTime->Time.FormatString("hh"); if (FStDateTime > FEdDateTime) { Application->MessageBox(L"°Ë»ö ½ÃÀ۽ð¢ÀÌ °Ë»ö Á¾·á½Ã°¢ º¸´Ù Å®´Ï´Ù.", FTitle.c_str(), MB_OK|MB_ICONWARNING|MB_APPLMODAL); ActiveControl = DtStDate; return; } if ( StrToInt(DtEdTime->Time.FormatString("hh")) - StrToInt(DtStTime->Time.FormatString("hh")) >= 3) { Application->MessageBox(L"3½Ã°£ ÀÌ»óÀÇ Á¤º¸¸¦ Á¶È¸ÇÒ ¼ö ¾ø½À´Ï´Ù.", FTitle.c_str(), MB_OK|MB_ICONWARNING|MB_APPLMODAL); ActiveControl = DtStDate; return; } FStDateTime = FStDateTime + "0000"; FEdDateTime = FEdDateTime + "5959"; FIdList = String(CbLinkLevel->ItemIndex+1); SelHistory(); ClearGis(); } //--------------------------------------------------------------------------- /* * Close ¹öư Ŭ¸¯ À̺¥Æ® Çڵ鷯 * arguments * Sender : event handler °´Ã¼ * return * void */ void __fastcall TIAN0040M::BtnCloseClick(TObject *Sender) { Close(); } //--------------------------------------------------------------------------- void __fastcall TIAN0040M::FormClose(TObject *Sender, TCloseAction &Action) { CommClose(); IAN0040M = NULL; Action = caFree; } //--------------------------------------------------------------------------- void __fastcall TIAN0040M::DtStDatePropertiesValidate(TObject *Sender, Variant &DisplayValue, TCaption &ErrorText, bool &Error) { DtEdDate->Date = DtStDate->Date; } //--------------------------------------------------------------------------- void __fastcall TIAN0040M::SelHistory() { TSqlCursor sqlCrs; String sQry; TADOQuery *pADO = ADOQry; int nLevel = StrToInt(FIdList); #if 0 switch(nLevel) { case 1: sQry = "SELECT PRCN_DT, TO_DATE(PRCN_DT, 'YYYYMMDDHH24MISS') AS PRCN_DT2, \r\n" " COUNT(LINK_ID) CNT \r\n" " FROM TB_LINK_TRAF_HS A \r\n" " WHERE PRCN_DT BETWEEN :p01 AND :p02 \r\n" " GROUP BY PRCN_DT \r\n" " ORDER BY PRCN_DT \r\n"; break; case 2: sQry = "SELECT STAT_DT AS PRCN_DT, TO_DATE(STAT_DT, 'YYYYMMDDHH24MISS') AS PRCN_DT2, \r\n" " COUNT(IFSC_ID) CNT \r\n" " FROM TB_IFSC_15M_STAT A \r\n" " WHERE STAT_DT BETWEEN :p01 AND :p02 \r\n" " GROUP BY STAT_DT \r\n" " ORDER BY STAT_DT \r\n"; break; case 3: sQry = "SELECT PRCN_DT, TO_DATE(PRCN_DT, 'YYYYMMDDHH24MISS') AS PRCN_DT2, \r\n" " COUNT(ROAD_ID) CNT \r\n" " FROM TB_ROAD_TRAF_HS A \r\n" " WHERE PRCN_DT BETWEEN :p01 AND :p02 \r\n" " GROUP BY PRCN_DT \r\n" " ORDER BY PRCN_DT \r\n"; break; default: return; } #else switch(nLevel) { case 1: sQry = "SELECT PRCN_DT, COUNT(LINK_ID) CNT \r\n" " FROM TB_LINK_TRAF_HS A \r\n" " WHERE PRCN_DT BETWEEN :p01 AND :p02 \r\n" " GROUP BY PRCN_DT \r\n" " ORDER BY PRCN_DT \r\n"; break; case 2: sQry = "SELECT STAT_DT AS PRCN_DT, COUNT(IFSC_ID) CNT \r\n" " FROM TB_IFSC_15M_STAT A \r\n" " WHERE STAT_DT BETWEEN :p01 AND :p02 \r\n" " GROUP BY STAT_DT \r\n" " ORDER BY STAT_DT \r\n"; break; case 3: sQry = "SELECT PRCN_DT, COUNT(ROAD_ID) CNT \r\n" " FROM TB_ROAD_TRAF_HS A \r\n" " WHERE PRCN_DT BETWEEN :p01 AND :p02 \r\n" " GROUP BY PRCN_DT \r\n" " ORDER BY PRCN_DT \r\n"; break; default: return; } #endif try { ITSDb_SQLText(pADO, sQry); ITSDb_SQLBind(pADO, "p01", FStDateTime); ITSDb_SQLBind(pADO, "p02", FEdDateTime); ITSDb_SQLOpen(pADO); DspHistory(); } catch(EDatabaseError &E) { throw Exception(String(E.ClassName()) + E.Message); } catch(...) { throw Exception("¾Ë¼ö¾ø´Â ¿À·ù°¡ ¹ß»ýÇÏ¿´½À´Ï´Ù."); } } //--------------------------------------------------------------------------- void __fastcall TIAN0040M::DspHistory() { TADOQuery *pADO = ADOQry; try { CMM_ClearGridTableView(TvList); int nRow = 0; try { TvList->BeginUpdate(); m_pGDC->RecordCount = pADO->RecordCount; for( ; !pADO->Eof; pADO->Next(), nRow++) { m_pGDC->Values[nRow][Column01->Index] = nRow+1; //m_pGDC->Values[nRow][Column02->Index] = pADO->FieldByName("PRCN_DT2")->AsDateTime.DateTimeString(); //°¡°ø½Ã°¢ m_pGDC->Values[nRow][Column02->Index] = ITSUtil_StrToTime(pADO->FieldByName("PRCN_DT")->AsString); //°¡°ø½Ã°¢ m_pGDC->Values[nRow][Column03->Index] = pADO->FieldByName("CNT")->AsInteger; m_pGDC->Values[nRow][Column04->Index] = pADO->FieldByName("PRCN_DT")->AsString; } } __finally { if (pADO) { pADO->Close(); } TvList->EndUpdate(); CxList->SetFocus(); //LblRecords->Caption = FormatFloat("##,##0", m_pGDC->RecordCount) + " °Ç"; cxTrackBar1->Position = 0; cxTrackBar1->Properties->Max = nRow; cxTrackBar1->Properties->Frequency = cxTrackBar1->Properties->Max * 0.1; } } catch(EDatabaseError &E) { throw Exception(String(E.ClassName()) + E.Message); } catch(...) { throw Exception("¾Ë¼ö¾ø´Â ¿À·ù°¡ ¹ß»ýÇÏ¿´½À´Ï´Ù."); } } //--------------------------------------------------------------------------- void __fastcall TIAN0040M::BtnPlayClick(TObject *Sender) { if (m_pGDC->RecordCount <= 0) { Application->MessageBox(L"Ç¥ÃâÇÒ Á¤º¸°¡ ¾ø½À´Ï´Ù. ÀÌ·ÂÁ¤º¸¸¦ ´Ù½Ã Á¶È¸ÇϽŠÈÄ ÀÛ¾÷À» ÁøÇà ÇϽʽÿä.", FTitle.c_str(), MB_OK|MB_ICONERROR|MB_APPLMODAL); return; } m_pGDC->FocusedRecordIndex = 0; int nIndex = m_pGDC->FocusedRecordIndex; if (nIndex < 0) return; FSimIndex = nIndex; cxTrackBar1->Position = nIndex; FStatTime = VarToStr(m_pGDC->Values[nIndex][Column04->Index]); CxList->SetFocus(); BtnPlay->Enabled = false; BtnStop->Enabled = true; BtnSearch->Enabled = false; cxGroupBox1->Caption = "¢º ¼ÒÅëÁ¤º¸ Ç¥Ãâ - " + VarToStr(m_pGDC->Values[nIndex][Column02->Index]); SelStatisticsHistory(FStatTime); TmrShow->Tag = 1; TmrShow->Interval = SeRefreshSec->Value * 1000; TmrShow->Enabled = true; } //--------------------------------------------------------------------------- void __fastcall TIAN0040M::BtnStopClick(TObject *Sender) { TmrShow->Enabled = false; BtnPlay->Enabled = true; BtnStop->Enabled = false; BtnSearch->Enabled = true; } //--------------------------------------------------------------------------- void __fastcall TIAN0040M::SelStatisticsHistory(String AStatTime) { int ii; TSqlCursor sqlCrs; String sQry; TADOQuery *pADO = ADOSta; sQry = "SELECT A.IFSC_ID, NVL(B.CMTR_GRAD_CD, 'LTC0') TRFGRD, C.SPED, C.STAT_DT REGDATE \r\n" " FROM TB_IFSC A, \r\n" " TB_CMTR_GRAD_CLSF B, \r\n" " TB_IFSC_15M_STAT C \r\n" " WHERE A.IFSC_ID = C.IFSC_ID \r\n" " AND A.SECT_GRAD_CD = B.SECT_GRAD_CD \r\n" " AND (C.SPED >= B.LWST_TRVL_SPED AND C.SPED <= B.HGHS_TRVL_SPED) \r\n" " AND STAT_DT = :p01 \r\n"; try { FLists.RemoveAll(); if (FLayerIdx < 0 || FGisStream == NULL) return; ITSDb_SQLText(pADO, sQry); ITSDb_SQLBind(pADO, "p01", AStatTime); ITSDb_SQLOpen(pADO); for( ; !pADO->Eof; pADO->Next()) { String sLinkId = pADO->FieldByName("IFSC_ID")->AsString; MYLinkValue *pValue = new MYLinkValue; String TRFGRD = pADO->FieldByName("TRFGRD")->AsString; pValue->Speed = pADO->FieldByName("SPED")->AsInteger; if (TRFGRD == "LTC1") pValue->clrTraffic = clLime; else if (TRFGRD == "LTC2") pValue->clrTraffic = clYellow; else if (TRFGRD == "LTC3") pValue->clrTraffic = clRed; else pValue->clrTraffic = clSilver; FLists.Push(sLinkId, pValue); } TColor clrTraffic = clSilver; System::AnsiString sLinkIDNm = "SD_LINK_ID"; System::AnsiString sColor1Nm = "SD_COLOR1"; System::AnsiString sColor2Nm = "SD_COLOR2"; System::AnsiString sSpeedNm = "SD_SPEED"; int jj, idx; int nFldCnt, nTotCnt; unsigned char sl; TFieldInfos FldInfos; char buf[260]; FGisStream->Position = 0; FGisStream->ReadBuffer(&nTotCnt, 4); FGisStream->ReadBuffer(&nFldCnt,4); FldInfos.Length = nFldCnt; FGisStream->Position = 8; for (ii = 0; ii < nFldCnt; ii++) { FGisStream->ReadBuffer(&sl, 1); memset(buf, 0x00, sizeof(buf)); FGisStream->ReadBuffer(buf, sl); FldInfos[ii].FFieldName = System::AnsiString(buf); FGisStream->ReadBuffer(&(FldInfos[ii].FFieldType), sizeof(FldInfos[ii].FFieldType)); } for (ii = 0; ii < nTotCnt; ii++) { if (FGisStream->Position >= FGisStream->Size) break; for (jj = 0; jj < nFldCnt; jj++) { switch (FldInfos[jj].FFieldType) { case ftSmallint : FGisStream->Position += sizeof(short); break; case ftFloat : FGisStream->Position += sizeof(double); break; case ftWord : FGisStream->Position += sizeof(unsigned short); break; case ftBoolean : FGisStream->Position += sizeof(bool); break; case ftDate : case ftTime : case ftDateTime : FGisStream->Position += sizeof(TDateTime); break; case ftInteger : if (FldInfos[jj].FFieldName == sColor1Nm) { FGisStream->WriteBuffer(&clrTraffic, sizeof(TColor)); } else { FGisStream->Position += sizeof(int); } break; case ftString : case ftWideString : FGisStream->ReadBuffer(&sl, 1); if (sl <= 1) { if (sl == 1) FGisStream->Position += sl; else continue; } else { memset(buf, 0x00, sizeof(buf)); FGisStream->ReadBuffer(buf, sl); if (FldInfos[jj].FFieldName == sLinkIDNm) { String sLinkId = String(buf); MYLinkValue *pValue = FLists.Find(sLinkId); if (pValue) clrTraffic = pValue->clrTraffic; else clrTraffic = clSilver; } } break; default: break; } } } FRAMEGisMap1->xsrvrMap->SetLayerAttSTM(FLayerIdx, FGisStream); FRAMEGisMap1->xclntMap->FullReDraw( ); } catch(EDatabaseError &E) { throw Exception(String(E.ClassName()) + E.Message); } catch(...) { throw Exception("¾Ë¼ö¾ø´Â ¿À·ù°¡ ¹ß»ýÇÏ¿´½À´Ï´Ù."); } } //--------------------------------------------------------------------------- void __fastcall TIAN0040M::ClearGis() { cxGroupBox1->Caption = "¢º ¼ÒÅëÁ¤º¸ Ç¥Ãâ"; } //--------------------------------------------------------------------------- void __fastcall TIAN0040M::TvListCellDblClick(TcxCustomGridTableView *Sender, TcxGridTableDataCellViewInfo *ACellViewInfo, TMouseButton AButton, TShiftState AShift, bool &AHandled) { if (BtnPlay->Enabled == false) return; int nRow = m_pGDC->FocusedRecordIndex; if( nRow <= -1 ) return; FStatTime = VarToStr(m_pGDC->Values[nRow][Column04->Index]); cxGroupBox1->Caption = "¢º ¼ÒÅëÁ¤º¸ Ç¥Ãâ - " + VarToStr(m_pGDC->Values[nRow][Column02->Index]); SelStatisticsHistory(FStatTime); } //--------------------------------------------------------------------------- void __fastcall TIAN0040M::BtnSearch2Click(TObject *Sender) { String sLinkId = EdLinkId->Text.Trim(); TmrClear->Enabled = false; TXiMapUtil::ClearPath(FRAMEGisMap1->xclntMap); TXiMapUtil::MoveServiceLink(FRAMEGisMap1->xclntMap, sLinkId); TmrClear->Enabled = true; } //--------------------------------------------------------------------------- void __fastcall TIAN0040M::TmrClearTimer(TObject *Sender) { try { TXiMapUtil::ClearPath(FRAMEGisMap1->xclntMap); } catch(...) {} } //--------------------------------------------------------------------------- void __fastcall TIAN0040M::cxGroupBox5DblClick(TObject *Sender) { cxGroupBox4->Visible = true; } //---------------------------------------------------------------------------