www.pudn.com > StuMis.rar > EditDlg.cpp


// EditDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "StuMis.h" 
#include "EditDlg.h" 
 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
extern CStuMisApp theApp; 
///////////////////////////////////////////////////////////////////////////// 
// CEditDlg property page 
 
IMPLEMENT_DYNCREATE(CEditDlg, CPropertyPage) 
 
CEditDlg::CEditDlg() : CPropertyPage(CEditDlg::IDD) 
{ 
	//{{AFX_DATA_INIT(CEditDlg) 
	m_in_id = _T(""); 
	m_out_name = _T(""); 
	m_out_birthday = COleDateTime::GetCurrentTime(); 
	m_out_class = _T(""); 
	m_out_department = _T(""); 
	m_out_native_place = _T(""); 
	m_out_sex = -1; 
	m_s_class = _T(""); 
	m_s_department = _T(""); 
	m_out_id = _T(""); 
	//}}AFX_DATA_INIT 
} 
 
CEditDlg::~CEditDlg() 
{ 
} 
 
void CEditDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CPropertyPage::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CEditDlg) 
	DDX_Control(pDX, IDC_XJLIST, m_xjlist); 
	DDX_Control(pDX, IDC_MLIST, m_mlist); 
	DDX_Control(pDX, IDC_CFLIST, m_cflist); 
	DDX_Text(pDX, IDC_IN_ID, m_in_id); 
	DDX_Text(pDX, IDC_OUT_NAME, m_out_name); 
	DDX_DateTimeCtrl(pDX, IDC_OUT_BIRTHDAY, m_out_birthday); 
	DDX_Text(pDX, IDC_OUT_CLASS, m_out_class); 
	DDX_Text(pDX, IDC_OUT_DEPARTMENT, m_out_department); 
	DDX_Text(pDX, IDC_OUT_NATIVE_PLACE, m_out_native_place); 
	DDX_CBIndex(pDX, IDC_OUT_SEX, m_out_sex); 
	DDX_Text(pDX, IDC_S_CLASS, m_s_class); 
	DDX_Text(pDX, IDC_S_DEPARTMENT, m_s_department); 
	DDX_Text(pDX, IDC_OUT_ID, m_out_id); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CEditDlg, CPropertyPage) 
	//{{AFX_MSG_MAP(CEditDlg) 
	ON_BN_CLICKED(IDC_X_SEARCH, OnXSearch) 
	ON_BN_CLICKED(IDC_EDIT, OnEdit) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CEditDlg message handlers 
 
