📄 customerprocess.java
字号:
rs.close();
pstat.close();
mm.SetType("true");
mm.SetNum(num*2);
System.out.println("AllRestaurantView success");
mo.appendmessage("AllRestaurantView"+"\n");
return true;
}
}
catch(SQLException e){
e.printStackTrace();
System.out.println("SQLException!");
}
return false;
}
///////////////////////////////////////////////
public boolean FoodView(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 food in this restaurant");
mo.appendmessage(id+" No food in this restaurant"+"\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+" FoodView success");
mo.appendmessage(id+" FoodView success"+"\n");
return true;
}
}
catch(SQLException e){
e.printStackTrace();
System.out.println("SQLException!");
}
return false;
}
///////////////////////////////////////////////////////////////////////////////////
public boolean Dine(MyMessage mm)
{
try{
String id = mm.GetMes(0);
Statement stat1=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
Statement stat2=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
Statement stat3=conn.createStatement();
ResultSet rsOfCustomerLogin=stat3.executeQuery("select * from login where id='"+mm.GetMes(0)+"'");
rsOfCustomerLogin.first();
ResultSet rsOfCustomerBankAccount=stat1.executeQuery("select * from bank_account where id='"+mm.GetMes(0)+"'");
ResultSet rsOfRestaurantBankAccount=stat2.executeQuery("select * from bank_account where id='"+mm.GetMes(1)+"'");
String cmd="select * from restaurant_customer_".concat(mm.GetMes(1));
PreparedStatement pstat1=conn.prepareStatement(cmd,ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
if(!rsOfCustomerBankAccount.next())
{
System.out.println(mm.GetMes(0)+" customer do not have an account");
mo.appendmessage(mm.GetMes(0)+" customer do not have an account"+"\n");
mm.SetType("customernoaccount");
mm.SetNum(0);
rsOfCustomerBankAccount.close();
rsOfRestaurantBankAccount.close();
rsOfCustomerLogin.close();
stat1.close();
stat2.close();
stat3.close();
pstat1.close();
return true;
}
else if(!rsOfRestaurantBankAccount.next())/////////////////////////
{
System.out.println(mm.GetMes(1)+" restaurant do not have an account");
mo.appendmessage(mm.GetMes(1)+" restaurant do not have an account"+"\n");
mm.SetType("restaurantnoaccount");////////////////////////will not excute
mm.SetNum(0);
rsOfCustomerBankAccount.close();
rsOfRestaurantBankAccount.close();
rsOfCustomerLogin.close();
stat1.close();
stat2.close();
stat3.close();
pstat1.close();
return true;
}
else
{
if("cash".equals(mm.GetMes(2)))
{
float customerCash=rsOfCustomerBankAccount.getFloat("cash");
float price = 0;
for(int i = 4;i < mm.GetNum();i+=2)
{
price += Float.parseFloat(mm.GetMes(i));
}
float restaurantCash=rsOfRestaurantBankAccount.getFloat("cash");
if(customerCash < price)
{
System.out.println(mm.GetMes(0)+" customer not enough cash");
mo.appendmessage(mm.GetMes(0)+" customer not enough cash"+"\n");
mm.SetType("noenoughcash");
mm.SetNum(0);
rsOfCustomerBankAccount.close();
rsOfRestaurantBankAccount.close();
rsOfCustomerLogin.close();
stat1.close();
stat2.close();
stat3.close();
pstat1.close();
return true;
}
else
{
customerCash-=price;
restaurantCash+=price;
rsOfCustomerBankAccount.updateFloat("cash", customerCash);
rsOfCustomerBankAccount.updateRow();
rsOfRestaurantBankAccount.updateFloat("cash", restaurantCash);
rsOfRestaurantBankAccount.updateRow();
//now connect to restaurant_customer_(id) and insert a new row
ResultSet rsOfRestaurantRecord=pstat1.executeQuery();
for(int i = 3;i < mm.GetNum();i += 2)
{
rsOfRestaurantRecord.moveToInsertRow();
rsOfRestaurantRecord.updateString("customer_id",mm.GetMes(0));
rsOfRestaurantRecord.updateString("customer_name",rsOfCustomerLogin.getString("name"));
rsOfRestaurantRecord.updateString("foodname",mm.GetMes(i));
rsOfRestaurantRecord.updateFloat("price",Float.parseFloat(mm.GetMes(i+1)));
rsOfRestaurantRecord.updateNull("time");
rsOfRestaurantRecord.insertRow();
}
//insert finished
rsOfRestaurantRecord.close();
mm.SetType("true");
mm.SetNum(0);
rsOfCustomerBankAccount.close();
rsOfRestaurantBankAccount.close();
rsOfCustomerLogin.close();
stat1.close();
stat2.close();
stat3.close();
pstat1.close();
System.out.println(mm.GetMes(0)+" Dine success");
mo.appendmessage(mm.GetMes(0)+" Dine success"+"\n");
return true;
}
}
else
{
float customerAccount=rsOfCustomerBankAccount.getFloat("account");
float price = 0;
for(int i = 4;i < mm.GetNum();i+=2)
{
price += Float.parseFloat(mm.GetMes(i));
}
float restaurantAccount=rsOfRestaurantBankAccount.getFloat("account");
if(customerAccount<price)
{
System.out.println(mm.GetMes(0)+" customer not enough account");
mo.appendmessage(mm.GetMes(0)+" customer not enough account"+"\n");
mm.SetType("notenoughaccount");
mm.SetNum(0);
rsOfCustomerBankAccount.close();
rsOfRestaurantBankAccount.close();
rsOfCustomerLogin.close();
stat1.close();
stat2.close();
stat3.close();
pstat1.close();
return true;
}
else
{
customerAccount-=price;
restaurantAccount+=price;
rsOfCustomerBankAccount.updateFloat("account", customerAccount);
rsOfCustomerBankAccount.updateRow();
rsOfRestaurantBankAccount.updateFloat("account", restaurantAccount);
rsOfRestaurantBankAccount.updateRow();
//now connect to restaurant_customer_(id) and insert a new row
ResultSet rsOfRestaurantRecord=pstat1.executeQuery();
for(int i = 3;i < mm.GetNum();i += 2)
{
rsOfRestaurantRecord.moveToInsertRow();
rsOfRestaurantRecord.updateString("customer_id",mm.GetMes(0));
rsOfRestaurantRecord.updateString("customer_name",rsOfCustomerLogin.getString("name"));
rsOfRestaurantRecord.updateString("foodname",mm.GetMes(i));
rsOfRestaurantRecord.updateFloat("price",Float.parseFloat(mm.GetMes(i+1)));
rsOfRestaurantRecord.updateNull("time");
rsOfRestaurantRecord.insertRow();
}
//insert finished
stat = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet bankclient = stat.executeQuery("SELECT * FROM login WHERE id = '"+mm.GetMes(1)+"'");
bankclient.next();
String resname = new String(bankclient.getString("name"));
bankclient = stat.executeQuery("select * from bank_client");
bankclient.moveToInsertRow();
bankclient.updateString("id", mm.GetMes(0));
bankclient.updateString("name", rsOfCustomerLogin.getString("name"));
bankclient.updateString("h_type", "transfer");
bankclient.updateFloat("account", price);
bankclient.updateNull("time");
bankclient.updateString("to_id", mm.GetMes(1));
bankclient.updateString("to_name", resname);
bankclient.insertRow();
bankclient.close();
rsOfRestaurantRecord.close();
rsOfCustomerBankAccount.close();
rsOfRestaurantBankAccount.close();
rsOfCustomerLogin.close();
stat.close();
stat1.close();
stat2.close();
stat3.close();
pstat1.close();
mm.SetType("true");
mm.SetNum(0);
System.out.println(mm.GetMes(0)+" Dine success");
mo.appendmessage(mm.GetMes(0)+" Dine success"+"\n");
return true;
}
}
}
}
catch(SQLException e)
{
e.printStackTrace();
System.out.println("SQLException!");
}
return false;
}
///////////////////////////////////////////////////////////////////////////
public boolean BuySoft(MyMessage mm)
{
try
{
Statement stat1=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
Statement stat2=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
Statement stat3=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
Statement stat4=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rsOfCustomerInBank=stat1.executeQuery("select * from bank_account where id='"+mm.GetMes(0)+"'");
ResultSet rsOfSoftSellInBank=stat2.executeQuery("select * from bank_account where id='"+mm.GetMes(1)+"'");
ResultSet rsOfSoftSellAll=stat3.executeQuery(("select * from softsell_all_".concat(mm.GetMes(1))).concat(" where softname='"+mm.GetMes(2)+"'"));
ResultSet rsOfSoftSellCustomer=stat4.executeQuery("select * from softsell_customer_".concat(mm.GetMes(1)));
rsOfSoftSellAll.first();
if(!rsOfCustomerInBank.next())
{
System.out.println(mm.GetMes(0)+" customer does not have an account");
mo.appendmessage(mm.GetMes(0)+" customer does not have an account"+"\n");
mm.SetType("customernoaccount");
mm.SetNum(0);
rsOfCustomerInBank.close();
rsOfSoftSellInBank.close();
rsOfSoftSellAll.close();
rsOfSoftSellCustomer.close();
stat1.close();
stat2.close();
stat3.close();
stat4.close();
return true;
}
else if(!rsOfSoftSellInBank.next())
{
System.out.println(mm.GetMes(0)+" buy failed,sell company does not have an account");
mo.appendmessage(mm.GetMes(0)+" buy failed,sell company does not have an account"+"\n");
mm.SetType("sellnoaccount");
mm.SetNum(0);
rsOfCustomerInBank.close();
rsOfSoftSellInBank.close();
rsOfSoftSellAll.close();
rsOfSoftSellCustomer.close();
stat1.close();
stat2.close();
stat3.close();
stat4.close();
return true;
}
else
{
if("cash".equals(mm.GetMes(4)))
{
float customerCash=rsOfCustomerInBank.getFloat("cash");
float retail=Float.parseFloat(mm.GetMes(3));
rsOfSoftSellInBank.first();
float SoftSellCash=rsOfSoftSellInBank.getFloat("cash");
if(customerCash<retail)
{
System.out.println(mm.GetMes(0)+" customer does not have enough cash");
mo.appendmessage(mm.GetMes(0)+" customer does not have enough cash"+"\n");
rsOfCustomerInBank.close();
rsOfSoftSellInBank.close();
rsOfSoftSellAll.close();
rsOfSoftSellCustomer.close();
stat1.close();
stat2.close();
stat3.close();
stat4.close();
mm.SetType("notenoughcash");
mm.SetNum(0);
return true;
}
else
{
customerCash-=retail;
rsOfCustomerInBank.first();
rsOfCustomerInBank.updateFloat("cash",customerCash);
rsOfCustomerInBank.updateRow();
SoftSellCash+=retail;
rsOfSoftSellInBank.first();
rsOfSoftSellInBank.updateFloat("cash",SoftSellCash);
rsOfSoftSellInBank.updateRow();
rsOfSoftSellAll.first();
rsOfSoftSellAll.updateInt("sold",rsOfSoftSellAll.getInt("sold")+1);
rsOfSoftSellAll.updateInt("stored",rsOfSoftSellAll.getInt("stored")-1);
rsOfSoftSellAll.updateRow();
rsOfSoftSellCustomer.moveToInsertRow();
rsOfSoftSellCustomer.updateString("customer_id",mm.GetMes(0));
rsOfSoftSellCustomer.updateString("customer_name",rsOfCustomerInBank.getString("name"));
rsOfSoftSellCustomer.updateString("softname",mm.GetMes(2));
rsOfSoftSellCustomer.updateFloat("retail",Float.parseFloat(mm.GetMes(3)));
rsOfSoftSellCustomer.updateNull("time");
rsOfSoftSellCustomer.insertRow();
rsOfCustomerInBank.close();
rsOfSoftSellInBank.close();
rsOfSoftSellAll.close();
rsOfSoftSellCustomer.close();
stat1.close();
stat2.close();
stat3.close();
stat4.close();
mm.SetType("true");
mm.SetNum(0);
System.out.println(mm.GetMes(0)+" BuySoft success");
mo.appendmessage(mm.GetMes(0)+" BuySoft success"+"\n");
return true;
}
}
else
{
float customerAccount=rsOfCustomerInBank.getFloat("account");
float retail=Float.parseFloat(mm.GetMes(3));
rsOfSoftSellInBank.first();
float SoftSellAccount=rsOfSoftSellInBank.getFloat("account");
if(customerAccount<retail)
{
rsOfCustomerInBank.close();
rsOfSoftSellInBank.close();
rsOfSoftSellAll.close();
rsOfSoftSellCustomer.close();
stat1.close();
stat2.close();
stat3.close();
stat4.close();
mm.SetType("notenoughaccount");
mm.SetNum(0);
System.out.println(mm.GetMes(0)+" customer does not have enough account");
mo.appendmessage(mm.GetMes(0)+" customer does not have enough account"+"\n");
return true;
}
else
{
customerAccount-=retail;
rsOfCustomerInBank.first();
rsOfCustomerInBank.updateFloat("account",customerAccount);
rsOfCustomerInBank.updateRow();
SoftSellAccount+=retail;
rsOfSoftSellInBank.first();
rsOfSoftSellInBank.updateFloat("account",SoftSellAccount);
rsOfSoftSellInBank.updateRow();
rsOfSoftSellAll.first();
rsOfSoftSellAll.updateInt("sold",rsOfSoftSellAll.getInt("sold")+1);
rsOfSoftSellAll.updateInt("stored",rsOfSoftSellAll.getInt("stored")-1);
rsOfSoftSellAll.updateRow();
rsOfSoftSellCustomer.moveToInsertRow();
rsOfSoftSellCustomer.updateString("customer_id",mm.GetMes(0));
rsOfSoftSellCustomer.updateString("customer_name",rsOfCustomerInBank.getString("name"));
rsOfSoftSellCustomer.updateString("softname",mm.GetMes(2));
rsOfSoftSellCustomer.updateFloat("retail",Float.parseFloat(mm.GetMes(3)));
rsOfSoftSellCustomer.updateNull("time");
rsOfSoftSellCustomer.insertRow();
////////////////////////////////////////////////////////////////////////////////////////////
Statement stat5=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rsOfBankClient=stat5.executeQuery("select * from bank_client");
//////////////////////////////////////////////////////////////////////////////////////////
Statement stat6=conn.createStatement();
ResultSet rsOfCustomerLogin=stat6.executeQuery("select * from login where id='"+mm.GetMes(0)+"'");
rsOfCustomerLogin.first();
//////////////////////////////////////////////////////////////////////////////////////////
Statement stat7=conn.createStatement();
ResultSet rsOfSellLogin=stat7.executeQuery("select * from login where id='"+mm.GetMes(1)+"'");
rsOfSellLogin.first();
////////////////////////////////////////////////////////////////////////////////////
rsOfBankClient.moveToInsertRow();
rsOfBankClient.updateString("id",mm.GetMes(0));
rsOfBankClient.updateString("name",rsOfCustomerLogin.getString("name"));
rsOfBankClient.updateString("h_type","transfer");
rsOfBankClient.updateString("to_id",mm.GetMes(1));
rsOfBankClient.updateString("to_name",rsOfSellLogin.getString("name"));
rsOfBankClient.updateFloat("account",Float.parseFloat(mm.GetMes(3)));
rsOfBankClient.insertRow();
rsOfBankClient.close();
stat5.close();
rsOfCustomerLogin.close();
stat6.close();
rsOfSellLogin.close();
stat7.close();
rsOfCustomerInBank.close();
rsOfSoftSellInBank.close();
rsOfSoftSellAll.close();
rsOfSoftSellCustomer.close();
stat1.close();
stat2.close();
stat3.close();
stat4.close();
mm.SetType("true");
mm.SetNum(0);
System.out.println(mm.GetMes(0)+" BuySoft success");
mo.appendmessage(mm.GetMes(0)+" BuySoft success"+"\n");
return true;
}
}
}
}
catch(SQLException e)
{
System.out.println("SQLException!");
e.printStackTrace();
}
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -