コード例 #1
0
        /// <summary>
        /// 解锁今日提醒对应的文件。
        /// </summary>
        internal static void unlockToday()
        {
            Today today = Today.GetToday();

            foreach (Reminder reminder in today.TodayReminders)
            {
                try
                {
                    FileLockerManager.UnlockFile(reminder.FilePath);
                }
                catch (Exception)
                {
                    continue;
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// 锁定所有提醒对应的文件。
 /// </summary>
 internal static void lockAll()
 {
     foreach (Reminder reminder in ReminderManager.GetReminders())
     {
         if (reminder.IsFileLocked && reminder.IsEnabled)
         {
             try
             {
                 FileLockerManager.LockFile(reminder.FilePath);
             }
             catch (Exception)
             {
                 continue;
             }
         }
     }
 }
コード例 #3
0
 /// <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();
         }
     }
 }
コード例 #4
0
 /// <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);
     }
 }
コード例 #5
0
 /// <summary>
 /// 删除一个提醒。
 /// </summary>
 /// <param name="warnIfUnselected">指定当用户未选定任何提醒时,是否发出警告。</param>
 private void removeReminder(bool warnIfUnselected)
 {
     if (reminderListView.SelectedItems.Count > 0)
     {
         if (MessageBox.Show("删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             Reminder r = reminderListView.SelectedItems[0].Tag as Reminder;
             if (r != null)
             {
                 cachedReminders.Remove(r);
                 ReminderManager.SaveReminders(cachedReminders);
                 FileLockerManager.UnlockFile(r.FilePath);
                 loadToday();
                 loadReminder();
                 MessageBox.Show("已删除。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
     }
     else if (warnIfUnselected)
     {
         MessageBox.Show("请选择一项来删除!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
コード例 #6
0
        /// <summary>
        /// 托盘图标管理和托盘图标、UI消息循环。
        /// </summary>
        internal static void iconWorker()
        {
            Icon      = new NotifyIcon();
            Icon.Text = "FileReminder";
            Icon.Icon = FileReminder.Properties.Resources.icon;

            MenuItem todayMenu = new MenuItem("今日事项", (s, e) =>
            {
                using (TodayForm tf = new TodayForm())
                {
                    tf.ShowDialog();
                }
            });

            todayMenu.DefaultItem = true;
            MenuItem preferenceMenu = new MenuItem("设置", (s, e) =>
            {
                using (PreferenceForm pf = new PreferenceForm())
                {
                    pf.ShowDialog();
                }
            });
            MenuItem exitMenu = new MenuItem("暂时退出", (s, e) =>
            {
                FileLockerManager.UnlockAll();
                exit(0);
            });
            MenuItem uninstallMenu = new MenuItem("停止FileReminder", (s, e) =>
            {
                if (MessageBox.Show("停止吗?新的提醒将不会再显示了。", "FileReminder停止", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    try
                    {
                        RegistryKey run;
                        run = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
                        run.DeleteValue(Application.ProductName);
                    }
                    catch (Exception ex) { MessageBox.Show(ex.Message); }
                    FileLockerManager.UnlockAll();
                    exit(0);
                }
            });

            ContextMenu menu = new ContextMenu();

            menu.MenuItems.Add(todayMenu);
            menu.MenuItems.Add(preferenceMenu);
            menu.MenuItems.Add(uninstallMenu);
            menu.MenuItems.Add(exitMenu);
            Icon.ContextMenu = menu;

            Icon.DoubleClick += (s, e) =>
            {
                using (TodayForm tf = new TodayForm())
                {
                    tf.ShowDialog();
                }
            };

            Icon.Visible = true;

            Application.Run(); //执行消息循环。
        }