コード例 #1
0
ファイル: Todomoo.cs プロジェクト: suxiaojack/todomoo
        /// <summary>
        /// Read a summary of all tasks in the database.
        /// Stores an array of Task in Tasks variable.
        /// </summary>
        /// <param name="category">Filter by category</param>
        /// <param name="completed">If FALSE, do not load completed tasks</param>
        public static void LoadTasks(Category category, bool completed)
        {
            // Store running timers, delete paused timers
            foreach (Task t in Tasks) {
                if (t.IsTimerRunning()) { if (!LostTimers.Contains(t.Id)) LostTimers.Add(t.Id, new object[] { t.Timer, DateTime.Now }); }
                else LostTimers.Remove(t.Id);
            }

            // Read task IDs from the database
            string whereCondition = "(1)";
            if (category != null) whereCondition += " AND (category = " + category.Id + ")";
            if (!completed) whereCondition += " AND (completed IS NULL) ";
            DataTable dt = db.Query("SELECT id FROM task WHERE " + whereCondition + " GROUP BY task.id ");

            // Fill in the Tasks array
            Tasks.Clear();
            foreach (DataRow row in dt.Rows) {
                try { Tasks.Add(new Task((int)row["id"])); }
                catch { Utils.MsgDialog.Warning(mainForm.Lang.Get("task_loading_error") + " #" + row["id"].ToString(), mainForm.Lang.Get("warning")); }
            }

            // Restore saved timers
            foreach (Task t in Tasks) if (LostTimers.Contains(t.Id)) {
                int stopped_at = (int)((object[])LostTimers[t.Id])[0]; // Timer was stopper at second
                DateTime stopped_dt = (DateTime)((object[])LostTimers[t.Id])[1]; // Timer was stopped at time
                t.Timer = stopped_at + (int)(DateTime.Now.Subtract(stopped_dt).TotalSeconds); // Restore timer
                t.StartTimer(); // Start timer again!
            }
        }
コード例 #2
0
ファイル: Todomoo.cs プロジェクト: suxiaojack/todomoo
 /// <summary>
 /// Removes a category from the database. Category must be empty.
 /// </summary>
 /// <param name="category">Category to remove</param>
 public static void RemoveCategory(Category category)
 {
     db.NonQuery("DELETE FROM task WHERE category = " + category.Id);
     db.NonQuery("DELETE FROM category WHERE id = " + category.Id);
     Categories.Remove(category);
 }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: suxiaojack/todomoo
        // Loading operations
        private void MainFormLoad(object sender, EventArgs e)
        {
            treeTasks.MultiSelect = true;
            // Hide move panel
            HideMovePanel();

            // Set up application pahs
            DirectoryInfo appdir = new DirectoryInfo(Application.ExecutablePath);
            appdir = new DirectoryInfo(appdir.Parent.FullName);
            ApplicationDirectory = appdir.FullName.TrimEnd(new char[] {'\\'}) + "\\";
            DatabasePath = ApplicationDirectory + "db.sqlite";
            ConfigurationPath = ApplicationDirectory + "todomoo.conf";
            BackupDirectory = ApplicationDirectory + "backups\\";
            LanguageDirectory = ApplicationDirectory + "lang\\";

            // Create the main engine from the database file
            try { Todomoo.OpenDatabase(DatabasePath); }
            catch (Exception ex) { ExitWithError("Unable to load main database (db.sqlite)!\n" + ex.Message); return; }

            // Create the default configuration, then load user settings
            Settings = new Utils.AppSettings(ConfigurationPath);
            ApplyDefaultSettings();
            Settings.Load();

            // Language inizialization
            Lang = new Languages.Language(LanguageDirectory);
            Lang.LoadLanguage(Settings.Get("lang").ToString());
            ApplyLanguage();

            // Form aspect
            WindowState = (Settings.Get("window_maximized").ToString() == "1") ? FormWindowState.Maximized : FormWindowState.Normal;
            if (Settings.Get("window_maximized").ToString() != "1") {
                Rectangle screen = Screen.PrimaryScreen.Bounds;
                int w = Math.Max(100, Math.Min(screen.Width  - 50, (int)Settings.Get("window_width" )));
                int h = Math.Max(100, Math.Min(screen.Height - 50, (int)Settings.Get("window_height")));
                int x = Math.Max(0,   Math.Min(screen.Width  - w,  (int)Settings.Get("window_xpos" )));
                int y = Math.Max(0,   Math.Min(screen.Height - h,  (int)Settings.Get("window_ypos" )));
                SetBounds(x, y, w, h); }
            UpdateFormAspect();
            UpdateColumnsAspect();
            treeTasks.Refresh();

            // Icons initialization
            btnCategoryAll.Image = IconColoured.GetSquared(Color.Gray);

            // Setup task tree and load categories.
            // SelectedCategory set method automatically fill in the tree.
            SetupTaskTree();
            LoadCategories();
            int category_to_load_id = Utils.Conversion.ToInt(Settings.Get("selected_category").ToString());
            foreach (Category category in Todomoo.Categories) if (category.Id == category_to_load_id) SelectedCategory = category;

            // Updates auto check
            if (Settings.Get("updates_auto").ToString() == "1") {

                 // Wait 5secs and start to check for updates
                timerUpdates = new Timer();
                timerUpdates.Interval = 5000;
                timerUpdates.Tick += delegate {
                    timerUpdates.Stop();
                    u = new UpdatesCheck();
                    u.Error += delegate(string message) {
                        try { Utils.Debug.Write("Updates check error: " + message); } catch { } };
                    u.NewVersionAvailable += delegate(string version, string url_setup, int size_setup, string url_portable, int size_portable) {
                        try { this.Invoke((MethodInvoker)delegate { UpdatesForm.CreateWithNewVersion(Lang, Settings, version, url_setup, size_setup, url_portable, size_portable).ShowDialog(this); }); } catch { } };
                    u.Check();
                };
                timerUpdates.Start();

            }
        }
