package com.example.waoperations.Transference;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class TransferenceDataBaseHelper {

	 private static final int DATABASE_VERSION =4;
	 private static final String DATABASE_NAME = "WMSTransferenceBR.db";
     private static final String TABLE_NAME = "Transfer_TableBR";
     private static final String ID = "_id";
     private static final String ITEMID = "Articulo";
     private static final String ITEMBARCODE = "barcode";

     private ContactOpenHelper openHelper;
     private SQLiteDatabase database;

     public TransferenceDataBaseHelper(Context context) {
             openHelper = new ContactOpenHelper(context);
             database = openHelper.getWritableDatabase();
     }
     
     public void saveTransferenciasLine(String itemid,  String barcode )
     {
     	     ContentValues contentValues = new ContentValues();
     	     contentValues.put(ITEMID , itemid);
             contentValues.put(ITEMBARCODE, barcode);

             database.insert(TABLE_NAME, null, contentValues);
     }
 
 public void deleteAllData()
     {
     database.delete(TABLE_NAME, null, null);
     }
 
 public Cursor getAllTransferenciasLines() {
     return database.rawQuery(
     "SELECT * FROM " + TABLE_NAME+"", 
     null);
} 
 public Cursor getTransferenciasItemBarcode(String barcode) {
	 return database.rawQuery(
	       "SELECT * FROM " + TABLE_NAME+" WHERE " +ITEMBARCODE+ " ='"
	       +barcode+"'",
	       null);
	} 

public Cursor getItemByBarcode(String barcode) {
    String query= "SELECT * FROM "+TABLE_NAME+" where "+ ITEMBARCODE+"='"+barcode+"'";
    return database.rawQuery(query,null);
    }



     private class ContactOpenHelper extends SQLiteOpenHelper {

             public ContactOpenHelper(Context context) {
                     super(context, DATABASE_NAME, null, DATABASE_VERSION);
             }
             
             @Override
             public void onCreate(SQLiteDatabase database) {
                     database.execSQL("CREATE TABLE " + TABLE_NAME + "("
                                     + ID + " INTEGER PRIMARY KEY, "
                                     + ITEMID + " TEXT, "
                                     + ITEMBARCODE+ " TEXT)");        
             }
             
             @Override
             public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
                     database.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME + "");
                     onCreate(database);
             }

     }
	
	
	
	
	
	
	
	
}
