Beispiel #1
0
        private DBConnect con; //connection to the db

        public Home()
        {
            InitializeComponent();
            con = new DBConnect("localhost", "plutodb", "root", "");
            displayGreeting();

            //populate tasks list
            listViewToday.Columns.Add("");
            listViewToday.Columns.Add("task description");
            listViewToday.Columns.Add("location");
            listViewToday.Columns.Add("date/hour");
            listViewToday.Columns.Add("status");
            CTask.populateTaskList(listViewToday, today);

            //populate next list
            listViewNext.Columns.Add("");
            listViewNext.Columns.Add("task description");
            listViewNext.Columns.Add("location");
            listViewNext.Columns.Add("date/hour");
            listViewNext.Columns.Add("status");
            CTask.populateNextTasksList(listViewNext);

            //write the number of tasks for today
            int todayTasks = CTask.countTodayTasks();

            btnToday.Text = "Today(" + todayTasks + ")";

            //populate category list
            categories.MouseDown += new MouseEventHandler(categories_MouseDown);
            CCategory.populateCategoryList(categories);
        }
Beispiel #2
0
 private void CheckKeys(object sender, System.Windows.Forms.KeyPressEventArgs e)
 {
     //check if is pressed Enter
     if (e.KeyChar == (char)13)
     {
         string newCategName = newCategory.Text;
         CCategory.createNewCategory(newCategName);
     }
 }
Beispiel #3
0
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DBConnect con; //connection to the db

            con = new DBConnect("localhost", "plutodb", "root", "");
            //try to open the connection to db
            if (con.OpenConnection() == true)
            {
                //verify if there are any tasks in the category
                MySqlCommand cmdTasks = con.connection.CreateCommand();
                cmdTasks.CommandText = "SELECT * FROM tasks WHERE categories_id_category = @id_cat";
                cmdTasks.Parameters.AddWithValue("@id_cat", Home.id_category);

                //Create a data reader and execute the command
                MySqlDataReader dataReader = cmdTasks.ExecuteReader();
                if (dataReader.HasRows)
                {
                    DialogResult resultTasksDelete = MessageBox.Show("Are you sure you want to delete the category and all it's tasks?", "Confirmation", MessageBoxButtons.YesNo);
                    if (resultTasksDelete == DialogResult.Yes)
                    {
                        con.CloseConnection();
                        con.OpenConnection();

                        //delete tasks from category
                        MySqlCommand cmdDeleteTasks = con.connection.CreateCommand();
                        cmdDeleteTasks.CommandText = "DELETE FROM tasks WHERE categories_id_category = @id_cat";
                        cmdDeleteTasks.Parameters.AddWithValue("@id_cat", Home.id_category);
                        cmdDeleteTasks.ExecuteNonQuery();
                    }
                }

                con.CloseConnection();
                con.OpenConnection();

                //create command to delete category
                MySqlCommand cmd = con.connection.CreateCommand();
                cmd.CommandText = "DELETE FROM categories WHERE id_category = @id_cat";
                cmd.Parameters.AddWithValue("@id_cat", Home.id_category);

                cmd.ExecuteNonQuery();
            }

            CCategory.populateCategoryList(Login.h.categories);
            CTask.populateTaskList(Login.h.listViewToday, Login.h.today);
            CTask.populateNextTasksList(Login.h.listViewNext);

            con.CloseConnection();
        }
Beispiel #4
0
        private void categories_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (categories.SelectedItems.Count > 0)
            {
                //show the tasks from selected category
                string   categorySelected = categories.SelectedItem.ToString();
                char[]   delimiterChars   = { '(' };
                string[] words            = categorySelected.Split(delimiterChars);

                int categoryId = CCategory.getCategoryId(words[0]);

                listViewToday.ResetText();
                Login.h.today.Text = words[0];
                CCategory.populateTasksFromCategory(listViewToday, categoryId);
            }
        }
