home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / database / stdreg / columdlg.cpp next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  4.3 KB  |  167 lines

  1. // columdlg.cpp : implementation file
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "stdreg.h"
  15. #include "columdlg.h"
  16. #include "resource.h"
  17. #include "typeinfo.h"
  18.  
  19. #ifdef _DEBUG
  20. #undef THIS_FILE
  21. static char BASED_CODE THIS_FILE[] = __FILE__;
  22. #endif
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CColSyntaxDlg dialog
  26.  
  27.  
  28. CColSyntaxDlg::CColSyntaxDlg(CWnd* pParent /*=NULL*/)
  29.     : CDialog(CColSyntaxDlg::IDD, pParent)
  30. {
  31.     //{{AFX_DATA_INIT(CColSyntaxDlg)
  32.     m_strSyntax = "";
  33.     m_strListBoxInstruction = "";
  34.     m_strColTypeInstruction = "";
  35.     //}}AFX_DATA_INIT
  36. }
  37.  
  38. BOOL CColSyntaxDlg::OnInitDialog()
  39. {
  40.     CDialog::OnInitDialog();
  41.  
  42.     m_posMapSQLTypeToSyntax = m_pMapSQLTypeToSyntax->GetStartPosition();
  43.     GetNextSQLTypeAndUpdateControls();
  44.  
  45.     return TRUE;
  46. }
  47.  
  48.  
  49. void CColSyntaxDlg::DoDataExchange(CDataExchange* pDX)
  50. {
  51.     CDialog::DoDataExchange(pDX);
  52.     //{{AFX_DATA_MAP(CColSyntaxDlg)
  53.     DDX_Control(pDX, IDOK, m_ctlOK);
  54.     DDX_Control(pDX, IDC_TYPE_INFO_LIST, m_ctlTypeInfoList);
  55.     DDX_Text(pDX, IDC_SYNTAX, m_strSyntax);
  56.     DDX_Text(pDX, IDC_LIST_BOX_INSTRUCTION, m_strListBoxInstruction);
  57.     DDX_Text(pDX, IDC_COL_TYPE_INSTRUCTION, m_strColTypeInstruction);
  58.     //}}AFX_DATA_MAP
  59. }
  60.  
  61. void CColSyntaxDlg::GetNextSQLTypeAndUpdateControls()
  62. {
  63.     ASSERT(m_pMapSQLTypeToSyntax != NULL);
  64.     m_pMapSQLTypeToSyntax->GetNextAssoc(m_posMapSQLTypeToSyntax,
  65.         m_swCurrentSQLType, m_strSyntax);
  66.  
  67.     CString strWindowText;
  68.     strWindowText.LoadString(m_posMapSQLTypeToSyntax == NULL? IDS_OK : IDS_NEXT);
  69.     m_ctlOK.SetWindowText(strWindowText);
  70.  
  71.     int nInstructionIDS, nExampleIDS, nSQLTypeIDS;
  72.     switch (m_swCurrentSQLType)
  73.     {
  74.         case SQL_VARCHAR:
  75.             nInstructionIDS = IDS_VARCHAR_INSTRUCTION;
  76.             nExampleIDS =IDS_VARCHAR_EXAMPLE;
  77.             nSQLTypeIDS = IDS_VARCHAR;
  78.             break;
  79.  
  80.         case SQL_INTEGER:
  81.             nInstructionIDS = IDS_INTEGER_INSTRUCTION;
  82.             nExampleIDS =IDS_INTEGER_EXAMPLE;
  83.             nSQLTypeIDS = IDS_INTEGER;
  84.             break;
  85.  
  86.         case SQL_SMALLINT:
  87.             nInstructionIDS = IDS_SMALLINT_INSTRUCTION;
  88.             nExampleIDS =IDS_SMALLINT_EXAMPLE;
  89.             nSQLTypeIDS = IDS_SMALLINT;
  90.             break;
  91.     }
  92.  
  93.     m_strColTypeInstruction.LoadString(IDS_COL_TYPE_INSTRUCTION);
  94.     m_strColTypeInstruction += "\n\n";
  95.  
  96.     CString strInstructionPart2;
  97.     strInstructionPart2.LoadString(nInstructionIDS);
  98.     m_strColTypeInstruction += strInstructionPart2;
  99.     m_strColTypeInstruction += "\n\n";
  100.  
  101.     strInstructionPart2.LoadString(nExampleIDS);
  102.     m_strColTypeInstruction += strInstructionPart2;
  103.  
  104.     CString strListBoxInstruction;
  105.     strListBoxInstruction.LoadString(IDS_TYPE_INFO_LISTBOX_INSTRUCTION);
  106.     CString strSQLType;
  107.     strSQLType.LoadString(nSQLTypeIDS);
  108.     m_strListBoxInstruction.Format(strListBoxInstruction,strSQLType);
  109.  
  110.     // Update the m_strSyntax field as well as the instructions in the static controls.
  111.     UpdateData(FALSE);
  112.  
  113.     FillTypeInfoListbox();
  114. }
  115.  
  116. void CColSyntaxDlg::FillTypeInfoListbox()
  117. {
  118.     CTypeInfo typeInfo(&((CStdRegSetupApp*)AfxGetApp())->m_db);
  119.  
  120.     typeInfo.m_fSqlTypeParam = m_swCurrentSQLType;
  121.     if (!typeInfo.Open(CRecordset::forwardOnly, NULL, CRecordset::readOnly))
  122.         return;
  123.  
  124.     m_ctlTypeInfoList.ResetContent();
  125.     CString strTypeInfo;
  126.     while (!typeInfo.IsEOF())
  127.     {
  128.         strTypeInfo = typeInfo.m_strTypeName;
  129.         if (!typeInfo.m_strCreateParams.IsEmpty())
  130.         {
  131.             strTypeInfo += '(';
  132.             strTypeInfo += typeInfo.m_strCreateParams;
  133.             strTypeInfo += ')';
  134.         }
  135.         m_ctlTypeInfoList.AddString(strTypeInfo);
  136.         typeInfo.MoveNext();
  137.     }
  138.  
  139.     typeInfo.Close();
  140. }
  141.  
  142.  
  143. BEGIN_MESSAGE_MAP(CColSyntaxDlg, CDialog)
  144.     //{{AFX_MSG_MAP(CColSyntaxDlg)
  145.     //}}AFX_MSG_MAP
  146. END_MESSAGE_MAP()
  147.  
  148.  
  149. /////////////////////////////////////////////////////////////////////////////
  150. // CColSyntaxDlg message handlers
  151.  
  152. void CColSyntaxDlg::OnOK()
  153. {
  154.     if (!UpdateData())
  155.         return;
  156.  
  157.     m_pMapSQLTypeToSyntax->SetAt(m_swCurrentSQLType, m_strSyntax);
  158.  
  159.     if (m_posMapSQLTypeToSyntax == NULL)
  160.     {
  161.         EndDialog(IDOK);
  162.         return;
  163.     }
  164.  
  165.     GetNextSQLTypeAndUpdateControls();
  166. }
  167.