package com.cwbuyer.lib;

import java.io.File;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.cwbuyer.lib.CustActivity.MyAdapter1.ViewHolder;
import com.pwbuyer.main.R;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

@SuppressLint("InflateParams")
public class CustActivity extends Activity {
    Button tv = null;
    ListView lv = null;
    Button btn_selectAll = null;
    Button btn_send = null;
    Button btn_save = null;
    Button btn_calcel = null;
    Button btn_exit = null;    
    private List<HashMap<String, Object>> albun_list = null;
	final String filepath=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+	"/cwbuyer";

    int version = 1;
	int records =0;
	
	String f1[] ={ "CUSTNO", "CUSTNAME", "MOBIL", "DISCOUNT", "EMAIL", "COUNTRY", "PIC", "TRADETYPE", "C1", "C2"};	  

	Bundle bundle;
    Cursor cs;
    //0.大宗相本 1.大宗簡訊 2.大宗郵件
    //外部程式進入本作業時,須帶入 0,0 作配對 Displays 二為陣列判斷式
    // "0""0"(c)只要圖檔存在者都可以納入 "0""1"會員專區用 "0""2"臨時組合
    // "1""0"(s)只要手機存在者都可以納入 "1""1"會員專區用 "1""2"臨時組合    
    // "2""0"(m)只要MAIL存在者都可以納入 "2""1"會員專區用 "2""2"臨時組合    
    String displays[][]={{"C1","C2","C3"},{"S1","S2","S3"},{"M1","M2","M3"}};
    private static final String[] tradeStr = { "","","","","",""};    
	private ArrayList<String> mCountryList = new ArrayList<String>();
	private ArrayList<Integer> mCountryIdList = new ArrayList<Integer>();

    private List<HashMap<String, Object>> list = null;
    private MyAdapter1 adapter1;
    int dismode=0;
    String mKind=null;
    int dispk=0;
    
    //千萬不可以在第一時間就以 getResources().getText(R.string.str_album_send1).toString()方式帶入 
    String[][] dismodeS={    		{"00","01","02"},    		{"10","11","12"},    		{"20","21","22"}};
 
    @SuppressWarnings("unused")
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mainact);

		File myFilepath= new File(filepath);
		if (!myFilepath.exists()){myFilepath.mkdirs(); }
        
        tv = (Button) this.findViewById(R.id.tv);
        lv = (ListView) this.findViewById(R.id.lv);
        btn_selectAll = (Button) this.findViewById(R.id.selectall);
        btn_send = (Button) this.findViewById(R.id.btn_send);
        btn_save = (Button) this.findViewById(R.id.btn_save);        
        btn_calcel = (Button) this.findViewById(R.id.cancel);
        btn_exit = (Button) this.findViewById(R.id.btn_exit);        
        
        dismode=getIntent().getIntExtra("Qcustf",1);
        mKind=getIntent().getStringExtra("Qcust_qkind");
