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

📄 xuankedlg.cpp

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

#include "stdafx.h"
#include "pmz.h"
#include "xuankeDlg.h"
#include "pmzDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// xuankeDlg dialog
extern CString user_name;

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

void xuankeDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(xuankeDlg)
	DDX_Control(pDX, IDC_LIST1, m_pList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(xuankeDlg, CDialog)
	//{{AFX_MSG_MAP(xuankeDlg)
	ON_BN_CLICKED(IDOK, Onxuanke)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// xuankeDlg message handlers
BOOL xuankeDlg::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,100);
	m_pList->InsertColumn(3,"开课时间",LVCFMT_CENTER,120);
	//m_pList->InsertColumn(4,"开课地点",LVCFMT_CENTER,110);
	//m_pList->InsertColumn(5,"教师姓名",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,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_no;
         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_no=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_no);
		
		m_precordset->MoveNext();
		i++;
	  } 
	}

	delete m_precordset;
	delete m_tprecordset;
	delete m_dprecordset;
	return true;
	


}

void xuankeDlg::Onxuanke() 
{
  int j;
  j=m_pList.GetSelectionMark();
  if(j<0)
  {
	  AfxMessageBox("请在列表框点击选中要选的课程记录!");
	  return;
  }
  else
  {
	   CString str;
	   str=m_pList.GetItemText(j,0);
	   CString str1="insert into SC_info values('"+user_name+"','"+str+"','')";
	   CString str2="SELECT * FROM SC_info where S_no='"+user_name+"' and C_no='"+str+"' ";
	m_scprecordset=new SC_infodb(m_pdb);
    m_scprecordset->Open(SC_infodb::snapshot,str2);
    if(!m_scprecordset->IsEOF())
	{
		AfxMessageBox("此课程已选,请重新选择课程!");
		return;
	}
       m_pdb->ExecuteSQL(str1);
	   AfxMessageBox("选课成功!");
	   return;
	  
  }		
}

⌨️ 快捷键说明

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