第二次冲刺(三)
今天我完成了管理员界面的查看房间预定情况的部分。
关键代码为:
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_roominfo); Time time = new Time(); time.setToNow(); //获取系统当前时间 int year =time.year; int month=time.month+1; int day = time.monthDay; int hour = time.hour; int min = time.minute; int sec=time.minute; String y,mo,d,h,mi,s; y=String.valueOf(year); if(month<10)mo="0"+String.valueOf(month); else mo=String.valueOf(month); if(day<10)d="0"+String.valueOf(day); else d=String.valueOf(day); if(hour<10)h="0"+String.valueOf(hour); else h=String.valueOf(hour); if(min<10)mi="0"+String.valueOf(min); else mi=String.valueOf(min); if(sec<10)s="0"+String.valueOf(sec); else s=String.valueOf(sec); str=y+mo+d+h+mi+s; Bundle bundle=getIntent().getExtras(); roomid=bundle.getInt("roomid"); userid=bundle.getString("nowid"); int id=roomid+1; Thread thread=new Thread(new Runnable() { @Override public void run() { MysqlUser mysqlUser=new MysqlUser(); try { String sql="select roomstate from roominfo where roomid='"+id+"'"; roomstate=mysqlUser.select(sql); } catch (SQLException e) { e.printStackTrace(); } } }); thread.start(); try { thread.join(); } catch (InterruptedException e) { e.printStackTrace(); } Roominfo=(TextView) findViewById(R.id.roominfo); Roominfo.setText(names[roomid]); Roomstate=(TextView)findViewById(R.id.roomstate); if(roomstate.equals("1")){ Roomstate.setTextColor(Color.rgb(255, 0, 0)); Roomstate.setText("已被预定"); } else { Roomstate.setTextColor(Color.rgb(0, 255, 0)); Roomstate.setText("未被预定"); } Roominfo.setTypeface(Typeface.createFromAsset(RoominfoActivity.this.getAssets(), "font/KaiTi.TTF")); Roomstate.setTypeface(Typeface.createFromAsset(RoominfoActivity.this.getAssets(), "font/KaiTi.TTF")); Roomimg=(ImageView)findViewById(R.id.roomimg); Roomimg.setImageResource(img[roomid]); Reserve=(Button)findViewById(R.id.reserve); Reserve.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int id=roomid+1; if(roomstate.equals("1")) Toast.makeText(RoominfoActivity.this, "房间已被预定",Toast.LENGTH_SHORT).show(); else{ Toast.makeText(RoominfoActivity.this, "预定成功!",Toast.LENGTH_SHORT).show(); new Thread(new Runnable() { @Override public void run() { MysqlUser mysqlUser=new MysqlUser(); try { String sql="update roominfo set roomstate= 1,roomuserid='"+userid+"',reservetime='"+str+"'where roomid='"+id+"'"; mysqlUser.update(sql); } catch (SQLException e) { e.printStackTrace(); } } }).start(); } } }); }