public AppointmentsList(Model.Patient patient, Model.Hospital hospitalIn) { InitializeComponent(); using (SqlConnection connection = new SqlConnection()) { connection.Open(); using (SqlCommand command = new SqlCommand()) { command.Connection = connection; command.CommandText = "SELECT apptTime, apptDate, importance, reason FROM Hospital.dbo.Appointments" + "\n WHERE patientID = @patientID AND hospitalID = @hospitalID;"; SqlDataReader cursor = command.ExecuteReader(); if (cursor.Read()) { object[] tuple = new object[cursor.FieldCount]; cursor.GetValues(tuple); DateTime date = (DateTime)tuple[0]; DateTime time = (DateTime)tuple[1]; DateTime schedule = new DateTime(date.Year, date.Month, date.Day, time.Hour, time.Minute, time.Second, DateTimeKind.Local); Model.Triage importance = (Model.Triage)Enum.Parse(typeof(Model.Triage), (string)tuple[2]); Model.Specialty specialty = (Model.Specialty)Enum.Parse(typeof(Model.Specialty), (string)tuple[3]); } } } }
private void confirmButton_Click(object sender, EventArgs e) { if (((String)triage.SelectedItem) == "" || ((String)reasonList.SelectedItem) == "") { errorMessage.Visible = true; errorMessage.Text = "Please fill all fields"; return; } Model.Triage urgency = (Model.Triage)Enum.Parse(typeof(Model.Triage), (string)triage.SelectedItem); Model.Specialty reason = (Model.Specialty)Enum.Parse(typeof(Model.Specialty), (string)reasonList.SelectedItem); try { appointmentIn.AddAppointment(schedulePicker.Value, reason, triage.SelectedItem.ToString(), detailedReason.Text, patient); //If successfull, hide error message. errorMessage.Visible = false; } catch (Exception err) { errorMessage.Text = err.Message; errorMessage.Visible = true; } this.Close(); }