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

📄 honordlg.cpp

📁 学生管理系统数据库源码。很好用哦
💻 CPP
字号:
// HonorDlg.cpp : implementation file
//

#include "stdafx.h"
#include "school.h"
#include "HonorDlg.h"
#include "HonorInfoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CHonorDlg dialog


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


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


BEGIN_MESSAGE_MAP(CHonorDlg, CDialog)
	//{{AFX_MSG_MAP(CHonorDlg)
	ON_BN_CLICKED(IDC_BUTTON_NEW, OnButtonNew)
	ON_BN_CLICKED(IDC_BUTTON_MODIFY, OnButtonModify)
	ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CHonorDlg message handlers

BOOL CHonorDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	m_ctrList.InsertColumn(0,"序号");
	m_ctrList.InsertColumn(1,"姓名");
	m_ctrList.InsertColumn(2,"学号");
	m_ctrList.InsertColumn(3,"班级");
	m_ctrList.InsertColumn(4,"奖惩日期");
	m_ctrList.InsertColumn(5,"奖惩内容");
	m_ctrList.InsertColumn(6,"备注");

	m_ctrList.SetColumnWidth(0,60);
	m_ctrList.SetColumnWidth(1,80);
	m_ctrList.SetColumnWidth(2,80);
	m_ctrList.SetColumnWidth(3,80);
	m_ctrList.SetColumnWidth(4,100);
	m_ctrList.SetColumnWidth(5,160);
	m_ctrList.SetColumnWidth(6,160);

	m_ctrList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
	RefreshData("select * from honor");	
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CHonorDlg::RefreshData(CString strSQL)
{

	m_ctrList.DeleteAllItems();
	m_ctrList.SetRedraw(FALSE);

	UpdateData(TRUE);

	if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
	{
		MessageBox("打开数据库失败!","数据库错误",MB_OK);
		return ;
	}	
	int i=0;
	char buffer[20];
	while(!m_recordset.IsEOF())
	{
		_ltoa(m_recordset.m_ID,buffer,10);
		m_ctrList.InsertItem(i,buffer);
		m_ctrList.SetItemText(i,1,m_recordset.m_name);
		m_ctrList.SetItemText(i,2,m_recordset.m_code);
		m_ctrList.SetItemText(i,3,m_recordset.m_class);
		m_ctrList.SetItemText(i,4,m_recordset.m_date);
		m_ctrList.SetItemText(i,5,m_recordset.m_brief);
		m_ctrList.SetItemText(i,6,m_recordset.m_content);
		i++;
		m_recordset.MoveNext();
	}
	m_recordset.Close();
	m_ctrList.SetRedraw(TRUE);
	
}

void CHonorDlg::OnButtonNew() 
{
	// TODO: Add your control notification handler code here
	CHonorInfoDlg   Dlg;
	if(IDOK==Dlg.DoModal())
	{
//添加新记录
		if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE))
		{
			AfxMessageBox("打开数据库失败!");
			return ;
		}
		m_recordset.AddNew();
		m_recordset.m_name		=	Dlg.m_strName		;
		m_recordset.m_brief		=	Dlg.m_strBrief		;
		m_recordset.m_date		=   Dlg.m_strDate		;
		m_recordset.m_class		=	Dlg.m_strClass		;
		m_recordset.m_code		=	Dlg.m_strCode		;
		m_recordset.m_content	=	Dlg.m_strContent	;
		m_recordset.Update();
		m_recordset.Close();
		RefreshData("select * from honor ");
	}	
}

void CHonorDlg::OnButtonModify() 
{
	// TODO: Add your control notification handler code here
	CHonorInfoDlg Dlg;
	UpdateData();
	int i = m_ctrList.GetSelectionMark();
	if(0>i)
	{
		AfxMessageBox("请选择一条记录进行修改!");
		return;
	}

	CString strSQL;
	strSQL.Format("select * from honor where ID = %s",m_ctrList.GetItemText(i,0));
	if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
	{
		AfxMessageBox("打开数据库失败!");
		return ;
	}
	Dlg.m_strName		=	m_recordset.m_name			;
	Dlg.m_strBrief		=	m_recordset.m_brief			;
	Dlg.m_strDate		=	m_recordset.m_date			;
	Dlg.m_strClass		=	m_recordset.m_class			;
	Dlg.m_strCode		=	m_recordset.m_code			;
	Dlg.m_strContent	=	m_recordset.m_content		;
	m_recordset.Close();

	if(IDOK==Dlg.DoModal())
	{//修改记录
		strSQL.Format("select * from honor where ID = %s",m_ctrList.GetItemText(i,0));
		if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
		{
			AfxMessageBox("打开数据库失败!");
			return ;
		}
		m_recordset.Edit();
		m_recordset.m_name		=	Dlg.m_strName		;
		m_recordset.m_brief		=	Dlg.m_strBrief		;
		m_recordset.m_date		=   Dlg.m_strDate		;
		m_recordset.m_class		=	Dlg.m_strClass		;
		m_recordset.m_code		=	Dlg.m_strCode		;
		m_recordset.m_content	=	Dlg.m_strContent	;
		m_recordset.Update();
		m_recordset.Close();
		RefreshData("select * from honor ");
	}			
}

void CHonorDlg::OnButtonDelete() 
{
	// TODO: Add your control notification handler code here
	int i = m_ctrList.GetSelectionMark();
	if(0>i)
	{
		AfxMessageBox("请选择一条记录进行查看!");
		return;
	}
	CString strSQL;
	strSQL.Format("select * from honor where ID = %s ",m_ctrList.GetItemText(i,0));
	if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
	{
		AfxMessageBox("打开数据库失败!");
		return ;
	}
	m_recordset.Delete();
	m_recordset.Close();
	RefreshData("select * from honor ");		
}

void CHonorDlg::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	CHonorInfoDlg Dlg;
	UpdateData();
	int i = m_ctrList.GetSelectionMark();
	if(0>i)
	{
		AfxMessageBox("请选择一条记录进行修改!");
		return;
	}

	CString strSQL;
	strSQL.Format("select * from honor where ID = %s",m_ctrList.GetItemText(i,0));
	if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
	{
		AfxMessageBox("打开数据库失败!");
		return ;
	}
	Dlg.m_strName		=	m_recordset.m_name			;
	Dlg.m_strBrief		=	m_recordset.m_brief			;
	Dlg.m_strDate		=	m_recordset.m_date			;
	Dlg.m_strClass		=	m_recordset.m_class			;
	Dlg.m_strCode		=	m_recordset.m_code			;
	Dlg.m_strContent	=	m_recordset.m_content		;
	m_recordset.Close();

	if(IDOK==Dlg.DoModal())
	{//修改记录
		strSQL.Format("select * from honor where ID = %s",m_ctrList.GetItemText(i,0));
		if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
		{
			AfxMessageBox("打开数据库失败!");
			return ;
		}
		m_recordset.Edit();
		m_recordset.m_name		=	Dlg.m_strName		;
		m_recordset.m_brief		=	Dlg.m_strBrief		;
		m_recordset.m_date		=   Dlg.m_strDate		;
		m_recordset.m_class		=	Dlg.m_strClass		;
		m_recordset.m_code		=	Dlg.m_strCode		;
		m_recordset.m_content	=	Dlg.m_strContent	;
		m_recordset.Update();
		m_recordset.Close();
		RefreshData("select * from honor ");
	}			
	*pResult = 0;
}

⌨️ 快捷键说明

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