Saturday 5 April 2014

Databasedemo

1)Create DbHelper.java
=================
package com.abc.xyz;

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

public class DBHelper extends SQLiteOpenHelper{

public DBHelper(Context context) {
super(context, DBConstant.DB.DATABASENAME, null, DBConstant.DB.DB_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
String TABLE1 = String.format("CREATE TABLE %s (%s INTEGER(11)," +
"%s VARCHAR(30)," +
"%s INTEGER(11)," +
"%s VARCHAR(255)," +
"%s BIGINT(64)," +
"%s BIGINT(64)," +
"%s DATETIME," +
"%s DATETIME," +
"%s VARCHAR(10)," +
"%s TEXT," +
"%s TEXT," +
"%s INTEGER(11))", DBConstant.TABLE.CATEGORY_MASTER,
DBConstant.CATEGORY_MASTER.CATEGORY_ID,
DBConstant.CATEGORY_MASTER.CATEGORY_NAME,
DBConstant.CATEGORY_MASTER.PARENT_ID,
DBConstant.CATEGORY_MASTER.DESCRIPTION,
DBConstant.CATEGORY_MASTER.CREATED_BY,
DBConstant.CATEGORY_MASTER.UPDATED_BY,
DBConstant.CATEGORY_MASTER.CREATED_DT,
DBConstant.CATEGORY_MASTER.UPDATED_DT,
DBConstant.CATEGORY_MASTER.STATUS,
DBConstant.CATEGORY_MASTER.SELECT_IMG,
DBConstant.CATEGORY_MASTER.NORMAL_IMG,
DBConstant.CATEGORY_MASTER.SORTORDER);
Log.i(Constant.TAG,"TABLE1 = " + TABLE1.toString());
db.execSQL(TABLE1);

String TABLE2 = String.format("CREATE TABLE %s (%s BIGINT(64)," +
"%s BIGINT(64)," +
"%s TINYINT(1)," +
"%s BIGINT(64)," +
"%s VARCHAR(150)," +
"%s VARCHAR(150)," +
"%s INTEGER(11)," +
"%s TEXT," +
"%s DATETIME," +
"%s BIGINT(64)," +
"%s DATETIME," +
"%s BIGINT(64)," +
"%s CHARACTER(1))", DBConstant.TABLE.PARAMETER,
DBConstant.PARAMETER.PARA_ID,
DBConstant.PARAMETER.PARA_PARENT_ID,
DBConstant.PARAMETER.PARA_LEVEL,
DBConstant.PARAMETER.PARA_TYPE,
DBConstant.PARAMETER.PARA_VALUE,
DBConstant.PARAMETER.PARA_DESC,
DBConstant.PARAMETER.PARA_SORT_ORDER,
DBConstant.PARAMETER.PARA_TECH_DESC,
DBConstant.PARAMETER.CREATED_DT,
DBConstant.PARAMETER.CREATED_BY,
DBConstant.PARAMETER.UPDATED_DT,
DBConstant.PARAMETER.UPDATED_BY,
DBConstant.PARAMETER.STATUS);
Log.i(Constant.TAG,"TABLE2 = " + TABLE2.toString());
db.execSQL(TABLE2);


String TABLE3 = String.format("CREATE TABLE %s (%s INTEGER(11)," +
"%s INTEGER(11)," +
"%s VARCHAR(255)," +
"%s VARCHAR(255))", DBConstant.TABLE.PRODUCT_IMAGES,
DBConstant.PRODUCT_IMAGES.ID,
DBConstant.PRODUCT_IMAGES.PRODUCT_ID,
DBConstant.PRODUCT_IMAGES.NORMAL_IMG,
DBConstant.PRODUCT_IMAGES.SELECT_IMG);
Log.i(Constant.TAG,"TABLE3 = " + TABLE3.toString());
db.execSQL(TABLE3);


String TABLE4 = String.format("CREATE TABLE %s (%s BIGINT(32)," +
"%s VARCHAR(100)," +
"%s FLOAT(11,2)," +
"%s BIGINT(64)," +
"%s BIGINT(64)," +
"%s INTEGER(11)," +
"%s FLOAT(11,2)," +
"%s FLOAT(11,2)," +
"%s BIGINT(32)," +
"%s FLOAT(11,2)," +
"%s BIGINT(32)," +
"%s FLOAT(11,2)," +
"%s BIGINT(32)," +
"%s DATETIME," +
"%s BIGINT(64)," +
"%s DATETIME," +
"%s BIGINT(64)," +
"%s INTEGER(11))", DBConstant.TABLE.PRODUCT_MASTER,
DBConstant.PRODUCT_MASTER.PRODUCT_ID,
DBConstant.PRODUCT_MASTER.NAME,
DBConstant.PRODUCT_MASTER.PRICE,
DBConstant.PRODUCT_MASTER.PARA_STATUS_ID,
DBConstant.PRODUCT_MASTER.PARA_UNIT_ID,
DBConstant.PRODUCT_MASTER.CATEGORY_ID,
DBConstant.PRODUCT_MASTER.FACTORY_PRICE,
DBConstant.PRODUCT_MASTER.OPERATION_COST,
DBConstant.PRODUCT_MASTER.OPERATION_COST_IN,
DBConstant.PRODUCT_MASTER.COMPANY_MARGIN,
DBConstant.PRODUCT_MASTER.COMPANY_MARGIN_IN,
DBConstant.PRODUCT_MASTER.FRENCHIESE_MARGIN,
DBConstant.PRODUCT_MASTER.FRENCHIESE_MARGIN_IN,
DBConstant.PRODUCT_MASTER.CREATED_DT,
DBConstant.PRODUCT_MASTER.CREATED_BY,
DBConstant.PRODUCT_MASTER.UPDATED_DT,
DBConstant.PRODUCT_MASTER.UPDATED_BY,
DBConstant.PRODUCT_MASTER.SORTORDER);
Log.i(Constant.TAG,"TABLE4 = " + TABLE4.toString());
db.execSQL(TABLE4);

String TABLE5 = String.format("CREATE TABLE %s (%s BIGINT(32)," +
"%s BIGINT(32)," +
"%s BIGINT(32)," +
"%s FLOAT(11,2)," +
"%s FLOAT(11,2)," +
"%s BIGINT(32)," +
"%s FLOAT(11,2)," +
"%s BIGINT(32)," +
"%s FLOAT(11,2)," +
"%s BIGINT(32)," +
"%s FLOAT(11,2)," +
"%s FLOAT(11,2)," +
"%s FLOAT(11,2)," +
"%s FLOAT(11,2))", DBConstant.TABLE.PRODUCT_PRICE_DETAILS,
DBConstant.PRODUCT_PRICE_DETAILS.DETAILS_ID,
DBConstant.PRODUCT_PRICE_DETAILS.PRODUCT_ID,
DBConstant.PRODUCT_PRICE_DETAILS.PARA_WASTE_TYPE_ID,
DBConstant.PRODUCT_PRICE_DETAILS.FACTORY_PRICE,
DBConstant.PRODUCT_PRICE_DETAILS.OPERATION_COST,
DBConstant.PRODUCT_PRICE_DETAILS.OPERATION_COST_IN,
DBConstant.PRODUCT_PRICE_DETAILS.COMPANY_MARGIN,
DBConstant.PRODUCT_PRICE_DETAILS.COMPANY_MARGIN_IN,
DBConstant.PRODUCT_PRICE_DETAILS.FRENCHIESE_MARGIN,
DBConstant.PRODUCT_PRICE_DETAILS.FRENCHIESE_MARGIN_IN,
DBConstant.PRODUCT_PRICE_DETAILS.OPERATION_COST_AMT,
DBConstant.PRODUCT_PRICE_DETAILS.COMPANY_MARGIN_AMT,
DBConstant.PRODUCT_PRICE_DETAILS.FRENCHIESE_MARGIN_AMT,
DBConstant.PRODUCT_PRICE_DETAILS.PRICE);
Log.i(Constant.TAG,"TABLE5 = " + TABLE5.toString());
db.execSQL(TABLE5);

String TABLE6 = String.format("CREATE TABLE %s (%s BIGINT(32)," +
"%s BIGINT(32)," +
"%s VARCHAR(150)," +
"%s FLOAT(11,2)," +
"%s INTEGER(32)," +
"%s DATETIME," +
"%s BIGINT(64)," +
"%s DATETIME," +
"%s BIGINT(64))", DBConstant.TABLE.PRODUCT_QUALITY_PARAMETER,
DBConstant.PRODUCT_QUALITY_PARAMETER.PRODUCT_QUALITY_PARA_ID,
DBConstant.PRODUCT_QUALITY_PARAMETER.PRODUCT_ID,
DBConstant.PRODUCT_QUALITY_PARAMETER.PARAMETER_NAME,
DBConstant.PRODUCT_QUALITY_PARAMETER.PARA_RATE,
DBConstant.PRODUCT_QUALITY_PARAMETER.PARA_RATE_IN,
DBConstant.PRODUCT_QUALITY_PARAMETER.CREATED_DT,
DBConstant.PRODUCT_QUALITY_PARAMETER.CREATED_BY,
DBConstant.PRODUCT_QUALITY_PARAMETER.UPDATED_DT,
DBConstant.PRODUCT_QUALITY_PARAMETER.UPDATED_BY);
Log.i(Constant.TAG,"TABLE6 = " + TABLE6.toString());
db.execSQL(TABLE6);

String TABLE7 = String.format("CREATE TABLE %s (%s INTEGER primary key autoincrement," +
"%s BIGINT(32)," +
"%s BIGINT(32)," +
"%s BIGINT(32)," +
"%s BIGINT(32)," +
"%s TEXT," +
"%s FLOAT(11,2)," +
"%s FLOAT(11,2)," +
"%s FLOAT(11,2)," +
"%s TEXT," +
"%s BIGINT(32))", DBConstant.TABLE.COLLECTION,
DBConstant.COLLECTION.COLLECTION_ID,
DBConstant.COLLECTION.APPOINTMENT_ID,
DBConstant.COLLECTION.CATEGORY_ID,
DBConstant.COLLECTION.PRODUCT_ID,
DBConstant.COLLECTION.PRODUCT_QUALITY_PARA_ID,
DBConstant.COLLECTION.PARA_VALUE,
DBConstant.COLLECTION.QUANTITY,
DBConstant.COLLECTION.RATE,
DBConstant.COLLECTION.TOTAL,
DBConstant.COLLECTION.CATEGORY_PRODUCT_PARAMETER,
DBConstant.COLLECTION.USERID);
Log.i(Constant.TAG,"TABLE7 = " + TABLE7.toString());
db.execSQL(TABLE7);


/*String TABLE8 = String.format("CREATE TABLE %S (%S INTEGER primary key autoincrement,"+
, args)

APPOINTMENT_ID="appointment_id";
APP_DATE_TIME="app_date_time";
CUSTOMER_ID="customer_id";
CUSTOMER_NAME="customer_name";
CUSTOMR_CODE="customr_code";
ADDRESS1="address1";
ADDRESS2="address2";
CITY="city";
STATE="state";
COUNTRY="country";
ZIPCODE="zipcode";
MOBILE_NO="mobile_no";
LANDMARK="landmark";
PRICE_GROUP="price_group";
LATTITUDE="lattitude";
LONGITUDE="longitude";
VAT_VALUE="VAT_VALUE";
VAT="vat";*/

String TABLE8 = String.format("CREATE TABLE %S (" +
"%S INTEGER primary key autoincrement,"+
"%s VARCHAR(10)," + //appoinment Id y
"%s VARCHAR(10)," + //cust_id y
"%s DATETIME," + //app_date_time y
"%s VARCHAR(50)," + //customer_name y
"%s VARCHAR(35)," + //customer_code y
"%s VARCHAR(100)," + //address1 y
"%s VARCHAR(100)," + //address2 y
"%s VARCHAR(30)," + //city y
"%s VARCHAR(25)," + //state y
"%s VARCHAR(15)," + //country y
"%s VARCHAR(6)," + //zipcode y
"%s VARCHAR(10)," + //mobile_no
"%s VARCAHR(200),"+ //landmark
"%s VARCHAR(12)," + //price_group y
"%s VARCHAR(12)," + //longitute y
"%s VARCHAR(12)," + //latitute y
"%s VARCHAR(12)," + //VAT_VALUE
"%s VARCHAR(3)," +
"%s VARCHAR(2)," + //vat y
"%s VARCHAR(10),"+
"%s DATETIME)"
,DBConstant.TABLE.PENDING_LEADS,
DBConstant.PENDING_LEADS.PENDINGLEAD_ID,
DBConstant.PENDING_LEADS.APPOINTMENT_ID,
DBConstant.PENDING_LEADS.CUSTOMER_ID,
DBConstant.PENDING_LEADS.APP_DATE_TIME,
DBConstant.PENDING_LEADS.CUSTOMER_NAME,
DBConstant.PENDING_LEADS.CUSTOMR_CODE,
DBConstant.PENDING_LEADS.ADDRESS1,
DBConstant.PENDING_LEADS.ADDRESS2,
DBConstant.PENDING_LEADS.CITY,
DBConstant.PENDING_LEADS.STATE,
DBConstant.PENDING_LEADS.COUNTRY,
DBConstant.PENDING_LEADS.ZIPCODE,
DBConstant.PENDING_LEADS.MOBILE_NO,
DBConstant.PENDING_LEADS.LANDMARK,
DBConstant.PENDING_LEADS.PRICE_GROUP,
DBConstant.PENDING_LEADS.LONGITUDE,
DBConstant.PENDING_LEADS.LATTITUDE,
DBConstant.PENDING_LEADS.VAT_VALUE,
DBConstant.PENDING_LEADS.VAT,
DBConstant.PENDING_LEADS.FLAG,
DBConstant.PENDING_LEADS.USERID,
DBConstant.PENDING_LEADS.COLLECTION_DT);

Log.i(Constant.TAG,"TABLE8 = " + TABLE8.toString());

String TABLE9 = String.format("CREATE TABLE %s (%s INTEGER," +
"%s DATETIME," +
"%s FLOAT(11,2)," +
"%s FLOAT(11,2)," +
"%s BIGINT(32))", DBConstant.TABLE.CASH_TRANSACTION,
DBConstant.CASH_TRANSACTION.CT_ID,
DBConstant.CASH_TRANSACTION.DATE,
DBConstant.CASH_TRANSACTION.CASH_GIVEN,
DBConstant.CASH_TRANSACTION.CASH_RECEIVE,
DBConstant.CASH_TRANSACTION.USERID);
Log.i(Constant.TAG,"TABLE9 = " + TABLE9.toString());
db.execSQL(TABLE9);

db.execSQL(TABLE8);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if(newVersion > oldVersion){
Log.i(Constant.TAG,"New Version Greater than Old Version.");

       db.execSQL("DROP TABLE IF EXISTS "+ DBConstant.TABLE.CATEGORY_MASTER);
       db.execSQL("DROP TABLE IF EXISTS "+ DBConstant.TABLE.PARAMETER);
       db.execSQL("DROP TABLE IF EXISTS "+ DBConstant.TABLE.PRODUCT_IMAGES);
     
       db.execSQL("DROP TABLE IF EXISTS "+ DBConstant.TABLE.PRODUCT_MASTER);
       db.execSQL("DROP TABLE IF EXISTS "+ DBConstant.TABLE.PRODUCT_PRICE_DETAILS);
       db.execSQL("DROP TABLE IF EXISTS "+ DBConstant.TABLE.PRODUCT_QUALITY_PARAMETER);
       db.execSQL("DROP TABLE IF EXISTS "+ DBConstant.TABLE.COLLECTION);
     
       onCreate(db);
}
}


//Insert into CATEGORY_MASTER Table
public void Insert_CATEGORY_MASTER(SQLiteDatabase db,String category_id,String category_name,String parent_id,String description,String created_by,String updated_by,String created_dt,String updated_dt,String status,String select_img,String normal_img,String sortorder){
ContentValues cv = new ContentValues();
    cv.put(DBConstant.CATEGORY_MASTER.CATEGORY_ID,category_id);    
    cv.put(DBConstant.CATEGORY_MASTER.CATEGORY_NAME,category_name);
    cv.put(DBConstant.CATEGORY_MASTER.PARENT_ID,parent_id);    
    cv.put(DBConstant.CATEGORY_MASTER.DESCRIPTION,description);
    cv.put(DBConstant.CATEGORY_MASTER.CREATED_BY,created_by);    
    cv.put(DBConstant.CATEGORY_MASTER.UPDATED_BY,updated_by);
    cv.put(DBConstant.CATEGORY_MASTER.CREATED_DT,created_dt);    
    cv.put(DBConstant.CATEGORY_MASTER.UPDATED_DT,updated_dt);
    cv.put(DBConstant.CATEGORY_MASTER.STATUS,status);    
    cv.put(DBConstant.CATEGORY_MASTER.SELECT_IMG,select_img);    
    cv.put(DBConstant.CATEGORY_MASTER.NORMAL_IMG,normal_img);
    cv.put(DBConstant.CATEGORY_MASTER.SORTORDER,sortorder);
    db.insert(DBConstant.TABLE.CATEGORY_MASTER, null,cv);
}

//Insert into PARAMETER Table
public void Insert_PARAMETER(SQLiteDatabase db,String para_id,String para_parent_id,String para_level,String para_type,String para_value,String para_desc,String para_sort_order,String para_tech_desc,String created_dt,String created_by,String updated_dt,String updated_by,String status){
ContentValues cv = new ContentValues();
    cv.put(DBConstant.PARAMETER.PARA_ID,para_id);    
    cv.put(DBConstant.PARAMETER.PARA_PARENT_ID,para_parent_id);
    cv.put(DBConstant.PARAMETER.PARA_LEVEL,para_level);
    cv.put(DBConstant.PARAMETER.PARA_TYPE,para_type);    
    cv.put(DBConstant.PARAMETER.PARA_VALUE,para_value);
    cv.put(DBConstant.PARAMETER.PARA_DESC,para_desc);
    cv.put(DBConstant.PARAMETER.PARA_SORT_ORDER,para_sort_order);    
    cv.put(DBConstant.PARAMETER.PARA_TECH_DESC,para_tech_desc);
    cv.put(DBConstant.PARAMETER.CREATED_DT,created_by);    
    cv.put(DBConstant.PARAMETER.CREATED_BY,updated_by);
    cv.put(DBConstant.PARAMETER.UPDATED_DT,created_dt);    
    cv.put(DBConstant.PARAMETER.UPDATED_BY,updated_dt);
    cv.put(DBConstant.PARAMETER.STATUS,status);
    db.insert(DBConstant.TABLE.PARAMETER, null,cv);
}

//Insert into PRODUCT_IMAGES Table
public void Insert_PRODUCT_IMAGES(SQLiteDatabase db,String id,String product_id,String normal_img,String select_img){
ContentValues cv = new ContentValues();
    cv.put(DBConstant.PRODUCT_IMAGES.ID,id);    
    cv.put(DBConstant.PRODUCT_IMAGES.PRODUCT_ID,product_id);
    cv.put(DBConstant.PRODUCT_IMAGES.NORMAL_IMG,normal_img);    
    cv.put(DBConstant.PRODUCT_IMAGES.SELECT_IMG,select_img);
    db.insert(DBConstant.TABLE.PRODUCT_IMAGES, null,cv);
}

//Insert into PRODUCT_MASTER Table
public void Insert_PRODUCT_MASTER(SQLiteDatabase db,String product_id,String name,String price,String para_status_id,String para_unit_id,String category_id,String factory_price,String operation_cost,String operation_cost_in,String company_margin,String company_margin_in,String frenchiese_margin,String frenchiese_margin_in,String created_dt,String created_by,String updated_dt,String updated_by,String sortorder){
ContentValues cv = new ContentValues();
    cv.put(DBConstant.PRODUCT_MASTER.PRODUCT_ID,product_id);    
    cv.put(DBConstant.PRODUCT_MASTER.NAME,name);
    cv.put(DBConstant.PRODUCT_MASTER.PRICE,price);    
    cv.put(DBConstant.PRODUCT_MASTER.PARA_STATUS_ID,para_status_id);
    cv.put(DBConstant.PRODUCT_MASTER.PARA_UNIT_ID,para_unit_id);
    cv.put(DBConstant.PRODUCT_MASTER.CATEGORY_ID,category_id);
    cv.put(DBConstant.PRODUCT_MASTER.FACTORY_PRICE,factory_price);
    cv.put(DBConstant.PRODUCT_MASTER.OPERATION_COST,operation_cost);
    cv.put(DBConstant.PRODUCT_MASTER.OPERATION_COST_IN,operation_cost_in);
    cv.put(DBConstant.PRODUCT_MASTER.COMPANY_MARGIN,company_margin);
    cv.put(DBConstant.PRODUCT_MASTER.COMPANY_MARGIN_IN,company_margin_in);
    cv.put(DBConstant.PRODUCT_MASTER.FRENCHIESE_MARGIN,frenchiese_margin);
    cv.put(DBConstant.PRODUCT_MASTER.FRENCHIESE_MARGIN_IN,frenchiese_margin_in);
    cv.put(DBConstant.PRODUCT_MASTER.CREATED_DT,created_dt);    
    cv.put(DBConstant.PRODUCT_MASTER.CREATED_BY,created_by);
    cv.put(DBConstant.PRODUCT_MASTER.UPDATED_DT,updated_dt);    
    cv.put(DBConstant.PRODUCT_MASTER.UPDATED_BY,updated_by);
    cv.put(DBConstant.PRODUCT_MASTER.SORTORDER,sortorder);
    db.insert(DBConstant.TABLE.PRODUCT_MASTER, null,cv);
}

//Insert into PRODUCT_PRICE_DETAILS Table
public void Insert_PRODUCT_PRICE_DETAILS(SQLiteDatabase db,String details_id,String product_id,String para_waste_type_id,String factory_price,String operation_cost,String operation_cost_in,String company_margin,String company_margin_in,String frenchiese_margin,String frenchiese_margin_in,String operation_cost_amt,String company_margin_amt,String frenchiese_margin_amt,String price){
ContentValues cv = new ContentValues();
    cv.put(DBConstant.PRODUCT_PRICE_DETAILS.DETAILS_ID,details_id);    
    cv.put(DBConstant.PRODUCT_PRICE_DETAILS.PRODUCT_ID,product_id);
    cv.put(DBConstant.PRODUCT_PRICE_DETAILS.PARA_WASTE_TYPE_ID,para_waste_type_id);    
    cv.put(DBConstant.PRODUCT_PRICE_DETAILS.FACTORY_PRICE,factory_price);
    cv.put(DBConstant.PRODUCT_PRICE_DETAILS.OPERATION_COST,operation_cost);    
    cv.put(DBConstant.PRODUCT_PRICE_DETAILS.OPERATION_COST_IN,operation_cost_in);
    cv.put(DBConstant.PRODUCT_PRICE_DETAILS.COMPANY_MARGIN,company_margin);    
    cv.put(DBConstant.PRODUCT_PRICE_DETAILS.COMPANY_MARGIN_IN,company_margin_in);
        cv.put(DBConstant.PRODUCT_PRICE_DETAILS.FRENCHIESE_MARGIN,frenchiese_margin);
        cv.put(DBConstant.PRODUCT_PRICE_DETAILS.FRENCHIESE_MARGIN_IN,frenchiese_margin_in);
        cv.put(DBConstant.PRODUCT_PRICE_DETAILS.OPERATION_COST_AMT,operation_cost_amt);
        cv.put(DBConstant.PRODUCT_PRICE_DETAILS.COMPANY_MARGIN_AMT,company_margin_amt);
        cv.put(DBConstant.PRODUCT_PRICE_DETAILS.FRENCHIESE_MARGIN_AMT,frenchiese_margin_amt);
        cv.put(DBConstant.PRODUCT_PRICE_DETAILS.PRICE,price);
    db.insert(DBConstant.TABLE.PRODUCT_PRICE_DETAILS, null,cv);
}

//Insert into PRODUCT_QUALITY_PARAMETER Table
public void Insert_PRODUCT_QUALITY_PARAMETER(SQLiteDatabase db,String product_quality_para_id,String product_id,String parameter_name,String para_rate,String para_rate_in,String created_dt,String created_by,String updated_dt,String updated_by){
ContentValues cv = new ContentValues();
    cv.put(DBConstant.PRODUCT_QUALITY_PARAMETER.PRODUCT_QUALITY_PARA_ID,product_quality_para_id);    
    cv.put(DBConstant.PRODUCT_QUALITY_PARAMETER.PRODUCT_ID,product_id);
    cv.put(DBConstant.PRODUCT_QUALITY_PARAMETER.PARAMETER_NAME,parameter_name);    
    cv.put(DBConstant.PRODUCT_QUALITY_PARAMETER.PARA_RATE,para_rate);  
    cv.put(DBConstant.PRODUCT_QUALITY_PARAMETER.PARA_RATE_IN,para_rate_in);  
    cv.put(DBConstant.PRODUCT_QUALITY_PARAMETER.CREATED_DT,created_dt);  
    cv.put(DBConstant.PRODUCT_QUALITY_PARAMETER.CREATED_BY,created_by);  
    cv.put(DBConstant.PRODUCT_QUALITY_PARAMETER.UPDATED_DT,updated_dt);  
        cv.put(DBConstant.PRODUCT_QUALITY_PARAMETER.UPDATED_BY,updated_by);  
    db.insert(DBConstant.TABLE.PRODUCT_QUALITY_PARAMETER, null,cv);
}

//Insert into COLLECTION Table
public void Insert_COLLECTION(SQLiteDatabase db,String appointment_id,String category_id,String product_id,String product_quality_para_id,String para_value,Float quantity,Float rate,Float total,String category_product_parameter,String userid){
ContentValues cv = new ContentValues();
    cv.put(DBConstant.COLLECTION.APPOINTMENT_ID,appointment_id);    
    cv.put(DBConstant.COLLECTION.CATEGORY_ID,category_id);
    cv.put(DBConstant.COLLECTION.PRODUCT_ID,product_id);    
    cv.put(DBConstant.COLLECTION.PRODUCT_QUALITY_PARA_ID,product_quality_para_id);  
    cv.put(DBConstant.COLLECTION.PARA_VALUE,para_value);  
    cv.put(DBConstant.COLLECTION.QUANTITY,quantity);  
    cv.put(DBConstant.COLLECTION.RATE,rate);  
    cv.put(DBConstant.COLLECTION.TOTAL,total);  
    cv.put(DBConstant.COLLECTION.CATEGORY_PRODUCT_PARAMETER,category_product_parameter);  
        cv.put(DBConstant.COLLECTION.USERID,userid);
    db.insert(DBConstant.TABLE.COLLECTION, null,cv);
}

//Insert into PENDING_LEAD Table
public void Insert_PendingLead(SQLiteDatabase db, String appoinment_id, String app_date_time, String custome_id,
String customer_name, String customre_code,String address1, String address2, String city, String state,
String country, String zipcode, String mobile_no, String landmark, String price_group, String latitude,
String longitude, String vat_value, String vat,String UID){
ContentValues cv = new ContentValues();
cv.put(DBConstant.PENDING_LEADS.APPOINTMENT_ID, appoinment_id);
cv.put(DBConstant.PENDING_LEADS.APP_DATE_TIME, app_date_time);
cv.put(DBConstant.PENDING_LEADS.CUSTOMER_ID, custome_id);
cv.put(DBConstant.PENDING_LEADS.CUSTOMER_NAME, customer_name);
cv.put(DBConstant.PENDING_LEADS.CUSTOMR_CODE, customre_code);
cv.put(DBConstant.PENDING_LEADS.ADDRESS1, address1);
cv.put(DBConstant.PENDING_LEADS.ADDRESS2, address2);
cv.put(DBConstant.PENDING_LEADS.CITY, city);
cv.put(DBConstant.PENDING_LEADS.STATE, state);
cv.put(DBConstant.PENDING_LEADS.COUNTRY, country);
cv.put(DBConstant.PENDING_LEADS.ZIPCODE, zipcode);
cv.put(DBConstant.PENDING_LEADS.MOBILE_NO, mobile_no);
cv.put(DBConstant.PENDING_LEADS.LANDMARK, landmark);
cv.put(DBConstant.PENDING_LEADS.PRICE_GROUP, price_group);
cv.put(DBConstant.PENDING_LEADS.LATTITUDE, latitude);
cv.put(DBConstant.PENDING_LEADS.LONGITUDE, longitude);
cv.put(DBConstant.PENDING_LEADS.VAT_VALUE, vat_value);
cv.put(DBConstant.PENDING_LEADS.VAT, vat);
cv.put(DBConstant.PENDING_LEADS.FLAG, "0");
cv.put(DBConstant.PENDING_LEADS.USERID, UID);

/*cv.put(DBConstant.PENDING_LEADS.APPOINTMENT_ID, "1001");
cv.put(DBConstant.PENDING_LEADS.APP_DATE_TIME, "31-12-2012");
cv.put(DBConstant.PENDING_LEADS.CUSTOMER_ID, "1012");
cv.put(DBConstant.PENDING_LEADS.CUSTOMER_NAME, "Test Cust");
cv.put(DBConstant.PENDING_LEADS.CUSTOMR_CODE, "Cust-2012");
cv.put(DBConstant.PENDING_LEADS.ADDRESS1, "Vrundavan Society");
cv.put(DBConstant.PENDING_LEADS.ADDRESS2, "Jamnagar-Rajkot");
cv.put(DBConstant.PENDING_LEADS.CITY, "Dhrol");
cv.put(DBConstant.PENDING_LEADS.STATE, "Gujarat");
cv.put(DBConstant.PENDING_LEADS.COUNTRY, "India");
cv.put(DBConstant.PENDING_LEADS.ZIPCODE, "361210");
cv.put(DBConstant.PENDING_LEADS.MOBILE_NO, "9998576657");
cv.put(DBConstant.PENDING_LEADS.LANDMARK, "St Bus Stand");
cv.put(DBConstant.PENDING_LEADS.PRICE_GROUP, "12001");
cv.put(DBConstant.PENDING_LEADS.LATTITUDE, "72.426451245");
cv.put(DBConstant.PENDING_LEADS.LONGITUDE, "73.7545825");
cv.put(DBConstant.PENDING_LEADS.VAT_VALUE, "5");
cv.put(DBConstant.PENDING_LEADS.VAT, "12");*/
db.insert(DBConstant.TABLE.PENDING_LEADS, null, cv);
}

//Insert into CASH_TRANSACTION Table
public void Insert_CASH_TRANSACTION(SQLiteDatabase db,String ct_id,String date,Float cash_given,Float cash_receive,String userid){
ContentValues cv = new ContentValues();
    cv.put(DBConstant.CASH_TRANSACTION.CT_ID,ct_id);    
    cv.put(DBConstant.CASH_TRANSACTION.DATE,date);
    cv.put(DBConstant.CASH_TRANSACTION.CASH_GIVEN,cash_given);    
    cv.put(DBConstant.CASH_TRANSACTION.CASH_RECEIVE,cash_receive);    
        cv.put(DBConstant.CASH_TRANSACTION.USERID,userid);
    db.insert(DBConstant.TABLE.CASH_TRANSACTION, null,cv);
}

//DELETE FROM PENDING_LEADS where flag !=1 AND appointment_id NOT IN (Select DISTINCT appointment_id from collection)
public void DELETE_PENDING_LEADS(SQLiteDatabase db){
// String whereCause = String.format("DELETE FROM %s where flag !=1 AND %s NOT IN (SELECT %s FROM %s)",
// DBConstant.TABLE.PENDING_LEADS,DBConstant.PENDING_LEADS.APPOINTMENT_ID,DBConstant.COLLECTION.APPOINTMENT_ID,DBConstant.TABLE.COLLECTION);
String whereCause =String.format("flag =0  AND %s NOT IN (Select DISTINCT %s from %s)",DBConstant.PENDING_LEADS.APPOINTMENT_ID,DBConstant.COLLECTION.APPOINTMENT_ID,DBConstant.TABLE.COLLECTION);
Log.i("WhereCause :- ", whereCause);
db.delete(DBConstant.TABLE.PENDING_LEADS, whereCause, null);
// Cursor c = db.rawQuery(whereCause, null);
// db.delete(DBConstant.TABLE.CATEGORY_MASTER, null, null);
}

//Delete CATEGORY_MASTER Table
public void Delete_CATEGORY_MASTER(SQLiteDatabase db){
db.delete(DBConstant.TABLE.CATEGORY_MASTER, null, null);
}

//Delete into PARAMETER Table
public void Delete_PARAMETER(SQLiteDatabase db){
db.delete(DBConstant.TABLE.PARAMETER, null, null);
}
//Delete into PRODUCT_IMAGES Table
public void Delete_PRODUCT_IMAGES(SQLiteDatabase db){
db.delete(DBConstant.TABLE.PRODUCT_IMAGES, null, null);
}
//Delete into PRODUCT_MASTER Table
public void Delete_PRODUCT_MASTER(SQLiteDatabase db){
db.delete(DBConstant.TABLE.PRODUCT_MASTER, null, null);
}
//Delete into PRODUCT_PRICE_DETAILS Table
public void Delete_PRODUCT_PRICE_DETAILS(SQLiteDatabase db){
db.delete(DBConstant.TABLE.PRODUCT_PRICE_DETAILS, null, null);
}
//Delete into PRODUCT_QUALITY_PARAMETER Table
public void Delete_PRODUCT_QUALITY_PARAMETER(SQLiteDatabase db){
db.delete(DBConstant.TABLE.PRODUCT_QUALITY_PARAMETER, null, null);
}

//Delete into CASH_TRANSACTION Table
public void Delete_CASH_TRANSACTION(SQLiteDatabase db){
db.delete(DBConstant.TABLE.CASH_TRANSACTION, null, null);
}

//Delete into COLLECTION Table
public void Delete_COLLECTION(SQLiteDatabase db,String appointment_id,String userid){
String WHERE=String.format("%s = %s AND %s = %s",DBConstant.COLLECTION.APPOINTMENT_ID,appointment_id,DBConstant.COLLECTION.USERID,userid);
db.delete(DBConstant.TABLE.COLLECTION, WHERE, null);
}

//Delete into PENDING_LEADS By Appointment_IDs Table
public void Delete_PENDING_LEADS_By_Appointment_ID(SQLiteDatabase db,String appointment_id,String userid){
String WHERE=String.format("%s = %s AND %s = %s",DBConstant.COLLECTION.APPOINTMENT_ID,appointment_id,DBConstant.COLLECTION.USERID,userid);
db.delete(DBConstant.TABLE.PENDING_LEADS, WHERE, null);
}

//Delete into COLLECTION Table Record By collection_id
public void DELETE_COLLECTION_BY_COLLECTION_ID(SQLiteDatabase db,String collection_id,String User_id){
String WHERE=String.format("%s = %s AND %s = %s",DBConstant.COLLECTION.COLLECTION_ID,collection_id,DBConstant.COLLECTION.USERID,User_id);
db.delete(DBConstant.TABLE.COLLECTION, WHERE, null);
}

//Update into CASH_TRANSACTION Table
public void Update_CASH_TRANSACTION(SQLiteDatabase db,String ct_id,Float cash_receive,String userid){
String WHERE=String.format("%s = %s AND %s = %s",DBConstant.CASH_TRANSACTION.CT_ID,ct_id,DBConstant.CASH_TRANSACTION.USERID,userid);
ContentValues cv = new ContentValues();
    cv.put(DBConstant.CASH_TRANSACTION.CASH_RECEIVE,cash_receive);    
    db.update(DBConstant.TABLE.CASH_TRANSACTION,cv, WHERE,null);
}

//Delete Pending_Leads
// public void Delete_PENDING_LEADS(SQLiteDatabase db,String User_id){
// String whereCause = String.format("%s = %s", DBConstant.PENDING_LEADS.USERID,User_id);
// db.delete(DBConstant.TABLE.PENDING_LEADS, whereCause, null);
// }

//Select_CATEGORY_MASTER table
public Cursor Select_CATEGORY_MASTER(SQLiteDatabase db){
return  db.query(DBConstant.TABLE.CATEGORY_MASTER,null, String.format("%s = '%s'",DBConstant.CATEGORY_MASTER.STATUS, DBConstant.CATEGORY_MASTER.ACTIVE).toString(), null, null, null, DBConstant.CATEGORY_MASTER.SORTORDER);
}

//Select_PRODUCT_PRICE use Price Group
public Cursor Select_PRODUCT_PRICE(SQLiteDatabase db,String product_id,String price_group){
String SQL=String.format("SELECT product_master.name, product_master.para_status_id, product_master.para_unit_id, product_price_details.price FROM product_price_details LEFT JOIN product_master ON product_price_details.product_id = product_master.product_id WHERE product_master.product_id = %s and product_price_details.para_waste_type_id = %s", product_id,price_group);
return db.rawQuery(SQL,null);
}

//Select_PRODUCT_RETAILER_PRICE use Retailer Price Group
public Cursor Select_PRODUCT_RETAILER_PRICE(SQLiteDatabase db,String retailerprice_group_id,String category_id){
String SQL=String.format("select product_images.normal_img as image,product_price_details.price as price,parameter.para_value as unit, product_master.name as name,product_price_details.product_id as id,product_quality_parameter.parameter_name FROM product_master LEFT JOIN product_quality_parameter ON product_master.product_id = product_quality_parameter.product_id LEFT JOIN product_images ON product_master.product_id = product_images.product_id LEFT JOIN product_price_details ON product_master.product_id = product_price_details.product_id LEFT JOIN parameter ON product_master.para_unit_id = parameter.para_id WHERE product_price_details.para_waste_type_id = %s AND product_master.category_id = %s order by %s", retailerprice_group_id,category_id,DBConstant.PRODUCT_MASTER.SORTORDER);
return db.rawQuery(SQL,null);
}

//Select_PRODUCT from category
public Cursor Select_PRODUCT(SQLiteDatabase db,String category_id){
String SQL=String.format("SELECT product_master.product_id,product_master.name,product_master.price, product_master.para_status_id, product_master.para_unit_id,product_images.normal_img,product_images.select_img FROM product_master LEFT JOIN product_images ON product_master.product_id = product_images.product_id WHERE product_master.category_id = %s order by %s",category_id,DBConstant.PRODUCT_MASTER.SORTORDER);
return db.rawQuery(SQL,null);
}

//Select_PRODUCT_QUALITY_PARAMETER_
public Cursor Select_PRODUCT_QUALITY_PARAMETER(SQLiteDatabase db,String product_id){
String WHERE=String.format("%s = %s",DBConstant.PRODUCT_QUALITY_PARAMETER.PRODUCT_ID,product_id);
return  db.query(DBConstant.TABLE.PRODUCT_QUALITY_PARAMETER, new String[] {DBConstant.PRODUCT_QUALITY_PARAMETER.PRODUCT_QUALITY_PARA_ID, DBConstant.PRODUCT_QUALITY_PARAMETER.PARAMETER_NAME}, WHERE, null, null, null, null);
}

//Select_PRODUCT_QUALITY_PARAMETER_
public Cursor Select_PRODUCT_QUALITY_PARAMETER_(SQLiteDatabase db)//,String product_id){
{
//String WHERE=String.format("%s = %s",DBConstant.PRODUCT_QUALITY_PARAMETER.PRODUCT_ID,product_id);
return  db.query(DBConstant.TABLE.PRODUCT_QUALITY_PARAMETER, null, null, null, null, null, null);
}

//Select_PENDINGLEADS
public Cursor Select_PENDINGLEADS(SQLiteDatabase db,String user_id){
String mWhereCause = String.format("flag = %s AND %s = %s",0,DBConstant.PENDING_LEADS.USERID,user_id);
return db.query(DBConstant.TABLE.PENDING_LEADS, null, mWhereCause, null, null, null, null);
}

public Cursor Select_PENDINGLEADS(SQLiteDatabase db,String user_id,String strName){
String conditionWhere = String.format("flag =%s AND customer_name like '%s ","0",strName+"%'");
return db.query(DBConstant.TABLE.PENDING_LEADS, null, conditionWhere, null, null, null, null);
}

//Select_CASH_TRANSACTION
public Cursor Select_CASH_TRANSACTION(SQLiteDatabase db,String user_id){
String mWhereCause = String.format("%s = %s",DBConstant.CASH_TRANSACTION.USERID,user_id);
return db.query(DBConstant.TABLE.CASH_TRANSACTION, null, mWhereCause, null, null, null, null);
}

// public Cursor Select_PENDINGLEADS_NOT_EXIST_INTABLE(SQLiteDatabase db,String appointment_id){
// String mWhereCause = String.format(DBConstant.PENDING_LEADS.APPOINTMENT_ID+" = %s",appointment_id);
// return db.query(DBConstant.TABLE.PENDING_LEADS, null, mWhereCause, null, null, null, null);
// }
public void Update_Collection_info(SQLiteDatabase db, String appointment_id, String user_id,String Collection_dt){
String whereCause = String.format("%s = %s AND %s = %s",DBConstant.COLLECTION.APPOINTMENT_ID,appointment_id,DBConstant.COLLECTION.USERID,user_id);
Cursor c = db.query(DBConstant.TABLE.COLLECTION, null, whereCause, null, null, null, null);
if( c!=null){
c.moveToFirst();
String updateCollection = String.format("Update %s set %s = %s,%s = '%s' where %s = %s and %s = %s",
DBConstant.TABLE.PENDING_LEADS,DBConstant.PENDING_LEADS.FLAG,"1",DBConstant.PENDING_LEADS.COLLECTION_DT,Collection_dt,DBConstant.COLLECTION.APPOINTMENT_ID,
appointment_id,DBConstant.PENDING_LEADS.USERID,user_id);
Log.i("Update Collection :",updateCollection);
db.execSQL(updateCollection);
if(!c.isClosed()){
c.close();
}
}

}

//Select_PARAMETER for get para value(Example Kilogram..etc)
public String Select_PARAMETER_PARAVALUE(SQLiteDatabase db,String para_unit_id){
String PARA_VALUE="";
String WHERE =String.format("%s = %s",DBConstant.PARAMETER.PARA_ID,para_unit_id);
Cursor c = db.query(DBConstant.TABLE.PARAMETER, null, WHERE, null, null, null, null);
if(c!=null){
    if(c.getCount() > 0){
    c.moveToFirst();
    PARA_VALUE=c.getString(4);
    c.close();
    return PARA_VALUE;
    }
    else{
    c.close();
    return PARA_VALUE;
    }
}
else{
    return PARA_VALUE;
}
}

//Select_COLLECTION
public Cursor Select_COLLECTION(SQLiteDatabase db,String appointment_id,String userid){
String WHERE=String.format("%s = %s AND %s = %s",DBConstant.COLLECTION.APPOINTMENT_ID,appointment_id,DBConstant.COLLECTION.USERID,userid);
return  db.query(DBConstant.TABLE.COLLECTION, null, WHERE, null, null, null, null);
}

//Select_Finalized_DateTime for get DATETIME value
public String Select_Finalized_DateTime(SQLiteDatabase db,String appointment_id,String userid){
String DATETIME_VALUE="";
String WHERE=String.format("%s = %s AND %s = %s",DBConstant.PENDING_LEADS.APPOINTMENT_ID,appointment_id,DBConstant.PENDING_LEADS.USERID,userid);
Cursor c = db.query(DBConstant.TABLE.PENDING_LEADS, new String[]{DBConstant.PENDING_LEADS.COLLECTION_DT}, WHERE, null, null, null, null);
if(c!=null){
    if(c.getCount() > 0){
    c.moveToFirst();
    DATETIME_VALUE=c.getString(0);
    c.close();
    return DATETIME_VALUE;
    }
    else{
    c.close();
    return DATETIME_VALUE;
    }
}
else{
    return DATETIME_VALUE;
}
}

/********************Added By Vishal :: To Get Collection By Appointment ID***************************************************/
public Cursor Select_COLLECTION_By_Appointment_ID(SQLiteDatabase db,String Appointment_ID,String userid){
String WHERE=String.format("%s = %s AND %s = %s",DBConstant.COLLECTION.APPOINTMENT_ID,Appointment_ID,DBConstant.COLLECTION.USERID,userid);
return  db.query(DBConstant.TABLE.COLLECTION, null, WHERE, null, null, null, null);
}
/*****************************************************************************************************/
//Select_COLLECTION_SUM_TOTAL for get grand total
public String Select_COLLECTION_SUM_TOTAL(SQLiteDatabase db,String appointment_id,String userid){
        String GRAND_TOTAL="0";
String SQL=String.format("SELECT SUM(%s) from %s where %s = %s AND %s = %s", DBConstant.COLLECTION.TOTAL,DBConstant.TABLE.COLLECTION,DBConstant.COLLECTION.APPOINTMENT_ID,appointment_id,DBConstant.COLLECTION.USERID,userid);
Cursor c =  db.rawQuery(SQL,null);
if(c!=null){
    if(c.getCount() > 0){
    c.moveToFirst();
    GRAND_TOTAL=String.valueOf(c.getFloat(0));
    c.close();
    return GRAND_TOTAL;
    }
    else{
    c.close();
    return GRAND_TOTAL;
    }
}
else{
    return GRAND_TOTAL;
}

}

//Select_COLLECTION_COUNT_APPOINTMENT for get count record
public int Select_COLLECTION_COUNT_APPOINTMENT(SQLiteDatabase db,String appointment_id,String userid){
int Count=0;
String SQL=String.format("SELECT count(*) from %s where %s = %s AND %s = %s",DBConstant.TABLE.COLLECTION,DBConstant.COLLECTION.APPOINTMENT_ID,appointment_id,DBConstant.COLLECTION.USERID,userid);

Cursor c =  db.rawQuery(SQL,null);
if(c!=null){
    if(c.getCount() > 0){
    c.moveToFirst();
    Count=c.getInt(0);
    c.close();
    return Count;
    }
    else{
    c.close();
    return Count;
    }
}
else{
    return Count;
}
}

public int Select_COLLECTION_COUNT_APPOINTMENT_FLAG(SQLiteDatabase db,String appointment_id,String userid){
int Count=0;
// Select Count(*) from collection where appointment_id in (select appointment_id from PENDING_LEADS  WHERE flag=0);

// SELECT Count(*) FROM collection LEFT JOIN  PENDING_LEADS ON collection.appointment_id=PENDING_LEADS.appointment_id WHERE PENDING_LEADS.flag=0
// String SQL = String.format("SELECT Count(*) FROM %s LEFT JOIN %s ON %s.%s = %s.%s WHERE %s = 0",
// DBConstant.TABLE.COLLECTION,DBConstant.TABLE.PENDING_LEADS,DBConstant.TABLE.COLLECTION,DBConstant.COLLECTION.APPOINTMENT_ID,DBConstant.TABLE.PENDING_LEADS,DBConstant.PENDING_LEADS.APPOINTMENT_ID,DBConstant.PENDING_LEADS.FLAG);

String SQL=String.format("SELECT count(*) from %s where %s = %s AND %s = %s",DBConstant.TABLE.COLLECTION,DBConstant.COLLECTION.APPOINTMENT_ID,appointment_id,DBConstant.COLLECTION.USERID,userid);
Log.i("JOIN QUERY",SQL);
Cursor c =  db.rawQuery(SQL,null);
if(c!=null){
    if(c.getCount() > 0){
    c.moveToFirst();
    Count=c.getInt(0);
    c.close();
    return Count;
    }
    else{
    c.close();
    return Count;
    }
}
else{
    return Count;
}
}

public int Check_Pending_Leads_Status(SQLiteDatabase db, String appointment_id, String userid){
int Count = 0;
String SQL=String.format("SELECT count(*) from %s where %s = %s AND %s = %s",DBConstant.TABLE.PENDING_LEADS,DBConstant.COLLECTION.APPOINTMENT_ID,appointment_id,DBConstant.COLLECTION.USERID,userid);
Log.i("Query",SQL);
Cursor cr = db.rawQuery(SQL, null);
if( cr != null && cr.getCount()>0){
cr.moveToFirst();
Count = cr.getInt(0);
cr.close();
return Count;
}else{
return Count;
}
}
//Select_COLLECTION_COUNT_USERID for get count record
public int Select_COLLECTION_COUNT_USERID(SQLiteDatabase db,String userid){
int Count=0;
String SQL=String.format("SELECT count(*) from %s where  %s = %s ",DBConstant.TABLE.COLLECTION,DBConstant.COLLECTION.USERID,userid);

Cursor c =  db.rawQuery(SQL,null);
if(c!=null){
    if(c.getCount() > 0){
    c.moveToFirst();
    Count=c.getInt(0);
    c.close();
    return Count;
    }
    else{
    c.close();
    return Count;
    }
}
else{
    return Count;
}
}

//Select_COLLECTION_COUNT_APPOINTMENT for get check status record
public Cursor Select_Appointment_Status(SQLiteDatabase db,String userid){

String SQL=String.format("SELECT %s from %s where  %s = %s",DBConstant.PENDING_LEADS.APPOINTMENT_ID,DBConstant.TABLE.PENDING_LEADS,DBConstant.PENDING_LEADS.USERID,userid);
return  db.rawQuery(SQL,null);
}


//Select_PRODUCT_MAX_DATETIME for check updated datetime
public String Select_PRODUCT_MAX_DATETIME(SQLiteDatabase db){
String DATETIME="";
String SQL=String.format("SELECT MAX(%s) from %s", DBConstant.PRODUCT_MASTER.UPDATED_DT,DBConstant.TABLE.PRODUCT_MASTER);

Cursor c =  db.rawQuery(SQL,null);
if(c!=null){
    if(c.getCount() > 0){
    c.moveToFirst();
    DATETIME=c.getString(0);
    c.close();
    return DATETIME;
    }
    else{
    c.close();
    return DATETIME;
    }
}
else{
    return DATETIME;
}
}

//Get Finnalized collection Data

/* public Cursor Get_Finnalized_collection(SQLiteDatabase db){
return db.query(DBConstant.TABLE.PENDING_LEADS,new String[]{DBConstant.PENDING_LEADS.APPOINTMENT_ID}, null, null, null, null, null);
}*/

/********************Added By Vishal : To Get the Appointment IDs with Flag=1*****************************/
public Cursor Get_Appointment_IDs_WithFlag_Set(SQLiteDatabase db,String User_ID){
String mWhereArgs= String.format("%s = %s AND %s = %s",DBConstant.PENDING_LEADS.FLAG,"1",DBConstant.PENDING_LEADS.USERID,User_ID);
return db.query(DBConstant.TABLE.PENDING_LEADS,new String[]{DBConstant.PENDING_LEADS.APPOINTMENT_ID, DBConstant.PENDING_LEADS.CUSTOMER_ID,DBConstant.PENDING_LEADS.USERID}, mWhereArgs, null, null, null, null);
}
/*********************************************************************************************************/

/********************Added By Vishal : To Get the Collection IDs of Given Appointment IDs*****************************/
public Cursor Get_Collection_IDs_By_Appintment_ID(SQLiteDatabase db,String Appointment_ID,String User_ID){
String mWhereArgs =  String.format("%s = %s AND %s = %s",DBConstant.PENDING_LEADS.APPOINTMENT_ID,Appointment_ID,DBConstant.PENDING_LEADS.USERID,User_ID);
return db.query(DBConstant.TABLE.COLLECTION,new String[]{DBConstant.COLLECTION.COLLECTION_ID}, mWhereArgs, null, null, null, null);
}
/*********************************************************************************************************/
/********************Added By Vishal : To Get the Appointment ID From Given Collection ID*****************************/
public Cursor Get_AppintmentID_By_Collection_IDs(SQLiteDatabase db,String Collection_ID,String User_ID){
String mWhereArgs =  String.format("%s = %s AND %s = %s",DBConstant.COLLECTION.COLLECTION_ID,Collection_ID,DBConstant.COLLECTION.USERID,User_ID);
return db.query(DBConstant.TABLE.COLLECTION,new String[]{DBConstant.COLLECTION.APPOINTMENT_ID}, mWhereArgs, null, null, null, null);
}
/*********************************************************************************************************/
}
========================================================================
2)Create class DBConstant.java
=====================
package com.abc.xyz;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

