package com.sky.servlets;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.sky.dao.DepartmentDao;
import com.sky.dao.StaffDao;
import com.sky.dao.TitleDao;
import com.sky.dao.impl.DepartmentDaoImpl;
import com.sky.dao.impl.StaffDaoImpl;
import com.sky.dao.impl.TitleDaoImpl;
import com.sky.pojo.FullStaffs;
import com.sky.pojo.Staffs;
public class StaffServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
StaffDao staffDao = new StaffDaoImpl();
DepartmentDao departmentDao = new DepartmentDaoImpl();
TitleDao titleDao = new TitleDaoImpl();
Boolean res = null;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doPost(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
resp.setCharacterEncoding("utf-8");
String operation = req.getParameter("operation");
if (operation.equals("showOne")) { //查询单个员工
int id = Integer.parseInt(req.getParameter("id"));
Staffs staff = staffDao.selectOneById(id);
String departmentString = departmentDao.selectOneById(staff.getDepartment()).getName();
String titleString = titleDao.selectOneById(staff.getTitle()).getName();
FullStaffs fullStaff = new FullStaffs(staff.getId(), staff.getName(), staff.getSex(), staff.getBirth(), staff.getHome(), staff.getDepartment(), staff.getTitle(), departmentString, titleString, staff.getStatus());
req.setAttribute("staff", fullStaff);
req.getRequestDispatcher("/update-staff.jsp").forward(req, resp);
}else if (operation.equals("add")) { //添加员工
String name = req.getParameter("name");
String sex = req.getParameter("sex");
String birth = req.getParameter("birth");
String home = req.getParameter("home");
Integer department = Integer.parseInt(req.getParameter("department"));
Integer title = Integer.parseInt(req.getParameter("title"));
res = staffDao.addOneStaff(new Staffs(name, sex, birth, home, department, title));
if (res) {
//添加成功
req.getRequestDispatcher("/index.jsp").forward(req, resp);
} else {
//添加失败
req.getRequestDispatcher("/error.jsp").forward(req, resp);
}
}else if (operation.equals("queryAll")) { //查询全部员工号
List<Staffs> staffs = staffDao.selectAllStaffs();
List<FullStaffs> fullStaffs = new ArrayList<FullStaffs>();
for (Staffs staff : staffs) {
String departmentString = departmentDao.selectOneById(staff.getDepartment()).getName();
String titleString = titleDao.selectOneById(staff.getTitle()).getName();
fullStaffs.add(new FullStaffs(staff.getId(), staff.getName(), staff.getSex(), staff.getBirth(), staff.getHome(), staff.getDepartment(), staff.getTitle(), departmentString, titleString, staff.getStatus()));
}
req.setAttribute("staffs", fullStaffs);
//请求转发跳转
req.getRequestDispatcher("/show-staff.jsp").forward(req, resp);
}else if (operation.equals("update")) { //修改
int id = Integer.parseInt(req.getParameter("id"));
String name = req.getParameter("name");
String sex = req.getParameter("sex");
String birth = req.getParameter("birth");
String home = req.getParameter("home");
Integer department = Integer.parseInt(req.getParameter("department"));
Integer title = Integer.parseInt(req.getParameter("title"));
int status = Integer.parseInt(req.getParameter("status"));
Staffs staff = new Staffs(id, name, sex, birth, home, department, title, status);
res = staffDao.updateStaff(staff);
if (res) {
//修改成功
resp.sendRedirect(req.getContextPath()+"/queryAll.staff?operation=queryAll");
} else {
//修改失败
req.getRequestDispatcher("/error.jsp").forward(req, resp);
}
}else if (operation.equals("upload")) { //启用
int id = Integer.parseInt(req.getParameter("id"));
res = staffDao.updateStaffStatus(id, 1);
if (res) {
resp.sendRedirect(req.getContextPath()+"/queryAll.staff?operation=queryAll");
} else {
req.getRequestDispatcher("/error.jsp").forward(req, resp);
}
}else if (operation.equals("download")) { //停用
int id = Integer.parseInt(req.getParameter("id"));
res = staffDao.updateStaffStatus(id, 2);
if (res) {
resp.sendRedirect(req.getContextPath()+"/queryAll.staff?operation=queryAll");
} else {
req.getRequestDispatcher("/error.jsp").forward(req, resp);
}
}else if (operation.equals("delete")) { //删除
int id = Integer.parseInt(req.getParameter("id"));
res = staffDao.updateStaffStatus(id, 0);
if (res) {
resp.sendRedirect(req.getContextPath()+"/queryAll.staff?operation=queryAll");
} else {
req.getRequestDispatcher("/error.jsp").forward(req, resp);
}
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Sky管理系统及数据库文件.zip (414个子文件)
StaffServlet.class 6KB
StaffDaoImpl.class 5KB
TitleServlet.class 5KB
DepartmentServlet.class 5KB
TitleDaoImpl.class 5KB
DepartmentDaoImpl.class 5KB
FullStaffs.class 3KB
Staffs.class 3KB
Departments.class 2KB
AdminServlet.class 2KB
AdminDaoImpl.class 2KB
Titles.class 2KB
DBUtils.class 2KB
Admins.class 1KB
DepartmentDao.class 477B
TitleDao.class 432B
StaffDao.class 432B
AdminDao.class 206B
.classpath 964B
org.eclipse.wst.common.component 516B
org.eclipse.wst.jsdt.ui.superType.container 49B
semantic.ui.min.css 635KB
materialize.min.css 138KB
bootstrap.min.css 138KB
style.css 89KB
helper.css 54KB
font-awesome.min.css 38KB
jsgrid-theme.min.css 34KB
fullcalendar.css 30KB
weather-icons.css 30KB
mmc-chat.css 28KB
sweetalert.css 23KB
bootstrap-datepicker3.min.css 21KB
themify-icons.css 17KB
sidebar.css 17KB
jquery-ui.min.css 16KB
select2.min.css 15KB
pignose.calendar.min.css 14KB
barRating.css 14KB
dataTables.bootstrap.min.css 13KB
menu.css 12KB
lobipanel.min.css 12KB
chartist.min.css 11KB
buttons.bootstrap.min.css 8KB
buttons.dataTables.min.css 8KB
normalize.css 8KB
toastr.min.css 7KB
nestable.css 4KB
scrollable.min.css 3KB
ion.rangeSlider.css 3KB
owl.carousel.min.css 3KB
ion.rangeSlider.skinHTML5.css 3KB
ion.rangeSlider.skinModern.css 2KB
ion.rangeSlider.skinFlat.css 2KB
ion.rangeSlider.skinSimple.css 2KB
ion.rangeSlider.skinNice.css 2KB
viewsource.css 2KB
jsgrid.min.css 2KB
owl.theme.default.min.css 1003B
jqvmap.min.css 809B
jquery.lineProgressbar.css 374B
pace.css 319B
fontawesome-webfont.eot 162KB
weathericons-regular-webfont.eot 97KB
themify.eot 77KB
themify.eot 77KB
MontserratLight.eot 53KB
glyphicons-halflings-regular.eot 20KB
font-themify.html 86KB
form-basic.html 60KB
table-row-select.html 57KB
app-email.html 57KB
ui-navbar.html 55KB
ui-user-card.html 50KB
table-export.html 48KB
ui-button.html 47KB
ui-progressbar.html 46KB
app-widget-card.html 42KB
app-profile.html 42KB
ui-typography.html 40KB
form-validation.html 37KB
blank.html 36KB
vector-map.html 36KB
ui-dropdown.html 34KB
ui-panels.html 30KB
ui-images.html 30KB
ui-alerts.html 28KB
ui-timeline.html 28KB
app-event-calender.html 27KB
table-jsgrid.html 25KB
table-basic.html 25KB
uc-calendar.html 25KB
chart-flot.html 23KB
invoice.html 11KB
login.html 4KB
page-login.html 4KB
page-register.html 3KB
page-reset-password.html 2KB
mysql-connector-java-5.1.8.jar 707KB
c3p0-0.9.1.2.jar 596KB
共 414 条
- 1
- 2
- 3
- 4
- 5
资源评论
- 『IT界码仔』2019-11-13一点都相关的系统,没软用
咖喱东东
- 粉丝: 348
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功