BOOL CEditDlg::OnInitDialog()  
{ 
	CPropertyPage::OnInitDialog(); 
 
	m_mlist.SetExtendedStyle(LVS_EX_FULLROWSELECT); 
	// 设置List的列 
	int nWidth=90; 
	m_mlist.InsertColumn(0, "记录编号", LVCFMT_LEFT, nWidth-20); 
	m_mlist.InsertColumn(1, "学号", LVCFMT_LEFT, nWidth-20); 
	m_mlist.InsertColumn(2, "记录时间", LVCFMT_LEFT, nWidth+20); 
	m_mlist.InsertColumn(3, "奖励种类", LVCFMT_LEFT, nWidth+20); 
	m_mlist.InsertColumn(4, "详细描述", LVCFMT_LEFT, nWidth);	 
	 
 
 
	m_xjlist.SetExtendedStyle(LVS_EX_FULLROWSELECT); 
	// 设置List的列 
//	int nWidth=90; 
	m_xjlist.InsertColumn(0, "记录编号", LVCFMT_LEFT, nWidth-20); 
	m_xjlist.InsertColumn(1, "学号", LVCFMT_LEFT, nWidth-20); 
	m_xjlist.InsertColumn(2, "记录时间", LVCFMT_LEFT, nWidth+20); 
	m_xjlist.InsertColumn(3, "变更情况", LVCFMT_LEFT, nWidth+20); 
	m_xjlist.InsertColumn(4, "详细描述", LVCFMT_LEFT, nWidth); 
 
 
 
	m_cflist.SetExtendedStyle(LVS_EX_FULLROWSELECT); 
	// 设置List的列 
//	int nWidth=90; 
	m_cflist.InsertColumn(0, "记录编号", LVCFMT_LEFT, nWidth-10); 
	m_cflist.InsertColumn(1, "学号", LVCFMT_LEFT, nWidth-10); 
	m_cflist.InsertColumn(2, "记录时间", LVCFMT_LEFT, nWidth+10); 
	m_cflist.InsertColumn(3, "处罚级别", LVCFMT_LEFT, nWidth+10); 
	m_cflist.InsertColumn(4,"是否生效",LVCFMT_LEFT,nWidth+10); 
	m_cflist.InsertColumn(5, "详细描述", LVCFMT_LEFT, nWidth); 
/*	m_Sheet.AddPage(&m_xeditdlg); // 加第1页 
	m_Sheet.AddPage(&m_xsearchdlg); // 加第2页 
 
 
	m_Sheet.Create(this, WS_CHILD | WS_VISIBLE, 0); // 创建窗口 
	m_Sheet.ModifyStyleEx (0, WS_EX_CONTROLPARENT); // 修改风格 
	m_Sheet.ModifyStyle( 0, WS_TABSTOP ); // 修改风格 
 
	// 设置窗口位置 
	m_Sheet.SetWindowPos( NULL, -6, 20, 0, 0,  
			SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE ); 
	for(int i=0;i<2;i++) 
	{ 
		m_Sheet.SetActivePage(i); 
	 
	} 
	m_Sheet.SetActivePage(0); 
	// TODO: Add extra initialization here 
*/	 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void CEditDlg::OnXSearch()  
{ 
	// TODO: Add your control notification handler code here 
 
	CString strSQL; 
 
	UpdateData(); 
	strSQL.Format("SELECT * FROM STUDENT WHERE ID='%s'",m_in_id); 
	theApp.m_pRs.Open(_T(strSQL),CADORecordset::openUnknown); // 打开出差记录表 
//	m_mlist.DeleteAllItems(); // 清除列表框内容 
	while(!theApp.m_pRs.IsEOF()) // 对数据表中所有记录进行处理 
	{ 
 
		theApp.m_pRs.GetFieldValue("ID",m_out_id); 
 
		theApp.m_pRs.GetFieldValue("NAME",m_out_name); 
		theApp.m_pRs.GetFieldValue("SEX",m_out_sex); 
		theApp.m_pRs.GetFieldValue("CLASS",m_out_class); 
		theApp.m_pRs.GetFieldValue("DEPARTMENT",m_out_department); 
		theApp.m_pRs.GetFieldValue("BIRTHDAY",m_out_birthday); 
		theApp.m_pRs.GetFieldValue("NATIVE_PLACE",m_out_native_place); 
 
		theApp.m_pRs.MoveNext(); // 跳到下一条记录 
 
	} 
//	m_out_id.Format("%s",t_id); 
	theApp.m_pRs.Close(); // 关闭出差记录表	 
 
 
 
	 
	strSQL.Format("SELECT * FROM DEPARTMENT WHERE ID='%s'",m_out_department); 
	theApp.m_pRs.Open(_T(strSQL),CADORecordset::openUnknown); // 打开出差记录表 
//	m_mlist.DeleteAllItems(); // 清除列表框内容 
	while(!theApp.m_pRs.IsEOF()) // 对数据表中所有记录进行处理 
	{ 
 
		theApp.m_pRs.GetFieldValue("NAME",m_s_department); 
		theApp.m_pRs.MoveNext(); // 跳到下一条记录 
 
	} 
//	m_out_id.Format("%s",t_id); 
	theApp.m_pRs.Close(); // 关闭出差记录表	 
 
	 
	strSQL.Format("SELECT * FROM CLASS WHERE ID='%s'",m_out_class); 
	theApp.m_pRs.Open(_T(strSQL),CADORecordset::openUnknown); // 打开出差记录表 
//	m_mlist.DeleteAllItems(); // 清除列表框内容 
	while(!theApp.m_pRs.IsEOF()) // 对数据表中所有记录进行处理 
	{ 
 
		theApp.m_pRs.GetFieldValue("NAME",m_s_class); 
		theApp.m_pRs.MoveNext(); // 跳到下一条记录 
 
	} 
//	m_out_id.Format("%s",t_id); 
	theApp.m_pRs.Close(); // 关闭出差记录表		 
	 
	UpdatecfList(); 
	UpdatemList(); 
	UpdatexjList(); 
	 
 
 
	UpdateData(FALSE); 
} 
 
 
 
 
void CEditDlg::UpdatemList() 
{ 
		int i=0,id,stat; 
	CString strID,strSTime,strETime,strSQL; 
	COleDateTime	t_time; 
	strSQL.Format("SELECT * FROM REWARD WHERE STUDENT='%s'",m_in_id); 
	theApp.m_pRs.Open(_T(strSQL),CADORecordset::openUnknown); // 打开出差记录表 
	m_mlist.DeleteAllItems(); // 清除列表框内容 
	while(!theApp.m_pRs.IsEOF()) // 对数据表中所有记录进行处理 
	{ 
		m_mlist.InsertItem(i, "");// 添加新Item 
		theApp.m_pRs.GetFieldValue("ID",id); 
		strID.Format("%d",id); // 转换为字符串 
		m_mlist.SetItemText(i, 0, strID); 
		 
		theApp.m_pRs.GetFieldValue("STUDENT",strID); 
		m_mlist.SetItemText(i, 1, strID); 
		theApp.m_pRs.GetFieldValue("REC_TIME",t_time); 
		m_mlist.SetItemText(i, 2, t_time.Format("%y-%m-%d")); 
 
		theApp.m_pRs.GetFieldValue("LEVELS",stat); 
		switch(stat) 
		{ 
		case 0:strSTime.Format("校特等奖学金");break; 
		case 1:strSTime.Format("校一等奖学金");break; 
		case 2:strSTime.Format("校二等奖学金");break; 
		case 3:strSTime.Format("校三等奖学金");break; 
		case 4:strSTime.Format("系一等奖学金");break; 
		case 5:strSTime.Format("系二等奖学金");break; 
		case 6:strSTime.Format("系三等奖学金");break; 
 
		} 
		 
		m_mlist.SetItemText(i, 3, strSTime); 
 
		theApp.m_pRs.GetFieldValue("DESCRIPTION",strETime); 
		m_mlist.SetItemText(i, 4,strETime); 
		theApp.m_pRs.MoveNext(); // 跳到下一条记录 
		i++; 
	} 
	theApp.m_pRs.Close(); // 关闭出差记录表 
} 
 
void CEditDlg::UpdatecfList() 
{ 
		int i=0,id,stat; 
	CString strID,strSTime,strETime,strSQL; 
	COleDateTime	t_time; 
	strSQL.Format("SELECT * FROM PUNISHMENT WHERE STUDENT='%s'",m_in_id); 
	theApp.m_pRs.Open(_T(strSQL),CADORecordset::openUnknown); // 打开出差记录表 
	m_cflist.DeleteAllItems(); // 清除列表框内容 
	while(!theApp.m_pRs.IsEOF()) // 对数据表中所有记录进行处理 
	{ 
		m_cflist.InsertItem(i, "");// 添加新Item 
		theApp.m_pRs.GetFieldValue("ID",id); 
		strID.Format("%d",id); // 转换为字符串 
		m_cflist.SetItemText(i, 0, strID); 
		 
		theApp.m_pRs.GetFieldValue("STUDENT",strID); 
		m_cflist.SetItemText(i, 1, strID); 
		theApp.m_pRs.GetFieldValue("REC_TIME",t_time); 
		m_cflist.SetItemText(i, 2, t_time.Format("%y-%m-%d")); 
 
		theApp.m_pRs.GetFieldValue("LEVELS",stat); 
		switch(stat) 
		{ 
		case 0:strSTime.Format("警告");break; 
		case 1:strSTime.Format("严重警告");break; 
		case 2:strSTime.Format("记过");break; 
		case 3:strSTime.Format("记大过");break; 
		case 4:strSTime.Format("开除");break; 
		} 
		m_cflist.SetItemText(i, 3, strSTime); 
 
		theApp.m_pRs.GetFieldValue("ENABLE",stat); 
		switch(stat) 
		{ 
		case 0:strSTime.Format("是");break; 
		case 1:strSTime.Format("否");break; 
 
		} 
		m_cflist.SetItemText(i, 4, strSTime); 
 
 
		theApp.m_pRs.GetFieldValue("DESCRIPTION",strETime); 
		m_cflist.SetItemText(i, 5,strETime); 
		theApp.m_pRs.MoveNext(); // 跳到下一条记录 
		i++; 
	} 
	theApp.m_pRs.Close(); // 关闭出差记录表 
} 
 
void CEditDlg::UpdatexjList() 
{ 
	int i=0,id,stat; 
	CString strID,strSTime,strETime,strSQL; 
	COleDateTime	t_time; 
	strSQL.Format("SELECT * FROM CHANGE WHERE STUDENT='%s'",m_in_id); 
	theApp.m_pRs.Open(_T(strSQL),CADORecordset::openUnknown); // 打开出差记录表 
	m_xjlist.DeleteAllItems(); // 清除列表框内容 
	while(!theApp.m_pRs.IsEOF()) // 对数据表中所有记录进行处理 
	{ 
		m_xjlist.InsertItem(i, "");// 添加新Item 
		theApp.m_pRs.GetFieldValue("ID",id); 
		strID.Format("%d",id); // 转换为字符串 
		m_xjlist.SetItemText(i, 0, strID); 
		 
		theApp.m_pRs.GetFieldValue("STUDENT",strID); 
		m_xjlist.SetItemText(i, 1, strID); 
		theApp.m_pRs.GetFieldValue("REC_TIME",t_time); 
		m_xjlist.SetItemText(i, 2, t_time.Format("%y-%m-%d")); 
 
		theApp.m_pRs.GetFieldValue("CHANGE",stat); 
		switch(stat) 
		{ 
		case 0:strSTime.Format("转系");break; 
		case 1:strSTime.Format("休学");break; 
		case 2:strSTime.Format("复学");break; 
		case 3:strSTime.Format("退学");break; 
		case 4:strSTime.Format("毕业");break; 
		} 
		 
		m_xjlist.SetItemText(i, 3, strSTime); 
 
		theApp.m_pRs.GetFieldValue("DESCRIPTION",strETime); 
		m_xjlist.SetItemText(i, 4,strETime); 
		theApp.m_pRs.MoveNext(); // 跳到下一条记录 
		i++; 
	} 
	theApp.m_pRs.Close(); // 关闭出差记录表 
 
} 
 
void CEditDlg::OnEdit()  
{ 
	// TODO: Add your control notification handler code here 
	UpdateData(); 
//	CStuMisApp *app=AfxGetApp(); 
	CString addstr,strTime,strSQL; 
//	COleDateTime	t_time; 
//	strSQL.Format("UPDATE STUDENT SET NAME=%s,SEX=%d,CLASS=%s,DEPARTMENT=%s,NATIVE_PLACE=%s,BIRTHDAY FROM STUDENT WHERE ID='%s'",m_in_id); 
 
//	strTime.Format("%s",m_birthday.Format("%Y-%m-%d")); 
 
 
//	addstr.Format("insert into STUDENT (ID,NAME,SEX,CLASS,DEPARTMENT,NATIVE_PLACE,BIRTHDAY) values ('%s','%s',%d,'%s','%s','%s',%s)",m_stuid,m_name,m_sex,m_class,m_department,m_nativeplace,strTime);  
//	addstr.Format("insert into STUDENT (ID,NAME,SEX,NATIVE_PLACE) values ('%s','%s',%d,'%s')",m_stuid,m_name,m_sex,m_nativeplace);  
//	app->db.Execute(addstr); 
 //  m_pRecordset->AddNew();   
	strSQL.Format("SELECT * FROM STUDENT WHERE ID=%s",m_in_id); 
     
	theApp.m_pRs.Open(strSQL,CADORecordset::openUnknown); 
	 
	theApp.m_pRs.Edit(); 
 
	theApp.m_pRs.SetFieldValue("NAME",m_out_name); 
	theApp.m_pRs.SetFieldValue("CLASS",m_out_class); 
	theApp.m_pRs.SetFieldValue("SEX",m_out_sex); 
	theApp.m_pRs.SetFieldValue("DEPARTMENT",m_out_department); 
	theApp.m_pRs.SetFieldValue("BIRTHDAY",m_out_birthday); 
	theApp.m_pRs.SetFieldValue("NATIVE_PLACE",m_out_native_place); 
	if(!theApp.m_pRs.Update())AfxMessageBox("can not update"); 
	else AfxMessageBox("修改成功!!!"); 
	theApp.m_pRs.Close();	 
}