package com.neusoft.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import com.neusoft.domain.Cust;
import com.neusoft.domain.Device;
import com.neusoft.domain.Dr_record;
import com.neusoft.util.DbUtil;
public class DeviceDao {
public void insert(Device device) {
Connection conn = null;
PreparedStatement stmt = null;
PreparedStatement stmt2 = null;
try {
// 1连接数据库
conn = DbUtil.getConnection();
// 2开始事务
DbUtil.beginTransaction(conn);
// jdbc
String sql = "insert into dr_device values (repair_id_seq.nextval,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, device.getCustomer_id());
stmt.setString(2, device.getProduct_type());
stmt.setString(3, device.getMachine_brand());
stmt.setString(4, device.getMachine_version());
stmt.setString(5, device.getSerial_num());
stmt.setString(6, device.getNeed_parts());
stmt.setString(7, device.getProblem_look());
stmt.setString(8,device.getProblem_type());
stmt.setString(9, device.getOutlookcheck());
stmt.setString(10, device.getWork_code());
stmt.setString(11, device.getMaterial());
stmt.setString(12, device.getHdd());
stmt.setString(13, device.getRom());
stmt.setString(14, device.getPc_card());
stmt.setString(15, device.getAc_card());
stmt.setString(16, device.getCell());
stmt.setString(17, device.getHard_driver());
stmt.setString(18, device.getSoft_driver());
stmt.setString(19,device.getOthers());
stmt.setDate(20, device.getReport_time());
stmt.setInt(21, device.getPre_price());
stmt.setString(22, device.getReport_status());
stmt.executeUpdate();
// 3提交事务
DbUtil.commit(conn);
} catch (SQLException e) {
// 3回滚事务
try {
DbUtil.rollback(conn);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// 3回滚事务
try {
DbUtil.rollback(conn);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
DbUtil.close(null, null, conn);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void insertToDr_record(int repair_id) {
Connection conn = null;
PreparedStatement stmt = null;
PreparedStatement stmt2 = null;
try {
// 1连接数据库
conn = DbUtil.getConnection();
// 2开始事务
DbUtil.beginTransaction(conn);
// jdbc
String sql = "insert into dr_record values (?,?,?,?,?,?,?,?)";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, repair_id);
stmt.setString(2, null);
stmt.setString(3, null);
stmt.setString(4, null);
stmt.setDate(5, null);
stmt.setInt(6,0 );
stmt.setString(7, null);
stmt.setString(8, "0");
stmt.executeUpdate();
// 3提交事务
DbUtil.commit(conn);
} catch (SQLException e) {
// 3回滚事务
try {
DbUtil.rollback(conn);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// 3回滚事务
try {
DbUtil.rollback(conn);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
DbUtil.close(null, null, conn);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public void insertToDr_money(int repair_id) {
Connection conn = null;
PreparedStatement stmt = null;
PreparedStatement stmt2 = null;
try {
// 1连接数据库
conn = DbUtil.getConnection();
// 2开始事务
DbUtil.beginTransaction(conn);
// jdbc
String sql = "insert into dr_money values (?,?,?,?,?,?,?,?,?)";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, repair_id);
stmt.setInt(2, 0);
stmt.setInt(3, 0);
stmt.setString(4, null);
stmt.setString(5, null);
stmt.setDate(6,null );
stmt.setString(7, "n");
stmt.setString(8,"y");
stmt.setInt(9, 0);
stmt.executeUpdate();
// 3提交事务
DbUtil.commit(conn);
} catch (SQLException e) {
// 3回滚事务
try {
DbUtil.rollback(conn);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// 3回滚事务
try {
DbUtil.rollback(conn);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
DbUtil.close(null, null, conn);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public boolean findBySf(String sf) {
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
boolean f = false;
try {
// 1连接数据库
conn = DbUtil.getConnection();
// 2开始事务
DbUtil.beginTransaction(conn);
// jdbc
String sql = "select * from t_user where sf=?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, sf);
rs = stmt.executeQuery();
f = rs.next();
// 3提交事务
DbUtil.commit(conn);
} catch (SQLException e) {
// 3回滚事务
try {
DbUtil.rollback(conn);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// 3回滚事务
try {
DbUtil.rollback(conn);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
DbUtil.close(null, null, conn);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return f;
}
public ArrayList<Device> select(String repair_id, String customer_id) {
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
ArrayList<Device> list = new ArrayList<Device>();
try {
// 1连接数据库
conn = DbUtil.getConnection();
// 2开始事务
DbUtil.beginTransaction(conn);
// jdbc
String sql = "select * from dr_device where 1=1 ";
if (repair_id != null && !"".equals(repair_id)) {
sql += " AND repair_id like '%" + repair_id + "%'";
}
if (customer_id != null && !"".equals(customer_id)) {
sql += " AND customer_id = '" + customer_id + "'";
}
sql += " order by repair_id";
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
while (rs.next()) {
Device device = new Device();
device.setRepair_id(rs.getInt(1));
device.setCustomer_id(rs.getInt(2));
device.setProduct_type(rs.getString(3));
device.setMachine_brand(rs.getString(4));
device.setMachine_version(rs.getString(5));
device.setSerial_num(rs.getString(6));
device.setNeed_parts(rs.getString(7));
device.setProblem_look(rs.getString(8));
device.setProblem_type(rs.getString(9));
device.setOutlookcheck(rs.getString(10));
device.setWork_code(rs.getString(11));
device.setMaterial(rs.getString(12));
device.setHdd(rs.getString(13));
device.setRom(rs.getString(14))