package com.victor.dao;
import java.util.List;
import java.util.ArrayList;
import com.victor.tool.JDBConnection;
import java.sql.ResultSet;
import java.sql.*;
import com.victor.domain.ManagerActionForm;
public class ManagerDaoImpl
implements ManagerDao {
//查出所有的管理员
public List managerSelect(ManagerActionForm managerActionForm) {
JDBConnection connection = new JDBConnection();
List list = new ArrayList();
String sql = "select * from tb_manager where mark='" +
managerActionForm.getManagerMark() + "'";
try {
ResultSet rs = connection.executeQuery(sql);
while (rs.next()) {
ManagerActionForm manager = new ManagerActionForm();
manager.setManagerID(Integer.valueOf(rs.getString(1)));
manager.setManagerName(rs.getString(2));
manager.setManagerPassword(rs.getString(3));
manager.setManagerRealName(rs.getString(4));
manager.setManagerIssueDate(rs.getString(5));
manager.setManagerMark(rs.getString(6));
list.add(manager);
}
connection.close();
}
catch (SQLException ex) {
}
return list;
}
//核对普通管理员帐号和密码
public ManagerActionForm managerCheck(ManagerActionForm managerActionForm) {
ManagerActionForm manager = null;
JDBConnection connection = new JDBConnection();
String sql = "select * from tb_manager where Name='" +
managerActionForm.getManagerName() + "'";
try {
ResultSet rs = connection.executeQuery(sql);
while (rs.next()) {
manager = new ManagerActionForm();
manager.setManagerPassword(rs.getString(3));
}
}
catch (SQLException ex) {
}
connection.close();
return manager;
}
//普通管理员修改密码
public void managerUpdate(ManagerActionForm managerActionForm) {
JDBConnection connection = new JDBConnection();
String sql = "update tb_manager set Password='" +
managerActionForm.getManagerPassword() + "' where ID='" +
managerActionForm.getManagerID() + "'";
connection.executeUpdate(sql);
connection.close();
}
//普通管理员的单独查找之后,查找的数据在下一页显示
public List managerSelectOne(ManagerActionForm managerActionForm) {
List list = new ArrayList();
JDBConnection connection = new JDBConnection();
String sql = "select * from tb_manager where ID='" +
managerActionForm.getManagerID() + "'";
try {
ResultSet rs = connection.executeQuery(sql);
while (rs.next()) {
ManagerActionForm manager = new ManagerActionForm();
manager.setManagerID(Integer.valueOf(rs.getString(1)));
manager.setManagerPassword(rs.getString(3));
list.add(manager);
}
}
catch (SQLException ex) {
}
connection.close();
return list;
}
//核对总管理员帐号和密码
public ManagerActionForm adminCheck(ManagerActionForm managerActionForm) {
ManagerActionForm manager = null;
JDBConnection connection = new JDBConnection();
String sql = "select * from tb_manager where Name='" +
managerActionForm.getManagerName() + "' and mark='" +
managerActionForm.getManagerMark() + "'";
try {
ResultSet rs = connection.executeQuery(sql);
while (rs.next()) {
manager = new ManagerActionForm();
manager.setManagerPassword(rs.getString(3));
}
}
catch (SQLException ex) {
}
connection.close();
return manager;
}
//普通管理员注册
public void managerInsert(ManagerActionForm managerActionForm) {
JDBConnection connection = new JDBConnection();
String sql = "insert into tb_manager values('" +
managerActionForm.getManagerName() + "','" +
managerActionForm.getManagerPassword() +
"','" +
managerActionForm.getManagerRealName() + "',getDate(),'" +
managerActionForm.getManagerMark() + "')";
connection.executeUpdate(sql);
connection.close();
}
//普通管理员注册之前,核对是否有这个帐户名称
public String managerCheckName(ManagerActionForm managerActionForm) {
ManagerActionForm manager = null;
String name = "";
JDBConnection connection = new JDBConnection();
String sql = "select * from tb_manager where Name='" +
managerActionForm.getManagerName() + "'";
ResultSet rs = connection.executeQuery(sql);
try {
while (rs.next()) {
manager = new ManagerActionForm();
manager.setManagerName(rs.getString(2));
name = rs.getString(2);
}
}
catch (SQLException ex) {
}
connection.close();
return name;
}
//总管理员删除任何一个普通管理员
public void adminDelete(ManagerActionForm managerActionForm) {
JDBConnection connection = new JDBConnection();
String sql = "delete from tb_manager where ID='" +
managerActionForm.getManagerID() + "'";
connection.executeUpdate(sql);
connection.close();
}
//总管理员的单独查找,查找的内容在下一页中显示
public List adminSelectOne(ManagerActionForm managerActionForm) {
ManagerActionForm manager = null;
List list = new ArrayList();
JDBConnection connection = new JDBConnection();
String sql = "select * from tb_manager where ID='" +
managerActionForm.getManagerID() + "'";
ResultSet rs = connection.executeQuery(sql);
try {
while (rs.next()) {
manager = new ManagerActionForm();
manager.setManagerID(Integer.valueOf(rs.getString(1)));
manager.setManagerName(rs.getString(2));
manager.setManagerPassword(rs.getString(3));
manager.setManagerRealName(rs.getString(4));
manager.setManagerIssueDate(rs.getString(5));
manager.setManagerMark(rs.getString(6));
list.add(manager);
}
}
catch (SQLException ex) {
}
connection.close();
return list;
}
//总管理员修改普通管理员
public void adminUpdate(ManagerActionForm managerActionForm) {
JDBConnection connection = new JDBConnection();
String sql = "update tb_manager set Name='" +
managerActionForm.getManagerName() + "',Password='" +
managerActionForm.getManagerPassword() + "',RealName='" +
managerActionForm.getManagerRealName() + "',mark='" +
managerActionForm.getManagerMark() + "' where ID='" +
managerActionForm.getManagerID() + "'";
connection.executeUpdate(sql);
connection.close();
}
//修改总管理员的密码之前核对
public String adminCheckPassword(ManagerActionForm managerActionForm) {
JDBConnection connection = new JDBConnection();
String sql = "select * from tb_manager where password = '" +
managerActionForm.getManagerPassword() + "'";
String password = "";
ResultSet rs = connection.executeQuery(sql);
try {
while (rs.next()) {
password = rs.getString(3);
}
}
catch (SQLException ex) {
}
connection.close();
return password;
}
//修改总管理员的密码之前查出总管理员密码
public String adminSelectPassword() {
ManagerActionForm manager = null;
JDBConnection connection = new JDBConnection();
String sql = "select * from tb_manager where Name='mr' and mark='总管理员'";
String password = "";
ResultSet rs = connection.executeQuery(sql);
try {
while (rs.next()) {
manager = new ManagerActionForm();
manager.setManagerPassword(rs.getString(3));
password = rs.getString(3);
}
}
catch (SQLException ex) {
}
connection.close();
return password;
}
//修改管理员的密码
public void adminUpdatePassword(ManagerActionForm managerActionForm) {
JDBConnection connection = new JDBConnection();
String sql = "update tb_manager set Password='" +
managerActionForm.getManagerPassword() + "' where mark='总管理员'";
connecti