// testView.cpp : implementation of the CTestView class // #include "stdafx.h" #include "test.h" #include "testDoc.h" #include "testView.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CTestView IMPLEMENT_DYNCREATE(CTestView, CFormView) BEGIN_MESSAGE_MAP(CTestView, CFormView) //{{AFX_MSG_MAP(CTestView) ON_BN_CLICKED(IDC_save, Onsave) ON_BN_CLICKED(IDC_undo, Onundo) ON_BN_CLICKED(IDC_last, Onlast) ON_BN_CLICKED(IDC_next, Onnext) //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CTestView construction/destruction CTestView::CTestView() : CFormView(CTestView::IDD) { //{{AFX_DATA_INIT(CTestView) m_add = _T(""); m_age = 0; m_name = _T(""); m_num = 0; m_sex = _T(""); m_tel = _T(""); //}}AFX_DATA_INIT // TODO: add construction code here } CTestView::~CTestView() { } void CTestView::DoDataExchange(CDataExchange* pDX) { CFormView::DoDataExchange(pDX); //{{AFX_DATA_MAP(CTestView) DDX_Text(pDX, IDC_add, m_add); DDX_Text(pDX, IDC_age, m_age); DDX_Text(pDX, IDC_name, m_name); DDX_Text(pDX, IDC_num, m_num); DDX_Text(pDX, IDC_sex, m_sex); DDX_Text(pDX, IDC_tel, m_tel); //}}AFX_DATA_MAP } BOOL CTestView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CFormView::PreCreateWindow(cs); } void CTestView::OnInitialUpdate() { CFormView::OnInitialUpdate(); GetParentFrame()->RecalcLayout(); ResizeParentToFit(); } ///////////////////////////////////////////////////////////////////////////// // CTestView printing BOOL CTestView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CTestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CTestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } void CTestView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/) { // TODO: add customized printing code here } ///////////////////////////////////////////////////////////////////////////// // CTestView diagnostics #ifdef _DEBUG void CTestView::AssertValid() const { CFormView::AssertValid(); } void CTestView::Dump(CDumpContext& dc) const { CFormView::Dump(dc); } CTestDoc* CTestView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestDoc))); return (CTestDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CTestView message handlers void CTestView::Onsave() { // TODO: Add your control notification handler code here CTestDoc *pdoc=GetDocument(); UpdateData(true); //数据更新 int number=m_num-1; if(m_num>=34||m_num<=1) AfxMessageBox("学号需处于1-34之间"); //弹出消息参考 else { pdoc->student[number].add=m_add; //数据保存在对象数组中 pdoc->student[number].age=m_age; pdoc->student[number].name=m_name; pdoc->student[number].num=m_num; pdoc->student[number].sex=m_sex; pdoc->student[number].tel=m_tel; } } void CTestView::Onundo() { // TODO: Add your control notification handler code here //编辑框内内容清空 m_add=""; m_age=0; m_name=""; m_sex=""; m_tel=""; m_num=0; UpdateData(false); //更新显示 } void CTestView::Onlast() { // TODO: Add your control notification handler code here AfxMessageBox("输入学号单击\"上一个\"按钮可以查看上一条记录"); UpdateData(true); if(m_num<=0) AfxMessageBox("没有上一个"); else { CTestDoc *pdoc=GetDocument(); UpdateData(true); //更新数据 int number=m_num-2; //在对象数组中读取数据 m_add=pdoc->student[number].add; m_age=pdoc->student[number].age; m_name=pdoc->student[number].name; m_num=pdoc->student[number].num; m_sex=pdoc->student[number].sex; m_tel=pdoc->student[number].tel; UpdateData(false); } } void CTestView::Onnext() { // TODO: Add your control notification handler code here AfxMessageBox("输入学号单击\"下一个\"按钮可以查看下一条记录"); UpdateData(true); if(m_num>=34) AfxMessageBox("没有下一个"); else { CTestDoc *pdoc=GetDocument(); //得到当前文档指针 UpdateData(true); int number=m_num; //在对象数组中读取数据 m_add=pdoc->student[number].add; m_age=pdoc->student[number].age; m_name=pdoc->student[number].name; m_num=pdoc->student[number].num; m_sex=pdoc->student[number].sex; m_tel=pdoc->student[number].tel; UpdateData(false); //数据更新 } }