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.

359 lines
7.5 KiB

  1. // THSchedulePage.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "snapin.h"
  5. #include "THSchedulePage.h"
  6. #include "HMObject.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CTHSchedulePage property page
  14. IMPLEMENT_DYNCREATE(CTHSchedulePage, CHMPropertyPage)
  15. CTHSchedulePage::CTHSchedulePage() : CHMPropertyPage(CTHSchedulePage::IDD)
  16. {
  17. //{{AFX_DATA_INIT(CTHSchedulePage)
  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 = 0;
  26. m_EndTime_2 = 0;
  27. m_OnceDailyTime = 0;
  28. m_StartTime_1 = 0;
  29. m_StartTime_2 = 0;
  30. m_iDataCollection = -1;
  31. //}}AFX_DATA_INIT
  32. m_sHelpTopic = _T("HMon21.chm::/dTHsched.htm");
  33. }
  34. CTHSchedulePage::~CTHSchedulePage()
  35. {
  36. }
  37. void CTHSchedulePage::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CHMPropertyPage::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(CTHSchedulePage)
  41. DDX_Check(pDX, IDC_CHECK_FRIDAY, m_bFriday);
  42. DDX_Check(pDX, IDC_CHECK_MONDAY, m_bMonday);
  43. DDX_Check(pDX, IDC_CHECK_SATURDAY, m_bSaturday);
  44. DDX_Check(pDX, IDC_CHECK_SUNDAY, m_bSunday);
  45. DDX_Check(pDX, IDC_CHECK_THURSDAY, m_bThursday);
  46. DDX_Check(pDX, IDC_CHECK_TUESDAY, m_bTuesday);
  47. DDX_Check(pDX, IDC_CHECK_WEDNESDAY, m_bWednesday);
  48. DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_END_1, m_EndTime_1);
  49. DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_END_2, m_EndTime_2);
  50. DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_ONCE, m_OnceDailyTime);
  51. DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_START_1, m_StartTime_1);
  52. DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_START_2, m_StartTime_2);
  53. DDX_Radio(pDX, IDC_RADIO_ALL_DAY, m_iDataCollection);
  54. //}}AFX_DATA_MAP
  55. if( pDX->m_bSaveAndValidate )
  56. {
  57. m_iActiveDays = 0;
  58. if( m_bSunday )
  59. {
  60. m_iActiveDays |= 0x00000001;
  61. }
  62. if( m_bMonday )
  63. {
  64. m_iActiveDays |= 0x00000002;
  65. }
  66. if( m_bTuesday )
  67. {
  68. m_iActiveDays |= 0x00000004;
  69. }
  70. if( m_bWednesday )
  71. {
  72. m_iActiveDays |= 0x00000008;
  73. }
  74. if( m_bThursday )
  75. {
  76. m_iActiveDays |= 0x00000010;
  77. }
  78. if( m_bFriday )
  79. {
  80. m_iActiveDays |= 0x00000020;
  81. }
  82. if( m_bSaturday )
  83. {
  84. m_iActiveDays |= 0x00000040;
  85. }
  86. }
  87. switch( m_iDataCollection )
  88. {
  89. case 0:
  90. {
  91. GetDlgItem(IDC_DATETIMEPICKER_START_2)->EnableWindow(FALSE);
  92. GetDlgItem(IDC_DATETIMEPICKER_END_2)->EnableWindow(FALSE);
  93. GetDlgItem(IDC_DATETIMEPICKER_ONCE)->EnableWindow(FALSE);
  94. GetDlgItem(IDC_DATETIMEPICKER_START_1)->EnableWindow(FALSE);
  95. GetDlgItem(IDC_DATETIMEPICKER_END_1)->EnableWindow(FALSE);
  96. }
  97. break;
  98. case 1:
  99. {
  100. GetDlgItem(IDC_DATETIMEPICKER_START_2)->EnableWindow(FALSE);
  101. GetDlgItem(IDC_DATETIMEPICKER_END_2)->EnableWindow(FALSE);
  102. GetDlgItem(IDC_DATETIMEPICKER_ONCE)->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_ONCE)->EnableWindow(FALSE);
  112. GetDlgItem(IDC_DATETIMEPICKER_START_1)->EnableWindow(FALSE);
  113. GetDlgItem(IDC_DATETIMEPICKER_END_1)->EnableWindow(FALSE);
  114. }
  115. break;
  116. case 3:
  117. {
  118. GetDlgItem(IDC_DATETIMEPICKER_START_2)->EnableWindow(FALSE);
  119. GetDlgItem(IDC_DATETIMEPICKER_END_2)->EnableWindow(FALSE);
  120. GetDlgItem(IDC_DATETIMEPICKER_ONCE)->EnableWindow(TRUE);
  121. GetDlgItem(IDC_DATETIMEPICKER_START_1)->EnableWindow(FALSE);
  122. GetDlgItem(IDC_DATETIMEPICKER_END_1)->EnableWindow(FALSE);
  123. }
  124. break;
  125. }
  126. }
  127. BEGIN_MESSAGE_MAP(CTHSchedulePage, CHMPropertyPage)
  128. //{{AFX_MSG_MAP(CTHSchedulePage)
  129. ON_BN_CLICKED(IDC_RADIO_ALL_DAY, OnRadioAllDay)
  130. ON_BN_CLICKED(IDC_RADIO_ALL_DAY_EXCEPT, OnRadioAllDayExcept)
  131. ON_BN_CLICKED(IDC_RADIO_ONCE_DAILY, OnRadioOnceDaily)
  132. ON_BN_CLICKED(IDC_RADIO_ONLY_FROM, OnRadioOnlyFrom)
  133. //}}AFX_MSG_MAP
  134. END_MESSAGE_MAP()
  135. /////////////////////////////////////////////////////////////////////////////
  136. // CTHSchedulePage message handlers
  137. BOOL CTHSchedulePage::OnInitDialog()
  138. {
  139. CHMPropertyPage::OnInitDialog();
  140. CHMObject* pObject = GetObjectPtr();
  141. if( ! pObject )
  142. {
  143. return FALSE;
  144. }
  145. CWbemClassObject* pClassObject = pObject->GetClassObject();
  146. if( ! GfxCheckObjPtr(pClassObject,CWbemClassObject) )
  147. {
  148. return FALSE;
  149. }
  150. // get the active days
  151. pClassObject->GetProperty(IDS_STRING_MOF_ACTIVEDAYS,m_iActiveDays);
  152. // get the begin time
  153. CTime BeginTime;
  154. pClassObject->GetProperty(IDS_STRING_MOF_BEGINTIME,BeginTime,false);
  155. // get the end time
  156. CTime EndTime;
  157. pClassObject->GetProperty(IDS_STRING_MOF_ENDTIME,EndTime,false);
  158. delete pClassObject;
  159. pClassObject = NULL;
  160. if( BeginTime.GetHour() == 0 && BeginTime.GetMinute() == 0 && EndTime.GetHour() == 23 && EndTime.GetMinute() == 59 )
  161. {
  162. m_iDataCollection = 0;
  163. }
  164. else if( BeginTime.GetHour() == EndTime.GetHour() && BeginTime.GetMinute() == EndTime.GetMinute() )
  165. {
  166. m_iDataCollection = 3;
  167. m_OnceDailyTime = BeginTime;
  168. }
  169. else if( BeginTime.GetHour() > EndTime.GetHour() )
  170. {
  171. m_iDataCollection = 2;
  172. m_EndTime_2 = BeginTime;
  173. m_StartTime_2 = EndTime;
  174. }
  175. else
  176. {
  177. m_iDataCollection = 1;
  178. m_StartTime_1 = BeginTime;
  179. m_EndTime_1 = EndTime;
  180. }
  181. if( m_iActiveDays & 0x00000001 )
  182. {
  183. m_bSunday = TRUE;
  184. }
  185. if( m_iActiveDays & 0x00000002 )
  186. {
  187. m_bMonday = TRUE;
  188. }
  189. if( m_iActiveDays & 0x00000004 )
  190. {
  191. m_bTuesday = TRUE;
  192. }
  193. if( m_iActiveDays & 0x00000008 )
  194. {
  195. m_bWednesday = TRUE;
  196. }
  197. if( m_iActiveDays & 0x00000010 )
  198. {
  199. m_bThursday = TRUE;
  200. }
  201. if( m_iActiveDays & 0x00000020 )
  202. {
  203. m_bFriday = TRUE;
  204. }
  205. if( m_iActiveDays & 0x00000040 )
  206. {
  207. m_bSaturday = TRUE;
  208. }
  209. UpdateData(FALSE);
  210. return TRUE; // return TRUE unless you set the focus to a control
  211. // EXCEPTION: OCX Property Pages should return FALSE
  212. }
  213. void CTHSchedulePage::OnOK()
  214. {
  215. CHMPropertyPage::OnOK();
  216. }
  217. void CTHSchedulePage::OnRadioAllDay()
  218. {
  219. UpdateData();
  220. SetModified();
  221. }
  222. void CTHSchedulePage::OnRadioAllDayExcept()
  223. {
  224. UpdateData();
  225. SetModified();
  226. }
  227. void CTHSchedulePage::OnRadioOnceDaily()
  228. {
  229. UpdateData();
  230. SetModified();
  231. }
  232. void CTHSchedulePage::OnRadioOnlyFrom()
  233. {
  234. UpdateData();
  235. SetModified();
  236. }
  237. BOOL CTHSchedulePage::OnApply()
  238. {
  239. if( ! CHMPropertyPage::OnApply() )
  240. {
  241. return FALSE;
  242. }
  243. UpdateData();
  244. CTime BeginTime;
  245. CTime EndTime;
  246. switch( m_iDataCollection )
  247. {
  248. case 0: // all day
  249. {
  250. CTime time(0,0,0,23,59,0);
  251. EndTime = time;
  252. }
  253. break;
  254. case 1: // only from x to y
  255. {
  256. CTime time1(0,0,0,m_StartTime_1.GetHour(),m_StartTime_1.GetMinute(),0);
  257. CTime time2(0,0,0,m_EndTime_1.GetHour(),m_EndTime_1.GetMinute(),0);
  258. BeginTime = time1;
  259. EndTime = time2;
  260. }
  261. break;
  262. case 2: // all day except x to y
  263. {
  264. CTime time1(0,0,0,m_EndTime_2.GetHour(),m_EndTime_2.GetMinute(),0);
  265. CTime time2(0,0,0,m_StartTime_2.GetHour(),m_StartTime_2.GetMinute(),0);
  266. BeginTime = time1;
  267. EndTime = time2;
  268. }
  269. break;
  270. case 3: // once a day at x
  271. {
  272. CTime time(0,0,0,m_OnceDailyTime.GetHour(),m_OnceDailyTime.GetMinute(),0);
  273. BeginTime = EndTime = time;
  274. }
  275. break;
  276. }
  277. // update the agent object
  278. CWbemClassObject* pClassObject = GetObjectPtr()->GetClassObject();
  279. if( ! GfxCheckObjPtr(pClassObject,CWbemClassObject) )
  280. {
  281. return FALSE;
  282. }
  283. // set the active days
  284. pClassObject->SetProperty(IDS_STRING_MOF_ACTIVEDAYS,m_iActiveDays);
  285. // set the begin time
  286. pClassObject->SetProperty(IDS_STRING_MOF_BEGINTIME,BeginTime,false);
  287. // set the end time
  288. pClassObject->SetProperty(IDS_STRING_MOF_ENDTIME,EndTime,false);
  289. pClassObject->SaveAllProperties();
  290. delete pClassObject;
  291. SetModified(FALSE);
  292. return TRUE;
  293. }