MainTable.cpp 4.0 KB

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