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

📄 studentdlg.cpp

📁 一个简单的学生信息管理系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	if(dlg.DoModal()==IDOK)
	{
		 UpdateData(true);
	//	if(dlg.DoModal()==IDOK)
	while(dlg.m_num==""||dlg.m_name=="")
	{
		AfxMessageBox("请输入学号和姓名");
		if(!(dlg.DoModal()==IDOK)) break;
		
	}
	}

	if(!(dlg.m_num==""||dlg.m_name==""))
	{
		
//			UpdateData(true);
	_variant_t num,name,yuwen,shuxue,yingyu,wuli,huaxue;
	m_pConnection.CreateInstance(__uuidof(Connection));
	m_pRecordset.CreateInstance(__uuidof(Recordset));
	try{
		m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=swb.mdb","","",adModeUnknown);
		if(m_class=="一班")
			m_pRecordset->Open("SELECT * FROM student1",m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText); 	
		if(m_class=="二班")
			m_pRecordset->Open("SELECT * FROM student2",m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText); 	
		num=dlg.m_num;
		name=dlg.m_name;
		yuwen.vt=VT_I2;
		yuwen.lVal=dlg.m_yuwen;
		shuxue.vt=VT_I2;
		shuxue.lVal=dlg.m_shuxue;
		yingyu.vt=VT_I2;
		yingyu.lVal=dlg.m_yingyu;
		wuli.vt=VT_I2;
		wuli.lVal=dlg.m_wuli;
		huaxue.vt=VT_I2;
		huaxue.lVal=dlg.m_huaxue;
		m_pRecordset->MoveLast();
		m_pRecordset->AddNew();
		m_pRecordset->PutCollect("学号",num);
		m_pRecordset->PutCollect("姓名",name);
		m_pRecordset->PutCollect("语文",yuwen);
		m_pRecordset->PutCollect("数学",shuxue);
		m_pRecordset->PutCollect("英语",yingyu);
		m_pRecordset->PutCollect("物理",wuli);
		m_pRecordset->PutCollect("化学",huaxue);
		m_pRecordset->Update();

	m_pRecordset->Close();
    m_pConnection->Close();
	m_pRecordset=NULL;
	m_pConnection=NULL;

	}
	catch(_com_error* e)
	{
		AfxMessageBox(e->ErrorMessage());
	}
	
	CStudentdlg::OnShow();
   	}
}



void CStudentdlg::OnClickList2(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here


	nCurSel=m_list1.GetNextItem(-1,LVNI_ALL | LVNI_SELECTED);
	nCurSel2=-1;
	nCurSel1=-1;
	

	*pResult = 0;
}

