NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package com.example.asusrog.papajohns;

import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.NumberPicker;
import android.widget.TextView;
import android.widget.Toast;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;

public class OrderActivity extends AppCompatActivity {


Button order;
Button deletall;
String usid;
Context context;
SQLiteDatabase db;
ArrayList<String[]> listM = new ArrayList<String[]>();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_order);
context=this;
ListView lstview=(ListView)findViewById(R.id.listView2);
order = (Button) findViewById(R.id.orderBT);
deletall =(Button) findViewById(R.id.deletallBT);


db = openOrCreateDatabase("papaJ", Context.MODE_PRIVATE, null);


Cursor u = db.rawQuery("SELECT email as uid FROM users",null);
if(u!=null && u.moveToFirst()) {
usid = (String) u.getString(u.getColumnIndex("uid"));
}else
usid = "-1";


db.execSQL("CREATE TABLE IF NOT EXISTS orderItem(" +
" id INTEGER PRIMARY KEY AUTOINCREMENT," +
" pizzaID INT(11) NOT NULL, " +
" pizzaName VARCHAR(250) not null," +
" size VARCHAR(10) NOT NULL," +
" type VARCHAR(10) NOT NULL," +
" quan INT(2) NOT NULL," +
" price FLOAT(10) NOT NULL," +
" uid VARCHAR(250) NOT NULL );");



Cursor c = db.rawQuery("Select * from orderItem WHERE uid =""+usid+"";", null);




if (c.moveToFirst()) {
do {
String[] items1=new String[7];
items1[0]=c.getString(c.getColumnIndex("pizzaID"));
items1[1]=c.getString(c.getColumnIndex("pizzaName"));
items1[2]=c.getString(c.getColumnIndex("size"));
items1[3]=c.getString(c.getColumnIndex("type"));
items1[4]=c.getString( c.getColumnIndex("quan"));
items1[5]=c.getString( c.getColumnIndex("price"));
items1[6]=c.getString( c.getColumnIndex("id"));
listM.add(items1);
} while (c.moveToNext());
}

c.close();

TextView TotalPticeBT= (TextView) findViewById(R.id.totalpriceTV);
TextView TotalQuanBT= (TextView) findViewById(R.id.totalQuanTV);


Cursor c2 = db.rawQuery("SELECT SUM(price) AS tota from orderItem WHERE uid =""+usid+"";", null);

if (c2!=null && c2.moveToFirst()) {

TotalPticeBT.setText(c2.getString(c2.getColumnIndex("tota")));
}

c2.close();
Cursor cw = db.rawQuery("SELECT SUM(quan) AS totalq from orderItem WHERE uid =""+usid+"";", null);
if (cw!=null && cw.moveToFirst()) {
TotalQuanBT.setText(cw.getString(cw.getColumnIndex("totalq")));
}cw.close();




order.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

new AlertDialog.Builder(context)
.setTitle("Make Order")
.setMessage("Are You sure you want to make this order ?")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {

String dis="0",status="0",cLoction="MANAMABRUNCH";

Cursor c2 = db.rawQuery("SELECT email from users;", null);
if(c2.moveToFirst()) {
String userEmail = c2.getString(0);

new PostAsync().execute(dis, status,cLoction,userEmail,"order desc");
}else{

}

}
})
.show();
}
});

deletall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new AlertDialog.Builder(context)
.setTitle("Delete all items")
.setMessage("Are You sure you want to Delete all items ?")
.setNegativeButton("NO", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do nothing
}
})
.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
db.execSQL("DROP TABLE orderItem;");
Intent nextScreen = new Intent(getApplicationContext(), MenuActivity.class);

startActivity(nextScreen);
finish();
}
})
.show();
}
});
lstview.setOnItemClickListener(new AdapterView.OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view, final int position, long id){

new AlertDialog.Builder(context)
.setTitle("Order Item Details")
.setMessage("View details of item here! n And view image if you want")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do nothing
Toast.makeText(OrderActivity.this, "Make new order row in web servis n " +
"put all order item in orderItem table with order id " +
"n delete all order item from local database ", Toast.LENGTH_LONG).show();

}
})
.show();
// Toast.makeText(context, "An item of the ListView is clicked.", Toast.LENGTH_LONG).show();
}
});


// items1={"1","2","3","4","5","1","2","3","4","5"};

LstViewAdapter adapter=new LstViewAdapter(OrderActivity.this,R.layout.order_item,R.id.txt,listM);
// Bind data to the ListView
lstview.setAdapter(adapter);




}

public void clickMe(View view){
Button bt=(Button)view;

new AlertDialog.Builder(context)
.setTitle("Delete Order Item")
.setMessage("Are you sure? n Want to delete this item ?")
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do nothing
// Toast.makeText(OrderActivity.this, "Cancel ",Toast.LENGTH_LONG).show();

}
})
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do nothing
Toast.makeText(OrderActivity.this, "Delete row and reload activity", Toast.LENGTH_LONG).show();
Cursor c = db.rawQuery("Select id from orderItem", null);


}
})
.show();
//Toast.makeText(this, "Button "+bt.getText().toString(),Toast.LENGTH_LONG).show();
}

class PostAsync extends AsyncTask<String, String, JSONObject> {
JSONParser jsonParser = new JSONParser();

private ProgressDialog pDialog;

private static final String LOGIN_URL = "http://tootbh.com/a_papa/setOrders.php";

// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_MESSAGE = "message";

private static final String TAG_USERS = "user";
private static final String TAG_ID = "id";
private static final String TAG_NAME = "name";
private static final String TAG_MOBILE = "mobile";
private static final String TAG_EMAIL = "email";
SQLiteDatabase db;

JSONArray user = null;
int id;
String name,mobile,email;


@Override
protected void onPreExecute() {
pDialog = new ProgressDialog(OrderActivity.this);
pDialog.setMessage("Making order...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}

@Override
protected JSONObject doInBackground(String... args) {

try {

HashMap<String, String> params = new HashMap<>();

params.put("discount", args[0]);
params.put("status", args[1]);
params.put("cLoction", args[2]);
params.put("userEmail", args[3]);
params.put("orderDesc", args[4]);
Log.d("request", "starting");

JSONObject json = jsonParser.makeHttpRequest(
LOGIN_URL, "POST", params);

db=openOrCreateDatabase("papaJ", Context.MODE_PRIVATE, null);


Cursor c2 = db.rawQuery("SELECT * from orderItem WHERE uid =""+usid+"";", null);

HashMap<String, String> params2 = new HashMap<>();

if(c2.moveToFirst()){
params2.put("pizzaID", c2.getString(c2.getColumnIndex("pizzaID")));
params2.put("pizzaName", c2.getString(c2.getColumnIndex("pizzaName")));
params2.put("size", c2.getString(c2.getColumnIndex("size")));
params2.put("type", c2.getString(c2.getColumnIndex("type")));
params2.put("quan", c2.getString(c2.getColumnIndex("quan")));
params2.put("price", c2.getString(c2.getColumnIndex("price")));
params2.put("uid", c2.getString(c2.getColumnIndex("id")));
Log.d("request", "starting");

}
JSONObject json2 = jsonParser.makeHttpRequest(
LOGIN_URL, "POST", params);



if (json != null && json2 != null) {

/////////////////////////////////////////////////////////////////////////////////////////////////////////

int success = 0;
String message = "";

//Toast.makeText(getApplicationContext(), json.toString(), Toast.LENGTH_LONG).show();

try {
success = json.getInt(TAG_SUCCESS);
message = json.getString(TAG_MESSAGE);
} catch (JSONException e) {
e.printStackTrace();
}


if (success == 1) {
Log.d("Success!", message);
// Creating database and table




// db.execSQL("SELECT id FROM orders WHERE id=");


//db.execSQL("INSERT INTO users VALUES(1,'Abbas Salman','33213188','[email protected]');");


db.execSQL("INSERT INTO users VALUES("+id+",'"+name+"','"+mobile+"','"+email+"');");

Intent i = new Intent(OrderActivity.this,MainActivity.class);
startActivity(i);
finish();
Toast.makeText(getApplicationContext(), "-", Toast.LENGTH_LONG).show();
}else{
Log.d("Failure", message);
Toast.makeText(getApplicationContext(),"Not valid, ss Try again",Toast.LENGTH_LONG).show();
}


///////////////////////////////////////////////////////////////////////////////////////////////////////

return json;
}

} catch (Exception e) {
e.printStackTrace();
}

return null;
}

protected void onPostExecute(JSONObject json) {
if (pDialog != null && pDialog.isShowing()) {
pDialog.dismiss();
}

}

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_order, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
}

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.