Ejemplo n.º 1
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;
             }
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 加载提醒。
        /// </summary>
        private void loadReminder()
        {
            int selectedMonth = monthComboBox.SelectedIndex;
            int selectedDay   = dayComboBox.SelectedIndex;

            reminderListView.Items.Clear();

            cachedReminders = ReminderManager.GetReminders();

            foreach (Reminder reminder in cachedReminders)
            {
                if (((selectedMonth == 0) || (reminder.Month == selectedMonth)) &&
                    ((selectedDay == 0) || (reminder.Day == selectedDay)))
                {
                    addReminderToList(reminder);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获得“今日相关”提醒事项。
        /// </summary>
        /// <returns>今日相关类的实例。</returns>
        public static Today GetToday()
        {
            int   month = DateTime.Now.Month;
            int   day   = DateTime.Now.Day;
            Today ret   = new Today();
            Collection <Reminder> allReminders = ReminderManager.GetReminders();

            foreach (Reminder r in allReminders)
            {
                if (r.IsEnabled && r.Month == month && r.Day == day)
                {
                    ret.TodayReminders.Add(r);
                    if (!HasReminderDone(r))
                    {
                        ret.UndoneTodayReminders.Add(r);
                    }
                }
            }
            return(ret);
        }
Ejemplo n.º 4
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();
         }
     }
 }
Ejemplo n.º 5
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);
     }
 }
Ejemplo n.º 6
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);
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// 打开一个提醒对应的文件。
        /// </summary>
        /// <param name="r">要读取的提醒。</param>
        public static void DoReminder(Reminder r)
        {
            Thread worker = new Thread(new ThreadStart(() =>
            {
                if (!r.IsEnabled)
                {
                    return;
                }
                Process process;
                try
                {
                    process = Process.Start(r.FilePath);
                }
                catch (Exception)
                {
                    MessageBox.Show("打开文件失败:" + r.FilePath);
                    return;
                }
            }));

            worker.Start();
            r.LastRunYear = DateTime.Now.Year;
            ReminderManager.UpdateReminders();
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            string programPath    = ReminderManager.getRemindersPath() + @"\";
            string exePath        = programPath + Application.ProductName + ".exe";
            string startupAddress = "\"" + exePath + "\"" + @" run"; //带参的运行路径。

            try
            {
                //在系统任意处运行一次程序,可以达到更新的目的。
                if (Application.ExecutablePath != exePath)
                {
                    //杀掉老进程。
                    int currentProcessId = Process.GetCurrentProcess().Id;
                    foreach (Process p in Process.GetProcessesByName(Application.ProductName))
                    {
                        Debug.WriteLine(p.ProcessName);
                        if (p.Id != currentProcessId)
                        {
                            p.Kill();
                        }
                    }
update:             //等待进程完全结束。
                    try
                    {
                        Thread.Sleep(100);
                        File.Copy(Application.ExecutablePath, exePath, true);
                    }
                    catch (Exception)
                    {
                        goto update;
                    }
                }
                RegistryKey run;
                run = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
                string runitem = run.GetValue(Application.ProductName) as string;
                if (string.IsNullOrEmpty(runitem) || runitem != startupAddress)
                {
                    MessageBox.Show(string.Format("接下来会添加启动项,{0}请在安全软件的提示框中允许此操作。", Environment.NewLine), "FileReminder:用一个文件纪念特殊的日子。", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    run.SetValue(Application.ProductName, startupAddress);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            if (args.Length > 0)
            {
                if (args[0] == "run")
                {
                    //检测到第一个参数为“run”。
                    //作为后台进程运行。
                    runCore();
                    return;
                }
            }
            else
            {
                //没有额外参数。
                //显示设置界面后,运行一个新的后台进程。
                Application.Run(new PreferenceForm());
                Process.Start(programPath + Application.ProductName + ".exe", "run");
            }
        }