?? studentmanage.cpp
字號:
// StudentManage.cpp : implementation file
//
#include "stdafx.h"
#include "StudentCheck.h"
#include "StudentManage.h"
#include "Afxtempl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define COLNUM 12 // 11是記錄的屬性數(shù)目
/////////////////////////////////////////////////////////////////////////////
// CStudentManage dialog
CStudentManage::CStudentManage(CWnd* pParent /*=NULL*/)
: CDialog(CStudentManage::IDD, pParent)
{
//{{AFX_DATA_INIT(CStudentManage)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_DepInfo.LoadDep();
m_CurAdo.InitialDB();
m_AllStuInfos.GetAllDBInfo();
}
CStudentManage::~CStudentManage()
{
m_CurAdo.ClosedDB();
}
void CStudentManage::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStudentManage)
DDX_Control(pDX, IDC_MEMBER_LIST, m_StuInfoList);
DDX_Control(pDX, IDC_CLASS_TREE, m_DepInfoTree);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStudentManage, CDialog)
ON_WM_CONTEXTMENU()
//{{AFX_MSG_MAP(CStudentManage)
ON_NOTIFY(TVN_SELCHANGED, IDC_CLASS_TREE, OnTreeSelectChanged)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_MEMBER_LIST, OnItemchangedMemberList)
ON_NOTIFY(LVN_KEYDOWN, IDC_MEMBER_LIST, OnKeydownMemberList)
ON_NOTIFY(NM_DBLCLK, IDC_MEMBER_LIST, OnDblclkMemberList)
ON_COMMAND(ID_EDIT_INSERT, OnEditInsert)
ON_COMMAND(ID_EDIT_MODIFY, OnEditModify)
ON_COMMAND(ID_EDIT_DEL, OnEditDel)
ON_COMMAND(IDR_STU_MANAGE, OnStuManage)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CStudentManage::OnInitDialog()
{
CDialog::OnInitDialog();
CString strCurName;
if(!(m_DepImageInfo.Create(IDB_BITMAP1,16,1,RGB(0,255,0))))
AfxMessageBox("圖像列表創(chuàng)建出錯!");
m_DepInfoTree.SetImageList(&m_DepImageInfo,TVSIL_NORMAL);
HTREEITEM htRoot;
CString strRoot = "環(huán)境學(xué)院";
htRoot = m_DepInfoTree.InsertItem(strRoot); //添加根節(jié)點
m_DepInfoTree.SetItemData(htRoot,0);
m_DepInfo.CreatTree(htRoot, m_DepInfoTree);
m_DepInfoTree.Expand(htRoot, TVE_EXPAND);
ConstructTableName();
m_StuInfoList.SetExtendedStyle(LVS_EX_FULLROWSELECT| LVS_EX_GRIDLINES |LVS_EX_CHECKBOXES);
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CStudentManage message handlers
void CStudentManage::OnTreeSelectChanged(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
*pResult = 0;
HTREEITEM hCurItem;
HTREEITEM hCurChildItem;
CString strCurClassID;
hCurItem = m_DepInfoTree.GetSelectedItem();
if (NULL != hCurItem)
{
hCurChildItem = m_DepInfoTree.GetChildItem(hCurItem);
if (NULL == hCurChildItem) // 若某一個節(jié)點,其孩子為空,說明其為根節(jié)點,可以使用查詢語句尋找具體信息
{
// 如果當(dāng)前的所選擇的葉子節(jié)點發(fā)生了變化,那么就修改當(dāng)前查詢語句 m_strCurQuaryInfo
// 并且發(fā)送消息,導(dǎo)致整個對話框發(fā)生刷新
strCurClassID.Format("%d", m_DepInfoTree.GetItemData(hCurItem));
ModityCurQueryMessage(strCurClassID);
}
}
}
void CStudentManage::ModityCurQueryMessage(CString _strCurClassID)
{
//傳進來的是班級號 通過該號碼對班級成員進行檢索
CString strStandInfo;
CString strQuotationMark;
strStandInfo.LoadString(IDS_STANDARD_STU_QUERY);
strQuotationMark.LoadString(IDS_QUOTATION_MARK);
m_strCurQuaryInfo = strStandInfo + strQuotationMark + _strCurClassID + strQuotationMark;
// AfxMessageBox(m_strCurQuaryInfo);
RefreshData();
}
void CStudentManage::RefreshData()
{
//刷新,這里用了一個很笨的方法:全部重新查詢
//比較好的辦法是有針對性的查詢
//或者是有針對性的修改當(dāng)前顯示
//時間關(guān)系,采用最簡單的方式和方法進行
UpdateData(TRUE);
m_StuInfoList.DeleteAllItems();
CArray <CString, LPCTSTR> StudentInfoAry;
CString strCurColInfo;
StudentInfoAry.SetSize(COLNUM);
CString * pCurInfo = StudentInfoAry.GetData();
int nRecordNum = 0;
// 如果記錄集不為空
_RecordsetPtr CurRecordset;
_variant_t nIndex = (long)0;
_variant_t var;
CString strCollege="環(huán)境學(xué)院"; //把03給替換掉
CurRecordset = m_CurAdo.GetRecordSet(LPCTSTR(m_strCurQuaryInfo));
while (0 == CurRecordset->adoEOF)
{
//取一條記錄付值給數(shù)組StudentInfoAry
for (int i = 0; i < COLNUM; i++)
{
nIndex = (long) i;
var = CurRecordset->GetCollect(nIndex);
pCurInfo[i] = (LPCTSTR)(_bstr_t )var;
}
m_StuInfoList.InsertItem(nRecordNum, "");
for (int j = 0; j < COLNUM; j++)
{
// strCurColInfo = StudentInfoAry[i];
pCurInfo[j] = m_AllStuInfos.GetNum(pCurInfo[j]);
if(7==j)
pCurInfo[j]=strCollege;
m_StuInfoList.SetItemText(nRecordNum, j, pCurInfo[j]);
}
nRecordNum ++;
//記錄轉(zhuǎn)下一條
CurRecordset->MoveNext();
}
}
void CStudentManage::DelRecord()
{
//刪除記錄主要分成三個部分:
// 1 選擇要刪除的記錄
// 2 刪除之
// 3 對整體進行刷新
int nCurItem = 0;
int i = 0;
int nColCounts = 0;
LVCOLUMN colCurColumn;
CString strCurColName;
CString strStuID;
CString strDelRecord;
CString strCurDelCommand;
CString strQuotationMark;
CString strTableNameStuID;
char str[256];
strQuotationMark.LoadString(IDS_QUOTATION_MARK);
strDelRecord.LoadString(IDS_ORDERS_DEL_STU);
strTableNameStuID.LoadString(IDS_COLNAME_STUID);
colCurColumn.mask = LVCF_TEXT;
colCurColumn.pszText = str;
colCurColumn.cchTextMax = 256;
if (m_nCurItem >= 0)
{
// 如果當(dāng)前選到了記錄
// 獲得記錄的屬性數(shù)目
nColCounts = m_StuInfoList.GetHeaderCtrl()->GetItemCount();
// MD 老子討厭寫個破11在這里
for (i = 0; i < nColCounts; i++)
{
m_StuInfoList.GetColumn(i, &colCurColumn);
strCurColName = colCurColumn.pszText;
if (strCurColName == strTableNameStuID)
{
strStuID = m_StuInfoList.GetItemText(m_nCurItem, i);
strCurDelCommand = strDelRecord + strQuotationMark + strStuID + strQuotationMark;
RunSQLCommand(strCurDelCommand);
RefreshData();
}
}
}
}
void CStudentManage::InsertRecord()
{
CString strCurSQL;
CStudentInfoDlg CurStuInfoDlg;
CurStuInfoDlg.SetStuInfoPointer(&m_AllStuInfos);
if (TRUE == CurStuInfoDlg.DoModal())
{
strCurSQL = CurStuInfoDlg.GetModifySQL();
RunSQLCommand(strCurSQL);
RefreshData();
}
}
void CStudentManage::RunSQLCommand(CString _strSQLCommand)
{
// AfxMessageBox(_strSQLCommand);
m_CurAdo.ExecuteSQL(LPCTSTR(_strSQLCommand));
}
void CStudentManage::OnItemchangedMemberList(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
*pResult = 0;
// 獲得當(dāng)前 item
int nCurItem = 0;
nCurItem = pNMListView->iItem;
if (-1 != nCurItem)
{
m_nCurItem = nCurItem;
}
}
void CStudentManage::ConstructTableName()
{
CArray <CString, LPCTSTR> TableNameAry;
CString * pCurTableName = NULL;
UINT nCurUINT = IDS_COL_NAME_ID;
TableNameAry.SetSize(COLNUM);
pCurTableName = TableNameAry.GetData();
for (int i = 0; i < COLNUM; i++)
{
pCurTableName[i].LoadString(nCurUINT + i);
}
int j;
for (j = 0; j < COLNUM; j++)
{
m_StuInfoList.InsertColumn(j, pCurTableName[j], LVCFMT_LEFT, 100);
}
for (j = 0; j < COLNUM; j++)
{
m_StuInfoList.SetColumnWidth(j, 90);
}
}
void CStudentManage::OnKeydownMemberList(NMHDR* pNMHDR, LRESULT* pResult)
{
LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR;
// TODO: Add your control notification handler code here
*pResult = 0;
// DelRecord();
}
void CStudentManage::OnDblclkMemberList(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
*pResult = 0;
GetCurRecord();
}
void CStudentManage::GetCurRecord()
{
CStudentInfoDlg CurStuInfoDlg;
CurStuInfoDlg.SetStuInfoPointer(&m_AllStuInfos);
CArray <CString, LPCTSTR> StudentInfoAry;
StudentInfoAry.SetSize(COLNUM - 1); // 減一個是減掉了ID序列號
CString * pCurString = StudentInfoAry.GetData();
CString strCurSQL;
int nCurArySize = 0;
nCurArySize = StudentInfoAry.GetSize();
int i = 0;
int j = 0;
// 獲得當(dāng)前的記錄的所有信息 m_nCurItem 是當(dāng)前記錄
if (m_nCurItem >= 0)
{
for (i = 0; i < nCurArySize; i++)
{
pCurString[i] = m_StuInfoList.GetItemText(m_nCurItem, i+1);
}
CurStuInfoDlg.SetItmeInfos(&StudentInfoAry, nCurArySize);
CurStuInfoDlg.SetNewRecordSign(FALSE);
CurStuInfoDlg.SetStuIDReadOnly();
if (TRUE == CurStuInfoDlg.DoModal())
{
//判斷是否經(jīng)過修改,然后做數(shù)據(jù)庫的操作
if (CurStuInfoDlg.IsCurDateChanged())
{
strCurSQL = CurStuInfoDlg.GetModifySQL();
RunSQLCommand(strCurSQL);
RefreshData();
}
}
}
}
#include "resource.h"
void CStudentManage::OnContextMenu(CWnd*, CPoint point)
{
// CG: This block was added by the Pop-up Menu component { if (point.x == -1 && point.y == -1){ //keystroke invocation CRect rect; GetClientRect(rect); ClientToScreen(rect); point = rect.TopLeft(); point.Offset(5, 5); } CMenu menu; VERIFY(menu.LoadMenu(CG_IDR_POPUP_STUDENT_MANAGE)); CMenu* pPopup = menu.GetSubMenu(0); ASSERT(pPopup != NULL); CWnd* pWndPopupOwner = this; while (pWndPopupOwner->GetStyle() & WS_CHILD) pWndPopupOwner = pWndPopupOwner->GetParent(); pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, pWndPopupOwner); }
}
void CStudentManage::OnEditInsert()
{
// TODO: Add your command handler code here
InsertRecord();
}
void CStudentManage::OnEditModify()
{
// TODO: Add your command handler code here
GetCurRecord();
}
void CStudentManage::OnEditDel()
{
// TODO: Add your command handler code here
CString strSur2Del;
strSur2Del.LoadString(IDS_SURE_TO_DEL);
if (IDOK == AfxMessageBox(strSur2Del, MB_OKCANCEL))
{
DelRecord();
}
}
void CStudentManage::OnStuManage()
{
// TODO: Add your command handler code here
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -