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

📄 paraprocessdlg2.cpp

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

#include "stdafx.h"
#include "sjsys.h"
#include "ParaProcessDlg2.h"
#include "DeviceManagermentDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CParaProcessDlg2 dialog


CParaProcessDlg2::CParaProcessDlg2(CWnd* pParent /*=NULL*/)
	: CDialog(CParaProcessDlg2::IDD, pParent)
{
	//{{AFX_DATA_INIT(CParaProcessDlg2)
	m_Name = _T("");
	m_StartPort = _T("");
	m_EndPort = _T("");
	m_IpAddress = _T("");
	//}}AFX_DATA_INIT
}


void CParaProcessDlg2::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CParaProcessDlg2)
	DDX_Control(pDX, IDOK, m_OK);
	DDX_Control(pDX, IDC_SAVEBUTTON, m_save);
	DDX_Text(pDX, IDC_EDIT1, m_Name);
	DDX_Text(pDX, IDC_EDIT2, m_StartPort);
	DDX_Text(pDX, IDC_EDIT3, m_EndPort);
	DDX_Text(pDX, IDC_EDIT4, m_IpAddress);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CParaProcessDlg2, CDialog)
	//{{AFX_MSG_MAP(CParaProcessDlg2)
	ON_BN_CLICKED(IDC_SAVEBUTTON, OnSavebutton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CParaProcessDlg2 message handlers

void CParaProcessDlg2::OnSavebutton() 
{
	// TODO: Add your control notification handler code here
	UpdateData();//将控件中的值更新到变量
//	GetDlgItem(IDC_SAVEBUTTON)->EnableWindow(FALSE);
	CString strSQL;
	strSQL="SELECT * FROM Servtypeconf" ;//构造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("Startport",_variant_t(m_StartPort));
					m_pRecordset->PutCollect("Endport",_variant_t(m_EndPort));
					m_pRecordset->PutCollect("Ipaddr",_variant_t(m_IpAddress));
									
					m_pRecordset->Update(); //更新数据库
					AfxMessageBox("添加数据成功!");  //提示信息
				}
				m_pRecordset->Close();
			}
		  }
		  catch(_com_error e)///捕捉异常
		  {
		    CString errormessage;
			MessageBox("创建记录集失败!","错误");
		  }
		}

		if(m_flag==2)
		{
    		strSQL.Format("select * from Servtypeconf 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("Startport",_variant_t(m_StartPort));//产品编号
						m_pRecordset1->PutCollect("Endport",_variant_t(m_EndPort));//产品名称
						m_pRecordset1->PutCollect("Ipaddr",_variant_t(m_IpAddress)); //规格
					
						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("类型名不能为空","提示",MB_OK|MB_ICONINFORMATION);
		return;
	}
	CDialog::OnOK();	
}

void CParaProcessDlg2::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}



BOOL CParaProcessDlg2::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 Servtypeconf where Name='%s' and Startport='%s' and Endport='%s' and Ipaddr='%s'",m_Name,m_StartPort,m_EndPort,m_IpAddress);
			_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 + -