public final class DBConstant {
 public static final class DB{
   public static final String DATABASENAME="DBLetsRecycle";
   public static final int DB_VERSION=2;
 }

 public static final class JSON {
/** THIS IS SAME AS CATEGORY_MASTER TABLE*/
 public static final String CATEGORY="category";

/** THIS IS SAME AS PRODUCT_MASTER TABLE*/
 public static final String PRODUCT="product";

/**  THIS IS SAME AS PRODUCT_QUALITY_PARAMETER TABLE*/
 public static final String PRODUCTPARAM="productparam";

/**  THIS IS FOR PARAMETER TABLE*/
 public static final String HASCHILD="hasChild";
 }

 public static final class TABLE {
 public static final String CATEGORY_MASTER="category_master";
 public static final String PARAMETER="parameter";
 public static final String PRODUCT_IMAGES="product_images";
 public static final String PRODUCT_MASTER="product_master";
 public static final String PRODUCT_PRICE_DETAILS="product_price_details";
 public static final String PRODUCT_QUALITY_PARAMETER="product_quality_parameter";
 public static final String COLLECTION="collection";
 public static final String PENDING_LEADS = "pending_leads";
 public static final String CASH_TRANSACTION = "cash_transaction";
 }

 public static final class CATEGORY_MASTER {
 public static final String CATEGORY_ID="category_id";
 public static final String CATEGORY_NAME="category_name";
 public static final String PARENT_ID="parent_id";
 public static final String DESCRIPTION="description";
 public static final String CREATED_BY="created_by";
 public static final String UPDATED_BY="updated_by";
 public static final String CREATED_DT="created_dt";
 public static final String UPDATED_DT="updated_dt";
 public static final String STATUS="status";
 public static final String SELECT_IMG="select_img";
 public static final String NORMAL_IMG="normal_img";
 public static final String ACTIVE="Active";
 public static final String SORTORDER="sortorder";
 }

 public static final class PARAMETER {
 public static final String PARA_ID="para_id";
 public static final String PARA_PARENT_ID="para_parent_id";
 public static final String PARA_LEVEL="para_level";
 public static final String PARA_TYPE="para_type";
 public static final String PARA_VALUE="para_value";
 public static final String PARA_DESC="para_desc";
 public static final String PARA_SORT_ORDER="para_sort_order";
 public static final String PARA_TECH_DESC="para_tech_desc";
 public static final String CREATED_DT="created_dt";
 public static final String CREATED_BY="created_by";
 public static final String UPDATED_DT="updated_dt";
 public static final String UPDATED_BY="updated_by";
 public static final String STATUS="status";
 }

 public static final class PRODUCT_IMAGES {
 public static final String ID="id";
 public static final String PRODUCT_ID="product_id";
 public static final String NORMAL_IMG="normal_img";
 public static final String SELECT_IMG="select_img";
 }

 public static final class PRODUCT_MASTER {
 public static final String PRODUCT_ID="product_id";
 public static final String NAME="name";
 public static final String PRICE="price";
 public static final String PARA_STATUS_ID="para_status_id";
 public static final String PARA_UNIT_ID="para_unit_id";
 public static final String CATEGORY_ID="category_id";
 public static final String FACTORY_PRICE="factory_price";
 public static final String OPERATION_COST="operation_cost";
 public static final String OPERATION_COST_IN="operation_cost_in";
 public static final String COMPANY_MARGIN="company_margin";
 public static final String COMPANY_MARGIN_IN="company_margin_in";
 public static final String FRENCHIESE_MARGIN="frenchiese_margin";
 public static final String FRENCHIESE_MARGIN_IN="frenchiese_margin_in";
 public static final String CREATED_DT="created_dt";
 public static final String CREATED_BY="created_by";
 public static final String UPDATED_DT="updated_dt";
 public static final String UPDATED_BY="updated_by";
 public static final String SORTORDER="sortorder";
 }

