private void button2_Click(object sender, EventArgs e) { try { conn.Open(); string query = ("select * from employee_doctor where emp_doc_name = '" + comboBox1.SelectedItem.ToString() + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); sdr = cmd.ExecuteReader(); if (sdr.Read()) { int doc_id = Convert.ToInt32(sdr["emp_doc_id"].ToString()); query = ("select schedule_work_doctor.room_id from schedule_work_doctor inner join employee_doctor on employee_doctor.emp_doc_id = schedule_work_doctor.emp_doc_id inner join specialist on specialist.emp_doc_specialistid = employee_doctor.emp_doc_specialistid where schedule_work_doctor.swd_date_work = '" + txttime.Text + "' AND schedule_work_doctor.emp_doc_id = '" + doc_id + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); sdr = cmd.ExecuteReader(); if (sdr.Read()) { int room_id = Convert.ToInt32(sdr["room_id"].ToString()); int room_swd = Convert.ToInt32(txtroom.Text); if (room_id == room_swd) { query = ("Update schedule_work_doctor set swd_note = 'ทำงานแทน',swd_status_room = 1,swd_emp_work_place = '" + txtdoctorname.Text + "',emp_doc_id = '" + doc_id + "' where swd_id = '" + txtswd.Text + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); query = ("select swd_id,swd_date_work from schedule_work_doctor inner join employee_doctor on employee_doctor.emp_doc_id = schedule_work_doctor.emp_doc_id where swd_note = 'ทำงานแทน' AND schedule_work_doctor.swd_emp_work_place = '" + txtdoctorname.Text + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); sdr = cmd.ExecuteReader(); while (sdr.Read()) { int swd_id = sdr.GetInt32(0); DateTime date_sed = sdr.GetDateTime(1); string date_swd = date_sed.ToString("yyyy-MM-dd"); query = ("select count(appointment.app_date) from appointment inner join employee_doctor on employee_doctor.emp_doc_id = appointment.emp_doc_id where app_date = '" + date_swd + "' AND employee_doctor.emp_doc_name = '" + txtdoctorname.Text + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); int count_app = (int)cmd.ExecuteScalar(); if (count_app >= 1) { query = ("update appointment SET appointment.status_approve = 6,appointment.swd_id = '" + swd_id + "' from appointment inner join employee_doctor on employee_doctor.emp_doc_id = appointment.emp_doc_id where employee_doctor.emp_doc_name = '" + txtdoctorname.Text + "' AND appointment.app_date = '" + date_swd + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); clinic_schedule_now_today doc2 = new clinic_schedule_now_today(); doc2.Show(); clinic_schedule_now_today clnlog11 = new clinic_schedule_now_today(); clnlog11.Close(); Visible = false; } } clinic_schedule_now_today doc11 = new clinic_schedule_now_today(); doc11.Show(); clinic_schedule_now_today clnlog1 = new clinic_schedule_now_today(); clnlog1.Close(); Visible = false; // MessageBox.Show(" " + room_id); } else { MessageBox.Show("แพทย์มีข้อมูลการทำงานแล้ว"); } } else { query = ("Update schedule_work_doctor set swd_note = 'ทำงานแทน',swd_status_room = 1,swd_emp_work_place = '" + txtdoctorname.Text + "',emp_doc_id = '" + doc_id + "' where swd_id = '" + txtswd.Text + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); query = ("select swd_id,swd_date_work from schedule_work_doctor inner join employee_doctor on employee_doctor.emp_doc_id = schedule_work_doctor.emp_doc_id where swd_note = 'ทำงานแทน' AND schedule_work_doctor.swd_emp_work_place = '" + txtdoctorname.Text + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); sdr = cmd.ExecuteReader(); while (sdr.Read()) { int swd_id = sdr.GetInt32(0); DateTime date_sed = sdr.GetDateTime(1); string date_swd = date_sed.ToString("yyyy-MM-dd"); query = ("select count(appointment.app_date) from appointment inner join employee_doctor on employee_doctor.emp_doc_id = appointment.emp_doc_id where app_date = '" + date_swd + "' AND employee_doctor.emp_doc_name = '" + txtdoctorname.Text + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); int count_app = (int)cmd.ExecuteScalar(); if (count_app >= 1) { query = ("update appointment SET appointment.status_approve = 6,appointment.swd_id = '" + swd_id + "' from appointment inner join employee_doctor on employee_doctor.emp_doc_id = appointment.emp_doc_id where employee_doctor.emp_doc_name = '" + txtdoctorname.Text + "' AND appointment.app_date = '" + date_swd + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); clinic_schedule_now_today doc2 = new clinic_schedule_now_today(); doc2.Show(); clinic_schedule_now_today clnlog1 = new clinic_schedule_now_today(); clnlog1.Close(); Visible = false; } } clinic_schedule_now_today doc1 = new clinic_schedule_now_today(); doc1.Show(); clinic_schedule_now_today clnlog = new clinic_schedule_now_today(); clnlog.Close(); Visible = false; } } conn.Close(); }catch (Exception) { } }
private void msswd_Click(object sender, EventArgs e) { clinic_schedule_now_today sc = new clinic_schedule_now_today(); sc.Show(); }