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

📄 generalquerydlg.cpp

📁 &#61557 职责描述:
💻 CPP
字号:
// GeneralQueryDlg.cpp : implementation file
//

#include "StdAfx.h"
#include "StudentCheck.h"
#include "GeneralQueryDlg.h"
#include ".\generalquerydlg.h"


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

/////////////////////////////////////////////////////////////////////////////
// CGeneralQueryDlg dialog


CGeneralQueryDlg::CGeneralQueryDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CGeneralQueryDlg::IDD, pParent)
	//, m_STime(0)
	//, m_ETime(0)
	//, m_strTime(_T(""))
	, m_strStudentNum(_T(""))
{
	CTime End_t=CTime::GetCurrentTime();//取得当前值
	CTimeSpan tp(30,0,0,0); //时间间隔为30天
	//{{AFX_DATA_INIT(CGeneralQueryDlg)
	m_strTime=End_t.Format("%Y-%m-%d");
	m_STime=End_t-tp;
	m_ETime=End_t;
	m_bClass = FALSE;
	m_bGrade = FALSE;
	m_bSpecialty = FALSE;
	m_bStudentNum = FALSE;
	m_strClass = _T("");
	m_strGrade = _T("");
	m_strSpecialty = _T("");
	//}}AFX_DATA_INIT
}


void CGeneralQueryDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGeneralQueryDlg)
	DDX_Control(pDX, IDC_CMB_SPECIALTY, m_cmbSpecialty);
	DDX_Control(pDX, IDC_CMB_GRADE, m_cmbGrade);
	DDX_Control(pDX, IDC_CMB_CLASS, m_cmbClass);
	DDX_Control(pDX, IDC_CHECK_STUDENTNUM, m_btnStudentNum);
	DDX_Control(pDX, IDC_CHECK_SPECIALTY, m_btnSpecialty);
	DDX_Control(pDX, IDC_CHECK_GRADE, m_btnGrade);
	DDX_Control(pDX, IDC_CHECK_CLASS, m_btnClass);
	DDX_Check(pDX, IDC_CHECK_CLASS, m_bClass);
	DDX_Check(pDX, IDC_CHECK_GRADE, m_bGrade);
	DDX_Check(pDX, IDC_CHECK_SPECIALTY, m_bSpecialty);
	DDX_Check(pDX, IDC_CHECK_STUDENTNUM, m_bStudentNum);
	DDX_CBString(pDX, IDC_CMB_CLASS, m_strClass);
	DDX_CBString(pDX, IDC_CMB_GRADE, m_strGrade);
	DDX_CBString(pDX, IDC_CMB_SPECIALTY, m_strSpecialty);
	//}}AFX_DATA_MAP
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_START, m_STime);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_END, m_ETime);
	DDX_Text(pDX, IDC_STATIC_DATE, m_strTime);
	DDX_Text(pDX, IDC_EDIT_STUDENTNUM, m_strStudentNum);
}


BEGIN_MESSAGE_MAP(CGeneralQueryDlg, CDialog)
	//{{AFX_MSG_MAP(CGeneralQueryDlg)
	//}}AFX_MSG_MAP
	ON_CBN_SELCHANGE(IDC_CMB_GRADE, OnCbnSelchangeCmbGrade)
	ON_CBN_SELCHANGE(IDC_CMB_SPECIALTY, OnCbnSelchangeCmbSpecialty)
	ON_BN_CLICKED(IDC_CHECK_GRADE, OnBnClickedCheckGrade)
	ON_BN_CLICKED(IDC_CHECK_STUDENTNUM, OnBnClickedCheckStudentnum)
	ON_BN_CLICKED(IDC_CHECK_SPECIALTY, OnBnClickedCheckSpecialty)
	ON_BN_CLICKED(IDC_CHECK_CLASS, OnBnClickedCheckClass)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGeneralQueryDlg message handlers

BOOL CGeneralQueryDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	

	//初始化Grade下拉框
	InitGradeCombox();

	//初始化Specialty下拉框
	InitSpecialtyCombox();

	//初始化Class下拉框
	InitClassCombox();

	this->m_Sheet.AddPage(&m_ExcercisePage);//加出操页
	this->m_Sheet.AddPage(&m_CoursePage);//课堂页
	this->m_Sheet.AddPage(&m_ActivityPage);//活动页
	this->m_Sheet.AddPage(&m_DormPage);//寝室页
	this->m_Sheet.Create(this,WS_CHILD|WS_VISIBLE,0);//创建窗口
	this->m_Sheet.ModifyStyleEx(0,WS_EX_CONTROLPARENT);//修改风格
	this->m_Sheet.ModifyStyle(0,WS_TABSTOP);//修改风格

	//设置窗口位置
	this->m_Sheet.SetWindowPos(NULL,7,200,0,0,SWP_NOZORDER|SWP_NOSIZE|SWP_NOACTIVATE);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CGeneralQueryDlg::InitGradeCombox()
{
	int i=0;
	_bstr_t vSql;
	m_GradeID.RemoveAll();
	m_GradeName.RemoveAll();
	m_cmbGrade.ResetContent();
	//SQL语句
	vSql="Select GradeID,GradeName from Grade order by GradeID";
	m_CurAdo.GetRecordSet(vSql);

	_RecordsetPtr pRs;
	pRs=m_CurAdo.GetRecordSet(vSql);

	//获取记录集中的数据
	while(pRs->adoEOF==0)
	{
		m_GradeID.Add((LPCTSTR)(_bstr_t)pRs->GetCollect("GradeID"));
		m_GradeName.Add((LPCTSTR)(_bstr_t)pRs->GetCollect("GradeName"));

		m_cmbGrade.AddString(m_GradeName.GetAt(i));
		i++;
		pRs->MoveNext();
	}

	for(int j=0;j<m_GradeID.GetSize();j++)
	{
		m_cmbGrade.SetItemData(j,atoi(m_GradeID.GetAt(j)));
	}

}

void CGeneralQueryDlg::InitSpecialtyCombox(void)
{
	int i=0;
	_bstr_t vSql;
	m_SpecialtyID.RemoveAll();
	m_SpecialtyName.RemoveAll();
	m_cmbSpecialty.ResetContent();
	//SQL语句
	vSql="Select SpecialtyID,SpecialtyName from Specialty order by SpecialtyID";
	m_CurAdo.GetRecordSet(vSql);

	_RecordsetPtr pRs;
	pRs=m_CurAdo.GetRecordSet(vSql);

	//获取记录集中的数据
	while(pRs->adoEOF==0)
	{
		m_SpecialtyID.Add((LPCTSTR)(_bstr_t)pRs->GetCollect("SpecialtyID"));
		m_SpecialtyName.Add((LPCTSTR)(_bstr_t)pRs->GetCollect("SpecialtyName"));

		m_cmbSpecialty.AddString(m_SpecialtyName.GetAt(i));
		i++;
		pRs->MoveNext();
	}

	for(int j=0;j<m_SpecialtyID.GetSize();j++)
	{
		m_cmbSpecialty.SetItemData(j,atoi(m_SpecialtyID.GetAt(j)));
	}
}

void CGeneralQueryDlg::InitClassCombox(void)
{
	int i=0;
	_bstr_t vSql;
	m_ClassID.RemoveAll();
	m_ClassName.RemoveAll();
	m_cmbClass.ResetContent();
	//SQL语句
	vSql="Select ClassID,ClassName from Class order by ClassID";
	m_CurAdo.GetRecordSet(vSql);

	_RecordsetPtr pRs;
	pRs=m_CurAdo.GetRecordSet(vSql);

	//获取记录集中的数据
	while(pRs->adoEOF==0)
	{
		m_ClassID.Add((LPCTSTR)(_bstr_t)pRs->GetCollect("ClassID"));
		m_ClassName.Add((LPCTSTR)(_bstr_t)pRs->GetCollect("ClassName"));

		m_cmbClass.AddString(m_ClassName.GetAt(i));
		i++;
		pRs->MoveNext();
	}

	for(int j=0;j<m_ClassID.GetSize();j++)
	{
		m_cmbClass.SetItemData(j,atoi(m_ClassID.GetAt(j)));
	}
}

void CGeneralQueryDlg::ClassDataBindByGrade(CString GradeID)
{
	int i=0;
	_bstr_t vSql;
	m_ClassID.RemoveAll();
	m_ClassName.RemoveAll();
	m_cmbClass.ResetContent();
	//SQL语句
	vSql="Select ClassID,ClassName from Class  Where GradeID='"+GradeID+"'  order by ClassID";
	m_CurAdo.GetRecordSet(vSql);

	_RecordsetPtr pRs;
	pRs=m_CurAdo.GetRecordSet(vSql);

	//获取记录集中的数据
	while(pRs->adoEOF==0)
	{
		m_ClassID.Add((LPCTSTR)(_bstr_t)pRs->GetCollect("ClassID"));
		m_ClassName.Add((LPCTSTR)(_bstr_t)pRs->GetCollect("ClassName"));

		m_cmbClass.AddString(m_ClassName.GetAt(i));
		i++;
		pRs->MoveNext();
	}

	for(int j=0;j<m_ClassID.GetSize();j++)
	{
		m_cmbClass.SetItemData(j,atoi(m_ClassID.GetAt(j)));
	}
}

