GroupCombo.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // GroupCombo.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "cp_main.h"
  5. #include "GroupCombo.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CGroupCombo
  13. CGroupCombo::CGroupCombo()
  14. {
  15. m_lSkipGroupID = -1;
  16. }
  17. CGroupCombo::~CGroupCombo()
  18. {
  19. }
  20. BEGIN_MESSAGE_MAP(CGroupCombo, CComboBox)
  21. //{{AFX_MSG_MAP(CGroupCombo)
  22. // NOTE - the ClassWizard will add and remove mapping macros here.
  23. //}}AFX_MSG_MAP
  24. END_MESSAGE_MAP()
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CGroupCombo message handlers
  27. void CGroupCombo::FillCombo()
  28. {
  29. ResetContent();
  30. int nIndex = AddString(_T("--NONE--"));
  31. SetItemData(nIndex, 0);
  32. FillCombo(-1, 1);
  33. }
  34. void CGroupCombo::FillCombo(long lParentID, long lSpaces)
  35. {
  36. try
  37. {
  38. int nIndex;
  39. CString csSpaces;
  40. for(int i = 0; i < lSpaces; i++)
  41. {
  42. csSpaces += "---";
  43. }
  44. //First time through
  45. if(lSpaces > 0)
  46. {
  47. csSpaces += " ";
  48. //ResetContent();
  49. }
  50. lSpaces++;
  51. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, mText FROM Main WHERE bIsGroup = 1 AND lParentID = %d"), lParentID);
  52. if(q.eof() == false)
  53. {
  54. while(!q.eof())
  55. {
  56. if(q.getIntField(_T("lID")) != m_lSkipGroupID)
  57. {
  58. nIndex = AddString(csSpaces + q.getStringField(_T("mText")));
  59. SetItemData(nIndex, q.getIntField(_T("lID")));
  60. FillCombo(q.getIntField(_T("lID")), lSpaces);
  61. }
  62. q.nextRow();
  63. }
  64. }
  65. }
  66. CATCH_SQLITE_EXCEPTION
  67. }
  68. BOOL CGroupCombo::SetCurSelOnItemData(long lItemData)
  69. {
  70. long lCount = GetCount();
  71. for(int i = 0; i < lCount; i++)
  72. {
  73. if(GetItemData(i) == lItemData)
  74. {
  75. SetCurSel(i);
  76. return TRUE;
  77. }
  78. }
  79. SetCurSel(-1);
  80. return FALSE;
  81. }
  82. int CGroupCombo::GetItemDataFromCursel()
  83. {
  84. int nCursel = GetCurSel();
  85. return (int)GetItemData(nCursel);
  86. }