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

📄 listdlg.cpp

📁 学生信息管理系统是典型的信息管理系统(MIS),其开发主要包括后台数据库的建立和维护以及前端应用程序的开发两个方面。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// ListDlg.cpp : implementation file
//

#include "stdafx.h"
#include "List.h"
#include "ListDlg.h"
#include "CreateDialog.h"
#include "DisDialog.h"
#include  "AddObject.h"
#include "DeleObject.h"
#include "Add.h"
#include "Del.h"
#include "Seer.h"
#include "EditDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CListDlg dialog

CListDlg::CListDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CListDlg::IDD, pParent)
{   m_pDB=NULL;
    nField=0;
    m_pRecordSet=NULL;
   m_bIsAsc=FALSE;
	//{{AFX_DATA_INIT(CListDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON3);

}

void CListDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CListDlg)
	DDX_Control(pDX, IDC_SERCH, m_Serch);
	DDX_Control(pDX, IDC_STRAT, m_Strat);
	DDX_Control(pDX, IDC_EDIT, m_Edit);
	DDX_Control(pDX, IDC_DELE, m_Dele);
	DDX_Control(pDX, IDC_ALL, m_All);
	DDX_Control(pDX, IDC_ADD, m_Add);
	DDX_Control(pDX, IDC_LIST1, m_List1);
	DDX_Control(pDX, IDC_COMBO1, m_Com);
	//}}AFX_DATA_MAP

}

BEGIN_MESSAGE_MAP(CListDlg, CDialog)
	//{{AFX_MSG_MAP(CListDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
	ON_BN_CLICKED(IDC_STRAT, OnStrat)
	ON_COMMAND(ID_DELEOBJECT, OnDeleobject)
	ON_BN_CLICKED(IDC_ADD, OnAdd)
	ON_COMMAND(ID_ADDBUT, OnAddbut)
	ON_COMMAND(ID_DELEBUT, OnDelebut)
	ON_COMMAND(ID_ADDOBJCET, OnAddobjcet)
	ON_UPDATE_COMMAND_UI(ID_ADDOBJCET, OnUpdateAddobjcet)
	ON_UPDATE_COMMAND_UI(ID_DELEOBJECT, OnUpdateDeleobject)
	ON_UPDATE_COMMAND_UI(ID_ADDBUT, OnUpdateAddbut)
	ON_UPDATE_COMMAND_UI(ID_DELEBUT, OnUpdateDelebut)
	ON_BN_CLICKED(IDC_DELE, OnDele)
	ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST1, OnColumnclickList1)
	ON_BN_CLICKED(IDC_ALL, OnAll)
	ON_BN_CLICKED(IDC_SERCH, OnSerch)
	ON_BN_CLICKED(IDC_EDIT, OnEdit)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CListDlg message handlers

BOOL CListDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
   
	// Add "About..." menu item to system menu.
    SetWindowText("学生成绩管理");
	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);
	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}
   

	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	GetDlgItem(IDC_STRAT)->EnableWindow(FALSE);
    this->Enable(FALSE);

	m_pDB=new CDaoDatabase;
	CString sPath;
	GetModuleFileName(NULL,sPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
	sPath.ReleaseBuffer ();
	int nPos;
	nPos=sPath.ReverseFind ('\\');
	sPath=sPath.Left (nPos);
	nPos=sPath.ReverseFind('\\');
    sPath=sPath.Left (nPos);
	CString lpszFile = sPath + "\\db6.mdb";
	try{
		m_pDB->Open(lpszFile);
	}
	catch(CDaoException* e)
	{
		AfxMessageBox(e->m_pErrorInfo->m_strDescription,MB_ICONEXCLAMATION);
		delete m_pDB;
		e->Delete();
		return FALSE;
	}
    
    CDaoTableDefInfo tabInfo;
	int nTableDefCount = m_pDB->GetTableDefCount();
	for (int i = 0; i < nTableDefCount; i++)
	{
		m_pDB->GetTableDefInfo(i,tabInfo);
		if (tabInfo.m_lAttributes & dbSystemObject)
			continue;
		m_Com.AddString(tabInfo.m_strName);

	}
	m_pRecordSet=new CDaoRecordset(m_pDB);
    m_bTF=TRUE;
	m_bCR=FALSE;
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CListDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CListDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{CDialog::OnPaint();
	//	CPaintDC dc(this);
	//	CRect rect;
	//	GetClientRect(&rect);
	//	CDC dcMem; 
	//	dcMem.CreateCompatibleDC(&dc); 
	//	BITMAP bitMap;
	//	m_Bitmap.GetBitmap(&bitMap);
	//	CBitmap *pbmpOld=dcMem.SelectObject(&m_Bitmap);
	//	dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bitMap.bmWidth,bitMap.bmHeight,SRCCOPY);
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CListDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CListDlg::OnClosebutton() 
{
	// TODO: Add your control notification handler code here
	m_pDB->Close();

	CDialog::OnCancel();
}

void CListDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	
}

void CListDlg::OnSelchangeCombo1() 
{
	// TODO: Add your control notification handler code here
	CString m_string;
    m_Com.GetLBText(m_Com.GetCurSel(),m_string);
	if(m_GetString!=m_string)
	GetDlgItem(IDC_STRAT)->EnableWindow(TRUE);
	this->Enable(FALSE);
}

void CListDlg::OnStrat() 
{  
	if(m_pRecordSet->IsOpen())
    m_pRecordSet->Close();
  
    m_List1.DeleteAllItems();
    if(nField!=0)
	{
	for(long i=0;i<nField;i++)
	{
	m_List1.DeleteColumn(0);
	} 
	}
    
	m_Com.GetLBText(m_Com.GetCurSel(),m_GetString);
	if(m_GetString=="关闭班级")
    {   
		m_bTF=TRUE;
	    m_bCR=FALSE;
		return ;
	}
	m_bTF=FALSE;
	m_bCR=TRUE;
	CString strSQL="SELECT * FROM " + m_GetString;

try{
		m_pRecordSet->Open(dbOpenDynaset, strSQL);
		m_pRecordSet->m_strFilter.Empty();
	}
	catch(CDaoException *e)
	{   
		AfxMessageBox(e->m_pErrorInfo->m_strDescription,MB_ICONEXCLAMATION);
		delete m_pRecordSet;
		m_pDB->Close();
		delete m_pDB;
		e->Delete();
		return ;
	}
	 
	if(m_pRecordSet != NULL)
	{
		m_pImageList = new CImageList();
		m_pImageList->Create(IDB_BITMAP4, 16, 1, RGB(255,0,0));
		m_List1.SetImageList(m_pImageList, LVSIL_SMALL);	/* set extended stlyes*/
		
		DWORD dwExStyle = LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | /*LVS_EX_SUBITEMIMAGES |*/
		m_List1.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);						LVS_EX_HEADERDRAGDROP | LVS_EX_TRACKSELECT;

		LV_COLUMN lvColumn;
		lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
		lvColumn.fmt = LVCFMT_LEFT;	lvColumn.cx = 67;
	    nField=m_pRecordSet->GetFieldCount();
		for(int i = 0; i < nField; i++) // set up columns
		{    
			CDaoFieldInfo m_fieldinfo;
			m_pRecordSet->GetFieldInfo(i, m_fieldinfo);//get field name
			int len = m_fieldinfo.m_strName.GetLength();
			CString temp = m_fieldinfo.m_strName;
			TCHAR* szBuffer = new TCHAR[len + 1];
			strcpy(szBuffer, temp.GetBuffer(len));
			temp.ReleaseBuffer();
			lvColumn.pszText = szBuffer;
		    m_List1.InsertColumn(i, &lvColumn);//insert column		
			delete szBuffer;
		}
		/*set number of items in ListView*/
		m_pRecordSet->MoveFirst();
		m_pRecordSet->MoveLast();
        long count =m_pRecordSet->GetRecordCount();//Get number of records
	
        this->OnGetdispinfoList( count, nField);
	
	}
	GetDlgItem(IDC_STRAT)->EnableWindow(FALSE);
	this->Enable(TRUE);
}

void CListDlg::OnGetdispinfoList(long row,long column) 
{  
   
	if(!m_pRecordSet)
	return;
    COleVariant varValue;
	for(long i=0;i<row;i++)
	{	
		try
		{
	    m_pRecordSet->SetAbsolutePosition(i);//Set the file to desired index

		}
		catch(CDaoException* e)
		{
		AfxMessageBox(e->m_pErrorInfo->m_strDescription, 
				    MB_ICONEXCLAMATION );
		e->Delete();
		return;
		}
	
    	for(long j=0;j<column;j++)
		{   
		try	{
	   	     if(j)	
			 m_pRecordSet->GetFieldValue(j, varValue);
		   	 else
			 m_pRecordSet->GetFieldValue(0, varValue);
		}
		catch(CDaoException* e)
		{
			AfxMessageBox(e->m_pErrorInfo->m_strDescription, 
				    MB_ICONEXCLAMATION );
			e->Delete();
			return;
		}
	

		const VARIANT* variant = LPCVARIANT(varValue);
		
		if(variant->vt & VT_BYREF)

⌨️ 快捷键说明

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