private void DoneButton_Click(object sender, EventArgs e) { if (MetroFramework.MetroMessageBox.Show(this, "Are you sure task is done? This action is irrevocable and it will remove the task from the list..", "Proceed?", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { Bunifu.Framework.UI.BunifuImageButton selecteddonebutton = (Bunifu.Framework.UI.BunifuImageButton)sender; int getRowDone = TaskTable.GetRow(selecteddonebutton); var getPlayPauseButton = (Bunifu.Framework.UI.BunifuImageButton)TaskTable.GetControlFromPosition(2, getRowDone); if (getPlayPauseButton.Tag.ToString() == "Played") { PlayPauseButton_Click(getPlayPauseButton, e); } using (var conn = new MySqlConnection(ConnectionString)) { conn.Open(); using (MySqlCommand cmd = conn.CreateCommand()) { var getTaskLabelText = (Label)TaskTable.GetControlFromPosition(0, getRowDone); cmd.CommandText = "UPDATE `tbl_tasks` SET `isDone` = '1', `timestampUpdated` = NOW() WHERE `taskName` = @taskname AND `userID` = @userid AND `isDone` = '0' LIMIT 1;"; cmd.Parameters.AddWithValue("@userid", SetUser.Text); cmd.Parameters.AddWithValue("@taskname", getTaskLabelText.Text); if (cmd.ExecuteNonQuery() != 0) { getPlayPauseButton.Tag = "Stopped"; getPlayPauseButton.Image = new Bitmap(Properties.Resources.CircledPlay_34px); TaskTable.RowStyles[getRowDone].Height = 0F; } else { MetroFramework.MetroMessageBox.Show(this, "Cannot set the task to done! Please check db connection and try again!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }
public void RunAutoSave() { if (TaskTable.RowCount > 0) { for (int i = 0; i < TaskTable.RowCount - 2; i++) { var autoSaveButton = (Bunifu.Framework.UI.BunifuImageButton)TaskTable.GetControlFromPosition(2, i); if (autoSaveButton != null) { if (autoSaveButton.Tag.ToString() == "Played") { try { using (var conn = new MySqlConnection(ConnectionString)) { conn.Open(); using (MySqlCommand cmd = conn.CreateCommand()) { int getRowPlayPause = TaskTable.GetRow(autoSaveButton); var getTaskLabelText = (Label)TaskTable.GetControlFromPosition(0, getRowPlayPause); var SessionTime = (Label)TaskTable.GetControlFromPosition(1, getRowPlayPause); cmd.CommandText = "UPDATE `tbl_taskslog` SET `tasklogTime` = @tasklogtime, `timestampEnded` = NOW() WHERE `tasklogTime` IS NULL AND `timestampEnded` IS NULL AND `taskID` = (SELECT `taskID` FROM `tbl_tasks` WHERE `taskName` = @taskname AND `userID` = @userid);"; cmd.Parameters.AddWithValue("@tasklogtime", TimeSpan.Parse(SessionTime.Text).Subtract(TimeSpan.Parse(SessionTime.Tag.ToString())).ToString()); cmd.Parameters.AddWithValue("@userid", SetUser.Text); cmd.Parameters.AddWithValue("@taskname", getTaskLabelText.Text); if (cmd.ExecuteNonQuery() != 0) { using (MySqlCommand cmd1 = conn.CreateCommand()) { cmd1.CommandText = "UPDATE `tbl_tasks` SET `totalTime` = @tasklogtime, `timestampUpdated` = NOW() WHERE `taskName` = @taskname AND `userID` = @userid;"; cmd1.Parameters.AddWithValue("@tasklogtime", SessionTime.Text); cmd1.Parameters.AddWithValue("@userid", SetUser.Text); cmd1.Parameters.AddWithValue("@taskname", getTaskLabelText.Text); if (cmd1.ExecuteNonQuery() != 0) { autoSaveButton.Tag = "Stopped"; autoSaveButton.Image = new Bitmap(Properties.Resources.CircledPlay_34px); } else { MetroFramework.MetroMessageBox.Show(this, "Cannot update parent task! Please check db connection and try again!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MetroFramework.MetroMessageBox.Show(this, "Cannot pause tasks! Please check db connection and try again!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } catch (Exception ex) { MetroFramework.MetroMessageBox.Show(this, ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } } }
private void PlayPauseButton_Click(object sender, EventArgs e) { Bunifu.Framework.UI.BunifuImageButton selectedplaypausebutton = (Bunifu.Framework.UI.BunifuImageButton)sender; if (selectedplaypausebutton.Tag.ToString() == "Stopped") { try { using (var conn = new MySqlConnection(ConnectionString)) { conn.Open(); using (MySqlCommand cmd = conn.CreateCommand()) { int getRowPlayPause = TaskTable.GetRow(selectedplaypausebutton); var getTaskLabelText = (Label)TaskTable.GetControlFromPosition(0, getRowPlayPause); cmd.CommandText = "INSERT INTO `tbl_taskslog` (`taskID`,`timestampStarted`) VALUES ((SELECT `taskID` FROM `tbl_tasks` WHERE `taskName` = @taskname AND `userID` = @userid),NOW());"; cmd.Parameters.AddWithValue("@userid", SetUser.Text); cmd.Parameters.AddWithValue("@taskname", getTaskLabelText.Text); if (cmd.ExecuteNonQuery() != 0) { selectedplaypausebutton.Tag = "Played"; selectedplaypausebutton.Image = new Bitmap(Properties.Resources.PauseButtonLIGHt_34px); } else { MetroFramework.MetroMessageBox.Show(this, "Cannot resume tasks! Please check db connection and try again!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } catch (Exception ex) { MetroFramework.MetroMessageBox.Show(this, ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (selectedplaypausebutton.Tag.ToString() == "Played") { try { using (var conn = new MySqlConnection(ConnectionString)) { conn.Open(); using (MySqlCommand cmd = conn.CreateCommand()) { int getRowPlayPause = TaskTable.GetRow(selectedplaypausebutton); var getTaskLabelText = (Label)TaskTable.GetControlFromPosition(0, getRowPlayPause); var SessionTime = (Label)TaskTable.GetControlFromPosition(1, getRowPlayPause); cmd.CommandText = "UPDATE `tbl_taskslog` SET `tasklogTime` = @tasklogtime, `timestampEnded` = NOW() WHERE `tasklogTime` IS NULL AND `timestampEnded` IS NULL AND `taskID` = (SELECT `taskID` FROM `tbl_tasks` WHERE `taskName` = @taskname AND `userID` = @userid);"; cmd.Parameters.AddWithValue("@tasklogtime", TimeSpan.Parse(SessionTime.Text).Subtract(TimeSpan.Parse(SessionTime.Tag.ToString())).ToString()); cmd.Parameters.AddWithValue("@userid", SetUser.Text); cmd.Parameters.AddWithValue("@taskname", getTaskLabelText.Text); if (cmd.ExecuteNonQuery() != 0) { using (MySqlCommand cmd1 = conn.CreateCommand()) { cmd1.CommandText = "UPDATE `tbl_tasks` SET `totalTime` = @tasklogtime, `timestampUpdated` = NOW() WHERE `taskName` = @taskname AND `userID` = @userid;"; cmd1.Parameters.AddWithValue("@tasklogtime", SessionTime.Text); cmd1.Parameters.AddWithValue("@userid", SetUser.Text); cmd1.Parameters.AddWithValue("@taskname", getTaskLabelText.Text); if (cmd1.ExecuteNonQuery() != 0) { selectedplaypausebutton.Tag = "Stopped"; selectedplaypausebutton.Image = new Bitmap(Properties.Resources.CircledPlay_34px); } else { MetroFramework.MetroMessageBox.Show(this, "Cannot update parent task! Please check db connection and try again!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MetroFramework.MetroMessageBox.Show(this, "Cannot pause tasks! Please check db connection and try again!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } catch (Exception ex) { MetroFramework.MetroMessageBox.Show(this, ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void Delete_Click(object sender, EventArgs e) { if (sender is MenuItem menuItem) { ContextMenu menu = menuItem.GetContextMenu(); Control sourceControl = menu.SourceControl; try { int getRowDelete = TaskTable.GetRow(sourceControl); var getControl1 = TaskTable.GetControlFromPosition(0, getRowDelete); var getControl2 = TaskTable.GetControlFromPosition(1, getRowDelete); var getControl3 = TaskTable.GetControlFromPosition(2, getRowDelete); var getControl4 = TaskTable.GetControlFromPosition(3, getRowDelete); using (var conn = new MySqlConnection(ConnectionString)) { conn.Open(); using (MySqlCommand cmd = conn.CreateCommand()) { cmd.CommandText = "SELECT * FROM `tbl_taskslog` WHERE `taskID` = (SELECT `taskID` FROM `tbl_tasks` WHERE `taskName` = @taskname AND `userID` = @userid LIMIT 1);"; cmd.Parameters.AddWithValue("@taskname", sourceControl.Text); cmd.Parameters.AddWithValue("@userid", SetUser.Text); using (MySqlDataReader reader = cmd.ExecuteReader()) { if (reader.HasRows) { reader.Close(); if (MetroFramework.MetroMessageBox.Show(this, "There are logs associated with the task, are you sure you want to delete it? logs will also be deleted and it is irrevocable!", "Are you sure?!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { using (MySqlCommand cmd1 = conn.CreateCommand()) { cmd1.CommandText = "DELETE FROM `tbl_taskslog` WHERE `taskID` = (SELECT `taskID` FROM `tbl_tasks` WHERE `taskName` = @taskname AND `userID` = @userid); DELETE FROM `tbl_tasks` WHERE `taskName` = @taskname AND `userID` = @userid LIMIT 1;"; cmd1.Parameters.AddWithValue("@userid", SetUser.Text); cmd1.Parameters.AddWithValue("@taskname", sourceControl.Text); if (cmd1.ExecuteNonQuery() == 0) { MetroFramework.MetroMessageBox.Show(this, "Cannot delete the task! Please check db connection and try again!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { TaskTable.RowStyles[getRowDelete].Height = 0F; getControl1.Dispose(); getControl2.Dispose(); getControl3.Dispose(); getControl4.Dispose(); return; } } } else { return; } } else { reader.Close(); using (MySqlCommand cmd1 = conn.CreateCommand()) { cmd1.CommandText = "DELETE FROM `tbl_tasks` WHERE `taskName` = @taskname AND `userID` = @userid LIMIT 1;"; cmd1.Parameters.AddWithValue("@userid", SetUser.Text); cmd1.Parameters.AddWithValue("@taskname", sourceControl.Text); if (cmd1.ExecuteNonQuery() == 0) { MetroFramework.MetroMessageBox.Show(this, "Cannot delete the task! Please check db connection and try again!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { TaskTable.RowStyles[getRowDelete].Height = 0F; getControl1.Dispose(); getControl2.Dispose(); getControl3.Dispose(); getControl4.Dispose(); return; } } } } } } } catch (Exception ex) { MetroFramework.MetroMessageBox.Show(this, ex.ToString(), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }