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.

1059 lines
34 KiB

  1. /*++
  2. Copyright (C) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. schdprop.cpp
  5. Abstract:
  6. Implementation of the schedule property page.
  7. --*/
  8. #include "stdafx.h"
  9. #include <pdh.h> // for MIN_TIME_VALUE, MAX_TIME_VALUE
  10. #include "smcfgmsg.h"
  11. #include "globals.h"
  12. #include "smlogs.h"
  13. #include "schdprop.h"
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. static ULONG
  20. s_aulHelpIds[] =
  21. {
  22. IDC_SCHED_START_MANUAL_RDO, IDH_SCHED_START_MANUAL_RDO,
  23. IDC_SCHED_START_AT_RDO, IDH_SCHED_START_AT_RDO,
  24. IDC_SCHED_START_AT_TIME_DT, IDH_SCHED_START_AT_TIME_DT,
  25. IDC_SCHED_START_AT_DATE_DT, IDH_SCHED_START_AT_DATE_DT,
  26. IDC_SCHED_STOP_MANUAL_RDO, IDH_SCHED_STOP_MANUAL_RDO,
  27. IDC_SCHED_STOP_AT_RDO, IDH_SCHED_STOP_AT_RDO,
  28. IDC_SCHED_STOP_AFTER_RDO, IDH_SCHED_STOP_AFTER_RDO,
  29. IDC_SCHED_STOP_SIZE_RDO, IDH_SCHED_STOP_SIZE_RDO,
  30. IDC_SCHED_STOP_AT_TIME_DT, IDH_SCHED_STOP_AT_TIME_DT,
  31. IDC_SCHED_STOP_AT_DATE_DT, IDH_SCHED_STOP_AT_DATE_DT,
  32. IDC_SCHED_STOP_AFTER_SPIN, IDH_SCHED_STOP_AFTER_EDIT,
  33. IDC_SCHED_STOP_AFTER_EDIT, IDH_SCHED_STOP_AFTER_EDIT,
  34. IDC_SCHED_STOP_AFTER_UNITS_COMBO, IDH_SCHED_STOP_AFTER_UNITS_COMBO,
  35. IDC_SCHED_RESTART_CHECK, IDH_SCHED_RESTART_CHECK,
  36. IDC_SCHED_EXEC_CHECK, IDH_SCHED_EXEC_CHECK,
  37. IDC_SCHED_CMD_EDIT, IDH_SCHED_CMD_EDIT,
  38. IDC_SCHED_CMD_BROWSE_BTN, IDH_SCHED_CMD_BROWSE_BTN,
  39. 0,0
  40. };
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CScheduleProperty property page
  43. IMPLEMENT_DYNCREATE(CScheduleProperty, CSmPropertyPage)
  44. CScheduleProperty::CScheduleProperty(
  45. MMC_COOKIE lCookie,
  46. LONG_PTR hConsole,
  47. LPDATAOBJECT pDataObject )
  48. : CSmPropertyPage ( CScheduleProperty::IDD, hConsole, pDataObject ),
  49. m_llManualStartTime ( MAX_TIME_VALUE ),
  50. m_llManualStopTime ( MIN_TIME_VALUE )
  51. {
  52. // save pointers from arg list
  53. m_pQuery = reinterpret_cast <CSmLogQuery *>(lCookie);
  54. // EnableAutomation();
  55. //{{AFX_DATA_INIT(CScheduleProperty)
  56. m_dwStopAfterCount = 0;
  57. m_nStopAfterUnits = -1;
  58. m_bAutoRestart = FALSE;
  59. m_strEofCommand = L"";
  60. m_bExecEofCommand = FALSE;
  61. //}}AFX_DATA_INIT
  62. ZeroMemory (&m_stStartAt, sizeof ( m_stStartAt ) );
  63. ZeroMemory (&m_stStopAt, sizeof ( m_stStopAt ) );
  64. }
  65. CScheduleProperty::CScheduleProperty() : CSmPropertyPage(CScheduleProperty::IDD)
  66. {
  67. ASSERT (FALSE); // only the constructor w/ args should be called
  68. EnableAutomation();
  69. // //{{AFX_DATA_INIT(CScheduleProperty)
  70. m_dwStopAfterCount = 0;
  71. m_nStopAfterUnits = -1;
  72. m_bAutoRestart = FALSE;
  73. m_strEofCommand = L"";
  74. m_bExecEofCommand = FALSE;
  75. // //}}AFX_DATA_INIT
  76. }
  77. CScheduleProperty::~CScheduleProperty()
  78. {
  79. }
  80. void
  81. CScheduleProperty::OnFinalRelease()
  82. {
  83. // When the last reference for an automation object is released
  84. // OnFinalRelease is called. The base class automatically
  85. // deletes the object. Add additional cleanup required for your
  86. // object before calling the base class.
  87. CPropertyPage::OnFinalRelease();
  88. }
  89. BOOL
  90. CScheduleProperty::IsValidLocalData()
  91. {
  92. LONGLONG llStopTime;
  93. INT iPrevLength = 0;
  94. BOOL bContinue = TRUE;
  95. ResourceStateManager rsm;
  96. // Trim text fields before validation
  97. iPrevLength = m_strEofCommand.GetLength();
  98. m_strEofCommand.TrimLeft();
  99. m_strEofCommand.TrimRight();
  100. if ( iPrevLength != m_strEofCommand.GetLength() ) {
  101. SetDlgItemText ( IDC_SCHED_CMD_EDIT, m_strEofCommand );
  102. }
  103. if ( SLQ_AUTO_MODE_AT == m_SharedData.stiStopTime.dwAutoMode ) {
  104. SystemTimeToFileTime ( &m_stStopAt, (FILETIME *)&llStopTime );
  105. if ( SLQ_AUTO_MODE_AT == m_dwCurrentStartMode ) {
  106. LONGLONG llStartTime;
  107. SystemTimeToFileTime ( &m_stStartAt, (FILETIME *)&llStartTime );
  108. if ( llStartTime >= llStopTime ) {
  109. CString strMessage;
  110. strMessage.LoadString ( IDS_SCHED_START_PAST_STOP );
  111. MessageBox ( strMessage, m_pQuery->GetLogName(), MB_OK | MB_ICONERROR );
  112. SetFocusAnyPage ( IDC_SCHED_STOP_AT_TIME_DT );
  113. bContinue = FALSE;
  114. }
  115. } else {
  116. // Start mode is manual.
  117. // get local time
  118. SYSTEMTIME stLocalTime;
  119. FILETIME ftLocalTime;
  120. // Milliseconds set to 0 for Schedule times
  121. ftLocalTime.dwLowDateTime = ftLocalTime.dwHighDateTime = 0;
  122. GetLocalTime (&stLocalTime);
  123. stLocalTime.wMilliseconds = 0;
  124. SystemTimeToFileTime (&stLocalTime, &ftLocalTime);
  125. if ( *(LONGLONG*)&ftLocalTime >= llStopTime ) {
  126. CString strMessage;
  127. strMessage.LoadString ( IDS_SCHED_NOW_PAST_STOP );
  128. MessageBox ( strMessage, m_pQuery->GetLogName(), MB_OK | MB_ICONERROR );
  129. SetFocusAnyPage ( IDC_SCHED_STOP_AT_TIME_DT );
  130. bContinue = FALSE;
  131. }
  132. }
  133. } else if ( SLQ_AUTO_MODE_AFTER == m_SharedData.stiStopTime.dwAutoMode ) {
  134. bContinue = ValidateDWordInterval(IDC_SCHED_STOP_AFTER_EDIT,
  135. m_pQuery->GetLogName(),
  136. (long) m_dwStopAfterCount,
  137. 1,
  138. 100000);
  139. }
  140. // Validate command file path if logging to local machine.
  141. if ( bContinue
  142. && m_pQuery->GetLogService()->IsLocalMachine()
  143. && m_bExecEofCommand ) {
  144. DWORD dwStatus;
  145. dwStatus = IsCommandFilePathValid ( m_strEofCommand );
  146. if ( ERROR_SUCCESS != dwStatus ) {
  147. CString strMessage;
  148. FormatSmLogCfgMessage (
  149. strMessage,
  150. m_hModule,
  151. dwStatus );
  152. MessageBox ( strMessage, m_pQuery->GetLogName(), MB_OK | MB_ICONERROR);
  153. SetFocusAnyPage ( IDC_SCHED_CMD_EDIT );
  154. bContinue = FALSE;
  155. }
  156. }
  157. return bContinue;
  158. }
  159. void
  160. CScheduleProperty::StartModeRadioExchange(CDataExchange* pDX)
  161. {
  162. if ( !pDX->m_bSaveAndValidate ) {
  163. // Load control value from data
  164. switch ( m_dwCurrentStartMode ) {
  165. case SLQ_AUTO_MODE_NONE:
  166. m_nStartModeRdo = 0;
  167. break;
  168. case SLQ_AUTO_MODE_AT:
  169. m_nStartModeRdo = 1;
  170. break;
  171. default:
  172. ;
  173. break;
  174. }
  175. }
  176. DDX_Radio(pDX, IDC_SCHED_START_MANUAL_RDO, m_nStartModeRdo);
  177. if ( pDX->m_bSaveAndValidate ) {
  178. switch ( m_nStartModeRdo ) {
  179. case 0:
  180. m_dwCurrentStartMode = SLQ_AUTO_MODE_NONE;
  181. break;
  182. case 1:
  183. m_dwCurrentStartMode = SLQ_AUTO_MODE_AT;
  184. break;
  185. default:
  186. ;
  187. break;
  188. }
  189. }
  190. }
  191. void
  192. CScheduleProperty::StartAtExchange(CDataExchange* pDX)
  193. {
  194. CWnd* pWndTime = NULL;
  195. CWnd* pWndDate = NULL;
  196. pWndTime = GetDlgItem(IDC_SCHED_START_AT_TIME_DT);
  197. pWndDate = GetDlgItem(IDC_SCHED_START_AT_DATE_DT);
  198. if ( pDX->m_bSaveAndValidate ) {
  199. DWORD dwStatus;
  200. SYSTEMTIME stTemp;
  201. dwStatus = DateTime_GetSystemtime ( pWndTime->m_hWnd, &stTemp );
  202. m_stStartAt.wHour = stTemp.wHour;
  203. m_stStartAt.wMinute = stTemp.wMinute;
  204. m_stStartAt.wSecond = stTemp.wSecond;
  205. m_stStartAt.wMilliseconds = 0;
  206. dwStatus = DateTime_GetSystemtime ( pWndDate->m_hWnd, &stTemp );
  207. m_stStartAt.wYear = stTemp.wYear;
  208. m_stStartAt.wMonth = stTemp.wMonth;
  209. m_stStartAt.wDayOfWeek = stTemp.wDayOfWeek;
  210. m_stStartAt.wDay = stTemp.wDay;
  211. if ( SLQ_AUTO_MODE_AT == m_dwCurrentStartMode
  212. && IsModifiedPage() ) {
  213. // Set manual stop time to MAX so that automatic start will occur.
  214. // Do this only if the user has modified something on the page.
  215. m_llManualStopTime = MAX_TIME_VALUE;
  216. }
  217. } else {
  218. BOOL bStatus;
  219. bStatus = DateTime_SetSystemtime ( pWndTime->m_hWnd, GDT_VALID, &m_stStartAt );
  220. bStatus = DateTime_SetSystemtime ( pWndDate->m_hWnd, GDT_VALID, &m_stStartAt );
  221. }
  222. }
  223. void
  224. CScheduleProperty::StopAtExchange(CDataExchange* pDX)
  225. {
  226. CWnd* pWndTime = NULL;
  227. CWnd* pWndDate = NULL;
  228. pWndTime = GetDlgItem(IDC_SCHED_STOP_AT_TIME_DT);
  229. pWndDate = GetDlgItem(IDC_SCHED_STOP_AT_DATE_DT);
  230. if ( pDX->m_bSaveAndValidate ) {
  231. DWORD dwStatus;
  232. SYSTEMTIME stTemp;
  233. dwStatus = DateTime_GetSystemtime ( pWndTime->m_hWnd, &stTemp );
  234. m_stStopAt.wHour = stTemp.wHour;
  235. m_stStopAt.wMinute = stTemp.wMinute;
  236. m_stStopAt.wSecond = stTemp.wSecond;
  237. m_stStopAt.wMilliseconds = 0;
  238. dwStatus = DateTime_GetSystemtime ( pWndDate->m_hWnd, &stTemp );
  239. m_stStopAt.wYear = stTemp.wYear;
  240. m_stStopAt.wMonth = stTemp.wMonth;
  241. m_stStopAt.wDayOfWeek = stTemp.wDayOfWeek;
  242. m_stStopAt.wDay = stTemp.wDay;
  243. } else {
  244. BOOL bStatus;
  245. bStatus = DateTime_SetSystemtime ( pWndTime->m_hWnd, GDT_VALID, &m_stStopAt );
  246. bStatus = DateTime_SetSystemtime ( pWndDate->m_hWnd, GDT_VALID, &m_stStopAt );
  247. }
  248. }
  249. void
  250. CScheduleProperty::StopModeRadioExchange(CDataExchange* pDX)
  251. {
  252. // Note: Load is handled in OnInitDialog, OnSetActive.
  253. // That handling should be moved here.
  254. if ( !pDX->m_bSaveAndValidate ) {
  255. // Load control value from data
  256. switch ( m_SharedData.stiStopTime.dwAutoMode ) {
  257. case SLQ_AUTO_MODE_NONE:
  258. m_nStopModeRdo = 0;
  259. break;
  260. case SLQ_AUTO_MODE_AFTER:
  261. m_nStopModeRdo = 1;
  262. break;
  263. case SLQ_AUTO_MODE_AT:
  264. m_nStopModeRdo = 2;
  265. break;
  266. case SLQ_AUTO_MODE_SIZE:
  267. m_nStopModeRdo = 3;
  268. break;
  269. default:
  270. ;
  271. break;
  272. }
  273. }
  274. DDX_Radio(pDX, IDC_SCHED_STOP_MANUAL_RDO, m_nStopModeRdo);
  275. if ( pDX->m_bSaveAndValidate ) {
  276. switch ( m_nStopModeRdo ) {
  277. case 0:
  278. m_SharedData.stiStopTime.dwAutoMode = SLQ_AUTO_MODE_NONE;
  279. break;
  280. case 1:
  281. m_SharedData.stiStopTime.dwAutoMode = SLQ_AUTO_MODE_AFTER;
  282. break;
  283. case 2:
  284. m_SharedData.stiStopTime.dwAutoMode = SLQ_AUTO_MODE_AT;
  285. break;
  286. case 3:
  287. m_SharedData.stiStopTime.dwAutoMode = SLQ_AUTO_MODE_SIZE;
  288. break;
  289. default:
  290. ;
  291. break;
  292. }
  293. }
  294. }
  295. void
  296. CScheduleProperty::DoDataExchange(CDataExchange* pDX)
  297. {
  298. CString strTemp;
  299. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  300. CPropertyPage::DoDataExchange(pDX);
  301. //{{AFX_DATA_MAP(CScheduleProperty)
  302. DDX_Text(pDX, IDC_SCHED_CMD_EDIT, m_strEofCommand);
  303. DDX_Check(pDX, IDC_SCHED_EXEC_CHECK, m_bExecEofCommand);
  304. ValidateTextEdit(pDX, IDC_SCHED_STOP_AFTER_EDIT, 6, & m_dwStopAfterCount, 1, 100000);
  305. DDX_CBIndex(pDX, IDC_SCHED_STOP_AFTER_UNITS_COMBO, m_nStopAfterUnits);
  306. DDX_Check(pDX, IDC_SCHED_RESTART_CHECK, m_bAutoRestart);
  307. //}}AFX_DATA_MAP
  308. StartAtExchange ( pDX );
  309. StopAtExchange ( pDX );
  310. StopModeRadioExchange ( pDX );
  311. StartModeRadioExchange ( pDX );
  312. if ( pDX->m_bSaveAndValidate ) {
  313. m_dwStopAfterUnitsValue =
  314. (DWORD)((CComboBox *)GetDlgItem(IDC_SCHED_STOP_AFTER_UNITS_COMBO))->
  315. GetItemData(m_nStopAfterUnits);
  316. }
  317. }
  318. BEGIN_MESSAGE_MAP(CScheduleProperty, CSmPropertyPage)
  319. //{{AFX_MSG_MAP(CScheduleProperty)
  320. ON_BN_CLICKED(IDC_SCHED_CMD_BROWSE_BTN, OnSchedCmdBrowseBtn)
  321. ON_BN_CLICKED(IDC_SCHED_RESTART_CHECK, OnSchedRestartCheck)
  322. ON_BN_CLICKED(IDC_SCHED_EXEC_CHECK, OnSchedExecCheck)
  323. ON_BN_CLICKED(IDC_SCHED_START_MANUAL_RDO, OnSchedStartRdo)
  324. ON_BN_CLICKED(IDC_SCHED_START_AT_RDO, OnSchedStartRdo)
  325. ON_BN_CLICKED(IDC_SCHED_STOP_MANUAL_RDO, OnSchedStopRdo)
  326. ON_BN_CLICKED(IDC_SCHED_STOP_AFTER_RDO, OnSchedStopRdo)
  327. ON_BN_CLICKED(IDC_SCHED_STOP_AT_RDO, OnSchedStopRdo)
  328. ON_BN_CLICKED(IDC_SCHED_STOP_SIZE_RDO, OnSchedStopRdo)
  329. ON_WM_DESTROY()
  330. ON_NOTIFY ( DTN_DATETIMECHANGE, IDC_SCHED_START_AT_TIME_DT, OnKillfocusSchedStartAtDt)
  331. ON_NOTIFY ( NM_KILLFOCUS, IDC_SCHED_START_AT_TIME_DT, OnKillfocusSchedStartAtDt)
  332. ON_NOTIFY ( DTN_DATETIMECHANGE, IDC_SCHED_START_AT_DATE_DT, OnKillfocusSchedStartAtDt)
  333. ON_NOTIFY ( NM_KILLFOCUS, IDC_SCHED_START_AT_DATE_DT, OnKillfocusSchedStartAtDt)
  334. ON_NOTIFY ( DTN_DATETIMECHANGE, IDC_SCHED_STOP_AT_TIME_DT, OnKillfocusSchedStopAtDt)
  335. ON_NOTIFY ( NM_KILLFOCUS, IDC_SCHED_STOP_AT_TIME_DT, OnKillfocusSchedStopAtDt)
  336. ON_NOTIFY ( DTN_DATETIMECHANGE, IDC_SCHED_STOP_AT_DATE_DT, OnKillfocusSchedStopAtDt)
  337. ON_NOTIFY ( NM_KILLFOCUS, IDC_SCHED_STOP_AT_DATE_DT, OnKillfocusSchedStopAtDt)
  338. ON_CBN_SELENDOK(IDC_SCHED_STOP_AFTER_UNITS_COMBO, OnSelendokSchedStopAfterUnitsCombo)
  339. ON_EN_CHANGE(IDC_SCHED_STOP_AFTER_EDIT, OnKillfocusSchedStopAfterEdit)
  340. ON_EN_KILLFOCUS(IDC_SCHED_STOP_AFTER_EDIT, OnKillfocusSchedStopAfterEdit)
  341. ON_NOTIFY(UDN_DELTAPOS, IDC_SCHED_STOP_AFTER_SPIN, OnDeltaposSchedStopAfterSpin)
  342. ON_EN_CHANGE(IDC_SCHED_CMD_EDIT, OnKillfocusSchedCmdEdit)
  343. ON_EN_KILLFOCUS(IDC_SCHED_CMD_EDIT, OnKillfocusSchedCmdEdit)
  344. //}}AFX_MSG_MAP
  345. END_MESSAGE_MAP()
  346. BEGIN_DISPATCH_MAP(CScheduleProperty, CSmPropertyPage)
  347. //{{AFX_DISPATCH_MAP(CScheduleProperty)
  348. // NOTE - the ClassWizard will add and remove mapping macros here.
  349. //}}AFX_DISPATCH_MAP
  350. END_DISPATCH_MAP()
  351. // Note: we add support for IID_IScheduleProperty to support typesafe binding
  352. // from VBA. This IID must match the GUID that is attached to the
  353. // dispinterface in the .ODL file.
  354. // {65154EAD-BDBE-11D1-BF99-00C04F94A83A}
  355. static const IID IID_IScheduleProperty =
  356. { 0x65154ead, 0xbdbe, 0x11d1, { 0xbf, 0x99, 0x0, 0xc0, 0x4f, 0x94, 0xa8, 0x3a } };
  357. BEGIN_INTERFACE_MAP(CScheduleProperty, CSmPropertyPage)
  358. INTERFACE_PART(CScheduleProperty, IID_IScheduleProperty, Dispatch)
  359. END_INTERFACE_MAP()
  360. void
  361. CScheduleProperty::SetStopDefaultValues ( PSLQ_TIME_INFO pslqStartTime )
  362. {
  363. SLQ_TIME_INFO slqLocalTime;
  364. // Default Stop After values.
  365. m_dwStopAfterCount = 1;
  366. m_dwStopAfterUnitsValue = SLQ_TT_UTYPE_DAYS;
  367. // Get default time fields for Stop At mode.
  368. // Set default stop time for start time + 24 hrs
  369. slqLocalTime.llDateTime = 86400; // sec/day
  370. slqLocalTime.llDateTime *= 10000000; // 100ns /sec
  371. slqLocalTime.llDateTime += pslqStartTime->llDateTime;
  372. FileTimeToSystemTime( (CONST FILETIME *)&slqLocalTime.llDateTime, &m_stStopAt );
  373. }
  374. void
  375. CScheduleProperty::SetCmdBtnState ()
  376. {
  377. if ( SLQ_ALERT != m_pQuery->GetLogType() ) {
  378. if ( !m_bExecEofCommand ) {
  379. m_strEofCommand.Empty();
  380. }
  381. GetDlgItem(IDC_SCHED_CMD_EDIT)->EnableWindow (m_bExecEofCommand);
  382. GetDlgItem(IDC_SCHED_CMD_BROWSE_BTN)->EnableWindow (m_bExecEofCommand);
  383. }
  384. }
  385. void CScheduleProperty::SetStopBtnState ()
  386. {
  387. BOOL bSizeRdo;
  388. BOOL bAtRdo;
  389. BOOL bAfterRdo;
  390. BOOL bManualRdo;
  391. bAtRdo = bAfterRdo = bSizeRdo = FALSE;
  392. bManualRdo = ( SLQ_AUTO_MODE_NONE == m_SharedData.stiStopTime.dwAutoMode );
  393. if (!bManualRdo) {
  394. // check which button is checked and
  395. // enable/disable the appropriate edit/combo box
  396. bSizeRdo = ( SLQ_AUTO_MODE_SIZE == m_SharedData.stiStopTime.dwAutoMode );
  397. bAfterRdo = ( SLQ_AUTO_MODE_AFTER == m_SharedData.stiStopTime.dwAutoMode );
  398. bAtRdo = ( SLQ_AUTO_MODE_AT == m_SharedData.stiStopTime.dwAutoMode );
  399. }
  400. GetDlgItem(IDC_SCHED_STOP_AFTER_EDIT)->EnableWindow(bAfterRdo);
  401. GetDlgItem(IDC_SCHED_STOP_AFTER_SPIN)->EnableWindow(bAfterRdo);
  402. GetDlgItem(IDC_SCHED_STOP_AFTER_STATIC)->EnableWindow(bAfterRdo);
  403. GetDlgItem(IDC_SCHED_STOP_AFTER_UNITS_COMBO)->EnableWindow(bAfterRdo);
  404. GetDlgItem(IDC_SCHED_STOP_AT_TIME_DT)->EnableWindow(bAtRdo);
  405. GetDlgItem(IDC_SCHED_STOP_AT_ON_CAPTION)->EnableWindow(bAtRdo);
  406. GetDlgItem(IDC_SCHED_STOP_AT_DATE_DT)->EnableWindow(bAtRdo);
  407. if ( !(bSizeRdo || bAfterRdo) ) {
  408. m_bAutoRestart = FALSE;
  409. }
  410. GetDlgItem(IDC_SCHED_RESTART_CHECK)->EnableWindow(bSizeRdo || bAfterRdo);
  411. if ( SLQ_ALERT != m_pQuery->GetLogType() ) {
  412. // GetDlgItem(IDC_SCHED_EXEC_CHECK)->EnableWindow( TRUE );
  413. SetCmdBtnState();
  414. }
  415. // UpdateData updates Eof command and Restart UI.
  416. UpdateData ( FALSE );
  417. }
  418. void CScheduleProperty::SetStartBtnState ()
  419. {
  420. BOOL bManualRdo;
  421. BOOL bAutoFields;
  422. bManualRdo = ( SLQ_AUTO_MODE_NONE == m_dwCurrentStartMode );
  423. bAutoFields = !bManualRdo;
  424. GetDlgItem(IDC_SCHED_START_AT_TIME_DT)->EnableWindow(bAutoFields);
  425. GetDlgItem(IDC_SCHED_START_AT_ON_CAPTION)->EnableWindow(bAutoFields);
  426. GetDlgItem(IDC_SCHED_START_AT_DATE_DT)->EnableWindow(bAutoFields);
  427. }
  428. void
  429. CScheduleProperty::FillStartTimeStruct ( PSLQ_TIME_INFO pslqStartTime )
  430. {
  431. memset (pslqStartTime, 0, sizeof(SLQ_TIME_INFO));
  432. pslqStartTime->wTimeType = SLQ_TT_TTYPE_START;
  433. pslqStartTime->wDataType = SLQ_TT_DTYPE_DATETIME;
  434. pslqStartTime->dwAutoMode = m_dwCurrentStartMode;
  435. // Start mode and time
  436. if ( SLQ_AUTO_MODE_NONE == m_dwCurrentStartMode ) {
  437. // Manual start mode
  438. pslqStartTime->llDateTime = m_llManualStartTime;
  439. } else {
  440. SystemTimeToFileTime ( &m_stStartAt, (FILETIME *)&pslqStartTime->llDateTime );
  441. }
  442. }
  443. void
  444. CScheduleProperty::UpdateSharedStopTimeStruct ( void )
  445. {
  446. PSLQ_TIME_INFO pTime;
  447. // Save changes that this page might have made to the shared stop time structure.
  448. pTime = &m_SharedData.stiStopTime;
  449. ASSERT ( SLQ_TT_TTYPE_STOP == pTime->wTimeType ) ;
  450. // Stop mode and time
  451. if ( SLQ_AUTO_MODE_NONE == pTime->dwAutoMode
  452. || SLQ_AUTO_MODE_SIZE == pTime->dwAutoMode ) {
  453. // The only change that the file page ever makes is to change the stop
  454. // mode from Size to Manual (SLQ_AUTO_MODE_NONE). In this case, set
  455. // the stop time to a value consistent with the start mode.
  456. // Also, for SIZE mode, set the manual stop time as calculated in this
  457. // dialog.
  458. pTime->wDataType = SLQ_TT_DTYPE_DATETIME;
  459. pTime->llDateTime = m_llManualStopTime;
  460. } else if ( SLQ_AUTO_MODE_AFTER == pTime->dwAutoMode ) {
  461. pTime->wDataType = SLQ_TT_DTYPE_UNITS;
  462. pTime->dwValue = m_dwStopAfterCount;
  463. pTime->dwUnitType = m_dwStopAfterUnitsValue;
  464. } else if ( SLQ_AUTO_MODE_AT == pTime->dwAutoMode ) {
  465. pTime->wDataType = SLQ_TT_DTYPE_DATETIME;
  466. SystemTimeToFileTime ( &m_stStopAt, (FILETIME *)&pTime->llDateTime );
  467. }
  468. }
  469. BOOL
  470. CScheduleProperty::SaveDataToModel ( )
  471. {
  472. SLQ_TIME_INFO slqTime;
  473. BOOL bContinue = TRUE;
  474. ResourceStateManager rsm;
  475. // Validate StopAt time before saving
  476. if ( bContinue ) {
  477. bContinue = SampleTimeIsLessThanSessionTime ( m_pQuery );
  478. if ( !bContinue ) {
  479. if ( SLQ_AUTO_MODE_AFTER == m_SharedData.stiStopTime.dwAutoMode ) {
  480. SetFocusAnyPage ( IDC_SCHED_STOP_AFTER_EDIT );
  481. } else if ( SLQ_AUTO_MODE_AT == m_SharedData.stiStopTime.dwAutoMode ) {
  482. SetFocusAnyPage ( IDC_SCHED_STOP_AT_TIME_DT );
  483. }
  484. }
  485. }
  486. if ( bContinue ) {
  487. FillStartTimeStruct ( &slqTime );
  488. bContinue = m_pQuery->SetLogTime (&slqTime, (DWORD)slqTime.wTimeType);
  489. ASSERT (bContinue);
  490. UpdateSharedStopTimeStruct();
  491. bContinue = m_pQuery->SetLogTime (&m_SharedData.stiStopTime, (DWORD)m_SharedData.stiStopTime.wTimeType);
  492. ASSERT (bContinue);
  493. // Restart mode
  494. // Currently only support After 0 minutes.
  495. memset (&slqTime, 0, sizeof(slqTime));
  496. slqTime.wTimeType = SLQ_TT_TTYPE_RESTART;
  497. slqTime.dwAutoMode = (m_bAutoRestart ? SLQ_AUTO_MODE_AFTER : SLQ_AUTO_MODE_NONE );
  498. slqTime.wDataType = SLQ_TT_DTYPE_UNITS;
  499. slqTime.dwUnitType = SLQ_TT_UTYPE_MINUTES;
  500. slqTime.dwValue = 0;
  501. bContinue = m_pQuery->SetLogTime (&slqTime, (DWORD)slqTime.wTimeType);
  502. ASSERT (bContinue);
  503. // For Counter and trace log queries, set command file from page
  504. if ( SLQ_COUNTER_LOG == m_pQuery->GetLogType()
  505. || SLQ_TRACE_LOG == m_pQuery->GetLogType() ) {
  506. if (m_bExecEofCommand) {
  507. // then send filename
  508. bContinue = ( ERROR_SUCCESS == m_pQuery->SetEofCommand ( m_strEofCommand ) );
  509. } else {
  510. // Empty string
  511. bContinue = ( ERROR_SUCCESS == m_pQuery->SetEofCommand ( m_pQuery->cstrEmpty ) );
  512. }
  513. ASSERT (bContinue);
  514. }
  515. if ( bContinue ) {
  516. // ApplyRunAs must be called before UpdateService
  517. bContinue = ApplyRunAs( m_pQuery );
  518. }
  519. if ( bContinue ) {
  520. // Save property page shared data.
  521. m_pQuery->UpdatePropPageSharedData();
  522. // Sync the service with changes.
  523. // Must sync changes made by service to properties not modified by this page.
  524. bContinue = UpdateService ( m_pQuery, TRUE );
  525. }
  526. }
  527. return bContinue;
  528. }
  529. /////////////////////////////////////////////////////////////////////////////
  530. // CScheduleProperty message handlers
  531. void CScheduleProperty::OnSchedCmdBrowseBtn()
  532. {
  533. CString strCmdPath;
  534. UpdateData (TRUE); // to get the current filename
  535. strCmdPath = m_strEofCommand;
  536. if ( IDOK == BrowseCommandFilename ( this, strCmdPath )) {
  537. // Update the fields with the new information
  538. if ( strCmdPath != m_strEofCommand ) {
  539. m_strEofCommand = strCmdPath;
  540. // Todo: Set the query PASSWORD_DIRTY flag only when m_bExecEofCommand is TRUE
  541. // and command has changed.
  542. //
  543. // This must be done before the check for SetRunAs in the base class
  544. // IsValidData() method.
  545. if( !m_pQuery->m_strUser.IsEmpty() ) {
  546. if( !( m_pQuery->m_strUser.GetAt(0) == L'<' ) ) {
  547. m_pQuery->m_fDirtyPassword |= PASSWORD_DIRTY;
  548. }
  549. }
  550. SetModifiedPage ( TRUE );
  551. UpdateData ( FALSE );
  552. }
  553. } // else ignore if they canceled out
  554. }
  555. void CScheduleProperty::OnSchedExecCheck()
  556. {
  557. UpdateData(TRUE);
  558. SetCmdBtnState();
  559. UpdateData ( FALSE );
  560. SetModifiedPage(TRUE);
  561. }
  562. void CScheduleProperty::OnSchedRestartCheck()
  563. {
  564. UpdateData(TRUE);
  565. SetModifiedPage(TRUE);
  566. }
  567. void CScheduleProperty::OnSchedStartRdo()
  568. {
  569. BOOL bNewStateIsManualStart;
  570. bNewStateIsManualStart = ( 1 == ((CButton *)(GetDlgItem(IDC_SCHED_START_MANUAL_RDO)))->GetCheck() );
  571. if ( bNewStateIsManualStart && ( SLQ_AUTO_MODE_AT == m_dwCurrentStartMode ) ) {
  572. // Switching to Manual start. Set start time to MAX so that original state
  573. // will be stopped.
  574. m_llManualStartTime = MAX_TIME_VALUE;
  575. // Set stop time to MIN so that original state will be stopped.
  576. // This variable is only used/saved if the stop time is set to manual or size.
  577. // Always set it here, in case the stop mode is changed on the file property
  578. // page.
  579. m_llManualStopTime = MIN_TIME_VALUE;
  580. } else if ( !bNewStateIsManualStart && ( SLQ_AUTO_MODE_NONE == m_dwCurrentStartMode ) ) {
  581. // Switching to Start At mode.
  582. // Set manual or size stop time to MAX so that automatic start will occur.
  583. m_llManualStopTime = MAX_TIME_VALUE;
  584. }
  585. UpdateData( TRUE );
  586. SetStartBtnState();
  587. SetStopBtnState();
  588. SetModifiedPage( TRUE );
  589. }
  590. void
  591. CScheduleProperty::OnSchedStopRdo()
  592. {
  593. UpdateData(TRUE);
  594. SetStopBtnState();
  595. SetModifiedPage(TRUE);
  596. }
  597. void
  598. CScheduleProperty::OnCancel()
  599. {
  600. m_pQuery->SyncPropPageSharedData(); // Clear the memory shared between property pages.
  601. }
  602. BOOL
  603. CScheduleProperty::OnApply()
  604. {
  605. BOOL bContinue;
  606. bContinue = UpdateData (TRUE); // get data from page
  607. if ( bContinue ) {
  608. bContinue = IsValidData( m_pQuery, VALIDATE_APPLY );
  609. }
  610. if ( bContinue ) {
  611. bContinue = SaveDataToModel();
  612. }
  613. if ( bContinue ){
  614. bContinue = CSmPropertyPage::OnApply();
  615. }
  616. return bContinue;
  617. }
  618. BOOL
  619. CScheduleProperty::OnInitDialog()
  620. {
  621. SLQ_TIME_INFO slqTime;
  622. CComboBox * pCombo;
  623. int nIndex;
  624. CString strComboBoxString;
  625. int nResult;
  626. SYSTEMTIME stLocalTime;
  627. FILETIME ftLocalTime;
  628. ResourceStateManager rsm;
  629. // get local time
  630. // Milliseconds set to 0 for Schedule times
  631. GetLocalTime (&stLocalTime);
  632. stLocalTime.wMilliseconds = 0;
  633. SystemTimeToFileTime (&stLocalTime, &ftLocalTime);
  634. // get log start state
  635. m_pQuery->GetLogTime (&slqTime, SLQ_TT_TTYPE_START);
  636. m_dwCurrentStartMode = slqTime.dwAutoMode;
  637. if (slqTime.dwAutoMode == SLQ_AUTO_MODE_NONE) {
  638. m_llManualStartTime = slqTime.llDateTime;
  639. // get default value for start At time to load local member variables
  640. slqTime.llDateTime = *(LONGLONG *)(&ftLocalTime);
  641. }
  642. // get time fields for Start At controls
  643. // *** Check status
  644. FileTimeToSystemTime( (CONST FILETIME *)&slqTime.llDateTime, &m_stStartAt );
  645. // Stop default values are based on Start At time.
  646. SetStopDefaultValues( &slqTime );
  647. // Override default values for the selected stop mode.
  648. m_pQuery->GetLogTime (&slqTime, SLQ_TT_TTYPE_STOP);
  649. m_SharedData.stiStopTime.dwAutoMode = slqTime.dwAutoMode;
  650. switch (slqTime.dwAutoMode) {
  651. case SLQ_AUTO_MODE_AFTER:
  652. // set edit control & dialog box values
  653. m_dwStopAfterCount = slqTime.dwValue;
  654. m_dwStopAfterUnitsValue = slqTime.dwUnitType;
  655. break;
  656. case SLQ_AUTO_MODE_AT:
  657. FileTimeToSystemTime( (CONST FILETIME *)&slqTime.llDateTime, &m_stStopAt );
  658. break;
  659. default:
  660. case SLQ_AUTO_MODE_SIZE:
  661. case SLQ_AUTO_MODE_NONE:
  662. // Manual is the default case if none is specified
  663. m_llManualStopTime = slqTime.llDateTime;
  664. break;
  665. }
  666. // Init the Stop After time units combo, and select based on
  667. // either default values or stop after override.
  668. pCombo = (CComboBox *)GetDlgItem(IDC_SCHED_STOP_AFTER_UNITS_COMBO);
  669. pCombo->ResetContent();
  670. for (nIndex = 0; nIndex < (int)dwTimeUnitComboEntries; nIndex++) {
  671. strComboBoxString.LoadString ( TimeUnitCombo[nIndex].nResId );
  672. nResult = pCombo->InsertString (nIndex, (LPCWSTR)strComboBoxString);
  673. ASSERT (nResult != CB_ERR);
  674. nResult = pCombo->SetItemData (nIndex, (DWORD)TimeUnitCombo[nIndex].nData);
  675. ASSERT (nResult != CB_ERR);
  676. // set selected in combo box here
  677. if (m_dwStopAfterUnitsValue == (DWORD)(TimeUnitCombo[nIndex].nData)) {
  678. m_nStopAfterUnits = nIndex;
  679. nResult = pCombo->SetCurSel(nIndex);
  680. ASSERT (nResult != CB_ERR);
  681. }
  682. }
  683. // Get restart mode
  684. m_pQuery->GetLogTime (&slqTime, SLQ_TT_TTYPE_RESTART);
  685. ASSERT (slqTime.wDataType == SLQ_TT_DTYPE_UNITS);
  686. ASSERT (slqTime.wTimeType == SLQ_TT_TTYPE_RESTART);
  687. m_bAutoRestart = ( SLQ_AUTO_MODE_NONE == slqTime.dwAutoMode ? FALSE : TRUE );
  688. // Get EOF command, if not Alert query.
  689. if ( SLQ_ALERT != m_pQuery->GetLogType() ) {
  690. CString strLogText;
  691. m_pQuery->GetEofCommand ( m_strEofCommand );
  692. m_bExecEofCommand = !m_strEofCommand.IsEmpty();
  693. // Static text
  694. strLogText.LoadString ( IDS_SCHED_START_LOG_GROUP );
  695. SetDlgItemText( IDC_SCHED_START_GROUP, strLogText );
  696. strLogText.LoadString ( IDS_SCHED_STOP_LOG_GROUP );
  697. SetDlgItemText( IDC_SCHED_STOP_GROUP, strLogText );
  698. strLogText.LoadString ( IDS_SCHED_RESTART_LOG );
  699. SetDlgItemText( IDC_SCHED_RESTART_CHECK, strLogText );
  700. strLogText.LoadString ( IDS_SCHED_STOP_LOG_WHEN );
  701. SetDlgItemText( IDC_SCHED_STOP_WHEN_STATIC, strLogText );
  702. } else {
  703. // Hide the EOF command UI if Alert query.
  704. GetDlgItem(IDC_SCHED_EXEC_CHECK)->ShowWindow(FALSE);
  705. GetDlgItem(IDC_SCHED_CMD_EDIT)->ShowWindow(FALSE);
  706. GetDlgItem(IDC_SCHED_CMD_BROWSE_BTN)->ShowWindow(FALSE);
  707. m_strEofCommand.Empty();
  708. m_bExecEofCommand = FALSE;
  709. }
  710. // Modify or hide other Dialog elements based on query type.
  711. if ( SLQ_ALERT == m_pQuery->GetLogType() ) {
  712. GetDlgItem(IDC_SCHED_STOP_SIZE_RDO)->ShowWindow(FALSE);
  713. }
  714. CSmPropertyPage::OnInitDialog();
  715. SetHelpIds ( (DWORD*)&s_aulHelpIds );
  716. SetStartBtnState ();
  717. SetStopBtnState();
  718. return TRUE; // return TRUE unless you set the focus to a control
  719. // EXCEPTION: OCX Property Pages should return FALSE
  720. }
  721. void
  722. CScheduleProperty::OnKillfocusSchedCmdEdit()
  723. {
  724. CString strOldText;
  725. strOldText = m_strEofCommand;
  726. UpdateData ( TRUE );
  727. if ( 0 != strOldText.Compare ( m_strEofCommand ) ) {
  728. // Todo: Set the query PASSWORD_DIRTY flag only when m_bExecEofCommand is TRUE
  729. // and command has changed.
  730. //
  731. // This must be done before the check for SetRunAs in the base class
  732. // IsValidData() method.
  733. if( !m_pQuery->m_strUser.IsEmpty() ) {
  734. if( !( m_pQuery->m_strUser.GetAt(0) == L'<' ) ) {
  735. m_pQuery->m_fDirtyPassword |= PASSWORD_DIRTY;
  736. }
  737. }
  738. SetModifiedPage(TRUE);
  739. }
  740. }
  741. void CScheduleProperty::OnKillfocusSchedStopAfterEdit()
  742. {
  743. DWORD dwOldValue;
  744. dwOldValue = m_dwStopAfterCount;
  745. UpdateData ( TRUE );
  746. if (dwOldValue != m_dwStopAfterCount) {
  747. SetModifiedPage(TRUE);
  748. }
  749. }
  750. void
  751. CScheduleProperty::OnKillfocusSchedStartAtDt(NMHDR* /* pNMHDR */, LRESULT* /*pResult */)
  752. {
  753. SYSTEMTIME stOldTime;
  754. stOldTime = m_stStartAt;
  755. UpdateData ( TRUE );
  756. if ( stOldTime.wHour != m_stStartAt.wHour
  757. || stOldTime.wDay != m_stStartAt.wDay
  758. || stOldTime.wMinute != m_stStartAt.wMinute
  759. || stOldTime.wSecond != m_stStartAt.wSecond
  760. || stOldTime.wMonth != m_stStartAt.wMonth
  761. || stOldTime.wYear != m_stStartAt.wYear ) {
  762. SetModifiedPage(TRUE);
  763. }
  764. }
  765. void
  766. CScheduleProperty::OnKillfocusSchedStopAtDt(NMHDR* /* pNMHDR */, LRESULT* /*pResult */)
  767. {
  768. SYSTEMTIME stOldTime;
  769. stOldTime = m_stStopAt;
  770. UpdateData ( TRUE );
  771. if ( stOldTime.wHour != m_stStopAt.wHour
  772. || stOldTime.wDay != m_stStopAt.wDay
  773. || stOldTime.wMinute != m_stStopAt.wMinute
  774. || stOldTime.wSecond != m_stStopAt.wSecond
  775. || stOldTime.wMonth != m_stStopAt.wMonth
  776. || stOldTime.wYear != m_stStopAt.wYear ) {
  777. SetModifiedPage(TRUE);
  778. }
  779. }
  780. void CScheduleProperty::OnDeltaposSchedStopAfterSpin(NMHDR* pNMHDR, LRESULT* pResult)
  781. {
  782. OnDeltaposSpin(pNMHDR, pResult, & m_dwStopAfterCount, 1, 100000);
  783. }
  784. void
  785. CScheduleProperty::OnSelendokSchedStopAfterUnitsCombo()
  786. {
  787. int nSel;
  788. nSel = ((CComboBox *)GetDlgItem(IDC_SCHED_STOP_AFTER_UNITS_COMBO))->GetCurSel();
  789. if ((nSel != LB_ERR) && (nSel != m_nStopAfterUnits)) {
  790. UpdateData ( TRUE );
  791. SetModifiedPage ( TRUE );
  792. }
  793. }
  794. BOOL
  795. CScheduleProperty::OnSetActive()
  796. {
  797. CString strTemp;
  798. BOOL bEnableSizeRdo;
  799. BOOL bReturn;
  800. bReturn = CSmPropertyPage::OnSetActive();
  801. if ( bReturn ) {
  802. ResourceStateManager rsm;
  803. m_pQuery->GetPropPageSharedData ( &m_SharedData );
  804. UpdateData ( FALSE );
  805. // Set size radio button string and state
  806. strTemp.Empty();
  807. if ( SLQ_DISK_MAX_SIZE == m_SharedData.dwMaxFileSize ) {
  808. strTemp.Format ( IDS_SCHED_FILE_MAX_SIZE_DISPLAY );
  809. } else {
  810. if (m_SharedData.dwLogFileType == SLF_SQL_LOG) {
  811. strTemp.Format ( IDS_SCHED_LOG_SET_DISPLAY, m_SharedData.dwMaxFileSize );
  812. }
  813. else {
  814. strTemp.Format ( IDS_SCHED_FILE_SIZE_DISPLAY, m_SharedData.dwMaxFileSize );
  815. }
  816. }
  817. SetDlgItemText( IDC_SCHED_STOP_SIZE_RDO, strTemp );
  818. bEnableSizeRdo = ( SLF_BIN_CIRC_FILE != m_SharedData.dwLogFileType )
  819. && ( SLF_CIRC_TRACE_FILE != m_SharedData.dwLogFileType )
  820. && ( SLQ_DISK_MAX_SIZE != m_SharedData.dwMaxFileSize );
  821. GetDlgItem(IDC_SCHED_STOP_SIZE_RDO)->EnableWindow(bEnableSizeRdo);
  822. SetStartBtnState();
  823. SetStopBtnState();
  824. }
  825. return bReturn;
  826. }
  827. BOOL CScheduleProperty::OnKillActive()
  828. {
  829. BOOL bContinue;
  830. bContinue = CPropertyPage::OnKillActive();
  831. if ( bContinue ) {
  832. bContinue = IsValidData(m_pQuery, VALIDATE_FOCUS );
  833. }
  834. if ( bContinue ) {
  835. FillStartTimeStruct ( &m_SharedData.stiStartTime );
  836. UpdateSharedStopTimeStruct();
  837. m_pQuery->SetPropPageSharedData ( &m_SharedData );
  838. }
  839. if ( bContinue ) {
  840. SetIsActive ( FALSE );
  841. }
  842. return bContinue;
  843. }
  844. void
  845. CScheduleProperty::PostNcDestroy()
  846. {
  847. // delete this;
  848. CPropertyPage::PostNcDestroy();
  849. }