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

📄 paraprocessdlg3.cpp

📁 本程序使用Visual C++6.0编写
💻 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 + -