package com.cwbuyer.lib;

import java.io.BufferedWriter;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Calendar;
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.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

import com.cwbuyer.format.IDialog;
import com.cwbuyer.format.KeySet;
import com.pwbuyer.main.R;

//銷售王_櫃員業績統計
@SuppressLint("HandlerLeak")
@SuppressWarnings("unused")
public class QRep_14 extends Activity{
	
	ReportAdapter mAdapter = null;
	ReportAdapter mAdapter1 = null;
	ReportAdapter mAdapter2 = null;
	
	TextView mTextDuration = null;

//ACTION 預設模式 POS定義為 銷貨單;預購單;暫存單;單頭+單身	
	
	int mMode = KeySet.SearchMode.MONTH;
	
	private final int RESULT_GALLERY=6666; 		//GALLERY
	
	int mGroupMode = GroupMode.TOP1;  //預設初始到總績 
	final String myImportPath =android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+Utilis.getIni(this, "SYS", "YEAR",7);	
	String SD_PATH =android.os.Environment.getExternalStorageDirectory().getAbsolutePath();
	String pathName="/CWBuyer/cualbun";	
	
	/** State :  true 正式 , false 樣品*/
	String mEndDay = null;
	String mStartDay = null;
	private int PSWD=Utilis.toInt(Utilis.getIni(this,"SYS","DEPT",5)); //0OK 1密碼不符
	int nPart=0;
	String theEmp;//指向業務
	int locations=0;
	int locationa=0;
	String SQLADD="(QKIND ='30' OR QKIND ='31') and ISCONFIRM='Y' ";  //補充條件 零售業績 非零售業績
	public ProgressDialog myDialog = null;
	String uriAPI=null;
	protected static final int REFRESH_DATA = 0x00000001;

	//發展為長按而啟動的功能
	String[] menu_E={"廠商", "出貨","業務","員購"};
	String[] menu_S={"達成業績日報表","達成業績客戶表", "返回"};
	String[] menu_B={ "交易明細", "返回"};
	String[] menu_C={ "列印業績明細", "輸出CSV", "返回"};
	String mKind=null; //單別 102030405060
//	private static final String[] compStr = { "","","","","","","","",""};
	
	int nKind=0;
	DatePicker dp1;
	DatePicker dp2;
	
   	String btns=null;
   	String[] compStr;
   	int mCloud=Utilis.toInt(Utilis.getIni(this,"SYS","DEPT_SEND",4));
	int ORS=Utilis.toInt(Utilis.getIni(this, "SYS","DEPT_SEND", 6));

   	int TT10=0;  	//總進貨量_BSUM
   	int TM10=0; 	//總進貨額_(ASUM)
   	int TT30=0;	//總銷貨量_CASH
   	int TM30=0;	//總銷貨額_CARD
   	int TS30=0;	//總銷貨額_BSUM-CASH-CARD-ORDCASH-ORDCARD
   	int StkT=0;		//總存貨量
   	int StkM=0;	//總存貨額
   	int R10;
   	int TR10;
   	int TDisM=0; //本期總尾數折讓
   	
   	int T10=0;  	//本進貨量
   	int M10=0; 	//本進貨額
   	int T30=0;		//本銷貨量
   	int M30=0;	//本銷貨額
   	int S30=0;	//本銷貨額
   	int Profit=0; 	//本期毛利
   	int Profits=0; //本期利率
   	int DisM=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;
	
	ListView mListView = null;
	ListView mListView1 = null;
	ListView mListView2 = null;
	
	int Floor=0;
	int Floor1=0;
//給報表頭合計用	
	public String pt_iGoods; 
	public String pt_iImpo; 
	public String pt_iName; 
	public String pt_iMoney;
	public String pt_iCountry;
	public String pt_iNumber;
	public String pt_iCompany;
	public String pt_iFormdate;
	
	
	public class RepData{ 
		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;
		public String iUnit2;
		public int iSort;
		
	}

	interface GroupMode{
		int TOP1=1;		//薪資總帳表
		int TOP2 = 2;  	//薪資日報表
		int TOP3 = 3; 	//薪資客戶清單
		int TOP4 = 4; 	//
		
	}
	
	@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.qrep01);
        
        mTextDuration = (TextView)findViewById(R.id.text_duration);
        //@@應增加營業時間的判斷而視為當日或前一天
        mStartDay =DateUtil.getCurrentDate();  //2012/10/15 將 batch 視為當日的關鍵"/"
        mEndDay=mStartDay;
       // mMode = getIntent().getIntExtra("search_mode", KeySet.SearchMode.SEASON);
        
        if (!Utilis.getIni(this,"SYS","DEPT",1).equalsIgnoreCase(Utilis.getIni(this,"SYS","DEPT",6))) nPart=1;  //門市版        
        if (nPart==1){
        	mKind="31";
        	nKind=31;
        }else{
        	mKind="3%";
        	nKind=30;
        }
        
        ((Button)findViewById(R.id.btn_exit)).setOnClickListener(new MainClick());		//離開
        
        ((LinearLayout)findViewById(R.id.layout_bottom)).setVisibility(View.GONE);
        ((LinearLayout)findViewById(R.id.layout_tops)).setVisibility(View.GONE);
        ((LinearLayout)findViewById(R.id.layout_top)).setVisibility(View.VISIBLE);
        
        ((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_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)).setText("輸出");
        ((Button)findViewById(R.id.btn_btn4)).setOnClickListener(new MainClick()); //批號

    	((TextView)findViewById(R.id.text_r10t)).setText("業績:");
    	((TextView)findViewById(R.id.text_tott)).setText("達成業績:");
    	((TextView)findViewById(R.id.text_rp0t)).setText("非業績:");
    	
       	((TextView)findViewById(R.id.text_t10t)).setText("應收:");
       	((TextView)findViewById(R.id.text_t30t)).setText("件數:");
       	((TextView)findViewById(R.id.text_r30t)).setText("業績獎金:");
        
        mListView = (ListView)findViewById(R.id.list_item);
        mListView1 = (ListView)findViewById(R.id.list_item1);
        mListView2 = (ListView)findViewById(R.id.list_item2);

        mAdapter = new ReportAdapter(this);
        mAdapter1 = new ReportAdapter(this);
        mAdapter2 = new ReportAdapter(this);
        
        mListView.setAdapter(mAdapter);
        mListView1.setAdapter(mAdapter1);
        mListView2.setAdapter(mAdapter2);
        
     	btns=Utilis.getIni(this,"USER","COMPANY",9);
     	compStr = btns.split(","); 

        //原先就是執行一遍 因為不會中途改變模式
        //現在是可以切換
        //只要一切換,都會從最近日期範圍貨最近一批最近一季起算
        chkMode();
        
        mListView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View v,
					int position, long ids) {
				// TODO Auto-generated method stub
				locationa=position;
				
				Utilis.runVibrate(QRep_14.this);
				DialogUtilis.showDialog(QRep_14.this, "請選擇以下功能", -1,
						menu_S, new IDialog() {
							@Override
							public void onDialogFinish(int pos, String choice) {
								switch (pos) {
									case 0: //業績日報表
									{
										if (mAdapter1.mList != null) {
											mAdapter1.mList.clear();
										}
										if (mAdapter.getCount()>0){
											RepData datas = (RepData) mAdapter.getItem(locationa);
											theEmp=datas.iFormdate;
											//PrepareToReport
											pt_iGoods=datas.iGoods;
											pt_iImpo=datas.iImpo; 
											pt_iName=datas.iName; 
											pt_iMoney=datas.iMoney;
											pt_iCountry=datas.iCountry;
											pt_iNumber=datas.iNumber;
											pt_iCompany=datas.iCompany;
											
											String dbStartDay="";
											String dbEndDay="";
											int pcnts=Utilis.toInt(datas.iCompany.replace("抽成%: ", ""));
											if(mStartDay != null && mStartDay.length() > 0)	dbStartDay = mStartDay.replace("/", "-");
											if(mEndDay != null && mEndDay.length() > 0) dbEndDay = mEndDay.replace("/", "-");
											
											if  (Utilis.haveInternet(QRep_14.this) && Utilis.toInt(Utilis.getIni(QRep_14.this, "SYS", "IMPORT", 3))==1 && mCloud>0){
												StringBuffer bfstr = new StringBuffer();
												StringBuffer bfstrF = new StringBuffer();
												
													bfstr.append(Utilis.getIni(QRep_14.this, "SYS", "IMPORT", 2)).append(";");
													bfstrF.append("UID").append(";");
													bfstr.append(dbStartDay).append(";");
													bfstrF.append("BGDAY").append(";");
													bfstr.append(dbEndDay).append(";");
													bfstrF.append("ENDAY").append(";"); 
													bfstr.append(theEmp).append(";");
													bfstrF.append("EMPID").append(";"); 
													bfstr.append(Utilis.getIni(QRep_14.this,"SYS","DEPT",6)).append(";");
													bfstrF.append("DEPTAA").append(";");  //總倉代號 名稱
													bfstr.append(SQLADD);
													bfstrF.append("SQLADD");  //總倉代號 名稱
													
													final String []fields=bfstr.toString().split(";");
													final String []fieldFs=bfstrF.toString().split(";");
													
												      myDialog = ProgressDialog.show(QRep_14.this,"資料處理中.....","請稍候.............",true);//		setAutoRotationMode();			  
													  
												      new Thread()
												      { 
												        public void run()
												        { 
												          try
												          { 
																uriAPI="http://"+Utilis.getIni(QRep_14.this, "SYS", "IMPORT", 1)+File.separator+Utilis.getIni(QRep_14.this, "SYS", "IMPORT", 2)+File.separator+"qdeptrep_31.php";
																HttpPost httpRequest = new HttpPost(uriAPI);
																// Post運作傳送變數必須用NameValuePair[]陣列儲存
																Log.i("DOWNLOAD_2", "呼叫執行緒PHP___到此一遊"+uriAPI);

																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);
																	// 若狀態碼為200 ok 
																	if (httpResponse.getStatusLine().getStatusCode() == 200)
																	{
																		// 取出回應字串
																		//Toast.makeText(QRep_12.this, "取得前200", Toast.LENGTH_LONG).show();
																		String strResult = EntityUtils.toString(httpResponse	.getEntity());
																		//Toast.makeText(QRep_12.this, "取得"+strResult, Toast.LENGTH_LONG).show();
																		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(QRep_14.this);
											StringBuffer mBuf = new StringBuffer();
											mBuf.append(makeSQLforPrinter(dbStartDay,dbEndDay, theEmp));
											
											Cursor cs=db.rawQuery(mBuf.toString(), null);
											 Toast.makeText(QRep_14.this, "Found__"+cs.getCount(), Toast.LENGTH_LONG).show();
											if (cs.getCount()>0){
												while (cs.moveToNext()){
													RepData data = new RepData();
													data.iFormdate=theEmp;
													data.iGoods=datas.iGoods;
													data.iName=cs.getString(0);
													DisM=getDismoney(db,data.iName,theEmp,1);
													data.iCountry=cs.getString(2)+"件/折"+DisM;
													data.iImpo="應收金額:"+cs.getString(3);
													data.iCompany="達成業績:"+(cs.getInt(5)-DisM);
													data.iMoney="業績獎金:"+(cs.getInt(5)-DisM)*pcnts/100;
													mAdapter1.mList.add(data);
												}
											Floor=1;Floor1=1;
									        ((Button)findViewById(R.id.btn_btn0)).setVisibility(View.INVISIBLE);	//週        
									        ((Button)findViewById(R.id.btn_btn1)).setVisibility(View.INVISIBLE);  //月
									        ((Button)findViewById(R.id.btn_btn2)).setVisibility(View.INVISIBLE);//季
									        ((Button)findViewById(R.id.btn_btn3)).setVisibility(View.INVISIBLE);
									        ((Button)findViewById(R.id.btn_prev_date)).setVisibility(View.INVISIBLE);//上一
									        ((Button)findViewById(R.id.btn_next_date)).setVisibility(View.INVISIBLE);//下一

											
											((ListView)findViewById(R.id.list_item)).setVisibility(View.GONE);
											((ListView)findViewById(R.id.list_item1)).setVisibility(View.VISIBLE);
											
											mAdapter1.notifyDataSetChanged();
											
											mTextDuration.setText(datas.iGoods+"/ "+ mStartDay + "~" + mEndDay);
											}
											cs.close();
											db.close();
											}
										}										
										break;
									}
									case 1: //達成業績客戶表
									{
										if (mAdapter1.mList != null) {
											mAdapter1.mList.clear();
										}
										if (mAdapter.getCount()>0){
											RepData datas = (RepData) mAdapter.getItem(locationa);
											theEmp=datas.iFormdate;
											//PrepareToReport
											pt_iGoods=datas.iGoods;
											pt_iImpo=datas.iImpo; 
											pt_iName=datas.iName; 
											pt_iMoney=datas.iMoney;
											pt_iCountry=datas.iCountry;
											pt_iNumber=datas.iNumber;
											pt_iCompany=datas.iCompany;
											String dbStartDay="";
											String dbEndDay="";
											int pcnts=Utilis.toInt(datas.iCompany.replace("抽成%: ", ""));
											StringBuffer mBuf = new StringBuffer();

											if(mStartDay != null && mStartDay.length() > 0)	dbStartDay = mStartDay.replace("/", "-");
											if(mEndDay != null && mEndDay.length() > 0) dbEndDay = mEndDay.replace("/", "-");
											mBuf.append(makeSQLforPrinterUser(dbStartDay,dbEndDay, theEmp));
											
											if  (Utilis.haveInternet(QRep_14.this) && Utilis.toInt(Utilis.getIni(QRep_14.this, "SYS", "IMPORT", 3))==1 && mCloud>0){
												StringBuffer bfstr = new StringBuffer();
												StringBuffer bfstrF = new StringBuffer();
												
													bfstr.append(Utilis.getIni(QRep_14.this, "SYS", "IMPORT", 2)).append(";");
													bfstrF.append("UID").append(";");
													bfstr.append(dbStartDay).append(";");
													bfstrF.append("BGDAY").append(";");
													bfstr.append(dbEndDay).append(";");
													bfstrF.append("ENDAY").append(";"); 
													bfstr.append(theEmp).append(";");
													bfstrF.append("EMPID").append(";"); 
													bfstr.append(Utilis.getIni(QRep_14.this,"SYS","DEPT",6)).append(";");
													bfstrF.append("DEPTAA").append(";");  //總倉代號 名稱
													bfstr.append(SQLADD);
													bfstrF.append("SQLADD");  //總倉代號 名稱
													
													final String []fields=bfstr.toString().split(";");
													final String []fieldFs=bfstrF.toString().split(";");
													
												      myDialog = ProgressDialog.show(QRep_14.this,"資料處理中.....","請稍候.............",true);//		setAutoRotationMode();			  
													  
												      new Thread()
												      { 
												        public void run()
												        { 
												          try
												          { 
																uriAPI="http://"+Utilis.getIni(QRep_14.this, "SYS", "IMPORT", 1)+File.separator+Utilis.getIni(QRep_14.this, "SYS", "IMPORT", 2)+File.separator+"qdeptrep_31.php";
																HttpPost httpRequest = new HttpPost(uriAPI);
																// Post運作傳送變數必須用NameValuePair[]陣列儲存
																Log.i("DOWNLOAD_2", "呼叫執行緒PHP___到此一遊"+uriAPI);

																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);
																	// 若狀態碼為200 ok 
																	if (httpResponse.getStatusLine().getStatusCode() == 200)
																	{
																		// 取出回應字串
																		//Toast.makeText(QRep_12.this, "取得前200", Toast.LENGTH_LONG).show();
																		String strResult = EntityUtils.toString(httpResponse	.getEntity());
																		//Toast.makeText(QRep_12.this, "取得"+strResult, Toast.LENGTH_LONG).show();
																		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(QRep_14.this);
											Cursor cs=db.rawQuery(mBuf.toString(), null);
											 Toast.makeText(QRep_14.this, "Found__"+cs.getCount(), Toast.LENGTH_LONG).show();
											if (cs.getCount()>0){
												while (cs.moveToNext()){
													RepData data = new RepData();							
													data.iFormdate=theEmp;
													data.iGoods=cs.getString(1);
													data.iName=cs.getString(0);
													//帶入會員編號 &EMPID
													DisM=getDismoney(db,data.iName,theEmp,2);
													data.iCountry=cs.getString(2)+"件/折"+DisM;
													data.iImpo="應收金額:"+cs.getString(3);
													data.iCompany="達成業績:"+(cs.getInt(5)-DisM);
													data.iMoney="業績獎金:"+(cs.getInt(5)-DisM)*pcnts/100;
													mAdapter1.mList.add(data);
												}
											Floor=1;Floor1=2;
									        ((Button)findViewById(R.id.btn_btn0)).setVisibility(View.INVISIBLE);	//週        
									        ((Button)findViewById(R.id.btn_btn1)).setVisibility(View.INVISIBLE);  //月
									        ((Button)findViewById(R.id.btn_btn2)).setVisibility(View.INVISIBLE);//季
									        ((Button)findViewById(R.id.btn_btn3)).setVisibility(View.INVISIBLE);
									        ((Button)findViewById(R.id.btn_prev_date)).setVisibility(View.INVISIBLE);//上一
									        ((Button)findViewById(R.id.btn_next_date)).setVisibility(View.INVISIBLE);//下一

											
											((ListView)findViewById(R.id.list_item)).setVisibility(View.GONE);
											((ListView)findViewById(R.id.list_item1)).setVisibility(View.VISIBLE);
											
											mAdapter1.notifyDataSetChanged();
											
											mTextDuration.setText(datas.iGoods+"/ "+ mStartDay + "~" + mEndDay);
											}
											cs.close();
											db.close();
											}
										}										
										break;
									}
									case 2: //返回
									{
										break;
									}
								}
							}				
				});
			}
		});

        mListView1.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View v,
					int position, long ids) {
				// TODO Auto-generated method stub
				locations=position;
				
				Utilis.runVibrate(QRep_14.this);
				DialogUtilis.showDialog(QRep_14.this, "請選擇以下功能", -1,
						menu_B, new IDialog() {
							@Override
							public void onDialogFinish(int pos, String choice) {
								switch (pos) {
									case 0: //每日交易明細
									{
										if (mAdapter2.mList != null) {
											mAdapter2.mList.clear();
										}
										if (mAdapter1.getCount()>0){
											RepData datas = (RepData) mAdapter1.getItem(locations);
											if  (Utilis.haveInternet(QRep_14.this) && Utilis.toInt(Utilis.getIni(QRep_14.this, "SYS", "IMPORT", 3))==1 && mCloud>0){
												StringBuffer bfstr = new StringBuffer();
												StringBuffer bfstrF = new StringBuffer();
												
													bfstr.append(Utilis.getIni(QRep_14.this, "SYS", "IMPORT", 2)).append(";");
													bfstrF.append("UID").append(";");
													bfstr.append(datas.iName).append(";");
													bfstrF.append("BGDAY").append(";");
													bfstr.append(datas.iName).append(";");
													bfstrF.append("ENDAY").append(";"); 
													bfstr.append(theEmp).append(";");
													bfstrF.append("EMPID").append(";"); 
													bfstr.append(Utilis.getIni(QRep_14.this,"SYS","DEPT",6)).append(";");
													bfstrF.append("DEPTAA").append(";");  //總倉代號 名稱
													bfstr.append(SQLADD);
													bfstrF.append("SQLADD");  //總倉代號 名稱
													
													final String []fields=bfstr.toString().split(";");
													final String []fieldFs=bfstrF.toString().split(";");
													
												      myDialog = ProgressDialog.show(QRep_14.this,"資料處理中.....","請稍候.............",true);//		setAutoRotationMode();			  
													  
												      new Thread()
												      { 
												        public void run()
												        { 
												          try
												          { 
																uriAPI="http://"+Utilis.getIni(QRep_14.this, "SYS", "IMPORT", 1)+File.separator+Utilis.getIni(QRep_14.this, "SYS", "IMPORT", 2)+File.separator+"qdeptrep_32.php";
																HttpPost httpRequest = new HttpPost(uriAPI);
																// Post運作傳送變數必須用NameValuePair[]陣列儲存
																Log.i("DOWNLOAD_2", "呼叫執行緒PHP___到此一遊"+uriAPI);

																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_32.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(QRep_14.this);
											StringBuffer mBuf = new StringBuffer();
											if (Floor1==1){
											mBuf.append("select FORMNO,USER,USERNAME,HANDNO,BSUM,CASH,CARD,ORDCASH,ORDCARD,ATM");
											mBuf.append(" from qhead ");
										    mBuf.append(" where  (( FORMDATE = '").append(datas.iName).append("' and ISCONFIRM='Y' ) or ")
											.append(" ( FINEDATE<>'' and FINEDATE='").append(datas.iName).append("' and ISCONFIRM='Y') )");
											mBuf.append(" and EMPID='").append(theEmp).append("' and ")
											.append(SQLADD)
											.append(" order by FORMNO");
											
											}else{
												String Bg="";String En="";
												if(mStartDay != null && mStartDay.length() > 0)	Bg = mStartDay.replace("/", "-");
												if(mEndDay != null && mEndDay.length() > 0) En = mEndDay.replace("/", "-");

												mBuf.append("select FORMNO,USER,USERNAME,HANDNO,BSUM,CASH,CARD,ORDCASH,ORDCARD,ATM");
												mBuf.append(" from qhead where ").append(SQLADD);
												mBuf.append(" and  (( FORMDATE >= '").append(Bg).append("' and FORMDATE <= '").append(En).append("' ) or ")
												.append(" ( FINEDATE<>'' and FINEDATE >= '").append(Bg).append("' and FINEDATE <= '").append(En).append("' ))");
												mBuf.append(" and USER='").append(datas.iName)
												.append("' and EMPID='").append(theEmp).append("'")
												.append(" order by FORMNO");
											}
											
											Cursor cs=db.rawQuery(mBuf.toString(), null);
											if (cs.getCount()>0){
												while (cs.moveToNext()){
													RepData data = new RepData();
													data.iFormdate=theEmp;
													data.iGoods=cs.getString(1)+"/"+cs.getString(2);
													data.iName=cs.getString(0);
													data.iCountry=cs.getString(3);
													data.iImpo="應收:"+cs.getString(4);
													data.iMoney="現金:"+cs.getString(5)+" 卡:"+cs.getString(6)+" 匯:"+cs.getString(9);
													data.iCompany="訂金:"+cs.getString(7)+" 卡:"+cs.getString(8);
													mAdapter2.mList.add(data);
												}
											Floor=2;
											mAdapter2.notifyDataSetChanged();
											
											((ListView)findViewById(R.id.list_item1)).setVisibility(View.GONE);
											((ListView)findViewById(R.id.list_item2)).setVisibility(View.VISIBLE);
											mTextDuration.setText(datas.iGoods+"/ "+ mStartDay + "~" + mEndDay);
											}
											cs.close();
											db.close();
											
										}
										}
										break;
									}
									case 1: //返回
									{
										break;
									}
								}
							}				
				});
			}
		});
        
}	
	
	public void onResume(){
		super.onResume();
		
		//表示非外來程式 
//			getGroupData(QRep_01.this, mStartDay, mEndDay, null, null);
		
		DBCloud.aa0_aa1_auto_HI(this,nKind);
		
		Floor=0;Floor1=0;
        ((Button)findViewById(R.id.btn_btn0)).setVisibility(View.VISIBLE);	//週        
        ((Button)findViewById(R.id.btn_btn1)).setVisibility(View.VISIBLE);  //月
        ((Button)findViewById(R.id.btn_btn2)).setVisibility(View.VISIBLE);//季
        ((Button)findViewById(R.id.btn_btn3)).setVisibility(View.VISIBLE);
		((ListView)findViewById(R.id.list_item)).setVisibility(View.VISIBLE);
        ((Button)findViewById(R.id.btn_prev_date)).setVisibility(View.VISIBLE);//上一
        ((Button)findViewById(R.id.btn_next_date)).setVisibility(View.VISIBLE);//下一
		((ListView)findViewById(R.id.list_item1)).setVisibility(View.GONE);
		
		
			mAdapter.notifyDataSetChanged();
		}


 	@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
          new AlertDialog.Builder(QRep_14.this).setTitle(getString(R.string.str_msg)).setMessage(getString(R.string.msg_rep14_exit)).setPositiveButton(getString(R.string.str_ok), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
              finish();
            }
          }).setNegativeButton(getString(R.string.str_cancel), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
            }
          }).show();
          return true;
        } else {
          return super.onKeyDown(keyCode, event);
        }
    }

	
	private void setCondition(){
		mTextDuration.setText(" "+ mStartDay + "~" + mEndDay);
	}
	
	// 特別處理 日結單 GROUPS第一層 是以(日/週/月)為統計結算 childs第二層 才是單頭
	//如何分開 日結+單頭  及 單頭+單身 的製作就是關鍵
	public void getGroupData(Context context, String dbStartDay, String dbEndDay, String condition, String conditionValue) {
					
			if (mAdapter.mList != null) {
				mAdapter.mList.clear();
			}
			if(dbStartDay != null && dbStartDay.length() > 0)	dbStartDay = dbStartDay.replace("/", "-");
			if(dbEndDay != null && dbEndDay.length() > 0) dbEndDay = dbEndDay.replace("/", "-");
			
			TT10=0;  TM10=0; 	TT30=0;	TM30=0;
			TS30=0;	 StkT=0;		StkM=0;	
			Profit=0; Profits=0;	TR10=0; 
			
			if  (Utilis.haveInternet(context) && Utilis.toInt(Utilis.getIni(context, "SYS", "IMPORT", 3))==1 && mCloud>0){
				StringBuffer bfstr = new StringBuffer();
				StringBuffer bfstrF = new StringBuffer();
				
					bfstr.append(Utilis.getIni(this, "SYS", "IMPORT", 2)).append(";");
					bfstrF.append("UID").append(";");
					bfstr.append(dbStartDay).append(";");
					bfstrF.append("BGDAY").append(";");
					bfstr.append(dbEndDay).append(";");
					bfstrF.append("ENDAY").append(";");  //總倉代號 名稱
					bfstr.append(Utilis.getIni(QRep_14.this,"SYS","DEPT",1)).append(";");
					bfstrF.append("EMPID").append(";");  //總倉代號 名稱
					bfstr.append(Utilis.getIni(QRep_14.this,"SYS","DEPT",6)).append(";");
					bfstrF.append("DEPTAA").append(";");  //總倉代號 名稱
					bfstr.append(SQLADD);
					bfstrF.append("SQLADD");  //總倉代號 名稱
					
					final String []fields=bfstr.toString().split(";");
					final String []fieldFs=bfstrF.toString().split(";");
					
				      myDialog = ProgressDialog.show(this,"資料處理中.....","請稍候.............",true);//		setAutoRotationMode();			  
					  
				      new Thread()
				      { 
				        public void run()
				        { 
				          try
				          { 
								uriAPI="http://"+Utilis.getIni(QRep_14.this, "SYS", "IMPORT", 1)+File.separator+Utilis.getIni(QRep_14.this, "SYS", "IMPORT", 2)+File.separator+"qdeptrep_30.php";
								HttpPost httpRequest = new HttpPost(uriAPI);
								// Post運作傳送變數必須用NameValuePair[]陣列儲存
								Log.i("DOWNLOAD_2", "呼叫執行緒PHP___到此一遊"+uriAPI);

								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);
									// 若狀態碼為200 ok 
									if (httpResponse.getStatusLine().getStatusCode() == 200)
									{
										// 取出回應字串
										//Toast.makeText(QRep_12.this, "取得前200", Toast.LENGTH_LONG).show();
										String strResult = EntityUtils.toString(httpResponse	.getEntity());
										//Toast.makeText(QRep_12.this, "取得"+strResult, Toast.LENGTH_LONG).show();
										mHandlerQDR_30.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);
								try {
									Cursor cursorGroup = null;
					
									StringBuffer bufCategory = new StringBuffer();
								
									 Toast.makeText(QRep_14.this, "對帳自_"+dbStartDay+"至_"+dbEndDay+"為止", Toast.LENGTH_LONG).show();
					
									//以日期範圍依進貨優先定出商品範圍,再讀取 到目前總進 總銷
									//所取得的商品,再一一檢查之前不存在,才能視為新品
									//GroupMode.TOP1 到新品   TOP2 暢銷  TOP3 預購  TOP4 追加
									bufCategory=bufCategory.delete(0, bufCategory.toString().length());
							    	bufCategory.append("select EMPID,")
							    	.append("sum(SUBPRICE),sum(UNIT30),sum(UNIT30*P2),sum(SUBPRICE-UNIT30*P2)")
							    	.append(" from qitems");
					
							    	bufCategory.append(" where  (( FORMDATE >= '").append(dbStartDay).append("' and FORMDATE <= '").append(dbEndDay).append("' and ISCONFIRM='Y' ) or ")
									.append(" ( FINEDATE<>'' and FINEDATE >= '").append(dbStartDay).append("' and FINEDATE <= '").append(dbEndDay).append("' and ISCONFIRM='Y' )) and ");
									bufCategory.append(SQLADD)
							    	.append(" group by EMPID");
									
					 				cursorGroup = db.rawQuery(bufCategory.toString(), null);
									int chked=0;
					 				
									if (cursorGroup != null) {
										if (cursorGroup.getCount() > 0) {
											cursorGroup.moveToFirst();
											for (int i = 0; i < cursorGroup.getCount(); i++) {
												RepData data = new RepData();							
												data.iFormdate=cursorGroup.getString(0); //業務代號 做為KEY 不顯示
												theEmp=data.iFormdate;
												String [] empData =getEmpName(db,theEmp);
												data.iGoods=theEmp+"/"+empData[0];
												data.iCompany="抽成%: "+empData[1]; //原結欠
												
												DisM=getDismoney(db,mStartDay,theEmp,0);
												
												TR10=TR10+cursorGroup.getInt(4); //達成業績
												Profits=Profits+cursorGroup.getInt(3);  //基本業績
												data.iImpo="達成業績:"+cursorGroup.getInt(4); //達成業績
												T10=cursorGroup.getInt(1); //本期應收
												TT10=TT10+T10;  //總應收
												M10=cursorGroup.getInt(3);//成本_基本業績
												TM10=TM10+M10;//成本_總基本業績
												T30=cursorGroup.getInt(2); //現金收入_件數
												TT30=TT30+T30;  //總件數
												data.iName="應收:"+cursorGroup.getInt(1)+"尾數折讓:"+DisM;
												TDisM=TDisM+DisM;
												S30=cursorGroup.getInt(4)-DisM; //達成業績
												StkT=StkT+S30;
												Profit=Profit+(S30*Utilis.toInt(empData[1])/100);
												data.iCountry="件數小計:"+cursorGroup.getInt(2); 
												data.iMoney="業績獎金:"+S30*Utilis.toInt(empData[1])/100;
					
						 						mAdapter.mList.add(data);	
												cursorGroup.moveToNext();
											}	
					 					}	
			 				}
										cursorGroup.close();
						 				db.close();
										showTitleA();
										
								} catch (Exception e) {
									e.printStackTrace();
								}
			}								
		}
	
	private void showTitleA(){
			((TextView)findViewById(R.id.text_tot)).setText("$:"+(StkT));  //達成業績
			((TextView)findViewById(R.id.text_mtot)).setText(""); 
			((TextView)findViewById(R.id.text_r10)).setText("$:"+TR10);//業績

			((TextView)findViewById(R.id.text_t10)).setText("$:"+TT10);//總應收
			 if (PSWD==1) ((TextView)findViewById(R.id.text_m10)).setText("");
			 	else ((TextView)findViewById(R.id.text_m10)).setText("("+(TT10-TM10-TDisM)+")");//總毛利
			 
			((TextView)findViewById(R.id.text_t30)).setText("$:"+TT30);  //總件數
			((TextView)findViewById(R.id.text_m30)).setText("(折:"+TDisM+")"); //總尾數折讓
			((TextView)findViewById(R.id.text_r30)).setText("$:"+(Profit)); //總業績獎金
			((TextView)findViewById(R.id.text_rp0)).setText("$:"+(Profits));//非業績
	}
	
	class MainClick implements OnClickListener { //所有的觸發事件,在此集中管理
		@Override
		public void onClick(View v) {
			int id = v.getId();
			Utilis.runVibrate(QRep_14.this);
			switch (id) {
				case R.id.btn_exit:
				{
				if (Floor==0){	
		        	finish();
				}else if (Floor==1){
					Floor=0;Floor1=0;
			        ((Button)findViewById(R.id.btn_btn0)).setVisibility(View.VISIBLE);	//週        
			        ((Button)findViewById(R.id.btn_btn1)).setVisibility(View.VISIBLE);  //月
			        ((Button)findViewById(R.id.btn_btn2)).setVisibility(View.VISIBLE);//季
			        ((Button)findViewById(R.id.btn_btn3)).setVisibility(View.VISIBLE);
			        ((Button)findViewById(R.id.btn_prev_date)).setVisibility(View.VISIBLE);//上一
			        ((Button)findViewById(R.id.btn_next_date)).setVisibility(View.VISIBLE);//下一
					
					((ListView)findViewById(R.id.list_item)).setVisibility(View.VISIBLE);
					((ListView)findViewById(R.id.list_item1)).setVisibility(View.GONE);
					mTextDuration.setText(" "+ mStartDay + "~" + mEndDay);
				}else if (Floor==2){
					Floor=1;
					((ListView)findViewById(R.id.list_item1)).setVisibility(View.VISIBLE);
					((ListView)findViewById(R.id.list_item2)).setVisibility(View.GONE);
				}
					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:  //輸出
				{
					//可能是 Floor1==0總表 (1日報 2會員)
					Utilis.runVibrate(QRep_14.this);
					DialogUtilis.showDialog(QRep_14.this, "請選擇以下功能", -1,
							menu_C, new IDialog() {
								@Override
								public void onDialogFinish(int pos, String choice) {
									switch (pos) {
										case 0: //直接印出
										{
											StringBuffer sPrintB = new StringBuffer();
											String sepa="\r\n";
											int Loca=0;
											sPrintB.append("^QXXXX,0,0"+sepa);
											sPrintB.append("^W56"+sepa+"^H6"+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+2;sPrintB.append("AZ,10,"+Loca+",2,2,0,0,"+compStr[0]+sepa);
											if (Floor==0){
											Loca=Loca+50;sPrintB.append("AZ,30,"+Loca+",2,2,0,0,"+menu_E[(int)(nKind/10)-1]+"業績獎金對帳"+sepa);
											Loca=Loca+50;sPrintB.append("AZ,20,"+Loca+",1,2,0,0,期間: 自"+mStartDay+"~"+mEndDay+sepa);
											Loca=Loca+50;sPrintB.append("AZ,20,"+Loca+",1,2,0,0,總應收:$"+TT10+sepa);
																		sPrintB.append("AZ,232,"+Loca+",1,2,0,0,達成業績:$"+TR10+sepa);
											Loca=Loca+50;sPrintB.append("AZ,20,"+Loca+",1,2,0,0,總件數 : "+TT30+sepa);
											Loca=Loca+50;sPrintB.append("AZ,20,"+Loca+",1,2,0,0,不算業績:$"+Profits+sepa);
																		sPrintB.append("AZ,232,"+Loca+",1,2,0,0,業績獎金:$"+Profit+sepa);
											Loca=Loca+35;sPrintB.append("AZ,10,"+Loca+",1,2,0,0,--------------------------------------"+sepa);
											}  else if (Floor==1){//每日業績表
												Loca=Loca+50;sPrintB.append("AZ,30,"+Loca+",2,2,0,0,"+pt_iGoods+"_"+menu_E[(int)(nKind/10)-1]+"業績明細"+sepa);
												Loca=Loca+50;sPrintB.append("AZ,20,"+Loca+",1,2,0,0,期間: 自"+mStartDay+"~"+mEndDay+sepa);
												Loca=Loca+50;sPrintB.append("AZ,20,"+Loca+",1,2,0,0,"+pt_iName+sepa);
														sPrintB.append("AZ,232,"+Loca+",1,2,0,0,"+pt_iImpo+sepa);
												Loca=Loca+50;sPrintB.append("AZ,20,"+Loca+",1,2,0,0,"+pt_iCountry+sepa);
														sPrintB.append("AZ,232,"+Loca+",1,2,0,0,"+pt_iCompany+sepa);
												Loca=Loca+50;sPrintB.append("AZ,20,"+Loca+",1,2,0,0,"+pt_iMoney+sepa);
												Loca=Loca+35;sPrintB.append("AZ,10,"+Loca+",1,2,0,0,--------------------------------------"+sepa);
											}
											for (int ij=0;ij<mAdapter.getCount();ij++){
												RepData datas = (RepData) mAdapter.getItem(ij);
												theEmp=datas.iFormdate;
												Loca=Loca+35;sPrintB.append("AZ,10,"+Loca+",1,1,0,0,業務:"+datas.iGoods+sepa);
												Loca=Loca+25;sPrintB.append("AZ,20,"+Loca+",1,1,0,0,"+datas.iName+sepa);
																						sPrintB.append("AZ,232,"+Loca+",1,1,0,0,"+datas.iImpo+sepa);
												Loca=Loca+25;sPrintB.append("AZ,20,"+Loca+",1,1,0,0,"+datas.iCompany+sepa);
																						sPrintB.append("AZ,232,"+Loca+",1,1,0,0,"+datas.iMoney+sepa);
												Loca=Loca+25;sPrintB.append("AZ,20,"+Loca+",1,1,0,0,"+datas.iCountry+sepa);
											}
											
											Loca=Loca+25;sPrintB.append("AZ,10,"+Loca+",1,2,0,0,--------------------------------------"+sepa);
											if (sPrintB.toString().length()>0){
												Loca=Loca+65;sPrintB.append("AZ,20,"+Loca+",1,1,0,0,"+"[管制單]:這是一份內部結算明細清冊，"+sepa);
												Loca=Loca+30;sPrintB.append("AZ,20,"+Loca+",1,1,0,0,"+"並由相關人員檢視後,進行催帳事宜。"+sepa);
												Loca=Loca+30;sPrintB.append("AZ,20,"+Loca+",1,1,0,0,印製:"+DateUtil.getCurrentTime()+sepa);
												Loca=Loca+60;
												String lenS="0000"+(int)(Loca/7.2);
												sPrintB.replace(2, 6,lenS.substring(lenS.length()-4,lenS.length()));
												sPrintB.append("E"+sepa);
										        //Send to BarPrinter 
												String address=Utilis.getIni(QRep_14.this, "SYS","BAR_IP", 4);// 連線的ip
												int port=0;
												int success=1;
												   port =Utilis.toInt(Utilis.getIni(QRep_14.this, "SYS","BAR_IP", 5));// 連線的port
													 InetAddress serverAddr = null;
												        SocketAddress sc_add = null;
												        Socket socket = null;
									
															 try {
																 serverAddr = InetAddress.getByName(address);
																 sc_add= new InetSocketAddress(serverAddr,port);
																	 socket = new Socket();
																	 socket.connect(sc_add,2000);
																	 DataOutputStream out = new DataOutputStream(socket.getOutputStream());
																	 byte data[] = new String(sPrintB.toString().getBytes("UTF8")).getBytes("BIG5");
																	 out.write(data, 0, data.length);
																	 socket.close();
																	 Toast.makeText(QRep_14.this, "已成功傳送資訊到條碼機!!", Toast.LENGTH_LONG).show();
															 } catch (UnknownHostException e) {
																 success=0;
															 } catch (SocketException e) {
																 success=0;
															 } catch(IOException e) {
																 success=0;
															 }
												}
											break;
										}
										case 1: //製作CSV
										{
											StringBuffer sPrintB = new StringBuffer();
											String sepa="\r\n";
											sPrintB.append(";"+compStr[0]+";;;印製:"+DateUtil.getCurrentTime()+sepa);
											
											if (Floor==0){
												sPrintB.append(";"+menu_E[(int)(nKind/10)-1]+"業績獎金對帳");
												sPrintB.append(";;期間: 自"+mStartDay+";~"+mEndDay+";"+sepa);
												sPrintB.append(sepa);
												sPrintB.append("總應收:$;"+TT10+";達成業績:$;"+TR10+";總件數 : "+TT30+";尾數折讓:"+DisM+";業績獎金:$;"+Profit+";"+sepa);
												sPrintB.append(sepa);
												for (int ij=0;ij<mAdapter.getCount();ij++){
													RepData datas = (RepData) mAdapter.getItem(ij);
													theEmp=datas.iFormdate;
													sPrintB.append(datas.iGoods+";"+datas.iName+";"+datas.iImpo+";"+datas.iCompany+";"+datas.iMoney+";"+datas.iCountry+sepa);
												}
											}  else if (Floor==1){//每日業績表
												sPrintB.append(";"+pt_iGoods+menu_E[(int)(nKind/10)-1]+"業績明細");
												sPrintB.append(";期間: 自"+mStartDay+";~"+mEndDay+";"+sepa);
												sPrintB.append(sepa);
												sPrintB.append(pt_iName+";"+pt_iImpo+";"+pt_iCountry+";"+pt_iCompany+";"+pt_iMoney+";"+sepa);
												sPrintB.append(sepa);
												for (int ij=0;ij<mAdapter1.getCount();ij++){
													RepData datas = (RepData) mAdapter1.getItem(ij);
													theEmp=datas.iFormdate;
													sPrintB.append(datas.iGoods+";"+datas.iName+";"+datas.iImpo+";"+datas.iCompany+";"+datas.iMoney+";"+datas.iCountry+sepa);
												}
											}
											sPrintB.append(sepa);
											if (sPrintB.toString().length()>0){
												sPrintB.append(";[管制單]:這是一份內部結算明細清冊，"+sepa);
												sPrintB.append(";並由相關人員檢視後,進行催帳事宜。"+sepa);
					
										 		String batchFile=myImportPath+File.separator+"SalesReport.txt";  //預設為分色尺寸
										        File myFile = new File(batchFile); //其目的是為了產生一個新檔案或資料夾
										        if (myFile.exists()){
										        	myFile.delete();
										        }
								        		try {
								                    Writer out = new BufferedWriter(new OutputStreamWriter(
								                    	    new FileOutputStream(myFile), "UTF-8"));
								                    	try {
								                    	    out.write(sPrintB.toString());
								                    	} finally {
								                    	    out.close();
								                    	}                    
								        		} catch (Exception e) {
								        		}
								    			//進一步輸出,多媒體選擇
								    	    	Intent send = new Intent(Intent.ACTION_SEND);
								    	    	send.setType("image/jpeg");
								    		    String uriText;
								    		    Uri U=Uri.parse("file://"+myFile);  //重要的範例
								    		    uriText = "請選擇存入媒體種類";
								    		    send.putExtra(Intent.ACTION_SENDTO,uriText);
								    		    send.putExtra(Intent.EXTRA_STREAM,U);
								    		    startActivity(Intent.createChooser(send, uriText));
											}
											break;
										}
										case 2://返回
									}
								}				
					});
					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);
			    			break;
			    		}
						case KeySet.SearchMode.WEEK:  //就是7筆日結單(日期+單頭)
			    		{
			    			mStartDay = DateUtil.addDate(mStartDay, -7);
							mEndDay = DateUtil.addDate(mEndDay, -7);
			    			break;
			    		}
					}
					setCondition();
					getGroupData(QRep_14.this,mStartDay, mEndDay, null, null);
					mAdapter.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.WEEK:
			    		{
			    			mStartDay = DateUtil.addDate(mStartDay, 7);
							mEndDay = DateUtil.addDate(mEndDay, 7);
			    			break;
			    		}
					}
					setCondition();
					getGroupData(QRep_14.this,mStartDay, mEndDay, null, null);
					mAdapter.notifyDataSetChanged();
					break;

				}
			}
		}
	}
	

	Handler mHandlerQDR_30 = 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 ){
					Log.i("DOWNLOAD_5_mHandlerQC===", ""+Hresult);						
					if (Hresult.indexOf("\r\n")>2){
						
						String Linea [] = Hresult.split("\r\n");
							
						for (int xx=0;xx<Linea.length;xx++){
							String Lines[] =Linea [xx].split(",");

							RepData data = new RepData();							
							data.iGoods=Lines[1].trim();
							data.iFormdate=Lines[1].trim();
							TR10=TR10+(Utilis.toInt(Lines[10])-Utilis.toInt(Lines[11])); //前欠
							Profits=Profits+(Utilis.toInt(Lines[10]));  //總結欠
							data.iImpo="前帳:"+(Utilis.toInt(Lines[10])-Utilis.toInt(Lines[11]));
//							 if (Utilis.toInt(Lines[10]) !=0 || Utilis.toInt(Lines[11])!=0 ) {data.iSort=1;} else data.iSort=0;  //做為未來是否傳送資料依據
							
							T10=Utilis.toInt(Lines[2]); //本期應收
							TT10=TT10+T10;  //
							M10=Utilis.toInt(Lines[3]);//成本
							TM10=TM10+M10;//成本
							T30=Utilis.toInt(Lines[4]); //現金收入
							TT30=TT30+T30;
							M30=Utilis.toInt(Lines[5]); //票卡收入
							TM30=TM30+M30;
							S30=Utilis.toInt(Lines[6]); //訂現收入
							StkT=StkT+S30;
							R10=Utilis.toInt(Lines[7]); //訂刷收入
							StkM=StkM+R10;
							
							Profit=Profit+(T10-(T30+M30+S30+R10+Utilis.toInt(Lines[9])));

							data.iCompany="結欠:"+Utilis.toInt(Lines[10]); //到目前為止
							
//							 if(nKind!=PItemKind.TR10  && nKind!=PItemKind.TR20 && nKind!=PItemKind.TR21){  
								 //data.iPic=cursorGroup.getString(10);  	//圖片
							if (PSWD==1)
								data.iName="應收:"+T10;  //毛利
							else
								data.iName="應收:"+T10+"("+(T10-M10)+")";  //毛利

								data.iCountry="已收:"+(T30+S30)+" 卡:"+(M30+R10);
								data.iMoney="未收:"+(T10-(T30+M30+S30+R10));
//							 } else {
//								data.iName="應付:"+T10+"("+(T10-M10)+")";  //毛利
//								data.iCountry="已付:"+(T30+S30)+" 卡:"+(M30+R10);
//								data.iMoney="未付:"+(T10-(T30+M30+S30+R10));
//							 }
							
	 						mAdapter.mList.add(data);	
						}
 						mAdapter.notifyDataSetChanged();
					}
				}
				showTitleA();
			}
		}
	};
	

	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 ){
					Log.i("DOWNLOAD_6_mHandlerQC===", ""+Hresult);						
					if (Hresult.indexOf("\r\n")>2){
						String Linea [] = Hresult.split("\r\n");
							
						for (int xx=0;xx<Linea.length;xx++){
							String Lines[] =Linea [xx].split(",");

							RepData data = new RepData();							
							data.iFormdate=Lines[1]; //
							data.iGoods=Lines[1]; //

							data.iGoods=Lines[2];
							data.iName=Lines[1];
							data.iCountry=Lines[3];
							data.iImpo="應收:"+Lines[4];
							data.iMoney="現金:"+Lines[5]+" 匯卡:"+Lines[6];
							data.iCompany="訂金:"+Lines[7]+" 卡:"+Lines[8];
							
	 						mAdapter1.mList.add(data);	
						}						
						Floor=1;
				        ((Button)findViewById(R.id.btn_btn0)).setVisibility(View.INVISIBLE);	//週        
				        ((Button)findViewById(R.id.btn_btn1)).setVisibility(View.INVISIBLE);  //月
				        ((Button)findViewById(R.id.btn_btn2)).setVisibility(View.INVISIBLE);//季
				        ((Button)findViewById(R.id.btn_btn3)).setVisibility(View.INVISIBLE);
				        ((Button)findViewById(R.id.btn_prev_date)).setVisibility(View.INVISIBLE);//上一
				        ((Button)findViewById(R.id.btn_next_date)).setVisibility(View.INVISIBLE);//下一

						
						((ListView)findViewById(R.id.list_item)).setVisibility(View.GONE);
						((ListView)findViewById(R.id.list_item1)).setVisibility(View.VISIBLE);
						
						mAdapter1.notifyDataSetChanged();
					}
				}
			}
		}
	};
	

	Handler mHandlerQDR_32 = 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 ){
					Log.i("DOWNLOAD_6_mHandlerQC===", ""+Hresult);						
					if (Hresult.indexOf("\r\n")>2){
						String Linea [] = Hresult.split("\r\n");
							
						for (int xx=0;xx<Linea.length;xx++){
							String Lines[] =Linea [xx].split(",");

							RepData data = new RepData();							
							data.iGoods=Lines[2]+"/"+Lines[3];
							data.iName=Lines[1];
							data.iCountry=Lines[4];
							data.iImpo="應收:"+Lines[5];
							data.iMoney="現金:"+Lines[6]+" 匯卡:"+Lines[7];
							data.iCompany="訂金:"+Lines[8]+" 卡:"+Lines[9];
							mAdapter2.mList.add(data);
						}
					Floor=2;
					mAdapter2.notifyDataSetChanged();
					
					((ListView)findViewById(R.id.list_item1)).setVisibility(View.GONE);
					((ListView)findViewById(R.id.list_item2)).setVisibility(View.VISIBLE);
					}
				}
			}
		}
	};
	
	Handler mHandlerQDR_3A4= 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 ){
					Log.i("DOWNLOAD_6_mHandlerQC===", ""+Hresult);						
					if (Hresult.indexOf("\r\n")>2){
						RepData datas = (RepData) mAdapter.getItem(locations);											
						
						Hresult=	Hresult.substring(Hresult.indexOf("rep12;")+6);

						Intent intent = new Intent();
						//bundle.putString("Mkqrs",""+datas.iFormdate+","+nKind+",5,"+datas.iFormdate+","+Hresult+","
						//+datas.iGoods+";"+datas.iImpo+";"+datas.iName+";"+datas.iCountry+";"+datas.iMoney+";"+datas.iCompany+","+mStartDay+","+mEndDay);

						intent.putExtra("SERCH",datas.iFormdate);
						intent.putExtra("QKIND",""+nKind);
						intent.putExtra("MODE",5);
						intent.putExtra("EMPID",datas.iFormdate);
						intent.putExtra("BUFSTR",Hresult);
						intent.putExtra("BUFTITLE",datas.iGoods+";"+datas.iImpo+";"+datas.iName+";"+datas.iCountry+";"+datas.iMoney+";"+datas.iCompany);
						intent.putExtra("STARTDAY",mStartDay);
						intent.putExtra("ENDDAY",mEndDay);

						
						intent.setClass(QRep_14.this, MkqrSt.class);
						startActivity(intent);
 						
					}
				}
			}
		}
	};
	
	//雲端版 將依FORMDATE,PS1,sum(BSUM) 取得後 填入PS1 分類欄
	private String makeSQLforPrinter(String Bg,String En, String mEmpid){

		StringBuffer mBuf = new StringBuffer();
		
		mBuf.append("select FORMDATE,EMPID,sum(UNIT30),sum(SUBPRICE),sum(UNIT30*P2),sum(SUBPRICE-UNIT30*P2)");
		mBuf.append(" from qitems ");
	    mBuf.append(" where  (( FORMDATE >= '").append(Bg).append("' and FORMDATE <= '").append(En)	.append("' and ISCONFIRM='Y' ) or ")
		.append(" ( FINEDATE<>'' and FINEDATE>='").append(Bg)	.append("' and FINEDATE <= '").append(En).append("' and ISCONFIRM='Y' ))");
			mBuf.append(" and EMPID='").append(mEmpid).append("' and ");
			mBuf.append(SQLADD);
		mBuf.append(" group by EMPID,FORMDATE");
		return mBuf.toString();
	}
	
	private String makeSQLforPrinterUser(String Bg,String En, String mEmpid){

		StringBuffer mBuf = new StringBuffer();
		
		mBuf.append("select USER,USERNAME,sum(UNIT30),sum(SUBPRICE),sum(UNIT30*P2),sum(SUBPRICE-UNIT30*P2)");
		mBuf.append(" from qitems ");
	    mBuf.append(" where  (( FORMDATE >= '").append(Bg).append("' and FORMDATE <= '").append(En)	.append("' and ISCONFIRM='Y' ) or ")
		.append(" ( FINEDATE<>'' and FINEDATE>='").append(Bg)	.append("' and FINEDATE <= '").append(En).append("' and ISCONFIRM='Y' ))");
			mBuf.append(" and EMPID='").append(mEmpid).append("' and ");
			mBuf.append(SQLADD);
		mBuf.append(" group by USER,USERNAME");
		return mBuf.toString();
	}
	
	// 搜尋日期 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 int getDismoney(SQLiteDatabase sdb,String Aday,String who,int mode){
    	int dism=0;
    	String dbStartDay=mStartDay;
    	String dbEndDay=mEndDay;
		if(dbStartDay != null && dbStartDay.length() > 0)	dbStartDay = dbStartDay.replace("/", "-");
		if(dbEndDay != null && dbEndDay.length() > 0) dbEndDay = dbEndDay.replace("/", "-");

    	//mode==0總表 ==1 櫃員每日 ==2 會員 
		StringBuffer SQLH_Dismoney = new StringBuffer();
		SQLH_Dismoney.append("select sum(DISMONEY) from qhead where ").append(SQLADD).append(" and ISCONFIRM='Y' ").append(" and EMPID='").append(who).append("'");
		if (mode==0){//總表
			SQLH_Dismoney.append(" and  (( FORMDATE >= '").append(dbStartDay).append("' and FORMDATE <= '").append(dbEndDay).append("' ) or ")
			.append(" ( FINEDATE<>'' and FINEDATE >= '").append(dbStartDay).append("' and FINEDATE <= '").append(dbEndDay).append("' ))");
		}else if (mode==1){//櫃員每日
			SQLH_Dismoney.append(" and ( FORMDATE = '").append(Aday)
			.append("' or  FINEDATE='").append(Aday).append("' ) ");
		}else if (mode==2){//會員
			SQLH_Dismoney.append(" and  (( FORMDATE >= '").append(dbStartDay).append("' and FORMDATE <= '").append(dbEndDay).append("' ) or ")
			.append(" ( FINEDATE<>'' and FINEDATE >= '").append(dbStartDay).append("' and FINEDATE <= '").append(dbEndDay).append("' ))")
			.append(" and USER='").append(Aday).append("'");
		}
		Cursor cursorH=sdb.rawQuery(SQLH_Dismoney.toString(), null);
		if (cursorH.getCount()>0){
		 cursorH.moveToFirst();
		 dism=cursorH.getInt(0);
		}
		cursorH.close();
    	return dism;
    }
    
    private String[] getEmpName(SQLiteDatabase sdb,String empid){
    	Cursor empCS=sdb.rawQuery("select CUSTNAME,GPSLO,PIC from qcust where CUSTNO='"+empid+"' and TR='40'", null);
		String [] empname  =new String[3];
    	if (empCS.getCount()>0){
    		empCS.moveToFirst();
    		empname[0]=empCS.getString(0);
    		empname[1]=empCS.getString(1);
    		empname[2]=empCS.getString(2);
    	}	
    	empCS.close();
    	return empname;
    }
    
    private void chkMode(){        
        switch(mMode){ //剛進入主程式的狀態,初始的模式
        
	    	case KeySet.SearchMode.WEEK:
	    	{
	    		String day = Utilis.getWeekDate();
				String[] days = day.split("~");
	    		mStartDay = days[0];
	    		mEndDay = days[1];
//@@				mGroupMode = GroupMode.TOP2;
	    		
	    		((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)+menu_E[(int)(nKind/10)-1]+":[週統計]");
	        	getGroupData(QRep_14.this, mStartDay, mEndDay, null, null);
	    		mAdapter.notifyDataSetChanged();        
	    		break;
	    	}
	    	case KeySet.SearchMode.MONTH:
	    	{
	    		String day = Utilis.getMonthDate();
				String[] days = day.split("~");
	    		mStartDay = days[0];
	    		mEndDay = days[1];
	    		
	    		((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)+menu_E[(int)(nKind/10)-1]+":[月統計]");
	        	getGroupData(QRep_14.this, mStartDay, mEndDay, null, null);
	    		mAdapter.notifyDataSetChanged();        
	    		break;
	    	}
	    	case KeySet.SearchMode.SEASON:  //自定日期範圍
	    	{
	    		new AlertDialog.Builder(QRep_14.this).setTitle("銷貨單 搜尋(起始、結束日期)")
				.setView(makeDateDialog())
				.setNegativeButton(getString(R.string.str_cancel), new DialogInterface.OnClickListener() {
		            public void onClick(DialogInterface dialog, int which) {
		            }
		          }).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;
//		            	mTextDuration.setText(getString(R.string.str_duration) + " : " + mStartDay + "~" + mEndDay);
		            	mTextDuration.setText( mStartDay + "~" + mEndDay);
		            	
		            	setTitle(getString(R.string.app_name)+":[日期範圍]");
			    		((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("範圍");
			        	getGroupData(QRep_14.this, mStartDay, mEndDay, null, null);
			    		mAdapter.notifyDataSetChanged();        
		            }
		          }).show();
	    		break;
	    	}
	    	
        }
        setCondition();
    }

	/**
	 *  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;
	@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, "零售(含員購)");
    	return true;
    }
	
    @Override
	public boolean onOptionsItemSelected(MenuItem item) {			
		super.onOptionsItemSelected(item);
		switch (item.getItemId()) {
			case MENU_MAIN:
			{
				SQLADD="(QKIND ='30' OR QKIND ='31' OR QKIND ='40' OR QKIND ='41')";
				break;
			}
			case MENU_DETAIL:
			{
				SQLADD="(QKIND ='30' OR QKIND ='31')";
				break;
			}
			case MENU_S1S2:{
				SQLADD="(QKIND ='40' OR QKIND ='41')";
				break;
			}
			case MENU_S1:{
				SQLADD="TRADETYPE='5' and (QKIND ='30' OR QKIND ='31')";
				break;
			}
			case MENU_S2:{
				SQLADD="TRADETYPE='5' and (QKIND ='30' OR QKIND ='31' OR QKIND ='40' OR QKIND ='41')";
				break;
			}
					
		}
		if (Floor==0){
			setCondition();
			getGroupData(QRep_14.this,mStartDay, mEndDay, null, null);				
			mAdapter.notifyDataSetChanged();
		}else{
			Toast.makeText(QRep_14.this, "請返回第一層,才可以這些選項!!", Toast.LENGTH_LONG).show();
		}
		return true;
    }
    
    
private class ReportAdapter extends BaseAdapter{
		
		private LayoutInflater mInflater;
		
		public LinkedList<RepData> mList = new LinkedList<RepData>();
		
		public ReportAdapter (Context context ){
		      mInflater = LayoutInflater.from(context);
		}

		public RepData getData(int Position){
			return mList.get(Position);
		}
		
		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return mList.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return mList.get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return 0;
		}
		
		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHolder holder;
			if (convertView == null) {
				convertView = mInflater.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.textMoney = (TextView) convertView.findViewById(R.id.text_pmoney);
				holder.textNumber = (TextView) convertView.findViewById(R.id.text_pnumber);
				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");
			RepData data = mList.get(position);
//			if (nKind==30) 	holder.imageItem.setImageBitmap(Utilis.getLimitBitmap(data.iPic, 80, 80));
			
			holder.textGoodsNo.setText(data.iGoods);
			
			holder.textName.setText(data.iName);
			holder.textCountry.setText(data.iCountry);
			holder.textCompany.setText(data.iCompany);
			holder.textMoney.setText(data.iMoney);
			holder.textNumber.setText(data.iNumber);
			holder.textImpo.setText(data.iImpo);			
			return convertView;
		}

		/* class ViewHolder */
		private class ViewHolder {
			ImageView imageItem;
			TextView textGoodsNo;
			TextView textImpo;
			TextView textName;
			TextView textMoney;
			TextView textCountry;
			TextView textNumber;
			TextView textCompany;
			
		}
	}

}
