改写策略为王TSKING (源代码) 增加 SQL存储四 修改加载Codetable

Published

首先在CStkLibWnd中加入方法

int    LoadCodetable( CStockContainer &container );    // 读取所有股票的信息
int LoadCodeTableByMarket(CStockContainer& container, DWORD dwMarket);


int CStkLibWnd::LoadCodetable( CStockContainer & container )
{
 if(!IsOK()) 
 return 0;

 //上海指数
 LoadCodeTableByMarket(container, CStock::marketSHSE);

 //深圳指数
 LoadCodeTableByMarket(container, CStock::marketSZSE);

 return container.GetSize();

}

int CStkLibWnd::LoadCodeTableByMarket(CStockContainer& container, DWORD dwMarket)
 int ncrow=0;
 CSPString strSql = "";
 CSPString strStockCode = "";
 CSPString strMarKet=GetMarket(dwMarket);

 strSql.Format( "select * from StockList where Market='%s' order by Market,Code",strMarKet);

 int nRow=0;

 try
 {

 _RecordsetPtr m_pRecordsetT;
 m_pRecordsetT.CreateInstance(__uuidof(Recordset));
 m_pRecordsetT->Open(_variant_t(strSql),
 m_pCnn.GetInterfacePtr(),
 adOpenDynamic,
 adLockOptimistic,
 adCmdText);

 if(!m_pRecordsetT->adoEOF)
 {
 _variant_t var;
 while(!m_pRecordsetT->adoEOF)
 {
 CStockInfo info;
 var = m_pRecordsetT->GetCollect("Code");
 if(var.vt != VT_NULL)
 {
 strStockCode=(LPCSTR)_bstr_t(var);
 info.SetStockCode(dwMarket,strStockCode);
 }
 

 var = m_pRecordsetT->GetCollect("ChineseName");
 if(var.vt != VT_NULL)
 {
 CSPString sValue=(LPCSTR)_bstr_t(var);
 info.SetStockName(sValue);
 }

 var = m_pRecordsetT->GetCollect("ShortName");
 if(var.vt != VT_NULL)
 {
 CSPString sValue=(LPCSTR)_bstr_t(var);
 info.SetStockShortName(sValue);
 }

 var = m_pRecordsetT->GetCollect("otherName");
 if(var.vt != VT_NULL)
 {
 CSPString sValue=(LPCSTR)_bstr_t(var);
 info.SetStockNameEnu(sValue);
 }

 void * pArrayID = NULL;
 if (info.IsValidStock())
 {


 container.Add(info);


 }

 m_pRecordsetT->MoveNext();
 }
 }

 m_pRecordsetT->Close();
 }
 catch(_com_error e)
 {
 return container.GetSize();
 }

 ncrow = container.GetSize();
 return container.GetSize();
}

 

打开 StkLib项目中Database.cpp 找到函数LoadCodetable( CStockContainer & container )

函数里面加入

 

int nSize = 0;
 int nSize2 = 0;

 if(AfxGetCStkLibWnd().IsOK())
 {
 nSize2 = AfxGetCStkLibWnd().LoadCodetable(container);
 if(nSize2>0)
 return nSize2;
 }

 

确保首先执行。

看看调试的结果.

 

成功能了。