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

📄 studentsearch.cpp

📁 学生选课系统
💻 CPP
字号:
// StudentSearch.cpp : implementation file
//

#include "stdafx.h"
#include "SC.h"
#include "StudentSearch.h"
#include "Student.h"

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

/////////////////////////////////////////////////////////////////////////////
// CStudentSearch dialog


CStudentSearch::CStudentSearch(CWnd* pParent /*=NULL*/)
	: CDialog(CStudentSearch::IDD, pParent)
{
	//{{AFX_DATA_INIT(CStudentSearch)
	m_strAge2 = _T("");
	m_strDept = _T("");
	m_strName = _T("");
	m_strNo2 = _T("");
	m_strSex = _T("");
	m_strAge = _T("");
	m_strNo = _T("");
	//}}AFX_DATA_INIT
}


void CStudentSearch::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CStudentSearch)
	DDX_CBString(pDX, IDC_SEARCH_AGE_2, m_strAge2);
	DDX_Text(pDX, IDC_SEARCH_DEPT, m_strDept);
	DDX_Text(pDX, IDC_SEARCH_NAME, m_strName);
	DDX_CBString(pDX, IDC_SEARCH_NO_2, m_strNo2);
	DDX_CBString(pDX, IDC_SEARCH_SEX, m_strSex);
	DDX_Text(pDX, IDC_SEARCH_AGE, m_strAge);
	DDX_Text(pDX, IDC_SEARCH_NO, m_strNo);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CStudentSearch, CDialog)
	//{{AFX_MSG_MAP(CStudentSearch)
	ON_BN_CLICKED(IDC_S_SEARCH, OnSSearch)
	ON_EN_CHANGE(IDC_SEARCH_NO, OnChangeSearchNo)
	ON_EN_CHANGE(IDC_SEARCH_AGE, OnChangeSearchAge)
	ON_BN_CLICKED(IDC_S_RESET, OnSReset)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStudentSearch message handlers

BOOL CStudentSearch::OnInitDialog()
{
	CDialog::OnInitDialog();

	CComboBox *SS_NO2=(CComboBox*)GetDlgItem(IDC_SEARCH_NO_2);
	CComboBox *SS_AGE2=(CComboBox*)GetDlgItem(IDC_SEARCH_AGE_2);

	CEdit *No=(CEdit*)GetDlgItem(IDC_SEARCH_NO);
	CEdit *AGE=(CEdit*)GetDlgItem(IDC_SEARCH_AGE);

	No->SetWindowText("");
	AGE->SetWindowText("");

	SS_NO2->SetCurSel(0);
	SS_AGE2->SetCurSel(0);

	//SS_SQL->SetWindowText(m_strSQL);

	return TRUE;
}

void CStudentSearch::OnSSearch() 
{
	// TODO: Add your control notification handler code here

	UpdateData(TRUE);

	if(m_strNo.IsEmpty()==1&&m_strName.IsEmpty()==1&&m_strAge.IsEmpty()==1
		&&m_strSex.IsEmpty()==1&&m_strDept.IsEmpty()==1)	return;
	m_SQL="SELECT * FROM STUDENT WHERE ";
	int i=0;
	CString str[5];

	if(m_strNo.IsEmpty()==0)
	{
		str[i]="Sno"+m_strNo2+m_strNo;
		i++;
	}
	if(m_strName.IsEmpty()==0)
	{
		str[i]="Sname='"+m_strName+"'";
		i++;
	}
	if(m_strAge.IsEmpty()==0)
	{
		str[i]="Sage"+m_strAge2+m_strAge;
		i++;
	}
	if(m_strSex.IsEmpty()==0)
	{
		str[i]="Ssex='"+m_strSex+"'";
		i++;
	}
	if(m_strDept.IsEmpty()==0)
	{
		str[i]="Sdept='"+m_strDept+"'";
		i++;
	}
	for(i=0;i<5;i++)
	{
		if(i==0)
			if(str[i].IsEmpty()==0) m_SQL+=str[i];
		else if(str[i].IsEmpty()==0) m_SQL+=" AND "+str[i];
	}

	CStudent *pMain=(CStudent*)AfxGetApp()->GetMainWnd();
	pMain->m_strSQL=m_SQL;
	//pMain=(CStudent *)AfxGetApp()->m_pMainWnd;   
	//pMain->m_strSQL=m_SQL;
	//pMain->UpdateData(TRUE);
	MessageBox(pMain->m_strSQL);

	this->EndDialog(0);
	
}

void CStudentSearch::OnChangeSearchNo() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	CEdit *no=(CEdit*)GetDlgItem(IDC_SEARCH_NO);

	UpdateData(TRUE);

	CString t_no;
	t_no=m_strNo;
	if(t_no.IsEmpty()==1) return;
	else if(t_no.GetAt(t_no.GetLength()-1)<48||t_no.GetAt(t_no.GetLength()-1)>57)
	{
		t_no.Delete(t_no.GetLength()-1);
		no->SetWindowText(t_no);
	}
}

void CStudentSearch::OnChangeSearchAge() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
	CEdit *age=(CEdit*)GetDlgItem(IDC_SEARCH_AGE);

	UpdateData(TRUE);

	CString t_age;
	t_age=m_strAge;
	if(t_age.IsEmpty()==1) return;
	else if(t_age.GetAt(t_age.GetLength()-1)<48||t_age.GetAt(t_age.GetLength()-1)>57)
	{
		t_age.Delete(t_age.GetLength()-1);
		age->SetWindowText(t_age);
	}
}

void CStudentSearch::OnSReset() 
{
	// TODO: Add your control notification handler code here
	CComboBox *SS_NO2=(CComboBox*)GetDlgItem(IDC_SEARCH_NO_2);
	CComboBox *SS_AGE2=(CComboBox*)GetDlgItem(IDC_SEARCH_AGE_2);
	CComboBox *Sex=(CComboBox*)GetDlgItem(IDC_SEARCH_SEX);

	CEdit *No=(CEdit*)GetDlgItem(IDC_SEARCH_NO);
	CEdit *AGE=(CEdit*)GetDlgItem(IDC_SEARCH_AGE);
	CEdit *Name=(CEdit*)GetDlgItem(IDC_SEARCH_NAME);
	CEdit *Dept=(CEdit*)GetDlgItem(IDC_SEARCH_DEPT);

	No->SetWindowText("");
	AGE->SetWindowText("");
	Name->SetWindowText("");
	Dept->SetWindowText("");
	Sex->SetCurSel(0);
	SS_NO2->SetCurSel(0);
	SS_AGE2->SetCurSel(0);
}

⌨️ 快捷键说明

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