// Create new appointment private void btnAptNew_Click(object sender, EventArgs e) { this.Hide(); AppointmentForm newAppointment = new AppointmentForm(); try { con.Open(); // Fill appointment type combobox cmd.Connection = con; cmd.CommandText = "sp_allAppTypes"; cmd.CommandType = CommandType.StoredProcedure; MySqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { newAppointment.cbType.Items.Add(dr["type"].ToString()); } dr.Close(); // Fill appointment consultant combobox MySqlCommand cmd3 = new MySqlCommand("sp_getDistinctCoach"); cmd3.Connection = con; dr = cmd3.ExecuteReader(); while (dr.Read()) { newAppointment.cbUsr.Text = dr["coachName"].ToString(); newAppointment.cbUsr.Items.Add(dr["coachName"].ToString()); } dr.Close(); // Fill appointment Athlete name combobox MySqlCommand cmd2 = new MySqlCommand("sp_athleteName"); cmd2.Connection = con; dr = cmd2.ExecuteReader(); while (dr.Read()) { newAppointment.cbCustName.Items.Add(dr["athleteName"].ToString()); } newAppointment.gbAppointment.Text = "New Appointment"; newAppointment.lblApptID.Text = "0"; newAppointment.lblUpdated.Visible = false; newAppointment.lblLastUpdate.Visible = false; //newAppointment.dTPStartTime.Value = DateTime.Today; //newAppointment.dTPEndTime.Value = DateTime.Today; newAppointment.ShowDialog(); con.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message);// print error message } finally { if (dr != null) { dr.Close(); } if (con.State == ConnectionState.Open) { con.Close(); } } }
// View or Edit selected appointment private void btnApptView_Click(object sender, EventArgs e) { try { if (indexOfSelectedAppt >= 0) { int currentApptID = (int)dgvAppt.Rows[indexOfSelectedAppt].Cells[5].Value; AppointmentForm viewAppointment = new AppointmentForm(); if (currentApptID > 0) { con.Open(); // Fill appointment athlete name combobox MySqlCommand cmd2 = new MySqlCommand("sp_athleteName"); cmd2.Connection = con; dr = cmd2.ExecuteReader(); while (dr.Read()) { viewAppointment.cbCustName.Items.Add(dr["athleteName"].ToString()); } dr.Close(); // Fill appointment consultant combobox MySqlCommand cmd3 = new MySqlCommand("sp_getDistinctCoach"); cmd3.Connection = con; dr = cmd3.ExecuteReader(); while (dr.Read()) { viewAppointment.cbUsr.Items.Add(dr["coachName"].ToString()); viewAppointment.cbUsr.Text = currentCoach.ToString(); } dr.Close(); //Fill appointment type combobox MySqlCommand cmd4 = new MySqlCommand("sp_allAppTypes"); cmd4.Connection = con; dr = cmd4.ExecuteReader(); while (dr.Read()) { viewAppointment.cbType.Items.Add(dr["type"].ToString()); } dr.Close(); // Get appointment by appointmentID cmd.Connection = con; cmd.CommandText = "sp_viewAppts"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@apptID", currentApptID); dr = cmd.ExecuteReader(); if (dr.Read()) { viewAppointment.lblApptID.Text = dr["appointmentID"].ToString(); viewAppointment.cbCustName.Text = dr["athleteName"].ToString(); viewAppointment.cbType.Text = dr["type"].ToString(); viewAppointment.dTPStart.Text = GetCorrectedDate(Convert.ToDateTime((dr["start"]))).ToString("MMMM dd, yyyy"); DateTime appStartTime = GetCorrectedDate(Convert.ToDateTime((dr["start"]))); viewAppointment.dTPStartTime.Text = appStartTime.ToString(" HH:mm"); viewAppointment.dtpEnd.Text = GetCorrectedDate(Convert.ToDateTime((dr["end"]))).ToString(); DateTime appEndTime = GetCorrectedDate(Convert.ToDateTime(dr["end"])); viewAppointment.dTPEndTime.Text = appEndTime.ToString(" hh:mm tt"); DateTime lastUpdated = Convert.ToDateTime(dr["lastUpdate"]).ToLocalTime(); viewAppointment.lblUpdated.Text = lastUpdated.ToString("MMMM dd, yyyy hh:mm tt"); } con.Close(); } viewAppointment.gbAppointment.Text = "Edit Appointment"; this.Hide(); viewAppointment.ShowDialog(); } else { MessageBox.Show("Please select and Appointment to View/Edit!"); } } catch (Exception ex) { MessageBox.Show(ex.Message);// print error message } finally { if (dr != null) { dr.Close(); } if (con.State == ConnectionState.Open) { con.Close(); } } }