www.pudn.com > GSMTest1.rar > DutyEditdlg.cpp
// DutyEditdlg.cpp : implementation file // #include "stdafx.h" #include "GSMTest.h" #include "DutyEditdlg.h" #include#include #include "database.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CDutyEditdlg dialog CDutyEditdlg::CDutyEditdlg(CWnd* pParent /*=NULL*/) : CDialog(CDutyEditdlg::IDD, pParent) { //{{AFX_DATA_INIT(CDutyEditdlg) m_strName = _T(""); m_strRemark = _T(""); m_strTel = _T(""); //}}AFX_DATA_INIT } void CDutyEditdlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CDutyEditdlg) DDX_Text(pDX, IDC_NAME, m_strName); DDV_MaxChars(pDX, m_strName, 20); DDX_Text(pDX, IDC_REMARK, m_strRemark); DDV_MaxChars(pDX, m_strRemark, 200); DDX_Text(pDX, IDC_TEL, m_strTel); DDV_MaxChars(pDX, m_strTel, 15); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CDutyEditdlg, CDialog) //{{AFX_MSG_MAP(CDutyEditdlg) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDutyEditdlg message handlers void CDutyEditdlg::OnOK() { UpdateData(TRUE); m_strName.Replace("\'",""); m_strTel.Replace("\'",""); if(m_strName=="") { AfxMessageBox("请填写姓名!"); return; } if(m_strTel=="") { AfxMessageBox("请填写手机号!"); return; } CDatabase database; if(!database.ConnectDB()) { AfxMessageBox("连接服务器失败!"); return; } CString charset="set charset gb2312;";//使之正常显示中文,或用set character_set_results=gb2312; database.ExecuteSQL(charset,charset.GetLength());//执行语句. CString sSQL; if(m_sOption=="add") { //增加 sSQL.Format("insert into duty_info (duty_name,duty_tel,Remark) values('%s','%s','%s')", m_strName,m_strTel,m_strRemark); if(!database.ExecuteSQL(sSQL,sSQL.GetLength())) { AfxMessageBox("插入数据失败!"); return; } } if(m_sOption=="edit") { sSQL.Format("update duty_info set duty_tel='%s',duty_name='%s',Remark='%s' where duty_id='%s'", m_strTel,m_strName,m_strRemark,m_strID); if(!database.ExecuteSQL(sSQL,sSQL.GetLength())) { AfxMessageBox("编辑信息失败!"); return; } } CDialog::OnOK(); } BOOL CDutyEditdlg::OnInitDialog() { CDialog::OnInitDialog(); if(m_sOption=="edit") { UpdateData(FALSE); } return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }