private Handler handler = new Handler() { public void handleMessage(Message msg) { if(msg.what == 0) { progressDialog.dismiss();
queryListCursor(""); setDataList(); mStoreInfo.notifyDataSetChanged(); } else if(msg.what == 1) { progressDialog.dismiss(); Toast.makeText(StoreInfoActivity.this, "데이타를 가져오는데 에러가 발생하였습니다.", Toast.LENGTH_SHORT).show(); } } }; private void getAllData() { progressDialog = ProgressDialog.show(this, "", "데이타를 가져오고 있습니다.", true, false); new Thread() { public void run() { if(copyExcelFileToDB() == true) { handler.sendEmptyMessage(0); } else { handler.sendEmptyMessage(1); } } }.start(); } private boolean copyExcelFileToDB() { Workbook workbook = null; Sheet sheet = null; boolean returnValue = true; try { InputStream is = getBaseContext().getResources().getAssets().open("1st.xls"); workbook = Workbook.getWorkbook(is); if(workbook != null) { sheet = workbook.getSheet(0); if(sheet != null) { int nMaxColumn = 6; int nRowStartIndex = 0; int nRowEndIndex = sheet.getColumn(nMaxColumn - 1).length - 1; int nColumnStartIndex = 0; int nColumnEndIndex = 5; for(int nRow = nRowStartIndex; nRow <= nRowEndIndex; nRow++) { //번호, 현상호명, 배출건수, 자동, 수동, 현소재지 String num = sheet.getCell(nColumnStartIndex, nRow).getContents(); String name = sheet.getCell(nColumnStartIndex + 1, nRow).getContents(); String total = sheet.getCell(nColumnStartIndex + 2, nRow).getContents(); String auto = sheet.getCell(nColumnStartIndex + 3, nRow).getContents(); String no_auto = sheet.getCell(nColumnStartIndex + 4, nRow).getContents(); String addr = sheet.getCell(nColumnStartIndex + 5, nRow).getContents(); ContentValues cv = new ContentValues(); cv.put(StoreDBHandler.STORE_KEY_NUM, num); cv.put(StoreDBHandler.STORE_KEY_NAME, name); cv.put(StoreDBHandler.STORE_KEY_TOTAL, total); cv.put(StoreDBHandler.STORE_KEY_AUTO, auto); cv.put(StoreDBHandler.STORE_KEY_NOAUTO, no_auto); cv.put(StoreDBHandler.STORE_KEY_ADDRESS, addr); mGetHandler.mDb.insert(DBHandler.KEY_STORESINFO_TABLE_NAME, null, cv); } } else { Log.e(TAG, "Sheet is null"); returnValue = false; } } else { Log.e(TAG, "Workbook is null"); returnValue = false; } } catch (Exception e) { e.printStackTrace(); returnValue = false; } finally { if(workbook != null) { workbook.close(); // mGetHandler.DBclose(); returnValue = true; } } return returnValue; } |