⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webserviceimpl.java

📁 本系统可初步满足超市的收支管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package org.yeeku.service.impl;

import javax.servlet.http.*;
import javax.servlet.*;
import org.hibernate.*;
import org.hibernate.cfg.*;
import java.util.*;
import org.yeeku.model.*;
import org.yeeku.factory.*;
import org.yeeku.tools.*;
import org.yeeku.dao.*;
import org.yeeku.dao.impl.*;
import org.yeeku.exception.*;
import org.yeeku.service.*;
import org.yeeku.vo.*;
/**
 * @author  yeeku.H.lee kongyeeku@163.com
 * @version  1.0
 * <br>Copyright (C), 2005-2008, yeeku.H.Lee
 * <br>This program is protected by copyright laws.
 * <br>Program Name:
 * <br>Date: 
 */
public class WebServiceImpl implements WebService
{

	/**
	 * 新增一个供货商
	 * @param vendorName 供货商名字
	 * @param vendorAddress 供货商地址
	 * @param vendorPhone 供货商电话
	 * @param vendorFax 供货商传真
	 * @param vendorContentPerson 供货商联系人
	 * @return 创建是否成功
	 */
	public boolean createVendor(String vendorName , String vendorAddress , String vendorPhone , String vendorFax ,
		String vendorContactPerson)throws WEBException
	{
		VendorDao vd = null;
		try
		{
			vd = (VendorDao)DaoFactory.instance().getDao("vendorDao");
		
			Session sess = HibernateUtil.currentSession();
			Transaction tran = sess.beginTransaction();
			Vendor v = new Vendor();
			v.setVendorName(vendorName);
			v.setVendorAddress(vendorAddress);
			v.setVendorPhone(vendorPhone);
			v.setVendorFax(vendorFax);
			v.setVendorContactPerson(vendorContactPerson);
			vd.save(sess , v);
			tran.commit();
			return true;
		}
		catch (Exception ee)
		{
			throw new WEBException("增加供应商出现异常,请重试");
		}
		finally
		{
			HibernateUtil.closeSession();
		}
	}

	/**
	 * 根据分页列出所有供货商
	 * @param page 页码
	 * @return 指定页的所有供货商
	 */
	public Collection showVendor(int page)throws WEBException
	{
		try
		{
			System.out.println("page=" + page);
			int beginPage = 0;
			int listPage = 0;
			if (page == 1)
			{
				beginPage = 0;
				listPage = beginPage + 10;
			}
			else
			{
				beginPage = page * 10;
				listPage = beginPage + 10;
			}
			Collection result = new ArrayList();
			VendorDao vendorDao = (VendorDao)DaoFactory.instance().getDao("vendorDao");
			Session sess = HibernateUtil.currentSession();
			Transaction tran = sess.beginTransaction();
			List l = vendorDao.findByShowVendor(sess , beginPage , listPage);
			System.out.println("l=" + l);
			for (Iterator it = l.iterator(); it.hasNext() ; )
			{
				Vendor v = (Vendor)it.next();
				VendorVo vv = new VendorVo(v.getVendorId() , v.getVendorName() , v.getVendorAddress() , 
					v.getVendorPhone() , v.getVendorFax() , v.getVendorContactPerson());
				result.add(vv);
			}
			tran.commit();
			return result;
		}
		catch (Exception ee)
		{
			throw new WEBException("查询供货商出现异常,请重试");
		}
		finally
		{
			HibernateUtil.closeSession();
		}
	}

	/**
	 * 修改供货商
	 * @param vendorId 供货商id
	 * @param vendorName 供货商名字
	 * @param vendorAddress 供货商地址
	 * @param vendorPhone 供货商电话
	 * @param vendorFax 供货商传真
	 * @param vendorContentPerson 供货商联系人
	 * @return 修改是否成功
	 */
	public boolean updateVendor(Integer vendorId , String vendorName , String vendorAddress , String vendorPhone , String vendorFax ,
		String vendorContactPerson)throws WEBException
	{
		try
		{
			VendorDao vd = (VendorDao)DaoFactory.instance().getDao("vendorDao");
			Session sess = HibernateUtil.currentSession();
			Transaction tran = sess.beginTransaction();
			Vendor v = vd.get(sess , vendorId);
			if (v != null)
			{
				v.setVendorName(vendorName);
				v.setVendorAddress(vendorAddress);
				v.setVendorPhone(vendorPhone);
				v.setVendorFax(vendorFax);
				v.setVendorContactPerson(vendorContactPerson);
				vd.update(sess , v);
				tran.commit();
				return true;
			}
			return false;
		}
		catch (Exception ee)
		{
			throw new WEBException("更新供货商出现异常,请重试");
		}
		finally
		{
			HibernateUtil.closeSession();
		}
	}

	/**
	 * 根据ID查询供货商
	 * @param id 供货商id
	 * @return 该id对应的供货商组成的集合
	 */
	public Collection showVendorId(Integer id)throws WEBException
	{
		try
		{
			Collection result = new ArrayList();
			VendorDao vendorDao = (VendorDao)DaoFactory.instance().getDao("vendorDao");
			Session sess = HibernateUtil.currentSession();
			Transaction tran = sess.beginTransaction();
			Vendor v = vendorDao.get(sess , id);
			if (v != null)
			{
				VendorVo vv = new VendorVo(v.getVendorId() , v.getVendorName() , v.getVendorAddress() , 
						v.getVendorPhone() , v.getVendorFax() , v.getVendorContactPerson());
				result.add(vv);
				tran.commit();
				return result;
			}
			return null;
		}
		catch (Exception ee)
		{
			throw new WEBException("无法取得对应供货商,请重试");
		}
		finally
		{
			HibernateUtil.closeSession();
		}
	}

