Пример #1
0
        private void btnsent_Click(object sender, EventArgs e)
        {
            conn.Open();
            //MessageBox.Show("" + lblswdid.Text + ""+ lbldate.Text+ "" + lbltimezone1.Text);
            string today = DateTime.Now.ToString("yyyy-MM-dd", new CultureInfo("th-TH"));
            string query = ("select count(*) from time_attendance inner join employee_doctor on employee_doctor.emp_doc_id = time_attendance.emp_doc_id inner join schedule_work_doctor on schedule_work_doctor.emp_doc_id  = employee_doctor.emp_doc_id where remark = 'เข้างาน' AND swd_timezone = '" + lbltimezone1.Text + "'");

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

            int time_add = (int)cmd.ExecuteScalar();

            if (time_add < 1)
            {
                MessageBox.Show("ไม่มีข้อมูลส่งเข้าห้องตรวจ");
            }
            else
            {
                query = ("insert into queue_diag_room(qdr_date,qdr_time_sent,status_queue,swd_id,opd_id)values ('" + today + "', '" + lbltime1.Text + "',1,'" + lblswdid.Text + "','" + lblopdid.Text + "');");
                cmd   = new SqlCommand(query, conn);
                sda   = new SqlDataAdapter(cmd);
                dt    = new DataTable();
                sda.Fill(dt);

                Queue <int> collection = new Queue <int>();
                int         swd_id     = Convert.ToInt32(lblswdid.Text);
                query = ("select count(*) from queue_diag_room inner join opd on opd.opd_id = queue_diag_room.opd_id inner join schedule_work_doctor on schedule_work_doctor.swd_id = queue_diag_room.swd_id inner join employee_doctor on employee_doctor.emp_doc_id = schedule_work_doctor.emp_doc_id where  queue_diag_room.status_queue = 1 AND schedule_work_doctor.swd_id = '" + lblswdid.Text + "'");
                cmd   = new SqlCommand(query, conn);
                sda   = new SqlDataAdapter(cmd);
                dt    = new DataTable();
                sda.Fill(dt);

                int queue = (int)cmd.ExecuteScalar();
                collection.Enqueue(queue);

                foreach (int value in collection)
                {
                    if (value <= 9)
                    {
                        query = ("Update queue_diag_room Set qdr_record = '" + value + "' where opd_id = '" + lblopdid.Text + "'");
                        //
                        cmd = new SqlCommand(query, conn);
                        sda = new SqlDataAdapter(cmd);
                        dt  = new DataTable();
                        sda.Fill(dt);

                        query = ("Update visit_record set vr_status = 1 where opd_id = '" + lblopdid.Text + "'");
                        //
                        cmd = new SqlCommand(query, conn);
                        sda = new SqlDataAdapter(cmd);
                        dt  = new DataTable();
                        sda.Fill(dt);


                        query = ("Update queue_visit_record set qvr_status = 0 where opd_id = '" + lblopdid.Text + "'");

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

                        query = ("Update appointment SET status_approve = 0,status_app = 0 where app_id = '" + lblidapp.Text + "'");
                        cmd   = new SqlCommand(query, conn);
                        sda   = new SqlDataAdapter(cmd);
                        dt    = new DataTable();

                        sda.Fill(dt);

                        clinic_app_service s2 = new clinic_app_service();
                        s2.Show();
                        clinic_app_service clnlog = new clinic_app_service();
                        clnlog.Close();
                        Visible = false;
                        MessageBox.Show("ส่งเข้าห้องตรวจเรียบร้อย   คุณคิวที่    " + value);
                    }
                    else
                    {
                        MessageBox.Show("คิวห้องตรวจเต็ม");
                    }
                }
            }

            /*
             * //******
             *
             *
             * /*
             *
             */
            conn.Close();
        }
        private void btnsent_Click(object sender, EventArgs e)
        {
            conn.Open();
            string query = ("insert into queue_diag_room(qdr_date,qdr_time_sent,status_queue,swd_id,opd_id)values (SYSDATETIME(), SYSDATETIME(),1,'" + lblswdid.Text + "','" + lblopdid.Text + "');");

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

            Queue <int> collection = new Queue <int>();

            query = ("select count(*) from queue_diag_room inner join opd on opd.opd_id = queue_diag_room.opd_id inner join schedule_work_doctor on schedule_work_doctor.swd_id = queue_diag_room.swd_id inner join employee_doctor on employee_doctor.emp_doc_id = schedule_work_doctor.emp_doc_id where  queue_diag_room.status_queue = 1 AND schedule_work_doctor.swd_id = '" + lblswdid.Text + "'");
            cmd   = new SqlCommand(query, conn);
            sda   = new SqlDataAdapter(cmd);
            dt    = new DataTable();
            sda.Fill(dt);
            //  sdr = cmd.ExecuteReader();
            int queue = (int)cmd.ExecuteScalar();

            collection.Enqueue(queue);

            foreach (int value in collection)
            {
                if (value <= 9)
                {
                    query = ("Update queue_diag_room Set qdr_record = '" + value + "' where opd_id = '" + lblopdid.Text + "'");
                    //
                    cmd = new SqlCommand(query, conn);
                    sda = new SqlDataAdapter(cmd);
                    dt  = new DataTable();
                    sda.Fill(dt);

                    query = ("Update visit_record set vr_status = 1 where opd_id = '" + lblopdid.Text + "'");
                    //
                    cmd = new SqlCommand(query, conn);
                    sda = new SqlDataAdapter(cmd);
                    dt  = new DataTable();
                    sda.Fill(dt);


                    query = ("Update queue_visit_record set qvr_status = 0 where opd_id = '" + lblopdid.Text + "'");

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

                    query = ("Update appointment SET status_approve = 0,status_app = 0 where app_id = '" + lblidapp.Text + "'");
                    cmd   = new SqlCommand(query, conn);
                    sda   = new SqlDataAdapter(cmd);
                    dt    = new DataTable();

                    sda.Fill(dt);

                    clinic_app_service s2 = new clinic_app_service();
                    s2.Show();
                    clinic_app_service clnlog = new clinic_app_service();
                    clnlog.Close();
                    Visible = false;
                    MessageBox.Show("ส่งเข้าห้องตรวจเรียบร้อย   คุณคิวที่    " + value);
                }
                else
                {
                    MessageBox.Show("คิวห้องตรวจเต็ม");
                }
            }
            conn.Close();
        }