void CGeneralQueryDlg::ClassDataBindBySpecialty(CString SpecialtyID)
{
	int i=0;
	_bstr_t vSql;
	m_ClassID.RemoveAll();
	m_ClassName.RemoveAll();
	m_cmbClass.ResetContent();
	//SQL语句
	vSql="Select ClassID,ClassName from Class  Where SpecialtyID='"+SpecialtyID+"'  order by ClassID";
	m_CurAdo.GetRecordSet(vSql);

	_RecordsetPtr pRs;
	pRs=m_CurAdo.GetRecordSet(vSql);

	//获取记录集中的数据
	while(pRs->adoEOF==0)
	{
		m_ClassID.Add((LPCTSTR)(_bstr_t)pRs->GetCollect("ClassID"));
		m_ClassName.Add((LPCTSTR)(_bstr_t)pRs->GetCollect("ClassName"));

		m_cmbClass.AddString(m_ClassName.GetAt(i));
		i++;
		pRs->MoveNext();
	}

	for(int j=0;j<m_ClassID.GetSize();j++)
	{
		m_cmbClass.SetItemData(j,atoi(m_ClassID.GetAt(j)));
	}
}

void CGeneralQueryDlg::ClassDataBindByGradeSpecialty(CString GradeID, CString SpecialtyID)
{
	int i=0;
	_bstr_t vSql;
	m_ClassID.RemoveAll();
	m_ClassName.RemoveAll();
	m_cmbClass.ResetContent();
	//SQL语句
	vSql="Select ClassID,ClassName from Class  Where SpecialtyID='"+SpecialtyID+"'  and GradeID='"+GradeID+"'   order by ClassID";
	m_CurAdo.GetRecordSet(vSql);

	_RecordsetPtr pRs;
	pRs=m_CurAdo.GetRecordSet(vSql);

	//获取记录集中的数据
	while(pRs->adoEOF==0)
	{
		m_ClassID.Add((LPCTSTR)(_bstr_t)pRs->GetCollect("ClassID"));
		m_ClassName.Add((LPCTSTR)(_bstr_t)pRs->GetCollect("ClassName"));

		m_cmbClass.AddString(m_ClassName.GetAt(i));
		i++;
		pRs->MoveNext();
	}

	for(int j=0;j<m_ClassID.GetSize();j++)
	{
		m_cmbClass.SetItemData(j,atoi(m_ClassID.GetAt(j)));
	}
}

void CGeneralQueryDlg::OnCbnSelchangeCmbGrade()
{
	//取得当前选中的项的值
	int nGradeIndex=this->m_cmbGrade.GetCurSel();
	int nSpecialtyIndex=this->m_cmbSpecialty.GetCurSel();

	//根据索引号得到GradeID值
	DWORD dGradeID=this->m_cmbGrade.GetItemData(nGradeIndex);

	//将DWORD各式转换成字符串各式的
	CString strGradeID;
	strGradeID.Format(_T("%d"),dGradeID);

	//根据索引号得到SpecialtyID值
	DWORD dSpecialtyID=this->m_cmbSpecialty.GetItemData(nSpecialtyIndex);

	//将DWORD各式转换成字符串各式的
	CString strSpecialtyID;
	strSpecialtyID.Format(_T("%d"),dSpecialtyID);
	if(nSpecialtyIndex<0)
	{

		//通过得到的GradeID动态绑定班级下拉框
		this->ClassDataBindByGrade(strGradeID);
	}
	else
		this->ClassDataBindByGradeSpecialty(strGradeID,strSpecialtyID);
	
}

void CGeneralQueryDlg::OnCbnSelchangeCmbSpecialty()
{
	//取得当前选中的项的值
	int nSpecialtyIndex=this->m_cmbSpecialty.GetCurSel();
	int nGradeIndex=this->m_cmbGrade.GetCurSel();

	//根据索引号得到SpecialtyID值
	DWORD dSpecialtyID=this->m_cmbSpecialty.GetItemData(nSpecialtyIndex);

	//将DWORD各式转换成字符串各式的
	CString strSpecialtyID;
	strSpecialtyID.Format(_T("%d"),dSpecialtyID);

	//根据索引号得到GradeID值
	DWORD dGradeID=this->m_cmbGrade.GetItemData(nGradeIndex);

	//将DWORD各式转换成字符串各式的
	CString strGradeID;
	strGradeID.Format(_T("%d"),dGradeID);
	
	if(this->m_cmbGrade.GetCurSel()<0)
	{

		//通过得到的SpecialtyID动态绑定班级下拉框
		this->ClassDataBindBySpecialty(strSpecialtyID);
	}
	else
		this->ClassDataBindByGradeSpecialty(strGradeID,strSpecialtyID);
	
}
void CGeneralQueryDlg::OnBnClickedCheckGrade()
{
	if(this->m_btnGrade.GetCheck()>0&&this->m_btnStudentNum.GetCheck()>0)
		this->m_btnStudentNum.SetCheck(BST_UNCHECKED);		
}

