• 库存物资管理系统


    package com.bean;
    
    public class WarehouseBean {
        
        private String name;
        private String manufacturer;
        private String model;
        private String specifications;
        
        public WarehouseBean(String name,String manufacturer,String model,String specifications) {
            this.name = name;
            this.manufacturer = manufacturer;
            this.model = model;
            this.specifications = specifications;
        }
    
        public WarehouseBean(String name) {
            this.name = name;
            manufacturer = null;
            model = null;
            specifications = null;
        }
        
        public String getName() {
            return name;
        }
    
        public String getManufacturer() {
            return manufacturer;
        }
    
        public String getModel() {
            return model;
        }
    
        public String getSpecifications() {
            return specifications;
        }
    
    }
    WarehouseBean.java
    package com.bean;
    
    public class BillBean extends WarehouseBean{
        
        private int number;
        private boolean out_or_into;
        private String organization_name;
        private String person_name;
        
        public BillBean(String name, String manufacturer, String model, String specifications) {
            super(name, manufacturer, model, specifications);
            // TODO Auto-generated constructor stub
        }
        
        public BillBean(String name) {
            super(name);
        }
        
        public int getNumber() {
            return number;
        }
        public void setNumber(String number) {
            this.number = Integer.parseInt(number);
        }
        public boolean isOut_or_into() {
            return out_or_into;
        }
        public void setOut_or_into(boolean out_or_into) {
            this.out_or_into = out_or_into;
        }
        public String getOrganization_name() {
            return organization_name;
        }
        public void setOrganization_name(String organization_name) {
            this.organization_name = organization_name;
        }
    
        public String getPerson_name() {
            return person_name;
        }
    
        public void setPerson_name(String person_name) {
            this.person_name = person_name;
        }
        
        
        
        
    }
    BillBean.java
    package com.dao;
    import java.sql.*;
    
    import com.bean.WarehouseBean;
    import com.db.DB;
    
    public class WarehouseDao {
        
        @SuppressWarnings("static-access")
        public boolean add(WarehouseBean commodity){
            DB db=new DB();
            Connection con = db.getCon();
            try
            {
                PreparedStatement stm = (PreparedStatement) con.prepareStatement("insert into commodity (name,manufacturer,model,specifications) values (?,?,?,?)");
                stm.setString(1,commodity.getName());
                stm.setString(2,commodity.getManufacturer());
                stm.setString(3,commodity.getModel());
                stm.setString(4,commodity.getSpecifications());
                //con.commit();
                
                System.out.println(commodity.getName()+","+commodity.getManufacturer()+","+commodity.getModel()+","+commodity.getSpecifications());
                db.close(stm, con);
            } catch (Exception e) 
            {
                e.printStackTrace();
                return false;
            }
            return true;
        }
        
        @SuppressWarnings("static-access")
        public void delete(String name){
            DB db=new DB();
            Connection con = db.getCon();
            try
            {
                PreparedStatement stm = con.prepareStatement("delete from commodity where name = ?");
                stm.setString(1, name);
                stm.executeUpdate();
                stm.close();
                System.out.println("delete from commodity where name= "+name);        
                db.close(stm, con);
            
            } catch (Exception e) 
            {
                e.printStackTrace();
                System.out.println("delete lose");
            }
        }
        
        public int quate(WarehouseBean commodity){
            int i=-1;//i>0查询有结果
            DB db=new DB();
            Connection con = db.getCon();
            try{
                Statement stm = con.createStatement();
                ResultSet rs =stm.executeQuery("select id from goods where name='"+commodity.getName()+"' and model='"+commodity.getModel()+"' and manufacturer='"+commodity.getManufacturer()+"' and specificatios='"+commodity.getSpecifications()+"'");
                if(rs.next()){
                    i=rs.getInt("id");
                }
            } 
            catch (Exception e){
                e.printStackTrace();
            }
            return i;
        }
        
        public boolean update(WarehouseBean commodity){
            DB db=new DB();
            Connection con = db.getCon();
            try{
                Statement stm = con.createStatement();
                stm.execute("update commodity set name='"+commodity.getName()+"',manufacturer='"+commodity.getManufacturer()+"',model='"+commodity.getModel()+"',specifications='"+commodity.getSpecifications()+"' where name='"+commodity.getName()+"'");
                DB.close(stm, con);
                return true;
            } catch (Exception e) 
            {
                e.printStackTrace();
                return false;
            }
        }
        
    }
    WarehouseDao.java
    package com.dao;
    
    import java.util.List;
    import java.sql.*;
    import java.sql.Statement;
    import java.util.ArrayList;
    
    import com.bean.BillBean;
    import com.db.DB;
    
    public class BillDao {
        
        @SuppressWarnings("static-access")
        public boolean add(BillBean bill)
        {
            WarehouseDao commodity = new WarehouseDao();
            DB db=new DB();
            Connection con = db.getCon();
            try
            {
                PreparedStatement stm = (PreparedStatement) con.prepareStatement("insert into record (name,manufacturer,model,specifications,number,organization_name,person_name,out_or_into) values (?,?,?,?,?,?,?,?)");
                stm.setString(1,bill.getName());
                stm.setString(2,bill.getManufacturer());
                stm.setString(3,bill.getModel());
                stm.setString(4,bill.getSpecifications());
                stm.setInt(5,bill.getNumber());
                stm.setString(6,bill.getOrganization_name());
                stm.setString(7,bill.getPerson_name());
                
                if(bill.isOut_or_into()==true) {
                    stm.setString(8, "入库");
                    //con.commit();
                    commodity.add(bill);
                    System.out.println("add");
                }
                else {
                    stm.setString(8, "出库");
                    System.out.println("delete");
                    commodity.delete(bill.getName());
                }
                System.out.println(bill.getName()+","+bill.getManufacturer()+","+bill.getModel()+","+bill.getSpecifications()+","+bill.getNumber()+","+bill.getOrganization_name()+","+bill.getPerson_name()+","+bill.isOut_or_into());
                db.close(stm, con);
            } catch (Exception e) 
            {
                e.printStackTrace();
                System.out.println("false");
                return false;
            }
            System.out.println("true");
            return true;
        }
        
        public List<BillBean> select(String name)
        {
            List<BillBean> l=new ArrayList<BillBean>();
            BillBean bill=null;
            DB db=new DB();
            Connection con = db.getCon();
            try
            {
                Statement stm = con.createStatement();
                ResultSet rs = stm.executeQuery("select * from commodity where name like '%"+name+"'");
                while(rs.next())
                {
                    bill=new BillBean(rs.getString("name"));
                    //bill.setNumber(rs.getInt("number"));
                    bill.setOrganization_name(rs.getString("organization_name"));
                    bill.setPerson_name(rs.getString("name"));
                    l.add(bill);
                }
            } catch (Exception e) 
            {
            e.printStackTrace();
            
            }
            return l;
        }
        
    }
    BillDao.java
    package com.db;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    
    public class DB {
        private Connection con;
        @SuppressWarnings("unused")
        private Statement sta;
        @SuppressWarnings("unused")
        private ResultSet re;
        private String coursename = "com.mysql.jdbc.Driver";
        private String url = "jdbc:mysql://127.0.0.1:3306/stock_in_storage?useSSL=false";
            
        public Connection getCon() {
            try {
                Class.forName(coursename);
                System.out.println("驱动加载成功");
            }catch(ClassNotFoundException e) {
                e.printStackTrace();
            }
            try {
                con = DriverManager.getConnection(url,"root","963214785");
                System.out.println("数据库连接成功");
            }catch(Exception e){
                e.printStackTrace();
                con = null;
            }
            return con;
        }
        
        public static void close(Statement sta,Connection connection) {
            if(sta!=null) {
                try {
                    sta.close();
                }catch(SQLException e) {
                    e.printStackTrace();
                }
            }
            if(connection!=null) {
                try {
                    connection.close();
                }catch(SQLException e) {
                    e.printStackTrace();
                }
            }
        }
            
        public static void close(ResultSet re,Statement sta,Connection connection) {
            if(re!=null) {
                try {
                    re.close();
                }catch(SQLException e) {
                e.printStackTrace();
                }
            }
            if(sta!=null) {
                try {
                    sta.close();
                }catch(SQLException e) {
                    e.printStackTrace();
                }
            }
            if(connection!=null) {
                try {
                    connection.close();
                }catch(SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    DB.java
    package com.servlet;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.List;
    
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import com.bean.BillBean;
    import com.bean.WarehouseBean;
    import com.dao.BillDao;
    import com.dao.WarehouseDao;
    
    /**
     * Servlet implementation class BillServlet
     */
    @WebServlet("/BillServlet")
    public class BillServlet extends HttpServlet {
        private static final long serialVersionUID = 1L;
           
        /**
         * @see HttpServlet#HttpServlet()
         */
        public BillServlet() {
            super();
            // TODO Auto-generated constructor stub
        }
    
        /**
         * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
         */
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/html;charsetUTF-8");
            response.setCharacterEncoding("UTF-8");
            String action=request.getParameter("action");
            if(action.equals("bill.jsp"))
            {
                bill(request,response);
            }
            if(action.equals("outbill.jsp"))
            {
                outbill(request,response);
            }
            if(action.equals("update.jsp"))
            {
                update(request,response);
            }
            if(action.equals("quate.jsp"))
            {
            quate(request,response);
            }
        }
        
        private void bill(HttpServletRequest request, HttpServletResponse response)  throws ServletException, IOException{
            // TODO Auto-generated method stub
            BillBean bill=new BillBean(request.getParameter("name"),request.getParameter("manuturer"),request.getParameter("model"),request.getParameter("specifications"));
            System.out.println(request.getParameter("specifications"));
            bill.setNumber(request.getParameter("number"));
            bill.setOrganization_name(request.getParameter("organization_name"));
            bill.setPerson_name(request.getParameter("person_name"));
            bill.setOut_or_into(true);
            
            BillDao dao = new BillDao();
            if(dao.add(bill))
            {
                PrintWriter out = response.getWriter();
                out.print("<script charset='UTF-8'>alert('add success'); </script>");
                out.println("<html>");
                out.println("<body>");
                out.println("<input align='center' type='button' value='back' onclick='fanhui()'/>");
                out.print("<script charset='UTF-8'>function fanhui(){window.location.href='bill.jsp';} </script>");
                out.println("</body>");
                out.println("</html>");
                out.flush();
                out.close();
            }
            
        }
        
        private void outbill(HttpServletRequest request, HttpServletResponse response)  throws ServletException, IOException{
            // TODO Auto-generated method stub
            BillBean bill=new BillBean(request.getParameter("name"),request.getParameter("manuturer"),request.getParameter("model"),request.getParameter("specifications"));
            
            bill.setNumber(request.getParameter("number"));
            bill.setOrganization_name(request.getParameter("organization_name"));
            bill.setPerson_name(request.getParameter("person_name"));
            bill.setOut_or_into(false);
            
            BillDao dao = new BillDao();
            if(dao.add(bill))
            {
                PrintWriter out = response.getWriter();
                out.print("<script charset='UTF-8'>alert('add success'); </script>");
                out.println("<html>");
                out.println("<body>");
                out.println("<input align='center' type='button' value='back' onclick='fanhui()'/>");
                out.print("<script charset='UTF-8'>function fanhui(){window.location.href='outbill.jsp';} </script>");
                out.println("</body>");
                out.println("</html>");
                out.flush();
                out.close();
            }
        }
        
        private void update(HttpServletRequest request, HttpServletResponse response)  throws ServletException, IOException{
            // TODO Auto-generated method stub
            WarehouseBean commodity = new WarehouseBean(request.getParameter("name"),request.getParameter("manuturer"),request.getParameter("model"),request.getParameter("specifications"));
            
            WarehouseDao dao = new WarehouseDao();
            if(dao.update(commodity)) {
                PrintWriter out = response.getWriter();
                out.print("<script charset='UTF-8'>alert('update success'); </script>");
                out.println("<html>");
                out.println("<body>");
                out.println("<input align='center' type='button' value='back' onclick='fanhui()'/>");
                out.print("<script charset='UTF-8'>function fanhui(){window.location.href='update.jsp';} </script>");
                out.println("</body>");
                out.println("</html>");
                out.flush();
                out.close();
            }
        }
        
        private void quate(HttpServletRequest request, HttpServletResponse response)  throws ServletException, IOException{
            // TODO Auto-generated method stub
            BillBean bill=new BillBean(request.getParameter("name"));
            BillDao dao = new BillDao();
            List<BillBean>l=dao.select(bill.getName());
            request.getSession().setAttribute("l", l);
            PrintWriter out = response.getWriter();
            out.println("<html>");
            out.println("<body>");
            out.println("<input align='center' type='button' value='back' onclick='fanhui()'/>");
            out.print("<script charset='UTF-8'>function fanhui(){window.location.href='quate.jsp';} </script>");
            out.println("</body>");
            out.println("</html>");
            out.flush();
            out.close();
        }
    
    }
    BillServlet.java
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>main</title>
    </head>
    <body> 
        <div style="100%;text-align:center">
            <div>
                <div><a href="bill.jsp">入货单据</a></div>
                <div><a href="outbill.jsp">出货单据</a></div>
                <div><a href="update.jsp">商品信息修改</a></div>
                <div><a href="quate.jsp">商品信息查询</a></div>
            </div>
        </div>
    </body>
    </html>
    inedx.jsp
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>入货单</title>
    <style type="text/css">
    .save
    {
        border:0;
        cursor:pointer;
        color:#000000;
        background-color:#00ff00;
        200px;
    }
    </style>
    </head>
    <body>
    
        <div style="100%;text-align:center">
        <form method="post" action="BillServlet?action=bill.jsp">
        <div>
            <div style="display:inline"><label for="name" >商品名称</label></div>
            <div style="display:inline"><input type="text" name="name" id="name"/></div>
        </div>
        <div>
            <div style="display:inline"><label for="manuturer" >生产厂家</label></div>
            <div style="display:inline"><input type="text" name="manuturer" id="manuturer"/></div>
        </div>
        <div>
            <div style="display:inline"><label for="model" >型号</label></div>
            <div style="display:inline"><input type="text" name="model" id="model"/></div>
        </div>
        <div>
            <div style="display:inline"><label for="specifications" >规格</label></div>
            <div style="display:inline"><input type="text" name="specifications" id="specifications"/></div>
        </div>
        <div>
            <div style="display:inline"><label for="number" >数量</label></div>
            <div style="display:inline"><input type="text" name="number" id="number"/></div>
        </div>
        <div>
            <div style="display:inline"><label for="organization_name" >入库单位</label></div>
            <div style="display:inline"><input type="text" name="organization_name" id="organization_name"/></div>
        </div>
        <div>
            <div style="display:inline"><label for="person_name" >提货人姓名</label></div>
            <div style="display:inline"><input type="text" name="person_name" id="person_name"/></div>
        </div>
        <div><input class="save" type="submit" value="保存"/></div>
        <div><a href="index.jsp">返回主页面</a></div>
        </form>
    </div>
    </body>
    </html>
    bill.jsp
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>出货单</title>
    <style type="text/css">
    .save
    {
        border:0;
        cursor:pointer;
        color:#000000;
        background-color:#00ff00;
        200px;
    }
    </style>
    </head>
    <body>
        <div style="100%;text-align:center">
        <form method="post" action="BillServlet?action=outbill.jsp">
        <div>
            <div style="display:inline"><label for="name" >商品名称</label></div>
            <div style="display:inline"><input type="text" name="name" id="name"/></div>
        </div>
        <div>
            <div style="display:inline"><label for="manuturer" >生产厂家</label></div>
            <div style="display:inline"><input type="text" name="manuturer" id="manuturer"/></div>
        </div>
        <div>
            <div style="display:inline"><label for="model" >型号</label></div>
            <div style="display:inline"><input type="text" name="model" id="model"/></div>
        </div>
        <div>
            <div style="display:inline"><label for="specifications" >规格</label></div>
            <div style="display:inline"><input type="text" name="specitications" id="specifications"/></div>
        </div>
        <div>
            <div style="display:inline"><label for="number" >数量</label></div>
            <div style="display:inline"><input type="text" name="number" id="number"/></div>
        </div>
        <div>
            <div style="display:inline"><label for="organization_name" >出库单位</label></div>
            <div style="display:inline"><input type="text" name="organization_name" id="organization_name"/></div>
        </div>
        <div>
            <div style="display:inline"><label for="person_name" >送货人姓名</label></div>
            <div style="display:inline"><input type="text" name="person_name" id="person_name"/></div>
        </div>
        <div><input class="save" type="submit" value="保存"/></div>
        <div><a href="index.jsp">返回主页面</a></div>
        </form>
    </div>
    </body>
    </html>
    outbill.jsp
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>商品信息查询</title>
    <style type="text/css">
    .save
    {
        border:0;
        cursor:pointer;
        color:#000000;
        background-color:#00ff00;
        200px;
    }
    </style>
    </head>
    <body>
        <div style="100%;text-align:center">
        <form method="post" action="BillServlet?action=quate.jsp">
        <div>
            <div style="display:inline"><label for="name">商品名称</label></div>
            <div style="display:inline"><input type="text" name="name"/></div>
        </div>
        <div><input class="save" type="submit" value="查询"/></div>
        <div><a href="index.jsp">返回主页面</a></div>
        </form>
    </div>
    </body>
    </html>
    quate.jsp
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>商品信息修改</title>
    <style type="text/css">
    .save
    {
        border:0;
        cursor:pointer;
        color:#000000;
        background-color:#00ff00;
        200px;
    }
    </style>
    </head>
    <body>
        <div style="100%;text-align:center">
        <form method="post" action="BillServlet?action=update.jsp">
        <div>
            <div style="display:inline"><label for="name">商品名称</label></div>
            <div style="display:inline"><input type="text" name="name"/></div>
        </div>
        <div>
            <div style="display:inline"><label for="manuturer">生产厂家</label></div>
            <div style="display:inline"><input type="text" name="manuturer"/></div>
        </div>
        <div>
            <div style="display:inline"><label for="model">型号</label></div>
            <div style="display:inline"><input type="text" name="model"/></div>
        </div>
        <div>
            <div style="display:inline"><label for="specifications">规格</label></div>
            <div style="display:inline"><input type="text" name="specitications"/></div>
        </div>
        <div><input class="save" type="submit" value="修改"/></div>
        <div><a href="index.jsp">返回主页面</a></div>
        </form>
    </div>
    </body>
    </html>
    update.jsp
  • 相关阅读:
    vue+element-ui商城后台管理系统(day01-day02)
    ssl证书-https重定向
    图形化编程娱乐于教,Kittenblock实例,空格键控制随机背景和角色
    图形化编程娱乐于教,Kittenblock实例,造型切换,制作雷电效果
    图形化编程娱乐于教,Kittenblock实例,飞行人特效,角色的运动和形状改变
    图形化编程娱乐于教,scratch3.0实例,人物造型改变,字幕效果
    图形化编程娱乐于教,scratch3.0实例,回答询问
    图形化编程娱乐于教, scratch3.0实例,猜水果,解读消息,变量的使用
    图形化编程娱乐于教,Kittenblock实例,自制演奏模块,调用各种乐器演奏
    图形化编程娱乐于教,Kittenblock实例,角色在街上找人问路
  • 原文地址:https://www.cnblogs.com/gothic-death/p/10129244.html
Copyright © 2020-2023  润新知