public List <DailyTaskDAO> GetActiveTasks(UserDAO patient) { List <DailyTaskDAO> results = new List <DailyTaskDAO>(); patient.Find(); if (!patient.UserClass.Equals("Patient")) { return(null); } string myQueryStr = "select DailyTaskClass, idDailyTask from DailyTask where active=true and idPatient=" + patient.idNumber; OdbcConnection myConnection = GetConnection(); OdbcCommand myCommand = new OdbcCommand(myQueryStr, myConnection); myConnection.Open(); OdbcDataReader myReader; myReader = myCommand.ExecuteReader(); try { while (myReader.Read()) { DailyTaskDAO temp = null; if (myReader.GetString(0).Equals("WalkingTask")) { temp = new WalkingTaskDAO(); temp.m_idDailyTask = myReader.GetInt32(1); } if (temp == null) { return(null); } temp.Find(); results.Add(temp); } } finally { myReader.Close(); myConnection.Close(); } return(results); }
public List<DailyTaskDAO> GetActiveTasks(UserDAO patient) { List<DailyTaskDAO> results = new List<DailyTaskDAO>(); patient.Find(); if (!patient.UserClass.Equals("Patient")) return null; string myQueryStr = "select DailyTaskClass, idDailyTask from DailyTask where active=true and idPatient=" + patient.idNumber; OdbcConnection myConnection = GetConnection(); OdbcCommand myCommand = new OdbcCommand(myQueryStr, myConnection); myConnection.Open(); OdbcDataReader myReader; myReader = myCommand.ExecuteReader(); try { while (myReader.Read()) { DailyTaskDAO temp = null; if (myReader.GetString(0).Equals("WalkingTask")) { temp = new WalkingTaskDAO(); temp.m_idDailyTask = myReader.GetInt32(1); } if (temp == null) return null; temp.Find(); results.Add(temp); } } finally { myReader.Close(); myConnection.Close(); } return results; }
// Main begins program execution. static void Main() { // Write to console Console.WriteLine("Welcome to the C# Station Tutorial!"); //Check to see if the user "bh673" exists in the database. UserDAO u = new UserDAO(); u.Username = "******"; if (u.Find()) { //The record was found. Console.WriteLine("User's record was found."); } if (u.Password.Equals("password")) { //Check to see if the user's password equals the provided password: "******" Console.WriteLine("Password was Correct!"); } //Obtain a list of daily tasks, for the user "bh673". DailyTaskDAO dtd = new DailyTaskDAO(); List <DailyTaskDAO> res = dtd.GetActiveTasks(u); //List the number of steps for each of the walking tasks. List <DailyTaskDAO> .Enumerator t = res.GetEnumerator(); while (t.MoveNext()) { Console.WriteLine("Steps: " + (t.Current as WalkingTaskDAO).Steps); } //Add a Statistics record to the database. WalkingStatsDAO s = new WalkingStatsDAO(); s.idDailyTask = 1; s.StartDateTime = new DateTime(2007, 12, 25); s.EndDateTime = new DateTime(2008, 1, 1); s.Steps = 550; Console.WriteLine("Insert: " + s.Insert()); //Pause Console.WriteLine("I executed."); }
// Main begins program execution. static void Main() { // Write to console Console.WriteLine("Welcome to the C# Station Tutorial!"); //Check to see if the user "bh673" exists in the database. UserDAO u = new UserDAO(); u.Username = "******"; if (u.Find()) //The record was found. Console.WriteLine("User's record was found."); if (u.Password.Equals("password")) //Check to see if the user's password equals the provided password: "******" Console.WriteLine("Password was Correct!"); //Obtain a list of daily tasks, for the user "bh673". DailyTaskDAO dtd = new DailyTaskDAO(); List<DailyTaskDAO> res = dtd.GetActiveTasks(u); //List the number of steps for each of the walking tasks. List<DailyTaskDAO>.Enumerator t = res.GetEnumerator(); while (t.MoveNext()) Console.WriteLine("Steps: " + (t.Current as WalkingTaskDAO).Steps); //Add a Statistics record to the database. WalkingStatsDAO s = new WalkingStatsDAO(); s.idDailyTask = 1; s.StartDateTime = new DateTime(2007, 12, 25); s.EndDateTime = new DateTime(2008, 1, 1); s.Steps = 550; Console.WriteLine("Insert: " + s.Insert()); //Pause Console.WriteLine("I executed."); }