//Method used to search the InPatient by their ID public static InPatients SearchInPatient(int patient_id) { SqlConnection conn = DatabaseHelper.GetConnectionObject(); SqlCommand command = DatabaseHelper.GetCommandObject(); InPatients inpatient = new InPatients(); command.CommandText = "SELECT * FROM [187057_Akash].inpatients WHERE patient_id = " + patient_id + ""; conn.Open(); int recordsCount = Convert.ToInt32(command.ExecuteScalar()); if (recordsCount > 0) { SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { inpatient.Patient_Id = reader.GetInt32(0); inpatient.AdmitDate = reader.GetDateTime(1); inpatient.DoctorAssigned = reader.GetInt32(2); inpatient.Disease = reader.GetString(3); inpatient.RoomAssigned = reader.GetInt32(4); } } conn.Close(); return(inpatient); }
private void AddInpatientInfo(object sender, RoutedEventArgs e) { InPatients inpatient = new InPatients(); try { inpatient.Patient_Id = Convert.ToInt32(patientid.Text); inpatient.AdmitDate = Convert.ToDateTime(admission_date_textbox.Text.ToString()); inpatient.DoctorAssigned = Convert.ToInt32((doctor_assigned_textbox.SelectedItem as ComboboxItem).Value); inpatient.Disease = Convert.ToString(disease_textbox.Text.ToString()); inpatient.RoomAssigned = Convert.ToInt32((room_assigned_textbox.SelectedItem as ComboboxItem).Value); bool isAdded = HospitalBusinessLayer.HospitalBAL.AddInPatient(inpatient); if (isAdded) { MessageBox.Show("Added"); } else { MessageBox.Show("Unable to add"); } }catch (Exception exp) { MessageBox.Show(exp.Message); } }
//Method to add an InPatient public static bool AddInPatients(InPatients inpatient) { SqlConnection conn = DatabaseHelper.GetConnectionObject(); SqlCommand command = DatabaseHelper.GetCommandObject(); bool isAdded = false; command.CommandText = "INSERT INTO [187057_Akash].inpatients VALUES ('" + inpatient.Patient_Id + "', '" + inpatient.AdmitDate.ToString("yyyy-MM-dd HH:mm:ss") + "', '" + inpatient.DoctorAssigned + "', '" + inpatient.Disease + "', '" + inpatient.RoomAssigned + "');"; conn.Open(); int result = command.ExecuteNonQuery(); if (result > 0) { SqlCommand command2 = DatabaseHelper.GetCommandObject(); command2.Parameters.Clear(); command2.Connection = conn; command2.Parameters.AddWithValue("@patient_id", inpatient.Patient_Id); command2.Parameters.AddWithValue("@room_assigned", inpatient.RoomAssigned); command2.CommandText = "UPDATE [187057_Akash].rooms SET patient_id =@patient_id WHERE room_id =@room_assigned;"; command2.ExecuteNonQuery(); isAdded = true; } conn.Close(); return(isAdded); }
//Add a new INPATIENT public static bool AddInPatient(InPatients inpatient) { return(HospitalDataAccessLayer.HospitalDAL.AddInPatients(inpatient)); }