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

📄 waredao.java

📁 销售管理系统 随着我国国民经济的持续发展
💻 JAVA
字号:
package com.dao;

import com.tool.JDBConnection;
import java.util.*;
import com.domain.WareVO;
import java.sql.*;

public class WareDao {
  private JDBConnection connection = null;
  public WareDao() {
    connection = new JDBConnection();
    this.connection.creatConnection(); //利用构造方法调用类中的对象对数据库创建连接
  }

  public List wareSelect() {
    List list = new ArrayList();
    WareVO ware = null;
    String sql = "select * from tb_inware order by id";
    ResultSet rs = connection.executeQuery(sql);
    try {
      while (rs.next()) {
        ware = new WareVO();
        ware.setId(Integer.valueOf(rs.getString(1)));
        ware.setNumber(rs.getString(2));
        ware.setName(rs.getString(3));
        ware.setKind(rs.getString(4));
        ware.setBusiness(rs.getString(5));
        ware.setAccount(Integer.valueOf(rs.getString(6)));
        ware.setMeasure(rs.getString(7));
        ware.setRemark(rs.getString(8));
        ware.setMoney(rs.getFloat(9));
        list.add(ware);
      }
    }
    catch (SQLException ex) {
    }
    connection.closeConnection();
    return list;
  }

  public WareVO wareSelectOne(String number) {
    WareVO ware = null;
    String sql = "select * from tb_inware where number='" + number + "'";
    ResultSet rs = connection.executeQuery(sql);
    try {
      while (rs.next()) {
        ware = new WareVO();
        ware.setId(Integer.valueOf(rs.getString(1)));
        ware.setNumber(rs.getString(2));
        ware.setName(rs.getString(3));
        ware.setKind(rs.getString(4));
        ware.setBusiness(rs.getString(5));
        ware.setAccount(Integer.valueOf(rs.getString(6)));
        ware.setMeasure(rs.getString(7));
        ware.setRemark(rs.getString(8));
        ware.setMoney(rs.getFloat(9));
      }
    }
    catch (SQLException ex) {
    }
    connection.closeConnection();
    return ware;
  }
//查找货品的名称
  public String wareName(String number) {
    String name = null;
    String sql = "select * from tb_inware where number='" + number + "'";
    ResultSet rs = connection.executeQuery(sql);
    try {
      while (rs.next()) {
        name = rs.getString("name");
      }
    }
    catch (SQLException ex) {
    }
    connection.closeConnection();
    return name;
  }
//查找货品规格
  public String wareMeasure(String number) {
    String measure = null;
    String sql = "select * from tb_inware where number='" + number + "'";
    ResultSet rs = connection.executeQuery(sql);
    try {
      while (rs.next()) {
        measure = rs.getString("measure");
      }
    }
    catch (SQLException ex) {
    }
    connection.closeConnection();
    return measure;
  }



  //查找货品的名称
    public int wareAccount(String number) {
      int account =0;
      String sql = "select * from tb_inware where number='" + number + "'";
      ResultSet rs = connection.executeQuery(sql);
      try {
        while (rs.next()) {
          account = rs.getInt("account");
        }
      }
      catch (SQLException ex) {
      }
      connection.closeConnection();
      return account;
  }

  public WareVO wareSelectName(String name) {
    WareVO ware = null;
    String sql = "select * from tb_inware where name='" + name + "'";
    ResultSet rs = connection.executeQuery(sql);
    try {
      while (rs.next()) {
        ware = new WareVO();
        ware.setId(Integer.valueOf(rs.getString(1)));
        ware.setNumber(rs.getString(2));
        ware.setName(rs.getString(3));
        ware.setKind(rs.getString(4));
        ware.setBusiness(rs.getString(5));
        ware.setAccount(Integer.valueOf(rs.getString(6)));
        ware.setMeasure(rs.getString(7));
        ware.setRemark(rs.getString(8));
        ware.setMoney(rs.getFloat(9));
      }
    }
    catch (SQLException ex) {
    }
    connection.closeConnection();
    return ware;
  }

//添加操作
  public void wareInsert(WareVO vo) {
    String sql = "insert into  tb_inware values('" + vo.getNumber() + "','" +
        vo.getName() + "','" + vo.getKind() + "','" + vo.getBusiness() + "','" +
        vo.getAccount() + "','" + vo.getMeasure() + "','" + vo.getRemark() +
        "','" + vo.getMoney() + "') ";
    connection.executeUpdate(sql);
    connection.closeConnection();
  }

  public void wareDelete(Integer id) {
    String sql = "delete from tb_inware where id='" + id + "'";
    connection.executeUpdate(sql);
    connection.closeConnection();
  }

  public void wareUpdateNumber(Integer id, String number) {
    String unNumber = "ware-" + String.valueOf(id);
    String sql = "update tb_inware set number='" + unNumber +
        "'  where number='" + number + "'";
    connection.executeUpdate(sql);
    connection.closeConnection();
  }

  public void wareUpdate(WareVO vo) {
    String sql = "update tb_inware set name='" + vo.getName() + "',kind='" +
        vo.getKind() +
        "',business='" + vo.getBusiness() + "',measure='" + vo.getMeasure() +
        "',remark='" + vo.getRemark() + "',money='" + vo.getMoney() +
        "',account='" + vo.getAccount() + "' where id='" + vo.getId() + "'";
    connection.executeUpdate(sql);
    connection.closeConnection();
  }

  public void wareIn(Integer id, int account) {
    String sql = "update tb_inware set account='" + account + "' where id='" +
        id + "'";
    connection.executeUpdate(sql);
    connection.closeConnection();
  }

  public void wareOut(int account, String number) {
     String sql = "update tb_inware set account='"+account+"' where number='"+number+"'";
     connection.executeUpdate(sql);
     connection.closeConnection();
  }
  //获得货品的生产厂商
    public String wareCompanyName(String number) {
      String name = null;
      String sql = "select * from tb_inware where number='" + number + "'";
      ResultSet rs = connection.executeQuery(sql);
      try {
        while (rs.next()) {
          name = rs.getString("business");
        }
      }
      catch (SQLException ex) {
      }
      connection.closeConnection();
      return name;
  }
}

⌨️ 快捷键说明

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