DALMyBools.cpp
上传用户:weisheen
上传日期:2022-07-09
资源大小:19390k
文件大小:4k
源码类别:

ActiveX/DCOM/ATL

开发平台:

Visual C++

  1. // DALMyBools.cpp : Implementation of CDALMyBools
  2. #include "stdafx.h"
  3. #include "BooksDAL.h"
  4. #include "DALMyBools.h"
  5. /////////////////////////////////////////////////////////////////////////////
  6. // CDALMyBools
  7. STDMETHODIMP CDALMyBools::InterfaceSupportsErrorInfo(REFIID riid)
  8. {
  9. static const IID* arr[] = 
  10. {
  11. &IID_IDALMyBools
  12. };
  13. for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
  14. {
  15. if (InlineIsEqualGUID(*arr[i],riid))
  16. return S_OK;
  17. }
  18. return S_FALSE;
  19. }
  20. STDMETHODIMP CDALMyBools::GetBookByIsbn(UINT bookisbn, DTOBook **mybook)
  21. {
  22. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  23. // TODO: Add your implementation code here
  24. _ConnectionPtr conn=this->GetMyConn();
  25. *mybook=(DTOBook*)::CoTaskMemAlloc(sizeof(DTOBook));
  26. _CommandPtr sqlobj;
  27. sqlobj.CreateInstance(__uuidof(Command));
  28. sqlobj->CommandText=(_bstr_t)this->m_sqlQueryById;
  29. sqlobj->CommandType=adCmdText;
  30. sqlobj->ActiveConnection=conn;
  31. // _ParameterPtr para1=sqlobj->CreateParameter("id",adInteger,adParamInput,4);
  32. // para1->Value=_variant_t((long)bookisbn);
  33. sqlobj->Parameters->Append(GetIdPara(bookisbn,sqlobj));
  34. _RecordsetPtr data=sqlobj->Execute(NULL,NULL,adCmdText);
  35. if(!data->adEOF)
  36. {
  37. (*mybook)->BookIsnb=(UINT)(long)(data->GetCollect("bookisnb"));
  38. _variant_t vtname=data->GetCollect("bookname");
  39. (*mybook)->BookName=::SysAllocString(vtname.bstrVal);
  40. _variant_t vtauthor=data->GetCollect("bookauthor");
  41. (*mybook)->BookAuthor=::SysAllocString(vtauthor.bstrVal);
  42. }
  43. return S_OK;
  44. }
  45. STDMETHODIMP CDALMyBools::QueryAllBook(DTOBook **allBook)
  46. {
  47. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  48. // TODO: Add your implementation code here
  49. return S_OK;
  50. }
  51. STDMETHODIMP CDALMyBools::SaveBook(DTOBook *bookdata, UINT *pResult)
  52. {
  53. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  54. // TODO: Add your implementation code here
  55. return S_OK;
  56. }
  57. STDMETHODIMP CDALMyBools::DeleteBookById(UINT id, UINT *iResult)
  58. {
  59. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  60. // TODO: Add your implementation code here
  61. _ConnectionPtr conn=this->GetMyConn();
  62. _CommandPtr sqlobj;
  63. sqlobj.CreateInstance(__uuidof(Command));
  64. sqlobj->CommandText=(_bstr_t)this->m_sqlDelete;
  65. sqlobj->CommandType=adCmdText;
  66. sqlobj->ActiveConnection=conn;
  67. sqlobj->Parameters->Append(GetIdPara(id,sqlobj));
  68. VARIANT vResult;
  69. vResult.vt=VT_I4;
  70. try{
  71. sqlobj->Execute(&vResult,NULL,adCmdText);
  72. }
  73. catch(_com_error ex)
  74. {
  75. int i=0;
  76. i=i+1;
  77. }
  78. *iResult=vResult.lVal;
  79. return S_OK;
  80. }
  81. STDMETHODIMP CDALMyBools::Update(DTOBook *Book, UINT *iResult)
  82. {
  83. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  84. // TODO: Add your implementation code here
  85. return S_OK;
  86. }
  87. STDMETHODIMP CDALMyBools::get_UID(BSTR *pVal)
  88. {
  89. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  90. // TODO: Add your implementation code here
  91. return S_OK;
  92. }
  93. STDMETHODIMP CDALMyBools::put_UID(BSTR newVal)
  94. {
  95. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  96. // TODO: Add your implementation code here
  97. this->m_UID=CString(newVal);
  98. ::SysFreeString(newVal);
  99. return S_OK;
  100. }
  101. STDMETHODIMP CDALMyBools::get_PWD(BSTR *pVal)
  102. {
  103. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  104. // TODO: Add your implementation code here
  105. return S_OK;
  106. }
  107. STDMETHODIMP CDALMyBools::put_PWD(BSTR newVal)
  108. {
  109. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  110. // TODO: Add your implementation code here
  111. this->m_PWD=CString(newVal);
  112. ::SysFreeString(newVal);
  113. return S_OK;
  114. }
  115. STDMETHODIMP CDALMyBools::get_DataSource(BSTR *pVal)
  116. {
  117. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  118. // TODO: Add your implementation code here
  119. return S_OK;
  120. }
  121. STDMETHODIMP CDALMyBools::put_DataSource(BSTR newVal)
  122. {
  123. AFX_MANAGE_STATE(AfxGetStaticModuleState())
  124. // TODO: Add your implementation code here
  125. this->m_DataSource=CString(newVal);
  126. ::SysFreeString(newVal);
  127. return S_OK;
  128. }
  129. _ConnectionPtr CDALMyBools::GetMyConn()
  130. {
  131. CString strFormat="Provider=OraOLEDB.Oracle.1;User Id=%s;Data Source=%s";
  132. CString str;
  133. str.Format(strFormat,this->m_UID,this->m_DataSource);
  134. _ConnectionPtr mytools;
  135. mytools.CreateInstance(__uuidof(Connection));
  136. mytools->Open(_bstr_t(str),"",_bstr_t(this->m_PWD),-1);
  137. return mytools;
  138. }
  139. _ParameterPtr CDALMyBools::GetIdPara(UINT id,_CommandPtr sqlObj)
  140. {
  141. _ParameterPtr para1=sqlObj->CreateParameter("id",adInteger,adParamInput,4);
  142. para1->Value=_variant_t((long)id);
  143. return para1;
  144. }