public Patient(int id, String firstname, String lastname, Session lastsession) { this.ID = id; this.FirstName = firstname; this.LastName = lastname; this.LastSession = lastsession; }
public Session getLastSession(int id) { MySqlDataReader rdr = null; string stm = @"SELECT `ID`, `FirstName`, `LastName`, `Date`, `CheckInOneTime`, `CheckInTwoTime`, `CheckInThreeTime`, `CheckInFourTime` FROM ( SELECT `p`.`ID`, `p`.`FirstName`, `p`.`LastName`, `s`.`Date`, `s`.`CheckInOneTime`, `s`.`CheckInTwoTime`, `s`.`CheckInThreeTime`, `s`.`CheckInFourTime` FROM `patients` p, `sessions` s WHERE `p`.`ID` = @ID AND `p`.`ID` = `s`.`patientID` ORDER BY `s`.`Date` DESC ) s LIMIT 1"; try { MySqlCommand cmd = new MySqlCommand(); cmd.Connection = this.conn; cmd.CommandText = stm; cmd.Prepare(); cmd.Parameters.AddWithValue("@ID", id); rdr = cmd.ExecuteReader(); if (rdr.Read()) { Session s = new Session(rdr.GetString(3), rdr.GetString(4), rdr.GetString(5), rdr.GetString(6), rdr.GetString(7)); rdr.Close(); return s; } else { rdr.Close(); return new Session("2012-01-01 00:00:00", "00:00", "00:00", "00:00", "00:00"); } } catch (MySqlException ex) { Console.WriteLine("Error: {0}", ex.ToString()); rdr.Close(); return new Session("2012-01-01 00:00:00", "00:00", "00:00", "00:00", "00:00"); } }