库存管理系统

    

首先建立一个包 建立Test类和util类

import  Ke.util;
import java.text.DateFormat;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.sql.*;
import java.util.Scanner;
public class Test {
    static Connection conn;
    static PreparedStatement ps = null;
    static ResultSet rs;
    static String sql = "select * from Ku_c";
    static util ut= new util();
    static Scanner in = new Scanner(System.in);
     static int id;
     static String name;//商品名称
     static String name_C;//生产厂家
     static String Xing_hao;//型号
     static String Gui;//规格
     static int num;//数量
     static Date create_date=new Date();
     static String date;
     static String name_Dan;//入库/出库单位
     static String name_peo;//送货提货人
     public static int a_id() {
         return id;
     }
     public static String a_name() {
         return name;
     }
     public static String a_name_C() {
         return name_C;
     }
     public static String a_Xing_hao() {
         return Xing_hao;
     }
     public static String a_Gui() {
         return Gui;
     }
     public static int a_num() {
         return num;
     }
    
     public static Date a_create_date() {
            return create_date;
     }
     public static String a_date() {
         return date;
     } 
     public static String a_name_Dan() {
         return name_Dan;
     } 
     public static String a_name_peo() {
         return name_peo;
     }
public static int add(String Name,int Id,String Name_C,String Xing,String gui,int Num,String Name_Dan,String Name_peo,String Date)
{
     conn= ut.getConn();
     String sql="insert into Ku_c values(?,?,?,?,?,?,?,?,?,?)";
     int b=0;
     try {
         ps=conn.prepareStatement(sql);
         ps.setString(2,Name);
         ps.setInt(1,Id);
         ps.setString(3, Name_C);
         ps.setString(4, Xing);
         ps.setString(5, gui);
         ps.setInt(6, Num);
         ps.setString(8, Name_Dan);
         ps.setString(9, Name_peo);
         create_date=new Date();
         Timestamp t=new Timestamp(create_date.getTime());
         System.out.println(t);
         ps.setTimestamp(7, t);
         ps.setString(10, Date);
         
         /*DateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         String i=df.format(create);
         ps.setString(5, i);*/
         
         //ps.setString(5, i);
         
         int a=ps.executeUpdate();
         if(a>0) {
             b++;
             System.out.println("添加成功");
             
         }
         else {
             System.out.println("添加失败");
         }
     }catch(Exception e) {
         e.printStackTrace();
     }
     try {
         if(ps!=null)ps.close();
         if(conn!=null)conn.close();
     }catch(Exception e2) {
         e2.printStackTrace();
     }
    return b;
}
public static int uqdate(String Name,int Id,String Name_C,String Xing,String gui,int Num,String Name_Dan,String Name_peo,String Date)
{

    int b=0;
    conn=ut.getConn();
    ps=null;
    sql="update Ku_c set id=?,name_C=?,Xing_hao=?,Gui=?,num=?,name_Dan=?,name_peo=?,date=? where name=?";
    try {
         ps=conn.prepareStatement(sql);
         ps.setInt(1,Id);
         ps.setString(2,Name_C);
         ps.setString(3,Xing);
         ps.setString(4,gui);
         ps.setInt(5,Num);
         ps.setString(6,Name_Dan);        
         ps.setString(7,Name_peo);
         ps.setString(8,Date );
         ps.setString(9,Name );
         
         int a=ps.executeUpdate();
         if(a>0) {
             b++;
             System.out.println("修改成功");
             
         }
         else {
             System.out.println("修改失败");
         }
    }catch(Exception e) {
        e.printStackTrace();
    }
    try {
         if(ps!=null)ps.close();
         if(conn!=null)conn.close();
     }catch(Exception e2) {
         e2.printStackTrace();
     }
    return b;
    
}
public static int delete(String A) {
    int b=0;
    conn=ut.getConn();
    ps=null;
    sql="delete from Ku_c where name=?";
    
    try {
        ps=conn.prepareStatement(sql);
        ps.setString(1,A );
        int a=ps.executeUpdate();
         if(a>0) {
             b++;
             System.out.println("删除成功");
             
         }
         else {
             System.out.println("删除失败");
         }
    }catch(Exception e) {
        e.printStackTrace();
    }
    try {
         if(ps!=null)ps.close();
         if(conn!=null)conn.close();
     }catch(Exception e2) {
         e2.printStackTrace();
     }
    return b;
    
}
public static void find_name(String a) {
    conn=ut.getConn();
    ps=null;
    ResultSet rs=null;
    sql="select * from Ku_c where name=?";
    try {
        ps=conn.prepareStatement(sql);
        ps.setString(1, a);
        rs=ps.executeQuery();
        if(rs.next()) {
             id = rs.getInt("id");
             name = rs.getString("name");
             name_C = rs.getString("name_C");
             Xing_hao = rs.getString("Xing_hao");
             Gui = rs.getString("Gui");
             num = rs.getInt("num");
             create_date=rs.getDate("create_date");
             name_Dan = rs.getString("name_Dan");
             name_peo = rs.getString("name_peo");
             date = rs.getString("date");
             
             System.out.println(name+id+name_C+Xing_hao+Gui+num+create_date+name_Dan+name_peo+date);
        }
    }catch(SQLException e) {
        e.printStackTrace();
    }finally {
        try {
             if(ps!=null)ps.close();
             if(conn!=null)conn.close();
         }catch(Exception e2) {
             e2.printStackTrace();
         }
    }
}
public static void find_date(String a) {
    conn=ut.getConn();
    ps=null;
    ResultSet rs=null;
    sql="select * from Ku_c where date=?";
    try {
        ps=conn.prepareStatement(sql);
        ps.setString(1, a);
        rs=ps.executeQuery();
        if(rs.next()) {
             id = rs.getInt("id");
             name = rs.getString("name");
             name_C = rs.getString("name_C");
             Xing_hao = rs.getString("Xing_hao");
             Gui = rs.getString("Gui");
             num = rs.getInt("num");
             create_date=rs.getDate("create_date");
             name_Dan = rs.getString("name_Dan");
             name_peo = rs.getString("name_peo");
             System.out.println(name+id+name_C+Xing_hao+Gui+num+create_date+name_Dan+name_peo+date);
        }
    }catch(SQLException e) {
        e.printStackTrace();
    }finally {
        try {
             if(ps!=null)ps.close();
             if(conn!=null)conn.close();
         }catch(Exception e2) {
             e2.printStackTrace();
         }
    }
}
public static void main(String[] args) {

    //System.out.println("请输入要删除商品");
    System.out.println("请输入查找商品:");
    Scanner scan=new Scanner(System.in);
    String a=scan.next();
    delete(a);
    //find_name(a);
    //find_date(a);
}
}



建立zhu.jsp 主页面

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<%@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=ISO-8859-1" >
<title>Insert title here</title>
<style>
     .a{
         font-size: 26px;
         margin-top: 20px;
     }
</style>
</head>
<body>
<div align= "center" >
         <div class = "a" >
           <a href = "add.jsp" >商品入库</a></br></div>
         <div class = "a" >
<a href = "find.jsp" >商品名查询 </a></br></div>
         <div class = "a" >
<a href = "finddate.jsp" >商品时间查询</a></br></div>
         <div class = "a" >
<a href = "delete.jsp" >商品出库</a></br></div>
         <div class = "a" >
<a href = "update.jsp" >商品修改</a></br></div>
</div>
</body>
</html></html>

  增add.jsp

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<%@page import= "entity.Test" %>
<%@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>
  <form action= "addresult.jsp" method= "post" id= "form"  >
 
  <input type= "hidden" name= "methodName" value= "0" />
 
<h4> 商品名称 :<input type= "text" name= "name" title= "不能为空" ></input><br></h4>
<h4> 成产厂商 :<input type= "text" name= "name_C" title= "不能为空" ></input><br></h4>
<h4> 商品型号(数字) :<input type= "text" name= "id" title= "不能为空" ></input><br></h4>
<h4> 商品规格 :<input type= "text" name= "Gui" title= "不能为空" ></input><br></h4>
<h4> 商品等级 :<input type= "text" name= "Xing_hao" title= "不能为空" ></input><br></h4>
<h4> 商品数量(数字) :<input type= "text" name= "num" title= "不能为空" ></input><br></h4>
<h4> 送货单位 :<input type= "text" name= "name_Dan" title= "不能为空" ></input><br></h4>
<h4> 送货人姓名:<input type= "text" name= "name_peo" title= "不能为空" ></input><br></h4>
<h4> 日期 :<input type= "text" name= "Date" title= "不能为空" ></input><br></h4>
  <input type= "submit" value= "完成" />
    </form>
  
</body>
</html>

  addresult.jsp

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<%@page import= "entity.Test" %>
<%@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>
<%
request.setCharacterEncoding( "utf-8" );
String a=request.getParameter( "id" );
String b=request.getParameter( "num" );
int a_i=Integer.parseInt(a);
int a_s=Integer.parseInt(b);
  if (Test.add(request.getParameter( "name" ),a_i,request.getParameter( "name_C" ),request.getParameter( "Xing_hao" ),request.getParameter( "Gui" ),a_s,request.getParameter( "name_Dan" ),request.getParameter( "name_peo" ),request.getParameter( "Date" ))==1)
  {
      {
          out .print( "<script language = 'javascript'>alert('入库成功');</script>" );
          response.setHeader( "refresh" , "0;url=zhu.jsp" );
             }
  }
  else {
      out .print( "<script language = 'javascript'>alert('入库失败');</script>" );
      response.setHeader( "refresh" , "0;url=zhu.jsp" );
         //out.println("添加失败");
  }
  %>
</body>
</html>

  删 delete.jsp

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<%@page import= "entity.Test" %>
<%@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=ISO-8859-1" >
<title>删除界面</title>
</head>
<body>
<form action= "deleteresult.jsp" method= "post" id= "form" onSubmit= "return validate()" >
 
  <input type= "hidden" name= "methodName" value= "0" />
 
<h4> 商品名称 :<input type= "text" name= "name" title= "不能为空" ></input><br></h4>
<h4> 成产厂商 :<input type= "text" name= "name_C" title= "不能为空" ></input><br></h4>
<h4> 商品型号(数字) :<input type= "text" name= "id" title= "不能为空" ></input><br></h4>
<h4> 商品规格 :<input type= "text" name= "Gui" title= "不能为空" ></input><br></h4>
<h4> 商品等级 :<input type= "text" name= "Xing_hao" title= "不能为空" ></input><br></h4>
<h4> 商品数量(数字) :<input type= "text" name= "num" title= "不能为空" ></input><br></h4>
<h4> 取货单位 :<input type= "text" name= "name_Dan" title= "不能为空" ></input><br></h4>
<h4> 取货人姓名:<input type= "text" name= "name_peo" title= "不能为空" ></input><br></h4>
<h4> 日期 :<input type= "text" name= "Date" title= "不能为空" ></input><br></h4>
<input type= "submit" value= "完成" />
    </form>
  
</body>
</html>

  deleteresult.jsp

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<%@page import= "entity.Test" %>
<%@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>
<%
request.setCharacterEncoding( "utf-8" );
  if (Test.delete(request.getParameter( "name" ))==1)
  {
      {
             out .print( "<script language = 'javascript'>alert('删除成功');</script>" );
             response.setHeader( "refresh" , "0;url=zhu.jsp" );
             }
  }
  else {
      out .print( "<script language = 'javascript'>alert('删除失败');</script>" );
      response.setHeader( "refresh" , "0;url=zhu.jsp" );
         //out.println("添加失败");
  }
  %>
</body>
</html>

  改update.jsp

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<%@page import= "entity.Test" %>
<%@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=ISO-8859-1" >
<title>修改界面</title>
 
</head>
<body>
  <form action= "uqdateresult.jsp" method= "post" id= "form"  >
 
  <input type= "hidden" name= "methodName" value= "0" />
 
<h4> 商品名称 :<input type= "text" name= "name" title= "不能为空" ></input><br></h4>
<h4> 成产厂商 :<input type= "text" name= "name_C" title= "不能为空" ></input><br></h4>
<h4> 商品型号(数字) :<input type= "text" name= "id" title= "不能为空" ></input><br></h4>
<h4> 商品规格 :<input type= "text" name= "Gui" title= "不能为空" ></input><br></h4>
<h4> 商品等级 :<input type= "text" name= "Xing_hao" title= "不能为空" ></input><br></h4>
<h4> 商品数量(数字) :<input type= "text" name= "num" title= "不能为空" ></input><br></h4>
<h4> 送货(取货)单位 :<input type= "text" name= "name_Dan" title= "不能为空" ></input><br></h4>
<h4> 送货(取货)人姓名:<input type= "text" name= "name_peo" title= "不能为空" ></input><br></h4>
<h4> 日期 :<input type= "text" name= "Date" title= "不能为空" ></input><br></h4>
  <input type= "submit" value= "完成" />
    </form>
</body>
</html>

  updateresult.jsp

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<%@page import= "entity.Test" %>
<%@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=ISO-8859-1" >
<title>修改结果</title>
</head>
<body>
<%
request.setCharacterEncoding( "utf-8" );
String a=request.getParameter( "id" );
String b=request.getParameter( "num" );
int a_i=Integer.parseInt(a);
int a_s=Integer.parseInt(b);
  if (Test.uqdate(request.getParameter( "name" ),a_i,request.getParameter( "name_C" ),request.getParameter( "Xing_hao" ),request.getParameter( "Gui" ),a_s,request.getParameter( "name_Dan" ),request.getParameter( "name_peo" ),request.getParameter( "Date" ))==1)
  {
      {
             out .print( "<script language = 'javascript'>alert('修改成功');</script>" );
             response.setHeader( "refresh" , "0;url=zhu.jsp" );
             }
  }
  else {
      out .print( "<script language = 'javascript'>alert('修改失败');</script>" );
      response.setHeader( "refresh" , "0;url=zhu.jsp" );
         //out.println("添加失败");
  }
  %>
</body>
</html>

猜你喜欢

转载自www.cnblogs.com/adret/p/10116946.html