码迷,mamicode.com
首页 > 其他好文 > 详细

库存管理系统

时间:2018-12-14 00:57:14      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:数据库增删改查   size   out   date()   block   pre   ons   4.0   span   

首先建立数据库的连接,通过界面把信息传给servlet,再通过service传给Dao层,进行数据库增删改查的操作,然后再返回给界面。

package com.servlet;

import java.io.IOException;
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 javax.swing.JOptionPane;
import java.sql.Timestamp;
import java.util.Date;
import com.bean.WarehouseBean;
import com.dao.WarehouseDao;
import com.util.DBUtil;
import com.dao.FlowDao;
@WebServlet("/addServlet")
public class addServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String name=request.getParameter("addname");
        String factory=request.getParameter("addfactory");
        String model=request.getParameter("addmodel");
        String standard=request.getParameter("addstandard");
        String number=request.getParameter("addnumber");
        String danwei=request.getParameter("adddanwei");
        String person=request.getParameter("addperson");
        Date date = new Date();
        Timestamp timeStamp = new Timestamp(date.getTime());
        int num = Integer.parseInt(number);
        int a=0,b=0;
        FlowDao flow=new FlowDao();
        WarehouseDao ware=new WarehouseDao();
        try {
            a=flow.addFlow(name, factory, model, standard, num, timeStamp, danwei, person);
            b=ware.addWarehouse(name, factory, model, standard);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if(a!=0&&b!=0)
        {
             int res=JOptionPane.showConfirmDialog(null, "???????", "??????", JOptionPane.YES_NO_OPTION);
                             if(res==JOptionPane.YES_OPTION){ 
                                 request.getRequestDispatcher("jiemian.jsp").forward(request, response);   //?????????????????????
                            }else{
                                  System.out.println("???????е????");    //????????????????????
                                  return;
                              } 
        }
        else
        {
            JOptionPane.showMessageDialog(null, "????????", "?????2???", JOptionPane.ERROR_MESSAGE);
            request.getRequestDispatcher("add.jsp").forward(request, response);
        }
        

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}
package com.servlet;

import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;

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 javax.swing.JOptionPane;

import com.bean.WarehouseBean;
import com.dao.WarehouseDao;
import com.util.DBUtil;
@WebServlet("/addWareServlet")
public class addWareServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public addWareServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String name=request.getParameter("addname");
        String factory=request.getParameter("addfactory");
        String model=request.getParameter("addmodel");
        String standard=request.getParameter("addstandard");
        Date date = new Date();
        Timestamp timeStamp = new Timestamp(date.getTime());
        int n=0;
        WarehouseDao ware=new WarehouseDao();
        try {
            n=ware.addWarehouse(name, factory, model, standard);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(n!=0)
        {
             int res=JOptionPane.showConfirmDialog(null, "???????", "??????", JOptionPane.YES_NO_OPTION);
                             if(res==JOptionPane.YES_OPTION){ 
                                 request.getRequestDispatcher("jiemian.jsp").forward(request, response);   //?????????????????????
                            }else{
                                  System.out.println("???????е????");    //????????????????????
                                  return;
                              } 
        }
        else
        {
            JOptionPane.showMessageDialog(null, "????????", "?????2???", JOptionPane.ERROR_MESSAGE);
            request.getRequestDispatcher("addWare.jsp").forward(request, response);
        }

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}
package com.servlet;

import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;

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 javax.swing.JOptionPane;

import com.dao.FlowDao;
import com.dao.WarehouseDao;


@WebServlet("/AmendServlet")
public class AmendServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
       


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String name=request.getParameter("Amendname");
        String factory=request.getParameter("Amendfactory");
        String model=request.getParameter("Amendmodel");
        String standard=request.getParameter("Amendstandard");
        String number=request.getParameter("Amendnumber");
        String danwei=request.getParameter("Amenddanwei");
        String person=request.getParameter("Amendperson");
        Date date = new Date();
        Timestamp timeStamp = new Timestamp(date.getTime());
        int num = Integer.parseInt(number);
        int a=0,b=0;
        FlowDao flow=new FlowDao();
        WarehouseDao ware=new WarehouseDao();
        try {
            a=flow.addFlow(name, factory, model, standard, num, timeStamp, danwei, person);
            b=ware.DeleteWare(name);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if(a!=0&&b!=0)
        {
             int res=JOptionPane.showConfirmDialog(null, "???????", "??????", JOptionPane.YES_NO_OPTION);
                             if(res==JOptionPane.YES_OPTION){ 
                                 request.getRequestDispatcher("jiemian.jsp").forward(request, response);   //?????????????????????
                            }else{
                                  System.out.println("???????е????");    //????????????????????
                                  return;
                              } 
        }
        else
        {
            JOptionPane.showMessageDialog(null, "????????", "?????2???", JOptionPane.ERROR_MESSAGE);
            request.getRequestDispatcher("Amend.jsp").forward(request, response);
        }
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}
package com.servlet;

import java.io.IOException;
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 javax.swing.JOptionPane;

import com.dao.WarehouseDao;
/**
 * Servlet implementation class AmendWareServlet
 */
@WebServlet("/AmendWareServlet")
public class AmendWareServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
       


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String Amendname=request.getParameter("Amendname");
        String amendname=request.getParameter("amendname");
        String amendfactory=request.getParameter("amendfactory");
        String amendmodel=request.getParameter("amendmodel");
        String amendstandard=request.getParameter("amendstandard");
        WarehouseDao admin1=new WarehouseDao();
        int a1=0,a2=0,a3=0,a4=0;
        try {
        a1=admin1.testUpdate1(Amendname,amendname);
        a2=admin1.testUpdate2(Amendname,amendfactory);
        a3=admin1.testUpdate3(Amendname,amendmodel);
        a4=admin1.testUpdate4(Amendname,amendstandard);
        }catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if(a1!=0&&a2!=0&&a3!=0&&a4!=0)
        {
            int res=JOptionPane.showConfirmDialog(null, "???????", "??????", JOptionPane.YES_NO_OPTION);
            if(res==JOptionPane.YES_OPTION){ 
                request.getRequestDispatcher("jiemian.jsp").forward(request, response);   //?????????????????????
           }else{
                 System.out.println("???????е????");    //????????????????????
                 return;
             } 
        }
        else
        {
            JOptionPane.showMessageDialog(null, "????????", "?????2???", JOptionPane.ERROR_MESSAGE);
            request.getRequestDispatcher("AmendWare.jsp").forward(request, response);
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}
package com.servlet;

import java.io.IOException;
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 javax.swing.JOptionPane;

import com.bean.WarehouseBean;
import com.dao.WarehouseDao;
import com.util.DBUtil;

@WebServlet("/DeleteWareServlet")
public class DeleteWareServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String name=request.getParameter("Deletename");
        int n=0;
        WarehouseDao ware=new WarehouseDao();
        try {
            n=ware.DeleteWare(name);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if(n!=0)
        {
             int res=JOptionPane.showConfirmDialog(null, "???????", "??????", JOptionPane.YES_NO_OPTION);
                             if(res==JOptionPane.YES_OPTION){ 
                                 request.getRequestDispatcher("jiemian.jsp").forward(request, response);   //?????????????????????
                            }else{
                                  System.out.println("???????е????");    //????????????????????
                                  return;
                              } 
        }
        else
        {
            JOptionPane.showMessageDialog(null, "????????", "?????2???", JOptionPane.ERROR_MESSAGE);
            request.getRequestDispatcher("DeleteWare.jsp").forward(request, response);
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}
package com.util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBUtil {
    public static String db_url = "jdbc:mysql://localhost:3306/sqltestdb";
    public static String db_user = "root";
    public static String db_password = "751208";

    public static Connection getConn() {
        Connection conn = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection(db_url, db_user, db_password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return conn;
    }
    
    public static void close(Statement state, Connection conn) {
        if(state!=null) {
            try {
                state.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(conn!=null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
    
    public static void close(ResultSet rs, Statement state, Connection conn) {
        if(rs!=null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(state!=null) {
            try {
                state.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if(conn!=null) {
            try {
                conn.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录界面</title>
</head>
<body>
<table width = "400" border ="0" height = "300" align = "center" cellpading ="0" style = "font-size:12px;color:#FFFFF;front-weight:bold">
<Tr height = "50" ><td>&nbsp;</td></Tr>
<tr>
   <td height = "200"><table width = "98%" border ="0" align = "center" cellpading = "0">
   <form name = "form1"  action = "addServlet" method = "post">
<tr>
<td>商品名称:</td><td><input type="text" name="addname" /></td>
</tr>
<tr>
<td>生产厂家:</td><td><input type="text" name="addfactory" /></td>
</tr>
<tr>
<td>型号:</td><td><input type="text" name="addmodel" /></td>
</tr>
<tr>
<td>规格:</td><td><input type="text" name="addstandard" /></td>
</tr>
<tr>
<td>数量:</td><td><input type="text" name="addnumber" /></td>
</tr>
<tr>
<td>入库单位名称:</td><td><input type="text" name="adddanwei" /></td>
</tr>
<tr>
<td>送货人姓名:</td><td><input type="text" name="addperson" /></td>
</tr>
<tr>
<td><input name = "login" type = "submit" id = "login" value = "提交" class = "button"></td>
</tr>
 </form>
 </table>
 </td>
 </tr>
</table>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录界面</title>
</head>
<body>
<table width = "400" border ="0" height = "300" align = "center" cellpading ="0" style = "font-size:12px;color:#FFFFF;front-weight:bold">
<Tr height = "50" ><td>&nbsp;</td></Tr>
<tr>
   <td height = "200"><table width = "98%" border ="0" align = "center" cellpading = "0">
   <form name = "form1"  action = "AmendServlet" method = "post">
<tr>
<td>商品名称:</td><td><input type="text" name="Amendname" /></td>
</tr>
<tr>
<td>生产厂家:</td><td><input type="text" name="Amendfactory" /></td>
</tr>
<tr>
<td>型号:</td><td><input type="text" name="Amendmodel" /></td>
</tr>
<tr>
<td>规格:</td><td><input type="text" name="Amendstandard" /></td>
</tr>
<tr>
<td>数量:</td><td><input type="text" name="Amendnumber" /></td>
</tr>
<tr>
<td>出库单位名称:</td><td><input type="text" name="Amenddanwei" /></td>
</tr>
<tr>
<td>提货人姓名:</td><td><input type="text" name="Amendperson" /></td>
</tr>
<tr>
<td><input name = "login" type = "submit" id = "login" value = "提交" class = "button"></td>
</tr>
 </form>
 </table>
 </td>
 </tr>
</table>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%>
      <%@page import="java.util.List" %>
      <%@page import="com.bean.WarehouseBean" %>
      <%@page import="com.bean.FlowBean" %>
      <%@page import="com.dao.WarehouseDao" %>
      <%@page import="com.dao.FlowDao" %>
      <%@page import="java.sql.Timestamp" %>
      <%@page import="java.text.SimpleDateFormat" %>
      <%@page import="java.util.Date" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录界面</title>
</head>
<body>
<table width = "400" border ="0" height = "300" align = "center" cellpading ="0" style = "font-size:12px;color:#FFFFF;front-weight:bold">
<Tr height = "50" ><td>&nbsp;</td></Tr>
<tr>
   <td height = "200"><table width = "98%" border ="0" align = "center" cellpading = "0">
   <form >
  <tr>
   <td>欢迎使用本系统</td>
  </tr>
  <tr>
  <%
    request.setCharacterEncoding("UTF-8");
    String time1=request.getParameter("time1");
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date date = sdf.parse("2016-06-06 16:24:50");
    FlowBean c=null;
    int a=0;
    List<FlowBean> beans = FlowDao.select();
    a=beans.size();
    for(int i=0;i<beans.size();i++)
    {
        c=beans.get(i);
        if(c.getDate().getTime()>date.getTime())
        {out.println("</br>");
        out.println("商品名称="+c.getName()+",生产厂家="+c.getFactory()+",型号="+c.getModel()+",规格="+c.getStandard());
        }

    }

  %>
  </tr>
  <tr>
  <td><a href="jiemian.jsp">返回</a></td>
  </tr>
  <tr>
  <td><a href="jieshu.jsp">结束</a></td>
  </tr>
 </form>
 </table>
 </td>
 </tr>
</table>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%>
      <%@page import="java.util.List" %>
      <%@page import="com.bean.WarehouseBean" %>
      <%@page import="com.bean.FlowBean" %>
      <%@page import="com.dao.WarehouseDao" %>
      <%@page import="com.dao.FlowDao" %>
      <%@page import="java.sql.Timestamp" %>
      <%@page import="java.text.SimpleDateFormat" %>
      <%@page import="java.util.Date" %>
      <%@page import="java.util.ArrayList" %>
      <%@page import="java.util.regex.Matcher" %>
      <%@page import="java.util.regex.Pattern" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录界面</title>
</head>
<body>
<table width = "400" border ="0" height = "300" align = "center" cellpading ="0" style = "font-size:12px;color:#FFFFF;front-weight:bold">
<Tr height = "50" ><td>&nbsp;</td></Tr>
<tr>
   <td height = "200"><table width = "98%" border ="0" align = "center" cellpading = "0">
   <form >
  <tr>
   <td>欢迎使用本系统</td>
  </tr>
  <tr>
  <%
    request.setCharacterEncoding("UTF-8");
    String name=request.getParameter("Selectname");
    FlowBean c=null;
    int a=0;
    List<FlowBean> beans = FlowDao.select();
    List<FlowBean> results = new ArrayList<FlowBean>();
    if(name!="")
    {
        Pattern pattern = Pattern.compile(name);
        for(int i=0;i<beans.size();i++)
        {
            Matcher matcher = pattern.matcher(((FlowBean)beans.get(i)).getName());
            if(matcher.find()){
                 results.add(beans.get(i));
               }
        }
    }
    for(int i=0;i<results.size();i++)
    {
        c=results.get(i);
        out.println("</br>");
        out.println("商品名称="+c.getName()+",生产厂家="+c.getFactory()+",型号="+c.getModel()+",规格="+c.getStandard()+",数量="+c.getNumber()+",时间="+c.getDate()+",单位名称="+c.getDanwei()+",送货人姓名="+c.getPerson());
    }

  %>
  </tr>
  <tr>
  <td><a href="jiemian.jsp">返回</a></td>
  </tr>
  <tr>
  <td><a href="jieshu.jsp">结束</a></td>
  </tr>
 </form>
 </table>
 </td>
 </tr>
</table>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录界面</title>
</head>
<body>
<table width = "400" border ="0" height = "300" align = "center" cellpading ="0" style = "font-size:12px;color:#FFFFF;front-weight:bold">
<Tr height = "50" ><td>&nbsp;</td></Tr>
<tr>
   <td height = "200"><table width = "98%" border ="0" align = "center" cellpading = "0">
   <form name = "form1"  action = "DeleteWareServlet" method = "post">
<tr>
<td>请输入要删除的商品名称:</td><td><input type="text" name="Deletename" /></td>
</tr>
<tr>
<td><input name = "login" type = "submit" id = "login" value = "提交" class = "button"></td>
</tr>
 </form>
 </table>
 </td>
 </tr>
</table>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录界面</title>
</head>
<body>
<table width = "400" border ="0" height = "300" align = "center" cellpading ="0" style = "font-size:12px;color:#FFFFF;front-weight:bold">
<Tr height = "50" ><td>&nbsp;</td></Tr>
<tr>
   <td height = "200"><table width = "98%" border ="0" align = "center" cellpading = "0">
   <form >
  <tr>
   <td>欢迎使用本系统</td>
  </tr>
  <tr>
   <td>请选择功能:</td>
  </tr>
    <tr>
   <td><a href="addWare.jsp">商品增加</a></td>
  </tr>
    <tr>
   <td><a href="DeleteWare.jsp">商品删除</a></td>
  </tr>
   <tr>
   <td><a href="AmendWare.jsp">商品修改</a></td>
  </tr>
     <tr>
   <td><a href="Selectware.jsp">商品查找</a></td>
  </tr>
  <tr>
   <td><a href="add.jsp">入库</a></td>
  </tr>
  <tr>
   <td><a href="Amend.jsp">出库</a></td>
  </tr>
  <tr>
  <td><a href="Select.jsp">查询</a></td>
  </tr>
 </form>
 </table>
 </td>
 </tr>
</table>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录界面</title>
</head>
<body>
<table width = "400" border ="0" height = "300" align = "center" cellpading ="0" style = "font-size:12px;color:#FFFFF;front-weight:bold">
<Tr height = "50" ><td>&nbsp;</td></Tr>
<tr>
   <td height = "200"><table width = "98%" border ="0" align = "center" cellpading = "0">
   <form >
  <tr>
   <td>欢迎使用本系统</td>
  </tr>
  <tr>
   <td>请选择功能:</td>
  </tr>
    <tr>
   <td><a href="Selectflow.jsp">商品名称查询</a></td>
  </tr>
    <tr>
   <td><a href="Selectdate.jsp">出入库日期查询</a></td>
  </tr>
 </form>
 </table>
 </td>
 </tr>
</table>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录界面</title>
</head>
<body>
<table width = "400" border ="0" height = "300" align = "center" cellpading ="0" style = "font-size:12px;color:#FFFFF;front-weight:bold">
<Tr height = "50" ><td>&nbsp;</td></Tr>
<tr>
   <td height = "200"><table width = "98%" border ="0" align = "center" cellpading = "0">
   <form name = "form1"  action = "chuli1.jsp" method = "post">
<tr>
<td>请输入一个时间:</td><td><input type="text" name="time1" /></td>
</tr>
<tr>
<td><input name = "login" type = "submit" id = "login" value = "提交" class = "button"></td>
</tr>
 </form>
 </table>
 </td>
 </tr>
</table>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录界面</title>
</head>
<body>
<table width = "400" border ="0" height = "300" align = "center" cellpading ="0" style = "font-size:12px;color:#FFFFF;front-weight:bold">
<Tr height = "50" ><td>&nbsp;</td></Tr>
<tr>
   <td height = "200"><table width = "98%" border ="0" align = "center" cellpading = "0">
   <form name = "form1"  action = "chuli2.jsp" method = "post">
<tr>
<td>请输入要查找的商品名称:</td><td><input type="text" name="Selectname" /></td>
</tr>
<tr>
<td><input name = "login" type = "submit" id = "login" value = "提交" class = "button"></td>
</tr>
 </form>
 </table>
 </td>
 </tr>
</table>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
      pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录界面</title>
</head>
<body>
<table width = "400" border ="0" height = "300" align = "center" cellpading ="0" style = "font-size:12px;color:#FFFFF;front-weight:bold">
<Tr height = "50" ><td>&nbsp;</td></Tr>
<tr>
   <td height = "200"><table width = "98%" border ="0" align = "center" cellpading = "0">
   <form name = "form1"  action = "chuli.jsp" method = "post">
<tr>
<td>请输入要查找的商品名称:</td><td><input type="text" name="Selectname" /></td>
</tr>
<tr>
<td><input name = "login" type = "submit" id = "login" value = "提交" class = "button"></td>
</tr>
 </form>
 </table>
 </td>
 </tr>
</table>
</html>

 



package com.bean; public class WarehouseBean { private String name; private String factory; private String model; private String standard; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getFactory() { return factory; } public void setFactory(String factory) { this.factory = factory; } public String getModel() { return model; } public void setModel(String model) { this.model = model; } public String getStandard() { return standard; } public void setStandard(String standard) { this.standard = standard; } }

 

package com.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.bean.FlowBean;
import com.bean.WarehouseBean;
import com.util.DBUtil;

public class FlowDao {
    public static int addFlow(String name,String factory,String model,String standard,int number,Timestamp date,String danwei,String person) throws Exception//????
    {
        int count = 0;
        Connection conn = DBUtil.getConn();
        try {
            String sql="insert into flow values(?,?,?,?,?,?,?,?)";
            PreparedStatement preparedStatement=conn.prepareStatement(sql);
            preparedStatement.setString(1, name);
            preparedStatement.setString(2, factory);
            preparedStatement.setString(3, model);
            preparedStatement.setString(4, standard);
            preparedStatement.setInt(5, number);
            preparedStatement.setTimestamp(6, date);
            preparedStatement.setString(7, danwei);
            preparedStatement.setString(8, person);
            count=preparedStatement.executeUpdate();
            conn.close();
        }catch (Exception e) {
            e.printStackTrace();
        }
        return count;
    }
    public static List<FlowBean> select() {//????
        List<FlowBean> beans = new ArrayList<FlowBean>();
        Connection conn = DBUtil.getConn();
        FlowBean adminBean=null;
        try {
            String sql="select * from Flow";
            Statement state = conn.createStatement();
            ResultSet rs = state.executeQuery(sql);
            while(rs.next()) {
                adminBean = new FlowBean();
                adminBean.setName(rs.getString("name"));
                adminBean.setFactory(rs.getString("factory"));
                adminBean.setModel(rs.getString("model"));
                adminBean.setStandard(rs.getString("standard"));
                adminBean.setNumber(rs.getInt("number"));
                adminBean.setDate(rs.getTimestamp("date"));
                adminBean.setDanwei(rs.getString("danwei"));
                adminBean.setPerson(rs.getString("person"));
                beans.add(adminBean);
            }
            conn.close();
        }catch (Exception e) {
            e.printStackTrace();
        }
        return beans;
        /*List<FlowBean> results = new ArrayList<FlowBean>();
        if(date!="")
        {
            Pattern pattern = Pattern.compile(date);
            for(int i=0;i<beans.size();i++)
            {
                Matcher matcher = pattern.matcher(((FlowBean)beans.get(i)).getName());
                if(matcher.find()){
                     results.add(beans.get(i));
                   }
            }
        }
        return results;*/
    }

}
package com.dao;
import com.util.DBUtil;

import com.bean.WarehouseBean;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class WarehouseDao {
    public static int addWarehouse(String name,String factory,String model,String standard) throws Exception//????
    {
        int count = 0;
        Connection conn = DBUtil.getConn();
        try {
            String sql="insert into Warehouse values(?,?,?,?)";
            PreparedStatement preparedStatement=conn.prepareStatement(sql);
            preparedStatement.setString(1, name);
            preparedStatement.setString(2, factory);
            preparedStatement.setString(3, model);
            preparedStatement.setString(4, standard);
            count=preparedStatement.executeUpdate();
            conn.close();
        }catch (Exception e) {
            e.printStackTrace();
        }
        return count;
    }
    public int DeleteWare(String name) throws Exception//???
    {
        int count=0;
        Connection conn = DBUtil.getConn();
        try {
            String sql="delete from Warehouse where name=?";
            PreparedStatement preparedStatement=conn.prepareStatement(sql);
            preparedStatement.setString(1, name);
            count=preparedStatement.executeUpdate();
            System.out.println(count);
            conn.close();
        }catch (Exception e) {
            e.printStackTrace();
        }
        return count;
    }
    public static List<WarehouseBean> select(String name) {//????
        List<WarehouseBean> beans = new ArrayList<WarehouseBean>();
        Connection conn = DBUtil.getConn();
        WarehouseBean adminBean=null;
        try {
            String sql="select * from Warehouse";
            Statement state = conn.createStatement();
            ResultSet rs = state.executeQuery(sql);
            while(rs.next()) {
                adminBean = new WarehouseBean();
                adminBean.setName(rs.getString("name"));
                adminBean.setFactory(rs.getString("factory"));
                adminBean.setModel(rs.getString("model"));
                adminBean.setStandard(rs.getString("standard"));
                beans.add(adminBean);
            }
            
        
            conn.close();
        }catch (Exception e) {
            e.printStackTrace();
        }
        List<WarehouseBean> results = new ArrayList<WarehouseBean>();
        if(name!="")
        {
            Pattern pattern = Pattern.compile(name);
            for(int i=0;i<beans.size();i++)
            {
                Matcher matcher = pattern.matcher(((WarehouseBean)beans.get(i)).getName());
                if(matcher.find()){
                     results.add(beans.get(i));
                   }
            }
        }
        return results;
    }
    public static int testUpdate1(String xiugainame,String xiuname) throws Exception//???
    {
        int count=0;
        Connection conn = DBUtil.getConn();
        try {
            String sql="update Warehouse set name=? where name=?";
            PreparedStatement preparedStatement=conn.prepareStatement(sql);
            preparedStatement.setString(1, xiuname);
            preparedStatement.setString(2, xiugainame);
            count=preparedStatement.executeUpdate();
            System.out.println(count);
            conn.close();
        }catch (Exception e) {
            e.printStackTrace();
        }
        return count;
    }
    public static int testUpdate2(String xiugainame,String xiufactory) throws Exception//???
    {
        int count=0;
        Connection conn = DBUtil.getConn();
        try {
            String sql="update Warehouse set factory=? where name=?";
            PreparedStatement preparedStatement=conn.prepareStatement(sql);
            preparedStatement.setString(1, xiufactory);
            preparedStatement.setString(2, xiugainame);
            count=preparedStatement.executeUpdate();
            System.out.println(count);
            conn.close();
        }catch (Exception e) {
            e.printStackTrace();
        }
        return count;
    }
    public static int testUpdate3(String xiugainame,String xiumodel) throws Exception//???
    {
        int count=0;
        Connection conn = DBUtil.getConn();
        try {
            String sql="update Warehouse set model=? where name=?";
            PreparedStatement preparedStatement=conn.prepareStatement(sql);
            preparedStatement.setString(1, xiumodel);
            preparedStatement.setString(2, xiugainame);
            count=preparedStatement.executeUpdate();
            System.out.println(count);
            conn.close();
        }catch (Exception e) {
            e.printStackTrace();
        }
        return count;
    }
    public static int testUpdate4(String xiugainame,String xiustandard) throws Exception//???
    {
        int count=0;
        Connection conn = DBUtil.getConn();
        try {
            String sql="update Warehouse set standard=? where name=?";
            PreparedStatement preparedStatement=conn.prepareStatement(sql);
            preparedStatement.setString(1, xiustandard);
            preparedStatement.setString(2, xiugainame);
            count=preparedStatement.executeUpdate();
            System.out.println(count);
            conn.close();
        }catch (Exception e) {
            e.printStackTrace();
        }
        return count;
    }

}

 

库存管理系统

标签:数据库增删改查   size   out   date()   block   pre   ons   4.0   span   

原文地址:https://www.cnblogs.com/zhang12345/p/10117074.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!