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

📄 080426dbdialogdlg.cpp

📁 ado 连接数据库,最简单的数据库编程 有利于初学者学习.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// 080426dbdialogDlg.cpp : implementation file
//

#include "stdafx.h"
#include "080426dbdialog.h"
#include "080426dbdialogDlg.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()

/////////////////////////////////////////////////////////////////////////////
// CMy080426dbdialogDlg dialog

CMy080426dbdialogDlg::CMy080426dbdialogDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMy080426dbdialogDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMy080426dbdialogDlg)
	m_name = _T("");
	m_stuNO = _T("");
	m_chinese = _T("");
	m_math = _T("");
	m_english = _T("");
	m_timer = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    nUpdate=0;
	m_BOOLTag=false;
}

void CMy080426dbdialogDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMy080426dbdialogDlg)
	DDX_Control(pDX, IDC_COMBO1, m_comboNO);
	DDX_Control(pDX, IDC_LIST1, m_ListCtrl);
	DDX_Text(pDX, IDC_EDIT1, m_name);
	DDV_MaxChars(pDX, m_name, 20);
	DDX_CBString(pDX, IDC_COMBO1, m_stuNO);
	DDV_MaxChars(pDX, m_stuNO, 20);
	DDX_Text(pDX, IDC_EDIT2, m_chinese);
	DDX_Text(pDX, IDC_EDIT3, m_math);
	DDX_Text(pDX, IDC_EDIT4, m_english);
	DDX_Text(pDX, IDC_EDIT5, m_timer);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMy080426dbdialogDlg, CDialog)
	//{{AFX_MSG_MAP(CMy080426dbdialogDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_ADD, OnAdd)
	ON_BN_CLICKED(IDC_DELETE, OnDelete)
	ON_BN_CLICKED(IDC_BTOK, OnBtok)
	ON_WM_TIMER()
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_ADDMAP, OnAddmap)
	ON_BN_CLICKED(IDC_BUTVIEW, OnButview)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMy080426dbdialogDlg message handlers

BOOL CMy080426dbdialogDlg::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
	SetTimer(1,1000,NULL);
	//m_bitmap.LoadBitmap(IDB_BITMAP1);
	UpdateData(false);
	// TODO: Add extra initialization here
	CoInitialize(NULL);
	CString combo;
	for(int i=1;i<51;i++)
	{
	combo.Format("2015451%02d",i);
    m_comboNO.InsertString(i-1,combo);
	}
	m_comboNO.SetCurSel(0);
	CString sql;
	try
	{
		m_pConnection.CreateInstance(__uuidof(Connection));
		sql.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=student.mdb");
		_bstr_t sql_=sql;
		m_pConnection->Open(sql_,"","",-1);
	}
    catch(_com_error& e)
	{
		AfxMessageBox(e.ErrorMessage());
		this->EndDialog(0);
	}
	CString header[7]={"学号","姓名","语文","数学","英语","平均分","时间"};
	for(i=0;i<7;i++)
	{
	m_ListCtrl.InsertColumn(i,header[i],LVCFMT_CENTER,70);
	}
    m_ListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_LIST);
	_bstr_t str1("select * from students");
     i=0;
	_variant_t temp;
	//CString strchange;
	try{
	m_pRecordset.CreateInstance(__uuidof(Recordset));
	m_pRecordset = m_pConnection->Execute(str1,NULL,adCmdText);
    m_pRecordset->MoveFirst();
	
	while(!m_pRecordset->adoEOF)//在一些常用的功能上,MFC一定会有很简单的方法的~
		{
			temp = m_pRecordset->GetCollect("number");
			if(temp.vt != VT_NULL)
			   m_ListCtrl.InsertItem(i,(char*)(_bstr_t)temp);
			temp =m_pRecordset->GetCollect("name");
			if(temp.vt != VT_NULL)
				m_ListCtrl.SetItemText(i,1,(char*)(_bstr_t)temp);
			temp =m_pRecordset->GetCollect("chinexe");
			if(temp.vt != VT_NULL)  
				m_ListCtrl.SetItemText(i,2,(char*)(_bstr_t)temp);
			temp =m_pRecordset->GetCollect("math");
			if(temp.vt != VT_NULL)
            m_ListCtrl.SetItemText(i,3,(char*)(_bstr_t)temp);
			
			temp =m_pRecordset->GetCollect("english");
			if(temp.vt != VT_NULL)
				m_ListCtrl.SetItemText(i,4,(char*)(_bstr_t)temp);
			temp =m_pRecordset->GetCollect("average");
			if(temp.vt!=VT_NULL)
				m_ListCtrl.SetItemText(i,5,(char*)(_bstr_t)temp);
			temp =m_pRecordset->GetCollect("timer");
			if(temp.vt!=VT_NULL)
				m_ListCtrl.SetItemText(i,6,(char*)(_bstr_t)temp);
			   
			   //strchange.Format("%f",temp2);
			   
			m_pRecordset->MoveNext();
	}

       m_pRecordset->Close();
	}
    catch(_com_error& e)
	{
		 AfxMessageBox(e.ErrorMessage());
	}
	m_ListCtrl.SetRedraw(TRUE);


	


	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMy080426dbdialogDlg::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 CMy080426dbdialogDlg::OnPaint() 
{   CPaintDC dc(this); 
	if (IsIconic())
	{  
		// 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);
	}
	if(m_BOOLTag)
	{   
	CDC dcMem; 
	dcMem.CreateCompatibleDC(&dc);                          //创建与对话框dc兼容的内存dc
	//CRect rect;
	//GetClientRect();
	BITMAP bitMap;
	m_Bitmap.GetBitmap(&bitMap);
	CBitmap *pbmpOld=dcMem.SelectObject(&m_Bitmap);		    //将背景位图选入内存dc中
	//dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bitMap.bmWidth,bitMap.bmHeight,MERGECOPY);
	dc.BitBlt(570, 40,800, 500, &dcMem, 0, 0, SRCCOPY);
	}
	    /*CDC dcMem; 
		dcMem.CreateCompatibleDC(&dc);                          //创建与对话框dc兼容的内存dc
		CRect rect;
		GetClientRect(&rect);
		BITMAP bitMap;
		m_bitmap.GetBitmap(&bitMap);
		CBitmap *pbmpOld=dcMem.SelectObject(&m_bitmap);		    //将背景位图选入内存dc中
		//dc.BitBlt(370, 100, 130, 160, &dcMem, 0, 0, SRCCOPY);
		dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bitMap.bmWidth,bitMap.bmHeight,SRCCOPY);*/
		CDialog::OnPaint();
	
}

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

void CMy080426dbdialogDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	m_pConnection->Close();
	CoUninitialize();
	
	// TODO: Add your message handler code here
	
}

void CMy080426dbdialogDlg::OnAdd() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
//	_CommandPtr m_pCommand;
	//m_pCommand.CreateInstance(__uuidof(Command));
	_variant_t T1,T2,T3;
	float t1,t2,t3,m_Average;
	CString str;
	T1 = m_chinese;
	t1=(float)T1;
	T2 = m_math;
	t2=(float)T2;
	T3 = m_english;
	t3=(float)T3;
	m_Average =t1+t2;
	m_Average =m_Average +t3;
	m_Average = m_Average/3;
    str.Format("%3.2f",m_Average);
	CString strItemText1;

⌨️ 快捷键说明

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