📄 customerview.cpp
字号:
// CustomerView.cpp : implementation of the CCustomerView class
//
#include "stdafx.h"
#include "order.h"
#include "CustomerSet.h"
#include "orderDoc.h"
#include "CustomerView.h"
#include "FilterDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCustomerView
IMPLEMENT_DYNCREATE(CCustomerView, CRecordView)
BEGIN_MESSAGE_MAP(CCustomerView, CRecordView)
//{{AFX_MSG_MAP(CCustomerView)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_COMMAND(ID_RECORD_ADD, OnRecordAdd)
ON_COMMAND(ID_RECORD_REFRESH, OnRecordRefresh)
ON_COMMAND(ID_RECORD_DELETE, OnRecordDelete)
ON_COMMAND(IDD_checkcustomer, Oncheckcustomer)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CCustomerView construction/destruction
CCustomerView::CCustomerView()
: CRecordView(CCustomerView::IDD)
{
//{{AFX_DATA_INIT(CCustomerView)
m_pSet = NULL;
//}}AFX_DATA_INIT
// TODO: add construction code here
m_bAddMode=FALSE;//**##
}
CCustomerView::~CCustomerView()
{
}
void CCustomerView::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCustomerView)
DDX_Control(pDX, IDC_EDIT1, m_cltcustName);
DDX_FieldText(pDX, IDC_EDIT1, m_pSet->m_custName, m_pSet);
//}}AFX_DATA_MAP
}
BOOL CCustomerView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CRecordView::PreCreateWindow(cs);
}
void CCustomerView::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_customerSet;
CRecordView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CCustomerView printing
BOOL CCustomerView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCustomerView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCustomerView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CCustomerView diagnostics
#ifdef _DEBUG
void CCustomerView::AssertValid() const
{
CRecordView::AssertValid();
}
void CCustomerView::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
COrderDoc* CCustomerView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(COrderDoc)));
return (COrderDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCustomerView database support
CRecordset* CCustomerView::OnGetRecordset()
{
return m_pSet;
}
void CCustomerView::OnButton3()
{
// TODO: Add your control notification handler code here
exit(0);//**##
}
void CCustomerView::OnRecordAdd() //**##
{
// TODO: Add your command handler code here
if(m_bAddMode)
OnMove(ID_RECORD_FIRST);
CString strCurrentName=m_pSet->m_custName;
m_pSet->AddNew();
m_pSet->SetFieldNull(&(m_pSet->m_custName),FALSE);
m_pSet->m_custName=strCurrentName;
m_bAddMode=TRUE;
m_cltcustName.SetReadOnly(FALSE);
UpdateData(FALSE);
}
BOOL CCustomerView::OnMove(UINT nIDMoveCommand)//**##
{
// TODO: Add your specialized code here and/or call the base class
if(m_bAddMode)
{
if(!UpdateData())
return FALSE;
TRY
{
m_pSet->Update();
}
CATCH(CDBException,e)
{
AfxMessageBox(e->m_strError);
return FALSE;
}
END_CATCH
m_pSet->Requery();
UpdateData(FALSE);
m_cltcustName.SetReadOnly(TRUE);
m_bAddMode=FALSE;
}
else
return CRecordView::OnMove(nIDMoveCommand);
}
void CCustomerView::OnRecordRefresh() //**##
{
// TODO: Add your command handler code here
if(m_bAddMode==TRUE)
{
m_pSet->Move(AFX_MOVE_REFRESH);
m_cltcustName.SetReadOnly(TRUE);
m_bAddMode=FALSE;
}
UpdateData(FALSE);
}
void CCustomerView::OnRecordDelete() //**##
{
// TODO: Add your command handler code here
m_pSet->Delete();
}
void CCustomerView::Oncheckcustomer()
{
// TODO: Add your command handler code here
FilterDialog dlg;
CString strFilter;
if(IDOK==dlg.DoModal())
{
strFilter="custName like'%"+dlg.m_strFilter+"%'";
m_pSet->m_strFilter=strFilter;
m_pSet->Requery();
UpdateData(FALSE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -