class CFeedItem {//RSS条目public:CFeedItem();virtual~CFeedItem();public:CStringm_strAuthor;//作者CStringm_strCategory;//类别CStringm_strDescription;//描述信息CStringm_strLink;//链接地址CStringm_strPubDate;//发布日期CStringm_strSubject;//主题CStringm_strTitle;//标题CStringm_strReadStatus;//是否已读} ; class CFeedSource {//RSS源public:CFeedSource();virtual~CFeedSource();public:CStringm_strCopyright;//版权CStringm_strDescription;//描述信息CStringm_strGenerator;//生产者CStringm_strLanguage;//语言CStringm_strLastBuildDate;//上次构建日期CStringm_strLink;//链接地址CStringm_strTitle;//标题CStringm_strTtl;CStringm_strWebMaster;//管理员CStringm_strImageDescription;//图片描述信息CStringm_strImageHeight;//图片高度CStringm_strImageWidth;//图片宽度CStringm_strImageLink;//图片链接地址CStringm_strImageTitle;//图片标题CStringm_strImageUrl;//图片UrlCStringm_strVersion;//图片版本} ; class CFeed {//RSS种子public:CFeed();CFeed(CStringstrXMLFile);virtual~CFeed();public:staticvoidRefreshAll();staticvoidMarkItemRead(CStringstrLink);staticvoidDeleteFeedSource(CStringstrLink);staticvoidDeleteListArray(CStringArray&strLinkArray);staticvoidGetFeedSourceList(CStringArray&strTitleArray,CStringArray&strLinkArray);voidLoadLocal(CString&strLink);voidBuildFromFile(CStringstrXMLFile);CFeedSourcem_source;//FeedSourceCArray<CFeedItem,CFeedItem>m_item;//FeedItemBOOLm_bAdded;voidSave(BOOLbSaveSource=TRUE);private:staticCStringEscapeQuote(CStringstrValue);staticCStringGetModuleFileDir();staticCStringGetFieldValue(FieldsPtrfields,longnIndex);staticCStringGetComError(_com_error&e);staticBOOLExecuteSQL(_ConnectionPtr&pCnn,CString&strSQL,CString&strMsg);voidGetVersion(MSXML2::IXMLDOMNode*pNode);voidIterateChildNodes(MSXML2::IXMLDOMNode*pNode);voidBuildImage(MSXML2::IXMLDOMNode*pNode);voidBuildItem(MSXML2::IXMLDOMNode*pNode);MSXML2::IXMLDOMDocument2*m_pDoc;//XMLDOMDocumentintm_nDepth;} ; // FeedSource.cpp:implementationoftheCFeedSourceclass. // /**/ ////////////////////////////////////////////////////////////////////// #include " stdafx.h " #include " AgileReader.h " #include " FeedSource.h " #ifdef_DEBUG #undef THIS_FILE static char THIS_FILE[] = __FILE__; #define newDEBUG_NEW #endif /**/ ////////////////////////////////////////////////////////////////////// // Construction/Destruction /**/ ////////////////////////////////////////////////////////////////////// CFeedItem::CFeedItem() {} CFeedItem:: ~ CFeedItem() {} CFeedSource::CFeedSource() {} CFeedSource:: ~ CFeedSource() {} CFeed::CFeed() {m_pDoc=NULL;m_nDepth=0;m_bAdded=FALSE;} CFeed::CFeed(CStringstrXMLFile) {m_pDoc=NULL;m_nDepth=0;m_bAdded=FALSE;BuildFromFile(strXMLFile);} CFeed:: ~ CFeed() {} /**/ ///////////////////////////////////////////////////////////////////////////// // BuildXMLFeedInformationfromanXMLFile // // strXMLFile:ParsedinXMLFileName // ThisfunctionwillbuildFeedObjectfromscratchbyparsingXMLFeedInformation // Resultisstoredinm_sourceandm_itemobjects // void CFeed::BuildFromFile(CStringstrXMLFile) {CStringstrTmpFile=GetModuleFileDir()+_T("//AgileReader.xml");//Step0.DownloadXMLFileif(URLDownloadToFile(NULL,strXMLFile,strTmpFile,0,NULL)!=S_OK){//下载XML文件AfxMessageBox(_T("Failedtodownload")+strXMLFile);return;}//Step1.OpenXMLDocument,ifopenfails,thenreturnif(m_pDoc!=NULL){m_pDoc->Release();m_pDoc=NULL;}if(SUCCEEDED(CoCreateInstance(MSXML2::CLSID_DOMDocument,NULL,CLSCTX_INPROC_SERVER,MSXML2::IID_IXMLDOMDocument,reinterpret_cast<void**>(&m_pDoc))))m_pDoc->put_async(VARIANT_FALSE);if(m_pDoc->load(_bstr_t(strTmpFile))==VARIANT_FALSE){//加载XML文档//FailedtoloadXMLDocument,reporterrormessageAfxMessageBox(_T("FailedtoloadXMLDocument"));return;}//Step2.Getversionpropertyifitisavailable//Step3.Iteratetochannelnode,getthefollowingchilditems//title//link//description//language//copyright//webMaster//lastBuildDate//ttl//generator//Thengotoimagenode,getthefollowingitems//title//url//link//width//height//description//Step4.gotoitemnode,getthefollowingitems//title//description//link//author//category//pubDate//subjectMSXML2::IXMLDOMNode*pNode=NULL;if(SUCCEEDED(m_pDoc->QueryInterface(MSXML2::IID_IXMLDOMNode,reinterpret_cast<void**>(&pNode)))){IterateChildNodes(pNode);pNode->Release();pNode=NULL;}//Wearenotusingsmartpointer,sowehavetoreleaseitoutselfif(m_pDoc){m_pDoc->Release();m_pDoc=NULL;}} /**/ ///////////////////////////////////////////////////////////////////////////// // GetFeedVersionInformation // void CFeed::GetVersion(MSXML2::IXMLDOMNode * pNode) {} /**/ ///////////////////////////////////////////////////////////////////////////// // IterateChildNode // void CFeed::IterateChildNodes(MSXML2::IXMLDOMNode * pNode) {//迭代访问所有子节点BSTRbstrNodeName;if(pNode){m_nDepth++;CStringstrOutput;pNode->get_nodeName(&bstrNodeName);////Findoutthenodetype(asastring).//BSTRbstrNodeType;pNode->get_nodeTypeString(&bstrNodeType);CStringstrType;strType=CString(bstrNodeType);SysFreeString(bstrNodeType);MSXML2::DOMNodeTypeeEnum;pNode->get_nodeType(&eEnum);CStringstrValue;BSTRbstrValue;switch(eEnum){caseMSXML2::NODE_TEXT:{//TextstringintheXMLdocumentBSTRbstrValue;pNode->get_text(&bstrValue);strOutput=CString(bstrValue);SysFreeString(bstrValue);break;}caseMSXML2::NODE_COMMENT:{//CommentintheXMLdocumentVARIANTvValue;pNode->get_nodeValue(&vValue);VariantClear(&vValue);break;}caseMSXML2::NODE_PROCESSING_INSTRUCTION:{//ProcessinginstructionstrOutput=CString(bstrNodeName);break;}caseMSXML2::NODE_ELEMENT:{//ElementstrOutput=CString(bstrNodeName);if(strOutput==_T("rss")){GetVersion(pNode);}elseif(strOutput==_T("copyright")){pNode->get_text(&bstrValue);m_source.m_strCopyright=CString(bstrValue);}elseif(strOutput==_T("title")&&m_nDepth==4){pNode->get_text(&bstrValue);m_source.m_strTitle=CString(bstrValue);}elseif(strOutput==_T("link")&&m_nDepth==4){pNode->get_text(&bstrValue);m_source.m_strLink=CString(bstrValue);}elseif(strOutput==_T("description")&&m_nDepth==4){pNode->get_text(&bstrValue);m_source.m_strDescription=CString(bstrValue);}elseif(strOutput==_T("language")){pNode->get_text(&bstrValue);m_source.m_strLanguage=CString(bstrValue);}elseif(strOutput==_T("webMaster")){pNode->get_text(&bstrValue);m_source.m_strWebMaster=CString(bstrValue);}elseif(strOutput==_T("lastBuildDate")){pNode->get_text(&bstrValue);m_source.m_strLastBuildDate=CString(bstrValue);}elseif(strOutput==_T("ttl")){pNode->get_text(&bstrValue);m_source.m_strTtl=CString(bstrValue);}elseif(strOutput==_T("generator")){pNode->get_text(&bstrValue);m_source.m_strGenerator=CString(bstrValue);}elseif(strOutput==_T("image")){BuildImage(pNode);}elseif(strOutput==_T("item")){BuildItem(pNode);}break;}caseMSXML2::NODE_DOCUMENT:{//DocumentstrOutput=CString(bstrNodeName)+_T("-")+CString(strType);break;}caseMSXML2::NODE_DOCUMENT_TYPE:{//DocumentTypestrOutput=CString(bstrNodeName)+_T("-")+CString(strType);break;}caseMSXML2::NODE_DOCUMENT_FRAGMENT:{//DocumentFragmentstrOutput=CString(bstrNodeName)+_T("-")+CString(strType);break;}caseMSXML2::NODE_NOTATION:{//NotationstrOutput=CString(bstrNodeName)+_T("-")+CString(strType);break;}caseMSXML2::NODE_ENTITY:{//EntitystrOutput=CString(bstrNodeName)+_T("-")+CString(strType);break;}caseMSXML2::NODE_ENTITY_REFERENCE:{//EntityReferencestrOutput=CString(bstrNodeName)+_T("-")+CString(strType);}caseMSXML2::NODE_CDATA_SECTION:{//CDatasectionstrOutput=CString(bstrNodeName)+_T("-")+CString(strType);}}SysFreeString(bstrNodeName);}////Anychildnodesofthisnodeneeddisplayingtoo.//MSXML2::IXMLDOMNode*pNext=NULL;MSXML2::IXMLDOMNode*pChild;pNode->get_firstChild(&pChild);while(pChild){//递归遍历子节点IterateChildNodes(pChild);pChild->get_nextSibling(&pNext);pChild->Release();pChild=pNext;}m_nDepth--;//递归深度减} /**/ ///////////////////////////////////////////////////////////////////////////// // BuildImageSection // void CFeed::BuildImage(MSXML2::IXMLDOMNode * pNode) {MSXML2::IXMLDOMNode*pNext=NULL;MSXML2::IXMLDOMNode*pChild;CStringstrOutput;BSTRbstrNodeName;BSTRbstrValue;pNode->get_firstChild(&pChild);while(pChild){pChild->get_nodeName(&bstrNodeName);strOutput=CString(bstrNodeName);if(strOutput==_T("title")){pChild->get_text(&bstrValue);m_source.m_strImageTitle=CString(bstrValue);}elseif(strOutput==_T("url")){pChild->get_text(&bstrValue);m_source.m_strImageUrl=CString(bstrValue);}elseif(strOutput==_T("link")){pChild->get_text(&bstrValue);m_source.m_strImageLink=CString(bstrValue);}elseif(strOutput==_T("width")){pChild->get_text(&bstrValue);m_source.m_strImageWidth=CString(bstrValue);}elseif(strOutput==_T("height")){pChild->get_text(&bstrValue);m_source.m_strImageHeight=CString(bstrValue);}elseif(strOutput==_T("description")){pChild->get_text(&bstrValue);m_source.m_strImageDescription=CString(bstrValue);}pChild->get_nextSibling(&pNext);pChild->Release();pChild=pNext;}} /**/ ///////////////////////////////////////////////////////////////////////////// // BuildItemSection // void CFeed::BuildItem(MSXML2::IXMLDOMNode * pNode) {MSXML2::IXMLDOMNode*pNext=NULL;MSXML2::IXMLDOMNode*pChild;CStringstrOutput;BSTRbstrNodeName;CFeedItemitem;BSTRbstrValue;pNode->get_firstChild(&pChild);while(pChild){pChild->get_nodeName(&bstrNodeName);strOutput=CString(bstrNodeName);if(strOutput==_T("title")){pChild->get_text(&bstrValue);item.m_strTitle=CString(bstrValue);}elseif(strOutput==_T("description")){pChild->get_text(&bstrValue);item.m_strDescription=CString(bstrValue);}elseif(strOutput==_T("link")){pChild->get_text(&bstrValue);item.m_strLink=CString(bstrValue);}elseif(strOutput==_T("author")){pChild->get_text(&bstrValue);item.m_strAuthor=CString(bstrValue);}elseif(strOutput==_T("category")){pChild->get_text(&bstrValue);item.m_strCategory=CString(bstrValue);}elseif(strOutput==_T("pubDate")){pChild->get_text(&bstrValue);item.m_strPubDate=CString(bstrValue);}elseif(strOutput==_T("subject")){pChild->get_text(&bstrValue);item.m_strSubject=CString(bstrValue);}pChild->get_nextSibling(&pNext);pChild->Release();pChild=pNext;}m_item.Add(item);} /**/ ///////////////////////////////////////////////////////////////////////////// // SaveFeedInformationintoDatabase // void CFeed::Save(BOOLbSaveSource /**/ /*=TRUE*/ ) {//保持RSS种子信息倒数据库种_ConnectionPtrpCnn=NULL;CStringstrSQL;CStringstrMsg;intnIndex;//Step1.CreateobjectpCnn.CreateInstance(__uuidof(Connection));if(pCnn==NULL){AfxMessageBox(_T("Cannotcreateconnectionobject,pleaseinstallMDAC!"));return;}//Step2.Openconnectiontry{CStringstrCnn;strCnn.Format(_T("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=%s//AgileReader.mdb;JetOLEDB:DatabasePassword=philips;"),GetModuleFileDir());pCnn->Open(_bstr_t(strCnn),"","",adConnectUnspecified);}catch(_com_error&e){AfxMessageBox(_T("Cannotopenconnection:/n")+GetComError(e));pCnn.Release();return;}//Step3.ExecuteInsertStatementonFeedSource//Indoubleclickcase,wedon'twanttosavethisif(bSaveSource){strSQL.Format(_T("insertintoFeedSource(FeedLink,description,title,version,copyright,generator,feedlanguage,lastbuilddate,ttl,webmaster,imagedescription,imageheight,imagewidth,imagelink,imagetitle,imageurl)values('%s','%s','%s','%s','%s','%s','%s','%s',%d,'%s','%s','%s','%s','%s','%s','%s')"),EscapeQuote(m_source.m_strLink),EscapeQuote(m_source.m_strDescription),EscapeQuote(m_source.m_strTitle),_T("2.0"),EscapeQuote(m_source.m_strCopyright),EscapeQuote(m_source.m_strGenerator),EscapeQuote(m_source.m_strLanguage),EscapeQuote(m_source.m_strLastBuildDate),EscapeQuote(m_source.m_strTtl),EscapeQuote(m_source.m_strWebMaster),EscapeQuote(m_source.m_strImageDescription),EscapeQuote(m_source.m_strImageHeight),EscapeQuote(m_source.m_strImageWidth),EscapeQuote(m_source.m_strImageLink),EscapeQuote(m_source.m_strImageTitle),EscapeQuote(m_source.m_strImageUrl));if(!ExecuteSQL(pCnn,strSQL,strMsg)){//AfxMessageBox(strMsg+strSQL);}else{m_bAdded=TRUE;}}//Step4.ExecuteInsertStatementonFeedItemfor(nIndex=0;nIndex<m_item.GetSize();nIndex++){strSQL.Format(_T("insertintoFeedItem(FeedLink,title,link,description,pubdate,author,category,subject)values('%s','%s','%s','%s','%s','%s','%s','%s')"),EscapeQuote(m_source.m_strLink),EscapeQuote(m_item[nIndex].m_strTitle),EscapeQuote(m_item[nIndex].m_strLink),EscapeQuote(m_item[nIndex].m_strDescription),EscapeQuote(m_item[nIndex].m_strPubDate),EscapeQuote(m_item[nIndex].m_strAuthor),EscapeQuote(m_item[nIndex].m_strCategory),EscapeQuote(m_item[nIndex].m_strSubject));if(!ExecuteSQL(pCnn,strSQL,strMsg)){//AfxMessageBox(strMsg+strSQL);}}pCnn.Release();} /**/ ///////////////////////////////////////////////////////////////////////////// // ExecuteSQLStatementandreturnerrormessageifany // BOOLCFeed::ExecuteSQL(_ConnectionPtr & pCnn,CString & strSQL,CString & strMsg) {try{pCnn->Execute(_bstr_t(strSQL),NULL,adCmdText);}catch(_com_error&e){strMsg=GetComError(e);returnFALSE;}returnTRUE;} /**/ ///////////////////////////////////////////////////////////////////////////// // RetrieveComErrorInformation // CStringCFeed::GetComError(_com_error & e) {CStringstrMsg;_bstr_tbstrSource(e.Source());_bstr_tbstrDescription(e.Description());strMsg.Format(_T("Code=%08lx/nCodemeaning=%s/nSource=%s/nDescription=%s"),e.Error(),e.ErrorMessage(),(LPCSTR)bstrSource,(LPCSTR)bstrDescription);returnstrMsg;} /**/ ///////////////////////////////////////////////////////////////////////////// // LoadFeedInformationfromdatabase // void CFeed::LoadLocal(CString & strLink) {//从数据库中读取RSS种子信息_ConnectionPtrpCnn=NULL;CStringstrSQL;CStringstrMsg;_RecordsetPtrrs=NULL;//Step1.CreateobjectpCnn.CreateInstance(__uuidof(Connection));if(pCnn==NULL){AfxMessageBox(_T("Cannotcreateconnectionobject,pleaseinstallMDAC!"));return;}//Step2.Openconnectiontry{CStringstrCnn;strCnn.Format(_T("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=%s//AgileReader.mdb;JetOLEDB:DatabasePassword=philips;"),GetModuleFileDir());pCnn->Open(_bstr_t(strCnn),"","",adConnectUnspecified);}catch(_com_error&e){AfxMessageBox(_T("Cannotopenconnection:/n")+GetComError(e));pCnn.Release();return;}//Step3.ReadFeedSourceandpopulateitintom_sourceobjectstrSQL.Format(_T("select*fromFeedSourcewhereFeedLink='%s'"),strLink);try{rs=pCnn->Execute(_bstr_t(strSQL),NULL,adCmdText);if(rs!=NULL&&rs->adoEOF!=TRUE){m_source.m_strLink=strLink;m_source.m_strDescription=GetFieldValue(rs->Fields,1);m_source.m_strTitle=GetFieldValue(rs->Fields,2);m_source.m_strVersion=GetFieldValue(rs->Fields,3);m_source.m_strCopyright=GetFieldValue(rs->Fields,4);m_source.m_strGenerator=GetFieldValue(rs->Fields,5);m_source.m_strLanguage=GetFieldValue(rs->Fields,6);m_source.m_strLastBuildDate=GetFieldValue(rs->Fields,7);m_source.m_strTtl=GetFieldValue(rs->Fields,8);m_source.m_strWebMaster=GetFieldValue(rs->Fields,9);m_source.m_strImageDescription=GetFieldValue(rs->Fields,10);m_source.m_strImageHeight=GetFieldValue(rs->Fields,11);m_source.m_strImageWidth=GetFieldValue(rs->Fields,12);m_source.m_strImageLink=GetFieldValue(rs->Fields,13);m_source.m_strImageTitle=GetFieldValue(rs->Fields,14);m_source.m_strImageUrl=GetFieldValue(rs->Fields,15);}}catch(_com_error&e){AfxMessageBox(GetComError(e));}rs.Release();rs=NULL;//Step4.ReadFeedItemandpopulateitintom_itemobjectstrSQL.Format(_T("select*fromFeedItemwhereFeedLink='%s'orderbypubDatedesc,titleasc"),strLink);try{rs=pCnn->Execute(_bstr_t(strSQL),NULL,adCmdText);while(rs!=NULL&&rs->adoEOF!=TRUE){if(rs->adoEOF){break;}CFeedItemitem;item.m_strTitle=GetFieldValue(rs->Fields,1);item.m_strLink=GetFieldValue(rs->Fields,2);item.m_strDescription=GetFieldValue(rs->Fields,3);item.m_strPubDate=GetFieldValue(rs->Fields,4);item.m_strAuthor=GetFieldValue(rs->Fields,5);item.m_strCategory=GetFieldValue(rs->Fields,6);item.m_strSubject=GetFieldValue(rs->Fields,7);item.m_strReadStatus=GetFieldValue(rs->Fields,8);m_item.Add(item);rs->MoveNext();if(rs->adoEOF){break;}}}catch(_com_error&e){AfxMessageBox(GetComError(e));}rs.Release();rs=NULL;pCnn.Release();pCnn=NULL;} /**/ ///////////////////////////////////////////////////////////////////////////// // GetFieldValue // CStringCFeed::GetFieldValue(FieldsPtrfields, long nIndex) {_variant_tvt=fields->GetItem(nIndex)->Value;if(vt.vt==VT_NULL||vt.vt==VT_EMPTY){return_T("");}returnCString((char*)_bstr_t(vt));} void CFeed::GetFeedSourceList(CStringArray & strTitleArray,CStringArray & strLinkArray) {_ConnectionPtrpCnn=NULL;CStringstrSQL;CStringstrMsg;_RecordsetPtrrs=NULL;//Step1.CreateobjectpCnn.CreateInstance(__uuidof(Connection));if(pCnn==NULL){AfxMessageBox(_T("Cannotcreateconnectionobject,pleaseinstallMDAC!"));return;}//Step2.Openconnectiontry{CStringstrCnn;strCnn.Format(_T("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=%s//AgileReader.mdb;JetOLEDB:DatabasePassword=philips;"),GetModuleFileDir());pCnn->Open(_bstr_t(strCnn),"","",adConnectUnspecified);}catch(_com_error&e){AfxMessageBox(_T("Cannotopenconnection:/n")+GetComError(e));pCnn.Release();return;}//Step3.ReadFeedSourceandpopulateitintom_sourceobjectstrSQL=_T("selectdistincttitle,FeedLinkfromFeedSourceorderbytitle");try{rs=pCnn->Execute(_bstr_t(strSQL),NULL,adCmdText);while(rs!=NULL&&rs->adoEOF!=TRUE&&rs->BOF!=TRUE){if(rs->adoEOF){break;}strTitleArray.Add(GetFieldValue(rs->Fields,0));strLinkArray.Add(GetFieldValue(rs->Fields,1));rs->MoveNext();}}catch(_com_error&e){AfxMessageBox(GetComError(e));}rs.Release();rs=NULL;pCnn.Release();} /**/ ///////////////////////////////////////////////////////////////////////////// // GetModuleFilePath // CStringCFeed::GetModuleFileDir() {//获取模块文件路径DWORDdwLength,dwSize;TCHARszFileName[MAX_PATH];CStringstrFileName;intnPos;dwSize=sizeof(szFileName)/sizeof(szFileName[0]);dwLength=::GetModuleFileName(AfxGetInstanceHandle(),szFileName,dwSize);if(dwLength<=0){return_T("");}strFileName=szFileName;nPos=strFileName.ReverseFind('//');returnstrFileName.Left(nPos);} /**/ ///////////////////////////////////////////////////////////////////////////// // EscapeSingleQuote // CStringCFeed::EscapeQuote(CStringstrValue) {strValue.Replace(_T("'"),_T("''"));returnstrValue;} /**/ ///////////////////////////////////////////////////////////////////////////// // DeletelistfromDatabase // void CFeed::DeleteListArray(CStringArray & strLinkArray) {_ConnectionPtrpCnn=NULL;CStringstrSQL;CStringstrMsg;intnIndex;//Step1.CreateobjectpCnn.CreateInstance(__uuidof(Connection));if(pCnn==NULL){AfxMessageBox(_T("Cannotcreateconnectionobject,pleaseinstallMDAC!"));return;}//Step2.Openconnectiontry{CStringstrCnn;strCnn.Format(_T("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=%s//AgileReader.mdb;JetOLEDB:DatabasePassword=philips;"),GetModuleFileDir());pCnn->Open(_bstr_t(strCnn),"","",adConnectUnspecified);}catch(_com_error&e){AfxMessageBox(_T("Cannotopenconnection:/n")+GetComError(e));pCnn.Release();return;}//Step3.DeleteLinkfromFeedListtablefor(nIndex=0;nIndex<strLinkArray.GetSize();nIndex++){strSQL.Format(_T("deletefromFeedItemwherelink='%s'"),EscapeQuote(strLinkArray[nIndex]));ExecuteSQL(pCnn,strSQL,strMsg);}//Step4.Done!pCnn.Release();} /**/ ///////////////////////////////////////////////////////////////////////////// // DeleteFeedSource // void CFeed::DeleteFeedSource(CStringstrLink) {_ConnectionPtrpCnn=NULL;CStringstrSQL;CStringstrMsg;//Step1.CreateobjectpCnn.CreateInstance(__uuidof(Connection));if(pCnn==NULL){AfxMessageBox(_T("Cannotcreateconnectionobject,pleaseinstallMDAC!"));return;}//Step2.Openconnectiontry{CStringstrCnn;strCnn.Format(_T("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=%s//AgileReader.mdb;JetOLEDB:DatabasePassword=philips;"),GetModuleFileDir());pCnn->Open(_bstr_t(strCnn),"","",adConnectUnspecified);}catch(_com_error&e){AfxMessageBox(_T("Cannotopenconnection:/n")+GetComError(e));pCnn.Release();return;}//Step3.DeleteLinkfromFeedListtablestrSQL.Format(_T("deletefromFeedSourcewhereFeedLink='%s'"),EscapeQuote(strLink));ExecuteSQL(pCnn,strSQL,strMsg);//Step4.Done!pCnn.Release();} /**/ ///////////////////////////////////////////////////////////////////////////// // Markanitemasread // void CFeed::MarkItemRead(CStringstrLink) {//标记Rss条目为已读状态_ConnectionPtrpCnn=NULL;CStringstrSQL;CStringstrMsg;//Step1.CreateobjectpCnn.CreateInstance(__uuidof(Connection));if(pCnn==NULL){AfxMessageBox(_T("Cannotcreateconnectionobject,pleaseinstallMDAC!"));return;}//Step2.Openconnectiontry{CStringstrCnn;strCnn.Format(_T("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=%s//AgileReader.mdb;JetOLEDB:DatabasePassword=philips;"),GetModuleFileDir());pCnn->Open(_bstr_t(strCnn),"","",adConnectUnspecified);}catch(_com_error&e){AfxMessageBox(_T("Cannotopenconnection:/n")+GetComError(e));pCnn.Release();return;}//Step3.DeleteLinkfromFeedListtablestrSQL.Format(_T("updateFeedItemsetreadstatus=1wherelink='%s'"),EscapeQuote(strLink));ExecuteSQL(pCnn,strSQL,strMsg);//Step4.Done!pCnn.Release();} /**/ ///////////////////////////////////////////////////////////////////////////// // RefreshAllSubScriptions // void CFeed::RefreshAll() {//刷新订阅信息_ConnectionPtrpCnn=NULL;CStringstrSQL;CStringstrMsg;CStringArraystrLinkArray;_RecordsetPtrrs=NULL;//Step1.CreateobjectpCnn.CreateInstance(__uuidof(Connection));if(pCnn==NULL){AfxMessageBox(_T("Cannotcreateconnectionobject,pleaseinstallMDAC!"));return;}//Step2.Openconnectiontry{CStringstrCnn;strCnn.Format(_T("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=%s//AgileReader.mdb;JetOLEDB:DatabasePassword=philips;"),GetModuleFileDir());pCnn->Open(_bstr_t(strCnn),"","",adConnectUnspecified);}catch(_com_error&e){AfxMessageBox(_T("Cannotopenconnection:/n")+GetComError(e));pCnn.Release();return;}//Step3.GetallthesubscriptionsstrSQL=_T("selectFeedLinkfromFeedSource");try{rs=pCnn->Execute(_bstr_t(strSQL),NULL,adCmdText);while(rs!=NULL&&rs->adoEOF!=TRUE){if(rs->adoEOF){break;}strLinkArray.Add(GetFieldValue(rs->Fields,0));rs->MoveNext();}}catch(_com_error&e){AfxMessageBox(GetComError(e));}rs.Release();rs=NULL;//Step4.Refreaheachlinkfor(intnIndex=0;nIndex<strLinkArray.GetSize();nIndex++){CFeedfeed(strLinkArray.GetAt(nIndex));feed.m_source.m_strLink=strLinkArray.GetAt(nIndex);feed.Save();}//Step5.Done!pCnn.Release();}