S2SH水费管理系统-JAVA【毕业设计、快速开发、源码、开题报告】

该文章描述了一个水表管理系统的后台功能,包括系统管理员的职责如用户管理、区域管理、水费计算和维护。用户主要功能是查看水费超表及退出系统。代码示例展示了管理员登录验证、信息添加和修改以及删除操作。系统还包含分页查询和权限控制等元素。
摘要由CSDN通过智能技术生成

 

功能介绍

系统管理员:系统管理,用户信息管理,区域信息管理,水表结算类型维护(月、季度、年),水费单价信息维护,水表信息管理,水费信息管理。

用户:水费超表,退出系统。

部分功能模块代码

package com.action;

import java.util.List;
import java.util.Map;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.util.Pagination;

import com.entity.Admin;
import com.entity.User;
import com.dao.AdminDAO;

public class AdminAction extends BaseAction implements ModelDriven<Admin> {
	@Autowired
	private AdminDAO adminDAO;

	// 模型驱动使用的对象,通过登录执行的方法将用户名和密码封装在Admin对象里.
	private Admin admin = new Admin();

	public Admin getModel() {
		return admin;
	}

	public String toadd() {
		return "toadd";
	}
	public String userlogin() {
		if(admin != null){
			String userNm = ServletActionContext.getRequest().getParameter("userName");
			String userPwd = ServletActionContext.getRequest().getParameter("userPw");
			
			Admin userTemp = new Admin();
			userTemp.setUsername(userNm);
			userTemp.setUserpwd(userPwd);
			userTemp.setIdentity("抄表员");
			List userList =  adminDAO.findByExample(admin);
			if(null != userList && userList.size() > 0){
				Admin user = (Admin) userList.get(0);
				ServletActionContext.getRequest().getSession().setAttribute("userType", 1);
				ServletActionContext.getRequest().getSession().setAttribute("user", user);
				return "userloginsucc";
			}
		}
		return "userloginfail";
	}
	public String add() {
		adminDAO.save(admin);
		this.setMessage("添加成功");
		this.setPath("admin!listpage.action");
		return "succeed";
	}

	//
	public String toedit() {
		admin = adminDAO.findById(admin.getId());
		getRequestMap().put("Admin", admin);
		return "toedit";
	}

	// 修改的执行方法
	public String edit() {
		adminDAO.merge(admin);
		this.setMessage("修改成功");
		this.setPath("admin!listpage.action");
		return "succeed";
	}

	public String listall() {
		List adminList = adminDAO.findByExample(admin);
		Map request = getRequestMap();
		request.put("adminList", adminList);
		return "list";
	}

	public String listpage() {
		List adminList = adminDAO.findByExample(admin);
		Map request = getRequestMap();
		request.put("adminList", adminList);
		return "list";
	}
	
	/**
	* 删除
	*/
	public String del() {
		if("admin".endsWith(admin.getUsername())){
			this.setMessage("超级管理员不能删除");
			this.setPath("admin!listpage.action");		
			return "succeed";
		}
		adminDAO.delete(admin);
		this.setMessage("添加成功");
		this.setPath("admin!listpage.action");		
		return "succeed";
	}

	public AdminDAO getAdminDAO() {
		return adminDAO;
	}

	public void setAdminDAO(AdminDAO adminDAO) {
		this.adminDAO = adminDAO;
	}

	public Admin getAdmin() {
		return this.admin;
	}

	public void setAdmin(Admin admin) {
		this.admin = admin;
	}

}
package com.service;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.directwebremoting.WebContext;
import org.directwebremoting.WebContextFactory;

import com.dao.AdminDAO;
import com.dao.UserDAO;
import com.entity.Admin;
import com.entity.User;

public class loginService {
	private AdminDAO adminDAO;
	private UserDAO userDAO;

	public String login(String userName, String userPw, int userType) {
		System.out.println("userType" + userType);
		try {
			Thread.sleep(700);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		String result = "no";

		if (userType == 0)//
		{
			String sql = "from Admin where identity = '管理员' and username=? and userpwd=?";
			Object[] con = { userName, userPw };
			List adminList = adminDAO.getHibernateTemplate().find(sql, con);
			if (adminList.size() == 0) {
				result = "no";
			} else {
				WebContext ctx = WebContextFactory.get();
				HttpSession session = ctx.getSession();
				Admin admin = (Admin) adminList.get(0);
				session.setAttribute("userType", 0);
				session.setAttribute("admin", admin);
				result = "yes";
			}
		}
		if (userType == 1) {
			String sql = "from User where loginname=? and pwd=?";
			Object[] con = { userName, userPw };
			List userList = userDAO.getHibernateTemplate().find(sql, con);
			if (userList.size() == 0) {
				result = "no";
			} else {
				WebContext ctx = WebContextFactory.get();
				HttpSession session = ctx.getSession();
				User user = (User) userList.get(0);
				session.setAttribute("userType", 1);
				session.setAttribute("user", user);
				result = "yes";
			}
		}
		return result;
	}

	public String adminPwEdit(String userPwNew) {
		System.out.println("DDDD");
		try {
			Thread.sleep(700);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		WebContext ctx = WebContextFactory.get();
		HttpSession session = ctx.getSession();

		Admin admin = (Admin) session.getAttribute("admin");
		admin.setUserpwd(userPwNew);

		adminDAO.getHibernateTemplate().update(admin);
		session.setAttribute("admin", admin);

		return "yes";
	}

	public AdminDAO getAdminDAO() {
		return adminDAO;
	}

	public void setAdminDAO(AdminDAO adminDAO) {
		this.adminDAO = adminDAO;
	}

	public UserDAO getUserDAO() {
		return userDAO;
	}

	public void setUserDAO(UserDAO userDAO) {
		this.userDAO = userDAO;
	}

}
package com.dao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.entity.Admin;

public class AdminDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(AdminDAO.class);

	public int findCount() {
		String hql = "select count(*)from Admin";
		List<Long> list = this.getHibernateTemplate().find(hql);
		if (list.size() > 0) {
			return list.get(0).intValue();
		}
		return 0;
	}

	/**
	 * 分页查找
	 */
	public List<Admin> findByPage(int begin, int pageSize) {
		DetachedCriteria critertia = DetachedCriteria.forClass(Admin.class);
		List<Admin> list = this.getHibernateTemplate().findByCriteria(
				critertia, begin, pageSize);
		return list;
	}

	public void save(Admin instance) {
		this.getHibernateTemplate().save(instance);
	}

	public void delete(Admin instance) {
		this.getHibernateTemplate().delete(instance);
	}

	public Admin findById(Integer id) {
		return (Admin) getHibernateTemplate().get("com.entity.Admin", id);
	}

	public List findByExample(Admin instance) {
		return getHibernateTemplate().findByExample(instance);
	}

	public List findByProperty(String propertyName, Object value) {
		String queryString = "from Admin as model where model." + propertyName
				+ "= ?";
		return getHibernateTemplate().find(queryString, value);
	}

	public List findAll() {
		return getHibernateTemplate().find("from Admin");
	}

	public Admin merge(Admin instance) {
		return (Admin) getHibernateTemplate().merge(instance);
	}

	public void saveOrUpdate(Admin instance) {
		this.getHibernateTemplate().saveOrUpdate(instance);
	}

}

论文目录

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值