void CarUpdate () { CCar* c; unsigned now; if (!TextureReady () || !EntityReady ()) return; now = GetTickCount (); if (next_update > now) return; next_update = now + UPDATE_INTERVAL; for (c = head; c; c = c->m_next) c->Update (); }
void __fastcall TGetTrackThread::GetLatestStatus() { //2001.12.25 修正運作方式為只取近期有更動過之資料,以加速大量資料時的處理速度 //2002.5.6 修正運作方式為比對UpdateTime,有更動過才更新 //2002.5.6 將由Database_Local的Database component轉換至本身開啟 sCarStatus CarStatus; memset(&CarStatus,0,sizeof(sCarStatus)); //RESET CarStatus 的記憶體 TQuery* pQArea = new TQuery(NULL); //free in last line pQArea->DatabaseName = "DB_DCH"; pQArea->SQL->Add("SELECT * FROM tArea"); TQuery* pQ_LatestStatus = new TQuery(NULL); //free in the last line pQ_LatestStatus->DatabaseName = "DB_DCH"; pQ_LatestStatus->SQL->Add("SELECT * FROM tLatestStatus"); try { pQArea->Active = true; for(pQ_LatestStatus->Active = true; !pQ_LatestStatus->Eof; pQ_LatestStatus->Next()) { if(Terminated) { //突發性結束 delete pQArea; delete pQ_LatestStatus; return; } AnsiString LocatorNo = pQ_LatestStatus->FieldByName("LocatorNo")->AsString; CCar* pCar = CallCenter_Main_Form->GetCarByLocatorNo(LocatorNo); if(pCar) { //有更動過的資料才更新,以RecvTime來判斷是否更動過資料! TDateTime NewUpdateTime = pQ_LatestStatus->FieldByName("UpdateTime")->AsDateTime; if(pCar->LatestStatusUpdateTime != NewUpdateTime) { pCar->LatestStatusUpdateTime = NewUpdateTime; strcpy(CarStatus.m_szLocatorNo,LocatorNo.c_str()); strcpy(CarStatus.m_szRecvDate,pQ_LatestStatus->FieldByName("RecvDate")->AsString.c_str()); //2002.5.10 轉換RecvTime為六位數 AnsiString RecvTimeStr = pQ_LatestStatus->FieldByName("RecvTime")->AsString.SubString(1,6); strcpy(CarStatus.m_szRecvTime,RecvTimeStr.c_str()); strcpy(CarStatus.m_szSendDate,pQ_LatestStatus->FieldByName("SendDate")->AsString.c_str()); strcpy(CarStatus.m_szSendTime,pQ_LatestStatus->FieldByName("SendTime")->AsString.c_str()); CarStatus.m_iStatus = pQ_LatestStatus->FieldByName("CarStatus")->AsInteger; CarStatus.m_iStatusHandle = pQ_LatestStatus->FieldByName("StatusHandle")->AsInteger; CarStatus.m_iLon = pQ_LatestStatus->FieldByName("Lon")->AsInteger; CarStatus.m_iLat = pQ_LatestStatus->FieldByName("Lat")->AsInteger; CarStatus.m_sSpeed = pQ_LatestStatus->FieldByName("Speed")->AsInteger; CarStatus.m_dMileage = pQ_LatestStatus->FieldByName("Mileage")->AsFloat; //單位公里 CarStatus.ReportRate = pQ_LatestStatus->FieldByName("ReportRate")->AsInteger; //回報頻率 CarStatus.m_szPlaceName = pQ_LatestStatus->FieldByName("PlaceName")->AsString; CarStatus.m_iDistID = pQ_LatestStatus->FieldByName("DistID")->AsInteger; //行政區編號 //取得行政區中文名稱 CarStatus.DistName = NULL; for(pQArea->First(); !pQArea->Eof; pQArea->Next()) { if(CarStatus.m_iDistID == pQArea->FieldByName("AreaID")->AsInteger) { CarStatus.DistName = pQArea->FieldByName("CName")->AsString; break; } } pCar->Update(&CarStatus); pCar->ReportCheckRate = pQ_LatestStatus->FieldByName("ReportChkRate")->AsFloat; //回報檢查頻率 pCar->GPSLock = pQ_LatestStatus->FieldByName("GPSLock")->AsBoolean; memset(&CarStatus,0,sizeof(sCarStatus)); //RESET CarStatus 的記憶體 } } } } catch(EDBEngineError &E) { DataModule1->EstablishConnect(1); } catch(...) { } delete pQArea; delete pQ_LatestStatus; }