 public static final class PRODUCT_PRICE_DETAILS {
 public static final String DETAILS_ID="details_id";
 public static final String PRODUCT_ID="product_id";
 public static final String PARA_WASTE_TYPE_ID="para_waste_type_id";
 public static final String FACTORY_PRICE="factory_price";
 public static final String OPERATION_COST="operation_cost";
 public static final String OPERATION_COST_IN="operation_cost_in";
 public static final String COMPANY_MARGIN="company_margin";
 public static final String COMPANY_MARGIN_IN="company_margin_in";
 public static final String FRENCHIESE_MARGIN="frenchiese_margin";
 public static final String FRENCHIESE_MARGIN_IN="frenchiese_margin_in";
 public static final String OPERATION_COST_AMT="operation_cost_amt";
 public static final String COMPANY_MARGIN_AMT="company_margin_amt";
 public static final String FRENCHIESE_MARGIN_AMT="frenchiese_margin_amt";
 public static final String PRICE="price";
 }

 public static final class PRODUCT_QUALITY_PARAMETER {
 public static final String PRODUCT_QUALITY_PARA_ID="product_quality_para_id";
 public static final String PRODUCT_ID="product_id";
 public static final String PARAMETER_NAME="parameter_name";
 public static final String PARA_RATE="para_rate";
 public static final String PARA_RATE_IN="para_rate_in";
 public static final String CREATED_DT="created_dt";
 public static final String CREATED_BY="created_by";
 public static final String UPDATED_DT="updated_dt";
 public static final String UPDATED_BY="updated_by";
 }

