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

📄 configtimepage.cpp

📁 基于指纹技术的学生考勤系统
💻 CPP
字号:
// ConfigTimePage.cpp : implementation file
//

#include "stdafx.h"
#include "FPSys.h"
#include "ConfigTimePage.h"

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

/////////////////////////////////////////////////////////////////////////////
// CConfigTimePage property page
extern CDatabase m_db;
extern CString FromIDToName(CString tabName,CString attr,int id);	//通过编号获得名字
int FromNameToID(CString tabName,CString attr,CString name);	//通过名字获得编号

IMPLEMENT_DYNCREATE(CConfigTimePage, CPropertyPage)

CConfigTimePage::CConfigTimePage() : CPropertyPage(CConfigTimePage::IDD)
{
	//{{AFX_DATA_INIT(CConfigTimePage)
	m_ScheduleID = _T("");
	m_strSchedule = _T("");
	m_ctUp = 0;
	//}}AFX_DATA_INIT
}

CConfigTimePage::~CConfigTimePage()
{
}

void CConfigTimePage::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CConfigTimePage)
	DDX_Control(pDX, IDC_DTP_DOWN, m_dtpDown);
	DDX_Control(pDX, IDC_DTP_UP, m_dtpUp);
	DDX_Control(pDX, IDC_LIST_LISTTIME, m_listTime);
	DDX_Text(pDX, IDC_EDIT_ID, m_ScheduleID);
	DDX_Text(pDX, IDC_EDIT_SCHEDULE, m_strSchedule);
	DDX_DateTimeCtrl(pDX, IDC_DTP_UP, m_ctUp);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CConfigTimePage, CPropertyPage)
	//{{AFX_MSG_MAP(CConfigTimePage)
	ON_BN_CLICKED(IDC_BTN_ADD, OnBtnAdd)
	ON_BN_CLICKED(IDC_BTN_DEL, OnBtnDel)
	ON_BN_CLICKED(IDC_BTN_MOD, OnBtnMod)
	ON_NOTIFY(NM_CLICK, IDC_LIST_LISTTIME, OnClickListListtime)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CConfigTimePage message handlers

void CConfigTimePage::OnBtnAdd() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	if(m_ScheduleID.IsEmpty()||m_strSchedule.IsEmpty())
	{
		MessageBox("请完整填写信息!");
		return;
	}
	if(m_ScheduleID.GetLength()>5)
	{
		MessageBox("你输入的编号的长度太了。\r\n请输入小于6位的编号!");
		m_ScheduleID.Empty();
		UpdateData(FALSE);
		return;
	}

	CString strUptime,strDowntime;
	CTime ctime;

	m_dtpUp.GetTime(ctime);
	strUptime.Format("%d:%d",ctime.GetHour(),ctime.GetMinute());
	
	//0000 00 00
	m_dtpDown.GetTime(ctime);
	strDowntime.Format("%d:%d",ctime.GetHour(),ctime.GetMinute());

	InsertToDb(m_ScheduleID,m_strSchedule,strUptime,strDowntime);
}

void CConfigTimePage::OnBtnDel() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CString sql;
	TRY{
		sql.Format("delete from tab_Coursetime where ScheduleID='%s'",m_ScheduleID);
		TRACE(sql);
		m_db.ExecuteSQL(sql);
		sql.Format("delete from tab_Schedule where ScheduleID='%s'",m_ScheduleID);
		TRACE(sql);
		m_db.ExecuteSQL(sql);

		int nItem=m_listTime.GetNextItem(-1,LVNI_SELECTED);
		m_listTime.DeleteItem(nItem);
	}
	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 CConfigTimePage::OnBtnMod() 
{
	// TODO: Add your control notification handler code here
	int nItem=m_listTime.GetNextItem(-1,LVNI_SELECTED);
	if(nItem==-1)
		return;
	UpdateData();
	if(strcmp(m_strPreScheduleId,m_ScheduleID)!=0)
	{
		MessageBox("编号不用修改,只能通过删除后再改!");
		m_ScheduleID=m_strPreScheduleId;
		UpdateData(FALSE);
		return;
	}
	CString strUptime,strDowntime;
	CTime ctime;

	m_dtpUp.GetTime(ctime);
	strUptime.Format("%d:%d",ctime.GetHour(),ctime.GetMinute());
	
	//0000 00 00
	m_dtpDown.GetTime(ctime);
	strDowntime.Format("%d:%d",ctime.GetHour(),ctime.GetMinute());

	UpdateScheduleTime(m_strSchedule,strUptime,strDowntime);
	//UpdateScheduleTime(CString m_strSchedule, CString strUptime, CString strDowntime)
}

BOOL CConfigTimePage::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	// TODO: Add extra initialization here
	DWORD dwExStyle=LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP|
					LVS_EX_ONECLICKACTIVATE|LVS_EX_UNDERLINEHOT;
	m_listTime.SetExtendedStyle(dwExStyle);
	m_listTime.InsertColumn(0,"编号",LVCFMT_CENTER,90);
	m_listTime.InsertColumn(1,"时段",LVCFMT_CENTER,90);
	m_listTime.InsertColumn(2,"上课时间",LVCFMT_CENTER,70);
	m_listTime.InsertColumn(3,"下课时间",LVCFMT_CENTER,70);
	
	InitCtrlData();

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CConfigTimePage::InitCtrlData()
{
	TRY{
		CString sql;
		sql.Format("select *from tab_CourseTime order by ScheduleID");
		CRecordset rs(&m_db);
		rs.Open(CRecordset::dynaset,sql);
		while(!rs.IsEOF())
		{
			int ScheduleId;
			CString sT1,sT2;
			CString Schedule;

			CDBVariant var;
			rs.GetFieldValue((short)0,var,SQL_C_SLONG);
			if(var.m_dwType!=DBVT_NULL)
				ScheduleId=var.m_lVal;
			var.Clear();
	/*		rs.GetFieldValue((short)1,var,SQL_C_SLONG);
			if(var.m_dwType!=DBVT_NULL)
				sT1=var.m_pdate;
			var.Clear();
			rs.GetFieldValue((short)2,var,SQL_C_SLONG);
			if(var.m_dwType!=DBVT_NULL)
				SchduleId=var.m_pdate;
			var.Clear();*/
			Schedule=FromIDToName("tab_Schedule","ScheduleID",ScheduleId);
			rs.GetFieldValue(1,sT1);
			rs.GetFieldValue(2,sT2);
			sT1=sT1.Mid(11,5);
			sT2=sT2.Mid(11,5);
			CString temp;
			temp.Format("%d",ScheduleId);
			InsertItem(temp,Schedule,sT1,sT2);
			rs.MoveNext();
		}
		rs.Close();
		sql.Format("select *from tab_Schedule order by ScheduleID");
		rs.Open(CRecordset::dynaset,sql);
		while(!rs.IsEOF())
		{
			int ScheduleId;
			CString Schedule;
			CDBVariant var;
			rs.GetFieldValue((short)0,var,SQL_C_SLONG);
			if(var.m_dwType!=DBVT_NULL)
				ScheduleId=var.m_lVal;
			var.Clear();
			rs.GetFieldValue(1,Schedule);
		/*	CString sql2;
			sql2.Format("select *from tab_CourseTime where ScheduleID=%d",ScheduleId);
			CRecordset rs2(&m_db);
			rs2.Open(CRecordset::dynaset,sql2);
			if(rs.IsEOF())*/
//			m_cSchedule.AddString(Schedule);
			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 CConfigTimePage::InsertItem(CString ScheduleID,CString Schedule, CString sT1, CString sT2)
{
	int nIndex=m_listTime.GetItemCount();
	LV_ITEM lvItem;
	lvItem.mask=LVIF_TEXT;
	lvItem.iItem=nIndex;
	lvItem.iSubItem=0;
	lvItem.pszText=(char*)(LPCTSTR)ScheduleID;
	m_listTime.InsertItem(&lvItem);
	
	m_listTime.SetItemText(nIndex,1,Schedule);
	m_listTime.SetItemText(nIndex,2,sT1);
	m_listTime.SetItemText(nIndex,3,sT2);
}

void CConfigTimePage::InsertToDb(CString m_strScheduleID,CString m_strSchedule,CString strUptime, CString strDowntime)
{
	CString sql;
	TRY{
		sql.Format("Insert into tab_Schedule(ScheduleID,Schedule) values('%s','%s')",
						m_strScheduleID,m_strSchedule);
		TRACE(sql);
		m_db.ExecuteSQL(sql);
		sql.Format("Insert into tab_CourseTime(ScheduleID,UpTime,DownTime) values('%s','%s','%s')",
						m_strScheduleID,strUptime,strDowntime);
		TRACE(sql);
		m_db.ExecuteSQL(sql);

		InsertItem(m_strScheduleID,m_strSchedule,strUptime,strDowntime);
	}
	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 CConfigTimePage::OnClickListListtime(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	int nItem=m_listTime.GetNextItem(-1,LVNI_SELECTED);
	if(nItem!=-1)
	{	
		CString id=m_listTime.GetItemText(nItem,0);
		GetDlgItem(IDC_EDIT_ID)->SetWindowText(id);
		m_strPreScheduleId=id;

		CString name=m_listTime.GetItemText(nItem,1);
		GetDlgItem(IDC_EDIT_SCHEDULE)->SetWindowText(name);
		
		CString strUp=m_listTime.GetItemText(nItem,2);
		CString strDown=m_listTime.GetItemText(nItem,3);

		CString sHour,sMinute;
		
		sHour=strUp.Mid(0,2);
		sMinute=strUp.Mid(3,2);
		CTime ct(2007,1,1,atoi(sHour),atoi(sMinute),0);
		VERIFY(m_dtpUp.SetTime(&ct));   

		sHour=strDown.Mid(0,2);
		sMinute=strDown.Mid(3,2);
		CTime ct1(2007,1,1,atoi(sHour),atoi(sMinute),0);
		VERIFY(m_dtpDown.SetTime(&ct1));   

	}

	*pResult = 0;
}

void CConfigTimePage::UpdateScheduleTime(CString m_strSchedule, CString strUptime, CString strDowntime)
{
	
	TRY{
		CString sql;
		sql.Format("Update tab_Schedule set Schedule='%s' where ScheduleID='%s'",
						m_strSchedule,m_ScheduleID);
		TRACE(sql);
		m_db.ExecuteSQL(sql);
		sql.Format("Update tab_CourseTime set UpTime='%s',DownTime='%s' where ScheduleID='%s'",
					strUptime,strDowntime,m_ScheduleID);
		TRACE(sql);
		m_db.ExecuteSQL(sql);

		int nItem=m_listTime.GetNextItem(-1,LVNI_SELECTED);
		m_listTime.SetItemText(nItem,1,m_strSchedule);
		m_listTime.SetItemText(nItem,2,strUptime);
		m_listTime.SetItemText(nItem,3,strDowntime);
	}
	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
}

⌨️ 快捷键说明

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