package com.cwbuyer.lib;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;


import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.os.Environment;
import android.util.Log;

/**
 *   qmtrm		---ok   新增資料 -2 Main
 *   qmtrs		---ok   新增資料 -1
 *   qhead      ---ok   同上 確認是否產生
 *   qitems     ---ok   進貨數量!
 *   qfact   	---OK   廠商主檔
 *   qc_color	---ok	產品顏色
 *   qc_country	---ok  	國家地區
 *   qc_type	---ok	商品類別
 *   qc_size	---ok  	尺寸規格
 *   qc_wash	---ok  	洗滌組合
 *   qc_quality	---ok  	成份組合 (衣物)
 *   qc_defpri	---ok	訂價策略
 *   
 *   qc_default     採購參數
 *   qdetail        商品主要table
 *   
 *   qc_unit    ---ok   X 尚不知道做啥
 *   qcuct   ---OK    X 客戶主檔 (不需要)
 *   qemp    ---ok    X 員工主檔 (不需要)
 *   qdept   ---ok    X 門市主檔 (不需要)
 */
@SuppressWarnings("unused")
public class SQLite {
	
	private  SQLiteDatabase myDatabase = null;
	
	public SQLite(Context context,String path){
		createContentDB(context,path);
	}
	
	//到時候需多一個傳入値,資料夾的全路徑,可以將動態的資料庫運作更新版本
	
	public void createContentDB(Context context,String path){
		String mDBPath = android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+path;		
		if(myDatabase == null){
			try{
				myDatabase = SQLiteDatabase.openDatabase(mDBPath, null,
				SQLiteDatabase.OPEN_READWRITE + SQLiteDatabase.CREATE_IF_NECESSARY );
			}catch(Exception e){
				e.getMessage();
			}
		}
		
		if(myDatabase != null){
			initContentDB(myDatabase, context);
		}
	}
	
	public void close(){
		if(myDatabase != null){
			try{
				myDatabase.close();
				myDatabase = null;
			}catch(Exception e){
			}
		}
	}
		
	public static void initContentDB(SQLiteDatabase db, Context cnt){
		int version = db.getVersion();
		if (version >= 57) {
			return ;
		}
		switch (version){
			case 22:
				try{
					//進行更新後執行
				      File file = new File(android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+ "/cwbuyer/para/ini.sdb");
				      SQLiteDatabase dbini = SQLiteDatabase.openOrCreateDatabase(file, null);
				      
				      dbini.execSQL("update system set T1='門市轉貨單',T2='總倉出貨單',T3='員工自購',T4='盤點',T5='故障品登錄(保留)',T6='門市對帳單(保留)',T7='(保留)',T8='(保留)',T9='(保留)',PS='' where _ID=17");
					
				      dbini.execSQL("update system set T1='大圖編輯(唯讀)',T2='明細清冊(唯讀)',T3='重返結帳作業',T4='各門市庫存表',T5='追蹤',T6='明細&補印條碼',T7='保留',T8='保留',T9='保留',PS='' where _ID=70");
					
				      dbini.execSQL("update system set T1='大圖編輯',T2='明細清冊',T3='重返結帳作業',T4='各門市庫存表',T5='追蹤',T6='明細&補印條碼',T7='保留',T8='保留',T9='保留',PS='' where _ID=73");
					
				      dbini.execSQL("update system set T1='大圖編輯',T2='明細清冊',T3='收尾款結帳',T4='各門市庫存表',T5='追蹤',T6='明細&補印條碼',T7='保留',T8='保留',T9='保留',PS='' where _ID=71");
					
				      dbini.execSQL("update system set T1='大圖編輯',T2='明細清冊',T3='結帳',T4='各門市庫存表',T5='追蹤',T6='明細&補印條碼',T7='保留',T8='保留',T9='保留',PS='' where _ID=72");
					
				      dbini.execSQL("update system set T1='採購參數設定',T2='採購單(新品&追加)',T3='廠商進貨',T4='門市出貨',T5='門市銷貨',T6='員工自購',T7='代碼設定',T8='門市轉貨單',T9='盤點',PS='' where _ID=21");
				      
				      dbini.execSQL("update system set T1='折數一',T2='折數二',T3='折數三',T4='折數四',T5='折數五',T6='折數六',T7='折數七',T8='折數八',T9='折數九',PS='常用折數設定' where _ID=1400");

				      dbini.execSQL("update system set T1='條碼機種類:1GODEX',T2='條碼機設定IP(198)',T3='條碼機設定PORT(9101)',T4='出貨單列印指定IP(199)',T5='出貨單列印指定PORT(9102)',T6='錢櫃控制指定IP(232)',T7='錢櫃控制指定PORT(9600)',T8='條碼機印製排數',T9='熱感列印:0.大明細1.小明細2.大主貨3.小主貨4.來源明細5.來源主貨',PS='條碼機的相關設定,及錢櫃設定等' where _ID=1550");
					
				      dbini.execSQL("update system set T9='出單0不印 1.(60)印名稱 2.(60)印LOGO 3(80)印LOGO 4(80)單等長 5-6(100) 9印A4單' where _ID=1300");

				      dbini.execSQL("update system set T9='開單時優先搜尋0貨號1來源編號2貨號+直銷  ' where _ID=1201");

				      dbini.execSQL("update system set T1='0批發1零售',T7='各門市會員是否同步0.同步(1.不同步)',T8='數位相機角度(0)(90)(180)(270)',T9='(0)歷史價 (1)取較小 (2)標準價(指定密碼) ' where _ID=1250");

				      dbini.execSQL("update system set T1='0.採購雲端輸出選項1.預設雲端',T4='0.輸出品名1.輸出備註(出圖預設品名)',T5='0.輸出貨號1.輸出來源(條碼預設貨號)',T6='0.輸出貨號1.輸出來源(訂購出圖貨號)',T7='交易優先拜訪0.單據1.採購單',T8='網頁上架 7預設上架 0不上架',T9='採購單顯示為0.品名1.備註'  where _ID=1620");

				      dbini.execSQL("update system set T1='0.門市同進貨輸出1.不詢問',T2='(總倉)電子郵件',T3='(採購)電子郵件',T4='門市業績(0本地端)(1雲端)',T5='折數是否隱藏 0不隱藏 1要隱藏',T6='預購留貨算應收帳款(0不計)(1要計)(2全不計)',T7='年度謄檔0不啟動 1啟動',T8='雲端預購留貨0不啟動 1.啟動',T9='0.建新品不馬上存入 1.即時存入伺服器',PS='門市結帳設定&門市業績統計方式' where _ID=1650");
					
				      dbini.execSQL("update system set T3='預購' where _ID=52");
					
				      dbini.execSQL("update system set T1='交易備註一',T2='交易備註二',T3='交易備註三',T4='交易備註四',T5='交易備註五',T6='交易備註六',T7='交易備註七',T8='交易備註八',T9='交易備註九',PS='交易時,常用的備註詞彙' where _ID=1500");
					
				      dbini.execSQL("update system set T6='0.賣價=定價策略 1.賣價=定價策略+管銷 2.公式',T7='0.整數 1.小數23位',T8='0.原價 1.無條件捨去 5.四捨五入法 9.無條件進入法',T9='(成本*)中盤價:批價 (批價*)網購價:零售' where _ID=1680");
					
				      dbini.close();

					db.execSQL("UPDATE qitems SET COUNTRY='台灣' WHERE COUNTRY='1'");					
					db.execSQL("UPDATE qitems SET COUNTRY='中國' WHERE COUNTRY='2'");					
					db.execSQL("UPDATE qitems SET COUNTRY='韓國' WHERE COUNTRY='3'");					
					db.execSQL("UPDATE qitems SET COUNTRY='日本' WHERE COUNTRY='4'");					
					db.execSQL("UPDATE qitems SET COUNTRY='泰國' WHERE COUNTRY='6'");					
					db.execSQL("UPDATE qitems SET UNIT10=0 WHERE UNIT10 isnull");
					db.execSQL("UPDATE qitems SET UNIT20=0 WHERE UNIT20 isnull");
					db.execSQL("UPDATE qitems SET UNIT30=0 WHERE UNIT30 isnull");
					db.execSQL("UPDATE qitems SET UNIT40=0 WHERE UNIT40 isnull");
					db.execSQL("UPDATE qitems SET TR='Y0' WHERE TR isnull or TR<' ' or TR=QKIND");
					db.execSQL("UPDATE qitems SET FINEDATE='' WHERE FINEDATE isnull ");
					db.execSQL("UPDATE qitems SET PS='' WHERE PS isnull ");
					db.execSQL("UPDATE qdetail SET UNIT='1' WHERE UNIT isnull ");
					db.execSQL("UPDATE qdetail SET PS='' WHERE PS isnull");
					
					db.execSQL("UPDATE qhead SET ORDDATE='' WHERE ORDDATE isnull");
					db.execSQL("UPDATE qhead SET FINEDATE='' WHERE FINEDATE isnull");
					db.execSQL("UPDATE qhead SET PS='' WHERE PS isnull");
					db.execSQL("UPDATE qhead SET PS1='' WHERE PS1 isnull");
					db.execSQL("UPDATE qhead SET PS2='' WHERE PS2 isnull");
					db.execSQL("UPDATE qhead SET ISLIST='N' WHERE ISLIST isnull");
					
					db.setVersion(23);
					
					if (Utilis.toInt(Utilis.getIni(cnt, "SYS", "IMPORT", 3))==1){
						String FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/aa0_aa1_auto_hi_n.php";
						String serverFileH ="/aa0_aa1_auto_hi_n.php";
						boolean success=false;
						success=ftpSendServer(cnt,FileH,serverFileH);
						
						 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/aa1_aa0_hi_update_n.php";
						serverFileH ="/aa1_aa0_hi_update_n.php";
						success=ftpSendServer(cnt,FileH,serverFileH);
						
						 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/aa1_aa0_batch_qdetail_n.php";
						serverFileH ="/aa1_aa0_batch_qdetail_n.php";
						success=ftpSendServer(cnt,FileH,serverFileH);
						
						 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/admin_checkout.php";
						serverFileH ="/web/admin/admin_checkout.php";
						success=ftpSendServer(cnt,FileH,serverFileH);
						
						 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/mem_psn.php";
						serverFileH ="/web/member/mem_psn.php";
						success=ftpSendServer(cnt,FileH,serverFileH);
						
						 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/msg_message_insert.php";
						serverFileH ="/web/msg/msg_message_insert.php";
			        	success=false;
						success=ftpSendServer(cnt,FileH,serverFileH);
						
						 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/msg_message.js";
						serverFileH ="/web/js/msg_message.js";
						success=ftpSendServer(cnt,FileH,serverFileH);
						
					}
					
				}catch(Exception e){
					e.printStackTrace();
				}
				
			case 23:	db.setVersion(24);
			
			case 24:
				if (Utilis.toInt(Utilis.getIni(cnt, "SYS", "IMPORT", 3))==1){
					initVersion24(db,cnt);
				}
				createQacc(db);
				createQMacc(db);
				db.setVersion(25);
			case 25:
				if (Utilis.toInt(Utilis.getIni(cnt, "SYS", "IMPORT", 3))==1){
					String FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/msg_message.php";
					String serverFileH ="/web/msg/msg_message.php";
		        	boolean success=false;
					success=ftpSendServer(cnt,FileH,serverFileH);
					
					FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/msg_message_content.php";
					serverFileH ="/web/msg/msg_message_content.php";
					success=ftpSendServer(cnt,FileH,serverFileH);
					
					FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/admin_message.php";
					serverFileH ="/web/admin/admin_message.php";
					success=ftpSendServer(cnt,FileH,serverFileH);
					
					FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/mem_psn.php";
					serverFileH ="/web/member/mem_psn.php";
					success=ftpSendServer(cnt,FileH,serverFileH);
				}
				db.setVersion(26);
			case 26:
				if (Utilis.toInt(Utilis.getIni(cnt, "SYS", "IMPORT", 3))==1){
					String FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/aa0_aa1_auto_qmacc.php";
					String serverFileH ="/aa0_aa1_auto_qmacc.php";
		        	boolean success=false;
					success=ftpSendServer(cnt,FileH,serverFileH);
					
					 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/aa1_aa0_qmacc_update.php";
					serverFileH ="/aa1_aa0_qmacc_update.php";
					success=ftpSendServer(cnt,FileH,serverFileH);
				}
				db.setVersion(27);
			case 27:
			      File file = new File(android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+ "/cwbuyer/para/ini.sdb");
			      SQLiteDatabase dbini = SQLiteDatabase.openOrCreateDatabase(file, null);
			      dbini.execSQL("update system set T5='採購單的排序 0.依輸入順序(預設) 1.依貨號 2.依來源編號' where _ID=1680");
			      dbini.execSQL("update system set T5='0' where _ID=1681");
			      dbini.close();
					if (Utilis.toInt(Utilis.getIni(cnt, "SYS", "IMPORT", 3))==1){
						String  FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/getweb_pic.php";
						String serverFileH ="/getweb_pic.php";
			        	boolean success=false;
						success=ftpSendServer(cnt,FileH,serverFileH);
					}
					db.setVersion(28);
			case 28:		
				if (Utilis.toInt(Utilis.getIni(cnt, "SYS", "IMPORT", 3))==1){
					String  FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qrep06_1.php";
					String serverFileH ="/qrep06_1.php";
		        	boolean success=false;
					success=ftpSendServer(cnt,FileH,serverFileH);
				}
				db.setVersion(29);
				case 29:{	
					String mDBPath = android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"cwbuyer/data/20123/qmtrio.sdb";		 
					File fileQmtrio = new File(mDBPath);
					SQLiteDatabase pdb = SQLiteDatabase.openOrCreateDatabase(fileQmtrio, null);
			         Cursor res = null;
			        try {
			            res = pdb.rawQuery("Select * from qpandn limit 1", null);
			            int colIndex =0; 
			            colIndex =res.getColumnIndex("SDT");
			            if (colIndex==-1){
							pdb.execSQL("ALTER TABLE qpandn add COLUMN SDT varchar(12)");
			            }
			            colIndex =res.getColumnIndex("BANKNAME");
			            if (colIndex==-1){
							pdb.execSQL("ALTER TABLE qpandn add COLUMN BANKNAME varchar(12)");
			            }
			            colIndex =res.getColumnIndex("TR");
			            if (colIndex==-1){
							pdb.execSQL("ALTER TABLE qpandn add COLUMN TR varchar(6)");
			            }
			
			        } catch (Exception e) {
			        } finally {
			            try { if (res !=null){ res.close(); } } catch (Exception e1) {}
			        }
			        pdb.close();
					
					Utilis.putIni(cnt, "INIH", "QHIS",DateUtil.getCurrentDate(),7);
					Utilis.putIni(cnt, "INIH", "QHIS",DateUtil.getCurrentDate(),8);
					initVersion29(cnt);
					db.setVersion(30);
				}
				case 30:{
					if (Utilis.toInt(Utilis.getIni(cnt, "SYS", "IMPORT", 3))==1){
						String  FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qmtrio.php";
						String serverFileH ="/qmtrio.php";
						boolean success=false;
						success=ftpSendServer(cnt,FileH,serverFileH);
					}
					db.setVersion(31);
				}	
				case 31:
				case 32:
				case 33:
				case 34:	
				case 35:
					if (Utilis.toInt(Utilis.getIni(cnt, "SYS", "IMPORT", 3))==1){
						String  FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qpandngetdat.php";
						String serverFileH ="/qpandngetdat.php";
						boolean success=false;
						success=ftpSendServer(cnt,FileH,serverFileH);
						
						FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qrep06_1.php";
						serverFileH ="/qrep06_1.php";
			        	success=false;
						success=ftpSendServer(cnt,FileH,serverFileH);
					}				
					db.setVersion(36);
				case 36:
					if (Utilis.toInt(Utilis.getIni(cnt, "SYS", "IMPORT", 3))==1){
						String  FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/aa0_aa1_auto_hi_n.php";
						String serverFileH ="/aa0_aa1_auto_hi_n.php";
						boolean success=false;
						success=ftpSendServer(cnt,FileH,serverFileH);
						
						FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/aa0_aa1_dn_hi.php";
						serverFileH ="/aa0_aa1_dn_hi.php";
			        	success=false;
						success=ftpSendServer(cnt,FileH,serverFileH);
					}				
					db.setVersion(37);
				case 37:
					if (Utilis.toInt(Utilis.getIni(cnt, "SYS", "IMPORT", 3))==1){
						String  FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qpandngetdat.php";
						String serverFileH ="/qpandngetdat.php";
						boolean success=false;
						success=ftpSendServer(cnt,FileH,serverFileH);
					}				
					db.setVersion(38);
				case 38:
					if (Utilis.toInt(Utilis.getIni(cnt, "SYS", "IMPORT", 3))==1){
						initVersion38(db,cnt);
					}
					createPpri(db);
					db.setVersion(39);
				case 39:{
					if (Utilis.toInt(Utilis.getIni(cnt, "SYS", "IMPORT", 3))==1){
						String  FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qrep01_30.php";
						String serverFileH ="/qrep01_30.php";
						boolean success=false;
						success=ftpSendServer(cnt,FileH,serverFileH);
						
						FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qrep01_3.php";
						serverFileH ="/qrep01_3.php";
						success=false;
						success=ftpSendServer(cnt,FileH,serverFileH);
					}
					db.setVersion(40);
				}	
				case 40:{
					if (Utilis.toInt(Utilis.getIni(cnt, "SYS", "IMPORT", 3))==1){
						String  FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qrep_today.php";
						String serverFileH ="/qrep_today.php";
						boolean success=false;
						success=ftpSendServer(cnt,FileH,serverFileH);
						initVersion38(db,cnt);
					}
					createPpri(db);
					db.setVersion(41);
				}	
				case 41:{
					if (Utilis.toInt(Utilis.getIni(cnt, "SYS", "IMPORT", 3))==1){
						String  FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qdeptrep_30_N.php";
						String serverFileH ="/qdeptrep_30_N.php";
						boolean success=false;
						success=ftpSendServer(cnt,FileH,serverFileH);
						
						FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qrep_today.php";
						serverFileH ="/qrep_today.php";
						success=false;
						success=ftpSendServer(cnt,FileH,serverFileH);
						
						FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qdeptrep_31_N.php";
						serverFileH ="/qdeptrep_31_N.php";
						success=false;
						success=ftpSendServer(cnt,FileH,serverFileH);
						
						FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qdeptrep_32_N.php";
						serverFileH ="/qdeptrep_32_N.php";
						success=false;
						success=ftpSendServer(cnt,FileH,serverFileH);
					}
					db.setVersion(42);
				}	
				case 42:{
					if (Utilis.toInt(Utilis.getIni(cnt, "SYS", "IMPORT", 3))==1){
						String  FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/getweb_bsumreport.php";
						String serverFileH ="/getweb_bsumreport.php";
						boolean success=false;
						success=ftpSendServer(cnt,FileH,serverFileH);
					}
					db.setVersion(43);
				}	
				case 43:{
				      File fileini = new File(android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+ "/cwbuyer/para/ini.sdb");
				      SQLiteDatabase dbini2 = SQLiteDatabase.openOrCreateDatabase(fileini, null);
				      dbini2.execSQL("update system set T5='請輸入條碼四IP位址(192.168.x.97)',T6='請輸入條碼四Port(9103)' where _ID=1203");
				      dbini2.execSQL("update system set T5='192.168.x.97',T6='9103' where _ID=1205");
				      dbini2.close();
					
					if (Utilis.toInt(Utilis.getIni(cnt, "SYS", "IMPORT", 3))==1){
						String  FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qdeptrep_30_N44.php";
						String serverFileH ="/qdeptrep_30_N44.php";
						boolean success=false;
						success=ftpSendServer(cnt,FileH,serverFileH);
						
						FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qdeptrep_32_N44.php";
						serverFileH ="/qdeptrep_32_N44.php";
						success=false;
						success=ftpSendServer(cnt,FileH,serverFileH);
					}
					db.setVersion(44);
				}
				case 44:{
					if (initVersion44(db,cnt)==true)
						db.setVersion(45);
				}
				case 45:
				case 46:
				case 47:	
				case 48:	
				{
				      if (initVersion45(db,cnt)==true)
				      db.setVersion(49);
				}
				case 49:
				case 50:
				case 51:
				{
				      if (initVersion49(db,cnt)==true)
				      db.setVersion(52);
				}
				case 52:
				{
				      if (initVersion53(db,cnt)==true)
				      db.setVersion(53);
				}
				case 53:
				{
					if (initVersion54(db,cnt)==true)
				      db.setVersion(54);
				}
				case 54:
				{
					if (initVersion55(db,cnt)==true)
				      db.setVersion(55);
				}
				case 55:
				{
				      File fileini = new File(android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+ "/cwbuyer/para/ini.sdb");
				      SQLiteDatabase dbini2 = SQLiteDatabase.openOrCreateDatabase(fileini, null);
				      dbini2.execSQL("update system set T9='出貨單印製指定單價:0正常1成本2中盤3批發4網購5零售' where _ID=1203");
				      dbini2.execSQL("update system set T9='0' where _ID=1205 and (T9<>'5' and T9<>'4' and T9<>'3' and T9<>'2' and T9<>'1')");
				      dbini2.close();
					if (initVersion56(db,cnt)==true)
				      db.setVersion(56);
				}
				case 56:
				{
				      db.execSQL("update qitems set SIZES=(select distinct SIZE from qdetail where qitems.GOODSNO=qdetail.GOODSNO ) where SIZES<>'F' and SIZES not like '%,%';");
				      db.setVersion(57);
				}
			}

	}
	
	public static boolean initVersion55(SQLiteDatabase db, Context cnt){
	      if (Utilis.toInt(Utilis.getIni(cnt, "SYS", "IMPORT", 3))==1){
			boolean success=false;
			String FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/cw_maintain_171114.php";
			String serverFileH ="/cw_maintain_171114.php";
			success=ftpSendServer(cnt,FileH,serverFileH);
			if (success==true){
				StringBuffer bfstr = new StringBuffer();
				StringBuffer bfstrF = new StringBuffer();
					bfstr.append(Utilis.getIni(cnt, "SYS", "IMPORT", 2));
					bfstrF.append("UID");
				Thread t = new Thread(new DBCloud.sendPostRunnableQC(cnt,bfstr.toString(),bfstrF.toString(),27));
				t.start();
			}
	      }
		return true;
	}

	
	public static boolean initVersion56(SQLiteDatabase db, Context cnt){
	      if (Utilis.toInt(Utilis.getIni(cnt, "SYS", "IMPORT", 3))==1){
			boolean success=false;
			String FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/aa0_aa1_gvor.php";
			String serverFileH ="/aa0_aa1_gvor.php";
			success=ftpSendServer(cnt,FileH,serverFileH);
			
			FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/aa0_aa1_auto_hi_orny_n.php";
			serverFileH ="/aa0_aa1_auto_hi_orny_n.php";
			success=ftpSendServer(cnt,FileH,serverFileH);

	      }
		return true;
	}

	public static boolean initVersion54(SQLiteDatabase db, Context cnt){
	      if (Utilis.toInt(Utilis.getIni(cnt, "SYS", "IMPORT", 3))==1){
			String  FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qrephisn.php";
			String serverFileH ="/qrephisn.php";
			boolean success=false;
			success=ftpSendServer(cnt,FileH,serverFileH);
	      }
		return true;
	}

	public static boolean initVersion53(SQLiteDatabase db, Context cnt){
	      if (Utilis.toInt(Utilis.getIni(cnt, "SYS", "IMPORT", 3))==1){
			String  FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qmtrio.php";
			String serverFileH ="/qmtrio.php";
			boolean success=false;
			success=ftpSendServer(cnt,FileH,serverFileH);
			FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/cw_maintain_171030.php";
			serverFileH ="/cw_maintain_171030.php";
			success=ftpSendServer(cnt,FileH,serverFileH);
			if (success==true){
				StringBuffer bfstr = new StringBuffer();
				StringBuffer bfstrF = new StringBuffer();
					bfstr.append(Utilis.getIni(cnt, "SYS", "IMPORT", 2));
					bfstrF.append("UID");
				Thread t = new Thread(new DBCloud.sendPostRunnableQC(cnt,bfstr.toString(),bfstrF.toString(),25));
				t.start();
			}
	      }
		return true;
	}

	public static boolean initVersion49(SQLiteDatabase db, Context cnt){
	      if (Utilis.toInt(Utilis.getIni(cnt, "SYS", "IMPORT", 3))==1){
			String  FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/aa0_aa1_auto_hi_orny_n.php";
			String serverFileH ="/aa0_aa1_auto_hi_orny_n.php";
			boolean success=false;
			success=ftpSendServer(cnt,FileH,serverFileH);

	      }
		return true;
	}

	public static boolean initVersion45(SQLiteDatabase db, Context cnt){
	      File fileini = new File(android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+ "/cwbuyer/para/ini.sdb");
	      SQLiteDatabase dbini2 = SQLiteDatabase.openOrCreateDatabase(fileini, null);
	      dbini2.execSQL("update system set T2='建立新品 預設 0分色尺寸 1不分色尺寸' where _ID=1250");
	      dbini2.close();
	      
	      if (Utilis.toInt(Utilis.getIni(cnt, "SYS", "IMPORT", 3))==1){
			String  FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/aa0_aa1_gvor.php";
			String serverFileH ="/aa0_aa1_gvor.php";
			boolean success=false;
			success=ftpSendServer(cnt,FileH,serverFileH);

			FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/aa1_aa0_gvor.php";
			serverFileH ="/aa1_aa0_gvor.php";
			success=false;
			success=ftpSendServer(cnt,FileH,serverFileH);
	      }
		return true;
	}

	
	public static boolean initVersion44(SQLiteDatabase db, Context cnt){
		
		String SQL="CREATE INDEX IF NOT EXISTS qheadF ON qhead (FORMNO);";
		db.execSQL(SQL);
		SQL="CREATE INDEX IF NOT EXISTS qheadM ON qhead (FORMDATE);";
		db.execSQL(SQL);
		SQL="CREATE INDEX IF NOT EXISTS qheadC ON qhead (USER);";
		db.execSQL(SQL);
		
		SQL="CREATE INDEX IF NOT EXISTS qitemsF ON qitems (FORMNO);";
		db.execSQL(SQL);
		SQL="CREATE INDEX IF NOT EXISTS qitemsM ON qitems (FORMDATE);";
		db.execSQL(SQL);
		SQL="CREATE INDEX IF NOT EXISTS qitemsG ON qitems (GOODSNO);";
		db.execSQL(SQL);
		SQL="CREATE INDEX IF NOT EXISTS qitemsD ON qitems (DEPTNO);";
		db.execSQL(SQL);
		
		SQL="CREATE INDEX IF NOT EXISTS qdetailG ON qdetail (GOODSNO);";
		db.execSQL(SQL);

		SQL="CREATE INDEX IF NOT EXISTS qcustC ON qcust (CUSTNO);";
		db.execSQL(SQL);
		
		//Cloud _index ( aa1_add44_index.php )
		if (Utilis.toInt(Utilis.getIni(cnt, "SYS", "IMPORT", 3))==1){
			String  FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/aa1_add44_index.php";
			String serverFileH ="/aa1_add44_index.php";
			boolean success=false;
			success=ftpSendServer(cnt,FileH,serverFileH);
			
			if (success){
				StringBuffer bfstr = new StringBuffer();
				StringBuffer bfstrF = new StringBuffer();
					bfstr.append(Utilis.getIni(cnt, "SYS", "IMPORT", 2));
					bfstrF.append("UID");
				Thread t = new Thread(new DBCloud.sendPostRunnableQC(cnt,bfstr.toString(),bfstrF.toString(),44));
				t.start();
			}
		}
		return true;
	}
	
	public static boolean initVersion38(SQLiteDatabase db, Context cnt){
		String  FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/aa1_addppri_table.php";
		String serverFileH ="aa1_addppri_table.php";
    	boolean success=false;
		success=ftpSendServer(cnt,FileH,serverFileH);

		FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qc_ppri_download.php";
		serverFileH ="/qc_ppri_download.php";
		success=ftpSendServer(cnt,FileH,serverFileH);
		
		 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qc_ppri_ninsert.php";
		serverFileH ="/qc_ppri_ninsert.php";
		success=ftpSendServer(cnt,FileH,serverFileH);
		
		 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/mupdate_yn.php";
		serverFileH ="/mupdate_yn.php";
		success=ftpSendServer(cnt,FileH,serverFileH);
		
		 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qc_each_del.php";
		serverFileH ="/qc_each_del.php";
		success=ftpSendServer(cnt,FileH,serverFileH);
		
		StringBuffer bfstr = new StringBuffer();
		StringBuffer bfstrF = new StringBuffer();
			bfstr.append(Utilis.getIni(cnt, "SYS", "IMPORT", 2));
			bfstrF.append("UID");
		Thread t = new Thread(new DBCloud.sendPostRunnableQC(cnt,bfstr.toString(),bfstrF.toString(),29));
		t.start();
		
	return true;
}

	public static boolean initVersion29(Context cnt){
		if (Utilis.toInt(Utilis.getIni(cnt, "SYS", "IMPORT", 3))==1){
			String  FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/aa0_aa1_pan_update.php";
			String serverFileH ="/aa0_aa1_pan_update.php";
        	boolean success=false;
			success=ftpSendServer(cnt,FileH,serverFileH);

			 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/aa1_addpandn_table.php";
			serverFileH ="/aa1_addpandn_table.php";
			success=ftpSendServer(cnt,FileH,serverFileH);

			 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qpandngetdat.php";
			serverFileH ="/qpandngetdat.php";
			success=ftpSendServer(cnt,FileH,serverFileH);

			 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qrep08_1.php";
			serverFileH ="/qrep08_1.php";
			success=ftpSendServer(cnt,FileH,serverFileH);

			StringBuffer bfstr = new StringBuffer();
			StringBuffer bfstrF = new StringBuffer();
				bfstr.append(Utilis.getIni(cnt, "SYS", "IMPORT", 2));
				bfstrF.append("UID");
			Thread t = new Thread(new DBCloud.sendPostRunnableQC(cnt,bfstr.toString(),bfstrF.toString(),26));
			t.start();
			
		}
		
	
		return true;
	}

	
	public static boolean initVersion24(SQLiteDatabase db, Context cnt){
			String  FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/aa1_addmaccs_table.php";
			String serverFileH ="aa1_addmaccs_table.php";
        	boolean success=false;
			success=ftpSendServer(cnt,FileH,serverFileH);

			 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/aa1_aa0_gvo.php";
			serverFileH ="/aa1_aa0_gvo.php";
			success=ftpSendServer(cnt,FileH,serverFileH);

			FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/aa0_aa1_gvo.php";
			serverFileH ="/aa_aa1_gvo.php";
			success=ftpSendServer(cnt,FileH,serverFileH);
			
			 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/cw_maintainDB.php";
			serverFileH ="/cw_maintainDB.php";
			success=ftpSendServer(cnt,FileH,serverFileH);

			FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qc_macc_download.php";
			serverFileH ="/qc_macc_download.php";
			success=ftpSendServer(cnt,FileH,serverFileH);
			
			 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qc_macc_ninsert.php";
			serverFileH ="/qc_macc_ninsert.php";
			success=ftpSendServer(cnt,FileH,serverFileH);
			
			 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/mupdate_yn.php";
			serverFileH ="/mupdate_yn.php";
			success=ftpSendServer(cnt,FileH,serverFileH);
			
			 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/update_yn.php";
			serverFileH ="/update_yn.php";
			success=ftpSendServer(cnt,FileH,serverFileH);
			
			 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qc_each_del.php";
			serverFileH ="/qc_each_del.php";
			success=ftpSendServer(cnt,FileH,serverFileH);
			
			 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qc_country_ninsert.php";
			serverFileH ="/qc_country_ninsert.php";
			success=ftpSendServer(cnt,FileH,serverFileH);
			
			 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qc_color_ninsert.php";
			serverFileH ="/qc_color_ninsert.php";
			success=ftpSendServer(cnt,FileH,serverFileH);
			
			 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qc_type_ninsert.php";
			serverFileH ="/qc_type_ninsert.php";
			success=ftpSendServer(cnt,FileH,serverFileH);
			
			 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qc_size_ninsert.php";
			serverFileH ="/qc_size_ninsert.php";
			success=ftpSendServer(cnt,FileH,serverFileH);
			
			 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qc_defpri_ninsert.php";
			serverFileH ="/qc_defpri_ninsert.php";
			success=ftpSendServer(cnt,FileH,serverFileH);
			
			 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qc_wash_ninsert.php";
			serverFileH ="/qc_wash_ninsert.php";
			success=ftpSendServer(cnt,FileH,serverFileH);
			
			 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/qc_quality_ninsert.php";
			serverFileH ="/qc_quality_ninsert.php";
			success=ftpSendServer(cnt,FileH,serverFileH);
			
			 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/getweb_bsum.php";
			serverFileH ="/getweb_bsum.php";
			success=ftpSendServer(cnt,FileH,serverFileH);
			
			 FileH=android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"CWBuyer/para/getweb_prod.php";
			serverFileH ="/getweb_prod.php";
			success=ftpSendServer(cnt,FileH,serverFileH);
			
			StringBuffer bfstr = new StringBuffer();
			StringBuffer bfstrF = new StringBuffer();
				bfstr.append(Utilis.getIni(cnt, "SYS", "IMPORT", 2));
				bfstrF.append("UID");
			Thread t = new Thread(new DBCloud.sendPostRunnableQC(cnt,bfstr.toString(),bfstrF.toString(),23));
			t.start();
			
		return true;
	}
	
	public static boolean ftpSendServer(Context cnt,String FileH,String serverFileH){
		File localFileH = new File(FileH);
		boolean success=false;
		try {
			success=DBCloud.ftpDownloadAndSaveFile(cnt,PrefKey.CWBUYER_WEB, 21,PrefKey.CWBUYER_FTPUSER, PrefKey.CWBUYER_PSWD, serverFileH, localFileH);												
			success=DBCloud.ftpUpdateFile(cnt,Utilis.getIni(cnt, "SYS", "IMPORT",1), 21,Utilis.getIni(cnt, "SYS", "IMPORT",4), Utilis.getIni(cnt, "SYS", "IMPORT",5), serverFileH, localFileH);												
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return success;
	}
	
	public static boolean createQmtrm(SQLiteDatabase db){
		String strCreateTagTable = "CREATE TABLE IF NOT EXISTS qmtrm("
			+ "TR varchar(2),"
			+ "MID INTEGER PRIMARY KEY AUTOINCREMENT,"
			+ "SUPPLY varchar(10),"    
			+ "COUNTRY varchar(20),"    
			+ "SOURCENO varchar(20),"
			+ "GOODSNO varchar(20),"
			+ "GOODSTYPE varchar(20),"
			+ "GOODSNAME varchar(30),"
			+ "UNIT1 varchar(6),"
			+ "UNIT2 varchar(6),"
			+ "UNIT double,"
			+ "BATCH varchar(10),"
			+ "BILL double,"
			+ "BILLRATE double,"
			+ "ADDCOST double,"
			+ "P0 double,"  // 自己加入 進價
			+ "P1 double,"
			+ "P2 double,"
			+ "P3 double,"
			+ "P4 double,"
			+ "P5 double,"
			+ "SEASON varchar(6),"
			+ "PS varchar(512),"
			+ "COLORS varchar(64),"
			+ "CREATEDATETIME datetime,"
			+ "STATE varchar(1),"
			+ "PIC TEXT,"
			+ "PICTURE TEXT,"
			+ "QUALITY_ID int(11),"
    		+ "WASH_ID int(11))";
		try{
			db.execSQL(strCreateTagTable);
		}catch(SQLException e){
			Log.e("Sales", "ERROR: " + e.getMessage());
			return false;   // maybe modify again
		}
		return true;
	}
	
	// Detail 明細表
	public static boolean createQDetail(SQLiteDatabase db){
		String strCreateTagTable = "CREATE TABLE IF NOT EXISTS qdetail("
			+ "TR varchar(2),"
			+ "MID INTEGER PRIMARY KEY AUTOINCREMENT,"
			+ "SUPPLY varchar(10),"    
			+ "COUNTRY varchar(20),"    
			+ "SOURCENO varchar(20),"
			+ "GOODSNO varchar(20),"
			+ "GOODSTYPE varchar(20),"
			+ "GOODSNAME varchar(30),"
			+ "UNIT1 varchar(6),"
			+ "UNIT2 varchar(6),"
			+ "UNIT double,"
			+ "BATCH varchar(10),"
			+ "BILL double,"
			+ "BILLRATE double,"
			+ "ADDCOST double,"
			+ "P0 double,"  // 自己加入 進價
			+ "P1 double,"
			+ "P2 double,"
			+ "P3 double,"
			+ "P4 double,"
			+ "P5 double,"
			+ "SEASON varchar(6),"
			+ "PS varchar(512),"
			+ "CREATEDATETIME datetime,"
			+ "STATE varchar(1),"
			+ "PIC TEXT,"
			+ "PICTURE TEXT,"
			+ "QUALITY_ID int(11),"
    		+ "WASH_ID int(11),"
    		+ "COLORNO varchar(256),"
			+ "COLOR varchar(256),"
			+ "SIZE varchar(256),"
			+ "INLIST TEXT,"  // 進貨 List
			+ "IMPO double,"
			+ "IMPOS double,"
			+ "OUTPO double,"
			+ "OUTPOS double,"
			+ "SPOS double,"
			+ "SPOSS double,"
			+ "IM_OUTSTK double,"
			+ "IM_POSSTK double,"
			+ "ORD double)";			
			
		try{
			db.execSQL(strCreateTagTable);
		}catch(SQLException e){
			Log.e("Sales", "ERROR: " + e.getMessage());
			return false;   // maybe modify again
		}
		return true;
	}
	
	// 建立 帳戶
	public static boolean createAccount(SQLiteDatabase db){
		String strCreateTagTable = "CREATE TABLE IF NOT EXISTS account(" +
			"_id INTEGER primary key autoincrement," +
			"acctext text," +
			"accrate TEXT," +
			"accnote TEXT," +
			"accmoney INTEGER," +
			"accsort INTEGER," +
			"accpic INTEGER," +
			"accinit INTEGER)";
		try{
			db.execSQL(strCreateTagTable);
		}catch(SQLException e){
			Log.e("Sales", "ERROR: " + e.getMessage());
			return false;   // maybe modify again
		}
		return true;
	}
	
	public static boolean createQmtrs(SQLiteDatabase db){
		String strCreateTagTable = "CREATE TABLE IF NOT EXISTS qmtrs("
			+ "TR varchar(2),"
			+ "MID INTEGER PRIMARY KEY AUTOINCREMENT,"
			+ "ID varchar(10),"    
			+ "GOODSNO varchar(20)," // GOOSNO
			+ "GOODSNOS varchar(20),"
			+ "COLORNO varchar(2),"
			+ "COLOR varchar(10),"
			+ "SIZE varchar(6),"
			+ "IMPO double,"
			+ "IMPOS varchar(10),"
			+ "OUTPO double,"
			+ "OUTPOS double,"
			+ "SPOS double,"
			+ "SPOSS double,"
			+ "IM_OUTSTK double,"
			+ "IM_POSSTK double,"
			+ "ORD double,"
			+ "STATE varchar(1),"
			+ "CREATEDATETIME datetime)";
		try{
			db.execSQL(strCreateTagTable);
		}catch(SQLException e){
			Log.e("Sales", "ERROR: " + e.getMessage());
			return false;   // maybe modify again
		}
		return true;
	}
	
	public static boolean createQHead(SQLiteDatabase db){
		String strCreateTagTable = "CREATE TABLE IF NOT EXISTS qhead("
			+ "TR varchar(2),"
			+ "ID INTEGER,"
			+ "QKIND varchar(6),"
			+ "FORMNO varchar(10),"
			+ "HANDNO varchar(10),"
			+ "FORMDATE varchar(10),"
			+ "CREATEDATETIME datetime,"
			+ "ISCONFIRM varchar(1),"
			+ "ISCHECK varchar(1),"
			+ "ISLIST varchar(1),"
			+ "EMPID varchar(3),"
			+ "EMPNAME varchar(10),"
			+ "USER varchar(10),"
			+ "USERNAME varchar(20),"
			+ "TRADETYPE varchar(1),"
			+ "DEPTNO varchar(8),"
			+ "ORDCASH double,"
			+ "ORDCARD double,"
			+ "CASH double,"
			+ "CARD double,"
			+ "ATOT double,"
			+ "ORDDATE varchar(10),"
			+ "FINEDATE varchar(10),"
			+ "ASUM double,"
			+ "BSUM double,"
			+ "BILLRATE double,"
			+ "COSTS double,"
			+ "TURESUM double,"
			+ "DISMONEY double,"
			+ "BANKNO varchar(20),"
			+ "BANKNAME varchar(20))";
		try{
			db.execSQL(strCreateTagTable);
		}catch(SQLException e){
			Log.e("Sales", "ERROR: " + e.getMessage());
			return false;   // maybe modify again
		}
		return true;
	}
	
	public static boolean createQItems(SQLiteDatabase db){
		String strCreateTagTable = "CREATE TABLE IF NOT EXISTS qitems("
			+ "TR varchar(2),"
			+ "ID INTEGER,"
			+ "QKIND varchar(6),"
			+ "FORMNO varchar(10),"
			+ "HANDNO varchar(10),"
			+ "FORMDATE varchar(10),"
			+ "CREATEDATETIME datetime,"
			+ "ISCONFIRM varchar(1),"
			+ "ISCHECK varchar(1),"
//			+ "ISLIST varchar(1),"
			+ "EMPID varchar(3),"
			+ "EMPNAME varchar(10),"
			+ "USER varchar(10),"
			+ "USERNAME varchar(20),"
			+ "TRADETYPE varchar(1),"
			+ "DEPTNO varchar(8),"
			+ "GOODSNO varchar(20),"
			+ "GOODSNOS varchar(20),"
			+ "SOURCENO varchar(20),"
			+ "UNIT1 varchar(6),"
			+ "UNIT2 varchar(6),"
			+ "UNIT double,"
			+ "UNITPRICE double,"
			+ "DISCOUNT double,"
			+ "ACOST double,"
			+ "RATE double,"
			+ "RATEPRICE double,"
			+ "REALSUM double,"
			+ "SUBPRICE double,"
			+ "P0 double,"  // 自己加入 進價  
			+ "P1 double,"
			+ "P2 double,"
			+ "P3 double,"
			+ "P4 double,"
			+ "P5 double,"
			+ "COLOR varchar(6),"
			+ "SIZE varchar(6),"
			+ "ORDDATE varchar(10),"
			+ "FINEDATE varchar(10))";
		try{
			db.execSQL(strCreateTagTable);
		}catch(SQLException e){
			Log.e("Sales", "ERROR: " + e.getMessage());
			return false;   // maybe modify again
		}
		return true;
	}
	
	public static boolean createQFact(SQLiteDatabase db){
		String strCreateTagTable = "CREATE TABLE IF NOT EXISTS qfact("
			+ "TR varchar(2),"
			+ "FACTNO varchar(10),"
			+ "FACTNAME varchar(20),"
			+ "MOBIL varchar(32),"
			+ "EMAIL varchar(32),"
			+ "MSN varchar(32),"
			+ "GMAIL varchar(32),"
			+ "GPSLA double,"
			+ "GPSLO double,"
			+ "DEPTNO varchar(8),"
			+ "EMPID varchar(3),"
			+ "DISCOUNT double,"
			+ "ADDRESS varchar(64),"
			+ "PS varchar(512),"
			+ "BANKNO varchar(20),"
			+ "BANKNAME varchar(20),"
			+ "COUNTRY varchar(20),"
			+ "TRADETYPE varchar(1),"
			+ "STATE varchar(1),"
			+ "PIC TEXT,"
			+ "BIRTHDAY datetime,"
			+ "CREATEDATETIME datetime)";
		try{
			db.execSQL(strCreateTagTable);
		}catch(SQLException e){
			Log.e("Sales", "ERROR: " + e.getMessage());
			return false;   // maybe modify again
		}
		return true;
	}
	
	public static boolean createQcColor(SQLiteDatabase db){
		String strCreateTagTable = "CREATE TABLE IF NOT EXISTS qc_color("
			+ "_ID INTEGER PRIMARY KEY AUTOINCREMENT,"
			+ "NO varchar(2),"
			+ "TXT varchar(10),"
			+ "PIC varchar(8))";
		
		try{
			db.execSQL(strCreateTagTable);
		}catch(SQLException e){
			Log.e("Sales", "ERROR: " + e.getMessage());
			return false;   // maybe modify again
		}
		return true;
	}
	
	public static boolean createQcCountry(SQLiteDatabase db){
		String strCreateTagTable = "CREATE TABLE IF NOT EXISTS qc_country("
			+ "_ID INTEGER PRIMARY KEY AUTOINCREMENT,"
			+ "NAME varchar(20),"
			+ "RATE double,"
			+ "PIC TEXT,"
			+ "LAMIN double,"
			+ "LAMAX double,"
			+ "LOMIN double,"
			+ "LOMAX double)";
		
		try{
			db.execSQL(strCreateTagTable);
		}catch(SQLException e){
			Log.e("qc_country", "ERROR: " + e.getMessage());
			return false;   // maybe modify again
		}
		return true;
	}
	
	public static boolean createQcType(SQLiteDatabase db){
		String strCreateTagTable = "CREATE TABLE IF NOT EXISTS qc_type("
			+ "_ID INTEGER PRIMARY KEY AUTOINCREMENT,"
			+ "ID varchar(2),"
			+ "GOODTYPE varchar(20),"
			+ "COUNTRY varchar(20),"
			+ "SEASON varchar(6),"
			+ "ADDCOST double,"
			+ "PIC TEXT)";
		
		try{
			db.execSQL(strCreateTagTable);
		}catch(SQLException e){
			Log.e("qc_type", "ERROR: " + e.getMessage());
			return false;   // maybe modify again
		}
		return true;
	}
	
	public static boolean createQcUnit(SQLiteDatabase db){
		String strCreateTagTable = "CREATE TABLE IF NOT EXISTS qc_unit("
			+ "_ID INTEGER PRIMARY KEY AUTOINCREMENT,"
			+ "UNIT varchar(6))";
		try{
			db.execSQL(strCreateTagTable);
		}catch(SQLException e){
			Log.e("qc_unit", "ERROR: " + e.getMessage());
			return false;   // maybe modify again
		}
		return true;
	}
	
	public static boolean createQcSize(SQLiteDatabase db){
		String strCreateTagTable = "CREATE TABLE IF NOT EXISTS qc_size("
			+ "_ID INTEGER PRIMARY KEY AUTOINCREMENT,"
			+ "SIZES varchar(80))";
		try{
			db.execSQL(strCreateTagTable);
		}catch(SQLException e){
			Log.e("qc_size", "ERROR: " + e.getMessage());
			return false;   // maybe modify again
		}
		return true;
	}
	
	public static boolean createQcWash(SQLiteDatabase db){
		String strCreateTagTable = "CREATE TABLE IF NOT EXISTS qc_wash("
			+ "_ID INTEGER PRIMARY KEY AUTOINCREMENT,"
			+ "WASH10 varchar(30),"
			+ "WASH11 TEXT,"
			+ "WASH20 varchar(30),"
			+ "WASH21 TEXT,"
			+ "WASH30 varchar(30),"
			+ "WASH31 TEXT,"
			+ "WASH40 varchar(30),"
			+ "WASH41 TEXT,"
			+ "WASH50 varchar(30),"
			+ "WASH51 TEXT,"
			+ "WASH60 varchar(30),"
			+ "WASH61 TEXT)";
		
		try{
			db.execSQL(strCreateTagTable);
		}catch(SQLException e){
			Log.e("qc_wash", "ERROR: " + e.getMessage());
			return false;   // maybe modify again
		}
		return true;
	}
	// 
	public static boolean createQcQuality(SQLiteDatabase db){
		String strCreateTagTable = "CREATE TABLE IF NOT EXISTS qc_quality("
			+ "_ID INTEGER PRIMARY KEY AUTOINCREMENT,"
			+ "QUA10 varchar(20),"
			+ "QUA11 varchar(4),"
			+ "QUA20 varchar(20),"
			+ "QUA21 varchar(4),"
			+ "QUA30 varchar(20),"
			+ "QUA31 varchar(4),"
			+ "QUA40 varchar(20),"
			+ "QUA41 varchar(4),"
			+ "QUA50 varchar(20),"
			+ "QUA51 varchar(4),"
			+ "QUA60 varchar(20),"
			+ "QUA61 varchar(4))";
		
		try{
			db.execSQL(strCreateTagTable);
		}catch(SQLException e){
			Log.e("qc_quality", "ERROR: " + e.getMessage());
			return false;   // maybe modify again
		}
		return true;
	}

	public static boolean createPpri(SQLiteDatabase db){
		String strCreateTagTable = "CREATE TABLE IF NOT EXISTS qc_ppri("
			+ "_ID INTEGER PRIMARY KEY AUTOINCREMENT,"
			+ "ID varchar(12),"
			+ "BPRI varchar(8),"
			+ "APRI varchar(8),"
			+ "YEAR varchar(4),"
			+ "SEASON varchar(12),"
			+ "PIC TEXT)";
		
		try{
			db.execSQL(strCreateTagTable);
		}catch(SQLException e){
			Log.e("qc_ppri", "ERROR: " + e.getMessage());
			return false;   // maybe modify again
		}
		return true;
	}
	
	public static boolean createQacc(SQLiteDatabase db){
		String strCreateTagTable = "CREATE TABLE IF NOT EXISTS qc_macc("
			+ "_ID INTEGER PRIMARY KEY AUTOINCREMENT,"
			+ "ID varchar(2),"
			+ "QNOM varchar(6),"
			+ "TXT varchar(20),"
			+ "IOKEY varchar(1),"
			+ "PIC TEXT)";
		
		try{
			db.execSQL(strCreateTagTable);
		}catch(SQLException e){
			Log.e("qc_qacc", "ERROR: " + e.getMessage());
			return false;   // maybe modify again
		}
		return true;
	}
	
	public static boolean createQMacc(SQLiteDatabase db){
		String strCreateTagTable = "CREATE TABLE IF NOT EXISTS qmacc("
				+ "TR varchar(2),"
				+ "ID INTEGER,"
				+ "QKIND varchar(2),"
				+ "FORMNO varchar(16),"
				+ "FORMDATE varchar(10),"
				+ "CTIME varchar(16),"
				+ "UTIME varchar(16),"
				+ "ISCONFIRM varchar(1),"
				+ "QATYPE varchar(20),"
				+ "QNOM varchar(6),"
				+ "QNOI varchar(6),"
				+ "PS varchar(512),"
				+ "MOUT double,"
				+ "MINTO double,"
				+ "MBEFORE double,"
				+ "MBALANCE double,"
				+ "MBETWEEN double,"
				+ "MAFTER double,"
				+ "DEPTNO varchar(6),"
				+ "DEPTNAME varchar(20),"
				+ "DEVISE varchar(2),"
				+ "ATMNO varchar(20),"
				+ "ATMNAME varchar(20),"
				+ "ATMDATE varchar(10),"
				+ "EMPID varchar(10),"
				+ "EMPNAME varchar(20),"
				+ "PIC varchar(128),"
				+ "BANKNAME varchar(10))";
		
		try{
			db.execSQL(strCreateTagTable);
		}catch(SQLException e){
			Log.e("QMacc", "ERROR: " + e.getMessage());
			return false;   // maybe modify again
		}
		return true;
	}
	
	
	
	// 訂價策略
	public static boolean createQcDefpri(SQLiteDatabase db){
		String strCreateTagTable = "CREATE TABLE IF NOT EXISTS qc_defpri("
			+ "_ID INTEGER PRIMARY KEY AUTOINCREMENT,"
			+ "DEFPRI varchar(8),"
			+ "COUNTRY varchar(20),"
			+ "P0 double,"  // 自己加入  進價
			+ "P1 double,"
			+ "P2 double,"
			+ "P3 double,"
			+ "P4 double,"
			+ "P5 double)";
			
		
		try{
			db.execSQL(strCreateTagTable);
		}catch(SQLException e){
			Log.e("Sales", "ERROR: " + e.getMessage());
			return false;   // maybe modify again
		}
		return true;
	}
	
	
	public static boolean createQcDefault(SQLiteDatabase db){
		String strCreateTagTable = "CREATE TABLE IF NOT EXISTS qc_default("
			+ "_ID INTEGER PRIMARY KEY AUTOINCREMENT,"
			+ "BILLRATE double,"       // 匯率
			+ "COUNTRY varchar(20),"   // 國家
			+ "BATCH varchar(20),"	   // 批號
			+ "FACTNO varchar(20),"    // 廠商編號
			+ "STATE varchar(1),"      // 正式/樣品
			+ "SOURCENO varchar(2),"   // 來原編號產生方式
			+ "PRODUCT varchar(2),"	   // 貨號產生
			+ "ITEMFIRST varchar(2),"  // 新增優先順序
			+ "SEASON varchar(1),"	   // 季節
			+ "YEAR varchar(2),"	   // 年度
			+ "EMPLOY varchar(128),"   // 員工
            + "ACCOUNT varchar(128))"; // 扣款帳號			
		try{
			db.execSQL(strCreateTagTable);
		}catch(SQLException e){
			Log.e("Sales", "ERROR: " + e.getMessage());
			return false;   // maybe modify again
		}
		return true;
	}
	
	
	// 用到!
	public static boolean createQEmp(SQLiteDatabase db){
		String strCreateTagTable = "CREATE TABLE IF NOT EXISTS qemp("
			+ "_ID INTEGER PRIMARY KEY AUTOINCREMENT,"				
			+ "QEMPID varchar(3),"
			+ "QEMPNAME varchar(20),"
			+ "MOBIL varchar(32),"
			+ "EMAIL varchar(32),"
			+ "MSN varchar(32),"
			+ "GMAIL varchar(32),"
			+ "GPSLA double,"
			+ "GPSLO double,"
			+ "DEPTNO varchar(8),"
			+ "ADDRESS varchar(64),"
			+ "PS varchar(512),"
			+ "STATE varchar(1),"
			+ "PIC TEXT,"
			+ "BIRTHDAY varchar(10),"
			+ "CREATEDATETIME varchar(20))";
			
		try{
			db.execSQL(strCreateTagTable);
		}catch(SQLException e){
			Log.e("Sales", "ERROR: " + e.getMessage());
			return false;   // maybe modify again
		}
		return true;
	}
	
	// 用到!	
	public static boolean createQDept(SQLiteDatabase db){
		String strCreateTagTable = "CREATE TABLE IF NOT EXISTS qdept("
			+ "_ID INTEGER PRIMARY KEY AUTOINCREMENT,"				
			+ "DEPTID varchar(8),"
			+ "DEPTNAME varchar(20),"
			+ "TRADTYPE varchar(1),"
			+ "GPSLA double,"
			+ "GPSLO double)";
		
		try{
			db.execSQL(strCreateTagTable);
		}catch(SQLException e){
			Log.e("Sales", "ERROR: " + e.getMessage());
			return false;   // maybe modify again
		}
		return true;
	}
	// 用到!
	public static boolean createQCust(SQLiteDatabase db){
		String strCreateTagTable = "CREATE TABLE IF NOT EXISTS qcust("
			+ "_ID INTEGER PRIMARY KEY AUTOINCREMENT,"				
			+ "TR varchar(2),"
			+ "CUSTNO varchar(10),"
			+ "CUSTNAME varchar(20),"
			+ "MOBIL varchar(32),"
			+ "EMAIL varchar(32),"
			+ "MSN varchar(32),"
			+ "GMAIL varchar(32),"
			+ "GPSLA double,"
			+ "GPSLO double,"
			+ "DEPTNO varchar(8),"
			+ "EMPID varchar(3),"
			+ "DISCOUNT double,"
			+ "ADDRESS varchar(64),"
			+ "PS varchar(512),"
			+ "BANKNO varchar(20),"
			+ "BANKNAME varchar(20),"
			+ "COUNTRY varchar(20),"
			+ "TRADETYPE varchar(1),"
			+ "STATE varchar(1),"
			+ "PIC TEXT,"
			+ "CREATEDATE varchar(10),"
			+ "CREATETIME varchar(10),"			
			+ "BIRTHDAY varchar(10),"
			+ "C1 varchar(1),"			
			+ "C2 varchar(1),"
			+ "C3 varchar(1),"
			+ "M1 varchar(1),"			
			+ "M2 varchar(1),"
			+ "M3 varchar(1),"
			+ "S1 varchar(1),"
			+ "S2 varchar(1),"
			+ "S3 varchar(1))";
		try{
			db.execSQL(strCreateTagTable);
		}catch(SQLException e){
			Log.e("Sales", "ERROR: " + e.getMessage());
			return false;   // maybe modify again
		}
		return true;
	}
	
	// 第一次使用的初始值
	// 初始化 產品顏色
	public static boolean initColor(SQLiteDatabase db, Context cnt){
		try{
			int[] colors = new int[]{Color.BLACK, Color.WHITE, Color.rgb(96, 96, 96), Color.rgb(160, 160, 160)
					,Color.rgb(255, 0, 0),Color.rgb(255, 124, 17), Color.rgb(255, 0, 225),Color.rgb(255, 81, 217)
					,Color.rgb(152, 108, 0),Color.rgb(198, 156, 63),	 Color.rgb(168, 0, 162), Color.rgb(217, 130, 255)
					,Color.rgb(21, 73, 168),Color.rgb(21, 36, 96),	 Color.rgb(16, 107, 204), Color.rgb(113, 226, 226)
					,Color.rgb(255, 213, 5),Color.rgb(234, 105, 30),	 Color.rgb(255, 174, 25), Color.rgb(209, 239, 148)
					,Color.rgb(21, 66, 11),Color.rgb(69, 216,36),	 Color.rgb(44, 137, 104), Color.rgb(92, 255, 84)
					,Color.rgb(84, 99, 24),Color.rgb(224, 211, 33),	 Color.rgb(242, 236, 79), Color.rgb(239, 255, 122)};
			String[] no = new String[]{"01","02","03","04"
					,"05","06","07","08"
					,"09","10","11","12"
					,"13","14","15","16"
					,"17","18","19","20"
					,"21","22","23","24"
					,"25","26","27","28"};
			String[] txt = new String[]{"黑色", "白色" , "深灰", "淺灰"
					, "紅色", "橘色", "桃紅", "粉紅"
					,"咖啡", "淺咖", "紫色", "粉紫"
					,"藍色", "寶藍", "淺藍", "湖藍"
					,"黃色", "駝色", "淺駝", "卡其"
					,"軍綠", "綠色", "藍綠", "淺綠"
					,"褐色", "黃褐", "米黃", "米白"};
			for(int i = 0; i < colors.length; i++){
					ContentValues value = new ContentValues();
			    	value.put("NO", no[i]);
			    	value.put("TXT", txt[i]);
			    	value.put("PIC", colors[i]);
				    long result = db.insert(TbName.QC_COLOR, null, value);
			}
		}catch(Exception e){
			Log.e("Sales", "ERROR: " + e.getMessage());
		}
		return true;
	}
	// 初始化 國家
	public static boolean initCountry(SQLiteDatabase db, Context cnt){
		try{
			String[] countryIcon = new String[]{"drawable/country_twn","drawable/country_chi",
							"drawable/country_koe","drawable/country_jpn","drawable/country_hk"};
			String[] country = new String[]{"台灣", "中國", "韓國", "日本","香港"};
			double[] rate = new double[]{1.0, 4.78, 0.0288, 0.38,3.9};
			double[] lamin = new double[]{21.0, 17.0, 33.0, 26.2,21.879}; 
			double[] lamax = new double[]{26.1, 52.0, 33.0, 26.2,22.517};
			double[] lomin = new double[]{119.7, 47.0, 125.0, 127.1,113.575};
			double[] lomax = new double[]{123.0, 119.6, 129.0, 149.0,114.46};
			for(int i = 0; i < 5; i++){
					ContentValues value = new ContentValues();
			    	value.put("NAME", country[i]);
			    	value.put("RATE", rate[i]);
			    	value.put("PIC", countryIcon[i]);
			    	value.put("LAMIN", lamin[i]);
			    	value.put("LAMAX", lamax[i]);
			    	value.put("LOMIN", lomin[i]);
			    	value.put("LOMAX", lomax[i]);
				    long result = db.insert(TbName.QC_COUNTRY, null, value);
			}
		}catch(Exception e){
			Log.e("Sales", "ERROR: " + e.getMessage());
		}
		return true;
	}
	
	// 初始化 商品類別
	public static boolean initType(SQLiteDatabase db, Context cnt){
		try{
		
			ArrayList<String> iconList = new ArrayList<String>();
			ArrayList<String> nidList = new ArrayList<String>();			
			String[] goodstyle = new String[]{"娃娃T", "格襯衫", "短上衣", "牛仔褲", "洋裝", "皮夾", "大衣", "長版T", "毛衣春", "羽絨外套", "羽絨大衣", "襯衫", "吊帶裙", "帽外套", "帽上衣", "二件式針織上衣", "蕾絲上衣", "長洋裝", "蛋糕洋", "毛衣秋", "牛仔上衣", "短外套", "長版上衣", "毛衣冬", "長版帽上衣", "馬甲", "皮帶", "空帽", "禮帽", "性感內褲", "小可愛", "挖背內衣", "罩衫", "挖背背心", "吊帶洋", "毛衣罩衫", "手機包", "平板電腦包", "牛仔超短褲", "蕾絲背心", "睡衣", "帽休閒套頭", "短裙", "短褲", "領短洋", "背心洋", "短洋", "針織外套", "褲裙", "包鞋","領背心洋", "細格襯衫"
};
//			String[] season = new String[]{"夏季", "夏季", "夏季","四季","夏季","四季","冬季","夏季","春季","冬季","冬季","夏季","四季","冬季","冬季","冬季","冬季","冬季","夏季","冬季","夏季","夏季","冬季","冬季","冬季","夏季","四季","四季","四季","四季","四季","四季","冬季","夏季","夏季","冬季","四季","四季","夏季","夏季","冬季","冬季","夏季","夏季","夏季","夏季","夏季","夏季","夏季","夏季","夏季"};
//			int[] season = new int[]{1,1,1,4,1,4,3,1,0,3,3,1,4,3,3,3,3,3,1,3,1,1,3,3,3,1,4,4,4,4,4,4,3,1,1,3,4,4,1,1,3,3,1,1,1,1,1,1,1,4,1,1};
			String[] season = new String[]{"1","1","1","4","1","4","3","1","0","3","3","1","4","3","3","3","3","3","1","3","1","1","3","3","3","1","4","4","4","4","4","4","3","1","1","3","4","4","1","1","3","3","1","1","1","1","1","1","1","4","1","1"};			
			double[] addcost = new double[]{40,40,80,80,70,20,80,60,60,100,100,40,60,60,60,50,50,70,60,60,40,50,60,60,80,30,20,30,30,20,25,25,40,30,40,50,20,20,50,40,60,60,40,40,60,60,60,40,40,60,100,60,60};
			
			for(int i = 1; i <= 55; i ++){
				String icon = null; String nid=null;
					icon = "drawable/cat_" + Utilis.formatNumber(""+i, 3);
					nid=Utilis.formatNumber(""+i,2);
					iconList.add(icon);
					nidList.add(nid);
			}
			
			for(int i = 0; i < iconList.size(); i++){
					ContentValues value = new ContentValues();
			    	value.put("ID", nidList.get(i));					
			    	value.put("GOODTYPE", goodstyle[i]);
			    	value.put("COUNTRY", 3);
			    	value.put("SEASON", season[i]);
			    	value.put("ADDCOST", addcost[i]);
			    	value.put("PIC", iconList.get(i));
				    long result = db.insert(TbName.QC_TYPE, null, value);
			}
		}catch(Exception e){
			Log.e("Sales", "ERROR: " + e.getMessage());
		}
		return true;
	}
	
	// 初始化 商品尺寸
	public static boolean initSize(SQLiteDatabase db, Context cnt){
		try{
			String[] size = new String[]{
					"F","S,M,L,XL","M,L,XL,2XL,3XL","35,36,37,38,39,40"
					,"25,26,27,28,29,30","28,30,32,34,36,38"
					,"220,225,230,235,240,245,250,255,260,265"
			};
			for(int i = 0; i < size.length; i++){
					ContentValues value = new ContentValues();
			    	value.put("SIZES", size[i]);
				    long result = db.insert(TbName.QC_SIZE, null, value);
			}
		}catch(Exception e){
			Log.e("Sales", "ERROR: " + e.getMessage());
		}
		return true;
	}
	
	// 初始化 洗滌組合
	public static boolean initWash(SQLiteDatabase db, Context cnt){
		try{
			String DATABASE_PATH = Environment.getExternalStorageDirectory().getAbsolutePath();
			String savepath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator
					+ "CWBuyer" + File.separator + "wash" + File.separator;
			String[] icon = new String[] {savepath + "bleach0.png",
					savepath + "bleach1.png",
					savepath + "bleach2.png",
					savepath + "bleach3.png",
					savepath + "dry0.png",
					savepath + "dry1.png",};
			
			ContentValues value = new ContentValues();
			value.put("WASH10", icon[0]);
			value.put("WASH20", icon[1]);
			value.put("WASH30", icon[2]);
			value.put("WASH40", icon[3]);
			value.put("WASH50", icon[4]);
			value.put("WASH60", icon[5]);
			
			long result = db.insert(TbName.QC_WASH, null, value);
		}catch(Exception e){
			Log.e("Sales", "ERROR: " + e.getMessage());
		}
		return true;
	}
	
	// 初始化 成份組合
	public static boolean initQuality(SQLiteDatabase db, Context cnt){
		try{
			String[] strElem1 = new String[]{"聚酯纖維","棉","金屬纖維","彈性纖維"};
			int[] nPercentage1 = new int[]{60,35};
			int[] nPercentage2 = new int[]{35,60};
			int[] nPercentage3 = new int[]{2,2};
			int[] nPercentage4 = new int[]{3,3};
			
			for(int i = 0; i < nPercentage1.length; i++){
				ContentValues value = new ContentValues();
				value.put("QUA10", strElem1[0]);
				value.put("QUA11", nPercentage1[i]);
				value.put("QUA20", strElem1[1]);
				value.put("QUA21", nPercentage2[i]);
				value.put("QUA30", strElem1[2]);
				value.put("QUA31", nPercentage3[i]);
				value.put("QUA40", strElem1[3]);
				value.put("QUA41", nPercentage4[i]);
				long result = db.insert(TbName.QC_QUALITY, null, value);
			}
		}catch(Exception e){
			Log.e("Sales", "ERROR: " + e.getMessage());
		}
		return true;
	}
	
	// 初始化 訂價策略
//  "_ID INTEGER PRIMARY KEY AUTOINCREMENT,"
//	 "DEFPRI varchar(8),"
//	 "COUNTRY varchar(20),"
	
	public static boolean initDefPri(SQLiteDatabase db, Context cnt){
		try{
//			for(int i = 0; i < nPercentage1.length; i++){
			// 加入
				String[] nPRI = new String[]{"3000","3500","4000","5000","6000","7000","8000","9000","10000","11000","12000","13000","14000","15000","16000","17000","18000","19000","20000","21000","22000","23000","24000","25000","26000","27000","28000","29000","30000","31000","32000","33000","34000","35000"}; 
				int[] nP0 = new int[]{3000,3500,4000,5000,6000,7000,8000,9000,10000,11000,12000,13000,14000,15000,16000,17000,18000,19000,20000,21000,22000,23000,24000,25000,26000,27000,28000,29000,30000,31000,32000,33000,34000,35000};										
				int[] nP1 = new int[]{85,100,115,145,175,205,235,265,295,325,355,385,415,445,475,505,535,565,595,625,655,685,715,745,775,805,835,865,895,925,955,985,1015,1045};
				int[] nP2 = new int[]{130,145,160,190,220,250,280,310,340,370,400,430,460,490,520,550,580,610,640,670,700,730,760,790,820,850,880,910,940,970,1000,1030,1060,1090};
				int[] nP3 = new int[]{150,160,180,210,240,270,300,330,360,400,440,480,520,560,600,640,680,720,760,800,840,880,920,960,1000,1050,1100,1150,1200,1250,1300,1350,1400,1450};
				int[] nP4 = new int[]{199,200,250,350,350,450,550,550,600,700,700,800,800,900,900,1000,1000,1100,1200,1300,1400,1500,1600,1700,1800,1900,2000,2100,2200,2300,2400,2500,2600,2700};
				int[] nP5 = new int[]{290,290,290,390,390,490,590,590,690,790,790,890,1080,1080,1180,1280,1380,1480,1580,1680,1780,1880,1980,2080,2180,2280,2380,2480,2580,2680,2780,2880,2980,3080};
				
				for(int i = 0; i < nP0.length; i++){
					ContentValues value = new ContentValues();
			    	value.put("DEFPRI", nPRI[i]);					
			    	value.put("COUNTRY", 3);					
					value.put("P0", nP0[i]);
					value.put("P1", nP1[i]);
					value.put("P2", nP2[i]);
					value.put("P3", nP3[i]);
					value.put("P4", nP4[i]);
					value.put("P5", nP5[i]);
					long result = db.insert(TbName.QC_DEFPRI, null, value);
				}	
		}catch(Exception e){
			Log.e("Sales", "ERROR: " + e.getMessage());
		}
		return true;
	}
	
	// 初始化 預設參數
	public static boolean initDefault(SQLiteDatabase db, Context cnt){
		try{
//			for(int i = 0; i < nPercentage1.length; i++){
			// 加入日本
				ContentValues value = new ContentValues();
				value.put("COUNTRY", 3);
				value.put("BILLRATE", 0.0288);
				value.put("BATCH", "3G1");
				value.put("FACTNO", "K001");
				value.put("STATE", 0);
				value.put("SOURCENO", 1);
				value.put("PRODUCT", 1);
				value.put("ITEMFIRST", 4); // test
				value.put("SEASON", 3);
				value.put("YEAR", "2012");
				value.put("EMPLOY", "001");
				value.put("ACCOUNT", 4);
				long result = db.insert(TbName.QC_DEFAULT, null, value);
				if(result <= 0){
					Log.e("Sales", "Fail");
				}
		}catch(Exception e){
			Log.e("Sales", "ERROR: " + e.getMessage());
		}
		return true;
	}

	// 初始化 預設參數
	public static boolean initDefault_1(SQLiteDatabase db, Context cnt){
		try{
//			for(int i = 0; i < nPercentage1.length; i++){
			// 加入日本
			Cursor cs = db.rawQuery("select * from qc_default", null);
			cs.moveToFirst();
				ContentValues value = new ContentValues();
				value.put("BAROUT","1");
				value.put("FILEOUT","1");
				value.put("PRINTOUT","1");
				value.put("CA1","1");				
				value.put("CA2","1");
				value.put("CA3","2");
				value.put("CB1","6");				
				value.put("CB2","2");
				value.put("CB3","6");
				value.put("CC1","2");				
				value.put("CC2","2");
				value.put("CC3","5");				
				value.put("CD1","0");				
				value.put("CD2","0");
				value.put("CD3","0");				
				value.put("HID","A");				
//				long result = db.update(TbName.QC_DEFAULT, value, "", toString[]{});
				long result = db.update(TbName.QC_DEFAULT, value, "", null);				
				if(result <= 0){
					Log.e("Sales", "Fail");
				}
		}catch(Exception e){
			Log.e("Sales", "ERROR: " + e.getMessage());
		}
		return true;
	}
	
	
//	initAccount
	// 初始化帳戶資料!
	public static boolean initAccount(SQLiteDatabase db, Context cnt){
		String[] texts = new String[]{"現金","現金(人民幣)","現金(美金)","現金(韓幣)","富邦銀行","iCash卡"};
		String[] rates = new String[]{"1","5.0","30","0.0288","1","1"};
		String[] notes = new String[]{"","","","","",""};
		int[] nPics = new int[]{1,2,1,1,4,5};
		int[] nSorts = new int[]{9990,9980,9970,9960,9950,9940};
		try{
			for(int i = 0; i < texts.length; i++){
				ContentValues value = new ContentValues();
				value.put("acctext", texts[i]);
				value.put("accrate", rates[i]);
				value.put("accnote", notes[i]);
				value.put("accmoney", 0);
				value.put("accsort", nSorts[i]);
				value.put("accpic", nPics[i]);
				value.put("accinit", 0);
				long result = db.insert(TbName.ACCOUNT, null, value);
				if(result <= 0){
					Log.e("Sales", "Fail");
				}
			}
		}catch(Exception e){
			Log.e("Sales", "ERROR: " + e.getMessage());
		}
		return true;
	}

	// 初始化 廠商資料
	public static boolean initQFact(SQLiteDatabase db, Context cnt){
		try{
				ContentValues value = new ContentValues();
				value.put("TR", 0);
				value.put("FACTNO", "K001");
				value.put("FACTNAME", "預設廠商");
				value.put("COUNTRY", 3);
				value.put("CREATEDATETIME", DateUtil.getCurrentDateDb());
				long result = db.insert(TbName.QFACT, null, value);
				
				value.put("TR", 0);
				value.put("FACTNO", "T0799");
				value.put("FACTNAME", "7街99號");
				value.put("COUNTRY", 0);
				value.put("CREATEDATETIME", DateUtil.getCurrentDateDb());
				result = db.insert(TbName.QFACT, null, value);

				value.put("TR", 0);
				value.put("FACTNO", "F1203");
				value.put("FACTNAME", "棟樓層檔號");
				value.put("COUNTRY", 1);
				value.put("CREATEDATETIME", DateUtil.getCurrentDateDb());
				result = db.insert(TbName.QFACT, null, value);

		}catch(Exception e){
			Log.e("Sales", "ERROR: " + e.getMessage());
		}
		return true;
	}
	
	// 初始化 經手人資料
	public static boolean initQEmp(SQLiteDatabase db, Context cnt){
		try{
				ContentValues value = new ContentValues();
				value.put("QEMPID", "001");
				value.put("QEMPNAME", "經手人");
				long result = db.insert(TbName.QEMP, null, value);
		}catch(Exception e){
			Log.e("Sales", "ERROR: " + e.getMessage());
		}
		return true;
	}

	// 初始化 經手人資料
	public static boolean initQDept(SQLiteDatabase db, Context cnt){
		try{
				ContentValues value = new ContentValues();
				value.put("DEPTID", "AA");
				value.put("DEPTNAME", "西門店");
				value.put("TRADETYPE", "3");  //批發
				long result = db.insert(TbName.QDEPT, null, value);
		}catch(Exception e){
			Log.e("Sales", "ERROR: " + e.getMessage());
		}
		return true;
	}
	

}
