private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (patientsListView.SelectedItems.Count > 0)
     {
         int patientId = int.Parse(patientsListView.SelectedItems[0].Tag.ToString());
         Patient patient = patientManager.GetPatientById(patientId);
         PatientDiseaseManager patientDiseaseManager = new PatientDiseaseManager();
         patientDiseaseManager.DeleteExisting(patient);
         if (patientManager.DeleteByPatientId(patientId))
         {
             Close();
             MessageBox.Show("Patient Successfully Deleted");
         }
         else
         {
             MessageBox.Show("An Error Occured");
         }
     }
     else
     {
         MessageBox.Show("You must Select a row");
     }
 }
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");
     }
 }