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

📄 paraprocessdlg1.cpp

📁 本程序使用Visual C++6.0编写
💻 CPP
字号:
// ParaProcessDlg1.cpp : implementation file
//

#include "stdafx.h"
#include "sjsys.h"
#include "ParaProcessDlg1.h"

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

/////////////////////////////////////////////////////////////////////////////
// CParaProcessDlg1 dialog


CParaProcessDlg1::CParaProcessDlg1(CWnd* pParent /*=NULL*/)
	: CDialog(CParaProcessDlg1::IDD, pParent)
{
	//{{AFX_DATA_INIT(CParaProcessDlg1)
	m_edit1 = _T("");
	m_edit2 = _T("");
	m_edit3 = _T("");
	m_edit4 = _T("");
	//}}AFX_DATA_INIT
}


void CParaProcessDlg1::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CParaProcessDlg1)
	DDX_Control(pDX, IDCANCEL, m_OK);
	DDX_Control(pDX, IDC_SAVABUTTON, m_save);
	DDX_Text(pDX, IDC_EDIT1, m_edit1);
	DDX_Text(pDX, IDC_EDIT2, m_edit2);
	DDX_Text(pDX, IDC_EDIT3, m_edit3);
	DDX_Text(pDX, IDC_EDIT4, m_edit4);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CParaProcessDlg1, CDialog)
	//{{AFX_MSG_MAP(CParaProcessDlg1)
	ON_BN_CLICKED(IDC_SAVABUTTON, OnSava)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CParaProcessDlg1 message handlers

BOOL CParaProcessDlg1::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 Subnet where Startip='%s' and Endip='%s' and Ipamsk='%s'",m_edit1,m_edit2,m_edit3);
			_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= m_pRecordset1->GetCollect("ID").lVal;
				}
			}
			catch(_com_error *e)
			{
				CString  errormessage;
				errormessage.Format("打开记录集失败!\r\n错误信息:%s",e->ErrorMessage());
				AfxMessageBox(errormessage);
			}
		m_pRecordset1->Close();
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CParaProcessDlg1::OnSava() 
{
	// TODO: Add your control notification handler code here
	UpdateData();//将控件中的值更新到变量
//	GetDlgItem(IDC_SAVABUTTON)->EnableWindow(FALSE);
	CString strSQL;
	strSQL="SELECT * FROM Subnet" ;//构造sql语句
	if(m_edit1!="")
      {
		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_edit1));
						m_pRecordset->PutCollect("Endip",_variant_t(m_edit2));
						m_pRecordset->PutCollect("Ipamsk",_variant_t(m_edit3));
						m_pRecordset->PutCollect("Descr",_variant_t(m_edit4));
					
						m_pRecordset->Update(); //更新数据库
					   AfxMessageBox("添加数据成功!");  //提示信息
					}
					m_pRecordset->Close();
				}
			}
			catch(_com_error e)///捕捉异常
			{
				CString errormessage;
				MessageBox("创建记录集失败!","错误");
			}
		}
		if(m_flag==2)
		{
    		strSQL.Format("select * from Subnet where ID='%d'",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_edit1));//产品编号
					m_pRecordset1->PutCollect("Endip",_variant_t(m_edit2));//产品名称
					m_pRecordset1->PutCollect("Ipamsk",_variant_t(m_edit3)); //规格
					m_pRecordset1->PutCollect("Descr",_variant_t(m_edit4));//产品编号
					
					m_pRecordset1->Update(); //更新数据库
				    AfxMessageBox("修改数据成功!");
				}
				else
				  MessageBox("该条记录不存在,如果想添加此记录,请单击添加按钮","提示",MB_OK|MB_ICONINFORMATION);
				m_pRecordset1->Close();
			}
			catch(_com_error *e)
			{
				CString  errormessage;
				errormessage.Format("打开记录集失败!\r\n错误信息:%s",e->ErrorMessage());
				AfxMessageBox(errormessage);
			}
		}
	}
	else  
	{
		MessageBox("起始IP不能为空","提示",MB_OK|MB_ICONINFORMATION);
		return;
	}
	CDialog::OnOK();
}

⌨️ 快捷键说明

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