东软mfc总结项目i-【学生信息管理系统】

来源:互联网 发布:全国环境监测实时数据 编辑:程序博客网 时间:2024/04/29 22:41
// DialogAdd.cpp : implementation file//#include "stdafx.h"#include "InformationProject.h"#include "DialogAdd.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CDialogAdd dialogCDialogAdd::CDialogAdd(CWnd* pParent /*=NULL*/): CDialog(CDialogAdd::IDD, pParent){//{{AFX_DATA_INIT(CDialogAdd)// NOTE: the ClassWizard will add member initialization here//}}AFX_DATA_INIT}void CDialogAdd::DoDataExchange(CDataExchange* pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CDialogAdd)DDX_Control(pDX, IDC_EDIT1, m_EditStudentID);DDX_Control(pDX, IDC_EDIT6, m_EditID);DDX_Control(pDX, IDC_EDIT5, m_EditQq);DDX_Control(pDX, IDC_EDIT4, m_EditTel);DDX_Control(pDX, IDC_EDIT3, m_EditClassNum);DDX_Control(pDX, IDC_EDIT2, m_EditName);//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CDialogAdd, CDialog)//{{AFX_MSG_MAP(CDialogAdd)//}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CDialogAdd message handlersvoid CDialogAdd::OnOK() {// TODO: Add extra validation herethis->GetDlgItemText(IDC_EDIT1, strStudentID);this->GetDlgItemText(IDC_EDIT2, strName);this->GetDlgItemText(IDC_EDIT3, strClassNum);this->GetDlgItemText(IDC_EDIT4, strTel);this->GetDlgItemText(IDC_EDIT5, strQq);this->GetDlgItemText(IDC_EDIT6, strID);CDialog::OnOK();}

 


// DialogDelete.cpp : implementation file//#include "stdafx.h"#include "InformationProject.h"#include "DialogDelete.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// DialogDelete dialogDialogDelete::DialogDelete(CWnd* pParent /*=NULL*/): CDialog(DialogDelete::IDD, pParent){//{{AFX_DATA_INIT(DialogDelete)// NOTE: the ClassWizard will add member initialization here//}}AFX_DATA_INIT}void DialogDelete::DoDataExchange(CDataExchange* pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(DialogDelete)DDX_Control(pDX, IDC_EDIT1, m_EditDelete);//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(DialogDelete, CDialog)//{{AFX_MSG_MAP(DialogDelete)//}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// DialogDelete message handlersvoid DialogDelete::OnOK() {// TODO: Add extra validation herethis->GetDlgItemText(IDC_EDIT1, strDelete);CDialog::OnOK();}

// DialogEdit.cpp : implementation file//#include "stdafx.h"#include "InformationProject.h"#include "DialogEdit.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// DialogEdit dialogDialogEdit::DialogEdit(CWnd* pParent /*=NULL*/): CDialog(DialogEdit::IDD, pParent){//{{AFX_DATA_INIT(DialogEdit)// NOTE: the ClassWizard will add member initialization here//}}AFX_DATA_INIT}void DialogEdit::DoDataExchange(CDataExchange* pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(DialogEdit)DDX_Control(pDX, IDC_EDIT1, m_EditEdit);//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(DialogEdit, CDialog)//{{AFX_MSG_MAP(DialogEdit)//}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// DialogEdit message handlersvoid DialogEdit::OnOK() {// TODO: Add extra validation herethis->GetDlgItemText(IDC_EDIT1, strEdit);CDialog::OnOK();}

// DialogFind.cpp : implementation file//#include "stdafx.h"#include "InformationProject.h"#include "DialogFind.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// DialogFind dialogDialogFind::DialogFind(CWnd* pParent /*=NULL*/): CDialog(DialogFind::IDD, pParent){//{{AFX_DATA_INIT(DialogFind)// NOTE: the ClassWizard will add member initialization here//}}AFX_DATA_INIT}void DialogFind::DoDataExchange(CDataExchange* pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(DialogFind)DDX_Control(pDX, IDC_EDIT1, m_EditFind);//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(DialogFind, CDialog)//{{AFX_MSG_MAP(DialogFind)//}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// DialogFind message handlersvoid DialogFind::OnOK() {// TODO: Add extra validation herethis->GetDlgItemText(IDC_EDIT1, strFind);CDialog::OnOK();}

// InformationProject.cpp : Defines the class behaviors for the application.//#include "stdafx.h"#include "InformationProject.h"#include "MainFrm.h"#include "InformationProjectDoc.h"#include "InformationProjectView.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CInformationProjectAppBEGIN_MESSAGE_MAP(CInformationProjectApp, CWinApp)//{{AFX_MSG_MAP(CInformationProjectApp)ON_COMMAND(ID_APP_ABOUT, OnAppAbout)// NOTE - the ClassWizard will add and remove mapping macros here.//    DO NOT EDIT what you see in these blocks of generated code!//}}AFX_MSG_MAP// Standard file based document commandsON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)// Standard print setup commandON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CInformationProjectApp constructionCInformationProjectApp::CInformationProjectApp(){// TODO: add construction code here,// Place all significant initialization in InitInstance}/////////////////////////////////////////////////////////////////////////////// The one and only CInformationProjectApp objectCInformationProjectApp theApp;/////////////////////////////////////////////////////////////////////////////// CInformationProjectApp initializationBOOL CInformationProjectApp::InitInstance(){AfxEnableControlContainer();// Standard initialization// If you are not using these features and wish to reduce the size//  of your final executable, you should remove from the following//  the specific initialization routines you do not need.#ifdef _AFXDLLEnable3dControls();// Call this when using MFC in a shared DLL#elseEnable3dControlsStatic();// Call this when linking to MFC statically#endif// Change the registry key under which our settings are stored.// TODO: You should modify this string to be something appropriate// such as the name of your company or organization.SetRegistryKey(_T("Local AppWizard-Generated Applications"));LoadStdProfileSettings();  // Load standard INI file options (including MRU)// Register the application's document templates.  Document templates//  serve as the connection between documents, frame windows and views.CSingleDocTemplate* pDocTemplate;pDocTemplate = new CSingleDocTemplate(IDR_MAINFRAME,RUNTIME_CLASS(CInformationProjectDoc),RUNTIME_CLASS(CMainFrame),       // main SDI frame windowRUNTIME_CLASS(CInformationProjectView));AddDocTemplate(pDocTemplate);// Parse command line for standard shell commands, DDE, file openCCommandLineInfo cmdInfo;ParseCommandLine(cmdInfo);// Dispatch commands specified on the command lineif (!ProcessShellCommand(cmdInfo))return FALSE;// The one and only window has been initialized, so show and update it.m_pMainWnd->ShowWindow(SW_SHOW);m_pMainWnd->UpdateWindow();return TRUE;}/////////////////////////////////////////////////////////////////////////////// CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog{public:CAboutDlg();// Dialog Data//{{AFX_DATA(CAboutDlg)enum { IDD = IDD_ABOUTBOX };//}}AFX_DATA// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(CAboutDlg)protected:virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support//}}AFX_VIRTUAL// Implementationprotected://{{AFX_MSG(CAboutDlg)// No message handlers//}}AFX_MSGDECLARE_MESSAGE_MAP()};CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD){//{{AFX_DATA_INIT(CAboutDlg)//}}AFX_DATA_INIT}void CAboutDlg::DoDataExchange(CDataExchange* pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CAboutDlg)//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)//{{AFX_MSG_MAP(CAboutDlg)// No message handlers//}}AFX_MSG_MAPEND_MESSAGE_MAP()// App command to run the dialogvoid CInformationProjectApp::OnAppAbout(){CAboutDlg aboutDlg;aboutDlg.DoModal();}/////////////////////////////////////////////////////////////////////////////// CInformationProjectApp message handlers

// InformationProjectDoc.cpp : implementation of the CInformationProjectDoc class//#include "stdafx.h"#include "InformationProject.h"#include "InformationProjectDoc.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CInformationProjectDocIMPLEMENT_DYNCREATE(CInformationProjectDoc, CDocument)BEGIN_MESSAGE_MAP(CInformationProjectDoc, CDocument)//{{AFX_MSG_MAP(CInformationProjectDoc)// NOTE - the ClassWizard will add and remove mapping macros here.//    DO NOT EDIT what you see in these blocks of generated code!//}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CInformationProjectDoc construction/destructionCInformationProjectDoc::CInformationProjectDoc(){// TODO: add one-time construction code here}CInformationProjectDoc::~CInformationProjectDoc(){}BOOL CInformationProjectDoc::OnNewDocument(){if (!CDocument::OnNewDocument())return FALSE;// TODO: add reinitialization code here// (SDI documents will reuse this document)return TRUE;}/////////////////////////////////////////////////////////////////////////////// CInformationProjectDoc serializationvoid CInformationProjectDoc::Serialize(CArchive& ar){if (ar.IsStoring()){// TODO: add storing code here}else{// TODO: add loading code here}}/////////////////////////////////////////////////////////////////////////////// CInformationProjectDoc diagnostics#ifdef _DEBUGvoid CInformationProjectDoc::AssertValid() const{CDocument::AssertValid();}void CInformationProjectDoc::Dump(CDumpContext& dc) const{CDocument::Dump(dc);}#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////// CInformationProjectDoc commands

