团队冲刺(二)4

package com.example.hotel.Activity.User;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.hotel.Activity.Manager.LookRoomActivity;
import com.example.hotel.Database.MysqlUser;
import com.example.hotel.R;

import java.sql.SQLException;

public class Myreserve2Activity extends AppCompatActivity {
    private String[] names = new String[]{
          

    };
    private int[] img = new int[]{R.drawable.room1,R.drawable.room2,R.drawable.room3,R.drawable.room4,R.drawable.room5,
            R.drawable.room6,R.drawable.room7,R.drawable.room8,R.drawable.room9,R.drawable.room10};
    private String str;
    private ImageView Roomimg;
    private TextView Roominfo,Reservetime;
    private Button Backroom;
    private int id;
    private int b[],p,flag;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_myreserve2);
        flag=0;
        Bundle bundle=getIntent().getExtras();
        b=bundle.getIntArray("b");
        p=bundle.getInt("roomid");
        id=b[p]+1;
        Thread thread=new Thread(new Runnable() {
            @Override
            public void run() {
                MysqlUser mysqlUser=new MysqlUser();
                try {
                    String sql="select reservetime from roominfo where roomid='"+id+"'";
                    str=mysqlUser.select(sql);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        });
        thread.start();
        try {
            thread.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        int year=Integer.valueOf(str.substring(0,4));
        int month=Integer.valueOf(str.substring(4,6));
        int day=Integer.valueOf(str.substring(6,8));
        int hour=Integer.valueOf(str.substring(8,10));
        int min=Integer.valueOf(str.substring(10,12));
        int sec=Integer.valueOf(str.substring(12,14));
        Reservetime=(TextView) findViewById(R.id.reservetime2);
        Reservetime.setText("预定时间为:"+year+""+month+""+day+""+" "+hour+":"+min+":"+sec);
        Roominfo=(TextView) findViewById(R.id.roominfo3);
        Roominfo.setText(names[b[p]]);
        Roominfo.setTypeface(Typeface.createFromAsset(Myreserve2Activity.this.getAssets(), "font/KaiTi.TTF"));
        Roomimg=(ImageView)findViewById(R.id.roomimg3);
        Roomimg.setImageResource(img[b[p]]);
        Backroom=findViewById(R.id.backroom2);
        Backroom.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(Myreserve2Activity.this, "退房成功!",Toast.LENGTH_SHORT).show();
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        MysqlUser mysqlUser=new MysqlUser();
                        try {
                            String sql="update roominfo set roomstate= 0,roomuserid=null ,reservetime=null where roomid='"+id+"'";
                            mysqlUser.update(sql);
                        } catch (SQLException e) {
                            e.printStackTrace();
                        }
                    }
                }).start();
            }
        });
    }
}

 

posted @ 2021-06-07 22:24  不想起名队  阅读(28)  评论(0)    收藏  举报