📄 rcvstudentview.cpp
字号:
// RcvStudentView.cpp : implementation of the CRcvStudentView class
//
#include "stdafx.h"
#include "RcvStudent.h"
#include "RcvStudentSet.h"
#include "RcvStudentDoc.h"
#include "RcvStudentView.h"
#include "KrrCom.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CRcvStudentView
IMPLEMENT_DYNCREATE(CRcvStudentView, CRecordView)
BEGIN_MESSAGE_MAP(CRcvStudentView, CRecordView)
//{{AFX_MSG_MAP(CRcvStudentView)
ON_BN_CLICKED(IDC_BT_RECEIVE_FROM_COM2, OnBtReceiveFromCom2)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BT_SAVE_TO_DB, OnBtSaveToDb)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRcvStudentView construction/destruction
CRcvStudentView::CRcvStudentView()
: CRecordView(CRcvStudentView::IDD)
{
//{{AFX_DATA_INIT(CRcvStudentView)
m_pSet = NULL;
m_nID = 0;
m_strName = _T("");
m_strPhone = _T("");
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CRcvStudentView::~CRcvStudentView()
{
}
void CRcvStudentView::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRcvStudentView)
DDX_Text(pDX, IDC_EDIT_ID, m_nID);
DDX_Text(pDX, IDC_EDIT_NAME, m_strName);
DDV_MaxChars(pDX, m_strName, 19);
DDX_Text(pDX, IDC_EDIT_PHONE, m_strPhone);
DDV_MaxChars(pDX, m_strPhone, 19);
//}}AFX_DATA_MAP
}
BOOL CRcvStudentView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CRecordView::PreCreateWindow(cs);
}
void CRcvStudentView::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_rcvStudentSet;
CRecordView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
m_com.Open ("COM2:");//打开串口
}
/////////////////////////////////////////////////////////////////////////////
// CRcvStudentView diagnostics
#ifdef _DEBUG
void CRcvStudentView::AssertValid() const
{
CRecordView::AssertValid();
}
void CRcvStudentView::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}
CRcvStudentDoc* CRcvStudentView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CRcvStudentDoc)));
return (CRcvStudentDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CRcvStudentView database support
CRecordset* CRcvStudentView::OnGetRecordset()
{
return m_pSet;
}
/////////////////////////////////////////////////////////////////////////////
// CRcvStudentView message handlers
void CRcvStudentView::OnBtReceiveFromCom2()
{
m_com.Read ((BYTE*)&m_nID,sizeof(m_nID));//读取数据
BYTE buf[20] = {0};
m_com.Read (buf,sizeof(buf));//读取数据
m_strName = (char*)buf;
m_com.Read (buf,sizeof(buf));
m_strPhone = (char*)buf;
UpdateData (FALSE);//更新对话框
}
void CRcvStudentView::OnDestroy()
{
CRecordView::OnDestroy();
m_com.Close();
}
void CRcvStudentView::OnBtSaveToDb()
{
m_pSet->AddNew();
m_pSet->m_StudentID = m_nID;
m_pSet->m_StudentName = m_strName;
m_pSet->m_Telephone = m_strPhone;
m_pSet->Update();
}
BOOL CRcvStudentView::OnMove(UINT nIDMoveCommand)
{
// TODO: Add your specialized code here and/or call the base class
if (CRecordView::OnMove(nIDMoveCommand)){
m_nID = m_pSet->m_StudentID;
m_strName = m_pSet->m_StudentName;
m_strPhone = m_pSet->m_Telephone;
UpdateData (FALSE);
return TRUE;
}
else{
return FALSE;
}
return FALSE;
// return CRecordView::OnMove(nIDMoveCommand);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -