/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.yuntong.action.ajaxaction;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.yuntong.service.Y_IRegisterManagerService;

/** 
 * MyEclipse Struts
 * Creation date: 04-14-2007
 * 填加损货信息
 * XDoclet definition:
 * @struts.action validate="true"
 */
public class Y_disrepareInfoAction extends Action {
	private Log log = LogFactory.getLog(Y_FindRegisterByIDAction.class);
	private Y_IRegisterManagerService registerManagerService;
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws IOException {
		response.setContentType("text/xml");
		PrintWriter out = response.getWriter();
			//得到提交信息
			String strRid=request.getParameter("rid");
			String strRoid=request.getParameter("roid");
			String strMoney=request.getParameter("money");
			String cause=request.getParameter("cause");
			log.info("货票编号："+strRid);
			log.info("车次编号："+strRoid);
			log.info("损失金额："+strMoney);
			log.info("损失原因："+cause);
			
			//格式转换
			int roid=1;
			long rid=Long.parseLong(strRid);
			float money=0;
			if(strMoney!=""){
				money=Float.parseFloat(strMoney);
			}
			if(strRoid!=""){
				roid=Integer.parseInt(strRoid);
			}
			//根据业务编号得到货票实际编号
			log.info("货票编号long:"+rid);
			int trueRid=0;
			try{
			 trueRid=registerManagerService.findRegisterID(rid);
			}catch(Exception ex){
				out.print("无此货票");
				out.close();
				return null;
			}
//			根据货票编号查找车次编号
			if(strRoid==""){
				roid=registerManagerService.findRoidByRid(trueRid);
				log.info("--------------车次编号："+roid);
			}
			//填加信息
			try{
			registerManagerService.insertDisrepareInfo(trueRid, roid, money, cause);
			out.print("成功填加损货信息");
			}catch(Exception e){
				out.print("不能插入重复记录");
				out.close();
				return null;
			}
			out.close();
		return null;
	}
	public Y_IRegisterManagerService getRegisterManagerService() {
		return registerManagerService;
	}
	public void setRegisterManagerService(
			Y_IRegisterManagerService registerManagerService) {
		this.registerManagerService = registerManagerService;
	}
}