⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 studentview.cpp

📁 学生成绩查询系统.帮忙大家学生和提升对VC++的学生和认识.
💻 CPP
字号:
// StudentView.cpp : implementation of the CStudentView class
//

#include "stdafx.h"
#include "Student.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, CFormView)

BEGIN_MESSAGE_MAP(CStudentView, CFormView)
	//{{AFX_MSG_MAP(CStudentView)
		// 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 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()

/////////////////////////////////////////////////////////////////////////////
// CStudentView construction/destruction

CStudentView::CStudentView()
	: CFormView(CStudentView::IDD)
{
	//{{AFX_DATA_INIT(CStudentView)
	m_Class = _T("");
	m_Course = _T("");
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CStudentView::~CStudentView()
{
}

void CStudentView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CStudentView)
	DDX_Control(pDX, IDC_MSFLEXGRID, m_Grid);
	DDX_Text(pDX, IDC_STATIC_CLASS, m_Class);
	DDX_Text(pDX, IDC_STATIC_COURSE, m_Course);
	//}}AFX_DATA_MAP
}

BOOL CStudentView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

void CStudentView::OnInitialUpdate()		// 第一次显示表单时调用
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();

	// 设置网格列数和各列宽度
	m_Grid.SetCols(8);
	m_Grid.SetColWidth(0, 450);
	m_Grid.SetColWidth(1, 850);
	m_Grid.SetColWidth(2, 700);
	m_Grid.SetColWidth(3, 500);
	m_Grid.SetColWidth(4, 500);
	m_Grid.SetColWidth(5, 500);
	m_Grid.SetColWidth(6, 500);
	m_Grid.SetColWidth(7, 600);
	// 设置网格中数据对齐方式(居中)
	for (int j = 0; j <= 7; j ++)
		m_Grid.SetFixedAlignment(j, 3);
	// 设置标题行文本
	m_Grid.SetRow(0);
	m_Grid.SetCol(0);
	m_Grid.SetText("序号");
	m_Grid.SetCol(1);
	m_Grid.SetText("学号");
	m_Grid.SetCol(2);
	m_Grid.SetText("姓名");
	m_Grid.SetCol(3);
	m_Grid.SetText("平时");
	m_Grid.SetCol(4);
	m_Grid.SetText("实验");
	m_Grid.SetCol(5);
	m_Grid.SetText("期中");
	m_Grid.SetCol(6);
	m_Grid.SetText("期末");
	m_Grid.SetCol(7);
	m_Grid.SetText("总评");

}

/////////////////////////////////////////////////////////////////////////////
// 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
}

void CStudentView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
	// TODO: add customized printing code here
}

/////////////////////////////////////////////////////////////////////////////
// CStudentView diagnostics

#ifdef _DEBUG
void CStudentView::AssertValid() const
{
	CFormView::AssertValid();
}

void CStudentView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CStudentDoc* CStudentView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CStudentDoc)));
	return (CStudentDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CStudentView message handlers

void CStudentView::UpdateGrid()						// 刷新表单中的学生成绩表函数
{
	CStudentDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	int rows = pDoc->m_studentlist.GetnStudent();	// 取线性表长度(学生人数)
	// 如果只有一个学生且数据为空,说明记录集为空,则不显示数据
	if (rows == 1 && pDoc->m_studentlist.GetpStudent()[0].GetID() == "")
	{
		rows --;
		pDoc->m_Period = -1;
	}
	m_Grid.SetRows(rows + 1);						// 设置网格行数
	char str[32];
	// 在网格中显示数据
	for (int i = 0; i < rows; i ++)					
	{
		m_Grid.SetRow(i + 1);
		m_Grid.SetCol(0);
		m_Grid.SetCellAlignment(3);
		m_Grid.SetText(itoa(i + 1, str, 10));
		m_Grid.SetCol(1);
		m_Grid.SetCellAlignment(3);
		m_Grid.SetText(pDoc->m_studentlist.GetpStudent()[i].GetID().data());
		m_Grid.SetCol(2);
		m_Grid.SetCellAlignment(3);
		m_Grid.SetText(pDoc->m_studentlist.GetpStudent()[i].GetName().data());
		m_Grid.SetCol(3);
		m_Grid.SetCellAlignment(3);
		sprintf(str, "%4.0f", pDoc->m_studentlist.GetpStudent()[i].GetExercise());
		m_Grid.SetText(str);
		m_Grid.SetCol(4);
		m_Grid.SetCellAlignment(3);
		sprintf(str, "%4.0f", pDoc->m_studentlist.GetpStudent()[i].GetReport());
		m_Grid.SetText(str);
		m_Grid.SetCol(5);
		m_Grid.SetCellAlignment(3);
		sprintf(str, "%4.0f", pDoc->m_studentlist.GetpStudent()[i].GetMidterm());
		m_Grid.SetText(str);
		m_Grid.SetCol(6);
		m_Grid.SetCellAlignment(3);
		sprintf(str, "%4.0f", pDoc->m_studentlist.GetpStudent()[i].GetTerminal());
		m_Grid.SetText(str);
		m_Grid.SetCol(7);
		m_Grid.SetCellAlignment(3);
		sprintf(str, "%4.1f", pDoc->m_studentlist.GetpStudent()[i].GetMark());
		m_Grid.SetText(str);
	}
}

void CStudentView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) // UpdateAllViews 函数调用
{
	// TODO: Add your specialized code here and/or call the base class
	CStudentDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (lHint == 0)		// 若不是改变焦点导致的UpdateAllViews调用,则刷新网格数据
	{
		// 显示班级、课程名于网格上方
		m_Class = pDoc->m_Class;
		m_Course = pDoc->m_Course;
		UpdateData(FALSE);
		// 刷新网格数据
		UpdateGrid();
	}
}

BEGIN_EVENTSINK_MAP(CStudentView, CFormView)
    //{{AFX_EVENTSINK_MAP(CStudentView)
	ON_EVENT(CStudentView, IDC_MSFLEXGRID, 69 /* SelChange */, OnSelChangeMsflexgrid, VTS_NONE)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CStudentView::OnSelChangeMsflexgrid()		// 当改变焦点于网格的不同单元格时调用 
{
	// TODO: Add your control notification handler code here
	CStudentDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	pDoc->m_Period = m_Grid.GetCol() - 3;		// 考核阶段为网格列号减3(前三列分别为序号、学号和姓名)
	pDoc->UpdateAllViews(NULL, 1);				// 改变焦点,则不刷新网格数据
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -