package com.cwbuyer.lib;

import java.io.File;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.ExpandableListView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.cwbuyer.adapter.TableAdapter;
import com.cwbuyer.adapter.TableAdapter.TableCell;
import com.cwbuyer.adapter.TableAdapter.TableRow;
import com.cwbuyer.format.IDialog;
import com.cwbuyer.format.KeySet;
import com.cwbuyer.lib.GalleryView.TableRowView;
import com.cwbuyer.main.QPosff.GroupMode;
import com.pwbuyer.main.R;

//銷售王的核心2層式ADAPTER,複製自 MANAGEITEM採購王
@SuppressLint({ "UseSparseArrays", "InflateParams", "HandlerLeak" })
@SuppressWarnings("unused")
public class QRep_03 extends Activity{
	
	ExpandItemAdapter mExpandAdapter = null;	
	
	TextView mTextDuration = null;

	LinearLayout mDisplayStk;
//ACTION 預設模式 POS定義為 銷貨單;預購單;暫存單;單頭+單身	
	
	int mMode = KeySet.SearchMode.DAY;
	
	private final int RESULT_GALLERY=6666; 		//GALLERY
	private LinkedList<GroupData> mGroupList = new LinkedList<GroupData>();	
	
	int mGroupMode = GroupMode.TOP1;  //預設初始到新品 
	final String myImportPath =android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+Utilis.getIni(this, "SYS", "YEAR",7);	
	
	int mCloud=Utilis.toInt(Utilis.getIni(this,"SYS","DEPT_SEND",4));
	String clouds="http://"+Utilis.getIni(QRep_03.this, "SYS", "IMPORT", 1)+File.separator+Utilis.getIni(QRep_03.this, "SYS", "IMPORT", 2)+File.separator;
	String uriAPI1=clouds+"qrep03_1.php";
	String mDept=Utilis.getIni(this,"SYS","DEPT",6);
	public ProgressDialog myDialog = null;
	protected static final int REFRESH_DATA = 0x00000001;
	DecimalFormat df = new DecimalFormat();
	String style = "#,##0";
	
	/** State :  true 正式 , false 樣品*/
	String mEndDay = null;
	String mStartDay = null;
	String mLimitDay = null;//WeiLa七天限制
	int WeiLa=0; //0不限制 1限七天
	String sepa="\r\n";
	String sepaA4=";";
	String CntsSQL="sum(A.ACOST),sum(A.SUBPRICE-A.ACOST) as SUMALL,"; //
	StringBuffer sPrintB = new StringBuffer();
	StringBuffer sPrintA4=new StringBuffer(); 

	int Loca=0;
	int Lgap=230;
	String mTitleP="";
	int PSWD=1;
	int nPart=0;
	String GoodChg="A.GOODSNO";
	String ColorChg="A.COLORS";
	String SizeChg="A.SIZES";
	String ConChg="主貨";
	String SQLADD="(A.QKIND ='30' OR A.QKIND ='31' OR A.QKIND ='40' OR A.QKIND ='41') and A.ISCONFIRM='Y'";
	int CountX=0;//還要製作 統計判斷 //03040 1.只要40 2.只要30
	int deptN=1;
	String [] DepNo;
	String [] DepNa;
	int ColNoSizN=0;
	String [][] ColNoSiz;	
   	int [][] Otott;

   	String [] Season_Array = {"春","夏","秋","冬","四季"};
	//發展為長按而啟動的功能
   	//原則上不變的 統計欄位
   	//"select sum(A.UNIT30),sum(A.UNIT40),sum(A.SUBPRICE),sum(A.ACOST),"
   	String [] sql_A={ 
   			"",
   			" A.USER,B.CUSTNAME,B.PIC from qitems as A  join qcust as B on A.USER=B.CUSTNO",
   			" A.EMPID,A.EMPNAME,B.PIC from qitems as A join qcust as B on A.EMPID=B.CUSTNO",
   			" A.DEPTNO,B.CUSTNAME,B.PIC from qitems as A  join qcust as B on A.DEPTNO=B.CUSTNO",
   			" A.SUPPLY,B.FACTNAME,B.PIC from qitems as A  join qfact as B on A.SUPPLY=B.FACTNO",
   			" A.GOODSTYPE,A.GOODSTYPE,'drawable/icon' from qitems as A",
   			" A.UNIT1,A.COLOR,A.UNIT1 from qitems as A",
   			" A.COUNTRY,B.NAME,B.PIC from qitems as A  join qc_country as B on A.COUNTRY=B.NAME",
   			" A.SIZE,A.SIZE,A.SIZE from qitems as A",
   			" A.SEASON,A.SEASON,A.SEASON  from qitems as A",
   			" A.EMPID,A.EMPNAME,B.PIC from qitems as A join qcust as B on A.EMPID=B.CUSTNO"
   			};
	String[] sql_D={ "A.GOODSNO","A.USER","A.EMPID","A.DEPTNO","A.SUPPLY","A.GOODSTYPE","A.UNIT1","A.COUNTRY","A.SIZE","A.SEASON","A.EMPID"};	
	String[] mode_E={ "","依會員排行", "依櫃員排行","依門市排行","依廠商排行","依類別排行","依顏色排行","依國別排行","依尺寸排行","依季節排行","依薪資排行"};
	String mKind=null; //單別 102030405060
	double sSort=0; //0依金額 1.依件數 2.依毛利
	private String batch;
	
	int nKind=30;
	DatePicker dp1;
	DatePicker dp2;
	
   	String btns=null;
   	String[] bttns;

   	int TT10=0;  	//總進貨量
   	double TM10=0; 	//總進貨額
   	int TT30=0;	//總銷貨量
   	double TM30=0;	//總銷貨額
   	int TS30=0;	//總銷貨額
   	int StkT=0;		//總存貨量
   	double StkM=0;	//總存貨額
   	
   	int T10=0;  	//本進貨量
   	double M10=0; 	//本進貨額
   	int T30=0;		//本銷貨量
   	double M30=0;	//本銷貨額
   	int S30=0;	//本銷貨額
   	double Profit=0; 	//本期毛利
   	double Profits=0; //本期利率
	
	private int mYear1 = 0;
	private int mYear2 = 0;
	private int mMonth1 = 0;
	private int mMonth2 = 0;
	private int mDay1 = 0;
	private int mDay2 = 0;

	class GroupData{ //第一層版面
		public double Sort=0;
		public String strTextG1;  // 左上
		public String strPic;  // 左中
		public String strText1; // 左中 會員編號/名稱 USER/USERNAME
		public String strText2; // 右上  		ASUM/BSUM
		public String strMoney; // 右中 		CASH/CARD
		public String strOriMoney;  //右下ORDCASH/ORDCARD
		public String strTextG2;  // 左下		
		public String SEARCH;  // 左下
	}
	
	class PxData{ //第二層版面
		public double Sort;
		public String iPic;  
		public String iGoods; 
		public String iImpo; 
		public String iName; 
		public String iMoney;
		public String iCountry;
		public String iNumber;
		public String iCompany;
		public String iFormdate;
		
	}
	
//	ListView mListView = null;
	ExpandableListView mExpandListView = null;
	
//For  Table
	int Wheight;
	int Wwidth;
	int tableHeight=30;
	int tabless=6;

	private LinearLayout lTableView = null;
	private LinearLayout mLayoutRoot = null;
	private ArrayList<String> mArrayColorNumber = new ArrayList<String>();
	private ArrayList<String> mArrayColorName = new ArrayList<String>();
	LinkedList<String> mSizeLink = new LinkedList<String>();
	LinkedList<String> mSizeLink1 = new LinkedList<String>();
	LinkedList<String> mColorLink = new LinkedList<String>();
	
	HashMap<Integer,Integer> mCountRow = new HashMap<Integer,Integer>(); // 顏色行資料
	HashMap<Integer,String> mCountCell = new HashMap<Integer,String>();  // 尺寸欄資料
	
	PxData data =null;	
//@@日後需補充用ITEM檢測HEAD是否漏掉的清單,並自動修補	
	public interface GroupMode{//EVERYDAY/WEEK/MONTH 以FORMDATE
		int TOP1 = 1;		//依會員
		int TOP2 = 2;  	//依櫃員
		int TOP3 = 3; 	//依門市
		int TOP4 = 4; 	//依廠商
		int TOP5 = 5; 	//依類別
		int TOP6 = 6; 	//依顏色
		int TOP7 = 7; 	//依尺寸
		int TOP8 = 8; 	//依國別
		int TOP9 = 9; 	//依季節
		int TOPA = 10; 	//依薪資
		
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent dataR) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, dataR);
		
		switch(requestCode){
		
		case 1001:
			{
				if (resultCode == RESULT_OK) {
				}else{
					finish();
				}
				break;
			}
		case RESULT_GALLERY:
			{
				
			}
		}	
    }

	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.qrep03);
        
		DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        Wwidth = dm.widthPixels;
        Wheight = dm.heightPixels;
        lTableView = (LinearLayout)findViewById(R.id.tableview);
		
		tableHeight=(int) (Wheight/24);
		if (Wwidth<=800) tabless=(int) (Wwidth/100)+2; else  tabless=(int) (Wwidth/140)+1;
		
		df.applyPattern(style);
		
        mTextDuration = (TextView)findViewById(R.id.text_duration);
        //@@應增加營業時間的判斷而視為當日或前一天
        mStartDay =DateUtil.getCurrentDate();  //2012/10/15 將 batch 視為當日的關鍵"/"
        mEndDay=mStartDay;
        
        mMode = getIntent().getIntExtra("search_mode", KeySet.SearchMode.DAY);		
        mGroupMode= getIntent().getIntExtra("search_group", GroupMode.TOP3);	
    	//沒有權限又啟動薇菈7日
    	mLimitDay = DateUtil.addDate(mStartDay, -7);
        
//        mMode = getIntent().getIntExtra("search_mode", SearchModeS.WEEK);
        //暫時不開放外部決定哪一種方式 預設為 週
//        nKind =getIntent().getIntExtra("QRep_01", PItemKind.TR10); //預設為進貨單
//        mKind=""+nKind;

        ((Button)findViewById(R.id.btn_exit)).setOnClickListener(new MainClick());		//離開
        
        ((Button)findViewById(R.id.btn_sort_top1)).setOnClickListener(new MainClick()); //依會員
        ((Button)findViewById(R.id.btn_sort_top2)).setOnClickListener(new MainClick()); //依櫃員        
        ((Button)findViewById(R.id.btn_sort_top3)).setOnClickListener(new MainClick()); //依門市
        ((Button)findViewById(R.id.btn_sort_top4)).setOnClickListener(new MainClick()); //依廠商
        ((Button)findViewById(R.id.btn_sort_top5)).setOnClickListener(new MainClick()); //依類別
        ((Button)findViewById(R.id.btn_sort_top6)).setOnClickListener(new MainClick()); //依顏色
        ((Button)findViewById(R.id.btn_sort_top7)).setOnClickListener(new MainClick()); //依國別
        ((Button)findViewById(R.id.btn_sort_top8)).setOnClickListener(new MainClick()); //依尺寸
        ((Button)findViewById(R.id.btn_sort_top9)).setOnClickListener(new MainClick()); //依季節
        ((Button)findViewById(R.id.btn_sort_topa)).setOnClickListener(new MainClick()); //依薪資

        ((Button)findViewById(R.id.btn_prev_date)).setOnClickListener(new MainClick());//上一
        ((Button)findViewById(R.id.btn_next_date)).setOnClickListener(new MainClick());//下一
        
        ((Button)findViewById(R.id.btn_btn0)).setOnClickListener(new MainClick());
        ((Button)findViewById(R.id.btn_btn1)).setOnClickListener(new MainClick());        
        ((Button)findViewById(R.id.btn_btn2)).setOnClickListener(new MainClick());
        ((Button)findViewById(R.id.btn_btn3)).setOnClickListener(new MainClick());
        ((Button)findViewById(R.id.btn_btn4)).setOnClickListener(new MainClick());
        ((Button)findViewById(R.id.btn_btn5)).setOnClickListener(new MainClick());
        mTextDuration.setOnClickListener(new MainClick());

    	mDisplayStk = (LinearLayout)findViewById(R.id.layout_bottom);
    	mDisplayStk.setVisibility(View.GONE);
    	
    	mLayoutRoot = (LinearLayout)findViewById(R.id.root);
        mExpandListView = (ExpandableListView)findViewById(R.id.list_item_expand);    	
        mExpandAdapter = new ExpandItemAdapter(this);
        mExpandListView.setAdapter(mExpandAdapter);
        mExpandListView.setOnChildClickListener(mChildClcik);
        mExpandListView.setOnItemLongClickListener(mLongClickListener);
        
        if (Utilis.getIni(this,"SYS","DEPT",5).equalsIgnoreCase("0")){  //密碼OK 或不用密碼
        	((LinearLayout)findViewById(R.id.layout_top)).setVisibility(View.VISIBLE);
        	PSWD=0;
        }else{
        	((LinearLayout)findViewById(R.id.layout_top)).setVisibility(View.GONE);
            ((Button)findViewById(R.id.btn_sort_top4)).setVisibility(View.GONE); //依廠商
        }
        //原先就是執行一遍 因為不會中途改變模式
        //現在是可以切換
        //只要一切換,都會從最近日期範圍貨最近一批最近一季起算
		//應追加 上一批 的程式
        if (!Utilis.getIni(this,"SYS","DEPT",1).equalsIgnoreCase(Utilis.getIni(this,"SYS","DEPT",6))) nPart=1;  //門市版
        if (PSWD!=0 && Utilis.toInt(Utilis.getIni(this,"SYS","DEPT_SEND",2))==1) WeiLa=1;

        SQLiteDatabase db = Utilis.getDB(this);		
		Cursor cs =db.rawQuery("select CUSTNO,CUSTNAME from qcust where TR='20' and  CUSTNO <>'"+Utilis.getIni(this,"SYS","DEPT",6)+"' order by CUSTNO",null);
		if (cs.getCount()>0){
			deptN=cs.getCount()+1;
			DepNo=new String[deptN];
			DepNa=new String[deptN];
			cs.moveToFirst();
			for (int i=0;i<cs.getCount();i++){
				DepNo[i+1]=cs.getString(0);
				DepNa[i+1]=cs.getString(1);
				cs.moveToNext();
			}
		}else{
			deptN=1;
			DepNo=new String[deptN];
			DepNa=new String[deptN];
		}
		DepNo[0]=Utilis.getIni(this,"SYS","DEPT",6);
		DepNa[0]=Utilis.getIni(this,"SYS","DEPT",7);
		
		db.close();
		cs.close();
        
        
        
        switch(mGroupMode){
        case GroupMode.TOP1:
        	resetButton(R.id.btn_sort_top1);
        	break;
        case GroupMode.TOP2:
        	resetButton(R.id.btn_sort_top2);
        	break;
        case GroupMode.TOP3:
        	resetButton(R.id.btn_sort_top3);
        	break;
        case GroupMode.TOP4:
        	resetButton(R.id.btn_sort_top4);
        	break;
        case GroupMode.TOP5:
        	resetButton(R.id.btn_sort_top5);
        	break;
        case GroupMode.TOP6:
        	resetButton(R.id.btn_sort_top6);
        	break;
        case GroupMode.TOP7:
        	resetButton(R.id.btn_sort_top7);
        	break;
        case GroupMode.TOP8:
        	resetButton(R.id.btn_sort_top8);
        	break;
        case GroupMode.TOP9:
        	resetButton(R.id.btn_sort_top9);
        	break;
        case GroupMode.TOPA:
        	resetButton(R.id.btn_sort_topa);
        	break;
        	
        }
        chkMode();
        
        mExpandListView.setOnScrollListener(new OnScrollListener() {
            public void onScrollStateChanged(AbsListView view,
                    int scrollState) { // TODO Auto-generated method stub
            	if(scrollState==SCROLL_STATE_FLING){
            	     //Toast.makeText(QRep_01.this,"Fling",Toast.LENGTH_SHORT).show();
            	    }else if(scrollState==SCROLL_STATE_IDLE){
            	     //Toast.makeText(QRep_01.this,"Idle",Toast.LENGTH_SHORT).show();
            	    }else if(scrollState==SCROLL_STATE_TOUCH_SCROLL){
                    	mDisplayStk.setVisibility(View.GONE);
            	     Toast.makeText(QRep_03.this,"touch",Toast.LENGTH_SHORT).show();
            	    }            	
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem,int visibleItemCount, int totalItemCount) {

            }
        });
}	
	
	
	
	public void onResume(){
		super.onResume();
		
		
		DBCloud.aa0_aa1_auto_HI(this,nKind);
		
/*		//表示非外來程式 
		getGroupData(QRep_03.this, mStartDay, mEndDay, null, null);
		
		int count =  mExpandAdapter.getGroupCount(); 
		for (int i = 0; i <count ; i++) 
		mExpandListView.collapseGroup(i); 
		mExpandAdapter.notifyDataSetChanged();
*/		
		}
	
	private void setCondition(){
		
		//台頭:CWBuyer銷售王+[進貨]
		//(APos.java)[新增][查詢][編輯] 帶過去的引數
		//現階段可分為:[交易中][統計中]
		
    	switch(mMode){ 
    	
    		case KeySet.SearchMode.BATCH:
    		{
    			mTextDuration.setText("  批號 : " +batch);
    			setTitle(getString(R.string.app_name)+":[依批號]"+mode_E[mGroupMode]+"("+ConChg+")");
	    	break;
    		}
			case KeySet.SearchMode.DAY:
			{
				mTextDuration.setText(" "+ mStartDay + "~" + mEndDay);
    			setTitle(getString(R.string.app_name)+":[依每日]"+mode_E[mGroupMode]+"("+ConChg+")");
				break;
			}
			case KeySet.SearchMode.WEEK:
			{
				mTextDuration.setText(" "+ mStartDay + "~" + mEndDay);
    			setTitle(getString(R.string.app_name)+":[依每週]"+mode_E[mGroupMode]+"("+ConChg+")");
				break;
			}
			case KeySet.SearchMode.MONTH:
			{
				mTextDuration.setText(" "+ mStartDay + "~" + mEndDay);
				setTitle(getString(R.string.app_name)+":[依每月]"+mode_E[mGroupMode]+"("+ConChg+")");
				break;
			}
			default:
			{
				mTextDuration.setText(" "+ mStartDay + "~" + mEndDay);
				setTitle(getString(R.string.app_name)+":[依日期範圍]"+mode_E[mGroupMode]+"("+ConChg+")");
				break;
			}
    	}
	}
	
	// 特別處理 日結單 GROUPS第一層 是以(日/週/月)為統計結算 childs第二層 才是單頭
	//如何分開 日結+單頭  及 單頭+單身 的製作就是關鍵
	public void getGroupData(Context context, String startDay, String endDay, String condition, String conditionValue) {
				
		if (mGroupList != null) {
			mGroupList.clear();
		}
			
			try {
				StringBuffer bufCategory = new StringBuffer();
				if(startDay != null && startDay.length() > 0)	startDay = startDay.replace("/", "-");
				if(endDay != null && endDay.length() > 0) endDay = endDay.replace("/", "-");

				T10=0;  	 M10=0; 	T30=0;	M30=0;
				TT10=0;  TM10=0; 	TT30=0;	TM30=0;
				TS30=0;	 StkT=0;		StkM=0;	
				Profit=0; Profits=0; 

				bufCategory=bufCategory.delete(0, bufCategory.toString().length());
				
				if (mGroupMode==10) 
					CntsSQL="sum(A.P2*A.UNIT30),sum(A.SUBPRICE-(A.P2*A.UNIT30)) as SUMALL,";
				else  
					CntsSQL="sum(A.ACOST),sum(A.SUBPRICE-A.ACOST) as SUMALL,";
				
				bufCategory.append("select sum(A.UNIT30) as SUM30,sum(A.UNIT40),sum(A.SUBPRICE) as SUMSUB,"+CntsSQL); //總件數,總實應收,總成本
					bufCategory.append(sql_A[mGroupMode]);
					if (mMode!=KeySet.SearchMode.BATCH){					
						bufCategory.append(" where A.FORMDATE >= '").append(startDay).append("'")
						.append(" and A.FORMDATE <= '").append(endDay).append("'");
					}else {
						bufCategory.append(" where A.BATCH = '").append(batch).append("'");
					}
					bufCategory.append(" and "+SQLADD);
					if (nPart==1){
						bufCategory.append(" and A.DEPTNO ='"+Utilis.getIni(this,"SYS","DEPT",1)+"'");
					}
					bufCategory.append(" group by "+sql_A[mGroupMode].substring(1,sql_A[mGroupMode].indexOf(" from"))+" order by");
					if (sSort==0)
						bufCategory.append(" SUMSUB desc");
					else if (sSort==1)
						bufCategory.append(" SUM30 desc");
					else
						bufCategory.append(" SUMALL desc");
						
					//Toast.makeText(QRep_03.this,bufCategory.toString() , Toast.LENGTH_SHORT).show();
					

					if  (Utilis.haveInternet(QRep_03.this) && Utilis.toInt(Utilis.getIni(QRep_03.this, "SYS", "IMPORT", 3))==1 && mCloud>0){
						StringBuffer bfstr = new StringBuffer();
						StringBuffer bfstrF = new StringBuffer();
						
							bfstr.append(Utilis.getIni(QRep_03.this, "SYS", "IMPORT", 2)).append(";");
							bfstrF.append("UID").append(";");
							bfstr.append(""+sSort).append(";");
							bfstrF.append("SORT").append(";");
							bfstr.append(GoodChg).append(";");
							bfstrF.append("GOODCHG").append(";");
							
							if (nPart==1) bfstr.append(Utilis.getIni(this,"SYS","DEPT",1)).append(";"); else bfstr.append("").append(";"); 
							bfstrF.append("DEPTNO").append(";"); 
							
							bfstr.append(startDay).append(";");
							bfstrF.append("STARTDAY").append(";");
							bfstr.append(endDay).append(";");
							bfstrF.append("ENDDAY").append(";");
							bfstr.append(bufCategory.toString()).append(";");
							bfstrF.append("SQLADD").append(";");  

							bfstr.append(SQLADD).append(";");
							bfstrF.append("SQLSTR").append(";"); 

							if (mMode==KeySet.SearchMode.BATCH) bfstr.append(batch).append(";");
							else bfstr.append("").append(";");
							bfstrF.append("BATCH").append(";"); 

							bfstr.append(sql_D[mGroupMode]).append(";");
							bfstrF.append("SQLD").append(";");
							
							bfstr.append(ColorChg).append(";");
							bfstrF.append("COLORCHG").append(";");
							
							bfstr.append(SizeChg);
							bfstrF.append("SIZECHG"); 
							
							final String []fields=bfstr.toString().split(";");
							final String []fieldFs=bfstrF.toString().split(";");
							
						      myDialog = ProgressDialog.show(QRep_03.this,"資料處理中.....","請稍候.............",true);//		setAutoRotationMode();			  
							  
						      new Thread()
						      { 
						        public void run()
						        { 
						          try
						          { 
										HttpPost httpRequest = new HttpPost(uriAPI1);
										// Post運作傳送變數必須用NameValuePair[]陣列儲存
										Log.i("DOWNLOAD_2", "呼叫執行緒PHP___到此一遊"+uriAPI1);

										
										List<NameValuePair> params = new ArrayList<NameValuePair>();
										for(int x=0;x<fields.length;x++){
											params.add(new BasicNameValuePair(fieldFs[x], fields[x]));
										}
										try {
											// 發出HTTP request(請求) 
											httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
											// 取得HTTP response(回傳) 
											HttpResponse httpResponse = new DefaultHttpClient()
													.execute(httpRequest);
											if (httpResponse.getStatusLine().getStatusCode() == 200)
											{
												// 取出回應字串
												String strResult = EntityUtils.toString(httpResponse.getEntity());
												mHandlerQDR_31.obtainMessage(REFRESH_DATA, strResult).sendToTarget();
											}
											
										} catch (Exception e)
										{
											e.printStackTrace();
										}

						          }
						          catch (Exception e)
						          {
						            e.printStackTrace();
						          }
						          finally
						          {
						            // 卸載所建立的myDialog物件。
						            myDialog.dismiss();
						          }
						        }
						      }.start(); 
					}else{	
					//單機統計
				SQLiteDatabase db = Utilis.getDB(context);
				Cursor cursorGroup = null;
				LinkedList<GroupData> groups = new LinkedList<GroupData>();
				LinkedList<List<PxData>> childs = new LinkedList<List<PxData>>();

 				cursorGroup = db.rawQuery(bufCategory.toString(), null);
				if (cursorGroup != null) {
					if (cursorGroup.getCount() > 0) {
						cursorGroup.moveToFirst();
						for (int i = 0; i < cursorGroup.getCount(); i++) {
							GroupData data = new GroupData();
							data.SEARCH = cursorGroup.getString(5);
							
							T30=cursorGroup.getInt(0)+cursorGroup.getInt(1);//總件數
							TT30=TT30+T30;
							
							M30=cursorGroup.getDouble(2);//總金額
							TM30=TM30+M30;
							
							M10=cursorGroup.getDouble(3);//總成本
							TM10=TM10+M10;
							
							data.strText2="銷:"+df.format(T30)+"件";							
							data.strOriMoney="銷$:"+df.format(M30);

								if (M30 >0 && PSWD==0)	{
									data.strTextG2="成本$:"+df.format(M10); //總成本strTextG2
									data.strMoney="毛:$"+df.format((M30-M10))+"/"+df.format(Math.round((M30-M10)*100/M30))+"%";
								} else {
									data.strMoney="毛:xxxxxx";
								}
								
								if (sSort==0)	data.Sort=M30; 
								else if (sSort==1)	data.Sort=T30; 
								else if (sSort==2)	data.Sort=M30-M10;
								
			 				StkT=TT30;  //總銷貨量
			 				StkM=TM30; //總銷金額
			 				Profit=TM30-TM10; //總毛利
			 				Profits=Math.round(Profit*100/TM30); //總毛利率
							data.strPic=cursorGroup.getString(7);  //圖片
							data.strTextG1=cursorGroup.getString(5); //主題一
							data.strText1=cursorGroup.getString(6); //主題二
					 				
		 					groups.add(data);
							cursorGroup.moveToNext();

						}	
 					}	
 				}
				cursorGroup.close();
				
 				((TextView)findViewById(R.id.text_t10)).setText(""+df.format(StkT)+"件");//總進->銷件
 				((TextView)findViewById(R.id.text_r10)).setText("$:"+df.format(StkM));  //盈虧 ->銷額
 				((TextView)findViewById(R.id.text_t30)).setText("$:"+df.format(TM10));  //本銷->毛利
 				((TextView)findViewById(R.id.text_r30)).setText("$:"+df.format(Profit)+"/"+df.format(Profits)+"%");
 				
			
			if (groups.size() > 0) {  //製作第二層因為進10出20銷30櫃40 件數 金額 預購 
				StringBuffer bufList = new StringBuffer();
//				Toast.makeText(QRep_03.this, "groups_size="+groups.size(), Toast.LENGTH_SHORT).show();				
				for (int i = 0; i < groups.size(); i++) {
						bufList.delete(0, bufList.length());
						bufList.append("select sum(A.UNIT30) as SUM30,sum(A.UNIT40),sum(A.SUBPRICE) as SUMSUB,"+CntsSQL); //總件數,總實應收,總成本
						bufList.append(GoodChg+",A.GOODSNAME,A.PIC,"+ColorChg+","+SizeChg)
						.append(" from qitems A");
						if (mMode!=KeySet.SearchMode.BATCH){
							bufList.append(" where A.FORMDATE >= '").append(startDay).append("'")
							.append(" and A.FORMDATE <= '").append(endDay).append("'");
						}else {
							bufList.append(" where A.BATCH = '").append(batch).append("'");
						}
						bufList.append(" and "+SQLADD);
						if (nPart==1){
							bufList.append(" and A.DEPTNO ='"+Utilis.getIni(this,"SYS","DEPT",1)+"'");
						}  //比對主題
						bufList.append(" and "+sql_D[mGroupMode]+"='"+groups.get(i).SEARCH+"'");						
						bufList.append(" group by "+GoodChg+",A.GOODSNAME,A.PIC,"+ColorChg+","+SizeChg+" order by ");

						if (sSort==0)
							bufList.append(" SUMSUB desc");
						else if (sSort==1)
							bufList.append(" SUM30 desc");
						else
							bufList.append(" SUMALL desc");
						
						//單機
						Cursor cursor = db.rawQuery(bufList.toString(), null);
						List<PxData> listData = new ArrayList<PxData>();							
					if (cursor != null) {
//						Toast.makeText(QRep_03.this, "qitems"+cursor.getCount(), Toast.LENGTH_SHORT).show();						
						if (cursor.getCount() > 0) {
							cursor.moveToFirst();
							for (int k = 0; k < cursor.getCount(); k++) {
								
								data=new PxData();

								data.iGoods = cursor.getString(cursor.getColumnIndex(GoodChg.replace("A.", "")));
								data.iName = cursor.getString(cursor.getColumnIndex("GOODSNAME"));
								data.iPic=cursor.getString(cursor.getColumnIndex("PIC"));
								data.iImpo ="銷:"+ df.format((cursor.getInt(0)+cursor.getInt(1)))+"件/$"+ df.format(cursor.getDouble(2));
								if (PSWD==0)
									data.iMoney ="銷:$"+ df.format(cursor.getDouble(2))+"("+df.format(cursor.getDouble(3))+")";
								else
									data.iMoney ="銷:$"+ df.format(cursor.getDouble(2));
								
								M10=cursor.getDouble(3);
								M30=cursor.getDouble(2);
								data.iCountry=cursor.getString(8);
								data.iNumber=cursor.getString(9);

								if (M30 >0 && PSWD==0)	{
									data.iCompany="毛:$"+df.format(M30-M10)+"/"+df.format(Math.round((M30-M10)*100/M30))+"%";
								} else {
									data.iCompany="毛:xxxxxx";
								}
								if (sSort==0)	data.Sort=cursor.getDouble(2); 
								else if (sSort==1)	data.Sort= (cursor.getInt(0)+cursor.getInt(1)); 
								else if (sSort==2)	data.Sort=M30-M10;
								
			 					listData.add(data);
				 				cursor.moveToNext();
							}
							childs.add(listData);
						}
					}
					cursor.close();	
				}
			}
				db.close();
				mExpandAdapter.setData(groups, childs);
				mExpandAdapter.notifyDataSetChanged();
			}

			} catch (Exception e) {
				e.printStackTrace();
			}
			
	}
	
	private LongClick mLongClickListener = new LongClick();

	
	class LongClick implements OnItemLongClickListener {
		@SuppressWarnings("static-access")
		@Override
		 public boolean onItemLongClick(AdapterView<?> parent, View childView,int flatPos, long id) {  			
                long packedPos = ((ExpandableListView) parent).getExpandableListPosition(flatPos);  
                final int groupPosition = mExpandListView.getPackedPositionGroup(packedPos);
                final int childPosition = ExpandableListView.getPackedPositionChild(id);
				final String compStr[]=Utilis.getIni(QRep_03.this,"USER","COMPANY",9).split("!&!");

				sPrintB.delete(0, sPrintB.toString().length());
				Loca=0;
				sPrintB.append("^QXXXX,0,0"+sepa);
				if (Utilis.toInt(compStr[8])<3){												
					sPrintB.append("^W56"+sepa);
				}else{
					sPrintB.append("^W75"+sepa);
					Lgap=280;
				}
				sPrintB.append("^H8"+sepa+"^P1"+sepa+"^S4"+sepa+"^AD"+sepa+"^C1"+sepa+"^R0"+sepa+"~Q+0"+sepa
				+"^O0"+sepa+"^D0"+sepa+"^E11"+sepa+"~R20"+sepa+"^L"+sepa+"Dy2-me-dd"+sepa+"Th:m:s"+sepa);
				Loca=Loca+30;
				Loca=Loca+2;sPrintB.append("AZ,30,"+Loca+",1,2,0,0,"+compStr[0]+"  銷售分析"+sepa);
				Loca=Loca+50;sPrintB.append("AZ,10,"+Loca+",1,2,0,0,"+getTitleP(mGroupMode)+" "+mStartDay+"～"+ mEndDay+sepa);
				Loca=Loca+20;sPrintB.append("AZ,10,"+Loca+",1,2,0,0,-------------------------------------------------"+sepa);
				Loca=Loca+5;sPrintB.append("AZ,10,"+Loca+",1,2,0,0,-------------------------------------------------"+sepa);
                
                if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
        			String [] Lmenu={"印製總表(不印明細)","印製總表(含所有明細)","印製總表(不印明細)A4","印製總表(含所有明細)A4","返回"};
	    			DialogUtilis.showDialog(QRep_03.this, "請選擇以下功能", -1,
	    					Lmenu, new IDialog() {
	    						@Override
	    						public void onDialogFinish(int pos, String choice) {
	    							switch (pos) {
		    								case 0: //印製總表(不印明細)
		    								{
	    						    			//GroupData datag =mExpandAdapter.groups.get(groupPosition);
												Loca=Loca+40;sPrintB.append("AZ,10,"+Loca+",1,2,0,0,"+"總銷: "+df.format(StkT)+"件"+sepa);
												sPrintB.append("AZ,"+Lgap+","+Loca+",1,2,0,0,"+"$ "+df.format(StkM)+sepa);
												Loca=Loca+50;sPrintB.append("AZ,10,"+Loca+",1,2,0,0,"+"成本:$ "+df.format(TM10)+sepa);
												sPrintB.append("AZ,"+Lgap+","+Loca+",1,2,0,0,"+"毛利 "+df.format(Profit)+"/"+df.format(Profits)+"%"+sepa);
												Loca=Loca+20;sPrintB.append("AZ,10,"+Loca+",1,2,0,0,-------------------------------------------------"+sepa);
												Loca=Loca+5;sPrintB.append("AZ,10,"+Loca+",1,2,0,0,-------------------------------------------------"+sepa);
												Loca=Loca+10;
												int count =  mExpandAdapter.getGroupCount(); //得知總筆數
												for (int g=0;g<count;g++){
													GroupData datag =mExpandAdapter.groups.get(g);
													Loca=Loca+25;sPrintB.append("AZ,10,"+Loca+",1,1,0,0,"+datag.strTextG1+sepa);													
													sPrintB.append("AZ,"+Lgap+","+Loca+",1,1,0,0,"+datag.strText2+sepa);
													Loca=Loca+25;sPrintB.append("AZ,10,"+Loca+",1,1,0,0,"+datag.strText1+sepa);													
													sPrintB.append("AZ,"+Lgap+","+Loca+",1,1,0,0,"+datag.strOriMoney+sepa);
													Loca=Loca+25;sPrintB.append("AZ,10,"+Loca+",1,1,0,0,"+datag.strTextG2+sepa);													
													sPrintB.append("AZ,"+Lgap+","+Loca+",1,1,0,0,"+datag.strMoney+sepa);
													Loca=Loca+15;sPrintB.append("AZ,10,"+Loca+",1,1,0,0,-------------------------------------------------"+sepa);
													if (Loca>2400){
														PosUtilis.startPartPrint(QRep_03.this,sPrintB,Loca );
														sPrintB.delete(0, sPrintB.toString().length());
														SystemClock.sleep(3000);
														sPrintB=PosUtilis.getPrintKind(QRep_03.this,Utilis.toInt(compStr[8]));
														Loca=0;
													}
													
												}
												sPrintB.append("AZ,10,"+Loca+",1,2,0,0,-------------------------------------------------"+sepa);
								    			Loca=Loca+80;
								    			//呼叫 開始列印 BarCodePrinter Socket
								    			PosUtilis.startPrint(QRep_03.this,sPrintB,Loca );
								    			
		    									break;
	    									}
		    								case 1: //印製總表(所有明細)
		    								{
												Loca=Loca+40;sPrintB.append("AZ,10,"+Loca+",1,2,0,0,"+"總銷: "+df.format(StkT)+"件"+sepa);
												sPrintB.append("AZ,"+Lgap+","+Loca+",1,2,0,0,"+"$ "+df.format(StkM)+sepa);
												Loca=Loca+50;sPrintB.append("AZ,10,"+Loca+",1,2,0,0,"+"成本:$ "+df.format(TM10)+sepa);
												sPrintB.append("AZ,"+Lgap+","+Loca+",1,2,0,0,"+"毛利 "+df.format(Profit)+"/"+df.format(Profits)+"%"+sepa);
												Loca=Loca+20;sPrintB.append("AZ,10,"+Loca+",1,2,0,0,-------------------------------------------------"+sepa);
												Loca=Loca+5;sPrintB.append("AZ,10,"+Loca+",1,2,0,0,-------------------------------------------------"+sepa);
												Loca=Loca+10;
												int count =  mExpandAdapter.getGroupCount(); //得知總筆數
												for (int g=0;g<count;g++){
													GroupData datag =mExpandAdapter.groups.get(g);
													Loca=Loca+25;sPrintB.append("AZ,10,"+Loca+",1,1,0,0,"+datag.strTextG1+sepa);													
													sPrintB.append("AZ,"+Lgap+","+Loca+",1,1,0,0,"+datag.strText2+sepa);
													Loca=Loca+25;sPrintB.append("AZ,10,"+Loca+",1,1,0,0,"+datag.strText1+sepa);													
													sPrintB.append("AZ,"+Lgap+","+Loca+",1,1,0,0,"+datag.strOriMoney+sepa);
													Loca=Loca+25;sPrintB.append("AZ,10,"+Loca+",1,1,0,0,"+datag.strTextG2+sepa);													
													sPrintB.append("AZ,"+Lgap+","+Loca+",1,1,0,0,"+datag.strMoney+sepa);
													Loca=Loca+15;sPrintB.append("AZ,10,"+Loca+",1,1,0,0,-------------------------------------------------"+sepa);
													Loca=Loca+5;sPrintB.append("AZ,10,"+Loca+",1,1,0,0,-------------------------------------------------"+sepa);

													int countC =  mExpandAdapter.getChildrenCount(g);
													
									    			for (int i = 0; i <countC ; i++){
									    				PxData data =mExpandAdapter.getData(g, i);
														Loca=Loca+25;  //
														sPrintB.append("AZ,20,"+Loca+",1,1,0,0,"+data.iGoods+sepa);
														sPrintB.append("AZ,"+Lgap+","+Loca+",1,1,0,0,"+data.iImpo+sepa);
														Loca=Loca+25;  //
														sPrintB.append("AZ,20,"+Loca+",1,1,0,0,"+data.iName+sepa);
														sPrintB.append("AZ,"+Lgap+","+Loca+",1,1,0,0,"+data.iMoney+sepa);				
														Loca=Loca+25;  //
														sPrintB.append("AZ,20,"+Loca+",1,1,0,0,"+data.iCompany+"  ("+data.iCountry+data.iNumber+")"+sepa);
														if (i<(countC-1)){
														Loca=Loca+12;  //
														sPrintB.append("AZ,20,"+Loca+",1,1,0,0,"+"-------------------------------------------------"+sepa);
														}
									    			}
													if (g<(count-1)){
										    			Loca=Loca+5;sPrintB.append("AZ,10,"+Loca+",1,2,0,0,"+"-------------------------------------------------"+sepa);
										    			Loca=Loca+5;sPrintB.append("AZ,10,"+Loca+",1,2,0,0,"+"-------------------------------------------------"+sepa);
														Loca=Loca+10;
													}
													if (Loca>2400){
														PosUtilis.startPartPrint(QRep_03.this,sPrintB,Loca );
														sPrintB.delete(0, sPrintB.toString().length());
														SystemClock.sleep(3000);
														sPrintB=PosUtilis.getPrintKind(QRep_03.this,Utilis.toInt(compStr[8]));
														Loca=0;
													}
												}
												Loca=Loca+1;sPrintB.append("AZ,10,"+Loca+",1,2,0,0,-------------------------------------------------"+sepa);
												Loca=Loca+5;sPrintB.append("AZ,10,"+Loca+",1,2,0,0,-------------------------------------------------"+sepa);
								    			Loca=Loca+80;
								    			//呼叫 開始列印 BarCodePrinter Socket
								    			PosUtilis.startPrint(QRep_03.this,sPrintB,Loca );
		    									
		    									break;
	    									}
		    								case 2: //印製總表(不印明細)A4
		    								{
		    									sPrintA4.delete(0, sPrintA4.toString().length());
		    									StringBuffer sPrintA4T=new StringBuffer(); 
		    									sPrintA4T.append(compStr[0]+"  銷售分析"+sepaA4);
		    									sPrintA4T.append(getTitleP(mGroupMode)+" "+mStartDay+"～"+ mEndDay+sepaA4);
												sPrintA4T.append("總銷: "+df.format(StkT)+"件"+sepaA4);
												sPrintA4T.append("$ "+df.format(StkM)+sepaA4);
												sPrintA4T.append("成本:$ "+df.format(TM10)+sepaA4);
												sPrintA4T.append("毛利 "+df.format(Profit)+"/"+df.format(Profits)+"%"+sepaA4);
												int count =  mExpandAdapter.getGroupCount(); //得知總筆數
												for (int g=0;g<count;g++){
													GroupData datag =mExpandAdapter.groups.get(g);
													sPrintA4.append(datag.strTextG1+sepaA4);													
													sPrintA4.append(datag.strText1+sepaA4);													
													sPrintA4.append(datag.strText2+sepaA4);
													sPrintA4.append(datag.strOriMoney+sepaA4);
													sPrintA4.append(datag.strTextG2+sepaA4);													
													sPrintA4.append(datag.strMoney+sepaA4);
								    				sPrintA4.append(";SSSS"+"\r\n");
													sPrintA4.append(";HHHH"+"\r\n");
												}
												Intent intent = new Intent();
												//bundle.putString("Mkqrs" , "STD,"+mKind+",11,"+mDept+","+sPrintA4T.toString()+","+sPrintA4.toString());
												intent.putExtra("SERCH",mStartDay+"~"+mEndDay+" 銷售分析 "+mode_E[mGroupMode]+"("+ConChg+")");
												intent.putExtra("QKIND",""+nKind);
												intent.putExtra("MODE",11);
												intent.putExtra("DEPTNO",mDept);
												intent.putExtra("BUFSTR",sPrintA4.toString());
												intent.putExtra("BUFTITLE",sPrintA4T.toString());
												intent.putExtra("STARTDAY",mode_E[mGroupMode]);
												intent.putExtra("ENDDAY",mEndDay);
												Toast.makeText(QRep_03.this,mode_E[mGroupMode]+"("+ConChg+")",Toast.LENGTH_SHORT).show();
												intent.setClass(QRep_03.this, MkqrSt.class);
												startActivity(intent);
		    									
		    									break;
	    									}
		    								case 3: //印製總表(所有明細)A4
		    								{
		    									sPrintA4.delete(0, sPrintA4.toString().length());
		    									StringBuffer sPrintA4T=new StringBuffer(); 
		    									sPrintA4T.append(compStr[0]+mode_E[mGroupMode]+"("+ConChg+")"+sepaA4);
		    									sPrintA4T.append(getTitleP(mGroupMode)+" "+mStartDay+"～"+ mEndDay+sepaA4);
												sPrintA4T.append("總銷: "+df.format(StkT)+"件"+sepaA4);
												sPrintA4T.append("$ "+df.format(StkM)+sepaA4);
												sPrintA4T.append("成本:$ "+df.format(TM10)+sepaA4);
												sPrintA4T.append("毛利 "+df.format(Profit)+"/"+df.format(Profits)+"%"+sepaA4);
												int count =  mExpandAdapter.getGroupCount(); //得知總筆數
												for (int g=0;g<count;g++){
													GroupData datag =mExpandAdapter.groups.get(g);
													sPrintA4.append(mode_E[mGroupMode]+datag.strTextG1+sepaA4);													
													sPrintA4.append(datag.strText1+sepaA4);													
													sPrintA4.append(datag.strText2+sepaA4);
													sPrintA4.append(datag.strOriMoney+sepaA4);
													sPrintA4.append(datag.strTextG2+sepaA4);													
													sPrintA4.append(datag.strMoney+sepaA4);
								    				sPrintA4.append(";SSSS"+"\r\n");

								    				int countC =  mExpandAdapter.getChildrenCount(g);
									    			for (int i = 0; i <countC ; i++){
									    				PxData data =mExpandAdapter.getData(g, i);
									    				sPrintA4.append(data.iGoods+sepaA4);
									    				sPrintA4.append(data.iName+sepaA4);
									    				sPrintA4.append(data.iImpo.substring(0, data.iImpo.indexOf("/"))+sepaA4);
									    				sPrintA4.append("銷:"+data.iImpo.substring(data.iImpo.indexOf("/")+1)+sepaA4);
									    				sPrintA4.append("成本:"+data.iMoney.substring(data.iMoney.indexOf("(")+1,data.iMoney.indexOf(")"))+sepaA4);				
									    				sPrintA4.append(data.iCompany+sepaA4);
									    				sPrintA4.append(" "+sepaA4);				
									    				sPrintA4.append(";SSSS"+"\r\n");
									    			}
													sPrintA4.append(";HHHH"+"\r\n");
												}
												Intent intent = new Intent();
												intent.putExtra("SERCH",mStartDay+"~"+mEndDay+" 銷售明細分析 "+mode_E[mGroupMode]+"("+ConChg+")");
												intent.putExtra("QKIND",""+nKind);
												intent.putExtra("MODE",12);
												intent.putExtra("DEPTNO",mDept);
												intent.putExtra("BUFSTR",sPrintA4.toString());
												intent.putExtra("BUFTITLE",sPrintA4T.toString());
												intent.putExtra("STARTDAY",mode_E[mGroupMode]);
												intent.putExtra("ENDDAY",mEndDay);
												Toast.makeText(QRep_03.this,mode_E[mGroupMode]+"("+ConChg+")",Toast.LENGTH_SHORT).show();
												intent.setClass(QRep_03.this, MkqrSt.class);
												startActivity(intent);
		    									
		    									break;
	    									}
		    								case 4: //返回
		    								{
		    									
		    									break;
	    									}
	    								}
	    							}
	    			});

                }else{//CHILD
        			String [] Lmenu={"印製單項(明細)","印製單項(明細)A4","追蹤","返回"};
	    			DialogUtilis.showDialog(QRep_03.this, "請選擇以下功能", -1,
	    					Lmenu, new IDialog() {
	    						@Override
	    						public void onDialogFinish(int pos, String choice) {
	    							switch (pos) {
		    								case 0: //印製單項(明細)
		    								{
													GroupData datag =mExpandAdapter.groups.get(groupPosition);
													Loca=Loca+40;sPrintB.append("AZ,10,"+Loca+",1,1,0,0,"+datag.strTextG1+sepa);													
													sPrintB.append("AZ,"+Lgap+","+Loca+",1,1,0,0,"+datag.strText2+sepa);
													Loca=Loca+25;sPrintB.append("AZ,10,"+Loca+",1,1,0,0,"+datag.strText1+sepa);													
													sPrintB.append("AZ,"+Lgap+","+Loca+",1,1,0,0,"+datag.strOriMoney+sepa);
													Loca=Loca+25;sPrintB.append("AZ,10,"+Loca+",1,1,0,0,"+datag.strTextG2+sepa);													
													sPrintB.append("AZ,"+Lgap+","+Loca+",1,1,0,0,"+datag.strMoney+sepa);
													Loca=Loca+15;sPrintB.append("AZ,10,"+Loca+",1,1,0,0,-------------------------------------------------"+sepa);
													Loca=Loca+5;sPrintB.append("AZ,10,"+Loca+",1,1,0,0,-------------------------------------------------"+sepa);

													int countC =  mExpandAdapter.getChildrenCount(groupPosition);
													
									    			for (int i = 0; i <countC ; i++){
									    				PxData data =mExpandAdapter.getData(groupPosition, i);
														Loca=Loca+25;  //
														sPrintB.append("AZ,20,"+Loca+",1,1,0,0,"+data.iGoods+sepa);
														sPrintB.append("AZ,"+Lgap+","+Loca+",1,1,0,0,"+data.iImpo+sepa);
														Loca=Loca+25;  //
														sPrintB.append("AZ,20,"+Loca+",1,1,0,0,"+data.iName+sepa);
														sPrintB.append("AZ,"+Lgap+","+Loca+",1,1,0,0,"+data.iMoney+sepa);				
														Loca=Loca+25;  //
														sPrintB.append("AZ,20,"+Loca+",1,1,0,0,"+data.iCompany+"  ("+data.iCountry+data.iNumber+")"+sepa);
														if (i<(countC-1)){
														Loca=Loca+12;  //
														sPrintB.append("AZ,20,"+Loca+",1,1,0,0,"+"-------------------------------------------------"+sepa);
														}
														if (Loca>2400){
															PosUtilis.startPartPrint(QRep_03.this,sPrintB,Loca );
															sPrintB.delete(0, sPrintB.toString().length());
															SystemClock.sleep(3000);
															sPrintB=PosUtilis.getPrintKind(QRep_03.this,Utilis.toInt(compStr[8]));
															Loca=0;
														}														
									    			}
										    			Loca=Loca+5;sPrintB.append("AZ,10,"+Loca+",1,2,0,0,"+"-------------------------------------------------"+sepa);
										    			Loca=Loca+5;sPrintB.append("AZ,10,"+Loca+",1,2,0,0,"+"-------------------------------------------------"+sepa);
														Loca=Loca+10;
								    			Loca=Loca+80;
								    			//呼叫 開始列印 BarCodePrinter Socket
								    			PosUtilis.startPrint(QRep_03.this,sPrintB,Loca );
		    									
		    									break;
	    									}
		    								case 1: //印製單項(明細)A4
		    								{
		    									
		    									break;
	    									}
		    								case 2://追蹤
		    								{
		    									data = mExpandAdapter.getData(groupPosition, childPosition);
		    									goQhis();									
		    									break;
		    								}
		    								
		    								case 3: //返回
		    								{
		    									
		    									break;
	    									}
	    								}
	    							}
	    			});
                }
				return true;
		}
	}
	

	private String getTitleP(int nGroupMode){
		String titleP="";
        switch(nGroupMode){
        case GroupMode.TOP1:
        	titleP=((Button)findViewById(R.id.btn_sort_top1)).getText().toString();
        	break;
        case GroupMode.TOP2:
        	titleP=((Button)findViewById(R.id.btn_sort_top2)).getText().toString();
        	break;
        case GroupMode.TOP3:
        	titleP=((Button)findViewById(R.id.btn_sort_top3)).getText().toString();
        	break;
        case GroupMode.TOP4:
        	titleP=((Button)findViewById(R.id.btn_sort_top4)).getText().toString();
        	break;
        case GroupMode.TOP5:
        	titleP=((Button)findViewById(R.id.btn_sort_top5)).getText().toString();
        	break;
        case GroupMode.TOP6:
        	titleP=((Button)findViewById(R.id.btn_sort_top6)).getText().toString();
        	break;
        case GroupMode.TOP7:
        	titleP=((Button)findViewById(R.id.btn_sort_top7)).getText().toString();
        	break;
        case GroupMode.TOP8:
        	titleP=((Button)findViewById(R.id.btn_sort_top8)).getText().toString();
        	break;
        case GroupMode.TOP9:
        	titleP=((Button)findViewById(R.id.btn_sort_top9)).getText().toString();
        	break;
        case GroupMode.TOPA:
        	titleP=((Button)findViewById(R.id.btn_sort_topa)).getText().toString();
        	break;
        }
        return titleP;
	}
	
	ExpandChildClick mChildClcik = new ExpandChildClick();
	
	class ExpandChildClick implements OnChildClickListener{
		@Override
		public boolean onChildClick(ExpandableListView parent, View v,
				final int groupPosition,final int childPosition, long id) {
			Utilis.runVibrate(QRep_03.this);
			PxData data = mExpandAdapter.getData(groupPosition, childPosition);
/*20161124
  			//值得研究 可以改變 大小
        	RelativeLayout.LayoutParams parms = new RelativeLayout.LayoutParams(Wwidth,600);
        	mDisplayStk.setLayoutParams(parms);
*/
			if (deptN>1){ //表示有總倉&多門市
				String GoodsNo=data.iGoods;
				if (GoodsNo.indexOf("-")>0) GoodsNo= GoodsNo.substring(0,GoodsNo.indexOf("-"));
				Bundle bundle = new Bundle();
				Intent intent = new Intent();
				bundle = new Bundle();
				bundle.putString("GalleryChild","'"+GoodsNo+"';0;1");
				intent.setClass(QRep_03.this, GalleryViewS.class);
				intent.putExtras(bundle);
				startActivity(intent);
			}else {
	        	mDisplayStk.setVisibility(View.VISIBLE);
	    		SQLiteDatabase db = Utilis.getDB(QRep_03.this);
				StringBuffer mColno=new StringBuffer();
				StringBuffer mColname=new StringBuffer();
				StringBuffer mSiz=new StringBuffer();
				String GoodsNo=data.iGoods;
				if (GoodsNo.indexOf("-")>0) GoodsNo= GoodsNo.substring(0,GoodsNo.indexOf("-"));
				Cursor cst =db.rawQuery("select COLOR,UNIT1 from qitems  where GOODSNO='" + GoodsNo+"' group by COLOR,UNIT1", null);
				if (cst.getCount()>0) {
					cst.moveToFirst();
					for (int x=0;x<cst.getCount();x++){
						if (mColno.length()<=0){
							mColno.append(cst.getString(0));	mColname.append(cst.getString(1));
						} else {
							mColno.append("，"+cst.getString(0));	mColname.append("，"+cst.getString(1));
						}
							cst.moveToNext();	
					}
				}
				cst =db.rawQuery("select SIZE from qitems  where GOODSNO='" + GoodsNo+"' group by SIZE", null);
				if (cst.getCount()>0) {
					cst.moveToFirst();
					for (int x=0;x<cst.getCount();x++){
						if (mSiz.length()<=0 ){
							mSiz.append(cst.getString(0));
						}else {
							mSiz.append(","+cst.getString(0));
						}	
					cst.moveToNext();	
					}
				}
				cst.close();
				makeTable(GoodsNo,mColno.toString(),mColname.toString(),mSiz.toString());
				db.close();
			}
			return false;
		}
	}
	
	
	class MainClick implements OnClickListener { //所有的觸發事件,在此集中管理
		@Override
		public void onClick(View v) {
			int id = v.getId();
			Utilis.runVibrate(QRep_03.this);
			switch (id) {
				case R.id.btn_exit:
				{
					finish();
					break;
				}
				case R.id.btn_btn0:  //只能在銷貨/預購/暫存狀態 進行新增
				{
					mMode=KeySet.SearchMode.DAY;
					chkMode();
					break;
				}
				case R.id.btn_btn1:  //只能在銷貨/預購/暫存狀態 進行新增
				{
					mMode=KeySet.SearchMode.WEEK;
					chkMode();
					break;
				}
				case R.id.btn_btn2:  //只能在銷貨/預購/暫存狀態 進行新增
				{
					mMode=KeySet.SearchMode.MONTH;
					chkMode();
					break;
				}
				case R.id.btn_btn3:  //只能在銷貨/預購/暫存狀態 進行新增
				{
					mMode=KeySet.SearchMode.SEASON;
					chkMode();
					break;
				}
				case R.id.btn_btn4:  //只能在銷貨/預購/暫存狀態 進行新增
				{
					mMode=KeySet.SearchMode.BATCH;
					chkMode();
					break;
				}
				case R.id.btn_btn5:  //排序的種類
				{
					if (sSort==0){
						sSort=1;
						((Button)findViewById(R.id.btn_btn5)).setText("件數");
					}else if (sSort==1){
						sSort=2;
						((Button)findViewById(R.id.btn_btn5)).setText("毛利");
					}else if (sSort==2){
						sSort=0;
						((Button)findViewById(R.id.btn_btn5)).setText("金額");
					}
					getGroupData(QRep_03.this,mStartDay, mEndDay, null, null);
					int count =  mExpandAdapter.getGroupCount(); 
//					for (int i = 0; i <count ; i++) 
//					mExpandListView.collapseGroup(i); 
					mExpandAdapter.notifyDataSetChanged();
					break;
				}

				case R.id.text_duration:  //當按了日期
				{
				if (GoodChg.equalsIgnoreCase("A.GOODSNO")){
					GoodChg="A.GOODSNOS";
					ColorChg="A.UNIT1";
					SizeChg="A.SIZES";
					ConChg="明細";
				}else{
					GoodChg="A.GOODSNO";
					ColorChg="A.COLORS";
					SizeChg="A.SIZES";
					ConChg="主貨";
				}
				//setCondition();
				getGroupData(QRep_03.this,mStartDay, mEndDay, null, null);				
				
				break;	
				}
				case R.id.btn_prev_date:  //當按了上一??
				{
					switch(mMode){
						case KeySet.SearchMode.MONTH:  //就是31筆日結單(日期+單頭)
			    		{
			    			mStartDay = DateUtil.addMonth(mStartDay, -1,true);
							mEndDay = DateUtil.addMonth(mStartDay, 1);
							if (WeiLa!=0 &&	DateUtil.compareTime(mStartDay, mLimitDay)<0 ){
								mStartDay=mLimitDay;
								mEndDay=DateUtil.addDate(mStartDay, +30);
							}
			    			break;
			    		}
						case KeySet.SearchMode.DAY: 
			    		{
			    			mStartDay = DateUtil.addDate(mStartDay, -1);
							mEndDay = mStartDay;
							if (WeiLa!=0 &&	DateUtil.compareTime(mStartDay, mLimitDay)<0 ){
								mStartDay=mLimitDay;
								mEndDay=mStartDay;
							}
			    			break;
			    		}
						case KeySet.SearchMode.WEEK:  //就是7筆日結單(日期+單頭)
			    		{
			    			mStartDay = DateUtil.addDate(mStartDay, -7);
							mEndDay = DateUtil.addDate(mEndDay, -7);
							if (WeiLa!=0 &&	DateUtil.compareTime(mStartDay, mLimitDay)<0 ){
								mStartDay=mLimitDay;
								mEndDay=DateUtil.addDate(mStartDay, +7);
							}
			    			break;
			    		}
						case KeySet.SearchMode.BATCH:  //銷貨單 (單頭+單身)
						{
				    		//應追加 上一批 的程式
							SQLiteDatabase db = Utilis.getDB(QRep_03.this);
							Cursor cursorAlbun = null;
							if(batch != null && batch.length() > 0){
								StringBuffer bufCategory = new StringBuffer();
									bufCategory.append("select distinct BATCH from qitems");
									bufCategory.append(" where BATCH<'" + batch+"'");
									bufCategory.append(" order by BATCH DESC LIMIT 1");
									cursorAlbun = db.rawQuery(bufCategory.toString(), null);
									
									if (cursorAlbun != null) {
										if (cursorAlbun.getCount() > 0) {
											cursorAlbun.moveToFirst();
											batch = cursorAlbun.getString(0);
										}
									}
							}
							cursorAlbun.close();
							db.close();
							break;
						}
					}
					if (WeiLa!=0 &&	DateUtil.compareTime(mStartDay, mLimitDay)<0 ){
						mStartDay=mLimitDay;
						mEndDay=DateUtil.addDate(mStartDay, +7);
					}
					getGroupData(QRep_03.this,mStartDay, mEndDay, null, null);
					int count =  mExpandAdapter.getGroupCount(); 
					for (int i = 0; i <count ; i++) 
					mExpandListView.collapseGroup(i); 
					mExpandAdapter.notifyDataSetChanged();
					break;
				}
				case R.id.btn_next_date:
				{
					switch(mMode){
			    		case KeySet.SearchMode.MONTH: //就是日結單(日期+單頭)
			    		{
			    			mStartDay = DateUtil.addMonth(mStartDay, 1,true);
							mEndDay = DateUtil.addMonth(mStartDay, 1);
			    			break;
			    		}
			    		case KeySet.SearchMode.DAY:
			    		{
			    			mStartDay = DateUtil.addDate(mStartDay, 1);
							mEndDay = mStartDay;
			    			break;
			    		}
			    		case KeySet.SearchMode.WEEK:
			    		{
			    			mStartDay = DateUtil.addDate(mStartDay, 7);
							mEndDay = DateUtil.addDate(mEndDay, 7);
			    			break;
			    		}
			    		case KeySet.SearchMode.BATCH:
						{
				    		//應追加 下一批 的程式
							SQLiteDatabase db = Utilis.getDB(QRep_03.this);
							Cursor cursorAlbun = null;
							if(batch != null && batch.length() > 0){
								StringBuffer bufCategory = new StringBuffer();
									bufCategory.append("select distinct BATCH from qitems");
									bufCategory.append(" where BATCH>'" + batch+"'");
									bufCategory.append(" order by BATCH DESC LIMIT 1");
									cursorAlbun = db.rawQuery(bufCategory.toString(), null);
									
									if (cursorAlbun != null) {
										if (cursorAlbun.getCount() > 0) {
											cursorAlbun.moveToFirst();
											batch = cursorAlbun.getString(0);
										}
									}
							}
							cursorAlbun.close();
							db.close();
							break;
						}
					}

					getGroupData(QRep_03.this,mStartDay, mEndDay, null, null);
					int count =  mExpandAdapter.getGroupCount(); 
					for (int i = 0; i <count ; i++) 
					mExpandListView.collapseGroup(i); 
					mExpandAdapter.notifyDataSetChanged();
					break;

				}
						
			    case R.id.btn_sort_top1: //依會員
			    	{
		    			resetButton(id);			    		
			    		mGroupMode = GroupMode.TOP1;
		    			getGroupData(QRep_03.this,mStartDay, mEndDay, null, null);
		    			int count =  mExpandAdapter.getGroupCount(); 
		    			for (int i = 0; i <count ; i++) 
		    			mExpandListView.collapseGroup(i); 
		    			mExpandAdapter.notifyDataSetChanged();
		    				
			   			break;
			    		}
			    case R.id.btn_sort_top2:  //依櫃員
			    		{
			    			resetButton(id);
			    			mGroupMode = GroupMode.TOP2;
			    			getGroupData(QRep_03.this,mStartDay, mEndDay, null, null);
			    			int count =  mExpandAdapter.getGroupCount(); 
			    			for (int i = 0; i <count ; i++) 
			    			mExpandListView.collapseGroup(i); 

			    			mExpandAdapter.notifyDataSetChanged();
			    				
			    				break;
			    			}
			    case R.id.btn_sort_top3: //依門市
			    		{
			    			resetButton(id);
			    			mGroupMode = GroupMode.TOP3;
			    			getGroupData(QRep_03.this,mStartDay, mEndDay, null, null);
			    			int count =  mExpandAdapter.getGroupCount(); 
			    			for (int i = 0; i <count ; i++) 
			    			mExpandListView.collapseGroup(i); 
			    			
			    			mExpandAdapter.notifyDataSetChanged();
			    				
			    				break;
			    		}
			    case R.id.btn_sort_top4: //依廠商
			    		{
			    			resetButton(id);
			    			mGroupMode = GroupMode.TOP4;
			    			getGroupData(QRep_03.this,mStartDay, mEndDay, null, null);
			    			int count =  mExpandAdapter.getGroupCount(); 
			    			for (int i = 0; i <count ; i++) 
			    			mExpandListView.collapseGroup(i); 
			    			mExpandAdapter.notifyDataSetChanged();
			    			
			    			break;
			    		}
			    case R.id.btn_sort_top5: //依類別
	    		{
	    			resetButton(id);
	    			mGroupMode = GroupMode.TOP5;
	    			getGroupData(QRep_03.this,mStartDay, mEndDay, null, null);
	    			int count =  mExpandAdapter.getGroupCount(); 
	    			for (int i = 0; i <count ; i++) 
	    			mExpandListView.collapseGroup(i); 
	    			mExpandAdapter.notifyDataSetChanged();
	    			
	    			break;
	    		}
			    case R.id.btn_sort_top6: //依顏色
	    		{
	    			resetButton(id);
	    			mGroupMode = GroupMode.TOP6;
	    			getGroupData(QRep_03.this,mStartDay, mEndDay, null, null);
	    			int count =  mExpandAdapter.getGroupCount(); 
	    			for (int i = 0; i <count ; i++) 
	    			mExpandListView.collapseGroup(i); 
	    			mExpandAdapter.notifyDataSetChanged();
	    			
	    			break;
	    		}
			    case R.id.btn_sort_top7: //依國別
	    		{
	    			resetButton(id);
	    			mGroupMode = GroupMode.TOP7;
	    			getGroupData(QRep_03.this,mStartDay, mEndDay, null, null);
	    			int count =  mExpandAdapter.getGroupCount(); 
	    			for (int i = 0; i <count ; i++) 
	    			mExpandListView.collapseGroup(i); 
	    			mExpandAdapter.notifyDataSetChanged();
	    			
	    			break;
	    		}
			    case R.id.btn_sort_top8: //依尺寸
	    		{
	    			resetButton(id);
	    			mGroupMode = GroupMode.TOP8;
	    			getGroupData(QRep_03.this,mStartDay, mEndDay, null, null);
	    			int count =  mExpandAdapter.getGroupCount(); 
	    			for (int i = 0; i <count ; i++) 
	    			mExpandListView.collapseGroup(i); 
	    			mExpandAdapter.notifyDataSetChanged();
	    			
	    			break;
	    		}
			    case R.id.btn_sort_top9: //依季節
	    		{
	    			resetButton(id);
	    			mGroupMode = GroupMode.TOP9;
	    			getGroupData(QRep_03.this,mStartDay, mEndDay, null, null);
	    			int count =  mExpandAdapter.getGroupCount(); 
	    			for (int i = 0; i <count ; i++) 
	    			mExpandListView.collapseGroup(i); 
	    			mExpandAdapter.notifyDataSetChanged();
	    			
	    			break;
	    		}
			    case R.id.btn_sort_topa:  //算薪資
	    		{
	    			resetButton(id);
	    			mGroupMode = GroupMode.TOPA;
	    			getGroupData(QRep_03.this,mStartDay, mEndDay, null, null);
	    			int count =  mExpandAdapter.getGroupCount(); 
	    			for (int i = 0; i <count ; i++) 
	    			mExpandListView.collapseGroup(i); 

	    			mExpandAdapter.notifyDataSetChanged();
	    				
    				break;
	    			}
			}
			setCondition();
		}
	}
	
	private void resetButton(int id){
		((Button)findViewById(R.id.btn_sort_top1)).setBackgroundResource(R.drawable.keypad_green);
        ((Button)findViewById(R.id.btn_sort_top2)).setBackgroundResource(R.drawable.keypad_green);
        ((Button)findViewById(R.id.btn_sort_top3)).setBackgroundResource(R.drawable.keypad_green);
        ((Button)findViewById(R.id.btn_sort_top4)).setBackgroundResource(R.drawable.keypad_green);
        ((Button)findViewById(R.id.btn_sort_top5)).setBackgroundResource(R.drawable.keypad_green);
        ((Button)findViewById(R.id.btn_sort_top6)).setBackgroundResource(R.drawable.keypad_green);
        ((Button)findViewById(R.id.btn_sort_top7)).setBackgroundResource(R.drawable.keypad_green);
        ((Button)findViewById(R.id.btn_sort_top8)).setBackgroundResource(R.drawable.keypad_green);
        ((Button)findViewById(R.id.btn_sort_top9)).setBackgroundResource(R.drawable.keypad_green);
        ((Button)findViewById(R.id.btn_sort_topa)).setBackgroundResource(R.drawable.keypad_green);
        ((Button)findViewById(id)).setBackgroundResource(R.drawable.keypad_yellow);
	}

	private void goQhis(){
		String GoodsNo=data.iGoods;
		if (GoodsNo.indexOf("-")>0) GoodsNo= GoodsNo.substring(0,GoodsNo.indexOf("-"));
		try{
			Intent intent = new Intent();
			intent.putExtra("QHis_kind", nKind);
			intent.putExtra("QHis_mode", 1);
			intent.putExtra("QHis_User","" );
			intent.putExtra("QHis_Goods",GoodsNo );
			intent.setClass(QRep_03.this, QHis.class);
			startActivity(intent);
		}catch(Exception e){
			e.printStackTrace();
		}finally{
		}
		

	}

	// 搜尋日期 Dialog
    private View makeDateDialog() {
    	View view = LayoutInflater.from(this).inflate(R.layout.search_date, null, false);
    	Calendar c = Calendar.getInstance();
    	c.set(Calendar.DAY_OF_MONTH, 1); // 關鍵
    	
	    mYear1 = c.get(Calendar.YEAR);
		mMonth1 = c.get(Calendar.MONTH) + 1;
		mDay1 = c.get(Calendar.DAY_OF_MONTH);
		c.add(Calendar.MONTH, 1);
		c.add(Calendar.DATE, -1);   // 關鍵
		mYear2 = c.get(Calendar.YEAR);
		mMonth2 = c.get(Calendar.MONTH) + 1;
		mDay2 = c.get(Calendar.DAY_OF_MONTH);
		
		dp1 = (DatePicker)view.findViewById(R.id.dp1);
		dp1.init(mYear1, mMonth1 - 1, mDay1, new DatePicker.OnDateChangedListener() {
			@Override
			public void onDateChanged(DatePicker view, int year,
					int monthOfYear, int dayOfMonth) {
				mYear1 = year;
				mMonth1 = monthOfYear + 1;
				mDay1 = dayOfMonth;
			}
		});
		
		dp2 = (DatePicker)view.findViewById(R.id.dp2);
		dp2.init(mYear2, mMonth2 - 1, mDay2, new DatePicker.OnDateChangedListener() {
			@Override
			public void onDateChanged(DatePicker view, int year,
					int monthOfYear, int dayOfMonth) {
				mYear2 = year;
				mMonth2 = monthOfYear + 1;
				mDay2 = dayOfMonth;
			}
		});
		
		return view;
	}
    
    private void chkMode(){        
        switch(mMode){ //剛進入主程式的狀態,初始的模式
        
	    	case KeySet.SearchMode.DAY:
	    	{
	    		mStartDay = DateUtil.getCurrentDate();
	    		mEndDay = mStartDay;
	    		
		    	getGroupData(QRep_03.this, mStartDay, mEndDay, null, null);
		    	
	    		((Button)findViewById(R.id.btn_next_date)).setVisibility(View.VISIBLE);
	    		((Button)findViewById(R.id.btn_next_date)).setText("下一日");
	    		((Button)findViewById(R.id.btn_prev_date)).setVisibility(View.VISIBLE);
	    		((Button)findViewById(R.id.btn_prev_date)).setText("上一日");
	    		setTitle(getString(R.string.app_name)+":[每日]"+mode_E[mGroupMode]);
	    		break;
	    	}
	    	case KeySet.SearchMode.WEEK:
	    	{
	    		String day = Utilis.getWeekDate();
				String[] days = day.split("~");
	    		mStartDay = days[0];
	    		mEndDay = days[1];
//@@				mGroupMode = GroupMode.TOP2;
	    		
		    	getGroupData(QRep_03.this, mStartDay, mEndDay, null, null);
		    	
	    		((Button)findViewById(R.id.btn_next_date)).setVisibility(View.VISIBLE);
	    		((Button)findViewById(R.id.btn_next_date)).setText("下一週");
	    		((Button)findViewById(R.id.btn_prev_date)).setVisibility(View.VISIBLE);
	    		((Button)findViewById(R.id.btn_prev_date)).setText("上一週");
	    		setTitle(getString(R.string.app_name)+":[每週]"+mode_E[mGroupMode]);
	    		break;
	    	}
	    	case KeySet.SearchMode.MONTH:
	    	{
	    		String day = Utilis.getMonthDate();
				String[] days = day.split("~");
	    		mStartDay = days[0];
	    		mEndDay = days[1];
	    		
		    	getGroupData(QRep_03.this, mStartDay, mEndDay, null, null);
		    	
	    		((Button)findViewById(R.id.btn_next_date)).setVisibility(View.VISIBLE);
	    		((Button)findViewById(R.id.btn_next_date)).setText("下個月");
	    		((Button)findViewById(R.id.btn_prev_date)).setVisibility(View.VISIBLE);
	    		((Button)findViewById(R.id.btn_prev_date)).setText("上個月");
	    		
	    		setTitle(getString(R.string.app_name)+":[每月]"+mode_E[mGroupMode]);
	    		break;
	    	}
	    	case KeySet.SearchMode.SEASON:  //自定日期範圍
	    	{
	    		final int nAccountId = getIntent().getIntExtra("accountid", 0);
	    		new AlertDialog.Builder(QRep_03.this).setTitle("銷貨單 搜尋(起始、結束日期)")
				.setView(makeDateDialog())
				.setPositiveButton(getString(R.string.str_ok), new DialogInterface.OnClickListener() {
		            public void onClick(DialogInterface dialog, int which) {
		            	String startDay = "" + mYear1 + "/" + Utilis.formatDate(mMonth1) + "/" + Utilis.formatDate(mDay1);
		            	String endDay = "" + mYear2 + "/" + Utilis.formatDate(mMonth2) + "/" + Utilis.formatDate(mDay2);
		            	
		            	mStartDay = startDay;
		            	mEndDay = endDay;
						if (WeiLa!=0 &&	DateUtil.compareTime(mStartDay, mLimitDay)<0 ){
							mStartDay=mLimitDay;
							mEndDay=DateUtil.addDate(mStartDay, +7);
						}
		            	mTextDuration.setText( mStartDay + "~" + mEndDay);
		            	
		            	getGroupData(QRep_03.this, mStartDay, mEndDay, null, null);
		            	
		            	setTitle(getString(R.string.app_name)+":[日期範圍]"+mode_E[mGroupMode]);
		            	
		            }
		          }).setNegativeButton(getString(R.string.str_cancel), new DialogInterface.OnClickListener() {
		            public void onClick(DialogInterface dialog, int which) {
		            }
		          }).show();
	    		break;
	    	}
	    	case KeySet.SearchMode.BATCH:  //批號
	    	{
	    		SQLiteDatabase db = Utilis.getDB(QRep_03.this);
				Cursor cursorAlbun = null;
				StringBuffer bufCategory = new StringBuffer();
				bufCategory.append("select distinct BATCH from qitems");
				bufCategory.append(" where BATCH> ' '");
				bufCategory.append(" order by BATCH DESC LIMIT 1");
				cursorAlbun = db.rawQuery(bufCategory.toString(), null);
				
				if (cursorAlbun != null) {
					if (cursorAlbun.getCount() > 0) {
						cursorAlbun.moveToFirst();
						batch = cursorAlbun.getString(0);
					}
				}
				cursorAlbun.close();
				db.close();
				if (WeiLa!=0 &&	DateUtil.compareTime(mStartDay, mLimitDay)<0 ){
					mStartDay=mLimitDay;
					mEndDay=DateUtil.addDate(mStartDay, +7);
				}
	    		getGroupData(QRep_03.this, mStartDay, mEndDay, null, null);
	    		
	    		((Button)findViewById(R.id.btn_next_date)).setVisibility(View.VISIBLE);
	    		((Button)findViewById(R.id.btn_next_date)).setText("下一批");
	    		((Button)findViewById(R.id.btn_prev_date)).setVisibility(View.VISIBLE);
	    		((Button)findViewById(R.id.btn_prev_date)).setText("上一批");

	    		setTitle(getString(R.string.app_name)+":[依批號結算]"+mode_E[mGroupMode]);	    		
	    		break;
	    	}
        }
        
		int count =  mExpandAdapter.getGroupCount(); 
		for (int i = 0; i <count ; i++) 
		mExpandListView.collapseGroup(i); 
        mExpandAdapter.notifyDataSetChanged();        
        setCondition();
    }

	private void makeTable(String kGoods,String kSplitColorNo,String kSplitColor,String kSplitSizes){
		
		//展開用的引用在庫存表
		String[] anames;	
		String[] anumber;
		String[] asizes;
		double[] attot;
	
		if(kSplitSizes != null && kSplitSizes.length() > 0
    		&& kSplitColorNo != null && kSplitColorNo.length() > 0
    		&& kSplitColor != null && kSplitColor.length() > 0){
			
			    	mArrayColorNumber.clear();
			    	mArrayColorNumber.removeAll(mArrayColorNumber);
			    	mArrayColorName.clear();
			    	mArrayColorName.removeAll(mArrayColorName);
			    	
		        	anumber = kSplitColorNo.split("，"); //取得各色號字串
		        	anames = kSplitColor.split("，");
		        	asizes = kSplitSizes.split(",");
		        	attot=new double[asizes.length*anumber.length];
			    	
			    	
			    	for(int i = 0; i < anumber.length; i++){ 
			    		mArrayColorNumber.add(anumber[i]); //從numbers字串陣列 存入 List_mArrayColorNumber
			    	}
			    	
			    	anames = kSplitColor.split("，");
			    	
			    	for(int i = 0; i < anames.length; i++){
			    		mArrayColorName.add(anames[i]);
			    	}
				
			    	//努力歸零 very important
			    	mLayoutRoot.removeAllViews(); //***************
					mSizeLink.clear();
					mCountRow.clear();	        		
					mCountCell.clear();
					
			    	mSizeLink.add("代碼"); // 顏色
			    	mSizeLink.add("顏色"); // 尺寸
			    	// 設定 Title 行 //使每個尺寸都有3格(進/銷/存)
			    	String ttot[] =new String[asizes.length*3*anumber.length] ; //進銷存統計用
			    	String ptot[] =new String[asizes.length*anumber.length] ;	//展開用
			    	for(int i = 0; i < asizes.length*3*anumber.length; i++){ttot[i]="0";}
			    	for(int i = 0; i < asizes.length*anumber.length; i++){ptot[i]="";}
			    	for(int i = 0; i < asizes.length; i++){
			    		mSizeLink.add(asizes[i]+"進");
			    		mSizeLink.add(asizes[i]+"銷(訂)");
			    		mSizeLink.add(asizes[i]+"存");
			    	}
			    	// 設定初始Row 列
			    	for(int i = 0; i <= mArrayColorName.size(); i++){
			    		// 設定Row會包含哪些 Key
			    		mCountRow.put(i, i * 100);
			    		for(int k = 0; k < mSizeLink.size(); k ++){ //s1,s2,s3,m1,m2,m3,l1,l2,l3,x1,x2,x3
			        		if( i == 0){
			        			mCountCell.put(k, mSizeLink.get(k)); //原先 i*100+k 沒有意義
			        		}
			        		else{ // 第二列以後
			        			if( k == 0){ // 新增號碼
			        					mCountCell.put(i * 100 + k, mArrayColorNumber.get(i - 1));
			        			} else {
			        					mCountCell.put(i * 100 + k, mArrayColorName.get(i - 1)); 
			        			}
			
			        		}			
			    		}
			    	}
			    	
					try{
						
					String mCountList= PosUtilis.getQMtrioArray(this,kGoods,kSplitColorNo,kSplitColor,kSplitSizes,mDept,"" , nPart,1);
						
			    	String[] numberLevel1 = mCountList.toString().split("，");
			    	for(int nRow = 1; nRow < mCountRow.size(); nRow++){
			    		String[] numberLevel2 = numberLevel1[nRow - 1].split(",");
			    		int nLevel2 = 0;
						int nCellKey = mCountRow.get(nRow);
						for(int i = 2 ; i < mSizeLink.size(); i++){
							if(nLevel2 < numberLevel2.length){
								mCountCell.put(nCellKey + i, numberLevel2[nLevel2]);
							}
							nLevel2++;
						}
					}
					
				}catch(Exception e){
					e.printStackTrace();
				}
					
					ArrayList<TableRow> table = new ArrayList<TableRow>();
				table.removeAll(table);
			
				for(int i = 0; i <= mArrayColorName.size(); i++){
					TableCell[] titles = new TableCell[mSizeLink.size()];
			
					for(int k = 0; k < titles.length; k++){
		    			if (k<=1) titles[k] = new TableCell((Wwidth/(tabless+1))-8,tableHeight,TableCell.STRING);
		    			else titles[k] = new TableCell((Wwidth/tabless)-8,tableHeight,TableCell.STRING);
					}
					table.add(new TableRow(titles));
				}
				
				TableRow tableRow = table.get(0);
				for(int i = 0; i <=mArrayColorName.size(); i ++){
					TableRowView row = new TableRowView(this, tableRow, 0,i);
					mLayoutRoot.addView(row);
				}
		
		}
	}
   	
public class TableRowView extends LinearLayout {  
    public TableRowView(Context context, TableRow tableRow,int imode, int position) {  
        super(context);  
        this.setOrientation(LinearLayout.HORIZONTAL);
        String colStr="01";
        for (int i = 0; i < tableRow.getSize(); i++) { 
            TableCell tableCell = tableRow.getCellValue(i);  
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(  
                    tableCell.width, tableCell.height);  
            layoutParams.setMargins(0, 0, 1, 1);  
            TextView textCell = new TextView(context);  
                textCell.setLines(1);  
                textCell.setGravity(Gravity.CENTER);  
                textCell.setBackgroundColor(Color.WHITE);
                if(mCountRow.containsKey(position) == true){
                	int key = mCountRow.get(position);  //keep
                	if( mCountCell.containsKey(key + i)){
                		textCell.setText(String.valueOf(mCountCell.get(key + i))); //keep
                	}else{
                		textCell.setText("X");
                	}
                }else{
                	textCell.setText("X");
                }
                textCell.setId(position * 200 + i);
                textCell.setTextColor(Color.BLACK);
                if(position >=1 && i >= 2){
                	if ((i+2) %3==1){
                	textCell.setBackgroundResource(R.drawable.keypad_yellow);
                	} else if((i+2) %3==2) {
                    	textCell.setBackgroundResource(R.drawable.keypad_green);                    		
                	} else if((i+2) %3==0) {
                    	textCell.setBackgroundResource(R.drawable.keypad_blue2);                    		
                	}
                	
                }else  if(position > 0 && i ==0 && imode==0){  //
                	String colorN=DBUtil.ColorGetTxt(QRep_03.this,textCell.getText().toString());
                	String [] colors=colorN.split(";");
                	textCell.setBackgroundColor(Utilis.toInt(colors[2]));
                }else  if(position == 0 && imode==1 && i>1 ){  //
                	String colorN=DBUtil.ColorGetTxt(QRep_03.this,textCell.getText().toString());
                	String [] colors=colorN.split(";");
                	if (((i+1) %3)==0){	
                		colStr=textCell.getText().toString();
                		colorN=DBUtil.ColorGetTxt(QRep_03.this,textCell.getText().toString());
                		colors=colorN.split(";");
                	}
               		if (((i+1) %3)==2){
               			textCell.setBackgroundResource(R.drawable.keypad_blue2);
               		}else{	
                		textCell.setBackgroundColor(Utilis.toInt(colors[2]));
               		}
                } else {
                	textCell.setBackgroundColor(Color.rgb(208, 208, 208));
                }
                
                addView(textCell, layoutParams);
                
        }  
        this.setBackgroundColor(Color.BLACK);
    }  
}

	Handler mHandlerQDR_31 = new Handler()
	{
		@Override
		public  void handleMessage(Message msg)
		{
			//傳回的//upup_1-30_系統時間
			
			String Hresult=null;
			switch (msg.what)
			{
			// 顯示網路上抓取的資料
			case REFRESH_DATA:
				if (msg.obj instanceof String) 
					Hresult = (String) msg.obj;
				if (Hresult != null ){
					if (Hresult.indexOf("HHHH\r\n")>2){

						Hresult=	Hresult.substring(Hresult.indexOf("rep03;")+6);
						
						Log.i("DOWNLOAD_31",Hresult );
						
						String LineH [] = Hresult.substring(0, Hresult.length()-6).split(";HHHH\r\n");

						LinkedList<GroupData> groups = new LinkedList<GroupData>();
						LinkedList<List<PxData>> childs = new LinkedList<List<PxData>>();
						
						for (int xx=0;xx<LineH.length;xx++){
							String LinesH[] =LineH[xx].substring(0, LineH[xx].length()-6).split(";SSSS\r\n");
							
							GroupData datah = new GroupData();

							String Lineshh[] =LinesH[0].split(";");
							
							datah.SEARCH = Lineshh[5];
							T30=Utilis.toInt(Lineshh[0])+Utilis.toInt(Lineshh[1]);//總件數
							TT30=TT30+T30;
							M30=Utilis.toDouble(Lineshh[2]);//總金額
							TM30=TM30+M30;
							M10=Utilis.toDouble(Lineshh[3]);//總成本
							TM10=TM10+M10;
							datah.strText2="銷:"+df.format(T30)+"件";							
							datah.strOriMoney="銷$:"+df.format(M30);
							
							if (M30 >0 && PSWD==0)	{
								datah.strTextG2="成本$:"+df.format(M10); //總成本strTextG2
								datah.strMoney="毛:$"+df.format(M30-M10)+"/"+df.format(Math.round((M30-M10)*100/M30))+"%";
							} else {
								datah.strMoney="毛:xxxxxx";
							}
							
							if (sSort==0)	datah.Sort=M30; 
							else if (sSort==1)	datah.Sort=T30; 
							else if (sSort==2)	datah.Sort=M30-M10;
								
			 				StkT=TT30;  //總銷貨量
			 				StkM=TM30; //總銷金額
			 				Profit=TM30-TM10; //總毛利
			 				Profits=Math.round(Profit*100/TM30); //總毛利率
							if (Lineshh[7] ==null || Lineshh[7].length()<=0 ) datah.strPic="drawable.icon"; 
							else datah.strPic=Lineshh[7];  //圖片
							datah.strTextG1=Lineshh[5]; //主題一
							datah.strText1=Lineshh[6]; //主題二
			 				groups.add(datah);
			 				
							
								List<PxData> listData = new ArrayList<PxData>();							
				 				for (int yy=1;yy<LinesH.length;yy++){
									String Lines[] =LinesH [yy].split(";");
									if (Lines.length>=10){
										PxData data=new PxData();
	
										data.iGoods =Lines[5] ;
										data.iName =Lines[6] ;
										data.iPic=Lines[7] ;
										data.iImpo ="銷:"+df.format(Utilis.toInt(Lines[0])+Utilis.toInt(Lines[1]))+"件/$"+ df.format(Utilis.toDouble(Lines[2]));
										if (PSWD==0)
											data.iMoney ="銷:$"+ df.format(Utilis.toDouble(Lines[2]))+"("+df.format(Utilis.toDouble(Lines[3]))+")";
										else
											data.iMoney ="銷:$"+ df.format(Utilis.toDouble(Lines[2]))+"(XXX)";
										
										M10=Utilis.toDouble(Lines[3]);
										M30=Utilis.toDouble(Lines[2]);
										data.iCountry=Lines[8];
										data.iNumber=Lines[9];
	
										if (M30 >0 && PSWD==0)	{
											data.iCompany="毛:$"+df.format((M30-M10))+"/"+df.format(Math.round((M30-M10)*100/M30))+"%";
										} else {
											data.iCompany="毛:xxxxxx";
										}
										if (sSort==0)	data.Sort=Utilis.toDouble(Lines[2]); 
										else if (sSort==1)	data.Sort=(Utilis.toInt(Lines[0])+Utilis.toInt(Lines[1])); 
										else if (sSort==2)	data.Sort=M30-M10;
										
					 					listData.add(data);
								}
				 			}
								childs.add(listData);
						}
						mExpandAdapter.setData(groups, childs);
						mExpandAdapter.notifyDataSetChanged();
		 				((TextView)findViewById(R.id.text_t10)).setText(""+df.format(StkT)+"件");//總進->銷件
		 				((TextView)findViewById(R.id.text_r10)).setText("$:"+df.format(StkM));  //盈虧 ->銷額
		 				((TextView)findViewById(R.id.text_t30)).setText("$:"+df.format(TM10));  //本銷->毛利
		 				((TextView)findViewById(R.id.text_r30)).setText("$:"+df.format(Profit)+"/"+df.format(Profits)+"%");
						
				}
			}
		}
	}
	};
	
	/**
	 *  Menu 使用
	 */
	
	private static final int MENU_MAIN = Menu.FIRST;
	private static final int MENU_DETAIL = Menu.FIRST+1;
	private static final int MENU_S1S2 = Menu.FIRST+2;
	private static final int MENU_S1 = Menu.FIRST+3;
	private static final int MENU_S2 = Menu.FIRST+4;
	private static final int MENU_S3 = Menu.FIRST+5;
	@Override
    public boolean onCreateOptionsMenu(Menu menu){
    	super.onCreateOptionsMenu(menu);
    	menu.add(0, MENU_MAIN, 0, "依主貨做統計");
    	menu.add(0, MENU_DETAIL, 1, "依明細做統計");
    	menu.add(0, MENU_S1S2, 2, "銷貨+員購");
    	menu.add(0, MENU_S1, 3, "銷貨(不計員購)");
    	menu.add(0, MENU_S2, 4, "員購(不計銷貨)");
    	menu.add(0, MENU_S3, 5, "零售業績統計");
    	return true;
    }
	
    @Override
	public boolean onOptionsItemSelected(MenuItem item) {			
		super.onOptionsItemSelected(item);
		switch (item.getItemId()) {
			case MENU_MAIN:
			{
				GoodChg="A.GOODSNO";
				ColorChg="A.COLORS";
				SizeChg="A.SIZES";
				ConChg="主貨";
				break;
			}
			case MENU_DETAIL:
			{
				GoodChg="A.GOODSNOS";
				ColorChg="A.UNIT1";
				SizeChg="A.SIZES";
				ConChg="明細";
				break;
			}
			case MENU_S1S2:{
				SQLADD="(A.QKIND ='30' OR A.QKIND ='31' OR A.QKIND ='40' OR A.QKIND ='41') and A.ISCONFIRM='Y'";
				break;
			}
			case MENU_S1:{
				SQLADD="(A.QKIND ='30' OR A.QKIND ='31') and A.ISCONFIRM='Y'";
				break;
			}
			case MENU_S2:{
				SQLADD="(A.QKIND ='40' OR A.QKIND ='41') and A.ISCONFIRM='Y'";
				break;
			}
			case MENU_S3:{
				SQLADD="A.TRADETYPE='5' and ( A.QKIND ='30' OR A.QKIND ='31') and A.ISCONFIRM='Y'";
				break;
			}
					
		}
		setCondition();
		getGroupData(QRep_03.this,mStartDay, mEndDay, null, null);				

		return true;
    }
    


	class ExpandItemAdapter extends BaseExpandableListAdapter{
		private Context context;

		LinkedList<GroupData> groups = new LinkedList<GroupData>();
		LinkedList<List<PxData>> childs = new LinkedList<List<PxData>>();
		private AsyncImageFileLoader asyncImageFileLoader;
		/*
		* 構造函數:
		* 參數1:context物件
		* 參數2:一級清單資料來源
		* 參數3:二級清單資料來源
		*/
		
		public ExpandItemAdapter(Context context)
		{
//			this.groups = groups;
//			this.childs = childs;
			this.context = context;
			asyncImageFileLoader = new AsyncImageFileLoader();
		}
		
		public void setData(LinkedList<GroupData> groups, LinkedList<List<PxData>> childs){
			if(this.groups != null){
				this.groups.clear();
			}
			if(this.childs != null){
				this.childs.clear();
			}
			this.groups = groups;
			this.childs = childs;
		}
		
//@@
		public PxData getData(int groupPosition, int childPosition){
			return childs.get(groupPosition).get(childPosition);
		}

		public Object getChild(int groupPosition, int childPosition)
		{
			return childs.get(groupPosition).get(childPosition);
		}

		public long getChildId(int groupPosition, int childPosition)
		{
		return childPosition;
		}
		
		/* class ViewHolder */
		private class ViewHolder {
			ImageView imageItem;
			TextView textName;
			TextView textMoney;
			TextView textCountry;
			TextView textNumber;
			TextView textCompany;
			TextView textGoodsNo;
			TextView textImpo;
		}
		
		/* class GroupViewHolder */
		private class GroupViewHolder {
			ImageView imageIcon;
			TextView text1;
			TextView text2;
			TextView textMoney;
			TextView textOriMoney;
			TextView textG1;
			TextView textG2;
		}

		//獲取二級清單的View物件
		public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView,
		ViewGroup parent)
		{
		PxData data = childs.get(groupPosition).get(childPosition);
		//
		LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			ViewHolder holder;
			if (convertView == null) {
				convertView = layoutInflater.inflate(R.layout.list_posh, null);
				holder = new ViewHolder();
				holder.imageItem = (ImageView)convertView.findViewById(R.id.img_ppic);
				holder.textGoodsNo = (TextView) convertView.findViewById(R.id.text_pgoodsno);
				holder.textImpo = (TextView) convertView.findViewById(R.id.text_pimpo);
				holder.textName = (TextView) convertView.findViewById(R.id.text_pname);
				holder.textNumber = (TextView) convertView.findViewById(R.id.text_pnumber);
				holder.textMoney = (TextView) convertView.findViewById(R.id.text_pmoney);
				holder.textCountry = (TextView) convertView.findViewById(R.id.text_pcountry);
				holder.textCompany = (TextView) convertView.findViewById(R.id.text_pcompany);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			java.text.DecimalFormat myformat=new java.text.DecimalFormat("0.00");
				try{
					//if(data.iPic != null && data.iPic.length() > 0){
					if(mGroupMode != GroupMode.TOP6 && data.iPic != null && data.iPic.length() > 0){
						holder.imageItem.setImageDrawable(Utilis.getResourceImage(QRep_03.this, data.iPic));
					}else{
						holder.imageItem.setImageResource(R.drawable.icon_store);
					}
				}catch(Exception e){
					e.printStackTrace();
				}
			holder.textName.setText(data.iName);
			holder.textGoodsNo.setText(data.iGoods);
			holder.textImpo.setText(data.iImpo);			
			holder.textMoney.setText(data.iMoney);
			holder.textCountry.setText(data.iCountry);
			holder.textCompany.setText(data.iCompany);
			holder.textNumber.setText(data.iNumber);
			return convertView;
		}

		public int getChildrenCount(int groupPosition)
		{
		return childs.get(groupPosition).size();
		}

		public Object getGroup(int groupPosition)
		{
		return groups.get(groupPosition);
		}

		public int getGroupCount()
		{
		return groups.size();
		}

		public long getGroupId(int groupPosition)
		{
		return groupPosition;
		}

		//獲取一級清單View物件
		public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)
		{
//			String text = groups.get(groupPosition).get("group");
			GroupData data = groups.get(groupPosition);
			
			LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			GroupViewHolder holder;
			if (convertView == null) {
				convertView = layoutInflater.inflate(R.layout.plist_group, null);
				holder = new GroupViewHolder();
				//id/text_ttime
				((TextView) convertView.findViewById(R.id.text_ttime)).setVisibility(View.INVISIBLE);
				holder.imageIcon = (ImageView)convertView.findViewById(R.id.img_icon);
				holder.text1 = (TextView) convertView.findViewById(R.id.text1);
				holder.text2 = (TextView) convertView.findViewById(R.id.text2);
				holder.textMoney = (TextView)convertView.findViewById(R.id.textMoney);
				holder.textOriMoney = (TextView)convertView.findViewById(R.id.textOriMoney);
				holder.textG1 = (TextView) convertView.findViewById(R.id.textg1);
				holder.textG2 = (TextView) convertView.findViewById(R.id.textg2);
				convertView.setTag(holder);
				
			} else {
				holder = (GroupViewHolder) convertView.getTag();
			}
			//@@應該區隔進貨單mKind=10 或日結單abMode==1 與不是進貨單
				holder.imageIcon.setVisibility(View.VISIBLE);
				try{
					if(mGroupMode != GroupMode.TOP6 && data.strPic != null && data.strPic.length() > 0){
						holder.imageIcon.setImageDrawable(Utilis.getResourceImage(QRep_03.this, data.strPic));
					}else{
						holder.imageIcon.setImageResource(R.drawable.icon_store);
					}
				}catch(Exception e){
					e.printStackTrace();
				}
				
				try{
					if (mGroupMode == GroupMode.TOP9) {holder.text1.setText(Season_Array[Utilis.toInt(data.strText1)]);}
					else{ holder.text1.setText(data.strText1);}
				}catch(Exception e){
					e.printStackTrace();
				}
			
			holder.text2.setText(data.strText2);
			holder.textOriMoney.setText(data.strOriMoney);
			holder.textMoney.setText(data.strMoney);
			holder.textG1.setText(data.strTextG1);
			holder.textG2.setText(data.strTextG2);
			return convertView;
		}

		public boolean hasStableIds()
		{
		return false;
		}

		public boolean isChildSelectable(int groupPosition, int childPosition)
		{
		return true;
		}
	}

}
