GroupCombo.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. }
  16. CGroupCombo::~CGroupCombo()
  17. {
  18. }
  19. BEGIN_MESSAGE_MAP(CGroupCombo, CComboBox)
  20. //{{AFX_MSG_MAP(CGroupCombo)
  21. // NOTE - the ClassWizard will add and remove mapping macros here.
  22. //}}AFX_MSG_MAP
  23. END_MESSAGE_MAP()
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CGroupCombo message handlers
  26. void CGroupCombo::FillCombo()
  27. {
  28. ResetContent();
  29. int nIndex = AddString("--NONE--");
  30. SetItemData(nIndex, 0);
  31. FillCombo(0, 0);
  32. }
  33. void CGroupCombo::FillCombo(long lParentID, long lSpaces)
  34. {
  35. try
  36. {
  37. int nIndex;
  38. CMainTable recset;
  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. recset.m_strFilter.Format("bIsGroup = TRUE AND lParentID = %d", lParentID);
  52. recset.Open();
  53. if(recset.IsEOF() == FALSE)
  54. {
  55. while(!recset.IsEOF())
  56. {
  57. nIndex = AddString(csSpaces + recset.m_strText);
  58. SetItemData(nIndex, recset.m_lID);
  59. FillCombo(recset.m_lID, lSpaces);
  60. recset.MoveNext();
  61. }
  62. }
  63. }
  64. catch(CDaoException* e)
  65. {
  66. ASSERT(FALSE);
  67. e->Delete();
  68. return;
  69. }
  70. }
  71. BOOL CGroupCombo::SetCurSelOnItemData(long lItemData)
  72. {
  73. long lCount = GetCount();
  74. for(int i = 0; i < lCount; i++)
  75. {
  76. if(GetItemData(i) == lItemData)
  77. {
  78. SetCurSel(i);
  79. return TRUE;
  80. }
  81. }
  82. SetCurSel(-1);
  83. return FALSE;
  84. }
  85. int CGroupCombo::GetItemDataFromCursel()
  86. {
  87. int nCursel = GetCurSel();
  88. return (int)GetItemData(nCursel);
  89. }