📄 datareader.cpp
字号:
#include "StdAfx.h"
#include "DataReader.h"
#include "DirectoryMG.h"
DataSet::DataSet(void)
{
}
DataSet::~DataSet(void)
{
}
DataSet & DataSet::operator =(const DataSet & other)
{
sCodeString = other.sCodeString;
sLocation = other.sLocation;
sName = other.sName;
return (*this);
}
CDataReader::CDataReader(void)
{
LoadFromFile();
}
CDataReader::~CDataReader(void)
{
Reset();
}
void CDataReader::LoadFromFile()
{
CString sBuf;
CString sTemp;
CString sFile = CDirectoryMG::GetDataPath();
CStdioFile file;
if (file.Open(sFile,CFile::modeRead))
{
while (file.ReadString(sTemp) != FALSE)
{
sBuf += sTemp;
}
}
if (file.m_hFile != CFile::hFileNull)
{
file.Close();
}
if (!sBuf.IsEmpty())
{
int iRowStart = 0;
int iEnd;
CString sRow;
while ((iEnd = sBuf.Find(_T(","),iRowStart)) != -1)
{
sRow = sBuf.Mid(iRowStart,iEnd - iRowStart);
SplitRow(sRow);
iRowStart = iEnd + 1;
}
}
}
void CDataReader::Reset()
{
for (int i = 0; i < (int)m_vctDatas.size(); i ++)
{
delete m_vctDatas[i];
}
m_vctDatas.clear();
}
void CDataReader::SplitRow(CString tsRow)
{
DataSet *pdata = new DataSet;
int iStart;
int iEnd;
iStart = 0;
iStart = tsRow.Find(_T("["));
iEnd = tsRow.Find(_T("]"));
pdata->sCodeString = tsRow.Mid(iStart+ 1,iEnd - iStart -1 );
iStart = iEnd + 1;
iStart = tsRow.Find(_T("["),iStart);
iEnd = tsRow.Find(_T("]"),iStart);
pdata->sLocation = tsRow.Mid(iStart + 1,iEnd - iStart -1 );
iStart = iEnd + 1;
iStart = tsRow.Find(_T("["),iStart);
iEnd = tsRow.Find(_T("]"),iStart);
pdata->sName = tsRow.Mid(iStart+1,iEnd - iStart -1 );
m_vctDatas.push_back(pdata);
}
void CDataReader::AddDataset(DataSet * tpDataSet)
{
DataSet * pNew = new DataSet;
*pNew = *tpDataSet;
m_vctDatas.push_back(pNew);
}
DataSet * CDataReader::FindDataSetByCode(CString sKey)
{
DataSet * pFind = NULL;
for (int i = 0; i < m_vctDatas.size(); i ++)
{
if (m_vctDatas[i]->sCodeString.CompareNoCase(sKey) == 0)
{
pFind = m_vctDatas[i];
}
}
return pFind;
}
DataSet * CDataReader::FindDataSetByLoacation(CString sKey)
{
DataSet * pFind = NULL;
for (int i = 0; i < m_vctDatas.size(); i ++)
{
if (m_vctDatas[i]->sLocation.CompareNoCase(sKey) == 0)
{
pFind = m_vctDatas[i];
}
}
return pFind;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -