📄 paraprocessdlg4.cpp
字号:
// ParaProcessDlg4.cpp : implementation file
//
#include "stdafx.h"
#include "sjsys.h"
#include "ParaProcessDlg4.h"
#include "DeviceManagermentDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CParaProcessDlg4 dialog
CParaProcessDlg4::CParaProcessDlg4(CWnd* pParent /*=NULL*/)
: CDialog(CParaProcessDlg4::IDD, pParent)
{
//{{AFX_DATA_INIT(CParaProcessDlg4)
m_StartIp = _T("");
m_Endip = _T("");
m_Describe = _T("");
//}}AFX_DATA_INIT
}
void CParaProcessDlg4::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CParaProcessDlg4)
DDX_Control(pDX, IDCANCEL, m_OK);
DDX_Control(pDX, IDC_SAVEBUTTON1, m_save);
DDX_Text(pDX, IDC_EDIT1, m_StartIp);
DDX_Text(pDX, IDC_EDIT2, m_Endip);
DDX_Text(pDX, IDC_EDIT3, m_Describe);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CParaProcessDlg4, CDialog)
//{{AFX_MSG_MAP(CParaProcessDlg4)
ON_BN_CLICKED(IDC_SAVEBUTTON1, OnSave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CParaProcessDlg4 message handlers
void CParaProcessDlg4::OnSave()
{
// TODO: Add your control notification handler code here
UpdateData();//将控件中的值更新到变量
GetDlgItem(IDC_SAVEBUTTON1)->EnableWindow(FALSE);
CString strSQL;
strSQL="SELECT * FROM Reserveip" ;//构造sql语句
if(m_StartIp!="")
{
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("startip",_variant_t(m_StartIp));
m_pRecordset->PutCollect("endip",_variant_t(m_Endip));
m_pRecordset->PutCollect("descr",_variant_t(m_Describe));
m_pRecordset->Update(); //更新数据库
AfxMessageBox("添加数据成功!"); //提示信息
}
}
m_pRecordset->Close();
}
catch(_com_error e)///捕捉异常
{
CString errormessage;
MessageBox("创建记录集失败!","错误");
}
}
if(m_flag==2)
{
strSQL.Format("select * from Reserveip 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("startip",_variant_t(m_StartIp));//产品编号
m_pRecordset1->PutCollect("endip",_variant_t(m_Endip));//产品名称
m_pRecordset1->PutCollect("descr",_variant_t(m_Describe));//产品编号
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("起始IP不能为空","提示",MB_OK|MB_ICONINFORMATION);
return;
}
CDialog::OnOK();
}
void CParaProcessDlg4::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
BOOL CParaProcessDlg4::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 Reserveip where startip='%s' and endip='%s' and descr='%s'",m_StartIp,m_Endip,m_Describe);
_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 + -