📄 instockformevent.java.svn-base
字号:
package com.casin.erp.event;
import com.waveline.webbuilder.event.DefaultContentFormEventImpl;
import com.waveline.webbuilder.struts.ContentFormForm;
import javax.servlet.http.HttpServletRequest;
import com.waveline.webbuilder.exception.ProgramException;
import com.waveline.webbuilder.exception.DataBaseException;
import com.casin.erp.InStock;
import com.waveline.webbuilder.util.FunctionUtil;
import com.casin.erp.Stock;
import com.casin.erp.InStockDetail;
import com.casin.erp.util.StockUtil;
import java.util.List;
import java.text.DecimalFormat;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class InStockFormEvent
extends DefaultContentFormEventImpl
{
public boolean afterInsertForm(HttpServletRequest request,
ContentFormForm contentFormForm,
Object session)
throws DataBaseException, ProgramException
{
if(contentFormForm.getContentObject() instanceof InStock)
{
InStock inStock = (InStock)contentFormForm.getContentObject();
Stock stock = (Stock)FunctionUtil.loadContentObject(Stock.class.getName(),inStock.getStock().getId());
if(inStock.getAmount().intValue() < 1)
{
contentFormForm.setRetMsg("入库数量必须是大于0的正整数。");
throw new ProgramException("入库数量必须是大于0的正整数。");
}
try
{
stock.setAmount(new Integer(stock.
getAmount().intValue() + inStock.getAmount().intValue()));
FunctionUtil.update(stock, false, session);
}
catch(Exception ex)
{
contentFormForm.setRetMsg("核加库存产品数量出现异常");
throw new ProgramException("核加库存产品数量出现异常。");
}
String serial = request.getParameter("serial");
if(inStock.getType().trim().equals("batch")){
//批量输入
int begNo = 0; //定义起始序列起始的数字值。
try{
begNo = Integer.parseInt(serial.substring(serial.length() -
4, serial.length()));
}catch(NumberFormatException ex){
contentFormForm.setRetMsg("你输入的序列号不符合标准,其后四位必须为数字组成。");
return false;
}
serial = serial.substring(0,serial.length()-4);
for (int i = 0; i < inStock.getAmount().intValue();begNo++ , i++)
{
InStockDetail detail = new InStockDetail();
detail.getInStock().setId(inStock.getId());
detail.setName(serial + this.getFomratNo(begNo));
detail.setStatus(new Integer(0));
FunctionUtil.create(detail, true, session);
}
}else if(inStock.getType().trim().equals("single")){
//单个输入
String[] serialArray = serial.split("\r\n");
if (inStock.getAmount().intValue() != serialArray.length)
{
contentFormForm.setRetMsg("入库数量( " +
inStock.getAmount().intValue()
+ " )必须和序列号数量( " +
serialArray.length + " )相等。");
return false;
}
for (int i = 0; i < serialArray.length; i++)
{
InStockDetail detail = new InStockDetail();
detail.getInStock().setId(inStock.getId());
detail.setName(serialArray[i]);
detail.setStatus(new Integer(0));
FunctionUtil.create(detail, true, session);
}
}else{
contentFormForm.setRetMsg("入库的序列号有误。");
return false;
}
}
return true;
}
public boolean afterDeleteForm(HttpServletRequest request,
ContentFormForm contentFormForm,
Object session)
throws DataBaseException, ProgramException
{
if(contentFormForm.getContentObject() instanceof InStock)
{
InStock inStock = (InStock)contentFormForm.getContentObject();
Stock stock = (Stock)FunctionUtil.loadContentObject(Stock.class.getName(),inStock.getStock().getId());
if(inStock.getAmount().intValue() > stock.getAmount().intValue())
{
contentFormForm.setRetMsg("库存产品数量不足,不能取消入库信息。");
return false;
}
StockUtil StockUtil = new StockUtil();
List list = StockUtil.getInStockDetailList(inStock);
for(int i = 0; i < list.size(); i++)
{
InStockDetail detail = (InStockDetail)list.get(i);
if(detail.getStatus() == null || detail.getStatus().intValue() == 1)
{
contentFormForm.setRetMsg("入库产品已被占用,不能取消入库信息。");
return false;
}
}
try
{
stock.setAmount(new Integer(stock.
getAmount().intValue() - inStock.getAmount().intValue()));
FunctionUtil.update(stock, false, session);
}
catch(Exception ex)
{
contentFormForm.setRetMsg("取消核加库存产品数量出现异常");
return false;
}
}
return true;
}
//传一整形返回为四位格式字串
public String getFomratNo(int no)
{
DecimalFormat fmt = new DecimalFormat("0000");
return fmt.format(no);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -