仓库管理系统(上货、回库)

仓库管理系统(上货、回库)

超市库存系统,库存管理员可登录系统,三次机会,否则需要管理员解锁。仓库管理员可选择入库,上货,回库。入库时,选择已有商品(可通过检索方式),如果已有商品中没有此商品,则可新建。上货:即将库中物品放至超市中。回库:将超市内物品重新放回库中。 物品即将过期时有过期提醒。

上一篇是写了过期提醒,这篇主要写上货和回库,其他功能大都是实现一些基本的增删改查就不一一写了。

首先说一下页面的布局,是使用easyui的面板,将页面分为上、左、中、右、下,只有中部是通过选择左部菜单中的选项,从而打开选项卡变换的,其他模块都是固定不变的。

以下时上货和回库的效果图:


图1.仓库原内库存量 

 



 图2.超市内原货量

 



 图3.上货量超过库存量,发出提醒

 



 图4.上货量为20

 



 图5.上货成功1(库存量减20)

 



 图6.上货成功2(超市内货量加20)

 



 图7.回库量大于超市内货量

 



 图8.回库量30

 



 图9.回库成功1(超市货量减30)

 



 图10.回库成功2(仓库内库存量加30)

 

大致效果如上。

那么下面就说一下上货和回库在dao层实现的方法吧:其实这两个方法大相径庭,上货呢,就只是在批次表中将库存量减前台页面传来的上货量,再将产品表中的货量加上传过来的上货量;回库呢,就是与之相反的操作,即将sql语句中的加减号与上货的反过来即可(下面附上上货方法的代码)。

 

/**
* 根据商品编号,和用户输入的数量,改变该商品的数量,
* 即:增加超市内商品数量,减少库存量,简称上货,
*(*********回库,就是减少 超市呢商品数量,增加库存量***********)
* (由前台js做出判断:若上货的数量超过库存量则给予用户提醒)
* @param proid 商品编号
* @param count 数量
* @return
*/
public boolean changeWarehouse(String proid,int amount){
        //batch 是批次表,sto_amount是库存量
        String sql = "update batch set sto_amount=sto_amount - "+ amount+" where proid="+proid                 +"and sto_amount >="+ amount ;
       //product 是产品表,amount是超市内货量
       String sql2 = "update product set amount=amount + "+ amount+" where proid="+proid ;
       boolean result = false;
       conn = DBUtil.getConn();
       try {
              ps = conn.prepareStatement(sql);
              int count = ps.executeUpdate();
              if(count>0){
                                 ps = conn.prepareStatement(sql2);
                                 int count1 = ps.executeUpdate();
                                 if(count1>0){
                                                       result = true;
                                  }
               }
       } catch (SQLException e) {
                    e.printStackTrace();
       }finally{
                   DBUtil.close(rs, ps, conn);
       }
        return result;
}

  

  接下来是上货的页面代码:

 

 

<a href="#"class="easyui-linkbutton" id="change"
data-options="iconCls:'icon-man',plain:'true'">上货
</a>

 

  当在页面点击 上货 时,会弹出一个window窗口,携带商品编号和需要用户输入的上货量,提交和重置按钮。

回库 代码与之相似)

在script中

$("#change").linkbutton({
width:80,
plain:true,
iconCls:"icon-edit",
onClick:function(){
var rows = $("#mytable").datagrid("getSelections");
if(rows.length != 1){
$.messager.alert("警告框","请选择一行数据进行修改","info");
return;
}else{
$("#batch_window").window({
title:"上货",
width:260,
height:220,
modal:true,//可视化
href:"${pageContext.request.contextPath}/jsp/change.jsp",
queryParams:{"type":"change",
"baid":rows[0].baid,
"sto_amount":rows[0].sto_amount,
"proid":rows[0].pro.proid,
//"proname":rows[0].pro.proname
},
onClose:function(){
$("#mytable").datagrid("reload");
}
});
}
}
});

 

下面是上货界面的代码,回库界面代码与之相似

<%@ page language="java"  pageEncoding="utf-8"%>
<!DOCTYPE HTML>
<html>
  <head>
    <title>上货界面</title>
    <script type="text/javascript" src="easyui/jquery.min.js"></script>
    <script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="easyui/locale/easyui-lang-zh_CN.js"></script>
    <link rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="easyui/themes/icon.css">
  </head>
  
  <body>
  	<script type="text/javascript">
	  	$(function(){
	  		$("#btnSub").linkbutton({//提交按钮
	  			width:80,
	  			iconCls:"icon-save",
	  			onClick:function(){
	  				var rows = $("#mytable").datagrid("getSelections");
	  				var sto_amount = parseInt(rows[0].sto_amount);
	  				var count = parseInt($("#count").val());
	  				if(sto_amount<count){
	  					alert("商品上货数量不能超过库存量!");
	  				}else{
	  					$.ajax({
		  					type:'post',
		  					url:'WarehouseServlet?type=change',
		  				    data:$("form").serialize(),
		  				    success:function(data){
		  				    	$("#mytable").datagrid('reload');
		  				    	$("#batch_window").window('close');
		  				    }
		  				});
	  				}
	  				
	  			}
	  		});
	  		$("#btnSet").linkbutton({//重置按钮
	  			width:80,
	  			iconCls:"icon-cancel",
	  			onClick:function(){
	  				//重置功能
	  				$("#myform")[0].reset();
	  			}
	  		});
	  	});
  	</script>
  
	页面显示内容
  	<div id="mypanel" class="easyui-panel" style="text-align:center;border:0">
  		<form id="myform" action="WarehouseServlet" method="get">
  			<input hidden="hidden" name="type" value="change">
  			 <p>
  				<label for="pro">商品编号:</label>
  				<input type="text" name="pro" class="easyui-numberbox" 
  				value="${param.proid}"/>
  				
  			</p> 		
  			<p>
  				<label for="count">上货量:</label>
  				<input type="text" id = "count" name="count" class="easyui-numberbox" />
  			</p>
  			<p>
  				<a id="btnSub">提交</a>
  				<a id="btnSet">重置</a>
  			</p>
  		</form>
  	</div>
  </body>
</html>

 

最后就是servlet中的代码啦,当用户在页面发出上货(change)的请求,servlet就会调用上货的方法并进行相应的页面跳转,当用户在页面发出回库(back)的请求,servlet也会作出相应的响应。

// 将库存中商品的数量减少放置到超市中的商品数量
else if ("change".equals(type)) {
String proid = request.getParameter("pro");//获取商品编号
int amount = Integer.parseInt(request.getParameter("count"));//获取上货量
boolean result = service.changeWarehouse(proid, amount);
Gson obj = new Gson();
String str = obj.toJson(result);//转gson格式
System.out.println(str);
if (result) {
request.getRequestDispatcher("jsp/search.jsp").forward(request,
response);//跳转页面到查询库存列表页面(即查询批次列表)
} else {
out.print("商品上货数量不能超过库存量!");
}
}

// 将从超市中减少的商品数量添加到仓库中的库存量中
else if ("back".equals(type)) {
String proid = request.getParameter("pro");
int amount = Integer.parseInt(request.getParameter("count"));//获取回货量
boolean result = service.changeMarket(proid, amount);
if (result) {
Gson obj = new Gson();
String str = obj.toJson(result);
System.out.println(str);
request.getRequestDispatcher("jsp/products.jsp").forward(
request, response);//跳转到查询超市商品列表页面(即查询产品表)
} else {
out.print("回库的商品数量不能超过超市内货存量!");
}
}

 

整理得比较凌乱,如有什么不够清楚的地方可以给我评论指出,有什么更好的方法和建议也希望能得到各位大神的指教!

 

猜你喜欢

转载自sunflower-13.iteye.com/blog/2376431