ADOMyRecordSet.cpp
上传用户:yffx2008
上传日期:2014-10-12
资源大小:12414k
文件大小:8k
源码类别:

交通/航空行业

开发平台:

Visual C++

  1. // ADOMyRecordSet.cpp: implementation of the CADOMyRecordSet class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "GpsSC.h"
  6. #include "ADOMyRecordSet.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. //////////////////////////////////////////////////////////////////////
  13. // Construction/Destruction
  14. //////////////////////////////////////////////////////////////////////
  15. extern CGpsSCApp theApp;
  16. CString CADOMyRecordSet::m_strHabitus="";
  17. CADOMyRecordSet::CADOMyRecordSet()
  18. {
  19. }
  20. CADOMyRecordSet::~CADOMyRecordSet()
  21. {
  22. m_pRecordset->Close();
  23. // m_pRecordset.Release();
  24. m_pRecordset = NULL;
  25. }
  26. void CADOMyRecordSet::Open(CString strTableName,int nType)
  27. {
  28. try
  29. {
  30. m_pRecordset.CreateInstance(__uuidof(Recordset));
  31. CString strSql;
  32. if(nType==0)
  33. strSql = "SELECT * FROM "+strTableName;
  34. else
  35. strSql = "SELECT * FROM "+strTableName+" ORDER BY DriverID";
  36. m_pRecordset->Open(_variant_t(strSql),(IDispatch *)theApp.m_pConnection,adOpenDynamic,adLockOptimistic,adCmdText);
  37. }
  38. catch (_com_error &e)
  39. {
  40. ::MessageBox(NULL,e.Description(),"OPEN提示",
  41. MB_OK | MB_ICONWARNING);
  42. }
  43. }
  44. void CADOMyRecordSet::Open(CString strTableName,CString str_sql)
  45. {
  46. try
  47. {
  48. m_pRecordset.CreateInstance(__uuidof(Recordset));
  49. CString strSql;
  50. if(str_sql!="")
  51. strSql = "SELECT * FROM "+strTableName+" WHERE"+str_sql;
  52. else
  53. strSql = "SELECT * FROM "+strTableName;
  54. m_pRecordset->Open(_variant_t(strSql),(IDispatch *)theApp.m_pConnection,adOpenDynamic,adLockOptimistic,adCmdText);
  55. }
  56. catch (_com_error &e)
  57. {
  58. ::MessageBox(NULL,e.Description(),"OPEN提示",
  59. MB_OK | MB_ICONWARNING);
  60. }
  61. }
  62. void CADOMyRecordSet::Open()
  63. {
  64. CString m_strRoad,RetTime;
  65. CTime time = CTime::GetCurrentTime();
  66. RetTime = time.Format("%Y/%m/%d/");
  67. try
  68. {
  69. m_pRecordset.CreateInstance(__uuidof(Recordset));
  70. CString strSql = "SELECT DISTINCT VehicleID FROM VehicleConveyInfo WHERE DateTime LIKE '"+RetTime+"%' ORDER BY VehicleID";
  71. m_pRecordset->Open(_variant_t(strSql),(IDispatch *)theApp.m_pConnection,adOpenDynamic,adLockOptimistic,adCmdText);
  72. }
  73. catch (_com_error &e)
  74. {
  75. ::MessageBox(NULL,e.Description(),"OPEN提示",
  76. MB_OK | MB_ICONWARNING);
  77. }
  78. }
  79. void CADOMyRecordSet::AddVehicleConveyInfo( CReceDataFromBus *pReceBus,CString str_DriverName)
  80. {
  81. CString m_strRoad,RetTime;
  82. CTime time = CTime::GetCurrentTime();
  83. RetTime = time.Format("%Y/%m/%d/");
  84. if(pReceBus->m_sBusLineID.Right(1)=='U')
  85. m_strRoad="上行";
  86. if(pReceBus->m_sBusLineID.Right(1)=='D')
  87. m_strRoad="下行";
  88. if(pReceBus->m_sOrderType=="23")
  89. m_strHabitus="路堵";
  90. if(pReceBus->m_sOrderType=="24")
  91. m_strHabitus="事故";
  92. if(pReceBus->m_sOrderType=="25")
  93. m_strHabitus="故障";
  94. if(pReceBus->m_sOrderType=="26")
  95. m_strHabitus="报警";
  96. if(pReceBus->m_sOrderType=="27")
  97. m_strHabitus="纠纷";
  98. if(pReceBus->m_sOrderType=="30")
  99. m_strHabitus="正常";
  100. if(pReceBus->m_sOrderType=="31")
  101. m_strHabitus="超速";
  102. if(pReceBus->m_sOrderType=="32")
  103. m_strHabitus="进站";
  104. if(pReceBus->m_sOrderType=="33")
  105. m_strHabitus="出站";
  106. try
  107. {
  108. m_pRecordset->AddNew();
  109. m_pRecordset->PutCollect("VehicleType", _variant_t(pReceBus->m_sVehicleType));
  110. m_pRecordset->PutCollect("DriverName", _variant_t(str_DriverName));
  111. m_pRecordset->PutCollect("DriverID", _variant_t(pReceBus->m_sDriverID));
  112. m_pRecordset->PutCollect("VehicleID", _variant_t(pReceBus->m_sVehicleID));
  113. m_pRecordset->PutCollect("BusWay", _variant_t(pReceBus->m_sBusLineID.Left(3)+m_strRoad));
  114. m_pRecordset->PutCollect("DateTime", _variant_t(RetTime+pReceBus->m_sReceTime));
  115. // m_pRecordset->PutCollect("RoadName", _variant_t(pReceBus->m_sBusRoadSn));
  116. m_pRecordset->PutCollect("RoadID", _variant_t(pReceBus->m_sBusRoadSn));
  117. m_pRecordset->PutCollect("Habitus", _variant_t(m_strHabitus));
  118. m_pRecordset->PutCollect("Longitude", _variant_t(pReceBus->gx));
  119. m_pRecordset->PutCollect("Latitude", _variant_t(pReceBus->gy));
  120. m_pRecordset->PutCollect("Speed", _variant_t(pReceBus->m_sSpeed));
  121. m_pRecordset->PutCollect("Angle", _variant_t(pReceBus->m_sCaurse));
  122. m_pRecordset->Update();
  123. }
  124. catch (_com_error &e)
  125. {
  126. m_pRecordset->Close();
  127. m_pRecordset.Release();
  128. m_pRecordset = NULL;
  129. ::MessageBox(NULL,e.Description(),"VEHICLE添加提示",
  130. MB_OK | MB_ICONWARNING);
  131. }
  132. }
  133. void CADOMyRecordSet::AddClientInfo( CString m_ClientName,
  134. CString str_ClientAge,
  135. CString str_ClientUnits,
  136. CString str_ClientDuty,
  137. CString str_ClientIDcard,
  138. CString str_ClientDrivelicence,
  139. CString str_ClientPhone,
  140. CString str_ClientPassword,
  141. CString str_CarNumber,
  142. CString str_CarType,
  143. CString str_CarColor,
  144. CString str_CarEngine,
  145. CString str_BatholithNo,
  146. CString str_CarPhone)
  147. {
  148. CString RetTime;
  149. CTime time = CTime::GetCurrentTime();
  150. RetTime = time.Format("%Y/%m/%d/%H:%M:%S");
  151. m_strHabitus+="应答";
  152. try
  153. {
  154. m_pRecordset->AddNew();
  155. // m_pRecordset->PutCollect("VehicleID", _variant_t(pReceBus->m_sVehicleID));
  156. // m_pRecordset->PutCollect("Habitus", _variant_t(m_strHabitus));
  157. // m_pRecordset->PutCollect("DateTime", _variant_t(RetTime));
  158. clientinfoSet.m_ClientName        = m_ClientName;
  159. clientinfoSet.m_ClientAge         = m_ClientAge;
  160. clientinfoSet.m_ClientUnits   = m_ClientUnits;
  161. clientinfoSet.m_ClientDuty   = m_ClientDuty;
  162. clientinfoSet.m_ClientIDcard   = m_ClientIDcard;
  163. clientinfoSet.m_ClientDrivelicence= m_ClientDrivelicence;
  164. clientinfoSet.m_ClientPhone       = m_ClientPhone;
  165. clientinfoSet.m_ClientPassword   = m_ClientPassword;
  166. clientinfoSet.m_CarNumber   = m_CarNumber;
  167. clientinfoSet.m_CarType   = m_CarType;
  168. clientinfoSet.m_CarColor   = m_CarColor;
  169. clientinfoSet.m_CarEngine   = m_CarEngine;
  170. clientinfoSet.m_BatholithNo   = m_BatholithNo;
  171. clientinfoSet.m_CarPhone   = m_CarPhone;
  172. m_pRecordset->Update();
  173. }
  174. catch (_com_error &e)
  175. {
  176. m_pRecordset->Close();
  177. m_pRecordset.Release();
  178. m_pRecordset = NULL;
  179. ::MessageBox(NULL,e.Description(),"CENTER添加提示",
  180. MB_OK | MB_ICONWARNING);
  181. }
  182. }
  183. CString CADOMyRecordSet::GetDriverName( CReceDataFromBus *pReceBus)
  184. {
  185. CString strDriverName;
  186. try
  187. {
  188. m_pRecordset.CreateInstance(__uuidof(Recordset));
  189. _variant_t vDriverName;
  190. CString strSql = "SELECT DriverName FROM DriverInfo WHERE DriverID='"+pReceBus->m_sDriverID+"'";
  191. m_pRecordset->Open(_variant_t(strSql),(IDispatch *)theApp.m_pConnection,adOpenDynamic,adLockOptimistic,adCmdText);
  192. if(m_pRecordset->adoEOF==VARIANT_FALSE)
  193. vDriverName = m_pRecordset->GetCollect("DriverName");
  194. strDriverName = (char*)_bstr_t(vDriverName);
  195. vDriverName.Clear();
  196. m_pRecordset->Close();
  197. // m_pRecordset.Release();
  198. m_pRecordset = NULL;
  199. }
  200. catch (_com_error &e)
  201. {
  202. m_pRecordset->Close();
  203. m_pRecordset.Release();
  204. m_pRecordset = NULL;
  205. ::MessageBox(NULL,e.Description(),"OPEN提示",
  206. MB_OK | MB_ICONWARNING);
  207. }
  208. return strDriverName;
  209. }
  210. void CADOMyRecordSet::DeleteAllInfo(CString strTableName,CString str_sql)
  211. {
  212. try
  213. {
  214. m_pRecordset.CreateInstance(__uuidof(Recordset));
  215. CString strSql;
  216. if(str_sql!="")
  217. strSql = "SELECT * FROM "+strTableName+" WHERE"+str_sql;
  218. else
  219. strSql = "SELECT * FROM "+strTableName;
  220. m_pRecordset->Open(_variant_t(strSql),(IDispatch *)theApp.m_pConnection,adOpenDynamic,adLockOptimistic,adCmdText);
  221. if(m_pRecordset->adoEOF==VARIANT_FALSE)
  222. {
  223. m_pRecordset->MoveFirst();
  224. AfxGetApp()->BeginWaitCursor();
  225. while(m_pRecordset->adoEOF==VARIANT_FALSE)
  226. {
  227. m_pRecordset->Delete(adAffectCurrent);
  228. m_pRecordset->MoveNext();
  229. }
  230. AfxGetApp()->EndWaitCursor();
  231. if(str_sql=="")
  232. AfxMessageBox("清空数据成功!");
  233. else
  234. AfxMessageBox("删除当前数据成功!");
  235. }
  236. else
  237. {
  238. AfxMessageBox("数据已清空!");
  239. }
  240. }
  241. catch (_com_error &e)
  242. {
  243. m_pRecordset->Close();
  244. m_pRecordset.Release();
  245. m_pRecordset = NULL;
  246. ::MessageBox(NULL,e.Description(),"OPEN提示",
  247. MB_OK | MB_ICONWARNING);
  248. }
  249. }