📄 ahnendoc.cpp
字号:
// ahnendoc.cpp : implementation file
//
#include "stdafx.h"
#include "tree.h"
#include "ahnendoc.h"
#include "treedoc.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAhnenDoc
IMPLEMENT_SERIAL(CAhnenDoc, CDocument, 0 /* schema number*/ )
CAhnenDoc::CAhnenDoc()
{
}
CAhnenDoc::~CAhnenDoc()
{
// make sure the CStrings in the array are emptied
for (int i = 0; i < m_arrAhnentafel.GetSize(); i++)
m_arrAhnentafel[i].Empty();
// empty the array
m_arrAhnentafel.RemoveAll();
}
BOOL CAhnenDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
double Seed_ID; // initial ID on which to base ahnentafel list
CString S; // temporary string storage
// Navigate the MFC architecture to get to the current document
CTreeApp* pApp = (CTreeApp*)AfxGetApp();
CFrameWnd* pChild = ((CMDIFrameWnd*)(pApp->m_pMainWnd))->GetActiveFrame();
CDocument* pDoc = pChild->GetActiveDocument();
// find ID of the current person selected in the
// previous document if there is one. Otherwise
// abort operation.
if ( (pDoc != NULL) )
{
S = pDoc->GetRuntimeClass()->m_lpszClassName;
if (S == "CTreeDoc")
{
TRACE0 ("Current document is CTreeDoc.\n");
TRACE1 ("Current person is %f.\n", ((CTreeDoc*)pDoc)->m_treeSet.m_ID);
Seed_ID = ((CTreeDoc*)pDoc)->m_treeSet.m_ID;
}
else
{
TRACE0 ("Current document is not CTreeDoc.\n");
return FALSE;
}
}
else
{
TRACE0 ("No current document is available.\n");
return FALSE;
}
m_treeSet.m_strFilter = "ID = ?";
m_treeSet.m_fIDParam = Seed_ID;
m_treeSet.Open();
if ( !(m_treeSet.IsBOF() && m_treeSet.IsEOF()) )
LoadAncestry(Seed_ID);
else
{
TRACE1("ID %f is invalid!\n", Seed_ID);
m_treeSet.Close();
return FALSE;
}
m_treeSet.Close();
return TRUE;
}
BEGIN_MESSAGE_MAP(CAhnenDoc, CDocument)
//{{AFX_MSG_MAP(CAhnenDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAhnenDoc support functions
CString Ahnentafel_String(double ID, CTreeSet* pSet)
{
CString S = pSet->FullName();
if (!pSet->IsFieldNull(&pSet->m_OCCUPATION))
S += '(' + pSet->m_OCCUPATION + ')';
S += ": born ";
if (!pSet->IsFieldNull(&pSet->m_BIRTHDATE))
S += pSet->m_BIRTHDATE.DateString();
else
S += "????";
if (!pSet->IsFieldNull(&pSet->m_WHERE_BORN))
S += ", " + pSet->m_WHERE_BORN;
S += "; died ";
if (!pSet->IsFieldNull(&pSet->m_DEATHDATE))
S += pSet->m_DEATHDATE.DateString();
else
S += "????";
if (!pSet->IsFieldNull(&pSet->m_WHERE_DIED))
S += ", " + pSet->m_WHERE_DIED;
return S;
}
void CAhnenDoc::LoadAncestry (double ID, int Ahnen_Number)
{
// Filter the record set for the given ID
m_treeSet.m_fIDParam = ID;
m_treeSet.Requery();
if ( m_treeSet.IsBOF() && m_treeSet.IsEOF() )
{
TRACE1("Database corrupt: Invalid ID reference -- %f!\n", ID);
return;
}
// Construct the ahnentafel string and insert it into
// the appropriate place in the array (checking for
// memory exceptions, of course).
CString S = Ahnentafel_String(ID, &m_treeSet);
TRY
{
m_arrAhnentafel.SetAtGrow(Ahnen_Number-1, S);
}
CATCH(CMemoryException, e)
{
TRACE1("LoadAncestry: memory exception on %s!\n", m_treeSet.m_FIRST);
return;
}
END_CATCH
// Recursively call LoadAncestry for Father and Mother
// if they are available (i.e. not NULL). Note that
// the Ahnen_Number is appropriately changed for each parent.
if (!m_treeSet.IsFieldNull(&m_treeSet.m_FATHER))
LoadAncestry(m_treeSet.m_FATHER, Ahnen_Number*2);
m_treeSet.m_fIDParam = ID;
m_treeSet.Requery(); // Why must we do this again? See the Q&A section.
if (!m_treeSet.IsFieldNull(&m_treeSet.m_MOTHER))
LoadAncestry(m_treeSet.m_MOTHER, Ahnen_Number*2+1);
}
/////////////////////////////////////////////////////////////////////////////
// CAhnenDoc serialization
void CAhnenDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CAhnenDoc commands
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -