/// <summary> /// 添加一个提醒。 /// </summary> private void addReminder() { using (ReminderForm rf = new ReminderForm()) { rf.ShowDialog(); if (rf.HasChanged) { cachedReminders.Add(rf.Reminder); ReminderManager.SaveReminders(cachedReminders); if (rf.Reminder.IsEnabled && rf.Reminder.IsFileLocked) { FileLockerManager.LockFile(rf.Reminder.FilePath); } MessageBox.Show(string.Format("已添加。{0}{0}当这一天到来时,我们会用这个文件提醒你。", Environment.NewLine), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); monthComboBox.SelectedIndex = rf.Reminder.Month; dayComboBox.SelectedIndex = rf.Reminder.Day; loadReminder(); loadToday(); } } }
/// <summary> /// 编辑一个提醒。 /// </summary> /// <param name="warnIfUnselected">指定当用户未选定任何提醒时,是否发出警告。</param> private void editReminder(bool warnIfUnselected) { if (reminderListView.SelectedItems.Count > 0) { Reminder r = reminderListView.SelectedItems[0].Tag as Reminder; if (r != null) { using (ReminderForm rf = new ReminderForm(r)) { rf.ShowDialog(); if (rf.HasChanged) { ReminderManager.UpdateReminders(); loadToday(); DateTime now = DateTime.Now; if (rf.Reminder.Month == now.Month && rf.Reminder.Day == now.Day || !rf.Reminder.IsEnabled || !rf.Reminder.IsFileLocked) { FileLockerManager.UnlockFile(r.FilePath); } else { FileLockerManager.LockFile(r.FilePath); } MessageBox.Show("已保存。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); monthComboBox.SelectedIndex = rf.Reminder.Month; dayComboBox.SelectedIndex = rf.Reminder.Day; loadReminder(); loadToday(); } } } } else if (warnIfUnselected) { MessageBox.Show("请选择一项来修改!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }