📄 myaldoc.cpp
字号:
// MyALDoc.cpp : implementation of the CMyALDoc class
//
#include "stdafx.h"
#include "MyAL.h"
#include "MyALDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyALDoc
IMPLEMENT_DYNCREATE(CMyALDoc, CDocument)
BEGIN_MESSAGE_MAP(CMyALDoc, CDocument)
//{{AFX_MSG_MAP(CMyALDoc)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyALDoc construction/destruction
CMyALDoc::CMyALDoc()
{
m_pBaseInfoSet = NULL;
m_pFamilySet = NULL;
m_pUnitSet = NULL;
m_pContactSet = NULL;
m_pOtherSet = NULL;
m_pActiveSet = NULL;
m_pRemarkSet = NULL;
m_nActiveCount = 0;
}
CMyALDoc::~CMyALDoc()
{
delete m_pBaseInfoSet;
delete m_pFamilySet;
delete m_pUnitSet;
delete m_pContactSet;
delete m_pOtherSet;
delete m_pActiveSet;
delete m_pRemarkSet;
}
BOOL CMyALDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
m_pBaseInfoSet = new CBaseInfoSet;
m_pFamilySet = new CFamilySet;
m_pUnitSet = new CUnitSet;
m_pContactSet = new CContactSet;
m_pOtherSet = new COtherSet;
m_pActiveSet = new CActiveSet;
m_pRemarkSet = new CRemarkSet;
SetTitle(_T("MyAddressList"));
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMyALDoc serialization
void CMyALDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CMyALDoc diagnostics
#ifdef _DEBUG
void CMyALDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CMyALDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMyALDoc commands
void CMyALDoc::OnCloseDocument()
{
if(m_pBaseInfoSet->IsOpen())
m_pBaseInfoSet->Close();
if(m_pFamilySet->IsOpen())
m_pFamilySet->Close();
if(m_pUnitSet->IsOpen())
m_pUnitSet->Close();
if(m_pContactSet->IsOpen())
m_pContactSet->Close();
if(m_pOtherSet->IsOpen())
m_pOtherSet->Close();
if(m_pActiveSet->IsOpen())
m_pActiveSet->Close();
if(m_pRemarkSet->IsOpen())
m_pRemarkSet->Close();
CDocument::OnCloseDocument();
}
BOOL CMyALDoc::Addnew()
{
CDetails dlg;
if(dlg.DoModal()==IDOK)
{
/**************************往m_pBaseInfoSet中添加记录**************************/
if(!m_pBaseInfoSet->IsOpen())
m_pBaseInfoSet->Open();
m_pBaseInfoSet->AddNew();
if(m_pBaseInfoSet->CanAppend())
{
m_pBaseInfoSet->m_Name = dlg.m_BIPage.m_strName;
m_pBaseInfoSet->m_Sex = dlg.m_BIPage.m_nSex;
m_pBaseInfoSet->m_Birthday = dlg.m_BIPage.m_OleBirthday;
m_pBaseInfoSet->m_System = dlg.m_BIPage.m_nSystem;
m_pBaseInfoSet->m_Clew = dlg.m_BIPage.m_bClew;
m_pBaseInfoSet->m_Province = dlg.m_BIPage.m_strProvince;
m_pBaseInfoSet->m_City = dlg.m_BIPage.m_strCity;
m_pBaseInfoSet->m_Country = dlg.m_BIPage.m_strCountry;
}
if(m_pBaseInfoSet->CanUpdate())
m_pBaseInfoSet->Update();
m_pBaseInfoSet->MoveLast();
/**************************往m_pFamilySet中添加记录**************************/
if(!m_pFamilySet->IsOpen())
m_pFamilySet->Open();
m_pFamilySet->AddNew();
if(m_pFamilySet->CanAppend())
{
m_pFamilySet->m_ID = m_pBaseInfoSet->m_ID;
m_pFamilySet->m_City = dlg.m_FPage.m_strCity;
m_pFamilySet->m_Country = dlg.m_FPage.m_strCountry;
m_pFamilySet->m_Leaguer = dlg.m_FPage.m_strLeaguer;
m_pFamilySet->m_PostalCode = dlg.m_FPage.m_strPostalcode;
m_pFamilySet->m_Province = dlg.m_FPage.m_strProvince;
m_pFamilySet->m_Street = dlg.m_FPage.m_strStreet;
m_pFamilySet->m_Telephone = dlg.m_FPage.m_strTelephone;
}
if(m_pFamilySet->CanUpdate())
m_pFamilySet->Update();
m_pFamilySet->MoveLast();
/**************************往m_pUnitSet中添加记录**************************/
if(!m_pUnitSet->IsOpen())
m_pUnitSet->Open();
m_pUnitSet->AddNew();
if(m_pUnitSet->CanAppend())
{
m_pUnitSet->m_ID = m_pBaseInfoSet->m_ID;
m_pUnitSet->m_Country = dlg.m_UPage.m_strCountry;
m_pUnitSet->m_Province = dlg.m_UPage.m_strProvince;
m_pUnitSet->m_City = dlg.m_UPage.m_strCity;
m_pUnitSet->m_UnitName = dlg.m_UPage.m_strUnitname;
m_pUnitSet->m_Department = dlg.m_UPage.m_strDeparment;
m_pUnitSet->m_Office = dlg.m_UPage.m_strOffice;
m_pUnitSet->m_Job = dlg.m_UPage.m_strJob;
m_pUnitSet->m_Street = dlg.m_UPage.m_strStreet;
m_pUnitSet->m_PostalCode = dlg.m_UPage.m_strPostalcode;
m_pUnitSet->m_Telephone = dlg.m_UPage.m_strTelephone;
m_pUnitSet->m_Fax = dlg.m_UPage.m_strFax;
m_pUnitSet->m_Web = dlg.m_UPage.m_strWeb;
m_pUnitSet->m_Email = dlg.m_UPage.m_strEmail;
}
if(m_pUnitSet->CanUpdate())
m_pUnitSet->Update();
m_pUnitSet->MoveLast();
/**************************往m_pContactSet中添加记录**************************/
if(!m_pContactSet->IsOpen())
m_pContactSet->Open();
m_pContactSet->AddNew();
if(m_pContactSet->CanAppend())
{
m_pContactSet->m_ID = m_pBaseInfoSet->m_ID;
m_pContactSet->m_PostalCode = dlg.m_CPage.m_strPostalcode;
m_pContactSet->m_Country = dlg.m_CPage.m_strCountry;
m_pContactSet->m_Province = dlg.m_CPage.m_strProvince;
m_pContactSet->m_City = dlg.m_CPage.m_strCity;
m_pContactSet->m_Street = dlg.m_CPage.m_strStreet;
m_pContactSet->m_Telephone = dlg.m_CPage.m_strTelephone;
m_pContactSet->m_Fax = dlg.m_CPage.m_strFax;
m_pContactSet->m_Handset = dlg.m_CPage.m_strHeadset;
m_pContactSet->m_Email = dlg.m_CPage.m_strEmail;
m_pContactSet->m_MSN = dlg.m_CPage.m_strMsn;
m_pContactSet->m_QQ = dlg.m_CPage.m_strQq;
m_pContactSet->m_ICQ = dlg.m_CPage.m_strIcq;
}
if(m_pContactSet->CanUpdate())
m_pContactSet->Update();
m_pContactSet->MoveLast();
/**************************往m_pOtherSet中添加记录**************************/
if(!m_pOtherSet->IsOpen())
m_pOtherSet->Open();
m_pOtherSet->AddNew();
if(m_pOtherSet->CanAppend())
{
m_pOtherSet->m_ID = m_pBaseInfoSet->m_ID;
m_pOtherSet->m_Nickname = dlg.m_OPage.m_strNickName;
m_pOtherSet->m_Favorites = dlg.m_OPage.m_strFavorites;
m_pOtherSet->m_Specialty = dlg.m_OPage.m_strSpecialty;
m_pOtherSet->m_Web = dlg.m_OPage.m_strWeb;
}
if(m_pOtherSet->CanUpdate())
m_pOtherSet->Update();
m_pOtherSet->MoveLast();
/**************************往m_pActiveSet中添加记录**************************/
if(!m_pActiveSet->IsOpen())
m_pActiveSet->Open();
m_pActiveSet->AddNew();
if(m_pActiveSet->CanAppend())
{
int nRecord = dlg.m_APage.m_activeArray.GetSize();
if(nRecord!=0)
{
for(int i=0;i<nRecord;i++)
{
m_pActiveSet->m_ID = m_pBaseInfoSet->m_ID;
m_pActiveSet->m_Clew = dlg.m_APage.m_activeArray[i].m_Clew;
m_pActiveSet->m_Date = dlg.m_APage.m_activeArray[i].m_Date;
m_pActiveSet->m_Summary = dlg.m_APage.m_activeArray[i].m_Summary;
m_pActiveSet->m_Type = dlg.m_APage.m_activeArray[i].m_Type;
if(m_pActiveSet->CanUpdate())
{
m_pActiveSet->Update();
m_pActiveSet->AddNew();
}
}
}
}
/**************************往m_pOtherSet中添加记录**************************/
if(!m_pRemarkSet->IsOpen())
m_pRemarkSet->Open();
m_pRemarkSet->AddNew();
if(m_pRemarkSet->CanAppend())
{
m_pRemarkSet->m_ID = m_pBaseInfoSet->m_ID;
m_pRemarkSet->m_Remark = dlg.m_RMPage.m_strRemark;
}
if(m_pRemarkSet->CanUpdate())
m_pRemarkSet->Update();
m_pRemarkSet->MoveLast();
return TRUE;
}
return FALSE;
}
void CMyALDoc::DelRecord(long lID)
{
CString strSQL;
if(m_pBaseInfoSet->IsOpen()) m_pBaseInfoSet->Close();
strSQL.Format("select * from BaseInfo where ID = %ld",lID);
m_pBaseInfoSet->Open(AFX_DAO_USE_DEFAULT_TYPE ,strSQL);
m_pBaseInfoSet->Delete();
if(m_pFamilySet->IsOpen()) m_pFamilySet->Close();
strSQL.Format("select * from Family where ID = %ld",lID);
m_pFamilySet->Open(AFX_DAO_USE_DEFAULT_TYPE ,strSQL);
m_pFamilySet->Delete();
if(m_pUnitSet->IsOpen()) m_pUnitSet->Close();
strSQL.Format("select * from Unit where ID = %ld",lID);
m_pUnitSet->Open(AFX_DAO_USE_DEFAULT_TYPE ,strSQL);
m_pUnitSet->Delete();
if(m_pContactSet->IsOpen()) m_pContactSet->Close();
strSQL.Format("select * from Contact where ID = %ld",lID);
m_pContactSet->Open(AFX_DAO_USE_DEFAULT_TYPE ,strSQL);
m_pContactSet->Delete();
if(m_pOtherSet->IsOpen()) m_pOtherSet->Close();
strSQL.Format("select * from Other where ID = %ld",lID);
m_pOtherSet->Open(AFX_DAO_USE_DEFAULT_TYPE ,strSQL);
m_pOtherSet->Delete();
if(m_pRemarkSet->IsOpen()) m_pRemarkSet->Close();
strSQL.Format("select * from Remark where ID = %ld",lID);
m_pRemarkSet->Open(AFX_DAO_USE_DEFAULT_TYPE ,strSQL);
m_pRemarkSet->Delete();
if(m_pActiveSet->IsOpen())
m_pActiveSet->Close();
m_pActiveSet->Open();
while(!m_pActiveSet->IsEOF())
{
if(m_pActiveSet->m_ID == lID)
{
TRACE("m_pActiveSet->m_ID == m_pBaseInfoSet->m_ID\n");
m_pActiveSet->Delete();
}
m_pActiveSet->MoveNext();
}
}
BOOL CMyALDoc::Modify(long lID)
{
CString strSQL;
if(m_pBaseInfoSet->IsOpen()) m_pBaseInfoSet->Close();
strSQL.Format("select * from BaseInfo where ID = %ld",lID);
m_pBaseInfoSet->Open(AFX_DAO_USE_DEFAULT_TYPE ,strSQL);
if(m_pFamilySet->IsOpen()) m_pFamilySet->Close();
strSQL.Format("select * from Family where ID = %ld",lID);
m_pFamilySet->Open(AFX_DAO_USE_DEFAULT_TYPE ,strSQL);
if(m_pUnitSet->IsOpen()) m_pUnitSet->Close();
strSQL.Format("select * from Unit where ID = %ld",lID);
m_pUnitSet->Open(AFX_DAO_USE_DEFAULT_TYPE ,strSQL);
if(m_pContactSet->IsOpen()) m_pContactSet->Close();
strSQL.Format("select * from Contact where ID = %ld",lID);
m_pContactSet->Open(AFX_DAO_USE_DEFAULT_TYPE ,strSQL);
if(m_pOtherSet->IsOpen()) m_pOtherSet->Close();
strSQL.Format("select * from Other where ID = %ld",lID);
m_pOtherSet->Open(AFX_DAO_USE_DEFAULT_TYPE ,strSQL);
if(m_pRemarkSet->IsOpen()) m_pRemarkSet->Close();
strSQL.Format("select * from Remark where ID = %ld",lID);
m_pRemarkSet->Open(AFX_DAO_USE_DEFAULT_TYPE ,strSQL);
CDetails dlg;
/***************************初始化BIPage页***************************/
dlg.m_BIPage.m_strName = m_pBaseInfoSet->m_Name;
dlg.m_BIPage.m_nSex = m_pBaseInfoSet->m_Sex;
dlg.m_BIPage.m_OleBirthday = m_pBaseInfoSet->m_Birthday;
dlg.m_BIPage.m_nSystem = m_pBaseInfoSet->m_System;
dlg.m_BIPage.m_bClew = m_pBaseInfoSet->m_Clew;
dlg.m_BIPage.m_strProvince = m_pBaseInfoSet->m_Province;
dlg.m_BIPage.m_strCity = m_pBaseInfoSet->m_City;
dlg.m_BIPage.m_strCountry = m_pBaseInfoSet->m_Country;
/***************************初始化FPage页***************************/
dlg.m_FPage.m_strPostalcode = m_pFamilySet->m_PostalCode;
dlg.m_FPage.m_strProvince = m_pFamilySet->m_Province;
dlg.m_FPage.m_strCity = m_pFamilySet->m_City;
dlg.m_FPage.m_strStreet = m_pFamilySet->m_Street;
dlg.m_FPage.m_strCountry = m_pFamilySet->m_Country;
dlg.m_FPage.m_strTelephone = m_pFamilySet->m_Telephone;
dlg.m_FPage.m_strLeaguer = m_pFamilySet->m_Leaguer;
/***************************初始化UPage页***************************/
dlg.m_UPage.m_strCity = m_pUnitSet->m_City;
dlg.m_UPage.m_strCountry = m_pUnitSet->m_Country;
dlg.m_UPage.m_strDeparment = m_pUnitSet->m_Department;
dlg.m_UPage.m_strEmail = m_pUnitSet->m_Email;
dlg.m_UPage.m_strFax = m_pUnitSet->m_Fax;
dlg.m_UPage.m_strJob = m_pUnitSet->m_Job;
dlg.m_UPage.m_strOffice = m_pUnitSet->m_Office;
dlg.m_UPage.m_strPostalcode = m_pUnitSet->m_PostalCode;
dlg.m_UPage.m_strProvince = m_pUnitSet->m_Province;
dlg.m_UPage.m_strStreet = m_pUnitSet->m_Street;
dlg.m_UPage.m_strTelephone = m_pUnitSet->m_Telephone;
dlg.m_UPage.m_strUnitname = m_pUnitSet->m_UnitName;
dlg.m_UPage.m_strWeb = m_pUnitSet->m_Web;
/***************************初始化CPage页***************************/
dlg.m_CPage.m_strCity = m_pContactSet->m_City;
dlg.m_CPage.m_strCountry = m_pContactSet->m_Country;
dlg.m_CPage.m_strEmail = m_pContactSet->m_Email;
dlg.m_CPage.m_strFax = m_pContactSet->m_Fax;
dlg.m_CPage.m_strHeadset = m_pContactSet->m_Handset;
dlg.m_CPage.m_strIcq = m_pContactSet->m_ICQ;
dlg.m_CPage.m_strMsn = m_pContactSet->m_MSN;
dlg.m_CPage.m_strPostalcode = m_pContactSet->m_PostalCode;
dlg.m_CPage.m_strProvince = m_pContactSet->m_Province;
dlg.m_CPage.m_strQq = m_pContactSet->m_QQ;
dlg.m_CPage.m_strStreet = m_pContactSet->m_Street;
dlg.m_CPage.m_strTelephone = m_pContactSet->m_Telephone;
/***************************初始化OPage页***************************/
dlg.m_OPage.m_strFavorites = m_pOtherSet->m_Favorites;
dlg.m_OPage.m_strNickName = m_pOtherSet->m_Nickname;
dlg.m_OPage.m_strSpecialty = m_pOtherSet->m_Specialty;
dlg.m_OPage.m_strWeb = m_pOtherSet->m_Web;
/***************************初始化APage页***************************/
if(m_pActiveSet->IsOpen())
m_pActiveSet->Close();
m_pActiveSet->Open();
while(!m_pActiveSet->IsEOF())
{
if(m_pActiveSet->m_ID == m_pBaseInfoSet->m_ID)
{
dlg.m_APage.m_Active.m_Clew = m_pActiveSet->m_Clew;
dlg.m_APage.m_Active.m_Date = m_pActiveSet->m_Date;
dlg.m_APage.m_Active.m_Summary = m_pActiveSet->m_Summary;
dlg.m_APage.m_Active.m_Type = m_pActiveSet->m_Type;
dlg.m_APage.m_activeArray.Add(dlg.m_APage.m_Active);
m_nActiveCount++;
}
m_pActiveSet->MoveNext();
}
/***************************初始化RMPage页***************************/
dlg.m_RMPage.m_strRemark = m_pRemarkSet->m_Remark;
/********************************************************************/
EndWaitCursor();
if(dlg.DoModal()==IDOK)
{
/**************************修改m_pBaseInfoSet中的记录**************************/
m_pBaseInfoSet->Edit();
if(m_pBaseInfoSet->GetEditMode()==dbEditInProgress)
{
m_pBaseInfoSet->m_Name = dlg.m_BIPage.m_strName;
m_pBaseInfoSet->m_Sex = dlg.m_BIPage.m_nSex;
m_pBaseInfoSet->m_Birthday = dlg.m_BIPage.m_OleBirthday;
m_pBaseInfoSet->m_System = dlg.m_BIPage.m_nSystem;
m_pBaseInfoSet->m_Clew = dlg.m_BIPage.m_bClew;
m_pBaseInfoSet->m_Province = dlg.m_BIPage.m_strProvince;
m_pBaseInfoSet->m_City = dlg.m_BIPage.m_strCity;
m_pBaseInfoSet->m_Country = dlg.m_BIPage.m_strCountry;
}
if(m_pBaseInfoSet->CanUpdate())
m_pBaseInfoSet->Update();
/**************************修改m_pFamilySet中的记录**************************/
m_pFamilySet->Edit();
if(m_pFamilySet->GetEditMode()==dbEditInProgress)
{
m_pFamilySet->m_ID = m_pBaseInfoSet->m_ID;
m_pFamilySet->m_City = dlg.m_FPage.m_strCity;
m_pFamilySet->m_Country = dlg.m_FPage.m_strCountry;
m_pFamilySet->m_Leaguer = dlg.m_FPage.m_strLeaguer;
m_pFamilySet->m_PostalCode = dlg.m_FPage.m_strPostalcode;
m_pFamilySet->m_Province = dlg.m_FPage.m_strProvince;
m_pFamilySet->m_Street = dlg.m_FPage.m_strStreet;
m_pFamilySet->m_Telephone = dlg.m_FPage.m_strTelephone;
}
if(m_pFamilySet->CanUpdate())
m_pFamilySet->Update();
/**************************修改m_pUnitSet中的记录**************************/
m_pUnitSet->Edit();
if(m_pUnitSet->GetEditMode()==dbEditInProgress)
{
m_pUnitSet->m_ID = m_pBaseInfoSet->m_ID;
m_pUnitSet->m_Country = dlg.m_UPage.m_strCountry;
m_pUnitSet->m_Province = dlg.m_UPage.m_strProvince;
m_pUnitSet->m_City = dlg.m_UPage.m_strCity;
m_pUnitSet->m_UnitName = dlg.m_UPage.m_strUnitname;
m_pUnitSet->m_Department = dlg.m_UPage.m_strDeparment;
m_pUnitSet->m_Office = dlg.m_UPage.m_strOffice;
m_pUnitSet->m_Job = dlg.m_UPage.m_strJob;
m_pUnitSet->m_Street = dlg.m_UPage.m_strStreet;
m_pUnitSet->m_PostalCode = dlg.m_UPage.m_strPostalcode;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -