studentView.cpp
资源名称:一个学生管理系统.rar [点击查看]
上传用户:hzzhuce
上传日期:2013-04-01
资源大小:1289k
文件大小:8k
源码类别:
SQL Server
开发平台:
Visual C++
- // studentView.cpp : implementation of the CStudentView class
- //
- #include "stdafx.h"
- #include "student.h"
- #include"Select.h"
- #include "studentSet.h"
- #include "studentDoc.h"
- #include "studentView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CStudentView
- IMPLEMENT_DYNCREATE(CStudentView, CRecordView)
- BEGIN_MESSAGE_MAP(CStudentView, CRecordView)
- //{{AFX_MSG_MAP(CStudentView)
- ON_BN_CLICKED(IDC_SHOW_BUTTON, OnShowButton)
- ON_BN_CLICKED(IDC_ADD_BUTTON2, OnAddButton2)
- ON_BN_CLICKED(IDC_DELETE_BUTTON, OnDeleteButton)
- ON_BN_CLICKED(IDC_MODIFY_BUTTON, OnModifyButton)
- ON_BN_CLICKED(IDC_QUERY_BUTTON, OnQueryButton)
- ON_BN_CLICKED(IDC_SORT_BUTTON, OnSortButton)
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CRecordView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CRecordView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRecordView::OnFilePrintPreview)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CStudentView construction/destruction
- CStudentView::CStudentView()
- : CRecordView(CStudentView::IDD)
- {
- //{{AFX_DATA_INIT(CStudentView)
- // NOTE: the ClassWizard will add member initialization here
- m_pSet = NULL;
- //}}AFX_DATA_INIT
- // TODO: add construction code here
- }
- CStudentView::~CStudentView()
- {
- }
- void CStudentView::DoDataExchange(CDataExchange* pDX)
- {
- CRecordView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CStudentView)
- DDX_Control(pDX, IDC_RECORD_LIST, m_Record_List);
- //}}AFX_DATA_MAP
- }
- BOOL CStudentView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CRecordView::PreCreateWindow(cs);
- }
- void CStudentView::OnInitialUpdate()
- {
- m_pSet = &GetDocument()->m_studentSet;
- CRecordView::OnInitialUpdate();
- GetParentFrame()->RecalcLayout();
- ResizeParentToFit();
- m_Record_List.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
- LV_COLUMN h;
- h.mask=LVCF_FMT|LVCF_TEXT|LVCF_WIDTH;
- h.fmt=LVCFMT_CENTER;
- h.cx=90;
- h.pszText="学号";
- m_Record_List.InsertColumn(0,&h);
- h.pszText="姓名";
- m_Record_List.InsertColumn(1,&h);
- h.pszText="数学";
- m_Record_List.InsertColumn(2,&h);
- h.pszText="语文";
- m_Record_List.InsertColumn(3,&h);
- h.pszText="英语";
- m_Record_List.InsertColumn(4,&h);
- OnShowButton();
- }
- /////////////////////////////////////////////////////////////////////////////
- // CStudentView printing
- BOOL CStudentView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CStudentView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CStudentView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CStudentView diagnostics
- #ifdef _DEBUG
- void CStudentView::AssertValid() const
- {
- CRecordView::AssertValid();
- }
- void CStudentView::Dump(CDumpContext& dc) const
- {
- CRecordView::Dump(dc);
- }
- CStudentDoc* CStudentView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CStudentDoc)));
- return (CStudentDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CStudentView database support
- CRecordset* CStudentView::OnGetRecordset()
- {
- return m_pSet;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CStudentView message handlers
- void CStudentView::OnShowButton()
- {
- // TODO: Add your control notification handler code here
- m_Record_List.DeleteAllItems();
- CString s;
- i=0;
- m_pSet->MoveFirst();
- while(!m_pSet->IsEOF())
- {
- s.Format("%d",m_pSet->m_column1);
- m_Record_List.InsertItem(i,s);
- m_Record_List.SetItemText(i,1,m_pSet->m_column2);
- s.Format("%d",m_pSet->m_column3);
- m_Record_List.SetItemText(i,2,s);
- s.Format("%d",m_pSet->m_column4);
- m_Record_List.SetItemText(i,3,s);
- s.Format("%d",m_pSet->m_column5);
- m_Record_List.SetItemText(i,4,s);
- m_pSet->MoveNext();
- i++;
- }
- }
- void CStudentView::OnAddButton2()
- {
- // TODO: Add your control notification handler code here
- CAdddlg dlg;
- CString s;
- if(dlg.DoModal()==IDOK)
- {
- m_pSet->AddNew();
- m_pSet->m_column1=atol(dlg.m_num);
- m_pSet->m_column2=dlg.m_name;
- m_pSet->m_column3=atol(dlg.m_math);
- m_pSet->m_column4=atol(dlg.m_chi);
- m_pSet->m_column5=atol(dlg.m_eng);
- s.Format("%d",m_pSet->m_column1);
- m_Record_List.InsertItem(i,s);
- m_Record_List.SetItemText(i,1,m_pSet->m_column2);
- s.Format("%d",m_pSet->m_column3);
- m_Record_List.SetItemText(i,2,s);
- s.Format("%d",m_pSet->m_column4);
- m_Record_List.SetItemText(i,3,s);
- s.Format("%d",m_pSet->m_column5);
- m_Record_List.SetItemText(i,4,s);
- m_pSet->Update();
- i++;
- }
- }
- void CStudentView::OnDeleteButton()
- {
- // TODO: Add your control notification handler code here
- CString s;
- m_pSet->MoveFirst();
- int index=m_Record_List.GetNextItem(-1,LVNI_SELECTED);
- if(index!=-1)
- {
- while(!m_pSet->IsEOF())
- {
- s.Format("%ld",m_pSet->m_column1);
- if(s==m_Record_List.GetItemText(index,0))
- {
- m_pSet->Delete();
- i--;
- }
- m_pSet->MoveNext();
- }
- MessageBox("记录已经删除!");
- m_Record_List.DeleteItem(index);
- }
- else
- MessageBox("请选中删除记录!");
- }
- void CStudentView::OnModifyButton()
- {
- // TODO: Add your control notification handler code here
- CString s;
- int j=0;
- CAdddlg dlg;
- m_pSet->MoveFirst();
- int index=m_Record_List.GetNextItem(-1,LVNI_SELECTED);
- if(index!=-1)
- {
- dlg.m_num=m_Record_List.GetItemText(index,0);
- dlg.m_name=m_Record_List.GetItemText(index,1);
- dlg.m_math=m_Record_List.GetItemText(index,2);
- dlg.m_chi=m_Record_List.GetItemText(index,3);
- dlg.m_eng=m_Record_List.GetItemText(index,4);
- if(dlg.DoModal()==IDOK)
- {
- while(!m_pSet->IsEOF())
- {
- if(m_pSet->m_column1==atol(dlg.m_num))
- {
- m_pSet->Edit();
- m_pSet->m_column1=atoi(dlg.m_num);
- m_pSet->m_column2=dlg.m_name;
- m_pSet->m_column3=atoi(dlg.m_math);
- m_pSet->m_column4=atoi(dlg.m_chi);
- m_pSet->m_column5=atoi(dlg.m_eng);
- m_pSet->Update();
- MessageBox("记录已经修改!");
- m_Record_List.DeleteItem(j);
- s.Format("%d",m_pSet->m_column1);
- m_Record_List.InsertItem(j,s);
- m_Record_List.SetItemText(j,1,m_pSet->m_column2);
- s.Format("%d",m_pSet->m_column3);
- m_Record_List.SetItemText(j,2,s);
- s.Format("%d",m_pSet->m_column4);
- m_Record_List.SetItemText(j,3,s);
- s.Format("%d",m_pSet->m_column5);
- m_Record_List.SetItemText(j,4,s);
- break;
- }
- else
- {
- j++;
- m_pSet->MoveNext();
- }
- }
- }
- }
- else
- MessageBox("请选中修改记录!");
- }
- void CStudentView::OnQueryButton()
- {
- // TODO: Add your control notification handler code here
- CString s;
- CSelect dlg;
- bool b=0;
- int j=0;
- m_pSet->MoveFirst();
- if(dlg.DoModal()==IDOK)
- {
- m_Record_List.DeleteAllItems();
- int j=0;
- while(!m_pSet->IsEOF())
- {
- if(m_pSet->m_column2==dlg.m_name)
- {
- s.Format("%d",m_pSet->m_column1);
- m_Record_List.InsertItem(j,s);
- m_Record_List.SetItemText(j,1,m_pSet->m_column2);
- s.Format("%d",m_pSet->m_column3);
- m_Record_List.SetItemText(j,2,s);
- s.Format("%d",m_pSet->m_column4);
- m_Record_List.SetItemText(j,3,s);
- s.Format("%d",m_pSet->m_column5);
- m_Record_List.SetItemText(j,4,s);
- j++;
- }
- m_pSet->MoveNext();
- }
- if(!j)MessageBox("你所要的记录不存在!");
- }
- }
- void CStudentView::OnSortButton()
- {
- // TODO: Add your control notification handler code here
- CSort dlg;
- if(dlg.DoModal()==IDOK)
- {
- m_Record_List.DeleteAllItems();
- m_pSet->m_strSort=dlg.m_Getstring;
- m_pSet->Requery();//重新建立记录集时使用
- OnShowButton();
- }
- }
- void CStudentView::OnDraw(CDC* pDC)
- {
- // TODO: Add your specialized code here and/or call the base class
- CStudentDoc*pDoc=GetDocument();
- ASSERT_VALID(pDoc);
- CDC MemDC;
- MemDC.CreateCompatibleDC(NULL);
- MemDC.SelectObject(pDoc->m_Bitmap);
- pDC->BitBlt(0,0,pDoc->m_nWidth,pDoc->m_nHeight,&MemDC,0,0,SRCCOPY);
- }