Podobne
- Strona startowa
- Linux. .Mandrake.10.Podręcznik.Użytkownika.[eBook.PL] (3)
- (eBook) James, William The Principles of Psychology Vol. I
- (business ebook) Internet Marketing Tips for Newbie
- Filozofia. Zarys historii A Karpiński, J Kojkoł
- Swietlisty Kamien 03 Paneb Og Jacq Christian(1)
- Daniel Goleman Inteligencja emocjonalna 1997
- Ryzl Milan Parapsychologia praktyczna
- Gajusz Juliusz Cezar O Wojnie Galicyjskiej
- Tolkien J.R.R. Dwie Wieze
- Lem Stanislaw Dzienniki gwiazdowe t.1 (2)
- zanotowane.pl
- doc.pisz.pl
- pdf.pisz.pl
- pero.xlx.pl
Cytat
Do celu tam się wysiada. Lec Stanisław Jerzy (pierw. de Tusch-Letz, 1909-1966)
A bogowie grają w kości i nie pytają wcale czy chcesz przyłączyć się do gry (. . . ) Bogowie kpią sobie z twojego poukładanego życia (. . . ) nie przejmują się zbytnio ani naszymi planami na przyszłość ani oczekiwaniami. Gdzieś we wszechświecie rzucają kości i przypadkiem wypada twoja kolej. I odtąd zwyciężyć lub przegrać - to tylko kwestia szczęścia. Borys Pasternak
Idąc po kurzych jajach nie podskakuj. Przysłowie szkockie
I Herkules nie poradzi przeciwko wielu.
Dialog półinteligentów równa się monologowi ćwierćinteligenta. Stanisław Jerzy Lec (pierw. de Tusch - Letz, 1909-1966)
[ Pobierz całość w formacie PDF ]
.This is different from the ODBCconfiguration.Again, it's the file or data source difference between the two APIs.Other than thatdifference, the declarations appear identical.In Listing 15.8, you can explore the document class declaration.Listing 15.8 The DAO CADDRESSBOOKDAODOC Class Declaration1: // AddressBookDAODoc.h : interface of the CAddressBookDAODocclass2: //3:///////////////////////////////////////////////////////////////////4:5: #if !defined(AFX_ADDRESSBOOKDAODOC_H__990F28BB_41F8_11D2_9D79_000000000000__INCLUDED_)6: #define AFX_ADDRESSBOOKDAODOC_H__990F28BB_41F8_11D2_9D79_000000000000__INCLUDED_7:8: #if _MSC_VER >= 10009: #pragma once10: #endif // _MSC_VER >= 100011:12:13: class CAddressBookDAODoc : public CDocument14: {15: protected: // create from serialization only16: CAddressBookDAODoc();17: DECLARE_DYNCREATE(CAddressBookDAODoc)18:19: // Attributes20: public:21: CAddressBookDAOSet m_addressBookDAOSet;22:23: // Operations24: public:25:26: // Overrides27: // ClassWizard generated virtual function overrides28: //{{AFX_VIRTUAL(CAddressBookDAODoc)29: public:30: virtual BOOL OnNewDocument();31: virtual void Serialize(CArchive& ar);32: //}}AFX_VIRTUAL33:34: // Implementation35: public:36: virtual ~CAddressBookDAODoc();37: #ifdef _DEBUG38: virtual void AssertValid() const;39: virtual void Dump(CDumpContext& dc) const;40: #endif41:42: protected:43:44: // Generated message map functions45: protected:46: //{{AFX_MSG(CAddressBookDAODoc)47: // NOTE - The ClassWizard will add and remove memberfunctions // here.48: // DO NOT EDIT what you see in these blocks of generated// code !49: //}}AFX_MSG50: DECLARE_MESSAGE_MAP()51: };52:53:///////////////////////////////////////////////////////////////////54:55: //{{AFX_INSERT_LOCATION}}56: // Microsoft Developer Studio will insert additionaldeclarations57: // immediately before the preceding line.58:59: #endif //!defined(AFX_ADDRESSBOOKDAODOC_H__990F28BB_41F8_11D2_9D79_000000000000__INCLUDED_)Notice that this again appears identical to the ODBC MFC Document wrapper class.Notice on line 21that the document owns the recordset (your coupling).Finally, the view class is explored in Listing 15.9.Listing 15.9 The DAO CADDRESSBOOKDAOVIEW Class Declaration1: // AddressBookDAOView.h : interface of the CAddressBookDAOView// class2: //3:///////////////////////////////////////////////////////////////////////4:5: #if !defined(AFX_ADDRESSBOOKDAOVIEW_H__990F28BD_41F8_11D2_9D79_000000000000__INCLUDED_)6: #define AFX_ADDRESSBOOKDAOVIEW_H__990F28BD_41F8_11D2_9D79_000000000000__INCLUDED_7:8: #if _MSC_VER >= 10009: #pragma once10: #endif // _MSC_VER >= 100011:12: class CAddressBookDAOSet;13:14: class CAddressBookDAOView : public CDaoRecordView15: {16: protected: // create from serialization only17: CAddressBookDAOView();18: DECLARE_DYNCREATE(CAddressBookDAOView)19:20: public:21: //{{AFX_DATA(CAddressBookDAOView)22: enum{ IDD = IDD_ADDRESSBOOKDAO_FORM };23: CAddressBookDAOSet* m_pSet;24: // NOTE: The ClassWizard will add data members here25: //}}AFX_DATA26:27: // Attributes28: public:29: CAddressBookDAODoc* GetDocument();30:31: // Operations32: public:33:34: // Overrides35: // ClassWizard generated virtual function overrides36: //{{AFX_VIRTUAL(CAddressBookDAOView)37: public:38: virtual CDaoRecordset* OnGetRecordset();39: virtual BOOL PreCreateWindow(CREATESTRUCT& cs);40: protected:41: virtual void DoDataExchange(CDataExchange* pDX);// DDX/DDV support42: virtual void OnInitialUpdate(); // called first time after// construct43: virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);44: virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);45: virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);46: //}}AFX_VIRTUAL47:48: // Implementation49: public:50: virtual ~CAddressBookDAOView();51: #ifdef _DEBUG52: virtual void AssertValid() const;53: virtual void Dump(CDumpContext& dc) const;54: #endif55:56: protected:57:58: // Generated message map functions59: protected:60: //{{AFX_MSG(CAddressBookDAOView)61: // NOTE - The ClassWizard will add and remove memberfunctions // here.62: // DO NOT EDIT what you see in these blocks ofgenerated// code !63: //}}AFX_MSG64: DECLARE_MESSAGE_MAP()65: };66:67: #ifndef _DEBUG // debug version in AddressBookDAOView.cpp68: inline CAddressBookDAODoc* CAddressBookDAOView::GetDocument()69: { return (CAddressBookDAODoc*)m_pDocument; }70: #endif71:72:///////////////////////////////////////////////////////////////////////73:74: AFX_INSERT_LOCATION}}75: // Microsoft Developer Studio will insert additionaldeclarations76: // immediately before the preceding line.77:78: #endif //!defined(AFX_ADDRESSBOOKDAOVIEW_H__990F28BD_41F8_11D2_9D79_000000000000__INCLUDED_)Again, this looks identical to the ODBC implementation, and in many respects it is.Getting DataIf you look implementation>at the OnInitialUpdate routine of your view class, you see that it,too, is identical to the ODBC implementation.Do you see a pattern?The GetDefaultDBName will return a string indicating the file and path information to the database(see Listing 15.10).In the ODBC implementation, you had to go to the DSN table to find thisinformation.Listing 15.10 DAO GETDEFAULTDBNAME Implementation1: CString CAddressBookDAOSet::GetDefaultDBName()2: {3: return _T("E:\\Teach_Yourself_stuff\\Database_21\\Day15\\Applications\\AddressBookDB.mdb");4: }TIPIt's not generally good practice to hard-code string information.Modify thisto return a string variable that will contain the file and path declaration.The DoFieldExchange, shown in Listing 15.11, is similar to the DoDataExchange for a dialog-based view.The data from the database's columns are mapped to the application's memory by thismechanism.Listing 15.11 The DAO GETDEFAULTSQL and DOFIELDEXCHANGE Implementations1: CString CAddressBookDAOSet::GetDefaultSQL()2: {3: return _T("[Addresses]");4: }5:6: void CAddressBookDAOSet::DoFieldExchange(CDaoFieldExchange* pFX)7: {8: //{{AFX_FIELD_MAP(CAddressBookDAOSet)9: pFX->SetFieldType(CDaoFieldExchange::outputColumn);10: DFX_Long(pFX, _T("[ID]"), m_ID);11: DFX_Text(pFX, _T("[Last Name]"), m_Last_Name);12: DFX_Text(pFX, _T("[First Name]"), m_First_Name);13: DFX_Text(pFX, _T("[Street]"), m_Street);14: DFX_Text(pFX, _T("[City]"), m_City);15: DFX_Text(pFX, _T("[State]"), m_State);16: DFX_Long(pFX, _T("[Zip]"), m_Zip);17: DFX_Text(pFX, _T("[Phone]"), m_Phone);18: //}}AFX_FIELD_MAP19: }Other DAO ClassesBoth the ODBC and the DAO Address Book applications, as presented, are quite simplistic, and theyreally don't do much.What if you decided that you need to add another phone number field to thedatabase? You could use Microsoft Access to add the field and rebuild these applications to read inthat field.You would also have to place controls on the views to display your new field.This is a littlebit of work, but what if you needed to let the application's users define temporary tables and queries?Except for SQL DDL statements, ODBC doesn't give the programmer a method for modifying thedata source's schema.Because DAO is file-based, the programmer is able to easily modify the schemaprogrammatically.MFC provides two class wrappers that enable the programmer to easily modify the structure of thedatabase.These are CDaoTableDef and CDaoQueryDef.These wrappers map to the TableDefand QueryDef objects directly.These classes contain member functions that enable the programmerto build new database structures as well as modify any database structures deemed as updatable
[ Pobierz całość w formacie PDF ]