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 WarehouseBarcodeDataBaseHelper {
	
	   private static final int DATABASE_VERSION = 2;
       private static final String DATABASE_NAME = "WMSBarcode.db";
       private static final String TABLE_NAME = "WarehouseBarcode_Table";
       private static final String ID = "_id";
       private static final String INVENTLOCATIONID= "bodega";
       private static final String BARCODE = "barcode";
       private static final String DATAAREAID = "empresa";
       private ContactOpenHelper openHelper;
       private SQLiteDatabase database;

       public WarehouseBarcodeDataBaseHelper(Context context) {
               openHelper = new ContactOpenHelper(context);
               database = openHelper.getWritableDatabase();
       }
       
       public void saveWarehouseBarcode(String inventlocationid,String barcode,String dataareaid) {
       	    ContentValues contentValues = new ContentValues();
               contentValues.put(INVENTLOCATIONID, inventlocationid);
               contentValues.put(BARCODE, barcode);
               contentValues.put(DATAAREAID, dataareaid);
               database.insert(TABLE_NAME, null, contentValues);
       }
       public void deleteAllData()
       {
                database.delete(TABLE_NAME, null, null);
       }
       public Cursor getAllWarehouseBarcodeLines() {
               return database.rawQuery(
                            "SELECT * FROM " + TABLE_NAME+"", 
                            null);
       } 
       public Cursor getAllWarehouseBarcodeLines(String barcode) {
           return database.rawQuery(
                        "SELECT * FROM " + TABLE_NAME+" WHERE "+BARCODE+" ='"+barcode+"'", 
                        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, "
                                       + INVENTLOCATIONID + " TEXT, "
                                       + BARCODE + " TEXT, "
                                       + DATAAREAID + " TEXT)");
               } 
               @Override
               public void onUpgrade(SQLiteDatabase database, int oldVersion, int newVersion) {
                       database.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME + "");
                       onCreate(database);
               }

       }

	
	
	

}