void CGeneralQueryDlg::OnBnClickedCheckStudentnum()
{
	if((this->m_btnStudentNum.GetCheck()>0&&this->m_btnGrade.GetCheck()>0)||
		(this->m_btnStudentNum.GetCheck()>0&&this->m_btnSpecialty.GetCheck()>0)||
		(this->m_btnStudentNum.GetCheck()>0&&this->m_btnClass.GetCheck()>0))
	{
		this->m_btnGrade.SetCheck(BST_UNCHECKED);
		this->m_btnSpecialty.SetCheck(BST_UNCHECKED);
		this->m_btnClass.SetCheck(BST_UNCHECKED);
	}
}



void CGeneralQueryDlg::OnBnClickedCheckSpecialty()
{
	if((this->m_btnStudentNum.GetCheck()>0&&this->m_btnSpecialty.GetCheck()>0))
		this->m_btnStudentNum.SetCheck(BST_UNCHECKED);
}

void CGeneralQueryDlg::OnBnClickedCheckClass()
{
	if((this->m_btnStudentNum.GetCheck()>0&&this->m_btnClass.GetCheck()>0))
		this->m_btnStudentNum.SetCheck(BST_UNCHECKED);
}

BOOL CGeneralQueryDlg::IsSelected()
{
	if(this->m_btnGrade.GetCheck()>0&&this->m_cmbGrade.GetCurSel()<0)
	{
		MessageBox("请选择年级!","错误提示");
		return FALSE;
	}
	if(this->m_btnSpecialty.GetCheck()>0&&this->m_cmbSpecialty.GetCurSel()<0)
	{
		MessageBox("请选择专业!","错误提示");
		return FALSE;
	}
	if(this->m_btnClass.GetCheck()>0&&this->m_cmbClass.GetCurSel()<0)
	{
		MessageBox("请选择班级!","错误提示");
		return FALSE;
	}
	if(this->m_btnStudentNum.GetCheck()>0&&this->m_strStudentNum.IsEmpty())
	{
		MessageBox("请输入学号!","错误提示");
		return FALSE;
	}
	return TRUE;
}

CString CGeneralQueryDlg::GetStartTime(void)
{
	CString strTime;
	strTime=this->m_STime.Format("%Y-%m-%d");
	return strTime;
}

CString CGeneralQueryDlg::GetEndTime(void)
{
	CString strTime;
	strTime=this->m_ETime.Format("%Y-%m-%d");
	return strTime;
}



CString CGeneralQueryDlg::GetGrade(void)
{
	CString strGradeID;
	//取得当前选中的项的值
	int nGradeIndex=this->m_cmbGrade.GetCurSel();
	if(nGradeIndex>=0)
	{
		//根据索引号得到GradeID值
		DWORD dGradeID=this->m_cmbGrade.GetItemData(nGradeIndex);
		//将DWORD各式转换成字符串各式的
		strGradeID.Format(_T("%d"),dGradeID);
	}
	return strGradeID;
}

CString CGeneralQueryDlg::GetSpecialty(void)
{
	CString strSpecialtyID;
	//取得当前选中的项的值
	int nSpecialtyIndex=this->m_cmbSpecialty.GetCurSel();
	if(nSpecialtyIndex>=0)
	{
		//根据索引号得到SpecialtyID值
		DWORD dSpecialtyID=this->m_cmbSpecialty.GetItemData(nSpecialtyIndex);
		//将DWORD各式转换成字符串各式的
		strSpecialtyID.Format(_T("%d"),dSpecialtyID);
	}
	return strSpecialtyID;
}

CString CGeneralQueryDlg::GetClass(void)
{
	CString strClassID;
	//取得当前选中的项的值
	int nClassIndex=this->m_cmbClass.GetCurSel();
	if(nClassIndex>=0)
	{
		//根据索引号得到ClassID值
		DWORD dClassID=this->m_cmbClass.GetItemData(nClassIndex);
		//将DWORD各式转换成字符串各式的
		strClassID.Format(_T("%d"),dClassID);
	}
	return strClassID;
}

CString CGeneralQueryDlg::GetStudentNum(void)
{
	
	CString strStudentNum;
	//取得当前选中的项的值
	strStudentNum=m_strStudentNum;
	
	return strStudentNum;
}

⌨️ 快捷键说明

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