public ReceiptImage getReceiptWithPhotoname(String photoname) throws ParseException { Log.d("MyQuittiDatasource", "getReceiptWithPhotoname: " + photoname); ReceiptImage receipt = null; this.open(); Log.d("MyQuittiDatasource", "photoname: " + photoname); Cursor cursor = database.rawQuery("SELECT * FROM receiptinfo WHERE photoname = '" + photoname + "'", null); // Cursor cursor = database.query(MySQLiteHelper.TABLE_RECEIPTINFO, // allColumns, MySQLiteHelper.COLUMN_PHOTONAME + " LIKE " + photoname, null, null, null, // null); cursor.moveToFirst(); // Comment newComment = cursorToComment(cursor); // cursor.close(); if (cursor.getCount() > 0) { receipt = cursorToReceiptImage(cursor); receipt.setCategory(getCategory(receipt.getReceiptId())); } System.out.println("*********************"); // cursor.moveToNext(); // make sure to close the cursor cursor.close(); // and database connection this.close(); Log.d("MyQuittiDatasource", "getReceiptWithPhotoname End"); return receipt; }
/** * Returns a list of all receipts in phones memory @Sami Nurmi * * @return List * @throws ParseException */ public List<ReceiptImage> getAllReceipts() throws ParseException { System.out.println("**********getAllReceipts getAllReceipts ************"); List<ReceiptImage> receipts = new ArrayList<ReceiptImage>(); Cursor cursor = database.query(MySQLiteHelper.TABLE_RECEIPTINFO, allColumns, null, null, null, null, null); cursor.moveToFirst(); while (!cursor.isAfterLast()) { ReceiptImage receipt = cursorToReceiptImage(cursor); // Category category = this.getCategory(receipt.getReceiptId()); List<Category> categories = this.getAllCategories(receipt.getReceiptId()); System.out.println("RECEIPTID----->" + receipt.getReceiptId()); receipt.setCategories(categories); receipts.add(receipt); cursor.moveToNext(); } // make sure to close the cursor cursor.close(); return receipts; }
/** * Returns a list of all receipts in phones memory with specific category SELECT * receiptinfo.receiptId, receiptinfo.photoname,category.categorytext FROM receiptinfo,category * WHERE receiptinfo.receiptid=category.fk_category_receiptinfo and category.categorytext like * 'Business' @Sami Nurmi * * @return List * @throws ParseException */ public List<ReceiptImage> getAllReceipts(String category) throws ParseException { List<ReceiptImage> receipts = new ArrayList<ReceiptImage>(); Cursor cursor = database.query(MySQLiteHelper.TABLE_RECEIPTINFO, allColumns, null, null, null, null, null); cursor.moveToFirst(); while (!cursor.isAfterLast()) { ReceiptImage receipt = cursorToReceiptImage(cursor); receipt.setCategory(getCategory(receipt.getReceiptId())); receipts.add(receipt); cursor.moveToNext(); } // make sure to close the cursor cursor.close(); return receipts; }
public ReceiptImage createReceiptWithCategories( String rootDirectory, String directory, String Extrainfo, String photoName, String isChecked, String latitude, String longitude, String categories[]) throws ParseException { Log.d("createReceiptWithCategories", "--createReceiptWithCategories--"); Log.v("MyQuittiDataSource", "--categories LENGTH----->" + categories.length); ContentValues values = new ContentValues(); values.put(MySQLiteHelper.COLUMN_PHOTONAME, photoName); values.put(MySQLiteHelper.COLUMN_ROOTDIRECTORY, rootDirectory); values.put(MySQLiteHelper.COLUMN_DIRECTORY, directory); values.put(MySQLiteHelper.COLUMN_EXTRAINFO, Extrainfo); values.put(MySQLiteHelper.COLUMN_ISCHECKED, isChecked); values.put(MySQLiteHelper.COLUMN_LATITUDE, isChecked); values.put(MySQLiteHelper.COLUMN_LONGITUDE, isChecked); long insertId = database.insert(MySQLiteHelper.TABLE_RECEIPTINFO, null, values); System.out.println("insertIdinsertIdinsertIdinsertId--->" + insertId); Cursor cursor = database.query( MySQLiteHelper.TABLE_RECEIPTINFO, allColumns, MySQLiteHelper.COLUMN_RECEIPTID + " = " + insertId, null, null, null, null); cursor.moveToFirst(); ReceiptImage newReceipt = cursorToReceiptImage(cursor); cursor.close(); // TODO: This is stupid way, but we were hurry for (int i = 0; i < categories.length; i++) { this.addCategory(categories[i], newReceipt.getReceiptId()); } Log.v("MyQuittiDataSource", "--createReceipt--END"); return newReceipt; }
/** * Method for deleting the ReceiptImage @Sami Nurmi * * @param receipt */ public void deleteReceipt(ReceiptImage receipt) { long id = receipt.getReceiptId(); System.out.println("Receipt deleted with id: " + id); database.delete( MySQLiteHelper.TABLE_RECEIPTINFO, MySQLiteHelper.COLUMN_RECEIPTID + " = " + id, null); }