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

📄 ocidemodlg.cpp

📁 利用oci(oracle connect interface)方式实现的数据库连接
💻 CPP
字号:
// OciDemoDlg.cpp : implementation file
//

#include "stdafx.h"
#include "OciDemo.h"
#include "OciDemoDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
connection* mycon=new connection;
//##ModelId=39A1381F0038
class CAboutDlg : public CDialog
{
public:
	//##ModelId=39A1381F0056
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	//##ModelId=39A1381F0060
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

//##ModelId=39A1381F0056
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

//##ModelId=39A1381F0060
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COciDemoDlg dialog

//##ModelId=39A1381D03C4
COciDemoDlg::COciDemoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(COciDemoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(COciDemoDlg)
	m_dept_no = 0;
	m_dept_name = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

//##ModelId=39A1381E002C
void COciDemoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(COciDemoDlg)
	DDX_Text(pDX, IDC_EDIT1, m_dept_no);
	DDX_Text(pDX, IDC_EDIT2, m_dept_name);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(COciDemoDlg, CDialog)
	//{{AFX_MSG_MAP(COciDemoDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COciDemoDlg message handlers

//##ModelId=39A1381E0072
BOOL COciDemoDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	if(!mycon->connect("system","manager","third")) 
	{
		mycon->display_error();
		AfxMessageBox("error connect",MB_OK);
	}
	
	

	return TRUE;  // return TRUE  unless you set the focus to a control
}

//##ModelId=39A1381E0074
void COciDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

//##ModelId=39A1381E0091
void COciDemoDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
//##ModelId=39A1381E009B
HCURSOR COciDemoDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}



//##ModelId=39A1381E00A4
void COciDemoDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	mycon->disconnect();

	// TODO: Add your message handler code here
	
}

//##ModelId=39A1381E00AE
void COciDemoDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	cursor  crsr;
    char    Dept_name[10][30];
	char    no[10][4];
		

	CString   sel;
	sel.Format("select dname,deptno from dept");//通过字符串的连接处理避免了比较麻烦的输入绑定

	//oci调用出错时由类成员函数作出提示,各成员;函数调用成功则返回TRUE
	//open;
	if(!crsr.open(mycon)) AfxMessageBox("fail open",MB_OK);
	//parse;
    crsr.parse(sel);

	crsr.define_by_name("deptno",no,4,STRING_TYPE);//当一次取时多行,必须保证第三个参数的精确性
	crsr.define_by_name("dname",Dept_name, 30,STRING_TYPE);	


	//查询
	crsr.execute();

	crsr.FetchMultiRow(10);

	m_dept_name=Dept_name[0];
	UpdateData(FALSE);	

	crsr.close();
}

//##ModelId=39A1381E00B0
void COciDemoDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	UpdateData();

	cursor crsr;
	CString UpdateStr;
	UpdateStr.Format("update dept set dname='%s' where deptno=%d",m_dept_name,m_dept_no);
	crsr.open(mycon);
	crsr.ExecuteSQL(UpdateStr.GetBuffer(UpdateStr.GetLength()));
	crsr.ExecuteSQL("commit");
	crsr.close();
}

⌨️ 快捷键说明

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