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.

914 lines
28 KiB

  1. /*++
  2. Copyright (C) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. fileprop.cpp
  5. Abstract:
  6. Implementation of the files property page.
  7. --*/
  8. #include "stdafx.h"
  9. #include "smlogs.h"
  10. #include "smcfgmsg.h"
  11. #include "smlogqry.h"
  12. #include "FileLogs.h"
  13. #include "sqlprop.h"
  14. #include "fileprop.h"
  15. #include "globals.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. USE_HANDLE_MACROS("SMLOGCFG(fileprop.cpp)");
  22. static ULONG
  23. s_aulHelpIds[] =
  24. {
  25. IDC_FILES_COMMENT_EDIT, IDH_FILES_COMMENT_EDIT,
  26. IDC_FILES_LOG_TYPE_COMBO, IDH_FILES_LOG_TYPE_COMBO,
  27. IDC_CFG_BTN, IDH_CFG_BTN,
  28. IDC_FILES_AUTO_SUFFIX_CHK, IDH_FILES_AUTO_SUFFIX_CHK,
  29. IDC_FILES_SUFFIX_COMBO, IDH_FILES_SUFFIX_COMBO,
  30. IDC_FILES_FIRST_SERIAL_EDIT,IDH_FILES_FIRST_SERIAL_EDIT,
  31. IDC_FILES_SAMPLE_DISPLAY, IDH_FILES_SAMPLE_DISPLAY,
  32. IDC_FILES_OVERWRITE_CHK, IDH_FILES_OVERWRITE_CHK,
  33. 0,0
  34. };
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CFilesProperty property page
  37. IMPLEMENT_DYNCREATE(CFilesProperty, CSmPropertyPage)
  38. CFilesProperty::CFilesProperty(MMC_COOKIE mmcCookie, LONG_PTR hConsole)
  39. : CSmPropertyPage ( CFilesProperty::IDD, hConsole )
  40. {
  41. // ::OutputDebugStringA("\nCFilesProperty::CFilesProperty");
  42. // save pointers from arg list
  43. m_pLogQuery = reinterpret_cast <CSmLogQuery *>(mmcCookie);
  44. m_dwSuffixValue = 0;
  45. m_dwLogFileTypeValue = 0;
  46. m_dwAppendMode = 0;
  47. m_dwMaxSizeInternal = 0;
  48. m_dwSubDlgFocusCtrl = 0;
  49. // EnableAutomation();
  50. //{{AFX_DATA_INIT(CFilesProperty)
  51. m_iLogFileType = -1;
  52. m_dwSuffix = -1;
  53. m_dwSerialNumber = 1;
  54. m_bAutoNameSuffix = FALSE;
  55. m_bOverWriteFile = FALSE;
  56. //}}AFX_DATA_INIT
  57. }
  58. CFilesProperty::CFilesProperty() : CSmPropertyPage ( CFilesProperty::IDD )
  59. {
  60. ASSERT (FALSE); // only the constructor with args above should be used
  61. EnableAutomation();
  62. m_dwSuffixValue = 0;
  63. m_dwAppendMode = 0;
  64. m_dwMaxSizeInternal = 0;
  65. m_dwSubDlgFocusCtrl = 0;
  66. // //{{AFX_DATA_INIT(CFilesProperty)
  67. m_iLogFileType = -1;
  68. m_dwSuffix = -1;
  69. m_dwSerialNumber = 1;
  70. m_bAutoNameSuffix = FALSE;
  71. m_bOverWriteFile = FALSE;
  72. // //}}AFX_DATA_INIT
  73. // CString variables are empty on construction.
  74. }
  75. CFilesProperty::~CFilesProperty()
  76. {
  77. // ::OutputDebugStringA("\nCFilesProperty::~CFilesProperty");
  78. }
  79. void CFilesProperty::OnFinalRelease()
  80. {
  81. // When the last reference for an automation object is released
  82. // OnFinalRelease is called. The base class will automatically
  83. // deletes the object. Add additional cleanup required for your
  84. // object before calling the base class.
  85. CPropertyPage::OnFinalRelease();
  86. }
  87. void CFilesProperty::DoDataExchange(CDataExchange* pDX)
  88. {
  89. CString strTemp;
  90. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  91. CPropertyPage::DoDataExchange(pDX);
  92. //{{AFX_DATA_MAP(CFilesProperty)
  93. DDX_Text(pDX, IDC_FILES_COMMENT_EDIT, m_strCommentText);
  94. DDV_MaxChars(pDX, m_strCommentText, MAX_PATH);
  95. DDX_CBIndex(pDX, IDC_FILES_LOG_TYPE_COMBO, m_iLogFileType);
  96. DDX_CBIndex(pDX, IDC_FILES_SUFFIX_COMBO, m_dwSuffix);
  97. DDX_Check(pDX, IDC_FILES_AUTO_SUFFIX_CHK, m_bAutoNameSuffix);
  98. DDX_Check(pDX, IDC_FILES_OVERWRITE_CHK, m_bOverWriteFile);
  99. ValidateTextEdit(pDX, IDC_FILES_FIRST_SERIAL_EDIT, 6, (DWORD *) & m_dwSerialNumber, eMinFirstSerial, eMaxFirstSerial);
  100. //}}AFX_DATA_MAP
  101. if ( pDX->m_bSaveAndValidate ) {
  102. m_dwLogFileTypeValue = (DWORD)((CComboBox *)GetDlgItem(IDC_FILES_LOG_TYPE_COMBO))->GetItemData(m_iLogFileType);
  103. if ( m_bAutoNameSuffix ) {
  104. m_dwSuffixValue = (DWORD)((CComboBox *)GetDlgItem(IDC_FILES_SUFFIX_COMBO))->GetItemData(m_dwSuffix);
  105. }
  106. }
  107. }
  108. BEGIN_MESSAGE_MAP(CFilesProperty, CSmPropertyPage)
  109. //{{AFX_MSG_MAP(CFilesProperty)
  110. ON_WM_DESTROY()
  111. ON_BN_CLICKED(IDC_FILES_AUTO_SUFFIX_CHK, OnAutoSuffixChk)
  112. ON_BN_CLICKED(IDC_FILES_OVERWRITE_CHK, OnOverWriteChk)
  113. ON_EN_CHANGE(IDC_FILES_COMMENT_EDIT, OnChangeFilesCommentEdit)
  114. ON_EN_KILLFOCUS(IDC_FILES_COMMENT_EDIT, OnKillfocusFilesCommentEdit)
  115. ON_EN_CHANGE(IDC_FILES_FIRST_SERIAL_EDIT, OnChangeFilesFirstSerialEdit)
  116. ON_EN_KILLFOCUS(IDC_FILES_FIRST_SERIAL_EDIT, OnKillfocusFirstSerialEdit)
  117. ON_CBN_SELENDOK(IDC_FILES_LOG_TYPE_COMBO, OnSelendokFilesLogFileTypeCombo)
  118. ON_CBN_SELENDOK(IDC_FILES_SUFFIX_COMBO, OnSelendokFilesSuffixCombo)
  119. ON_CBN_KILLFOCUS(IDC_FILES_SUFFIX_COMBO, OnKillfocusFilesSuffixCombo)
  120. ON_CBN_KILLFOCUS(IDC_FILES_LOG_TYPE_COMBO, OnKillfocusFilesLogFileTypeCombo)
  121. ON_BN_CLICKED(IDC_CFG_BTN, OnCfgBtn)
  122. //}}AFX_MSG_MAP
  123. END_MESSAGE_MAP()
  124. BEGIN_DISPATCH_MAP(CFilesProperty, CSmPropertyPage)
  125. //{{AFX_DISPATCH_MAP(CFilesProperty)
  126. // NOTE - the ClassWizard will add and remove mapping macros here.
  127. //}}AFX_DISPATCH_MAP
  128. END_DISPATCH_MAP()
  129. // Note: we add support for IID_IFilesProperty to support typesafe binding
  130. // from VBA. This IID must match the GUID that is attached to the
  131. // dispinterface in the .ODL file.
  132. // {65154EAB-BDBE-11D1-BF99-00C04F94A83A}
  133. static const IID IID_IFilesProperty =
  134. { 0x65154eab, 0xbdbe, 0x11d1, { 0xbf, 0x99, 0x0, 0xc0, 0x4f, 0x94, 0xa8, 0x3a } };
  135. BEGIN_INTERFACE_MAP(CFilesProperty, CSmPropertyPage)
  136. INTERFACE_PART(CFilesProperty, IID_IFilesProperty, Dispatch)
  137. END_INTERFACE_MAP()
  138. void
  139. CFilesProperty::EnableSerialNumber( void )
  140. {
  141. BOOL bEnable = ( SLF_NAME_NNNNNN == m_dwSuffixValue );
  142. if ( bEnable )
  143. bEnable = m_bAutoNameSuffix;
  144. GetDlgItem(IDC_FILES_FIRST_SERIAL_CAPTION)->EnableWindow( bEnable );
  145. GetDlgItem(IDC_FILES_FIRST_SERIAL_EDIT)->EnableWindow( bEnable );
  146. }
  147. BOOL
  148. CFilesProperty::UpdateSampleFileName( void )
  149. {
  150. CString strCompositeName;
  151. BOOL bIsValid = TRUE;
  152. DWORD dwLocalSuffixValue = SLF_NAME_NONE;
  153. ResourceStateManager rsm;
  154. if (m_bAutoNameSuffix) {
  155. dwLocalSuffixValue = m_dwSuffixValue;
  156. }
  157. CreateSampleFileName (
  158. m_pLogQuery->GetLogName(),
  159. m_pLogQuery->GetLogService()->GetMachineName(),
  160. m_strFolderName,
  161. m_strFileBaseName,
  162. m_strSqlName,
  163. dwLocalSuffixValue,
  164. m_dwLogFileTypeValue,
  165. m_dwSerialNumber,
  166. strCompositeName );
  167. m_strSampleFileName = strCompositeName;
  168. // Or call UpdateData ( FALSE );
  169. SetDlgItemText (IDC_FILES_SAMPLE_DISPLAY, strCompositeName);
  170. // Clear the selection
  171. ((CEdit*)GetDlgItem( IDC_FILES_SAMPLE_DISPLAY ))->SetSel ( -1, FALSE );
  172. if ( MAX_PATH <= m_strSampleFileName.GetLength() ) {
  173. bIsValid = FALSE;
  174. }
  175. return bIsValid;
  176. }
  177. void
  178. CFilesProperty::HandleLogTypeChange()
  179. {
  180. int nSel;
  181. nSel = ((CComboBox *)GetDlgItem(IDC_FILES_LOG_TYPE_COMBO))->GetCurSel();
  182. // nSel != m_iLogFileType determines data change.
  183. if ((nSel != LB_ERR) && (nSel != m_iLogFileType)) {
  184. UpdateData( TRUE );
  185. if ( SLF_BIN_FILE != m_dwLogFileTypeValue
  186. && SLF_SEQ_TRACE_FILE != m_dwLogFileTypeValue )
  187. {
  188. GetDlgItem(IDC_FILES_OVERWRITE_CHK)->EnableWindow(FALSE);
  189. } else {
  190. GetDlgItem(IDC_FILES_OVERWRITE_CHK)->EnableWindow( TRUE );
  191. }
  192. OnOverWriteChk();
  193. EnableSerialNumber();
  194. UpdateSampleFileName();
  195. SetModifiedPage(TRUE);
  196. }
  197. }
  198. BOOL
  199. CFilesProperty::IsValidLocalData()
  200. {
  201. BOOL bIsValid = TRUE;
  202. CString strTest;
  203. eValueRange eMaxFileSize;
  204. ResourceStateManager rsm;
  205. // assumes UpdateData has been called
  206. if ( !UpdateSampleFileName() ) {
  207. CString strMessage;
  208. strMessage.LoadString ( IDS_FILE_ERR_NAMETOOLONG );
  209. MessageBox ( strMessage, m_pLogQuery->GetLogName(), MB_OK | MB_ICONERROR);
  210. bIsValid = FALSE;
  211. m_dwSubDlgFocusCtrl = IDC_FILES_FILENAME_EDIT;
  212. OnCfgBtn();
  213. }
  214. if ( bIsValid ) {
  215. if ( m_strFolderName.IsEmpty() && (SLF_SQL_LOG != m_dwLogFileTypeValue)) {
  216. CString strMessage;
  217. strMessage.LoadString ( IDS_FILE_ERR_NOFOLDERNAME );
  218. MessageBox ( strMessage, m_pLogQuery->GetLogName(), MB_OK | MB_ICONERROR);
  219. bIsValid = FALSE;
  220. m_dwSubDlgFocusCtrl = IDC_FILES_FOLDER_EDIT;
  221. OnCfgBtn();
  222. }
  223. }
  224. if ( bIsValid ) {
  225. if ( SLF_SQL_LOG != m_dwLogFileTypeValue ) {
  226. if ( m_strFileBaseName.IsEmpty() && !m_bAutoNameSuffix ) {
  227. CString strMessage;
  228. strMessage.LoadString ( IDS_FILE_ERR_NOFILENAME );
  229. MessageBox ( strMessage, m_pLogQuery->GetLogName(), MB_OK | MB_ICONERROR);
  230. bIsValid = FALSE;
  231. m_dwSubDlgFocusCtrl = IDC_FILES_FILENAME_EDIT;
  232. OnCfgBtn();
  233. }
  234. if ( bIsValid ) {
  235. if ( !FileNameIsValid ( &m_strFileBaseName ) ) {
  236. CString strMessage;
  237. strMessage.LoadString (IDS_ERRMSG_INVALIDCHAR);
  238. MessageBox( strMessage, m_pLogQuery->GetLogName(), MB_OK| MB_ICONERROR );
  239. bIsValid = FALSE;
  240. m_dwSubDlgFocusCtrl = IDC_FILES_FILENAME_EDIT;
  241. OnCfgBtn();
  242. }
  243. }
  244. } else {
  245. ExtractDSN ( strTest );
  246. if ( strTest.IsEmpty() ) {
  247. CString strMessage;
  248. strMessage.LoadString ( IDS_SQL_ERR_NODSN );
  249. MessageBox ( strMessage, m_pLogQuery->GetLogName(), MB_OK | MB_ICONERROR);
  250. bIsValid = FALSE;
  251. m_dwSubDlgFocusCtrl = IDC_SQL_DSN_COMBO;
  252. OnCfgBtn();
  253. }
  254. if ( bIsValid ) {
  255. ExtractLogSetName ( strTest );
  256. if ( strTest.IsEmpty() && !m_bAutoNameSuffix ) {
  257. CString strMessage;
  258. strMessage.LoadString ( IDS_SQL_ERR_NOLOGSETNAME );
  259. MessageBox ( strMessage, m_pLogQuery->GetLogName(), MB_OK | MB_ICONERROR);
  260. bIsValid = FALSE;
  261. m_dwSubDlgFocusCtrl = IDC_SQL_LOG_SET_EDIT;
  262. OnCfgBtn();
  263. } else if ( !FileNameIsValid ( &strTest ) ){
  264. CString strMessage;
  265. strMessage.LoadString (IDS_ERRMSG_INVALIDCHAR);
  266. MessageBox( strMessage, m_pLogQuery->GetLogName(), MB_OK| MB_ICONERROR );
  267. bIsValid = FALSE;
  268. m_dwSubDlgFocusCtrl = IDC_SQL_LOG_SET_EDIT;
  269. OnCfgBtn();
  270. }
  271. }
  272. }
  273. }
  274. // Validate max log file size based on log file type
  275. if (bIsValid)
  276. {
  277. if ( SLQ_DISK_MAX_SIZE != m_dwMaxSizeInternal ) {
  278. if ( SLF_BIN_FILE == m_dwLogFileTypeValue ) {
  279. eMaxFileSize = eMaxCtrSeqBinFileLimit;
  280. } else if ( SLF_SEQ_TRACE_FILE == m_dwLogFileTypeValue ) {
  281. eMaxFileSize = eMaxTrcSeqBinFileLimit;
  282. } else if ( SLF_SQL_LOG == m_dwLogFileTypeValue ) {
  283. eMaxFileSize = eMaxSqlRecordsLimit;
  284. } else {
  285. eMaxFileSize = eMaxFileLimit;
  286. }
  287. bIsValid = ValidateDWordInterval(IDC_CFG_BTN,
  288. m_pLogQuery->GetLogName(),
  289. (long) m_dwMaxSizeInternal,
  290. eMinFileLimit,
  291. eMaxFileSize);
  292. if ( !bIsValid ) {
  293. if ( SLF_SQL_LOG == m_dwLogFileTypeValue ) {
  294. m_dwSubDlgFocusCtrl = IDC_SQL_SIZE_LIMIT_EDIT;
  295. } else {
  296. m_dwSubDlgFocusCtrl = IDC_FILES_SIZE_LIMIT_EDIT;
  297. }
  298. OnCfgBtn();
  299. }
  300. }
  301. }
  302. if (bIsValid)
  303. {
  304. bIsValid = ValidateDWordInterval(IDC_FILES_FIRST_SERIAL_EDIT,
  305. m_pLogQuery->GetLogName(),
  306. (long) m_dwSerialNumber,
  307. eMinFirstSerial,
  308. eMaxFirstSerial);
  309. }
  310. return bIsValid;
  311. }
  312. /////////////////////////////////////////////////////////////////////////////
  313. // CFilesProperty message handlers
  314. void
  315. CFilesProperty::OnCancel()
  316. {
  317. m_pLogQuery->SyncPropPageSharedData(); // Clear the memory shared between property pages.
  318. }
  319. BOOL
  320. CFilesProperty::OnApply()
  321. {
  322. BOOL bContinue = TRUE;
  323. ResourceStateManager rsm;
  324. // load data from dialog
  325. bContinue = UpdateData (TRUE);
  326. if ( bContinue ) {
  327. bContinue = IsValidData(m_pLogQuery, VALIDATE_APPLY );
  328. }
  329. if ( bContinue ) {
  330. bContinue = SampleTimeIsLessThanSessionTime ( m_pLogQuery );
  331. }
  332. // pass data to the query object
  333. if ( bContinue ) {
  334. bContinue = UpdateSharedData( TRUE );
  335. }
  336. if ( bContinue ) {
  337. m_pLogQuery->SetLogComment(m_strCommentText);
  338. m_pLogQuery->SetFileNameParts(m_strFolderName, m_strFileBaseName);
  339. m_pLogQuery->SetSqlName(m_strSqlName);
  340. if ( TRUE == m_bAutoNameSuffix ) {
  341. m_pLogQuery->SetFileNameAutoFormat(m_dwSuffixValue);
  342. } else {
  343. m_pLogQuery->SetFileNameAutoFormat(SLF_NAME_NONE);
  344. }
  345. m_pLogQuery->SetFileSerialNumber( m_dwSerialNumber );
  346. m_pLogQuery->SetMaxSize(m_dwMaxSizeInternal);
  347. // Save property page shared data.
  348. m_pLogQuery->UpdatePropPageSharedData();
  349. if ( LOWORD(m_dwLogFileTypeValue) == SLF_BIN_FILE
  350. || SLF_SEQ_TRACE_FILE == LOWORD(m_dwLogFileTypeValue) ) {
  351. if ( m_bOverWriteFile ) {
  352. m_pLogQuery->SetDataStoreAppendMode( SLF_DATA_STORE_OVERWRITE );
  353. } else {
  354. m_pLogQuery->SetDataStoreAppendMode( SLF_DATA_STORE_APPEND );
  355. }
  356. } else {
  357. if ( SLF_SQL_LOG == LOWORD(m_dwLogFileTypeValue) ) {
  358. m_pLogQuery->SetDataStoreAppendMode ( SLF_DATA_STORE_APPEND );
  359. } else {
  360. m_pLogQuery->SetDataStoreAppendMode ( SLF_DATA_STORE_OVERWRITE );
  361. }
  362. }
  363. m_pLogQuery->SetLogFileType ( m_dwLogFileTypeValue );
  364. if ( bContinue ) {
  365. bContinue = Apply(m_pLogQuery);
  366. }
  367. bContinue = CPropertyPage::OnApply();
  368. // Sync the service with changes.
  369. if ( bContinue ) {
  370. bContinue = UpdateService( m_pLogQuery, FALSE );
  371. if ( bContinue ) {
  372. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  373. CWaitCursor WaitCursor;
  374. // Service might have changed the serial number, so sync it.
  375. // Don't sync data that is modified by other pages.
  376. m_pLogQuery->SyncSerialNumberWithRegistry();
  377. m_dwSerialNumber = m_pLogQuery->GetFileSerialNumber();
  378. }
  379. }
  380. }
  381. return bContinue;
  382. }
  383. BOOL CFilesProperty::OnInitDialog()
  384. {
  385. UINT nIndex;
  386. CString strComboBoxString;
  387. CComboBox *pCombo;
  388. UINT nResult;
  389. DWORD dwEntries;
  390. PCOMBO_BOX_DATA_MAP pCbData;
  391. ResourceStateManager rsm;
  392. m_strLogName = m_pLogQuery->GetLogName();
  393. m_pLogQuery->GetLogComment ( m_strCommentText );
  394. // Why get max size internal when it is in the shared data?
  395. // This should not be a problem, because only this page
  396. // modifies the value, and GetMaxSize is only called in OnInitDialog.
  397. m_dwMaxSizeInternal = m_pLogQuery->GetMaxSize();
  398. // load log file type combo box
  399. m_pLogQuery->GetLogFileType ( m_dwLogFileTypeValue );
  400. m_pLogQuery->GetDataStoreAppendMode ( dwEntries );
  401. m_bOverWriteFile = ( SLF_DATA_STORE_OVERWRITE == dwEntries );
  402. if ( SLQ_TRACE_LOG == m_pLogQuery->GetLogType() ) {
  403. dwEntries = dwTraceFileTypeComboEntries;
  404. pCbData = (PCOMBO_BOX_DATA_MAP)&TraceFileTypeCombo[0];
  405. } else {
  406. dwEntries = dwFileTypeComboEntries;
  407. pCbData = (PCOMBO_BOX_DATA_MAP)&FileTypeCombo[0];
  408. }
  409. pCombo = (CComboBox *)GetDlgItem(IDC_FILES_LOG_TYPE_COMBO);
  410. pCombo->ResetContent();
  411. for (nIndex = 0; nIndex < dwEntries; nIndex++) {
  412. strComboBoxString.LoadString( pCbData[nIndex].nResId );
  413. nResult = pCombo->InsertString (nIndex, (LPCWSTR)strComboBoxString);
  414. ASSERT (nResult != CB_ERR);
  415. nResult = pCombo->SetItemData (nIndex, (DWORD)pCbData[nIndex].nData);
  416. ASSERT (nResult != CB_ERR);
  417. // set log type in combo box here
  418. if (m_dwLogFileTypeValue == (int)(pCbData[nIndex].nData)) {
  419. m_iLogFileType = nIndex;
  420. nResult = pCombo->SetCurSel(nIndex);
  421. ASSERT (nResult != CB_ERR);
  422. if ( SLF_BIN_FILE != m_dwLogFileTypeValue
  423. && SLF_SEQ_TRACE_FILE != m_dwLogFileTypeValue )
  424. {
  425. GetDlgItem(IDC_FILES_OVERWRITE_CHK)->EnableWindow(FALSE);
  426. } else {
  427. GetDlgItem(IDC_FILES_OVERWRITE_CHK)->EnableWindow( TRUE );
  428. }
  429. }
  430. }
  431. m_pLogQuery->GetFileNameParts ( m_strFolderName, m_strFileBaseName );
  432. m_pLogQuery->GetSqlName ( m_strSqlName );
  433. m_dwSerialNumber = m_pLogQuery->GetFileSerialNumber();
  434. // load the filename suffix combo box here
  435. m_dwSuffixValue = m_pLogQuery->GetFileNameAutoFormat();
  436. pCombo = (CComboBox *)GetDlgItem(IDC_FILES_SUFFIX_COMBO);
  437. pCombo->ResetContent();
  438. for (nIndex = 0; nIndex < dwFileNameSuffixComboEntries; nIndex++) {
  439. strComboBoxString.LoadString ( FileNameSuffixCombo[nIndex].nResId );
  440. nResult = pCombo->InsertString (nIndex, (LPCWSTR)strComboBoxString);
  441. ASSERT (nResult != CB_ERR);
  442. pCombo->SetItemData (nIndex, (DWORD)FileNameSuffixCombo[nIndex].nData);
  443. ASSERT (nResult != CB_ERR);
  444. // set the correct entry in the combo box here
  445. if (m_dwSuffixValue == (int)(FileNameSuffixCombo[nIndex].nData)) {
  446. m_dwSuffix = nIndex;
  447. nResult = pCombo->SetCurSel(nIndex);
  448. ASSERT (nResult != CB_ERR);
  449. }
  450. if ( SLF_NAME_NNNNNN == (int)(FileNameSuffixCombo[nIndex].nData ) ) {
  451. m_dwSuffixIndexNNNNNN = nIndex;
  452. }
  453. }
  454. if ( SLF_NAME_NONE == m_dwSuffixValue ) {
  455. // then the combo box will not have been selected so:
  456. pCombo->SetCurSel(m_dwSuffixIndexNNNNNN);
  457. // disable
  458. pCombo->EnableWindow(FALSE);
  459. // and clear the check box
  460. m_bAutoNameSuffix = FALSE;
  461. } else {
  462. m_bAutoNameSuffix = TRUE;
  463. }
  464. // set the check box in UpdateData ( FALSE );
  465. // update the dialog box
  466. CSmPropertyPage::OnInitDialog();
  467. SetHelpIds ( (DWORD*)&s_aulHelpIds );
  468. EnableSerialNumber();
  469. UpdateSampleFileName();
  470. SetModifiedPage( FALSE );
  471. return TRUE; // return TRUE unless you set the focus to a control
  472. // EXCEPTION: OCX Property Pages should return FALSE
  473. }
  474. void
  475. CFilesProperty::OnAutoSuffixChk()
  476. {
  477. UpdateData( TRUE );
  478. // enable the suffix combo window based on the state of the button
  479. GetDlgItem(IDC_FILES_SUFFIX_COMBO)->EnableWindow (m_bAutoNameSuffix);
  480. if (m_bAutoNameSuffix) {
  481. if ( SLF_NAME_NONE == m_dwSuffixValue ) {
  482. // then initialize a new default
  483. // select the default serial numbering
  484. ((CComboBox *)(GetDlgItem(IDC_FILES_SUFFIX_COMBO)))->SetCurSel( m_dwSuffixIndexNNNNNN );
  485. m_dwSuffixValue = SLF_NAME_NNNNNN;
  486. }
  487. }
  488. EnableSerialNumber();
  489. UpdateSampleFileName();
  490. // This method is only called when the checkbox value has changed.
  491. SetModifiedPage(TRUE);
  492. }
  493. void
  494. CFilesProperty::OnOverWriteChk()
  495. {
  496. BOOL bOldValue;
  497. bOldValue = m_bOverWriteFile;
  498. UpdateData(TRUE);
  499. if (bOldValue != m_bOverWriteFile) {
  500. SetModifiedPage(TRUE);
  501. }
  502. }
  503. void CFilesProperty::OnChangeFilesFirstSerialEdit()
  504. {
  505. DWORD dwOldValue;
  506. dwOldValue = m_dwSerialNumber;
  507. UpdateData( TRUE );
  508. UpdateSampleFileName();
  509. if (dwOldValue != m_dwSerialNumber) {
  510. SetModifiedPage(TRUE);
  511. }
  512. }
  513. void CFilesProperty::OnChangeFilesCommentEdit()
  514. {
  515. CString strOldText;
  516. strOldText = m_strCommentText;
  517. UpdateData ( TRUE );
  518. if ( 0 != strOldText.Compare ( m_strCommentText ) ) {
  519. SetModifiedPage(TRUE);
  520. }
  521. }
  522. void CFilesProperty::OnSelendokFilesSuffixCombo()
  523. {
  524. int nSel;
  525. nSel = ((CComboBox *)GetDlgItem(IDC_FILES_SUFFIX_COMBO))->GetCurSel();
  526. // Check of m_dwSuffix ensures that the value has changed.
  527. if ( LB_ERR != nSel && m_dwSuffix != nSel ) {
  528. UpdateData ( TRUE );
  529. EnableSerialNumber();
  530. /*
  531. if (m_dwLogFileTypeValue == SLF_BIN_FILE) {
  532. GetDlgItem(IDC_FILES_OVERWRITE_CHK)->EnableWindow(
  533. m_dwSuffixValue == SLF_NAME_NNNNNN ? FALSE : TRUE);
  534. }
  535. else {
  536. GetDlgItem(IDC_FILES_OVERWRITE_CHK)->EnableWindow(FALSE);
  537. }
  538. */
  539. UpdateSampleFileName();
  540. SetModifiedPage(TRUE);
  541. }
  542. }
  543. void
  544. CFilesProperty::OnSelendokFilesLogFileTypeCombo()
  545. {
  546. HandleLogTypeChange();
  547. return;
  548. }
  549. void CFilesProperty::OnKillfocusFilesCommentEdit()
  550. {
  551. CString strOldText;
  552. strOldText = m_strCommentText;
  553. UpdateData ( TRUE );
  554. if ( 0 != strOldText.Compare ( m_strCommentText ) ) {
  555. SetModifiedPage(TRUE);
  556. }
  557. }
  558. void CFilesProperty::OnKillfocusFirstSerialEdit()
  559. {
  560. DWORD dwOldValue;
  561. dwOldValue = m_dwSerialNumber;
  562. UpdateData ( TRUE );
  563. if (dwOldValue != m_dwSerialNumber) {
  564. SetModifiedPage(TRUE);
  565. }
  566. }
  567. void CFilesProperty::OnKillfocusFilesSuffixCombo()
  568. {
  569. int nSel;
  570. nSel = ((CComboBox *)GetDlgItem(IDC_FILES_SUFFIX_COMBO))->GetCurSel();
  571. if ((nSel != LB_ERR) && (nSel != m_dwSuffix)) {
  572. SetModifiedPage(TRUE);
  573. }
  574. }
  575. void CFilesProperty::OnKillfocusFilesLogFileTypeCombo()
  576. {
  577. int nSel;
  578. nSel = ((CComboBox *)GetDlgItem(IDC_FILES_LOG_TYPE_COMBO))->GetCurSel();
  579. if ((nSel != LB_ERR) && (nSel != m_iLogFileType)) {
  580. SetModifiedPage(TRUE);
  581. }
  582. }
  583. void CFilesProperty::PostNcDestroy()
  584. {
  585. // delete this;
  586. CPropertyPage::PostNcDestroy();
  587. }
  588. BOOL
  589. CFilesProperty::UpdateSharedData( BOOL bUpdateModel )
  590. {
  591. BOOL bContinue = TRUE;
  592. if ( SLQ_AUTO_MODE_SIZE == m_SharedData.stiStopTime.dwAutoMode ) {
  593. CString strMsg;
  594. if ( SLF_BIN_CIRC_FILE == m_dwLogFileTypeValue
  595. || SLQ_DISK_MAX_SIZE == m_dwMaxSizeInternal ) {
  596. if ( SLF_BIN_CIRC_FILE == m_dwLogFileTypeValue ) {
  597. strMsg.LoadString ( IDS_FILE_CIRC_SET_MANUAL_STOP );
  598. } else {
  599. ASSERT( SLQ_DISK_MAX_SIZE == m_dwMaxSizeInternal );
  600. strMsg.LoadString ( IDS_FILE_MAX_SET_MANUAL_STOP );
  601. }
  602. MessageBox( strMsg, m_pLogQuery->GetLogName(), MB_OK | MB_ICONINFORMATION);
  603. m_SharedData.stiStopTime.dwAutoMode = SLQ_AUTO_MODE_NONE;
  604. if ( bUpdateModel ) {
  605. SLQ_TIME_INFO slqTime;
  606. memset (&slqTime, 0, sizeof(slqTime));
  607. slqTime.wTimeType = SLQ_TT_TTYPE_STOP;
  608. slqTime.wDataType = SLQ_TT_DTYPE_DATETIME;
  609. slqTime.dwAutoMode = SLQ_AUTO_MODE_NONE;
  610. bContinue = m_pLogQuery->SetLogTime ( &slqTime, (DWORD)slqTime.wTimeType );
  611. }
  612. }
  613. }
  614. m_SharedData.strFileBaseName = m_strFileBaseName;
  615. m_SharedData.strFolderName = m_strFolderName;
  616. m_SharedData.strSqlName = m_strSqlName;
  617. m_SharedData.dwLogFileType = m_dwLogFileTypeValue;
  618. if ( TRUE == m_bAutoNameSuffix ) {
  619. m_SharedData.dwSuffix = m_dwSuffixValue;
  620. } else {
  621. m_SharedData.dwSuffix = SLF_NAME_NONE;
  622. }
  623. m_SharedData.dwSerialNumber = m_dwSerialNumber;
  624. m_SharedData.dwMaxFileSize = m_dwMaxSizeInternal;
  625. m_pLogQuery->SetPropPageSharedData ( &m_SharedData );
  626. return bContinue;
  627. }
  628. BOOL CFilesProperty::OnKillActive()
  629. {
  630. BOOL bContinue = TRUE;
  631. ResourceStateManager rsm;
  632. bContinue = CPropertyPage::OnKillActive();
  633. if ( bContinue ) {
  634. bContinue = IsValidData(m_pLogQuery, VALIDATE_FOCUS );
  635. }
  636. if ( bContinue ) {
  637. m_SharedData.dwLogFileType = m_dwLogFileTypeValue;
  638. bContinue = UpdateSharedData( FALSE );
  639. }
  640. if ( bContinue ) {
  641. SetIsActive ( FALSE );
  642. }
  643. return bContinue;
  644. }
  645. BOOL CFilesProperty::OnSetActive()
  646. {
  647. BOOL bReturn;
  648. bReturn = CSmPropertyPage::OnSetActive();
  649. if ( bReturn ) {
  650. m_pLogQuery->GetPropPageSharedData ( &m_SharedData );
  651. UpdateData( FALSE );
  652. }
  653. return bReturn;
  654. }
  655. DWORD
  656. CFilesProperty::ExtractDSN ( CString& rstrDSN )
  657. {
  658. DWORD dwStatus = ERROR_SUCCESS;
  659. INT iTotalLength;
  660. INT iRightLength;
  661. // Format string: "SQL:%s!%s"
  662. MFC_TRY
  663. iTotalLength = m_strSqlName.GetLength();
  664. iRightLength = iTotalLength - m_strSqlName.Find(L"!");
  665. rstrDSN = m_strSqlName.Mid ( 4, iTotalLength - iRightLength - 4 );
  666. MFC_CATCH_DWSTATUS;
  667. return dwStatus;
  668. }
  669. DWORD
  670. CFilesProperty::ExtractLogSetName ( CString& rstrLogSetName )
  671. {
  672. DWORD dwStatus = ERROR_SUCCESS;
  673. // Format string: "SQL:%s!%s"
  674. MFC_TRY
  675. rstrLogSetName = m_strSqlName.Right(m_strSqlName.GetLength() - m_strSqlName.Find(L"!") - 1);
  676. MFC_CATCH_DWSTATUS;
  677. return dwStatus;
  678. }
  679. void CFilesProperty::OnCfgBtn()
  680. {
  681. DWORD dwStatus = ERROR_SUCCESS;
  682. CFileLogs FilelogsDlg;
  683. CSqlProp SqlLogDlg;
  684. CString strTempBaseName;
  685. CString strTempFolderName;
  686. CString strTempSqlName;
  687. DWORD dwTempMaxSize;
  688. if ( SLF_SQL_LOG == m_dwLogFileTypeValue ){
  689. SqlLogDlg.m_pLogQuery = m_pLogQuery;
  690. SqlLogDlg.m_dwLogFileTypeValue = m_dwLogFileTypeValue;
  691. SqlLogDlg.m_bAutoNameSuffix = m_bAutoNameSuffix;
  692. //Extract the DSN and logset name from the formatted Sql Log name
  693. dwStatus = ExtractDSN ( SqlLogDlg.m_strDSN );
  694. dwStatus = ExtractLogSetName ( SqlLogDlg.m_strLogSetName );
  695. // Default the log set name to the base file name.
  696. if (SqlLogDlg.m_strLogSetName.IsEmpty() ) {
  697. SqlLogDlg.m_strLogSetName = m_strFileBaseName;
  698. }
  699. // Todo: Handle bad status
  700. SqlLogDlg.m_dwFocusControl = m_dwSubDlgFocusCtrl;
  701. SqlLogDlg.m_dwMaxSizeInternal = m_dwMaxSizeInternal;
  702. SqlLogDlg.SetContextHelpFilePath(GetContextHelpFilePath());
  703. if ( IDOK == SqlLogDlg.DoModal() ) {
  704. strTempSqlName = m_strSqlName;
  705. dwTempMaxSize = m_dwMaxSizeInternal;
  706. m_strSqlName = SqlLogDlg.m_SqlFormattedLogName;
  707. m_dwMaxSizeInternal = SqlLogDlg.m_dwMaxSizeInternal;
  708. if ( 0 != strTempSqlName.CompareNoCase ( m_strSqlName )
  709. || m_dwMaxSizeInternal != dwTempMaxSize )
  710. {
  711. SetModifiedPage(TRUE);
  712. }
  713. }
  714. }else{
  715. FilelogsDlg.m_pLogQuery = m_pLogQuery;
  716. FilelogsDlg.m_dwLogFileTypeValue = m_dwLogFileTypeValue;
  717. FilelogsDlg.m_strFolderName = m_strFolderName;
  718. FilelogsDlg.m_strFileBaseName = m_strFileBaseName;
  719. FilelogsDlg.m_dwMaxSizeInternal = m_dwMaxSizeInternal;
  720. FilelogsDlg.m_bAutoNameSuffix = m_bAutoNameSuffix;
  721. FilelogsDlg.SetContextHelpFilePath(GetContextHelpFilePath());
  722. FilelogsDlg.m_dwFocusControl = m_dwSubDlgFocusCtrl;
  723. if ( IDOK == FilelogsDlg.DoModal() ) {
  724. strTempFolderName = m_strFolderName;
  725. strTempBaseName = m_strFileBaseName;
  726. dwTempMaxSize = m_dwMaxSizeInternal;
  727. m_strFolderName = FilelogsDlg.m_strFolderName ;
  728. m_strFileBaseName = FilelogsDlg.m_strFileBaseName;
  729. m_dwMaxSizeInternal = FilelogsDlg.m_dwMaxSizeInternal;
  730. if ( 0 != strTempFolderName.CompareNoCase ( m_strFolderName )
  731. || 0 != strTempBaseName.CompareNoCase ( m_strFileBaseName )
  732. || m_dwMaxSizeInternal != dwTempMaxSize )
  733. {
  734. SetModifiedPage(TRUE);
  735. }
  736. }
  737. }
  738. m_dwSubDlgFocusCtrl = 0;
  739. UpdateSampleFileName();
  740. }