📄 query.cpp
字号:
fprintf(pFile,"StatGroup=%i\n", m_nStatGroup);
fprintf(pFile,"Cond=%i\n", m_nCond);
fprintf(pFile,"CondValue=%lf\n", m_dCondValue);
fprintf(pFile,"CondValueStr=%s\n",m_sCondValue);
CQueryElement* pQueryElement = GetNextQuery();
if (pQueryElement != NULL)
{
pQueryElement->Write(pFile);
}
}
///////////////////////////////////////////////////////////////////////////////
CString CQuery::DateCondAsString()
{
CString sDate;
for (int i = 0; m_aQueryDates[i].m_nID != GetDateCond(); i++);
CString sDesc = m_aQueryDates[i].m_psDescription;
switch (GetDateCond())
{
case FirstDateRange : case LastDateRange : case AllDatesRange :
case AllDatesAfter : case AllDatesBefore :
m_dtStart.DateAsString(sDate);
sDesc += " " + sDate;
}
switch (GetDateCond())
{
case FirstDateRange : case LastDateRange : case AllDatesRange :
m_dtEnd.DateAsString(sDate);
sDesc += " " + BDString(IDS_TO) + " " + sDate;
}
return sDesc;
}
///////////////////////////////////////////////////////////////////////////////
void CQueryLink::Write(FILE* pFile)
{
fprintf(pFile, "Link=");
int c = 0;
for (int i = 0; i < m_aFeatures.GetSize(); i++)
{
if (m_aFeatures.GetAt(i).GetSelected())
{
if (c > 0) fprintf(pFile,",");
fprintf(pFile,"%li",m_aFeatures.GetAt(i).m_lId);
c++;
}
}
fprintf(pFile,"\n");
CQueryElement::Write(pFile);
}
///////////////////////////////////////////////////////////////////////////////
BOOL CQueryLink::Read(FILE* pFile)
{
CDWordArray adw;
CString sHeader = BDNextItem(pFile);
if (sHeader != "Link") return FALSE;
BDNext(pFile, adw, FALSE);
for (int i = 0; i < m_aFeatures.GetSize(); i++)
{
CQueryFeature feature = m_aFeatures.GetAt(i);
feature.SetSelected(FALSE);
for (int j = 0; j < adw.GetSize(); j++)
{
if (m_aFeatures.GetAt(i).m_lId == (long)adw[j])
{
feature.SetSelected(TRUE);
}
}
m_aFeatures.SetAt(i, feature);
}
return CQueryElement::Read(pFile);
}
///////////////////////////////////////////////////////////////////////////////
void CQueryStats::Write(FILE* pFile)
{
fprintf(pFile,"Statistic\n");
fprintf(pFile,"AttrId2=%i\n",m_nAttrId2);
fprintf(pFile,"FTypeId2=%i\n",m_lFType2);
fprintf(pFile,"Statistic=%i\n",m_nStatistic);
fprintf(pFile,"DecPlaces=%i\n",m_nDecPlaces);
fprintf(pFile,"Value1=%lf\n",m_dValue1);
fprintf(pFile,"Value2=%lf\n",m_dValue2);
CQueryElement::Write(pFile);
}
///////////////////////////////////////////////////////////////////////////////
BOOL CQueryStats::Read(FILE* pFile)
{
m_nAttrId2 = BDNextInt(pFile);
m_lFType2 = BDNextInt(pFile);
m_nStatistic = BDNextInt(pFile);
m_nDecPlaces = BDNextInt(pFile, "DecPlaces", 0);
m_dValue1 = BDNextDouble(pFile, "Value1", 0);
m_dValue1 = BDNextDouble(pFile, "Value2", 0);
return CQueryElement::Read(pFile);
}
///////////////////////////////////////////////////////////////////////////////
CString CArrayAttrSel::GetAttrDesc(CAttrArray& aAttr)
{
CString sAttrName;
for (int i = 0; i < GetSize(); i++)
{
// Attributes
for (int j = 0; j < aAttr.GetSize(); j++)
{
if (GetAt(i).m_lAttr == aAttr.GetAt(j)->GetAttrId() &&
GetAt(i).m_lFType == aAttr.GetAt(j)->GetFTypeId())
{
CAttribute* pAttr = aAttr.GetAt(j);
if (pAttr->GetDataType() != BDCOORD &&
pAttr->GetDataType() != BDMAPLINES)
{
if (sAttrName.GetLength() > 0) sAttrName+= " ";
CBDAttribute* pAttr = (CBDAttribute*)aAttr[j];
sAttrName += pAttr->AsString();
sAttrName.TrimRight();
};
}
}
};
// Filter out anything in square brackets
return CQuery::StripBrackets(sAttrName);
}
///////////////////////////////////////////////////////////////////////////////
CQueryElement::CQueryElement()
{
m_nDataType = 0;
m_nAttrId = 0;
m_lFType = 0;
m_nStatGroup= none;
m_nSortBy = none;
m_nGroupBy = none;
m_pNext = NULL;
m_bSelected = FALSE;
m_nCond = none;
m_dCondValue = 0;
}
///////////////////////////////////////////////////////////////////////////////
CQueryElement::CQueryElement(CQueryElement& rSrc)
{
*this = rSrc;
}
CQueryElement& CQueryElement::operator=(CQueryElement& rSrc)
{
m_nDataType = rSrc.m_nDataType;
m_nAttrId = rSrc.m_nAttrId;
m_lFType = rSrc.m_lFType;
m_nStatGroup = rSrc.m_nStatGroup;
m_nSortBy = rSrc.m_nSortBy;
m_nGroupBy = rSrc.m_nGroupBy;
m_bSelected = rSrc.m_bSelected;
m_sDesc = rSrc.m_sDesc;
m_sColName = rSrc.m_sColName;
m_nCond = rSrc.m_nCond;
m_dCondValue = rSrc.m_dCondValue;
m_sCondValue = rSrc.m_sCondValue;
m_pNext = NULL;
if (rSrc.m_pNext != NULL)
{
CQueryElement* pNext = rSrc.m_pNext;
switch (pNext->m_nDataType)
{
case BDFTYPE :
m_pNext = new CQuery((CQuery&)*pNext); break;
case BDLINK : case BDFEATURE :
m_pNext = new CQueryLink((CQueryLink&)*pNext); break;
case BDNUMBER :
m_pNext = new CQueryNumber((CQueryNumber&)*pNext); break;
case BDBOOLEAN :
m_pNext = new CQueryBoolean((CQueryBoolean&)*pNext); break;
case BDQUERYSTATS :
m_pNext = new CQueryStats((CQueryStats&)*pNext); break;
default :
m_pNext = new CQueryElement(*pNext);
}
ASSERT(m_pNext != NULL);
}
return *this;
}
///////////////////////////////////////////////////////////////////////////////
CQueryElement::~CQueryElement()
{
Delete(m_pNext);
}
///////////////////////////////////////////////////////////////////////////////
void CQueryElement::Delete(CQueryElement*& pElement)
{
if (pElement != NULL)
{
if (pElement->m_pNext != NULL)
{
Delete(pElement->m_pNext);
}
switch (pElement->GetDataType())
{
case BDFTYPE :
delete ((CQuery*)pElement);
break;
case BDLINK : case BDFEATURE :
delete ((CQueryLink*)pElement);
break;
case BDNUMBER : delete ((CQueryNumber*)pElement);
break;
case BDBOOLEAN : delete ((CQueryBoolean*)pElement);
break;
case BDDATE : case BDTEXT : case BDCOORD : case BDHOTLINK : case BDLONGTEXT :
case BDMAPLINES : case BDIMAGE : case BDFILE :
delete pElement;
break;
case BDQUERYSTATS : delete ((CQueryStats*)pElement);
break;
default:
ASSERT(FALSE);
}
}
pElement = NULL;
}
///////////////////////////////////////////////////////////////////////////////
CQueryFeature::CQueryFeature()
{
m_bSelected = FALSE;
}
///////////////////////////////////////////////////////////////////////////////
CQueryLink::CQueryLink()
{
}
///////////////////////////////////////////////////////////////////////////////
CQueryLink::CQueryLink(CQueryLink& rSrc) : CQueryElement(rSrc)
{
m_aFeatures.Copy(rSrc.m_aFeatures);
}
///////////////////////////////////////////////////////////////////////////////
CQueryLink::CQueryLink(long lFType)
{
CFeature feature;
feature.m_lFeatureTypeId = lFType;
BOOL bFound = BDFeature(BDHandle(), &feature, BDSELECT2);
while (bFound)
{
CQueryFeature qf = feature;
qf.m_sName.TrimRight();
m_aFeatures.Add(qf);
bFound = BDGetNext(BDHandle());
}
BDEnd(BDHandle());
}
///////////////////////////////////////////////////////////////////////////////
CQueryBoolean::CQueryBoolean()
{
CQueryFeature feature;
feature.m_lId = no;
feature.m_sName = BDString(IDS_NO);
feature.SetSelected();
m_aFeatures.Add(feature);
feature.m_lId = yes;
feature.m_sName = BDString(IDS_YES);
m_aFeatures.Add(feature);
}
///////////////////////////////////////////////////////////////////////////////
CQueryStats::CQueryStats()
{
m_nAttrId2 = 0;
m_lFType2 = 0;
m_nStatistic = 0;
m_nDecPlaces = 0;
m_dValue2 = 0;
}
///////////////////////////////////////////////////////////////////////////////
CQueryStats::CQueryStats(CQueryStats& rSrc) : CQueryElement(rSrc)
{
m_nAttrId2 = rSrc.m_nAttrId2;
m_lFType2 = rSrc.m_lFType2;
m_nStatistic = rSrc.m_nStatistic;
m_nDecPlaces = rSrc.m_nDecPlaces;
m_dValue1 = rSrc.m_dValue1;
m_dValue2 = rSrc.m_dValue2;
}
///////////////////////////////////////////////////////////////////////////////
CQueryAttrArray::CQueryAttrArray(LPCSTR sFeature)
{
m_sFeature = sFeature;
m_bCondMet = FALSE;
m_lFeatureActive = 0;
m_lParentFeatureActive = 0;
}
///////////////////////////////////////////////////////////////////////////////
CQueryAttrArray::CQueryAttrArray(CQueryAttrArray& rSrc) :
CAttrArray(rSrc)
{
m_sFeature = rSrc.m_sFeature;
m_bCondMet = rSrc.m_bCondMet;
m_lFeatureActive = rSrc.m_lFeatureActive;
m_sFeatureActive = rSrc.m_sFeatureActive;
m_lParentFeatureActive = rSrc.m_lParentFeatureActive;
m_dateActive = rSrc.m_dateActive;
}
///////////////////////////////////////////////////////////////////////////////
CQueryAttrArray::~CQueryAttrArray()
{
}
///////////////////////////////////////////////////////////////////////////////
CQueryAttrSel::CQueryAttrSel()
{
m_lAttr = 0;
m_lFType = 0;
m_lDataType = 0;
m_nStatGroup = 0;
m_nGroupBy = 0;
m_nSortBy = 0;
}
///////////////////////////////////////////////////////////////////////////////
CQueryResult::CQueryResult()
{
m_pQuery = NULL;
m_bBaseFType = FALSE;
m_pQueryResult = NULL;
}
CQueryResult::~CQueryResult()
{
if (m_pQueryResult != NULL) delete m_pQueryResult;
RemoveAllX();
}
///////////////////////////////////////////////////////////////////////////////
void CQueryResult::RemoveAllX()
{
for (int i = 0; i < GetSize(); i++)
{
delete GetAt(i);
}
RemoveAll();
}
///////////////////////////////////////////////////////////////////////////////
BOOL CQueryResult::Initialise(CQuery* pQuery)
{
BOOL bOK = TRUE;
// Pointer to the header of the list
m_pQuery = pQuery;
// Initialise list of features
AfxGetApp()->BeginWaitCursor();
if (InitFeatures(pQuery))
{
// For each feature type retrieve data, ensure it has attributes selected
bOK = RetrieveData(pQuery);
// Perform calculations
if (bOK)
{
CalcRowBasedStats();
// Sort the results of the query
SortQueryResults();
// Calculate statistics
CalculateStatistics();
};
} else
{
bOK = FALSE;
RemoveAllX();
}
AfxGetApp()->EndWaitCursor();
return bOK;
}
///////////////////////////////////////////////////////////////////////////////
//
// Determines the description of the query from the selected feature type and
// attributes
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -