/// <summary>
        /// Adds an available task to a type
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddTask_Click(object sender, EventArgs e)
        {
            DataRowView selectedTask = (DataRowView)this.AvailableTasksListBox.SelectedItem;

            if (selectedTask != null)
            {
                string      task_id      = selectedTask["task_id"].ToString();
                DataRowView selectedType = (DataRowView)this.TypesListBox.SelectedItem;
                string      type_id      = selectedType["type_id"].ToString();

                if (!string.IsNullOrEmpty(task_id) && !string.IsNullOrEmpty(type_id))
                {
                    string error = Data.Ins_Task(type_id, task_id, "");
                    if (string.IsNullOrEmpty(error))
                    {
                        //MessageBox.Show("Task was added for type");
                        this.info = info = new TimeTrackInfo();
                        this.TypesListBox_Bind();
                        this.TypesListBox.ClearSelected();
                        this.TypesListBox.SelectedValue = selectedType.Row[0];
                        this.RefereshMain();
                    }
                    else
                    {
                        MessageBox.Show(error);
                    }
                }
            }
        }
        /// <summary>
        /// Adds a new sub task
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddSubTask_Click(object sender, EventArgs e)
        {
            DataRowView selectedTask = (DataRowView)this.CurrentTasksListBox.SelectedItem;

            if (selectedTask != null)
            {
                string      task_id         = selectedTask["task_id"].ToString();
                DataRowView selectedType    = (DataRowView)this.TypesListBox.SelectedItem;
                string      type_id         = selectedType["type_id"].ToString();
                string      link_id         = selectedTask["link_id"].ToString();
                DataRowView selectedSubTask = (DataRowView)this.AvailableSubTasksListBox.SelectedItem;
                string      sub_task_id     = selectedSubTask["sub_task_id"].ToString();
                if (!string.IsNullOrEmpty(sub_task_id))
                {
                    string error = Data.Ins_New_Sub_Task(link_id, sub_task_id, "");
                    if (string.IsNullOrEmpty(error))
                    {
                        //MessageBox.Show("Sub Task was added for task");
                        this.info = info = new TimeTrackInfo();
                        this.TypesListBox_Bind();
                        this.TypesListBox.ClearSelected();
                        this.TypesListBox.SelectedValue        = type_id;
                        this.CurrentTasksListBox.SelectedValue = task_id;
                        this.RefereshMain();
                    }
                    else
                    {
                        MessageBox.Show(error);
                    }
                }
            }
        }
        /// <summary>
        /// Deletes a task
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDeleteTask_Click(object sender, EventArgs e)
        {
            DataRowView selectedTask = (DataRowView)this.CurrentTasksListBox.SelectedItem;

            if (selectedTask != null)
            {
                // Get the values from the selected row
                string task_id = selectedTask["task_id"].ToString();
                string type_id = selectedTask["type_id"].ToString();
                string link_id = selectedTask["link_id"].ToString();

                // Check to make sure that they are not null
                if (!string.IsNullOrEmpty(task_id) && !string.IsNullOrEmpty(type_id) && !string.IsNullOrEmpty(link_id))
                {
                    string error = Data.Del_Task(task_id, link_id, type_id);
                    if (string.IsNullOrEmpty(error))
                    {
                        MessageBox.Show("Tasks is Deleted");
                        this.info = info = new TimeTrackInfo();
                        this.TypesListBox_Bind();
                        this.TypesListBox.ClearSelected();
                        this.TypesListBox.SelectedValue = type_id;
                        //this.CurrentTasksListBox.SelectedValue = task_id;
                        this.RefereshMain();
                    }
                    else
                    {
                        MessageBox.Show(error);
                    }
                }
            }
        }
        /// <summary>
        /// Creates a new type
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnNewType_Click(object sender, EventArgs e)
        {
            string newType = this.txtNewType.Text;

            if (!string.IsNullOrEmpty(newType))
            {
                string error = Data.Ins_Type(newType);
                if (string.IsNullOrEmpty(error))
                {
                    //MessageBox.Show("Type was added");
                    this.info = null;
                    this.txtNewType.Clear();
                    this.TypesListBox_Bind();
                    this.RefereshMain();
                }
                else
                {
                    MessageBox.Show(error);
                }
            }
            else
            {
                MessageBox.Show("Please enter a type");
            }
        }
        /// <summary>
        /// Deletes a type
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, EventArgs e)
        {
            DataRowView selectedType = (DataRowView)this.TypesListBox.SelectedItem;
            string      error        = string.Empty;
            string      type_id      = selectedType["type_id"].ToString();

            if (!string.IsNullOrEmpty(type_id))
            {
                DialogResult results = MessageBox.Show("Are you sure you want to delete the type?", "Delete Type", MessageBoxButtons.YesNo);
                if (results == System.Windows.Forms.DialogResult.Yes)
                {
                    // First delete the tasks, which will also delete the sub tasks
                    for (int x = 0; x < this.CurrentTasksListBox.Items.Count; x++)
                    {
                        DataRowView task    = (DataRowView)this.CurrentTasksListBox.Items[x];
                        string      task_id = task["task_id"].ToString();
                        string      link_id = task["link_id"].ToString();
                        error = Data.Del_Task(task_id, link_id, type_id);
                        if (!string.IsNullOrEmpty(error))
                        {
                            MessageBox.Show(error);
                            return;
                        }
                    }

                    error = Data.Del_Type(type_id);
                    if (string.IsNullOrEmpty(error))
                    {
                        MessageBox.Show("Type was deleted");
                        this.info = null;
                        this.TypesListBox_Bind();
                        this.RefereshMain();
                    }
                    else
                    {
                        MessageBox.Show(error);
                    }
                }
            }
        }