private void button2_Click(object sender, EventArgs e) { try { conn.Open(); if (txtswd.Text == "" && txtnamedoc.Text == "") { MessageBox.Show("ยังไม่มีข้อมูลการทำงานแทน"); } else { string query = ("select count(*) from schedule_work_doctor where swd_note = 'รอการทำงานแทน' AND swd_id = '" + txtswd.Text + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); int count = (int)cmd.ExecuteScalar(); if (count < 1) { query = ("Update schedule_work_doctor set swd_note = 'รอการทำงานแทน',swd_status_room = 8,swd_emp_work_place = '" + txtnamedoc.Text + "' where swd_id = '" + txtswd.Text + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); clinic_schedule_now doc1 = new clinic_schedule_now(); doc1.Show(); clinic_schedule_now clnlog = new clinic_schedule_now(); clnlog.Close(); Visible = false; } } conn.Close(); } catch (Exception) { } }
private void button1_Click(object sender, EventArgs e) { try { conn.Open(); string query = ("SELECT COUNT(*) from schedule_work_doctor where swd_date_work = '" + txtdatenext.Text + "' AND swd_note = 'รอการทำงานแทน' AND emp_doc_id = '" + id_doc.Text + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); int count_swd_next_change = (int)cmd.ExecuteScalar(); if (count_swd_next_change == 1) { MessageBox.Show("มีแพทย์ทำงานในห้องตรวจแล้ว"); } else { // MessageBox.Show("มีแพทย์ทำงานในห้องตรวจแล้วppppp"); 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()) { CultureInfo ThaiCulture = new CultureInfo("th-TH"); int doc_id = Convert.ToInt32(sdr["emp_doc_id"].ToString()); string doc_name = sdr["emp_doc_name"].ToString(); if (doc_name == txtdoctorname.Text) { MessageBox.Show("ไม่สามารถส่งคำขอทำงานแทนได้"); } else { if (txtdatenext.Text == "" && txttimenext.Text == "") { MessageBox.Show("กรุณาเลือกวันเลื่อนปฏิบัติงาน"); } else { query = ("select swd_id from schedule_work_doctor where swd_date_work = '" + txtdatenext.Text + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sdr = cmd.ExecuteReader(); if (sdr.Read()) { int swdid = Convert.ToInt32(sdr["swd_id"].ToString()); query = ("select swd_start_time,swd_status_room, room_id from schedule_work_doctor where swd_date_work = '" + txtdatenext.Text + "' AND swd_status_room = 0 AND swd_start_time = '" + txttimenext.Text + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sdr = cmd.ExecuteReader(); if (sdr.Read()) { int room_id = Convert.ToInt32(sdr["room_id"].ToString()); int status_room = Convert.ToInt32(sdr["swd_status_room"].ToString()); string time = sdr["swd_start_time"].ToString(); query = ("select swd_start_time,swd_status_room, room_id ,emp_doc_id from schedule_work_doctor where swd_status_room = 1 AND swd_date_work = '" + txtdatenext.Text + "' AND emp_doc_id = '" + id_doc.Text + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sdr = cmd.ExecuteReader(); if (sdr.Read()) { int roomiddoc = Convert.ToInt32(sdr["room_id"].ToString()); int docid = Convert.ToInt32(sdr["emp_doc_id"].ToString()); query = ("SELECT COUNT(*) from schedule_work_doctor where swd_status_room = 1 AND room_id = '" + roomiddoc + "' AND swd_date_work = '" + txtdatenext.Text + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); int count = (int)cmd.ExecuteScalar(); if (count == 2) { MessageBox.Show("มีแพทย์ทำงานห้องตรวจแล้ว"); } else { 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(); if (sdr.Read()) { int swd_id = Convert.ToInt32(sdr["swd_id"].ToString()); DateTime date_sed = Convert.ToDateTime(sdr["swd_date_work"].ToString()); 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 = 3,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 + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); // MessageBox.Show("เลื่อน"); } } 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 = '" + textBox1.Text + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); query = ("Update schedule_work_doctor set swd_note = 'เลื่อนปฏิบัติงาน',swd_status_room = 1, swd_emp_work_place = '" + txtdoctorname.Text + "',emp_doc_id = '" + id_doc.Text + "' where room_id = '" + roomiddoc + "' AND swd_start_time = '" + txttimenext.Text + "' AND swd_date_work = '" + txtdatenext.Text + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); MessageBox.Show("เลื่อนปฏิบัติงาน1"); clinic_schedule_now m3 = new clinic_schedule_now(); m3.Show(); clinic_schedule_now clnlog = new clinic_schedule_now(); clnlog.Close(); Visible = false; } } else { 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(); if (sdr.Read()) { int swd_id = Convert.ToInt32(sdr["swd_id"].ToString()); DateTime date_sed = Convert.ToDateTime(sdr["swd_date_work"].ToString()); 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 = 3,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 + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); // MessageBox.Show("เลื่อน"); } } 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 = '" + textBox1.Text + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); query = ("Update schedule_work_doctor set swd_note = 'เลื่อนปฏิบัติงาน',swd_status_room = 1, swd_emp_work_place = '" + txtdoctorname.Text + "',emp_doc_id = '" + id_doc.Text + "' where room_id = '" + room_id + "' AND swd_start_time = '" + txttimenext.Text + "' AND swd_date_work = '" + txtdatenext.Text + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); MessageBox.Show("เลื่อนปฏิบัติงาน1"); clinic_schedule_now m3 = new clinic_schedule_now(); m3.Show(); clinic_schedule_now clnlog = new clinic_schedule_now(); clnlog.Close(); Visible = false; } } } } } } } conn.Close(); } catch (Exception ex) { MessageBox.Show("กรุณาเลือกแพทย์ทำงานแทน"); } }