Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

253 lines
6.0 KiB

  1. // DBTestDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "DBTest.h"
  5. #include "DBTestDlg.h"
  6. #import "\bin\McsVarSetMin.tlb" no_namespace
  7. #import "..\DBManager.tlb" no_namespace
  8. #import "c:\program files\Common Files\System\ADO\msado21.tlb" no_namespace rename("EOF", "EndOfFile")
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CAboutDlg dialog used for App About
  16. class CAboutDlg : public CDialog
  17. {
  18. public:
  19. CAboutDlg();
  20. // Dialog Data
  21. //{{AFX_DATA(CAboutDlg)
  22. enum { IDD = IDD_ABOUTBOX };
  23. //}}AFX_DATA
  24. // ClassWizard generated virtual function overrides
  25. //{{AFX_VIRTUAL(CAboutDlg)
  26. protected:
  27. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  28. //}}AFX_VIRTUAL
  29. // Implementation
  30. protected:
  31. //{{AFX_MSG(CAboutDlg)
  32. //}}AFX_MSG
  33. DECLARE_MESSAGE_MAP()
  34. };
  35. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  36. {
  37. //{{AFX_DATA_INIT(CAboutDlg)
  38. //}}AFX_DATA_INIT
  39. }
  40. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  41. {
  42. CDialog::DoDataExchange(pDX);
  43. //{{AFX_DATA_MAP(CAboutDlg)
  44. //}}AFX_DATA_MAP
  45. }
  46. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  47. //{{AFX_MSG_MAP(CAboutDlg)
  48. // No message handlers
  49. //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CDBTestDlg dialog
  53. CDBTestDlg::CDBTestDlg(CWnd* pParent /*=NULL*/)
  54. : CDialog(CDBTestDlg::IDD, pParent)
  55. {
  56. //{{AFX_DATA_INIT(CDBTestDlg)
  57. // NOTE: the ClassWizard will add member initialization here
  58. //}}AFX_DATA_INIT
  59. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  60. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  61. }
  62. void CDBTestDlg::DoDataExchange(CDataExchange* pDX)
  63. {
  64. CDialog::DoDataExchange(pDX);
  65. //{{AFX_DATA_MAP(CDBTestDlg)
  66. // NOTE: the ClassWizard will add DDX and DDV calls here
  67. //}}AFX_DATA_MAP
  68. }
  69. BEGIN_MESSAGE_MAP(CDBTestDlg, CDialog)
  70. //{{AFX_MSG_MAP(CDBTestDlg)
  71. ON_WM_SYSCOMMAND()
  72. ON_WM_PAINT()
  73. ON_WM_QUERYDRAGICON()
  74. //}}AFX_MSG_MAP
  75. END_MESSAGE_MAP()
  76. /////////////////////////////////////////////////////////////////////////////
  77. // CDBTestDlg message handlers
  78. BOOL CDBTestDlg::OnInitDialog()
  79. {
  80. CDialog::OnInitDialog();
  81. // Add "About..." menu item to system menu.
  82. // IDM_ABOUTBOX must be in the system command range.
  83. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  84. ASSERT(IDM_ABOUTBOX < 0xF000);
  85. CMenu* pSysMenu = GetSystemMenu(FALSE);
  86. if (pSysMenu != NULL)
  87. {
  88. CString strAboutMenu;
  89. strAboutMenu.LoadString(IDS_ABOUTBOX);
  90. if (!strAboutMenu.IsEmpty())
  91. {
  92. pSysMenu->AppendMenu(MF_SEPARATOR);
  93. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  94. }
  95. }
  96. // Set the icon for this dialog. The framework does this automatically
  97. // when the application's main window is not a dialog
  98. SetIcon(m_hIcon, TRUE); // Set big icon
  99. SetIcon(m_hIcon, FALSE); // Set small icon
  100. // TODO: Add extra initialization here
  101. return TRUE; // return TRUE unless you set the focus to a control
  102. }
  103. void CDBTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
  104. {
  105. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  106. {
  107. CAboutDlg dlgAbout;
  108. dlgAbout.DoModal();
  109. }
  110. else
  111. {
  112. CDialog::OnSysCommand(nID, lParam);
  113. }
  114. }
  115. // If you add a minimize button to your dialog, you will need the code below
  116. // to draw the icon. For MFC applications using the document/view model,
  117. // this is automatically done for you by the framework.
  118. void CDBTestDlg::OnPaint()
  119. {
  120. if (IsIconic())
  121. {
  122. CPaintDC dc(this); // device context for painting
  123. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  124. // Center icon in client rectangle
  125. int cxIcon = GetSystemMetrics(SM_CXICON);
  126. int cyIcon = GetSystemMetrics(SM_CYICON);
  127. CRect rect;
  128. GetClientRect(&rect);
  129. int x = (rect.Width() - cxIcon + 1) / 2;
  130. int y = (rect.Height() - cyIcon + 1) / 2;
  131. // Draw the icon
  132. dc.DrawIcon(x, y, m_hIcon);
  133. }
  134. else
  135. {
  136. CDialog::OnPaint();
  137. }
  138. }
  139. // The system calls this to obtain the cursor to display while the user drags
  140. // the minimized window.
  141. HCURSOR CDBTestDlg::OnQueryDragIcon()
  142. {
  143. return (HCURSOR) m_hIcon;
  144. }
  145. void CDBTestDlg::OnOK()
  146. {
  147. IIManageDBPtr pDb(__uuidof(IManageDB));
  148. IVarSetPtr pVS(__uuidof(VarSet));
  149. _variant_t var;
  150. var = L"This should say hello";
  151. pVS->put(L"Hello", var);
  152. var = L"****************";
  153. pVS->put(L"Hello.1", var);
  154. var.vt = VT_UI4;
  155. var.lVal = 25000;
  156. pVS->put(L"Number", var);
  157. var.vt = VT_I4;
  158. var.lVal = -8438;
  159. pVS->put(L"NegInt", var);
  160. try
  161. {
  162. // Get IUnknown pointer to the Varset
  163. IUnknown * pUnk;
  164. pVS->QueryInterface(IID_IUnknown, (void**) &pUnk);
  165. // Tell DB to save the settings.
  166. // pDb->SaveSettings(pUnk);
  167. long lVal = 1;
  168. pDb->GetNextActionID(&lVal);
  169. pDb->SetActionHistory(lVal, pUnk);
  170. // Clear the varset
  171. pVS->Clear();
  172. // Save a migrated object.
  173. pVS->put(L"SourceDomain", L"SDomain");
  174. pVS->put(L"TargetDomain", L"TDomain");
  175. pVS->put(L"SourceAdsPath", L"CN=Sham,OU=ShamTest");
  176. pVS->put(L"TargetAdsPath", L"CN=Sham,OU=More");
  177. var.vt = VT_UI1;
  178. var.lVal = 10;
  179. pVS->put(L"status", var);
  180. pVS->put(L"SourceSamName", L"Sham");
  181. pVS->put(L"TargetSamName", L"Sham");
  182. pVS->put(L"Type", L"user");
  183. pVS->put(L"GUID", L"10293092-290039-21290-10293");
  184. pDb->SaveMigratedObject(lVal, pUnk);
  185. // Get the Varset from DB
  186. // pDb->GetSettings(&pUnk);
  187. pDb->GetActionHistory(lVal, &pUnk);
  188. pDb->GetMigratedObjects(lVal, &pUnk);
  189. //IUnknown * pXL;
  190. _RecordsetPtr p;
  191. //p->QueryInterface(IID_IUnknown, (void *) &pXL);
  192. p = pDb->GetRSForReport(L"MigratedObjects");
  193. // Dump the varset to check its content.
  194. pUnk->Release();
  195. while ( !p->EndOfFile )
  196. {
  197. var = p->Fields->GetItem(L"ActionID")->Value;
  198. p->MoveNext();
  199. }
  200. pVS->DumpToFile(L"C:\\settings.txt");
  201. }
  202. catch ( _com_error &e )
  203. {
  204. AfxMessageBox(e.ErrorMessage() + e.Description());
  205. }
  206. CDialog::OnOK();
  207. }