📄 test.java
字号:
my.add(df);
my.add(hint2);
my.add(tc);
my.setSize(450,300);
my.setVisible(true);
}
});
df.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String url="jdbc:odbc:HOTEL";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(java.lang.ClassNotFoundException ex){}
try{String s1,s2,s3,s4,s5;
Connection con=DriverManager.getConnection(url,"",null);
Statement stmt=con.createStatement();
s1=handcode1.getText();
s2=roomnum1.getText();
s3=roomcount1.getText();
s4=roomprice1.getText();
s5=billcode1.getText();
double n=Double.parseDouble(s4);
double m=Double.parseDouble(s3);
double l=m*n;
String s6=String.valueOf(l);
String sql="INSERT INTO xiaofei(billcode,handcode,rsfname,rsfcount,rsfprice) VALUES(?,?,?,?,?)";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1,s5);
ps.setString(2,s1);
ps.setString(3,s2);
ps.setString(4,s3);
ps.setString(5,s4);
String sql2="UPDATE bill SET billcode=? WHERE handcode=?";
PreparedStatement ps2=con.prepareStatement(sql2);
ps2.setString(1,s5);
ps2.setString(2,s1);
String sql3="UPDATE bill SET summoney=summoney+? WHERE billcode=?";
PreparedStatement ps3=con.prepareStatement(sql3);
ps3.setString(1,s6);
ps3.setString(2,s5);
if(s1.length()!=0&&s2.length()!=0&&s3.length()!=0){
ps.executeUpdate();
ps2.executeUpdate();
ps3.executeUpdate();
hint2.setText("订房成功!");
stmt.close();
con.close();
}
else{
stmt.close();
con.close();
hint2.setText("订房失败!");
}
}
catch(SQLException ex){}
}
});
////////////////////////////////////////////////////
m22.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
my=new Dialog(test.this,"服务",true);
my.setLayout(new FlowLayout(FlowLayout.LEADING,20,20));
my.add(sername);
my.add(sername1);
my.add(sercount);
my.add(sercount1);
my.add(serprice);
my.add(serprice1);
my.add(billcode);
my.add(billcode1);
my.add(handcode);
my.add(handcode1);
my.add(fw);
my.add(hint3);
my.add(tc);
my.setSize(450,300);
my.setVisible(true);
}
});
fw.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String url="jdbc:odbc:HOTEL";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(java.lang.ClassNotFoundException ex){}
try{String s1,s2,s3,s4,s5;
Connection con=DriverManager.getConnection(url,"",null);
Statement stmt=con.createStatement();
s1=sername1.getText();
s2=sercount1.getText();
s3=serprice1.getText();
s4=handcode1.getText();
s5=billcode1.getText();
double n=Double.parseDouble(s2);
double m=Double.parseDouble(s3);
double l=m*n;
String s6=String.valueOf(l);
String sql="INSERT INTO xiaofei(billcode,handcode,rsfname,rsfcount,rsfprice) VALUES(?,?,?,?,?)";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1,s5);
ps.setString(2,s4);
ps.setString(3,s1);
ps.setString(4,s2);
ps.setString(5,s3);
String sql2="UPDATE bill SET billcode=? WHERE handcode=?";
PreparedStatement ps2=con.prepareStatement(sql2);
ps2.setString(1,s5);
ps2.setString(2,s4);
String sql3="UPDATE bill SET summoney=summoney+? WHERE billcode=?";
PreparedStatement ps3=con.prepareStatement(sql3);
ps3.setString(1,s6);
ps3.setString(2,s5);
if(s1.length()!=0&&s2.length()!=0&&s3.length()!=0){
ps.executeUpdate();
ps2.executeUpdate();
ps3.executeUpdate();
hint3.setText("预定成功!");
stmt.close();
con.close();
}
else{
stmt.close();
con.close();
hint3.setText("预定失败!");
}
}
catch(SQLException ex){}
}
});
//////////////////////////////////////////////////
/////////////////////////////////////////////
m23.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
my=new Dialog(test.this,"订餐",true);
my.setLayout(new FlowLayout(FlowLayout.LEADING,20,20));
my.add(foodname);
my.add(foodname1);
my.add(foodcount);
my.add(foodcount1);
my.add(foodprice);
my.add(foodprice1);
my.add(billcode);
my.add(billcode1);
my.add(handcode);
my.add(handcode1);
my.add(dc);
my.add(hint4);
my.add(tc);
my.setSize(450,300);
my.setVisible(true);
}
});
dc.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String url="jdbc:odbc:HOTEL";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(java.lang.ClassNotFoundException ex){}
try{String s1,s2,s3,s4,s5;
Connection con=DriverManager.getConnection(url,"",null);
Statement stmt=con.createStatement();
s1=foodname1.getText();
s2=foodcount1.getText();
s3=foodprice1.getText();
s4=handcode1.getText();
s5=billcode1.getText();
double n=Double.parseDouble(s2);
double m=Double.parseDouble(s3);
double l=m*n;
String s6=String.valueOf(l);
String sql="INSERT INTO xiaofei(billcode,handcode,rsfname,rsfcount,rsfprice) VALUES(?,?,?,?,?)";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1,s5);
ps.setString(2,s4);
ps.setString(3,s1);
ps.setString(4,s2);
ps.setString(5,s3);
String sql2="UPDATE bill SET billcode=? WHERE handcode=?";
PreparedStatement ps2=con.prepareStatement(sql2);
ps2.setString(1,s5);
ps2.setString(2,s4);
String sql3="UPDATE bill SET summoney=summoney+? WHERE billcode=?";
PreparedStatement ps3=con.prepareStatement(sql3);
ps3.setString(1,s6);
ps3.setString(2,s5);
if(s1.length()!=0&&s2.length()!=0&&s3.length()!=0){
ps.executeUpdate();
ps2.executeUpdate();
ps3.executeUpdate();
hint4.setText("订餐成功!");
stmt.close();
con.close();
}
else{
stmt.close();
con.close();
hint4.setText("订餐失败!");
}
}
catch(SQLException ex){}
}
});
//////////////////////////////////////////////////////帐单操作
m17.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
my=new Dialog(test.this,"结帐",true);
my.setLayout(new FlowLayout(FlowLayout.LEADING,20,20));
my.addWindowListener( //关闭按钮事件
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
my.dispose();
}
}
);
my.add(hand);
my.add(hand1);
my.add(billnum);
my.add(billnum1);
;
my.add(paid);
my.add(paid1);
my.add(jz);
my.add(hint5);
////////////////////////////////////////////
my.setSize(450,300);
my.setVisible(true);
}
});
m15.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
my=new Dialog(test.this,"查询消费项目",true);
my.setLayout(new FlowLayout(FlowLayout.LEADING,20,20));
my.addWindowListener( //关闭按钮事件
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
my.dispose();
}
}
);
my.add(billcode);
my.add(billcode1);
my.add(qd1);
////////////////////////////////////////////
my.setSize(450,300);
my.setVisible(true);
}
});
qd1.addActionListener(new ActionListener(){ //查询消费按钮
public void actionPerformed(ActionEvent e){
JFrame f=new JFrame("查询消费项目");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(java.lang.ClassNotFoundException ex){}
try{
String[] names;
String s="";
int i,j,RowNum,ColNum;
Object[][] info;
///////////////////////////////////////从数据库获取数据////////////////////////
String url="jdbc:odbc:HOTEL";
Connection con=DriverManager.getConnection(url,"",null);
s=billcode1.getText();
Statement stmt=con.createStatement();
String sql="select count(*) from xiaofei WHERE billcode LIKE '%"+s+"%'"; //取得数据表的记录数和字段数
ResultSet res=stmt.executeQuery(sql);
res.next();
RowNum=res.getInt(1);
String sqlstr="SELECT * FROM xiaofei WHERE billcode LIKE '%"+s+"%'";
res=stmt.executeQuery(sqlstr); //发送SQL语句
ResultSetMetaData rsmd=res.getMetaData();
ColNum=rsmd.getColumnCount();
names=new String[ColNum]; //构造JTable
for (i=1;i<=ColNum;i++) names[i-1]=rsmd.getColumnName(i);
info=new Object[RowNum][];
i=0;
while (res.next())
{
info[i]=new Object[ColNum];
for (j=1;j<=ColNum;j++)
{
info[i][j-1]=res.getObject(j);
}
i++;
}
//////////////////////////////////////
JTable table=new JTable(info,names);
table.setPreferredScrollableViewportSize(new Dimension(400,200));
JScrollPane scrollPane=new JScrollPane(table);
Container cont=f.getContentPane();
cont.add(scrollPane);
//table.revalidate();
//f.repaint();
f.pack();
f.setLocation(500,200);
f.setResizable(true);
f.setSize(500,400);
f.setVisible(true);
table.revalidate();
}catch(SQLException ex){}
}
});
/////////////////////////////////////////////////
jz.addActionListener(new ActionListener(){ //结帐按钮
public void actionPerformed(ActionEvent e){
String url="jdbc:odbc:HOTEL";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(java.lang.ClassNotFoundException ex){}
try{String s1,s2,s3,s4,s5;
Connection con=DriverManager.getConnection(url,"",null);
Statement stmt=con.createStatement();
s1=hand1.getText();
s2=billnum1.getText();
s3=paid1.getText();
String sql="UPDATE bill SET paid=?,repaid=paid-summoney,paidtype=true WHERE billcode=? and handcode=?";
PreparedStatement ps=con.prepareStatement(sql);
ps.setString(1,s3);
ps.setString(2,s2);
ps.setString(3,s1);
if(s1.length()!=0&&s2.length()!=0&&s3.length()!=0){
ps.executeUpdate();
hint5.setText("结帐成功!");
stmt.close();
con.close();
}
else{
stmt.close();
con.close();
hint5.setText("结帐失败!");
}
}
catch(SQLException ex){}
}
});
/////////////////////////////////////////////////////
m16.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
my=new Dialog(test.this,"帐单查询",true);
my.setLayout(new FlowLayout(FlowLayout.LEADING,20,20));
my.addWindowListener( //关闭按钮事件
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
my.dispose();
}
}
);
my.add(handcode);
my.add(handcode1);
my.add(qd);
////////////////////////////////////////////
my.setSize(450,300);
my.setVisible(true);
}
});
/////////////
qd.addActionListener(new ActionListener(){ //查询消费按钮
public void actionPerformed(ActionEvent e){
JFrame f=new JFrame("帐单显示");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(java.lang.ClassNotFoundException ex){}
try{
String[] names;
String s="";
int i,j,RowNum,ColNum;
Object[][] info;
///////////////////////////////////////从数据库获取数据////////////////////////
String url="jdbc:odbc:HOTEL";
Connection con=DriverManager.getConnection(url,"",null);
s=handcode1.getText();
Statement stmt=con.createStatement();
String sql="select count(*) from bill WHERE handcode LIKE '%"+s+"%'"; //取得数据表的记录数和字段数
ResultSet res=stmt.executeQuery(sql);
res.next();
RowNum=res.getInt(1);
String sqlstr="SELECT * FROM bill WHERE handcode LIKE '%"+s+"%'";
res=stmt.executeQuery(sqlstr); //发送SQL语句
ResultSetMetaData rsmd=res.getMetaData();
ColNum=rsmd.getColumnCount();
names=new String[ColNum]; //构造JTable
for (i=1;i<=ColNum;i++) names[i-1]=rsmd.getColumnName(i);
info=new Object[RowNum][];
i=0;
while (res.next())
{
info[i]=new Object[ColNum];
for (j=1;j<=ColNum;j++)
{
info[i][j-1]=res.getObject(j);
}
i++;
}
//////////////////////////////////////
JTable table=new JTable(info,names);
table.setPreferredScrollableViewportSize(new Dimension(400,200));
JScrollPane scrollPane=new JScrollPane(table);
Container cont=f.getContentPane();
cont.add(scrollPane);
//table.revalidate();
//f.repaint();
f.pack();
f.setLocation(900,200);
f.setResizable(false);
f.setSize(500,400);
f.setVisible(true);
}catch(SQLException ex){}
}
});
}
public static void main(String a[])
{
new test();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -