home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / Cell Control / DATA1.CAB / VCDEMO_Files / DbaseDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-11  |  2.5 KB  |  99 lines

  1. // DbaseDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "VCDemo.h"
  6. #include "DbaseDlg.h"
  7.  
  8. #include <afxpriv.h>
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CDbaseDlg dialog
  18.  
  19.  
  20. CDbaseDlg::CDbaseDlg(CWnd* pParent /*=NULL*/)
  21.     : CDialog(CDbaseDlg::IDD, pParent)
  22. {
  23.     //{{AFX_DATA_INIT(CDbaseDlg)
  24.     m_filename = _T("");
  25.     //}}AFX_DATA_INIT
  26. }
  27.  
  28.  
  29. void CDbaseDlg::DoDataExchange(CDataExchange* pDX)
  30. {
  31.     CDialog::DoDataExchange(pDX);
  32.     //{{AFX_DATA_MAP(CDbaseDlg)
  33.     DDX_Text(pDX, IDC_EDIT_FILENAME, m_filename);
  34.     DDX_Control(pDX, IDC_SGCTRL1, m_ctrl);
  35.     //}}AFX_DATA_MAP
  36. }
  37.  
  38.  
  39. BEGIN_MESSAGE_MAP(CDbaseDlg, CDialog)
  40.     //{{AFX_MSG_MAP(CDbaseDlg)
  41.     ON_BN_CLICKED(IDC_BUTTON_BROWSER, OnButtonBrowser)
  42.     ON_BN_CLICKED(IDC_BUTTON_OPEN, OnButtonOpen)
  43.     //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45.  
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CDbaseDlg message handlers
  48.  
  49. void CDbaseDlg::OnButtonBrowser() 
  50. {
  51.     // TODO: Add your control notification handler code here
  52.     UpdateData();
  53.     CFileDialog file( TRUE, "*.MDB", m_filename, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, 
  54.                                         "Access File(*.MDB)|*.MDB|", NULL );
  55.     if ( file.DoModal() == IDOK ){
  56.         m_filename = file.GetPathName( );
  57.     }
  58.     UpdateData(FALSE);
  59. }
  60.  
  61. void CDbaseDlg::OnButtonOpen() 
  62. {
  63.     // TODO: Add your control notification handler code here
  64.     USES_CONVERSION;      //add #include <afxpriv.h> in your stdafx.h
  65.  
  66.     UpdateData();
  67.     if( m_filename.IsEmpty() ){
  68.         AfxMessageBox( "Please input filename!" );
  69.         GetDlgItem( IDC_EDIT_FILENAME )->SetFocus();
  70.     }
  71.     else{
  72.         COleVariant var;
  73.         if( m_ctrl.DoOpenFileDbase( 0, m_filename, &var ) ){
  74.             CString tables, tablename;
  75.             COleVariant varcols, varrows;
  76.             long cols,rows;
  77.             if( var.vt == VT_BSTR )
  78.                 tables = W2A(V_BSTR(&var));
  79.             for( int i=0; i<3; i++){ //support at most 3 tables
  80.                 int loc = tables.Find( "\r\n" );
  81.                 if( loc > 0 ){
  82.                     tablename = tables.Left( loc );
  83.                     tables = tables.Right( tables.GetLength() - loc - 2 );
  84.                     if( i > 0 )m_ctrl.DoAppendPage( "", 1 );
  85.                     m_ctrl.DoDumpDbaseTable( tablename, 0, -1, i, TRUE, &varcols, &varrows);
  86.                     m_ctrl.DoSetCurrentPage( i );
  87.                     varcols.ChangeType( VT_R8 );
  88.                     varrows.ChangeType( VT_R8 );
  89.                     cols = long(varcols.dblVal);
  90.                     rows = long(varrows.dblVal);
  91.                     m_ctrl.SetCols( cols );
  92.                     m_ctrl.SetRows( rows-1 );
  93.                 }
  94.             }
  95.             m_ctrl.DoCloseDbase();
  96.         }
  97.     }
  98. }
  99.