package com.lzw.dao;
import internalFrame.guanli.Item;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import model.TbGysinfo;
import model.TbKhinfo;
import model.TbKucun;
import model.TbRkthDetail;
import model.TbRkthMain;
import model.TbRukuDetail;
import model.TbRukuMain;
import model.TbSellDetail;
import model.TbSellMain;
import model.TbSpinfo;
import model.TbUserlist;
import model.TbXsthDetail;
import model.TbXsthMain;
public class Dao {
protected static String dbClassName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
protected static String dbUrl = "jdbc:microsoft:sqlserver://localhost:1433;"
+ "DatabaseName=db_JXC;SelectMethod=Cursor";
protected static String dbUser = "sa";
protected static String dbPwd = "";
protected static String second = null;
public static Connection conn = null;
static {
try {
if (conn == null) {
Class.forName(dbClassName).newInstance();
conn = DriverManager.getConnection(dbUrl, dbUser, dbPwd);
}
} catch (Exception ee) {
ee.printStackTrace();
}
}
private Dao() {
}
// 读取所有客户信息
public static List getKhInfos() {
List list = findForList("select id,khname from tb_khinfo");
return list;
}
// 读取所有供应商信息
public static List getGysInfos() {
List list = findForList("select id,name from tb_gysinfo");
return list;
}
// 读取客户信息
public static TbKhinfo getKhInfo(Item item) {
String where = "khname='" + item.getName() + "'";
if (item.getId() != null)
where = "id='" + item.getId() + "'";
TbKhinfo info = new TbKhinfo();
ResultSet set = findForResultSet("select * from tb_khinfo where "
+ where);
try {
if (set.next()) {
info.setId(set.getString("id").trim());
info.setKhname(set.getString("khname").trim());
info.setJian(set.getString("jian").trim());
info.setAddress(set.getString("address").trim());
info.setBianma(set.getString("bianma").trim());
info.setFax(set.getString("fax").trim());
info.setHao(set.getString("hao").trim());
info.setLian(set.getString("lian").trim());
info.setLtel(set.getString("ltel").trim());
info.setMail(set.getString("mail").trim());
info.setTel(set.getString("tel").trim());
info.setXinhang(set.getString("xinhang").trim());
}
} catch (SQLException e) {
e.printStackTrace();
}
return info;
}
// 读取指定供应商信息
public static TbGysinfo getGysInfo(Item item) {
String where = "name='" + item.getName() + "'";
if (item.getId() != null)
where = "id='" + item.getId() + "'";
TbGysinfo info = new TbGysinfo();
ResultSet set = findForResultSet("select * from tb_gysinfo where "
+ where);
try {
if (set.next()) {
info.setId(set.getString("id").trim());
info.setAddress(set.getString("address").trim());
info.setBianma(set.getString("bianma").trim());
info.setFax(set.getString("fax").trim());
info.setJc(set.getString("jc").trim());
info.setLian(set.getString("lian").trim());
info.setLtel(set.getString("ltel").trim());
info.setMail(set.getString("mail").trim());
info.setName(set.getString("name").trim());
info.setTel(set.getString("tel").trim());
info.setYh(set.getString("yh").trim());
}
} catch (SQLException e) {
e.printStackTrace();
}
return info;
}
// 读取用户
public static TbUserlist getUser(String name, String password) {
TbUserlist user = new TbUserlist();
ResultSet rs = findForResultSet("select * from tb_userlist where username='"
+ name + "'");
try {
if (rs.next()) {
user.setUsername(name);
user.setPass(rs.getString("pass"));
if (user.getPass().equals(password)) {
user.setName(rs.getString("name"));
user.setQuan(rs.getString("quan"));
}
}
} catch (SQLException e) {
e.printStackTrace();
}
return user;
}
// 执行指定查询
public static ResultSet query(String QueryStr) {
ResultSet set = findForResultSet(QueryStr);
return set;
}
// 执行删除
public static int delete(String sql) {
return update(sql);
}
// 添加客户信息的方法
public static boolean addKeHu(TbKhinfo khinfo) {
if (khinfo == null)
return false;
return insert("insert tb_khinfo values('" + khinfo.getId() + "','"
+ khinfo.getKhname() + "','" + khinfo.getJian() + "','"
+ khinfo.getAddress() + "','" + khinfo.getBianma() + "','"
+ khinfo.getTel() + "','" + khinfo.getFax() + "','"
+ khinfo.getLian() + "','" + khinfo.getLtel() + "','"
+ khinfo.getMail() + "','" + khinfo.getXinhang() + "','"
+ khinfo.getHao() + "')");
}
// 修改客户信息的方法
public static int updateKeHu(TbKhinfo khinfo) {
return update("update tb_khinfo set jian='" + khinfo.getJian()
+ "',address='" + khinfo.getAddress() + "',bianma='"
+ khinfo.getBianma() + "',tel='" + khinfo.getTel() + "',fax='"
+ khinfo.getFax() + "',lian='" + khinfo.getLian() + "',ltel='"
+ khinfo.getLtel() + "',mail='" + khinfo.getMail()
+ "',xinhang='" + khinfo.getXinhang() + "',hao='"
+ khinfo.getHao() + "' where id='" + khinfo.getId() + "'");
}
// 修改库存的方法
public static int updateKucunDj(TbKucun kcInfo) {
return update("update tb_kucun set dj=" + kcInfo.getDj()
+ " where id='" + kcInfo.getId() + "'");
}
// 修改供应商信息的方法
public static int updateGys(TbGysinfo gysInfo) {
return update("update tb_gysinfo set jc='" + gysInfo.getJc()
+ "',address='" + gysInfo.getAddress() + "',bianma='"
+ gysInfo.getBianma() + "',tel='" + gysInfo.getTel()
+ "',fax='" + gysInfo.getFax() + "',lian='" + gysInfo.getLian()
+ "',ltel='" + gysInfo.getLtel() + "',mail='"
+ gysInfo.getMail() + "',yh='" + gysInfo.getYh()
+ "' where id='" + gysInfo.getId() + "'");
}
// 添加供应商信息的方法
public static boolean addGys(TbGysinfo gysInfo) {
if (gysInfo == null)
return false;
return insert("insert tb_gysinfo values('" + gysInfo.getId() + "','"
+ gysInfo.getName() + "','" + gysInfo.getJc() + "','"
+ gysInfo.getAddress() + "','" + gysInfo.getBianma() + "','"
+ gysInfo.getTel() + "','" + gysInfo.getFax() + "','"
+ gysInfo.getLian() + "','" + gysInfo.getLtel() + "','"
+ gysInfo.getMail() + "','" + gysInfo.getYh() + "')");
}
// 添加商品
public static boolean addSp(TbSpinfo spInfo) {
if (spInfo == null)
return false;
return insert("insert tb_spinfo values('" + spInfo.getId() + "','"
+ spInfo.getSpname() + "','" + spInfo.getJc() + "','"
+ spInfo.getCd() + "','" + spInfo.getDw() + "','"
+ spInfo.getGg() + "','" + spInfo.getBz() + "','"
+ spInfo.getPh() + "','" + spInfo.getPzwh() + "','"
+ spInfo.getMemo() + "','" + spInfo.getGysname() + "')");
}
// 更新商品
public static int updateSp(TbSpinfo spInfo) {
return update("update tb_spinfo set jc='" + spInfo.getJc() + "',cd='"
+ spInfo.getCd() + "',dw='" + spInfo.getDw() + "',gg='"
+ spInfo.getGg() + "',bz='" + spInfo.getBz() + "',ph='"
+ spInfo.getPh() + "',pzwh='" + spInfo.getPzwh() + "',memo='"
+ spInfo.getMemo() + "',gysname='" + spInfo.getGysname()
+ "' where id='" + spInfo.getId() + "'");
}
// 读取商品信息
public static TbSpinfo getSpInfo(Item item) {
String where = "spname='" + item.getName() + "'";
if (item.getId() != null)
where = "id='" + item.getId() + "'";
ResultSet rs = findForResultSet("select * from tb_spinfo where "
+ where);
TbSpinfo spInfo = new TbSpinfo();
try {
if (rs.next()) {
spInfo.setId(rs.getString("id").trim());
spInfo.setBz(rs.getString("bz").trim());
spInfo.setCd(rs.getString("cd").trim());
spInfo.setDw(rs.getString("