package com.activity.chaoran;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.sys.SysData;

public class ExitThread extends Thread {
	public String gzid;
	public String mxTempTable;
	public Handler handler;
	public String method;

	public ExitThread(String gzid, String mxTempTable, Handler handler,
			String method) {
		this.gzid = gzid;
		this.mxTempTable = mxTempTable;
		this.handler = handler;
		this.method = method;
	}

	public void run() {
		super.run();
		Log.v("SearchThread", "run执行");
		try {
			String url = SysData.url + "/webservice/ServiceInterface?wsdl";
			// method = "exitDj";
			SoapObject rpc = new SoapObject("", method);
			rpc.addProperty("gzid", gzid);
			rpc.addProperty("mxTempTable", mxTempTable);
			HttpTransportSE ht = new HttpTransportSE(url);
			ht.debug = true;
			SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
					SoapEnvelope.VER11);
			envelope.bodyOut = rpc;
			envelope.dotNet = true;
			envelope.setOutputSoapObject(rpc);
			ht.call("", envelope);
			if (handler != null) {
				if (envelope.getResponse() != null) {// 判断是否返回结果，因为我这个是一个查询操作，是带有返回值的。
					Message msg = new Message();
					msg.obj = envelope.getResponse();
					if (method.equals("exitDj")) {
						msg.arg1 = 4;
					} else if (method.equals("queryMx")) {
						msg.arg1 = 5;
					}
					handler.sendMessage(msg);
				} else {
					Message msg = new Message();
					msg.obj = null;
					handler.sendMessage(msg);
				}
			}
		} catch (Exception e) {
			if (handler != null) {
				Message msg = new Message();
				if (method.equals("exitDj")) {
					msg.what = -4;
				} else if (method.equals("queryMx")) {
					msg.what = -5;
				}
				msg.obj = e.toString();
				handler.sendMessage(msg);
//				e.printStackTrace();
			}
		}
	}
}
