SelectDB.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // SelectDB.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "cp_main.h"
  5. #include "SelectDB.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CSelectDB dialog
  13. CSelectDB::CSelectDB(CWnd* pParent /*=NULL*/)
  14. : CDialog(CSelectDB::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CSelectDB)
  17. //}}AFX_DATA_INIT
  18. }
  19. void CSelectDB::DoDataExchange(CDataExchange* pDX)
  20. {
  21. CDialog::DoDataExchange(pDX);
  22. //{{AFX_DATA_MAP(CSelectDB)
  23. DDX_Control(pDX, IDC_PATH, m_ePath);
  24. //}}AFX_DATA_MAP
  25. }
  26. BEGIN_MESSAGE_MAP(CSelectDB, CDialog)
  27. //{{AFX_MSG_MAP(CSelectDB)
  28. ON_BN_CLICKED(IDC_SELECT, OnSelect)
  29. ON_BN_CLICKED(IDC_USE_DEFAULT, OnUseDefault)
  30. //}}AFX_MSG_MAP
  31. END_MESSAGE_MAP()
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CSelectDB message handlers
  34. BOOL CSelectDB::OnInitDialog()
  35. {
  36. CDialog::OnInitDialog();
  37. m_ePath.SetWindowText(CGetSetOptions::GetDBPath(FALSE));
  38. m_ePath.SetFocus();
  39. return FALSE;
  40. }
  41. void CSelectDB::OnOK()
  42. {
  43. CString csPath;
  44. m_ePath.GetWindowText(csPath);
  45. CGetSetOptions::SetDBPath(csPath);
  46. CDialog::OnOK();
  47. }
  48. void CSelectDB::OnSelect()
  49. {
  50. OPENFILENAME FileName;
  51. TCHAR szFileName[400];
  52. TCHAR szDir[400];
  53. memset(&FileName, 0, sizeof(FileName));
  54. memset(szFileName, 0, sizeof(szFileName));
  55. memset(&szDir, 0, sizeof(szDir));
  56. FileName.lStructSize = sizeof(FileName);
  57. FileName.lpstrTitle = _T("Open Database");
  58. FileName.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST;
  59. FileName.nMaxFile = 400;
  60. FileName.lpstrFile = szFileName;
  61. FileName.lpstrInitialDir = szDir;
  62. FileName.lpstrFilter = _T("Database Files (.MDB)\0*.mdb");
  63. FileName.lpstrDefExt = _T("mdb");
  64. if(GetOpenFileName(&FileName) == 0)
  65. return;
  66. CString csPath(FileName.lpstrFile);
  67. if(ValidDB(csPath) == FALSE)
  68. {
  69. MessageBox(_T("Invalid Database"), _T("Ditto"), MB_OK);
  70. m_ePath.SetFocus();
  71. }
  72. else
  73. m_ePath.SetWindowText(csPath);
  74. }
  75. void CSelectDB::OnUseDefault()
  76. {
  77. CGetSetOptions::SetDBPath("");
  78. CString csPath = CGetSetOptions::GetDBPath();
  79. if(ValidDB(csPath) == FALSE)
  80. DeleteFile(csPath);
  81. if(CheckDBExists(CGetSetOptions::GetDBPath()))
  82. EndDialog(IDOK);
  83. }