	/**
	 * 获取所有供货商
	 * @return 返回系统的全部供货商
	 */
	public Collection showVendor()throws WEBException
	{
		try
		{
			Collection result = new ArrayList();
			VendorDao vendorDao = (VendorDao)DaoFactory.instance().getDao("vendorDao");
			Session sess = HibernateUtil.currentSession();
			Transaction tran = sess.beginTransaction();
			List l = vendorDao.findByShowVendor(sess);
			System.out.println("l=" + l);
			for (Iterator it = l.iterator(); it.hasNext() ; )
			{
				Vendor v = (Vendor)it.next();
				VendorVo vv = new VendorVo(v.getVendorId() , v.getVendorName() , v.getVendorAddress() , 
					v.getVendorPhone() , v.getVendorFax() , v.getVendorContactPerson());
				result.add(vv);
			}
			tran.commit();
			return result;
		}
		catch (Exception ee)
		{
			throw new WEBException("返回所有供货商时出现异常,请重试");
		}
		finally
		{
			HibernateUtil.closeSession();
		}
	}

	/**
	 * 新增一个部门
	 * @param deptName 部门名
	 * @param description 部门描述
	 * @return 创建部门是否成功
	 */
	public boolean createDept(String deptName , String description)throws WEBException
	{
		DeptDao dd = null;
		try
		{
			dd = (DeptDao)DaoFactory.instance().getDao("deptDao");
			Session sess = HibernateUtil.currentSession();
			Transaction tran = sess.beginTransaction();
			Dept d = new Dept();
			d.setDeptName(deptName);
			d.setDescription(description);
			dd.save(sess , d);
			tran.commit();
			return true;
		}
		catch (Exception ee)
		{
			throw new WEBException("添加部门时出现异常,请重试");
		}
		finally
		{
			HibernateUtil.closeSession();
		}
	}

	/**
	 * 根据分页列出所有部门
	 * @param page 页码
	 * @return 指定页的所有部门
	 */
	public Collection showDept(int page)throws WEBException
	{
		DeptDao deptDao = null;
		System.out.println("page=" + page);

		int beginPage = 0;
		int listPage = 0;
		if (page == 1)
		{
			beginPage = 0;
			listPage = beginPage + 10;
		}
		else
		{
			beginPage = page * 10;
			listPage = beginPage + 10;
		}
		Collection result = new ArrayList();
		try
		{
			deptDao = (DeptDao)DaoFactory.instance().getDao("deptDao");
			Session sess = HibernateUtil.currentSession();
			Transaction tran = sess.beginTransaction();
			List l = deptDao.findByShowDept(sess , beginPage , listPage);
			System.out.println("l=" + l);
			for (Iterator it = l.iterator(); it.hasNext() ; )
			{
				Dept d = (Dept)it.next();
				DeptVo dv = new DeptVo(d.getDeptId() , d.getDeptName() , d.getDescription());
				result.add(dv);
			}
			tran.commit();
			return result;
		}
		catch (Exception ee)
		{
			throw new WEBException("查询部门时出现异常,请重试");
		}
		finally
		{
			HibernateUtil.closeSession();
		}
	}

	/**
	 * 修改部门
	 * @param deptId 部门id
	 * @param deptName 部门名
	 * @param description 部门描述
	 * @return 修改部门是否成功
	 */
	public boolean updateDept(Integer deptId , String deptName , String description)throws WEBException
	{
		DeptDao dd = null;
		try
		{
			dd = (DeptDao)DaoFactory.instance().getDao("deptDao");
			Session sess = HibernateUtil.currentSession();
			Transaction tran = sess.beginTransaction();
			Dept d = dd.get(sess , deptId);
			if (d != null)
			{
				d.setDeptName(deptName);
				d.setDescription(description);
				dd.update(sess , d);
				return true;
			}
			tran.commit();
			return false;
		}
		catch (Exception ee)
		{
			throw new WEBException("修改部门时出现异常,请重试");
		}
		finally
		{
			HibernateUtil.closeSession();
		}
	}

	/**
	 * 根据ID查询部门
	 * @param id 部门id
	 * @return 指定ID对应部门组成的集合
	 */
	public Collection showDeptId(Integer id)throws WEBException
	{
		DeptDao deptDao = null;
		Collection result = new ArrayList();
		try
		{
			deptDao = (DeptDao)DaoFactory.instance().getDao("deptDao");
			Session sess = HibernateUtil.currentSession();
			Transaction tran = sess.beginTransaction();
			Dept d = deptDao.get(sess , id);
			DeptVo dv = new DeptVo(d.getDeptId() , d.getDeptName() , d.getDescription());
			result.add(dv);
			tran.commit();
			return result;
		}
		catch (Exception ee)
		{
			throw new WEBException("无法正常获得指定的部门,请重试");
		}
		finally
		{
			HibernateUtil.closeSession();
		}
	}

	/**
	 * 显示所有部门
	 * @return 系统中的所有部门
	 */
	public Collection showDept()throws WEBException
	{
		
		DeptDao deptDao = null;
		Collection result = new ArrayList();
		try
		{
			deptDao = (DeptDao)DaoFactory.instance().getDao("deptDao");
			Session sess = HibernateUtil.currentSession();
			Transaction tran = sess.beginTransaction();
			List l = deptDao.findByShowDept(sess);
			for (Iterator it = l.iterator(); it.hasNext() ; )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -