📄 restaurantprocess.java
字号:
package serverpack;
import java.sql.*;
import java.text.DecimalFormat;
public class RestaurantProcess {
private Connection conn;
private Statement stat;
private Monitor mo;
private DecimalFormat df;
public RestaurantProcess(Connection c,Monitor m){conn = c;mo = m;df = new DecimalFormat("#,###,###,###.00");}
public boolean RestaurantAddToMenu(MyMessage mm)
{
try{
String id = new String(mm.GetMes(0));
String cmd="select * from restaurant_menu_".concat(mm.GetMes(0));
cmd=cmd.concat(" where foodname='"+mm.GetMes(1)+"'");
PreparedStatement pstat=conn.prepareStatement(cmd,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=pstat.executeQuery();
if(rs.next())
{
System.out.println(id+" food name already exist");
mo.appendmessage(id+" food name already exist"+"\n");
rs.close();
pstat.close();
mm.SetType("false");
mm.SetNum(0);
return true;
}
else
{
rs.moveToInsertRow();
rs.updateString("foodname",mm.GetMes(1));
rs.updateFloat("price",Float.parseFloat(mm.GetMes(2)));
rs.insertRow();
mm.SetType("true");
mm.SetNum(0);
rs.close();
pstat.close();
System.out.println(id+" RestaurantAddToMenu success");
mo.appendmessage(id+" RestaurantAddToMenu success"+"\n");
return true;
}
}
catch(SQLException e)
{
System.out.println("SQLException");
e.printStackTrace();
}
return false;
}
///////////////////////////////////////////////////////////////////////////////////
public boolean RestaurantMenuView(MyMessage mm)
{
try
{
String id = new String(mm.GetMes(0));
String cmd="select * from restaurant_menu_".concat(mm.GetMes(0));
PreparedStatement pstat=conn.prepareStatement(cmd);
ResultSet rs=pstat.executeQuery();
if(!rs.next())
{
mm.SetType("false");
mm.SetNum(0);
System.out.println(id+" no menu information");
mo.appendmessage(id+" no menu information"+"\n");
rs.close();
pstat.close();
return true;
}
else{
rs.last();
int num=rs.getRow();
rs.beforeFirst();
int count=0;
while(rs.next())
{
mm.SetMes(rs.getString("foodname"), count++);
mm.SetMes(df.format(rs.getFloat("price")), count++);
}
rs.close();
pstat.close();
mm.SetType("true");
mm.SetNum(num*2);
System.out.println(id+" RestaurantMenuView success");
mo.appendmessage(id+" RestaurantMenuView success"+"\n");
return true;
}
}
catch(SQLException e){
e.printStackTrace();
System.out.println("SQLException!");
}
return false;
}
public boolean RestaurantCustomerView(MyMessage mm)
{
try
{
String id = new String(mm.GetMes(0));
String cmd="select * from restaurant_customer_".concat(mm.GetMes(0));
PreparedStatement pstat=conn.prepareStatement(cmd);
ResultSet rs=pstat.executeQuery();
if(!rs.next())
{
mm.SetType("false");
mm.SetNum(0);
System.out.println(id+" no custome information");
mo.appendmessage(id+" no custome information"+"\n");
rs.close();
pstat.close();
return true;
}
else{
rs.last();
int num=rs.getRow();
rs.beforeFirst();
int count=0;
while(rs.next())
{
mm.SetMes(rs.getString("customer_id"), count++);
mm.SetMes(rs.getString("customer_name"), count++);
mm.SetMes(rs.getString("foodname"), count++);
mm.SetMes(df.format(rs.getFloat("price")), count++);
mm.SetMes(rs.getString("time"), count++);
}
rs.close();
pstat.close();
mm.SetType("true");
mm.SetNum(num*5);
System.out.println(id+" RestaurantCustomerView success");
mo.appendmessage(id+" RestaurantCustomerView success"+"\n");
return true;
}
}
catch(SQLException e){
e.printStackTrace();
System.out.println("SQLException!");
}
return false;
}
//////////////////////////////////////////////////////////////////////////////
public boolean RestaurantFinanceView(MyMessage mm)
{
float soldall=0;
try{
String id = new String(mm.GetMes(0));
String cmd="select * from restaurant_customer_".concat(mm.GetMes(0));
PreparedStatement pstat=conn.prepareStatement(cmd);
ResultSet rs=pstat.executeQuery();
if(!rs.next())
{
System.out.println("there is no customer who has been here");
mm.SetType("true");
mm.SetNum(1);
mm.SetMes(df.format(0),0);
rs.close();
pstat.close();
return true;
}
else
{
do
{
soldall+=rs.getFloat("price");
}while(rs.next());
}
mm.SetType("true");
mm.SetNum(1);
mm.SetMes(df.format(soldall), 0);
System.out.println(id+" RestaurantFinanceView success");
mo.appendmessage(id+" RestaurantFinanceView success"+"\n");
rs.close();
pstat.close();
return true;
}
catch(SQLException e)
{
System.out.println("SQLException");
e.printStackTrace();
}
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -