private void button3_Click(object sender, EventArgs e)
        {
            CultureInfo ThaiCulture = new CultureInfo("th-TH");
            DateTime    today       = DateTime.Today;
            string      etoday      = today.ToString("yyyy-MM-dd", ThaiCulture);

            //  CultureInfo ThaiCulture = new CultureInfo("th-TH");
            DateTime date         = Convert.ToDateTime(dateTimePicker1.Text);
            string   date_th      = date.ToString("yyyy-MM-dd", ThaiCulture);
            string   day          = date.ToString("dddd", ThaiCulture);
            int      day_count    = date.Day;
            int      today_count  = today.Day;
            int      month_select = date.Month;

            int month_count = today.Month;
            int month_swd   = Convert.ToInt32(txtmonth.Text);

            string query = ("Update schedule_work_doctor set  swd_start_time = '' ,swd_end_time = '',swd_note = '" + txtremark.Text + "' ,swd_date_work = '' where room_id = '" + txtroom.Text + "' AND swd_timezone = '" + txttimezone.Text + "' AND swd_day_work = '" + day + "' AND swd_num_week = '" + txtweek.Text + "'");

            cmd = new SqlCommand(query, conn);
            sda = new SqlDataAdapter(cmd);
            dt  = new DataTable();

            sda.Fill(dt);
            clinic_timeswd_ms doc1 = new clinic_timeswd_ms();

            doc1.Show();
            clinic_timeswd_ms clnlog = new clinic_timeswd_ms();

            clnlog.Close();
            Visible = false;
            MessageBox.Show("เปลี่ยนแปลงตารางเรียบร้อย");
        }
        private void button2_Click(object sender, EventArgs e)
        {
            CultureInfo ThaiCulture = new CultureInfo("th-TH");
            DateTime    today       = DateTime.Today;
            string      etoday      = today.ToString("yyyy-MM-dd", ThaiCulture);

            //  CultureInfo ThaiCulture = new CultureInfo("th-TH");
            DateTime date         = Convert.ToDateTime(dateTimePicker1.Text);
            string   date_th      = date.ToString("yyyy-MM-dd", ThaiCulture);
            string   day          = date.ToString("dddd", ThaiCulture);
            int      day_count    = date.Day;
            int      today_count  = today.Day;
            int      month_select = date.Month;

            int month_count = today.Month;
            int month_swd   = Convert.ToInt32(txtmonth.Text);

            if (month_count > month_swd)
            {
                MessageBox.Show("ไม่สามารถจัดตารางได้");
            }
            else
            {
                if (month_count >= month_select && today_count >= day_count)
                {
                    MessageBox.Show("ไม่สามารถจัดตารางได้");
                }
                else
                {
                    conn.Open();
                    string query = ("select count(*) from schedule_work_doctor where swd_date_work = '" + date_th + "' AND room_id = '" + txtroom.Text + "'");
                    cmd = new SqlCommand(query, conn);
                    sda = new SqlDataAdapter(cmd);
                    dt  = new DataTable();
                    sda.Fill(dt);

                    int swd_count = (int)cmd.ExecuteScalar();
                    if (swd_count < 1)
                    {
                        query = ("Update schedule_work_doctor set  swd_note = '" + txtremark.Text + "' ,swd_date_work = '" + date_th + "' where room_id = '" + txtroom.Text + "'  AND swd_day_work = '" + day + "' AND swd_num_week = '" + txtweek.Text + "'");
                        cmd   = new SqlCommand(query, conn);
                        sda   = new SqlDataAdapter(cmd);
                        dt    = new DataTable();

                        sda.Fill(dt);
                        clinic_timeswd_ms doc1 = new clinic_timeswd_ms();
                        doc1.Show();
                        clinic_timeswd_ms clnlog = new clinic_timeswd_ms();
                        clnlog.Close();
                        Visible = false;
                        MessageBox.Show("เปลี่ยนแปลงตารางเรียบร้อย");
                    }
                    else
                    {
                        MessageBox.Show("วันที่ซ้ำ");
                    }
                    conn.Close();
                }
            }
        }
        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox2.SelectedItem.ToString() == "ปิด")
            {
                string query = ("Update schedule_work_doctor set swd_status_room = 0 ,swd_date_work = '',emp_doc_id = 0 ,swd_work_place = '',swd_emp_work_place = '',swd_note = '',swd_status = '" + comboBox2.SelectedItem.ToString() + "',swd_end_date = '' ");
                cmd = new SqlCommand(query, conn);
                sda = new SqlDataAdapter(cmd);
                dt  = new DataTable();

                sda.Fill(dt);

                clinic_timeswd_ms doc1 = new clinic_timeswd_ms();
                doc1.Show();
                clinic_timeswd_ms clnlog = new clinic_timeswd_ms();
                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 ,swd_date_work = '',emp_doc_id = 0 ,swd_work_place = '',swd_emp_work_place = '',swd_note = '',swd_status = '" + comboBox2.SelectedItem.ToString() + "',swd_end_date = '' ");
                cmd = new SqlCommand(query, conn);
                sda = new SqlDataAdapter(cmd);
                dt  = new DataTable();

                sda.Fill(dt);

                clinic_timeswd_ms doc1 = new clinic_timeswd_ms();
                doc1.Show();
                clinic_timeswd_ms clnlog = new clinic_timeswd_ms();
                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;

            int month_today_count = month_today.Month;

            /*
             * 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 (month_today_count >= month)
            {
                MessageBox.Show("ไม่สามารถจัดตารางได้");
            }
            else
            {
                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);

                clinic_timeswd_ms doc1 = new clinic_timeswd_ms();
                doc1.Show();

                clinic_timeswd_ms clnlog = new clinic_timeswd_ms();
                clnlog.Close();
                Visible = false;


                MessageBox.Show("จัดตารางปฏิบัติงานแพทย์ประจำเดือน  " + value);
            }



            //  int key = ((KeyValuePair<int,string>)comboBox1.SelectedItem).Key;
        }
        private void dateTimePicker2_ValueChanged(object sender, EventArgs e)
        {
            CultureInfo ThaiCulture = new CultureInfo("th-TH");
            DateTime    date_end    = Convert.ToDateTime(dateTimePicker2.Text);
            string      end_date    = date_end.ToString("yyyy-MM-dd", ThaiCulture);

            string query = ("Update schedule_work_doctor set swd_end_date = '" + end_date + "'");

            cmd = new SqlCommand(query, conn);
            sda = new SqlDataAdapter(cmd);
            dt  = new DataTable();

            sda.Fill(dt);

            clinic_timeswd_ms doc1 = new clinic_timeswd_ms();

            doc1.Show();
            clinic_timeswd_ms clnlog = new clinic_timeswd_ms();

            clnlog.Close();
            Visible = false;
            //  MessageBox.Show(""+end_date);
        }