home *** CD-ROM | disk | FTP | other *** search
- // BinaryDataDlg.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "ADO.h"
- #include "ADODlg.h"
-
- // Change path to match your configuration
- #import "D:\Program Files\Common Files\System\ado\msado15.dll" rename("EOF","Eof") rename("BOF","Bof")
-
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
-
- LPCTSTR g_sampleDescription =
- _T("This sample demonstrates how to bind the BeeGrid control to an ADO recordset.")
- _T("");
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CADODlg dialog
-
- CADODlg::CADODlg(CWnd* pParent /*=NULL*/)
- : CDialog(CADODlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CADODlg)
- m_description = g_sampleDescription;
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
-
- void CADODlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CADODlg)
- DDX_Text(pDX, IDC_DESCR, m_description);
- //}}AFX_DATA_MAP
- DDX_BeeGrid(pDX, IDC_GRID1, m_grid);
- }
-
- BEGIN_MESSAGE_MAP(CADODlg, CDialog)
- //{{AFX_MSG_MAP(CADODlg)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CADODlg message handlers
-
- BOOL CADODlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // 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
-
- //
- // Initialize BeeGrid
- //
-
- try
- {
- m_grid.intf->DataMode = sgBound;
- m_grid.intf->AllowEdit = VARIANT_TRUE;
- m_grid.intf->AllowAddNew = VARIANT_TRUE;
- m_grid.intf->AllowDelete = VARIANT_TRUE;
-
- // Change the connection string to match your configuration
- LPCTSTR szProvider = _T("Provider=Microsoft.Jet.OLEDB.4.0;")
- _T("Data Source=F:\\Projects\\SampleData\\nwind.mdb;")
- _T("Persist Security Info=False");
-
- // Open connection object
- ADODB::_ConnectionPtr spConnection(_T("ADODB.Connection"));
- spConnection->CursorLocation = ADODB::adUseClient;
- spConnection->Open(szProvider, _T(""), _T(""), ADODB::adOpenUnspecified);
-
- // Pack connection pointer into the variant needed by recordset object
- IDispatchPtr spConnectionDisp = spConnection;
- _variant_t varConnection = spConnectionDisp.GetInterfacePtr();
-
- // Retrieve a recordset
- ADODB::_RecordsetPtr spRecordset(_T("ADODB.Recordset"));
- spRecordset->Open(_T("Products"), varConnection, ADODB::adOpenStatic,
- ADODB::adLockOptimistic, ADODB::adCmdTable);
-
- // Bind grid
- MSDATASRC::DataSourcePtr spDataSource = spRecordset;
- m_grid.intf->DataSource = spDataSource;
- }
- catch (_com_error& e)
- {
- CString err;
- err.Format("Error# %08X\n%s\0", e.Error(), LPCSTR(e.Description()));
- AfxMessageBox(err);
- }
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
-
-
- // 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.
-
- void CADODlg::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.
- HCURSOR CADODlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
-
- BEGIN_EVENTSINK_MAP(CADODlg, CDialog)
- //{{AFX_EVENTSINK_MAP(CADODlg)
- //}}AFX_EVENTSINK_MAP
- END_EVENTSINK_MAP()
-
-
-