package cc.zte.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import cc.zte.db.DBManager;
import cc.zte.entity.Appoint;
import java.util.Random;
import cc.zte.entity.Day;
import cc.zte.entity.Depart;
import cc.zte.entity.Doctor;
import cc.zte.entity.Hospital;
import cc.zte.entity.Orders;
import cc.zte.entity.Patient;
import cc.zte.entity.Reply;
import cc.zte.entity.Section;
import cc.zte.entity.Topic;
public class PatientDao extends DBManager{
//����û��Ƿ����
public Patient checkPatientLogin(String puname,String pupwd){
Patient user=null;
String sql = "select * from patient where uname='"+puname+"' and upwd='"+pupwd+"'";
this.setSql(sql);
try {
rs = this.executeQuery();
while(rs.next()){
user = new Patient();
// ���û��������Ը�ֵ
user.setPid(rs.getInt("pid"));
user.setName(rs.getString("name"));
user.setAddress(rs.getString("address"));
user.setAge(rs.getString("age"));
user.setPhone(rs.getString("phone"));
user.setSex(rs.getString("sex"));
user.setUname(rs.getString("uname"));
user.setUpwd(rs.getString("upwd"));
user.setPcount(rs.getString("pcount"));
user.setPstatus(rs.getString("pstatus"));
user.setPcard(rs.getString("pcard"));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return user;
}
//����û�ID�Ƿ��Ѿ�����
public boolean isunameExist(String name) {
boolean a = false;
String sql = "select * from patient where uname='"+name+"'";
this.setSql(sql);
try {
rs = this.executeQuery();
while(rs.next()){
a = true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return a;
}
//������֤�Ƿ�ע��
public boolean iscardExist(String pcard) {
boolean a = false;
String sql = "select * from patient where pcard='"+pcard+"'";
this.setSql(sql);
try {
rs = this.executeQuery();
while(rs.next()){
a = true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return a;
}
//ע�Ỽ�߷���
public int insertPatient(Patient patient){
String sql = "insert into Patient values(?,?,?,?,?,?,?,?,?,?)";
List<Object> param = new ArrayList<Object>();
param.add(patient.getName());
param.add(patient.getUname());
param.add(patient.getUpwd());
param.add(patient.getSex());
param.add(patient.getPcard());
param.add(patient.getAge());
param.add(patient.getAddress());
param.add(patient.getPhone());
param.add(patient.getPcount());
param.add(patient.getPstatus());
this.setSql(sql);
this.setParam(param);
int a = this.executeUpdate();
return a;
}
//�������
public boolean checkPwd(int pid ,String upwd){
String sql = "select upwd from patient where pid = '"+pid+"'";
this.setSql(sql);
try {
rs = this.executeQuery();
while(rs.next()){
String pwd=rs.getString("upwd");
if(pwd.equals(upwd))
{ return true;}
else{return false;}
}
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
//������
public int changePwd(int pid,String nupwd){
String sql = "update patient set upwd= '"+nupwd+"' where pid ='"+pid+"'";
this.setSql(sql);
return this.executeUpdate();
}
//�ĸ�����Ϣ
public Patient changeMsg(Patient user,String age,String phone,String address) throws SQLException
{
String sql = "update patient set address= '"+address+"' ,phone='"+phone+"',age='"+age+"' where pid ='"+user.getPid()+"'";
this.setSql(sql);
Patient userr=null;
if(this.executeUpdate()!=0){
userr = new Patient();
// ���û��������Ը�ֵ
userr.setPid(user.getPid());
userr.setUname(user.getUname());
userr.setUpwd(user.getUpwd());
userr.setAddress(address);
userr.setName(user.getName());
userr.setAge(age);
userr.setSex(user.getSex());
userr.setPhone(phone);
userr.setPcount(user.getPcount());
userr.setPstatus(user.getPstatus());
userr.setPcard(user.getPcard());
}
return userr;
}
//��ѯһ��������Ϣ
public Patient CheckPatientone(int pid ){
String sql = "select * from patient where pid='"+pid+"'";
this.setSql(sql);
rs = this.executeQuery();
Patient d = new Patient();
try {
while(rs.next()){
d.setAddress(rs.getString("address"));
d.setAge(rs.getString("age"));
d.setName(rs.getString("name"));
d.setPcard(rs.getString("pcard"));
d.setPcount(rs.getString("pcount"));
d.setPhone(rs.getString("phone"));
d.setPid(rs.getInt("pid"));
d.setPstatus(rs.getString("pstatus"));
d.setSex(rs.getString("sex"));
d.setUname(rs.getString("uname"));
d.setUpwd(rs.getString("upwd"));
this.setParam(param);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return d;
}
//���߲�ѯҽԺ
public List<Hospital> CheckHospital(String hname){
List<Hospital> list = new ArrayList<Hospital>();
String sql = "select * from hospital where hstatus='1' ";
System.out.println("hname00000000000000000");
System.out.println(hname);
if(hname!="")
{
sql+=" and hname like '"+hname+"%'";
}
this.setSql(sql);
rs = this.executeQuery();
Hospital d = new Hospital();
try {
while(rs.next()){
d = new Hospital();
d.setHaddress(rs.getString("haddress"));
d.setHid( rs.getInt("hid"));
d.setHintr(rs.getString("hintr")) ;
d.setHname(rs.getString("hname")) ;
d.setHphone(rs.getString("hphone")) ;
this.setParam(param);
list.add(d);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
//��ѯҽԺ��ҳ��Ϣ
public ResultSet GetHospital(int hid){
rs=null;
String sql = "select * from hospital where hid='"+hid+"'";
this.setSql(sql);
rs = this.executeQuery();
return rs;
}
//��ѯҽԺ�Ŀ�����Ϣ
public List<Depart> CheckDepart(int hid){
List<Depart> list = new ArrayList<Depart>();
String sql = "select * from department where hid='"+hid+"' order by kid";
this.setSql(sql);
rs = this.executeQuery();
Depart d = new Depart();
try {
while(rs.next()){
d = new Depart();
d.setHid( rs.getInt("hid"));
d.setKaddress(rs.getString("kaddress"));
d.setKid( rs.getString("kid"));
d.setKintr(rs.getString("kintr")) ;
d.setKname(rs.getString("kname")) ;
d.setKphone(rs.getString("kphone")) ;
this.setParam(param);
list.add(d);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
//��ѯ ҽ�� ��Ϣ
public List<Doctor> CheckDoctor(int hid,String kid ){
List<Doctor> list = new ArrayList<Doctor>();
String sql = "select * from doctor where hid='"+hid+"'";
System.out.println("hid");
System.out.println(kid);
if(kid!=