//    dismode= 0"相本管理清單",1"大宗簡訊清單",2"大宗電郵清單"
        
        dismodeS[0][0]=getResources().getText(R.string.str_album_send1).toString();
        dismodeS[0][1]=getResources().getText(R.string.str_album_send2).toString();
        dismodeS[0][2]=getResources().getText(R.string.str_album_send3).toString();
        dismodeS[1][0]=getResources().getText(R.string.str_sms_send1).toString();
        dismodeS[1][1]=getResources().getText(R.string.str_sms_send2).toString();
        dismodeS[1][2]=getResources().getText(R.string.str_sms_send3).toString();
        dismodeS[2][0]=getResources().getText(R.string.str_mail_send1).toString();
        dismodeS[2][1]=getResources().getText(R.string.str_mail_send2).toString();
        dismodeS[2][2]=getResources().getText(R.string.str_mail_send3).toString();

        //		交易價別方式設定 **千萬不可在陣列中一開始就使用轉址參考型別 LINE_51
		tradeStr[0] = getResources().getText(R.string.str_trade_0).toString();
		tradeStr[1] = getResources().getText(R.string.str_trade_1).toString();
		tradeStr[2] = getResources().getText(R.string.str_trade_2).toString();
		tradeStr[3] = getResources().getText(R.string.str_trade_3).toString();
		tradeStr[4] = getResources().getText(R.string.str_trade_4).toString();
		tradeStr[5] = getResources().getText(R.string.str_trade_5).toString();

		getCountryData(this);        
        
        dispk=0; //臨時用
        tv.setText(dismodeS[dismode][dispk]);
        SQLiteDatabase db = Utilis.getDB(this);        
		
		//將在未來針對大宗 簡訊 郵件 像簿等 進行編輯內容的必要條件過濾

		f1[8]=displays[dismode][0]; 
		f1[9]=displays[dismode][dispk]; 
		
        	StringBuffer buf = new StringBuffer();        
        	buf.append("Select * from "+TbName.QCUST);
        	buf.append(" where "+displays[dismode][0]+"=1 and TR='"+mKind.substring(0, 1)+"0'");
			
			cs = db.rawQuery(buf.toString(), null);
			

		 int records=cs.getCount();
			if (records!=0){
				showCheckBoxListView(cs);
				db.close();
				cs.close();
			 } else {
				 // when data not found 表示初始狀態 
				 // 先判斷資料型態 dismode (0)全面掃描圖檔存在的 (1)手機!=null (2)email!=nill 
				 //進行自動建立
//		{ "custno", "custname", "mobil", "discount", "email", "country", "pic", "tradetype", "c1", "c2"};
				 
				 if (buf!=null) buf.delete(0,buf.toString().length());
		        	buf.append("Select * from "+TbName.QCUST );
		        	buf.append(" where TR='"+mKind.substring(0, 1)+"0'");
		        	buf.append(" order by CUSTNAME ");
					
					cs = db.rawQuery(buf.toString(), null);
				 
						records=cs.getCount();
						ContentValues value = new ContentValues();
						
						while (cs.moveToNext()){

			        		String f3[] ={cs.getString(cs.getColumnIndex("CUSTNO"))};
			            	
							if (dismode==0){ //相本
					            File imageFile = new File(cs.getString(cs.getColumnIndex("PIC")));			            	
					            if (imageFile.exists()){ //表示存在著圖檔
					            	value.put(displays[dismode][0], "1");
					            } else { 
					            	value.put(displays[dismode][0], "0");
					            }
							} else if (dismode==1){ //大宗簡訊
								if (cs.getString(cs.getColumnIndex("MOBIL")).length()>=10){ //電話不可留白
					            	value.put(displays[dismode][0], "1");
					            } else {
					            	value.put(displays[dismode][0], "0");
					            }								
							} else if (dismode==2){ //大宗電郵
								if (cs.getString(cs.getColumnIndex("EMAIL")).length()>10){ //電郵不可留白
					            	value.put(displays[dismode][0], "1");
					            } else { 
					            	value.put(displays[dismode][0], "0");
					            }
							}
							int success = db.update(com.cwbuyer.lib.TbName.QCUST, value,	"CUSTNO=?", f3);		
							
						}
						db.close();
						cs.close();
						finish();
			 }		
         
        //全选
        btn_selectAll.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View arg0) {
                for(int i=0;i<list.size();i++){
                    HashMap<String, Object> map = list.get(i);
                    if (map != null) {
                        map.put("item_cb", true);
                    }
                   list.listIterator(i);
                }
                adapter1.notifyDataSetChanged();//注意这一句必须加上，否则checkbox无法正常更新状态
                //資料庫立即維護程式碼
            }
        });
         
        //全不選
        btn_calcel.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {
                for(int i=0;i<list.size();i++){
                    HashMap<String, Object> map = list.get(i);
                    if (map != null) {
                        map.put("item_cb", false);
                    }
                   list.listIterator(i);
                }
                adapter1.notifyDataSetChanged();//注意这一句必须加上，否则checkbox无法正常更新状态
                //資料庫立即維護程式碼
            }
        });

        //加入 VIP OR 臨編
        btn_save.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {
            	//開出AlertDialog 詢問
            	String[] dlgMenu=
    		        {getResources().getText(R.string.str_m_tovip).toString(),getResources().getText(R.string.str_m_totmp).toString()};
    		        new AlertDialog.Builder(CustActivity.this)
    		        .setTitle(getResources().getText(R.string.str_m_tosel).toString())
    		        .setItems(dlgMenu, mListener1)
    		        .setPositiveButton(R.string.str_cancel,
    		        new DialogInterface.OnClickListener()
    		        {
    		          public void onClick(DialogInterface dialog, int which)
    		          {
    		          }
    		        }).show();
            }
        });

        //返回
        btn_exit.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {
            	finish();
            }
        });
        
        
        //切換畫面(清單)(VIP)(臨編)
        tv.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {
            	
            	int serched=0;
        				
				while (dispk<2) {
					dispk++;
    				f1[8]=displays[dismode][0];
    				f1[9]=displays[dismode][dispk];
    		        SQLiteDatabase db = Utilis.getDB(CustActivity.this);    				
    	        	StringBuffer buf = new StringBuffer();        
    	        	buf.append("Select * from "+TbName.QCUST);
    	        	buf.append(" where "+displays[dismode][dispk]+"=1 and TR='"+mKind.substring(0, 1)+"0'");
    				
    				cs = db.rawQuery(buf.toString(), null);

    				if (cs.getCount()!=0){
    					if (dispk==0){
    						btn_save.setText(getResources().getText(R.string.str_m_ins).toString());
    						} else {
    							btn_save.setText(getResources().getText(R.string.str_m_sav).toString());
    						}        						
    					tv.setText(dismodeS[dismode][dispk]);
    					list.clear();
    					serched=1;
  					showCheckBoxListView(cs);
    					break;
    				}
    			db.close();
    			cs.close();
       			}
				if (serched==0){ //都無資料 或dispk==2 即返回管理(第一層)
					dispk=0;
    		        SQLiteDatabase db = Utilis.getDB(CustActivity.this);    				
    	        	StringBuffer buf = new StringBuffer();        
    	        	buf.append("Select * from "+TbName.QCUST);
    	        	buf.append(" where "+displays[dismode][dispk]+"=1 and TR='"+mKind.substring(0, 1)+"0'");    	        	
    				cs = db.rawQuery(buf.toString(), null);
   				
					btn_save.setText(getResources().getText(R.string.str_m_ins).toString());        						
					tv.setText(dismodeS[dismode][dispk]);
					list.clear();
					serched=1;
					showCheckBoxListView(cs);
					db.close();
					cs.close();
				}
   			}
        });

        //加入 .lst檔交給各輸出
        btn_send.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {
            	String myFilePath = filepath+"/cu_albun.lst";
				File myFile = new File(myFilePath); //其目的是為了產生一個新檔案或資料夾
                String keyString[] = { "item_tv" ,"item_tv1" ,"item_tv2" ,"item_tv3" ,"item_tv4" ,"item_tv5" ,"item_iv", "item_cb","item_tv6"};
                albun_list = new ArrayList<HashMap<String, Object>>();
            	
           	if (dismode>0){            	
                for(int i=0;i<list.size();i++){
                    HashMap<String, Object> map = list.get(i);
                    HashMap<String, Object> maps = new HashMap<String, Object>();                        
                    if (map != null && (Boolean)map.get(keyString[7]) ) {
                    		maps.put("eno", (String) map.get(keyString[0]));
                    		maps.put("ename", (String) map.get(keyString[1]));                        		
                    		maps.put("emobil", (String) map.get(keyString[2]));
                    		maps.put("eemail", (String) map.get(keyString[4]));
                    		maps.put("ebars", (String) map.get(keyString[0])+","+(String) map.get(keyString[1])+","+(String) map.get(keyString[2])+","+(String) map.get(keyString[4]));                        		
                    		maps.put("epics", (String) map.get(keyString[8]));                        		
                        albun_list.add(maps);
                    }
                }
              } else { //出圖格式套用採購系統的mkqr中的6*3
            	   for(int i=0;i<list.size();i++){
                       HashMap<String, Object> map = list.get(i);
                       HashMap<String, Object> maps = new HashMap<String, Object>();                        
                       if (map != null && (Boolean)map.get(keyString[7]) ) {
                       		maps.put("eno", (String) map.get(keyString[0]));
                       		maps.put("ename", (String) map.get(keyString[1]));                        		
                       		maps.put("eprice", (String) map.get(keyString[2]));
                       		maps.put("ecolor", (String) map.get(keyString[3]));
                       		maps.put("esize", (String) map.get(keyString[4]));
                       		maps.put("ebars", (String) map.get(keyString[0])+","+(String) map.get(keyString[1])+","+(String) map.get(keyString[2])+","+(String) map.get(keyString[4]));                        		
                       		maps.put("epics", (String) map.get(keyString[8]));                        		
                           albun_list.add(maps);
                       }
                   }
              }   
                 if (albun_list.size()>0){ 
           		FileOutputStream istream = null;
           		ObjectOutputStream os = null;
           		try {
           			istream = new FileOutputStream(myFilePath);
           			os = new ObjectOutputStream(istream);
                       if (albun_list !=null && albun_list.size()>0)
                       { os.writeObject(albun_list); }
           			os.close();
           			istream.close();
           			//進一步 呼叫 MKQR 且需要帶入 myFilePath 才能開啟
           			
           		} catch (Exception e) {

           		}
              }
          
            	//dismode =0 出圖 =1 簡訊 =2 電郵
                 
            	if (dismode==0){ //出圖

            		Bundle bundle = new Bundle();
           			Intent intent = new Intent();
           			bundle = new Bundle();
					bundle.putString("Mkqrs",myFilePath+","+"Cust"+",2");																						
        			intent.setClass(CustActivity.this, Mkqr.class);
        			intent.putExtras(bundle);
        			startActivity(intent);
        			
                  } else if (dismode==1){ //簡訊
            		
           			Intent intent = new Intent();
        			bundle = new Bundle();
        			bundle.putString("Qsms",myFilePath+",sms");
        			intent.setClass(CustActivity.this, Qsms_one.class);
        			intent.putExtras(bundle);
        			startActivity(intent);
        			
                  } else if (dismode==2){//電郵
            		
           			Intent intent = new Intent();
        			bundle = new Bundle();
        			bundle.putString("Qsms",myFilePath+",email");
        			intent.setClass(CustActivity.this, Qsms_one.class);
        			intent.putExtras(bundle);
        			startActivity(intent);
        			
            	}
            }
        });

    }  //主程式段尾部
    
    
    private android.content.DialogInterface.OnClickListener mListener1=new DialogInterface.OnClickListener()
	  {
	    @SuppressWarnings("unused")
		@Override
	    public void onClick(DialogInterface dialog, int which)
	    {
	      // TODO Auto-generated method stub
            String keyString[] = { "item_tv" ,"item_tv1" ,"item_tv2" ,"item_tv3" ,"item_tv4" ,"item_tv5" ,"item_iv", "item_cb","item_tv6"};
            
	        SQLiteDatabase dbs = Utilis.getDB(CustActivity.this);    				
			ContentValues value = new ContentValues();
        	
	      switch(which)
	      {
	        case 0:  //儲存到VIP  c2 m2 s2 
	        	
                for(int i=0;i<list.size();i++){
                    HashMap<String, Object> map = list.get(i);
                    if (map != null) { //update it
		        		String f3[] ={(String) map.get(keyString[0])};
		            	String v1[]= new String[1];
		            	value.clear();
		            	if (dispk==0){ //表示由管理畫面挑選資料後 繼續加入 VIP者
		            		if ((Boolean)map.get(keyString[7])){
		            			v1[0]="1";
		            			
		            			value.put(displays[dismode][1], "1");
								int success = dbs.update(com.cwbuyer.lib.TbName.QCUST, value,	"CUSTNO=?", f3);		
		            			
		            		}
		            	} else {
		            		
		            		if ((Boolean)map.get(keyString[7])){
	            			value.put(displays[dismode][1], "1");
	            			} else 
	            			{
		            			value.put(displays[dismode][1], "0");	            				
	            			}
							int success = dbs.update(com.cwbuyer.lib.TbName.QCUST, value,	"CUSTNO=?", f3);		
		            	}
                   }
                }	
	          break;
	        case 1:   //儲存到臨編  c3 m3  s3
	        	
                for(int i=0;i<list.size();i++){
                    HashMap<String, Object> map = list.get(i);
                    if (map != null) { //update it
		        		String f3[] ={(String) map.get(keyString[0])};
		            	String v1[]= new String[1];
		            	value.clear();
		            	
		            	if (dispk==0){ //表示由管理畫面挑選資料後 繼續加入 VIP者
			            	if ((Boolean)map.get(keyString[7])){
			            		v1[0]="1";
		            			value.put(displays[dismode][2], "1");			            		
								int success = dbs.update(com.cwbuyer.lib.TbName.QCUST, value,	"CUSTNO=?", f3);		
			            	}
			            } else {
			            	if ((Boolean)map.get(keyString[7])){
			            		v1[0]="1";
			            		value.put(displays[dismode][2], "1");
			            		} else {
		            			value.put(displays[dismode][2], "0");			            			
			            			v1[0]="0";
			            		}
							int success = dbs.update(com.cwbuyer.lib.TbName.QCUST, value,	"CUSTNO=?", f3);		
			            }
                    }
                 }	
	          break;
	      }
	      dbs.close();
	      value.clear();
	    }
	  };    
	  

	//事先整理出產地國別	
		public void getCountryData(Context context){
			if(mCountryIdList != null){
				mCountryIdList.clear();
			}
			if(mCountryList != null){
				mCountryList.clear();
			} 
			
			SQLiteDatabase dbc = Utilis.getDB(context);
			Cursor cursor = dbc.rawQuery("select _ID,NAME,PIC from qc_country order by _ID", null);
			if(cursor != null){
				try{
					if(cursor.getCount() > 0){
						cursor.moveToFirst();
						for(int i = 0; i < cursor.getCount(); i++){
							int id = cursor.getInt(cursor.getColumnIndex("_ID"));
							String name = cursor.getString(cursor.getColumnIndex("NAME"));
							mCountryIdList.add(id);
							mCountryList.add(name);
							cursor.moveToNext();
						}
					}
				}catch(Exception e){
					
				}finally{
					
				}
			}
			dbc.close();
			cursor.close();
		}
	  
    public void showCheckBoxListView(Cursor css) {
        list = new ArrayList<HashMap<String, Object>>();

        while (css.moveToNext()) {
            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put("item_tv", css.getString(css.getColumnIndex("CUSTNO")));
            map.put("item_tv1",css.getString(css.getColumnIndex("CUSTNAME")));
            map.put("item_tv2", css.getString(css.getColumnIndex("MOBIL")));
//@@@需將銀行代號 帶入銀行名稱
            int gtrade =css.getInt(css.getColumnIndex("TRADETYPE"));
            int cindex = mCountryIdList.indexOf(css.getInt(css.getColumnIndex("COUNTRY")));
			if(cindex>0){map.put("item_tv3",mCountryList.get(cindex)+tradeStr[gtrade-1]+"("+""+css.getString(css.getColumnIndex("DISCOUNT"))+")"+getResources().getText(R.string.str_discount) );}
			else {
				map.put("item_tv3",tradeStr[gtrade-1]+"("+""+css.getString(css.getColumnIndex("DISCOUNT"))+")"+getResources().getText(R.string.str_discount) );
			}
            map.put("item_tv4", css.getString(css.getColumnIndex("EMAIL")));
            map.put("item_tv5", css.getString(css.getColumnIndex("BANKNAME")));
			
			map.put("item_iv",null);
             if (css.getString(css.getColumnIndex(displays[dismode][dispk])).equalsIgnoreCase("1")) {map.put("item_cb", true);} else {map.put("item_cb", false);}
             map.put("item_tv6", css.getString(css.getColumnIndex("PIC")));
             
            list.add(map);
 
            adapter1 = new MyAdapter1(this, list, R.layout.mainlist,
                    new String[] { "item_tv" ,"item_tv1" ,"item_tv2" ,"item_tv3" ,"item_tv4" ,"item_tv5" ,"item_iv", "item_cb","item_tv6"}, new int[] {
                            R.id.item_tv,R.id.item_tv1,R.id.item_tv2,R.id.item_tv3,R.id.item_tv4,R.id.item_tv5,R.id.item_iv, R.id.item_cb,R.id.item_tv6 });
                            
            lv.setAdapter(adapter1);
            
            lv.setOnItemClickListener(new OnItemClickListener() {
 
                @Override
                public void onItemClick(AdapterView<?> arg0, View view,
                        int position, long arg3) {
                    ViewHolder holder = (ViewHolder) view.getTag();
                    holder.cb.toggle();// 在每次获取点击的item时改变checkbox的状态
                    
                    HashMap<String, Object> map = list.get(position);
                    if (map != null) {
                    	 if (holder.cb.isChecked()){
                    		 map.put("item_cb", true);
                    	 } else {
                    		 map.put("item_cb", false);
                    	 }

                    	    list.listIterator(position);
                       }

                    //資料庫立即維護程式碼
                }
            });
        }
    }
 
    public static class MyAdapter1 extends BaseAdapter {
        public static HashMap<Integer, Boolean> isSelected;
        @SuppressWarnings("unused")
		private Context context = null;
        private LayoutInflater inflater = null;
        private List<HashMap<String, Object>> list = null;
        private String keyString[] = null;
        private String itemString = null; // 记录每个item中textview的值
        @SuppressWarnings("unused")
		private Bitmap itemBitmap = null;
        private Boolean itemBoolean = true;        
        private int idValue[] = null;// id值
 
        public MyAdapter1(Context context, List<HashMap<String, Object>> list,
                int resource, String[] from, int[] to) {
            this.context = context;
            this.list = list;
            keyString = new String[from.length];
            idValue = new int[to.length];
            System.arraycopy(from, 0, keyString, 0, from.length);
            System.arraycopy(to, 0, idValue, 0, to.length);
            inflater = LayoutInflater.from(context);
        }
 
        @Override
        public int getCount() {
            return list.size();
        }
 
        @Override
        public Object getItem(int arg0) {
            return list.get(arg0);
        }
 
        @Override
        public long getItemId(int arg0) {
            return 0;
        }
 
        @SuppressWarnings("unused")
		@Override
        public View getView(int position, View view, ViewGroup arg2) {
            ViewHolder holder = null;
            if (holder == null) {
                holder = new ViewHolder();
                if (view == null) {
                    view = inflater.inflate(R.layout.mainlist, null);
                }
                holder.tv = (TextView) view.findViewById(R.id.item_tv);
                holder.tv1 = (TextView) view.findViewById(R.id.item_tv1);
                holder.tv2 = (TextView) view.findViewById(R.id.item_tv2);
                holder.tv3 = (TextView) view.findViewById(R.id.item_tv3);
                holder.tv4 = (TextView) view.findViewById(R.id.item_tv4);
                holder.tv5 = (TextView) view.findViewById(R.id.item_tv5);                
                holder.iv=(ImageView)view.findViewById(R.id.item_iv);
                holder.cb = (CheckBox) view.findViewById(R.id.item_cb);
                holder.tv6 = (TextView) view.findViewById(R.id.item_tv6);                
                view.setTag(holder);
            } else {
                holder = (ViewHolder) view.getTag();
            }
            HashMap<String, Object> map = list.get(position);
            if (map != null) {
                itemString = (String) map.get(keyString[0]);
                holder.tv.setText(itemString);

                itemString = (String) map.get(keyString[1]);
                holder.tv1.setText(itemString);
                
                itemString = (String) map.get(keyString[2]);
                holder.tv2.setText(itemString);
                
                itemString = (String) map.get(keyString[3]);
                holder.tv3.setText(itemString);
                
                itemString = (String) map.get(keyString[4]);
                holder.tv4.setText(itemString);
                
                itemString = (String) map.get(keyString[5]);
                holder.tv5.setText(itemString);
                
                	 itemString = (String) map.get(keyString[8]);
 	                if(itemString != null && itemString.length() > 0){	                
 	                	if( itemString.indexOf("drawable/") < 0) { 
 	        			Bitmap bmp=Utilis.getLimitBitmap( itemString,30,30);
 	        			if (bmp!=null)holder.iv.setImageBitmap(bmp);
         				} else{ 
 	    	    			holder.iv.setImageResource(R.drawable.m053);
         				}	                
    					} else {
 	    	    			holder.iv.setImageResource(R.drawable.m053);    				
 	    			}                	
               
                itemBoolean = (Boolean)map.get(keyString[7]);
                holder.cb.setChecked(itemBoolean);
                
                itemString = (String) map.get(keyString[8]);
                holder.tv6.setText(itemString);
                
            }

            return view;
        }

     public   class ViewHolder {
            public TextView tv = null;
            public TextView tv1 = null;
            public TextView tv2 = null;
            public TextView tv3 = null;
            public TextView tv4 = null;
            public TextView tv5 = null;
            public CheckBox cb = null;
            public ImageView iv =null;
            public TextView tv6 = null;            
        } 
        

        
    }
    
    
	 @Override
		protected void onResume() {
			// TODO Auto-generated method stub
			super.onResume();
		}

		@Override
		protected void onPause() {
			// TODO Auto-generated method stub
			super.onPause();
		}

		@Override
		protected void onDestroy() {
			// TODO Auto-generated method stub
			super.onDestroy();

		}


}
