www.pudn.com > StuMis.rar > JWmoney.cpp
// JWmoney.cpp : implementation file
//
#include "stdafx.h"
#include "StuMis.h"
#include "JWmoney.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CStuMisApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CJWmoney property page
IMPLEMENT_DYNCREATE(CJWmoney, CPropertyPage)
CJWmoney::CJWmoney() : CPropertyPage(CJWmoney::IDD)
{
//{{AFX_DATA_INIT(CJWmoney)
m_sid = _T("");
m_editlong = _T("");
m_datetime = COleDateTime::GetCurrentTime();
m_combo = -1;
//}}AFX_DATA_INIT
}
CJWmoney::~CJWmoney()
{
}
void CJWmoney::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CJWmoney)
DDX_Control(pDX, IDC_MONEYLIST, m_mlist);
DDX_Text(pDX, IDC_SID, m_sid);
DDX_Text(pDX, IDC_EDITLONG, m_editlong);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER1, m_datetime);
DDX_CBIndex(pDX, IDC_COMBO1, m_combo);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CJWmoney, CPropertyPage)
//{{AFX_MSG_MAP(CJWmoney)
ON_WM_PAINT()
ON_BN_CLICKED(IDC_DELETE, OnDelete)
ON_BN_CLICKED(IDC_AddItem, OnAddItem)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CJWmoney message handlers
void CJWmoney::UpdateList()
{
int i=0,id,stat;
CString strID,strSTime,strETime,strSQL;
COleDateTime t_time;
strSQL.Format("SELECT * FROM REWARD WHERE STUDENT='%s'",m_sid);
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(); // 关闭出差记录表
}
BOOL CJWmoney::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);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CJWmoney::OnPaint()
{
CPaintDC dc(this); // device context for painting
// UpdateData(FALSE);
// m_sid=(CJWinputDlg*)(GetParent( ))->m_inputid;
// TODO: Add your message handler code here
// UpdateList();
// Do not call CPropertyPage::OnPaint() for painting messages
}
void CJWmoney::OnDelete()
{
// TODO: Add your control notification handler code here
CString strSQL;
int nItem;
// 得到第一个被选择Item的位置
POSITION pos = m_mlist.GetFirstSelectedItemPosition();
if(pos==NULL)
{
AfxMessageBox("没有选择记录!");
return;
}
while(pos) // 遍历所有被选Item
{
nItem=m_mlist.GetNextSelectedItem(pos); // 得到Item Index
// 构造SQL语句
strSQL="delete from REWARD where ID=" + m_mlist.GetItemText(nItem, 0);
theApp.db.Execute(strSQL); // 执行
}
// COvertimeRS rs(&db); // 构造加班记录表
UpdateList(); // 更新列表框
}
void CJWmoney::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 REWARD"),CADORecordset::openUnknown);
theApp.m_pRs.AddNew();
theApp.m_pRs.SetFieldValue("STUDENT",m_sid);
theApp.m_pRs.SetFieldValue("LEVELS",m_combo);
// 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_editlong);
// theApp.m_pRs.SetFieldValue("BIRTHDAY",m_birthday);
theApp.m_pRs.Update();
theApp.m_pRs.Close();
UpdateList();
}
BOOL CJWmoney::OnSetActive()
{
// TODO: Add your specialized code here and/or call the base class
// UpdateData(FALSE);
// UpdateList();
return CPropertyPage::OnSetActive();
}