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

📄 additiondaoimpl.java

📁 一个优秀的干洗店管理系统
💻 JAVA
字号:
package dao.clothesAdditionDao.additionDaoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

import javax.swing.JOptionPane;

import vo.ClothesAccessoriesVo;
import vo.ClothesBrandsVo;
import vo.ClothesColorsVo;
import vo.ClothesFlawsVo;
import dao.clothesAdditionDao.ClothesAdditionDao;
import dao.common.DBConnectionManager;
import dao.common.DbException;
import dao.common.sql.DbClothesAdditionSql;

public class AdditionDaoImpl implements  ClothesAdditionDao{
	static public int CLOTHES_BARND = 0;
	static public int CLOTHES_COLOR = 1;
	static public int CLOTHES_FLAW = 2;
	static public int CLOTHES_ACCESSORY = 3;
	
	private DBConnectionManager manager = DBConnectionManager.getInstance();
	
	public boolean registAdditionInfo(String content,int type) throws DbException{
		boolean flag = false;
	    Connection con = null;
	    PreparedStatement pstmt = null;
	    try{
	      con = manager.getConnection("oracle");
	      if(type == CLOTHES_BARND){
	    	  pstmt = con.prepareStatement(DbClothesAdditionSql.INSERT_CLOTHES_BRAND);
	      }else if(type==CLOTHES_COLOR){
	    	  pstmt = con.prepareStatement(DbClothesAdditionSql.INSERT_CLOTHES_COLOR);
	      }else if(type==CLOTHES_FLAW){
	    	  pstmt = con.prepareStatement(DbClothesAdditionSql.INSERT_CLOTHES_FLAW);
	      }else if(type==CLOTHES_ACCESSORY){
	    	  pstmt = con.prepareStatement(DbClothesAdditionSql.INSERT_CLOTHES_ACCESSORY);
	      }
	      pstmt.setString(1, content);
	      int count = pstmt.executeUpdate();
	      if(count != 0){
	    	  flag = true;
	      }else{
	    	  throw new DbException(content + "添加失败");
	      }
	    }catch(SQLException e){
	    	JOptionPane.showMessageDialog(null, e.getMessage(), "提示",
	                 JOptionPane.YES_OPTION);;
	    }finally{
	        manager.freeConnection("oracle", con);
	    }
	     return flag;  
	}
	
	private boolean contentExists(Connection con,String content,String type){
		 PreparedStatement pstmt = null;
		 ResultSet set = null;
		 try{
			pstmt = con.prepareStatement(DbClothesAdditionSql.FIND_ALL_CLOTHES_BRAND);
			set = pstmt.getResultSet();
			while(set.next()){
				String record = set.getString("CLOTHES_BRAND");
				if(record.equals(content)){
					return true;
				}
			}
		}catch(SQLException e){
	    	e.printStackTrace();
	    }
		return false;
	}
	
	public Vector getClothesBrands() throws DbException{
	    Connection con = null;
	    PreparedStatement pstmt = null;
	    ResultSet set = null;
	    Vector v = null;
	    try{
	      con = manager.getConnection("oracle");
	      pstmt = con.prepareStatement(DbClothesAdditionSql.FIND_ALL_CLOTHES_BRAND);
	      set = pstmt.executeQuery();
	      v = new Vector();
	      while(set.next()){
	    	  String brand = set.getString("CLOTHES_BRAND");
	    	  ClothesBrandsVo brandVo =  new ClothesBrandsVo(brand);
	    	  v.add(brandVo);
	      }
	    }catch(SQLException e){
	    	JOptionPane.showMessageDialog(null, e.getMessage(), "提示",
	                 JOptionPane.YES_OPTION);;
	    }finally{
	        manager.freeConnection("oracle", con);
	    }
	    return v;
	}
	
	public Vector getClothesAccessoriess() throws DbException{
	    Connection con = null;
	    PreparedStatement pstmt = null;
	    ResultSet set = null;
	    Vector v = null;
	    try{
	      con = manager.getConnection("oracle");
	      pstmt = con.prepareStatement(DbClothesAdditionSql.FIND_ALL_CLOTHES_ACCESSORY);
	      set = pstmt.executeQuery();
	      v = new Vector();
	      while(set.next()){
	    	  String accessory = set.getString("CLOTHES_ACCESSORY");
	    	  ClothesAccessoriesVo acceVo =  new ClothesAccessoriesVo(accessory);
	    	  v.add(acceVo);
	      }
	    }catch(SQLException e){
	    	JOptionPane.showMessageDialog(null, e.getMessage(), "提示",
	                 JOptionPane.YES_OPTION);;
	    }finally{
	        manager.freeConnection("oracle", con);
	    }
	    return v;
	}
		
