Leaked source code of windows server 2003
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.

285 lines
7.3 KiB

  1. // adsqryDoc.cpp : implementation of the CAdsqryDoc class
  2. //
  3. #include "stdafx.h"
  4. #include "adsqDoc.h"
  5. #include "newquery.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CAdsqryDoc
  13. IMPLEMENT_DYNCREATE(CAdsqryDoc, CDocument)
  14. BEGIN_MESSAGE_MAP(CAdsqryDoc, CDocument)
  15. //{{AFX_MSG_MAP(CAdsqryDoc)
  16. // NOTE - the ClassWizard will add and remove mapping macros here.
  17. // DO NOT EDIT what you see in these blocks of generated code!
  18. //}}AFX_MSG_MAP
  19. END_MESSAGE_MAP()
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CAdsqryDoc construction/destruction
  22. /***********************************************************
  23. Function:
  24. Arguments:
  25. Return:
  26. Purpose:
  27. Author(s):
  28. Revision:
  29. Date:
  30. ***********************************************************/
  31. CAdsqryDoc::CAdsqryDoc()
  32. {
  33. // TODO: add one-time construction code here
  34. m_pDataSource = NULL;
  35. }
  36. /***********************************************************
  37. Function:
  38. Arguments:
  39. Return:
  40. Purpose:
  41. Author(s):
  42. Revision:
  43. Date:
  44. ***********************************************************/
  45. CAdsqryDoc::~CAdsqryDoc()
  46. {
  47. if( m_pDataSource )
  48. {
  49. delete m_pDataSource;
  50. }
  51. }
  52. /***********************************************************
  53. Function:
  54. Arguments:
  55. Return:
  56. Purpose:
  57. Author(s):
  58. Revision:
  59. Date:
  60. ***********************************************************/
  61. BOOL CAdsqryDoc::OnNewDocument()
  62. {
  63. CNewQuery aNewQuery;
  64. CString strTitle;
  65. SEARCHPREF* pSearchPref;
  66. if (!CDocument::OnNewDocument())
  67. return FALSE;
  68. if( aNewQuery.DoModal( ) != IDOK )
  69. return FALSE;
  70. pSearchPref = (SEARCHPREF*) AllocADsMem( sizeof(SEARCHPREF) );
  71. if( NULL == pSearchPref )
  72. return FALSE;
  73. pSearchPref->bEncryptPassword = FALSE;
  74. pSearchPref->bUseSQL = FALSE;
  75. pSearchPref->nAsynchronous = -1;
  76. pSearchPref->nDerefAliases = -1;
  77. pSearchPref->nSizeLimit = -1;
  78. pSearchPref->nTimeLimit = -1;
  79. pSearchPref->nAttributesOnly = -1;
  80. pSearchPref->nScope = -1;
  81. pSearchPref->nTimeOut = -1;
  82. pSearchPref->nPageSize = -1;
  83. pSearchPref->nChaseReferrals = -1;
  84. _tcscpy( pSearchPref->szSource, aNewQuery.m_strSource );
  85. _tcscpy( pSearchPref->szQuery, aNewQuery.m_strQuery );
  86. _tcscpy( pSearchPref->szAttributes, aNewQuery.m_strAttributes );
  87. _tcscpy( pSearchPref->szScope, aNewQuery.m_strScope );
  88. _tcscpy( pSearchPref->szUserName, aNewQuery.m_strUser );
  89. _tcscpy( pSearchPref->szPassword, aNewQuery.m_strPassword );
  90. pSearchPref->bEncryptPassword = aNewQuery.m_bEncryptPassword;
  91. pSearchPref->bUseSQL = aNewQuery.m_bUseSQL;
  92. if( !GetSearchPreferences( pSearchPref ) )
  93. return FALSE;
  94. if( aNewQuery.m_bUseSearch )
  95. {
  96. m_pDataSource = new CADsSearchDataSource;
  97. }
  98. else
  99. {
  100. m_pDataSource = new CADsOleDBDataSource;
  101. }
  102. m_pDataSource->SetQueryParameters( pSearchPref );
  103. FreeADsMem( pSearchPref );
  104. strTitle = aNewQuery.m_strSource + _T(" ")+
  105. aNewQuery.m_strQuery + _T(" ")+
  106. aNewQuery.m_strAttributes;
  107. m_pDataSource->RunTheQuery( );
  108. SetTitle( strTitle );
  109. return TRUE;
  110. }
  111. /***********************************************************
  112. Function:
  113. Arguments:
  114. Return:
  115. Purpose:
  116. Author(s):
  117. Revision:
  118. Date:
  119. ***********************************************************/
  120. BOOL CAdsqryDoc::GetSearchPreferences( SEARCHPREF* pSearchPref )
  121. {
  122. CSearchPreferencesDlg aSearchPref;
  123. if( aSearchPref.DoModal( ) != IDOK )
  124. {
  125. return FALSE;
  126. }
  127. //***************************************************************************
  128. if( !aSearchPref.m_strAsynchronous.IsEmpty( ) )
  129. {
  130. if( !aSearchPref.m_strAsynchronous.CompareNoCase( _T("Yes") ) )
  131. {
  132. pSearchPref->nAsynchronous = 1;
  133. }
  134. else
  135. {
  136. pSearchPref->nAsynchronous = 0;
  137. }
  138. }
  139. //***************************************************************************
  140. if( !aSearchPref.m_strChaseReferrals.IsEmpty( ) )
  141. {
  142. if( !aSearchPref.m_strChaseReferrals.CompareNoCase( _T("Yes") ) )
  143. {
  144. pSearchPref->nChaseReferrals = 1;
  145. }
  146. else
  147. {
  148. pSearchPref->nChaseReferrals = 0;
  149. }
  150. }
  151. //***************************************************************************
  152. if( !aSearchPref.m_strAttributesOnly.IsEmpty( ) )
  153. {
  154. if( !aSearchPref.m_strAttributesOnly.CompareNoCase( _T("Yes") ) )
  155. {
  156. pSearchPref->nAttributesOnly = 1;
  157. }
  158. else
  159. {
  160. pSearchPref->nAttributesOnly = 0;
  161. }
  162. }
  163. //***************************************************************************
  164. if( !aSearchPref.m_strDerefAliases.IsEmpty( ) )
  165. {
  166. if( !aSearchPref.m_strDerefAliases.CompareNoCase( _T("Yes") ) )
  167. {
  168. pSearchPref->nDerefAliases = 1;
  169. }
  170. else
  171. {
  172. pSearchPref->nDerefAliases = 0;
  173. }
  174. }
  175. //***************************************************************************
  176. if( !aSearchPref.m_strTimeOut.IsEmpty( ) )
  177. {
  178. pSearchPref->nTimeOut = _ttoi( aSearchPref.m_strTimeOut.GetBuffer( 16 ) );
  179. }
  180. //***************************************************************************
  181. if( !aSearchPref.m_strTimeLimit.IsEmpty( ) )
  182. {
  183. pSearchPref->nTimeLimit = _ttoi( aSearchPref.m_strTimeLimit.GetBuffer( 16 ) );
  184. }
  185. //***************************************************************************
  186. if( !aSearchPref.m_strSizeLimit.IsEmpty( ) )
  187. {
  188. pSearchPref->nSizeLimit = _ttoi( aSearchPref.m_strSizeLimit.GetBuffer( 16 ) );
  189. }
  190. //***************************************************************************
  191. if( !aSearchPref.m_strPageSize.IsEmpty( ) )
  192. {
  193. pSearchPref->nPageSize = _ttoi( aSearchPref.m_strPageSize.GetBuffer( 16 ) );
  194. }
  195. //***************************************************************************
  196. if( !aSearchPref.m_strScope.IsEmpty( ) )
  197. {
  198. _tcscpy( pSearchPref->szScope, aSearchPref.m_strScope );
  199. }
  200. return TRUE;
  201. }
  202. /////////////////////////////////////////////////////////////////////////////
  203. // CAdsqryDoc serialization
  204. /***********************************************************
  205. Function:
  206. Arguments:
  207. Return:
  208. Purpose:
  209. Author(s):
  210. Revision:
  211. Date:
  212. ***********************************************************/
  213. void CAdsqryDoc::Serialize(CArchive& ar)
  214. {
  215. if (ar.IsStoring())
  216. {
  217. // TODO: add storing code here
  218. }
  219. else
  220. {
  221. // TODO: add loading code here
  222. }
  223. }
  224. /////////////////////////////////////////////////////////////////////////////
  225. // CAdsqryDoc diagnostics
  226. #ifdef _DEBUG
  227. void CAdsqryDoc::AssertValid() const
  228. {
  229. CDocument::AssertValid();
  230. }
  231. void CAdsqryDoc::Dump(CDumpContext& dc) const
  232. {
  233. CDocument::Dump(dc);
  234. }
  235. #endif //_DEBUG
  236. /////////////////////////////////////////////////////////////////////////////
  237. // CAdsqryDoc commands