private void button4_Click(object sender, EventArgs e) { string value = ((KeyValuePair <int, string>)comboBox1.SelectedItem).Value; int month = ((KeyValuePair <int, string>)comboBox1.SelectedItem).Key; DateTime month_today = DateTime.Today; DateTime day_end = Convert.ToDateTime(dateTimePicker1.Text); int end_day = day_end.Day; int end_month = day_end.Month; int day_today = month_today.Day; int month_today_count = month_today.Month; int month_year_count = month_today.Year; int year_end = day_end.Year; if (day_today != 20) { if (month_today_count >= month & month_year_count >= year_end) { MessageBox.Show("ไม่สามารถกำหนดช่วงเวลาตารางปฏิบัติงานได้"); } else { try { conn.Open(); // string query = ("select count(*) from schedule_work_doctor where swd_status = 'เปิด' AND swd_status_chenge = 0"); // string query = ("select count(*) from schedule_work_doctor where swd_status = 'เปิด' AND swd_status_chenge = 1 AND swd_month_work = '" + lblmonth1.Text + "' "); string query = ("select count(*) from schedule_work_doctor where swd_status = 'การจัดตารางงานเสร็จสิ้น' AND swd_status_chenge = 2 AND swd_month_work = '" + lblmonth1.Text + "' "); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); int swd_count = (int)cmd.ExecuteScalar(); /* query = ("select swd_date_work from schedule_work_doctor ORDER BY swd_date_work DESC"); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * * sda.Fill(dt); * * sdr = cmd.ExecuteReader(); * * if (sdr.Read()) * {*/ string date_work_w = day_end.ToString("yyyy-MM-dd", new CultureInfo("th-TH")); query = ("select count(*) from schedule_work_doctor where swd_status = 'เปิด'AND swd_end_date = '" + date_work_w + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); int count_swd = (int)cmd.ExecuteScalar(); if (count_swd > 1) { MessageBox.Show("มีข้อมูลการปฏิบัติงานแล้ว"); } else { if (swd_count > 1) { if (month_today.Date >= day_end.Date) { MessageBox.Show("ไม่สามารถจัดตารางการปฏิบัติงานได้"); } else { CultureInfo enCulture = new CultureInfo("en-US"); CultureInfo thCulture = new CultureInfo("th-TH"); DateTime year_today = DateTime.Now; DateTime year_lbl = Convert.ToDateTime(dateTimePicker1.Text); // string year_1 = year_today.ToString("yyyy", enCulture); string year_1 = year_lbl.ToString("yyyy", enCulture); string date_month = "" + year_1 + "-" + month + "-01"; DateTime month_first = Convert.ToDateTime(date_month); int day = month_first.Day; int month_1 = month_first.Month; // string first = month_first.ToString("" + year_1 + "-" + month + "-dd", enCulture); string first = month_first.ToString("" + year_1 + "-" + month + "-dd"); int year = month_first.Year; int result_day = end_day - 1; for (int i = 0; i <= result_day; i++) { DateTime new_birthday; try { new_birthday = new DateTime(year, month_1, day + i); } catch { new_birthday = new DateTime(year, month + 1, 1); } for (int room = 1; room <= 3; room++) { if (i <= end_day) { string day_work_place = new_birthday.ToString("yyyy-MM-dd", thCulture); string day_only = new_birthday.ToString("dddd", thCulture); // MessageBox.Show(day_work_place + "" +day_only); // int day_num = new_birthday.Day; // MessageBox.Show("" + new_birthday.ToString("yyyy-MM-dd", thCulture) + " Week " + new_birthday.ToString("dddd", thCulture) + " " + day_of_week + " week " + num + " room " + room); /* string query = ("insert into schedule_work_doctor (swd_date_work,swd_day_work,room_id,swd_start_time,swd_end_time,swd_timezone,swd_month_work,swd_status,swd_status_room) values('" + day_work_place + "', '" + day_only + "', '" + room + "', '08.30', '11.30', 'เช้า', '" + value + "', 'ปิด','0')"); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * * sda.Fill(dt); * * int queue = (int)cmd.ExecuteScalar(); */ query = ("insert into schedule_work_doctor (swd_date_work,swd_day_work,room_id,swd_start_time,swd_end_time,swd_timezone,swd_month_work,swd_status,swd_status_room,swd_status_checkwork,swd_status_chenge,emp_doc_id) values('" + day_work_place + "', '" + day_only + "', '" + room + "', '08.30', '11.30', 'เช้า', '" + value + "', 'เปิด','0',0,1,0)"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); query = ("insert into schedule_work_doctor (swd_date_work,swd_day_work,room_id,swd_start_time,swd_end_time,swd_timezone,swd_month_work,swd_status,swd_status_room,swd_status_checkwork,swd_status_chenge,emp_doc_id) values('" + day_work_place + "', '" + day_only + "', '" + room + "', '13.00', '15.30', 'บ่าย', '" + value + "', 'เปิด','0',0,1,0)"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); /* lstBirthDays.Items.Add(day_work_place + " : " + * day_only + "" + room + "" + "เช้า"); * lstBirthDays.Items.Add(day_work_place + " : " + * day_only + "" + room + "" + "บ่าย");*/ /* * clinic_time_schms doc1 = new clinic_time_schms(); * doc1.Show(); * * clinic_time_schms clnlog = new clinic_time_schms(); * clnlog.Close(); * Visible = false; * */ } } } clinic_time_schms doc1 = new clinic_time_schms(); doc1.Show(); clinic_time_schms clnlog = new clinic_time_schms(); clnlog.Close(); Visible = false; MessageBox.Show("จัดตารางปฏิบัติงานแพทย์ประจำเดือน " + value); } } else { MessageBox.Show("ไม่สามารถเปลี่ยนเดือนได้"); } } conn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OKCancel); } } } else { MessageBox.Show("ไม่มีข้อมูลลงเวลาตารางการปฏิบัติงาน", "status"); } }
private void timeToolStripMenuItem_Click(object sender, EventArgs e) { clinic_time_schms sc = new clinic_time_schms(); sc.Show(); }
/* private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) * { * if (comboBox2.SelectedItem.ToString() == "ปิด") * { * string query = ("Update schedule_work_doctor set swd_status_room = 0 ,emp_doc_id = 0 ,swd_work_place = '',swd_emp_work_place = '',swd_status = '" + comboBox2.SelectedItem.ToString() + "',swd_end_date = '',swd_note = '' where swd_month_work = '"+lblmonth1.Text+"'"); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * * sda.Fill(dt); * * clinic_time_schms doc1 = new clinic_time_schms(); * doc1.Show(); * clinic_time_schms clnlog = new clinic_time_schms(); * clnlog.Close(); * Visible = false; * MessageBox.Show("เปลี่ยนเป็นสถานะ " + comboBox2.SelectedItem.ToString()); * * * * } * else if (comboBox2.SelectedItem.ToString() == "เปิด") * { * string query = ("Update schedule_work_doctor set swd_status_room = 0 ,emp_doc_id = 0 ,swd_work_place = '',swd_emp_work_place = '',swd_status = '" + comboBox2.SelectedItem.ToString() + "',swd_end_date = '',swd_note = '' where swd_month_work = '"+lblmonth1.Text+"'"); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * * sda.Fill(dt); * * clinic_time_schms doc1 = new clinic_time_schms(); * doc1.Show(); * clinic_time_schms clnlog = new clinic_time_schms(); * clnlog.Close(); * Visible = false; * MessageBox.Show("เปลี่ยนเป็นสถานะ " + comboBox2.SelectedItem.ToString()); * * * } * } */ private void button1_Click(object sender, EventArgs e) { string value = ((KeyValuePair <int, string>)comboBox1.SelectedItem).Value; int month = ((KeyValuePair <int, string>)comboBox1.SelectedItem).Key; DateTime month_today = DateTime.Today; DateTime day_end = Convert.ToDateTime(dateTimePicker1.Text); int end_day = day_end.Day; int end_month = day_end.Month; int day_today = month_today.Day; int month_today_count = month_today.Month; int month_year_count = month_today.Year; int year_end = day_end.Year; /* * string query = ("Update schedule_work_doctor set swd_month_work = '" + value + "'"); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * * sda.Fill(dt);*/ if (day_today == 20) { try { conn.Open(); // query = ("Update schedule_work_doctor set swd_status = 'จัดตารางงานใหม่',swd_note = 'จัดตารางงานใหม่'"); string query = ("select count(schedule_work_doctor.emp_doc_id) from schedule_work_doctor inner join room on room.room_id = schedule_work_doctor.room_id where swd_status = 'เปิด' AND schedule_work_doctor.room_id = 1 AND swd_month_work = '" + lblmonth1.Text + "' AND emp_doc_id = 0 AND swd_date_work = '1900-01-01'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); int swd_count = (int)cmd.ExecuteScalar(); query = ("select count(schedule_work_doctor.emp_doc_id) from schedule_work_doctor inner join room on room.room_id = schedule_work_doctor.room_id where swd_status = 'เปิด' AND schedule_work_doctor.room_id = 1 AND swd_month_work = '" + lblmonth1.Text + "' AND emp_doc_id = 0 "); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); int swd_count1 = (int)cmd.ExecuteScalar(); if (swd_count1 <= swd_count) { query = ("Update schedule_work_doctor set swd_status_chenge = 2 , swd_status = 'การจัดตารางงานเสร็จสิ้น' "); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); // conn.Close(); // MessageBox.Show("เปลี่ยนสถานะ ปิด" + day_work_ww4); clinic_time_schms doc1 = new clinic_time_schms(); doc1.Show(); clinic_time_schms clnlog = new clinic_time_schms(); clnlog.Close(); Visible = false; MessageBox.Show("จัดตารางปฏิบัติงานเสร็จสิ้น"); } else { clinic_ms_time_month doc1 = new clinic_ms_time_month(); doc1.Show(); } conn.Close(); } catch (Exception) { } } else { MessageBox.Show("ยังไม่ถึงเวลาจัดตารางปฏิบัติงาน", "status"); } }
private void Clinic_boss_Load(object sender, EventArgs e) { try { CultureInfo ThaiCulture = new CultureInfo("th-TH"); DateTime today = DateTime.Today; string month_th = today.ToString("yyyy-MM-dd", ThaiCulture); DateTime month = Convert.ToDateTime(month_th); conn.Open(); string query = ("select swd_month_work,swd_date_work from schedule_work_doctor Order by swd_id DESC"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); sdr = cmd.ExecuteReader(); int day = today.Day; if (sdr.Read()) { string month_work = sdr["swd_date_work"].ToString(); string month_th_last = sdr["swd_month_work"].ToString(); DateTime month_date_last = Convert.ToDateTime(month_work); string month_thai = month_date_last.ToString("yyyy-MM-dd"); query = ("select count(*) from schedule_work_doctor where swd_status = 'การจัดตารางงานเสร็จสิ้น' AND swd_date_work = '" + month_thai + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); int swd_count1 = (int)cmd.ExecuteScalar(); query = ("select count(*) from schedule_work_doctor where swd_status = 'เปิด' and swd_month_work = '" + month_th_last + "'"); cmd = new SqlCommand(query, conn); sda = new SqlDataAdapter(cmd); dt = new DataTable(); sda.Fill(dt); int swd_count2 = (int)cmd.ExecuteScalar(); if (swd_count2 > 1) { if (day == 20) { DialogResult dialogResult = MessageBox.Show("กรุณาจัดตารางการปฏิบัติงานแพทย์", "status", MessageBoxButtons.YesNo); // MessageBox.Show("กรุณาส่งข้อมูลการทำงาน"); if (dialogResult == DialogResult.Yes) { clinic_time_schms log1 = new clinic_time_schms(); log1.Show(); clinic_time_schms main1 = new clinic_time_schms(); main1.Close(); Visible = false; } else if (dialogResult == DialogResult.No) { } if (swd_count1 != 0) { if (day >= 21) { dialogResult = MessageBox.Show("กรุณาจัดช่วงเวลาการทำงาน", "status", MessageBoxButtons.YesNo); // MessageBox.Show("กรุณาจัดช่วงเวลาการทำงาน"); if (dialogResult == DialogResult.Yes) { clinic_time_schms log = new clinic_time_schms(); log.Show(); clinic_time_schms main = new clinic_time_schms(); main.Close(); Visible = false; } else if (dialogResult == DialogResult.No) { } } else if (day >= 1 && day <= 19) { dialogResult = MessageBox.Show("คุณต้องการจัดช่วงเวลาการทำงานหรือไม่", "status", MessageBoxButtons.YesNo); // MessageBox.Show("กรุณาจัดช่วงเวลาการทำงาน"); if (dialogResult == DialogResult.Yes) { clinic_time_schms log = new clinic_time_schms(); log.Show(); clinic_time_schms main = new clinic_time_schms(); main.Close(); Visible = false; } else if (dialogResult == DialogResult.No) { } } } } } else { if (swd_count1 != 0) { if (day >= 21) { DialogResult dialogResult = MessageBox.Show("คุณต้องการจัดช่วงเวลาการทำงานหรือไม่", "status", MessageBoxButtons.YesNo); // MessageBox.Show("กรุณาจัดช่วงเวลาการทำงาน"); if (dialogResult == DialogResult.Yes) { clinic_time_schms log = new clinic_time_schms(); log.Show(); clinic_time_schms main = new clinic_time_schms(); main.Close(); Visible = false; } else if (dialogResult == DialogResult.No) { } } else if (day >= 1 && day <= 19) { DialogResult dialogResult = MessageBox.Show("คุณต้องการจัดช่วงเวลาการทำงานหรือไม่", "status", MessageBoxButtons.YesNo); // MessageBox.Show("กรุณาจัดช่วงเวลาการทำงาน"); if (dialogResult == DialogResult.Yes) { clinic_time_schms log = new clinic_time_schms(); log.Show(); clinic_time_schms main = new clinic_time_schms(); main.Close(); Visible = false; } else if (dialogResult == DialogResult.No) { } } } //***************************************** } } /* query = ("select swd_month_work from schedule_work_doctor where swd_status = 'การจัดตารางงานเสร็จสิ้น' Order by swd_id DESC "); * cmd = new SqlCommand(query, conn); * sda = new SqlDataAdapter(cmd); * dt = new DataTable(); * * sda.Fill(dt); * * sdr = cmd.ExecuteReader(); * int day1 = today.Day; * * if (sdr.Read()) * { * string month_work = sdr["swd_month_work"].ToString(); * if (month_work == month) * { * * MessageBox.Show("กรุณาจัดช่วงเวลาการทำงาน"); * clinic_time_schms log = new clinic_time_schms(); * log.Show(); * clinic_time_schms main = new clinic_time_schms(); * main.Close(); * Visible = false; * * * * } * } */ conn.Close(); } catch (Exception) { } }