Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Design issue

Design issue

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasedesignsaleshelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Emanuele 0
    wrote on last edited by
    #1

    I’m writing an MFC Doc/View (SDI) application with database support (DAO). In CMyDoc class I put a member variable CmyDaoDB* m_MyDaoDB and some function to add/delete data to/from Database. On the view I build a listbox control in wich I need to put the entire recordset (say Customers). I’d like to buil a member function in the CmyDoc class that return the list of Customer to view. But how? I think that the only solution is to access directly to CmyDaoDB from the view to get the customers: while (!m_MyDaoDb->IsEOF()) { /* Put the record in the list control */ m_MyDaoDb->MoveNext() } Is there a better way to get that list? (I mean more OO)

    D T 2 Replies Last reply
    0
    • E Emanuele 0

      I’m writing an MFC Doc/View (SDI) application with database support (DAO). In CMyDoc class I put a member variable CmyDaoDB* m_MyDaoDB and some function to add/delete data to/from Database. On the view I build a listbox control in wich I need to put the entire recordset (say Customers). I’d like to buil a member function in the CmyDoc class that return the list of Customer to view. But how? I think that the only solution is to access directly to CmyDaoDB from the view to get the customers: while (!m_MyDaoDb->IsEOF()) { /* Put the record in the list control */ m_MyDaoDb->MoveNext() } Is there a better way to get that list? (I mean more OO)

      D Offline
      D Offline
      Doug Garno
      wrote on last edited by
      #2

      You have the basic idea. The way that I do it is to pass the list control to the Doc and have the doc populate the list, that way the View doesn't need to know anything about the database. Something like this: CDoc::AddCustomers( CListCtrl* pList ) { // Reset the list control content pList->DeleteAllItems(); // I'm assuming that you somehow get a CDaoRecordset for the Customer table // and not accessing the database object directly. m_MyDaoDB->MoveFirst(); while( m_MyDaoDB->IsEOF() != 0 ) { // Add the record to the list m_MyDaoDB->MoveNext(); } } Don't know if this is a better OO way, but the Doc should know about the data, and the view handles the UI. I like to keep access to the data in the Doc and the View handles the display and user interaction.

      1 Reply Last reply
      0
      • E Emanuele 0

        I’m writing an MFC Doc/View (SDI) application with database support (DAO). In CMyDoc class I put a member variable CmyDaoDB* m_MyDaoDB and some function to add/delete data to/from Database. On the view I build a listbox control in wich I need to put the entire recordset (say Customers). I’d like to buil a member function in the CmyDoc class that return the list of Customer to view. But how? I think that the only solution is to access directly to CmyDaoDB from the view to get the customers: while (!m_MyDaoDb->IsEOF()) { /* Put the record in the list control */ m_MyDaoDb->MoveNext() } Is there a better way to get that list? (I mean more OO)

        T Offline
        T Offline
        Tomasz Sowinski
        wrote on last edited by
        #3

        Is there a better way to get that list? (I mean more OO) "More OO" solution is to create a public member in your doc class which takes CListBox reference as an argument and fills the window with database contents:

        // error handling omitted
        void CYourDoc::FillListBox(CListBox &lbx)
        {
        // use m_MyDaoDb here to fill &lbx
        while (!m_MyDaoDb->IsEOF())
        {
        int idx = lbx.AddString(...);
        lbx.SetItemData(idx, ...);
        m_MyDaoDb->MoveNext();
        }
        }

        Tomasz Sowinski -- http://www.shooltz.com

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups