private void btnUpdate_Click(object sender, EventArgs e) { try { if (this.dtpAppointmentDate.Value.Date < DateTime.Today) { throw new Exception("Selected date must be of today or future"); } DoctorRepo doctorRepo = new DoctorRepo(); DataTable doctorData = doctorRepo.GetIndividualDoctorsInfo(Convert.ToInt32(this.txtDoctorID.Text)); doctorRepo.DoctorID = Convert.ToInt32(doctorData.Rows[0]["doctorid"].ToString()); doctorRepo.Specialty = doctorData.Rows[0]["specialty"].ToString(); doctorRepo.AvailableDays = doctorData.Rows[0]["availabledays"].ToString(); doctorRepo.EmployeeIdOfDoctor = Convert.ToInt32(doctorData.Rows[0]["empid"].ToString()); // Check if available day of doctor matches with appointment day string[] daysAvailabe = doctorRepo.AvailableDays.Split(' '); bool checkValidDay = false; string selectedDay = dtpAppointmentDate.Value.DayOfWeek.ToString().Substring(0, 3); foreach (string days in daysAvailabe) { if (days.Equals(selectedDay)) { checkValidDay = true; break; } else { checkValidDay = false; } } // If its a invalid day if (!checkValidDay) { throw new Exception("Doctor not available on this day. Check Available days"); } AppointmentRepo ap = new AppointmentRepo(); ap.AppointmentID = Convert.ToInt32(this.txtAppointmentID.Text); ap.Time = this.cmbAppointmentTime.Text.ToString(); ap.Date = this.dtpAppointmentDate.Value.ToString("MM/dd/yyyy"); ap.DoctorID = Convert.ToInt32(this.txtDoctorID.Text); ap.PatientID = Convert.ToInt32(this.txtPatientID.Text); // Check if clash appointment if (ap.RowExits(ap.Time, ap.Date, ap.DoctorID)) { throw new Exception("Clash Appointment"); } // If no clash appointment then proceed int appointmentCreated = ap.CreateAppointment(ap.Time, ap.Date, ap.PatientID, ap.DoctorID); if (appointmentCreated == 1) { // Must remove it from cancelled appointment now since reassigned CancelledAppointmentsRepo.RemoveCancelledAppointment(ap.AppointmentID); MessageBox.Show("Appointment reassigned"); // refresh the table this.PopulateCancelledTable(); this.ClearAll(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnUpdate_Click(object sender, EventArgs e) { try { if (this.dtpAppointmentDate.Value.Date < DateTime.Today) { throw new Exception("Selected date must be of today or future"); } DoctorRepo doctorRepo = new DoctorRepo(); DataTable doctorData = doctorRepo.GetIndividualDoctorsInfo(Convert.ToInt32(this.txtDoctorID.Text)); doctorRepo.DoctorID = Convert.ToInt32(doctorData.Rows[0]["doctorid"].ToString()); doctorRepo.Specialty = doctorData.Rows[0]["specialty"].ToString(); doctorRepo.AvailableDays = doctorData.Rows[0]["availabledays"].ToString(); doctorRepo.EmployeeIdOfDoctor = Convert.ToInt32(doctorData.Rows[0]["empid"].ToString()); // Check if available day of doctor matches with appointment day string[] daysAvailabe = doctorRepo.AvailableDays.Split(' '); bool checkValidDay = false; //string selectedDay = dtpAppointmentDate.Value.DayOfWeek.ToString().Substring(0, 3).ToLower(); string selectedDay = dtpAppointmentDate.Value.DayOfWeek.ToString().Substring(0, 3); foreach (string days in daysAvailabe) { if (days.Equals(selectedDay)) { checkValidDay = true; break; } else { checkValidDay = false; } } // If its a invalid day if (!checkValidDay) { throw new Exception("Doctor not available on this day. Check Available days"); } AppointmentRepo ap = new AppointmentRepo(); ap.AppointmentID = Convert.ToInt32(this.txtAppointmentID.Text); ap.Time = this.cmbAppointmentTime.Text.ToString(); ap.Date = this.dtpAppointmentDate.Value.ToString("MM/dd/yyyy"); ap.DoctorID = Convert.ToInt32(this.txtDoctorID.Text); ap.PatientID = Convert.ToInt32(this.txtPatientID.Text); // Check if clash appointment if (ap.RowExits(ap.Time, ap.Date, ap.DoctorID)) { throw new Exception("Clash Appointment"); } // If no clash appointment then proceed var ask = MessageBox.Show("Confirm appointment update?", "Question", MessageBoxButtons.YesNo); if (ask == DialogResult.Yes) { int appointmentUpdated = ap.UpdateAppointment(ap.AppointmentID, ap.Time, ap.Date, ap.PatientID, ap.DoctorID); if (appointmentUpdated == 1) { MessageBox.Show("Appointment Updated"); this.PopulateAppointmentTable(); this.ClearAll(); } else { MessageBox.Show("Error"); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnConfirmAppointment_Click(object sender, EventArgs e) { try { // Check if text field contains value this.CheckTextField(); if (this.dtpAppointmentDate.Value.Date < DateTime.Today) { throw new Exception("Selected date must be of today or future"); } DoctorRepo doctorRepo = new DoctorRepo(); DataTable doctorData = doctorRepo.GetIndividualDoctorsInfo(Convert.ToInt32(this.txtDoctorID.Text)); doctorRepo.DoctorID = Convert.ToInt32(doctorData.Rows[0]["doctorid"].ToString()); doctorRepo.Specialty = doctorData.Rows[0]["specialty"].ToString(); doctorRepo.AvailableDays = doctorData.Rows[0]["availabledays"].ToString(); doctorRepo.EmployeeIdOfDoctor = Convert.ToInt32(doctorData.Rows[0]["empid"].ToString()); // Check if available day of doctor matches with appointment day string[] daysAvailabe = doctorRepo.AvailableDays.Split(' '); bool checkValidDay = false; //string selectedDay = dtpAppointmentDate.Value.DayOfWeek.ToString().Substring(0, 3).ToLower(); string selectedDay = dtpAppointmentDate.Value.DayOfWeek.ToString().Substring(0, 3); foreach (string days in daysAvailabe) { if (days.Equals(selectedDay)) { checkValidDay = true; break; } else { checkValidDay = false; } } // If its a invalid day if (!checkValidDay) { throw new Exception("Doctor not available on this day. Check Available days"); } // Get the person id of the doctor string sql = @"select employee.personid from employee where employee.empid = '" + doctorRepo.EmployeeIdOfDoctor + "' "; DataTable data = DataAccess.GetDataTable(sql); int id = Convert.ToInt32(data.Rows[0]["personid"].ToString()); PersonRepo p = new PersonRepo(); DataTable ds = p.GetIndividualPerson(id); string a = ds.Rows[0]["personid"].ToString(); // should not be able to confirm appointment if doctor and patient are same person if (a.Equals(this.txtPersonID.Text)) { //MessageBox.Show("Doctor and Patient cannot be the same person"); throw (new Exception("Doctor and patient cannot be the same person")); } AppointmentRepo ap = new AppointmentRepo(); string apTime = this.cmbAppointmentTime.Text.ToString(); string apDate = this.dtpAppointmentDate.Value.ToString("MM/dd/yyyy"); int apDoctorid = Convert.ToInt32(this.txtDoctorID.Text); if (ap.RowExits(apTime, apDate, apDoctorid)) { //this.txtPersonID.Text = this.PatientID.ToString(); throw new Exception("Clash Appointment"); } var result = MessageBox.Show("Confirm appointment?", "Confirm", MessageBoxButtons.YesNoCancel); if (result == DialogResult.Yes) { if (this.txtPersonID.Text == string.Empty) { // Person p = new Person(); p.Name = this.txtName.Text; p.Age = Int32.Parse(this.txtAge.Text); p.Gender = this.cmbGender.Text; p.BloodGroup = this.cmbBloodGroup.Text; p.Phone = this.txtPhone.Text; // Create a new person int personCreated = p.CreatePerson(p.Name, p.Age, p.Gender, p.BloodGroup, p.Phone); // Refresh the person table this.PopulatePersonTable(); // If person created successfully get his/her id to insert into appointment table if (personCreated == 1) { DataTable lastPersonInsertedDT = p.GetLastPerson(); this.PatientID = Convert.ToInt32(lastPersonInsertedDT.Rows[0]["personid"].ToString()); int appointmentCreated = ap.CreateAppointment(this.cmbAppointmentTime.Text.ToString(), this.dtpAppointmentDate.Value.ToString("MM/dd/yyyy"), this.PatientID, Convert.ToInt32(this.txtDoctorID.Text)); if (appointmentCreated == 1) { MessageBox.Show("Appointment Confirmed"); this.CLearAll(); } } } else { // Person already exists in database, so no need to create newly this.PatientID = Convert.ToInt32(txtPersonID.Text); int appointmentCreated = ap.CreateAppointment(apTime, apDate, this.PatientID, apDoctorid); if (appointmentCreated == 1) { MessageBox.Show("Appointment Confirmed"); this.CLearAll(); } } } } catch (Exception msg) { MessageBox.Show(msg.Message, "ERROR"); } }