📄 chaxunkechengxinxidlg.cpp
字号:
// chaxunkechengxinxiDlg.cpp : implementation file
//
#include "stdafx.h"
#include "pmz.h"
#include "chaxunkechengxinxiDlg.h"
#include "pmzDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// chaxunkechengxinxiDlg dialog
chaxunkechengxinxiDlg::chaxunkechengxinxiDlg(CWnd* pParent /*=NULL*/)
: CDialog(chaxunkechengxinxiDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(chaxunkechengxinxiDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_pdb=new CDatabase;
m_pdb->Open(NULL,FALSE,FALSE,mydb);
}
chaxunkechengxinxiDlg::~chaxunkechengxinxiDlg()
{
m_pdb->Close();
delete m_pdb;
}
void chaxunkechengxinxiDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(chaxunkechengxinxiDlg)
DDX_Control(pDX, IDC_LIST1, m_pList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(chaxunkechengxinxiDlg, CDialog)
//{{AFX_MSG_MAP(chaxunkechengxinxiDlg)
ON_BN_CLICKED(IDOK, Onshanchukechengxinxi)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// chaxunkechengxinxiDlg message handlers
chaxunkechengxinxiDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CListCtrl* m_pList = (CListCtrl*)GetDlgItem(IDC_LIST1);
DWORD dwStyle= GetWindowLong(m_pList->m_hWnd, GWL_STYLE);
SetWindowLong( m_pList->m_hWnd, GWL_STYLE, dwStyle | LVS_REPORT);
//设置ListCtrl可以整行选择和网格条纹
DWORD styles = m_pList->GetExtendedStyle();
m_pList->SetExtendedStyle(styles|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
m_pList->SetBkColor(RGB(0xFF, 0xFF, 0xE0));
m_pList->SetTextBkColor(RGB(0xFF, 0xFF, 0xE0));
//设置列的题头
m_pList->InsertColumn(1,"课程号",LVCFMT_CENTER,80);
m_pList->InsertColumn(2,"课程名",LVCFMT_CENTER,120);
m_pList->InsertColumn(3,"教师姓名",LVCFMT_CENTER,110);
m_pList->InsertColumn(4,"系办电话",LVCFMT_CENTER,120);
m_pList->InsertColumn(5,"开课院系",LVCFMT_CENTER,180);
CString str1="SELECT * FROM C_info ",C_no,C_name,C_time,C_place,T_no;
m_pList->DeleteAllItems();
m_precordset=new kecheng_infodb(m_pdb);
m_precordset->Open(kecheng_infodb::snapshot,str1);
int i=0;
if(m_precordset->IsEOF())
{
return true;
}
else
{
m_precordset->MoveFirst();
while(!m_precordset->IsEOF())
{
CString strt=m_precordset->m_T_no;
CString str2="SELECT * FROM T_info where T_no='"+strt+"'";
CString T_name,T_officetel;
m_tprecordset=new T_infodb(m_pdb);
m_tprecordset->Open(T_infodb::snapshot,str2);
CString strd=m_tprecordset->m_department_no;
CString str3="SELECT * FROM department_info where department_no='"+strd+"'";
CString department_name;
m_dprecordset=new department_infodb(m_pdb);
m_dprecordset->Open(department_infodb::snapshot,str3);
C_no=m_precordset->m_C_no;
C_name=m_precordset->m_C_name;
T_name=m_tprecordset->m_T_name;
T_officetel=m_tprecordset->m_T_officetel;
department_name=m_dprecordset->m_department_name;
m_pList->InsertItem(i,C_no);
m_pList->SetItemText(i,1,C_name);
m_pList->SetItemText(i,2,T_name);
m_pList->SetItemText(i,3,T_officetel);
m_pList->SetItemText(i,4,department_name);
m_precordset->MoveNext();
i++;
}
}
delete m_precordset;
delete m_tprecordset;
delete m_dprecordset;
return true;
}
void chaxunkechengxinxiDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void chaxunkechengxinxiDlg::Onshanchukechengxinxi()
{
int j;
j=m_pList.GetSelectionMark();
if(j<0)
{
AfxMessageBox("请在列表框点击选中要删除的记录!");
return;
}
else
{
if(AfxMessageBox("这将删除所有与此教师有关的信息,继续吗?",MB_YESNO)==IDYES)
{
CString str;
str=m_pList.GetItemText(j,0);
CString str0="delete from CT_info where C_no= '"+str+"'";
CString str1="delete from SC_info where C_no= '"+str+"'";
CString str2="delete from C_info where C_no= '"+str+"'";
m_pdb->ExecuteSQL(str0);
m_pdb->ExecuteSQL(str1);
m_pdb->ExecuteSQL(str2);
m_pList.DeleteItem(j);
AfxMessageBox("删除成功!");
}
else return;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -