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

📄 scoredialog.cpp

📁 这是目前正应用于辽宁省很多县级中学的试题库系统源代码
💻 CPP
字号:
// ScoreDialog.cpp : implementation file
//

#include "stdafx.h"
#include "TestPaper.h"
#include "ScoreDialog.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CScoreDialog dialog


CScoreDialog::CScoreDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CScoreDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CScoreDialog)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CScoreDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CScoreDialog)
	DDX_Control(pDX, IDC_LIST1, m_ListCtrl);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CScoreDialog, CDialog)
	//{{AFX_MSG_MAP(CScoreDialog)
	ON_COMMAND(ID_SCORESC, OnScoresc)
	//}}AFX_MSG_MAP
	ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnScoreDblclickList)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CScoreDialog message handlers

BOOL CScoreDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	CMainFrame* pMainFrame=(CMainFrame*) AfxGetMainWnd();
	HICON hIcon=AfxGetApp()->LoadIcon(IDI_ICON11);
	this->SendMessage(WM_SETICON,ICON_BIG,(LPARAM)hIcon);
	CRect rect;
	CDBVariant OleVar;
	CString buf;
	int i=0;
	GetClientRect(rect);
    m_ListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP);
    int Listwid=rect.right-rect.left;
    m_ListCtrl.InsertColumn(0,_T("学生姓名"),LVCFMT_CENTER,Listwid/6);
    m_ListCtrl.InsertColumn(1,_T("考试科目"),LVCFMT_CENTER,Listwid/6);
	m_ListCtrl.InsertColumn(2,_T("准考证号"),LVCFMT_CENTER,Listwid/6);
    m_ListCtrl.InsertColumn(3,_T("试卷名称"),LVCFMT_CENTER,Listwid/6);
    m_ListCtrl.InsertColumn(4,_T("考试得分"),LVCFMT_CENTER,Listwid/6);
	m_ListCtrl.InsertColumn(5,_T("工作单位"),LVCFMT_CENTER,Listwid/6);
	m_ListCtrl.DeleteAllItems();
	
	pMainFrame->m_xinpaperset.MoveFirst();
	while(!pMainFrame->m_xinpaperset.IsEOF())
	{
		int temp=0;
		pMainFrame->m_xinpaperset.GetFieldValue(temp,OleVar);
		m_ListCtrl.InsertItem(i,"");
		m_ListCtrl.SetItemText(i,0,OleVar.m_pstring->GetBuffer(1));
        pMainFrame->m_xinpaperset.GetFieldValue(1,OleVar);
        m_ListCtrl.SetItemText(i,1,OleVar.m_pstring->GetBuffer(1));
		pMainFrame->m_xinpaperset.GetFieldValue(2,OleVar);
		m_ListCtrl.SetItemText(i,2,OleVar.m_pstring->GetBuffer(1));
		pMainFrame->m_xinpaperset.GetFieldValue(3,OleVar);
	    m_ListCtrl.SetItemText(i,3,OleVar.m_pstring->GetBuffer(1));
		pMainFrame->m_xinpaperset.GetFieldValue(4,OleVar);
		buf.Format("%d",OleVar.m_iVal);
		m_ListCtrl.SetItemText(i,4,buf);	
		pMainFrame->m_xinpaperset.GetFieldValue(5,OleVar);
		m_ListCtrl.SetItemText(i,5,OleVar.m_pstring->GetBuffer(1));
		pMainFrame->m_xinpaperset.MoveNext();
		i++;
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}


void CScoreDialog::OnScoreDblclickList(NMHDR* pNMHDR, LRESULT* pResult)
{
	CPoint cMousePoint;// 鼠标位置
	GetCursorPos(&cMousePoint);// 屏幕的鼠标位置,并非窗口的
    POINT  cListOriginPoint;
	CRect  cListWindowRect;
	UINT uFlags;
	m_ListCtrl.GetWindowRect(&cListWindowRect);
	cListOriginPoint = cListWindowRect.TopLeft();
	CPoint cTestPoint(cMousePoint.x - cListOriginPoint.x,cMousePoint.y - cListOriginPoint.y);
	nItem = m_ListCtrl.HitTest(cTestPoint,&uFlags);
	if(nItem>=0)
	{
		ClientToScreen(&cTestPoint);
		CMenu* pMenu=new CMenu;
		pMenu->LoadMenu(IDR_MENU2);
		CMenu* pFileMenu=pMenu->GetSubMenu(0);
		pFileMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,cTestPoint.x,cTestPoint.y,this);
		delete pMenu;
	}
}

void CScoreDialog::OnScoresc() 
{
	// TODO: Add your command handler code here
	CMainFrame* pMainFrame=(CMainFrame*) AfxGetMainWnd();
	int i=nItem;
	CString strSQL;
	if(pMainFrame->BoolConnent==FALSE || pMainFrame->m_xinpaperset.GetRecordCount()==0)
	{
		AfxMessageBox("请连接数据源或无记录!");
		return;
	} 
	if(!pMainFrame->m_xinpaperset.CanUpdate())
         return;
	if(i==-1)
	{
		AfxMessageBox("请选择删除项!");
		return;
	}
	else
	{
	    if(AfxMessageBox("确实需要删除这项记录吗?",MB_YESNO)==IDYES)
		{
	
	    CString strSQL;
		CString temp;
		temp.Empty();
   	    strSQL.Empty();
	    temp=m_ListCtrl.GetItemText(i,2);
	    strSQL.Format("delete from 成绩表 where 准考证号='"+temp+"'");
		pMainFrame->m_database.ExecuteSQL(strSQL);
		m_ListCtrl.DeleteItem(i);
		}
	}
}

⌨️ 快捷键说明

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