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


// JWpunish.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "StuMis.h" 
#include "JWpunish.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
extern CStuMisApp theApp; 
///////////////////////////////////////////////////////////////////////////// 
// CJWpunish property page 
 
IMPLEMENT_DYNCREATE(CJWpunish, CPropertyPage) 
 
CJWpunish::CJWpunish() : CPropertyPage(CJWpunish::IDD) 
{ 
	//{{AFX_DATA_INIT(CJWpunish) 
	m_sid = _T(""); 
	m_eidtlong = _T(""); 
	m_datetime = COleDateTime::GetCurrentTime(); 
	m_combo = -1; 
	m_comboen = -1; 
	//}}AFX_DATA_INIT 
} 
 
CJWpunish::~CJWpunish() 
{ 
} 
 
void CJWpunish::DoDataExchange(CDataExchange* pDX) 
{ 
	CPropertyPage::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CJWpunish) 
	DDX_Control(pDX, IDC_CFLIST, m_cflist); 
	DDX_Text(pDX, IDC_SID, m_sid); 
	DDX_Text(pDX, IDC_EDITLONG, m_eidtlong); 
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER1, m_datetime); 
	DDX_CBIndex(pDX, IDC_COMBO1, m_combo); 
	DDX_CBIndex(pDX, IDC_COMBOEN, m_comboen); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CJWpunish, CPropertyPage) 
	//{{AFX_MSG_MAP(CJWpunish) 
	ON_BN_CLICKED(IDC_DELETE, OnDelete) 
	ON_BN_CLICKED(IDC_AddItem, OnAddItem) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CJWpunish message handlers 
 
void CJWpunish::UpdateList() 
{ 
		int i=0,id,stat; 
	CString strID,strSTime,strETime,strSQL; 
	COleDateTime	t_time; 
	strSQL.Format("SELECT * FROM PUNISHMENT WHERE STUDENT='%s'",m_sid); 
	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(); // 关闭出差记录表 
} 
 
BOOL CJWpunish::OnInitDialog()  
{ 
	CPropertyPage::OnInitDialog(); 
	 
	// TODO: Add extra initialization here 
	 
	// TODO: Add extra initialization here 
//    m_xjlist.SetExtendedStyle(LVS_EX_GRIDLINES||LVS_EX_FULLROWSELECT ); 
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); 
//	CErrandRS rs(&db); // 构造出差记录表 
//	UpdateList(rs); // 更新List		 
 
//	return TRUE;  // return TRUE unles	 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void CJWpunish::OnDelete()  
{ 
	// TODO: Add your control notification handler code here 
		CString strSQL; 
	int nItem; 
	// 得到第一个被选择Item的位置 
	POSITION pos = m_cflist.GetFirstSelectedItemPosition(); 
	if(pos==NULL) 
	{ 
		AfxMessageBox("没有选择记录!"); 
		return; 
	} 
	while(pos) // 遍历所有被选Item 
	{ 
		nItem=m_cflist.GetNextSelectedItem(pos); // 得到Item Index 
		// 构造SQL语句 
		strSQL="delete from PUNISHMENT where ID=" + m_cflist.GetItemText(nItem, 0); 
		theApp.db.Execute(strSQL); // 执行 
	} 
//	COvertimeRS rs(&db); // 构造加班记录表 
	UpdateList(); // 更新列表框		 
} 
 
void CJWpunish::OnAddItem()  
{ 
	// TODO: Add your control notification handler code here 
	UpdateData(); 
 
//	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();    
	theApp.m_pRs.Open(_T("SELECT * FROM PUNISHMENT"),CADORecordset::openUnknown); 
 
	theApp.m_pRs.AddNew(); 
	theApp.m_pRs.SetFieldValue("STUDENT",m_sid); 
	theApp.m_pRs.SetFieldValue("LEVELS",m_combo); 
	theApp.m_pRs.SetFieldValue("ENABLE",m_comboen); 
//	theApp.m_pRs.SetFieldValue("SEX",m_sex); 
//	theApp.m_pRs.SetFieldValue("CLASS",m_combo); 
	theApp.m_pRs.SetFieldValue("REC_TIME",m_datetime); 
	theApp.m_pRs.SetFieldValue("DESCRIPTION",m_eidtlong); 
//	theApp.m_pRs.SetFieldValue("BIRTHDAY",m_birthday); 
	theApp.m_pRs.Update(); 
	theApp.m_pRs.Close();	 
 
	UpdateList(); 
}