コード例 #4
0
ファイル: Todomoo.cs プロジェクト: suxiaojack/todomoo
 /// <summary>
 /// Read a summary of all tasks in the database.
 /// Stores an array of Task in Tasks variable.
 /// </summary>
 /// <param name="category">Filter by category</param>
 public static void LoadTasks(Category category)
 {
     LoadTasks(category, true);
 }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: suxiaojack/todomoo
        private void CategoryNew()
        {
            try {

                // Edit a new category in a Category form.
                Category new_category = new Category();
                CategoryForm form = new CategoryForm(Lang, new_category);
                DialogResult res = form.ShowDialog();

                // If the category has been modified, save it to the DB.
                if (res != DialogResult.OK) return;
                new_category.Update(); // Save task in DB

                // Add category and update the category bar
                Todomoo.Categories.Add(new_category);
                RedrawCategoriesBar();
                SelectedCategory = new_category;
                CountTasks();

            } catch {
                Utils.MsgDialog.Error(Lang.Get("task_save_error"), Lang.Get("error")); return;
            }
        }
コード例 #6
0
ファイル: MainForm.cs プロジェクト: suxiaojack/todomoo
        // Load categories in the toolbar
        private void LoadCategories()
        {
            toolCategories.SuspendLayout();

            // Load categories from the database
            Todomoo.LoadCategories();
            RedrawCategoriesBar();
            CountTasks();

            toolCategories.ResumeLayout();

            // Now selected a category
            SelectedCategory = selected_category;
        }
コード例 #7
0
ファイル: MainForm.cs プロジェクト: suxiaojack/todomoo
        private void CategoryDeleteSelected()
        {
            if (SelectedCategory == null) return;
            try {

                // Ask if not empty
                if (SelectedCategory.GetTasksCount() > 0) {
                    if (!Utils.MsgDialog.Question(Lang.Get("category_delete_confirm"), Lang.Get("warning"))) return;
                }

                // Remove category and update bar
                Todomoo.RemoveCategory(SelectedCategory);
                RedrawCategoriesBar();
                SelectedCategory = null;

            } catch (Exception ex) {
                if (ex.Message == "NOT EMPTY") Utils.MsgDialog.Warning(Lang.Get("category_delete_not_empty") + ".", Lang.Get("warning"));
                else Utils.MsgDialog.Error(Lang.Get("category_delete_error"), Lang.Get("error"));
            }
        }
コード例 #8
0
ファイル: MainForm.cs プロジェクト: suxiaojack/todomoo
        private void UpdateFormAspect()
        {
            SuspendLayout();

            // Reselect current category. Needed for keeping sorting.
            SelectedCategory = SelectedCategory;

            // Interface
            mnMenu.RenderMode = mnContextCategory.RenderMode = mnContextTask.RenderMode = (Settings.Get("style_menu").ToString() == "0" ? ToolStripRenderMode.System : ToolStripRenderMode.Professional);
            toolToolbar.RenderMode = (Settings.Get("style_toolbar").ToString() == "0" ? ToolStripRenderMode.System : ToolStripRenderMode.Professional);
            toolCategories.RenderMode = (Settings.Get("style_categories").ToString() == "0" ? ToolStripRenderMode.System : ToolStripRenderMode.Professional);

            ResumeLayout();
        }
コード例 #9
0
ファイル: MainForm.cs プロジェクト: suxiaojack/todomoo
        // Categories toolbar right click
        void ToolCategoriesMouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right) {

                // Select clicked item, show context menu
                try {
                    ToolStripItem item = toolCategories.GetItemAt(e.Location);
                    if (!(item.Tag is Category)) return;
                    if (SelectedCategory != null) if (SelectedCategory != (Category)item.Tag)
                        SelectedCategory = (Category)item.Tag;
                    if (SelectedCategory == null)
                        SelectedCategory = (Category)item.Tag;
                    mnContextCategory.Show(toolCategories, e.Location);
                } catch {}

            }
        }
コード例 #10
0
ファイル: MainForm.cs プロジェクト: suxiaojack/todomoo
        // Categories toolbar left click
        void ToolCategoriesItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            // New category button
            if (e.ClickedItem == btnCategoryNew) {
                CategoryNew();

            // All category button
            } else if (e.ClickedItem == btnCategoryAll) {
                SelectedCategory = null;

            // Am I moving?
            } else if ((moving.Count>0) && (e.ClickedItem.Tag is Category)) {
                TaskMoveConfirm((Category)e.ClickedItem.Tag);

            // Single category switch
            } else if (e.ClickedItem.Tag is Category) {
                SelectedCategory = (Category)e.ClickedItem.Tag;
            }
        }
コード例 #11
0
ファイル: MainForm.cs プロジェクト: suxiaojack/todomoo
        // Confirm moving in a category
        private void TaskMoveConfirm(Category target)
        {
            if (moving.Count == 0 ) return;
            foreach (Task tmoving in moving)
            {
                // In category
                if (target != null)
                {

                    // Update
                    tmoving.ParentId = 0; // No more child
                    Todomoo.ChangeCategoryToHierarchy(tmoving, target.Id);
                    tmoving.Update();
                    LoadTasks(true);
                }
            }
            // Done
            TaskMoveCancel();
        }