Ejemplo n.º 1
0
 private void AppointmentDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     appointmentDTO = (AppointmentDTO)appointmentDataGridView.Rows[e.RowIndex].DataBoundItem;
     if (appointmentDataGridView.Columns[e.ColumnIndex].Name == "ViewVisit")
     {
         using (Form appointmmentVisitFormDialog = new AppointmentVisitDialog(appointmentDTO))
         {
             DialogResult result = appointmmentVisitFormDialog.ShowDialog();
             if (result == DialogResult.OK || result == DialogResult.Cancel)
             {
                 this.LoadDataGrid();
             }
         };
     }
     else if (appointmentDataGridView.Columns[e.ColumnIndex].Name == "EditAppointment")
     {
         var _datediff = appointmentDTO.AppointmentDateTime - DateTime.Now;
         var patient   = patientController.GetPatientByPatientId(appointmentDTO.PatientID.Value);
         if (_datediff.Days >= 1)
         {
             using (Form editAppointmentDialog = new AppointmentInformationDialog(appointmentDTO, patient))
             {
                 DialogResult result = editAppointmentDialog.ShowDialog();
                 if (result == DialogResult.OK || result == DialogResult.Cancel)
                 {
                     this.LoadDataGrid();
                 }
             }
         }
         else
         {
             MessageBox.Show("Appointments less than 24 hours cannot be edited.", "Unauthorized", MessageBoxButtons.OK, MessageBoxIcon.Stop);
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// The event handler method for AppointmentDatatGrid CellContentClick
 /// </summary>
 private void AppointmentDatatGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     appointmentDTO = (AppointmentDTO)appointmentsDataGridView.Rows[e.RowIndex].DataBoundItem;
     if (appointmentsDataGridView.Columns[e.ColumnIndex].Name == "ViewVisit")
     {
         Form         appointmmentVisitFormDialog = new AppointmentVisitDialog(appointmentDTO);
         DialogResult result = appointmmentVisitFormDialog.ShowDialog();
     }
     else if (appointmentsDataGridView.Columns[e.ColumnIndex].Name == "EditAppointment")
     {
         var _datediff = appointmentDTO.AppointmentDateTime - DateTime.Now;
         if (_datediff.Days >= 1)
         {
             using (Form editAppointmentDialog = new AppointmentInformationDialog(appointmentDTO, patient))
             {
                 DialogResult result = editAppointmentDialog.ShowDialog();
                 if (result == DialogResult.OK || result == DialogResult.Cancel)
                 {
                     this.RefreshDataGrid();
                 }
             }
         }
         else
         {
             MessageBox.Show("Appointments less than 24 hours cannot be edited.", "Unauthorized", MessageBoxButtons.OK, MessageBoxIcon.Stop);
         }
     }
     else if (appointmentsDataGridView.Columns[e.ColumnIndex].Name == "DeleteAppointment")
     {
         var currentAppointment = new Appointment(appointmentDTO.AppointmentID,
                                                  appointmentDTO.PatientID,
                                                  appointmentDTO.DoctorID,
                                                  appointmentDTO.AppointmentDateTime,
                                                  appointmentDTO.ReasonForVisit);
         var visits = this.visitController.GetVisitByAppointment(currentAppointment).Count;
         if (visits < 1)
         {
             string message = "Are you sure you want to delete this appointment?"
                              + Environment.NewLine + $"Doctor: {appointmentDTO.DoctorName}"
                              + Environment.NewLine + $"Appointement Time: {appointmentDTO.AppointmentDateTime.ToLongTimeString()}";
             string caption = $"Delete appointment {appointmentDTO.AppointmentID}";
             var    result  = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
             if (result == DialogResult.Yes)
             {
                 if (appointmentController.DeleteAppointment(currentAppointment))
                 {
                     MessageBox.Show("Appointment deleted successfully");
                     RefreshDataGrid();
                 }
             }
         }
         else
         {
             MessageBox.Show("Appointment has a visit information and can't be deleted.");
         }
     }
 }