⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chaxunyuanxixinxidlg.cpp

📁 是我大学事情开发的一个很经典的案例
💻 CPP
字号:
// chaxunyuanxixinxiDlg.cpp : implementation file
//

#include "stdafx.h"
#include "pmz.h"
#include "chaxunyuanxixinxiDlg.h"
#include "pmzDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// chaxunyuanxixinxiDlg dialog


chaxunyuanxixinxiDlg::chaxunyuanxixinxiDlg(CWnd* pParent /*=NULL*/)
	: CDialog(chaxunyuanxixinxiDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(chaxunyuanxixinxiDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
		m_pdb=new CDatabase;          
	m_pdb->Open( NULL, FALSE, FALSE,mydb);
}


void chaxunyuanxixinxiDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(chaxunyuanxixinxiDlg)
	DDX_Control(pDX, IDC_LIST1, m_pList);
	//}}AFX_DATA_MAP
}
chaxunyuanxixinxiDlg::~chaxunyuanxixinxiDlg()
{
	m_pdb->Close();
	delete m_pdb;
}

BEGIN_MESSAGE_MAP(chaxunyuanxixinxiDlg, CDialog)
	//{{AFX_MSG_MAP(chaxunyuanxixinxiDlg)
	ON_BN_CLICKED(IDOK, Onshanchuyuanxixinxi)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// chaxunyuanxixinxiDlg message handlers
BOOL chaxunyuanxixinxiDlg::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,200);
	m_pList->InsertColumn(3,"院系电话",LVCFMT_CENTER,150);
	m_pList->InsertColumn(4,"系主任",LVCFMT_CENTER,100);

	CString str1="SELECT * FROM department_info ",department_no,department_name,department_tel,dean_name;
    m_pList->DeleteAllItems();
	m_precordset=new department_infodb(m_pdb);

	m_precordset->Open(department_infodb::snapshot,str1);
    int i=0;
	if(m_precordset->IsEOF())
	{
     return true;
	}
	else
	{
	  m_precordset->MoveFirst();
	  while(!m_precordset->IsEOF())
	  {
		
		department_no=m_precordset->m_department_no;
		department_name=m_precordset->m_department_name;
		department_tel=m_precordset->m_department_tel;
		dean_name=m_precordset->m_dean_name;

		m_pList->InsertItem(i,department_no);
		m_pList->SetItemText(i,1,department_name);
		m_pList->SetItemText(i,2,department_tel);
		m_pList->SetItemText(i,3,dean_name);
		m_precordset->MoveNext();
		i++;
	  } 
	}

	delete m_precordset;
	return true;
}

void chaxunyuanxixinxiDlg::Onshanchuyuanxixinxi() 
{
  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 str1="delete from department_info where department_no= '"+str+"'";
       m_pdb->ExecuteSQL(str1);
	   m_pList.DeleteItem(j);
	   AfxMessageBox("删除成功!");
	  }
	  else return;
	  
  }	
}

void chaxunyuanxixinxiDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

⌨️ 快捷键说明

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