?? paraprocessdlg3.cpp
字號:
// ParaProcessDlg3.cpp : implementation file
//
#include "stdafx.h"
#include "sjsys.h"
#include "ParaProcessDlg3.h"
#include "DeviceManagermentDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CParaProcessDlg3 dialog
CParaProcessDlg3::CParaProcessDlg3(CWnd* pParent /*=NULL*/)
: CDialog(CParaProcessDlg3::IDD, pParent)
{
//{{AFX_DATA_INIT(CParaProcessDlg3)
m_Name = _T("");
m_Port = _T("");
//}}AFX_DATA_INIT
}
void CParaProcessDlg3::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CParaProcessDlg3)
DDX_Control(pDX, IDOK, m_OK);
DDX_Control(pDX, IDC_SAVEBUTTON1, m_save);
DDX_Text(pDX, IDC_EDIT1, m_Name);
DDX_Text(pDX, IDC_EDIT2, m_Port);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CParaProcessDlg3, CDialog)
//{{AFX_MSG_MAP(CParaProcessDlg3)
ON_BN_CLICKED(IDC_SAVEBUTTON1, OnSavebutton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CParaProcessDlg3 message handlers
void CParaProcessDlg3::OnSavebutton()
{
// TODO: Add your control notification handler code here
UpdateData();//將控件中的值更新到變量
// GetDlgItem(IDC_SAVEBUTTON1)->EnableWindow(FALSE);
CString strSQL;
strSQL="SELECT * FROM Servtype" ;//構造sql語句
if(m_Name!="")
{
if(m_flag==1)
{
try
{
HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CSjsysApp*)AfxGetApp())->pConnection.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);//打開查詢結果記錄集
if(SUCCEEDED(hTRes))
{
TRACE(_T("連接成功!\n"));
m_pRecordset->AddNew();//添加新的記錄
m_pRecordset->PutCollect("Name",_variant_t(m_Name));
m_pRecordset->PutCollect("Port",_variant_t(m_Port));
m_pRecordset->Update(); //更新數據庫
AfxMessageBox("添加數據成功!"); //提示信息
}
else
MessageBox("該條記錄不存在,如果想添加此記錄,請單擊添加按鈕","提示",MB_OK|MB_ICONINFORMATION);
}
m_pRecordset->Close();
}
catch(_com_error e)///捕捉異常
{
CString errormessage;
MessageBox("創建記錄集失敗!","錯誤");
}
}
if(m_flag==2)
{
strSQL.Format("select * from Servtype where ID='%s'",m_id);
_RecordsetPtr m_pRecordset1;
m_pRecordset1.CreateInstance(_T("ADODB.Recordset"));
try
{
m_pRecordset1->Open((LPTSTR)strSQL.GetBuffer(130),
((CSjsysApp*)AfxGetApp())->pConnection.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if (!m_pRecordset1->adoEOF)
{
m_pRecordset1->PutCollect("Name",_variant_t(m_Name));//產品編號
m_pRecordset1->PutCollect("Port",_variant_t(m_Port));//產品名稱
m_pRecordset1->Update(); //更新數據庫
AfxMessageBox("修改數據成功!");
}
m_pRecordset1->Close();
}
catch(_com_error *e)
{
CString errormessage;
errormessage.Format("打開記錄集失敗!\r\n錯誤信息:%s",e->ErrorMessage());
AfxMessageBox(errormessage);
return;
}
}
}
else
{
MessageBox("起始名稱不能為空","提示",MB_OK|MB_ICONINFORMATION);
return;
}
CDialog::OnOK();
}
void CParaProcessDlg3::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
BOOL CParaProcessDlg3::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_OK.SetShade(CShadeButtonST::SHS_HBUMP);
m_save.SetShade(CShadeButtonST::SHS_HBUMP);
CString strSQL;
if(m_flag==2)
{
strSQL.Format("select * from Servtype where Name='%s' and Port='%s'",m_Name,m_Port);
_RecordsetPtr m_pRecordset1;
m_pRecordset1.CreateInstance(_T("ADODB.Recordset"));
try
{
m_pRecordset1->Open((LPTSTR)strSQL.GetBuffer(130),
((CSjsysApp*)AfxGetApp())->pConnection.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if (!m_pRecordset1->adoEOF)
{
m_id=((CSjsysApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset1->GetCollect("ID"));
}
m_pRecordset1->Close();
}
catch(_com_error *e)
{
CString errormessage;
errormessage.Format("打開記錄集失敗!\r\n錯誤信息:%s",e->ErrorMessage());
AfxMessageBox(errormessage);
}
}
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 + -