www.pudn.com > vc524448882244.rar > stuView.cpp


// stuView.cpp : implementation of the CStuView class 
// 
 
#include "stdafx.h" 
#include "stu.h" 
 
#include "stuSet.h" 
#include "stuDoc.h" 
#include "stuView.h" 
#include "FindDlg.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CStuView 
 
IMPLEMENT_DYNCREATE(CStuView, CRecordView) 
 
BEGIN_MESSAGE_MAP(CStuView, CRecordView) 
	//{{AFX_MSG_MAP(CStuView) 
	ON_BN_CLICKED(IDC_Add, OnAdd) 
	ON_BN_CLICKED(IDC_Del, OnDel) 
	ON_BN_CLICKED(IDC_Modi, OnModi) 
	ON_BN_CLICKED(IDC_Find, OnFind) 
	ON_BN_CLICKED(IDC_PERC, OnPerc) 
	ON_BN_CLICKED(IDC_PERA, OnPera) 
	ON_BN_CLICKED(IDC_PASSC, OnPassc) 
	ON_BN_CLICKED(IDC_SUPERC, OnSuperc) 
	//}}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() 
 
///////////////////////////////////////////////////////////////////////////// 
// CStuView construction/destruction 
 
CStuView::CStuView() 
	: CRecordView(CStuView::IDD) 
{ 
	//{{AFX_DATA_INIT(CStuView) 
	m_pSet = NULL; 
	m_percount = 0; 
	m_peraver = 0; 
	m_passcount = 0; 
	m_supercount = 0; 
	//}}AFX_DATA_INIT 
	// TODO: add construction code here 
 
} 
 
CStuView::~CStuView() 
{ 
} 
 
void CStuView::DoDataExchange(CDataExchange* pDX) 
{ 
	CRecordView::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CStuView) 
	DDX_Text(pDX, IDC_PERCOUNT, m_percount); 
	DDX_Text(pDX, IDC_PERAVER, m_peraver); 
	DDX_Text(pDX, IDC_PASSCOUNT, m_passcount); 
	DDX_FieldText(pDX, IDC_STUID, m_pSet->m_stuID, m_pSet); 
	DDX_FieldText(pDX, IDC_NAME, m_pSet->m_name, m_pSet); 
	DDX_FieldText(pDX, IDC_ENG, m_pSet->m_eng, m_pSet); 
	DDX_FieldText(pDX, IDC_CHIN, m_pSet->m_chin, m_pSet); 
	DDX_FieldText(pDX, IDC_COMP, m_pSet->m_comp, m_pSet); 
	DDX_FieldText(pDX, IDC_AGE, m_pSet->m_age, m_pSet); 
	DDX_Text(pDX, IDC_SUPERCOUNT, m_supercount); 
	//}}AFX_DATA_MAP 
} 
 
BOOL CStuView::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	// TODO: Modify the Window class or styles here by modifying 
	//  the CREATESTRUCT cs 
 
	return CRecordView::PreCreateWindow(cs); 
} 
 
void CStuView::OnInitialUpdate() 
{ 
	m_pSet = &GetDocument()->m_stuSet; 
	CRecordView::OnInitialUpdate(); 
	GetParentFrame()->RecalcLayout(); 
	ResizeParentToFit(); 
 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CStuView printing 
 
BOOL CStuView::OnPreparePrinting(CPrintInfo* pInfo) 
{ 
	// default preparation 
	return DoPreparePrinting(pInfo); 
} 
 
void CStuView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add extra initialization before printing 
} 
 
void CStuView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add cleanup after printing 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CStuView diagnostics 
 
#ifdef _DEBUG 
void CStuView::AssertValid() const 
{ 
	CRecordView::AssertValid(); 
} 
 
void CStuView::Dump(CDumpContext& dc) const 
{ 
	CRecordView::Dump(dc); 
} 
 
CStuDoc* CStuView::GetDocument() // non-debug version is inline 
{ 
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CStuDoc))); 
	return (CStuDoc*)m_pDocument; 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CStuView database support 
CRecordset* CStuView::OnGetRecordset() 
{ 
	return m_pSet; 
} 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CStuView message handlers 
 