 public static final class COLLECTION {
 public static final String COLLECTION_ID="collection_id";
 public static final String APPOINTMENT_ID="appointment_id";
 public static final String CATEGORY_ID="category_id";
 public static final String PRODUCT_ID="product_id";
 public static final String PRODUCT_QUALITY_PARA_ID="product_quality_para_id";
 public static final String PARA_VALUE="para_value";
 public static final String QUANTITY="quantity";
 public static final String RATE="rate";
 public static final String TOTAL="total";
 public static final String CATEGORY_PRODUCT_PARAMETER="category_product_parameter";
 public static final String USERID="userid";
 }

 public static final class PENDING_LEADS {
 public static final String PENDINGLEAD_ID ="pendinglead_id";
 public static final String APPOINTMENT_ID="appointment_id";
 public static final String APP_DATE_TIME="app_date_time";
 public static final String CUSTOMER_ID="customer_id";
 public static final String CUSTOMER_NAME="customer_name";
 public static final String CUSTOMR_CODE="customr_code";
 public static final String ADDRESS1="address1";
 public static final String ADDRESS2="address2";
 public static final String CITY="city";
 public static final String STATE="state";
 public static final String COUNTRY="country";
 public static final String ZIPCODE="zipcode";
 public static final String MOBILE_NO="mobile_no";
 public static final String LANDMARK="landmark";
 public static final String PRICE_GROUP="price_group";
 public static final String LATTITUDE="lattitude";
 public static final String LONGITUDE="longitude";
 public static final String VAT_VALUE="vat_value";
 public static final String VAT="vat";
 public static final String FLAG="flag";
 public static final String USERID="userid";
 public static final String COLLECTION_DT="collection_dt";

