📄 allmethod.java
字号:
package com.nitpro.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.nitpro.form.DoctorMsgForm;
import com.nitpro.form.ItemChargeForm;
import com.nitpro.form.PatientForm;
import com.nitpro.form.See_doctor_messageForm;
import com.nitpro.form.TotalChargeForm;
public class AllMethod implements AllMethodDAO{
private Connection conn = null;
private ResultSet rs = null;
private Statement stmt = null;
private PreparedStatement ps = null;
public String bx(String s) {
try {
byte b[] = s.getBytes("iso-8859-1");
s = new String(b);
} catch (Exception e) {
}
return s;
}
public int login(String operator_id,String operator_pwd){
int rst = 0;
String sql = "select * from operator where operator_id='"+operator_id+"'";
conn = MySQLDAOFactory.getConnection();
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
if(rs.next()){
if(operator_pwd.equals(rs.getString("operator_pwd"))){
rst = 1;//正确
}else{
rst = 2;//密码错误
}
}else{
rst = 3;//用户不存在
}
} catch (SQLException e) {
e.printStackTrace();
} finally{
MySQLDAOFactory.closeResultSet(rs);
MySQLDAOFactory.closeStatement(stmt);
MySQLDAOFactory.closeConnection(conn);
}
return rst;
}
public int checkMedicine_id(String medicine_id){
int rst = 0;
String sql = "select * from price_management where medicine_id='"+medicine_id+"'";
conn = MySQLDAOFactory.getConnection();
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
if(rs.next()){
rst = 1;//存在,不可用
}else{
rst = 2;//可用
}
} catch (SQLException e) {
e.printStackTrace();
} finally{
MySQLDAOFactory.closeResultSet(rs);
MySQLDAOFactory.closeStatement(stmt);
MySQLDAOFactory.closeConnection(conn);
}
return rst;
}
public int itemChargeInput(ItemChargeForm iform){
int rst = 0;
String sql = "insert into price_management values(?,?,?,?,'N')";
conn = MySQLDAOFactory.getConnection();
try {
ps = conn.prepareStatement(sql);
ps.setString(1, bx(iform.getMedicine_id()));
ps.setString(2, bx(iform.getMedicine_name()));
ps.setFloat(3, iform.getMedicine_price());
ps.setString(4, bx(iform.getType_id()));
rst = ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally{
MySQLDAOFactory.closePreparedStatement(ps);
MySQLDAOFactory.closeConnection(conn);
}
return rst;
}
public List itemChargeSelect(String selectoption){
List list = new ArrayList();
String sql = "select * from price_management where isdelete='N' and medicine_id like '%"+selectoption+"%' or medicine_name like '%"+bx(selectoption)+"%' ";
conn = MySQLDAOFactory.getConnection();
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()){
ItemChargeForm iform = new ItemChargeForm();
iform.setMedicine_id(rs.getString("medicine_id"));
iform.setMedicine_name(rs.getString("medicine_name"));
iform.setMedicine_price(rs.getFloat("medicine_price"));
list.add(iform);
}
} catch (SQLException e) {
e.printStackTrace();
} finally{
MySQLDAOFactory.closeResultSet(rs);
MySQLDAOFactory.closeStatement(stmt);
MySQLDAOFactory.closeConnection(conn);
}
return list;
}
public List itemChargeSpecalSelect(String medicine_id){
List list = new ArrayList();
String sql = "select * from price_management where medicine_id='"+medicine_id+"'";
conn = MySQLDAOFactory.getConnection();
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()){
ItemChargeForm iform = new ItemChargeForm();
iform.setMedicine_id(rs.getString("medicine_id"));
iform.setMedicine_name(rs.getString("medicine_name"));
iform.setMedicine_price(rs.getFloat("medicine_price"));
list.add(iform);
}
} catch (SQLException e) {
e.printStackTrace();
} finally{
MySQLDAOFactory.closeResultSet(rs);
MySQLDAOFactory.closeStatement(stmt);
MySQLDAOFactory.closeConnection(conn);
}
return list;
}
public void itemChargeDelect(String medicine_id){
String sql = "update price_management set isdelete='Y' where medicine_id='"+medicine_id+"'";
conn = MySQLDAOFactory.getConnection();
try {
stmt = conn.createStatement();
stmt.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
} finally{
MySQLDAOFactory.closeStatement(stmt);
MySQLDAOFactory.closeConnection(conn);
}
}
public int itemChargeUpdate(String medicine_id,float medicine_price){
int rst = 0;
String sql = "update price_management set medicine_price='"+medicine_price+"' where medicine_id='"+medicine_id+"'";
conn = MySQLDAOFactory.getConnection();
try {
stmt = conn.createStatement();
stmt.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
} finally{
MySQLDAOFactory.closeStatement(stmt);
MySQLDAOFactory.closeConnection(conn);
}
return rst;
}
public List getMedicineType(){
List list = new ArrayList();
String sql = "select * from medicine_type_list";
conn = MySQLDAOFactory.getConnection();
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()){
ItemChargeForm iform = new ItemChargeForm();
iform.setType_id(rs.getString("type_id"));
iform.setType_name(rs.getString("type_name"));
list.add(iform);
}
} catch (SQLException e) {
e.printStackTrace();
} finally{
MySQLDAOFactory.closeResultSet(rs);
MySQLDAOFactory.closeStatement(stmt);
MySQLDAOFactory.closeConnection(conn);
}
return list;
}
public List getDoctorMsg(String selectoption){
List list = new ArrayList();
String sql = "select * from doctor_message where doctor_id like '%"+selectoption+"%' or doctor_name like '%"+bx(selectoption)+"%' and isdelete='N'";
conn = MySQLDAOFactory.getConnection();
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()){
DoctorMsgForm dmf = new DoctorMsgForm();
dmf.setDoctor_id(rs.getString("doctor_id"));
dmf.setDoctor_name(rs.getString("doctor_name"));
dmf.setDoctor_sex(rs.getString("doctor_sex"));
dmf.setDepartment(rs.getString("department"));
list.add(dmf);
}
} catch (SQLException e) {
e.printStackTrace();
} finally{
MySQLDAOFactory.closeResultSet(rs);
MySQLDAOFactory.closeStatement(stmt);
MySQLDAOFactory.closeConnection(conn);
}
return list;
}
public int doctorMsgInput(DoctorMsgForm dmf){
int rst = 0;
String sql = "insert into doctor_message values(?,?,?,?,'N')";
conn = MySQLDAOFactory.getConnection();
try {
ps = conn.prepareStatement(sql);
ps.setString(1, bx(dmf.getDoctor_id()));
ps.setString(2, bx(dmf.getDoctor_name()));
ps.setString(3, bx(dmf.getDoctor_sex()));
ps.setString(4, bx(dmf.getDepartment()));
rst = ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally{
MySQLDAOFactory.closePreparedStatement(ps);
MySQLDAOFactory.closeConnection(conn);
}
return rst;
}
public List getDoctorSpecalMsg(String doctor_id){
List list = new ArrayList();
String sql = "select * from doctor_message where doctor_id ='"+doctor_id+"'";
conn = MySQLDAOFactory.getConnection();
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()){
DoctorMsgForm dmf = new DoctorMsgForm();
dmf.setDoctor_id(rs.getString("doctor_id"));
dmf.setDoctor_name(rs.getString("doctor_name"));
dmf.setDoctor_sex(rs.getString("doctor_sex"));
dmf.setDepartment(rs.getString("department"));
list.add(dmf);
}
} catch (SQLException e) {
e.printStackTrace();
} finally{
MySQLDAOFactory.closeResultSet(rs);
MySQLDAOFactory.closeStatement(stmt);
MySQLDAOFactory.closeConnection(conn);
}
return list;
}
public void doctorMsgDelect(String doctor_id){
String sql = "update doctor_message set isdelete='Y' where doctor_id='"+doctor_id+"'";
conn = MySQLDAOFactory.getConnection();
try {
stmt = conn.createStatement();
stmt.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
} finally{
MySQLDAOFactory.closeStatement(stmt);
MySQLDAOFactory.closeConnection(conn);
}
}
public int checkDoctorID(String doctor_id){
int rst = 0;
String sql = "select * from doctor_message where doctor_id='"+doctor_id+"'";
conn = MySQLDAOFactory.getConnection();
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
if(rs.next()){
rst = 1;//不可用
}else{
rst = 2;//可用
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
MySQLDAOFactory.closeResultSet(rs);
MySQLDAOFactory.closeStatement(stmt);
MySQLDAOFactory.closeConnection(conn);
}
return rst;
}
public String getMedicine(String patient_id){
String target = null;
String sql = "select medicine_list from see_doctor_message where patient_id='"+patient_id+"'";
conn = MySQLDAOFactory.getConnection();
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
if(rs.next()){
target = rs.getString("medicine_list");
}else{
target=null;
}
} catch (SQLException e) {
e.printStackTrace();
} finally{
MySQLDAOFactory.closeResultSet(rs);
MySQLDAOFactory.closeStatement(stmt);
MySQLDAOFactory.closeConnection(conn);
}
return target;
}
public float getMedicinePrice(String medicine_id){
float price = 0;
String sql = "select medicine_price from price_management where medicine_id='"+medicine_id+"'";
conn = MySQLDAOFactory.getConnection();
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
if(rs.next()){
price = rs.getFloat("medicine_price");
}else{
price=0;
}
} catch (SQLException e) {
e.printStackTrace();
} finally{
MySQLDAOFactory.closeResultSet(rs);
MySQLDAOFactory.closeStatement(stmt);
MySQLDAOFactory.closeConnection(conn);
}
return price;
}
public int totalPriceInput(String patient_id,float medicine_charge,float registers_charge,float deal_charge,float examination_charge){
int rst = 0;
String sql = "insert into charge_management(patient_id,medicine_charge,registers_charge,deal_charge,examination_charge,isdelete) values(?,?,?,?,?,'N')";
conn = MySQLDAOFactory.getConnection();
try {
ps = conn.prepareStatement(sql);
ps.setString(1, patient_id);
ps.setFloat(2, medicine_charge);
ps.setFloat(3, registers_charge);
ps.setFloat(4, deal_charge);
ps.setFloat(5, examination_charge);
rst = ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally{
MySQLDAOFactory.closePreparedStatement(ps);
MySQLDAOFactory.closeConnection(conn);
}
return rst;
}
public List getTotalPriceList(String patient_id){
List list = new ArrayList();
String sql = "select * from charge_management where patient_id='"+patient_id+"' and isdelete='N'";
conn = MySQLDAOFactory.getConnection();
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()){
TotalChargeForm t = new TotalChargeForm();
t.setRegisters_charge(rs.getFloat("registers_charge"));
t.setExamination_charge(rs.getFloat("examination_charge"));
t.setDeal_charge(rs.getFloat("deal_charge"));
list.add(t);
}
} catch (SQLException e) {
e.printStackTrace();
} finally{
MySQLDAOFactory.closeResultSet(rs);
MySQLDAOFactory.closeStatement(stmt);
MySQLDAOFactory.closeConnection(conn);
}
return list;
}
public int addPatient(PatientForm form) {
// TODO Auto-generated method stub
int row = 0;
String sql = "insert into patient_message" +
"(patient_id,patient_name,patient_sex,patient_birth,patient_address,patient_jiguan,patient_state,pay_money,isdelete)" +
" value(?,?,?,?,?,?,?,?,'N');";
conn = MySQLDAOFactory.getConnection();
try {
ps = conn.prepareStatement(sql);
ps.setString(1, form.getPatient_id());
ps.setString(2, form.getPatient_name());
ps.setString(3, form.getPatient_sex());
ps.setString(4, form.getPatient_birth());
ps.setString(5, form.getPatient_address());
ps.setString(6, form.getPatient_jiguan());
ps.setString(7, form.getPatient_state());
ps.setInt(8,form.getPay_money());
row = ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
MySQLDAOFactory.closePreparedStatement(ps);
MySQLDAOFactory.closeConnection(conn);
}
return row;
}
public ArrayList listPatient(){
ArrayList patientList = new ArrayList();
String sql = "select * from patient_message where isdelete='N'";
conn = MySQLDAOFactory.getConnection();
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while(rs.next()){
PatientForm pf = new PatientForm();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -