package com.chaoran.lx.thread;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import android.database.Cursor;
import android.os.Handler;
import android.os.Message;

import com.chaoran.db.DBManager;

import flex.messaging.io.ArrayList;

public class LxRunYmupThread implements Runnable {
	private DBManager dbManager;
	private String ymupSql;
	private Map hzData;
	private Handler handler;
    public LxRunYmupThread(DBManager dbManager,String ymupSql,Map hzData,Handler handler){
    	this.dbManager=dbManager;
    	this.ymupSql=ymupSql;
    	this.hzData=hzData;
    	this.handler=handler;
    }
	@Override
	public void run() {
		 System.out.println(dbManager.rsCount("TEMP_BI_DJHZ")+"-=====------------------条");
		dbManager.exeSql("delete from TEMP_BI_DJHZ");
		 System.out.println(dbManager.rsCount("TEMP_BI_DJHZ")+"-=====------------------条");
		String hzSql="insert into TEMP_BI_DJHZ(FIELDNAME,FIELDVALUE) values(?,?)";
	    dbManager.batchSave(hzSql, hzData);
	    Cursor cursor=dbManager.query(ymupSql);
	    String mess=null;
	    if(cursor.moveToFirst()){
	    	mess=cursor.getString(0);
	    }
	    cursor.close();
	    cursor=dbManager.query("select fieldname,fieldvalue from TEMP_BI_DJHZ");
	    ArrayList list=new ArrayList();
	    for(cursor.moveToFirst();!cursor.isAfterLast();cursor.moveToNext()){
	    	HashMap hzMap=new HashMap();
	    	hzMap.put(cursor.getString(0),cursor.getString(1));
	    	list.add(hzMap);
	    }
	    HashMap returnMap=new HashMap();
	    returnMap.put("mes", mess);
	    returnMap.put("hz", list);
	    Message msg = new Message();
	    msg.arg1 = 2;
	    handler.sendMessage(msg);
	    System.out.println(dbManager.rsCount("TEMP_BI_DJHZ")+"-------------------条");
	}
}
