Пример #1
0
 private void AddPatientButton_Click(object sender, EventArgs e)
 {
     using (Form patientFormDialog = new PatientInformationDialog(new UserDTO()))
     {
         DialogResult result = patientFormDialog.ShowDialog();
         if (result == DialogResult.OK || result == DialogResult.Cancel)
         {
             this.RefreshDataGrid();
         }
     }
 }
Пример #2
0
        /// <summary>
        /// The event handler method for PatientsDatatGrid CellContentClick
        /// </summary>
        private void PatientsDatatGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            patient = (UserDTO)patientsDatatGrid.Rows[e.RowIndex].DataBoundItem;
            if (patientsDatatGrid.Columns[e.ColumnIndex].Name == "ViewAppointment")
            {
                this.appointmentsDataGridView.Visible    = true;
                this.appointmentsDataGridView.DataSource = null;

                List <AppointmentDTO> appointmentDTO = this.appointmentController.GetPatientsAppointments(new Patient(patient.PatientId, patient.Id, true));

                if (appointmentDTO.Count <= 0)
                {
                    MessageBox.Show("No Appointments found in the system for the Patient.", "Not Found", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                this.appointmentsDataGridView.DataSource = appointmentDTO;
            }
            else if (patientsDatatGrid.Columns[e.ColumnIndex].Name == "EditPatient")
            {
                using (Form patientFormDialog = new PatientInformationDialog(patient))
                {
                    DialogResult result = patientFormDialog.ShowDialog();
                    if (result == DialogResult.OK || result == DialogResult.Cancel)
                    {
                        this.RefreshDataGrid();
                    }
                }
            }
            else if (patientsDatatGrid.Columns[e.ColumnIndex].Name == "CreateAppointment")
            {
                using (Form newAppointmentDialog = new NewAppointmentDialog(patient))
                {
                    DialogResult result = newAppointmentDialog.ShowDialog();
                    if (result == DialogResult.OK || result == DialogResult.Cancel)
                    {
                        this.RefreshDataGrid();
                    }
                }
            }
            else if (patientsDatatGrid.Columns[e.ColumnIndex].Name == "DeletePatient")
            {
                var hasUpcomingAppointment = this.appointmentController.GetPatientsAppointments(new Patient(patient.PatientId, patient.Id, true)).Exists(x => x.AppointmentDateTime >= DateTime.Now);
                if (!hasUpcomingAppointment)
                {
                    string message = "Are you sure you want to delete this patient?"
                                     + Environment.NewLine + $"Patient: {patient.FullName}";
                    string caption = $"Delete {patient.FirstName}  {patient.LastName}";
                    var    result  = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        if (patientController.DeletePatient(new Patient(patient.PatientId, patient.Id, true)))
                        {
                            MessageBox.Show("Patient deleted successfully");
                            PatientSearch();
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Patient has upcoming appointment and can't be deleted.");
                }
            }
        }