Beispiel #5
0
        private void categories_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (categories.SelectedItems.Count > 0)
                {
                    //show the tasks from selected category
                    string   categorySelected = categories.SelectedItem.ToString();
                    char[]   delimiterChars   = { '(' };
                    string[] words            = categorySelected.Split(delimiterChars);

                    id_category = CCategory.getCategoryId(words[0]);

                    contextMenuStrip1.Show(Cursor.Position);
                }
            }
        }
Beispiel #6
0
        private void update_Click(object sender, EventArgs e)
        {
            DBConnect con; //connection to the db

            con = new DBConnect("localhost", "plutodb", "root", "");
            //try to open the connection to db
            if (con.OpenConnection() == true)
            {
                //create command
                MySqlCommand cmd = con.connection.CreateCommand();
                cmd.CommandText = "UPDATE categories SET category_name = @cat_name, category_color = @cat_color WHERE id_category = @id_cat";
                cmd.Parameters.AddWithValue("@cat_name", categ_name.Text);
                cmd.Parameters.AddWithValue("@cat_color", categ_color.Text);
                cmd.Parameters.AddWithValue("@id_cat", Home.id_category);

                cmd.ExecuteNonQuery();
            }

            CCategory.populateCategoryList(Login.h.categories);
            con.CloseConnection();
            this.Close();
        }
Beispiel #7
0
        public static void doneTask(System.Windows.Forms.ListView f_listView)
        {
            string taskName   = f_listView.SelectedItems[0].SubItems[1].Text;
            bool   taskDoneDB = false;;

            //try to open the database
            DBConnect con; //connection to the db

            con = new DBConnect("localhost", "plutodb", "root", "");
            con.OpenConnection();

            //create command
            MySqlCommand cmdDone = con.connection.CreateCommand();

            cmdDone.CommandText = "SELECT * FROM tasks WHERE users_id_user = ?id_user AND task_name = ?task_nm";
            cmdDone.Parameters.AddWithValue("?id_user", Login.user_class.getUserId().ToString());
            cmdDone.Parameters.AddWithValue("?task_nm", taskName);
            MySqlDataReader dataReader = cmdDone.ExecuteReader();

            if (dataReader.HasRows)
            {
                while (dataReader.Read())
                {
                    //verify if the task is done
                    taskDoneDB = Convert.ToBoolean(dataReader["done"]);
                }
            }
            con.CloseConnection();

            DialogResult resultTasksDelete;

            if (taskDoneDB == false)
            {
                resultTasksDelete = MessageBox.Show("Task is done? ", "Confirmation", MessageBoxButtons.YesNo);
            }
            else
            {
                resultTasksDelete = MessageBox.Show("Do you want to undo task? ", "Confirmation", MessageBoxButtons.YesNo);
            }

            if (resultTasksDelete == DialogResult.Yes)
            {
                //try to open the connection to db
                if (con.OpenConnection() == true)
                {
                    //create command
                    MySqlCommand cmd = con.connection.CreateCommand();
                    cmd.CommandText = "UPDATE tasks SET done = ?done WHERE task_name = ?task_name";
                    cmd.Parameters.AddWithValue("?task_name", taskName);
                    cmd.Parameters.AddWithValue("?done", !taskDoneDB);

                    cmd.ExecuteNonQuery();
                }
            }
            con.CloseConnection();

            //write the number of tasks for today
            int todayTasks = CTask.countTodayTasks();

            Login.h.btnToday.Text = "Today(" + todayTasks + ")";

            //update task lists
            populateTaskList(Login.h.listViewToday, Login.h.today);
            populateNextTasksList(Login.h.listViewNext);
            CCategory.populateCategoryList(Login.h.categories);
        }
Beispiel #8
0
        //---------------------------------------------------------------
        ///Add.a.task Button
        private void btnAddTask_Click(object sender, EventArgs e)
        {
            //Check if all the fields are completed with the proper informations
            bool category    = false;
            bool description = false;
            bool location    = false;
            bool priority    = false;
            int  priorityValue; Int32.TryParse(cmbBoxPriority.Text, out priorityValue);

            if (comboBoxChooseCategory.Text.ToString().Equals("Choose category") || comboBoxChooseCategory.Text.ToString().Equals(String.Empty))
            {
                category = true;
            }
            if (textBoxTaskTitle.Text.ToString().Equals("Task description") || textBoxTaskTitle.Text.ToString().Equals(String.Empty))
            {
                description = true;
            }
            if (labelLocation.Text.ToString().Equals("Task location") || labelLocation.Text.ToString().Equals(String.Empty))
            {
                location = true;
            }
            if (cmbBoxPriority.Text.ToString().Equals("Priorities") || priorityValue < 1 || priorityValue > 3)
            {
                priority = true;
            }

            //If at least one field is not good, a message box will appear
            //otherwise, the informations will be inserted in the database
            if (category || description || location || priority)
            {
                MessageBox.Show(" Complete all the fields with the proper information !! ");
            }
            else
            {
                fTaskDataTimeString = fTaskDataTimeString + fTaskTime;
                //MessageBox.Show(fCategory);
                //MessageBox.Show(fTaskTitle);
                //MessageBox.Show(fTaskDataTimeString);
                //MessageBox.Show(fTaskLocation);
                //MessageBox.Show(fTaskPriority);
                //MessageBox.Show(fRecurrentDays);

                if (con.OpenConnection() == true)
                {
                    //Create command
                    MySqlCommand cmd = con.connection.CreateCommand();
                    if (fRecurrentDays == "0000000")
                    {
                        cmd.CommandText = "INSERT INTO tasks (task_name, task_priority, deadline, users_id_user, categories_id_category, done) VALUES (?taskName, ?taskPriority, ?taskdeadline, ?usersIdUser, ?CategoriesIdCategory, ?taskDone )";
                        cmd.Parameters.AddWithValue("taskName", fTaskTitle);
                        cmd.Parameters.AddWithValue("taskPriority", fTaskPriorityInt);
                        cmd.Parameters.AddWithValue("taskdeadline", fTaskDataTimeString);
                        cmd.Parameters.AddWithValue("usersIdUser", userID);
                        cmd.Parameters.AddWithValue("CategoriesIdCategory", fTaskIDCategory);
                        cmd.Parameters.AddWithValue("taskDone", fTaskDone);
                        try
                        {
                            cmd.ExecuteNonQuery();
                            MessageBox.Show("Now, Pluto knows about your task!\nDon't forget about it! Because he wouldn't :)");
                            CCategory.populateCategoryList(Login.h.categories);

                            //write the number of tasks for today
                            int todayTasks = CTask.countTodayTasks();
                            Login.h.btnToday.Text = "Today(" + todayTasks + ")";

                            //update today and next list
                            CTask.populateTaskList(Login.h.listViewToday, Login.h.today);
                            CTask.populateNextTasksList(Login.h.listViewNext);
                        }
                        catch (MySqlException ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                    }
                    else
                    {
                        cmd.CommandText = "INSERT INTO recurring_tasks (task_name, task_priority, deadline, rec_days, users_id_user, categories_id_category, done) VALUES (?taskName, ?taskPriority, ?taskdeadline, ?taskRecDays,?usersIdUser, ?CategoriesIdCategory, ?taskDone )";
                        cmd.Parameters.AddWithValue("taskName", fTaskTitle);
                        cmd.Parameters.AddWithValue("taskPriority", fTaskPriorityInt);
                        cmd.Parameters.AddWithValue("taskdeadline", fTaskDataTimeString);
                        cmd.Parameters.AddWithValue("taskRecDays", fRecurrentDays);
                        cmd.Parameters.AddWithValue("usersIdUser", userID);
                        cmd.Parameters.AddWithValue("CategoriesIdCategory", fTaskIDCategory);
                        cmd.Parameters.AddWithValue("taskDone", fTaskDone);
                        try
                        {
                            cmd.ExecuteNonQuery();
                            MessageBox.Show("Now, Pluto knows about your task!\nDon't forget about it! Because he wouldn't :)");
                        }
                        catch (MySqlException ex)
                        {
                            MessageBox.Show(ex.ToString());
                        }
                    }
                    //close connection
                    con.CloseConnection();
                }
                else
                {
                    MessageBox.Show("Database can't be opened");
                }
                this.Close();
            }
        }