package com.ibm.etp.bussiness.persistance.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import com.ibm.etp.bussiness.classes.Client;
import com.ibm.etp.bussiness.classes.Client_Type;
import com.ibm.etp.bussiness.dataBaseConn.DataConn1;
import com.ibm.etp.bussiness.persistance.Admin_Function_Inter;
public class Admin_Function implements Admin_Function_Inter {
static Admin_Function instance = null;
/**
* 获取单一实例化对象
*
* @return
*/
public static Admin_Function getInstance() {
if (instance == null) {
instance = new Admin_Function();
}
return instance;
}
/**
* 通过客户id对客户的基本信息进行查询,主要包括客户的姓名、年龄、公司名和更新时间
*
* @param client_id
* ,客户id
*/
public void basic_Search(Integer client_id) {
DataConn1 dc = DataConn1.getDatabase();
Connection cc = dc.getConnection();
String sql = "select client_mobile,client_company_name,"
+ "client_age,client_name, client_id "
+ "from client where client_id=" + client_id;
PreparedStatement ps = dc.ChuLi_Table(sql);
try {
ResultSet rs = ps.executeQuery();
while (rs.next()) {
System.out.println("客户id是:" + rs.getInt("client_id")
+ "; 客户姓名是:" + rs.getString("client_name") + "; 公司名称:"
+ rs.getString("client_company_name") + "; 客户年龄:"
+ rs.getString("client_age") + "; 客户手机号:"
+ rs.getString("client_mobile"));
}
dc.dataClose(rs, ps, cc);
} catch (SQLException e) {
e.printStackTrace();
}
}
public Client xiangxi_Search(Integer client_id) {
DataConn1 dat = DataConn1.getDatabase();
String sql = "select * from client where client_id=" + client_id;
Connection con = dat.getConnection();
PreparedStatement stmt = dat.ChuLi_Table(sql);
Client client = new Client();
try {
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
client.setClient_id(rs.getInt("client_id"));
client.setClient_name(rs.getString("client_name"));
client.setClient_ower(rs.getString("client_ower"));
client.setClient_job(rs.getString("client_job"));
client.setCompany_name(rs.getString("client_company_name"));
client.setDept_name(rs.getString("client_dept_name"));
client.setEmail(rs.getString("client_email"));
client.setCellphone(rs.getLong("client_mobile"));
client.setTelphone(rs.getLong("client_tel"));
client.setClient_MSN(rs.getString("client_msn"));
client.setClient_address(rs.getString("client_address"));
client.setClient_faxes(rs.getInt("client_fax"));
client.setBirthday(rs.getString("client_birthday"));
client.setClient_age(rs.getInt("client_age"));
client.setClient_sex(rs.getString("client_sex"));
client.setCompany_net(rs.getString("client_company_mainpage"));
client.setClient_QQ(rs.getInt("client_qq"));
client.setClient_img(rs.getString("client_icon"));
client.setClient_date(rs.getString("client_date"));
}
dat.dataClose(rs, stmt, con);
} catch (SQLException e) {
e.printStackTrace();
}
return client;
}
public ArrayList<Client> searchAllClientInfor() {
ArrayList<Client> array = new ArrayList<Client>();
DataConn1 dc = DataConn1.getDatabase();
Connection cc = dc.getConnection();
String sql = "select client_mobile,client_company_name,"
+ "client_age,client_name, client_id " + "from client";
PreparedStatement ps = dc.ChuLi_Table(sql);
try {
ResultSet rs = ps.executeQuery();
while (rs.next()) {
/*
* System.out.println("客户id是:" + rs.getInt("client_id") +
* "; 客户姓名是:" + rs.getString("client_name") + "; 公司名称:" +
* rs.getString("client_company_name") + "; 客户年龄:" +
* rs.getString("client_age") + "; 客户手机号:" +
* rs.getString("client_mobile"));
*/
Client client = new Client();
client.setClient_id(rs.getInt("client_id"));
client.setClient_name(rs.getString("client_name"));
client.setCompany_name(rs.getString("client_company_name"));
client.setClient_age(rs.getInt("client_age"));
client.setCellphone(rs.getLong("client_mobile"));
array.add(client);
}
dc.dataClose(rs, ps, cc);
} catch (SQLException e) {
e.printStackTrace();
}
return array;
}
public ArrayList<Client> chaxunByType(int type_id) {
ArrayList<Client> array = new ArrayList<Client>();
DataConn1 dc = DataConn1.getDatabase();
Connection cc = dc.getConnection();
String sql = "select * from client,type where client.client_id=type.client_id and type.type_id="
+ type_id;
PreparedStatement ps = dc.ChuLi_Table(sql);
try {
ResultSet rs = ps.executeQuery();
while (rs.next()) {
Client client = new Client();
client.setClient_id(rs.getInt("client_id"));
client.setClient_name(rs.getString("client_name"));
client.setClient_ower(rs.getString("client_ower"));
client.setClient_job(rs.getString("client_job"));
client.setCompany_name(rs.getString("client_company_name"));
client.setDept_name(rs.getString("client_dept_name"));
client.setEmail(rs.getString("client_email"));
client.setCellphone(rs.getLong("client_mobile"));
client.setTelphone(rs.getLong("client_tel"));
client.setClient_MSN(rs.getString("client_msn"));
client.setClient_address(rs.getString("client_address"));
client.setClient_faxes(rs.getInt("client_fax"));
client.setBirthday(rs.getString("client_birthday"));
client.setClient_age(rs.getInt("client_age"));
client.setClient_sex(rs.getString("client_sex"));
client.setCompany_net(rs.getString("client_company_mainpage"));
client.setClient_QQ(rs.getInt("client_qq"));
client.setClient_img(rs.getString("client_icon"));
client.setClient_date(rs.getString("client_date"));
array.add(client);
}
dc.dataClose(rs, ps, cc);
} catch (SQLException e) {
e.printStackTrace();
}
return array;
}
/**
* param client_id为客户编号,oldClient_type为客户移动前的类别编号,newClient_type为客户移动后的类别编号
* return Boolean类型
* 方法功能:先从类别表(type)中查询所有数据,然后用client_id和newClient_type与表中数据进行比较,目的在于查看
* 表中是否存在要移动的数据,如果有,就禁止移动,如果没有,则可移动。移动过后,必须要把移动前的记录删除,然后
* 再在表中新建一条记录,整个过程就实现了移动的功能。
*/
public boolean moveClientInfor(Integer client_id, Integer oldClient_type,
Integer newClient_type) {
boolean boo = true;
DataConn1 my = DataConn1.getDatabase();
String sql = "insert into type values(" + client_id + ","
+ newClient_type + ")";
String sql1 = "select * from type";
String sql2 = "delete from type where client_id=" + client_id
+ "and type_id=" + oldClient_type;
Connection con = my.getConnection();
PreparedStatement rs = my.ChuLi_Table(sql);
PreparedStatement ps = my.ChuLi_Table(sql1);
PreparedStatement ps1 = my.ChuLi_Table(sql2);
try {
ResultSet res = ps.executeQuery();
while (res.next()) {
if (res.getInt(1) == client_id
&& res.getInt(2) == newClient_type) {
boo = false;
break;
}
}
if (boo) {
ps1.executeUpdate();
rs.executeUpdate();
}
my.dataClose(res, rs, con);
my.dataClose(res, ps1, con);
my.dataClose(res, ps, con);
} catch (SQLException e) {
e.printStackTrace();
}
return boo;
}
/**
* param client_id为客户编号,newClient_type为客户复制后的类别编号 return Boolean类型
* 方法功能:先从类别表(type)中查询所有数据,然后用cli