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

📄 course.cpp

📁 &#61557 职责描述:
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	if (InsertStuAct()) 
		AfxMessageBox("成功保存数据!");	
}

void CCourse::OnExit() 
{
	this->OnOK();		
}

BOOL CCourse::InsertStuAct()
{
	CString strStuNum,strCourseID,strTime;
	_bstr_t vSQL;
	int nCheck,nUnCheck;
	nCheck=0;
	nUnCheck=0;

	strCourseID.Format("%d",m_cmbAct.GetItemData(m_cmbAct.GetCurSel()));
	strTime=Time;	

	if (m_StuActList.GetItemCount()<=0)
	{
		AfxMessageBox("列表控件里,无学生记录!!!");
		return false;
	}
	//插入所有该班的学生
	for(int i=0 ; i< m_StuActList.GetItemCount(); i++)
	{	
			//判断该学生是否参加该活动
			if (iCheck[i])
			{	
				//参加活动的学生要小于,sa_CheckOn实际存储的
				if (nCheck<sa_CheckOn.GetSize())
				{
					//参加活动的学生
					strStuNum=sa_CheckOn.GetAt(nCheck);	
					vSQL="Insert into StuCourse(StudentNum,CourseID,CourDateTime ,IsCourse)\
					VALUES ( '" +strStuNum +"','"+strCourseID+"','"+strTime+"','1')";
					m_CurAdo.ExecuteSQL(vSQL);
					nCheck++;
				}

			}
			else
			{
				//不参加活动的学生要小于,sa_CheckNot实际存储的
				if (nUnCheck<sa_CheckNot.GetSize())
				{
					//没参加活动学生
					strStuNum=sa_CheckNot.GetAt(nUnCheck);
					vSQL="Insert into StuCourse(StudentNum,CourseID,CourDateTime ,IsCourse)\
					VALUES ( '" +strStuNum +"','"+strCourseID+"','"+strTime+"','0')";
					m_CurAdo.ExecuteSQL(vSQL);
					nUnCheck++;
				}

			}														      			
	}

    return true;
}

void CCourse::OnClickMemberList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;

	//若鼠标没有点击listCtrl中的项,则不执行以下操作
   CString str1;	
   if (phdn->iItem < 0)
		return;
  	 
    CString strTemp;
	strTemp.Format("%d", m_StuActList.GetItemData(phdn->iItem));
//	
	if ( strTemp.GetLength()>8 )
	{
		//获的是学号,标识为非查询
		//保存按钮时,对列表复选框的操作 
		if (iCheck[phdn->iItem])
		{
			iCheck[phdn->iItem] = 0;
			m_StuActList.SetCheck(phdn->iItem, FALSE);
		}
		else
		{
			iCheck[phdn->iItem] = 1;
			m_StuActList.SetCheck(phdn->iItem);
		}
	}
	else
	{
		//获的ID,标识查询
		//修改按钮时,对列表复选框的操作
		//若修改,要通知查询,已经修改,

		if (iModyCheck[phdn->iItem])  //为的是和查询数据库里的做对比
		{                             //记录变化的数据,以便用来更新
			iModyCheck[phdn->iItem] = 0;
			m_StuActList.SetCheck(phdn->iItem, FALSE);
		}
		else
		{
			iModyCheck[phdn->iItem] = 1;
			m_StuActList.SetCheck(phdn->iItem);
		}
	}


	*pResult = 0;
 
}

void CCourse::OnQuery() 
{
	// TODO: Add your control notification handler code here
	//通过选择班级、课程、时间来查询显示该班每个人的出勤情况
	//1.能够在列表控件里显示每个人的出勤信息
	//2、并能够对每个人的出勤信息进行修改
	GetDlgItem(IDC_MODIFY)->EnableWindow(true);
	GetDlgItem(IDC_All_CHECK)->EnableWindow(false);
	GetDlgItem(IDC_AllNOT_CHECK)->EnableWindow(false);
	GetDlgItem(IDC_SAVE)->EnableWindow(false);	

	ShowQueryTitle();  //设置标题头
	QueryData();   //查询数据库
 
}

