/*
 * 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_ClientInfoVO;
import com.yuntong.myexception.Y_MyNullResultException;
import com.yuntong.service.Y_IClientManagerService;
import com.yuntong.service.Y_IMarketManagerService;
import com.yuntong.service.impl.Y_ClientManagerService;

/** 
 * MyEclipse Struts
 * Creation date: 03-31-2007
 * 
 * XDoclet definition:
 * @struts.action validate="true"
 */
public class Y_FindClientByIDAction extends Action {
	/*
	 * Generated Methods
	 */
	private Y_IMarketManagerService mservice;
	private Y_IClientManagerService service;
	
	public Y_IClientManagerService getService() {
		return service;
	}

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

	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * 根据用户编号得到用户信息
	 * @throws IOException 
	 * @throws Y_MyNullResultException 
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws IOException{
		response.setContentType("text/xml; charset=UTF-8");
		PrintWriter out = response.getWriter();
		String clientID=request.getParameter("sid");
		try{	
		long longClientID=Long.parseLong(clientID);		
		Y_ClientInfoVO vo=service.findById(longClientID);
		
		
		String caddress=vo.getClientAddress();                         //客户地址
		String ccompany=vo.getClientCompany();							//公司名
		String cemail= vo.getClientEmail();								//email
		int cmarketid=vo.getClientMarketID();							//市场编号
		String cmarketname=vo.getClientMarketName();					//市场名称
		String cname=vo.getClientName();								//联系人
		String sphone=vo.getClientPhone();								//电话
		String cpostid=vo.getClientPostID();							//邮政编码
		//根据市场名称查找地区名称
		String areaname=mservice.findAreaNameByMarketName(cmarketname);	//地区名称
		
		
		out.print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		out.print("<info>");
			out.print("<cid>");
				out.print(longClientID+"");
			out.print("</cid>");
			
			out.print("<caddress>");
			out.print(caddress+"");
			out.print("</caddress>");
			
			out.print("<cemail>");
			out.print(cemail+"");
			out.print("</cemail>");
			
			out.print("<ccompany>");
			out.print(ccompany+"");
			out.print("</ccompany>");
		
			out.print("<cmarketname>");
			out.print(cmarketname+"");
			out.print("</cmarketname>");
			
			out.print("<cname>");
			out.print(cname+"");
			out.print("</cname>");
			
			out.print("<sphone>");
			out.print(sphone+"");
			out.print("</sphone>");
			
			out.print("<cpostid>");
			out.print(cpostid+"");
			out.print("</cpostid>");
			
			out.print("<areaname>");
			out.print(areaname+"");
			out.print("</areaname>");
			
			out.print("<error>");
			out.print(1);
			out.print("</error>");
		out.print("</info>");
		}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>");
			
		}
		out.close();
		return null;
	}

	public Y_IMarketManagerService getMservice() {
		return mservice;
	}

	public void setMservice(Y_IMarketManagerService mservice) {
		this.mservice = mservice;
	}
}