MainTable.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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_strText = _T("");
  22. m_lShortCut = 0;
  23. m_lDontAutoDelete = 0;
  24. m_lTotalCopySize = 0;
  25. m_nFieldCount = m_nFields = 6;
  26. //}}AFX_FIELD_INIT
  27. m_nDefaultType = dbOpenDynaset;
  28. m_bBindFields = true;
  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. // make sure this isn't called when we aren't using bound fields
  41. VERIFY( m_bBindFields == true );
  42. //{{AFX_FIELD_MAP(CMainTable)
  43. pFX->SetFieldType(CDaoFieldExchange::outputColumn);
  44. DFX_Long(pFX, _T("[lID]"), m_lID);
  45. DFX_Long(pFX, _T("[lDate]"), m_lDate);
  46. DFX_Text(pFX, _T("[mText]"), m_strText);
  47. DFX_Long(pFX, _T("[lShortCut]"), m_lShortCut);
  48. DFX_Long(pFX, _T("[lDontAutoDelete]"), m_lDontAutoDelete);
  49. DFX_Long(pFX, _T("[lTotalCopySize]"), m_lTotalCopySize);
  50. //}}AFX_FIELD_MAP
  51. }
  52. void CMainTable::Open(int nOpenType , LPCTSTR lpszSql , int nOptions)
  53. {
  54. OnQuery();
  55. CDaoRecordset::Open(nOpenType, lpszSql, nOptions);
  56. }
  57. void CMainTable::Requery()
  58. {
  59. OnQuery();
  60. CDaoRecordset::Requery();
  61. }
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CMainTable member functions
  64. void CMainTable::OnQuery()
  65. {}
  66. bool CMainTable::SetBindFields(bool bVal)
  67. {
  68. bool bOld = m_bBindFields;
  69. m_bBindFields = bVal;
  70. if(m_bBindFields)
  71. m_nFields = m_nFieldCount;
  72. else
  73. m_nFields = 0;
  74. return bOld;
  75. }
  76. // only deletes from Main
  77. BOOL CMainTable::DeleteAll()
  78. {
  79. BOOL bRet = FALSE;
  80. try
  81. {
  82. theApp.EnsureOpenDB();
  83. theApp.m_pDatabase->Execute("DELETE * FROM Main", dbFailOnError);
  84. bRet = TRUE;
  85. }
  86. catch(CDaoException* e)
  87. {
  88. AfxMessageBox(e->m_pErrorInfo->m_strDescription);
  89. e->Delete();
  90. }
  91. return bRet;
  92. }
  93. void CMainTable::LoadAcceleratorKeys( CAccels& accels )
  94. {
  95. CMainTable recset;
  96. try
  97. {
  98. recset.Open("SELECT * FROM Main WHERE lShortCut > 0");
  99. CAccel a;
  100. while(!recset.IsEOF())
  101. {
  102. a.Cmd = recset.m_lID;
  103. a.Key = recset.m_lShortCut;
  104. accels.AddAccel( a );
  105. recset.MoveNext();
  106. }
  107. }
  108. catch(CDaoException* e)
  109. {
  110. e->Delete();
  111. }
  112. }
  113. /*
  114. //HACCEL CMainTable::LoadAcceleratorKeys()
  115. //{
  116. // CMainTable recset;
  117. //
  118. // try
  119. // {
  120. // recset.Open("SELECT * FROM Main WHERE lShortCut > 0");
  121. //
  122. // CArray<ACCEL, ACCEL> keys;
  123. //
  124. // while(!recset.IsEOF())
  125. // {
  126. // ACCEL me;
  127. // me.cmd = (USHORT)recset.m_lID;
  128. // me.fVirt = 0;
  129. // if( HIBYTE(recset.m_lShortCut) & HOTKEYF_SHIFT ) me.fVirt |= FSHIFT;
  130. // if( HIBYTE(recset.m_lShortCut) & HOTKEYF_CONTROL ) me.fVirt |= FCONTROL;
  131. // if( HIBYTE(recset.m_lShortCut) & HOTKEYF_ALT ) me.fVirt |= FALT;
  132. // me.fVirt |= FVIRTKEY;
  133. // me.key = LOBYTE(recset.m_lShortCut);
  134. //
  135. // keys.Add(me);
  136. //
  137. // recset.MoveNext();
  138. // }
  139. //
  140. // if(keys.GetSize() > 0)
  141. // return CreateAcceleratorTable(keys.GetData(), keys.GetSize());
  142. // }
  143. // catch(CDaoException* e)
  144. // {
  145. // e->Delete();
  146. // }
  147. //
  148. // return NULL;
  149. //}
  150. */
  151. void CMainTable::Open(LPCTSTR lpszFormat,...)
  152. {
  153. m_pDatabase = theApp.EnsureOpenDB();
  154. CString csText;
  155. va_list vlist;
  156. ASSERT(AfxIsValidString(lpszFormat));
  157. va_start(vlist,lpszFormat);
  158. csText.FormatV(lpszFormat,vlist);
  159. va_end(vlist);
  160. Open(AFX_DAO_USE_DEFAULT_TYPE, csText, 0);
  161. }
  162. /////////////////////////////////////////////////////////////////////////////
  163. // CMainTable diagnostics
  164. #ifdef _DEBUG
  165. void CMainTable::AssertValid() const
  166. {
  167. CDaoRecordset::AssertValid();
  168. }
  169. void CMainTable::Dump(CDumpContext& dc) const
  170. {
  171. CDaoRecordset::Dump(dc);
  172. }
  173. #endif //_DEBUG