Beispiel #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Starting program...");
            bool stopcondition = true;
            int  userOption;

            if (!File.Exists("todolist.txt"))
            {
                Console.WriteLine("No list found, creating a new list");
                File.Create("todolist.txt").Dispose();
            }
            Console.WriteLine("Opening list...");
            ToDoList list = new ToDoList();

            list.Open();
            Console.Write("Welcome user! ");
            while (stopcondition)
            {
                Console.WriteLine("What would you like to do? (Input number) \n");
                list.PrintOptions();
                Console.WriteLine("0. Save and quit");
                try
                {
                    userOption = (int)Char.GetNumericValue(Console.ReadKey().KeyChar);
                    if (userOption == 0)
                    {
                        Console.WriteLine("Quitting...");
                        list.Save();
                        stopcondition = false;
                    }
                    else
                    {
                        list.Execute(userOption);
                    }
                }
                catch (FormatException)
                {
                    Console.WriteLine("Error! Not a number.");
                    Console.ReadLine();
                    Console.Clear();
                }
                catch (OverflowException)
                {
                    Console.WriteLine("Error! Number too big.");
                    Console.ReadLine();
                    Console.Clear();
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Load a database from the given path
 /// </summary>
 /// <param name="path">The from where you want to load the database</param>
 private void LoadDatabase(string path)
 {
     loadedDB = path;
     ToDoList = new ToDoList();
     if (File.Exists(path))
     {
         try
         {
             ToDoList = DbVersionManager.ReadToDoList(path);
         }
         catch
         {
             MessageBox.Show("Database corrupted");
         }
     }
 }
Beispiel #3
0
        /// <summary>
        /// Is triggered when the edit button is clicked
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event data</param>
        private void editToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int index = olvTasks.SelectedIndex;

            if (index >= ToDoList.Tasks.Count || index < 0)
            {
                return;
            }
            Task     t  = ToDoList.Tasks[index];
            FormTask ft = new FormTask("Edit a task", t);

            if (ft.ShowDialog() == DialogResult.OK)
            {
                ToDoList.ModifyTaskByIndex(index, t);
            }
        }