//Fetch existing DT from Database based on taskId and update this instance with its info public DisposableTask FetchDisposableTask(int taskId) { MySqlConnection conn = null; DisposableTask myDisposableTask = new DisposableTask(); try { conn = new MySqlConnection(connectionString); conn.Open(); MySqlCommand cmd = new MySqlCommand("SELECT* from `Task` WHERE `TaskId` = @taskId", conn); cmd.Parameters.Add(new MySqlParameter("taskId", taskId)); MySqlDataReader reader = cmd.ExecuteReader(); reader.Read(); myDisposableTask.setTaskId((int)reader.GetValue(0)); //TaskId myDisposableTask.setTitle((String)reader.GetValue(1)); //Title myDisposableTask.setDescription((String)reader.GetValue(2)); //Notes myDisposableTask.setAllowNotifications((Boolean)reader.GetValue(3)); //allowNotifications myDisposableTask.setIsComplete((Boolean)reader.GetValue(4)); //isComplete myDisposableTask.setRepeatability((Boolean)reader.GetValue(5)); //isRepeatable myDisposableTask.setTaskFKey((int)reader.GetValue(6)); //taskFKey } catch (Exception ex) { Console.WriteLine("FetchDisposableTask Failure!" + ex); } finally { if (conn != null) { conn.Close(); } } myDisposableTask.setSubTasks(FetchAllSubTasks(taskId)); return(myDisposableTask); }
//if createTask is clicked private void backToDash(object sender, RoutedEventArgs e) { taskTitle = this.taskTitleText.Text; taskDesc = this.descText.Text; if (this.yesRadio.IsChecked == true) { this.repeatable = true; //create repeatableTask RepeatableTask rt = new RepeatableTask(taskTitle, taskDesc, dict); rt.setTaskFKey(user.UserId); rt.SaveTask(); //save task to db list.Add(rt); Dashboard dash = new Dashboard(user); NavigationService.Navigate(dash); } else if (this.noRadio.IsChecked == true) { repeatable = false; //create disposableTask DisposableTask dt = new DisposableTask(taskTitle, taskDesc, dict); dt.setTaskFKey(user.UserId); //dt.setTaskFKey(55); //TODO user.UserId does not return the correct ID dt.SaveTask(); //save task to db list.Add(dt); Dashboard dash = new Dashboard(user); NavigationService.Navigate(dash); } //NavigationService nav = NavigationService.GetNavigationService(this); // nav.Navigate(new Uri("/GUI/Dashboard.xaml", UriKind.RelativeOrAbsolute)); }