// InformationProjectView.cpp : implementation of the CInformationProjectView class//#include "stdafx.h"#include "InformationProject.h"#include "InformationProjectDoc.h"#include "InformationProjectView.h"#include "DialogAdd.h"#include "DialogFind.h"#include "DialogDelete.h"#include "DialogEdit.h"#include "InformationRecordSet.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CInformationProjectViewIMPLEMENT_DYNCREATE(CInformationProjectView, CView)BEGIN_MESSAGE_MAP(CInformationProjectView, CView)//{{AFX_MSG_MAP(CInformationProjectView)ON_COMMAND(ID_ADD, OnAdd)ON_COMMAND(ID_FIND, OnFind)ON_COMMAND(ID_DELETE, OnDelete)ON_COMMAND(ID_EDIT, OnEdit)//}}AFX_MSG_MAP// Standard printing commandsON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CInformationProjectView construction/destructionCInformationProjectView::CInformationProjectView():y(20),str("0000"),isFind(false),isDelete(false){// TODO: add construction code here}CInformationProjectView::~CInformationProjectView(){}BOOL CInformationProjectView::PreCreateWindow(CREATESTRUCT& cs){// TODO: Modify the Window class or styles here by modifying//  the CREATESTRUCT csreturn CView::PreCreateWindow(cs);}/////////////////////////////////////////////////////////////////////////////// CInformationProjectView drawingvoid CInformationProjectView::OnDraw(CDC* pDC){CInformationProjectDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);// TODO: add draw code for native data herepDC->TextOut(20, y, str);}/////////////////////////////////////////////////////////////////////////////// CInformationProjectView printingBOOL CInformationProjectView::OnPreparePrinting(CPrintInfo* pInfo){// default preparationreturn DoPreparePrinting(pInfo);}void CInformationProjectView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/){// TODO: add extra initialization before printing}void CInformationProjectView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/){// TODO: add cleanup after printing}/////////////////////////////////////////////////////////////////////////////// CInformationProjectView diagnostics#ifdef _DEBUGvoid CInformationProjectView::AssertValid() const{CView::AssertValid();}void CInformationProjectView::Dump(CDumpContext& dc) const{CView::Dump(dc);}CInformationProjectDoc* CInformationProjectView::GetDocument() // non-debug version is inline{ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CInformationProjectDoc)));return (CInformationProjectDoc*)m_pDocument;}#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////// CInformationProjectView message handlersvoid CInformationProjectView::OnAdd() {// TODO: Add your command handler code hereCDialogAdd add;InformationRecordSet rs;if (add.DoModal() == IDOK){//存放到类成员变量中strStudentID = add.strStudentID;strName = add.strName;strClassNum = add.strClassNum;strTel = add.strTel;strQq = add.strQq;strID = add.strID;//对数据库进行写入rs.Open();rs.AddNew();rs.m_StudentID = strStudentID;rs.m_Name = strName;rs.m_ClassNum = strClassNum;rs.m_Tel = strTel;rs.m_Qq = strQq;rs.m_ID = strID;rs.Update();rs.Close();MessageBox("添加成功!", "添加");}}void CInformationProjectView::OnFind() {// TODO: Add your command handler code hereDialogFind find;InformationRecordSet rs;strFind = _T("");if (find.DoModal() == IDOK){strFind = find.strFind;strFind.Format("StudentID='%s'", strFind);//小技巧isFind = true;}//查找符合条件的记录if (isFind){rs.m_strFilter=strFind;rs.Open();while (!rs.IsEOF()){strStudentID = rs.m_StudentID;strName = rs.m_Name;strClassNum = rs.m_ClassNum;strTel = rs.m_Tel;strQq = rs.m_Qq;strID = rs.m_ID;str = "学号:" + strStudentID + ",姓名:" + strName + ",班级:" + strClassNum + ",手机:" + strTel + ",QQ:" + strQq + ",身份证:" + strID + "。";rs.MoveNext();}if (str == "0000"){MessageBox("没有该记录!","查找");}Invalidate();//刷新一下才显示rs.Close();}}void CInformationProjectView::OnDelete() {// TODO: Add your command handler code hereDialogDelete Ddelete;InformationRecordSet rs;CClientDC dc(this);strDelete = _T("");if (Ddelete.DoModal() == IDOK){strDelete = Ddelete.strDelete;strDelete.Format("StudentID='%s'", strDelete);//小技巧//查找符合条件的记录rs.m_strFilter=strDelete;rs.Open();while (!rs.IsEOF()){/*strStudentID = rs.m_StudentID;strName = rs.m_Name;strClassNum = rs.m_ClassNum;strTel = rs.m_Tel;strQq = rs.m_Qq;strID = rs.m_ID;str = "学号:" + strStudentID + ",姓名:" + strName + ",班级:" + strClassNum + ",手机:" + strTel + ",QQ:" + strQq + ",身份证:" + strID + "。";*/rs.Delete();rs.MoveNext();MessageBox("删除成功!","删除");isDelete = true;}if (isDelete == false){MessageBox("没有该记录!","删除");}rs.Close();}}void CInformationProjectView::OnEdit() {// TODO: Add your command handler code hereDialogEdit edit;InformationRecordSet rs;strEdit = _T("");if (edit.DoModal() == IDOK){strEdit = edit.strEdit;strEdit.Format("StudentID='%s'", strEdit);//小技巧//查找符合条件的记录rs.m_strFilter=strEdit;rs.Open();CDialogAdd add;add.DoModal();rs.Edit();//存放到类成员变量中strStudentID = add.strStudentID;strName = add.strName;strClassNum = add.strClassNum;strTel = add.strTel;strQq = add.strQq;strID = add.strID;//对数据库进行写入rs.m_StudentID = strStudentID;rs.m_Name = strName;rs.m_ClassNum = strClassNum;rs.m_Tel = strTel;rs.m_Qq = strQq;rs.m_ID = strID;rs.Update();MessageBox("修改成功!","修改");Invalidate();//刷新一下才显示rs.Close();}}

// InformationRecordSet.cpp : implementation file//#include "stdafx.h"#include "InformationProject.h"#include "InformationRecordSet.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// InformationRecordSetIMPLEMENT_DYNAMIC(InformationRecordSet, CRecordset)InformationRecordSet::InformationRecordSet(CDatabase* pdb): CRecordset(pdb){//{{AFX_FIELD_INIT(InformationRecordSet)m_StudentID = _T("");m_Name = _T("");m_ClassNum = _T("");m_Tel = _T("");m_Qq = _T("");m_ID = _T("");m_nFields = 6;//}}AFX_FIELD_INITm_nDefaultType = dynaset;}CString InformationRecordSet::GetDefaultConnect(){return _T("ODBC;DSN=MyInformation");}CString InformationRecordSet::GetDefaultSQL(){return _T("[InformationTable]");}void InformationRecordSet::DoFieldExchange(CFieldExchange* pFX){//{{AFX_FIELD_MAP(InformationRecordSet)pFX->SetFieldType(CFieldExchange::outputColumn);RFX_Text(pFX, _T("[StudentID]"), m_StudentID);RFX_Text(pFX, _T("[Name]"), m_Name);RFX_Text(pFX, _T("[ClassNum]"), m_ClassNum);RFX_Text(pFX, _T("[Tel]"), m_Tel);RFX_Text(pFX, _T("[Qq]"), m_Qq);RFX_Text(pFX, _T("[ID]"), m_ID);//}}AFX_FIELD_MAP}/////////////////////////////////////////////////////////////////////////////// InformationRecordSet diagnostics#ifdef _DEBUGvoid InformationRecordSet::AssertValid() const{CRecordset::AssertValid();}void InformationRecordSet::Dump(CDumpContext& dc) const{CRecordset::Dump(dc);}#endif //_DEBUG

// MainFrm.cpp : implementation of the CMainFrame class//#include "stdafx.h"#include "InformationProject.h"#include "MainFrm.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CMainFrameIMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)//{{AFX_MSG_MAP(CMainFrame)// NOTE - the ClassWizard will add and remove mapping macros here.//    DO NOT EDIT what you see in these blocks of generated code !ON_WM_CREATE()//}}AFX_MSG_MAPEND_MESSAGE_MAP()static UINT indicators[] ={ID_SEPARATOR,           // status line indicatorID_INDICATOR_CAPS,ID_INDICATOR_NUM,ID_INDICATOR_SCRL,};/////////////////////////////////////////////////////////////////////////////// CMainFrame construction/destructionCMainFrame::CMainFrame(){// TODO: add member initialization code here}CMainFrame::~CMainFrame(){}int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct){if (CFrameWnd::OnCreate(lpCreateStruct) == -1)return -1;/*if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||!m_wndToolBar.LoadToolBar(IDR_MAINFRAME)){TRACE0("Failed to create toolbar\n");return -1;      // fail to create}if (!m_wndStatusBar.Create(this) ||!m_wndStatusBar.SetIndicators(indicators,  sizeof(indicators)/sizeof(UINT))){TRACE0("Failed to create status bar\n");return -1;      // fail to create}// TODO: Delete these three lines if you don't want the toolbar to//  be dockablem_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);EnableDocking(CBRS_ALIGN_ANY);DockControlBar(&m_wndToolBar);*/return 0;}BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs){if( !CFrameWnd::PreCreateWindow(cs) )return FALSE;// TODO: Modify the Window class or styles here by modifying//  the CREATESTRUCT csreturn TRUE;}/////////////////////////////////////////////////////////////////////////////// CMainFrame diagnostics#ifdef _DEBUGvoid CMainFrame::AssertValid() const{CFrameWnd::AssertValid();}void CMainFrame::Dump(CDumpContext& dc) const{CFrameWnd::Dump(dc);}#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////// CMainFrame message handlers

#if !defined(AFX_DIALOGADD_H__6090309F_F551_4A7F_8360_864745D7ED61__INCLUDED_)#define AFX_DIALOGADD_H__6090309F_F551_4A7F_8360_864745D7ED61__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000// DialogAdd.h : header file///////////////////////////////////////////////////////////////////////////////// CDialogAdd dialogclass CDialogAdd : public CDialog{// Constructionpublic:CDialogAdd(CWnd* pParent = NULL);   // standard constructorCString strStudentID;CString strName;CString strClassNum;CString strTel;CString strQq;CString strID;// Dialog Data//{{AFX_DATA(CDialogAdd)enum { IDD = IDD_DIALOG_ADD };CEditm_EditStudentID;CEditm_EditID;CEditm_EditQq;CEditm_EditTel;CEditm_EditClassNum;CEditm_EditName;//}}AFX_DATA// Overrides// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(CDialogAdd)protected:virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support//}}AFX_VIRTUAL// Implementationprotected:// Generated message map functions//{{AFX_MSG(CDialogAdd)virtual void OnOK();//}}AFX_MSGDECLARE_MESSAGE_MAP()};//{{AFX_INSERT_LOCATION}}// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_DIALOGADD_H__6090309F_F551_4A7F_8360_864745D7ED61__INCLUDED_)

#if !defined(AFX_DIALOGDELETE_H__15A1212A_8AC8_4E3F_8B70_67C471234FF0__INCLUDED_)#define AFX_DIALOGDELETE_H__15A1212A_8AC8_4E3F_8B70_67C471234FF0__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000// DialogDelete.h : header file///////////////////////////////////////////////////////////////////////////////// DialogDelete dialogclass DialogDelete : public CDialog{// Constructionpublic:DialogDelete(CWnd* pParent = NULL);   // standard constructorCString strDelete;// Dialog Data//{{AFX_DATA(DialogDelete)enum { IDD = IDD_DIALOG_DELETE };CEditm_EditDelete;//}}AFX_DATA// Overrides// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(DialogDelete)protected:virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support//}}AFX_VIRTUAL// Implementationprotected:// Generated message map functions//{{AFX_MSG(DialogDelete)virtual void OnOK();//}}AFX_MSGDECLARE_MESSAGE_MAP()};//{{AFX_INSERT_LOCATION}}// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_DIALOGDELETE_H__15A1212A_8AC8_4E3F_8B70_67C471234FF0__INCLUDED_)

#if !defined(AFX_DIALOGEDIT_H__03586D1E_15A0_4FB3_B15B_1A673C34C55F__INCLUDED_)#define AFX_DIALOGEDIT_H__03586D1E_15A0_4FB3_B15B_1A673C34C55F__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000// DialogEdit.h : header file///////////////////////////////////////////////////////////////////////////////// DialogEdit dialogclass DialogEdit : public CDialog{// Constructionpublic:DialogEdit(CWnd* pParent = NULL);   // standard constructorCString strEdit;// Dialog Data//{{AFX_DATA(DialogEdit)enum { IDD = IDD_DIALOG_EDIT };CEditm_EditEdit;//}}AFX_DATA// Overrides// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(DialogEdit)protected:virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support//}}AFX_VIRTUAL// Implementationprotected:// Generated message map functions//{{AFX_MSG(DialogEdit)virtual void OnOK();//}}AFX_MSGDECLARE_MESSAGE_MAP()};//{{AFX_INSERT_LOCATION}}// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_DIALOGEDIT_H__03586D1E_15A0_4FB3_B15B_1A673C34C55F__INCLUDED_)

#if !defined(AFX_DIALOGFIND_H__3C996D18_0133_48FF_ADFC_D14344FBE500__INCLUDED_)#define AFX_DIALOGFIND_H__3C996D18_0133_48FF_ADFC_D14344FBE500__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000// DialogFind.h : header file///////////////////////////////////////////////////////////////////////////////// DialogFind dialogclass DialogFind : public CDialog{// Constructionpublic:DialogFind(CWnd* pParent = NULL);   // standard constructorCString strFind;// Dialog Data//{{AFX_DATA(DialogFind)enum { IDD = IDD_DIALOG_FIND };CEditm_EditFind;//}}AFX_DATA// Overrides// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(DialogFind)protected:virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support//}}AFX_VIRTUAL// Implementationprotected:// Generated message map functions//{{AFX_MSG(DialogFind)virtual void OnOK();//}}AFX_MSGDECLARE_MESSAGE_MAP()};//{{AFX_INSERT_LOCATION}}// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_DIALOGFIND_H__3C996D18_0133_48FF_ADFC_D14344FBE500__INCLUDED_)

// InformationProject.h : main header file for the INFORMATIONPROJECT application//#if !defined(AFX_INFORMATIONPROJECT_H__D2526321_80AB_412F_B931_0DA5D4AA40CB__INCLUDED_)#define AFX_INFORMATIONPROJECT_H__D2526321_80AB_412F_B931_0DA5D4AA40CB__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000#ifndef __AFXWIN_H__#error include 'stdafx.h' before including this file for PCH#endif#include "resource.h"       // main symbols/////////////////////////////////////////////////////////////////////////////// CInformationProjectApp:// See InformationProject.cpp for the implementation of this class//class CInformationProjectApp : public CWinApp{public:CInformationProjectApp();// Overrides// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(CInformationProjectApp)public:virtual BOOL InitInstance();//}}AFX_VIRTUAL// Implementation//{{AFX_MSG(CInformationProjectApp)afx_msg void OnAppAbout();// NOTE - the ClassWizard will add and remove member functions here.//    DO NOT EDIT what you see in these blocks of generated code !//}}AFX_MSGDECLARE_MESSAGE_MAP()};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_INFORMATIONPROJECT_H__D2526321_80AB_412F_B931_0DA5D4AA40CB__INCLUDED_)

// InformationProjectDoc.h : interface of the CInformationProjectDoc class///////////////////////////////////////////////////////////////////////////////#if !defined(AFX_INFORMATIONPROJECTDOC_H__B3B9F6E7_4CD0_42F8_BAF6_4CF6339E33CD__INCLUDED_)#define AFX_INFORMATIONPROJECTDOC_H__B3B9F6E7_4CD0_42F8_BAF6_4CF6339E33CD__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000class CInformationProjectDoc : public CDocument{protected: // create from serialization onlyCInformationProjectDoc();DECLARE_DYNCREATE(CInformationProjectDoc)// Attributespublic:// Operationspublic:// Overrides// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(CInformationProjectDoc)public:virtual BOOL OnNewDocument();virtual void Serialize(CArchive& ar);//}}AFX_VIRTUAL// Implementationpublic:virtual ~CInformationProjectDoc();#ifdef _DEBUGvirtual void AssertValid() const;virtual void Dump(CDumpContext& dc) const;#endifprotected:// Generated message map functionsprotected://{{AFX_MSG(CInformationProjectDoc)// NOTE - the ClassWizard will add and remove member functions here.//    DO NOT EDIT what you see in these blocks of generated code !//}}AFX_MSGDECLARE_MESSAGE_MAP()};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_INFORMATIONPROJECTDOC_H__B3B9F6E7_4CD0_42F8_BAF6_4CF6339E33CD__INCLUDED_)

// InformationProjectView.h : interface of the CInformationProjectView class///////////////////////////////////////////////////////////////////////////////#if !defined(AFX_INFORMATIONPROJECTVIEW_H__D7A72F51_3587_4A4D_B1FD_260E314D6610__INCLUDED_)#define AFX_INFORMATIONPROJECTVIEW_H__D7A72F51_3587_4A4D_B1FD_260E314D6610__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000class CInformationProjectView : public CView{protected: // create from serialization onlyCInformationProjectView();DECLARE_DYNCREATE(CInformationProjectView)// Attributespublic:CInformationProjectDoc* GetDocument();// Operationspublic:int y;CString str;bool isFind;bool isDelete;CString strStudentID;CString strName;CString strClassNum;CString strTel;CString strQq;CString strID;CString strFind;CString strDelete;CString strEdit;// Overrides// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(CInformationProjectView)public:virtual void OnDraw(CDC* pDC);  // overridden to draw this viewvirtual BOOL PreCreateWindow(CREATESTRUCT& cs);protected:virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);//}}AFX_VIRTUAL// Implementationpublic:virtual ~CInformationProjectView();#ifdef _DEBUGvirtual void AssertValid() const;virtual void Dump(CDumpContext& dc) const;#endifprotected:// Generated message map functionsprotected://{{AFX_MSG(CInformationProjectView)afx_msg void OnAdd();afx_msg void OnFind();afx_msg void OnDelete();afx_msg void OnEdit();//}}AFX_MSGDECLARE_MESSAGE_MAP()};#ifndef _DEBUG  // debug version in InformationProjectView.cppinline CInformationProjectDoc* CInformationProjectView::GetDocument()   { return (CInformationProjectDoc*)m_pDocument; }#endif///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_INFORMATIONPROJECTVIEW_H__D7A72F51_3587_4A4D_B1FD_260E314D6610__INCLUDED_)

#if !defined(AFX_INFORMATIONRECORDSET_H__B2ECF318_E73E_497F_B5C1_F8411786BFE7__INCLUDED_)#define AFX_INFORMATIONRECORDSET_H__B2ECF318_E73E_497F_B5C1_F8411786BFE7__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000// InformationRecordSet.h : header file//#include <afxdb.h>/////////////////////////////////////////////////////////////////////////////// InformationRecordSet recordsetclass InformationRecordSet : public CRecordset{public:InformationRecordSet(CDatabase* pDatabase = NULL);DECLARE_DYNAMIC(InformationRecordSet)// Field/Param Data//{{AFX_FIELD(InformationRecordSet, CRecordset)CStringm_StudentID;CStringm_Name;CStringm_ClassNum;CStringm_Tel;CStringm_Qq;CStringm_ID;//}}AFX_FIELD// Overrides// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(InformationRecordSet)public:virtual CString GetDefaultConnect();    // Default connection stringvirtual CString GetDefaultSQL();    // Default SQL for Recordsetvirtual void DoFieldExchange(CFieldExchange* pFX);  // RFX support//}}AFX_VIRTUAL// Implementation#ifdef _DEBUGvirtual void AssertValid() const;virtual void Dump(CDumpContext& dc) const;#endif};//{{AFX_INSERT_LOCATION}}// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_INFORMATIONRECORDSET_H__B2ECF318_E73E_497F_B5C1_F8411786BFE7__INCLUDED_)

// MainFrm.h : interface of the CMainFrame class///////////////////////////////////////////////////////////////////////////////#if !defined(AFX_MAINFRM_H__FB24BCD3_F334_46AE_8A92_45C8EA9A22E3__INCLUDED_)#define AFX_MAINFRM_H__FB24BCD3_F334_46AE_8A92_45C8EA9A22E3__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000class CMainFrame : public CFrameWnd{protected: // create from serialization onlyCMainFrame();DECLARE_DYNCREATE(CMainFrame)// Attributespublic:// Operationspublic:// Overrides// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(CMainFrame)virtual BOOL PreCreateWindow(CREATESTRUCT& cs);//}}AFX_VIRTUAL// Implementationpublic:virtual ~CMainFrame();#ifdef _DEBUGvirtual void AssertValid() const;virtual void Dump(CDumpContext& dc) const;#endifprotected:  // control bar embedded membersCStatusBar  m_wndStatusBar;CToolBar    m_wndToolBar;// Generated message map functionsprotected://{{AFX_MSG(CMainFrame)afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);// NOTE - the ClassWizard will add and remove member functions here.//    DO NOT EDIT what you see in these blocks of generated code!//}}AFX_MSGDECLARE_MESSAGE_MAP()};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_MAINFRM_H__FB24BCD3_F334_46AE_8A92_45C8EA9A22E3__INCLUDED_)

//{{NO_DEPENDENCIES}}// Microsoft Developer Studio generated include file.// Used by InformationProject.rc//#define IDD_ABOUTBOX                    100#define IDR_MAINFRAME                   128#define IDR_INFORMTYPE                  129#define IDD_DIALOG_ADD                  130#define IDD_DIALOG_FIND                 131#define IDD_DIALOG_DELETE               132#define IDD_DIALOG_EDIT                 133#define IDC_EDIT1                       1000#define IDC_EDIT2                       1001#define IDC_EDIT3                       1002#define IDC_EDIT4                       1003#define IDC_EDIT5                       1004#define IDC_EDIT6                       1005#define ID_ADD                          32771#define ID_FIND                         32772#define ID_DELETE                       32773#define ID_EDIT                         32774// Next default values for new objects// #ifdef APSTUDIO_INVOKED#ifndef APSTUDIO_READONLY_SYMBOLS#define _APS_3D_CONTROLS                     1#define _APS_NEXT_RESOURCE_VALUE        132#define _APS_NEXT_COMMAND_VALUE         32775#define _APS_NEXT_CONTROL_VALUE         1001#define _APS_NEXT_SYMED_VALUE           101#endif#endif


更改后的view.cpp:功能显示当前数据库记录个数

