package com.activity.chaoran;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import com.sys.SysData;

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

public class SearchThread extends Thread {
	private String fangalx;
	private String functionname;
	private Handler handler;
	private int type;// 0 表示检索方案 1表示 页面修改方案,2表示提取方案

	public SearchThread(String fangalx, String functionname, Handler handler,
			int type) {
		this.fangalx = fangalx;
		this.functionname = functionname;
		this.handler = handler;
		this.type = type;
	}

	public void run() {
		super.run();
		Log.v("SearchThread", "run执行");
		try {
			String url = SysData.url
					+ "/webservice/ServiceInterface?wsdl";
			String method = null;
			if (type == 0) {
				method = "queryZdysql";
			} else if(type==1) {
				method = "selectYmupSql";
			}else if(type==2) {
				method = "selectDjtqFun";
			}
			SoapObject rpc = new SoapObject("", method);
			rpc.addProperty("fangalx", fangalx);
			rpc.addProperty("functionname", functionname);
			HttpTransportSE ht = new HttpTransportSE(url,SysData.timeout);
			ht.debug = true;
			SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
					SoapEnvelope.VER11);
			envelope.bodyOut = rpc;
			envelope.dotNet = true;
			envelope.setOutputSoapObject(rpc);
			ht.call("", envelope);
			if (envelope.getResponse() != null) {// 判断是否返回结果，因为我这个是一个查询操作，是带有返回值的。
				Message msg = new Message();
				msg.obj = org.kobjects.base64.Base64.decode(envelope
						.getResponse().toString());
				msg.arg1 = type;
				handler.sendMessage(msg);
			}
		} catch (Exception e) {
			Message msg = new Message();
			msg.what = -1;
			msg.obj = e.toString();
			handler.sendMessage(msg);
		}
	}
}
