package cn.edu.hbcf.dao;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import cn.edu.hbcf.base.BaseDAO;
import cn.edu.hbcf.model.Student;
import cn.edu.hbcf.model.applyLeave;
public class AppLeaveDAO extends BaseDAO{
public AppLeaveDAO(Connection con) {
// TODO Auto-generated constructor stub
super(con);
}
private static HttpSession session;
private static HttpServletRequest request;
//************************学生端的假条处理信息**************************//
public boolean add(String time1,String time2,String times,String phone,String excuse){
request = ServletActionContext.getRequest();
session = request.getSession();
String id = (String)session.getAttribute("id");
String name = (String)session.getAttribute("loginname");
String cname1 = (String)session.getAttribute("cname");
String sql = "insert into appLeave(userId,username,cname,time1,time2,times,phone,excuse) values ('"+id+"','"+name+"','"+cname1+"','"+time1+"','"+time2+"','"+times+"','"+phone+"','"+excuse+"')";
try {
stmt = con.createStatement();
int flag = stmt.executeUpdate(sql);
if(flag!=0){//flag是否为0
return true;
}else{
return false;
}
} catch (SQLException e) {
e.printStackTrace();
}
return true;
}
public boolean delete(String time1,String time2){
request = ServletActionContext.getRequest();
session = request.getSession();
String id = (String)session.getAttribute("id");
String statu = "销假";
String sql = "update appLeave set status='"+statu+"' where userId='"+id+"' and time1='"+time1+"' and time2='"+time2+"'";
try {
stmt = con.createStatement();
int flag = stmt.executeUpdate(sql);
if(flag!=0){//flag是否为0
return true;
}else{
return false;
}
} catch (SQLException e) {
e.printStackTrace();
}
return true;
}
public boolean update(){
return true;
}
public boolean query(String userId){
return true;
}
public List<applyLeave> queryall(){
request = ServletActionContext.getRequest();
session = request.getSession();
String id = (String)session.getAttribute("id");
String sql = "select * from appLeave where userId='"+id+"'";
List<applyLeave> list = new ArrayList<applyLeave>();
try{
pstmt = con.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()){
applyLeave appLeave = new applyLeave();
appLeave.setUserId(rs.getString("userId"));
appLeave.setUsername(rs.getString("username"));
appLeave.setCname(rs.getString("cname"));
appLeave.setTimes(rs.getString("times"));
appLeave.setPhone(rs.getString("phone"));
appLeave.setExcuse(rs.getString("excuse"));
appLeave.setStatus(rs.getString("status"));
list.add(appLeave);
}
return list;
}catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
public List<applyLeave> updLeave(){
request = ServletActionContext.getRequest();
session = request.getSession();
String id = (String)session.getAttribute("id");
String sql = "select * from appLeave where userId='"+id+"' and status in (select status from appLeave where status='审批未通过' or status='请假')";
List<applyLeave> ulist = new ArrayList<applyLeave>();
try{
pstmt = con.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()){
applyLeave appLeave = new applyLeave();
appLeave.setUserId(rs.getString("userId"));
appLeave.setUsername(rs.getString("username"));
appLeave.setCname(rs.getString("cname"));
appLeave.setTime1(rs.getString("time1"));
appLeave.setTime2(rs.getString("time2"));
appLeave.setTimes(rs.getString("times"));
appLeave.setPhone(rs.getString("phone"));
appLeave.setExcuse(rs.getString("excuse"));
appLeave.setStatus(rs.getString("status"));
ulist.add(appLeave);
}
return ulist;
}catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
public boolean trueleave(String updTime1, String updTime2, String updTimes,
String updExcuse) {
request = ServletActionContext.getRequest();
session = request.getSession();
String id = (String)session.getAttribute("id");
String statu = "请假";
String sql = "update appLeave set time1='"+updTime1+"', time2='"+updTime2+"', times='"+updTimes+"', excuse='"+updExcuse+"', status='"+statu+"' where userId='"+id+"' and status in (select status from appLeave where status='审批未通过' or status='请假')";
try {
stmt = con.createStatement();
int flag = stmt.executeUpdate(sql);
if(flag!=0){//flag是否为0
return true;
}else{
return false;
}
} catch (SQLException e) {
e.printStackTrace();
}
return true;
}
public boolean status()
{
request = ServletActionContext.getRequest();
session = request.getSession();
String id = (String)session.getAttribute("id");
String sql = "select * from appLeave where userId='"+id+"'";
try{
pstmt = con.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()){
String status = rs.getString("status");
session.setAttribute("status",status);
}
}catch (SQLException e) {
e.printStackTrace();
return false;
}
return true;
}
//************************普通老师端的假条处理信息**************************//
public List<applyLeave> twait(){
List<applyLeave> tlist = new ArrayList<applyLeave>();
request = ServletActionContext.getRequest();
session = request.getSession();
String cname = (String)session.getAttribute("cname");
String sql = "select * from appLeave where cname='"+cname+"' and times>0 and times<4 and status='请假'";
try{
pstmt = con.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()){
applyLeave tleave = new applyLeave();
tleave.setUserId(rs.getString("userId"));
tleave.setUsername(rs.getString("username"));
tleave.setCname(rs.getString("cname"));
tleave.setTimes(rs.getString("times"));
tleave.setPhone(rs.getString("phone"));
tleave.setExcuse(rs.getString("excuse"));
tleave.setStatus(rs.getString("status"));
tlist.add(tleave);
}
return tlist;
}catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
public boolean await(String userId) {
request = ServletActionContext.getRequest();
session = request.getSession();
String cname = (String)session.getAttribute("cname");
String statu = "审批通过";
String sql = "update appLeave set status='"+statu+"' where userId='"+userId+"' and cname='"+cname+"' and status='请假'";
try {
stmt = con.createStatement();
int flag = stmt.executeUpdate(sql);
if(flag!=0){//flag是否为0
return true;
}else{
return false;
}
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
public boolean noAllow(String userId) {
request = ServletActionContext.getRequest();
session = request.getSession();
String cname = (String)session.getAttribute("cname");
String statu = "审批未通过";
String sql = "update appLeave set status='"+statu+"' where userId='"+userId+"' and cname='"+cname+"' and status='请假'";
try {
stmt = con.createStatement();
int flag = stmt.executeUpdate(sql);
if(flag!=0){//flag是否为0
return true;
}else{
return false;
}
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
public List<applyLeave> tleave(){
List<applyLeave> tlist = new ArrayList<applyLeave>();
request = Se
- 1
- 2
前往页