private void button24_Click(object sender, EventArgs e)
        {
            string query = ("UPDATE medicine_use SET medi_use_status = 2 where treatr_id = '" + lblidt.Text + "'");

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



            query = ("Update treatment_record SET treatr_status = 0 where treatr_id = '" + lblidt.Text + "'");
            cmd   = new SqlCommand(query, conn);
            sda   = new SqlDataAdapter(cmd);
            dt    = new DataTable();
            sda.Fill(dt);

            clinic_doctor_service3 m3 = new clinic_doctor_service3();

            m3.Show();
            clinic_doctor_service3 clnlog = new clinic_doctor_service3();

            clnlog.Close();
            Visible = false;


            MessageBox.Show("จ่ายยาเรียบร้อย");
        }
        private void button3_Click(object sender, EventArgs e)
        {
            string query = ("insert into treatment_record (treatr_symptom,treatr_diagnose,treatr_status,disease_id,emp_doc_id,opd_id) values ('" + txtsystoms.Text + "','" + txtdis.Text + "',1,'" + txtiddis.Text + "','" + txtdocid.Text + "','" + lblopdid.Text + "')");

            cmd = new SqlCommand(query, conn);
            sda = new SqlDataAdapter(cmd);
            dt  = new DataTable();
            //  MessageBox.Show("บันทึกการรักษาเรียบร้อย");
            sda.Fill(dt);
            query = ("Update queue_diag_room SET status_queue = 0 where opd_id = '" + lblopdid.Text + "'");
            cmd   = new SqlCommand(query, conn);
            sda   = new SqlDataAdapter(cmd);
            dt    = new DataTable();
            sda.Fill(dt);

            clinic_doctor_service3 m3 = new clinic_doctor_service3();

            m3.Show();
            clinic_doctor_service3 clnlog = new clinic_doctor_service3();

            clnlog.Close();
            Visible = false;


            MessageBox.Show("บันทึกการรักษาเรียบร้อย");
        }
        private void button4_Click(object sender, EventArgs e)
        {
            conn.Open();
            string query = ("select medi_qty_use from medical where medi_id = '" + lblmed.Text + "'");

            cmd = new SqlCommand(query, conn);
            sda = new SqlDataAdapter(cmd);
            dt  = new DataTable();
            sda.Fill(dt);
            sdr = cmd.ExecuteReader();
            if (sdr.Read())
            {
                int nummed    = Convert.ToInt32(sdr["medi_qty_use"].ToString());
                int cut_stock = nummed - Convert.ToInt32(txtnum.Text);
                if (nummed < 5)
                {
                    MessageBox.Show("ยาใกล้หมดคลังแล้ว");

                    query = ("Update medical set medi_qty_use = '" + cut_stock + "' where medi_id = '" + lblmed.Text + "'");
                    cmd   = new SqlCommand(query, conn);
                    sda   = new SqlDataAdapter(cmd);
                    dt    = new DataTable();
                    sda.Fill(dt);


                    query = ("insert into  medicine_use (medi_use_remark,medi_use_date,medi_use_status,medi_num,treatr_id,medi_id)values ('" + txtre2.Text + "',SYSDATETIME(),1,'" + txtnum.Text + "','" + lblidt.Text + "','" + lblmed.Text + "')");
                    cmd   = new SqlCommand(query, conn);
                    sda   = new SqlDataAdapter(cmd);
                    dt    = new DataTable();
                    //  MessageBox.Show("บันทึกการรักษาเรียบร้อย");
                    sda.Fill(dt);

                    clinic_doctor_service3 m3 = new clinic_doctor_service3();
                    m3.Show();
                    clinic_doctor_service3 clnlog = new clinic_doctor_service3();
                    clnlog.Close();
                    Visible = false;


                    MessageBox.Show("บันทึกใบจ่ายยาเรียบร้อย");
                }
                else if (nummed < 0)
                {
                    MessageBox.Show("ยาหมดคลังแล้ว");
                }
                else if (nummed > 5)
                {
                    query = ("Update medical set medi_qty_use = '" + cut_stock + "' where medi_id = '" + lblmed.Text + "'");
                    cmd   = new SqlCommand(query, conn);
                    sda   = new SqlDataAdapter(cmd);
                    dt    = new DataTable();
                    sda.Fill(dt);


                    query = ("insert into  medicine_use (medi_use_remark,medi_use_date,medi_use_status,medi_num,treatr_id,medi_id)values ('" + txtre2.Text + "',SYSDATETIME(),1,'" + txtnum.Text + "','" + lblidt.Text + "','" + lblmed.Text + "')");
                    cmd   = new SqlCommand(query, conn);
                    sda   = new SqlDataAdapter(cmd);
                    dt    = new DataTable();
                    //  MessageBox.Show("บันทึกการรักษาเรียบร้อย");
                    sda.Fill(dt);

                    clinic_doctor_service3 m3 = new clinic_doctor_service3();
                    m3.Show();
                    clinic_doctor_service3 clnlog = new clinic_doctor_service3();
                    clnlog.Close();
                    Visible = false;


                    MessageBox.Show("บันทึกใบจ่ายยาเรียบร้อย");
                }
            }

            conn.Close();


            /*
             * query = ("Update treatment_record SET treatr_status = 0 where treatr_id = '"+lblidt.Text+"'");
             * cmd = new SqlCommand(query, conn);
             * sda = new SqlDataAdapter(cmd);
             * dt = new DataTable();
             * sda.Fill(dt);
             */
        }
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            clinic_doctor_service3 ser = new clinic_doctor_service3();

            ser.Show();
        }