?? departmentdlg.cpp
字號:
// DepartmentDlg.cpp : implementation file
//
#include "stdafx.h"
#include "StuManage.h"
#include "DepartmentDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDepartmentDlg dialog
extern CStuManageApp theApp;
CDepartmentDlg::CDepartmentDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDepartmentDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDepartmentDlg)
m_strClass = _T("");
m_strDepartment = _T("");
m_strSchool = _T("");
m_strSpeciality = _T("");
//}}AFX_DATA_INIT
}
void CDepartmentDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDepartmentDlg)
DDX_Control(pDX, IDC_TREE_DEPARTMENT, m_treeDepartment);
DDX_Text(pDX, IDC_EDIT_CLASS, m_strClass);
DDX_Text(pDX, IDC_EDIT_DEPARTMENT, m_strDepartment);
DDX_Text(pDX, IDC_EDIT_SCHOOL, m_strSchool);
DDX_Text(pDX, IDC_EDIT_SPECIALITY, m_strSpeciality);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDepartmentDlg, CDialog)
//{{AFX_MSG_MAP(CDepartmentDlg)
ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_DEPARTMENT, OnSelchangedTreeDepartment)
ON_BN_CLICKED(ID_ADD_DEPARTMENT_BTN, OnAddDepartmentBtn)
ON_BN_CLICKED(IDC_ADD_DEPARTMENT_BTN_NEXT, OnAddDepartmentBtnNext)
ON_BN_CLICKED(IDC_EXECUTE_DEPARTMENT_BTN, OnExecuteDepartmentBtn)
ON_BN_CLICKED(ID_DELETE_DEPARTMENT_BTN, OnDeleteDepartmentBtn)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDepartmentDlg message handlers
BOOL CDepartmentDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_strSchool = "浙江科技學院";
DWORD dwStyles=GetWindowLong(m_treeDepartment.m_hWnd,GWL_STYLE);//獲取樹控制原風格
dwStyles|=TVS_EDITLABELS|TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT;
SetWindowLong(m_treeDepartment.m_hWnd,GWL_STYLE,dwStyles);//重新設置風格
HTREEITEM hRoot,hCur,hChild;//樹控制項目句柄
TV_INSERTSTRUCT TCItem;//插入數據項數據結構
TCItem.hParent=TVI_ROOT;//增加根項
TCItem.hInsertAfter=TVI_LAST;//在最后項之后
TCItem.item.mask=TVIF_TEXT|TVIF_PARAM|TVIF_IMAGE|TVIF_SELECTEDIMAGE;//設屏蔽
TCItem.item.pszText="浙江科技學院";
TCItem.item.lParam=0;//序號
hRoot=m_treeDepartment.InsertItem(&TCItem);//返回根項句柄
CString str,sql,str1,str2;
char* DJ[20];//院系結點
char* SJ[20][20];//專業結點
char* CJ[20][20][20];//班級結點
int i,j,m;
str = "院系";
sql="SELECT * FROM Department WHERE Type = '"+str+"'";
m_pRecordset_dep.CreateInstance("ADODB.Recordset");
m_pRecordset_dep->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenDynamic,adLockOptimistic,adCmdText);
if(m_pRecordset_dep->GetRecordCount() != 0)
{
i=0;
while(!m_pRecordset_dep->adoEOF)
{
str = m_pRecordset_dep->GetCollect("Name").bstrVal;
DJ[i] = str.LockBuffer();
//添加院系
TCItem.hParent=hRoot;
TCItem.item.pszText=DJ[i];
TCItem.item.lParam=(i+1)*20;//子項序號
hCur=m_treeDepartment.InsertItem(&TCItem);
//-------------------------------------------------------
str1 = "專業";
sql="SELECT * FROM Department WHERE Type = '"+str1+"' and Department = '"+str+"'";
m_pRecordset_spe.CreateInstance("ADODB.Recordset");
m_pRecordset_spe->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenDynamic,adLockOptimistic,adCmdText);
if(m_pRecordset_spe->GetRecordCount() != 0)
{
j=0;
while(!m_pRecordset_spe->adoEOF)
{
str1 = m_pRecordset_spe->GetCollect("Name").bstrVal;
SJ[i][j] = str1.LockBuffer();
//添加專業
TCItem.hParent=hCur;
TCItem.item.pszText=SJ[i][j];
TCItem.item.lParam=(i+1)*20+(j+1);//子項序號
hChild = m_treeDepartment.InsertItem(&TCItem);
//--------------------------------------------------
str2 = "班級";
sql="SELECT * FROM Department WHERE Type = '"+str2+"' and Speciality = '"+str1+"' and Department = '"+str+"'";
m_pRecordset_cla.CreateInstance("ADODB.Recordset");
m_pRecordset_cla->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenDynamic,adLockOptimistic,adCmdText);
if(m_pRecordset_cla->GetRecordCount() != 0)
{
m=0;
while(!m_pRecordset_cla->adoEOF)
{
str2 = m_pRecordset_cla->GetCollect("Name").bstrVal;
CJ[i][j][m] = str2.LockBuffer();
//添加班級
TCItem.hParent=hChild;
TCItem.item.pszText=CJ[i][j][m];
TCItem.item.lParam=(i+1)*20*20+(j+1)*20 +(m+1);//子項序號
m_treeDepartment.InsertItem(&TCItem);
m++;
m_pRecordset_cla->MoveNext();
}
m_treeDepartment.Expand(hChild,TVE_EXPAND);//展開班級樹
}
m_pRecordset_cla->Close();
//--------------------------------------------------
j++;
m_pRecordset_spe->MoveNext();
}
m_treeDepartment.Expand(hCur,TVE_EXPAND);//展開專業樹
}
m_pRecordset_spe->Close();
//--------------------------------------------------------
i++;
m_pRecordset_dep->MoveNext();
}
m_treeDepartment.Expand(hRoot,TVE_EXPAND);//展開院系樹
}
m_pRecordset_dep->Close();
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDepartmentDlg::OnSelchangedTreeDepartment(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
SetStatus(TRUE,TRUE,TRUE);
CString sql;
CString text;
CString name,type,department,speciality;
//獲取選中的內容
HTREEITEM hCurItem;
hCurItem=m_treeDepartment.GetSelectedItem ();
text=m_treeDepartment.GetItemText(hCurItem);
if(text.CollateNoCase("浙江科技學院") != 0)
{
sql="SELECT * FROM Department where Name='"+text+"'";
m_pRecordset_spe.CreateInstance("ADODB.Recordset");
m_pRecordset_spe->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenDynamic,adLockOptimistic,adCmdText);
if(m_pRecordset_spe->GetRecordCount()!=0)
{
type = m_pRecordset_spe->GetCollect("Type").bstrVal;
if(type.CompareNoCase("院系") == 0)
{
m_strDepartment = text;
m_strSpeciality = "";
m_strClass = "";
}
else if(type.CompareNoCase("專業") == 0)
{
m_strDepartment = m_pRecordset_spe->GetCollect("Department").bstrVal;
m_strSpeciality = text;
m_strClass = "";
}
else if(type.CollateNoCase("班級") == 0)
{
m_strDepartment = m_pRecordset_spe->GetCollect("Department").bstrVal;
m_strSpeciality = m_pRecordset_spe->GetCollect("Speciality").bstrVal;
m_strClass = text;
}
else
{
return;
}
}
m_pRecordset_spe->Close();
}
else
{
return;
}
UpdateData(FALSE);
*pResult = 0;
}
void CDepartmentDlg::OnAddDepartmentBtn() //同級別
{
// TODO: Add your control notification handler code here
if(theApp.m_Level != 2)
{
AfxMessageBox("您無權進行院系設置");
return;
}
SetStatus(TRUE,TRUE,TRUE);
CString sql;
CString text;
CString name,type,department,speciality;
//獲取選中的內容
HTREEITEM hCurItem;
hCurItem=m_treeDepartment.GetSelectedItem ();
text=m_treeDepartment.GetItemText(hCurItem);
if(text.CollateNoCase("浙江科技學院") != 0)
{
sql="SELECT * FROM Department where Name='"+text+"'";
m_pRecordset_spe.CreateInstance("ADODB.Recordset");
m_pRecordset_spe->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenDynamic,adLockOptimistic,adCmdText);
if(m_pRecordset_spe->GetRecordCount()!=0)
{
type = m_pRecordset_spe->GetCollect("Type").bstrVal;//接點處的類型
if(type.CompareNoCase("院系") == 0)//如果為院系,專業、班級為無效狀態
{
SetStatus(TRUE,FALSE,FALSE);
m_strDepartment = "";//等待輸入
m_flag = 0;
}
else if(type.CompareNoCase("專業") == 0)//如果為專業,班級為無效狀態
{
SetStatus(FALSE,TRUE,FALSE);
m_strSpeciality = "";//等待輸入
m_flag = 1;
}
else if(type.CollateNoCase("班級") == 0)//如果為班級
{
SetStatus(FALSE,FALSE,TRUE);
m_strClass = "";//等待輸入
m_flag = 2;
}
else
{
return;
}
}
m_pRecordset_spe->Close();
}
else
{
return;
}
UpdateData(FALSE);
}
void CDepartmentDlg::OnAddDepartmentBtnNext()
{
// TODO: Add your control notification handler code here
if(theApp.m_Level != 2)
{
AfxMessageBox("您無權進行院系設置");
return;
}
SetStatus(TRUE,TRUE,TRUE);
CString sql;
CString text;
CString name,type,department,speciality;
//獲取選中的內容
HTREEITEM hCurItem;
hCurItem=m_treeDepartment.GetSelectedItem ();
text=m_treeDepartment.GetItemText(hCurItem);
if(text.CollateNoCase("浙江科技學院") != 0)
{
sql="SELECT * FROM Department where Name='"+text+"'";
m_pRecordset_spe.CreateInstance("ADODB.Recordset");
m_pRecordset_spe->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenDynamic,adLockOptimistic,adCmdText);
if(m_pRecordset_spe->GetRecordCount()!=0)
{
type = m_pRecordset_spe->GetCollect("Type").bstrVal;//接點處的類型
if(type.CompareNoCase("院系") == 0)//如果為院系,專業、班級為無效狀態
{
SetStatus(FALSE,TRUE,FALSE);
m_strSpeciality = "";//等待輸入
m_flag = 3;
}
else if(type.CompareNoCase("專業") == 0)//如果為專業,班級為無效狀態
{
SetStatus(FALSE,FALSE,TRUE);
m_strClass = "";//等待輸入
m_flag = 4;
}
else if(type.CollateNoCase("班級") == 0)//如果為班級
{
SetStatus(FALSE,FALSE,FALSE);
AfxMessageBox("沒有下一級別");
}
else
{
return;
}
}
m_pRecordset_spe->Close();
}
else
{
return;
}
UpdateData(FALSE);
}
void CDepartmentDlg::SetStatus(BOOL status1,BOOL status2,BOOL status3)
{
GetDlgItem(IDC_EDIT_DEPARTMENT)->EnableWindow(status1);
GetDlgItem(IDC_EDIT_SPECIALITY)->EnableWindow(status2);
GetDlgItem(IDC_EDIT_CLASS)->EnableWindow(status3);
}
void CDepartmentDlg::OnDeleteDepartmentBtn()
{
// TODO: Add your control notification handler code here
if(theApp.m_Level != 2)
{
AfxMessageBox("您無權進行院系設置");
return;
}
SetStatus(TRUE,TRUE,TRUE);
CString sql;
CString text;
CString name,type,department,speciality;
//獲取選中的內容
HTREEITEM hCurItem;
hCurItem=m_treeDepartment.GetSelectedItem ();
text=m_treeDepartment.GetItemText(hCurItem);
if(text.CollateNoCase("浙江科技學院") != 0)
{
sql="SELECT * FROM Department where Name='"+text+"'";
m_pRecordset_spe.CreateInstance("ADODB.Recordset");
m_pRecordset_spe->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenDynamic,adLockOptimistic,adCmdText);
if(m_pRecordset_spe->GetRecordCount()!=0)
{
type = m_pRecordset_spe->GetCollect("Type").bstrVal;//接點處的類型
if(type.CompareNoCase("院系") == 0)//如果為院系,專業、班級為無效狀態
{
m_flag = 5;
}
else if(type.CompareNoCase("專業") == 0)//如果為專業,班級為無效狀態
{
m_flag = 6;
}
else if(type.CollateNoCase("班級") == 0)//如果為班級
{
m_flag = 7;
}
else
{
return;
}
}
m_pRecordset_spe->Close();
}
else
{
return;
}
UpdateData(FALSE);
}
void CDepartmentDlg::OnExecuteDepartmentBtn()
{
// TODO: Add your control notification handler code here
//open access
UpdateData(TRUE);
CString sql;
CString name,department,speciality;
sql="SELECT * FROM Department ";
m_pRecordset_spe.CreateInstance("ADODB.Recordset");
m_pRecordset_spe->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenDynamic,adLockOptimistic,adCmdText);
switch( m_flag )
{
case 0:
if(m_strDepartment.CompareNoCase("") == 0)
AfxMessageBox("請輸入新增院系的名稱");
else
{
m_pRecordset_spe->AddNew();
m_pRecordset_spe->PutCollect("Name",(_variant_t)m_strDepartment);
m_pRecordset_spe->PutCollect("Type",(_variant_t)"院系");
m_pRecordset_spe->Update();
}
break;
case 1:
case 3:
if(m_strSpeciality.CompareNoCase("") == 0)
AfxMessageBox("請輸入新增專業的名稱");
else
{
m_pRecordset_spe->AddNew();
m_pRecordset_spe->PutCollect("Name",(_variant_t)m_strSpeciality);
m_pRecordset_spe->PutCollect("Type",(_variant_t)"專業");
m_pRecordset_spe->PutCollect("Department",(_variant_t)m_strDepartment);
m_pRecordset_spe->Update();
}
break;
case 2:
case 4:
if(m_strClass.CompareNoCase("") == 0)
AfxMessageBox("請輸入新增班級的名稱");
else
{
m_pRecordset_spe->AddNew();
m_pRecordset_spe->PutCollect("Name",(_variant_t)m_strClass);
m_pRecordset_spe->PutCollect("Type",(_variant_t)"班級");
m_pRecordset_spe->PutCollect("Department",(_variant_t)m_strDepartment);
m_pRecordset_spe->PutCollect("Speciality",(_variant_t)m_strSpeciality);
m_pRecordset_spe->Update();
}
break;
case 5:
if(m_pRecordset_spe->GetRecordCount()!=0)
{
m_pRecordset_spe->MoveFirst();
while(!m_pRecordset_spe->adoEOF)
{
name = m_pRecordset_spe->GetCollect("Name").bstrVal;
department = m_pRecordset_spe->GetCollect("Department").bstrVal;
if(m_strDepartment.CompareNoCase(name)==0||m_strDepartment.CompareNoCase(department)==0)
m_pRecordset_spe->Delete(adAffectCurrent);
m_pRecordset_spe->MoveNext();
}
}
break;
case 6:
if(m_pRecordset_spe->GetRecordCount()!=0)
{
m_pRecordset_spe->MoveFirst();
while(!m_pRecordset_spe->adoEOF)
{
name = m_pRecordset_spe->GetCollect("Name").bstrVal;
speciality = m_pRecordset_spe->GetCollect("Speciality").bstrVal;
if(m_strSpeciality.CompareNoCase(name)==0||m_strSpeciality.CompareNoCase(speciality)==0)
m_pRecordset_spe->Delete(adAffectCurrent);
m_pRecordset_spe->MoveNext();
}
}
break;
case 7:
if(m_pRecordset_spe->GetRecordCount()!=0)
{
m_pRecordset_spe->MoveFirst();
while(!m_pRecordset_spe->adoEOF)
{
name = m_pRecordset_spe->GetCollect("Name").bstrVal;
if(m_strClass.CompareNoCase(name)==0)
m_pRecordset_spe->Delete(adAffectCurrent);
m_pRecordset_spe->MoveNext();
}
}
break;
default :
break;
}
m_pRecordset_spe->Close();
m_treeDepartment.DeleteAllItems();
OnInitDialog();
m_flag = -1;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -