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

📄 techxxdlg.cpp

📁 学生成绩管理系统,实现增加删除修改保存等功能
💻 CPP
字号:
// TechxxDlg.cpp : implementation file
//

#include "stdafx.h"
#include "StuManage.h"
#include "TechxxDlg.h"
#include "TechxxSet.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTechxxDlg dialog


CTechxxDlg::CTechxxDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTechxxDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTechxxDlg)
	m_techNo = _T("");
	m_techName = _T("");
	m_techCourse = _T("");
	//}}AFX_DATA_INIT
}


void CTechxxDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTechxxDlg)
	DDX_Control(pDX, IDC_TECHXX_LIST, m_techList);
	DDX_Text(pDX, IDC_TECHNO_EDIT, m_techNo);
	DDX_Text(pDX, IDC_TECHNAME_EDIT, m_techName);
	DDX_Text(pDX, IDC_TECHCOURSE_EDIT, m_techCourse);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTechxxDlg, CDialog)
	//{{AFX_MSG_MAP(CTechxxDlg)
	ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton)
	ON_BN_CLICKED(IDC_SAVE_BUTTON, OnSaveButton)
	ON_BN_CLICKED(IDC_DELETE_BUTTON, OnDeleteButton)
	ON_BN_CLICKED(IDC_MODIFY_BUTTON, OnModifyButton)
	ON_BN_CLICKED(IDC_CANCEL, OnCancel)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTechxxDlg message handlers

BOOL CTechxxDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_techList.InsertColumn(0,"教师代号");
	m_techList.InsertColumn(1,"教师工号");
	m_techList.InsertColumn(2,"教师姓名");
	m_techList.InsertColumn(3,"所授课程");
	CRect rect;
	m_techList.GetWindowRect(&rect);
	int wid=rect.right-rect.left;
	m_techList.SetColumnWidth(0,wid/4);
    m_techList.SetColumnWidth(1,wid/4);
	m_techList.SetColumnWidth(2,wid/4);
	m_techList.SetColumnWidth(3,wid/4);
	m_techList.SetExtendedStyle(LVS_EX_FULLROWSELECT);
	RefreshList();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CTechxxDlg::RefreshList()
{
    if(!m_database.IsOpen()) {
		m_database.Open(_T("xscjgl"));
	}
	m_techList.DeleteAllItems();
    CTechxxSet m_TechxxSet(&m_database);
	CString strSQL;
	strSQL.Format("select * from jsxx");
	m_database.ExecuteSQL(strSQL);
	m_TechxxSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);
	if(m_TechxxSet.GetRecordCount()!=0)
		m_TechxxSet.MoveFirst();
	int i=0;
	while(!m_TechxxSet.IsEOF()) {
		CString temp;
		m_TechxxSet.GetFieldValue("TechID",temp);
		m_techList.InsertItem(i,temp);
		m_techList.SetItemText(i,1,m_TechxxSet.m_TechNo);
		m_techList.SetItemText(i,2,m_TechxxSet.m_TechName);
		m_techList.SetItemText(i,3,m_TechxxSet.m_CourseName);
		m_TechxxSet.MoveNext();
		i++;
	}
	m_TechxxSet.Close();
}

void CTechxxDlg::OnAddButton() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CTechxxSet m_TechxxSet;
	if(!UpdateData())
		return;
	if(m_techNo.GetLength()==0) {
		MessageBox("请输入教师工号!");
	    return;
	}
	if(m_techName.GetLength()==0) {
		MessageBox("请输入教师姓名!");
		return;
	}
	CString strSQL;
	int flag=0;
	int i=1;
	while(!flag) {
		CTechxxSet m_TechxxSet(&m_database);
		strSQL.Format("select * from jsxx where TechID=%d",i);
		m_TechxxSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);
		if(m_TechxxSet.GetRecordCount()==0) {
			strSQL.Format("insert into jsxx values(%d,\'%s',\'%s',\'%s')",i,m_techNo,m_techName,m_techCourse);
			m_database.ExecuteSQL(strSQL);
			m_TechxxSet.Close();
			m_database.Close();	
			RefreshList();
			flag=1;
		}
		i++;
	}
	//CDialog::OnOK();	
}

void CTechxxDlg::OnSaveButton() 
{
	// TODO: Add your control notification handler code here
	CTechxxSet m_TechxxSet(&m_database);
	m_TechxxSet.m_TechNo=m_techNo;
	m_TechxxSet.m_TechName=m_techName;
	m_TechxxSet.m_CourseName=m_techCourse;
	m_TechxxSet.Close();
	RefreshList();
	CDialog::OnOK();
}

void CTechxxDlg::OnDeleteButton() 
{
	// TODO: Add your control notification handler code here
	CTechxxSet m_TechxxSet;
	int i=m_techList.GetSelectionMark();
	CString strSQL;
    int keyid=atoi(m_techList.GetItemText(i,0));
	if(keyid<0)
	{
		MessageBox("请选择您要删除的一行!");
	}
	else
	{
		if(MessageBox("您确定要删除该记录吗?","是否删除",MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
		{
			strSQL.Format("delete from jsxx where TechID=%d",keyid);
			m_database.ExecuteSQL(strSQL);
			m_database.Close();
			RefreshList();
		}
	}
}

void CTechxxDlg::OnModifyButton() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CTechxxSet m_TechxxSet;
	CString strSQL;
	int flag=0;
	//int i=atoi(m_stuNo);
	while(!flag) {
		CTechxxSet m_TechxxSet(&m_database);
		strSQL.Format("update jsxx set TechName='%s',CourseName='%s' where TechNo='%s'",m_techName,m_techCourse,m_techNo);
		m_database.ExecuteSQL(strSQL);
		m_database.Close();	
		RefreshList();
		flag=1;	
	}
}

void CTechxxDlg::OnCancel() 
{
	// TODO: Add your control notification handler code here
	OnOK();
}

⌨️ 快捷键说明

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