1. 程式人生 > >庫存管理系統

庫存管理系統

 

 

    

首先建立一個包 建立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