📄 c02view.cpp
字号:
// C02View.cpp : implementation of the CC02View class
//
#include "stdafx.h"
#include "C02.h"
#include "C02Set.h"
#include "C02Doc.h"
#include "C02View.h"
#include "dlglookup.h"
#include "adddlg.h"
#include "dlgdelete.h"
#include "dlgmodify.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CC02View
IMPLEMENT_DYNCREATE(CC02View, CRecordView)
BEGIN_MESSAGE_MAP(CC02View, CRecordView)
//{{AFX_MSG_MAP(CC02View)
ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
ON_BN_CLICKED(IDC_BUTTON_MODIFY, OnButtonModify)
ON_COMMAND(ID_RECORD_FIRST, OnRecordFirst)
ON_COMMAND(ID_RECORD_LAST, OnRecordLast)
ON_COMMAND(ID_RECORD_NEXT, OnRecordNext)
ON_COMMAND(ID_RECORD_PREV, OnRecordPrev)
ON_BN_CLICKED(IDC_BUTTON_lookup, OnBUTTONlookup)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRecordView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CC02View construction/destruction
CC02View::CC02View()
: CRecordView(CC02View::IDD)
{
//{{AFX_DATA_INIT(CC02View)
m_pSet = NULL;
m_name = _T("");
m_type = _T("");
m_mail = _T("");
m_address = _T("");
m_phone = _T("");
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CC02View::~CC02View()
{
}
void CC02View::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CC02View)
DDX_Text(pDX, IDC_EDIT_NAME, m_name);
DDX_Text(pDX, IDC_EDIT_TYPE, m_type);
DDX_Text(pDX, IDC_EDIT_MAIL, m_mail);
DDX_Text(pDX, IDC_EDIT_ADDRESS, m_address);
DDX_Text(pDX, IDC_EDIT_phone, m_phone);
//}}AFX_DATA_MAP
}
BOOL CC02View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CRecordView::PreCreateWindow(cs);
}
void CC02View::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_c02Set;
CRecordView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
try
{
m_pSet=new CC02Set();
m_pSet->Open();
RefreshData();
}
catch(CDBException* pe)
{
AfxMessageBox(pe->m_strError);
pe->Delete();
}
}
/////////////////////////////////////////////////////////////////////////////
// CC02View printing
BOOL CC02View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CC02View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CC02View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CC02View diagnostics
#ifdef _DEBUG
void CC02View::AssertValid() const
{
CRecordView::AssertValid();
}
void CC02View::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
CC02Doc* CC02View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CC02Doc)));
return (CC02Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CC02View database support
CRecordset* CC02View::OnGetRecordset()
{
return m_pSet;
}
/////////////////////////////////////////////////////////////////////////////
// CC02View message handlers
void CC02View::OnButtonAdd()
{
/* try
{
m_pSet->AddNew();
UpdateData(TRUE);
m_pSet->m_Address=m_address;
m_pSet->m_Mail=m_mail;
m_pSet->m_Name=m_name;
m_pSet->m_Type=m_type;
m_pSet->m_Phone=m_phone;
m_pSet->Update();
m_pSet->Requery();
}
catch(CDBException* pe)
{
AfxMessageBox(pe->m_strError);
pe->Delete();
} // TODO: Add your control notification handler code here
*/
adddlg addlg;
if(addlg.DoModal()==IDOK)
{
try
{
m_pSet->AddNew();
UpdateData(TRUE);
m_pSet->m_Address=addlg.m_addaddress;
m_pSet->m_Mail=addlg.m_addmail;
m_pSet->m_Name=addlg.m_addname;
m_pSet->m_Type=addlg.m_addtype;
m_pSet->m_Phone=addlg.m_addphone;
m_pSet->Update();
m_pSet->Requery();
}
catch(CDBException* pe)
{
AfxMessageBox(pe->m_strError);
pe->Delete();
}
}
}
void CC02View::OnButtonDelete()
{
// TODO: Add your control notification handler code here
/*try
{
m_pSet->Delete();
m_pSet->Requery();
RefreshData();
}
catch(CDBException* pe)
{
AfxMessageBox(pe->m_strError);
pe->Delete();
}
*/
dlgdelete ddelete;
if(ddelete.DoModal()==IDOK)
{
try
{
m_pSet->Delete();
m_pSet->Requery();
RefreshData();
}
catch(CDBException* pe)
{
AfxMessageBox(pe->m_strError);
pe->Delete();
}
}
}
void CC02View::OnButtonModify()
{
// TODO: Add your control notification handler code here
/*try
{
m_pSet->Edit();
UpdateData(TRUE);
m_pSet->m_Address=m_address;
m_pSet->m_Mail=m_mail;
m_pSet->m_Name=m_name;
m_pSet->m_Type=m_type;
m_pSet->m_Phone=m_phone;
m_pSet->Update();
}
catch(CDBException* pe)
{
AfxMessageBox(pe->m_strError);
pe->Delete();
}
*/
int n;
dlgmodify dmodify;
dmodify.m_dmail=m_mail;
dmodify.m_dname=m_name;
dmodify.m_dtype=m_type;
dmodify.m_dphone=m_phone;
dmodify.m_daddress=m_address;
n=dmodify.DoModal();
if(n==IDOK)
{
try
{
m_pSet->Edit();
UpdateData(TRUE);
m_pSet->m_Address=dmodify.m_daddress;
m_pSet->m_Mail=dmodify.m_dmail;
m_pSet->m_Name=dmodify.m_dname;
m_pSet->m_Type=dmodify.m_dtype;
m_pSet->m_Phone=dmodify.m_dphone;
m_pSet->Update();
RefreshData();
}
catch(CDBException* pe)
{
AfxMessageBox(pe->m_strError);
pe->Delete();
}
}
}
void CC02View::OnRecordFirst()
{
// TODO: Add your command handler code here
m_pSet->MoveFirst();
RefreshData();
}
void CC02View::OnRecordLast()
{
// TODO: Add your command handler code here
m_pSet->MoveLast();
RefreshData();
}
void CC02View::OnRecordNext()
{
// TODO: Add your command handler code here
m_pSet->MoveNext();
RefreshData();
}
void CC02View::OnRecordPrev()
{
// TODO: Add your command handler code here
m_pSet->MovePrev();
RefreshData();
}
void CC02View::RefreshData()
{
m_name=m_pSet->m_Name;
m_address=m_pSet->m_Address;
m_mail=m_pSet->m_Mail;
m_type=m_pSet->m_Type;
m_phone=m_pSet->m_Phone;
UpdateData(FALSE);
}
void CC02View::OnBUTTONlookup()
{
// TODO: Add your control notification handler code here
/*dlglookup *pdlg=new dlglookup;
pdlg->Create(IDD_DIALOG1);
pdlg->ShowWindow(SW_SHOW);*/
dlglookup dlg;
if(dlg.DoModal()==IDOK)
{
m_pSet->m_strFilter="NAme=''";
m_pSet->m_strFilter.Insert(6,dlg.m_dlgname);
m_pSet->Requery();
RefreshData();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -