1)DBHelper.java
package com.xyz.mrs;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DbHelper extends SQLiteOpenHelper{
//This Is For Make Database
public DbHelper(Context context) {
super(context, DbConstant.DB.DATABASENAME, null, DbConstant.DB.DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
//This Is For Make Database Table
String TABLE1 = String.format("CREATE TABLE %s (" +
"%s INTEGER PRIMARY KEY AUTOINCREMENT," +
"%s VARCHAR(50)," +
"%s VARCHAR(50)," +
"%s VARCHAR(50)," +
"%s VARCHAR(50)," +
"%s VARCHAR(50)," +
"%s INEGER," +
"%s INTEGER)",DbConstant.QUICKTEST_RESULT.QUICKTEST_RESULT_TABLE,
DbConstant.QUICKTEST_RESULT.RESULT_ID,
DbConstant.QUICKTEST_RESULT.PLAYER_NAME,
DbConstant.QUICKTEST_RESULT.RESULT_GUARDIAN,
DbConstant.QUICKTEST_RESULT.RESULT_RELATIONIST,
DbConstant.QUICKTEST_RESULT.RESULT_CREATOR,
DbConstant.QUICKTEST_RESULT.RESULT_ACHIEVER,
DbConstant.QUICKTEST_RESULT.RESULT_SHOW,
DbConstant.QUICKTEST_RESULT.QUICK_OR_FULL);
db.execSQL(TABLE1);
String TABLE2 = String.format("CREATE TABLE %s (" +
"%s INTEGER PRIMARY KEY AUTOINCREMENT," +
"%s INTEGER," +
"%s INEGER," +
"%s INTEGER, " +
"%s INTEGER, " +
"%s INTEGER, " +
"%s INTEGER, " +
"%s INTEGER)",DbConstant.QUICKTEST_EXAM.QUICKTEST_EXAM_TABLE,
DbConstant.QUICKTEST_EXAM.QUICK_TEST_ID,
DbConstant.QUICKTEST_EXAM.QUICK_TEST_QUES_ID,
DbConstant.QUICKTEST_EXAM.RESULT_ID,
DbConstant.QUICKTEST_EXAM.GUARDIAN,
DbConstant.QUICKTEST_EXAM.RELATIONIST,
DbConstant.QUICKTEST_EXAM.CREATOR,
DbConstant.QUICKTEST_EXAM.ACHIEVER,
DbConstant.QUICKTEST_EXAM.SELECTED);
db.execSQL(TABLE2);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
db.execSQL("DROP TABLE IF EXISTS "+ DbConstant.QUICKTEST_RESULT.QUICKTEST_RESULT_TABLE);
db.execSQL("DROP TABLE IF EXISTS "+ DbConstant.QUICKTEST_EXAM.QUICKTEST_EXAM_TABLE);
onCreate(db);
}
//***********************************************************************************************************************
public static void InsertQuicktestExam(SQLiteDatabase db,int quick_test_ques_id,int result_id,int guardian,int relationist, int creator, int achiever,int intselected){
ContentValues cv = new ContentValues();
cv.put(DbConstant.QUICKTEST_EXAM.QUICK_TEST_QUES_ID,quick_test_ques_id);
cv.put(DbConstant.QUICKTEST_EXAM.RESULT_ID,result_id);
cv.put(DbConstant.QUICKTEST_EXAM.GUARDIAN,guardian);
cv.put(DbConstant.QUICKTEST_EXAM.RELATIONIST,relationist);
cv.put(DbConstant.QUICKTEST_EXAM.CREATOR,creator);
cv.put(DbConstant.QUICKTEST_EXAM.ACHIEVER,achiever);
cv.put(DbConstant.QUICKTEST_EXAM.SELECTED,intselected);
db.insert(DbConstant.QUICKTEST_EXAM.QUICKTEST_EXAM_TABLE, null,cv);
}
//***********************************************************************************************************************
public static void UpdateQuicktestExam(SQLiteDatabase db,int quick_test_ques_id,int result_id,int intGuardian, int intRelationist,int intCreator, int intAchiever,int intselected){
String strwhere = String.format("%s = %s and %s = %s",DbConstant.QUICKTEST_EXAM.QUICK_TEST_QUES_ID,quick_test_ques_id,DbConstant.QUICKTEST_EXAM.RESULT_ID,result_id);
ContentValues cv = new ContentValues();
cv.put(DbConstant.QUICKTEST_EXAM.QUICK_TEST_QUES_ID,quick_test_ques_id);
cv.put(DbConstant.QUICKTEST_EXAM.RESULT_ID,result_id);
cv.put(DbConstant.QUICKTEST_EXAM.GUARDIAN ,intGuardian);
cv.put(DbConstant.QUICKTEST_EXAM.RELATIONIST, intRelationist);
cv.put(DbConstant.QUICKTEST_EXAM.CREATOR, intCreator);
cv.put(DbConstant.QUICKTEST_EXAM.ACHIEVER, intAchiever);
cv.put(DbConstant.QUICKTEST_EXAM.SELECTED, intselected);
db.update(DbConstant.QUICKTEST_EXAM.QUICKTEST_EXAM_TABLE, cv, strwhere, null);
}
//***********************************************************************************************************************
public int getQuickResultID(SQLiteDatabase db){
int id = 0;
String SQL = String.format("SELECT %s FROM %s WHERE %s = (SELECT MAX(%s) FROM %s)",DbConstant.QUICKTEST_RESULT.RESULT_ID,DbConstant.QUICKTEST_RESULT.QUICKTEST_RESULT_TABLE,DbConstant.QUICKTEST_RESULT.RESULT_ID,DbConstant.QUICKTEST_RESULT.RESULT_ID,DbConstant.QUICKTEST_RESULT.QUICKTEST_RESULT_TABLE);
Cursor cursor = db.rawQuery(SQL,null);
if(cursor!=null){
if(cursor.getCount()>0){
cursor.moveToFirst();
id= cursor.getInt(0);
}
if(!cursor.isClosed()){
cursor.close();
}
}
return id;
}
//***********************************************************************************************************************
public int getQuickExamSelcted(SQLiteDatabase db,int intQuickTest_Id,int intresult_Id){
int id = 5;
String SQL = String.format("SELECT %s From %s WHERE %s = %s and %s = %s",DbConstant.QUICKTEST_EXAM.SELECTED,DbConstant.QUICKTEST_EXAM.QUICKTEST_EXAM_TABLE,DbConstant.QUICKTEST_EXAM.QUICK_TEST_QUES_ID,intQuickTest_Id,DbConstant.QUICKTEST_EXAM.RESULT_ID, intresult_Id);
Cursor cursor = db.rawQuery(SQL,null);
if(cursor!=null){
if(cursor.getCount()>0){
cursor.moveToFirst();
id= cursor.getInt(0);
}
if(!cursor.isClosed()){
cursor.close();
}
}
return id;
}
//***********************************************************************************************************************
public int checkRecordExist_QuickExam(SQLiteDatabase db,int intQuickTest_Id,int intresult_Id){
int count = 0;
String SQL = String.format("SELECT count(*) From %s WHERE %s = %s and %s = %s",DbConstant.QUICKTEST_EXAM.QUICKTEST_EXAM_TABLE,DbConstant.QUICKTEST_EXAM.QUICK_TEST_QUES_ID,intQuickTest_Id,DbConstant.QUICKTEST_EXAM.RESULT_ID, intresult_Id);
Cursor cursor = db.rawQuery(SQL,null);
if(cursor!=null){
if(cursor.getCount()>0){
cursor.moveToFirst();
count = cursor.getInt(0);
}
if(!cursor.isClosed()){
cursor.close();
}
}
return count;
}
//***********************************************************************************************************************
public Cursor GetResultData(SQLiteDatabase db,int result_show){
// String strwhere = "result_show =" + result_show;
String strwhere = String.format("%s = %s",DbConstant.QUICKTEST_RESULT.RESULT_SHOW,result_show);
return db.query(DbConstant.QUICKTEST_RESULT.QUICKTEST_RESULT_TABLE,null, strwhere, null, null, null, null);
}
//***********************************************************************************************************************
public int[] QUICKTEST_GUARDIAN_TOTAL(SQLiteDatabase db,int intresult_Id){
int TOTAL[] = new int[4];
String SQL=String.format("SELECT SUM(%s),SUM(%s),SUM(%s),SUM(%s) from %s where %s = %s",DbConstant.QUICKTEST_EXAM.GUARDIAN,DbConstant.QUICKTEST_EXAM.RELATIONIST,DbConstant.QUICKTEST_EXAM.CREATOR,DbConstant.QUICKTEST_EXAM.ACHIEVER,DbConstant.QUICKTEST_EXAM.QUICKTEST_EXAM_TABLE,DbConstant.QUICKTEST_EXAM.RESULT_ID, intresult_Id);
Cursor c = db.rawQuery(SQL,null);
if(c!=null){
if(c.getCount() > 0){
c.moveToFirst();
TOTAL[0]=c.getInt(0);
TOTAL[1]=c.getInt(1);
TOTAL[2]=c.getInt(2);
TOTAL[3]=c.getInt(3);
}
if(!c.isClosed()){
c.close();
}
}
return TOTAL;
}
//***********************************************************************************************************************
public String getQuickPlayerName(SQLiteDatabase db){
String strName = null;
String SQL = String.format("SELECT %s FROM %s WHERE %s = (SELECT MAX(%s) FROM %s)",DbConstant.QUICKTEST_RESULT.PLAYER_NAME,DbConstant.QUICKTEST_RESULT.QUICKTEST_RESULT_TABLE,DbConstant.QUICKTEST_RESULT.RESULT_ID,DbConstant.QUICKTEST_RESULT.RESULT_ID,DbConstant.QUICKTEST_RESULT.QUICKTEST_RESULT_TABLE);
Cursor cursor = db.rawQuery(SQL,null);
if(cursor!=null){
if(cursor.getCount()>0){
cursor.moveToFirst();
strName = cursor.getString(0);
}
if(!cursor.isClosed()){
cursor.close();
}
}
return strName;
}
//***********************************************************************************************************************
public static void InsertQuicktestResult(SQLiteDatabase db,String player_name,int result_guardian, int result_relationist,int result_creator, int result_achiever, int result_show,int quick_or_full){
ContentValues cv = new ContentValues();
cv.put(DbConstant.QUICKTEST_RESULT.PLAYER_NAME,player_name);
cv.put(DbConstant.QUICKTEST_RESULT.RESULT_GUARDIAN,result_guardian);
cv.put(DbConstant.QUICKTEST_RESULT.RESULT_RELATIONIST,result_relationist);
cv.put(DbConstant.QUICKTEST_RESULT.RESULT_CREATOR,result_creator);
cv.put(DbConstant.QUICKTEST_RESULT.RESULT_ACHIEVER,result_achiever);
cv.put(DbConstant.QUICKTEST_RESULT.RESULT_SHOW,result_show);
cv.put(DbConstant.QUICKTEST_RESULT.QUICK_OR_FULL,quick_or_full);
db.insert(DbConstant.QUICKTEST_RESULT.QUICKTEST_RESULT_TABLE, null,cv);
}
//***********************************************************************************************************************
public static void UpdateQuicktestResult(SQLiteDatabase db,int result_id,String player_name,String guardian,String relationist,String creator, String achiever,int show_result ){
String strwhere = String.format(DbConstant.QUICKTEST_RESULT.RESULT_ID +"= %s ",result_id);
ContentValues cv = new ContentValues();
cv.put(DbConstant.QUICKTEST_RESULT.PLAYER_NAME,player_name);
cv.put(DbConstant.QUICKTEST_RESULT.RESULT_GUARDIAN,guardian);
cv.put(DbConstant.QUICKTEST_RESULT.RESULT_RELATIONIST,relationist);
cv.put(DbConstant.QUICKTEST_RESULT.RESULT_CREATOR,creator);
cv.put(DbConstant.QUICKTEST_RESULT.RESULT_ACHIEVER,achiever);
cv.put(DbConstant.QUICKTEST_RESULT.RESULT_SHOW, show_result);
db.update(DbConstant.QUICKTEST_RESULT.QUICKTEST_RESULT_TABLE, cv, strwhere, null);
}
//***********************************************************************************************************************
public void Delete_Result(SQLiteDatabase db,String result_id){
String WHERE=String.format("%s = %s",DbConstant.QUICKTEST_RESULT.RESULT_ID,result_id);
db.delete(DbConstant.QUICKTEST_RESULT.QUICKTEST_RESULT_TABLE, WHERE, null);
}
}
2)Fulltest.java
package com.drc.mrs;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;
import com.drc.xmlconstant.Dict_FullTestQuestion_Constant;
import com.drc.xmlconstant.Dict_ScoreTableFulltest_Constant;
import com.drc.xmlconstant.Dict_Wording_Constant;
public class FullTest extends Activity implements OnClickListener{
private SharedPreferences mSharedPreferences_Read = null;
private Button btnBack = null;
private Button btnResult = null;
private Button btnPrevious =null;
private Button btnNext = null;
private RadioButton rbtn1 = null;
private RadioButton rbtn2 = null;
private RadioButton rbtn3 = null;
private RadioButton rbtn4 = null;
private TextView txtQuestion_No = null;
private int intTotalQuestion = 35;
private int intCount = 1;
private String strResult1 = null,strResult2 = null;
private String strResult3 = null,strResult4 = null;
private String strQuestion1 = null;
private String strQuestion2 = null;
private String strQuestion3 = null;
private String strQuestion4 = null;
private int intResultID = 0;
private int isRecordExist=0;
private TextView txtCodeOfUTitle = null;
private ImageView imgCodeOfUnderstanding = null;
private int intLanguage_Position=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
Utils.enableStrictMode();
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.xfulltest);
mSharedPreferences_Read = getSharedPreferences(Constant.SHAREDPREFERENCE.COMMAN_SHAREDPREFERENCE, MODE_WORLD_READABLE);
intLanguage_Position = mSharedPreferences_Read.getInt(Constant.SHAREDPREFERENCE.LANGUAGE_POSITION, Constant.SHAREDPREFERENCE.DEFAULT_LANGUAGE_POSITION);
btnBack = (Button)findViewById(R.id.btnBack);
btnBack.setOnClickListener(this);
btnResult = (Button)findViewById(R.id.btnResults);
btnResult.setOnClickListener(this);
btnPrevious = (Button)findViewById(R.id.btnPrevious);
btnPrevious.setOnClickListener(this);
btnNext = (Button)findViewById(R.id.btnNext);
btnNext.setOnClickListener(this);
rbtn1 = (RadioButton)findViewById(R.id.rbtn1);
rbtn1.setOnClickListener(this);
rbtn2 = (RadioButton)findViewById(R.id.rbtn2);
rbtn2.setOnClickListener(this);
rbtn3 = (RadioButton)findViewById(R.id.rbtn3);
rbtn3.setOnClickListener(this);
rbtn4 = (RadioButton)findViewById(R.id.rbtn4);
rbtn4.setOnClickListener(this);
rbtn1.setTag(Constant.UNCHECK);
rbtn2.setTag(Constant.UNCHECK);
rbtn3.setTag(Constant.UNCHECK);
rbtn4.setTag(Constant.UNCHECK);
rbtn1.setChecked(false);
rbtn2.setChecked(false);
rbtn3.setChecked(false);
rbtn4.setChecked(false);
txtQuestion_No = (TextView)findViewById(R.id.txtQuestion_No);
txtCodeOfUTitle = (TextView)findViewById(R.id.txtFullTestTilte);
imgCodeOfUnderstanding = (ImageView)findViewById(R.id.imgCodeOfUnderstanding);
btnBack.setText(mSharedPreferences_Read.getString(Dict_Wording_Constant.WORDINGS.BACK_BUTTON + Constant.LANGUAGE_TAG[intLanguage_Position],""));
btnResult.setText(mSharedPreferences_Read.getString(Dict_Wording_Constant.WORDINGS.RESULTS_BUTTON + Constant.LANGUAGE_TAG[intLanguage_Position],""));
txtCodeOfUTitle.setText(mSharedPreferences_Read.getString(Dict_Wording_Constant.WORDINGS.CODE_OF_U_TEST_TITLE + Constant.LANGUAGE_TAG[intLanguage_Position],""));
//imgCodeOfUnderstanding.setText(mSharedPreferences_Read.getString(Dict_Wording_Constant.WORDINGS.HOMESCREEN_TITLE,""));
if(intLanguage_Position==Constant.SHAREDPREFERENCE.ENGLISH){
imgCodeOfUnderstanding.setBackgroundResource(R.drawable.begrips_code_logo_en);
}
else if(intLanguage_Position==Constant.SHAREDPREFERENCE.NEDERLANDS){
imgCodeOfUnderstanding.setBackgroundResource(R.drawable.begrips_code_logo_nl);
}
else if(intLanguage_Position==Constant.SHAREDPREFERENCE.DEUTSCH){
imgCodeOfUnderstanding.setBackgroundResource(R.drawable.begrips_code_logo_de);
}
strQuestion1 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.A_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strQuestion2 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.B_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strQuestion3 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.C_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strQuestion4 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.D_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
txtQuestion_No.setText(String.valueOf(intCount));
rbtn1.setText(strQuestion1);
rbtn2.setText(strQuestion2);
rbtn3.setText(strQuestion3);
rbtn4.setText(strQuestion4);
strResult1 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.A_SCORE_FULLTEST, intCount), "");
strResult2 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.B_SCORE_FULLTEST,intCount) ,"");
strResult3 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.C_SCORE_FULLTEST, intCount), "");
strResult4 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.D_SCORE_FULLTEST,intCount) ,"");
//***********************************************************************************************************************
OpenDatabase();
mDbHelper.InsertQuicktestResult(mSQLiteDatabase,"", 0,0,0,0,0,1);
CloseDataBase();
txtQuestion_No.setText(String.valueOf(intCount));
btnPrevious.setVisibility(Button.INVISIBLE);
btnResult.setVisibility(Button.INVISIBLE);
if(!rbtn1.isChecked() || !rbtn2.isChecked() || !rbtn3.isChecked() || !rbtn4.isChecked()){
btnNext.setVisibility(Button.INVISIBLE);
}
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode==KeyEvent.KEYCODE_BACK)
{
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
private synchronized void RadioCheck(){
btnNext.setVisibility(Button.INVISIBLE);
btnResult.setVisibility(Button.INVISIBLE);
rbtn1.setButtonDrawable(R.drawable.radio_button_normal);
rbtn2.setButtonDrawable(R.drawable.radio_button_normal);
rbtn3.setButtonDrawable(R.drawable.radio_button_normal);
rbtn4.setButtonDrawable(R.drawable.radio_button_normal);
rbtn1.setTag(Constant.UNCHECK);
rbtn2.setTag(Constant.UNCHECK);
rbtn3.setTag(Constant.UNCHECK);
rbtn4.setTag(Constant.UNCHECK);
rbtn1.setChecked(false);
rbtn2.setChecked(false);
rbtn3.setChecked(false);
rbtn4.setChecked(false);
}
private synchronized void RadioUnchecked(int position){
rbtn1.setButtonDrawable(R.drawable.radio_button_normal);
rbtn2.setButtonDrawable(R.drawable.radio_button_normal);
rbtn3.setButtonDrawable(R.drawable.radio_button_normal);
rbtn4.setButtonDrawable(R.drawable.radio_button_normal);
rbtn1.setTag(Constant.UNCHECK);
rbtn2.setTag(Constant.UNCHECK);
rbtn3.setTag(Constant.UNCHECK);
rbtn4.setTag(Constant.UNCHECK);
rbtn1.setChecked(false);
rbtn2.setChecked(false);
rbtn3.setChecked(false);
rbtn4.setChecked(false);
if(position == 1){
rbtn1.setButtonDrawable(R.drawable.radio_button_selected);
rbtn1.setTag(Constant.CHECK);
rbtn1.setChecked(true);
}
else if(position == 2){
rbtn2.setButtonDrawable(R.drawable.radio_button_selected);
rbtn2.setTag(Constant.CHECK);
rbtn2.setChecked(true);
}
else if(position == 3){
rbtn3.setButtonDrawable(R.drawable.radio_button_selected);
rbtn3.setTag(Constant.CHECK);
rbtn3.setChecked(true);
}
else if(position == 4){
rbtn4.setButtonDrawable(R.drawable.radio_button_selected);
rbtn4.setTag(Constant.CHECK);
rbtn4.setChecked(true);
}
}
@Override
public synchronized void onClick(View v) {
// TODO Auto-generated method stub
if(v==btnBack){
finish();
}
else if(v==btnResult){
InsertQuickTestExam();
Intent mIntent = new Intent(this,Results.class);
mIntent.putExtra(Constant.RESULT_INTENT.RESULT_ID, intResultID);
mIntent.setAction(Constant.FULLTEST_CATEGORY.FULLTEST_ACTION);
startActivity(mIntent);
finish();
}
else if(v==rbtn1){
if(intCount < intTotalQuestion){
if(v.getTag().toString().equals(Constant.UNCHECK)){
btnNext.setVisibility(Button.VISIBLE);
RadioUnchecked(1);
}
else{
RadioCheck();
}
}
else{
if(v.getTag().toString().equals(Constant.UNCHECK)){
btnNext.setVisibility(Button.INVISIBLE);
btnResult.setVisibility(Button.VISIBLE);
RadioUnchecked(1);
}else{
RadioCheck();
}
}
}
else if(v==rbtn2){
if(intCount < intTotalQuestion){
if(v.getTag().toString().equals(Constant.UNCHECK)){
btnNext.setVisibility(Button.VISIBLE);
RadioUnchecked(2);
}
else{
RadioCheck();
}
}
else{
if(v.getTag().toString().equals(Constant.UNCHECK)){
btnNext.setVisibility(Button.INVISIBLE);
btnResult.setVisibility(Button.VISIBLE);
RadioUnchecked(2);
}
else{
RadioCheck();
}
}
}
else if(v==rbtn3){
if(intCount < intTotalQuestion){
if(v.getTag().toString().equals(Constant.UNCHECK)){
btnNext.setVisibility(Button.VISIBLE);
RadioUnchecked(3);
}
else{
RadioCheck();
}
}
else{
if(v.getTag().toString().equals(Constant.UNCHECK)){
btnNext.setVisibility(Button.INVISIBLE);
btnResult.setVisibility(Button.VISIBLE);
RadioUnchecked(3);
}
else{
RadioCheck();
}
}
}
else if(v==rbtn4){
if(intCount < intTotalQuestion){
if(v.getTag().toString().equals(Constant.UNCHECK)){
btnNext.setVisibility(Button.VISIBLE);
RadioUnchecked(4);
}
else{
RadioCheck();
}
}
else{
if(v.getTag().toString().equals(Constant.UNCHECK)){
btnNext.setVisibility(Button.INVISIBLE);
btnResult.setVisibility(Button.VISIBLE);
RadioUnchecked(4);
}
else{
RadioCheck();
}
}
}
else if(v==btnPrevious){
if(intTotalQuestion > 1)
{
InsertQuickTestExam();
if(intCount > 1)
{
intCount=intCount-1;
txtQuestion_No.setText(String.valueOf(intCount));
strQuestion1 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.A_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strQuestion2 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.B_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strQuestion3 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.C_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strQuestion4 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.D_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
rbtn1.setText(strQuestion1);
rbtn2.setText(strQuestion2);
rbtn3.setText(strQuestion3);
rbtn4.setText(strQuestion4);
getCheckboxStatus();
strResult1 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.A_SCORE_FULLTEST, intCount), "");
strResult2 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.B_SCORE_FULLTEST,intCount) ,"");
strResult3 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.C_SCORE_FULLTEST, intCount), "");
strResult4 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.D_SCORE_FULLTEST,intCount) ,"");
ButtonHide(intCount,intTotalQuestion);
}
else
{
intCount=1;
Toast.makeText(this, "intcount==="+intCount, Toast.LENGTH_SHORT).show();
ButtonHide(intCount,intTotalQuestion);
}
}
}
else if(v==btnNext){
if(intTotalQuestion > 1)
{
InsertQuickTestExam();
if(intCount < intTotalQuestion-1)
{
intCount=intCount+1;
txtQuestion_No.setText(String.valueOf(intCount));
strQuestion1 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.A_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strQuestion2 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.B_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strQuestion3 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.C_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strQuestion4 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.D_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strResult1 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.A_SCORE_FULLTEST, intCount), "");
strResult2 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.B_SCORE_FULLTEST,intCount) ,"");
strResult3 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.C_SCORE_FULLTEST, intCount), "");
strResult4 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.D_SCORE_FULLTEST,intCount) ,"");
rbtn1.setText(strQuestion1);
rbtn2.setText(strQuestion2);
rbtn3.setText(strQuestion3);
rbtn4.setText(strQuestion4);
getCheckboxStatus();
if(intCount < intTotalQuestion){
ButtonHide(intCount,intTotalQuestion);
}
}
else
{
intCount=intTotalQuestion;
txtQuestion_No.setText(String.valueOf(intCount));
strQuestion1 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.A_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strQuestion2 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.B_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strQuestion3 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.C_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strQuestion4 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.D_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strResult1 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.A_SCORE_FULLTEST, intCount), "");
strResult2 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.B_SCORE_FULLTEST,intCount) ,"");
strResult3 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.C_SCORE_FULLTEST, intCount), "");
strResult4 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.D_SCORE_FULLTEST,intCount) ,"");
rbtn1.setText(strQuestion1);
rbtn2.setText(strQuestion2);
rbtn3.setText(strQuestion3);
rbtn4.setText(strQuestion4);
getCheckboxStatus();
ButtonHide(intCount,intTotalQuestion);
}
}
if(intCount < intTotalQuestion && (rbtn1.isChecked() || rbtn2.isChecked() || rbtn3.isChecked() || rbtn4.isChecked())){
btnNext.setVisibility(Button.VISIBLE);
}
else if(intCount >= intTotalQuestion && (rbtn1.isChecked() || rbtn2.isChecked() || rbtn3.isChecked() || rbtn4.isChecked())){
btnNext.setVisibility(Button.INVISIBLE);
}
else{
btnNext.setVisibility(Button.INVISIBLE);
btnResult.setVisibility(Button.INVISIBLE);
}
}
}
//This function is used to set visibility of button
private synchronized void ButtonHide(int CurrentRecord,int TotalRecord){
if(TotalRecord > 1){
if(CurrentRecord >= TotalRecord)
{
btnResult.setVisibility(Button.VISIBLE);
btnNext.setVisibility(ImageView.INVISIBLE);
}else{
btnNext.setVisibility(ImageView.VISIBLE);
}
if(CurrentRecord != 1)
{
btnPrevious.setVisibility(ImageView.VISIBLE);
}else{
btnPrevious.setVisibility(ImageView.INVISIBLE);
}
}
else{
btnResult.setVisibility(Button.INVISIBLE);
btnNext.setVisibility(ImageView.INVISIBLE);
btnPrevious.setVisibility(ImageView.INVISIBLE);
}
}
private synchronized void getCheckboxStatus(){
OpenDatabase();
int isRadioSelected = mDbHelper.getQuickExamSelcted(mSQLiteDatabase, intCount,intResultID);
CloseDataBase();
if(isRadioSelected == 0){
RadioUnchecked(1);
}
else if(isRadioSelected == 1){
RadioUnchecked(2);
}
else if(isRadioSelected == 2){
RadioUnchecked(3);
}
else if(isRadioSelected == 3){
RadioUnchecked(4);
}
else{
rbtn1.setChecked(false);
rbtn2.setChecked(false);
rbtn3.setChecked(false);
rbtn4.setChecked(false);
rbtn1.setTag(Constant.UNCHECK);
rbtn2.setTag(Constant.UNCHECK);
rbtn3.setTag(Constant.UNCHECK);
rbtn4.setTag(Constant.UNCHECK);
rbtn1.setButtonDrawable(R.drawable.radio_button_normal);
rbtn2.setButtonDrawable(R.drawable.radio_button_normal);
rbtn3.setButtonDrawable(R.drawable.radio_button_normal);
rbtn4.setButtonDrawable(R.drawable.radio_button_normal);
}
}
//***********************************************************************************************************************
/**
* @author Manisha
* @param none
* @return void
* @use This function is used for InsertQuickTestExam
*/
private synchronized void InsertQuickTestExam(){
OpenDatabase();
intResultID = mDbHelper.getQuickResultID(mSQLiteDatabase);
isRecordExist = mDbHelper.checkRecordExist_QuickExam(mSQLiteDatabase, intCount, intResultID);
CloseDataBase();
if(isRecordExist>0){
if(rbtn1.isChecked()){
if(strResult1.trim().equals(Constant.FULLTEST_CATEGORY.BW_GUARDIAN)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount, intResultID, 1, 0, 0, 0,0);
CloseDataBase();
}
else if(strResult1.trim().equals(Constant.FULLTEST_CATEGORY.VB_RELATIONIST)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 1, 0, 0,0);
CloseDataBase();
}
else if(strResult1.trim().equals(Constant.FULLTEST_CATEGORY.BD_CREATOR)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 0, 1, 0,0);
CloseDataBase();
}
else if(strResult1.trim().equals(Constant.FULLTEST_CATEGORY.BS_ACHIEVER)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 0, 0, 1,0);
CloseDataBase();
}
}
else if(rbtn2.isChecked()){
if(strResult2.trim().equals(Constant.FULLTEST_CATEGORY.BW_GUARDIAN)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 1, 0, 0, 0,1);
CloseDataBase();
}
else if(strResult2.trim().equals(Constant.FULLTEST_CATEGORY.VB_RELATIONIST)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 1, 0, 0,1);
CloseDataBase();
}
else if(strResult2.trim().equals(Constant.FULLTEST_CATEGORY.BD_CREATOR)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount, intResultID, 0, 0, 1, 0,1);
CloseDataBase();
}
else if(strResult2.trim().equals(Constant.FULLTEST_CATEGORY.BS_ACHIEVER)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 0, 0, 1,1);
CloseDataBase();
}
}
else if(rbtn3.isChecked()){
if(strResult3.trim().equals(Constant.FULLTEST_CATEGORY.BW_GUARDIAN)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 1, 0, 0, 0,2);
CloseDataBase();
}
else if(strResult3.trim().equals(Constant.FULLTEST_CATEGORY.VB_RELATIONIST)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 1, 0, 0,2);
CloseDataBase();
}
else if(strResult3.trim().equals(Constant.FULLTEST_CATEGORY.BD_CREATOR)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount, intResultID, 0, 0, 1, 0,2);
CloseDataBase();
}
else if(strResult3.trim().equals(Constant.FULLTEST_CATEGORY.BS_ACHIEVER)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 0, 0, 1,2);
CloseDataBase();
}
}
else if(rbtn4.isChecked()){
if(strResult4.trim().equals(Constant.FULLTEST_CATEGORY.BW_GUARDIAN)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 1, 0, 0, 0,3);
CloseDataBase();
}
else if(strResult4.trim().equals(Constant.FULLTEST_CATEGORY.VB_RELATIONIST)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 1, 0, 0,3);
CloseDataBase();
}
else if(strResult4.trim().equals(Constant.FULLTEST_CATEGORY.BD_CREATOR)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount, intResultID, 0, 0, 1, 0,3);
CloseDataBase();
}
else if(strResult4.trim().equals(Constant.FULLTEST_CATEGORY.BS_ACHIEVER)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 0, 0, 1,3);
//System.out.println("strresult===="+intCount+" "+intResultID );
CloseDataBase();
}
}
else{
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 0, 0, 0,5);
CloseDataBase();
}
}
else {
if(rbtn1.isChecked()){
if(strResult1.trim().equals(Constant.FULLTEST_CATEGORY.BW_GUARDIAN)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount, intResultID, 1, 0, 0, 0,0);
CloseDataBase();
}
else if(strResult1.trim().equals(Constant.FULLTEST_CATEGORY.VB_RELATIONIST)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 1, 0, 0,0);
CloseDataBase();
}
else if(strResult1.trim().equals(Constant.FULLTEST_CATEGORY.BD_CREATOR)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 0, 1,0,0);
CloseDataBase();
}
else if(strResult1.trim().equals(Constant.FULLTEST_CATEGORY.BS_ACHIEVER)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 0, 0, 1,0);
CloseDataBase();
}
}
else if(rbtn2.isChecked()){
if(strResult2.trim().equals(Constant.FULLTEST_CATEGORY.BW_GUARDIAN)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount,intResultID, 1, 0, 0, 0,1);
System.out.println("strresultinsert===="+intCount+" "+intResultID );
CloseDataBase();
}
else if(strResult2.trim().equals(Constant.FULLTEST_CATEGORY.VB_RELATIONIST)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 1, 0, 0,1);
CloseDataBase();
}
else if(strResult2.trim().equals(Constant.FULLTEST_CATEGORY.BD_CREATOR)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount, intResultID, 0, 0, 1, 0,1);
CloseDataBase();
}
else if(strResult2.trim().equals(Constant.FULLTEST_CATEGORY.BS_ACHIEVER)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 0, 0, 1,1);
CloseDataBase();
}
}
else if(rbtn3.isChecked()){
if(strResult3.trim().equals(Constant.FULLTEST_CATEGORY.BW_GUARDIAN)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount,intResultID, 1, 0, 0, 0,2);
CloseDataBase();
}
else if(strResult3.trim().equals(Constant.FULLTEST_CATEGORY.VB_RELATIONIST)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 1, 0, 0,2);
CloseDataBase();
}
else if(strResult3.trim().equals(Constant.FULLTEST_CATEGORY.BD_CREATOR)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount, intResultID, 0, 0, 1, 0,2);
CloseDataBase();
}
else if(strResult3.trim().equals(Constant.FULLTEST_CATEGORY.BS_ACHIEVER)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 0, 0, 1,2);
CloseDataBase();
}
}
else if(rbtn4.isChecked()){
if(strResult4.trim().equals(Constant.FULLTEST_CATEGORY.BW_GUARDIAN)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount,intResultID, 1, 0, 0, 0,3);
CloseDataBase();
}
else if(strResult4.trim().equals(Constant.FULLTEST_CATEGORY.VB_RELATIONIST)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 1, 0, 0,3);
CloseDataBase();
}
else if(strResult4.trim().equals(Constant.FULLTEST_CATEGORY.BD_CREATOR)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount, intResultID, 0, 0, 1, 0,3);
CloseDataBase();
}
else if(strResult4.trim().equals(Constant.FULLTEST_CATEGORY.BS_ACHIEVER)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 0, 0, 1,3);
CloseDataBase();
}
}
}
}
/**THIS FUNCTION IS USED FOR OPEN DATABASE */
private DbHelper mDbHelper=null;
private SQLiteDatabase mSQLiteDatabase=null;
private void OpenDatabase()
{
try{
if(mDbHelper==null && mSQLiteDatabase==null){
mDbHelper = new DbHelper(FullTest.this);
mSQLiteDatabase = mDbHelper.getWritableDatabase();
// mSQLiteDatabase.setLockingEnabled(true);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
/**THIS FUNCTION IS USED FOR CLOSE DATABASE */
private void CloseDataBase()
{
try{
if(mDbHelper!=null && mSQLiteDatabase!=null){
mSQLiteDatabase.close();
mDbHelper.close();
mSQLiteDatabase=null;
mDbHelper=null;
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
=======================================
3)DbConstant.java
package com.drc.mrs;
public class DbConstant {
public static final class DB{
public static final String DATABASENAME = "DBCodeForU";
public static final int DB_VERSION = 2;
}
public static final class QUICKTEST_RESULT{
public static final String QUICKTEST_RESULT_TABLE = "QuickTestResult";
public static final String RESULT_ID = "result_id";
public static final String PLAYER_NAME = "player_name";
public static final String RESULT_SHOW = "result_show";
public static final String QUICK_OR_FULL = "quick_full";
public static final String RESULT_GUARDIAN = "result_guardian";
public static final String RESULT_RELATIONIST = "result_relationist";
public static final String RESULT_CREATOR = "result_creator";
public static final String RESULT_ACHIEVER = "reslult_achiever";
}
public static final class QUICKTEST_EXAM{
public static final String QUICKTEST_EXAM_TABLE = "QuickTestExam";
public static final String QUICK_TEST_ID = "quick_test_id";
public static final String QUICK_TEST_QUES_ID = "quick_test_ques_id";
public static final String RESULT_ID = "result_id";
public static final String GUARDIAN = "guardian";
public static final String RELATIONIST = "relationist";
public static final String CREATOR = "creator";
public static final String ACHIEVER = "achiever";
public static final String SELECTED = "selected";
}
}
========================================
For get result data
============
public void getResultData() {
Cursor c = mDbHelper.GetResultData(mSQLiteDatabase,1);
if(c!=null){
if(c.getCount() > 0){
c.moveToFirst();
while(c.isAfterLast() == false){
alstResultID.add(c.getString(0));
alstPlayerName.add(c.getString(1));
alstGuardian.add(c.getString(2));
alstRelationist.add(c.getString(3));
alstCreator.add(c.getString(4));
alstAchiever.add(c.getString(5));
alstResult_show.add(c.getString(6));
alstQuick_Full.add(c.getString(7));
c.moveToNext();
};
}
c.close();
}
}
==============================================
For get result data
===========
intResultID = getIntent().getExtras().getInt(Constant.RESULT_INTENT.RESULT_ID, 0);
OpenDatabase(Results.this);
int total[] = mDbHelper.QUICKTEST_GUARDIAN_TOTAL(mSQLiteDatabase, intResultID);
intGuardian = total[0];
intRelationist = total[1];
intCreator = total[2];
intAchiever = total[3];
CloseDataBase(Results.this);
=============================================
*******************************************************************************
=============================================
New
1)package com.ovte.letsrecycle;
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;
}
}
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);
}*/
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);
}
/*********************************************************************************************************/
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);
}
/*********************************************************************************************************/
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)DBConstant
==============
package com.ovte.letsrecycle;
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();
}
}
/**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();
}
}
}
USE OF FUNCTION
===========
======================
UPDATECOllection
public void onClick(DialogInterface dialog, int which) {
if(mCommonClass.CheckNetwork(FinalizedOrder.this)){
new Send_FinalisedOrder().execute("Send Collection");
}else{
DBConstant.OpenDatabase(FinalizedOrder.this);
DBConstant.mDBHelper.Update_Collection_info(DBConstant.mSQLiteDatabase,
mSharedPreferencesRead.getString(Constant.LEADSPENDING_SHARED.LPS_APPOINTMENT_ID, ""),
mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, ""),
GetDateTimeFormat(System.currentTimeMillis()));
DBConstant.CloseDataBase();
Finalized_Done_Alert();
}
dialog.cancel();
return;
}
=====================
/**This function use for get Price And ParaValue*/
private float Price=0f;
private String Para_value="";
private void GetPriceAndParaValue(){
String para_unit_id="";
DBConstant.OpenDatabase(this);
Cursor c = DBConstant.mDBHelper.Select_PRODUCT_PRICE(DBConstant.mSQLiteDatabase, mSharedPreferencesRead.getString(Constant.MAINPRODUCT_SHARED.MPS_PRODUCT_ID, ""), mSharedPreferencesRead.getString(Constant.LEADSPENDING_SHARED.LPS_PRICE_GROUP, ""));
if(c!=null){
if(c.getCount() > 0){
c.moveToFirst();
para_unit_id=c.getString(2);
Price=(float)c.getFloat(3);
c.close();
}
else{
c.close();
}
}
Para_value=DBConstant.mDBHelper.Select_PARAMETER_PARAVALUE(DBConstant.mSQLiteDatabase,para_unit_id);
DBConstant.CloseDataBase();
// String Price_Paravalue=String.format("%s %s / %s",Constant.RUPEES,Price,Para_value);
// txtrate_parameter.setText(Price_Paravalue);
SetRateParaValue();
SetRate();
}
======================
/**This function use for get Price And ParaValue*/
private float Price=0f;
private String Para_value="";
private void GetPriceAndParaValue(){
String para_unit_id="";
DBConstant.OpenDatabase(this);
Cursor c = DBConstant.mDBHelper.Select_PRODUCT_PRICE(DBConstant.mSQLiteDatabase, mSharedPreferencesRead.getString(Constant.MAINPRODUCT_SHARED.MPS_PRODUCT_ID, ""), mSharedPreferencesRead.getString(Constant.LEADSPENDING_SHARED.LPS_PRICE_GROUP, ""));
if(c!=null){
if(c.getCount() > 0){
c.moveToFirst();
para_unit_id=c.getString(2);
Price=(float)c.getFloat(3);
c.close();
}
else{
c.close();
}
}
Para_value=DBConstant.mDBHelper.Select_PARAMETER_PARAVALUE(DBConstant.mSQLiteDatabase,para_unit_id);
DBConstant.CloseDataBase();
// String Price_Paravalue=String.format("%s %s / %s",Constant.RUPEES,Price,Para_value);
// txtrate_parameter.setText(Price_Paravalue);
SetRateParaValue();
SetRate();
}
================
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if(mCommonClass.CheckNetwork(FinalizedOrder.this)){
new Send_FinalisedOrder().execute("Send Collection");
}else{
DBConstant.OpenDatabase(FinalizedOrder.this);
DBConstant.mDBHelper.Update_Collection_info(DBConstant.mSQLiteDatabase,
mSharedPreferencesRead.getString(Constant.LEADSPENDING_SHARED.LPS_APPOINTMENT_ID, ""),
mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, ""),
GetDateTimeFormat(System.currentTimeMillis()));
DBConstant.CloseDataBase();
Finalized_Done_Alert();
}
dialog.cancel();
return;
}
});
=====================================
3)package com.ovte.letsrecycle;
import java.util.ArrayList;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class LeadsPending extends Activity{
private SharedPreferences mSharedPreferencesRead=null;
private SharedPreferences mSharedPreferencesWrite=null;
private CommonClass mCommonClass=new CommonClass();
private LeadsPending_BaseAdapter mLeadsPending_BaseAdapter=null;
private ListView lst_leadspending=null;
private ArrayList<String> Alst_appointment_id=null,
Alst_app_date_time=null,
Alst_customer_id=null,
Alst_customer_name=null,
Alst_customr_code=null,
Alst_address=null,
Alst_add1 = null,
Alst_add2 = null,
Alst_City = null,
Alst_State = null,
Alst_Country = null,
Alst_Zipcode = null,
Alst_mobile_no=null,
Alst_landmark=null,
Alst_price_group=null,
Alst_lattitude=null,
Alst_longitude=null,
Alst_vat=null,
Alst_vat_val=null;
private Button btn_Search = null;
private EditText edt_customreName = null;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.xleadspending);
mSharedPreferencesRead = getSharedPreferences(Constant.SHAREDPREFERENCES,MODE_WORLD_READABLE);
mSharedPreferencesWrite=getSharedPreferences(Constant.SHAREDPREFERENCES, MODE_WORLD_WRITEABLE);
Alst_appointment_id=new ArrayList<String>();
Alst_app_date_time=new ArrayList<String>();
Alst_customer_id=new ArrayList<String>();
Alst_customer_name=new ArrayList<String>();
Alst_customr_code=new ArrayList<String>();
Alst_address=new ArrayList<String>();
Alst_add1 = new ArrayList<String>();
Alst_add2 = new ArrayList<String>();
Alst_City = new ArrayList<String>();
Alst_State = new ArrayList<String>();
Alst_Country = new ArrayList<String>();
Alst_Zipcode = new ArrayList<String>();
Alst_mobile_no=new ArrayList<String>();
Alst_landmark=new ArrayList<String>();
Alst_price_group=new ArrayList<String>();
Alst_lattitude=new ArrayList<String>();
Alst_longitude=new ArrayList<String>();
Alst_vat=new ArrayList<String>();
Alst_vat_val = new ArrayList<String>();
Button btn_back=(Button)findViewById(R.id.btn_back);
btn_back.setVisibility(Button.VISIBLE);
btn_back.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
Button btn_Refresh=(Button)findViewById(R.id.btn_reload);
btn_Refresh.setVisibility(Button.VISIBLE);
btn_Refresh.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
getData_Refresh();
}
});
edt_customreName = (EditText)findViewById(R.id.edt_custName);
btn_Search = (Button)findViewById(R.id.btn_Find);
btn_Search.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(edt_customreName.getText().toString().trim().equals("")){
Log.i(Constant.TAG,"True Condition "+edt_customreName.getText().toString().trim());
ClearData();
getPendingLeads("");
if(mLeadsPending_BaseAdapter != null){
mLeadsPending_BaseAdapter.Update_Data_Record();
mLeadsPending_BaseAdapter.notifyDataSetChanged();
}
}else{
Log.i(Constant.TAG,"False Condition "+edt_customreName.getText().toString().trim());
if(check_collection()){
Finalized_Previous_Alert();
}else{
ClearData();
getPendingLeads(edt_customreName.getText().toString().trim());
if(mLeadsPending_BaseAdapter != null){
mLeadsPending_BaseAdapter.Update_Data_Record();
mLeadsPending_BaseAdapter.notifyDataSetChanged();
}
}
}
}
});
lst_leadspending=(ListView)findViewById(R.id.lst_leadspending);
getData_Refresh();
/*if(mCommonClass.CheckNetwork(this)){
new CheckPendingLeadStatus().execute("checkpending Leads Finilized or not");
}else{
InitData();
}*/
}
private void getData_Refresh(){
if(mCommonClass.CheckNetwork(this)){
new CheckPendingLeadStatus().execute("checkpending Leads Finilized or not");
}else{
InitData();
}
}
/*private boolean check_finilized(){
boolean check = false;
for(int i=0;i< mLeadsPending_BaseAdapter.BoolAppointment_Status.length;i++){
if(mLeadsPending_BaseAdapter.BoolAppointment_Status[i]){
Finalized_Previous_Alert();
check = false;
}else{
check = true;
}
}
return check;
}*/
private boolean check_collection(){
boolean status = false;
for(int i=0;i < Alst_appointment_id.size();i++){
if(Check_Appointment_Collection(Alst_appointment_id.get(i).toString().trim())){
status = true;
break;
}
}
return status;
}
private void InitData(){
ClearData();
if(mCommonClass.CheckNetwork(this)){
new GetPendingLead().execute("Leads Pending");
}else{
getPendingLeads("");
}
}
private void ClearData(){
Alst_appointment_id.clear();
Alst_app_date_time.clear();
Alst_customer_id.clear();
Alst_customer_name.clear();
Alst_customr_code.clear();
Alst_address.clear();
Alst_add1.clear();
Alst_add2.clear();
Alst_City.clear();
Alst_State.clear();
Alst_Country.clear();
Alst_Zipcode.clear();
Alst_mobile_no.clear();
Alst_landmark.clear();
Alst_price_group.clear();
Alst_lattitude.clear();
Alst_longitude.clear();
Alst_vat.clear();
Alst_vat_val.clear();
}
/**This class use for check pendinglead status*/
private class CheckPendingLeadStatus extends AsyncTask<String, String,Boolean>{
private ProcessDialog mProcessDialog=null;
@Override
protected void onPreExecute() {
mProcessDialog= new ProcessDialog(LeadsPending.this,Constant.SERVER,Constant.LOADING);
super.onPreExecute();
}
@Override
protected Boolean doInBackground(String... data) {
Boolean Status = false;
try{
DBConstant.OpenDatabase(LeadsPending.this);
Cursor c = DBConstant.mDBHelper.Select_Appointment_Status(DBConstant.mSQLiteDatabase, mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, ""));
if( c != null){
if(c.getCount() > 0){
Log.i(Constant.TAG, "Leads Pending :"+c.getCount());
c.moveToFirst();
while(c.isAfterLast() == false){
// Log.i(Constant.TAG, "Dta : "+c.getString(0).toString());
String apoinment_Id=c.getString(0).toString();
String strURL = getResources().getString(R.string.CHECK_PENDINGLEAD_STATUS_URL);
ArrayList<NameValuePair> mNameValuePair = new ArrayList<NameValuePair>();
mNameValuePair.add(new BasicNameValuePair(Constant.CHECK_LEADSPENDING_STATUS_REQUEST.APPOINTMENT_ID,apoinment_Id));
String result = mCommonClass.PostConnection(strURL, mNameValuePair);
try {
JSONObject jsonLeadsPending = new JSONObject(result);
if(jsonLeadsPending.getString(Constant.COMMON_JSON.TYPE).equals(Constant.COMMON_JSON.OK)){
DBConstant.mDBHelper.Delete_COLLECTION(DBConstant.mSQLiteDatabase,apoinment_Id,mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID,""));
DBConstant.mDBHelper.Delete_PENDING_LEADS_By_Appointment_ID(DBConstant.mSQLiteDatabase,apoinment_Id,mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID,""));
}
} catch (Exception e) {
e.printStackTrace();
}
c.moveToNext();
}
}
if(!c.isClosed()){
c.close();
}
}
DBConstant.CloseDataBase();
Status = true;
}catch (Exception e) {
e.printStackTrace();
}
return Status;
}
@Override
protected void onPostExecute(Boolean result) {
mProcessDialog.dismiss();
InitData();
/* if(result)
{
InitData();
}
else{
Toast.makeText(LeadsPending.this, Constant.SERVERCONNERROR,Toast.LENGTH_SHORT).show();
}*/
super.onPostExecute(result);
}
}
/**This class use for get pending leads*/
private class GetPendingLead extends AsyncTask<String, String,String>{
private ProcessDialog mProcessDialog=null;
@Override
protected void onPreExecute() {
mProcessDialog= new ProcessDialog(LeadsPending.this,Constant.SERVER,Constant.LOADING);
super.onPreExecute();
}
protected String doInBackground(String... params) {
String strURL = getResources().getString(R.string.PENDINGLEAD_URL);
ArrayList<NameValuePair> mNameValuePair = new ArrayList<NameValuePair>();
mNameValuePair.add(new BasicNameValuePair(Constant.LEADSPENDING_REQUEST.COLLECTION_BY,mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, "")));
mNameValuePair.add(new BasicNameValuePair(Constant.LEADSPENDING_REQUEST.LEADSPENDING_ACTION,Constant.LEADSPENDING_REQUEST.LEADSPENDING_ROWS));
return mCommonClass.PostConnection(strURL, mNameValuePair);
}
protected void onPostExecute(String result) {
mProcessDialog.dismiss();
if(result!=null)
{
Log.i(Constant.TAG,"LeadsPending Response = " + result);
try {
JSONObject jsonLeadsPending = new JSONObject(result);
if(jsonLeadsPending.getString(Constant.COMMON_JSON.TYPE).equals(Constant.COMMON_JSON.OK)){
DBConstant.OpenDatabase(LeadsPending.this);
DBConstant.mDBHelper.DELETE_PENDING_LEADS(DBConstant.mSQLiteDatabase);
// DBConstant.mDBHelper.Delete_PENDING_LEADS(DBConstant.mSQLiteDatabase);
// Cursor c = DBConstant.mDBHelper.Select_PENDINGLEADS(DBConstant.mSQLiteDatabase,mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, ""));
// Log.i("Count :----> ", "Total Records == "+c.getCount());
// vat_value=(int)jsonLeadsPending.getInt(Constant.LEADSPENDING_JSON.VAT_VALUE);
JSONObject jsonReturnResult = jsonLeadsPending.getJSONObject(Constant.LEADSPENDING_JSON.RETURNRESULT);
// JSONArray jsonArray = jsonReturnResult.names();
// Log.i(Constant.TAG,"jsonArray Response = " + jsonArray.toString());
int total_rows=jsonReturnResult.getInt(Constant.LEADSPENDING_JSON.TOTAL_ROWS);
for (int j = 0; j < total_rows; j++) {
JSONObject jsonOBJName = jsonReturnResult.getJSONObject(String.valueOf(j));
String str_appointment_id = jsonOBJName.getString(Constant.LEADSPENDING_JSON.APPOINTMENT_ID).toString().trim();
String str_app_date_time = jsonOBJName.getString(Constant.LEADSPENDING_JSON.APP_DATE_TIME).toString().trim();
String str_customer_id = jsonOBJName.getString(Constant.LEADSPENDING_JSON.CUSTOMER_ID).toString().trim();
String str_customer_name = jsonOBJName.getString(Constant.LEADSPENDING_JSON.CUSTOMER_NAME).toString().trim();
String str_customr_code = jsonOBJName.getString(Constant.LEADSPENDING_JSON.CUSTOMR_CODE).toString().trim();
String str_add1 = jsonOBJName.getString(Constant.LEADSPENDING_JSON.ADDRESS1).toString().trim();
String str_add2 = jsonOBJName.getString(Constant.LEADSPENDING_JSON.ADDRESS2).toString().trim();
String str_City = jsonOBJName.getString(Constant.LEADSPENDING_JSON.CITY).toString().trim();
String str_State = jsonOBJName.getString(Constant.LEADSPENDING_JSON.STATE).toString().trim();
String str_Country = jsonOBJName.getString(Constant.LEADSPENDING_JSON.COUNTRY).toString().trim();
String str_Zipcode = jsonOBJName.getString(Constant.LEADSPENDING_JSON.ZIPCODE).toString().trim();
/*String Address=BuildAddress(jsonOBJName.getString(Constant.LEADSPENDING_JSON.ADDRESS1).toString().trim(),
jsonOBJName.getString(Constant.LEADSPENDING_JSON.ADDRESS2).toString().trim(),
jsonOBJName.getString(Constant.LEADSPENDING_JSON.CITY).toString().trim(),
jsonOBJName.getString(Constant.LEADSPENDING_JSON.STATE).toString().trim(),
jsonOBJName.getString(Constant.LEADSPENDING_JSON.COUNTRY).toString().trim(),
jsonOBJName.getString(Constant.LEADSPENDING_JSON.ZIPCODE).toString().trim());
Alst_address.add(Address);*/
String str_mobile_no = jsonOBJName.getString(Constant.LEADSPENDING_JSON.MOBILE_NO).toString().trim();
String str_landmark = jsonOBJName.getString(Constant.LEADSPENDING_JSON.LANDMARK).toString().trim();
String str_price_group = jsonOBJName.getString(Constant.LEADSPENDING_JSON.PRICE_GROUP).toString().trim();
String str_lattitude = jsonOBJName.getString(Constant.LEADSPENDING_JSON.LATTITUDE).toString().trim();
String str_longitude = jsonOBJName.getString(Constant.LEADSPENDING_JSON.LONGITUDE).toString().trim();
String str_vat = jsonOBJName.getString(Constant.LEADSPENDING_JSON.VAT).toString().trim();
String str_vat_val = jsonOBJName.getString(Constant.LEADSPENDING_JSON.VAT_VAL).toString().trim();
/* Log.i(Constant.TAG,"Id "+Alst_appointment_id.get(0).toString().trim());
Log.i(Constant.TAG, "Date "+Alst_app_date_time.get(0).toString().trim());
Log.i(Constant.TAG, "Cust_id : "+ Alst_customer_id.get(0).toString().trim());
Log.i(Constant.TAG, "Name : "+Alst_customer_name.get(0).toString());
Log.i(Constant.TAG, "Add : "+ Alst_address.get(0).toString());
Log.i(Constant.TAG, "Address1 :"+Alst_add1.get(0).toString().trim());
Log.i(Constant.TAG, "Adderss2 :"+Alst_add2.get(0).toString().trim());
Log.i(Constant.TAG, "City :" + Alst_City.get(0).toString().trim());
Log.i(Constant.TAG, "State :" +Alst_State.get(0).toString().trim());
Log.i(Constant.TAG, "Country :"+Alst_Country.get(0).toString().trim());
Log.i(Constant.TAG, "ZipCode :"+Alst_Zipcode.get(0).toString().trim());
Log.i(Constant.TAG, "Mob No :"+ Alst_mobile_no.get(0).toString().trim());
Log.i(Constant.TAG, "Landmark :"+ Alst_landmark.get(0).toString().trim());
Log.i(Constant.TAG, "Price Group :"+ Alst_price_group.get(0).toString().trim());
Log.i(Constant.TAG, "Latitude :"+ Alst_lattitude.get(0).toString().trim());
Log.i(Constant.TAG, "Longitide :"+ Alst_longitude.get(0).toString().trim()); */// String.valueOf(vat_value), Alst_vat.get(0).toString().trim());)
if(Check_Finalize_User_Collection_Exists(str_appointment_id)){
Log.i(Constant.TAG, "Appointment-id "+str_appointment_id + " all ready finalized");
}else{
DBConstant.mDBHelper.Insert_PendingLead(DBConstant.mSQLiteDatabase, str_appointment_id,str_app_date_time, str_customer_id, str_customer_name, str_customr_code, str_add1, str_add2, str_City, str_State, str_Country, str_Zipcode, str_mobile_no, str_landmark, str_price_group, str_lattitude, str_longitude, String.valueOf(str_vat_val), str_vat, mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, ""));
}
}
DBConstant.CloseDataBase();
getPendingLeads("");
// mLeadsPending_BaseAdapter=new LeadsPending_BaseAdapter();
// lst_leadspending.setAdapter(mLeadsPending_BaseAdapter);
}else{
Toast.makeText(LeadsPending.this, jsonLeadsPending.getString(Constant.COMMON_JSON.ERR_MSG).toString(), Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
else{
Toast.makeText(LeadsPending.this, Constant.SERVERCONNERROR,Toast.LENGTH_SHORT).show();
}
super.onPostExecute(result);
}
}
/** This fuction is used to fetch data of Pending Leads form SQLite Database*/
public void getPendingLeads(String name){
DBConstant.OpenDatabase(LeadsPending.this);
// Cursor cr = DBConstant.mDBHelper.Select_PENDINGLEADS(DBConstant.mSQLiteDatabase);
Cursor c = null;
if(name.equals("")){
c = DBConstant.mDBHelper.Select_PENDINGLEADS(DBConstant.mSQLiteDatabase,mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, ""));
}else{
c = DBConstant.mDBHelper.Select_PENDINGLEADS(DBConstant.mSQLiteDatabase,mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, ""),name);
}
if( c != null){
if(c.getCount() > 0){
Log.i(Constant.TAG, "Leads Pending :"+c.getCount());
c.moveToFirst();
while(c.isAfterLast() == false){
Alst_appointment_id.add(c.getString(1).toString());
Alst_customer_id.add(c.getString(2).toString());
Alst_app_date_time.add(c.getString(3).toString());
Alst_customer_name.add(c.getString(4).toString());
Alst_customr_code.add(c.getString(5).toString());
Alst_add1.add(c.getString(6).toString());
Alst_add2.add(c.getString(7).toString());
Alst_City.add(c.getString(8).toString());
Alst_State.add(c.getString(9).toString());
Alst_Country.add(c.getString(10).toString());
Alst_Zipcode.add(c.getString(11).toString());
Alst_mobile_no.add(c.getString(12).toString());
Alst_landmark.add(c.getString(13).toString());
Alst_price_group.add(c.getString(14).toString());
Alst_longitude.add(c.getString(15).toString());
Alst_lattitude.add(c.getString(16).toString());
Alst_vat.add(c.getString(18).toString());
Alst_vat_val.add(c.getString(17).toString());
String Address=BuildAddress(c.getString(6).toString(),
c.getString(7).toString(),
c.getString(8).toString(),
c.getString(9).toString(),
c.getString(10).toString(),
c.getString(11).toString());
Alst_address.add(Address);
c.moveToNext();
}
if(mLeadsPending_BaseAdapter == null){
mLeadsPending_BaseAdapter=new LeadsPending_BaseAdapter();
lst_leadspending.setAdapter(mLeadsPending_BaseAdapter);
}else{
mLeadsPending_BaseAdapter.Update_Data_Record();
mLeadsPending_BaseAdapter.notifyDataSetChanged();
}
}else{
Toast.makeText(LeadsPending.this, Constant.NO_RECORD_FOUND, Toast.LENGTH_SHORT).show();
}
if(!c.isClosed()){
c.close();
}
}
DBConstant.CloseDataBase();
}
/**This function use for merge Address*/
private String BuildAddress(String address1,String address2,String city,String state,String country,String zipcode){
String Address="";
if(!address1.equals("")){
Address=String.format("%s",address1);
}
if(!address2.equals("")){
if(Address.equals("")){
Address=String.format("%s",address2);
}
else{
Address=String.format("%s, %s", Address,address2);
}
}
if(!city.equals("")){
Address=String.format("%s, %s", Address,city);
}
if(!state.equals("")){
Address=String.format("%s, %s", Address,state);
}
if(!country.equals("")){
Address=String.format("%s, %s", Address,country);
}
if(!zipcode.equals("")){
Address=String.format("%s, %s", Address,zipcode);
}
return Address;
}
private class LeadsPending_BaseAdapter extends BaseAdapter{
public boolean BoolAppointment_Status[]=null;
private LayoutInflater mLayoutInflater=null;
public LeadsPending_BaseAdapter() {
mLayoutInflater=LayoutInflater.from(getApplicationContext());
Update_Data_Record();
}
public void Update_Data_Record() {
BoolAppointment_Status=null;
BoolAppointment_Status=new boolean[Alst_appointment_id.size()];
for(int i=0;i < Alst_appointment_id.size();i++){
if(Check_Appointment_Collection(Alst_appointment_id.get(i).toString().trim())){
BoolAppointment_Status[i]=true;
}
else{
BoolAppointment_Status[i]=false;
}
}
}
@Override
public int getCount() {
return Alst_appointment_id.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if(convertView==null){
convertView=mLayoutInflater.inflate(R.layout.xleadspending_customerdetails,null);
}
TextView txt_customer_name=(TextView)convertView.findViewById(R.id.txt_customer_name);
txt_customer_name.setText(Alst_customer_name.get(position));
TextView txt_customer_code=(TextView)convertView.findViewById(R.id.txt_customer_code);
txt_customer_code.setText(Alst_customr_code.get(position));
TextView txt_customer_address=(TextView)convertView.findViewById(R.id.txt_customer_address);
txt_customer_address.setText(Alst_address.get(position));
LinearLayout lly_customer_phoneno=(LinearLayout)convertView.findViewById(R.id.lly_customer_phoneno);
lly_customer_phoneno.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
TelephoneDial(Alst_mobile_no.get(position).toString());
}
});
TextView txt_customer_phoneno=(TextView)convertView.findViewById(R.id.txt_customer_phoneno);
txt_customer_phoneno.setText(Alst_mobile_no.get(position));
ImageView img_customer_landmark=(ImageView)convertView.findViewById(R.id.img_customer_landmark);
img_customer_landmark.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
MapLocation(Alst_lattitude.get(position).toString(),Alst_longitude.get(position).toString());
}
});
TextView txt_customer_landmark=(TextView)convertView.findViewById(R.id.txt_customer_landmark);
txt_customer_landmark.setText(Alst_landmark.get(position));
txt_customer_landmark.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
MapLocation(Alst_lattitude.get(position).toString(),Alst_longitude.get(position).toString());
}
});
final ImageView img_appcollection_notification=(ImageView)convertView.findViewById(R.id.img_appcollection_notification);
if(BoolAppointment_Status[position]){
img_appcollection_notification.setVisibility(ImageView.VISIBLE);
}
else{
img_appcollection_notification.setVisibility(ImageView.INVISIBLE);
}
ImageView img_customer_home_reached=(ImageView)convertView.findViewById(R.id.img_customer_home_reached);
img_customer_home_reached.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Reached(position,img_appcollection_notification.isShown());
}
});
ImageView img_customer_reached=(ImageView)convertView.findViewById(R.id.img_customer_reached);
img_customer_reached.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Reached(position,img_appcollection_notification.isShown());
}
});
TextView txt_appdatetime=(TextView)convertView.findViewById(R.id.txt_appdatetime);
txt_appdatetime.setText(Alst_app_date_time.get(position).toString());
return convertView;
}
}
/**This function use for check collection count or not*/
private boolean Check_Appointment_Collection(String appointment_id){
boolean Status=false;
DBConstant.OpenDatabase(this);
if(DBConstant.mDBHelper.Select_COLLECTION_COUNT_APPOINTMENT_FLAG(DBConstant.mSQLiteDatabase, appointment_id,mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, "")) > 0){
Status=true;
}
else{
Status=false;
}
DBConstant.CloseDataBase();
return Status;
}
//// /**This function use for check User collection Exists or not*/
// private boolean Check_User_Collection_Exists(){
// boolean Status=false;
// DBConstant.OpenDatabase(this);
// if(DBConstant.mDBHelper.Select_COLLECTION_COUNT_USERID(DBConstant.mSQLiteDatabase,mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, "")) > 0){
// Status=true;
// }
// else{
// Status=false;
// }
// DBConstant.CloseDataBase();
// return Status;
// }
// /**This function use for check User collection Exists or not*/
// private boolean Check_User_Collection_Exists(int position){
// boolean Status=false;
// DBConstant.OpenDatabase(this);
// if(DBConstant.mDBHelper.Select_COLLECTION_COUNT_APPOINTMENT_FLAG(DBConstant.mSQLiteDatabase, Alst_appointment_id.get(position).toString().trim(),mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, "")) > 0){
// Status=true;
// }
// else{
// Status=false;
// }
// DBConstant.CloseDataBase();
// return Status;
// }
// /**This function use for check User collection Exists or not*/
// private boolean Check_User_Collection_Exists_Flag(int position){
// boolean Status=false;
// DBConstant.OpenDatabase(this);
// if(DBConstant.mDBHelper.Select_COLLECTION_COUNT_APPOINTMENT_FLAG(DBConstant.mSQLiteDatabase, Alst_appointment_id.get(position).toString().trim(),mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, "")) > 0){
// Status=true;
// }
// else{
// Status=false;
// }
// DBConstant.CloseDataBase();
// return Status;
// }
// /**This function use for check Finalize User collection Exists or not*/
private boolean Check_Finalize_User_Collection_Exists(String appointment_id){
boolean Status=false;
if(DBConstant.mDBHelper.Check_Pending_Leads_Status(DBConstant.mSQLiteDatabase, appointment_id, mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, "")) > 0){
Status=true;
}
else{
Status=false;
}
return Status;
}
private void Reached(int position,boolean visible){
if(visible){
GoToReach(position);
}
else{
boolean flag_status=true;
if(mLeadsPending_BaseAdapter!=null){
for(int i=0;i< mLeadsPending_BaseAdapter.BoolAppointment_Status.length;i++){
if(mLeadsPending_BaseAdapter.BoolAppointment_Status[i]){
Finalized_Previous_Alert();
flag_status=false;
break;
}
}
}
if(flag_status){
GoToReach(position);
}
}
}
private void GoToReach(int position){
// if(mCommonClass.CheckNetwork(LeadsPending.this)){
ClearSharedPreferences();
SharedPreferences.Editor mSharedPreferencesEdit = mSharedPreferencesWrite.edit();
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_APPOINTMENT_ID, Alst_appointment_id.get(position).toString().trim());
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_APP_DATE_TIME, Alst_app_date_time.get(position).toString().trim());
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_CUSTOMER_ID, Alst_customer_id.get(position).toString().trim());
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_CUSTOMER_NAME, Alst_customer_name.get(position).toString().trim());
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_CUSTOMR_CODE, Alst_customr_code.get(position).toString().trim());
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_ADDRESS, Alst_address.get(position).toString().trim());
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_MOBILE_NO, Alst_mobile_no.get(position).toString().trim());
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_LANDMARK, Alst_landmark.get(position).toString().trim());
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_PRICE_GROUP, Alst_price_group.get(position).toString().trim());
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_LATTITUDE, Alst_lattitude.get(position).toString().trim());
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_LONGITUDE, Alst_longitude.get(position).toString().trim());
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_VAT, Alst_vat.get(position).toString().trim().toUpperCase());
mSharedPreferencesEdit.putFloat(Constant.LEADSPENDING_SHARED.LPS_VAT_VAL,Float.parseFloat(Alst_vat_val.get(position)));
mSharedPreferencesEdit.commit();
Reached_Location();
// }
}
/**This function for Finalized Previous Alert*/
private void Finalized_Previous_Alert() {
AlertDialog mAlertDialog = new AlertDialog.Builder(this).create();
mAlertDialog.setTitle(Constant.FINALIZED_MESSAGE.FINALIZED_TITLE);
mAlertDialog.setMessage(Constant.FINALIZED_MESSAGE.FINALIZED_PREVIOUS_COLLECTION);
mAlertDialog.setCancelable(false);
mAlertDialog.setCanceledOnTouchOutside(false);
mAlertDialog.setButton(Constant.FINALIZED_MESSAGE.OK, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
});
// Create and show the dialog
mAlertDialog.show();
}
private void ClearSharedPreferences(){
SharedPreferences.Editor mSharedPreferencesEdit = mSharedPreferencesWrite.edit();
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_APPOINTMENT_ID, "");
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_APP_DATE_TIME, "");
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_CUSTOMER_ID, "");
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_CUSTOMER_NAME, "");
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_CUSTOMR_CODE, "");
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_ADDRESS, "");
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_MOBILE_NO, "");
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_LANDMARK, "");
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_PRICE_GROUP, "");
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_LATTITUDE, "");
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_LONGITUDE, "");
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_VAT, "");
mSharedPreferencesEdit.putFloat(Constant.LEADSPENDING_SHARED.LPS_VAT_VAL, 0.0f);
mSharedPreferencesEdit.commit();
}
/**This function for conformation to reached*/
private void Reached_Location() {
AlertDialog mAlertDialog = new AlertDialog.Builder(this).create();
mAlertDialog.setTitle(Constant.REACHED_MESSAGE.REACHED_TITLE);
mAlertDialog.setMessage(Constant.REACHED_MESSAGE.REACHED_TEXT);
mAlertDialog.setCancelable(false);
mAlertDialog.setCanceledOnTouchOutside(false);
mAlertDialog.setButton(Constant.YES, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if(strLatitude!=null && strLongitude!=null){
new SendLatLong().execute("Send Lat Long");
}
else{
Check_Update();
Log.i(Constant.TAG,Constant.LOCATION_MESSAGE);
// Toast.makeText(getApplicationContext(),Constant.LOCATION_MESSAGE, Toast.LENGTH_SHORT).show();
}
return;
}
});
mAlertDialog.setButton2(Constant.NO, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
return;
}
});
// Create and show the dialog
mAlertDialog.show();
}
/**This function for check database update*/
private void Check_Update(){
String LastDateTime="";
DBConstant.OpenDatabase(this);
LastDateTime=DBConstant.mDBHelper.Select_PRODUCT_MAX_DATETIME(DBConstant.mSQLiteDatabase);
DBConstant.CloseDataBase();
if(mCommonClass.CheckNetwork(this)){
Intent mIntent= new Intent(this,MainCategory.class);
GetMaster mGetMaster=new GetMaster(this,LastDateTime,mIntent);
mGetMaster.execute("Get All Data When Update DateTime");
}else{
Intent mIntent= new Intent(this,MainCategory.class);
startActivity(mIntent);
finish();
}
}
/**This function for send reached location*/
private class SendLatLong extends AsyncTask<String,String,String>{
private ProcessDialog mProcessDialog=null;
@Override
protected void onPreExecute() {
super.onPreExecute();
mProcessDialog= new ProcessDialog(LeadsPending.this,Constant.SERVER,Constant.LOADING);
}
@Override
protected String doInBackground(String... params) {
String strURL = getResources().getString(R.string.APPOINTMENT_URL);
ArrayList<NameValuePair> mNameValuePair = new ArrayList<NameValuePair>();
mNameValuePair.add(new BasicNameValuePair(Constant.REACHED_REQUEST.HDN_ACTION,Constant.REACHED_REQUEST.HDN_ACTION_APPOINTMENT));
mNameValuePair.add(new BasicNameValuePair(Constant.REACHED_REQUEST.ADMIN_USERID,mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, "")));
mNameValuePair.add(new BasicNameValuePair(Constant.REACHED_REQUEST.LATITUDE,strLatitude));
mNameValuePair.add(new BasicNameValuePair(Constant.REACHED_REQUEST.LONGITUDE,strLongitude));
mNameValuePair.add(new BasicNameValuePair(Constant.REACHED_REQUEST.CUSTOMER_CODE, mSharedPreferencesRead.getString(Constant.LEADSPENDING_SHARED.LPS_CUSTOMR_CODE, "")));
mNameValuePair.add(new BasicNameValuePair(Constant.REACHED_REQUEST.CUSTOMER_ID,mSharedPreferencesRead.getString(Constant.LEADSPENDING_SHARED.LPS_CUSTOMER_ID, "")));
mNameValuePair.add(new BasicNameValuePair(Constant.REACHED_REQUEST.APPOINTMENT_ID, mSharedPreferencesRead.getString(Constant.LEADSPENDING_SHARED.LPS_APPOINTMENT_ID, "")));
return mCommonClass.PostConnection(strURL, mNameValuePair);
}
@Override
protected void onPostExecute(String result) {
mProcessDialog.dismiss();
if(result!=null)
{
Log.i(Constant.TAG,"Appointment Response = " + result);
try {
JSONObject jsonAppointment = new JSONObject(result);
if(jsonAppointment.getString(Constant.COMMON_JSON.TYPE).equals(Constant.COMMON_JSON.OK)){
// Check_Update();
}else{
Toast.makeText(LeadsPending.this, jsonAppointment.getString(Constant.COMMON_JSON.ERR_MSG).toString(), Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
else{
Toast.makeText(LeadsPending.this, Constant.SERVERCONNERROR,Toast.LENGTH_SHORT).show();
}
Check_Update();
super.onPostExecute(result);
}
}
/**
* @param
* @author piyush
* {@docRoot}
* @see : Use for Dial phone no
* */
private void TelephoneDial(String Phoneno){
Intent iv = new Intent(Intent.ACTION_DIAL,Uri.parse("tel:" + Phoneno));
startActivity(iv);
}
/**
* @param
* @author piyush
* {@docRoot}
* @see This function use for open Google Map*/
private void MapLocation(String Latitude,String Longitude){
try{
// Toast.makeText(LeadsPending.this, "Lati :"+Latitude+"Long :"+Longitude, Toast.LENGTH_SHORT).show();
if( Latitude.equals("0") || Longitude.equals("0")){
Toast.makeText(LeadsPending.this, Constant.LOCATION_NOT_FOUND, Toast.LENGTH_SHORT).show();
}else{
Intent mIntent = new Intent(Intent.ACTION_VIEW);
mIntent.setData(Uri.parse("geo:0,0?q=" + (Latitude+","+Longitude)));
startActivity(mIntent);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void onResume() {
AddLocationManager();
super.onResume();
}
@Override
protected void onPause() {
RemoveLocationManager();
super.onPause();
}
private LocationManager mLocationManager=null;
private LocationListener mLocationListener =null;
private String strLatitude=null,strLongitude=null;
/**Location Update Register*/
private void AddLocationManager() {
if(mLocationManager==null){
mLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
}
if(mLocationManager!=null)
{
if(mLocationManager.isProviderEnabled(Constant.PROVIDER)){
mLocationListener = new MyLocationListener();
mLocationManager.requestLocationUpdates( Constant.PROVIDER, 0, 1, mLocationListener);
}
else{
Toast.makeText(getApplicationContext(), Constant.PROVIDER_NOT,Toast.LENGTH_LONG).show();
mLocationManager=null;
mLocationListener=null;
}
}
}
/**Location Update Remove*/
private void RemoveLocationManager() {
if(mLocationListener!=null && mLocationManager!=null)
{
mLocationManager.removeUpdates(mLocationListener);
mLocationListener=null;
mLocationManager=null;
}
}
/** Class My Location Listener */
private class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location loc)
{
strLatitude=(String.valueOf(loc.getLatitude()));
strLongitude=(String.valueOf(loc.getLongitude()));
}
@Override
public void onProviderDisabled(String provider)
{
}
@Override
public void onProviderEnabled(String provider)
{
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
}/* End of Class MyLocationListener */
public void GoToCategory(){
Intent mIntent= new Intent(this,MainCategory.class);
startActivity(mIntent);
finish();
}
}
package com.xyz.mrs;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DbHelper extends SQLiteOpenHelper{
//This Is For Make Database
public DbHelper(Context context) {
super(context, DbConstant.DB.DATABASENAME, null, DbConstant.DB.DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
//This Is For Make Database Table
String TABLE1 = String.format("CREATE TABLE %s (" +
"%s INTEGER PRIMARY KEY AUTOINCREMENT," +
"%s VARCHAR(50)," +
"%s VARCHAR(50)," +
"%s VARCHAR(50)," +
"%s VARCHAR(50)," +
"%s VARCHAR(50)," +
"%s INEGER," +
"%s INTEGER)",DbConstant.QUICKTEST_RESULT.QUICKTEST_RESULT_TABLE,
DbConstant.QUICKTEST_RESULT.RESULT_ID,
DbConstant.QUICKTEST_RESULT.PLAYER_NAME,
DbConstant.QUICKTEST_RESULT.RESULT_GUARDIAN,
DbConstant.QUICKTEST_RESULT.RESULT_RELATIONIST,
DbConstant.QUICKTEST_RESULT.RESULT_CREATOR,
DbConstant.QUICKTEST_RESULT.RESULT_ACHIEVER,
DbConstant.QUICKTEST_RESULT.RESULT_SHOW,
DbConstant.QUICKTEST_RESULT.QUICK_OR_FULL);
db.execSQL(TABLE1);
String TABLE2 = String.format("CREATE TABLE %s (" +
"%s INTEGER PRIMARY KEY AUTOINCREMENT," +
"%s INTEGER," +
"%s INEGER," +
"%s INTEGER, " +
"%s INTEGER, " +
"%s INTEGER, " +
"%s INTEGER, " +
"%s INTEGER)",DbConstant.QUICKTEST_EXAM.QUICKTEST_EXAM_TABLE,
DbConstant.QUICKTEST_EXAM.QUICK_TEST_ID,
DbConstant.QUICKTEST_EXAM.QUICK_TEST_QUES_ID,
DbConstant.QUICKTEST_EXAM.RESULT_ID,
DbConstant.QUICKTEST_EXAM.GUARDIAN,
DbConstant.QUICKTEST_EXAM.RELATIONIST,
DbConstant.QUICKTEST_EXAM.CREATOR,
DbConstant.QUICKTEST_EXAM.ACHIEVER,
DbConstant.QUICKTEST_EXAM.SELECTED);
db.execSQL(TABLE2);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
db.execSQL("DROP TABLE IF EXISTS "+ DbConstant.QUICKTEST_RESULT.QUICKTEST_RESULT_TABLE);
db.execSQL("DROP TABLE IF EXISTS "+ DbConstant.QUICKTEST_EXAM.QUICKTEST_EXAM_TABLE);
onCreate(db);
}
//***********************************************************************************************************************
public static void InsertQuicktestExam(SQLiteDatabase db,int quick_test_ques_id,int result_id,int guardian,int relationist, int creator, int achiever,int intselected){
ContentValues cv = new ContentValues();
cv.put(DbConstant.QUICKTEST_EXAM.QUICK_TEST_QUES_ID,quick_test_ques_id);
cv.put(DbConstant.QUICKTEST_EXAM.RESULT_ID,result_id);
cv.put(DbConstant.QUICKTEST_EXAM.GUARDIAN,guardian);
cv.put(DbConstant.QUICKTEST_EXAM.RELATIONIST,relationist);
cv.put(DbConstant.QUICKTEST_EXAM.CREATOR,creator);
cv.put(DbConstant.QUICKTEST_EXAM.ACHIEVER,achiever);
cv.put(DbConstant.QUICKTEST_EXAM.SELECTED,intselected);
db.insert(DbConstant.QUICKTEST_EXAM.QUICKTEST_EXAM_TABLE, null,cv);
}
//***********************************************************************************************************************
public static void UpdateQuicktestExam(SQLiteDatabase db,int quick_test_ques_id,int result_id,int intGuardian, int intRelationist,int intCreator, int intAchiever,int intselected){
String strwhere = String.format("%s = %s and %s = %s",DbConstant.QUICKTEST_EXAM.QUICK_TEST_QUES_ID,quick_test_ques_id,DbConstant.QUICKTEST_EXAM.RESULT_ID,result_id);
ContentValues cv = new ContentValues();
cv.put(DbConstant.QUICKTEST_EXAM.QUICK_TEST_QUES_ID,quick_test_ques_id);
cv.put(DbConstant.QUICKTEST_EXAM.RESULT_ID,result_id);
cv.put(DbConstant.QUICKTEST_EXAM.GUARDIAN ,intGuardian);
cv.put(DbConstant.QUICKTEST_EXAM.RELATIONIST, intRelationist);
cv.put(DbConstant.QUICKTEST_EXAM.CREATOR, intCreator);
cv.put(DbConstant.QUICKTEST_EXAM.ACHIEVER, intAchiever);
cv.put(DbConstant.QUICKTEST_EXAM.SELECTED, intselected);
db.update(DbConstant.QUICKTEST_EXAM.QUICKTEST_EXAM_TABLE, cv, strwhere, null);
}
//***********************************************************************************************************************
public int getQuickResultID(SQLiteDatabase db){
int id = 0;
String SQL = String.format("SELECT %s FROM %s WHERE %s = (SELECT MAX(%s) FROM %s)",DbConstant.QUICKTEST_RESULT.RESULT_ID,DbConstant.QUICKTEST_RESULT.QUICKTEST_RESULT_TABLE,DbConstant.QUICKTEST_RESULT.RESULT_ID,DbConstant.QUICKTEST_RESULT.RESULT_ID,DbConstant.QUICKTEST_RESULT.QUICKTEST_RESULT_TABLE);
Cursor cursor = db.rawQuery(SQL,null);
if(cursor!=null){
if(cursor.getCount()>0){
cursor.moveToFirst();
id= cursor.getInt(0);
}
if(!cursor.isClosed()){
cursor.close();
}
}
return id;
}
//***********************************************************************************************************************
public int getQuickExamSelcted(SQLiteDatabase db,int intQuickTest_Id,int intresult_Id){
int id = 5;
String SQL = String.format("SELECT %s From %s WHERE %s = %s and %s = %s",DbConstant.QUICKTEST_EXAM.SELECTED,DbConstant.QUICKTEST_EXAM.QUICKTEST_EXAM_TABLE,DbConstant.QUICKTEST_EXAM.QUICK_TEST_QUES_ID,intQuickTest_Id,DbConstant.QUICKTEST_EXAM.RESULT_ID, intresult_Id);
Cursor cursor = db.rawQuery(SQL,null);
if(cursor!=null){
if(cursor.getCount()>0){
cursor.moveToFirst();
id= cursor.getInt(0);
}
if(!cursor.isClosed()){
cursor.close();
}
}
return id;
}
//***********************************************************************************************************************
public int checkRecordExist_QuickExam(SQLiteDatabase db,int intQuickTest_Id,int intresult_Id){
int count = 0;
String SQL = String.format("SELECT count(*) From %s WHERE %s = %s and %s = %s",DbConstant.QUICKTEST_EXAM.QUICKTEST_EXAM_TABLE,DbConstant.QUICKTEST_EXAM.QUICK_TEST_QUES_ID,intQuickTest_Id,DbConstant.QUICKTEST_EXAM.RESULT_ID, intresult_Id);
Cursor cursor = db.rawQuery(SQL,null);
if(cursor!=null){
if(cursor.getCount()>0){
cursor.moveToFirst();
count = cursor.getInt(0);
}
if(!cursor.isClosed()){
cursor.close();
}
}
return count;
}
//***********************************************************************************************************************
public Cursor GetResultData(SQLiteDatabase db,int result_show){
// String strwhere = "result_show =" + result_show;
String strwhere = String.format("%s = %s",DbConstant.QUICKTEST_RESULT.RESULT_SHOW,result_show);
return db.query(DbConstant.QUICKTEST_RESULT.QUICKTEST_RESULT_TABLE,null, strwhere, null, null, null, null);
}
//***********************************************************************************************************************
public int[] QUICKTEST_GUARDIAN_TOTAL(SQLiteDatabase db,int intresult_Id){
int TOTAL[] = new int[4];
String SQL=String.format("SELECT SUM(%s),SUM(%s),SUM(%s),SUM(%s) from %s where %s = %s",DbConstant.QUICKTEST_EXAM.GUARDIAN,DbConstant.QUICKTEST_EXAM.RELATIONIST,DbConstant.QUICKTEST_EXAM.CREATOR,DbConstant.QUICKTEST_EXAM.ACHIEVER,DbConstant.QUICKTEST_EXAM.QUICKTEST_EXAM_TABLE,DbConstant.QUICKTEST_EXAM.RESULT_ID, intresult_Id);
Cursor c = db.rawQuery(SQL,null);
if(c!=null){
if(c.getCount() > 0){
c.moveToFirst();
TOTAL[0]=c.getInt(0);
TOTAL[1]=c.getInt(1);
TOTAL[2]=c.getInt(2);
TOTAL[3]=c.getInt(3);
}
if(!c.isClosed()){
c.close();
}
}
return TOTAL;
}
//***********************************************************************************************************************
public String getQuickPlayerName(SQLiteDatabase db){
String strName = null;
String SQL = String.format("SELECT %s FROM %s WHERE %s = (SELECT MAX(%s) FROM %s)",DbConstant.QUICKTEST_RESULT.PLAYER_NAME,DbConstant.QUICKTEST_RESULT.QUICKTEST_RESULT_TABLE,DbConstant.QUICKTEST_RESULT.RESULT_ID,DbConstant.QUICKTEST_RESULT.RESULT_ID,DbConstant.QUICKTEST_RESULT.QUICKTEST_RESULT_TABLE);
Cursor cursor = db.rawQuery(SQL,null);
if(cursor!=null){
if(cursor.getCount()>0){
cursor.moveToFirst();
strName = cursor.getString(0);
}
if(!cursor.isClosed()){
cursor.close();
}
}
return strName;
}
//***********************************************************************************************************************
public static void InsertQuicktestResult(SQLiteDatabase db,String player_name,int result_guardian, int result_relationist,int result_creator, int result_achiever, int result_show,int quick_or_full){
ContentValues cv = new ContentValues();
cv.put(DbConstant.QUICKTEST_RESULT.PLAYER_NAME,player_name);
cv.put(DbConstant.QUICKTEST_RESULT.RESULT_GUARDIAN,result_guardian);
cv.put(DbConstant.QUICKTEST_RESULT.RESULT_RELATIONIST,result_relationist);
cv.put(DbConstant.QUICKTEST_RESULT.RESULT_CREATOR,result_creator);
cv.put(DbConstant.QUICKTEST_RESULT.RESULT_ACHIEVER,result_achiever);
cv.put(DbConstant.QUICKTEST_RESULT.RESULT_SHOW,result_show);
cv.put(DbConstant.QUICKTEST_RESULT.QUICK_OR_FULL,quick_or_full);
db.insert(DbConstant.QUICKTEST_RESULT.QUICKTEST_RESULT_TABLE, null,cv);
}
//***********************************************************************************************************************
public static void UpdateQuicktestResult(SQLiteDatabase db,int result_id,String player_name,String guardian,String relationist,String creator, String achiever,int show_result ){
String strwhere = String.format(DbConstant.QUICKTEST_RESULT.RESULT_ID +"= %s ",result_id);
ContentValues cv = new ContentValues();
cv.put(DbConstant.QUICKTEST_RESULT.PLAYER_NAME,player_name);
cv.put(DbConstant.QUICKTEST_RESULT.RESULT_GUARDIAN,guardian);
cv.put(DbConstant.QUICKTEST_RESULT.RESULT_RELATIONIST,relationist);
cv.put(DbConstant.QUICKTEST_RESULT.RESULT_CREATOR,creator);
cv.put(DbConstant.QUICKTEST_RESULT.RESULT_ACHIEVER,achiever);
cv.put(DbConstant.QUICKTEST_RESULT.RESULT_SHOW, show_result);
db.update(DbConstant.QUICKTEST_RESULT.QUICKTEST_RESULT_TABLE, cv, strwhere, null);
}
//***********************************************************************************************************************
public void Delete_Result(SQLiteDatabase db,String result_id){
String WHERE=String.format("%s = %s",DbConstant.QUICKTEST_RESULT.RESULT_ID,result_id);
db.delete(DbConstant.QUICKTEST_RESULT.QUICKTEST_RESULT_TABLE, WHERE, null);
}
}
2)Fulltest.java
package com.drc.mrs;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;
import com.drc.xmlconstant.Dict_FullTestQuestion_Constant;
import com.drc.xmlconstant.Dict_ScoreTableFulltest_Constant;
import com.drc.xmlconstant.Dict_Wording_Constant;
public class FullTest extends Activity implements OnClickListener{
private SharedPreferences mSharedPreferences_Read = null;
private Button btnBack = null;
private Button btnResult = null;
private Button btnPrevious =null;
private Button btnNext = null;
private RadioButton rbtn1 = null;
private RadioButton rbtn2 = null;
private RadioButton rbtn3 = null;
private RadioButton rbtn4 = null;
private TextView txtQuestion_No = null;
private int intTotalQuestion = 35;
private int intCount = 1;
private String strResult1 = null,strResult2 = null;
private String strResult3 = null,strResult4 = null;
private String strQuestion1 = null;
private String strQuestion2 = null;
private String strQuestion3 = null;
private String strQuestion4 = null;
private int intResultID = 0;
private int isRecordExist=0;
private TextView txtCodeOfUTitle = null;
private ImageView imgCodeOfUnderstanding = null;
private int intLanguage_Position=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
Utils.enableStrictMode();
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.xfulltest);
mSharedPreferences_Read = getSharedPreferences(Constant.SHAREDPREFERENCE.COMMAN_SHAREDPREFERENCE, MODE_WORLD_READABLE);
intLanguage_Position = mSharedPreferences_Read.getInt(Constant.SHAREDPREFERENCE.LANGUAGE_POSITION, Constant.SHAREDPREFERENCE.DEFAULT_LANGUAGE_POSITION);
btnBack = (Button)findViewById(R.id.btnBack);
btnBack.setOnClickListener(this);
btnResult = (Button)findViewById(R.id.btnResults);
btnResult.setOnClickListener(this);
btnPrevious = (Button)findViewById(R.id.btnPrevious);
btnPrevious.setOnClickListener(this);
btnNext = (Button)findViewById(R.id.btnNext);
btnNext.setOnClickListener(this);
rbtn1 = (RadioButton)findViewById(R.id.rbtn1);
rbtn1.setOnClickListener(this);
rbtn2 = (RadioButton)findViewById(R.id.rbtn2);
rbtn2.setOnClickListener(this);
rbtn3 = (RadioButton)findViewById(R.id.rbtn3);
rbtn3.setOnClickListener(this);
rbtn4 = (RadioButton)findViewById(R.id.rbtn4);
rbtn4.setOnClickListener(this);
rbtn1.setTag(Constant.UNCHECK);
rbtn2.setTag(Constant.UNCHECK);
rbtn3.setTag(Constant.UNCHECK);
rbtn4.setTag(Constant.UNCHECK);
rbtn1.setChecked(false);
rbtn2.setChecked(false);
rbtn3.setChecked(false);
rbtn4.setChecked(false);
txtQuestion_No = (TextView)findViewById(R.id.txtQuestion_No);
txtCodeOfUTitle = (TextView)findViewById(R.id.txtFullTestTilte);
imgCodeOfUnderstanding = (ImageView)findViewById(R.id.imgCodeOfUnderstanding);
btnBack.setText(mSharedPreferences_Read.getString(Dict_Wording_Constant.WORDINGS.BACK_BUTTON + Constant.LANGUAGE_TAG[intLanguage_Position],""));
btnResult.setText(mSharedPreferences_Read.getString(Dict_Wording_Constant.WORDINGS.RESULTS_BUTTON + Constant.LANGUAGE_TAG[intLanguage_Position],""));
txtCodeOfUTitle.setText(mSharedPreferences_Read.getString(Dict_Wording_Constant.WORDINGS.CODE_OF_U_TEST_TITLE + Constant.LANGUAGE_TAG[intLanguage_Position],""));
//imgCodeOfUnderstanding.setText(mSharedPreferences_Read.getString(Dict_Wording_Constant.WORDINGS.HOMESCREEN_TITLE,""));
if(intLanguage_Position==Constant.SHAREDPREFERENCE.ENGLISH){
imgCodeOfUnderstanding.setBackgroundResource(R.drawable.begrips_code_logo_en);
}
else if(intLanguage_Position==Constant.SHAREDPREFERENCE.NEDERLANDS){
imgCodeOfUnderstanding.setBackgroundResource(R.drawable.begrips_code_logo_nl);
}
else if(intLanguage_Position==Constant.SHAREDPREFERENCE.DEUTSCH){
imgCodeOfUnderstanding.setBackgroundResource(R.drawable.begrips_code_logo_de);
}
strQuestion1 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.A_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strQuestion2 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.B_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strQuestion3 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.C_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strQuestion4 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.D_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
txtQuestion_No.setText(String.valueOf(intCount));
rbtn1.setText(strQuestion1);
rbtn2.setText(strQuestion2);
rbtn3.setText(strQuestion3);
rbtn4.setText(strQuestion4);
strResult1 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.A_SCORE_FULLTEST, intCount), "");
strResult2 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.B_SCORE_FULLTEST,intCount) ,"");
strResult3 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.C_SCORE_FULLTEST, intCount), "");
strResult4 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.D_SCORE_FULLTEST,intCount) ,"");
//***********************************************************************************************************************
OpenDatabase();
mDbHelper.InsertQuicktestResult(mSQLiteDatabase,"", 0,0,0,0,0,1);
CloseDataBase();
txtQuestion_No.setText(String.valueOf(intCount));
btnPrevious.setVisibility(Button.INVISIBLE);
btnResult.setVisibility(Button.INVISIBLE);
if(!rbtn1.isChecked() || !rbtn2.isChecked() || !rbtn3.isChecked() || !rbtn4.isChecked()){
btnNext.setVisibility(Button.INVISIBLE);
}
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode==KeyEvent.KEYCODE_BACK)
{
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
private synchronized void RadioCheck(){
btnNext.setVisibility(Button.INVISIBLE);
btnResult.setVisibility(Button.INVISIBLE);
rbtn1.setButtonDrawable(R.drawable.radio_button_normal);
rbtn2.setButtonDrawable(R.drawable.radio_button_normal);
rbtn3.setButtonDrawable(R.drawable.radio_button_normal);
rbtn4.setButtonDrawable(R.drawable.radio_button_normal);
rbtn1.setTag(Constant.UNCHECK);
rbtn2.setTag(Constant.UNCHECK);
rbtn3.setTag(Constant.UNCHECK);
rbtn4.setTag(Constant.UNCHECK);
rbtn1.setChecked(false);
rbtn2.setChecked(false);
rbtn3.setChecked(false);
rbtn4.setChecked(false);
}
private synchronized void RadioUnchecked(int position){
rbtn1.setButtonDrawable(R.drawable.radio_button_normal);
rbtn2.setButtonDrawable(R.drawable.radio_button_normal);
rbtn3.setButtonDrawable(R.drawable.radio_button_normal);
rbtn4.setButtonDrawable(R.drawable.radio_button_normal);
rbtn1.setTag(Constant.UNCHECK);
rbtn2.setTag(Constant.UNCHECK);
rbtn3.setTag(Constant.UNCHECK);
rbtn4.setTag(Constant.UNCHECK);
rbtn1.setChecked(false);
rbtn2.setChecked(false);
rbtn3.setChecked(false);
rbtn4.setChecked(false);
if(position == 1){
rbtn1.setButtonDrawable(R.drawable.radio_button_selected);
rbtn1.setTag(Constant.CHECK);
rbtn1.setChecked(true);
}
else if(position == 2){
rbtn2.setButtonDrawable(R.drawable.radio_button_selected);
rbtn2.setTag(Constant.CHECK);
rbtn2.setChecked(true);
}
else if(position == 3){
rbtn3.setButtonDrawable(R.drawable.radio_button_selected);
rbtn3.setTag(Constant.CHECK);
rbtn3.setChecked(true);
}
else if(position == 4){
rbtn4.setButtonDrawable(R.drawable.radio_button_selected);
rbtn4.setTag(Constant.CHECK);
rbtn4.setChecked(true);
}
}
@Override
public synchronized void onClick(View v) {
// TODO Auto-generated method stub
if(v==btnBack){
finish();
}
else if(v==btnResult){
InsertQuickTestExam();
Intent mIntent = new Intent(this,Results.class);
mIntent.putExtra(Constant.RESULT_INTENT.RESULT_ID, intResultID);
mIntent.setAction(Constant.FULLTEST_CATEGORY.FULLTEST_ACTION);
startActivity(mIntent);
finish();
}
else if(v==rbtn1){
if(intCount < intTotalQuestion){
if(v.getTag().toString().equals(Constant.UNCHECK)){
btnNext.setVisibility(Button.VISIBLE);
RadioUnchecked(1);
}
else{
RadioCheck();
}
}
else{
if(v.getTag().toString().equals(Constant.UNCHECK)){
btnNext.setVisibility(Button.INVISIBLE);
btnResult.setVisibility(Button.VISIBLE);
RadioUnchecked(1);
}else{
RadioCheck();
}
}
}
else if(v==rbtn2){
if(intCount < intTotalQuestion){
if(v.getTag().toString().equals(Constant.UNCHECK)){
btnNext.setVisibility(Button.VISIBLE);
RadioUnchecked(2);
}
else{
RadioCheck();
}
}
else{
if(v.getTag().toString().equals(Constant.UNCHECK)){
btnNext.setVisibility(Button.INVISIBLE);
btnResult.setVisibility(Button.VISIBLE);
RadioUnchecked(2);
}
else{
RadioCheck();
}
}
}
else if(v==rbtn3){
if(intCount < intTotalQuestion){
if(v.getTag().toString().equals(Constant.UNCHECK)){
btnNext.setVisibility(Button.VISIBLE);
RadioUnchecked(3);
}
else{
RadioCheck();
}
}
else{
if(v.getTag().toString().equals(Constant.UNCHECK)){
btnNext.setVisibility(Button.INVISIBLE);
btnResult.setVisibility(Button.VISIBLE);
RadioUnchecked(3);
}
else{
RadioCheck();
}
}
}
else if(v==rbtn4){
if(intCount < intTotalQuestion){
if(v.getTag().toString().equals(Constant.UNCHECK)){
btnNext.setVisibility(Button.VISIBLE);
RadioUnchecked(4);
}
else{
RadioCheck();
}
}
else{
if(v.getTag().toString().equals(Constant.UNCHECK)){
btnNext.setVisibility(Button.INVISIBLE);
btnResult.setVisibility(Button.VISIBLE);
RadioUnchecked(4);
}
else{
RadioCheck();
}
}
}
else if(v==btnPrevious){
if(intTotalQuestion > 1)
{
InsertQuickTestExam();
if(intCount > 1)
{
intCount=intCount-1;
txtQuestion_No.setText(String.valueOf(intCount));
strQuestion1 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.A_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strQuestion2 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.B_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strQuestion3 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.C_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strQuestion4 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.D_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
rbtn1.setText(strQuestion1);
rbtn2.setText(strQuestion2);
rbtn3.setText(strQuestion3);
rbtn4.setText(strQuestion4);
getCheckboxStatus();
strResult1 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.A_SCORE_FULLTEST, intCount), "");
strResult2 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.B_SCORE_FULLTEST,intCount) ,"");
strResult3 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.C_SCORE_FULLTEST, intCount), "");
strResult4 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.D_SCORE_FULLTEST,intCount) ,"");
ButtonHide(intCount,intTotalQuestion);
}
else
{
intCount=1;
Toast.makeText(this, "intcount==="+intCount, Toast.LENGTH_SHORT).show();
ButtonHide(intCount,intTotalQuestion);
}
}
}
else if(v==btnNext){
if(intTotalQuestion > 1)
{
InsertQuickTestExam();
if(intCount < intTotalQuestion-1)
{
intCount=intCount+1;
txtQuestion_No.setText(String.valueOf(intCount));
strQuestion1 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.A_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strQuestion2 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.B_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strQuestion3 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.C_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strQuestion4 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.D_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strResult1 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.A_SCORE_FULLTEST, intCount), "");
strResult2 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.B_SCORE_FULLTEST,intCount) ,"");
strResult3 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.C_SCORE_FULLTEST, intCount), "");
strResult4 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.D_SCORE_FULLTEST,intCount) ,"");
rbtn1.setText(strQuestion1);
rbtn2.setText(strQuestion2);
rbtn3.setText(strQuestion3);
rbtn4.setText(strQuestion4);
getCheckboxStatus();
if(intCount < intTotalQuestion){
ButtonHide(intCount,intTotalQuestion);
}
}
else
{
intCount=intTotalQuestion;
txtQuestion_No.setText(String.valueOf(intCount));
strQuestion1 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.A_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strQuestion2 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.B_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strQuestion3 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.C_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strQuestion4 = mSharedPreferences_Read.getString(String.format(Dict_FullTestQuestion_Constant.ANSWERS_FULLTEST.D_FULLTEST_INDEX, intCount,Constant.LANGUAGE_TAG[intLanguage_Position]), "");
strResult1 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.A_SCORE_FULLTEST, intCount), "");
strResult2 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.B_SCORE_FULLTEST,intCount) ,"");
strResult3 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.C_SCORE_FULLTEST, intCount), "");
strResult4 = mSharedPreferences_Read.getString(String.format(Dict_ScoreTableFulltest_Constant.SCORETABEL_FULLTEST.D_SCORE_FULLTEST,intCount) ,"");
rbtn1.setText(strQuestion1);
rbtn2.setText(strQuestion2);
rbtn3.setText(strQuestion3);
rbtn4.setText(strQuestion4);
getCheckboxStatus();
ButtonHide(intCount,intTotalQuestion);
}
}
if(intCount < intTotalQuestion && (rbtn1.isChecked() || rbtn2.isChecked() || rbtn3.isChecked() || rbtn4.isChecked())){
btnNext.setVisibility(Button.VISIBLE);
}
else if(intCount >= intTotalQuestion && (rbtn1.isChecked() || rbtn2.isChecked() || rbtn3.isChecked() || rbtn4.isChecked())){
btnNext.setVisibility(Button.INVISIBLE);
}
else{
btnNext.setVisibility(Button.INVISIBLE);
btnResult.setVisibility(Button.INVISIBLE);
}
}
}
//This function is used to set visibility of button
private synchronized void ButtonHide(int CurrentRecord,int TotalRecord){
if(TotalRecord > 1){
if(CurrentRecord >= TotalRecord)
{
btnResult.setVisibility(Button.VISIBLE);
btnNext.setVisibility(ImageView.INVISIBLE);
}else{
btnNext.setVisibility(ImageView.VISIBLE);
}
if(CurrentRecord != 1)
{
btnPrevious.setVisibility(ImageView.VISIBLE);
}else{
btnPrevious.setVisibility(ImageView.INVISIBLE);
}
}
else{
btnResult.setVisibility(Button.INVISIBLE);
btnNext.setVisibility(ImageView.INVISIBLE);
btnPrevious.setVisibility(ImageView.INVISIBLE);
}
}
private synchronized void getCheckboxStatus(){
OpenDatabase();
int isRadioSelected = mDbHelper.getQuickExamSelcted(mSQLiteDatabase, intCount,intResultID);
CloseDataBase();
if(isRadioSelected == 0){
RadioUnchecked(1);
}
else if(isRadioSelected == 1){
RadioUnchecked(2);
}
else if(isRadioSelected == 2){
RadioUnchecked(3);
}
else if(isRadioSelected == 3){
RadioUnchecked(4);
}
else{
rbtn1.setChecked(false);
rbtn2.setChecked(false);
rbtn3.setChecked(false);
rbtn4.setChecked(false);
rbtn1.setTag(Constant.UNCHECK);
rbtn2.setTag(Constant.UNCHECK);
rbtn3.setTag(Constant.UNCHECK);
rbtn4.setTag(Constant.UNCHECK);
rbtn1.setButtonDrawable(R.drawable.radio_button_normal);
rbtn2.setButtonDrawable(R.drawable.radio_button_normal);
rbtn3.setButtonDrawable(R.drawable.radio_button_normal);
rbtn4.setButtonDrawable(R.drawable.radio_button_normal);
}
}
//***********************************************************************************************************************
/**
* @author Manisha
* @param none
* @return void
* @use This function is used for InsertQuickTestExam
*/
private synchronized void InsertQuickTestExam(){
OpenDatabase();
intResultID = mDbHelper.getQuickResultID(mSQLiteDatabase);
isRecordExist = mDbHelper.checkRecordExist_QuickExam(mSQLiteDatabase, intCount, intResultID);
CloseDataBase();
if(isRecordExist>0){
if(rbtn1.isChecked()){
if(strResult1.trim().equals(Constant.FULLTEST_CATEGORY.BW_GUARDIAN)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount, intResultID, 1, 0, 0, 0,0);
CloseDataBase();
}
else if(strResult1.trim().equals(Constant.FULLTEST_CATEGORY.VB_RELATIONIST)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 1, 0, 0,0);
CloseDataBase();
}
else if(strResult1.trim().equals(Constant.FULLTEST_CATEGORY.BD_CREATOR)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 0, 1, 0,0);
CloseDataBase();
}
else if(strResult1.trim().equals(Constant.FULLTEST_CATEGORY.BS_ACHIEVER)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 0, 0, 1,0);
CloseDataBase();
}
}
else if(rbtn2.isChecked()){
if(strResult2.trim().equals(Constant.FULLTEST_CATEGORY.BW_GUARDIAN)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 1, 0, 0, 0,1);
CloseDataBase();
}
else if(strResult2.trim().equals(Constant.FULLTEST_CATEGORY.VB_RELATIONIST)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 1, 0, 0,1);
CloseDataBase();
}
else if(strResult2.trim().equals(Constant.FULLTEST_CATEGORY.BD_CREATOR)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount, intResultID, 0, 0, 1, 0,1);
CloseDataBase();
}
else if(strResult2.trim().equals(Constant.FULLTEST_CATEGORY.BS_ACHIEVER)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 0, 0, 1,1);
CloseDataBase();
}
}
else if(rbtn3.isChecked()){
if(strResult3.trim().equals(Constant.FULLTEST_CATEGORY.BW_GUARDIAN)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 1, 0, 0, 0,2);
CloseDataBase();
}
else if(strResult3.trim().equals(Constant.FULLTEST_CATEGORY.VB_RELATIONIST)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 1, 0, 0,2);
CloseDataBase();
}
else if(strResult3.trim().equals(Constant.FULLTEST_CATEGORY.BD_CREATOR)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount, intResultID, 0, 0, 1, 0,2);
CloseDataBase();
}
else if(strResult3.trim().equals(Constant.FULLTEST_CATEGORY.BS_ACHIEVER)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 0, 0, 1,2);
CloseDataBase();
}
}
else if(rbtn4.isChecked()){
if(strResult4.trim().equals(Constant.FULLTEST_CATEGORY.BW_GUARDIAN)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 1, 0, 0, 0,3);
CloseDataBase();
}
else if(strResult4.trim().equals(Constant.FULLTEST_CATEGORY.VB_RELATIONIST)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 1, 0, 0,3);
CloseDataBase();
}
else if(strResult4.trim().equals(Constant.FULLTEST_CATEGORY.BD_CREATOR)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount, intResultID, 0, 0, 1, 0,3);
CloseDataBase();
}
else if(strResult4.trim().equals(Constant.FULLTEST_CATEGORY.BS_ACHIEVER)){
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 0, 0, 1,3);
//System.out.println("strresult===="+intCount+" "+intResultID );
CloseDataBase();
}
}
else{
OpenDatabase();
mDbHelper.UpdateQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 0, 0, 0,5);
CloseDataBase();
}
}
else {
if(rbtn1.isChecked()){
if(strResult1.trim().equals(Constant.FULLTEST_CATEGORY.BW_GUARDIAN)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount, intResultID, 1, 0, 0, 0,0);
CloseDataBase();
}
else if(strResult1.trim().equals(Constant.FULLTEST_CATEGORY.VB_RELATIONIST)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 1, 0, 0,0);
CloseDataBase();
}
else if(strResult1.trim().equals(Constant.FULLTEST_CATEGORY.BD_CREATOR)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 0, 1,0,0);
CloseDataBase();
}
else if(strResult1.trim().equals(Constant.FULLTEST_CATEGORY.BS_ACHIEVER)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 0, 0, 1,0);
CloseDataBase();
}
}
else if(rbtn2.isChecked()){
if(strResult2.trim().equals(Constant.FULLTEST_CATEGORY.BW_GUARDIAN)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount,intResultID, 1, 0, 0, 0,1);
System.out.println("strresultinsert===="+intCount+" "+intResultID );
CloseDataBase();
}
else if(strResult2.trim().equals(Constant.FULLTEST_CATEGORY.VB_RELATIONIST)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 1, 0, 0,1);
CloseDataBase();
}
else if(strResult2.trim().equals(Constant.FULLTEST_CATEGORY.BD_CREATOR)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount, intResultID, 0, 0, 1, 0,1);
CloseDataBase();
}
else if(strResult2.trim().equals(Constant.FULLTEST_CATEGORY.BS_ACHIEVER)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 0, 0, 1,1);
CloseDataBase();
}
}
else if(rbtn3.isChecked()){
if(strResult3.trim().equals(Constant.FULLTEST_CATEGORY.BW_GUARDIAN)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount,intResultID, 1, 0, 0, 0,2);
CloseDataBase();
}
else if(strResult3.trim().equals(Constant.FULLTEST_CATEGORY.VB_RELATIONIST)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 1, 0, 0,2);
CloseDataBase();
}
else if(strResult3.trim().equals(Constant.FULLTEST_CATEGORY.BD_CREATOR)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount, intResultID, 0, 0, 1, 0,2);
CloseDataBase();
}
else if(strResult3.trim().equals(Constant.FULLTEST_CATEGORY.BS_ACHIEVER)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 0, 0, 1,2);
CloseDataBase();
}
}
else if(rbtn4.isChecked()){
if(strResult4.trim().equals(Constant.FULLTEST_CATEGORY.BW_GUARDIAN)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount,intResultID, 1, 0, 0, 0,3);
CloseDataBase();
}
else if(strResult4.trim().equals(Constant.FULLTEST_CATEGORY.VB_RELATIONIST)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 1, 0, 0,3);
CloseDataBase();
}
else if(strResult4.trim().equals(Constant.FULLTEST_CATEGORY.BD_CREATOR)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount, intResultID, 0, 0, 1, 0,3);
CloseDataBase();
}
else if(strResult4.trim().equals(Constant.FULLTEST_CATEGORY.BS_ACHIEVER)){
OpenDatabase();
mDbHelper.InsertQuicktestExam(mSQLiteDatabase, intCount,intResultID, 0, 0, 0, 1,3);
CloseDataBase();
}
}
}
}
/**THIS FUNCTION IS USED FOR OPEN DATABASE */
private DbHelper mDbHelper=null;
private SQLiteDatabase mSQLiteDatabase=null;
private void OpenDatabase()
{
try{
if(mDbHelper==null && mSQLiteDatabase==null){
mDbHelper = new DbHelper(FullTest.this);
mSQLiteDatabase = mDbHelper.getWritableDatabase();
// mSQLiteDatabase.setLockingEnabled(true);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
/**THIS FUNCTION IS USED FOR CLOSE DATABASE */
private void CloseDataBase()
{
try{
if(mDbHelper!=null && mSQLiteDatabase!=null){
mSQLiteDatabase.close();
mDbHelper.close();
mSQLiteDatabase=null;
mDbHelper=null;
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
=======================================
3)DbConstant.java
package com.drc.mrs;
public class DbConstant {
public static final class DB{
public static final String DATABASENAME = "DBCodeForU";
public static final int DB_VERSION = 2;
}
public static final class QUICKTEST_RESULT{
public static final String QUICKTEST_RESULT_TABLE = "QuickTestResult";
public static final String RESULT_ID = "result_id";
public static final String PLAYER_NAME = "player_name";
public static final String RESULT_SHOW = "result_show";
public static final String QUICK_OR_FULL = "quick_full";
public static final String RESULT_GUARDIAN = "result_guardian";
public static final String RESULT_RELATIONIST = "result_relationist";
public static final String RESULT_CREATOR = "result_creator";
public static final String RESULT_ACHIEVER = "reslult_achiever";
}
public static final class QUICKTEST_EXAM{
public static final String QUICKTEST_EXAM_TABLE = "QuickTestExam";
public static final String QUICK_TEST_ID = "quick_test_id";
public static final String QUICK_TEST_QUES_ID = "quick_test_ques_id";
public static final String RESULT_ID = "result_id";
public static final String GUARDIAN = "guardian";
public static final String RELATIONIST = "relationist";
public static final String CREATOR = "creator";
public static final String ACHIEVER = "achiever";
public static final String SELECTED = "selected";
}
}
========================================
For get result data
============
public void getResultData() {
Cursor c = mDbHelper.GetResultData(mSQLiteDatabase,1);
if(c!=null){
if(c.getCount() > 0){
c.moveToFirst();
while(c.isAfterLast() == false){
alstResultID.add(c.getString(0));
alstPlayerName.add(c.getString(1));
alstGuardian.add(c.getString(2));
alstRelationist.add(c.getString(3));
alstCreator.add(c.getString(4));
alstAchiever.add(c.getString(5));
alstResult_show.add(c.getString(6));
alstQuick_Full.add(c.getString(7));
c.moveToNext();
};
}
c.close();
}
}
==============================================
For get result data
===========
intResultID = getIntent().getExtras().getInt(Constant.RESULT_INTENT.RESULT_ID, 0);
OpenDatabase(Results.this);
int total[] = mDbHelper.QUICKTEST_GUARDIAN_TOTAL(mSQLiteDatabase, intResultID);
intGuardian = total[0];
intRelationist = total[1];
intCreator = total[2];
intAchiever = total[3];
CloseDataBase(Results.this);
=============================================
*******************************************************************************
=============================================
New
1)package com.ovte.letsrecycle;
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;
}
}
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);
}*/
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);
}
/*********************************************************************************************************/
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);
}
/*********************************************************************************************************/
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)DBConstant
==============
package com.ovte.letsrecycle;
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();
}
}
/**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();
}
}
}
USE OF FUNCTION
===========
======================
UPDATECOllection
public void onClick(DialogInterface dialog, int which) {
if(mCommonClass.CheckNetwork(FinalizedOrder.this)){
new Send_FinalisedOrder().execute("Send Collection");
}else{
DBConstant.OpenDatabase(FinalizedOrder.this);
DBConstant.mDBHelper.Update_Collection_info(DBConstant.mSQLiteDatabase,
mSharedPreferencesRead.getString(Constant.LEADSPENDING_SHARED.LPS_APPOINTMENT_ID, ""),
mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, ""),
GetDateTimeFormat(System.currentTimeMillis()));
DBConstant.CloseDataBase();
Finalized_Done_Alert();
}
dialog.cancel();
return;
}
=====================
/**This function use for get Price And ParaValue*/
private float Price=0f;
private String Para_value="";
private void GetPriceAndParaValue(){
String para_unit_id="";
DBConstant.OpenDatabase(this);
Cursor c = DBConstant.mDBHelper.Select_PRODUCT_PRICE(DBConstant.mSQLiteDatabase, mSharedPreferencesRead.getString(Constant.MAINPRODUCT_SHARED.MPS_PRODUCT_ID, ""), mSharedPreferencesRead.getString(Constant.LEADSPENDING_SHARED.LPS_PRICE_GROUP, ""));
if(c!=null){
if(c.getCount() > 0){
c.moveToFirst();
para_unit_id=c.getString(2);
Price=(float)c.getFloat(3);
c.close();
}
else{
c.close();
}
}
Para_value=DBConstant.mDBHelper.Select_PARAMETER_PARAVALUE(DBConstant.mSQLiteDatabase,para_unit_id);
DBConstant.CloseDataBase();
// String Price_Paravalue=String.format("%s %s / %s",Constant.RUPEES,Price,Para_value);
// txtrate_parameter.setText(Price_Paravalue);
SetRateParaValue();
SetRate();
}
======================
/**This function use for get Price And ParaValue*/
private float Price=0f;
private String Para_value="";
private void GetPriceAndParaValue(){
String para_unit_id="";
DBConstant.OpenDatabase(this);
Cursor c = DBConstant.mDBHelper.Select_PRODUCT_PRICE(DBConstant.mSQLiteDatabase, mSharedPreferencesRead.getString(Constant.MAINPRODUCT_SHARED.MPS_PRODUCT_ID, ""), mSharedPreferencesRead.getString(Constant.LEADSPENDING_SHARED.LPS_PRICE_GROUP, ""));
if(c!=null){
if(c.getCount() > 0){
c.moveToFirst();
para_unit_id=c.getString(2);
Price=(float)c.getFloat(3);
c.close();
}
else{
c.close();
}
}
Para_value=DBConstant.mDBHelper.Select_PARAMETER_PARAVALUE(DBConstant.mSQLiteDatabase,para_unit_id);
DBConstant.CloseDataBase();
// String Price_Paravalue=String.format("%s %s / %s",Constant.RUPEES,Price,Para_value);
// txtrate_parameter.setText(Price_Paravalue);
SetRateParaValue();
SetRate();
}
================
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if(mCommonClass.CheckNetwork(FinalizedOrder.this)){
new Send_FinalisedOrder().execute("Send Collection");
}else{
DBConstant.OpenDatabase(FinalizedOrder.this);
DBConstant.mDBHelper.Update_Collection_info(DBConstant.mSQLiteDatabase,
mSharedPreferencesRead.getString(Constant.LEADSPENDING_SHARED.LPS_APPOINTMENT_ID, ""),
mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, ""),
GetDateTimeFormat(System.currentTimeMillis()));
DBConstant.CloseDataBase();
Finalized_Done_Alert();
}
dialog.cancel();
return;
}
});
=====================================
3)package com.ovte.letsrecycle;
import java.util.ArrayList;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class LeadsPending extends Activity{
private SharedPreferences mSharedPreferencesRead=null;
private SharedPreferences mSharedPreferencesWrite=null;
private CommonClass mCommonClass=new CommonClass();
private LeadsPending_BaseAdapter mLeadsPending_BaseAdapter=null;
private ListView lst_leadspending=null;
private ArrayList<String> Alst_appointment_id=null,
Alst_app_date_time=null,
Alst_customer_id=null,
Alst_customer_name=null,
Alst_customr_code=null,
Alst_address=null,
Alst_add1 = null,
Alst_add2 = null,
Alst_City = null,
Alst_State = null,
Alst_Country = null,
Alst_Zipcode = null,
Alst_mobile_no=null,
Alst_landmark=null,
Alst_price_group=null,
Alst_lattitude=null,
Alst_longitude=null,
Alst_vat=null,
Alst_vat_val=null;
private Button btn_Search = null;
private EditText edt_customreName = null;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.xleadspending);
mSharedPreferencesRead = getSharedPreferences(Constant.SHAREDPREFERENCES,MODE_WORLD_READABLE);
mSharedPreferencesWrite=getSharedPreferences(Constant.SHAREDPREFERENCES, MODE_WORLD_WRITEABLE);
Alst_appointment_id=new ArrayList<String>();
Alst_app_date_time=new ArrayList<String>();
Alst_customer_id=new ArrayList<String>();
Alst_customer_name=new ArrayList<String>();
Alst_customr_code=new ArrayList<String>();
Alst_address=new ArrayList<String>();
Alst_add1 = new ArrayList<String>();
Alst_add2 = new ArrayList<String>();
Alst_City = new ArrayList<String>();
Alst_State = new ArrayList<String>();
Alst_Country = new ArrayList<String>();
Alst_Zipcode = new ArrayList<String>();
Alst_mobile_no=new ArrayList<String>();
Alst_landmark=new ArrayList<String>();
Alst_price_group=new ArrayList<String>();
Alst_lattitude=new ArrayList<String>();
Alst_longitude=new ArrayList<String>();
Alst_vat=new ArrayList<String>();
Alst_vat_val = new ArrayList<String>();
Button btn_back=(Button)findViewById(R.id.btn_back);
btn_back.setVisibility(Button.VISIBLE);
btn_back.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
Button btn_Refresh=(Button)findViewById(R.id.btn_reload);
btn_Refresh.setVisibility(Button.VISIBLE);
btn_Refresh.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
getData_Refresh();
}
});
edt_customreName = (EditText)findViewById(R.id.edt_custName);
btn_Search = (Button)findViewById(R.id.btn_Find);
btn_Search.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(edt_customreName.getText().toString().trim().equals("")){
Log.i(Constant.TAG,"True Condition "+edt_customreName.getText().toString().trim());
ClearData();
getPendingLeads("");
if(mLeadsPending_BaseAdapter != null){
mLeadsPending_BaseAdapter.Update_Data_Record();
mLeadsPending_BaseAdapter.notifyDataSetChanged();
}
}else{
Log.i(Constant.TAG,"False Condition "+edt_customreName.getText().toString().trim());
if(check_collection()){
Finalized_Previous_Alert();
}else{
ClearData();
getPendingLeads(edt_customreName.getText().toString().trim());
if(mLeadsPending_BaseAdapter != null){
mLeadsPending_BaseAdapter.Update_Data_Record();
mLeadsPending_BaseAdapter.notifyDataSetChanged();
}
}
}
}
});
lst_leadspending=(ListView)findViewById(R.id.lst_leadspending);
getData_Refresh();
/*if(mCommonClass.CheckNetwork(this)){
new CheckPendingLeadStatus().execute("checkpending Leads Finilized or not");
}else{
InitData();
}*/
}
private void getData_Refresh(){
if(mCommonClass.CheckNetwork(this)){
new CheckPendingLeadStatus().execute("checkpending Leads Finilized or not");
}else{
InitData();
}
}
/*private boolean check_finilized(){
boolean check = false;
for(int i=0;i< mLeadsPending_BaseAdapter.BoolAppointment_Status.length;i++){
if(mLeadsPending_BaseAdapter.BoolAppointment_Status[i]){
Finalized_Previous_Alert();
check = false;
}else{
check = true;
}
}
return check;
}*/
private boolean check_collection(){
boolean status = false;
for(int i=0;i < Alst_appointment_id.size();i++){
if(Check_Appointment_Collection(Alst_appointment_id.get(i).toString().trim())){
status = true;
break;
}
}
return status;
}
private void InitData(){
ClearData();
if(mCommonClass.CheckNetwork(this)){
new GetPendingLead().execute("Leads Pending");
}else{
getPendingLeads("");
}
}
private void ClearData(){
Alst_appointment_id.clear();
Alst_app_date_time.clear();
Alst_customer_id.clear();
Alst_customer_name.clear();
Alst_customr_code.clear();
Alst_address.clear();
Alst_add1.clear();
Alst_add2.clear();
Alst_City.clear();
Alst_State.clear();
Alst_Country.clear();
Alst_Zipcode.clear();
Alst_mobile_no.clear();
Alst_landmark.clear();
Alst_price_group.clear();
Alst_lattitude.clear();
Alst_longitude.clear();
Alst_vat.clear();
Alst_vat_val.clear();
}
/**This class use for check pendinglead status*/
private class CheckPendingLeadStatus extends AsyncTask<String, String,Boolean>{
private ProcessDialog mProcessDialog=null;
@Override
protected void onPreExecute() {
mProcessDialog= new ProcessDialog(LeadsPending.this,Constant.SERVER,Constant.LOADING);
super.onPreExecute();
}
@Override
protected Boolean doInBackground(String... data) {
Boolean Status = false;
try{
DBConstant.OpenDatabase(LeadsPending.this);
Cursor c = DBConstant.mDBHelper.Select_Appointment_Status(DBConstant.mSQLiteDatabase, mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, ""));
if( c != null){
if(c.getCount() > 0){
Log.i(Constant.TAG, "Leads Pending :"+c.getCount());
c.moveToFirst();
while(c.isAfterLast() == false){
// Log.i(Constant.TAG, "Dta : "+c.getString(0).toString());
String apoinment_Id=c.getString(0).toString();
String strURL = getResources().getString(R.string.CHECK_PENDINGLEAD_STATUS_URL);
ArrayList<NameValuePair> mNameValuePair = new ArrayList<NameValuePair>();
mNameValuePair.add(new BasicNameValuePair(Constant.CHECK_LEADSPENDING_STATUS_REQUEST.APPOINTMENT_ID,apoinment_Id));
String result = mCommonClass.PostConnection(strURL, mNameValuePair);
try {
JSONObject jsonLeadsPending = new JSONObject(result);
if(jsonLeadsPending.getString(Constant.COMMON_JSON.TYPE).equals(Constant.COMMON_JSON.OK)){
DBConstant.mDBHelper.Delete_COLLECTION(DBConstant.mSQLiteDatabase,apoinment_Id,mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID,""));
DBConstant.mDBHelper.Delete_PENDING_LEADS_By_Appointment_ID(DBConstant.mSQLiteDatabase,apoinment_Id,mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID,""));
}
} catch (Exception e) {
e.printStackTrace();
}
c.moveToNext();
}
}
if(!c.isClosed()){
c.close();
}
}
DBConstant.CloseDataBase();
Status = true;
}catch (Exception e) {
e.printStackTrace();
}
return Status;
}
@Override
protected void onPostExecute(Boolean result) {
mProcessDialog.dismiss();
InitData();
/* if(result)
{
InitData();
}
else{
Toast.makeText(LeadsPending.this, Constant.SERVERCONNERROR,Toast.LENGTH_SHORT).show();
}*/
super.onPostExecute(result);
}
}
/**This class use for get pending leads*/
private class GetPendingLead extends AsyncTask<String, String,String>{
private ProcessDialog mProcessDialog=null;
@Override
protected void onPreExecute() {
mProcessDialog= new ProcessDialog(LeadsPending.this,Constant.SERVER,Constant.LOADING);
super.onPreExecute();
}
protected String doInBackground(String... params) {
String strURL = getResources().getString(R.string.PENDINGLEAD_URL);
ArrayList<NameValuePair> mNameValuePair = new ArrayList<NameValuePair>();
mNameValuePair.add(new BasicNameValuePair(Constant.LEADSPENDING_REQUEST.COLLECTION_BY,mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, "")));
mNameValuePair.add(new BasicNameValuePair(Constant.LEADSPENDING_REQUEST.LEADSPENDING_ACTION,Constant.LEADSPENDING_REQUEST.LEADSPENDING_ROWS));
return mCommonClass.PostConnection(strURL, mNameValuePair);
}
protected void onPostExecute(String result) {
mProcessDialog.dismiss();
if(result!=null)
{
Log.i(Constant.TAG,"LeadsPending Response = " + result);
try {
JSONObject jsonLeadsPending = new JSONObject(result);
if(jsonLeadsPending.getString(Constant.COMMON_JSON.TYPE).equals(Constant.COMMON_JSON.OK)){
DBConstant.OpenDatabase(LeadsPending.this);
DBConstant.mDBHelper.DELETE_PENDING_LEADS(DBConstant.mSQLiteDatabase);
// DBConstant.mDBHelper.Delete_PENDING_LEADS(DBConstant.mSQLiteDatabase);
// Cursor c = DBConstant.mDBHelper.Select_PENDINGLEADS(DBConstant.mSQLiteDatabase,mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, ""));
// Log.i("Count :----> ", "Total Records == "+c.getCount());
// vat_value=(int)jsonLeadsPending.getInt(Constant.LEADSPENDING_JSON.VAT_VALUE);
JSONObject jsonReturnResult = jsonLeadsPending.getJSONObject(Constant.LEADSPENDING_JSON.RETURNRESULT);
// JSONArray jsonArray = jsonReturnResult.names();
// Log.i(Constant.TAG,"jsonArray Response = " + jsonArray.toString());
int total_rows=jsonReturnResult.getInt(Constant.LEADSPENDING_JSON.TOTAL_ROWS);
for (int j = 0; j < total_rows; j++) {
JSONObject jsonOBJName = jsonReturnResult.getJSONObject(String.valueOf(j));
String str_appointment_id = jsonOBJName.getString(Constant.LEADSPENDING_JSON.APPOINTMENT_ID).toString().trim();
String str_app_date_time = jsonOBJName.getString(Constant.LEADSPENDING_JSON.APP_DATE_TIME).toString().trim();
String str_customer_id = jsonOBJName.getString(Constant.LEADSPENDING_JSON.CUSTOMER_ID).toString().trim();
String str_customer_name = jsonOBJName.getString(Constant.LEADSPENDING_JSON.CUSTOMER_NAME).toString().trim();
String str_customr_code = jsonOBJName.getString(Constant.LEADSPENDING_JSON.CUSTOMR_CODE).toString().trim();
String str_add1 = jsonOBJName.getString(Constant.LEADSPENDING_JSON.ADDRESS1).toString().trim();
String str_add2 = jsonOBJName.getString(Constant.LEADSPENDING_JSON.ADDRESS2).toString().trim();
String str_City = jsonOBJName.getString(Constant.LEADSPENDING_JSON.CITY).toString().trim();
String str_State = jsonOBJName.getString(Constant.LEADSPENDING_JSON.STATE).toString().trim();
String str_Country = jsonOBJName.getString(Constant.LEADSPENDING_JSON.COUNTRY).toString().trim();
String str_Zipcode = jsonOBJName.getString(Constant.LEADSPENDING_JSON.ZIPCODE).toString().trim();
/*String Address=BuildAddress(jsonOBJName.getString(Constant.LEADSPENDING_JSON.ADDRESS1).toString().trim(),
jsonOBJName.getString(Constant.LEADSPENDING_JSON.ADDRESS2).toString().trim(),
jsonOBJName.getString(Constant.LEADSPENDING_JSON.CITY).toString().trim(),
jsonOBJName.getString(Constant.LEADSPENDING_JSON.STATE).toString().trim(),
jsonOBJName.getString(Constant.LEADSPENDING_JSON.COUNTRY).toString().trim(),
jsonOBJName.getString(Constant.LEADSPENDING_JSON.ZIPCODE).toString().trim());
Alst_address.add(Address);*/
String str_mobile_no = jsonOBJName.getString(Constant.LEADSPENDING_JSON.MOBILE_NO).toString().trim();
String str_landmark = jsonOBJName.getString(Constant.LEADSPENDING_JSON.LANDMARK).toString().trim();
String str_price_group = jsonOBJName.getString(Constant.LEADSPENDING_JSON.PRICE_GROUP).toString().trim();
String str_lattitude = jsonOBJName.getString(Constant.LEADSPENDING_JSON.LATTITUDE).toString().trim();
String str_longitude = jsonOBJName.getString(Constant.LEADSPENDING_JSON.LONGITUDE).toString().trim();
String str_vat = jsonOBJName.getString(Constant.LEADSPENDING_JSON.VAT).toString().trim();
String str_vat_val = jsonOBJName.getString(Constant.LEADSPENDING_JSON.VAT_VAL).toString().trim();
/* Log.i(Constant.TAG,"Id "+Alst_appointment_id.get(0).toString().trim());
Log.i(Constant.TAG, "Date "+Alst_app_date_time.get(0).toString().trim());
Log.i(Constant.TAG, "Cust_id : "+ Alst_customer_id.get(0).toString().trim());
Log.i(Constant.TAG, "Name : "+Alst_customer_name.get(0).toString());
Log.i(Constant.TAG, "Add : "+ Alst_address.get(0).toString());
Log.i(Constant.TAG, "Address1 :"+Alst_add1.get(0).toString().trim());
Log.i(Constant.TAG, "Adderss2 :"+Alst_add2.get(0).toString().trim());
Log.i(Constant.TAG, "City :" + Alst_City.get(0).toString().trim());
Log.i(Constant.TAG, "State :" +Alst_State.get(0).toString().trim());
Log.i(Constant.TAG, "Country :"+Alst_Country.get(0).toString().trim());
Log.i(Constant.TAG, "ZipCode :"+Alst_Zipcode.get(0).toString().trim());
Log.i(Constant.TAG, "Mob No :"+ Alst_mobile_no.get(0).toString().trim());
Log.i(Constant.TAG, "Landmark :"+ Alst_landmark.get(0).toString().trim());
Log.i(Constant.TAG, "Price Group :"+ Alst_price_group.get(0).toString().trim());
Log.i(Constant.TAG, "Latitude :"+ Alst_lattitude.get(0).toString().trim());
Log.i(Constant.TAG, "Longitide :"+ Alst_longitude.get(0).toString().trim()); */// String.valueOf(vat_value), Alst_vat.get(0).toString().trim());)
if(Check_Finalize_User_Collection_Exists(str_appointment_id)){
Log.i(Constant.TAG, "Appointment-id "+str_appointment_id + " all ready finalized");
}else{
DBConstant.mDBHelper.Insert_PendingLead(DBConstant.mSQLiteDatabase, str_appointment_id,str_app_date_time, str_customer_id, str_customer_name, str_customr_code, str_add1, str_add2, str_City, str_State, str_Country, str_Zipcode, str_mobile_no, str_landmark, str_price_group, str_lattitude, str_longitude, String.valueOf(str_vat_val), str_vat, mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, ""));
}
}
DBConstant.CloseDataBase();
getPendingLeads("");
// mLeadsPending_BaseAdapter=new LeadsPending_BaseAdapter();
// lst_leadspending.setAdapter(mLeadsPending_BaseAdapter);
}else{
Toast.makeText(LeadsPending.this, jsonLeadsPending.getString(Constant.COMMON_JSON.ERR_MSG).toString(), Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
else{
Toast.makeText(LeadsPending.this, Constant.SERVERCONNERROR,Toast.LENGTH_SHORT).show();
}
super.onPostExecute(result);
}
}
/** This fuction is used to fetch data of Pending Leads form SQLite Database*/
public void getPendingLeads(String name){
DBConstant.OpenDatabase(LeadsPending.this);
// Cursor cr = DBConstant.mDBHelper.Select_PENDINGLEADS(DBConstant.mSQLiteDatabase);
Cursor c = null;
if(name.equals("")){
c = DBConstant.mDBHelper.Select_PENDINGLEADS(DBConstant.mSQLiteDatabase,mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, ""));
}else{
c = DBConstant.mDBHelper.Select_PENDINGLEADS(DBConstant.mSQLiteDatabase,mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, ""),name);
}
if( c != null){
if(c.getCount() > 0){
Log.i(Constant.TAG, "Leads Pending :"+c.getCount());
c.moveToFirst();
while(c.isAfterLast() == false){
Alst_appointment_id.add(c.getString(1).toString());
Alst_customer_id.add(c.getString(2).toString());
Alst_app_date_time.add(c.getString(3).toString());
Alst_customer_name.add(c.getString(4).toString());
Alst_customr_code.add(c.getString(5).toString());
Alst_add1.add(c.getString(6).toString());
Alst_add2.add(c.getString(7).toString());
Alst_City.add(c.getString(8).toString());
Alst_State.add(c.getString(9).toString());
Alst_Country.add(c.getString(10).toString());
Alst_Zipcode.add(c.getString(11).toString());
Alst_mobile_no.add(c.getString(12).toString());
Alst_landmark.add(c.getString(13).toString());
Alst_price_group.add(c.getString(14).toString());
Alst_longitude.add(c.getString(15).toString());
Alst_lattitude.add(c.getString(16).toString());
Alst_vat.add(c.getString(18).toString());
Alst_vat_val.add(c.getString(17).toString());
String Address=BuildAddress(c.getString(6).toString(),
c.getString(7).toString(),
c.getString(8).toString(),
c.getString(9).toString(),
c.getString(10).toString(),
c.getString(11).toString());
Alst_address.add(Address);
c.moveToNext();
}
if(mLeadsPending_BaseAdapter == null){
mLeadsPending_BaseAdapter=new LeadsPending_BaseAdapter();
lst_leadspending.setAdapter(mLeadsPending_BaseAdapter);
}else{
mLeadsPending_BaseAdapter.Update_Data_Record();
mLeadsPending_BaseAdapter.notifyDataSetChanged();
}
}else{
Toast.makeText(LeadsPending.this, Constant.NO_RECORD_FOUND, Toast.LENGTH_SHORT).show();
}
if(!c.isClosed()){
c.close();
}
}
DBConstant.CloseDataBase();
}
/**This function use for merge Address*/
private String BuildAddress(String address1,String address2,String city,String state,String country,String zipcode){
String Address="";
if(!address1.equals("")){
Address=String.format("%s",address1);
}
if(!address2.equals("")){
if(Address.equals("")){
Address=String.format("%s",address2);
}
else{
Address=String.format("%s, %s", Address,address2);
}
}
if(!city.equals("")){
Address=String.format("%s, %s", Address,city);
}
if(!state.equals("")){
Address=String.format("%s, %s", Address,state);
}
if(!country.equals("")){
Address=String.format("%s, %s", Address,country);
}
if(!zipcode.equals("")){
Address=String.format("%s, %s", Address,zipcode);
}
return Address;
}
private class LeadsPending_BaseAdapter extends BaseAdapter{
public boolean BoolAppointment_Status[]=null;
private LayoutInflater mLayoutInflater=null;
public LeadsPending_BaseAdapter() {
mLayoutInflater=LayoutInflater.from(getApplicationContext());
Update_Data_Record();
}
public void Update_Data_Record() {
BoolAppointment_Status=null;
BoolAppointment_Status=new boolean[Alst_appointment_id.size()];
for(int i=0;i < Alst_appointment_id.size();i++){
if(Check_Appointment_Collection(Alst_appointment_id.get(i).toString().trim())){
BoolAppointment_Status[i]=true;
}
else{
BoolAppointment_Status[i]=false;
}
}
}
@Override
public int getCount() {
return Alst_appointment_id.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if(convertView==null){
convertView=mLayoutInflater.inflate(R.layout.xleadspending_customerdetails,null);
}
TextView txt_customer_name=(TextView)convertView.findViewById(R.id.txt_customer_name);
txt_customer_name.setText(Alst_customer_name.get(position));
TextView txt_customer_code=(TextView)convertView.findViewById(R.id.txt_customer_code);
txt_customer_code.setText(Alst_customr_code.get(position));
TextView txt_customer_address=(TextView)convertView.findViewById(R.id.txt_customer_address);
txt_customer_address.setText(Alst_address.get(position));
LinearLayout lly_customer_phoneno=(LinearLayout)convertView.findViewById(R.id.lly_customer_phoneno);
lly_customer_phoneno.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
TelephoneDial(Alst_mobile_no.get(position).toString());
}
});
TextView txt_customer_phoneno=(TextView)convertView.findViewById(R.id.txt_customer_phoneno);
txt_customer_phoneno.setText(Alst_mobile_no.get(position));
ImageView img_customer_landmark=(ImageView)convertView.findViewById(R.id.img_customer_landmark);
img_customer_landmark.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
MapLocation(Alst_lattitude.get(position).toString(),Alst_longitude.get(position).toString());
}
});
TextView txt_customer_landmark=(TextView)convertView.findViewById(R.id.txt_customer_landmark);
txt_customer_landmark.setText(Alst_landmark.get(position));
txt_customer_landmark.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
MapLocation(Alst_lattitude.get(position).toString(),Alst_longitude.get(position).toString());
}
});
final ImageView img_appcollection_notification=(ImageView)convertView.findViewById(R.id.img_appcollection_notification);
if(BoolAppointment_Status[position]){
img_appcollection_notification.setVisibility(ImageView.VISIBLE);
}
else{
img_appcollection_notification.setVisibility(ImageView.INVISIBLE);
}
ImageView img_customer_home_reached=(ImageView)convertView.findViewById(R.id.img_customer_home_reached);
img_customer_home_reached.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Reached(position,img_appcollection_notification.isShown());
}
});
ImageView img_customer_reached=(ImageView)convertView.findViewById(R.id.img_customer_reached);
img_customer_reached.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Reached(position,img_appcollection_notification.isShown());
}
});
TextView txt_appdatetime=(TextView)convertView.findViewById(R.id.txt_appdatetime);
txt_appdatetime.setText(Alst_app_date_time.get(position).toString());
return convertView;
}
}
/**This function use for check collection count or not*/
private boolean Check_Appointment_Collection(String appointment_id){
boolean Status=false;
DBConstant.OpenDatabase(this);
if(DBConstant.mDBHelper.Select_COLLECTION_COUNT_APPOINTMENT_FLAG(DBConstant.mSQLiteDatabase, appointment_id,mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, "")) > 0){
Status=true;
}
else{
Status=false;
}
DBConstant.CloseDataBase();
return Status;
}
//// /**This function use for check User collection Exists or not*/
// private boolean Check_User_Collection_Exists(){
// boolean Status=false;
// DBConstant.OpenDatabase(this);
// if(DBConstant.mDBHelper.Select_COLLECTION_COUNT_USERID(DBConstant.mSQLiteDatabase,mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, "")) > 0){
// Status=true;
// }
// else{
// Status=false;
// }
// DBConstant.CloseDataBase();
// return Status;
// }
// /**This function use for check User collection Exists or not*/
// private boolean Check_User_Collection_Exists(int position){
// boolean Status=false;
// DBConstant.OpenDatabase(this);
// if(DBConstant.mDBHelper.Select_COLLECTION_COUNT_APPOINTMENT_FLAG(DBConstant.mSQLiteDatabase, Alst_appointment_id.get(position).toString().trim(),mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, "")) > 0){
// Status=true;
// }
// else{
// Status=false;
// }
// DBConstant.CloseDataBase();
// return Status;
// }
// /**This function use for check User collection Exists or not*/
// private boolean Check_User_Collection_Exists_Flag(int position){
// boolean Status=false;
// DBConstant.OpenDatabase(this);
// if(DBConstant.mDBHelper.Select_COLLECTION_COUNT_APPOINTMENT_FLAG(DBConstant.mSQLiteDatabase, Alst_appointment_id.get(position).toString().trim(),mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, "")) > 0){
// Status=true;
// }
// else{
// Status=false;
// }
// DBConstant.CloseDataBase();
// return Status;
// }
// /**This function use for check Finalize User collection Exists or not*/
private boolean Check_Finalize_User_Collection_Exists(String appointment_id){
boolean Status=false;
if(DBConstant.mDBHelper.Check_Pending_Leads_Status(DBConstant.mSQLiteDatabase, appointment_id, mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, "")) > 0){
Status=true;
}
else{
Status=false;
}
return Status;
}
private void Reached(int position,boolean visible){
if(visible){
GoToReach(position);
}
else{
boolean flag_status=true;
if(mLeadsPending_BaseAdapter!=null){
for(int i=0;i< mLeadsPending_BaseAdapter.BoolAppointment_Status.length;i++){
if(mLeadsPending_BaseAdapter.BoolAppointment_Status[i]){
Finalized_Previous_Alert();
flag_status=false;
break;
}
}
}
if(flag_status){
GoToReach(position);
}
}
}
private void GoToReach(int position){
// if(mCommonClass.CheckNetwork(LeadsPending.this)){
ClearSharedPreferences();
SharedPreferences.Editor mSharedPreferencesEdit = mSharedPreferencesWrite.edit();
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_APPOINTMENT_ID, Alst_appointment_id.get(position).toString().trim());
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_APP_DATE_TIME, Alst_app_date_time.get(position).toString().trim());
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_CUSTOMER_ID, Alst_customer_id.get(position).toString().trim());
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_CUSTOMER_NAME, Alst_customer_name.get(position).toString().trim());
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_CUSTOMR_CODE, Alst_customr_code.get(position).toString().trim());
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_ADDRESS, Alst_address.get(position).toString().trim());
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_MOBILE_NO, Alst_mobile_no.get(position).toString().trim());
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_LANDMARK, Alst_landmark.get(position).toString().trim());
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_PRICE_GROUP, Alst_price_group.get(position).toString().trim());
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_LATTITUDE, Alst_lattitude.get(position).toString().trim());
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_LONGITUDE, Alst_longitude.get(position).toString().trim());
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_VAT, Alst_vat.get(position).toString().trim().toUpperCase());
mSharedPreferencesEdit.putFloat(Constant.LEADSPENDING_SHARED.LPS_VAT_VAL,Float.parseFloat(Alst_vat_val.get(position)));
mSharedPreferencesEdit.commit();
Reached_Location();
// }
}
/**This function for Finalized Previous Alert*/
private void Finalized_Previous_Alert() {
AlertDialog mAlertDialog = new AlertDialog.Builder(this).create();
mAlertDialog.setTitle(Constant.FINALIZED_MESSAGE.FINALIZED_TITLE);
mAlertDialog.setMessage(Constant.FINALIZED_MESSAGE.FINALIZED_PREVIOUS_COLLECTION);
mAlertDialog.setCancelable(false);
mAlertDialog.setCanceledOnTouchOutside(false);
mAlertDialog.setButton(Constant.FINALIZED_MESSAGE.OK, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
});
// Create and show the dialog
mAlertDialog.show();
}
private void ClearSharedPreferences(){
SharedPreferences.Editor mSharedPreferencesEdit = mSharedPreferencesWrite.edit();
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_APPOINTMENT_ID, "");
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_APP_DATE_TIME, "");
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_CUSTOMER_ID, "");
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_CUSTOMER_NAME, "");
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_CUSTOMR_CODE, "");
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_ADDRESS, "");
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_MOBILE_NO, "");
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_LANDMARK, "");
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_PRICE_GROUP, "");
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_LATTITUDE, "");
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_LONGITUDE, "");
mSharedPreferencesEdit.putString(Constant.LEADSPENDING_SHARED.LPS_VAT, "");
mSharedPreferencesEdit.putFloat(Constant.LEADSPENDING_SHARED.LPS_VAT_VAL, 0.0f);
mSharedPreferencesEdit.commit();
}
/**This function for conformation to reached*/
private void Reached_Location() {
AlertDialog mAlertDialog = new AlertDialog.Builder(this).create();
mAlertDialog.setTitle(Constant.REACHED_MESSAGE.REACHED_TITLE);
mAlertDialog.setMessage(Constant.REACHED_MESSAGE.REACHED_TEXT);
mAlertDialog.setCancelable(false);
mAlertDialog.setCanceledOnTouchOutside(false);
mAlertDialog.setButton(Constant.YES, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if(strLatitude!=null && strLongitude!=null){
new SendLatLong().execute("Send Lat Long");
}
else{
Check_Update();
Log.i(Constant.TAG,Constant.LOCATION_MESSAGE);
// Toast.makeText(getApplicationContext(),Constant.LOCATION_MESSAGE, Toast.LENGTH_SHORT).show();
}
return;
}
});
mAlertDialog.setButton2(Constant.NO, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
return;
}
});
// Create and show the dialog
mAlertDialog.show();
}
/**This function for check database update*/
private void Check_Update(){
String LastDateTime="";
DBConstant.OpenDatabase(this);
LastDateTime=DBConstant.mDBHelper.Select_PRODUCT_MAX_DATETIME(DBConstant.mSQLiteDatabase);
DBConstant.CloseDataBase();
if(mCommonClass.CheckNetwork(this)){
Intent mIntent= new Intent(this,MainCategory.class);
GetMaster mGetMaster=new GetMaster(this,LastDateTime,mIntent);
mGetMaster.execute("Get All Data When Update DateTime");
}else{
Intent mIntent= new Intent(this,MainCategory.class);
startActivity(mIntent);
finish();
}
}
/**This function for send reached location*/
private class SendLatLong extends AsyncTask<String,String,String>{
private ProcessDialog mProcessDialog=null;
@Override
protected void onPreExecute() {
super.onPreExecute();
mProcessDialog= new ProcessDialog(LeadsPending.this,Constant.SERVER,Constant.LOADING);
}
@Override
protected String doInBackground(String... params) {
String strURL = getResources().getString(R.string.APPOINTMENT_URL);
ArrayList<NameValuePair> mNameValuePair = new ArrayList<NameValuePair>();
mNameValuePair.add(new BasicNameValuePair(Constant.REACHED_REQUEST.HDN_ACTION,Constant.REACHED_REQUEST.HDN_ACTION_APPOINTMENT));
mNameValuePair.add(new BasicNameValuePair(Constant.REACHED_REQUEST.ADMIN_USERID,mSharedPreferencesRead.getString(Constant.LOGIN_SHARED.LS_USERID, "")));
mNameValuePair.add(new BasicNameValuePair(Constant.REACHED_REQUEST.LATITUDE,strLatitude));
mNameValuePair.add(new BasicNameValuePair(Constant.REACHED_REQUEST.LONGITUDE,strLongitude));
mNameValuePair.add(new BasicNameValuePair(Constant.REACHED_REQUEST.CUSTOMER_CODE, mSharedPreferencesRead.getString(Constant.LEADSPENDING_SHARED.LPS_CUSTOMR_CODE, "")));
mNameValuePair.add(new BasicNameValuePair(Constant.REACHED_REQUEST.CUSTOMER_ID,mSharedPreferencesRead.getString(Constant.LEADSPENDING_SHARED.LPS_CUSTOMER_ID, "")));
mNameValuePair.add(new BasicNameValuePair(Constant.REACHED_REQUEST.APPOINTMENT_ID, mSharedPreferencesRead.getString(Constant.LEADSPENDING_SHARED.LPS_APPOINTMENT_ID, "")));
return mCommonClass.PostConnection(strURL, mNameValuePair);
}
@Override
protected void onPostExecute(String result) {
mProcessDialog.dismiss();
if(result!=null)
{
Log.i(Constant.TAG,"Appointment Response = " + result);
try {
JSONObject jsonAppointment = new JSONObject(result);
if(jsonAppointment.getString(Constant.COMMON_JSON.TYPE).equals(Constant.COMMON_JSON.OK)){
// Check_Update();
}else{
Toast.makeText(LeadsPending.this, jsonAppointment.getString(Constant.COMMON_JSON.ERR_MSG).toString(), Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
else{
Toast.makeText(LeadsPending.this, Constant.SERVERCONNERROR,Toast.LENGTH_SHORT).show();
}
Check_Update();
super.onPostExecute(result);
}
}
/**
* @param
* @author piyush
* {@docRoot}
* @see : Use for Dial phone no
* */
private void TelephoneDial(String Phoneno){
Intent iv = new Intent(Intent.ACTION_DIAL,Uri.parse("tel:" + Phoneno));
startActivity(iv);
}
/**
* @param
* @author piyush
* {@docRoot}
* @see This function use for open Google Map*/
private void MapLocation(String Latitude,String Longitude){
try{
// Toast.makeText(LeadsPending.this, "Lati :"+Latitude+"Long :"+Longitude, Toast.LENGTH_SHORT).show();
if( Latitude.equals("0") || Longitude.equals("0")){
Toast.makeText(LeadsPending.this, Constant.LOCATION_NOT_FOUND, Toast.LENGTH_SHORT).show();
}else{
Intent mIntent = new Intent(Intent.ACTION_VIEW);
mIntent.setData(Uri.parse("geo:0,0?q=" + (Latitude+","+Longitude)));
startActivity(mIntent);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected void onResume() {
AddLocationManager();
super.onResume();
}
@Override
protected void onPause() {
RemoveLocationManager();
super.onPause();
}
private LocationManager mLocationManager=null;
private LocationListener mLocationListener =null;
private String strLatitude=null,strLongitude=null;
/**Location Update Register*/
private void AddLocationManager() {
if(mLocationManager==null){
mLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
}
if(mLocationManager!=null)
{
if(mLocationManager.isProviderEnabled(Constant.PROVIDER)){
mLocationListener = new MyLocationListener();
mLocationManager.requestLocationUpdates( Constant.PROVIDER, 0, 1, mLocationListener);
}
else{
Toast.makeText(getApplicationContext(), Constant.PROVIDER_NOT,Toast.LENGTH_LONG).show();
mLocationManager=null;
mLocationListener=null;
}
}
}
/**Location Update Remove*/
private void RemoveLocationManager() {
if(mLocationListener!=null && mLocationManager!=null)
{
mLocationManager.removeUpdates(mLocationListener);
mLocationListener=null;
mLocationManager=null;
}
}
/** Class My Location Listener */
private class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location loc)
{
strLatitude=(String.valueOf(loc.getLatitude()));
strLongitude=(String.valueOf(loc.getLongitude()));
}
@Override
public void onProviderDisabled(String provider)
{
}
@Override
public void onProviderEnabled(String provider)
{
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
}/* End of Class MyLocationListener */
public void GoToCategory(){
Intent mIntent= new Intent(this,MainCategory.class);
startActivity(mIntent);
finish();
}
}
No comments:
Post a Comment