Example #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);
        }
Example #2
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);
        }
Example #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();
            }
        }