📄 shipage.cpp
字号:
// shipage.cpp : implementation file
//
#include "stdafx.h"
#include "教学管理信息系统.h"
#include "shipage.h"
#include "Public.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// Cshipage property page
IMPLEMENT_DYNCREATE(Cshipage, CPropertyPage)
Cshipage::Cshipage() : CPropertyPage(Cshipage::IDD)
{
//{{AFX_DATA_INIT(Cshipage)
m_stuname = _T("");
m_sum = _T("");
m_time = _T("");
m_bursename = _T("");
m_bursekind = _T("");
//}}AFX_DATA_INIT
}
Cshipage::~Cshipage()
{
}
void Cshipage::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(Cshipage)
DDX_Control(pDX, IDC_LISTburseship, m_lstburse);
DDX_Text(pDX, IDC_EDITstuname, m_stuname);
DDX_Text(pDX, IDC_EDITsum, m_sum);
DDX_Text(pDX, IDC_EDITtime, m_time);
DDX_Text(pDX, IDC_EDITbursename, m_bursename);
DDX_Text(pDX, IDC_EDITbursekind, m_bursekind);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(Cshipage, CPropertyPage)
//{{AFX_MSG_MAP(Cshipage)
ON_BN_CLICKED(IDC_BUTTONadd, OnBUTTONadd)
ON_NOTIFY(NM_CLICK, IDC_LISTburseship, OnClickLISTburseship)
ON_BN_CLICKED(IDC_BUTTONuupdate, OnBUTTONuupdate)
ON_NOTIFY(LVN_COLUMNCLICK, IDC_LISTburseship, OnColumnclickLISTburseship)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Cshipage message handlers
void Cshipage::OnBUTTONadd()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
try{
if(m_set.IsOpen())
m_set.Close();
m_set.Open(CRecordset::dynaset,NULL,CRecordset::none);
m_set.AddNew();
m_set.m_stuname=m_stuname;
m_set.m_bursename=m_bursename;
m_set.m_bursekind=m_bursekind;
m_set.m_time=m_time;
m_set.m_sum=m_sum;
m_set.Update();
m_set.Requery();
m_set.Close();
m_lstburse.DeleteAllItems();
initctrldata();
SetDlgItemText(IDC_EDITstuname,"");
SetDlgItemText(IDC_EDITbursekind,"");
SetDlgItemText(IDC_EDITbursename,"");
SetDlgItemText(IDC_EDITtime,"");
SetDlgItemText(IDC_EDITsum,"");
}
catch(CDBException*e)
{
e->ReportError();
return;
}
}
BOOL Cshipage::OnInitDialog()
{
CPropertyPage::OnInitDialog();
if(CPublic::or==2)
{
GetDlgItem(IDC_BUTTONadd)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTONuupdate)->EnableWindow(FALSE);
}
// TODO: Add extra initialization here
int i;
DWORD dwNewStyle= LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP |
LVS_EX_ONECLICKACTIVATE | LVS_EX_UNDERLINEHOT;
m_lstburse.SetExtendedStyle(dwNewStyle);
m_lstburse.InsertColumn(0,"学生姓名",LVCFMT_CENTER);
m_lstburse.InsertColumn(1,"奖学金名称",LVCFMT_CENTER);
m_lstburse.InsertColumn(2,"类别(等级)",LVCFMT_CENTER);
m_lstburse.InsertColumn(3,"获奖时间",LVCFMT_CENTER);
m_lstburse.InsertColumn(4,"金额",LVCFMT_CENTER);
for(i=0;i<5;i++)
m_lstburse.SetColumnWidth(i,80);
initctrldata();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void Cshipage::insertstufeeinfo(CString stuname,CString duty,CString
time,CString depart,CString other)
{
int index=m_lstburse.GetItemCount();
LV_ITEM lvitem;
lvitem.mask=LVIF_TEXT;
lvitem.iItem=index;
lvitem.iSubItem=0;
CString temp;
temp.Format("%d");
lvitem.pszText=(char*)(LPCTSTR)temp;
m_lstburse.InsertItem(&lvitem);
m_lstburse.SetItemText(index,0,stuname);
m_lstburse.SetItemText(index,1,duty);
m_lstburse.SetItemText(index,2,time);
m_lstburse.SetItemText(index,3,depart);
m_lstburse.SetItemText(index,4,other);
}
void Cshipage::initctrldata()
{
CDatabase m_database;
if(!m_database.Open(NULL,FALSE,FALSE,"ODBC;DSN=教务课程信息管理数据库"))
{
AfxMessageBox("连接数据库失败");
}
try{
m_set.Open(CRecordset::dynaset,NULL,CRecordset::none);
while(!m_set.IsEOF())
{
CString stuname,duty,time,depart,other;
m_set.GetFieldValue((short)0,stuname);
m_set.GetFieldValue(1,duty);
m_set.GetFieldValue(2,time);
m_set.GetFieldValue(3,depart);
m_set.GetFieldValue(4,other);
insertstufeeinfo(stuname,duty,time,depart,other);
m_set.MoveNext();
}
m_set.Close();
}
catch(CDBException*e)
{
e->ReportError();
return;
}
}
void Cshipage::OnClickLISTburseship(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
nitem=m_lstburse.GetNextItem(-1,LVNI_SELECTED);
if(nitem!=-1)
{
m_stuname=m_lstburse.GetItemText(nitem,0);
m_bursename=m_lstburse.GetItemText(nitem,1);
m_bursekind=m_lstburse.GetItemText(nitem,2);
m_time=m_lstburse.GetItemText(nitem,3);
m_sum=m_lstburse.GetItemText(nitem,4);
UpdateData(FALSE);
}
*pResult = 0;
}
void Cshipage::OnBUTTONuupdate()
{
// TODO: Add your control notification handler code here
if(m_set.IsOpen())
m_set.Close();
m_set.Open(CRecordset::dynaset,NULL,CRecordset::none);
m_set.MoveFirst();
for(int i=0;i<=nitem;i++)
{
if(i==nitem)
{
UpdateData(TRUE);
m_set.Edit();
m_set.m_stuname=m_stuname;
m_set.m_bursename=m_bursename;
m_set.m_bursekind=m_bursekind;
m_set.m_time=m_time;
m_set.m_sum=m_sum;
m_set.Update();
m_set.Requery();
m_set.Close();
m_lstburse.DeleteAllItems();
initctrldata();
}
else
{
m_set.MoveNext();
}
}
}
void Cshipage::OnColumnclickLISTburseship(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
int i=pNMListView->iSubItem;
if(m_set.IsOpen())
m_set.Close();
m_set.Open(CRecordset::dynaset,NULL,CRecordset::none);
if(i==0)
{
m_set.m_strSort="stuname";
m_set.Close();
m_lstburse.DeleteAllItems();
initctrldata();
}
if(i==1)
{
m_set.m_strSort="bursename";
m_set.Close();
m_lstburse.DeleteAllItems();
initctrldata();
}
if(i==2)
{
m_set.m_strSort="bursekind";
m_set.Close();
m_lstburse.DeleteAllItems();
initctrldata();
}
if(i==3)
{
m_set.m_strSort="time";
m_set.Close();
m_lstburse.DeleteAllItems();
initctrldata();
}
if(i==4)
{
m_set.m_strSort="sum";
m_set.Close();
m_lstburse.DeleteAllItems();
initctrldata();
}
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -