/*
 * 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 javax.servlet.http.HttpSession;

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-07-2007
 * 改变货票状态(到货确认)
 * XDoclet definition:
 * @struts.action validate="true"
 */
public class Y_UpdateRegisterTypeAction extends Action {
	private Log log = LogFactory.getLog(Y_UpdateRegisterTypeAction.class);
		private Y_IRegisterManagerService service;
		public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws IOException {
			 response.setContentType("text/html");
			PrintWriter out = response.getWriter();
		//得到当前货票编号，状态
		HttpSession session=request.getSession();
		//如果没有查询信息返回
		if(session.getAttribute("Y_rid")==null||session.getAttribute("Y_sid")==null){
			out.print("请先查询货票");
			return null;
		}
		log.info(session.getAttribute("Y_rid"));
		String strRid=session.getAttribute("Y_rid").toString();
		String strSid=session.getAttribute("Y_sid").toString();				
		int rid= Integer.parseInt(strRid);
		int sid= Integer.parseInt(strSid);
		//判断更新为那种状态
		if(sid==3){
			sid=5;
		}else if(sid==4){
			sid=6;
		}else{
			out.println("此货票为已确认货票或未估价货票");
			return null;
		}
		session.removeAttribute("Y_rid");
		session.removeAttribute("Y_sid");
		try{
		service.updateRegisterType(rid, sid);
		//得到司机，车辆编号
		int did= Integer.parseInt(session.getAttribute("Y_did")+"");
		int cid= Integer.parseInt(session.getAttribute("Y_cid")+"");
		
		//修改车辆司机状态
		log.info("//修改车辆司机状态");
		service.updateCarAndDriver(cid, did);		
		
		out.println("确认成功");
		log.info("更新成功");
		}catch(Exception e){
			e.printStackTrace();
			out.println("此货票为已确认货票或未估价货票");
			log.info("状态更新失败。。。。。。。。。");
		}
		return null;
	}
		public Y_IRegisterManagerService getService() {
			return service;
		}
		public void setService(Y_IRegisterManagerService service) {
			this.service = service;
		}
}
