package com.cwbuyer.lib; import java.io.File; import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; import java.util.LinkedList; import android.app.Activity; import android.app.AlertDialog; import android.content.ContentValues; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.graphics.Color; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.view.Gravity; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.View.OnClickListener; import android.widget.AdapterView; import android.widget.AdapterView.OnItemLongClickListener; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.RadioGroup; import android.widget.ScrollView; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; import android.widget.AdapterView.OnItemClickListener; import com.cwbuyer.adapter.TableAdapter.TableCell; import com.cwbuyer.adapter.TableAdapter.TableRow; import com.cwbuyer.format.EMode; import com.cwbuyer.format.IDateDialog; import com.cwbuyer.format.IDialog; import com.cwbuyer.lib.Utilis; import com.cwbuyer.main.AccountList; import com.cwbuyer.main.QCustff; import com.pwbuyer.main.R; public class QpandnF extends Activity { ReportAdapter mAdapter = null; RepData datas; String goodO=""; String goodOName=""; String goodOPic=""; String aExtWord=""; private int mRestoreChoice = 0; String[] Pndnddlist; EditText pInput; int nPart=0; //預設裝置為[0總倉][1門市][2業務裝置]理論上較像外部裝置,但是只可以盤點(不一定提供圖檔) int nDept=1; //預設門市盤點 0.總倉 1.門市 2.廠商 盤點 int nSuccess=0; //如果nSuccess==0是應該不可以新增一個盤表,已存在未入帳的盤點清冊 int nCompares=1; //表示上盤日期比本盤日期還大,是不可以執行 int nTradetype=5; //預設為零售價 int nPandnK=0; //0詳式 1簡式 2盤價 int nKind=1; //0暫盤表 1主盤表 1盤差表 2盤準表 3已盤表 4未盤表 5.增盤表(原盤表不存在的商品ID>80000 and ID<100000) //@@@關鍵點 暫存的ID>100000 在增盤表的商品 也+100000?? //所以增盤表統計時,應判斷( ID>80000 and ID<100000 ) or (ID>180000 and ID<200000) int locations=0; int nDiscount=100; int nID=0; int nCondition=0; //控制頁面的判斷 1一樓選擇盤表 2二樓主盤表清冊 3三樓明細盤表清冊 int nState=0; //PNDNSTATE =0盤表 1暫盤 2歷史盤表 String[] mState={"(尚未入帳)","","(已經過帳)"}; int chkIn=0; int findP=0; int nPrice=0; int nAcost=0; int nAstk =0; int nAimn=0; int nAstn=0; int nAadn=0; int nLstk=0; int nAdefn=0; double nAdefm=0; int nPin=0; //nDept nTradetype nDiscount nState int cLstkn=0; int cLstkm=0; int tLastStkn=0; double tLastStkm=0; //上次的盤存總件數&總金額 ListView mListView = null; Button mBTain; Button mBTaim; Button mBTastn; Button mBTastm; Button mBTastkn; Button mBTastkm; Button mBTaadn; Button mBTaadm; LinkedList mSizeLink = new LinkedList(); LinkedList mColorLink = new LinkedList(); private LinearLayout lTableView = null; private LinearLayout mLayoutRoot = null; HashMap mCountRow = new HashMap(); // 顏色行資料 HashMap mCountCell = new HashMap(); // 尺寸欄資料 private String[] eachItem; private String[] eachField; int Wheight; int Wwidth; int tableHeight=30; String mColor=null; //單一顏色 String mColorno=null; //單一顏色 String mySize=null; //單一尺寸 private int mChoiceMode = ChoiceMode.PLUS; //預設 盤進+ String aInput=null; String mDBPath = android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"cwbuyer/data/20123/qmtrio.sdb"; String SD_PATH =android.os.Environment.getExternalStorageDirectory().getAbsolutePath(); String[] menu_E; String[] menu_LE; // String[] menu_E={ "進行盤點", "入帳","","匯出單一筆盤點清冊","分享","重新盤點","盤點量同在庫量","返回"}; String[] mKind={"總倉","門市","廠商"}; String[] sKind={"盤點中","暫盤中","已過帳"}; boolean isNew=true; private int mYear = 0; private int mMonth = 0; private int mDay = 0; String Ldate="2012-03-14"; String Ddate=null; String[] mTradeTypeStr={"外幣價","成本價","中盤價","批發價","網購價","零售價","歷史價"}; String mWho=null; String mWhoName=null; String mItem=null; String mItemName=null; String mLocDD="A區"; private final int RESULT_QCUSTFF = 9999; //會員檔回傳口令 private final int RESULT_QFACT = 1020; //廠商檔回傳口令 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; } public interface ChoiceMode{ int SERCH = 0; //查詢 int PLUS= +1; //盤進 int MILUS = -1; // 盤退 } @Override protected void onActivityResult(int requestCode, int resultCode, Intent dataR) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, dataR); switch (requestCode){ case RESULT_QCUSTFF: //返回(總倉)(專櫃)的各種可能性 { if (resultCode == RESULT_OK) { int newone=1; String mW=dataR.getStringExtra("qcust_key"); File fileQmtrio = new File(mDBPath); SQLiteDatabase mdb = SQLiteDatabase.openOrCreateDatabase(fileQmtrio, null); Cursor csm = mdb.rawQuery("select PNDNADAY from qpandn where USER='"+mW+"' and PNDNFKIND="+nDept +" and PNDNSTATE<>2 and ID=3", null); if (csm.getCount()>0){ newone=0;//表示不可重覆建立新的盤表 Toast.makeText(QpandnF.this, "不可以重複建立:"+mW+csm.getCount()+" 門市的盤點表!!", Toast.LENGTH_SHORT).show(); } csm.close(); mdb.close(); if (newone==1){ SQLiteDatabase db = Utilis.getDB(QpandnF.this); Cursor cs = null; StringBuffer mySqlBuf = new StringBuffer(); mySqlBuf.append("select CUSTNO,CUSTNAME,TRADETYPE,DISCOUNT from qcust where CUSTNO='"+mW+"' and TR='20'"); cs = db.rawQuery(mySqlBuf.toString(), null); if (cs.getCount()>0){ cs.moveToFirst(); nTradetype=cs.getInt(2);if (nTradetype<=0) nTradetype=1; mWho=cs.getString(0); mWhoName=cs.getString(1); ((Button)findViewById(R.id.btn_pndnno)).setText(cs.getString(0)); ((Button)findViewById(R.id.btn_pndnname)).setText(cs.getString(1)); ((Spinner)findViewById(R.id.spinner_pri)).setSelection(nTradetype); if (cs.getDouble(3)!=0){ nDiscount=cs.getInt(3); ((Button)findViewById(R.id.btn_disc)).setText(cs.getString(3)); }else{ nDiscount=100; ((Button)findViewById(R.id.btn_disc)).setText(""+nDiscount); } nSuccess=getSuccess(); nCondition=1;setCondition(); }else{ nSuccess=0; } db.close(); cs.close(); }else{ nCondition=2;setCondition(); } } break; } case RESULT_QFACT: { if (resultCode == RESULT_OK) { int newone=1; String mW=dataR.getStringExtra("fact_id"); File fileQmtrio = new File(mDBPath); SQLiteDatabase mdb = SQLiteDatabase.openOrCreateDatabase(fileQmtrio, null); Cursor csm = mdb.rawQuery("select PNDNADAY from qpandn where USER='"+mW+"' and PNDNFKIND="+nDept +" and PNDNSTATE<>2 and ID=3", null); if (csm.getCount()>0) { newone=0;//表示不可重覆建立新的盤表 Toast.makeText(QpandnF.this, "不可以重複建立:"+mW+" 的盤點表!!", Toast.LENGTH_SHORT).show(); } csm.close(); mdb.close(); if (newone==1){ SQLiteDatabase db = Utilis.getDB(QpandnF.this); Cursor cs = null; StringBuffer mySqlBuf = new StringBuffer(); mySqlBuf.append("select FACTNO,FACTNAME,TRADETYPE,DISCOUNT from qfact where FACTNO='"+mW+"' "); cs = db.rawQuery(mySqlBuf.toString(), null); if (cs.getCount()>0){ cs.moveToFirst(); nTradetype=cs.getInt(2);if (nTradetype<=0) nTradetype=1; mWho=cs.getString(0); mWhoName=cs.getString(1); ((Button)findViewById(R.id.btn_pndnno)).setText(cs.getString(0)); ((Button)findViewById(R.id.btn_pndnname)).setText(cs.getString(1)); ((Spinner)findViewById(R.id.spinner_pri)).setSelection(nTradetype); if (cs.getString(3)!=null){ nDiscount=cs.getInt(3); ((Button)findViewById(R.id.btn_disc)).setText(cs.getString(3)); }else{ nDiscount=100; ((Button)findViewById(R.id.btn_disc)).setText(""+nDiscount); } nSuccess=getSuccess(); }else{ nSuccess=0; } db.close(); cs.close(); }else{ nCondition=2;setCondition(); } } break; } } } public void onDestroy(){ super.onDestroy(); } /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.pandnf); setTitle(getString(R.string.app_name_version)); Wheight = this.getWindowManager().getDefaultDisplay().getHeight(); Wwidth = this.getWindowManager().getDefaultDisplay().getWidth(); if (Wwidth<=800 && Wheight<=1280 ) {// HTC EVO 3D G_NOTE tableHeight=38; } else if (Wwidth<=1080 && Wheight<=1920 ) {// HTC EVO 3D G_NOTE tableHeight=60; } else {//平板 GTP3100 A10 tableHeight=50; } if (!Utilis.getIni(this,"SYS","DEPT",1).equalsIgnoreCase(Utilis.getIni(this,"SYS","DEPT",6))) nPart=1; //0門市版1總倉 ArrayAdapter adapterAccount = new ArrayAdapter(this, android.R.layout.simple_spinner_item, mTradeTypeStr); adapterAccount.setDropDownViewResource(R.layout.sst_simple_dropdown_item); Spinner SpinPri = (Spinner)findViewById(R.id.spinner_pri); SpinPri.setAdapter(adapterAccount); SpinPri.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() { public void onItemSelected(AdapterView adapterView, View view, int position, long id) { nTradetype = position; if (nTradetype<=0) nTradetype=1; reCountBG(); } public void onNothingSelected(AdapterView arg0) { } }); if( nPandnK==0 ){ //詳式盤點 預設 ((RadioGroup)findViewById(R.id.GroupP)).check(R.id.radioP0); }else if (nPandnK==1) { //簡式盤點 ((RadioGroup)findViewById(R.id.GroupP)).check(R.id.radioP1); }else{ //價格盤點 ((RadioGroup)findViewById(R.id.GroupP)).check(R.id.radioP2); } //GalleryView 11個欄位排列為 //0代碼/1顏色/2尺寸/3暫盤/4已盤/5盤差/6應盤/7銷貨/8出貨/9進貨/10上存 //nState 0主盤表 1暫盤表 2歷史表 //nKind 0主盤表 1盤差表 2盤準表 3已盤表 4未盤表 5.增盤表(原盤表不存在的商品ID>8000 and ID<10000) //如果非總倉系統,一經點選 radio 可以為門市或廠商,就是不能為總倉,否則3種皆可 //確認點選(門市)後,隨即拉開(門市通訊錄)供選後_確認傳回 //並檢查,有否未入帳的(盤點清冊)若無:表首次盤點:上盤日期:2012-03-14,本盤日期:(today) //若有盤點清冊都已入帳,則取出最後一份盤清冊,並存入上盤日期 //傳回該門市或廠商的代號,簡稱,價別,折數,盤點輸出的方式(詳式or簡式or盤價) //讀取上盤的REC1:(盤存)件數 盤存金額 //--??--何時啟動上存的數據取出,然後建立本期的盤點清冊 //本盤日期:預設為當月最後一天,如果>20天,則自動取上月最後一天 //--??--價別&折數 可供修改 //價別:歷史價成本價中盤價批發價網購價零售價 (spinner) //折數:可以喚出計算機版面 //首頁的3+1大圖示功能 門市盤點 總倉盤點 廠商盤點 離開 ((LinearLayout)findViewById(R.id.layout_deptpndn)).setOnClickListener(new MainClick()); ((LinearLayout)findViewById(R.id.layout_aapndn)).setOnClickListener(new MainClick()); ((LinearLayout)findViewById(R.id.layout_factpndn)).setOnClickListener(new MainClick()); ((LinearLayout)findViewById(R.id.layout_exitpndn)).setOnClickListener(new MainClick()); //新增盤表的功能鍵 ((Button)findViewById(R.id.btn_pndnno)).setOnClickListener(new MainClick()); ((Button)findViewById(R.id.btn_disc)).setOnClickListener(new MainClick()); ((Button)findViewById(R.id.btn_dpndn)).setOnClickListener(new MainClick()); ((Button)findViewById(R.id.btn_cmd)).setOnClickListener(new MainClick()); ((Button)findViewById(R.id.btn_pdd)).setOnClickListener(new MainClick()); //在盤點清冊階段,顯示且只要 新增盤表__匯入盤表_離開 //在盤點階段,顯示 儲存暫存__放棄暫存__返回清冊 ((Button)findViewById(R.id.btn_add)).setOnClickListener(new MainClick()); ((Button)findViewById(R.id.btn_save)).setOnClickListener(new MainClick()); ((Button)findViewById(R.id.btn_savein)).setOnClickListener(new MainClick()); ((Button)findViewById(R.id.btn_reset)).setOnClickListener(new MainClick()); ((Button)findViewById(R.id.btn_exit)).setOnClickListener(new MainClick()); ((ImageButton)findViewById(R.id.pbtn_input)).setOnClickListener(new MainClick()); ((LinearLayout)findViewById(R.id.line_input)).setVisibility(View.INVISIBLE); pInput = (EditText)findViewById(R.id.pedIn); mBTain=((Button)findViewById(R.id.btn_ainn));//本進 mBTaim=((Button)findViewById(R.id.btn_ainm)); mBTastn=((Button)findViewById(R.id.btn_astn));//本銷 mBTastm=((Button)findViewById(R.id.btn_astm)); mBTastkn=((Button)findViewById(R.id.btn_astkn));//本存 mBTastkm=((Button)findViewById(R.id.btn_astkm)); mBTaadn=((Button)findViewById(R.id.btn_aadn));//本進 mBTaadm=((Button)findViewById(R.id.btn_aadm)); ((Button)findViewById(R.id.btn_disc)).addTextChangedListener(watcherPrice); // ((RadioGroup)findViewById(R.id.GroupDept)).setOnClickListener(new MainClick()); //由USER將選擇好項目,自然取得mSpinnerProduct 備用著囉! lTableView = (LinearLayout)findViewById(R.id.tableview); mLayoutRoot = (LinearLayout)findViewById(R.id.root); mListView = (ListView)findViewById(R.id.list_pditem); mAdapter = new ReportAdapter(this); mListView.setAdapter(mAdapter); mListView.setVisibility(View.GONE); mListView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub locations=arg2; datas = (RepData) mAdapter.getItem(locations); mItem=datas.iFormdate; mItemName=datas.iGoods; if (nCondition==2){ //二樓 String [] mDdate=datas.iName.split("~"); mWho=datas.iFormdate; mWhoName=datas.iGoods; Ddate=mDdate[1]; Ldate=mDdate[0]; Utilis.runVibrate(QpandnF.this); DialogUtilis.showDialog(QpandnF.this, "請選擇以下功能", -1, menu_LE, new IDialog() { @Override public void onDialogFinish(int pos, String choice) { switch (pos) { case 0://二樓刪除盤表(含現行(如果為最後一筆,可以刪除)歷史(如果為最後一筆,不可刪除)) { //nState==2 歷史表 最後一筆決不可刪 //唯有歷史表,才需要這個判斷 //進階版 應需要檢查 本盤表是否已存在 外部的匯出檔案 int CanDel=0; if (nState==2){ String LPD=""; //找出最後的 歷史表的盤點日期 File fileQmtrio = new File(mDBPath); SQLiteDatabase mdb = SQLiteDatabase.openOrCreateDatabase(fileQmtrio, null); StringBuffer mySqlBuf = new StringBuffer(); mySqlBuf.append("select PNDNADAY from qpandn where USER='"+mWho+"' and PNDNFKIND="+nDept ); mySqlBuf.append(" and PNDNSTATE=2 and ID=3 order by PNDNADAY desc LIMIT 1"); Cursor cs = mdb.rawQuery(mySqlBuf.toString(), null); if (cs.getCount()>0){ cs.moveToFirst(); if (Ddate.equalsIgnoreCase(cs.getString(0))){ //表示最後歷史盤點表,不可以刪除 //不論 總倉門市廠商 Toast.makeText(QpandnF.this, "這是最後歷史盤表,不可以刪除!!", Toast.LENGTH_SHORT).show(); }else{ //表示可以刪除 CanDel=1; } } cs.close(); mdb.close(); }else { //非歷史盤表 CanDel=1; } if (CanDel==1){ //不是最後歷史盤表,或其他盤表,可以刪除 DialogUtilis.showDialog(QpandnF.this, "確定整張單刪除?", -1, new String[] { "取消刪除", datas.iGoods+"的盤點清冊 當真刪除!!" }, new IDialog() { @Override public void onDialogFinish(int pos, String choice) { switch (pos) { case 0: {break;} case 1: // 確定刪除 { File fileQmtrio = new File(mDBPath); SQLiteDatabase mdb = SQLiteDatabase.openOrCreateDatabase(fileQmtrio, null); StringBuffer SQLb=new StringBuffer(); SQLb.append("delete from qpandn where USER='"+mWho+"' and PNDNFKIND="+nDept ); SQLb.append(" and PNDNADAY='"+Ddate+"'"); mdb.execSQL(SQLb.toString()); mdb.close(); getGroupData(QpandnF.this, mWho, nState); //2表示PNDNSTATE!=2 未入帳的盤表 mAdapter.notifyDataSetChanged(); } } } }); } break; } case 1://匯出且移除盤表(現行/歷史(條件)) { //先製作CSV檔 //匯出或覆蓋 到指定的路徑 //刪除主檔 break; } case 2://現行:重新盤點 歷史:取消過帳 { if (nState!=2){ //現行:重新盤點 DialogUtilis.showDialog(QpandnF.this, "確定已盤好的要歸零,再重新盤點?", -1, new String[] { "取消歸零", "當真歸零!起手無回大丈夫!" }, new IDialog() { @Override public void onDialogFinish(int pos, String choice) { switch (pos) { case 0: break; case 1: zeroPin("",1); //1.盤點歸零 0.暫盤歸零 2 } } }); }else{//歷史:取消過帳 DialogUtilis.showDialog(QpandnF.this, "已過帳的歷史盤表,要取消過帳?", -1, new String[] { "返回", "當真取消過帳!起手無回大丈夫!" }, new IDialog() { @Override public void onDialogFinish(int pos, String choice) { switch (pos) { case 0: break; case 1: //首先要 取得該盤點單的轉單單號 //刪除QQ(QHEAD,QITEMS) 也要遵循CLOUD規則 //再將PNDNSTATE 設為0 File fileQmtrio = new File(mDBPath); SQLiteDatabase mdb = SQLiteDatabase.openOrCreateDatabase(fileQmtrio, null); StringBuffer SQLb=new StringBuffer(); SQLb.append("select * from qpandn where USER='"+mWho+"' and PNDNFKIND="+nDept ); SQLb.append(" and PNDNADAY='"+Ddate+"' and ID=3"); mdb.execSQL(SQLb.toString()); mdb.close(); } } }); } break; } case 3://現行:同在庫量 歷史:輸出 { if (nState!=2){ DialogUtilis.showDialog(QpandnF.this, "已盤同應盤量,先假設全部符合?", -1, new String[] { "返回", "當真讓已盤同應盤量!" }, new IDialog() { @Override public void onDialogFinish(int pos, String choice) { switch (pos) { case 0: break; case 1: zeroPin("",2); //2.已盤同在庫量 } } }); } break; } case 4://現行:暫盤歸零 歷史:返回 { if (nState!=2){ DialogUtilis.showDialog(QpandnF.this, "確定暫盤要歸零,再重新盤點?", -1, new String[] { "取消歸零", "當真歸零!起手無回大丈夫!" }, new IDialog() { @Override public void onDialogFinish(int pos, String choice) { switch (pos) { case 0: break; case 1: zeroPin("",0); //暫盤歸零 } } }); } break; } case 5://現行:暫盤入帳 歷史:不執行 { zeroPin("",12); //所有暫盤入為已盤 break; } case 6://現行:盤點過帳 歷史:不執行 { if (nState !=2 && nDept !=2 && datas.iMoney.indexOf("暫盤:")<0){ //有可能為門市 總倉 但廠商不可執行過帳動作 DialogUtilis.showDialog(QpandnF.this, "請選擇盤點過帳的方式:", -1, new String[] { "盤差轉盤銷單", "盤差轉盤退單","返回" }, new IDialog() { @Override public void onDialogFinish(int pos, String choice) { switch (pos) { case 2: break; case 0: //盤差轉盤銷單 1確認為 總倉30 或門市31 (*-1) if (nDept==1) SaveinQQ(datas,mWho,0); else SaveinQQ(datas,mWho,2); break; case 1: //盤差轉盤退單 1確認為 總倉10 或門市20 if (nDept==1) SaveinQQ(datas,mWho,1); else SaveinQQ(datas,mWho,3); break; } } }); }else { Toast.makeText(QpandnF.this, mWho+" 盤點表,請檢查暫盤是否全部轉入已盤!! ", Toast.LENGTH_SHORT).show(); } break; } case 7://現行:輸出 歷史:不執行 { break; } case 8://現行:返回 歷史:不執行 { break; } } } }); return true; }else if (nCondition==3 && nState!=2){ //三樓 Utilis.runVibrate(QpandnF.this); //[0]"單款(暫盤)歸零";[1]="單款(盤點)歸零";[2]="單款(盤準)零誤差"; [3]="補價";[4]="返回"; DialogUtilis.showDialog(QpandnF.this, "請選擇以下功能", -1, menu_LE, new IDialog() { @Override public void onDialogFinish(int pos, String choice) { switch (pos) { case 0://三樓 單款暫盤歸零 { zeroPin(datas.iFormdate,0); break; } case 1: //三樓 單款盤點歸零 { zeroPin(datas.iFormdate,1); break; } case 2: //單款盤準 { zeroPin(datas.iFormdate,2); break; } case 3: //補價 對話框 { break; } case 4: //返回 { break; } } } }); return true; } return false; } }); // mListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View v, int position, long ids) { // TODO Auto-generated method stub locations=position; datas = (RepData) mAdapter.getItem(locations); Utilis.runVibrate(QpandnF.this); if (nCondition==3){//三樓 只有顯示該品TABLE goodO=datas.iFormdate; File fileQmtrio = new File(mDBPath); SQLiteDatabase mdb = SQLiteDatabase.openOrCreateDatabase(fileQmtrio, null); StringBuffer mSQL = new StringBuffer(); Cursor csm; //@@@ID>10<10000表示總盤表 10000以上為暫盤表 //ID>8000<10000表示為補增資料 可以列式條件 //是否納入 已盤清冊 未盤清冊 盤差清冊 等多元查詢 mSQL.append("select * from qpandn where USER='"+mWho+"' and PNDNADAY='"+Ddate+"'") .append(" and PNDNFKIND="+nDept); mSQL.append(" and GOODSNO='"+goodO+"'"); csm=mdb.rawQuery(mSQL.toString(), null); if(csm.getCount()>0 ){ //唯一性的,可以進行比對 csm.moveToFirst(); disPlayTable(csm.getString(csm.getColumnIndex("DATA"))); } csm.close(); mdb.close(); }else{ //二樓 String [] mDdate=datas.iName.split("~"); mWho=datas.iFormdate; mWhoName=datas.iGoods; Ddate=mDdate[1]; Ldate=mDdate[0]; DialogUtilis.showDialog(QpandnF.this, "請選擇以下功能", -1, menu_E, new IDialog() { @Override public void onDialogFinish(int pos, String choice) { switch (pos) { case 0:nKind=0; break;//進行盤點 case 1:nKind=1; break;//進行盤點 case 2:nKind=2; break;//進行盤點 case 3:nKind=3; break;//進行盤點 case 4:nKind=4; break;//進行盤點 case 5:nKind=5; break;//進行盤點 case 6:nKind=6; break;//進行盤點 case 7:nKind=7; break;//進行盤點 case 8:nKind=-1; break;//進行盤點 } if (nKind>=0){ nCondition=3; setCondition(); // aExtWord=""; getDetailData(QpandnF.this, mWho); //aState==1 有找到 暫盤表 mAdapter.notifyDataSetChanged(); }else if(nKind==-1) nKind=0; } }); } } }); pInput.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { //監視鍵盤按鍵 if(event.getAction()== KeyEvent.ACTION_DOWN){ if (keyCode==KeyEvent.KEYCODE_ENTER){ if (Utilis.toInt(Utilis.getIni(QpandnF.this,"SYS","DEPT",8))==1) { aInput=pInput.getText().toString(); //未來設置全大寫開關(許先生貨號有小寫英文為供應商代號) } else { aInput=pInput.getText().toString().toUpperCase(); } catched(); return true; } } return false; } }); pInput.setOnFocusChangeListener(new View.OnFocusChangeListener(){ public void onFocusChange(View view, boolean hasFocus){ if(hasFocus){ pInput.getSelectionStart(); } } }); mListView.setOnFocusChangeListener(new View.OnFocusChangeListener(){ public void onFocusChange(View view, boolean hasFocus){ if(hasFocus){ pInput.requestFocus(); } else { } } }); nCondition=0; setCondition(); //一樓 } //END OF PROGRAM private void catched(){ pInput.setSelectAllOnFocus(true); int Echk=-1; int Schk=-1; if (aInput.indexOf("-")!=aInput.lastIndexOf("-")){//表示輸入了商品,顏色尺寸 goodO=aInput.substring(0,aInput.indexOf("-")); mColorno=aInput.substring(aInput.indexOf("-")+1,aInput.lastIndexOf("-")); mySize=aInput.substring(aInput.lastIndexOf("-")+1); String Adata=searched(); if (Adata.length()>0){ Schk=1; for (int ii=0;ii0) goodO=aInput.substring(0,aInput.indexOf("-")); else goodO=aInput; File fileQmtrio = new File(mDBPath); SQLiteDatabase mdb = SQLiteDatabase.openOrCreateDatabase(fileQmtrio, null); StringBuffer mSQL = new StringBuffer(); Cursor csm; mSQL.append("select * from qpandn where USER='"+mWho+"' and PNDNADAY='"+Ddate+"'") .append(" and PNDNFKIND="+nDept); mSQL.append(" and GOODSNO like '%"+goodO+"%'"); csm=mdb.rawQuery(mSQL.toString(), null); if (csm.getCount()>0){// csm.moveToFirst(); Schk=1; goodO=csm.getString(csm.getColumnIndex("GOODSNO")); for (int ii=0;ii0){ csm.moveToLast(); if (csm.getInt(1)<2){ //0.新盤表 1盤點中 2.已入帳 //盤點尚未入帳,不得新增盤點清冊 Success=0; }else { //可以取得上次盤點日及上存總件數總金額 ((Button)findViewById(R.id.btn_lstkn)).setText(csm.getString(2)); ((Button)findViewById(R.id.btn_lstkm)).setText(csm.getString(3)); cLstkn=csm.getInt(2); cLstkm=csm.getInt(3); Success=1; //表示可新增的盤點清冊 } Ldate=csm.getString(0); isNew=false; } else { //首次盤點 Ldate="2012-03-14"; ((Button)findViewById(R.id.btn_lstkn)).setText("0"); ((Button)findViewById(R.id.btn_lstkm)).setText("0"); cLstkn=0; cLstkm=0; Success=1; isNew=true; } String day = Utilis.getMonthDate(); day=day.replace("/", "-"); String[] days = day.split("~"); Ddate = days[1]; Utilis.addMonth(Ddate, -1); ((Button)findViewById(R.id.btn_lpndn)).setText(Ldate); ((Button)findViewById(R.id.btn_dpndn)).setText(Ddate); csm.close(); mdb.close(); if (Success==0 && isNew==false){ ((TextView)findViewById(R.id.pndn_title)).setText(mKind[nDept]+"庫存盤點清冊[失敗]"); }else{ ((TextView)findViewById(R.id.pndn_title)).setText(mKind[nDept]+"盤點清冊"+mState[nState]); } return Success; } private void setCondition(){ //btop 首頁 //ctop 新增盤表 //pditem 盤點清冊 // switch (nCondition){ case 0:{ //一樓 //line_input ((LinearLayout)findViewById(R.id.body)).setBackgroundResource(R.drawable.keypad_gray4); ((ScrollView)findViewById(R.id.layout_cctop)).setVisibility(View.GONE); mLayoutRoot.setVisibility(View.GONE); ((ScrollView)findViewById(R.id.layout_bbtop)).setVisibility(View.VISIBLE); mListView.setVisibility(View.GONE); ((LinearLayout)findViewById(R.id.layout_bottom)).setVisibility(View.GONE); ((LinearLayout)findViewById(R.id.line_input)).setVisibility(View.INVISIBLE); ((TextView)findViewById(R.id.pndn_title)).setText("請選擇盤點對象"); ((Button)findViewById(R.id.btn_cmd)).setVisibility(View.GONE); ((Button)findViewById(R.id.btn_pdd)).setVisibility(View.GONE); break; } case 2: //(二樓)盤表清冊 GroupData { ((ScrollView)findViewById(R.id.layout_cctop)).setVisibility(View.GONE); ((ScrollView)findViewById(R.id.layout_bbtop)).setVisibility(View.GONE); mLayoutRoot.setVisibility(View.GONE); ((LinearLayout)findViewById(R.id.line_input)).setVisibility(View.GONE); ((LinearLayout)findViewById(R.id.layout_bottom)).setVisibility(View.VISIBLE); ((Button)findViewById(R.id.btn_save)).setVisibility(View.VISIBLE); ((Button)findViewById(R.id.btn_save)).setText("匯入盤表"); ((Button)findViewById(R.id.btn_reset)).setVisibility(View.VISIBLE); ((Button)findViewById(R.id.btn_reset)).setText("匯出盤表"); mListView.setVisibility(View.VISIBLE); ((Button)findViewById(R.id.btn_cmd)).setVisibility(View.GONE); ((Button)findViewById(R.id.btn_pdd)).setVisibility(View.GONE); //PNDNFKIND==nDept0 總倉 1門市 2廠商 if (nState!=2){ //輕按 menu_E=new String [9];menu_E[0]="暫盤中,繼續盤點"; menu_E[1]="全部的盤點明細";menu_E[2]="盤點且還有盤差的明細";menu_E[3]="盤點而沒有盤差的明細"; menu_E[4]="已經有盤過的明細";menu_E[5]="還沒有盤過的明細";menu_E[6]="增盤明細(收負帳)"; menu_E[7]="本期沒有盤差的明細";menu_E[8]="返回"; //長按 menu_LE=new String [9];menu_LE[0]="刪除盤表(須重新新增盤表)"; menu_LE[1]="匯出且移除盤表";menu_LE[2]="盤點表歸零,重新盤點";menu_LE[3]="盤點量同在庫量"; menu_LE[4]="暫盤表歸零";menu_LE[5]="暫盤表入帳";menu_LE[6]="盤好後,盤點過帳"; menu_LE[7]="輸出";menu_LE[8]="返回"; ((Button)findViewById(R.id.btn_add)).setVisibility(View.VISIBLE); ((Button)findViewById(R.id.btn_add)).setText("新增盤表"); ((Button)findViewById(R.id.btn_savein)).setVisibility(View.VISIBLE); ((Button)findViewById(R.id.btn_savein)).setText("以前盤表"); ((TextView)findViewById(R.id.pndn_title)).setText(mKind[nDept]+"盤點清冊"+mState[nState]); if (nDept==0){ //總倉盤點 ((LinearLayout)findViewById(R.id.body)).setBackgroundResource(R.drawable.keypad_gray5); }else if(nDept==1){//門市盤點 ((LinearLayout)findViewById(R.id.body)).setBackgroundResource(R.drawable.keypad_reds); }else if(nDept==2){//廠商盤點 ((LinearLayout)findViewById(R.id.body)).setBackgroundResource(R.drawable.keypad_blue2); } }else{ //長按 menu_LE=new String [5];menu_LE[0]="刪除盤表"; menu_LE[1]="匯出且移除盤表";menu_LE[2]="取消過帳,重新盤點"; menu_LE[3]="輸出";menu_LE[4]="返回"; ((Button)findViewById(R.id.btn_add)).setVisibility(View.GONE); ((Button)findViewById(R.id.btn_savein)).setText("現在盤表"); ((TextView)findViewById(R.id.pndn_title)).setText(mKind[nDept]+"盤點清冊"+mState[nState]); } break; } case 1: //(二樓) 新增盤表 { mListView.setVisibility(View.GONE); ((ScrollView)findViewById(R.id.layout_bbtop)).setVisibility(View.GONE); ((ScrollView)findViewById(R.id.layout_cctop)).setVisibility(View.VISIBLE); mLayoutRoot.setVisibility(View.GONE); ((LinearLayout)findViewById(R.id.line_input)).setVisibility(View.GONE); ((LinearLayout)findViewById(R.id.layout_bottom)).setVisibility(View.VISIBLE); ((Button)findViewById(R.id.btn_add)).setVisibility(View.VISIBLE); ((Button)findViewById(R.id.btn_add)).setText("建立盤點清冊"); ((Button)findViewById(R.id.btn_save)).setVisibility(View.GONE); ((Button)findViewById(R.id.btn_reset)).setVisibility(View.GONE); ((Button)findViewById(R.id.btn_savein)).setVisibility(View.GONE); ((Button)findViewById(R.id.btn_cmd)).setVisibility(View.GONE); ((Button)findViewById(R.id.btn_pdd)).setVisibility(View.GONE); if (nDept==0) //總倉盤點應多顯示 一個 出貨統計 ((LinearLayout)findViewById(R.id.lay_ad)).setVisibility(View.VISIBLE); else ((LinearLayout)findViewById(R.id.lay_ad)).setVisibility(View.GONE); break; } case 3: //三樓 是在某一張盤單下 輕按: 直接顯示TABLE表 { mListView.setVisibility(View.VISIBLE); mLayoutRoot.setVisibility(View.VISIBLE); ((Button)findViewById(R.id.btn_savein)).setVisibility(View.VISIBLE); ((Button)findViewById(R.id.btn_savein)).setText("櫃位搜尋"); if (nState!=2){//現行盤表 ((LinearLayout)findViewById(R.id.line_input)).setVisibility(View.VISIBLE); ((Button)findViewById(R.id.btn_add)).setVisibility(View.VISIBLE); ((Button)findViewById(R.id.btn_add)).setText("保留功能"); ((Button)findViewById(R.id.btn_save)).setVisibility(View.VISIBLE); ((Button)findViewById(R.id.btn_save)).setText("(暫盤)存入"); ((Button)findViewById(R.id.btn_reset)).setVisibility(View.VISIBLE); ((Button)findViewById(R.id.btn_reset)).setText("(暫盤)歸零"); ((Button)findViewById(R.id.btn_cmd)).setVisibility(View.VISIBLE); ((Button)findViewById(R.id.btn_pdd)).setVisibility(View.VISIBLE); //長按 menu_LE=new String [5]; menu_LE[0]="單款(暫盤)歸零"; menu_LE[1]="單款(盤點)歸零"; menu_LE[2]="單款(盤準)零誤差"; menu_LE[3]="補價"; menu_LE[4]="返回"; if (nDept==0){ //總倉盤點 ((LinearLayout)findViewById(R.id.body)).setBackgroundResource(R.drawable.keypad_gray); }else if(nDept==1){//門市盤點 ((LinearLayout)findViewById(R.id.body)).setBackgroundResource(R.drawable.keypad_orange); }else if(nDept==2){//廠商盤點 ((LinearLayout)findViewById(R.id.body)).setBackgroundResource(R.drawable.keypad_blue2); } pInput.requestFocus(); }else{//歷史盤表 ((LinearLayout)findViewById(R.id.line_input)).setVisibility(View.GONE); ((Button)findViewById(R.id.btn_add)).setVisibility(View.GONE); ((Button)findViewById(R.id.btn_save)).setVisibility(View.GONE); ((Button)findViewById(R.id.btn_reset)).setVisibility(View.GONE); //長按 menu_LE=new String [5];menu_LE[0]="返回"; } ((TextView)findViewById(R.id.pndn_title)).setText(mKind[nDept]+"盤點清冊"+mState[nState]); break; } } if (nCondition!=0) ((TextView)findViewById(R.id.pndn_end)).setText(mWhoName+"正在"+mKind[nDept]+nCondition+"樓 進行"+sKind[nState]); else{ ((TextView)findViewById(R.id.pndn_end)).setText(""); mWho=""; mWhoName=""; } } private void getGroupData(Context context, String aWho, int xState ) { // if (mAdapter.mList != null) { mAdapter.mList.clear(); } //@@@關鍵問題須強化nState的傳遞值 File fileQmtrio = new File(mDBPath); SQLiteDatabase mdb = SQLiteDatabase.openOrCreateDatabase(fileQmtrio, null); StringBuffer mSQL = new StringBuffer(); Cursor csm; SQLiteDatabase db = Utilis.getDB(QpandnF.this); Cursor cs; mSQL.append("select USER,USERNAME,PNDNADAY,PNDNBDAY,") .append("sum(ASTKN),sum(ASTKM),sum(ASTN),sum(ASTM),sum(APANN),sum(APANM),sum(ADEFN),sum(ADEFM),sum(EXPRICE),sum(APIN)") .append(" from qpandn where ID=3 and PNDNFKIND="+nDept+" and PNDNSTATE=" +xState); //只針對 盤表頭 if (aWho.length()>0){//表示為單一對象 mSQL.append(" and USER='"+mWho+"'"); } mSQL.append(" group by USER,USERNAME,PNDNADAY,PNDNBDAY"); csm=mdb.rawQuery(mSQL.toString(), null); Toast.makeText(QpandnF.this, mWho+"_State_"+xState+"_"+csm.getCount()+"盤點表_nDept"+nDept, Toast.LENGTH_SHORT).show(); if(csm.getCount()>0){ // csm.moveToFirst(); for(int xx=0;xx0){ cs.moveToFirst(); data.iPic=cs.getString(0); } data.iGoods=csm.getString(0)+"/"+csm.getString(1); //代號_名稱 data.iName=csm.getString(3)+"~"+csm.getString(2); //上盤日期~本盤日期 data.iNumber="補價:"+csm.getDouble(12); //補價 data.iCountry="本銷:"+csm.getString(6)+"/"+csm.getDouble(7); //本銷 data.iImpo="應盤"+csm.getString(4)+"/"+csm.getDouble(5); //本存 if (csm.getInt(13)!=0) data.iMoney="暫盤:"+csm.getString(13)+"/已盤:"+csm.getString(8); //本盤 else data.iMoney="已盤:"+csm.getString(8)+"/"+csm.getDouble(9); //本盤 data.iCompany="盤差:"+csm.getString(10)+"/"+csm.getDouble(11); //盤差 data.iFormdate=csm.getString(0); //盤點對象代號 mAdapter.mList.add(data); csm.moveToNext(); } } db.close(); mdb.close(); csm.close(); } private void getDetailData(Context context, String aWho) { // if (mAdapter.mList != null) { mAdapter.mList.clear(); } File fileQmtrio = new File(mDBPath); SQLiteDatabase mdb = SQLiteDatabase.openOrCreateDatabase(fileQmtrio, null); StringBuffer mSQL = new StringBuffer(); Cursor csm; //ID>10<100000表示總盤表 100000以上為暫盤表 //ID>50000 <80000表示為盤零表 //ID>80000<100000表示為補增資料 可以列式條件 //是否納入 已盤清冊 未盤清冊 盤差清冊 等多元查詢 //nKind== 0.暫盤表 1總盤表 2盤差表 3盤準表 4已盤表 5未盤表 6.增盤表(原盤表不存在的商品ID>80000 and ID<100000) mSQL.append("select * from qpandn where USER='"+aWho+"' and PNDNADAY='"+Ddate+"'") .append(" and PNDNFKIND="+nDept+" and PNDNSTATE=" +nState); switch (nKind){ case 0: //暫盤表 mSQL.append(" and ID>100000 and ID<200000 and APIN<>0"); break; case 1: //總盤表(包含:主盤,增盤,暫盤) mSQL.append(" and ((ID>10 and ID<50000) or (ID>80000 and ID<100000) or (ID>100000 and ID<150000) or (ID>180000 and ID<200000)) "); break; case 2: //盤差表 mSQL.append(" and ID>10 and ID<200000"); mSQL.append(" and ADEFN<>0 and PNDNDD>''"); break; case 3: //盤準表 mSQL.append(" and ID>10 and ID<200000 "); mSQL.append(" and ADEFN=0 and PNDNDD>'' and ((APANN+APIN)=ASTKN)"); break; case 4: //已盤表 mSQL.append(" and ID>10 and ID<200000"); mSQL.append(" and APANN<>0 and PNDNDD>''"); break; case 5: //未盤表 mSQL.append(" and ID>10 and ID<200000"); mSQL.append(" and APANN=0 and APIN=0 and PNDNDD=''"); break; case 6: //增盤表 mSQL.append(" and ((ID>80000 and ID<100000) or (ID>180000 and ID<200000)) "); break; case 7: //盤零表 mSQL.append(" and ((ID>50000 and ID<80000) or (ID>150000 and ID<180000)) "); break; } //如果有額外的條件時 if (aExtWord.length()>0) mSQL.append(aExtWord); mSQL.append(" order by GOODSNO"); csm=mdb.rawQuery(mSQL.toString(), null); if(csm.getCount()>0){ // csm.moveToFirst(); for(int xx=0;xx100000) data.iMoney="暫盤:"+csm.getInt(csm.getColumnIndex("APIN"))+"/已盤:"+csm.getString(csm.getColumnIndex("APANN"))+"/"+csm.getString(csm.getColumnIndex("APANM")); //本盤 else data.iMoney="已盤:"+csm.getString(csm.getColumnIndex("APANN"))+"/"+csm.getDouble(csm.getColumnIndex("APANM")); //本盤 data.iCompany="盤差:"+csm.getString(csm.getColumnIndex("ADEFN"))+"/"+csm.getDouble(csm.getColumnIndex("ADEFM"));//盤差 data.iFormdate=csm.getString(csm.getColumnIndex("GOODSNO")); //盤點對象代號 mAdapter.mList.add(data); csm.moveToNext(); } } mdb.close(); csm.close(); } private void reCountBG(){ int cAin=0; int cAim=0; int cAstn=0; int cAstm=0; int cAadn=0; int cAadm=0; int cAstkn=0; int cAstkm=0; nDiscount=Utilis.toInt(((Button)findViewById(R.id.btn_disc)).getText().toString()); SQLiteDatabase db = Utilis.getDB(QpandnF.this); Cursor cs; StringBuffer mySqlBuf = new StringBuffer(); mySqlBuf.append("select sum(UNIT10),sum(UNIT20),sum(UNIT30),sum(UNIT40),P1,P2,P3,P4,P5 from qitems "); mySqlBuf.append(" where FORMDATE>'"+Ldate+"' and FORMDATE<='"+Ddate+"' and ISCONFIRM='Y'"); if (nDept==0){ //總倉盤點 mySqlBuf.append(" and DEPTNO='"+mWho+"' group by P1,P2,P3,P4,P5"); cs=db.rawQuery(mySqlBuf.toString(),null); if (cs.getCount()>0){ cs.moveToFirst(); for(int x=0;x0){ cs.moveToFirst(); for(int x=0;x'"+Ldate+"' and FORMDATE<='"+Ddate+"' and ISCONFIRM='Y'"); mySqlBuf.append(" and USER='"+mWho+"' and QKIND like '2%' group by P1,P2,P3,P4,P5"); cs=db.rawQuery(mySqlBuf.toString(),null); if (cs.getCount()>0){ cs.moveToFirst(); for(int x=0;x0){ cs.moveToFirst(); for(int x=0;x0 && nCompares<0){ //一切符合建立盤表的條件 // String sepa=","; String sepaE=","; tLastStkn=0; tLastStkm=0; Toast.makeText(QpandnF.this, "Begin Create step02!!", Toast.LENGTH_SHORT).show(); File fileQmtrio = new File(mDBPath); SQLiteDatabase mdb = SQLiteDatabase.openOrCreateDatabase(fileQmtrio, null); SQLiteDatabase db = Utilis.getDB(QpandnF.this); Cursor cs; Cursor csm; StringBuffer mySqlBuf = new StringBuffer(); if (isNew==false){ //若存在上次盤點清冊,且PNDNSTATE=2已完成盤點入帳 須先重置 //取得上次盤點件數金額 還有?? 最後應存入本次盤點的ID=3 csm=mdb.rawQuery("select APANN,APANM from qpandn where ID==3 and USER='"+mWho+"' and PNDNFKIND="+nDept+" and PNDNSTATE=2 and PNDNADAY='"+Ldate+"'", null); if (csm.getCount()>0){ csm.moveToFirst(); tLastStkn=csm.getInt(0); tLastStkm=csm.getDouble(1); csm.close(); } csm=mdb.rawQuery("select * from qpandn where ID>10 and USER='"+mWho+"' and PNDNFKIND="+nDept+" and PNDNSTATE=2 and PNDNADAY='"+Ldate+"' and APANN<>0", null); nID=10; //這樣的條件會有同款庫存正負相抵為0時,就不再列出上存的疑點???? //先將上次盤點清冊的(本盤)>0者,取出並作為本次盤點清冊的(上存) //不只主貨號的表檔,也要將明細的各筆(為零者,不再出列) if (csm.getCount()>0){ csm.moveToFirst(); for (int i=0;i2 && k!=5 && k!=6 ) fieldB[k]="0"; nBufB.append(fieldB[k]+sepa); } nBufB.append(fieldB[10]); fieldA[ij]=nBufB.toString(); buf=buf+fieldA[ij]+sepaE; } valueI.put("PNDNFKIND",csm.getInt(csm.getColumnIndex("PNDNFKIND"))) ; valueI.put("PNDNPKIND",csm.getInt(csm.getColumnIndex("PNDNPKIND"))) ; valueI.put("PNDNCKIND",csm.getInt(csm.getColumnIndex("PNDNCKIND"))) ; valueI.put("PNDNSTATE",0) ; //新的盤表 valueI.put("ID",nID) ; valueI.put("USER",csm.getString(csm.getColumnIndex("USER"))) ; valueI.put("USERNAME",csm.getString(csm.getColumnIndex("USERNAME"))) ; valueI.put("PNDNBDAY",csm.getString(csm.getColumnIndex("PNDNADAY"))) ; valueI.put("PNDNADAY",Ddate) ; valueI.put("GOODSNO",csm.getString(csm.getColumnIndex("GOODSNO"))) ; valueI.put("GOODSNAME",csm.getString(csm.getColumnIndex("GOODSNAME"))) ; // String chg=csm.getString(csm.getColumnIndex("PIC")); // if (chg.indexOf("/cwbuyer/")>0) chg=chg.replace(chg.substring(0, chg.indexOf("/cwbuyer/")), SD_PATH); // valueI.put("PIC",chg) ; valueI.put("PIC",csm.getDouble(csm.getColumnIndex("PIC"))) ; valueI.put("UNITPRICE",csm.getInt(csm.getColumnIndex("UNITPRICE"))) ; valueI.put("DISCOUNT",csm.getDouble(csm.getColumnIndex("DISCOUNT"))) ; valueI.put("ACOST",csm.getDouble(csm.getColumnIndex("ACOST"))) ; valueI.put("EXPRICE",csm.getDouble(csm.getColumnIndex("EXPRICE"))) ; valueI.put("DATA",buf) ; valueI.put("DATA0","") ; valueI.put("PNDNDD","") ; valueI.put("DEPTSNO","") ; valueI.put("PARTSNO","") ; valueI.put("LASTSTKN",csm.getInt(csm.getColumnIndex("APANN"))) ; valueI.put("LASTSTKM",csm.getDouble(csm.getColumnIndex("APANM"))) ; valueI.put("AINN",0) ; valueI.put("AINM",0) ; valueI.put("ASTN",0) ; valueI.put("ASTM",0) ; valueI.put("ASTKN",csm.getInt(csm.getColumnIndex("APANN"))) ; valueI.put("ASTKM",csm.getDouble(csm.getColumnIndex("APANM"))) ; valueI.put("APANN",0) ; valueI.put("APANM",0) ; valueI.put("ADEFN",""+(csm.getInt(csm.getColumnIndex("APANN"))*-1)) ; valueI.put("ADEFM",""+(csm.getDouble(csm.getColumnIndex("APANM"))*-1)) ; valueI.put("CDT","") ; valueI.put("APIN",0) ; mdb.insert("qpandn", null, valueI); // db.setTransactionSuccessful(); // } finally { // db.endTransaction(); // } csm.moveToNext(); } //將上盤表的盤點量轉存入本盤表(上存) //可以確保資料存入資料庫 if (nID>=11){ //表示有上存資料時 //開始讀取現行主檔的明細資料 if (mySqlBuf.toString().length()>0) mySqlBuf.delete(0, mySqlBuf.toString().length()); if(nDept!=1){ //總倉或廠商 較類似 一趟SQL就可以完成 mySqlBuf.append("select GOODSNO,COLOR,UNIT1,SIZE,max(P1),min(P2),min(P3),min(P4),min(P5),sum(UNIT10),sum(UNIT20),sum(UNIT30),sum(UNIT40),GOODSNAME,PIC from qitems "); mySqlBuf.append(" where FORMDATE>'"+Ldate+"' and FORMDATE<='"+Ddate+"' and ISCONFIRM='Y'"); if (nDept==0){ mySqlBuf.append(" and DEPTNO='"+mWho+"'"); //理論上就是總倉代號 }else{ mySqlBuf.append(" and SUPPLY='"+mWho+"'"); //廠商代號 } mySqlBuf.append(" group by GOODSNO,COLOR,UNIT1,SIZE,GOODSNAME,PIC"); cs = db.rawQuery(mySqlBuf.toString(), null); if (cs.getCount()>0){ //本期有交易 cs.moveToFirst(); goodO=cs.getString(0); //初始goodO goodOName=cs.getString(13); goodOPic=cs.getString(14); String buf=""; findP=0; nPrice=cs.getInt(nTradetype+3); nAcost=cs.getInt(4); nAstk =0; nAimn=0; nAstn=0; nAadn=0; nLstk=0; csm=mdb.rawQuery("select * from qpandn where ID>10 and USER='"+mWho+"' and PNDNFKIND="+nDept+" and PNDNADAY='"+Ddate+"' and GOODSNO='"+goodO+"'", null); if(csm.getCount()>0){ //有上存盤表,取得buf也取得各量值 csm.moveToFirst(); buf=csm.getString(csm.getColumnIndex("DATA")); findP=1; nLstk=csm.getInt(csm.getColumnIndex("LASTSTKN")); } for (int ii=0;ii0){ if (findP==0) nID+=1; //原先盤表不存在需insert bufSave(QpandnF.this,mdb,buf,findP); } goodO=cs.getString(0); goodOName=cs.getString(13); goodOPic=cs.getString(14); buf=""; findP=0; nPrice=cs.getInt(nTradetype+3); nAcost=cs.getInt(4); nAstk =0; nAimn=0; nAstn=0; nAadn=0; nLstk=0; chkIn=0; csm=mdb.rawQuery("select * from qpandn where ID>10 and USER='"+mWho+"' and PNDNFKIND="+nDept+" and PNDNADAY='"+Ddate+"' and GOODSNO='"+cs.getString(0)+"'", null); if (csm.getCount()>0){ //表示盤表存在 csm.moveToFirst(); buf=csm.getString(csm.getColumnIndex("DATA")); findP=1; nLstk=csm.getInt(csm.getColumnIndex("LASTSTKN")); } buf=bufAdd(db,cs,buf); }//不同貨號END //如果到最後一筆,需要存入 if (ii==cs.getCount()){ if (buf.length()>0){ if (findP==0) nID+=1; //原先盤表不存在需insert bufSave(QpandnF.this,mdb,buf,findP); } } cs.moveToNext(); }//for_end } if (cs.toString().length()>0) cs.close(); }else{ //門市盤點的計算規則 UNIT10用不到 mySqlBuf.append("select GOODSNO,COLOR,UNIT1,SIZE,max(P1),min(P2),min(P3),min(P4),min(P5),sum(UNIT10),sum(UNIT20),sum(UNIT30),sum(UNIT40),GOODSNAME,PIC from qitems "); mySqlBuf.append(" where FORMDATE>'"+Ldate+"' and FORMDATE<='"+Ddate+"' and ISCONFIRM='Y'"); mySqlBuf.append(" and (USER='"+mWho+"' or DEPTNO='"+mWho+"')"); //理論上 mySqlBuf.append(" group by GOODSNO,COLOR,UNIT1,SIZE,GOODSNAME,PIC"); cs = db.rawQuery(mySqlBuf.toString(), null); if (cs.getCount()>0){ //本期有交易 cs.moveToFirst(); goodO=cs.getString(0); //初始goodO goodOName=cs.getString(13); goodOPic=cs.getString(14); String buf=""; findP=0; nPrice=cs.getInt(nTradetype+3); nAcost=cs.getInt(4); nAstk =0; nAimn=0; nAstn=0; nAadn=0; nLstk=0; csm=mdb.rawQuery("select * from qpandn where ID>10 and USER='"+mWho+"' and PNDNFKIND="+nDept+" and PNDNADAY='"+Ddate+"' and GOODSNO='"+goodO+"'", null); if(csm.getCount()>0){ //有上存盤表,取得buf也取得各量值 csm.moveToFirst(); buf=csm.getString(csm.getColumnIndex("DATA")); findP=1; nLstk=csm.getInt(csm.getColumnIndex("LASTSTKN")); } for (int ii=0;ii0){ if (findP==0) nID+=1; //原先盤表不存在需insert bufSave(QpandnF.this,mdb,buf,findP); } goodO=cs.getString(0); goodOName=cs.getString(13); goodOPic=cs.getString(14); buf=""; findP=0; nPrice=cs.getInt(nTradetype+3); nAcost=cs.getInt(4); nAstk =0; nAimn=0; nAstn=0; nAadn=0; nLstk=0; chkIn=0; csm=mdb.rawQuery("select * from qpandn where ID>10 and USER='"+mWho+"' and PNDNFKIND="+nDept+" and PNDNADAY='"+Ddate+"' and GOODSNO='"+cs.getString(0)+"'", null); if (csm.getCount()>0){ //表示盤表存在 csm.moveToFirst(); buf=csm.getString(csm.getColumnIndex("DATA")); findP=1; nLstk=csm.getInt(csm.getColumnIndex("LASTSTKN")); } buf=bufAdd(db,cs,buf); }//不同貨號END //如果到最後一筆,需要存入 if (ii==cs.getCount()){ if (buf.length()>0){ if (findP==0) nID+=1; //原先盤表不存在需insert bufSave(QpandnF.this,mdb,buf,findP); } } cs.moveToNext(); }//for_end } if (cs.toString().length()>0) cs.close(); } } //如果上盤表存在,理論上nID會>11 } if (csm.toString().length()>0) csm.close(); } else { //初次盤點 String buf=""; nID=10; if (nDept!=1) //總倉or廠商 { mySqlBuf.append("select GOODSNO,COLOR,UNIT1,SIZE,max(P1),min(P2),min(P3),min(P4),min(P5),sum(UNIT10),sum(UNIT20),sum(UNIT30),sum(UNIT40),GOODSNAME,PIC from qitems "); mySqlBuf.append(" where FORMDATE>'"+Ldate+"' and FORMDATE<='"+Ddate+"' and ISCONFIRM='Y'"); if (nDept==0){ mySqlBuf.append(" and DEPTNO='"+mWho+"'"); //理論上就是總倉代號 }else{ mySqlBuf.append(" and SUPPLY='"+mWho+"'"); //廠商代號 } mySqlBuf.append(" group by GOODSNO,COLOR,UNIT1,SIZE,GOODSNAME,PIC"); cs = db.rawQuery(mySqlBuf.toString(), null); if (cs.getCount()>0){ // cs.moveToFirst(); buf=""; goodO=cs.getString(0);//主貨號 goodOName=cs.getString(13); goodOPic=cs.getString(14); nPrice=cs.getInt(nTradetype+3); nAcost=cs.getInt(4); nAstk =0; nAimn=0; nAstn=0; nAadn=0; nLstk=0; chkIn=0; //buf=bufAdd(db,cs,buf); //cs.moveToNext(); // for (int ii=0;ii0) cs.close(); }else{ //門市初次盤點 mySqlBuf.delete(0, mySqlBuf.toString().length()); mySqlBuf.append("select GOODSNO,COLOR,UNIT1,SIZE,max(P1),min(P2),min(P3),min(P4),min(P5),sum(UNIT10),sum(UNIT20),sum(UNIT30),sum(UNIT40),GOODSNAME,PIC from qitems "); mySqlBuf.append(" where FORMDATE>'"+Ldate+"' and FORMDATE<='"+Ddate+"' and ISCONFIRM='Y'"); mySqlBuf.append(" and (USER='"+mWho+"' or DEPTNO='"+mWho+"')"); // mySqlBuf.append(" group by GOODSNO,COLOR,UNIT1,SIZE,GOODSNAME,PIC"); cs = db.rawQuery(mySqlBuf.toString(), null); if (cs.getCount()>0){ //本期有交易 cs.moveToFirst(); goodO=cs.getString(0); //初始goodO goodOName=cs.getString(13); goodOPic=cs.getString(14); buf=""; findP=0; nPrice=cs.getInt(nTradetype+3); nAcost=cs.getInt(4); nAstk =0; nAimn=0; nAstn=0; nAadn=0; nLstk=0; for (int ii=0;ii0) cs.close(); } } db.close(); StringBuffer mSQL = new StringBuffer(); mSQL.append("select sum(AINN),sum(AINM),sum(ASTN),sum(ASTM),sum(ASTKN),sum(ASTKM) from qpandn where USER='"+mWho+"' and PNDNADAY='"+Ddate+"'") .append(" and PNDNFKIND="+nDept+" and PNDNSTATE=" +nState+" and ID>10 and ID<10000"); csm=mdb.rawQuery(mSQL.toString(), null); if(csm.getCount()>0){ // csm.moveToFirst(); //製作單頭ID=3 int cAin=csm.getInt(0); int cAim=csm.getInt(1); int cAstn=csm.getInt(2); int cAstm=csm.getInt(3); int cAstkn=tLastStkn+csm.getInt(4); double cAstkm=tLastStkm+cAim-cAstm; ContentValues valueI = new ContentValues(); valueI.put("PNDNFKIND",""+nDept); //0AA 1A1 2SUPPLY valueI.put("PNDNPKIND",""+nTradetype); //priceType P1-P5 valueI.put("PNDNCKIND",""+nPandnK) ; //GOODSNOS GOODNO PRICE nState=0;valueI.put("PNDNSTATE",nState) ; //新的盤表 valueI.put("ID",3) ; valueI.put("USER",mWho) ; valueI.put("USERNAME",((Button)findViewById(R.id.btn_pndnname)).getText().toString()) ; valueI.put("PNDNBDAY",Ldate) ; valueI.put("PNDNADAY",Ddate) ; valueI.put("GOODSNO","") ; valueI.put("GOODSNAME","") ; valueI.put("PIC","") ;//Picture of USER valueI.put("UNITPRICE",0) ; valueI.put("DISCOUNT",nDiscount) ; valueI.put("ACOST",0) ; valueI.put("DATA","") ; valueI.put("DATA0","") ; valueI.put("PNDNDD","") ; valueI.put("DEPTSNO","") ; valueI.put("PARTSNO","") ; valueI.put("LASTSTKN",tLastStkn) ; valueI.put("LASTSTKM",tLastStkm) ; valueI.put("AINN",cAin) ; valueI.put("AINM",cAim); valueI.put("ASTN",cAstn) ; valueI.put("ASTM",cAstm); valueI.put("ASTKN",cAstkn); //本存(應盤) valueI.put("ASTKM",cAstkm); //這是個不對稱的欄位 valueI.put("APANN",0) ; //本盤 valueI.put("APANM",0) ; valueI.put("ADEFN",(cAstkn*-1)) ; //盤差量 valueI.put("ADEFM",(cAstkm*-1)) ; //盤差金 valueI.put("APIN",0) ; //暫盤 mdb.insert("qpandn", null, valueI); } mdb.close(); nCondition=2; setCondition(); //回盤點清冊 if (nDept!=0) mWho=""; getGroupData(QpandnF.this, mWho, nState); //2表示PNDNSTATE!=2 未入帳的盤表 mAdapter.notifyDataSetChanged(); //須區分出(廠商)(總倉)(門市(專櫃)) //取得本區間的進貨(廠商總倉10)(門市2021) 數據作為(本進) //取得本區間的銷貨(總倉30)(門市3141) 數據作為(本銷) //還要一邊比對盤點清冊是否已存在,而進一步運算 //關鍵_先解讀各色尺寸的(上存)(本進)(本銷)(本存)並經運算後,再重置 //也要將各小計放在REC的欄位,也要重置正確的(DATA) //並製作本存=上存+本進-本銷 //如果不存在(上存=0)增設一筆新紀錄(取得主貨號品名) //運算的安排__色號,色名,尺寸,本存,本盤,盤差,上存,本進,本銷\r\n //以條碼刷入(明細貨號後)先分解(split("-"))主貨號,顏色,尺寸 //取得主貨號REC,分解先以split(\r\n)取得每一筆顏色尺寸 //再以split(",")取得每一筆的各欄位 //經運算後,再存回去.... //再用字串StringBuffer的技巧,重組字串,再存回DATA //暫存的概念... } }else if (nCondition==3 ){ //(三樓)繼續盤點 盤點明細清單 Toast.makeText(QpandnF.this, "保留的功能!目前沒有作用!!", Toast.LENGTH_SHORT).show(); //呼叫 GalleryVP /* Intent intent = new Intent(); Bundle bundle = new Bundle(); bundle = new Bundle(); bundle.putString("GalleryChild",mWho+","+Ddate+","+nDept+""+nState+""+nDiscount); intent.setClass(QpandnF.this, GalleryVP.class); intent.putExtras(bundle); startActivity(intent); */ } break; } case R.id.btn_save: //儲存 將盤點中的暫盤資料確實存入盤點清冊 { if (nCondition==3){//ID>100000 視為暫盤 DATA 每一個色尺寸 都要分解 重算 打包 並算出TOT 維護 zeroPin("",12); } else if (nCondition==2){//匯入盤表 } break; } case R.id.btn_savein: //將盤好的盤點清冊,比對了總倉或門市的實際數據,產生一份盤銷單(50/51) { //2樓_現在盤表/以前盤表 //3樓_櫃位搜尋 if (nCondition==3 ){ //拉出對話框 先整理出所有 櫃位清單,任選後 在搜尋之 StringBuffer mLst = new StringBuffer(); mLayoutRoot.removeAllViews(); File fileQmtrio = new File(mDBPath); SQLiteDatabase mdb = SQLiteDatabase.openOrCreateDatabase(fileQmtrio, null); StringBuffer mSQL = new StringBuffer(); Cursor csm; mSQL.append("select PNDNDD,sum(ASTKN),sum(APANN),sum(APIN),sum(ADEFN) from qpandn where USER='"+mWho+"' and PNDNADAY='"+Ddate+"'") .append(" and PNDNFKIND="+nDept +" and ID>10 group by PNDNDD "); csm=mdb.rawQuery(mSQL.toString(), null); if(csm.getCount()>0 ){ //唯一性的,可以進行比對 csm.moveToFirst(); for (int ii=0;ii 0){ //當找到檔案數量後 AlertDialog.Builder sortDlg = new AlertDialog.Builder(QpandnF.this); sortDlg.setTitle(msgTitle) .setSingleChoiceItems(Pndnddlist, 0, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { mRestoreChoice = item; } }) .setPositiveButton(getString(R.string.str_ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //確認 mLocDD=Pndnddlist[mRestoreChoice].substring(0, Pndnddlist[mRestoreChoice].indexOf("__")); aExtWord=" and PNDNDD='"+mLocDD+"'"; ((Button)findViewById(R.id.btn_pdd)).setText(mLocDD); getDetailData(QpandnF.this, mWho); //aState==1 有找到 暫盤表 mAdapter.notifyDataSetChanged(); } }) .setNegativeButton("還原", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //取消 aExtWord=""; getDetailData(QpandnF.this, mWho); //aState==1 有找到 暫盤表 mAdapter.notifyDataSetChanged(); } }).show(); } } }else if (nCondition==2 ){ //2樓_現在盤表/以前盤表 if (nState==2){ //從以前盤表->回到現在 ((Button)findViewById(R.id.btn_savein)).setText("以前盤表"); nState=0; }else{ ((Button)findViewById(R.id.btn_savein)).setText("回到現在"); nState=2; } //((TextView)findViewById(R.id.pndn_title)).setText(mKind[nDept]+"盤點清冊"+mState[nState]); nCondition=2; setCondition(); getGroupData(QpandnF.this, mWho, nState); //2表示PNDNSTATE!=2 未入帳的盤表 mAdapter.notifyDataSetChanged(); } break; } case R.id.btn_reset: { if (nCondition==3 ){//三樓(暫存)歸零 DialogUtilis.showDialog(QpandnF.this, "確定暫盤要歸零,再重新盤點?", -1, new String[] { "取消歸零", "當真歸零!起手無回大丈夫!" }, new IDialog() { @Override public void onDialogFinish(int pos, String choice) { switch (pos) { case 0: break; case 1: zeroPin("",0); //如果有值,是針對單筆 } } }); } break; } case R.id.btn_exit: //離開盤點系統 回到主程式 { if (nCondition==1 || nCondition==3 ){ //從三樓 或 從新增盤表 返回 if (nDept!=0) mWho=""; //總倉唯一 (門市廠商盤點 對多 所以mWho="") nCondition=2; setCondition(); }else if (nCondition==2){ nCondition=0; setCondition(); } getGroupData(QpandnF.this, mWho, nState); //2表示PNDNSTATE!=2 未入帳的盤表 mAdapter.notifyDataSetChanged(); break; } //----------/主畫面的6大功能\--下方的 buttom case R.id.layout_deptpndn: //門市盤點作業 { nDept=1;nState=0; nCondition=2; setCondition(); // mWho=""; getGroupData(QpandnF.this, mWho, nState); //2表示PNDNSTATE!=2 未入帳的盤表 mAdapter.notifyDataSetChanged(); //預設為(未入帳) //如果有門市盤點清冊,直接顯示所有清冊 //下半部視窗隨著輕觸(門市)顯示 的 上存/本/進/銷/存 //如果沒有半個門市時,是否直接進入新增門市??? //getCust(); //並非馬上新增 //未入帳盤點清冊下鈕包含:__新增__匯入__返回__ //輕觸ITEM_menu包含: 繼續盤點/入帳/直接刪除/匯出/輸出/重新盤點/盤點量同在庫量/返回 //已入帳盤點清冊(如果沒有範圍)勢必會一大串(如果寄賣盤以100個專櫃而言,有可能全部超過數百) //所以(已入帳)顯示最後盤點清冊(所有專櫃),如果指定某一對象,應該顯示該對象所有盤點清冊(以夾鏈方式往右呈現) //下鈕包含:__返回 //輕按MENU__取消入帳(一定要為最後一筆盤點清冊)才可為之__直接刪除__匯出(送回總倉進一步維護總倉庫存)__ //__輸出(分享的概念)__明細清單__返回 break; } case R.id.layout_aapndn: // 總倉盤點作業 { nDept=0;nState=0; nCondition=2; setCondition(); // if( nPart==0 ){ //總倉做總倉盤點 mWho=Utilis.getIni(QpandnF.this,"SYS","DEPT",6); } getGroupData(QpandnF.this, mWho, nState); //2表示PNDNSTATE!=2 未入帳的盤表 mAdapter.notifyDataSetChanged(); break; } case R.id.layout_factpndn: // 廠商盤點作業 { nDept=2;;nState=0; nCondition=2; setCondition(); // mWho=""; getGroupData(QpandnF.this, mWho, nState); // mAdapter.notifyDataSetChanged(); break; } case R.id.layout_exitpndn: // 結束盤點回庫存管理(MENU) { //取得總倉代號&名稱,並確認為總倉系統或門市系統&且預設總倉盤點 finish(); break; } //--------------------/新增盤點清冊/----------------------- case R.id.btn_pndnno: //[編號]當需要重新挑選對象時 { nDept=1;nState=0; nCondition=1; setCondition(); // getCust(); break; } case R.id.btn_disc: // { DialogUtilis.showComputer(QpandnF.this, id); reCountBG(); break; } case R.id.pbtn_input: { catched(); break; } case R.id.btn_pdd://輸入櫃位 { if (nCondition==3){ //對話窗 LayoutInflater factory = LayoutInflater.from(QpandnF.this); final View v1 = factory.inflate(R.layout.register, null); final EditText edtReg = (EditText) v1.findViewById(R.id.edtReg); ((TextView) v1.findViewById(R.id.TextView01)).setText("盤點時,系統為了資料安全起見,將正在盤點的商品放在(暫存區),並將商品的區域位置製作標簽,視為櫃位"); edtReg.setText(mLocDD); new AlertDialog.Builder(QpandnF.this).setTitle("請輸入正在盤點的櫃位:").setView(v1).setNeutralButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { mLocDD=edtReg.getText().toString(); ((Button)findViewById(R.id.btn_pdd)).setText(mLocDD); } }).show(); } break; } case R.id.btn_cmd://輸入櫃位 { if (mChoiceMode==ChoiceMode.SERCH){ mChoiceMode=ChoiceMode.PLUS; ((Button)findViewById(R.id.btn_cmd)).setText("盤進(+)"); }else if (mChoiceMode==ChoiceMode.PLUS){ mChoiceMode=ChoiceMode.MILUS; ((Button)findViewById(R.id.btn_cmd)).setText("盤退(-)"); }else if (mChoiceMode==ChoiceMode.MILUS){ mChoiceMode=ChoiceMode.SERCH; ((Button)findViewById(R.id.btn_cmd)).setText("僅查詢"); } break; } case R.id.btn_dpndn: // 本次盤點日 { if (nSuccess>0){ mYear=Utilis.toInt(Ddate.substring(0, 4)); mMonth=Utilis.toInt(Ddate.substring(5, 7)); mDay=Utilis.toInt(Ddate.substring(8, 10)); Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, mYear); c.set(Calendar.MONTH, mMonth - 1); c.set(Calendar.DAY_OF_MONTH, mDay); Utilis.showDateDialog(QpandnF.this, "請輸入本次盤點日期", c, new IDateDialog(){ @Override public void onDateDialogFinish(String date, int year, int month, int day) { ((Button)findViewById(R.id.btn_dpndn)).setText(date); nCompares=Utilis.compareTime(Ldate, date); if (nCompares>=0){ //表示本盤<=上盤,是無法盤點,需重返 Toast.makeText(QpandnF.this, "本次盤點日須比上次盤點日還大", Toast.LENGTH_SHORT).show(); }else{ //合法本盤日期 Ddate=date; reCountBG(); } } }); }else{ //資訊不完整,可以集中管理 //尚未取得編號簡稱,或上次盤點日及價別及折數 //是否警示:當價別折數與DATA上的設定不符時或與上次盤點不符時 //@@@還是限定價別與折數需與DATA一致,不開放異動?? Toast.makeText(QpandnF.this, "請補正其他資訊!!", Toast.LENGTH_SHORT).show(); } break; } // default: // break; } } } private TextWatcher watcherPrice = new TextWatcher(){ @Override public void afterTextChanged(Editable s) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { reCountBG(); } }; private class ReportAdapter extends BaseAdapter{ private LayoutInflater mInflater; public LinkedList mList = new LinkedList(); 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; RepData data = mList.get(position); if (convertView == null) { convertView = mInflater.inflate(R.layout.list_posh, null); holder = new ViewHolder(); holder.imageItem = (ImageView)convertView.findViewById(R.id.img_ppic); if (data.iGoods.length()>0) ((TextView) convertView.findViewById(R.id.text_pgoodsno)).setBackgroundColor(Color.GREEN); // else ((TextView) convertView.findViewById(R.id.text_pgoodsno)).setBackgroundColor(Color.GREEN); 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"); 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; } } private void disPlayTable(String mData){ //到時候需區隔 0總倉 1門市 2廠商 mLayoutRoot.removeAllViews(); mSizeLink.clear(); mCountRow.clear(); mCountCell.clear(); mSizeLink.add("代碼");mSizeLink.add("顏色");mSizeLink.add("尺寸"); mSizeLink.add("暫盤");mSizeLink.add("已盤");mSizeLink.add("盤差"); mSizeLink.add("應盤");mSizeLink.add("本銷"); if (nDept==0) mSizeLink.add("本出"); else if (nDept==1) mSizeLink.add("轉出"); else mSizeLink.add("保留"); mSizeLink.add("本進");mSizeLink.add("上存"); mCountRow.put(0, 0 * 100); for (int k=0;k<11;k++) mCountCell.put(k, mSizeLink.get(k)); //02,黑色,F,0,0,-16,16,0,0,16,0,11,灰色,F,0,0,-7,7,0,0,7,0, //分解 DATA //String mData=csm.getString(csm.getColumnIndex("DATA")); eachItem = mData.split(","); //取得各色號尺寸數據字串 for (int i=0;i table = new ArrayList(); table.removeAll(table); for(int i = 0; i <= eachItem.length; i++){ TableCell[] titles = new TableCell[mSizeLink.size()]; for(int k = 0; k < titles.length; k++){ if (k<=2) titles[k] = new TableCell((Wwidth/8)-8,tableHeight,TableCell.STRING); else titles[k] = new TableCell((Wwidth/6)-8,tableHeight,TableCell.STRING); } table.add(new TableRow(titles)); } TableRow tableRow = table.get(0); for(int i = 0; i <=eachItem.length; i ++){ TableRowView row = new TableRowView(this, tableRow, i); mLayoutRoot.addView(row); } } public class TableRowView extends LinearLayout { public TableRowView(Context context, TableRow tableRow, int position) { super(context); this.setOrientation(LinearLayout.HORIZONTAL); for (int i = 0; i < tableRow.getSize(); i++) { TableCell tableCell = tableRow.getCellValue(i); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( tableCell.width, tableCell.height); layoutParams.setMargins(0, 0, 1, 1); TextView textCell = new TextView(context); textCell.setLines(1); textCell.setGravity(Gravity.CENTER); textCell.setBackgroundColor(Color.WHITE); if(mCountRow.containsKey(position) == true){ int key = mCountRow.get(position); if( mCountCell.containsKey(key + i)){ textCell.setText(String.valueOf(mCountCell.get(key + i))); }else{ textCell.setText("X"); } }else{ textCell.setText("X"); } textCell.setId(position * 100 + i); textCell.setOnClickListener(new Clickable(position,i)); textCell.setTextColor(Color.BLACK); if(position>0 && i>=2 ){ switch(i){ case 2:textCell.setBackgroundResource(R.drawable.keypad_orange);break; //尺寸 case 3:textCell.setBackgroundColor(Color.WHITE);break; //暫盤 case 4:textCell.setBackgroundResource(R.drawable.keypad_yellow);break; //已盤 case 5:textCell.setBackgroundResource(R.drawable.keypad_green);break; //盤差 case 6:textCell.setBackgroundResource(R.drawable.keypad_blue2);break; //應盤 case 7:textCell.setBackgroundResource(R.drawable.keypad_orange);break; //銷貨 } }else if(position>0 && i==0){ // int getCol=-6250336; if (textCell.getText().toString().equalsIgnoreCase("01")){}else{ getCol=ColorGetnumber(QpandnF.this,textCell.getText().toString()); } textCell.setBackgroundColor(getCol); } else { textCell.setBackgroundColor(-6250336); } addView(textCell, layoutParams); } this.setBackgroundColor(Color.BLACK); } } class Clickable implements OnClickListener{ private int mRow; private int mCell; Clickable(int row, int cell){ mRow = row; mCell = cell; } @Override public void onClick(View v) { int id = v.getId(); if(mRow>0 && mChoiceMode!= ChoiceMode.SERCH && nState!=2 ){ //非查詢,又是已過帳盤表,不可再盤點 int nCellKey = mCountRow.get(mRow); mColorno= mCountCell.get(nCellKey + 0); mySize= mCountCell.get(nCellKey + 2); aInput=goodO+"-"+mColorno+"-"+mySize; //未來應考慮 數字鍵盤呼叫 //showComputer(id); searched(); Toast.makeText(QpandnF.this, "點選的:"+aInput+" 暫盤累進"+mChoiceMode, Toast.LENGTH_SHORT).show(); RepData data = new RepData(); data.iPic=datas.iPic; data.iGoods=mLocDD; //櫃位 data.iName=datas.iName; data.iCountry=datas.iCountry; data.iNumber=datas.iNumber; //單價 data.iImpo=datas.iImpo; //應盤 data.iMoney="暫盤:"+nPin+"/已盤:"+nAadn; //本盤 data.iCompany="盤差:"+nAdefn+"/"+nAdefm;//盤差 data.iFormdate=datas.iFormdate; //盤點對象代號 mAdapter.mList.set(locations, data); mAdapter.notifyDataSetChanged(); mListView.setSelection(locations); }else{ Toast.makeText(QpandnF.this, "[查詢]或[已過帳的盤表]不可盤點哦!!", Toast.LENGTH_SHORT).show(); } } } private void zeroPin(String aGood,int aMode){ //aGood有值,表示單款歸零 //mode=0暫盤歸零 1盤點歸零 mLayoutRoot.removeAllViews(); File fileQmtrio = new File(mDBPath); SQLiteDatabase mdb = SQLiteDatabase.openOrCreateDatabase(fileQmtrio, null); StringBuffer mSQL = new StringBuffer(); Cursor csm; mSQL.append("select * from qpandn where USER='"+mWho+"' and PNDNADAY='"+Ddate+"'") .append(" and PNDNFKIND="+nDept +"" ); if (aMode>0 && aMode!=12) mSQL.append(" and ID>10"); else mSQL.append(" and ID>100000"); if (aGood.length()>0) mSQL.append(" and GOODSNO='"+aGood+"'"); csm=mdb.rawQuery(mSQL.toString(), null); if(csm.getCount()>0 ){ //唯一性的,可以進行比對 csm.moveToFirst(); for (int ii=0;ii100000) aID=aID-100000; }else if (aMode==1){ fieldB[4]="0"; //已盤歸零 if (aID>100000) aID=aID-100000; }else if (aMode==2){ //盤準 也只能計算給 暫盤 而不要直接轉入 已盤 fieldB[3]=""+(Utilis.toInt(fieldB[3])-Utilis.toInt(fieldB[5])); if (aID<100000) aID=aID+100000; }else if (aMode==12){//暫盤 轉入已盤 fieldB[4]=""+(Utilis.toInt(fieldB[4])+Utilis.toInt(fieldB[3])); fieldB[3]="0"; //暫盤歸零 if (aID>100000) aID=aID-100000; } fieldB[5]=""+(Utilis.toInt(fieldB[4])+Utilis.toInt(fieldB[3])-Utilis.toInt(fieldB[6])); nAdefn=Utilis.toInt(fieldB[5]); //盤差 nAdefm=nAdefn*(csm.getInt(csm.getColumnIndex("UNITPRICE"))*csm.getDouble(csm.getColumnIndex("DISCOUNT"))/100); tAdefn=tAdefn+nAdefn; tAdefm=tAdefm+nAdefm; tApann=tApann+Utilis.toInt(fieldB[4]); tApanm=tApanm+Utilis.toInt(fieldB[4])*(csm.getDouble(csm.getColumnIndex("UNITPRICE"))*csm.getDouble(csm.getColumnIndex("DISCOUNT"))/100); tApin=tApin+Utilis.toInt(fieldB[3]); for (int ik=0;ik<10;ik++) Cdata.append(fieldB[ik]+","); Cdata.append(fieldB[10]+","); } //副程式_要兜回DATA //也須維護 該商品的 盤差小計(金額) 已盤小計(金額) //存入PANDNF StringBuffer Bdata=new StringBuffer(); Bdata.append("update qpandn set DATA='"+Cdata.toString()+"',APIN="+tApin+",APANN="+tApann+",APANM="+tApanm+",ADEFN="+tAdefn+",ADEFM="+tAdefm+",CDT='"+DateUtil.getSystemTime().substring(2, 14)+"',ID="+aID); if (aMode==2) Bdata.append(",PNDNDD='"+mLocDD+"'"); Bdata.append(" where USER='"+mWho+"' and PNDNADAY='"+Ddate+"' and PNDNFKIND="+nDept+" and GOODSNO='"+bGood+"'"); mdb.execSQL(Bdata.toString()); if (aGood.length()>0){ //應是唯一的商品 RepData data = new RepData(); data.iPic=datas.iPic; data.iGoods=mLocDD; //櫃位 data.iName=datas.iName; data.iCountry=datas.iCountry; data.iNumber=datas.iNumber; data.iImpo=datas.iImpo; data.iMoney="暫盤:"+tApin+"/已盤:"+tApann; //本盤 data.iCompany="盤差:"+tAdefn+"/"+tAdefm;//盤差 data.iFormdate=datas.iFormdate; //盤點對象代號 mAdapter.mList.set(locations, data); } csm.moveToNext(); } if (aGood.length()<=0) getDetailData(QpandnF.this, mWho); //aState==1 有找到 暫盤表 mAdapter.notifyDataSetChanged(); //最後要維護 ID=3 盤表頭 mSQL.delete(0, mSQL.toString().length()); mSQL.append("select sum(APANN),sum(APANM),sum(ADEFN),sum(ADEFM),sum(APIN) from qpandn where USER='"+mWho+"' and PNDNADAY='"+Ddate+"'") .append(" and PNDNFKIND="+nDept +" and ID>10"); csm=mdb.rawQuery(mSQL.toString(), null); if(csm.getCount()>0 ){ //唯一性的,可以進行比對 csm.moveToFirst(); int qApann=csm.getInt(0); double qApanm=csm.getDouble(1); int qAdefn=csm.getInt(2); double qAdefm=csm.getDouble(3); int qPin=csm.getInt(4); mSQL.delete(0, mSQL.toString().length()); mSQL.append("update qpandn set APIN="+qPin+",APANN="+qApann+",APANM="+qApanm+",ADEFN="+qAdefn+",ADEFM="+qAdefm+",CDT='"+DateUtil.getSystemTime().substring(2, 14)+"'") .append(" where USER='"+mWho+"' and PNDNADAY='"+Ddate+"' and PNDNFKIND="+nDept+" and ID=3"); mdb.execSQL(mSQL.toString()); } } csm.close(); mdb.close(); } private String searched(){ //是否有2段式 先QPANDNF_及自家盤表 找不到 續找如果是自家門市,或總倉 //尋找QITEMS 建立初始盤表 並讓上存=0 //由table // aInput=goodO+"-"+mColorno+"-"+mySize; //@@@Keyin 時 ,有2個(-) 表示有輸入完整貨號,才會進入到 本程序 String Adata=""; File fileQmtrio = new File(mDBPath); SQLiteDatabase mdb = SQLiteDatabase.openOrCreateDatabase(fileQmtrio, null); StringBuffer mSQL = new StringBuffer(); Cursor csm; //@@@ID>10<10000表示總盤表 10000以上為暫盤表 //ID>8000<10000表示為補增資料 可以列式條件 //是否納入 已盤清冊 未盤清冊 盤差清冊 等多元查詢 mSQL.append("select * from qpandn where USER='"+mWho+"' and PNDNADAY='"+Ddate+"'") .append(" and PNDNFKIND="+nDept); mSQL.append(" and GOODSNO='"+goodO+"'"); csm=mdb.rawQuery(mSQL.toString(), null); if(csm.getCount()==1 ){ //唯一性的,可以進行比對 csm.moveToFirst(); int aID=csm.getInt(csm.getColumnIndex("ID")); if (aID<100000) aID=aID+100000; Adata=csm.getString(csm.getColumnIndex("DATA")); int Achk=-1; //[10]上存 [9]本進 [8]本出 [7]本銷 [6]應盤 [5]盤差 [4]已盤 [3]暫盤 [2]SIZE[1]COLOR_NAME[0]COLOR_NO String [] fieldA=Adata.split(","); //各色尺寸 String [] fieldB=fieldA[0].split(",");//首筆的欄位 for (int ij=0;ij=0){ if (mChoiceMode!= ChoiceMode.SERCH){ fieldB[3]=""+(Utilis.toInt(fieldB[3])+mChoiceMode);//暫盤 fieldB[5]=""+(Utilis.toInt(fieldB[5])+mChoiceMode); //盤差 //重組單一色尺寸欄位 Bdata.append(fieldB[0]); for (int ik=1;ik<11;ik++) Bdata.append(","+fieldB[ik]); fieldA[Achk]=Bdata.toString(); //重組DATA Bdata.delete(0, Bdata.toString().length()); //Bdata.append(fieldA[0]); for (int ij=0;ij0){ cs.moveToFirst(); Colname=cs.getString(1); } db.close(); cs.close(); return Colname; } private int ColorGetnumber(Context context,String key){ int number=0; SQLiteDatabase db = Utilis.getDB(context); Cursor cs = null; StringBuffer mySqlBuf = new StringBuffer(); mySqlBuf.append("select distinct NO,PIC from qc_color where NO='"+key+"'"); cs = db.rawQuery(mySqlBuf.toString(), null); if (cs.getCount()>0){ cs.moveToFirst(); number=cs.getInt(1); } db.close(); cs.close(); return number; } private double SaveinQQ(RepData datas,String WHO,int pMode){ double result=-1; String [] LIMITD=datas.iName.split("~"); SQLiteDatabase db = Utilis.getDB(QpandnF.this); Cursor cs=null; StringBuffer SQLb=new StringBuffer(); Cursor cursorx=null; File fileQmtrio = new File(mDBPath); SQLiteDatabase mdb = SQLiteDatabase.openOrCreateDatabase(fileQmtrio, null); SQLb.append("select GOODSNO,UNITPRICE,DISCOUNT,EXPRICE,DATA,CDT,ID from qpandn where USER='"+WHO+"' and PNDNFKIND="+nDept ); SQLb.append(" and PNDNADAY='"+LIMITD[1]+"' and CDT >'120314000000' and ID>10"); cursorx=mdb.rawQuery(SQLb.toString(),null); Toast.makeText(QpandnF.this, WHO+" TOOT_REC!! ="+cursorx.getCount(), Toast.LENGTH_SHORT).show(); if (cursorx.getCount()>0){ cursorx.moveToFirst(); double tMoney=0; double tCost=0; double tExtPrice=0; int tTot=0; String pKind="30312010"; switch (pMode){ case 0:pKind="31";break; //門市轉銷貨 case 1:pKind="20";break; //門市轉出退 case 2:pKind="30";break; //總倉轉銷貨 case 3:pKind="10";break; //總倉轉進退 } String msFno=Utilis.getIni(QpandnF.this,"SYS","DEPT",1)+Utilis.getIni(QpandnF.this,"SYS","DEPT",2)+pKind.substring(0,1)+Utilis.getCurrentYearFormat().substring(0, 1); String mFormno= getNFormno(msFno); for (int ii=0;ii0){ cs.moveToFirst(); String FIELDA []=cursorx.getString(4).split(","); for (int ij=0;ij0時 ContentValues value = new ContentValues(); value.put("TR",pKind); value.put("QKIND",pKind); value.put("ID",cursorx.getString(6)); //0正品 1實收價 value.put("DEPTNO",mWho); value.put("USER",mWho); value.put("USERNAME","盤銷單"); value.put("SUPPLY",cs.getString(cs.getColumnIndex("SUPPLY"))); value.put("FORMDATE",LIMITD[1]); value.put("FORMNO",mFormno); value.put("CREATEDATETIME",cursorx.getString(5)); value.put("ISCONFIRM","Y"); value.put("EMPID","PAN"); value.put("EMPNAME","盤點"); value.put("TRADETYPE",""+nTradetype); value.put("SOURCENO",cs.getString(cs.getColumnIndex("SOURCENO"))); value.put("GOODSNO",cs.getString(cs.getColumnIndex("GOODSNO"))); value.put("GOODSTYPE",cs.getString(cs.getColumnIndex("GOODSTYPE"))); value.put("GOODSNAME",cs.getString(cs.getColumnIndex("GOODSNAME"))); value.put("UNIT2", cs.getString(cs.getColumnIndex("UNIT2"))); if (pMode==3) value.put("UNIT10",Utilis.toInt(FIELDB[5])); else value.put("UNIT10",0); if (pMode==1) value.put("UNIT20",Utilis.toInt(FIELDB[5])); else value.put("UNIT20",0); if (pMode==0 || pMode==2) value.put("UNIT30",Utilis.toInt(FIELDB[5])*-1); else value.put("UNIT30",0); double aCost=0; double aMoney=0; if (pMode==0 || pMode==2){ aCost=Utilis.toInt(FIELDB[5])*-1*cs.getInt(cs.getColumnIndex("P1")); aMoney=Utilis.toInt(FIELDB[5])*-1*cursorx.getInt(1)*cursorx.getDouble(2)/100; tTot=tTot+Utilis.toInt(FIELDB[5])*-1; }else{ aCost=Utilis.toInt(FIELDB[5])*cs.getInt(cs.getColumnIndex("P1")); aMoney=Utilis.toInt(FIELDB[5])*cursorx.getInt(1)*cursorx.getDouble(2)/100; tTot=tTot+Utilis.toInt(FIELDB[5]); } value.put("UNIT40",0); value.put("P0",cs.getDouble(cs.getColumnIndex("P0"))); value.put("P1",cs.getDouble(cs.getColumnIndex("P1"))); value.put("P2",cs.getDouble(cs.getColumnIndex("P2"))); value.put("P3",cs.getDouble(cs.getColumnIndex("P3"))); value.put("P4",cs.getDouble(cs.getColumnIndex("P4"))); value.put("P5",cs.getDouble(cs.getColumnIndex("P5"))); value.put("ORDDATE",""); value.put("FINEDATE",""); value.put("RATE",cs.getDouble(cs.getColumnIndex("RATE"))); value.put("COLORS",cs.getString(cs.getColumnIndex("COLORS"))); value.put("SIZES",cs.getString(cs.getColumnIndex("SIZES"))); value.put("PIC",cs.getString(cs.getColumnIndex("PIC"))); value.put("SEASON",cs.getString(cs.getColumnIndex("SEASON"))); value.put("BATCH",cs.getString(cs.getColumnIndex("BATCH"))); value.put("COUNTRY",cs.getString(cs.getColumnIndex("COUNTRY"))); value.put("YEAR",cs.getString(cs.getColumnIndex("YEAR"))); tExtPrice=tExtPrice+cursorx.getDouble(3); value.put("GOODSNOS",cursorx.getString(0)+"-"+FIELDB[0]+"-"+FIELDB[2]); value.put("COLOR",FIELDB[0]); value.put("SIZE",FIELDB[2]); value.put("UNIT1", FIELDB[1]); value.put("RATEPRICE",0); value.put("UNITPRICE",cursorx.getString(1)); value.put("DISCOUNT",cursorx.getString(2) ); value.put("ACOST",aCost ); value.put("SUBPRICE",aMoney ); value.put("REALSUM",0); tMoney=tMoney+aMoney; tCost=tCost+aCost; result = db.insert(TbName.QITEMS, null, value); } } } cursorx.moveToNext(); } if ((tMoney!=0 || tCost!=0 || tTot!=0) && result>=0){ ContentValues value = new ContentValues(); value.put("TR",pKind); value.put("QKIND",pKind); value.put("ID",pKind); //0正品 1實收價 value.put("DEPTNO",mWho); value.put("USER",mWho); value.put("USERNAME","盤銷單"); value.put("FORMDATE",LIMITD[1]); value.put("FORMNO",mFormno); value.put("HANDNO","+"+tTot); value.put("CREATEDATETIME",DateUtil.getSystemTime().substring(2, 14)); value.put("ISCONFIRM","Y"); value.put("ISCHECK","N"); value.put("EMPID","PAN"); value.put("EMPNAME","盤點"); value.put("TRADETYPE",""+nTradetype); value.put("ATOT",tTot); value.put("ASUM",tMoney); value.put("BSUM",tMoney); value.put("COSTS",tCost); value.put("CASH",0); value.put("CARD",0); value.put("ORDCASH",0); value.put("ORDCARD",0); value.put("TURESUM",0); value.put("DISMONEY",tExtPrice); value.put("BANKNO","1"); value.put("BANKNAME",Utilis.getIni(QpandnF.this,"SYS","DEPT",1)+Utilis.getIni(QpandnF.this,"SYS","DEPT",2)); result = db.insert(TbName.QHEAD, null, value); //一旦完成 過帳 應將 盤表 PNDNSTATE=2 // if (result>=0){ Toast.makeText(QpandnF.this, mWho+" 盤點表已成功過帳!! ", Toast.LENGTH_SHORT).show(); //保留雲端的傳送,予以手動傳送 // } } if (pMode==1 || pMode==3) mdb.execSQL("update qpandn set PNDNSTATE='2',PARTSNO='"+mFormno+"' where USER='"+mWho+"' and PNDNFKIND="+nDept+" and PNDNADAY='"+LIMITD[1]+"'"); else mdb.execSQL("update qpandn set PNDNSTATE='2',DEPTSNO='"+mFormno+"' where USER='"+mWho+"' and PNDNFKIND="+nDept+" and PNDNADAY='"+LIMITD[1]+"'"); } db.close(); cs.close(); mdb.close(); cursorx.close(); return result; } private String getNFormno(String formf){ int flowNumber = 0; SQLiteDatabase db = Utilis.getDB(this); try{ Cursor cursor = db.rawQuery("select FORMNO from " + TbName.QHEAD + " where FORMNO like '"+formf+"%' order by FORMNO DESC limit 1", null); if(cursor != null){ try{ if(cursor.getCount() > 0){ cursor.moveToFirst(); flowNumber = Utilis.toInt(cursor.getString(cursor.getColumnIndex("FORMNO")).substring(formf.length()))+1; } }catch(Exception e){ e.printStackTrace(); } cursor.close(); }else{ //新的開始單號 flowNumber=1; } }catch(Exception e){ e.printStackTrace(); } if(db != null){ db.close(); } return formf+Utilis.formatFlow(flowNumber); } private String bufAdd(SQLiteDatabase db,Cursor cs,String buf){ //到時候需區隔 0總倉 1門市 2廠商 StringBuffer nBufB=new StringBuffer(); String sepaE=","; String sepa=","; int Aimn=cs.getInt(10); //取至(UNIT20) 當門市盤點時(混淆的是 門市的轉入轉出都合計了) int Astsn=cs.getInt(11)+cs.getInt(12); int Aadn=0; nAstn=nAstn+Astsn;//本銷UNIT30UNIT40 chkIn=0; if (nDept==0){//總倉(本進-本出-本銷) nAstk=nAstk+cs.getInt(9)-Aimn-Astsn; nAadn=nAadn+Aimn; nAimn=nAimn+cs.getInt(9); }else if (nDept==2){ //廠商較像門市(本進-本銷) nAstk=nAstk+cs.getInt(9)-Astsn; nAimn=nAimn+cs.getInt(9); nAadn=0; }else if (nDept==1){ //須先取得本進,門市(本進-本銷) Cursor csi = db.rawQuery("select sum(UNIT20) from qitems where GOODSNO='"+cs.getString(0)+"' and COLOR='"+cs.getString(1)+"' and SIZE='"+cs.getString(3)+"' and ISCONFIRM='Y' and DEPTNO='"+mWho+"' and QKIND='21' and FORMDATE>'"+Ldate+"' and FORMDATE<='"+Ddate+"'", null); //轉出的數據 需減2倍(因為cs是將進貨和轉貨都視為總合(UNIT20)) if (csi.getCount()>0){ // csi.moveToFirst(); //本進-本退-本銷 Aadn=csi.getInt(0); //實際門市退貨量 Aimn=Aimn-Aadn; //進退合計-退貨 nAadn=nAadn+Aadn; //本退 nAimn=nAimn+Aimn-Aadn; //本進 }else{ nAimn=nAimn+Aimn; //本進 } nAstk=nAstk+Aimn-Aadn-Astsn; csi.close(); } nAcost=cs.getInt(4);//成本P1 //總應盤 總盤差 if(buf.length()>0){ String [] fieldA=buf.split(sepaE); //各色尺寸 for (int ij=0;ij0){ //在盤表中存在,重組buf_data字串 buf=""; for (int ij=0;ij0){ //有盤差 valueI.put("ID",nID) ; }else{ //沒有盤差 50000-80000 int nnID=nID+50000; valueI.put("ID",nnID) ; } valueI.put("USER",mWho) ; valueI.put("USERNAME",((Button)findViewById(R.id.btn_pndnname)).getText().toString()) ; valueI.put("PNDNBDAY",Ldate) ; valueI.put("PNDNADAY",Ddate) ; valueI.put("GOODSNO",goodO) ; valueI.put("GOODSNAME",goodOName) ; valueI.put("PIC",goodOPic) ; valueI.put("UNITPRICE",nPrice) ; valueI.put("DISCOUNT",nDiscount) ; valueI.put("ACOST",nAcost) ; valueI.put("DATA",buf) ; valueI.put("DATA0","") ; valueI.put("PNDNDD","") ; valueI.put("DEPTSNO","") ; valueI.put("PARTSNO","") ; valueI.put("LASTSTKN",0) ; valueI.put("LASTSTKM",0) ; valueI.put("AINN",nAimn) ; valueI.put("AINM",(nAimn*nPrice/100*nDiscount)); valueI.put("ASTN",nAstn) ; valueI.put("ASTM",(nAstn*nPrice/100*nDiscount)); valueI.put("ASTKN",nAstk) ; //本存 if(nDept==0) { //總倉 廠商@@@ valueI.put("ASTKM",nAadn) ; //本出 }else{ //本存金額 valueI.put("ASTKM",(int)(nAstk*nPrice/100*nDiscount)); } valueI.put("APANN",0) ; //本盤 valueI.put("APANM",0) ; valueI.put("ADEFN",(nAstk*-1)) ; //盤差量 valueI.put("ADEFM",((nAstk*-1)*nPrice/100*nDiscount)) ; //盤差金 valueI.put("APIN",0) ; //暫盤 mdb.insert("qpandn", null, valueI); } else { //update 應該不是只有DATA欄位更新,而是如上欄位也要更新 StringBuffer SQLTXT=new StringBuffer(); SQLTXT.append("update qpandn set DATA='"+buf+"',") .append("AINN="+nAimn+",") .append("AINM="+(nAimn*nPrice/100*nDiscount)+",") .append("ASTN="+nAstn+",") .append("ASTM="+(nAstn*nPrice/100*nDiscount)+",") .append("ASTKN="+(nAstk+nLstk)+","); //還要加上存 if(nDept==0) { SQLTXT.append("ASTKM="+nAadn+",") ; //本出 本轉貨 }else{ //本存金額 SQLTXT.append("ASTKM="+((nAstk+nLstk)*nPrice/100*nDiscount)+","); } SQLTXT.append("ADEFN="+((nAstk+nLstk)*-1)+",") .append("ADEFM="+(((nAstk+nLstk)*-1)*nPrice/100*nDiscount)+",") //盤差量 盤差金 .append("APIN=0") .append(" where ID>10 and USER='"+mWho+"' and PNDNFKIND="+nDept+" and PNDNADAY='"+Ddate+"' and GOODSNO='"+goodO+"'"); mdb.execSQL(SQLTXT.toString()); } // }catch(Exception e){ // e.printStackTrace(); // }finally{ // mdb.endTransaction(); // } } }