1)create class SalesBookingRequest.java
============================
package com.mrs.aspi_motors;
import java.util.ArrayList;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
public class SalesBookingRequest extends Activity implements OnClickListener{
private Spinner spnBrand = null;
private Spinner spnProduct = null;
private Spinner spnCarModel = null;
private Spinner spnColor = null;
private Button btnAccessories = null;
//private Spinner spnAccessories = null;
private Spinner spnBuying_Time_frame = null;
private int intBrandID = 0, intProductID = 0,intModelID = 0,intColorID = 0,intAccessories = 0,intBuying_Time_Frame = 0;
private CommanClass mCommanClass = null;
private SharedPreferences mSharedPreferencesRead=null;
private Button btnBack = null;
private Button btnSubmit = null;
private String strMessage = null;
private String strOwnerName = null;
private String strMobileNo = null;
private String strEmailId = null;
private EditText edtName_Of_Owner = null;
private EditText edtEmailID = null;
private EditText edtMobileNo = null;
private String strUserID = null;
private String strAccessoriesID;
private JSONArray jsonArrayAccessoriesID = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.xsales_booking_request);
mSharedPreferencesRead = getSharedPreferences(Constant.SHAREDPREFERENCES.SHAREDPREFERENCE, MODE_WORLD_READABLE);
//if(getIntent().getAction().equals(Constant.REGISTER_VEHICAL.REGISTER_VEHICAL_INTENT)){
strUserID = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_USER_ID, "");
strOwnerName = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_NAME_OF_OWNER, "");
strEmailId = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_EMAIL_ID, "");
strMobileNo = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_MOBILE_NO, "");
// }
// else if(getIntent().getAction().equals(Constant.LOGIN.LOGIN_SUBMIT_INTENT)){
// strOwnerName = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_NAME_OF_OWNER, "");
// strEmailId = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_EMAIL_ID, "");
// strMobileNo = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_MOBILE_NO, "");
// }
// else{
// strOwnerName = "";
// strEmailId = "";
// strMobileNo = "";
// }
// strOwnerName = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_NAME_OF_OWNER, "");
// strMobileNo = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_MOBILE_NO, "");
// strEmailId = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_EMAIL_ID, "");
mCommanClass = new CommanClass();
btnBack = (Button)findViewById(R.id.btnBack);
btnBack.setOnClickListener(this);
btnSubmit = (Button)findViewById(R.id.btnSubmit);
btnSubmit.setOnClickListener(this);
btnAccessories = (Button)findViewById(R.id.btnAccessories);
btnAccessories.setOnClickListener(this);
btnAccessories.setText(Constant.SPPINER_CONSTANT.SELECT_ACCESSORIES);
edtName_Of_Owner = (EditText)findViewById(R.id.edtNameOfOwner);
edtName_Of_Owner.setText(strOwnerName);
edtEmailID = (EditText)findViewById(R.id.edtEmail_Id);
edtEmailID.setText(strEmailId);
edtMobileNo = (EditText)findViewById(R.id.edtMobileNo);
edtMobileNo.setText(strMobileNo);
InItSpinnerData();
}
//***********************************************************************************************************************
/**
* @author Manisha
* @param none
* @return void
* @use This function is used for getBrandData
*/
private ArrayList<Integer> alstBrandID=null;
private ArrayAdapter<String> aadpBrandName=null;
private void GetBrandData() {
alstBrandID=new ArrayList<Integer>();
alstBrandID.clear();
aadpBrandName = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
aadpBrandName.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
aadpBrandName.clear();
spnBrand.setAdapter(aadpBrandName);
DBConstant.OpenDatabase(SalesBookingRequest.this);
Cursor c = DBConstant.mDBHelper.GET_BRNAD_DATA(DBConstant.mSQLiteDatabase);
if(c!=null){
if(c.getCount() > 0){
c.moveToFirst();
while(c.isAfterLast()==false){
alstBrandID.add(c.getInt(1));
aadpBrandName.add(c.getString(2).toString());
c.moveToNext();
}
spnBrand.setAdapter(aadpBrandName);
}
}
c.close();
DBConstant.CloseDataBase();
}
//***********************************************************************************************************************
/**
* @author Manisha
* @param none
* @return void
* @use This function is used for getProductData
*/
private ArrayList<Integer> alstProductID=null;
private ArrayAdapter<String> aadpProductName=null;
private void GetProductData(int pos){
alstProductID=new ArrayList<Integer>();
alstProductID.clear();
aadpProductName = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
aadpProductName.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
aadpProductName.clear();
spnProduct.setAdapter(aadpProductName);
DBConstant.OpenDatabase(SalesBookingRequest.this);
Cursor c = DBConstant.mDBHelper.GET_PRODUCT_DATA(DBConstant.mSQLiteDatabase,alstBrandID.get(pos));
if(c!=null){
if(c.getCount() > 0){
c.moveToFirst();
while(c.isAfterLast()==false){
alstProductID.add(c.getInt(1));
aadpProductName.add(c.getString(3).toString());
c.moveToNext();
}
spnProduct.setAdapter(aadpProductName);
}
}
c.close();
DBConstant.CloseDataBase();
}
//***********************************************************************************************************************
/**
* @author Manisha
* @param none
* @return void
* @use This function is used for getModelData
*/
private ArrayList<Integer> alstModelID=null;
private ArrayAdapter<String> aadpModeName=null;
private void GetModelData(int pos){
alstModelID=new ArrayList<Integer>();
alstModelID.clear();
aadpModeName = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
aadpModeName.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
aadpModeName.clear();
spnCarModel.setAdapter(aadpModeName);
DBConstant.OpenDatabase(SalesBookingRequest.this);
Cursor c = DBConstant.mDBHelper.GET_MODEL_DATA(DBConstant.mSQLiteDatabase,alstProductID.get(pos));
if(c!=null){
if(c.getCount() > 0){
c.moveToFirst();
while(c.isAfterLast()==false){
alstModelID.add(c.getInt(1));
aadpModeName.add(c.getString(3).toString());
c.moveToNext();
}
spnCarModel.setAdapter(aadpModeName);
}
}
c.close();
DBConstant.CloseDataBase();
}
//***********************************************************************************************************************
/**
* @author Manisha
* @param none
* @return void
* @use This function is used for getModelData
*/
private ArrayList<Integer> alstColorId=null;
private ArrayAdapter<String> aadpColorName=null;
private void GetColorData(){
alstColorId=new ArrayList<Integer>();
alstColorId.clear();
aadpColorName = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
aadpColorName.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
aadpColorName.clear();
spnColor.setAdapter(aadpColorName);
DBConstant.OpenDatabase(SalesBookingRequest.this);
Cursor c = DBConstant.mDBHelper.GET_COLOR_DATA(DBConstant.mSQLiteDatabase);
if(c!=null){
if(c.getCount() > 0){
c.moveToFirst();
while(c.isAfterLast()==false){
alstColorId.add(c.getInt(1));
aadpColorName.add(c.getString(2).toString());
c.moveToNext();
}
spnColor.setAdapter(aadpColorName);
}
}
c.close();
DBConstant.CloseDataBase();
}
//***********************************************************************************************************************
/**
* @author Manisha
* @param none
* @return void
* @use This function is used for getAccessoriesData
*/
//For get accessories data
// protected ArrayList<St> alstAccessories_Name = new ArrayList<CharSequence>();
private int[] mAccessoriesID = null;
private CharSequence[] maccessories_name = null;
private boolean[] checkPosition = null;
// private ArrayList<Integer> alstAccessories_Id=new ArrayList<Integer>();
public void showAccessoriesDialog() {
if(mAccessoriesID==null){
DBConstant.OpenDatabase(SalesBookingRequest.this);
Cursor c = DBConstant.mDBHelper.GET_ACCESSORIES_DATA(DBConstant.mSQLiteDatabase);
if(c!=null){
if(c.getCount() > 0){
int i = 0;
mAccessoriesID = new int[c.getCount()];
maccessories_name = new CharSequence[c.getCount()];
checkPosition = new boolean[c.getCount()];
c.moveToFirst();
while(c.isAfterLast()==false){
mAccessoriesID[i] = c.getInt(1);
maccessories_name[i] = c.getString(2).toString();
checkPosition[i]=false;
i++;
c.moveToNext();
}
}
if(!c.isClosed()){
c.close();
}
}
DBConstant.CloseDataBase();
}
DialogInterface.OnMultiChoiceClickListener PositionDailogListner = new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
checkPosition[which]=isChecked;
}
};
AlertDialog.Builder mAlertDialog_Builder = new AlertDialog.Builder(this);
mAlertDialog_Builder.setTitle(Constant.SPPINER_CONSTANT.SELECT_ACCESSORIES); //Select Position
mAlertDialog_Builder.setPositiveButton(Constant.COMMON_ALERT.POSITIVE_BUTTON, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
btnAccessories.setText("");
jsonArrayAccessoriesID = new JSONArray();
strAccessoriesID = "";
for(int i=0 ; i < checkPosition.length ; i++){
if(checkPosition[i]){
try {
jsonArrayAccessoriesID.put(mAccessoriesID[i]);
} catch (Exception e) {
e.printStackTrace();
}
if(btnAccessories.getText().toString().trim().equals("")){
btnAccessories.setText(maccessories_name[i]);
// strAccessoriesID = mAccessoriesID[i];
}else{
btnAccessories.setText(btnAccessories.getText() + "," +maccessories_name[i]);
}
}
}
dialog.cancel();
}
});
mAlertDialog_Builder.setMultiChoiceItems(maccessories_name, checkPosition, PositionDailogListner);
AlertDialog mAlertDialog = mAlertDialog_Builder.create();
mAlertDialog.show();
mAlertDialog.setCanceledOnTouchOutside(true);
}
//***********************************************************************************************************************
/**
* @author Manisha
* @param none
* @return void
* @use This function is used for getModelData
*/
private ArrayList<Integer> alstBuying_Time_Frame_Id=null;
private ArrayAdapter<String> aadpBuying_Time_Frame_Name=null;
private void GetBuying_Time_Frame_Data(){
alstBuying_Time_Frame_Id=new ArrayList<Integer>();
alstBuying_Time_Frame_Id.clear();
aadpBuying_Time_Frame_Name = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
aadpBuying_Time_Frame_Name.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
aadpBuying_Time_Frame_Name.clear();
spnBuying_Time_frame.setAdapter(aadpBuying_Time_Frame_Name);
DBConstant.OpenDatabase(SalesBookingRequest.this);
Cursor c = DBConstant.mDBHelper.GET_BUYING_TIME_FRAME_DATA(DBConstant.mSQLiteDatabase);
if(c!=null){
if(c.getCount() > 0){
c.moveToFirst();
while(c.isAfterLast()==false){
alstBuying_Time_Frame_Id.add(c.getInt(1));
aadpBuying_Time_Frame_Name.add(c.getString(2).toString());
c.moveToNext();
}
spnBuying_Time_frame.setAdapter(aadpBuying_Time_Frame_Name);
}
}
c.close();
DBConstant.CloseDataBase();
}
//***********************************************************************************************************************
/**
* @author Manisha
* @param none
* @return void
* @use This function is used for get data for spinner
*/
public void InItSpinnerData(){
spnBrand = (Spinner)findViewById(R.id.spnBrand);
spnProduct = (Spinner)findViewById(R.id.spnProduct);
spnCarModel = (Spinner)findViewById(R.id.spnModel);
spnColor = (Spinner)findViewById(R.id.spnColor);
// spnAccessories = (Spinner)findViewById(R.id.spnAccessories);
spnBuying_Time_frame = (Spinner)findViewById(R.id.spnBuyingTimeFrame);
GetBrandData();
GetColorData();
// GetAccessoriesData();
GetBuying_Time_Frame_Data();
spnBrand.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
intBrandID = alstBrandID.get(arg2);
System.out.println("intBrandID=="+intBrandID);
GetProductData(arg2);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
spnProduct.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
intProductID = alstProductID.get(arg2);
GetModelData(arg2);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
spnCarModel.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
intModelID = alstModelID.get(arg2);
System.out.println("intModelID====="+intModelID);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
spnColor.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
intColorID = alstColorId.get(arg2);
System.out.println("intColorID====="+intColorID);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
// spnAccessories.setOnItemSelectedListener(new OnItemSelectedListener() {
// @Override
// public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
// intAccessories = alstAccessories_Id.get(arg2);
// System.out.println("intAccessories====="+intAccessories);
// }
// @Override
// public void onNothingSelected(AdapterView<?> arg0) {
//
// }
// });
//
spnBuying_Time_frame.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
intBuying_Time_Frame = alstBuying_Time_Frame_Id.get(arg2);
System.out.println("intBuying_Time_Frame====="+intBuying_Time_Frame);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
}
//************************************************************************************************************************************
//This class is used for get Add appointment
private class Sales_Booking_Request extends AsyncTask<String, String, String>
{
private ProcessDialog mProcessDialog=null;
protected void onPreExecute() {
mProcessDialog = new ProcessDialog(SalesBookingRequest.this,Constant.PROGRESSBAR.SERVER,Constant.PROGRESSBAR.LOADING);
super.onPreExecute();
}
protected String doInBackground(String... params){
String strURL = getResources().getString(R.string.SALES_BOOKING_REQUEST_URL);
ArrayList<NameValuePair> mNameValuePair = new ArrayList<NameValuePair>();
mNameValuePair.add(new BasicNameValuePair(Constant.SALES_BOOKING_REQUEST.ID, strUserID.toString().trim()));
mNameValuePair.add(new BasicNameValuePair(Constant.SALES_BOOKING_REQUEST.BRAND, String.valueOf(intBrandID)));
mNameValuePair.add(new BasicNameValuePair(Constant.SALES_BOOKING_REQUEST.PRODUCT, String.valueOf(intProductID)));
mNameValuePair.add(new BasicNameValuePair(Constant.SALES_BOOKING_REQUEST.MODEL, String.valueOf(intModelID)));
mNameValuePair.add(new BasicNameValuePair(Constant.SALES_BOOKING_REQUEST.COLOR, String.valueOf(intColorID)));
mNameValuePair.add(new BasicNameValuePair(Constant.SALES_BOOKING_REQUEST.ACCESSORIES, jsonArrayAccessoriesID.toString()));
mNameValuePair.add(new BasicNameValuePair(Constant.SALES_BOOKING_REQUEST.BUYING_TME_FRAME, String.valueOf(intBuying_Time_Frame)));
mNameValuePair.add(new BasicNameValuePair(Constant.SALES_BOOKING_REQUEST.OWNER_NAME, edtName_Of_Owner.getText().toString().trim()));
mNameValuePair.add(new BasicNameValuePair(Constant.SALES_BOOKING_REQUEST.MOBILE_NO, edtMobileNo.getText().toString().trim()));
mNameValuePair.add(new BasicNameValuePair(Constant.SALES_BOOKING_REQUEST.EMAIL_ID, edtEmailID.getText().toString().trim()));
System.out.println("SalesBooking Request==="+mNameValuePair.toString());
return mCommanClass.PostConnection(strURL, mNameValuePair);
}
protected void onPostExecute(String result){
mProcessDialog.dismiss();
if(result!=null){
// System.out.println("Sales Booking Response====="+result.toString());
try {
JSONObject mJSONOBJECT = new JSONObject(result);
String strType = mJSONOBJECT.getString(Constant.JSON.TYPE);
if(strType.equalsIgnoreCase(Constant.JSON.OK)){
strMessage = mJSONOBJECT.getString(Constant.JSON.MESSAGE);
// JSONObject mJSONOBJECT_RESULT = mJSONOBJECT.getJSONObject(Constant.JSON.RESULT);
// //strUserId = mJSONOBJECT_RESULT.getString(Constant.REGISTER_VEHICAL_RESPONSE.USER_ID);
SalesBookingRequestDialog();
}
else{
strMessage = mJSONOBJECT.getString(Constant.JSON.MESSAGE);
SalesBookingFailRequestDialog();
//Toast.makeText(SalesInquiry.this,mJSONOBJECT.getString(Constant.JSON.MESSAGE), Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
else{
Toast.makeText(SalesBookingRequest.this,Constant.SERVERCONNERROR, Toast.LENGTH_SHORT).show();
}
super.onPostExecute(result);
}
}
private boolean BlankSpinner(){
boolean boolBlank = true;
if(spnBrand.getSelectedItem().equals(Constant.SPPINER_CONSTANT.SELECT_BRNAD)){
Toast.makeText(SalesBookingRequest.this,Constant.SPPINER_TOAST_CONSTANT.SELECT_BRNAD,Toast.LENGTH_SHORT).show();
boolBlank = true;
}
else if(spnProduct.getSelectedItem().equals(Constant.SPPINER_CONSTANT.SELECT_PRODUCT)){
Toast.makeText(SalesBookingRequest.this,Constant.SPPINER_TOAST_CONSTANT.SELECT_PRODUCT,Toast.LENGTH_SHORT).show();
boolBlank = true;
}
else if(spnCarModel.getSelectedItem().equals(Constant.SPPINER_CONSTANT.SELECT_MODEL)){
Toast.makeText(SalesBookingRequest.this,Constant.SPPINER_TOAST_CONSTANT.SELECT_MODEL,Toast.LENGTH_SHORT).show();
boolBlank = true;
}
else if(spnColor.getSelectedItem().equals(Constant.SPPINER_CONSTANT.SELECT_COLOR)){
Toast.makeText(SalesBookingRequest.this,Constant.SPPINER_TOAST_CONSTANT.SELECT_COLOR,Toast.LENGTH_SHORT).show();
boolBlank = true;
}
else if(btnAccessories.getText().equals(Constant.SPPINER_CONSTANT.SELECT_ACCESSORIES)){
Toast.makeText(SalesBookingRequest.this,Constant.SPPINER_TOAST_CONSTANT.SELECT_ACCESSORIES,Toast.LENGTH_SHORT).show();
boolBlank = true;
}
else if(spnBuying_Time_frame.getSelectedItem().equals(Constant.SPPINER_CONSTANT.SELECT_BUYING_TIME_FRAME)){
Toast.makeText(SalesBookingRequest.this,Constant.SPPINER_TOAST_CONSTANT.SELECT_BUYING_TIME_FRAME,Toast.LENGTH_SHORT).show();
boolBlank = true;
}
else{
boolBlank = false;
}
return boolBlank;
}
//***********************************************************************************************************************
/**
* @author Manisha
* @param none
* @return void
* @use This Dialog is used for show SalesBookingRequestDialog
*/
public void SalesBookingRequestDialog(){
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(SalesBookingRequest.this);
alertDialogBuilder
.setMessage(strMessage)
.setCancelable(false)
.setPositiveButton(Constant.COMMON_ALERT.POSITIVE_BUTTON,new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
finish();
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
public void SalesBookingFailRequestDialog(){
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(SalesBookingRequest.this);
alertDialogBuilder
.setMessage(strMessage)
.setCancelable(false)
.setPositiveButton(Constant.COMMON_ALERT.POSITIVE_BUTTON,new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
@Override
public void onClick(View v) {
if(v==btnBack){
finish();
}
else if(v==btnSubmit){
if(!BlankSpinner()){
if(!check_not_null() ){
if(mCommanClass.CheckNetwork(this)){
new Sales_Booking_Request().execute("");
}
}
}
}
else if(v==btnAccessories){
showAccessoriesDialog();
}
}
private boolean check_not_null()
{
boolean blank = true;
if (edtName_Of_Owner.getText().toString().equals("") || edtEmailID.getText().toString().equals("")
|| edtMobileNo.getText().toString().equals("")) {
Toast.makeText(this, Constant.REGISTER_VEHICAL.FILL_REQUIRED_FIELD, Toast.LENGTH_SHORT).show();
blank = true;
}else if(edtMobileNo.getText().length() < 10){
Toast.makeText(this, Constant.REGISTER_VEHICAL.FILL_MOBILE_NO,Toast.LENGTH_LONG).show();
}
else {
if(CommanClass.isEmailValid(edtEmailID.getText().toString()) == false){
edtEmailID.setText("");
Toast.makeText(this, Html.fromHtml(Constant.REGISTER_VEHICAL.ENTER_VALID_EMAILID) , Toast.LENGTH_SHORT).show();
blank = true;
}else{
blank = false;
}
}
return blank;
}
}
2)
============================
package com.mrs.aspi_motors;
import java.util.ArrayList;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
public class SalesBookingRequest extends Activity implements OnClickListener{
private Spinner spnBrand = null;
private Spinner spnProduct = null;
private Spinner spnCarModel = null;
private Spinner spnColor = null;
private Button btnAccessories = null;
//private Spinner spnAccessories = null;
private Spinner spnBuying_Time_frame = null;
private int intBrandID = 0, intProductID = 0,intModelID = 0,intColorID = 0,intAccessories = 0,intBuying_Time_Frame = 0;
private CommanClass mCommanClass = null;
private SharedPreferences mSharedPreferencesRead=null;
private Button btnBack = null;
private Button btnSubmit = null;
private String strMessage = null;
private String strOwnerName = null;
private String strMobileNo = null;
private String strEmailId = null;
private EditText edtName_Of_Owner = null;
private EditText edtEmailID = null;
private EditText edtMobileNo = null;
private String strUserID = null;
private String strAccessoriesID;
private JSONArray jsonArrayAccessoriesID = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.xsales_booking_request);
mSharedPreferencesRead = getSharedPreferences(Constant.SHAREDPREFERENCES.SHAREDPREFERENCE, MODE_WORLD_READABLE);
//if(getIntent().getAction().equals(Constant.REGISTER_VEHICAL.REGISTER_VEHICAL_INTENT)){
strUserID = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_USER_ID, "");
strOwnerName = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_NAME_OF_OWNER, "");
strEmailId = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_EMAIL_ID, "");
strMobileNo = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_MOBILE_NO, "");
// }
// else if(getIntent().getAction().equals(Constant.LOGIN.LOGIN_SUBMIT_INTENT)){
// strOwnerName = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_NAME_OF_OWNER, "");
// strEmailId = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_EMAIL_ID, "");
// strMobileNo = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_MOBILE_NO, "");
// }
// else{
// strOwnerName = "";
// strEmailId = "";
// strMobileNo = "";
// }
// strOwnerName = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_NAME_OF_OWNER, "");
// strMobileNo = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_MOBILE_NO, "");
// strEmailId = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_EMAIL_ID, "");
mCommanClass = new CommanClass();
btnBack = (Button)findViewById(R.id.btnBack);
btnBack.setOnClickListener(this);
btnSubmit = (Button)findViewById(R.id.btnSubmit);
btnSubmit.setOnClickListener(this);
btnAccessories = (Button)findViewById(R.id.btnAccessories);
btnAccessories.setOnClickListener(this);
btnAccessories.setText(Constant.SPPINER_CONSTANT.SELECT_ACCESSORIES);
edtName_Of_Owner = (EditText)findViewById(R.id.edtNameOfOwner);
edtName_Of_Owner.setText(strOwnerName);
edtEmailID = (EditText)findViewById(R.id.edtEmail_Id);
edtEmailID.setText(strEmailId);
edtMobileNo = (EditText)findViewById(R.id.edtMobileNo);
edtMobileNo.setText(strMobileNo);
InItSpinnerData();
}
//***********************************************************************************************************************
/**
* @author Manisha
* @param none
* @return void
* @use This function is used for getBrandData
*/
private ArrayList<Integer> alstBrandID=null;
private ArrayAdapter<String> aadpBrandName=null;
private void GetBrandData() {
alstBrandID=new ArrayList<Integer>();
alstBrandID.clear();
aadpBrandName = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
aadpBrandName.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
aadpBrandName.clear();
spnBrand.setAdapter(aadpBrandName);
DBConstant.OpenDatabase(SalesBookingRequest.this);
Cursor c = DBConstant.mDBHelper.GET_BRNAD_DATA(DBConstant.mSQLiteDatabase);
if(c!=null){
if(c.getCount() > 0){
c.moveToFirst();
while(c.isAfterLast()==false){
alstBrandID.add(c.getInt(1));
aadpBrandName.add(c.getString(2).toString());
c.moveToNext();
}
spnBrand.setAdapter(aadpBrandName);
}
}
c.close();
DBConstant.CloseDataBase();
}
//***********************************************************************************************************************
/**
* @author Manisha
* @param none
* @return void
* @use This function is used for getProductData
*/
private ArrayList<Integer> alstProductID=null;
private ArrayAdapter<String> aadpProductName=null;
private void GetProductData(int pos){
alstProductID=new ArrayList<Integer>();
alstProductID.clear();
aadpProductName = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
aadpProductName.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
aadpProductName.clear();
spnProduct.setAdapter(aadpProductName);
DBConstant.OpenDatabase(SalesBookingRequest.this);
Cursor c = DBConstant.mDBHelper.GET_PRODUCT_DATA(DBConstant.mSQLiteDatabase,alstBrandID.get(pos));
if(c!=null){
if(c.getCount() > 0){
c.moveToFirst();
while(c.isAfterLast()==false){
alstProductID.add(c.getInt(1));
aadpProductName.add(c.getString(3).toString());
c.moveToNext();
}
spnProduct.setAdapter(aadpProductName);
}
}
c.close();
DBConstant.CloseDataBase();
}
//***********************************************************************************************************************
/**
* @author Manisha
* @param none
* @return void
* @use This function is used for getModelData
*/
private ArrayList<Integer> alstModelID=null;
private ArrayAdapter<String> aadpModeName=null;
private void GetModelData(int pos){
alstModelID=new ArrayList<Integer>();
alstModelID.clear();
aadpModeName = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
aadpModeName.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
aadpModeName.clear();
spnCarModel.setAdapter(aadpModeName);
DBConstant.OpenDatabase(SalesBookingRequest.this);
Cursor c = DBConstant.mDBHelper.GET_MODEL_DATA(DBConstant.mSQLiteDatabase,alstProductID.get(pos));
if(c!=null){
if(c.getCount() > 0){
c.moveToFirst();
while(c.isAfterLast()==false){
alstModelID.add(c.getInt(1));
aadpModeName.add(c.getString(3).toString());
c.moveToNext();
}
spnCarModel.setAdapter(aadpModeName);
}
}
c.close();
DBConstant.CloseDataBase();
}
//***********************************************************************************************************************
/**
* @author Manisha
* @param none
* @return void
* @use This function is used for getModelData
*/
private ArrayList<Integer> alstColorId=null;
private ArrayAdapter<String> aadpColorName=null;
private void GetColorData(){
alstColorId=new ArrayList<Integer>();
alstColorId.clear();
aadpColorName = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
aadpColorName.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
aadpColorName.clear();
spnColor.setAdapter(aadpColorName);
DBConstant.OpenDatabase(SalesBookingRequest.this);
Cursor c = DBConstant.mDBHelper.GET_COLOR_DATA(DBConstant.mSQLiteDatabase);
if(c!=null){
if(c.getCount() > 0){
c.moveToFirst();
while(c.isAfterLast()==false){
alstColorId.add(c.getInt(1));
aadpColorName.add(c.getString(2).toString());
c.moveToNext();
}
spnColor.setAdapter(aadpColorName);
}
}
c.close();
DBConstant.CloseDataBase();
}
//***********************************************************************************************************************
/**
* @author Manisha
* @param none
* @return void
* @use This function is used for getAccessoriesData
*/
//For get accessories data
// protected ArrayList<St> alstAccessories_Name = new ArrayList<CharSequence>();
private int[] mAccessoriesID = null;
private CharSequence[] maccessories_name = null;
private boolean[] checkPosition = null;
// private ArrayList<Integer> alstAccessories_Id=new ArrayList<Integer>();
public void showAccessoriesDialog() {
if(mAccessoriesID==null){
DBConstant.OpenDatabase(SalesBookingRequest.this);
Cursor c = DBConstant.mDBHelper.GET_ACCESSORIES_DATA(DBConstant.mSQLiteDatabase);
if(c!=null){
if(c.getCount() > 0){
int i = 0;
mAccessoriesID = new int[c.getCount()];
maccessories_name = new CharSequence[c.getCount()];
checkPosition = new boolean[c.getCount()];
c.moveToFirst();
while(c.isAfterLast()==false){
mAccessoriesID[i] = c.getInt(1);
maccessories_name[i] = c.getString(2).toString();
checkPosition[i]=false;
i++;
c.moveToNext();
}
}
if(!c.isClosed()){
c.close();
}
}
DBConstant.CloseDataBase();
}
DialogInterface.OnMultiChoiceClickListener PositionDailogListner = new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
checkPosition[which]=isChecked;
}
};
AlertDialog.Builder mAlertDialog_Builder = new AlertDialog.Builder(this);
mAlertDialog_Builder.setTitle(Constant.SPPINER_CONSTANT.SELECT_ACCESSORIES); //Select Position
mAlertDialog_Builder.setPositiveButton(Constant.COMMON_ALERT.POSITIVE_BUTTON, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
btnAccessories.setText("");
jsonArrayAccessoriesID = new JSONArray();
strAccessoriesID = "";
for(int i=0 ; i < checkPosition.length ; i++){
if(checkPosition[i]){
try {
jsonArrayAccessoriesID.put(mAccessoriesID[i]);
} catch (Exception e) {
e.printStackTrace();
}
if(btnAccessories.getText().toString().trim().equals("")){
btnAccessories.setText(maccessories_name[i]);
// strAccessoriesID = mAccessoriesID[i];
}else{
btnAccessories.setText(btnAccessories.getText() + "," +maccessories_name[i]);
}
}
}
dialog.cancel();
}
});
mAlertDialog_Builder.setMultiChoiceItems(maccessories_name, checkPosition, PositionDailogListner);
AlertDialog mAlertDialog = mAlertDialog_Builder.create();
mAlertDialog.show();
mAlertDialog.setCanceledOnTouchOutside(true);
}
//***********************************************************************************************************************
/**
* @author Manisha
* @param none
* @return void
* @use This function is used for getModelData
*/
private ArrayList<Integer> alstBuying_Time_Frame_Id=null;
private ArrayAdapter<String> aadpBuying_Time_Frame_Name=null;
private void GetBuying_Time_Frame_Data(){
alstBuying_Time_Frame_Id=new ArrayList<Integer>();
alstBuying_Time_Frame_Id.clear();
aadpBuying_Time_Frame_Name = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
aadpBuying_Time_Frame_Name.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
aadpBuying_Time_Frame_Name.clear();
spnBuying_Time_frame.setAdapter(aadpBuying_Time_Frame_Name);
DBConstant.OpenDatabase(SalesBookingRequest.this);
Cursor c = DBConstant.mDBHelper.GET_BUYING_TIME_FRAME_DATA(DBConstant.mSQLiteDatabase);
if(c!=null){
if(c.getCount() > 0){
c.moveToFirst();
while(c.isAfterLast()==false){
alstBuying_Time_Frame_Id.add(c.getInt(1));
aadpBuying_Time_Frame_Name.add(c.getString(2).toString());
c.moveToNext();
}
spnBuying_Time_frame.setAdapter(aadpBuying_Time_Frame_Name);
}
}
c.close();
DBConstant.CloseDataBase();
}
//***********************************************************************************************************************
/**
* @author Manisha
* @param none
* @return void
* @use This function is used for get data for spinner
*/
public void InItSpinnerData(){
spnBrand = (Spinner)findViewById(R.id.spnBrand);
spnProduct = (Spinner)findViewById(R.id.spnProduct);
spnCarModel = (Spinner)findViewById(R.id.spnModel);
spnColor = (Spinner)findViewById(R.id.spnColor);
// spnAccessories = (Spinner)findViewById(R.id.spnAccessories);
spnBuying_Time_frame = (Spinner)findViewById(R.id.spnBuyingTimeFrame);
GetBrandData();
GetColorData();
// GetAccessoriesData();
GetBuying_Time_Frame_Data();
spnBrand.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
intBrandID = alstBrandID.get(arg2);
System.out.println("intBrandID=="+intBrandID);
GetProductData(arg2);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
spnProduct.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
intProductID = alstProductID.get(arg2);
GetModelData(arg2);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
spnCarModel.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
intModelID = alstModelID.get(arg2);
System.out.println("intModelID====="+intModelID);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
spnColor.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
intColorID = alstColorId.get(arg2);
System.out.println("intColorID====="+intColorID);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
// spnAccessories.setOnItemSelectedListener(new OnItemSelectedListener() {
// @Override
// public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
// intAccessories = alstAccessories_Id.get(arg2);
// System.out.println("intAccessories====="+intAccessories);
// }
// @Override
// public void onNothingSelected(AdapterView<?> arg0) {
//
// }
// });
//
spnBuying_Time_frame.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
intBuying_Time_Frame = alstBuying_Time_Frame_Id.get(arg2);
System.out.println("intBuying_Time_Frame====="+intBuying_Time_Frame);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
}
//************************************************************************************************************************************
//This class is used for get Add appointment
private class Sales_Booking_Request extends AsyncTask<String, String, String>
{
private ProcessDialog mProcessDialog=null;
protected void onPreExecute() {
mProcessDialog = new ProcessDialog(SalesBookingRequest.this,Constant.PROGRESSBAR.SERVER,Constant.PROGRESSBAR.LOADING);
super.onPreExecute();
}
protected String doInBackground(String... params){
String strURL = getResources().getString(R.string.SALES_BOOKING_REQUEST_URL);
ArrayList<NameValuePair> mNameValuePair = new ArrayList<NameValuePair>();
mNameValuePair.add(new BasicNameValuePair(Constant.SALES_BOOKING_REQUEST.ID, strUserID.toString().trim()));
mNameValuePair.add(new BasicNameValuePair(Constant.SALES_BOOKING_REQUEST.BRAND, String.valueOf(intBrandID)));
mNameValuePair.add(new BasicNameValuePair(Constant.SALES_BOOKING_REQUEST.PRODUCT, String.valueOf(intProductID)));
mNameValuePair.add(new BasicNameValuePair(Constant.SALES_BOOKING_REQUEST.MODEL, String.valueOf(intModelID)));
mNameValuePair.add(new BasicNameValuePair(Constant.SALES_BOOKING_REQUEST.COLOR, String.valueOf(intColorID)));
mNameValuePair.add(new BasicNameValuePair(Constant.SALES_BOOKING_REQUEST.ACCESSORIES, jsonArrayAccessoriesID.toString()));
mNameValuePair.add(new BasicNameValuePair(Constant.SALES_BOOKING_REQUEST.BUYING_TME_FRAME, String.valueOf(intBuying_Time_Frame)));
mNameValuePair.add(new BasicNameValuePair(Constant.SALES_BOOKING_REQUEST.OWNER_NAME, edtName_Of_Owner.getText().toString().trim()));
mNameValuePair.add(new BasicNameValuePair(Constant.SALES_BOOKING_REQUEST.MOBILE_NO, edtMobileNo.getText().toString().trim()));
mNameValuePair.add(new BasicNameValuePair(Constant.SALES_BOOKING_REQUEST.EMAIL_ID, edtEmailID.getText().toString().trim()));
System.out.println("SalesBooking Request==="+mNameValuePair.toString());
return mCommanClass.PostConnection(strURL, mNameValuePair);
}
protected void onPostExecute(String result){
mProcessDialog.dismiss();
if(result!=null){
// System.out.println("Sales Booking Response====="+result.toString());
try {
JSONObject mJSONOBJECT = new JSONObject(result);
String strType = mJSONOBJECT.getString(Constant.JSON.TYPE);
if(strType.equalsIgnoreCase(Constant.JSON.OK)){
strMessage = mJSONOBJECT.getString(Constant.JSON.MESSAGE);
// JSONObject mJSONOBJECT_RESULT = mJSONOBJECT.getJSONObject(Constant.JSON.RESULT);
// //strUserId = mJSONOBJECT_RESULT.getString(Constant.REGISTER_VEHICAL_RESPONSE.USER_ID);
SalesBookingRequestDialog();
}
else{
strMessage = mJSONOBJECT.getString(Constant.JSON.MESSAGE);
SalesBookingFailRequestDialog();
//Toast.makeText(SalesInquiry.this,mJSONOBJECT.getString(Constant.JSON.MESSAGE), Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
else{
Toast.makeText(SalesBookingRequest.this,Constant.SERVERCONNERROR, Toast.LENGTH_SHORT).show();
}
super.onPostExecute(result);
}
}
private boolean BlankSpinner(){
boolean boolBlank = true;
if(spnBrand.getSelectedItem().equals(Constant.SPPINER_CONSTANT.SELECT_BRNAD)){
Toast.makeText(SalesBookingRequest.this,Constant.SPPINER_TOAST_CONSTANT.SELECT_BRNAD,Toast.LENGTH_SHORT).show();
boolBlank = true;
}
else if(spnProduct.getSelectedItem().equals(Constant.SPPINER_CONSTANT.SELECT_PRODUCT)){
Toast.makeText(SalesBookingRequest.this,Constant.SPPINER_TOAST_CONSTANT.SELECT_PRODUCT,Toast.LENGTH_SHORT).show();
boolBlank = true;
}
else if(spnCarModel.getSelectedItem().equals(Constant.SPPINER_CONSTANT.SELECT_MODEL)){
Toast.makeText(SalesBookingRequest.this,Constant.SPPINER_TOAST_CONSTANT.SELECT_MODEL,Toast.LENGTH_SHORT).show();
boolBlank = true;
}
else if(spnColor.getSelectedItem().equals(Constant.SPPINER_CONSTANT.SELECT_COLOR)){
Toast.makeText(SalesBookingRequest.this,Constant.SPPINER_TOAST_CONSTANT.SELECT_COLOR,Toast.LENGTH_SHORT).show();
boolBlank = true;
}
else if(btnAccessories.getText().equals(Constant.SPPINER_CONSTANT.SELECT_ACCESSORIES)){
Toast.makeText(SalesBookingRequest.this,Constant.SPPINER_TOAST_CONSTANT.SELECT_ACCESSORIES,Toast.LENGTH_SHORT).show();
boolBlank = true;
}
else if(spnBuying_Time_frame.getSelectedItem().equals(Constant.SPPINER_CONSTANT.SELECT_BUYING_TIME_FRAME)){
Toast.makeText(SalesBookingRequest.this,Constant.SPPINER_TOAST_CONSTANT.SELECT_BUYING_TIME_FRAME,Toast.LENGTH_SHORT).show();
boolBlank = true;
}
else{
boolBlank = false;
}
return boolBlank;
}
//***********************************************************************************************************************
/**
* @author Manisha
* @param none
* @return void
* @use This Dialog is used for show SalesBookingRequestDialog
*/
public void SalesBookingRequestDialog(){
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(SalesBookingRequest.this);
alertDialogBuilder
.setMessage(strMessage)
.setCancelable(false)
.setPositiveButton(Constant.COMMON_ALERT.POSITIVE_BUTTON,new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
finish();
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
public void SalesBookingFailRequestDialog(){
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(SalesBookingRequest.this);
alertDialogBuilder
.setMessage(strMessage)
.setCancelable(false)
.setPositiveButton(Constant.COMMON_ALERT.POSITIVE_BUTTON,new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
@Override
public void onClick(View v) {
if(v==btnBack){
finish();
}
else if(v==btnSubmit){
if(!BlankSpinner()){
if(!check_not_null() ){
if(mCommanClass.CheckNetwork(this)){
new Sales_Booking_Request().execute("");
}
}
}
}
else if(v==btnAccessories){
showAccessoriesDialog();
}
}
private boolean check_not_null()
{
boolean blank = true;
if (edtName_Of_Owner.getText().toString().equals("") || edtEmailID.getText().toString().equals("")
|| edtMobileNo.getText().toString().equals("")) {
Toast.makeText(this, Constant.REGISTER_VEHICAL.FILL_REQUIRED_FIELD, Toast.LENGTH_SHORT).show();
blank = true;
}else if(edtMobileNo.getText().length() < 10){
Toast.makeText(this, Constant.REGISTER_VEHICAL.FILL_MOBILE_NO,Toast.LENGTH_LONG).show();
}
else {
if(CommanClass.isEmailValid(edtEmailID.getText().toString()) == false){
edtEmailID.setText("");
Toast.makeText(this, Html.fromHtml(Constant.REGISTER_VEHICAL.ENTER_VALID_EMAILID) , Toast.LENGTH_SHORT).show();
blank = true;
}else{
blank = false;
}
}
return blank;
}
}
2)
No comments:
Post a Comment