⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fmfoxview.cpp

📁 本例要使用的ODBC数据源名为fox
💻 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 + -