 /*public static final String PENDINGLEAD_ID = "pendinglead_id";
 public static final String APPOINTMENT_ID = "appointment_id";
 public static final String CUSTOMER_ID = "customer_id";
 public static final String COLLECTION_BY = "collection_by";
 public static final String PARA_STATUS_ID = "para_status_id";
 public static final String APP_DATE_TIME = "app_date_time";
 public static final String REMARK = "remark";
 public static final String DUSTBIN_ID = "dustbin_id";
 public static final String CREATED_BY = "created_by";
 public static final String UPDATED_BY = "updated_by";
 public static final String CREATED_DT = "created_dt";
 public static final String UPDATED_DT = "updated_dt";
 public static final String COLLECTION_BY_USER = "collection_by_user";
 public static final String CUSTOMER_NAME = "customer_name";
 public static final String CUSTOMR_CODE = "customr_code";
 public static final String SALUTATION = "salutation";
 public static final String FIRST_NAME = "first_name";
 public static final String MIDDLE_NAME = "middle_name";
 public static final String LAST_NAME = "last_name";
 public static final String CODE = "code";
 public static final String EMAIL = "email";
 public static final String ADDRESS1 = "address1";
 public static final String ADDRESS2 = "address2";
 public static final String CITY = "city";
 public static final String STATE = "state";
 public static final String COUNTRY = "country";
 public static final String ZIPCODE = "zipcode";
 public static final String R_PHONE = "r_phone";
 public static final String O_PHONE = "o_phone";
 public static final String MOBILE_NO = "mobile_no";
 public static final String LANDMARK = "landmark";
 public static final String PRICE_GROUP = "price_group";
 public static final String LONGITUDE = "longitude";
 public static final String LATTITUDE = "lattitude";
 public static final String VAT = "vat";
 public static final String TIN_NO = "tin_no";
 public static final String ALLOCATED_DUSTBIN_CODE = "allocated_dustbin_code";
 public static final String CREATED = "created";
 public static final String UPDATED = "updated";
 public static final String DATE_CREATE = "date_create";
 public static final String DATE_UPDATE = "date_update";*/

 }

