home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / samples / c08 / where / querydlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  2.3 KB  |  102 lines

  1. // QueryDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Biblio.h"
  6. #include "QueryDlg.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CQueryDlg dialog
  16.  
  17.  
  18. CQueryDlg::CQueryDlg(CWnd* pParent /*=NULL*/)
  19.     : CDialog(CQueryDlg::IDD, pParent)
  20. {
  21.     //{{AFX_DATA_INIT(CQueryDlg)
  22.     m_strWhere = _T("");
  23.     m_pSet = 0;
  24.     //}}AFX_DATA_INIT
  25. }
  26.  
  27.  
  28. void CQueryDlg::DoDataExchange(CDataExchange* pDX)
  29. {
  30.     CDialog::DoDataExchange(pDX);
  31.     //{{AFX_DATA_MAP(CQueryDlg)
  32.     DDX_Control(pDX, IDC_OPERATION, m_ctlOperation);
  33.     DDX_Control(pDX, IDC_FIELDNAME, m_ctlFieldName);
  34.     DDX_Control(pDX, IDC_WHERE, m_ctlWhere);
  35.     DDX_Text(pDX, IDC_WHERE, m_strWhere);
  36.     //}}AFX_DATA_MAP
  37. }
  38.  
  39.  
  40. BEGIN_MESSAGE_MAP(CQueryDlg, CDialog)
  41.     //{{AFX_MSG_MAP(CQueryDlg)
  42.     ON_CBN_SELENDOK(IDC_FIELDNAME, OnSelendokFieldName)
  43.     ON_CBN_SELENDOK(IDC_OPERATION, OnSelendokOperation)
  44.     //}}AFX_MSG_MAP
  45. END_MESSAGE_MAP()
  46.  
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CQueryDlg message handlers
  49.  
  50. BOOL CQueryDlg::OnInitDialog() 
  51. {
  52.     ASSERT(m_pSet != 0);
  53.     CDialog::OnInitDialog();
  54.     
  55.     // Load the recordset field names into the fieldname combobox
  56.     int nFields = m_pSet->GetFieldCount();
  57.     for(int i = 0; i < nFields; i++)
  58.     {
  59.         CDaoFieldInfo dfi;
  60.         m_pSet->GetFieldInfo(i,    dfi);
  61.         m_ctlFieldName.AddString(dfi.m_strName);
  62.     }
  63.     
  64.     return TRUE;  // return TRUE unless you set the focus to a control
  65.                   // EXCEPTION: OCX Property Pages should return FALSE
  66. }
  67.  
  68. void CQueryDlg::OnSelendokFieldName() 
  69. {
  70.     // The fieldname has changed. Update the WHERE clause.
  71.     CString strField("[");
  72.     CString strCurSel;
  73.     int index = m_ctlFieldName.GetCurSel();
  74.  
  75.     if(-1 == index)
  76.         return;
  77.  
  78.     m_ctlFieldName.GetLBText(index, strCurSel);
  79.     strField += strCurSel;
  80.     strField += "] ";
  81.  
  82.     m_ctlWhere.ReplaceSel(strField);
  83. }
  84.  
  85.  
  86. void CQueryDlg::OnSelendokOperation() 
  87. {
  88.     // The operation has set. Update the WHERE clause.
  89.     CString strOperation(" ");
  90.     CString strCurSel;
  91.     int index = m_ctlOperation.GetCurSel();
  92.  
  93.     if(-1 == index)
  94.         return;
  95.  
  96.     m_ctlOperation.GetLBText(index, strCurSel);
  97.     strOperation += strCurSel;
  98.     strOperation += " ";
  99.  
  100.     m_ctlWhere.ReplaceSel(strOperation);
  101. }
  102.