www.gusucode.com > ADO操作access全过程和CListCtrl的用法C++源码程序 > ADO操作access全过程和CListCtrl的用法/tele/Update.cpp

    // Update.cpp : implementation file
//

#include "stdafx.h"
#include "Tele.h"
#include "Update.h"
#include "brow.h"

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

/////////////////////////////////////////////////////////////////////////////
// CUpdate dialog


CUpdate::CUpdate(CWnd* pParent /*=NULL*/)
	: CDialog(CUpdate::IDD, pParent)

{
	//{{AFX_DATA_INIT(CUpdate)
	m_strName = _T("");
	m_strTele = _T("");
	m_strRemarks = _T("");
	m_strSignal = _T("");
	//}}AFX_DATA_INIT
}


void CUpdate::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CUpdate)
	DDX_Text(pDX, IDC_EDIT1, m_strName);
	DDX_Text(pDX, IDC_EDIT2, m_strTele);
	DDX_Text(pDX, IDC_EDIT3, m_strRemarks);
	DDX_Text(pDX, IDC_EDIT4, m_strSignal);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CUpdate, CDialog)
	//{{AFX_MSG_MAP(CUpdate)
	ON_BN_CLICKED(IDC_BUTTON_UPDATE, OnButtonUpdate)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUpdate message handlers

void CUpdate::OnButtonUpdate() 
{
	UpdateData(TRUE);
	
		if ( (strcmp(m_strName,"") == 0) || (strcmp(m_strTele,"") == 0) || (strcmp(m_strSignal,"") == 0)  )
	{
		AfxMessageBox("信息不全");
		return;
	}


	CString strSql

	= "UPDATE telelist SET name = '"
	+ m_strName +
	"',tele ='"
	+ m_strTele +
	"',remarks='"
	+ m_strRemarks +
	"' WHERE ID ="
	+ m_strSignal;  

	((static_cast<CTeleApp *>(AfxGetApp()))->g_pDb)->Execute(strSql);

	AfxMessageBox("更新完毕");

}



BOOL CUpdate::OnInitDialog()
{
	CDialog::OnInitDialog();

	CADORecordset* pRs = new CADORecordset(CTeleApp::g_pDb);
	CString TempSql;
	
	if(pRs->Open( (LPCTSTR) ("SELECT *  FROM telelist where ID =" + CBrow::g_strItem) ) )
		
		
	pRs->GetFieldValue("name",m_strName);
		
	pRs->GetFieldValue("tele",m_strTele);
	
	pRs->GetFieldValue("remarks",m_strRemarks);
		
	pRs->GetFieldValue("ID",m_strSignal);
		
	pRs->Close();
		
	delete pRs;	

	UpdateData(FALSE);

	return TRUE;
}