ganbupage.cpp

来自「大学班务管理系统」· C++ 代码 · 共 266 行

CPP
266
字号
// ganbupage.cpp : implementation file
//

#include "stdafx.h"
#include "教学管理信息系统.h"
#include "ganbupage.h"
#include "Public.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// Cganbupage property page

IMPLEMENT_DYNCREATE(Cganbupage, CPropertyPage)

Cganbupage::Cganbupage() : CPropertyPage(Cganbupage::IDD)
{
	//{{AFX_DATA_INIT(Cganbupage)
	m_stuname = _T("");
	m_duty = _T("");
	m_time = _T("");
	m_depart = _T("");
	m_other = _T("");
	//}}AFX_DATA_INIT
}

Cganbupage::~Cganbupage()
{
}

void Cganbupage::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(Cganbupage)
	DDX_Control(pDX, IDC_LISTstuofficial, m_lstofficial);
	DDX_Text(pDX, IDC_EDITstuname, m_stuname);
	DDX_Text(pDX, IDC_EDITduty, m_duty);
	DDX_Text(pDX, IDC_EDITtime, m_time);
	DDX_Text(pDX, IDC_EDITdepart, m_depart);
	DDX_Text(pDX, IDC_EDITother, m_other);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(Cganbupage, CPropertyPage)
	//{{AFX_MSG_MAP(Cganbupage)
	ON_BN_CLICKED(IDC_BUTTONadd, OnBUTTONadd)
	ON_NOTIFY(NM_CLICK, IDC_LISTstuofficial, OnClickLISTstuofficial)
	ON_BN_CLICKED(IDC_BUTTONupdate, OnBUTTONupdate)
	ON_NOTIFY(LVN_COLUMNCLICK, IDC_LISTstuofficial, OnColumnclickLISTstuofficial)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Cganbupage message handlers

void Cganbupage::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_name=m_stuname;
    m_set.m_duty=m_duty;
	m_set.m_time=m_time;
	m_set.m_depart=m_depart;
    m_set.m_other=m_other;
	
    m_set.Update();
    m_set.Requery();
    m_set.Close();
     m_lstofficial.DeleteAllItems();
     initctrldata();
	 SetDlgItemText(IDC_EDITstuname,""); 
	 SetDlgItemText(IDC_EDITduty,"");
	 SetDlgItemText(IDC_EDITtime,"");
	 SetDlgItemText(IDC_EDITdepart,"");
	 SetDlgItemText(IDC_EDITother,"");

}
catch(CDBException*e)
	{
		e->ReportError();
		return;
	}
}

BOOL Cganbupage::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	  if(CPublic::or==2)
    {
	GetDlgItem(IDC_BUTTONadd)->EnableWindow(FALSE);
	GetDlgItem(IDC_BUTTONupdate)->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_lstofficial.SetExtendedStyle(dwNewStyle);
	m_lstofficial.InsertColumn(0,"学生姓名",LVCFMT_CENTER);
	m_lstofficial.InsertColumn(1,"职务",LVCFMT_CENTER);
	m_lstofficial.InsertColumn(2,"任职时间",LVCFMT_CENTER);
	m_lstofficial.InsertColumn(3,"任职部门",LVCFMT_CENTER);
    m_lstofficial.InsertColumn(4,"备注",LVCFMT_CENTER);
	for(i=0;i<5;i++)
	m_lstofficial.SetColumnWidth(i,80);
	initctrldata();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
void Cganbupage::insertstufeeinfo(CString stuname,CString duty,CString 
								time,CString depart,CString other)
								
{
	int index=m_lstofficial.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_lstofficial.InsertItem(&lvitem);
    m_lstofficial.SetItemText(index,0,stuname);
	m_lstofficial.SetItemText(index,1,duty);
	m_lstofficial.SetItemText(index,2,time);
    m_lstofficial.SetItemText(index,3,depart);
    m_lstofficial.SetItemText(index,4,other);

}




void Cganbupage::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 Cganbupage::OnClickLISTstuofficial(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
		nitem=m_lstofficial.GetNextItem(-1,LVNI_SELECTED);
	if(nitem!=-1)
	{
		m_stuname=m_lstofficial.GetItemText(nitem,0);
        m_duty=m_lstofficial.GetItemText(nitem,1);
		m_time=m_lstofficial.GetItemText(nitem,2);
		m_depart=m_lstofficial.GetItemText(nitem,3);
		m_other=m_lstofficial.GetItemText(nitem,4);

         UpdateData(FALSE);
	}

	*pResult = 0;
}

void Cganbupage::OnBUTTONupdate() 
{
	// 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_name=m_stuname;
    m_set.m_duty=m_duty;
	m_set.m_time=m_time;
	m_set.m_depart=m_depart;
    m_set.m_other=m_other;
    m_set.Update();
    m_set.Requery();
    m_set.Close();
    m_lstofficial.DeleteAllItems();
    initctrldata(); 
	}
		 else
		 {
			 m_set.MoveNext();
			 
		 }
 }
}

void Cganbupage::OnColumnclickLISTstuofficial(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="name";
	m_set.Close();
    m_lstofficial.DeleteAllItems();
	initctrldata();
	}
	if(i==1)
	{
	m_set.m_strSort="duty";
	m_set.Close();
    m_lstofficial.DeleteAllItems();
	initctrldata();
	}
	if(i==2)
	{
	m_set.m_strSort="time";
	m_set.Close();
    m_lstofficial.DeleteAllItems();
	initctrldata();
	}
	if(i==3)
	{
	m_set.m_strSort="depart";
	m_set.Close();
    m_lstofficial.DeleteAllItems();
	initctrldata();
	}
	*pResult = 0;
}

⌨️ 快捷键说明

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