public CaseFile GetAllReports(CaseFile caseFile) { try { MySqlDataReader reader = null; conn.Open(); string sqlStatement = "SELECT * FROM reports WHERE case_id=@caseID"; MySqlCommand command = new MySqlCommand(sqlStatement, conn); command.Prepare(); command.Parameters.AddWithValue("@caseID", caseFile.caseID); reader = command.ExecuteReader(); while (reader.Read()) { String reportID = reader["report_id"].ToString(); String caseID = reader["case_id"].ToString(); string authorID = reader["author_id"].ToString(); DateTime lastModified = reader.GetDateTime("last_modified").ToLocalTime(); Report tempReport = caseFile.AddReport(reportID, authorID.ToString()); tempReport.lastModified = lastModified; FormSyncer formSyncer = new FormSyncer(); formSyncer.GetForms(tempReport); } conn.Close(); return(caseFile); } catch (Exception e) { Console.WriteLine(e.ToString()); return(caseFile); } }
public Boolean InsertReport(CaseFile caseFile, Report report) { try { MySqlDataReader reader = null; conn.Open(); string insertStatement = "INSERT INTO reports" + "(case_id, author_id, last_modified) " + "VALUES (@caseID," + "@authorID, UTC_TIMESTAMP())"; MySqlCommand command = new MySqlCommand(insertStatement, conn); command.Prepare(); command.Parameters.AddWithValue("@caseID", caseFile.caseID); command.Parameters.AddWithValue("@authorID", "Kenny"); // TODO: Switch to current users ID command.ExecuteNonQuery(); string getIDStatement = "SELECT @@IDENTITY AS theID"; command = new MySqlCommand(getIDStatement, conn); reader = command.ExecuteReader(); while (reader.Read()) { report.reportID = reader["theID"].ToString(); } conn.Close(); FormSyncer syncer = new FormSyncer(); foreach (Form form in report.forms) { syncer.InsertForm(form); } return(true); } catch (Exception e) { Console.WriteLine(e.ToString()); return(false); } }