public bool addSubTask(SubTask inTask) { MySqlConnection conn = null; MySqlCommand command = null; try{ conn = new MySqlConnection(connectionString); conn.Open(); command = new MySqlCommand( "INSERT INTO 'SubTask' (SubTaskID, DueDate, isComplete, FilePath, Title, Description, RepeatFrom) VALUES (@subTaskID, @dueDate, @isComplete, @filePath, @title, @description, @repeatFrom", conn ); command.Parameters.AddWithValue("@subTaskId", inTask.getId()); command.Parameters.AddWithValue("@dueDate", inTask.getDueDate()); command.Parameters.AddWithValue("@isComplete", inTask.isComplete()); command.Parameters.AddWithValue("@title", inTask.getTitle()); command.Parameters.AddWithValue("@description", inTask.getNotes()); command.Parameters.AddWithValue("@repeatfrom", null); command.ExecuteNonQuery(); }catch (Exception ex) { Console.WriteLine("this is not supposed to happen" + ex); return(false); } finally{ if (conn != null) { conn.Close(); } } return(true); }
//notes field->somehow wrap text onto new line to fill box area? (it's all just going onto one line) private void addSubTask(object sender, RoutedEventArgs e) { if (subTitle == "" && subNotes == "") { } else { subTitle = this.subTitleText.Text; subNotes = this.subNotesText.Text; if (this.dueDatePicker.SelectedDate == null) { dueDate = new DateTime(); } else { dueDate = this.dueDatePicker.SelectedDate.Value.Date; } SubTask subt = new SubTask(dueDate, subTitle, subNotes); subt.SaveSubTask(); //save subtask to db this.idCount++; //int nextId = subt.getNextId(); //subt.setId(nextId); dict.Add(idCount, subt); this.subTitleText.Text = ""; this.subNotesText.Text = ""; this.dueDatePicker.SelectedDate = null; this.dueDatePicker.DisplayDate = DateTime.Today; } }
public SubTask getSubTask(int inId) { SubTask task = new SubTask(); task.setId(inId); MySqlConnection conn = null; MySqlCommand command = null; MySqlDataReader reader = null; try{ conn = new MySqlConnection(connectionString); conn.Open(); command = new MySqlCommand( "SELECT * FROM `SubTask` WHERE `SubTaskId` = @inId;", conn); command.Parameters.AddWithValue("@inId", inId); reader = command.ExecuteReader(); reader.Read(); task.setDueDate((DateTime)reader.GetValue(1)); task.setTitle((String)reader.GetValue(4)); task.setNotes((String)reader.GetValue(5)); return(task); }catch (Exception ex) { Console.WriteLine("this is not supposed to happen: " + ex); return(null); } finally{ if (conn != null) { conn.Close(); } } }
public void UpdateSubTask(SubTask subTask) { if (CheckTaskExistsInDB(subTask.getId())) { MySqlConnection conn = null; try { conn = new MySqlConnection(connectionString); conn.Open(); MySqlCommand cmd = new MySqlCommand("UPDATE `SubTask` SET `DueDate` = @DueDate, `isComplete` = @isComplete," + "`FilePath` = @FilePath, `Title` = @Title, `Description` = @Description," + "`RepeatFrom` = @RepeatFrom WHERE `SubTaskID` = @SubTaskID", conn); cmd.Parameters.Add(new SqlParameter("DueDate", subTask.getDueDate())); cmd.Parameters.Add(new SqlParameter("isComplete", subTask.getTaskComplete())); cmd.Parameters.Add(new SqlParameter("Title", subTask.getTitle())); cmd.Parameters.Add(new SqlParameter("Description", subTask.getNotes())); cmd.Parameters.Add(new SqlParameter("RepeatFrom", subTask.getRepeatFrom())); cmd.ExecuteNonQuery(); } catch (Exception ex) { Console.WriteLine("UpdateSubTask Failure!" + ex); } finally { if (conn != null) { conn.Close(); } } } }
public void getFromDB(int inId) { SubTask temp = db.getSubTask(inId); this.complete = temp.complete; this.dueDate = temp.dueDate; this.subtaskId = temp.subtaskId; this.title = temp.title; this.notes = temp.notes; }
//returns all subtasks with the subtaskFKey to match the parameter taskId public Dictionary <int, SubTask> FetchAllSubTasks(int taskId) { Dictionary <int, SubTask> returnedSubTasks = new Dictionary <int, SubTask>(); SubTask tempSubTask; MySqlConnection conn = null; try { conn = new MySqlConnection(connectionString); conn.Open(); MySqlCommand cmd = new MySqlCommand("SELECT * FROM `Subtask` WHERE `subtaskFKey` = @taskId", conn); cmd.Parameters.Add(new MySqlParameter("subtaskFKey", taskId)); MySqlDataReader reader = cmd.ExecuteReader(); int count = reader.FieldCount; while (reader.Read()) { for (int i = 0; i < count; i++) { tempSubTask = new SubTask(); SubTask temp = FetchSubTask(((int)reader.GetValue(i))); temp.setId((int)reader.GetValue(0)); //subtaskId temp.setDueDate((DateTime)reader.GetValue(1)); //dueDate temp.setTitle((String)reader.GetValue(2)); //title temp.setNotes((String)reader.GetValue(3)); //description //TODO THIS WON'T WORK //TODO THIS WON'T WORK temp.setRepeatFrom((DateTime)reader.GetValue(5)); //repeatFrom temp.setTaskComplete((Boolean)reader.GetValue(6)); //isComplete temp.setSubtaskFKey((int)reader.GetValue(7)); //subTaskFKey returnedSubTasks.Add(((int)reader.GetValue(i)), temp); } } //Console.WriteLine("Result: Success!"); } catch (Exception ex) { Console.WriteLine("fetchAllSubTasks: Failure!" + ex); } finally { if (conn != null) { conn.Close(); } } return(returnedSubTasks); }
//Returns a Subtask object for the passed in id public SubTask FetchSubTask(int SubtaskId) { MySqlConnection conn = null; SubTask mySubTask = new SubTask(); if (CheckSubTaskExistsInDB(SubtaskId)) { try { conn = new MySqlConnection(connectionString); conn.Open(); MySqlCommand cmd = new MySqlCommand("SELECT* from `Subtask` WHERE `subtaskId` = @SubtaskId", conn); cmd.Parameters.Add(new MySqlParameter("SubtaskId", SubtaskId)); MySqlDataReader reader = cmd.ExecuteReader(); int count = reader.FieldCount; //Database columns: //subtaskId dueDate title description filePath repeatFrom isComplete subtaskFKey mySubTask.setId((int)reader.GetValue(0)); //subtaskId mySubTask.setDueDate((DateTime)reader.GetValue(1)); //dueDate mySubTask.setTitle((String)reader.GetValue(2)); //title mySubTask.setNotes((String)reader.GetValue(3)); //description //TODO THIS WON'T WORK //TODO THIS WON'T WORK mySubTask.setRepeatFrom((DateTime)reader.GetValue(5)); //repeatFrom mySubTask.setTaskComplete((Boolean)reader.GetValue(6)); //isComplete mySubTask.setSubtaskFKey((int)reader.GetValue(7)); //subTaskFKey //Console.WriteLine("Result: Success!"); } catch (Exception ex) { Console.WriteLine("fetchSubTask: Failure!" + ex); } finally { if (conn != null) { conn.Close(); } } } return(mySubTask); }
public override Boolean Equals(Object obj) { Boolean returnBool = false; if (obj is SubTask) { SubTask temp = (SubTask)obj; if (this.dueDate.Equals(temp.dueDate) && this.complete.Equals(temp.complete) && this.title.Equals(temp.title) && this.notes.Equals(temp.notes) && this.subtaskId.Equals(temp.subtaskId) && this.repeatFrom.Equals(temp.repeatFrom) && this.subtaskFKey.Equals(temp.subtaskFKey)) { returnBool = true; } } return(returnBool); }
public void InsertSubTask(SubTask subTask) { addSubTask(subTask); }