void CCourse::SetTtitleTree()
{
	CString str1;

	if (bTitleTree)
	{
		int nColumnCount = m_StuActList.GetHeaderCtrl()->GetItemCount();
		// Delete all of the columns.
		for (int i=0;i < nColumnCount;i++)
		{
		   m_StuActList.DeleteColumn(0);
		}
		ConstructTableName();  //设置列表框表头
		bTitleTree=false;
		bTitleQuery=true;
	}
}

void CCourse::OnModify() 
{
	//修改,仅仅是对从数据库中查到的数据进行修改
	//仅修改学生是否缺勤,
	//因此,课程,日期应该值为不可用
	GetDlgItem(IDC_COMB_COURSE)->EnableWindow(false);
	GetDlgItem(IDC_DATETIME)->EnableWindow(false);
	//对学生出勤情况进行修改
	CString StuCourseID; //记录ID
	_bstr_t vSQL;
    CString strTemp;

 
	if (m_StuActList.GetItemCount()<=0)
	{
		AfxMessageBox("列表控件里,无学生记录!!!");
		return ;
	}
	//插入所有该班的学生
	for(int i=0 ; i< m_StuActList.GetItemCount(); i++)
	{	
		StuCourseID.Format("%d",m_StuActList.GetItemData(i));
		//判断该学生是否参加该活动
		if (iModyCheck[i] !=iModyCheckBase[i])
		{
		
			strTemp.Format("%d",iModyCheck[i]);
			//该学生的出勤状态被修改,应该更新数据库
			vSQL = "Update StuCourse Set IsCourse= " + strTemp 
			  +	" Where ID= " + StuCourseID;
			m_CurAdo.ExecuteSQL(vSQL);
			AfxMessageBox(" 修改了: " + StuCourseID);
			
		}

															      			
	}

}

void CCourse::ShowQueryTitle()
{
	//在列表框中显示标题
   if (bTitleQuery)
   {
		int nColumnCount = m_StuActList.GetHeaderCtrl()->GetItemCount();
		// Delete all of the columns.
		for (int i=0;i < nColumnCount;i++)
		   m_StuActList.DeleteColumn(0);

		m_StuActList.InsertColumn(0,"学号",LVCFMT_LEFT,100);
		m_StuActList.InsertColumn(1,"姓名",LVCFMT_LEFT,80);
		m_StuActList.InsertColumn(2,"班级名称",LVCFMT_LEFT,150);
		m_StuActList.InsertColumn(3,"课程名称",LVCFMT_LEFT,100);
		m_StuActList.InsertColumn(4,"上课时间",LVCFMT_LEFT,80);
		m_StuActList.InsertColumn(5,"是否出勤",LVCFMT_LEFT,80);
 		m_StuActList.InsertColumn(6,"ID",LVCFMT_LEFT,80);
		bTitleQuery=false;
		bTitleTree=true;
		UpdateData(0);
   }
}

void CCourse::QueryData()
{
    //联合多个表格进行查询,主要就是了解该课程,该时间下的学生的出勤情况
	//对StuCourse表中的项,ID为主键

	CString strCourseID,strTime,strClassID;	
	
 
	//获取时间控件的值
	CTime time;
	m_dateAct.GetTime(time);
	Time=time.Format("%Y-%m-%d");					//转换实际格式
	strCourseID.Format("%d", m_cmbAct.GetItemData(m_cmbAct.GetCurSel()));
	strTime = Time;
	
	CString strMarkSharp;
	strMarkSharp.LoadString(IDS_MARK_SHARP);
	strClassID=m_ClassID;
	if (strClassID.GetLength()<8)
	{
		AfxMessageBox("请选择班级!!!");
		return;
	}
	int nColumn=7;  //要显示六列数据

	//设置SELECT语句
	_bstr_t vSQL;
	CString strSQL;
	vSQL = "select Student.StudentNum,Name, ClassName,CourseName,CourDateTime, IsCourse, \
       StuCourse.ID from Student, Course, StuCourse, Class where Student.ClassID='" \
	   + m_ClassID + "' and Student.ClassID=Class.ClassID "\
	   + " and  Student.StudentNum=StuCourse.StudentNum " +" and StuCourse.CourDateTime= " \
	   + strMarkSharp + strTime + strMarkSharp \
	   + " and  StuCourse.CourseID="+strCourseID+ " and  StuCourse.CourseID=Course.CourseID " \
	   + " ORDER BY StuCourse.ID ";


	m_StuActList.DeleteAllItems();
	CArray <CString, LPCTSTR> StudentInfoAry;
	CString strCurColInfo;	
	StudentInfoAry.SetSize(nColumn);  
	CString * pCurInfo = StudentInfoAry.GetData();
	int nRecordNum = 0;
	//执行SELETE语句,如果记录集不为空
	
	_RecordsetPtr CurRecordset;
	_variant_t nIndex = (long)0; 
	_variant_t var;
	int iModCheBase=0;
	CurRecordset = m_CurAdo.GetRecordSet(vSQL);
	while (0 == CurRecordset->adoEOF)
	{
		//取一条记录付值给数组StudentInfoAry	
		for (int i = 0; i < nColumn; i++)
		{
			nIndex = (long) i;
			var = CurRecordset->GetCollect(nIndex);
			pCurInfo[i] = (LPCTSTR)(_bstr_t )var;
 		}
		m_StuActList.InsertItem(nRecordNum, "");
		for (int j = 0; j < nColumn; j++)
		{
			if(j==6)//表示ID
				m_StuActList.SetItemData(nRecordNum,atoi(pCurInfo[j]));	
			if (5==j) //是否出勤
			{
				if (1==atoi(pCurInfo[j]))
				{
					iModyCheckBase[iModCheBase] = 1; //保存该学生的选择状态
					m_StuActList.SetCheck(nRecordNum, true);
					m_StuActList.SetItemText(nRecordNum,j,"是");
					iModCheBase++;
				}			
				else
				{
					iModyCheckBase[iModCheBase] = 0;
					m_StuActList.SetCheck(nRecordNum, false);
					m_StuActList.SetItemText(nRecordNum,j,"否");
					iModCheBase++;
				}		
			}
			else
				m_StuActList.SetItemText(nRecordNum, j, pCurInfo[j]);
		}
		nRecordNum ++;
		//记录转下一条
		CurRecordset->MoveNext();
	}	
	for(int k=0 ; k<iModCheBase ;k++)
		iModyCheck[k]=iModyCheckBase[k]; //原数据库中的标识赋值给待变的
}

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

	HTREEITEM hCurItem;
	HTREEITEM hCurChildItem;
	CString strCurClassID;
	hCurItem = m_StuActTree.GetSelectedItem();
	if (NULL != hCurItem)
	{
		hCurChildItem = m_StuActTree.GetChildItem(hCurItem);
		if (NULL == hCurChildItem) // 若某一个节点,其孩子为空,说明其为根节点,可以使用查询语句寻找具体信息
		{
			
			GetDlgItem(IDC_MODIFY)->EnableWindow(false);
			GetDlgItem(IDC_All_CHECK)->EnableWindow(true);
			GetDlgItem(IDC_AllNOT_CHECK)->EnableWindow(true);	
			GetDlgItem(IDC_SAVE)->EnableWindow(true); 

			GetDlgItem(IDC_COMB_COURSE)->EnableWindow(true);
			GetDlgItem(IDC_DATETIME)->EnableWindow(true);

			// 如果当前的所选择的叶子节点发生了变化,那么就修改当前查询语句 m_strCurQuaryInfo 
			// 并且发送消息,导致整个对话框发生刷新
			strCurClassID.Format("%d", m_StuActTree.GetItemData(hCurItem));
			m_ClassID=strCurClassID;  //把当前班级ID赋值给成员变量
			//当前选择的是班级,控制显示表头
			SetTtitleTree();
			ModityCurQueryMessage(strCurClassID);
		}
	}
	*pResult = 0;
}

 

⌨️ 快捷键说明

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