⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 administrator.java

📁 基于java的医院门诊管理系统
💻 JAVA
字号:
package crqs.dboperation;

import java.io.Serializable;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import crqs.exceptions.RecordsNotExistException;
import crqs.infobeans.DoctorInfo;
import crqs.infobeans.PatientInfo;
import crqs.infobeans.SectionInfo;
import crqs.util.Page;

public class Administrator extends DBOperation implements Serializable {

	public Administrator() {
	}

	public Administrator(String un, String pw) {
		super(un, pw);
	}

	// true:登陆成功
	// false:密码错误
	// SQLException:数据库异常
	// RecordsNotExistException:记录不存在
	public boolean login() throws SQLException, RecordsNotExistException {
		String sql = "Select * from Administrator where UserName='"
				+ this.userName + "'";
		try {
			executeQuery(sql);
			if (result.next()) {
				if (result.getString("Passwd").equals(this.password))
					return true;
				else
					return false;
			} else
				throw new RecordsNotExistException();
		} finally {
			closeConnection();
		}
	}

	// true:密码修改成功
	// false:旧密码不正确
	// SQLException:数据库异常
	public boolean setPassword(String old, String newPw) throws SQLException {
		String sql = "Select Passwd from Administrator where UserName='"
				+ this.userName + "'";
		try {
			executeQuery(sql);
			result.next();
			if (!result.getString(1).equals(old.trim()))
				return false;
			else {
				sql = "Update Administrator set Passwd='" + newPw
						+ "' where UserName='" + this.userName + "'";
				executeUpdate(sql);
				return true;
			}
		} finally {
			closeConnection();
		}
	}

	// true:医生添加成功
	// false:医生ID已存在
	// SQLException:数据库异常
	public boolean addDoctor(String userName, String passwd, String mailbox,
			String phoneNO, String name, String resume, String gender,
			String age, String title, String secID) throws SQLException {
		String sql = "Select * from Doctor where UserName='" + userName + "'";
		try {
			executeQuery(sql);
			if (result.next())
				return false;
			else {
				sql = "Insert into Doctor"
						+ "(UserName,Passwd,DName,Age,Gender,"
						+ "Title,SectionNO,PhoneNO,Mailbox,Resume) "
						+ "values('" + userName + "','" + passwd + "','" + name
						+ "'," + age + ",'" + gender + "'," + title + ","
						+ secID + ",'" + phoneNO + "','" + mailbox + "','"
						+ resume + "')";
				executeUpdate(sql);
				return true;
			}
		} finally {
			closeConnection();
		}
	}

	// SQLException:数据库异常
	public void deleteDoctor(String docID) throws SQLException {
		String sql = "Delete from Doctor where UserName='" + docID + "'";
		try {
			executeUpdate(sql);
		} finally {
			closeConnection();
		}
	}

	// PatientInfo:患者信息
	// SQLException:数据库异常
	// RecordsNotExistException:记录不存在
	public PatientInfo searchPatient(String patID) throws SQLException,
			RecordsNotExistException {
		String sql = "Select PName, Gender, Age, IDCard from Patient "
				+ "where UserName='" + patID + "'";
		try {
			executeQuery(sql);
			if (result.next()) {
				PatientInfo pi = new PatientInfo();
				pi.setUserName(patID);
				pi.setRealName(result.getString("PName"));
				pi.setGender(result.getString("Gender").charAt(0));
				pi.setAge(result.getInt("Age"));
				pi.setIdentity(result.getString("IDCard"));
				return pi;
			} else
				throw new RecordsNotExistException();
		} finally {
			closeConnection();
		}
	}

	// SQLException:数据库异常
	public void deletePatient(String patID) throws SQLException {
		String sql = "Delete from Patient where UserName='" + patID + "'";
		try {
			executeUpdate(sql);
		} finally {
			closeConnection();
		}
	}

	// SQLException:数据库异常
	public void addSection(String secName, String description,
			String abbreviation) throws SQLException {
		Connection conn = null;
		CallableStatement stmt = null;
		try {
			conn = DBConnection.getConnection();
			stmt = conn.prepareCall("{call addSection(?,?,?)}");
			stmt.setString(1, secName);
			stmt.setString(2, abbreviation);
			stmt.setString(3, description);
			stmt.execute();
		} finally {
			conn.close();
			stmt.close();
		}
	}

	// SQLException:数据库异常
	public void deleteSection(int secID) throws SQLException {
		String sql = "delete from Section where SectionNO=" + secID;
		try {
			executeUpdate(sql);
		} finally {
			closeConnection();
		}
	}

	// DoctorInfo:医生信息
	// SQLException:数据库异常
	// RecordsNotExistException:记录不存在
	public DoctorInfo searchDoctor(String docID) throws SQLException,
			RecordsNotExistException {
		String sql = "Select DName, Gender, Age, SName, TName "
				+ "from Doctor, Section, Title "
				+ "where Doctor.SectionNO=Section.SectionNO "
				+ "and Doctor.Title=Title.TitleNO " + "and UserName='" + docID
				+ "'";
		try {
			executeQuery(sql);
			if (result.next()) {
				DoctorInfo di = new DoctorInfo();
				di.setUserName(docID);
				di.setRealName(result.getString("DName"));
				di.setGender(result.getString("Gender").charAt(0));
				di.setAge(result.getInt("Age"));
				di.setSection(result.getString("SName"));
				di.setTitle(result.getString("TName"));
				return di;
			} else
				throw new RecordsNotExistException();
		} finally {
			closeConnection();
		}
	}

	// Page:医生信息的集合
	// SQLException:数据库异常
	// RecordsNotExistException:记录不存在
	public Page searchDoctor(String name, int secID, String gender, int title)
			throws SQLException, RecordsNotExistException {
		String sql = "Select UserName, DName, Gender, Age, SName, TName from Doctor, Section, Title "
				+ "where Doctor.SectionNO=Section.SectionNO and Doctor.Title=TitleNO"
				+ (name.equals("all") ? " " : (" and DName='" + name + "'"))
				+ (secID == 0 ? " " : (" and Doctor.SectionNO=" + secID))
				+ " and Gender='"
				+ gender
				+ "'"
				+ (title == 0 ? " " : (" and Doctor.Title=" + title));
		try {
			executeQuery(sql);
			if (result.next()) {
				DoctorInfo di = null;
				ArrayList al = new ArrayList();
				do {
					di = new DoctorInfo();
					di.setUserName(result.getString("UserName"));
					di.setRealName(result.getString("DName"));
					di.setGender(result.getString("Gender").charAt(0));
					di.setAge(result.getInt("Age"));
					di.setSection(result.getString("SName"));
					di.setTitle(result.getString("TName"));
					al.add(di);
				} while (result.next());
				return new Page(al);
			} else
				throw new RecordsNotExistException();
		} finally {
			closeConnection();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -