home *** CD-ROM | disk | FTP | other *** search
- // extdatView.cpp : implementation of the CExtdatView class
- //
-
- #include "stdafx.h"
- #include "extdat.h"
-
- #include "extdatDoc.h"
- #include "extdatView.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CExtdatView
-
- IMPLEMENT_DYNCREATE(CExtdatView, CView)
-
- BEGIN_MESSAGE_MAP(CExtdatView, CView)
- //{{AFX_MSG_MAP(CExtdatView)
- ON_COMMAND(ID_EXTERNAL_LINK_DBASE, OnExternalLinkDBase)
- ON_COMMAND(ID_EXTERNAL_LINK_CDTEXT, OnExternalCDtext)
- ON_COMMAND(ID_EXTERNAL_LINK_FWTEXT, OnExternalLinkFWtext)
- ON_COMMAND(ID_EXTERNAL_OPEN_FWTEXT, OnExternalOpenFWText)
- ON_COMMAND(ID_EXTERNAL_OPEN_CDTEXT, OnExternalOpenCDText)
- ON_COMMAND(ID_EXTERNAL_OPEN_DBASE, OnExternalOpenDBase)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CExtdatView construction/destruction
-
- CExtdatView::CExtdatView()
- {
- // TODO: add construction code here
-
- }
-
- CExtdatView::~CExtdatView()
- {
- }
-
- BOOL CExtdatView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
-
- return CView::PreCreateWindow(cs);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CExtdatView drawing
-
- void CExtdatView::OnDraw(CDC* pDC)
- {
- CExtdatDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
-
- // TODO: add draw code for native data here
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CExtdatView diagnostics
-
- #ifdef _DEBUG
- void CExtdatView::AssertValid() const
- {
- CView::AssertValid();
- }
-
- void CExtdatView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
-
- CExtdatDoc* CExtdatView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CExtdatDoc)));
- return (CExtdatDoc*)m_pDocument;
- }
- #endif //_DEBUG
-
- CString CExtdatView::GetDefaultDBName()
- {
- CFileStatus status;
- CString strFileName= _T("..\\..\\States.mdb");
- if( !CFile::GetStatus( strFileName, status ) )
- {
- strFileName= _T("..\\States.mdb");
- if( !CFile::GetStatus( strFileName, status ) )
- {
- strFileName= _T("");
- }
- }
- return strFileName;
- }
- CString CExtdatView::GetDefaultDirectory()
- {
- CString filename= GetDefaultDBName();
- // Remove the file name, keep the path w/o trailing '\'
- int idx= filename.ReverseFind('\\');
- if (idx == -1)
- return _T("");
- return filename.Left(idx);
- }
- CString CExtdatView::GetISAMName()
- {
- return CString("Availabl");
- }
- CString CExtdatView::GetFWTextName()
- {
- return CString("PetList.txt");
- }
- CString CExtdatView::GetCDTextName()
- {
- return CString("Names.txt");
- }
- /////////////////////////////////////////////////////////////////////////////
- // CExtdatView message handlers
-
-
- /// ISAM DATABASE
- void CExtdatView::OnExternalLinkDBase()
- {
-
- // Open a database to link from
- CDaoDatabase db;
- db.Open(GetDefaultDBName());
-
- // Create a tabeldef
- CDaoTableDef tbl(&db);
- // Specify a friendly name, source table name and directory.
- CString TableName("Available States");
- tbl.Create(TableName);
- tbl.SetSourceTableName(GetISAMName());
- CString strConn;
- strConn.Format("dBASE III;DATABASE=%s", GetDefaultDirectory());
- tbl.SetConnect(strConn); // for ODBC _T() required.
-
- // Try to delete any existing table with this name.
- // This will throw an exception if no table exists,
- // which is OK.
- try
- {
- db.DeleteTableDef(TableName);
- }
- catch (CDaoException* e)
- {
- e->Delete();
- }
- tbl.Append();
-
- }
-
- void CExtdatView::OnExternalOpenDBase()
- {
- CString dbPath = GetDefaultDirectory();
- CString dbDBaseName= GetISAMName();
-
- CDaoDatabase db;
- db.Open(dbPath, FALSE, FALSE, "dBASE III;");
-
- CDaoRecordset rs(&db);
- rs.Open(dbOpenTable,dbDBaseName);
- while (!rs.IsEOF())
- {
- // process record ...
- COleVariant field0;
- rs.GetFieldValue(0, field0);
- TRACE("field 0: %s\n", field0.pbVal);
-
- rs.MoveNext();
- }
- }
-
- // Character-delimited TEXT FILE
- void CExtdatView::OnExternalCDtext()
- {
-
- // Open a database to link from
- CDaoDatabase db;
- db.Open(GetDefaultDBName());
-
- // Create a tabeldef
- CDaoTableDef tbl(&db);
- // Specify a friendly name, source table name and directory.
- CString TableName("Names");
- tbl.Create(TableName);
- tbl.SetSourceTableName(GetCDTextName());
- CString strConn;
- strConn.Format("Text;DATABASE=%s", GetDefaultDirectory());
- tbl.SetConnect(strConn); // for ODBC _T() required around string.
-
- // Try to delete any existing table with this name.
- // This will throw an exception if no table exists,
- // which is OK.
- try
- {
- db.DeleteTableDef(TableName);
- }
- catch (CDaoException* e)
- {
- e->Delete();
- }
-
- tbl.Append();
-
- }
- void CExtdatView::OnExternalOpenCDText()
- {
- // Open a text file as a dynaset recordset.
- CString dbPath = GetDefaultDirectory();
- CString dbTextFileName= GetCDTextName();
- CString sql;
- sql.Format("SELECT * FROM %s", dbTextFileName);
-
- CDaoDatabase db;
- db.Open(dbPath, FALSE, FALSE, "Text;");
-
- CDaoRecordset rs(&db);
- rs.Open(dbOpenDynaset,sql);
- while (!rs.IsEOF())
- {
- // process record ...
- COleVariant field0;
- rs.GetFieldValue(0, field0);
- TRACE("field0: %s\n", field0.pbVal);
-
- rs.MoveNext();
- }
-
- }
-
- // Fixed width field TEXT FILE
- void CExtdatView::OnExternalLinkFWtext()
- {
- // Open a database to link from
- CDaoDatabase db;
- db.Open(GetDefaultDBName());
-
- // Create a tabeldef
- CDaoTableDef tbl(&db);
- // Specify a friendly name, source table name and directory.
- CString TableName("Pets");
- tbl.Create(TableName);
- tbl.SetSourceTableName(GetFWTextName());
- CString strConn;
- strConn.Format("Text;DATABASE=%s", GetDefaultDirectory());
- tbl.SetConnect(strConn); // for ODBC _T() required around string.
-
- // Try to delete any existing table with this name.
- // This will throw an exception if no table exists,
- // which is OK.
- try
- {
- db.DeleteTableDef(TableName);
- }
- catch (CDaoException* e)
- {
- e->Delete();
- }
-
-
- tbl.Append();
-
- }
-
- void CExtdatView::OnExternalOpenFWText()
- {
- // Open a text file as a dynaset recordset.
- CString dbPath = GetDefaultDirectory();
- CString dbTextFileName= GetFWTextName();
- CString sql;
- sql.Format("SELECT * FROM %s", dbTextFileName);
-
- CDaoDatabase db;
- db.Open(dbPath, FALSE, FALSE, "Text;");
-
- CDaoRecordset rs(&db);
- rs.Open(dbOpenDynaset,sql);
- while (!rs.IsEOF())
- {
- // process record ...
- COleVariant field0;
- rs.GetFieldValue(0, field0);
- TRACE("field0: %s\n", field0.pbVal);
-
- rs.MoveNext();
- }
-
- }
-