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.

579 lines
12 KiB

  1. // DPSchedulePage.cpp : implementation file
  2. //
  3. // Copyright (c) Microsoft Corporation
  4. //
  5. // 03/24/00 v-marfin 62368 : fix for hours to seconds conversion.
  6. //
  7. //
  8. #include "stdafx.h"
  9. #include "snapin.h"
  10. #include "DPSchedulePage.h"
  11. #include "HMObject.h"
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CDPSchedulePage property page
  19. IMPLEMENT_DYNCREATE(CDPSchedulePage, CHMPropertyPage)
  20. CDPSchedulePage::CDPSchedulePage() : CHMPropertyPage(CDPSchedulePage::IDD)
  21. {
  22. //{{AFX_DATA_INIT(CDPSchedulePage)
  23. m_bFriday = FALSE;
  24. m_bMonday = FALSE;
  25. m_bSaturday = FALSE;
  26. m_bSunday = FALSE;
  27. m_bThursday = FALSE;
  28. m_bTuesday = FALSE;
  29. m_bWednesday = FALSE;
  30. m_EndTime_1 = CTime::GetCurrentTime();
  31. m_EndTime_2 = CTime::GetCurrentTime();
  32. m_StartTime_1 = CTime::GetCurrentTime();
  33. m_StartTime_2 = CTime::GetCurrentTime();
  34. m_iTotalSamples = 0;
  35. m_iDataCollection = -1;
  36. m_iCollectionIntervalTime = 0;
  37. //}}AFX_DATA_INIT
  38. m_sHelpTopic = _T("HMon21.chm::dDEsched.htm");
  39. }
  40. CDPSchedulePage::~CDPSchedulePage()
  41. {
  42. }
  43. void CDPSchedulePage::DoDataExchange(CDataExchange* pDX)
  44. {
  45. CHMPropertyPage::DoDataExchange(pDX);
  46. //{{AFX_DATA_MAP(CDPSchedulePage)
  47. DDX_Control(pDX, IDC_DATETIMEPICKER_START_2, m_StartTimeCtrl2);
  48. DDX_Control(pDX, IDC_DATETIMEPICKER_START_1, m_StartTimeCtrl1);
  49. DDX_Control(pDX, IDC_DATETIMEPICKER_END_2, m_EndTimeCtrl2);
  50. DDX_Control(pDX, IDC_DATETIMEPICKER_END_1, m_EndTimeCtrl1);
  51. DDX_Control(pDX, IDC_SPIN2, m_Spin2);
  52. DDX_Control(pDX, IDC_SPIN1, m_Spin1);
  53. DDX_Control(pDX, IDC_COMBO_UNITS, m_Units);
  54. DDX_Check(pDX, IDC_CHECK_FRIDAY, m_bFriday);
  55. DDX_Check(pDX, IDC_CHECK_MONDAY, m_bMonday);
  56. DDX_Check(pDX, IDC_CHECK_SATURDAY, m_bSaturday);
  57. DDX_Check(pDX, IDC_CHECK_SUNDAY, m_bSunday);
  58. DDX_Check(pDX, IDC_CHECK_THURSDAY, m_bThursday);
  59. DDX_Check(pDX, IDC_CHECK_TUESDAY, m_bTuesday);
  60. DDX_Check(pDX, IDC_CHECK_WEDNESDAY, m_bWednesday);
  61. DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_END_1, m_EndTime_1);
  62. DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_END_2, m_EndTime_2);
  63. DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_START_1, m_StartTime_1);
  64. DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_START_2, m_StartTime_2);
  65. DDX_Text(pDX, IDC_EDIT_TOTAL_SAMPLES, m_iTotalSamples);
  66. DDX_Radio(pDX, IDC_RADIO_ALL_DAY, m_iDataCollection);
  67. DDX_Text(pDX, IDC_EDIT_DATA_COLLECT_INTERVAL, m_iCollectionIntervalTime);
  68. //}}AFX_DATA_MAP
  69. if( pDX->m_bSaveAndValidate )
  70. {
  71. m_iActiveDays = 0;
  72. if( m_bSunday )
  73. {
  74. m_iActiveDays |= 0x00000001;
  75. }
  76. if( m_bMonday )
  77. {
  78. m_iActiveDays |= 0x00000002;
  79. }
  80. if( m_bTuesday )
  81. {
  82. m_iActiveDays |= 0x00000004;
  83. }
  84. if( m_bWednesday )
  85. {
  86. m_iActiveDays |= 0x00000008;
  87. }
  88. if( m_bThursday )
  89. {
  90. m_iActiveDays |= 0x00000010;
  91. }
  92. if( m_bFriday )
  93. {
  94. m_iActiveDays |= 0x00000020;
  95. }
  96. if( m_bSaturday )
  97. {
  98. m_iActiveDays |= 0x00000040;
  99. }
  100. }
  101. switch( m_iDataCollection )
  102. {
  103. case 0:
  104. {
  105. GetDlgItem(IDC_DATETIMEPICKER_START_2)->EnableWindow(FALSE);
  106. GetDlgItem(IDC_DATETIMEPICKER_END_2)->EnableWindow(FALSE);
  107. GetDlgItem(IDC_DATETIMEPICKER_START_1)->EnableWindow(FALSE);
  108. GetDlgItem(IDC_DATETIMEPICKER_END_1)->EnableWindow(FALSE);
  109. }
  110. break;
  111. case 1:
  112. {
  113. GetDlgItem(IDC_DATETIMEPICKER_START_2)->EnableWindow(FALSE);
  114. GetDlgItem(IDC_DATETIMEPICKER_END_2)->EnableWindow(FALSE);
  115. GetDlgItem(IDC_DATETIMEPICKER_START_1)->EnableWindow(TRUE);
  116. GetDlgItem(IDC_DATETIMEPICKER_END_1)->EnableWindow(TRUE);
  117. }
  118. break;
  119. case 2:
  120. {
  121. GetDlgItem(IDC_DATETIMEPICKER_START_2)->EnableWindow(TRUE);
  122. GetDlgItem(IDC_DATETIMEPICKER_END_2)->EnableWindow(TRUE);
  123. GetDlgItem(IDC_DATETIMEPICKER_START_1)->EnableWindow(FALSE);
  124. GetDlgItem(IDC_DATETIMEPICKER_END_1)->EnableWindow(FALSE);
  125. }
  126. break;
  127. }
  128. }
  129. BEGIN_MESSAGE_MAP(CDPSchedulePage, CHMPropertyPage)
  130. //{{AFX_MSG_MAP(CDPSchedulePage)
  131. ON_BN_CLICKED(IDC_RADIO_ALL_DAY, OnRadioAllDay)
  132. ON_BN_CLICKED(IDC_RADIO_ALL_DAY_EXCEPT, OnRadioAllDayExcept)
  133. ON_BN_CLICKED(IDC_RADIO_ONCE_DAILY, OnRadioOnceDaily)
  134. ON_BN_CLICKED(IDC_RADIO_ONLY_FROM, OnRadioOnlyFrom)
  135. ON_BN_CLICKED(IDC_CHECK_FRIDAY, OnCheckFriday)
  136. ON_BN_CLICKED(IDC_CHECK_MONDAY, OnCheckMonday)
  137. ON_BN_CLICKED(IDC_CHECK_SATURDAY, OnCheckSaturday)
  138. ON_BN_CLICKED(IDC_CHECK_SUNDAY, OnCheckSunday)
  139. ON_BN_CLICKED(IDC_CHECK_THURSDAY, OnCheckThursday)
  140. ON_BN_CLICKED(IDC_CHECK_TUESDAY, OnCheckTuesday)
  141. ON_BN_CLICKED(IDC_CHECK_WEDNESDAY, OnCheckWednesday)
  142. ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER_END_1, OnDatetimechangeDatetimepickerEnd1)
  143. ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER_END_2, OnDatetimechangeDatetimepickerEnd2)
  144. ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER_ONCE, OnDatetimechangeDatetimepickerOnce)
  145. ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER_START_1, OnDatetimechangeDatetimepickerStart1)
  146. ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER_START_2, OnDatetimechangeDatetimepickerStart2)
  147. ON_EN_CHANGE(IDC_EDIT_TOTAL_SAMPLES, OnChangeEditTotalSamples)
  148. ON_EN_CHANGE(IDC_EDIT_DATA_COLLECT_INTERVAL, OnChangeEditDataCollectInterval)
  149. //}}AFX_MSG_MAP
  150. END_MESSAGE_MAP()
  151. /////////////////////////////////////////////////////////////////////////////
  152. // CDPSchedulePage message handlers
  153. BOOL CDPSchedulePage::OnInitDialog()
  154. {
  155. CHMPropertyPage::OnInitDialog();
  156. CWbemClassObject* pClassObject = GetObjectPtr()->GetClassObject();
  157. if( ! GfxCheckObjPtr(pClassObject,CWbemClassObject) )
  158. {
  159. return FALSE;
  160. }
  161. // get the active days
  162. pClassObject->GetProperty(IDS_STRING_MOF_ACTIVEDAYS,m_iActiveDays);
  163. // get the begin time
  164. int iBeginHour;
  165. int iBeginMinute;
  166. CString sBeginTime;
  167. pClassObject->GetProperty(IDS_STRING_MOF_BEGINTIME,sBeginTime);
  168. if( sBeginTime.IsEmpty() )
  169. {
  170. iBeginHour = 0;
  171. iBeginMinute = 0;
  172. }
  173. else
  174. {
  175. sBeginTime = sBeginTime.Right(17);
  176. sBeginTime = sBeginTime.Left(4);
  177. _stscanf(sBeginTime,_T("%02d%02d"), &iBeginHour, &iBeginMinute);
  178. }
  179. // get the end time
  180. int iEndHour;
  181. int iEndMinute;
  182. CString sEndTime;
  183. pClassObject->GetProperty(IDS_STRING_MOF_ENDTIME,sEndTime);
  184. if( sEndTime.IsEmpty() )
  185. {
  186. iEndHour = 23;
  187. iEndMinute = 59;
  188. }
  189. else
  190. {
  191. sEndTime = sEndTime.Right(17);
  192. sEndTime = sEndTime.Left(4);
  193. _stscanf(sEndTime,_T("%02d%02d"), &iEndHour, &iEndMinute);
  194. }
  195. pClassObject->GetProperty(IDS_STRING_MOF_COLLECTIONINTERVAL,m_iCollectionInterval);
  196. pClassObject->GetProperty(IDS_STRING_MOF_STATISTICSWINDOW,m_iTotalSamples);
  197. delete pClassObject;
  198. pClassObject = NULL;
  199. m_iCollectionIntervalTime = m_iCollectionInterval;
  200. if( iBeginHour == 0 && iBeginMinute == 0 && iEndHour == 23 && iEndMinute == 59 )
  201. {
  202. m_iDataCollection = 0;
  203. }
  204. else if( iBeginHour > iEndHour )
  205. {
  206. m_iDataCollection = 2;
  207. m_EndTime_2 = CTime(1999,12,31,iBeginHour,iBeginMinute,0);
  208. m_StartTime_2 = CTime(1999,12,31,iEndHour,iEndMinute,0);
  209. }
  210. else
  211. {
  212. m_iDataCollection = 1;
  213. m_StartTime_1 = CTime(1999,12,31,iBeginHour,iBeginMinute,0);
  214. m_EndTime_1 = CTime(1999,12,31,iEndHour,iEndMinute,0);
  215. }
  216. if( m_iActiveDays & 0x00000001 )
  217. {
  218. m_bSunday = TRUE;
  219. }
  220. if( m_iActiveDays & 0x00000002 )
  221. {
  222. m_bMonday = TRUE;
  223. }
  224. if( m_iActiveDays & 0x00000004 )
  225. {
  226. m_bTuesday = TRUE;
  227. }
  228. if( m_iActiveDays & 0x00000008 )
  229. {
  230. m_bWednesday = TRUE;
  231. }
  232. if( m_iActiveDays & 0x00000010 )
  233. {
  234. m_bThursday = TRUE;
  235. }
  236. if( m_iActiveDays & 0x00000020 )
  237. {
  238. m_bFriday = TRUE;
  239. }
  240. if( m_iActiveDays & 0x00000040 )
  241. {
  242. m_bSaturday = TRUE;
  243. }
  244. m_Units.SetCurSel(0);
  245. m_Spin1.SetRange32(0,INT_MAX-1);
  246. m_Spin2.SetRange32(0,INT_MAX-1);
  247. CString sTimeFormat;
  248. int iLen = GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_STIMEFORMAT,NULL,0);
  249. GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_STIMEFORMAT,sTimeFormat.GetBuffer(iLen+1),iLen);
  250. sTimeFormat.ReleaseBuffer();
  251. int iIndex = sTimeFormat.Find(_T(":ss"));
  252. if( iIndex != -1 )
  253. {
  254. sTimeFormat.Delete(iIndex,3);
  255. }
  256. iIndex = sTimeFormat.Find(_T(":s"));
  257. if( iIndex != -1 )
  258. {
  259. sTimeFormat.Delete(iIndex,2);
  260. }
  261. m_StartTimeCtrl2.SetFormat(sTimeFormat);
  262. m_StartTimeCtrl1.SetFormat(sTimeFormat);
  263. m_EndTimeCtrl2.SetFormat(sTimeFormat);
  264. m_EndTimeCtrl1.SetFormat(sTimeFormat);
  265. UpdateData(FALSE);
  266. return TRUE; // return TRUE unless you set the focus to a control
  267. // EXCEPTION: OCX Property Pages should return FALSE
  268. }
  269. void CDPSchedulePage::OnOK()
  270. {
  271. CHMPropertyPage::OnOK();
  272. }
  273. void CDPSchedulePage::OnRadioAllDay()
  274. {
  275. UpdateData();
  276. SetModified();
  277. }
  278. void CDPSchedulePage::OnRadioAllDayExcept()
  279. {
  280. UpdateData();
  281. SetModified();
  282. }
  283. void CDPSchedulePage::OnRadioOnceDaily()
  284. {
  285. UpdateData();
  286. SetModified();
  287. }
  288. void CDPSchedulePage::OnRadioOnlyFrom()
  289. {
  290. UpdateData();
  291. SetModified();
  292. }
  293. BOOL CDPSchedulePage::OnApply()
  294. {
  295. if( ! CHMPropertyPage::OnApply() )
  296. {
  297. return FALSE;
  298. }
  299. UpdateData();
  300. switch( m_Units.GetCurSel() )
  301. {
  302. case 0: // seconds
  303. {
  304. if( m_iCollectionIntervalTime == 0 )
  305. {
  306. AfxMessageBox(IDS_STRING_WRONG_COLLECTION_VALUE);
  307. return FALSE;
  308. }
  309. else
  310. {
  311. m_iCollectionInterval = m_iCollectionIntervalTime;
  312. }
  313. }
  314. break;
  315. case 1: // minutes
  316. {
  317. m_iCollectionInterval = (m_iCollectionIntervalTime*60);
  318. }
  319. break;
  320. case 2: // hours
  321. {
  322. // v-marfin 62368 : fix for hours to seconds conversion.
  323. m_iCollectionInterval = (m_iCollectionIntervalTime*(60*60));
  324. }
  325. break;
  326. }
  327. int iBeginHour=0;
  328. int iBeginMinute=0;
  329. int iEndHour=0;
  330. int iEndMinute=0;
  331. switch( m_iDataCollection )
  332. {
  333. case 0: // all day
  334. {
  335. iBeginHour = iBeginMinute = 0;
  336. iEndHour = 23;
  337. iEndMinute = 59;
  338. }
  339. break;
  340. case 1: // only from x to y
  341. {
  342. iBeginHour = m_StartTime_1.GetHour();
  343. iBeginMinute = m_StartTime_1.GetMinute();
  344. iEndHour = m_EndTime_1.GetHour();
  345. iEndMinute = m_EndTime_1.GetMinute();
  346. }
  347. break;
  348. case 2: // all day except x to y
  349. {
  350. iBeginHour = m_EndTime_2.GetHour();
  351. iBeginMinute = m_EndTime_2.GetMinute();
  352. iEndHour = m_StartTime_2.GetHour();
  353. iEndMinute = m_StartTime_2.GetMinute();
  354. }
  355. break;
  356. }
  357. // update the agent object
  358. CWbemClassObject* pClassObject = GetObjectPtr()->GetClassObject();
  359. if( ! GfxCheckObjPtr(pClassObject,CWbemClassObject) )
  360. {
  361. return FALSE;
  362. }
  363. // set the active days
  364. pClassObject->SetProperty(IDS_STRING_MOF_ACTIVEDAYS,m_iActiveDays);
  365. // set the begin time
  366. CString sTime;
  367. sTime.Format(_T("********%02d%02d**.******+***"),iBeginHour,iBeginMinute);
  368. pClassObject->SetProperty(IDS_STRING_MOF_BEGINTIME,sTime);
  369. // set the end time
  370. sTime.Format(_T("********%02d%02d**.******+***"),iEndHour,iEndMinute);
  371. pClassObject->SetProperty(IDS_STRING_MOF_ENDTIME,sTime);
  372. pClassObject->SetProperty(IDS_STRING_MOF_COLLECTIONINTERVAL,m_iCollectionInterval);
  373. pClassObject->SetProperty(IDS_STRING_MOF_STATISTICSWINDOW,m_iTotalSamples);
  374. pClassObject->SaveAllProperties();
  375. delete pClassObject;
  376. SetModified(FALSE);
  377. return TRUE;
  378. }
  379. void CDPSchedulePage::OnCheckFriday()
  380. {
  381. UpdateData();
  382. SetModified();
  383. }
  384. void CDPSchedulePage::OnCheckMonday()
  385. {
  386. UpdateData();
  387. SetModified();
  388. }
  389. void CDPSchedulePage::OnCheckSaturday()
  390. {
  391. UpdateData();
  392. SetModified();
  393. }
  394. void CDPSchedulePage::OnCheckSunday()
  395. {
  396. UpdateData();
  397. SetModified();
  398. }
  399. void CDPSchedulePage::OnCheckThursday()
  400. {
  401. UpdateData();
  402. SetModified();
  403. }
  404. void CDPSchedulePage::OnCheckTuesday()
  405. {
  406. UpdateData();
  407. SetModified();
  408. }
  409. void CDPSchedulePage::OnCheckWednesday()
  410. {
  411. UpdateData();
  412. SetModified();
  413. }
  414. void CDPSchedulePage::OnDatetimechangeDatetimepickerEnd1(NMHDR* pNMHDR, LRESULT* pResult)
  415. {
  416. UpdateData();
  417. SetModified();
  418. *pResult = 0;
  419. }
  420. void CDPSchedulePage::OnDatetimechangeDatetimepickerEnd2(NMHDR* pNMHDR, LRESULT* pResult)
  421. {
  422. UpdateData();
  423. SetModified();
  424. *pResult = 0;
  425. }
  426. void CDPSchedulePage::OnDatetimechangeDatetimepickerOnce(NMHDR* pNMHDR, LRESULT* pResult)
  427. {
  428. UpdateData();
  429. SetModified();
  430. *pResult = 0;
  431. }
  432. void CDPSchedulePage::OnDatetimechangeDatetimepickerStart1(NMHDR* pNMHDR, LRESULT* pResult)
  433. {
  434. UpdateData();
  435. SetModified();
  436. *pResult = 0;
  437. }
  438. void CDPSchedulePage::OnDatetimechangeDatetimepickerStart2(NMHDR* pNMHDR, LRESULT* pResult)
  439. {
  440. UpdateData();
  441. SetModified();
  442. *pResult = 0;
  443. }
  444. void CDPSchedulePage::OnChangeEditTotalSamples()
  445. {
  446. // TODO: If this is a RICHEDIT control, the control will not
  447. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  448. // function and call CRichEditCtrl().SetEventMask()
  449. // with the ENM_CHANGE flag ORed into the mask.
  450. if( ! m_Units.GetSafeHwnd() )
  451. return;
  452. UpdateData();
  453. SetModified();
  454. }
  455. void CDPSchedulePage::OnChangeEditDataCollectInterval()
  456. {
  457. // TODO: If this is a RICHEDIT control, the control will not
  458. // send this notification unless you override the CHMPropertyPage::OnInitDialog()
  459. // function and call CRichEditCtrl().SetEventMask()
  460. // with the ENM_CHANGE flag ORed into the mask.
  461. if( ! m_Units.GetSafeHwnd() )
  462. return;
  463. UpdateData();
  464. SetModified();
  465. }