ADOMyRecordSet.cpp
上传用户:yffx2008
上传日期:2014-10-12
资源大小:12414k
文件大小:8k
- // ADOMyRecordSet.cpp: implementation of the CADOMyRecordSet class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "GpsSC.h"
- #include "ADOMyRecordSet.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- extern CGpsSCApp theApp;
- CString CADOMyRecordSet::m_strHabitus="";
- CADOMyRecordSet::CADOMyRecordSet()
- {
- }
- CADOMyRecordSet::~CADOMyRecordSet()
- {
- m_pRecordset->Close();
- // m_pRecordset.Release();
- m_pRecordset = NULL;
- }
- void CADOMyRecordSet::Open(CString strTableName,int nType)
- {
- try
- {
- m_pRecordset.CreateInstance(__uuidof(Recordset));
- CString strSql;
- if(nType==0)
- strSql = "SELECT * FROM "+strTableName;
- else
- strSql = "SELECT * FROM "+strTableName+" ORDER BY DriverID";
- m_pRecordset->Open(_variant_t(strSql),(IDispatch *)theApp.m_pConnection,adOpenDynamic,adLockOptimistic,adCmdText);
- }
- catch (_com_error &e)
- {
- ::MessageBox(NULL,e.Description(),"OPEN提示",
- MB_OK | MB_ICONWARNING);
- }
- }
- void CADOMyRecordSet::Open(CString strTableName,CString str_sql)
- {
- try
- {
- m_pRecordset.CreateInstance(__uuidof(Recordset));
- CString strSql;
- if(str_sql!="")
- strSql = "SELECT * FROM "+strTableName+" WHERE"+str_sql;
- else
- strSql = "SELECT * FROM "+strTableName;
- m_pRecordset->Open(_variant_t(strSql),(IDispatch *)theApp.m_pConnection,adOpenDynamic,adLockOptimistic,adCmdText);
- }
- catch (_com_error &e)
- {
- ::MessageBox(NULL,e.Description(),"OPEN提示",
- MB_OK | MB_ICONWARNING);
- }
- }
- void CADOMyRecordSet::Open()
- {
- CString m_strRoad,RetTime;
- CTime time = CTime::GetCurrentTime();
- RetTime = time.Format("%Y/%m/%d/");
- try
- {
- m_pRecordset.CreateInstance(__uuidof(Recordset));
- CString strSql = "SELECT DISTINCT VehicleID FROM VehicleConveyInfo WHERE DateTime LIKE '"+RetTime+"%' ORDER BY VehicleID";
- m_pRecordset->Open(_variant_t(strSql),(IDispatch *)theApp.m_pConnection,adOpenDynamic,adLockOptimistic,adCmdText);
- }
- catch (_com_error &e)
- {
- ::MessageBox(NULL,e.Description(),"OPEN提示",
- MB_OK | MB_ICONWARNING);
- }
- }
- void CADOMyRecordSet::AddVehicleConveyInfo( CReceDataFromBus *pReceBus,CString str_DriverName)
- {
- CString m_strRoad,RetTime;
- CTime time = CTime::GetCurrentTime();
- RetTime = time.Format("%Y/%m/%d/");
- if(pReceBus->m_sBusLineID.Right(1)=='U')
- m_strRoad="上行";
- if(pReceBus->m_sBusLineID.Right(1)=='D')
- m_strRoad="下行";
- if(pReceBus->m_sOrderType=="23")
- m_strHabitus="路堵";
- if(pReceBus->m_sOrderType=="24")
- m_strHabitus="事故";
- if(pReceBus->m_sOrderType=="25")
- m_strHabitus="故障";
- if(pReceBus->m_sOrderType=="26")
- m_strHabitus="报警";
- if(pReceBus->m_sOrderType=="27")
- m_strHabitus="纠纷";
- if(pReceBus->m_sOrderType=="30")
- m_strHabitus="正常";
- if(pReceBus->m_sOrderType=="31")
- m_strHabitus="超速";
- if(pReceBus->m_sOrderType=="32")
- m_strHabitus="进站";
- if(pReceBus->m_sOrderType=="33")
- m_strHabitus="出站";
- try
- {
- m_pRecordset->AddNew();
- m_pRecordset->PutCollect("VehicleType", _variant_t(pReceBus->m_sVehicleType));
- m_pRecordset->PutCollect("DriverName", _variant_t(str_DriverName));
- m_pRecordset->PutCollect("DriverID", _variant_t(pReceBus->m_sDriverID));
- m_pRecordset->PutCollect("VehicleID", _variant_t(pReceBus->m_sVehicleID));
- m_pRecordset->PutCollect("BusWay", _variant_t(pReceBus->m_sBusLineID.Left(3)+m_strRoad));
- m_pRecordset->PutCollect("DateTime", _variant_t(RetTime+pReceBus->m_sReceTime));
- // m_pRecordset->PutCollect("RoadName", _variant_t(pReceBus->m_sBusRoadSn));
- m_pRecordset->PutCollect("RoadID", _variant_t(pReceBus->m_sBusRoadSn));
- m_pRecordset->PutCollect("Habitus", _variant_t(m_strHabitus));
- m_pRecordset->PutCollect("Longitude", _variant_t(pReceBus->gx));
- m_pRecordset->PutCollect("Latitude", _variant_t(pReceBus->gy));
- m_pRecordset->PutCollect("Speed", _variant_t(pReceBus->m_sSpeed));
- m_pRecordset->PutCollect("Angle", _variant_t(pReceBus->m_sCaurse));
- m_pRecordset->Update();
- }
- catch (_com_error &e)
- {
- m_pRecordset->Close();
- m_pRecordset.Release();
- m_pRecordset = NULL;
- ::MessageBox(NULL,e.Description(),"VEHICLE添加提示",
- MB_OK | MB_ICONWARNING);
- }
- }
- void CADOMyRecordSet::AddClientInfo( CString m_ClientName,
- CString str_ClientAge,
- CString str_ClientUnits,
- CString str_ClientDuty,
- CString str_ClientIDcard,
- CString str_ClientDrivelicence,
- CString str_ClientPhone,
- CString str_ClientPassword,
- CString str_CarNumber,
- CString str_CarType,
- CString str_CarColor,
- CString str_CarEngine,
- CString str_BatholithNo,
- CString str_CarPhone)
- {
- CString RetTime;
- CTime time = CTime::GetCurrentTime();
- RetTime = time.Format("%Y/%m/%d/%H:%M:%S");
- m_strHabitus+="应答";
- try
- {
- m_pRecordset->AddNew();
- // m_pRecordset->PutCollect("VehicleID", _variant_t(pReceBus->m_sVehicleID));
- // m_pRecordset->PutCollect("Habitus", _variant_t(m_strHabitus));
- // m_pRecordset->PutCollect("DateTime", _variant_t(RetTime));
- clientinfoSet.m_ClientName = m_ClientName;
- clientinfoSet.m_ClientAge = m_ClientAge;
- clientinfoSet.m_ClientUnits = m_ClientUnits;
- clientinfoSet.m_ClientDuty = m_ClientDuty;
- clientinfoSet.m_ClientIDcard = m_ClientIDcard;
- clientinfoSet.m_ClientDrivelicence= m_ClientDrivelicence;
- clientinfoSet.m_ClientPhone = m_ClientPhone;
- clientinfoSet.m_ClientPassword = m_ClientPassword;
- clientinfoSet.m_CarNumber = m_CarNumber;
- clientinfoSet.m_CarType = m_CarType;
- clientinfoSet.m_CarColor = m_CarColor;
- clientinfoSet.m_CarEngine = m_CarEngine;
- clientinfoSet.m_BatholithNo = m_BatholithNo;
- clientinfoSet.m_CarPhone = m_CarPhone;
- m_pRecordset->Update();
- }
- catch (_com_error &e)
- {
- m_pRecordset->Close();
- m_pRecordset.Release();
- m_pRecordset = NULL;
- ::MessageBox(NULL,e.Description(),"CENTER添加提示",
- MB_OK | MB_ICONWARNING);
- }
- }
- CString CADOMyRecordSet::GetDriverName( CReceDataFromBus *pReceBus)
- {
- CString strDriverName;
- try
- {
- m_pRecordset.CreateInstance(__uuidof(Recordset));
- _variant_t vDriverName;
- CString strSql = "SELECT DriverName FROM DriverInfo WHERE DriverID='"+pReceBus->m_sDriverID+"'";
- m_pRecordset->Open(_variant_t(strSql),(IDispatch *)theApp.m_pConnection,adOpenDynamic,adLockOptimistic,adCmdText);
- if(m_pRecordset->adoEOF==VARIANT_FALSE)
- vDriverName = m_pRecordset->GetCollect("DriverName");
- strDriverName = (char*)_bstr_t(vDriverName);
- vDriverName.Clear();
- m_pRecordset->Close();
- // m_pRecordset.Release();
- m_pRecordset = NULL;
- }
- catch (_com_error &e)
- {
- m_pRecordset->Close();
- m_pRecordset.Release();
- m_pRecordset = NULL;
- ::MessageBox(NULL,e.Description(),"OPEN提示",
- MB_OK | MB_ICONWARNING);
- }
- return strDriverName;
- }
- void CADOMyRecordSet::DeleteAllInfo(CString strTableName,CString str_sql)
- {
- try
- {
- m_pRecordset.CreateInstance(__uuidof(Recordset));
- CString strSql;
- if(str_sql!="")
- strSql = "SELECT * FROM "+strTableName+" WHERE"+str_sql;
- else
- strSql = "SELECT * FROM "+strTableName;
- m_pRecordset->Open(_variant_t(strSql),(IDispatch *)theApp.m_pConnection,adOpenDynamic,adLockOptimistic,adCmdText);
- if(m_pRecordset->adoEOF==VARIANT_FALSE)
- {
- m_pRecordset->MoveFirst();
- AfxGetApp()->BeginWaitCursor();
- while(m_pRecordset->adoEOF==VARIANT_FALSE)
- {
- m_pRecordset->Delete(adAffectCurrent);
- m_pRecordset->MoveNext();
- }
- AfxGetApp()->EndWaitCursor();
- if(str_sql=="")
- AfxMessageBox("清空数据成功!");
- else
- AfxMessageBox("删除当前数据成功!");
- }
- else
- {
- AfxMessageBox("数据已清空!");
- }
- }
- catch (_com_error &e)
- {
- m_pRecordset->Close();
- m_pRecordset.Release();
- m_pRecordset = NULL;
- ::MessageBox(NULL,e.Description(),"OPEN提示",
- MB_OK | MB_ICONWARNING);
- }
- }