	public Vector getClothesColors() throws DbException{
		boolean flag = false;
	    Connection con = null;
	    PreparedStatement pstmt = null;
	    ResultSet set = null;
	    Vector v = null;
	    try{
	      con = manager.getConnection("oracle");
	      pstmt = con.prepareStatement(DbClothesAdditionSql.FIND_ALL_CLOTHES_COLOR);
	      set = pstmt.executeQuery();
	      v = new Vector();
	      while(set.next()){
	    	  String color = set.getString("CLOTHES_COLOR");
	    	  ClothesColorsVo colorVo =  new ClothesColorsVo(color);
	    	  v.add(colorVo);
	      }
	    }catch(SQLException e){
	    	JOptionPane.showMessageDialog(null, e.getMessage(), "提示",
	                 JOptionPane.YES_OPTION);;
	    }finally{
	        manager.freeConnection("oracle", con);
	    }
	    return v;
	}
	
	public Vector getClothesFlaws() throws DbException{
		boolean flag = false;
	    Connection con = null;
	    PreparedStatement pstmt = null;
	    ResultSet set = null;
	    Vector v = null;
	    try{
	      con = manager.getConnection("oracle");
	      pstmt = con.prepareStatement(DbClothesAdditionSql.FIND_ALL_CLOTHES_FLAW);
	      set = pstmt.executeQuery();
	      v = new Vector();
	      while(set.next()){
	    	  String flaw = set.getString("CLOTHES_FLAW");
	    	  ClothesFlawsVo flawVo =  new ClothesFlawsVo(flaw);
	    	  v.add(flawVo);
	      }
	    }catch(SQLException e){
	    	JOptionPane.showMessageDialog(null, e.getMessage(), "提示",
	                 JOptionPane.YES_OPTION);;
	    }finally{
	        manager.freeConnection("oracle", con);
	    }
	    return v;
	}
	
	public boolean deleteAdditionInfo(String content,int type) throws DbException{
		boolean flag = false;
	    Connection con = null;
	    PreparedStatement pstmt = null;
	    try{
	      con = manager.getConnection("oracle");
	      if(type == CLOTHES_BARND){
	    	  pstmt = con.prepareStatement(DbClothesAdditionSql.DELETE_CLOTHES_BRAND);
	      }else if(type==CLOTHES_COLOR){
	    	  pstmt = con.prepareStatement(DbClothesAdditionSql.DELETE_CLOTHES_COLOR);
	      }else if(type==CLOTHES_FLAW){
	    	  pstmt = con.prepareStatement(DbClothesAdditionSql.DELETE_CLOTHES_FLAW);
	      }else if(type==CLOTHES_ACCESSORY){
	    	  pstmt = con.prepareStatement(DbClothesAdditionSql.DELETE_CLOTHES_ACCESSORY);
	      }
	      pstmt.setString(1, content);
	      int count = pstmt.executeUpdate();
	      if(count != 0){
	    	  flag = true;
	      }else{
	    	  throw new DbException(content + "删除失败");
	      }
	    }catch(SQLException e){
	    	JOptionPane.showMessageDialog(null, e.getMessage(), "提示",
	                 JOptionPane.YES_OPTION);;
	    }finally{
	        manager.freeConnection("oracle", con);
	    }
	    return flag;
	}
	
	public boolean updateAdditionInfo(String newContent,String oldContent,int type) throws DbException{
		boolean flag = false;
		Connection con = null;
	    PreparedStatement pstmt = null;
	    try{
	      con = manager.getConnection("oracle");
	      if(type == CLOTHES_BARND){
	    	  pstmt = con.prepareStatement(DbClothesAdditionSql.UPDATE_CLOTHES_BRAND);
	      }else if(type==CLOTHES_COLOR){
	    	  pstmt = con.prepareStatement(DbClothesAdditionSql.UPDATE_CLOTHES_COLOR);
	      }else if(type==CLOTHES_FLAW){
	    	  pstmt = con.prepareStatement(DbClothesAdditionSql.UPDATE_CLOTHES_FLAW);
	      }else if(type==CLOTHES_ACCESSORY){
	    	  pstmt = con.prepareStatement(DbClothesAdditionSql.UPDATE_CLOTHES_ACCESSORY);
	      }
	      pstmt.setString(1, newContent);
	      pstmt.setString(2, oldContent);
	      int count = pstmt.executeUpdate();
	      if(count != 0){
	    	  flag = true;
	      }else{
	    	  throw new DbException( "添加失败:无法将" + oldContent + "修改为" + newContent);
	      }
	    }catch(SQLException e){
	    	JOptionPane.showMessageDialog(null, e.getMessage(), "提示",
	                 JOptionPane.YES_OPTION);;
	    }finally{
	        manager.freeConnection("oracle", con);
	    }
	    return flag;
	 }

}















⌨️ 快捷键说明

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