// Creates appointment from appointmentID to delete public static AppointmentsTable createAppointment(int appointmentID) { AppointmentsTable deleteAppointment = new AppointmentsTable(); foreach (AppointmentsTable appointment in dbcon.AppointmentsTables) { if (appointment.AppointmentID == appointmentID) // if input is equal an appointmentID in database, copy it for deletion { deleteAppointment.AppointmentID = appointment.AppointmentID; deleteAppointment.PatientID = appointment.PatientID; deleteAppointment.DoctorID = appointment.DoctorID; deleteAppointment.Date = appointment.Date; deleteAppointment.Time = appointment.Time; deleteAppointment.Purpose = appointment.Purpose; deleteAppointment.VisitSummary = appointment.VisitSummary; break; } } return(deleteAppointment); }
protected void CreateAppointmentButton_Click(object sender, EventArgs e) { flag = true; AppointmentsTable newAppointment = new AppointmentsTable(); newAppointment.PatientID = myPatient.PatientID; newAppointment.DoctorID = Convert.ToInt32(DoctorDropDownList.SelectedItem.Value); newAppointment.Date = Convert.ToDateTime(ShowSelectedDateLabel.Text); int hour = Convert.ToInt32(HourDropDownList.SelectedValue); int min = Convert.ToInt32(MinDropDownList.SelectedValue); TimeSpan mytime = new TimeSpan(hour, min, 0); newAppointment.Time = mytime; newAppointment.Purpose = ""; newAppointment.VisitSummary = ""; foreach (AppointmentsTable appointment in dbcon.AppointmentsTables) { if (DateTime.Compare(appointment.Date, newAppointment.Date) == 0) { if (TimeSpan.Compare(appointment.Time, newAppointment.Time) == 0) { DisplayMesageLabel.Text = "An appointment already exists at this date and time."; DisplayMesageLabel.Visible = true; flag = false; } } } if (flag) { dbcon.AppointmentsTables.Add(newAppointment); dbcon.SaveChanges(); DisplayMesageLabel.Text = "Appointment Added."; DisplayMesageLabel.Visible = true; Server.Transfer("Appointments.aspx", true); } }