 public static final class CASH_TRANSACTION {
 public static final String CT_ID="ct_id";
 public static final String DATE="date";
 public static final String CASH_GIVEN="cash_given";
 public static final String CASH_RECEIVE="cash_receive";
 public static final String USERID="userid";
 }


 /**THIS FUNCTION IS USED FOR OPEN DATABASE */
 public static DBHelper mDBHelper=null;
 public static SQLiteDatabase mSQLiteDatabase=null;
 public static void OpenDatabase(Context context)
{
       try{
        if(mDBHelper==null && mSQLiteDatabase==null){
  mDBHelper = new DBHelper(context);
   mSQLiteDatabase = mDBHelper.getWritableDatabase();
//    mSQLiteDatabase.setLockingEnabled(true);
        }
       }
       catch (Exception e) {
e.printStackTrace();is
}
}
/**THIS FUNCTION IS USED FOR CLOSE DATABASE */
 public static void CloseDataBase()
{
 try{
 if(mDBHelper!=null && mSQLiteDatabase!=null){
mSQLiteDatabase.close();
mDBHelper.close();
mSQLiteDatabase=null;
mDBHelper=null;
   }
 }
 catch (Exception e) {
e.printStackTrace();
 }
 
}
}

3)From where u want to call this
======================
 DBConstant.OpenDatabase(CashTransaction_Activity.this);
DBConstant.mDBHelper.Delete_CASH_TRANSACTION(DBConstant.mSQLiteDatabase);
 
JSONArray jsonusercashDetails_array=jsonusercashDetails.getJSONArray(Constant.CASH_TRANSACTION_JSON.RETURNRESULT);
for(int i=0;i < jsonusercashDetails_array.length();i++){
JSONObject jsoncashdata=jsonusercashDetails_array.getJSONObject(i);
String id=jsoncashdata.getString(Constant.CASH_TRANSACTION_JSON.ID);
String userid=jsoncashdata.getString(Constant.CASH_TRANSACTION_JSON.USERID);
String date=jsoncashdata.getString(Constant.CASH_TRANSACTION_JSON.DATE);
Float cash_given=Float.parseFloat(jsoncashdata.getString(Constant.CASH_TRANSACTION_JSON.CASH_GIVEN));
Float cash_receive=Float.valueOf(jsoncashdata.getString(Constant.CASH_TRANSACTION_JSON.CASH_RECEIVE));
DBConstant.mDBHelper.Insert_CASH_TRANSACTION(DBConstant.mSQLiteDatabase,id, date, cash_given, cash_receive, userid);
}
DBConstant.CloseDataBase();

No comments:

Post a Comment