/*
 * 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.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


import com.yuntong.business.vo.Y_FactoryInfoVO;
import com.yuntong.myexception.Y_MyNullResultException;
import com.yuntong.service.Y_IFactoryManagerService;

/** 
 * MyEclipse Struts
 * Creation date: 03-26-2007
 * 收货登记，查询厂商信息
 * XDoclet definition:
 * @struts.action validate="true"
 */
public class Y_SelectFactoryAction extends Action {
	/*
	 * Generated Methods
	 */
	private Y_IFactoryManagerService service;
	
	public Y_IFactoryManagerService getService() {
		return service;
	}

	public void setService(Y_IFactoryManagerService service) {
		this.service = service;
	}

	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Y_MyNullResultException 
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
		//response.setCharacterEncoding("UTF-8");
		response.setContentType("text/xml; charset=UTF-8");
		
		try {
			PrintWriter out = response.getWriter();
			//选择的厂家编号
			String factoryID=request.getParameter("fid");
			int intFactoryID=Integer.parseInt(factoryID);
			
			try{
				
				Y_FactoryInfoVO infoVO=service.findFactoryByID(intFactoryID);						
			//查询结果
			int intFID=infoVO.getFactoryID();
			String FName=infoVO.getFactoryName();
			String FLinkMan=infoVO.getFactoryLinkMan();
			int FAreaID=infoVO.getFactoryAreaID();
			String FAreaName=infoVO.getFactoryAreaName();
			String FPhone=infoVO.getFactoryPhone();
			String FFax=infoVO.getFactoryFax();
			String FPostID=infoVO.getFactoryPostID();
			String FEmail=infoVO.getFactoryEmail();
			String FAddress=infoVO.getFactoryAddress();
			String FInfo=infoVO.getFactoryRemark();
			
			//拼写并打印xml文件
			out.print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
			out.print("<info>");
			//System.out.println(intFID+"");
				//编号
				out.print("<factoryID>");
					out.print(intFID+"");
				out.print("</factoryID>");
				//公司名
				out.print("<factoryName>");
					out.print(FName+"");
				out.print("</factoryName>");
				//联系人
				out.print("<factoryLinkMan>");
					out.print(FLinkMan+"");
				out.print("</factoryLinkMan>");
//				地区编号
				out.print("<FAreaID>");
					out.print(FAreaID+"");
				out.print("</FAreaID>");
//				地区名称
				out.print("<FAreaName>");
					out.print(FAreaName+"");
				out.print("</FAreaName>");
//				联系电话
				out.print("<FPhone>");
					out.print(FPhone+"");
				out.print("</FPhone>");
//				传真
				out.print("<FFax>");
					out.print(FFax+"");
				out.print("</FFax>");
//				邮政编码
				out.print("<FPostID>");
					out.print(FPostID+"");
				out.print("</FPostID>");
//				电子邮件
				out.print("<FEmail>");
					out.print(FEmail+"");
				out.print("</FEmail>");
//				详细地址
				out.print("<FAddress>");
					out.print(FAddress+"");
				out.print("</FAddress>");
//				备注
				out.print("<FInfo>");
					out.print(FInfo+"");
				out.print("</FInfo>");
				out.print("<error>");
				out.print("1");
			out.print("</error>");
			out.print("</info>");
			
			out.close();
			}catch(Exception e){
				out.print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
				out.print("<info>");
					out.print("<error>");
						out.print("无此信息");
					out.print("</error>");
				out.print("</info>");
				
			}
		} catch (IOException e) {
			
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
}