?? fmfoxview.cpp
字號:
// fmfoxView.cpp : implementation of the CFmfoxView class
//
#include "stdafx.h"
#include "fmfox.h"
#include "fmfoxSet.h"
#include "fmfoxDoc.h"
#include "fmfoxView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFmfoxView
IMPLEMENT_DYNCREATE(CFmfoxView, CRecordView)
BEGIN_MESSAGE_MAP(CFmfoxView, CRecordView)
//{{AFX_MSG_MAP(CFmfoxView)
ON_COMMAND(ID_RECORD_FIRST, OnRecordFirst)
ON_UPDATE_COMMAND_UI(ID_RECORD_FIRST, OnUpdateRecordFirst)
ON_COMMAND(ID_RECORD_NEXT, OnRecordNext)
ON_UPDATE_COMMAND_UI(ID_RECORD_NEXT, OnUpdateRecordNext)
ON_COMMAND(ID_RECORD_PREV, OnRecordPrev)
ON_UPDATE_COMMAND_UI(ID_RECORD_PREV, OnUpdateRecordPrev)
ON_COMMAND(ID_RECORD_LAST, OnRecordLast)
ON_UPDATE_COMMAND_UI(ID_RECORD_LAST, OnUpdateRecordLast)
ON_BN_CLICKED(IDC_INSERT, OnInsert)
ON_BN_CLICKED(IDC_ENTER, OnEnter)
ON_BN_CLICKED(IDC_IDELETE, OnIdelete)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFmfoxView construction/destruction
CFmfoxView::CFmfoxView()
: CRecordView(CFmfoxView::IDD)
{
//{{AFX_DATA_INIT(CFmfoxView)
m_pSet = NULL;
m_Date = _T("");
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CFmfoxView::~CFmfoxView()
{
}
void CFmfoxView::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFmfoxView)
DDX_Text(pDX, IDC_DATE, m_Date);
DDX_FieldText(pDX, IDC_GRADE, m_pSet->m_A2, m_pSet);
DDX_FieldText(pDX, IDC_NAME, m_pSet->m_A1, m_pSet);
//}}AFX_DATA_MAP
TRACE("Waiting...\n");
}
BOOL CFmfoxView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CRecordView::PreCreateWindow(cs);
}
void CFmfoxView::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_fmfoxSet;
CRecordView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
//本函數沒有插入語句提示,以下語句是后插入的:
m_pSet->Edit();
TRACE("The current status is %d\n",m_pSet->CanAppend( ));
TRACE("The current update status is %d\n",m_pSet->CanUpdate( ));
m_Date=(m_pSet->m_A3+CTimeSpan(1,0,0,0)).FormatGmt("%y-%m-%d");//轉換后的日期會發生一天的誤差
//TRACE("The current test is %s\n",m_Date);所以加上一天的時間
UpdateData(FALSE);
}
/////////////////////////////////////////////////////////////////////////////
// CFmfoxView diagnostics
#ifdef _DEBUG
void CFmfoxView::AssertValid() const
{
CRecordView::AssertValid();
}
void CFmfoxView::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
CFmfoxDoc* CFmfoxView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFmfoxDoc)));
return (CFmfoxDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CFmfoxView database support
CRecordset* CFmfoxView::OnGetRecordset()
{
return m_pSet;
}
/////////////////////////////////////////////////////////////////////////////
// CFmfoxView message handlers
void CFmfoxView::OnRecordFirst()
{
// TODO: Add your command handler code here
m_pSet->MoveFirst();
m_Date=(m_pSet->m_A3+CTimeSpan(1,0,0,0)).FormatGmt("%y-%m-%d");
UpdateData(FALSE);//在進行DDE交換時使內存變量與數據表記錄同步
GetDlgItem(IDC_NAME)->SetFocus();
TRACE("The current name is %s\n",m_Date);
}
void CFmfoxView::OnUpdateRecordFirst(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(!m_pSet->IsBOF());
}
void CFmfoxView::OnRecordNext()
{
// TODO: Add your command handler code here
m_pSet->MoveNext();
m_Date=(m_pSet->m_A3+CTimeSpan(1,0,0,0)).FormatGmt("%y-%m-%d");
UpdateData(FALSE);//在進行DDE交換時使內存變量與數據表記錄同步
GetDlgItem(IDC_NAME)->SetFocus();
}
void CFmfoxView::OnUpdateRecordNext(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
//pCmdUI->Enable(!IsOnLastRecord());//可試著對比和下面語句的細微區別
pCmdUI->Enable(!m_pSet->IsEOF());
}
void CFmfoxView::OnRecordPrev()
{
// TODO: Add your command handler code here
m_pSet->MovePrev();
m_Date=(m_pSet->m_A3+CTimeSpan(1,0,0,0)).FormatGmt("%y-%m-%d");
UpdateData(FALSE);
GetDlgItem(IDC_NAME)->SetFocus();
}
void CFmfoxView::OnUpdateRecordPrev(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(!m_pSet->IsBOF());
}
void CFmfoxView::OnRecordLast()
{
// TODO: Add your command handler code here
m_pSet->MoveLast( );
m_Date=(m_pSet->m_A3+CTimeSpan(1,0,0,0)).FormatGmt("%y-%m-%d");
UpdateData(FALSE);
GetDlgItem(IDC_NAME)->SetFocus();
}
void CFmfoxView::OnUpdateRecordLast(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
//pCmdUI->Enable(!IsOnLastRecord());//可試著對比和下面語句的細微區別
pCmdUI->Enable(!m_pSet->IsEOF());
}
void CFmfoxView::OnInsert()
{
// TODO: Add your control notification handler code here
m_pSet->AddNew();//插入一個新記錄
m_pSet->m_A1="New Name";
m_pSet->m_A2=(double)100.0;
m_pSet->m_A3=CTime::GetCurrentTime();;
m_Date=(m_pSet->m_A3+CTimeSpan(1,0,0,0)).FormatGmt("%y-%m-%d");
m_pSet->Update();//將新記錄寫入數據表內
if(m_pSet->Requery())m_pSet->MoveLast();
UpdateData(FALSE);//在進行DDE交換時將內存變量值傳向對話框文本編輯欄內
GetDlgItem(IDC_NAME)->SetFocus();
}
void CFmfoxView::OnEnter()
{
// TODO: Add your control notification handler code here
TRACE("The current record name is %s\n",m_pSet->m_A1);
m_pSet->Edit();//轉入修改模式
UpdateData(TRUE);
m_pSet->Update();
GetDlgItem(IDC_NAME)->SetFocus();
}
void CFmfoxView::OnIdelete()
{
// TODO: Add your control notification handler code here
m_pSet->Delete();//刪除當前記錄
m_pSet->Move(-1);//記錄指針回退一個位置
if(IsOnFirstRecord()||m_pSet->IsBOF())m_pSet->Move(1);
while(m_pSet->IsDeleted())m_pSet->Move(1);//若當前記錄已被刪除,則將記錄指針向后定位到一個未刪除記錄處
if(m_pSet->Requery())m_pSet->Move(0);
UpdateData(FALSE);//在進行DDE交換時將內存變量值傳向對話框文本編輯欄內
GetDlgItem(IDC_NAME)->SetFocus();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -