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.

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