MainTable.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // MainTable.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CP_Main.h"
  5. #include "MainTable.h"
  6. #include "DatabaseUtilities.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CMainTable
  14. IMPLEMENT_DYNAMIC(CMainTable, CDaoRecordset)
  15. CMainTable::CMainTable(CDaoDatabase* pdb)
  16. : CDaoRecordset(pdb)
  17. {
  18. //{{AFX_FIELD_INIT(CMainTable)
  19. m_lID = 0;
  20. m_lDate = 0;
  21. m_strType = _T("");
  22. m_strText = _T("");
  23. m_lShortCut = 0;
  24. m_lDontAutoDelete = 0;
  25. m_lTotalCopySize = 0;
  26. m_nFields = 7;
  27. //}}AFX_FIELD_INIT
  28. m_nDefaultType = dbOpenDynaset;
  29. }
  30. CString CMainTable::GetDefaultDBName()
  31. {
  32. return GetDBName();
  33. }
  34. CString CMainTable::GetDefaultSQL()
  35. {
  36. return _T("[Main]");
  37. }
  38. void CMainTable::DoFieldExchange(CDaoFieldExchange* pFX)
  39. {
  40. //{{AFX_FIELD_MAP(CMainTable)
  41. pFX->SetFieldType(CDaoFieldExchange::outputColumn);
  42. DFX_Long(pFX, _T("[lID]"), m_lID);
  43. DFX_Long(pFX, _T("[lDate]"), m_lDate);
  44. DFX_Text(pFX, _T("[strType]"), m_strType);
  45. DFX_Text(pFX, _T("[strText]"), m_strText);
  46. DFX_Long(pFX, _T("[lShortCut]"), m_lShortCut);
  47. DFX_Long(pFX, _T("[lDontAutoDelete]"), m_lDontAutoDelete);
  48. DFX_Long(pFX, _T("[lTotalCopySize]"), m_lTotalCopySize);
  49. //}}AFX_FIELD_MAP
  50. }
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CMainTable diagnostics
  53. #ifdef _DEBUG
  54. void CMainTable::AssertValid() const
  55. {
  56. CDaoRecordset::AssertValid();
  57. }
  58. void CMainTable::Dump(CDumpContext& dc) const
  59. {
  60. CDaoRecordset::Dump(dc);
  61. }
  62. #endif //_DEBUG
  63. // only deletes from Main
  64. BOOL CMainTable::DeleteAll()
  65. {
  66. BOOL bRet = FALSE;
  67. try
  68. {
  69. theApp.EnsureOpenDB();
  70. theApp.m_pDatabase->Execute("DELETE * FROM Main", dbFailOnError);
  71. bRet = TRUE;
  72. }
  73. catch(CDaoException* e)
  74. {
  75. AfxMessageBox(e->m_pErrorInfo->m_strDescription);
  76. e->Delete();
  77. }
  78. return bRet;
  79. }
  80. HACCEL CMainTable::LoadAcceleratorKeys()
  81. {
  82. CMainTable recset;
  83. try
  84. {
  85. recset.Open("SELECT * FROM Main WHERE lShortCut > 0");
  86. CArray<ACCEL, ACCEL> keys;
  87. while(!recset.IsEOF())
  88. {
  89. ACCEL me;
  90. me.cmd = (USHORT)recset.m_lID;
  91. me.fVirt = 0;
  92. if( HIBYTE(recset.m_lShortCut) & HOTKEYF_SHIFT ) me.fVirt |= FSHIFT;
  93. if( HIBYTE(recset.m_lShortCut) & HOTKEYF_CONTROL ) me.fVirt |= FCONTROL;
  94. if( HIBYTE(recset.m_lShortCut) & HOTKEYF_ALT ) me.fVirt |= FALT;
  95. me.fVirt |= FVIRTKEY;
  96. me.key = LOBYTE(recset.m_lShortCut);
  97. keys.Add(me);
  98. recset.MoveNext();
  99. }
  100. if(keys.GetSize() > 0)
  101. return CreateAcceleratorTable(keys.GetData(), keys.GetSize());
  102. }
  103. catch(CDaoException* e)
  104. {
  105. e->Delete();
  106. }
  107. return NULL;
  108. }
  109. void CMainTable::Open(LPCTSTR lpszFormat,...)
  110. {
  111. m_pDatabase = theApp.EnsureOpenDB();
  112. CString csText;
  113. va_list vlist;
  114. ASSERT(AfxIsValidString(lpszFormat));
  115. va_start(vlist,lpszFormat);
  116. csText.FormatV(lpszFormat,vlist);
  117. va_end(vlist);
  118. CDaoRecordset::Open(AFX_DAO_USE_DEFAULT_TYPE, csText, 0);
  119. }