【VC开源代码栏目提醒】:网学会员,鉴于大家对VC开源代码十分关注,论文会员在此为大家搜集整理了“CStudentDlg.cpp”一文,供大家参考学习!
// CStudentDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CStudent.h"
#include "CStudentDlg.h"
#include "MyODBC.h"
#include "StudentInfoDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CCStudentDlg dialog
CCStudentDlg::CCStudentDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCStudentDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCStudentDlg)
m_szCondition = _T("");
m_bCheck = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_szSQL="select * from student_info";
}
void CCStudentDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCStudentDlg)
DDX_Control(pDX, IDC_COMBO1, m_ComboBox);
DDX_Control(pDX, IDC_LIST1, m_Report);
DDX_Text(pDX, IDC_EDIT1, m_szCondition);
DDX_Check(pDX, IDC_CHECK1, m_bCheck);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCStudentDlg, CDialog)
//{{AFX_MSG_MAP(CCStudentDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCStudentDlg message handlers
BOOL CCStudentDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// 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);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_Report.SetExtendedStyle(LVS_EX_HEADERDRAGDROP|LVS_EX_FULLROWSELECT|LVS_EX_TRACKSELECT);
// m_Report.SetImageList(&ImageList, LVSIL_SMALL);
SetCombox();
ShowData(m_szSQL);
return TRUE; // return TRUE unless you set the focus to a control
}
void CCStudentDlg::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 CCStudentDlg::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();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CCStudentDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BOOL CCStudentDlg::ShowData(CString strSql)
{
int i = 0, iCount;
m_Report.DeleteAllItems();//首先清空listview
iCount = m_Report.GetHeaderCtrl()->GetItemCount();
for(i = 0; i < iCount; i++)
{
m_Report.DeleteColumn(0);
}
CMyODBC db;
//CString szSQL="select * from admin where Name='"+m_szUserName+"' and pwd='"+m_szPwd+"'";
if(!db.ConnectDB("student.mdb","MICROSOFT ACCESS DRIVER (*.mdb)","",""))
{
MessageBox("连接数据库错误!");
return false;
}
db.Query(strSql);
int j=db.GetFieldCount();
for(short ii = 0; ii < j; ii++)
{
CString sz=db.GetFieldName(ii);
m_Report.InsertColumn(ii, sz,LVCFMT_CENTER,80);
}
int iRow=0;
do
{
int nCol=0;
for(nCol = 0; nCol < j; nCol++)
{
CString sz;
if(!db.GetFieldValue(nCol,sz))
break;
if(nCol == 0)
{
m_Report.InsertItem(iRow, sz);
}
else
{
m_Report.SetItemText(iRow, nCol, sz);
}
}
iRow++;
}while(db.NextRecord());
return TRUE;
}
void CCStudentDlg::SetCombox()
{
CString strSql;
m_ComboBox.ResetContent();
strSql = "select * from student_info";
CMyODBC db;
//CString szSQL="select * from admin where Name='"+m_szUserName+"' and pwd='"+m_szPwd+"'";
if(!db.ConnectDB("student.mdb","MICROSOFT ACCESS DRIVER (*.mdb)","",""))
{
MessageBox("连接数据库错误!");
return ;
}
db.Query(strSql);
int j=db.GetFieldCount();
for(short ii = 0; ii < j; ii++)
{
CString sz=db.GetFieldName(ii);
m_ComboBox.InsertString(ii, sz);
}
m_ComboBox.SetCurSel(2);
}
void CCStudentDlg::OnButton1()
{
// TODO: Add your control notification handler code here
UpdateData();
CString szfield;
int i=m_ComboBox.GetCurSel();
m_ComboBox.GetLBText(i,szfield);
CMyODBC db;
if(!db.ConnectDB("student.mdb","MICROSOFT ACCESS DRIVER (*.mdb)","",""))
{
MessageBox("连接数据库错误!");
return ;
}
db.Query("select * from student_info");
CODBCFieldInfo fi;
db.GetFieldInfo(i,fi);
int nCon;
if(fi.m_nSQLType==SQL_SMALLINT)
{
上一篇:
CStudent.cpp
下一篇:
白色姜花,略微开了