Esempio n. 1
0
        private MedicalInformation selectMedicalInformation(int medicalID)
        {
            MySqlConnection connection = OpenConnection();
            if (connection == null)
                return null;

            MySqlCommand selectCommand = new MySqlCommand(null, connection);
            selectCommand.CommandText = "SELECT * FROM medical_information WHERE Medical_ID = @medicalID;";
            selectCommand.Parameters.AddWithValue("@medicalID", medicalID);

            selectCommand.Prepare();
            MySqlDataReader medicalReader = selectCommand.ExecuteReader();

            MedicalInformation newMedical = new MedicalInformation();
            while (medicalReader.Read())
            {
                newMedical = constructMedical(medicalReader);
            }

            CloseConnection(connection);
            return newMedical;
        }
Esempio n. 2
0
        public void insertMedical(MedicalInformation medicalToAdd)
        {
            MySqlConnection connection = OpenConnection();
            if (connection == null)
                return;

            MySqlCommand insertCommand = new MySqlCommand(null, connection);
            insertCommand.CommandText = @"INSERT INTO medical_information VALUES (@medicalid, @allergies, @medication, @other, @doctor, @doctoraddress);";

            insertCommand.Parameters.AddWithValue("@medicalid", medicalToAdd.MedicalID);
            insertCommand.Parameters.AddWithValue("@allergies", medicalToAdd.Allergies);
            insertCommand.Parameters.AddWithValue("@medication", medicalToAdd.Medication);
            insertCommand.Parameters.AddWithValue("@other", medicalToAdd.Other);
            insertCommand.Parameters.AddWithValue("@doctor", medicalToAdd.Doctor);
            insertCommand.Parameters.AddWithValue("@doctoraddress", medicalToAdd.DoctorAddress.Address1);

            Console.WriteLine("Executing: [ " + insertCommand.CommandText + "].");
            insertCommand.Prepare();
            insertCommand.ExecuteNonQuery();

            //Remember the last medical id
            //Remember the last medical id
            MySqlCommand idCommand = new MySqlCommand("SELECT LAST_INSERT_ID()", connection);
            object test = idCommand.ExecuteScalar();
            try
            {
                lastMedicalID = int.Parse(test.ToString());
            }
            catch (ArgumentNullException)
            {

            }
            catch (FormatException)
            {

            }

            CloseConnection(connection);
        }
Esempio n. 3
0
 private MedicalInformation constructMedical(MySqlDataReader medicalReader)
 {
     MedicalInformation newMedical = new MedicalInformation();
     newMedical.MedicalID = medicalReader.GetInt16("Medical_ID");
     newMedical.Allergies = SafeGetString(medicalReader, "Allergies");
     newMedical.Medication = SafeGetString(medicalReader, "Medication");
     newMedical.Other = SafeGetString(medicalReader, "Other");
     newMedical.Doctor = medicalReader.GetString("Doctor");
     newMedical.DoctorAddress = constructAddress(medicalReader);
     return newMedical;
 }