package cn.sxt.fdc.dao.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import cn.sxt.fdc.dao.CustomerDao;
import cn.sxt.fdc.entity.Customer_Care;
import cn.sxt.fdc.entity.Customer_Condition;
import cn.sxt.fdc.entity.Customer_Info;
import cn.sxt.fdc.entity.Customer_Source;
import cn.sxt.fdc.entity.Customer_Type;
import cn.sxt.fdc.entity.User_Info;
import cn.sxt.fdc.util.BjsxtJdbc;
import cn.sxt.fdc.util.JdbcUtil;
import cn.sxt.fdc.util.SxtPageUtil;
public class CustomerDaoImpl implements CustomerDao {
Connection conn=null;
PreparedStatement pst=null;
ResultSet re=null;
//查询客户信息
@Override
public List selectCustomerDao(String selectType,String input,SxtPageUtil sxtPageUtil) {
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
List cusList=new ArrayList();
try {
conn=BjsxtJdbc.getConnection();
StringBuilder sql=new StringBuilder("select i.*,c.condition_name,s.source_name,t.type_name,u.user_name from customer_info i "
+"join customer_condition c on i.condition_id=c.condition_id "
+"join customer_source s on i.source_id=s.source_id "
+"join customer_type t on i.type_id=t.type_id "
+"left join user_info u on i.user_id=u.user_id ");
if((selectType!=null&&!"".equals(selectType))&&(input!=null&&!"".equals(input))){
if(selectType.equals("customer_name")){
sql.append("where customer_name = ? limit "+ sxtPageUtil.getStart() +","+ sxtPageUtil.getSize() );
pstmt=BjsxtJdbc.getPreparedStatement(conn, sql);
pstmt.setString(1, input);
}else if(selectType.equals("condition_name")){
sql.append("where condition_name = ? limit "+ sxtPageUtil.getStart() +","+ sxtPageUtil.getSize() );
pstmt=BjsxtJdbc.getPreparedStatement(conn, sql);
pstmt.setString(1,input);
}else if(selectType.equals("source_name")){
sql.append("where source_name =? limit "+ sxtPageUtil.getStart() +","+ sxtPageUtil.getSize());
pstmt=BjsxtJdbc.getPreparedStatement(conn, sql);
pstmt.setString(1, input);
}else if(selectType.equals("type_name")){
sql.append("where type_name =? limit "+ sxtPageUtil.getStart() +","+ sxtPageUtil.getSize());
pstmt=BjsxtJdbc.getPreparedStatement(conn, sql);
pstmt.setString(1, input);
}else if(selectType.equals("user_name")){
sql.append("where user_name =? limit "+ sxtPageUtil.getStart() +","+ sxtPageUtil.getSize());
pstmt=BjsxtJdbc.getPreparedStatement(conn, sql);
pstmt.setString(1, input);
}else{
sql.append("where customer_company =? limit "+ sxtPageUtil.getStart() +","+ sxtPageUtil.getSize());
pstmt=BjsxtJdbc.getPreparedStatement(conn, sql);
pstmt.setString(1, input);
}
// pstmt=BjsxtJdbc.getPreparedStatement(conn, sql);
// pstmt.setString(1, "%"+input+"%");
}else if((selectType==null||"".equals(selectType))&&(input==null||"".equals(input))){
sql.append(" limit "+ sxtPageUtil.getStart() +","+ sxtPageUtil.getSize());
pstmt=BjsxtJdbc.getPreparedStatement(conn, sql);
}else{
return cusList;
}
rs=pstmt.executeQuery();
while(rs.next()){
int id = rs.getInt("customer_id");
// int cid = rs.getInt("condition_id");
// int sid = rs.getInt("source_id");
// int uid = rs.getInt("user_id");
// int tid=rs.getInt("type_id");
String name = rs.getString("customer_name");
Date date = rs.getDate("customer_addtime");
String company = rs.getString("customer_company");
String cname = rs.getString("condition_name");
String sname = rs.getString("source_name");
String tname = rs.getString("type_name");
String cremark = rs.getString("customer_remark");
String sex = rs.getString("customer_sex");
String mobile = rs.getString("customer_mobile");
String qq = rs.getString("customer_qq");
String job = rs.getString("customer_job");
String email = rs.getString("customer_email");
String uname=rs.getString("user_name");
List list=new ArrayList();
list.add(id);
list.add(name);
list.add(date);
list.add(company);
list.add(cname);
list.add(sname);
list.add(tname);
list.add(cremark);
list.add(sex);
list.add(mobile);
list.add(qq);
list.add(job);
list.add(email);
list.add(uname);
cusList.add(list);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return cusList;
}
//查询客户类型
@Override
public void selectCustomerType(SxtPageUtil<Customer_Type> sxtPageUtil) {
List<Customer_Type> customerTypeList = new ArrayList<>();
try {
//创建连接
conn = JdbcUtil.getConnection();
StringBuilder sql = new StringBuilder("select * from customer_type where 1=1 ");
sql.append(" limit "+ sxtPageUtil.getStart() +","+ sxtPageUtil.getSize());
System.out.println("CustomerDaoImpl.selectCustomerType()"+sql);
pst =conn.prepareStatement(sql.toString());
//发送sql获取结果集
re= pst.executeQuery();
//处理结果
while(re.next()){
int id = re.getInt("type_id");
String uname = re.getString("type_name");
String used = re.getString("is_used");
//创建对象
Customer_Type customerType = new Customer_Type(id, uname, used);
//把对象存放到集合中
customerTypeList.add(customerType);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
JdbcUtil.closeAll(re, pst, conn);
}
sxtPageUtil.setList(customerTypeList);
}
//模糊查询
@Override
public void likeSelectCustomerType(String name,SxtPageUtil<Customer_Type> sxtPageUtil) {
List<Customer_Type> customerTypeList = new ArrayList<>();
try {
//创建连接
conn = JdbcUtil.getConnection();
String sql="select * from customer_type ";
sql+="where type_name like '%"+name+"%' limit "+ sxtPageUtil.getStart() +","+sxtPageUtil.getSize();
System.out.println("CustomerDaoImpl.selectCustomerType()"+sql);
pst =conn.prepareStatement(sql.toString());
//发送sql获取结果集
re= pst.executeQuery();
//处理结果
while(re.next()){
int id = re.getInt("type_id");
String uname = re.getString("type_name");
String used = re.getString("is_used");
//创建对象
Customer_Type customerType = new Customer_Type(id, uname, used);
//把对象存放到集合中
customerTypeList.add(customerType);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
JdbcUtil.closeAll(re, pst, conn);
}
sxtPageUtil.setList(customerTypeList);
}
//添加客户类型
@Override
public int addCustomer_Type(Customer_Type c) {
int n=0;
try {
conn=JdbcUtil.getConnection();
String sql="insert into customer_type values(?,?)";
pst=conn.prepareStatement(sql.toString());
Object []objs={c.getType_name(),c.getIs_used()};
for (int i = 0; i < objs.length; i++) {
pst.setObject(i+1, objs[i]);
}
n=pst.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
JdbcUtil.closeAll(re, pst, conn);
}
return n;
}
//查询客户状态信息
@Override
public List<Customer_Condition> selectConditionDao() {
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
List<Customer_Condition> clist=new ArrayList<Customer_Condition>();
try {
conn=BjsxtJdbc.getConnection();
String sql="select * from customer_condition";
pstmt=BjsxtJdbc.getPreparedStateme
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
房地产管理系统 (385个子文件)
CustomerDaoImpl.class 27KB
CustomerServlet.class 22KB
EmployeeDaoImpl.class 14KB
EmployeeServlet.class 10KB
User_Info.class 8KB
AdminServlet.class 7KB
Customer_Info.class 7KB
CustomerServiceImpl.class 7KB
SxtPageUtil.class 7KB
AdminDaoimpl.class 6KB
BjsxtJdbc.class 4KB
User_Infos.class 4KB
EmployeeServiceImpl.class 3KB
Customer_Linkreord.class 3KB
Customer_Care.class 3KB
Customer_Linkman.class 3KB
UserServlet.class 3KB
Email_Info.class 3KB
Notice_Info.class 3KB
JdbcUtil.class 3KB
CustomerService.class 3KB
CustomerDao.class 2KB
House_Info.class 2KB
House_Infos.class 2KB
Customer_Condition.class 2KB
Department_Info.class 2KB
User_Role.class 2KB
Customer_Source.class 2KB
Customer_Type.class 2KB
AdminServiceimpl.class 1KB
BjsxtUtil.class 1KB
House_Type.class 1KB
EmployeeService.class 1KB
CharsetFilter.class 1KB
EmployeeDao.class 1KB
AdminService.class 502B
AdminDao.class 488B
.classpath 1KB
org.eclipse.wst.common.component 499B
org.eclipse.wst.jsdt.ui.superType.container 49B
datepicker.css 5KB
datepicker.css 5KB
admin.css 2KB
WdatePicker.css 158B
wc.db 151KB
entries 3B
format 3B
login_08.gif 26KB
login_03.gif 21KB
main_09.gif 7KB
login_05.gif 7KB
login_07.gif 5KB
main_30.gif 3KB
main_40.gif 3KB
main_03.gif 3KB
main_32.gif 2KB
main_04.gif 2KB
main_29.gif 2KB
main_22.gif 2KB
main_47.gif 2KB
main_48.gif 2KB
login_06.gif 2KB
img.gif 2KB
main_20.gif 1KB
main_18.gif 1KB
main_12.gif 1KB
main_11.gif 1KB
main_14.gif 1KB
main_16.gif 1KB
datePicker.gif 1KB
tab_17.gif 924B
main_58.gif 804B
tab_20.gif 770B
tab_07.gif 752B
back.gif 749B
next.gif 745B
last.gif 741B
go.gif 736B
first.gif 736B
tab_18.gif 715B
main_07.gif 701B
tab_03.gif 699B
main_37.gif 661B
main_05.gif 640B
tb.gif 585B
main_31.gif 552B
tab_19.gif 420B
dl.gif 377B
tab_05.gif 375B
11.gif 341B
33.gif 337B
main_21.gif 317B
main_34.gif 292B
bg2.gif 273B
22.gif 215B
main_36.gif 203B
edt.gif 197B
bg.gif 160B
del.gif 145B
left.gif 124B
共 385 条
- 1
- 2
- 3
- 4
资源评论
m0_37123464
- 粉丝: 2
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功