void CStuView::OnAdd()  
{ 
	// TODO: Add your control notification handler code here 
	if(!m_pSet->IsOpen()) return; 
	if(!m_pSet->CanAppend()) return; 
	m_pSet->AddNew(); 
	UpdateData(TRUE); 
	if(m_pSet->CanUpdate()) 
		m_pSet->Update(); 
	m_pSet->Requery(); 
	UpdateData(FALSE); 
	 
} 
 
void CStuView::OnDel()  
{ 
	// TODO: Add your control notification handler code here 
	if(MessageBox("确定要删除记录?","删除记录?",MB_YESNO|MB_ICONQUESTION)==IDYES) 
	{ 
		m_pSet->Delete(); 
		m_pSet->MovePrev(); 
		if(m_pSet->IsBOF()) m_pSet->MoveLast(); 
		if(m_pSet->IsEOF()) m_pSet->SetFieldNull(NULL); 
		UpdateData(FALSE); 
	} 
	 
} 
 
void CStuView::OnModi()  
{ 
	// TODO: Add your control notification handler code here 
	m_pSet->Edit(); 
	if(m_pSet->CanUpdate()) 
	{ 
		m_pSet->Update(); 
	} 
	 
} 
 
void CStuView::OnFind()  
{ 
	// TODO: Add your control notification handler code here 
	CDBVariant varBookmark; 
	BOOL lFound=FALSE; 
	CFindDlg dlg; 
	if(dlg.DoModal()!=IDOK) return; 
	if(m_pSet->CanBookmark()) m_pSet->GetBookmark(varBookmark); 
	m_pSet->MoveFirst(); 
	while(!m_pSet->IsEOF()&&!lFound) 
	{ 
	if(m_pSet->m_name==dlg.m_sName) lFound=TRUE; 
	else m_pSet->MoveNext(); 
	} 
	if(!lFound) 
	{ 
	MessageBox("未发现满足条件的记录!","查找错误",MB_OK|MB_ICONERROR); 
	if(m_pSet->CanBookmark()) 
	m_pSet->SetBookmark(varBookmark); 
	else 
	m_pSet->MoveFirst(); 
	} 
	else{ 
	UpdateData(FALSE); 
	} 
	 
} 
 
void CStuView::OnPerc()  
{ 
 
	// TODO: Add your control notification handler code here 
	m_percount=m_pSet->m_chin+m_pSet->m_eng+m_pSet->m_comp; 
 
		CRecordView::OnInitialUpdate(); 
 
} 
 
void CStuView::OnPera()  
{ 
	// TODO: Add your control notification handler code here 
	m_peraver=m_percount/3; 
 
	CRecordView::OnInitialUpdate(); 
} 
 
void CStuView::OnPassc()  
{ //int i; 
//	m_passcount=0; 
	// TODO: Add your control notification handler code here 
//i=m_pSet->GetRecordCount(); 
 
/*for(int j=0;jm_chin>=60 && m_pSet->m_eng >=60 && m_pSet->m_comp>=60) 
++m_passcount; 
	m_pSet->MoveNext(); 
if(m_pSet->IsEOF()) 
m_pSet->MoveFirst(); 
	 
}*/ if(m_pSet->GetRecordCount()>0)  
{ 
  m_passcount=0; 
  m_pSet->MoveFirst(); 
  do 
  { 
 	if(m_pSet->m_chin>=60 && m_pSet->m_eng >=60 && m_pSet->m_comp>=60) 
     m_passcount++; 
	m_pSet->MoveNext(); 
   } while(!m_pSet->IsEOF()); 
  m_pSet->MoveLast(); 
} 
 
	CRecordView::OnInitialUpdate(); 
} 
 
void CStuView::OnSuperc()  
{ 
	// TODO: Add your control notification handler code here 
if(m_pSet->GetRecordCount()>0)  
{ 
  m_supercount=0; 
  m_pSet->MoveFirst(); 
  do 
  { 
 	if(m_pSet->m_chin>=80 && m_pSet->m_eng >=80 && m_pSet->m_comp>=80) 
     m_supercount++; 
	m_pSet->MoveNext(); 
   } while(!m_pSet->IsEOF()); 
  m_pSet->MoveLast(); 
} 
 
	CRecordView::OnInitialUpdate(); 
	 
}