void CStudentdlg::OnDelete() 
{
	_variant_t num;
	CString strnum,item,m_class;
	item=m_list1.GetItemText(nCurSel,0);
	m_combo3.GetLBText(m_combo3.GetCurSel(),m_class);

   	m_pConnection.CreateInstance(__uuidof(Connection));
	m_pRecordset.CreateInstance(__uuidof(Recordset));
	m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=swb.mdb","","",adModeUnknown);
	if(m_class=="一班")
		m_pRecordset->Open("SELECT * FROM student1",m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
	if(m_class=="二班")
		m_pRecordset->Open("SELECT * FROM student2",m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);

	if(nCurSel!=-1)
	{
        m_pRecordset->MoveFirst();
     	num=m_pRecordset->GetCollect("学号");

    	strnum=(LPCSTR)(_bstr_t)num;
    	while(strnum!=item)
		{
    		m_pRecordset->MoveNext();
    		num=m_pRecordset->GetCollect("学号");
    	    strnum=(LPCSTR)(_bstr_t)num;
		
		}
		CDODELETE dlg;
		if(dlg.DoModal()==IDOK)
			m_pRecordset->Delete(adAffectCurrent);
    	m_pRecordset->Close();
        m_pConnection->Close();
    	m_pRecordset=NULL;
    	m_pConnection=NULL;

    	CStudentdlg::OnShow();
	}


}


void CStudentdlg::OnEdit() 
{
	if(nCurSel!=-1)
	{
	CModifydlg dlg;
	_variant_t nnum;
	CString item,strnum,m_class;
	m_combo3.GetLBText(m_combo3.GetCurSel(),m_class);
	_variant_t num,name,yuwen,shuxue,yingyu,wuli,huaxue;
	dlg.m_num=m_list1.GetItemText(nCurSel,0);
	dlg.m_name=m_list1.GetItemText(nCurSel,1);

       
		CString var;
    	var=m_list1.GetItemText(nCurSel,2);
		dlg.m_yuwen=atoi(var);
		var=m_list1.GetItemText(nCurSel,3);
		dlg.m_shuxue=atoi(var);
		var=m_list1.GetItemText(nCurSel,4);
		dlg.m_yingyu=atoi(var);
		var=m_list1.GetItemText(nCurSel,5);
		dlg.m_wuli=atoi(var);
		var=m_list1.GetItemText(nCurSel,6);
		dlg.m_huaxue=atoi(var);



		item=m_list1.GetItemText(nCurSel,0);
     	m_pConnection.CreateInstance(__uuidof(Connection));
    	m_pRecordset.CreateInstance(__uuidof(Recordset));
    	m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=swb.mdb","","",adModeUnknown);
		if(m_class=="一班")
			m_pRecordset->Open("SELECT * FROM student1",m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
		if(m_class=="二班")
			m_pRecordset->Open("SELECT * FROM student2",m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);

        
        	m_pRecordset->MoveFirst();
		   	nnum=m_pRecordset->GetCollect("学号");

		  	strnum=(LPCSTR)(_bstr_t)nnum;
		  	while(strnum!=item)
			{
		 		m_pRecordset->MoveNext();
		    	nnum=m_pRecordset->GetCollect("学号");
		   	    strnum=(LPCSTR)(_bstr_t)nnum;
		
			}


			if(dlg.DoModal()==IDOK)
			{
			
		 		num=dlg.m_num;
		 		name=dlg.m_name;
		  		yuwen.vt=VT_I2;
		  		yuwen.lVal=dlg.m_yuwen;
		   		shuxue.vt=VT_I2;
		     	shuxue.lVal=dlg.m_shuxue;
		  		yingyu.vt=VT_I2;
		    	yingyu.lVal=dlg.m_yingyu;
				wuli.vt=VT_I2;
    			wuli.lVal=dlg.m_wuli;
		   		huaxue.vt=VT_I2;
    			huaxue.lVal=dlg.m_huaxue;

	    		m_pRecordset->PutCollect("学号",num);
				m_pRecordset->PutCollect("姓名",name);
     			m_pRecordset->PutCollect("语文",yuwen);
	    		m_pRecordset->PutCollect("数学",shuxue);
				m_pRecordset->PutCollect("英语",yingyu);
    			m_pRecordset->PutCollect("物理",wuli);
	      		m_pRecordset->PutCollect("化学",huaxue);
				m_pRecordset->Update();

				m_pRecordset->Close();
	            m_pConnection->Close();
		        m_pRecordset=NULL;
			    m_pConnection=NULL;

				CStudentdlg::OnShow();


	
			}
			else
			{
				m_pRecordset->Close();
				  m_pConnection->Close();
				m_pRecordset=NULL;
				m_pConnection=NULL;
			}
		
	}
	if(nCurSel2!=-1)
	{
		CEditTeacher dlg;
		CString item,kemu;
		_variant_t var;
		item=m_list3.GetItemText(nCurSel2,0);
		dlg.m_subject=item;
		dlg.m_teacher=m_list3.GetItemText(nCurSel2,1);
		m_pConnection.CreateInstance(__uuidof(Connection));
		m_pRecordset.CreateInstance(__uuidof(Recordset));
		m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=swb.mdb","","",adModeUnknown);
    	m_pRecordset->Open("SELECT * FROM teacher",m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
		var=m_pRecordset->GetCollect("科目");
		if(var.vt!=VT_NULL)
			kemu=(LPCSTR)_bstr_t(var);
		while(kemu!=item)
		{
			m_pRecordset->MoveNext();
			var=m_pRecordset->GetCollect("科目");
		    if(var.vt!=VT_NULL)
				kemu=(LPCSTR)_bstr_t(var);
		}

        if(dlg.DoModal()==IDOK)
		{
			m_pRecordset->PutCollect("科目",(_variant_t)dlg.m_subject);
			m_pRecordset->PutCollect("任课老师",(_variant_t)dlg.m_teacher);
			m_pRecordset->Update();

			m_pRecordset->Close();
			m_pConnection->Close();
			m_pRecordset=NULL;
			m_pConnection=NULL;

			CStudentdlg::OnShow();

		}
		else
		{
			m_pRecordset->Close();
			m_pConnection->Close();
			m_pRecordset=NULL;
			m_pConnection=NULL;
		}
		

		
		
		
	}
    	
}
void CStudentdlg::OnFind() 
{
	CFinddlg dlg;
	
	if(dlg.DoModal()==IDOK&&dlg.m_combo1!=""&&dlg.m_combo2!="")
	{
		_variant_t var;
		CString num,name,yuwen,shuxue,yingyu,wuli,huaxue;
		CString str1=dlg.m_combo1;
		CString str2=dlg.m_combo2;
		CString str3,m_class;
		m_combo3.GetLBText(m_combo3.GetCurSel(),m_class);

		str3.Format("%d",dlg.m_value);
	    
		if(m_class=="一班")
			SQLQueryAll = "SELECT * FROM student1 WHERE "+str1+" "+str2+" "+str3+" ";
		if(m_class=="二班")
			SQLQueryAll = "SELECT * FROM student2 WHERE "+str1+" "+str2+" "+str3+" ";
		m_pConnection.CreateInstance(__uuidof(Connection));
    	m_pRecordset.CreateInstance(__uuidof(Recordset));
    	m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=swb.mdb","","",adModeUnknown);
    	m_pRecordset->Open(_variant_t(SQLQueryAll),m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
		

		m_list1.DeleteAllItems();
		if(!m_pRecordset->BOF)
			m_pRecordset->MoveFirst();
		else
		{
			AfxMessageBox("表内没有记录~!");
			return;
		}
		while(!m_pRecordset->adoEOF)
		{
		var=m_pRecordset->GetCollect("学号");
		if(var.vt!=VT_NULL)
			num=(LPCSTR)_bstr_t(var);
		var=m_pRecordset->GetCollect("姓名");
		if(var.vt!=VT_NULL)
     		name=(LPCSTR)_bstr_t(var);
        var=m_pRecordset->GetCollect("语文");
		if(var.vt!=VT_NULL)
			yuwen=(LPCSTR)_bstr_t(var);
        var=m_pRecordset->GetCollect("数学");
		if(var.vt!=VT_NULL)
			shuxue=(LPCSTR)_bstr_t(var);
	    var=m_pRecordset->GetCollect("英语");
		if(var.vt!=VT_NULL)
			yingyu=(LPCSTR)_bstr_t(var);
	    var=m_pRecordset->GetCollect("物理");
		if(var.vt!=VT_NULL)
			wuli=(LPCSTR)_bstr_t(var);
	    var=m_pRecordset->GetCollect("化学");
		if(var.vt!=VT_NULL)
			huaxue=(LPCSTR)_bstr_t(var); 

		int i=0;
		m_list1.InsertItem(i,"0");
		m_list1.SetItemText(i,0,num);
		m_list1.SetItemText(i,1,name);
		m_list1.SetItemText(i,2,yuwen);
		m_list1.SetItemText(i,3,shuxue);
		m_list1.SetItemText(i,4,yingyu);
		m_list1.SetItemText(i,5,wuli);
		m_list1.SetItemText(i,6,huaxue);
		m_pRecordset->MoveNext();
		
		
		i++;

		}
		

	}

}

void CStudentdlg::OnClickList3(NMHDR* pNMHDR, LRESULT* pResult) 
{
    nCurSel2=m_list3.GetNextItem(-1,LVNI_ALL | LVNI_SELECTED);
	nCurSel=-1;
	nCurSel1=-1;
	*pResult = 0;
}

void CStudentdlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	nCurSel1=m_list1.GetNextItem(-1,LVNI_ALL | LVNI_SELECTED);
	nCurSel=-1;
	nCurSel2=-1;
	
	*pResult = 0;
}

void CStudentdlg::OnSelchangeCombo3() 
{
	CStudentdlg::OnShow();
	
}

#include "resource.h"
void CStudentdlg::OnContextMenu(CWnd*, CPoint point)
{
	// CG: This block was added by the Pop-up Menu component	{		if (point.x == -1 && point.y == -1){			//keystroke invocation			CRect rect;			GetClientRect(rect);			ClientToScreen(rect);			point = rect.TopLeft();			point.Offset(5, 5);		}		CMenu menu;		VERIFY(menu.LoadMenu(CG_IDR_POPUP_STUDENTDLG));		CMenu* pPopup = menu.GetSubMenu(0);		ASSERT(pPopup != NULL);		CWnd* pWndPopupOwner = this;		while (pWndPopupOwner->GetStyle() & WS_CHILD)			pWndPopupOwner = pWndPopupOwner->GetParent();		pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,			pWndPopupOwner);	}
}

void CStudentdlg::OnRclickList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	nCurSel1=m_list1.GetNextItem(-1,LVNI_ALL | LVNI_SELECTED);
	nCurSel=-1;
	nCurSel2=-1;
	
	*pResult = 0;
}

void CStudentdlg::OnRclickList2(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	nCurSel=m_list1.GetNextItem(-1,LVNI_ALL | LVNI_SELECTED);
	nCurSel2=-1;
	nCurSel1=-1;
	
	*pResult = 0;
}

void CStudentdlg::OnRclickList3(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	nCurSel2=m_list3.GetNextItem(-1,LVNI_ALL | LVNI_SELECTED);
	nCurSel=-1;
	nCurSel1=-1;
	
	*pResult = 0;
}

void CStudentdlg::OnEditRshow() 
{
	CStudentdlg::OnShow();
     	
}

void CStudentdlg::OnEditEappend() 
{
	CStudentdlg::OnAPPEND();
   	
}

void CStudentdlg::OnEditRdelete() 
{
	CStudentdlg::OnDelete();
 	
}

void CStudentdlg::OnEditRedit() 
{
	CStudentdlg::OnEdit();
 	
}

void CStudentdlg::OnEditRsearch() 
{
	CStudentdlg::OnFind();
 	
}

⌨️ 快捷键说明

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