// InformationProjectView.cpp : implementation of the CInformationProjectView class//#include "stdafx.h"#include "InformationProject.h"#include "InformationProjectDoc.h"#include "InformationProjectView.h"#include "DialogAdd.h"#include "DialogFind.h"#include "DialogDelete.h"#include "DialogEdit.h"#include "InformationRecordSet.h"#define WM_NC 1001   // 托盘区触发的自定义消息#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CInformationProjectViewIMPLEMENT_DYNCREATE(CInformationProjectView, CView)BEGIN_MESSAGE_MAP(CInformationProjectView, CView)//{{AFX_MSG_MAP(CInformationProjectView)ON_COMMAND(ID_ADD, OnAdd)ON_COMMAND(ID_FIND, OnFind)ON_COMMAND(ID_DELETE, OnDelete)ON_COMMAND(ID_EDIT, OnEdit)//}}AFX_MSG_MAP// Standard printing commandsON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CInformationProjectView construction/destructionCInformationProjectView::CInformationProjectView():y(20),str("0000"),isFind(false),isDelete(false){// TODO: add construction code here}CInformationProjectView::~CInformationProjectView(){}BOOL CInformationProjectView::PreCreateWindow(CREATESTRUCT& cs){// TODO: Modify the Window class or styles here by modifying//  the CREATESTRUCT cs    return CView::PreCreateWindow(cs);}/////////////////////////////////////////////////////////////////////////////// CInformationProjectView drawingvoid CInformationProjectView::OnDraw(CDC* pDC){CInformationProjectDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);// TODO: add draw code for native data hereInformationRecordSet rs;CRect rect;this->GetWindowRect(&rect);int x;x = rect.Height() - 30;rs.Open();while(!rs.IsEOF()){rs.MoveNext();}int count = rs.GetRecordCount();CString strCount;strCount.Format("当前共有%d条学生信息。", count);pDC->TextOut(20, y, str);pDC->TextOut(20,x, strCount);}/////////////////////////////////////////////////////////////////////////////// CInformationProjectView printingBOOL CInformationProjectView::OnPreparePrinting(CPrintInfo* pInfo){// default preparationreturn DoPreparePrinting(pInfo);}void CInformationProjectView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/){// TODO: add extra initialization before printing}void CInformationProjectView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/){// TODO: add cleanup after printing}/////////////////////////////////////////////////////////////////////////////// CInformationProjectView diagnostics#ifdef _DEBUGvoid CInformationProjectView::AssertValid() const{CView::AssertValid();}void CInformationProjectView::Dump(CDumpContext& dc) const{CView::Dump(dc);}CInformationProjectDoc* CInformationProjectView::GetDocument() // non-debug version is inline{ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CInformationProjectDoc)));return (CInformationProjectDoc*)m_pDocument;}#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////// CInformationProjectView message handlersvoid CInformationProjectView::OnAdd() {// TODO: Add your command handler code hereCDialogAdd add;InformationRecordSet rs;if (add.DoModal() == IDOK){//存放到类成员变量中strStudentID = add.strStudentID;strName = add.strName;strClassNum = add.strClassNum;strTel = add.strTel;strQq = add.strQq;strID = add.strID;//对数据库进行写入rs.Open();rs.AddNew();rs.m_StudentID = strStudentID;rs.m_Name = strName;rs.m_ClassNum = strClassNum;rs.m_Tel = strTel;rs.m_Qq = strQq;rs.m_ID = strID;rs.Update();rs.Close();MessageBox("添加成功!", "添加");}Invalidate();}void CInformationProjectView::OnFind() {// TODO: Add your command handler code hereDialogFind find;InformationRecordSet rs;strFind = _T("");if (find.DoModal() == IDOK){strFind = find.strFind;strFind.Format("StudentID='%s'", strFind);//小技巧isFind = true;}//查找符合条件的记录if (isFind){rs.m_strFilter=strFind;rs.Open();while (!rs.IsEOF()){strStudentID = rs.m_StudentID;strName = rs.m_Name;strClassNum = rs.m_ClassNum;strTel = rs.m_Tel;strQq = rs.m_Qq;strID = rs.m_ID;str = "学号:" + strStudentID + ",姓名:" + strName + ",班级:" + strClassNum + ",手机:" + strTel + ",QQ:" + strQq + ",身份证:" + strID + "。";rs.MoveNext();}if (str == "0000"){MessageBox("没有该记录!","查找");}Invalidate();//刷新一下才显示rs.Close();}}void CInformationProjectView::OnDelete() {// TODO: Add your command handler code hereDialogDelete Ddelete;InformationRecordSet rs;CClientDC dc(this);strDelete = _T("");if (Ddelete.DoModal() == IDOK){strDelete = Ddelete.strDelete;strDelete.Format("StudentID='%s'", strDelete);//小技巧//查找符合条件的记录rs.m_strFilter=strDelete;rs.Open();while (!rs.IsEOF()){/*strStudentID = rs.m_StudentID;strName = rs.m_Name;strClassNum = rs.m_ClassNum;strTel = rs.m_Tel;strQq = rs.m_Qq;strID = rs.m_ID;str = "学号:" + strStudentID + ",姓名:" + strName + ",班级:" + strClassNum + ",手机:" + strTel + ",QQ:" + strQq + ",身份证:" + strID + "。";*/rs.Delete();rs.MoveNext();MessageBox("删除成功!","删除");isDelete = true;}if (isDelete == false){MessageBox("没有该记录!","删除");}rs.Close();}Invalidate();}void CInformationProjectView::OnEdit() {// TODO: Add your command handler code hereDialogEdit edit;InformationRecordSet rs;strEdit = _T("");if (edit.DoModal() == IDOK){strEdit = edit.strEdit;strEdit.Format("StudentID='%s'", strEdit);//小技巧//查找符合条件的记录rs.m_strFilter=strEdit;rs.Open();CDialogAdd add;add.DoModal();rs.Edit();//存放到类成员变量中strStudentID = add.strStudentID;strName = add.strName;strClassNum = add.strClassNum;strTel = add.strTel;strQq = add.strQq;strID = add.strID;//对数据库进行写入rs.m_StudentID = strStudentID;rs.m_Name = strName;rs.m_ClassNum = strClassNum;rs.m_Tel = strTel;rs.m_Qq = strQq;rs.m_ID = strID;rs.Update();MessageBox("修改成功!","修改");Invalidate();//刷新一下才显示rs.Close();}}


 

原创粉丝点击