package manager;
import manager.*;
import JDBC.*;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import order.meals.bean.dish;
import order.meals.bean.restaurant;
import order.meals.bean.ordert;
/**
* 订单模块
* @author zenoting
*
*/
public class OrderManager {
private JDBCconnect j = new JDBCconnect();
public OrderManager() {
j.getConnect();
}
/**
* 搜索美食
*/
public List<dish> search(String searchname){
try{
/*int PageSize = 5;
int Page=1;
int totalPage=1;
int totalrecord=0;
String sql="select count* as recordcount from dish";
System.out.println(sql);
if(j.selectRecord(sql).next()) totalrecord=j.selectRecord(sql).getInt("recordcount");
sql = "select * from dish where Dish_Name like'%"+searchname+"%'";
System.out.println(sql);
if(totalrecord%PageSize==0)
totalPage=totalrecord/PageSize;
else
totalPage = (int)Math.floor(totalrecord/PageSize)+1;
if(totalPage==0)totalPage=1;
try{
page=page;
}
catch(java.lang.NumberFormatException e){
page=1;
}
if(page<1)page=1;
if(page>totalPage)page=totalPage;
sql = "select * from dish where Dish_Name like'%"+searchname+"%'";
System.out.println(sql);
j.selectRecord(sql).absolute((page-1)*PageSize+1);*/
String sql=null;
if(searchname!=null)
sql = "select * from dish where Dish_Name like'%"+searchname+"%'";
else
sql="select* from dish";
List<dish> dishlist=new ArrayList();
int count=0;
ResultSet rs=j.selectRecord1(sql);
while(rs.next()){
System.out.println(count++);
String Dish_Name = rs.getString("Dish_Name");
System.out.println("Dish_Name");
String Dish_Rest = rs.getString("Dish_Rest");
System.out.println("Dish_Rest");
String Dish_Price = String.valueOf(rs.getFloat("Dish_Price"));
System.out.println("Dish_Price");
String Dish_Disc = rs.getString("Dish_Disc");
System.out.println("Dish_Disc");
dish d=new dish();
d.setDish_Name(Dish_Name);
d.setDish_Rest(Dish_Rest);
d.setDish_Price(Dish_Price);
d.setDish_Disc(Dish_Disc);
dishlist.add(d);
}
return dishlist;
}catch (Exception e) {
e.printStackTrace();
return null;
}
}
//查看所有美食
public List<dish> look(String restaurant){
try{
String sql = "select * from dish where Dish_Rest ='"+restaurant+"'";
List<dish> dishlist=new ArrayList();
int count=0;
ResultSet rs=j.selectRecord1(sql);
while(rs.next()){
System.out.println(count++);
String Dish_Name = rs.getString("Dish_Name");
System.out.println("Dish_Name");
String Dish_Rest = rs.getString("Dish_Rest");
System.out.println("Dish_Rest");
String Dish_Price = String.valueOf(rs.getFloat("Dish_Price"));
System.out.println("Dish_Price");
String Dish_Disc = rs.getString("Dish_Disc");
System.out.println("Dish_Disc");
dish d=new dish();
d.setDish_Name(Dish_Name);
d.setDish_Rest(Dish_Rest);
d.setDish_Price(Dish_Price);
d.setDish_Disc(Dish_Disc);
dishlist.add(d);
}
return dishlist;
}catch (Exception e) {
e.printStackTrace();
return null;
}
}
//餐厅查看订单(未确认)
public List<ordert> presentrest(String username){
try{
String sql="select* from ordert where Order_Status=0 and Order_Rest='"+username+"'";
System.out.println(sql);
List<ordert> orderlist=new ArrayList();
ResultSet rs=j.selectRecord1(sql);
while(rs.next()){
int Order_No=rs.getInt("Order_No");
System.out.println(Order_No);
//String Order_Date=rs.getString("Order_Date");
String Order_Rest=rs.getString("Order_Rest");
String Order_Cont=rs.getString("Order_Cont");
String Order_Person=rs.getString("Order_Person");
int Order_Amount=rs.getInt("Order_Amount");
ordert o=new ordert();
o.setOrder_No(Order_No);
// o.setOrder_Date(Order_Date);
o.setOrder_Rest(Order_Rest);
o.setOrder_Cont(Order_Cont);
o.setOrder_Person(Order_Person);
o.setOrder_Amount(Order_Amount);
orderlist.add(o);
}
return orderlist;
}catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* 餐厅查看历史订单
*/
public List<ordert> presenthistory(String username){
try{
String sql="select* from ordert where Order_Status=1 and Order_Rest='"+username+"'";
System.out.println(sql);
List<ordert> orderlist=new ArrayList();
ResultSet rs=j.selectRecord1(sql);
while(rs.next()){
int Order_No=rs.getInt("Order_No");
System.out.println(Order_No);
//String Order_Date=rs.getString("Order_Date");
String Order_Rest=rs.getString("Order_Rest");
String Order_Cont=rs.getString("Order_Cont");
String Order_Person=rs.getString("Order_Person");
int Order_Amount=rs.getInt("Order_Amount");
ordert o=new ordert();
o.setOrder_No(Order_No);
// o.setOrder_Date(Order_Date);
o.setOrder_Rest(Order_Rest);
o.setOrder_Cont(Order_Cont);
o.setOrder_Person(Order_Person);
o.setOrder_Amount(Order_Amount);
orderlist.add(o);
}
return orderlist;
}catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
*确认订单
* @param id
*/
public void OrderQeuren(String orderno){
try{ String sql="update ordert set Order_Status=1 where Order_No='"+orderno+"'";
j.updateRecord(sql);
}
catch (Exception e){
e.printStackTrace();
}
}
/**
* 取消订单并删除
*/
public void OrderQuxiao(String orderno){
try{
String sql="delete from ordert where Order_No='"+orderno+"'";
j.deleteRecord(sql);
}
catch (Exception e){
e.printStackTrace();
}
}
/**
* 显示订单(普通用户)
*/
public List<ordert> present(String person){
try{
String sql="select* from ordert where Order_Person='"+person+"'";
List<ordert> orderlist=new ArrayList();
ResultSet rs=j.selectRecord1(sql);
while(rs.next()){
int Order_No = rs.getInt(1);
String Order_Rest = rs.getString(2);
String Order_Cont= rs.getString(3);
String Order_Person = rs.getString(4);
int status=rs.getInt(5);
String Order_Status=null;
if(status==0)Order_Status="未处理";
if(status==1)Order_Status="已处理";
int Order_Amount=rs.getInt(6);
ordert o=new ordert();
o.setOrder_No(Order_No);
o.setOrder_Rest(Order_Rest);
o.setOrder_Cont(Order_Cont);
o.setOrder_Person(Order_Person);
o.setOrder_Status(Order_Status);
o.setOrder_Amount(Order_Amount);
orderlist.add(o);
}
return orderlist;
}catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* 普通用户下订单
*/
public boolean ordermeals(String dishname,String dishrest,String person){
try{
int totalrecord=0;
String sql="select max(Order_No) as d from ordert";
ResultSet rs=j.selectRecord1(sql);
if(rs.next())
totalrecord=rs.getInt("d");
totalrecord=totalrecord+1;
System.out.println(sql);
System.out.println("totalrecord");
System.out.println(dishname);
System.out.println(dishrest);
sql="insert into ordert values('"+totalrecord+"','"+dishrest+"','"+dishname+"','"+person+"',0,1)";
j.insertRecord(sql);
System.out.println(sql);
return true;
}catch (Exception e) {
e.printStackTrace();
return false;
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
前往页