📄 studentdlg.cpp
字号:
m_recordset.m_honor_date2 =Dlg.m_strHonorDate2 ;
m_recordset.m_honor_date3 =Dlg.m_strHonorDate3 ;
m_recordset.m_honor_date4 =Dlg.m_strHonorDate4 ;
m_recordset.m_honor_date5 =Dlg.m_strHonorDate5 ;
m_recordset.m_honor_date6 =Dlg.m_strHonorDate6 ;
m_recordset.m_family_phone1 =Dlg.m_strPhone1 ;
m_recordset.m_family_phone2 =Dlg.m_strPhone2 ;
m_recordset.m_family_phone3 =Dlg.m_strPhone3 ;
m_recordset.m_political =Dlg.m_strPolitical ;
m_recordset.m_family_political1 =Dlg.m_strPolitical1 ;
m_recordset.m_family_political2 =Dlg.m_strPolitical3 ;
m_recordset.m_family_political3 =Dlg.m_strPolitical2 ;
m_recordset.m_postcode =Dlg.m_strPostCode ;
m_recordset.m_family_relation1 =Dlg.m_strRelation1 ;
m_recordset.m_family_relation2 =Dlg.m_strRelation2 ;
m_recordset.m_family_relation3 =Dlg.m_strRelation3 ;
m_recordset.m_honor_remark1 =Dlg.m_strRemark1 ;
m_recordset.m_honor_remark2 =Dlg.m_strRemark2 ;
m_recordset.m_honor_remark3 =Dlg.m_strRemark3 ;
m_recordset.m_honor_remark4 =Dlg.m_strRemark4 ;
m_recordset.m_honor_remark5 =Dlg.m_strRemark5 ;
m_recordset.m_honor_remark6 =Dlg.m_strRemark6 ;
m_recordset.m_term1 =Dlg.m_strScore1 ;
m_recordset.m_term10 =Dlg.m_strScore10 ;
m_recordset.m_term2 =Dlg.m_strScore2 ;
m_recordset.m_term3 =Dlg.m_strScore3 ;
m_recordset.m_term4 =Dlg.m_strScore4 ;
m_recordset.m_term5 =Dlg.m_strScore5 ;
m_recordset.m_term6 =Dlg.m_strScore6 ;
m_recordset.m_term7 =Dlg.m_strScore7 ;
m_recordset.m_term8 =Dlg.m_strScore8 ;
m_recordset.m_term9 =Dlg.m_strScore9 ;
m_recordset.m_code =Dlg.m_strCode ;
m_recordset.m_name =Dlg.m_strName ;
m_recordset.Update();
m_recordset.Close();
strSQL = "select * from student ";
RefreshData(strSQL);
}
}
void CStudentDlg::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 student where code = '%s'",m_ctrList.GetItemText(i,0));
if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
{
AfxMessageBox("打开数据库失败!");
return ;
}
m_recordset.Delete();
m_recordset.Close();
strSQL = "select * from student";
RefreshData(strSQL);
}
void CStudentDlg::OnButtonBrowse()
{
// TODO: Add your control notification handler code here
CStudentInfoDlg Dlg;
UpdateData();
int i = m_ctrList.GetSelectionMark();
if(0>i)
{
AfxMessageBox("请选择一条记录进行查看!");
return;
}
Dlg.m_strCode=m_ctrList.GetItemText(i,0);
Dlg.DoModal();
}
void CStudentDlg::OnSetfocusComboMajor()
{
// TODO: Add your control notification handler code here
UpdateData();
CString strSQL;
//清空ComboBox查询内容//////////////////////
int nCount=m_ctrMajor.GetCount();
for(int i=0;i<nCount;i++)
{
m_ctrMajor.DeleteString(0);
}
nCount=m_ctrClass.GetCount();
for(i=0;i<nCount;i++)
{
m_ctrClass.DeleteString(0);
}
///////////////////////////////////////////
CMajorSet recordset ;
strSQL.Format( "select * from major where department = '%s'",m_strDepartment);
if(!recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
{
MessageBox("打开数据库失败!","数据库错误",MB_OK);
return ;
}
while(!recordset.IsEOF())
{
m_ctrMajor.AddString(recordset.m_name);
recordset.MoveNext();
}
recordset.Close();
}
void CStudentDlg::OnSetfocusComboClass()
{
// TODO: Add your control notification handler code here
UpdateData();
CString strSQL;
//清空ComboBox查询内容//////////////////////
int nCount=m_ctrClass.GetCount();
for(int i=0;i<nCount;i++)
{
m_ctrClass.DeleteString(0);
}
///////////////////////////////////////////
CClassSet recordset ;
strSQL.Format( "select * from class where department = '%s' and major = '%s'",m_strDepartment,m_strMajor);
if(!recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
{
MessageBox("打开数据库失败!","数据库错误",MB_OK);
return ;
}
while(!recordset.IsEOF())
{
m_ctrClass.AddString(recordset.m_name);
recordset.MoveNext();
}
recordset.Close();
}
void CStudentDlg::OnSelchangeComboDepartment()
{
// TODO: Add your control notification handler code here
UpdateData();
//清空ComboBox查询内容//////////////////////
int nCount=m_ctrMajor.GetCount();
for(int i=0;i<nCount;i++)
{
m_ctrMajor.DeleteString(0);
}
nCount=m_ctrClass.GetCount();
for(i=0;i<nCount;i++)
{
m_ctrClass.DeleteString(0);
}
///////////////////////////////////////////
}
void CStudentDlg::OnSelchangeComboMajor()
{
// TODO: Add your control notification handler code here
UpdateData();
//清空ComboBox查询内容//////////////////////
int nCount=m_ctrClass.GetCount();
for(int i=0;i<nCount;i++)
{
m_ctrClass.DeleteString(0);
}
///////////////////////////////////////////
}
void CStudentDlg::OnButtonSearch()
{
// TODO: Add your control notification handler code here
UpdateData();
CString strSQL,strTemp;
strTemp="";
BOOL bHaveCon = FALSE;
if(m_strDepartment!="")
{
strSQL.Format("select * from student where department = '%s' ",m_strDepartment);
bHaveCon = TRUE;
}
if(m_strMajor!="")
{
if(bHaveCon)
{
strTemp.Format(" major = '%s' ",m_strMajor);
strSQL=strSQL + " and " + strTemp;
}
else
{
strSQL.Format("select * from student where major = '%s' ",m_strMajor);
}
bHaveCon=TRUE;
}
if(m_strClass!="")
{
if(bHaveCon)
{
strTemp.Format(" class = '%s' ",m_strClass);
strSQL=strSQL + " and " + strTemp;
}
else
{
strSQL.Format("select * from student where class = '%s' ",m_strClass);
}
bHaveCon=TRUE;
}
if(!bHaveCon)
{
strSQL="select * from student";
}
RefreshData(strSQL);
}
void CStudentDlg::RefreshData(CString strSQL)
{
m_ctrList.DeleteAllItems();
m_ctrList.SetRedraw(FALSE);
UpdateData(TRUE);
// strSQL="select * from dept";
if(!m_recordset.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
{
MessageBox("打开数据库失败!","数据库错误",MB_OK);
return ;
}
int i=0;
CString strTime;
while(!m_recordset.IsEOF())
{
m_ctrList.InsertItem(i,m_recordset.m_code);
m_ctrList.SetItemText(i,1,m_recordset.m_name);
m_ctrList.SetItemText(i,2,m_recordset.m_oldname);
m_ctrList.SetItemText(i,3,m_recordset.m_sex);
strTime.Format("%d-%d-%d",m_recordset.m_birthday.GetYear(),m_recordset.m_birthday.GetMonth(),m_recordset.m_birthday.GetDay());
m_ctrList.SetItemText(i,4,strTime);
m_ctrList.SetItemText(i,5,m_recordset.m_folk);
m_ctrList.SetItemText(i,6,m_recordset.m_political);
m_ctrList.SetItemText(i,7,m_recordset.m_native);
m_ctrList.SetItemText(i,8,m_recordset.m_family);
m_ctrList.SetItemText(i,9,m_recordset.m_phone);
m_ctrList.SetItemText(i,10,m_recordset.m_postcode);
m_ctrList.SetItemText(i,11,m_recordset.m_address);
m_ctrList.SetItemText(i,12,m_recordset.m_IDCard);
strTime.Format("%d-%d-%d",m_recordset.m_enroll_date.GetYear(),m_recordset.m_enroll_date.GetMonth(),m_recordset.m_enroll_date.GetDay());
m_ctrList.SetItemText(i,13,strTime);
strTime.Format("%d-%d-%d",m_recordset.m_graduate_date.GetYear(),m_recordset.m_graduate_date.GetMonth(),m_recordset.m_graduate_date.GetDay());
m_ctrList.SetItemText(i,14,strTime);
m_ctrList.SetItemText(i,15,m_recordset.m_class);
m_ctrList.SetItemText(i,16,m_recordset.m_department);
m_ctrList.SetItemText(i,17,m_recordset.m_major);
i++;
m_recordset.MoveNext();
}
m_recordset.Close();
m_ctrList.SetRedraw(TRUE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -