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

📄 newmodifydlg.cpp

📁 VC++一个数据库的开发
💻 CPP
字号:
// NewModifyDlg.cpp : implementation file
//

#include "stdafx.h"
#include "AdoDB.h"
#include "NewModifyDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CNewModifyDlg dialog


CNewModifyDlg::CNewModifyDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CNewModifyDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CNewModifyDlg)
	m_ctlDate = COleDateTime::GetCurrentTime();
	m_ctlTime = COleDateTime::GetCurrentTime();
	m_strMsg = _T("");
	m_strName = _T("");
	m_strTelNumber = _T("");
	//}}AFX_DATA_INIT
	m_pDBManager=0;
}


void CNewModifyDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CNewModifyDlg)
	DDX_DateTimeCtrl(pDX, IDC_DATE, m_ctlDate);
	DDX_DateTimeCtrl(pDX, IDC_TIME, m_ctlTime);
	DDX_Text(pDX, IDC_EDIT_MESSAGE, m_strMsg);
	DDV_MaxChars(pDX, m_strMsg, 50);
	DDX_Text(pDX, IDC_EDIT_NAME, m_strName);
	DDV_MaxChars(pDX, m_strName, 8);
	DDX_Text(pDX, IDC_EDIT_TELNO, m_strTelNumber);
	DDV_MaxChars(pDX, m_strTelNumber, 14);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CNewModifyDlg, CDialog)
	//{{AFX_MSG_MAP(CNewModifyDlg)
	ON_BN_CLICKED(IDC_DONE, OnDone)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNewModifyDlg message handlers

void CNewModifyDlg::OnCancel()
{
	CDialog::OnCancel();
	this->DestroyWindow();
}
void CNewModifyDlg::OnDone() 
{
	// TODO: Add your control notification handler code here
	if(!m_pDBManager)
		return;

	UpdateData();
	LONG lID=m_stRecord.lID;
	memset(&m_stRecord,0,sizeof(StClientTalkInfo));
	m_stRecord.lID=lID;

	sprintf(m_stRecord.szClientName,m_strName);
	sprintf(m_stRecord.szPhoneNumber,m_strTelNumber);
	sprintf(m_stRecord.szMessage,m_strMsg);
	m_stRecord.dtTime.SetDateTime(m_ctlDate.GetYear(),m_ctlDate.GetMonth(),m_ctlDate.GetDay(),
		m_ctlTime.GetHour(),m_ctlTime.GetMinute(),m_ctlTime.GetSecond());
	
	if (m_pDBManager->UpdateRecord(m_stRecord))
	{		
		OnCancel();		
	}
	else
	{
		CString strMsg=_T("连接数据库已连接,更新数据失败,原因:\n");
		strMsg+=m_pDBManager->GetLastError();
		AfxMessageBox(strMsg);
	}
}


BOOL CNewModifyDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	if (m_stRecord.lID>0)
	{
		m_strName=m_stRecord.szClientName;
		m_strTelNumber=m_stRecord.szPhoneNumber;
		m_strMsg=m_stRecord.szMessage;
		m_ctlDate=m_stRecord.dtTime;
		m_ctlTime=m_stRecord.dtTime;

		UpdateData(FALSE);
	}
	else
	{
		m_strName=_T("");
		m_strTelNumber=_T("");
		m_strMsg=_T("");
		m_ctlDate=COleDateTime::GetCurrentTime();
		m_ctlTime=COleDateTime::GetCurrentTime();
		UpdateData(FALSE);
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

⌨️ 快捷键说明

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