//Saves Task, used by RepeatableTask.SaveTask() public void SaveRepeatTask(RepeatableTask savedTask) { if (doesTaskExist(savedTask.getTaskId())) { MySqlConnection conn = null; try { conn = new MySqlConnection(connectionString); conn.Open(); MySqlCommand cmd = new MySqlCommand("UPDATE `Task` SET `title` = @title, `notes` = @notes," + "`allowNotifications` = @allowNotifications, `isComplete` = @isComplete, `isRepeatable` = @isRepeatable," + "`taskFKey` = @taskFKey WHERE `taskId` = @taskId", conn); cmd.Parameters.Add(new MySqlParameter("taskId", savedTask.getTaskId())); cmd.Parameters.Add(new MySqlParameter("title", savedTask.getTitle())); cmd.Parameters.Add(new MySqlParameter("notes", savedTask.getDescription())); cmd.Parameters.Add(new MySqlParameter("allowNotifications", savedTask.getAllowNotifications())); cmd.Parameters.Add(new MySqlParameter("isComplete", savedTask.getIsComplete())); cmd.Parameters.Add(new MySqlParameter("isRepeatable", false)); cmd.Parameters.Add(new MySqlParameter("taskFKey", savedTask.getTaskId())); cmd.ExecuteNonQuery(); } catch (Exception ex) { Console.WriteLine("SaveRepeatTask Failure!" + ex); } finally { if (conn != null) { conn.Close(); } } } }
//Inserts new Repeatable task into the table public int InsertRepeatTask(RepeatableTask newTask) { MySqlConnection conn = null; MySqlCommand command = null; int taskId = 0; try { conn = new MySqlConnection(connectionString); conn.Open(); command = new MySqlCommand("INSERT INTO `Task` (`title`,`notes`,`allowNotifications`, `isComplete`,`isRepeatable`) " + "VALUES(@title, @notes, @allowNotifications, @isComplete, @isRepeatable);" + "SELECT `taskId` AS `taskId` FROM `Task` WHERE `taskId` = @@Identity;", conn); command.Parameters.AddWithValue("@title", newTask.getTitle()); command.Parameters.AddWithValue("@notes", newTask.getDescription()); command.Parameters.AddWithValue("@allowNotifications", newTask.getAllowNotifications()); command.Parameters.AddWithValue("@isComplete", newTask.getIsComplete()); command.Parameters.AddWithValue("@isRepeatable", 1); MySqlDataReader reader = command.ExecuteReader(); taskId = (int)reader.GetValue(0); } catch (Exception ex) { Console.WriteLine("InsertDisposableTask: Failure!" + ex); } finally { if (conn != null) { conn.Close(); } } return(taskId); }