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

📄 queryattenddlg.cpp

📁 基于指纹技术的学生考勤系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			CString tempId,tempCount;
			CDBVariant var;
			rs.GetFieldValue((short)0,var,SQL_C_SLONG);
			if(var.m_dwType!=DBVT_NULL)
				id=var.m_lVal;
			var.Clear();

			tempId.Format("%d",id);
			rs.GetFieldValue(1,sName);
			rs.GetFieldValue(2,sDepartName);
			rs.GetFieldValue(3,sClassName);
			rs.GetFieldValue((short)4,var,SQL_C_SLONG);
			if(var.m_dwType!=DBVT_NULL)
				iCount=var.m_iVal;
			var.Clear();
			tempCount.Format("%d",iCount);
			
			if(atoi(tempCount)>=atoi(m_strAttendTime))
				InsertToItem(tempId,sName,sDepartName,sClassName,tempCount);
			rs.MoveNext();
		}
	}
	CATCH(CDBException,ex)
	{
		AfxMessageBox(ex->m_strError);
		AfxMessageBox(ex->m_strStateNativeOrigin);
	}
	AND_CATCH(CMemoryException,pEx)
	{
		pEx->ReportError();
		AfxMessageBox("memory exception");
	}
	AND_CATCH(CException,e)
	{
		TCHAR szError[100];
		e->GetErrorMessage(szError,100);
		AfxMessageBox(szError);
	}
	END_CATCH
}

void CQueryAttendDlg::InsertToItem(CString tempId, CString sName, CString sDepartName, CString sClassName, CString tempCount)
{
	int nIndex=m_listQStudent.GetItemCount();
	LV_ITEM lvItem;
	lvItem.mask=LVIF_TEXT;
	lvItem.iItem=nIndex;
	lvItem.iSubItem=0;
	lvItem.pszText=(char*)(LPCTSTR)tempId;
	m_listQStudent.InsertItem(&lvItem);

	m_listQStudent.SetItemText(nIndex,1,sName);
	m_listQStudent.SetItemText(nIndex,2,sDepartName);
	m_listQStudent.SetItemText(nIndex,3,sClassName);
	m_listQStudent.SetItemText(nIndex,4,tempCount);
}

void CQueryAttendDlg::OnClickListQstudent(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	m_listQAttend.DeleteAllItems();
	int nItem=m_listQStudent.GetNextItem(-1,LVNI_SELECTED);
	if(nItem!=-1)
	{
		CString sId=m_listQStudent.GetItemText(nItem,0);
		CString sql;
		sql.Format("select AttendID,ClassID from tab_student where sID='%s'",sId);
	//	MessageBox(sql);return;
		TRY{
			CRecordset rs(&m_db);
			rs.Open(CRecordset::dynaset,sql);
			if(!rs.IsEOF())
			{
				long lAttId;
				CDBVariant var;
				rs.GetFieldValue((short)0,var,SQL_C_SLONG);
				if(var.m_dwType!=DBVT_NULL)
					lAttId=var.m_lVal;
				var.Clear();
				long ClassId;
				rs.GetFieldValue(1,var,SQL_C_SLONG);
				if(var.m_dwType!=DBVT_NULL)
					ClassId=var.m_lVal;
				var.Clear();
				CString ClassName=FromIDToName("tab_Class","ClassID",ClassId);
				QueryAttendInfo(lAttId,ClassName);
			}
		}
		CATCH(CDBException,ex)
		{
			AfxMessageBox(ex->m_strError);
			AfxMessageBox(ex->m_strStateNativeOrigin);
		}
		AND_CATCH(CMemoryException,pEx)
		{
			pEx->ReportError();
			AfxMessageBox("memory exception");
		}
		AND_CATCH(CException,e)
		{
			TCHAR szError[100];
			e->GetErrorMessage(szError,100);
			AfxMessageBox(szError);
		}
		END_CATCH
	}

	*pResult = 0;
}

void CQueryAttendDlg::QueryAttendInfo(long lAttId,CString ClassName)
{
	CString sql;
	sql.Format("select AttendTypeID,TheDay from tab_AttendInfomation where AttendID=%d",lAttId);
	TRY{
		CRecordset rs(&m_db);
		rs.Open(CRecordset::dynaset,sql);
		while(!rs.IsEOF())
		{
			int iAttendTypeId;
			CString sDayTime;
			CString sAttendType;

			CDBVariant var;
			rs.GetFieldValue((short)0,var,SQL_C_SLONG);
			if(var.m_dwType!=DBVT_NULL)
				iAttendTypeId=var.m_lVal;			
			var.Clear();
			sAttendType.Format("%d",iAttendTypeId);	
													//获得考勤类型
			sAttendType=FromIDToName("tab_AttendType","AttendTypeID",iAttendTypeId);
			rs.GetFieldValue(1,sDayTime);			//获得时间
		//	MessageBox(sDayTime);
		//	0000-00-00 00:00:00.000
			CString sYear,sMonth,sDay,sHour,sMinute;
			sYear.Format("%s",sDayTime.Mid(0,4));
			sMonth.Format("%s",sDayTime.Mid(5,2));
			sDay.Format("%s",sDayTime.Mid(8,2));
			sHour.Format("%s",sDayTime.Mid(11,2));
			sMinute.Format("%s",sDayTime.Mid(14,2));
			CTime ctime(atoi(sYear),atoi(sMonth),atoi(sDay),atoi(sHour),atoi(sMinute),0);
			int iWeekday;
			iWeekday=ctime.GetDayOfWeek();
			CString sWeekday;
			sWeekday="星期"+Weedday[(iWeekday+5)%7];//获得星期
			// 以下获得课程名称:通过时间,获得时段,再以时段为条件查询课程表中的课程ID
			CString strCourseName=GetCourseName(iWeekday,sHour,sMinute,ClassName);
			/***********************************************************************
			至此已获得要显示时的所需要信息: 考勤类型sAttendType,课程strCourseName
											  星期 sWeekday,时间 sDayTime
			************************************************************************/
			InsertToItem2(sAttendType,strCourseName,sWeekday,sDayTime);
			
			rs.MoveNext();
		}
	}
	CATCH(CDBException,ex)
	{
		AfxMessageBox(ex->m_strError);
		AfxMessageBox(ex->m_strStateNativeOrigin);
	}
	AND_CATCH(CMemoryException,pEx)
	{
		pEx->ReportError();
		AfxMessageBox("memory exception");
	}
	AND_CATCH(CException,e)
	{
		TCHAR szError[100];
		e->GetErrorMessage(szError,100);
		AfxMessageBox(szError);
	}
	END_CATCH
}

CString CQueryAttendDlg::GetCourseName(int iWeekday,CString strHour, CString strMinute,CString ClassName)
{
	//通过 班级ID,时段ID,星期 三个条件可获得课程ID	
	CString sCourseName;
	//星期已作为参数传入,下面语句获得班级ID
	long classId=FromNameToID("tab_Class","ClassName",ClassName);

	//获得时段
	long iTime;
	iTime=atoi(strHour)*60+atoi(strMinute);
	TRY{
		long lScheduleId;
		CRecordset rs(&m_db);
		rs.Open(CRecordset::dynaset,"select *from tab_CourseTime");
		while(!rs.IsEOF())
		{
			CString strUptime,strDowntime;
			long lUptime,lDowntime;
			CDBVariant var;
			rs.GetFieldValue((short)0,var,SQL_C_SLONG);
			if(var.m_dwType!=DBVT_NULL)
				lScheduleId=var.m_lVal;			
			var.Clear();
			rs.GetFieldValue(1,strUptime);
			rs.GetFieldValue(2,strDowntime);
			lUptime=atoi(strUptime.Mid(11,2))*60+atoi(strUptime.Mid(14,2));
			lDowntime=atoi(strDowntime.Mid(11,2))*60+atoi(strDowntime.Mid(14,2));
			if(1==CompareSchedule(iTime,lUptime,lDowntime))
			{
				lScheduleId=lScheduleId;
				break;
			}
			rs.MoveNext();
		}
		rs.Close();
		//至些,已经获得三个条件了:班级ID,时段ID,星期,下面由这三个条件求出课程ID
		long lCourseId;		
		CString sql;
		sql.Format("select CourseID from tab_Coursetab where ClassID=%d and ScheduleID=%d "
					"and TheWeekday=%d",classId,lScheduleId,iWeekday);
		rs.Open(CRecordset::dynaset,sql);
		if(!rs.IsEOF())
		{
			CDBVariant var;
			rs.GetFieldValue((short)0,var,SQL_C_SLONG);
			if(var.m_dwType!=DBVT_NULL)
				lCourseId=var.m_lVal;			
			var.Clear();
			sCourseName=FromIDToName("tab_Course","CourseID",lCourseId);
		}
		return sCourseName;
	}
	CATCH(CDBException,ex)
	{
		AfxMessageBox(ex->m_strError);
		AfxMessageBox(ex->m_strStateNativeOrigin);
	}
	AND_CATCH(CMemoryException,pEx)
	{
		pEx->ReportError();
		AfxMessageBox("memory exception");
	}
	AND_CATCH(CException,e)
	{
		TCHAR szError[100];
		e->GetErrorMessage(szError,100);
		AfxMessageBox(szError);
	}
	END_CATCH
}

int CQueryAttendDlg::CompareSchedule(long iTime, long lUptime, long lDowntime)
{

	if(iTime>=lUptime && iTime<=lDowntime)
		return 1;
	else
		return 0;
}

void CQueryAttendDlg::InsertToItem2(CString sAttendType, CString strCourseName, CString sWeekday, CString sDayTime)
{
	int nIndex=m_listQAttend.GetItemCount();
	LV_ITEM lvItem;
	lvItem.mask=LVIF_TEXT;
	lvItem.iItem=nIndex;
	lvItem.iSubItem=0;
	lvItem.pszText=(char*)(LPCTSTR)sAttendType;
	m_listQAttend.InsertItem(&lvItem);

	m_listQAttend.SetItemText(nIndex,1,strCourseName);
	m_listQAttend.SetItemText(nIndex,2,sWeekday);
	m_listQAttend.SetItemText(nIndex,3,sDayTime);
}

void CQueryAttendDlg::OnCheckTime() 
{
	// TODO: Add your control notification handler code here
	MessageBox("抱歉!现阶段该功能还没有完成!");
	m_checkTime.SetCheck(0);
	return;
	if(1==m_checkTime.GetCheck())
	{
		GetDlgItem(IDC_DTP_UP)->EnableWindow(TRUE);
		GetDlgItem(IDC_DTP_DOWN)->EnableWindow(TRUE);
	}
	else
	{
		GetDlgItem(IDC_DTP_UP)->EnableWindow(FALSE);
		GetDlgItem(IDC_DTP_DOWN)->EnableWindow(FALSE);
	}
}

void CQueryAttendDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
//	DestroyWindow();
	//MessageBox("");
	AnimateWindow(GetSafeHwnd(),1000,AW_HIDE|AW_CENTER);
	CDialog::OnClose();
}

void CQueryAttendDlg::OnChangeEditAttendtime() 
{
	// 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
	UpdateData(TRUE);
	LPCTSTR FILE_NAME=".\\time.ini";
	WritePrivateProfileString("Time","Caption","TimeSet",FILE_NAME);

	WritePrivateProfileString("Time","Conter",m_strAttendTime,FILE_NAME);
}

void CQueryAttendDlg::OnBtnQuery() 
{
	// TODO: Add your control notification handler code here
	m_listQStudent.DeleteAllItems();
	QueryStudentInfo();
}

void CQueryAttendDlg::OnRclickListQattend(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	int nItem=m_listQAttend.GetNextItem(-1,LVNI_SELECTED);
	if(nItem!=-1)
	{
		CPoint point;
		GetCursorPos(&point);
		CMenu   menu,*pmenu;   
		menu.LoadMenu(IDR_MENU2);   
		pmenu=menu.GetSubMenu(0);   
		//CPoint   ptScreen(point);   
//		ClientToScreen(&ptScreen);   
		pmenu->TrackPopupMenu(TPM_RIGHTBUTTON,point.x,point.y,this);  
	}
	*pResult = 0;
}

void CQueryAttendDlg::OnBtnLookcourse() 
{
	// TODO: Add your control notification handler code here
	CCourseDlg dlg;
	OpenFrm=1;
	dlg.DoModal();
}

BOOL CQueryAttendDlg::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
{
	// TODO: Add your specialized code here and/or call the base class
	AnimateWindow(GetSafeHwnd(),1000,AW_SLIDE|AW_HOR_POSITIVE);
	return CDialog::Create(IDD, pParentWnd);
}

void CQueryAttendDlg::OnOK() 
{
	// TODO: Add extra validation here
	AnimateWindow(GetSafeHwnd(),1000,AW_HIDE|AW_CENTER);
	CDialog::OnOK();
}

int CQueryAttendDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	AnimateWindow(GetSafeHwnd(),1000,AW_BLEND|AW_HOR_POSITIVE);
	return 0;
}

void CQueryAttendDlg::OnRclickListQstudent(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
//	int nItem=m_listQStudent.GetNextItem(-1,LVNI_SELECTED);
//	if(nItem!=-1)
//	{
		CPoint point;
		GetCursorPos(&point);
		CMenu   menu,*pmenu;   
		menu.LoadMenu(IDR_MENU1);   
		pmenu=menu.GetSubMenu(0);   
		//CPoint   ptScreen(point);   
//		ClientToScreen(&ptScreen);   
		pmenu->TrackPopupMenu(TPM_RIGHTBUTTON,point.x,point.y,this);  
//	}
	*pResult = 0;
}

void CQueryAttendDlg::OnDel() 
{
	// TODO: Add your command handler code here
	int nItem=m_listQStudent.GetNextItem(-1,LVNI_SELECTED);
	CString sId;
	sId=m_listQStudent.GetItemText(nItem,0);
}

void CQueryAttendDlg::OnDelall() 
{
	// TODO: Add your command handler code here
	
}

void CQueryAttendDlg::OnDeldetail() 
{
	// TODO: Add your command handler code here
	int nItem=m_listQAttend.GetNextItem(-1,LVNI_SELECTED);
	CString s;
	s.Format("%d",nItem);
	MessageBox(s);
}

⌨️ 快捷键说明

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