/// <summary> /// Retrieve all previous medicines the patient has had from the database. /// </summary> public void retrieveMedicineHistory() { DataTable table = new DataTable(); string connStr = "server=csdatabase.eku.edu;user=stu_csc340;database=csc340_db;port=3306;password=Colonels18;SSLMode=None"; MySqlConnection conn = new MySqlConnection(connStr); try { Console.WriteLine("Connecting to MySQL..."); conn.Open(); string sql = "SELECT m.name, DATE_FORMAT(pr.dateFilled, \"%m-%d-%Y\") AS dateFilled, m.quantity, m.dosage, m.route, " + "m.instructions, m.prescriptionID " + "FROM DixonPatient pa JOIN DixonPrescription pr ON pr.patientID = pa.patientID " + "JOIN DixonMedicine m ON m.prescriptionID = pr.id WHERE pa.patientID = @id;"; MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.Parameters.AddWithValue("@id", Id); MySqlDataAdapter myAdapter = new MySqlDataAdapter(cmd); myAdapter.Fill(table); Console.WriteLine("Table is ready."); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } conn.Close(); MedicineHistory.Clear(); //remove medicines from medicineHistory before adding all of them foreach (DataRow row in table.Rows) { Medicine medicine = new Medicine(); medicine.Name = row["name"].ToString(); medicine.Date = row["dateFilled"].ToString(); medicine.Quantity = (int)row["quantity"]; medicine.Dosage = row["dosage"].ToString(); medicine.Route = row["route"].ToString(); medicine.Instructions = row["instructions"].ToString(); medicine.PrescriptionID = (int)row["prescriptionID"]; medicineHistory.Add(medicine); } }
/// <summary> /// Adds list of medicines to the Medicines property of prescription. /// </summary> public void retrieveMedicines() { DataTable table = new DataTable(); string connStr = "server=csdatabase.eku.edu;user=stu_csc340;database=csc340_db;port=3306;password=Colonels18;SSLMode=None"; MySqlConnection conn = new MySqlConnection(connStr); try { Console.WriteLine("Connecting to MySQL..."); conn.Open(); string sql = "SELECT m.name, m.quantity, m.dosage, m.route, m.instructions " + "FROM DixonPrescription pr JOIN DixonMedicine m ON m.prescriptionID = pr.id " + "WHERE pr.id = @id;"; MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.Parameters.AddWithValue("@id", Id); MySqlDataAdapter myAdapter = new MySqlDataAdapter(cmd); myAdapter.Fill(table); Console.WriteLine("Table is ready."); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } conn.Close(); ArrayList medicines = new ArrayList(); foreach (DataRow row in table.Rows) { Medicine medicine = new Medicine(); medicine.Name = row["name"].ToString(); medicine.Quantity = (int)row["quantity"]; medicine.Dosage = row["dosage"].ToString(); medicine.Route = row["route"].ToString(); medicine.Instructions = row["instructions"].ToString(); medicines.Add(medicine); } Medicines = medicines; }