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.

474 lines
10 KiB

  1. // ActionSchedulePage.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "snapin.h"
  5. #include "ActionSchedulePage.h"
  6. #include "Action.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CActionSchedulePage property page
  14. IMPLEMENT_DYNCREATE(CActionSchedulePage, CHMPropertyPage)
  15. CActionSchedulePage::CActionSchedulePage() : CHMPropertyPage(CActionSchedulePage::IDD)
  16. {
  17. //{{AFX_DATA_INIT(CActionSchedulePage)
  18. m_bFriday = FALSE;
  19. m_bMonday = FALSE;
  20. m_bSaturday = FALSE;
  21. m_bSunday = FALSE;
  22. m_bThursday = FALSE;
  23. m_bTuesday = FALSE;
  24. m_bWednesday = FALSE;
  25. m_EndTime_1 = CTime::GetCurrentTime();
  26. m_EndTime_2 = CTime::GetCurrentTime();
  27. m_StartTime_1 = CTime::GetCurrentTime();
  28. m_StartTime_2 = CTime::GetCurrentTime();
  29. m_iDataCollection = -1;
  30. //}}AFX_DATA_INIT
  31. m_sHelpTopic = _T("HMon21.chm::/dactsked.htm");
  32. }
  33. CActionSchedulePage::~CActionSchedulePage()
  34. {
  35. }
  36. void CActionSchedulePage::DoDataExchange(CDataExchange* pDX)
  37. {
  38. CHMPropertyPage::DoDataExchange(pDX);
  39. //{{AFX_DATA_MAP(CActionSchedulePage)
  40. DDX_Control(pDX, IDC_DATETIMEPICKER_START_2, m_StartTimeCtrl2);
  41. DDX_Control(pDX, IDC_DATETIMEPICKER_START_1, m_StartTimeCtrl1);
  42. DDX_Control(pDX, IDC_DATETIMEPICKER_END_2, m_EndTimeCtrl2);
  43. DDX_Control(pDX, IDC_DATETIMEPICKER_END_1, m_EndTimeCtrl1);
  44. DDX_Check(pDX, IDC_CHECK_FRIDAY, m_bFriday);
  45. DDX_Check(pDX, IDC_CHECK_MONDAY, m_bMonday);
  46. DDX_Check(pDX, IDC_CHECK_SATURDAY, m_bSaturday);
  47. DDX_Check(pDX, IDC_CHECK_SUNDAY, m_bSunday);
  48. DDX_Check(pDX, IDC_CHECK_THURSDAY, m_bThursday);
  49. DDX_Check(pDX, IDC_CHECK_TUESDAY, m_bTuesday);
  50. DDX_Check(pDX, IDC_CHECK_WEDNESDAY, m_bWednesday);
  51. DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_END_1, m_EndTime_1);
  52. DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_END_2, m_EndTime_2);
  53. DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_START_1, m_StartTime_1);
  54. DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_START_2, m_StartTime_2);
  55. DDX_Radio(pDX, IDC_RADIO_ALL_DAY, m_iDataCollection);
  56. //}}AFX_DATA_MAP
  57. if( pDX->m_bSaveAndValidate )
  58. {
  59. m_iActiveDays = 0;
  60. if( m_bSunday )
  61. {
  62. m_iActiveDays |= 0x00000001;
  63. }
  64. if( m_bMonday )
  65. {
  66. m_iActiveDays |= 0x00000002;
  67. }
  68. if( m_bTuesday )
  69. {
  70. m_iActiveDays |= 0x00000004;
  71. }
  72. if( m_bWednesday )
  73. {
  74. m_iActiveDays |= 0x00000008;
  75. }
  76. if( m_bThursday )
  77. {
  78. m_iActiveDays |= 0x00000010;
  79. }
  80. if( m_bFriday )
  81. {
  82. m_iActiveDays |= 0x00000020;
  83. }
  84. if( m_bSaturday )
  85. {
  86. m_iActiveDays |= 0x00000040;
  87. }
  88. }
  89. switch( m_iDataCollection )
  90. {
  91. case 0:
  92. {
  93. GetDlgItem(IDC_DATETIMEPICKER_START_2)->EnableWindow(FALSE);
  94. GetDlgItem(IDC_DATETIMEPICKER_END_2)->EnableWindow(FALSE);
  95. GetDlgItem(IDC_DATETIMEPICKER_START_1)->EnableWindow(FALSE);
  96. GetDlgItem(IDC_DATETIMEPICKER_END_1)->EnableWindow(FALSE);
  97. }
  98. break;
  99. case 1:
  100. {
  101. GetDlgItem(IDC_DATETIMEPICKER_START_2)->EnableWindow(FALSE);
  102. GetDlgItem(IDC_DATETIMEPICKER_END_2)->EnableWindow(FALSE);
  103. GetDlgItem(IDC_DATETIMEPICKER_START_1)->EnableWindow(TRUE);
  104. GetDlgItem(IDC_DATETIMEPICKER_END_1)->EnableWindow(TRUE);
  105. }
  106. break;
  107. case 2:
  108. {
  109. GetDlgItem(IDC_DATETIMEPICKER_START_2)->EnableWindow(TRUE);
  110. GetDlgItem(IDC_DATETIMEPICKER_END_2)->EnableWindow(TRUE);
  111. GetDlgItem(IDC_DATETIMEPICKER_START_1)->EnableWindow(FALSE);
  112. GetDlgItem(IDC_DATETIMEPICKER_END_1)->EnableWindow(FALSE);
  113. }
  114. break;
  115. }
  116. }
  117. BEGIN_MESSAGE_MAP(CActionSchedulePage, CHMPropertyPage)
  118. //{{AFX_MSG_MAP(CActionSchedulePage)
  119. ON_BN_CLICKED(IDC_CHECK_FRIDAY, OnCheckFriday)
  120. ON_BN_CLICKED(IDC_CHECK_MONDAY, OnCheckMonday)
  121. ON_BN_CLICKED(IDC_CHECK_SATURDAY, OnCheckSaturday)
  122. ON_BN_CLICKED(IDC_CHECK_SUNDAY, OnCheckSunday)
  123. ON_BN_CLICKED(IDC_CHECK_THURSDAY, OnCheckThursday)
  124. ON_BN_CLICKED(IDC_CHECK_TUESDAY, OnCheckTuesday)
  125. ON_BN_CLICKED(IDC_CHECK_WEDNESDAY, OnCheckWednesday)
  126. ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER_END_1, OnDatetimechangeDatetimepickerEnd1)
  127. ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER_END_2, OnDatetimechangeDatetimepickerEnd2)
  128. ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER_ONCE, OnDatetimechangeDatetimepickerOnce)
  129. ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER_START_1, OnDatetimechangeDatetimepickerStart1)
  130. ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER_START_2, OnDatetimechangeDatetimepickerStart2)
  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. //}}AFX_MSG_MAP
  136. END_MESSAGE_MAP()
  137. /////////////////////////////////////////////////////////////////////////////
  138. // CActionSchedulePage message handlers
  139. BOOL CActionSchedulePage::OnInitDialog()
  140. {
  141. CHMPropertyPage::OnInitDialog();
  142. CWbemClassObject* pClassObject = GetObjectPtr()->GetClassObject();
  143. if( ! GfxCheckObjPtr(pClassObject,CWbemClassObject) )
  144. {
  145. return FALSE;
  146. }
  147. // get the active days
  148. pClassObject->GetProperty(IDS_STRING_MOF_ACTIVEDAYS,m_iActiveDays);
  149. // get the begin time
  150. int iBeginHour;
  151. int iBeginMinute;
  152. CString sBeginTime;
  153. pClassObject->GetProperty(IDS_STRING_MOF_BEGINTIME,sBeginTime);
  154. if( sBeginTime.IsEmpty() )
  155. {
  156. iBeginHour = 0;
  157. iBeginMinute = 0;
  158. }
  159. else
  160. {
  161. sBeginTime = sBeginTime.Right(17);
  162. sBeginTime = sBeginTime.Left(4);
  163. _stscanf(sBeginTime,_T("%02d%02d"), &iBeginHour, &iBeginMinute);
  164. }
  165. // get the end time
  166. int iEndHour;
  167. int iEndMinute;
  168. CString sEndTime;
  169. pClassObject->GetProperty(IDS_STRING_MOF_ENDTIME,sEndTime);
  170. if( sEndTime.IsEmpty() )
  171. {
  172. iEndHour = 23;
  173. iEndMinute = 59;
  174. }
  175. else
  176. {
  177. sEndTime = sEndTime.Right(17);
  178. sEndTime = sEndTime.Left(4);
  179. _stscanf(sEndTime,_T("%02d%02d"), &iEndHour, &iEndMinute);
  180. }
  181. delete pClassObject;
  182. pClassObject = NULL;
  183. if( iBeginHour == 0 && iBeginMinute == 0 && iEndHour == 23 && iEndMinute == 59 )
  184. {
  185. m_iDataCollection = 0;
  186. }
  187. else if( iBeginHour > iEndHour )
  188. {
  189. m_iDataCollection = 2;
  190. m_EndTime_2 = CTime(1999,12,31,iBeginHour,iBeginMinute,0);
  191. m_StartTime_2 = CTime(1999,12,31,iEndHour,iEndMinute,0);
  192. }
  193. else
  194. {
  195. m_iDataCollection = 1;
  196. m_StartTime_1 = CTime(1999,12,31,iBeginHour,iBeginMinute,0);
  197. m_EndTime_1 = CTime(1999,12,31,iEndHour,iEndMinute,0);
  198. }
  199. if( m_iActiveDays & 0x00000001 )
  200. {
  201. m_bSunday = TRUE;
  202. }
  203. if( m_iActiveDays & 0x00000002 )
  204. {
  205. m_bMonday = TRUE;
  206. }
  207. if( m_iActiveDays & 0x00000004 )
  208. {
  209. m_bTuesday = TRUE;
  210. }
  211. if( m_iActiveDays & 0x00000008 )
  212. {
  213. m_bWednesday = TRUE;
  214. }
  215. if( m_iActiveDays & 0x00000010 )
  216. {
  217. m_bThursday = TRUE;
  218. }
  219. if( m_iActiveDays & 0x00000020 )
  220. {
  221. m_bFriday = TRUE;
  222. }
  223. if( m_iActiveDays & 0x00000040 )
  224. {
  225. m_bSaturday = TRUE;
  226. }
  227. CString sTimeFormat;
  228. int iLen = GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_STIMEFORMAT,NULL,0);
  229. GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_STIMEFORMAT,sTimeFormat.GetBuffer(iLen+1),iLen);
  230. sTimeFormat.ReleaseBuffer();
  231. int iIndex = sTimeFormat.Find(_T(":ss"));
  232. if( iIndex != -1 )
  233. {
  234. sTimeFormat.Delete(iIndex,3);
  235. }
  236. iIndex = sTimeFormat.Find(_T(":s"));
  237. if( iIndex != -1 )
  238. {
  239. sTimeFormat.Delete(iIndex,2);
  240. }
  241. m_StartTimeCtrl2.SetFormat(sTimeFormat);
  242. m_StartTimeCtrl1.SetFormat(sTimeFormat);
  243. m_EndTimeCtrl2.SetFormat(sTimeFormat);
  244. m_EndTimeCtrl1.SetFormat(sTimeFormat);
  245. UpdateData(FALSE);
  246. return TRUE; // return TRUE unless you set the focus to a control
  247. // EXCEPTION: OCX Property Pages should return FALSE
  248. }
  249. BOOL CActionSchedulePage::OnApply()
  250. {
  251. if( ! CHMPropertyPage::OnApply() )
  252. {
  253. return FALSE;
  254. }
  255. UpdateData();
  256. int iBeginHour=0;
  257. int iBeginMinute=0;
  258. int iEndHour=0;
  259. int iEndMinute=0;
  260. switch( m_iDataCollection )
  261. {
  262. case 0: // all day
  263. {
  264. iBeginHour = iBeginMinute = 0;
  265. iEndHour = 23;
  266. iEndMinute = 59;
  267. }
  268. break;
  269. case 1: // only from x to y
  270. {
  271. iBeginHour = m_StartTime_1.GetHour();
  272. iBeginMinute = m_StartTime_1.GetMinute();
  273. iEndHour = m_EndTime_1.GetHour();
  274. iEndMinute = m_EndTime_1.GetMinute();
  275. }
  276. break;
  277. case 2: // all day except x to y
  278. {
  279. iBeginHour = m_EndTime_2.GetHour();
  280. iBeginMinute = m_EndTime_2.GetMinute();
  281. iEndHour = m_StartTime_2.GetHour();
  282. iEndMinute = m_StartTime_2.GetMinute();
  283. }
  284. break;
  285. }
  286. // update the agent object
  287. CWbemClassObject* pClassObject = GetObjectPtr()->GetClassObject();
  288. if( ! GfxCheckObjPtr(pClassObject,CWbemClassObject) )
  289. {
  290. return FALSE;
  291. }
  292. // set the active days
  293. pClassObject->SetProperty(IDS_STRING_MOF_ACTIVEDAYS,m_iActiveDays);
  294. // set the begin time
  295. CString sTime;
  296. sTime.Format(_T("********%02d%02d**.******+***"),iBeginHour,iBeginMinute);
  297. pClassObject->SetProperty(IDS_STRING_MOF_BEGINTIME,sTime);
  298. // set the end time
  299. sTime.Format(_T("********%02d%02d**.******+***"),iEndHour,iEndMinute);
  300. pClassObject->SetProperty(IDS_STRING_MOF_ENDTIME,sTime);
  301. pClassObject->SaveAllProperties();
  302. delete pClassObject;
  303. SetModified(FALSE);
  304. return TRUE;
  305. }
  306. void CActionSchedulePage::OnCheckFriday()
  307. {
  308. UpdateData();
  309. SetModified();
  310. }
  311. void CActionSchedulePage::OnCheckMonday()
  312. {
  313. UpdateData();
  314. SetModified();
  315. }
  316. void CActionSchedulePage::OnCheckSaturday()
  317. {
  318. UpdateData();
  319. SetModified();
  320. }
  321. void CActionSchedulePage::OnCheckSunday()
  322. {
  323. UpdateData();
  324. SetModified();
  325. }
  326. void CActionSchedulePage::OnCheckThursday()
  327. {
  328. UpdateData();
  329. SetModified();
  330. }
  331. void CActionSchedulePage::OnCheckTuesday()
  332. {
  333. UpdateData();
  334. SetModified();
  335. }
  336. void CActionSchedulePage::OnCheckWednesday()
  337. {
  338. UpdateData();
  339. SetModified();
  340. }
  341. void CActionSchedulePage::OnDatetimechangeDatetimepickerEnd1(NMHDR* pNMHDR, LRESULT* pResult)
  342. {
  343. UpdateData();
  344. SetModified();
  345. *pResult = 0;
  346. }
  347. void CActionSchedulePage::OnDatetimechangeDatetimepickerEnd2(NMHDR* pNMHDR, LRESULT* pResult)
  348. {
  349. UpdateData();
  350. SetModified();
  351. *pResult = 0;
  352. }
  353. void CActionSchedulePage::OnDatetimechangeDatetimepickerOnce(NMHDR* pNMHDR, LRESULT* pResult)
  354. {
  355. UpdateData();
  356. SetModified();
  357. *pResult = 0;
  358. }
  359. void CActionSchedulePage::OnDatetimechangeDatetimepickerStart1(NMHDR* pNMHDR, LRESULT* pResult)
  360. {
  361. UpdateData();
  362. SetModified();
  363. *pResult = 0;
  364. }
  365. void CActionSchedulePage::OnDatetimechangeDatetimepickerStart2(NMHDR* pNMHDR, LRESULT* pResult)
  366. {
  367. UpdateData();
  368. SetModified();
  369. *pResult = 0;
  370. }
  371. void CActionSchedulePage::OnRadioAllDay()
  372. {
  373. UpdateData();
  374. SetModified();
  375. }
  376. void CActionSchedulePage::OnRadioAllDayExcept()
  377. {
  378. UpdateData();
  379. SetModified();
  380. }
  381. void CActionSchedulePage::OnRadioOnceDaily()
  382. {
  383. UpdateData();
  384. SetModified();
  385. }
  386. void CActionSchedulePage::OnRadioOnlyFrom()
  387. {
  388. UpdateData();
  389. SetModified();
  390. }