package com.xu.dao.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import com.xu.dao.IOrderDAO;
import com.xu.vo.Orders;
public class OrderDAOImpl implements IOrderDAO{
private Connection conn=null;
private PreparedStatement pst=null;
public OrderDAOImpl(Connection conn){
this.conn=conn;
}
public Set<Orders> searchOrder(String id)throws Exception{
Orders o=null;
Set<Orders> orders=new HashSet<Orders>();
String sql="SELECT * FROM orders WHERE id LIKE \'%"+id+"%\'";
this.pst=this.conn.prepareStatement(sql);
ResultSet rs=this.pst.executeQuery();
while(rs.next()){
o=new Orders();
o.setId(rs.getString(1));
o.setGoodsid(rs.getString(2));
o.setCounts(rs.getInt(3));
o.setPostperson(rs.getString(4));
o.setGetperson(rs.getString(5));
o.setPaymethod(rs.getString(6));
o.setCarid(rs.getString(7));
o.setChecked(rs.getString(8));
o.setPrice(rs.getFloat(9));
o.setTotle(rs.getFloat(10));
o.setThetime(rs.getDate(11).toString());
o.setArrival(rs.getString(12));
if(rs.getDate(13)==null){
}else{
o.setThelasttime(rs.getDate(13).toString());
}
o.setOwn(rs.getString(14));
o.setSignperson(rs.getString(15));
o.setIsdeal(rs.getString(16));
o.setPhone(rs.getString(17));
orders.add(o);
}
this.pst.close();
rs.close();
return orders;
}
public boolean addOrder(Orders o)throws Exception{
boolean flag=false;
String sql="insert into orders(id,goodsid,counts,paymethod,price,totle,thetime,own,phone) values(?,?,?,?,?,?,?,?,?)";
this.pst=this.conn.prepareStatement(sql);
this.pst.setString(1, o.getId());
this.pst.setString(2,o.getGoodsid());
this.pst.setInt(3,o.getCounts());
this.pst.setString(4, o.getPaymethod());
this.pst.setDouble(5, o.getPrice());
this.pst.setDouble(6, o.getTotle());
this.pst.setString(7, o.getThetime());
this.pst.setString(8, o.getOwn());
this.pst.setString(9, o.getPhone());
if(this.pst.executeUpdate()>0){
flag=true;
this.pst.close();
}
return flag;
}
public Set<Orders> heDui()throws Exception{
Orders o=null;
Set<Orders> orders=new HashSet<Orders>();
String sql="SELECT * FROM orders WHERE checked =\"未核定...\"";
this.pst=this.conn.prepareStatement(sql);
ResultSet rs=this.pst.executeQuery();
while(rs.next()){
o=new Orders();
o.setId(rs.getString(1));
o.setGoodsid(rs.getString(2));
o.setCounts(rs.getInt(3));
o.setPostperson(rs.getString(4));
o.setGetperson(rs.getString(5));
o.setPaymethod(rs.getString(6));
o.setCarid(rs.getString(7));
o.setChecked(rs.getString(8));
o.setPrice(rs.getFloat(9));
o.setTotle(rs.getFloat(10));
o.setThetime(rs.getDate(11).toString());
o.setArrival(rs.getString(12));
if(rs.getDate(13)==null){
}else{
o.setThelasttime(rs.getDate(13).toString());
}
o.setOwn(rs.getString(14));
o.setSignperson(rs.getString(15));
o.setIsdeal(rs.getString(16));
o.setPhone(rs.getString(17));
orders.add(o);
}
this.pst.close();
rs.close();
return orders;
}
public Set<Orders> daiChuLi() throws Exception{
Orders o=null;
Set<Orders> orders=new HashSet<Orders>();
String sql="SELECT * FROM orders WHERE isdeal=\"未处理..\"and checked=\"已核对...\"";
this.pst=this.conn.prepareStatement(sql);
ResultSet rs=this.pst.executeQuery();
while(rs.next()){
o=new Orders();
o.setId(rs.getString(1));
o.setGoodsid(rs.getString(2));
o.setCounts(rs.getInt(3));
o.setPostperson(rs.getString(4));
o.setGetperson(rs.getString(5));
o.setPaymethod(rs.getString(6));
o.setCarid(rs.getString(7));
o.setChecked(rs.getString(8));
o.setPrice(rs.getFloat(9));
o.setTotle(rs.getFloat(10));
o.setThetime(rs.getDate(11).toString());
o.setArrival(rs.getString(12));
o.setThelasttime(rs.getDate(13).toString());
o.setOwn(rs.getString(14));
o.setSignperson(rs.getString(15));
o.setIsdeal(rs.getString(16));
o.setPhone(rs.getString(17));
orders.add(o);
}
this.pst.close();
rs.close();
return orders;
}
public Set<Orders> weiTongguo()throws Exception{
Orders o=null;
Set<Orders> orders=new HashSet<Orders>();
String sql="SELECT * FROM orders WHERE checked=\"n\"";
this.pst=this.conn.prepareStatement(sql);
ResultSet rs=this.pst.executeQuery();
while(rs.next()){
o=new Orders();
o.setId(rs.getString(1));
o.setGoodsid(rs.getString(2));
o.setCounts(rs.getInt(3));
o.setPostperson(rs.getString(4));
o.setGetperson(rs.getString(5));
o.setPaymethod(rs.getString(6));
o.setCarid(rs.getString(7));
o.setChecked(rs.getString(8));
o.setPrice(rs.getFloat(9));
o.setTotle(rs.getFloat(10));
o.setThetime(rs.getDate(11).toString());
o.setArrival(rs.getString(12));
o.setThelasttime(rs.getDate(13).toString());
o.setOwn(rs.getString(14));
o.setSignperson(rs.getString(15));
o.setIsdeal(rs.getString(16));
o.setPhone(rs.getString(17));
orders.add(o);
}
this.pst.close();
rs.close();
return orders;
}
public boolean fenPei(Orders o)throws Exception{ //加个触发器 同时将车辆的working修改为忙碌
boolean flag=false;
String sql="update orders set postperson=?,getperson=?,carid=?,checked=?,thelasttime=?,signperson=?,isdeal=? where id=?";
this.pst=this.conn.prepareStatement(sql);
pst.setString(1, o.getPostperson());
pst.setString(2, o.getGetperson());
pst.setString(3, o.getCarid());
pst.setString(4,o.getChecked());
pst.setString(5, o.getThelasttime());
pst.setString(6,o.getSignperson());
pst.setString(7,o.getIsdeal());
pst.setString(8,o.getId());
if(this.pst.executeUpdate()>=1){
flag=true;
};
return flag;
}
public boolean confimOrders(String id)throws Exception{
boolean flag=false;
String sql="update orders set isdeal=\"已处理...\" where id=?";// 增加一个触发器,出发车辆信息中的working为闲置
this.pst=this.conn.prepareStatement(sql);
pst.setString(1, id);
if(this.pst.executeUpdate()>=1){
flag=true;
}
return flag;
}
public boolean setFail(String id)throws Exception{
boolean flag=false;
SimpleDateFormat myFmt2=new SimpleDateFormat("yyyyMMdd");
String s=myFmt2.format(new Date()).toString();
String sql="update orders set checked=\"n\" , thelasttime="+s+" where id="+id;
this.pst=this.conn.prepareStatement(sql);
if(this.pst.executeUpdate()>=1){
flag=true;
}
return flag;
}
public boolean setLocation(String id,String f1,String f2)throws Exception{
boolean flag=false;
String ff=f1+"_"+f2;
System.out.print(ff);
String sql="update orders set location=? where carid=?";
this.pst=this.conn.prepareStatement(sql);
pst.setString(1,ff);
pst.setString(2, id);
if(this.pst.executeUpdate()>=1){
flag=true;
}
return flag;
}
public String getLocation(String s)throws Exception{
String ss=null;
String sql="SELECT location FROM orders WHERE id=?";
this.pst=this.conn.prepareStatement(sql);
pst.setString(1,s);
ResultSet rs=this