📄 operator.java
字号:
package operator;
import conn.DataBaseConnection;
import java.sql.*;
import java.util.*;
import java.io.*;
public class Operator implements Serializable
{
private Connection con=null;
//构造函数
public Operator()
{
this.con=DataBaseConnection.getConnection();
}
//办公人员
public Officer queryAdmin(String username,String password)
{
PreparedStatement pstmt=null;
ResultSet rst=null;
Officer officer=new Officer();
try{
pstmt = con.prepareStatement(
"select * from admin where adminId='" + username + "'");
rst = pstmt.executeQuery();
if (rst.next()) {
String pwd=rst.getString("adminPassword").trim();
if(pwd.equals(password))
{
officer.setStudentPower(rst.getString("studentPower"));//登录成功
officer.setCoursePower(rst.getString("coursePower"));
officer.setGradePower(rst.getString("gradePower"));
officer.setClassPower(rst.getString("classPower"));
officer.setPunRewPower(rst.getString("punRewPower"));
officer.setComposePower(rst.getString("composePower"));
officer.setRankExamPower(rst.getString("rankExamPower"));
officer.setGraduatePower(rst.getString("graduatePower"));
officer.setAssessPower(rst.getString("assessPower"));
officer.setSuZhiPower(rst.getString("suZhiPower"));
officer.setReturnValue(1);
}
else
{
officer.setReturnValue(0);//登录失败
}
}
else
{
officer.setReturnValue(2);//用户不存在
}
}catch(SQLException ex)
{
System.err.println(ex.getMessage());
ex.printStackTrace();
}
finally
{
try{
if(rst!=null){
rst.close();
}
if(rst!=null){
pstmt.close();
}
if(rst!=null){
con.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
return officer;
}
//班级干部
public Monitor queryMonitor(String username,String password)
{
PreparedStatement pstmt=null;
ResultSet rst=null;
Monitor monitor=new Monitor();
try{
pstmt = con.prepareStatement(
"select monitorAdminPassword,monitorName,className from monitorAdmin where monitorAdminId='" + username + "'");
rst = pstmt.executeQuery();
if (rst.next()) {
String pwd=rst.getString("monitorAdminPassword").trim();
if(pwd.equals(password))
{
monitor.setMonitorName1(rst.getString("monitorName"));//登录成功
monitor.setClassName1(rst.getString("className"));
monitor.setReturnValue(1);
}
else
{
monitor.setReturnValue(0);//登录失败
}
}
else
{
monitor.setReturnValue(2);//用户不存在
}
}catch(SQLException ex)
{
System.err.println(ex.getMessage());
ex.printStackTrace();
}
finally
{
try{
if(rst!=null){
rst.close();
}
if(rst!=null){
pstmt.close();
}
if(rst!=null){
con.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
return monitor;
}
//学生用户
public int queryStudent(String username,String password)
{
PreparedStatement pstmt=null;
ResultSet rst=null;
int returnValue=0;
try{
pstmt = con.prepareStatement(
"select password from xuesheng where studentId='" + username + "' and flag='"+1+"'");
rst = pstmt.executeQuery();
if (rst.next()) {
String pwd=rst.getString("password").trim();
if(pwd.equals(password))
{
returnValue=1;//登录成功
}
else
{
returnValue=0;//登录失败
}
}
else
{
returnValue= 2;//用户不存在
}
}catch(SQLException ex)
{
System.err.println(ex.getMessage());
}
finally
{
try{
if(rst!=null){
rst.close();
}
if(rst!=null){
pstmt.close();
}
if(rst!=null){
con.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
return returnValue;
}
//系统管理员
public int querySystemAdmin(String username,String password)
{
PreparedStatement pstmt=null;
ResultSet rst=null;
int returnValue=0;
try{
pstmt = con.prepareStatement(
"select systemAdminPassword from systemAdmin where systemAdminId='" + username + "'");
rst = pstmt.executeQuery();
if (rst.next()) {
String pwd=rst.getString("systemAdminPassword").trim();
if(pwd.equals(password))
{
returnValue=1;//登录成功
}
else
{
returnValue=0;//登录失败
}
}
else
{
returnValue= 2;//用户不存在
}
}catch(SQLException ex)
{
System.err.println(ex.getMessage());
ex.printStackTrace();
}
finally
{
try{
if(rst!=null){
rst.close();
}
if(rst!=null){
pstmt.close();
}
if(rst!=null){
con.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
return returnValue;
}
//是否存在办公人员编号
public boolean existOfficer(Officer officer) {
try {
String adminId = officer.getAdminId();
PreparedStatement pstmt = con.prepareStatement(
"select adminId from admin where adminId='" +
adminId + "'");
ResultSet rst = pstmt.executeQuery();
if (rst.next()) {
return true;
}
} catch (Exception ex) {
return false;
}
return false;
}
//添加办公人员
public String addOfficer(Officer officer)
{
PreparedStatement pstmt=null;
String str="";
try
{
if (existOfficer(officer)) {
return "exist"; //存在此学生
}
pstmt=con.prepareStatement("insert into admin values(?,?,?,?,?,?,?,?,?,?,?,?,?)");
pstmt.setString(1,officer.getAdminId());
pstmt.setString(2,officer.getAdminName());
pstmt.setString(3,officer.getAdminPassword().trim());
pstmt.setString(4,officer.getStudentPower());
pstmt.setString(5,officer.getCoursePower());
pstmt.setString(6,officer.getGradePower());
pstmt.setString(7,officer.getClassPower());
pstmt.setString(8,officer.getPunRewPower());
pstmt.setString(9,officer.getComposePower());
pstmt.setString(10,officer.getRankExamPower());
pstmt.setString(11,officer.getGraduatePower());
pstmt.setString(12,officer.getAssessPower());
pstmt.setString(13,officer.getSuZhiPower());
pstmt.execute();
str="sucess";
}catch(SQLException ex)
{
System.err.println(ex.getMessage());
str="failer";
}
finally
{
try{
if(pstmt!=null){
pstmt.close();
}
if(con!=null){
con.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
return str;
}
//
//更新办公人员
public String updateOfficer(Officer officer)
{
PreparedStatement pstmt=null;
String str="";
try
{
pstmt=con.prepareStatement("update admin set studentPower=?,coursePower=?,gradePower=?,classPower=?,punRewPower=?,composePower=?,rankExamPower=?,graduatePower=?,assessPower=?,suZhiPower=? where adminId=?");
pstmt.setString(1,officer.getStudentPower());
pstmt.setString(2,officer.getCoursePower());
pstmt.setString(3,officer.getGradePower());
pstmt.setString(4,officer.getClassPower());
pstmt.setString(5,officer.getPunRewPower());
pstmt.setString(6,officer.getComposePower());
pstmt.setString(7,officer.getRankExamPower());
pstmt.setString(8,officer.getGraduatePower());
pstmt.setString(9,officer.getAssessPower());
pstmt.setString(10,officer.getSuZhiPower());
pstmt.setString(11,officer.getAdminId());
pstmt.execute();
str="sucess";
}catch(SQLException ex)
{
System.err.println(ex.getMessage());
str="failer";
}
finally
{
try{
if(pstmt!=null){
pstmt.close();
}
if(con!=null){
con.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
return str;
}
//
public String deleteOfficer(String adminId)
{
PreparedStatement pstmt=null;
String str="";
try
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -