public void Save(PatientDisease patientDisease)
 {
     string connectionString = ConfigurationManager.ConnectionStrings["HospitalConnectionString"].ConnectionString;
     SqlConnection sqlConnection = new SqlConnection(connectionString);
     string query = "INSERT INTO PatientDiseaseTable (PatientId,DiseaseId) VALUES('" + patientDisease.PatientId + "','"+patientDisease.DiseaseId+"')";
     SqlCommand sqlCommand = new SqlCommand(query, sqlConnection);
     sqlConnection.Open();
     sqlCommand.ExecuteNonQuery();
     sqlConnection.Close();
 }
Example #2
0
 private void saveButton_Click(object sender, EventArgs e)
 {
     PatientManager patientManager=new PatientManager();
     PatientDiseaseManager patientDiseaseManager=new PatientDiseaseManager();
     Patient patient=new Patient();
     patient.Id = patientId;
     patient.Name = patientsNameTextBox.Text;
     patient.DoctorId = int.Parse(doctorComboBox.SelectedValue.ToString());
     if (mode == "Update" && patient.Name!="")
     {
         int row = patientManager.Update(patient);
         if (row == 1)
         {
             PatientDiseaseManager aPatientDiseaseManager=new PatientDiseaseManager();
             aPatientDiseaseManager.DeleteExisting(patient);
             foreach (var index in diseaseCheckedListBox.CheckedItems)
             {
                 Disease disease = (Disease)index;
                 PatientDisease patientDisease = new PatientDisease();
                 patientDisease.PatientId = patient.Id;
                 patientDisease.DiseaseId = disease.Id;
                 patientDiseaseManager.Save(patientDisease);
             }
             Close();
             MessageBox.Show("Patient Successfully Updated");
         }
     }
     else if(patient.Name!="")
     {
         int retrievedPatientId = patientManager.Save(patient);
         if (retrievedPatientId > 0)
         {
             foreach (var index in diseaseCheckedListBox.CheckedItems)
             {
                 Disease disease = (Disease) index;
                 PatientDisease patientDisease = new PatientDisease();
                 patientDisease.PatientId = retrievedPatientId;
                 patientDisease.DiseaseId = disease.Id;
                 patientDiseaseManager.Save(patientDisease);
             }
             Close();
             MessageBox.Show("Patient Successfully Saved");
         }
     }
     else
     {
         MessageBox.Show("Name cannot be empty");
     }
 }
 public void Save(PatientDisease patientDisease)
 {
     patientDiseaseGateway.Save(patientDisease);
 }