示例#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);
        }
示例#2
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();
        }
示例#3
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();
            }
        }