Commit 092fc9ea authored by sam.pople's avatar sam.pople

try6

parent d3f5f464
...@@ -19,8 +19,8 @@ public class Database extends SQLiteOpenHelper { ...@@ -19,8 +19,8 @@ public class Database extends SQLiteOpenHelper {
@Override @Override
public void onCreate(SQLiteDatabase data) { public void onCreate(SQLiteDatabase data) {
data.execSQL("CREATE TABLE IF NOT EXISTS user (username TEXT PRIMARY KEY, password TEXT)"); data.execSQL("CREATE TABLE IF NOT EXISTS user (username TEXT PRIMARY KEY, password TEXT)");
data.execSQL("CREATE TABLE IF NOT EXISTS play (playname TEXT PRIMARY KEY, tickets INTEGER)"); data.execSQL("CREATE TABLE IF NOT EXISTS play (playName TEXT PRIMARY KEY, tickets INTEGER)");
data.execSQL("CREATE TABLE IF NOT EXISTS booking (bookingid INTEGER PRIMARY KEY AUTOINCREMENT, playname TEXT, noticket INTEGER, fullname TEXT, seatingtype Text)"); data.execSQL("CREATE TABLE IF NOT EXISTS booking (bookingid INTEGER PRIMARY KEY AUTOINCREMENT, playName TEXT, noticket INTEGER)");
} }
@Override @Override
public void onUpgrade(SQLiteDatabase data, int i, int i1) { public void onUpgrade(SQLiteDatabase data, int i, int i1) {
...@@ -37,7 +37,8 @@ public class Database extends SQLiteOpenHelper { ...@@ -37,7 +37,8 @@ public class Database extends SQLiteOpenHelper {
long conclusion = MyDatabase.insert("user", null, cv); long conclusion = MyDatabase.insert("user", null, cv);
if (conclusion == -1) { if (conclusion == -1) {
return false; return false;
} else { } else
{
return true; return true;
} }
} }
...@@ -61,13 +62,11 @@ public class Database extends SQLiteOpenHelper { ...@@ -61,13 +62,11 @@ public class Database extends SQLiteOpenHelper {
return false; return false;
} }
} }
public Boolean booking(String playName, String fullname, int notickets, String seatingtype) { public Boolean bookinginput(String playName, int noticket) {
SQLiteDatabase MyDatabase = this.getWritableDatabase(); SQLiteDatabase MyDatabase = this.getWritableDatabase();
ContentValues cv = new ContentValues(); ContentValues cv = new ContentValues();
cv.put("playname", playName); cv.put("playName", playName);
cv.put("noticket", notickets); cv.put("noticket", noticket);
cv.put("fullname", fullname);
cv.put("seatingtype", seatingtype);
long conclusion = MyDatabase.insert("booking", null, cv); long conclusion = MyDatabase.insert("booking", null, cv);
if (conclusion == -1) { if (conclusion == -1) {
return false; return false;
...@@ -76,28 +75,28 @@ public class Database extends SQLiteOpenHelper { ...@@ -76,28 +75,28 @@ public class Database extends SQLiteOpenHelper {
return true; return true;
} }
} }
public boolean play(String playName,int tickets){ public boolean playinput(String playName, int ticketsavail){
SQLiteDatabase data = this.getWritableDatabase(); SQLiteDatabase data = this.getWritableDatabase();
ContentValues cv = new ContentValues(); ContentValues cv = new ContentValues();
cv.put("playname", playName); cv.put("playName", playName);
cv.put("tickets", tickets); cv.put("tickets", ticketsavail);
long conclusion = data.insert("play", null, cv); long conclusion = data.insert("play", null, cv);
return conclusion != -1; return conclusion != -1;
} }
public boolean ticketsupdate(String playName,int newtickets){ public boolean ticketsupdate(String playName, int newtickets){
SQLiteDatabase data = this.getWritableDatabase(); SQLiteDatabase data = this.getWritableDatabase();
ContentValues cv = new ContentValues(); ContentValues cv = new ContentValues();
cv.put("noticket", newtickets); cv.put("tickets", newtickets);
int rows = data.update("play", cv, "playname=?", new String[]{playName}); int rows = data.update("play", cv, "playName=?", new String[]{playName});
return rows > 0; return rows > 0;
} }
public int tickets(String playName) { public int gettickets(String playName) {
SQLiteDatabase data = this.getReadableDatabase(); SQLiteDatabase data = this.getReadableDatabase();
Cursor record = data.query("play", new String[]{"tickets"}, "playname=?", new String[]{playName}, null, null, null); Cursor record = data.query("play", new String[]{"tickets"}, "playName=?", new String[]{playName}, null, null, null);
if (record.moveToFirst()) { if (record.moveToFirst()) {
int notickets = record.getInt(record.getColumnIndexOrThrow("tickets")); int ticketsavail = record.getInt(record.getColumnIndexOrThrow("tickets"));
record.close(); record.close();
return notickets; return ticketsavail;
} }
record.close(); record.close();
return 0; return 0;
...@@ -105,10 +104,10 @@ public class Database extends SQLiteOpenHelper { ...@@ -105,10 +104,10 @@ public class Database extends SQLiteOpenHelper {
public List<String> currentbookings() { public List<String> currentbookings() {
List<String> findbookings = new ArrayList<>(); List<String> findbookings = new ArrayList<>();
SQLiteDatabase data = this.getReadableDatabase(); SQLiteDatabase data = this.getReadableDatabase();
Cursor record = data.rawQuery("SELECT playname FROM booking", null); Cursor record = data.rawQuery("SELECT playName FROM booking", null);
if (record.moveToFirst()) { if (record.moveToFirst()) {
do { do {
String playName = record.getString(record.getColumnIndexOrThrow("playname")); String playName = record.getString(record.getColumnIndexOrThrow("playName"));
findbookings.add(playName); findbookings.add(playName);
} }
while (record.moveToNext()); while (record.moveToNext());
......
...@@ -20,6 +20,8 @@ public class MainActivity extends AppCompatActivity { ...@@ -20,6 +20,8 @@ public class MainActivity extends AppCompatActivity {
plays = new ArrayList<>(); plays = new ArrayList<>();
plays.add(new performancetickets("The Merchant of Venice", 17)); plays.add(new performancetickets("The Merchant of Venice", 17));
Button performance1 = (Button) findViewById(R.id.Performance1); Button performance1 = (Button) findViewById(R.id.Performance1);
Button wheelchair = (Button) findViewById(R.id.filtered); Button wheelchair = (Button) findViewById(R.id.filtered);
Button view = (Button) findViewById(R.id.viewall); Button view = (Button) findViewById(R.id.viewall);
...@@ -53,8 +55,6 @@ public class MainActivity extends AppCompatActivity { ...@@ -53,8 +55,6 @@ public class MainActivity extends AppCompatActivity {
startActivity(intent); startActivity(intent);
} }
}); });
} }
} }
...@@ -2,24 +2,22 @@ package com.example.playsrus; ...@@ -2,24 +2,22 @@ package com.example.playsrus;
public class performancetickets { public class performancetickets {
private int notickets; private String playName;
private String playname; private int ticketsavail;
public performancetickets(String playname, int notickets) { public performancetickets(String playName, int ticketsavail) {
this.notickets = notickets; this.playName = playName;
this.playname = playname; this.ticketsavail = ticketsavail;
}
public String findplayname() {
return playname;
} }
public int findtickets() { public String getPlayName() {
return notickets; return playName;
} }
public int getTicketsavail() {
public void applytickets(int notickets) { return ticketsavail;
this.notickets = notickets;
} }
public void setTicketsavail(int ticketsavail) {
this.ticketsavail = ticketsavail;
} }
}
...@@ -12,65 +12,100 @@ import android.widget.TextView; ...@@ -12,65 +12,100 @@ import android.widget.TextView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import com.example.playsrus.databinding.SeatingBinding;
import com.example.playsrus.databinding.SignupBinding;
import org.w3c.dom.Text;
public class seating extends AppCompatActivity implements AdapterView.OnItemSelectedListener{ public class seating extends AppCompatActivity implements AdapterView.OnItemSelectedListener{
String[] seatings = { "Seated" }; String[] seatings = { "Seated" };
private EditText fullName; private EditText fullName;
private EditText orderedtickets;
private TextView displayplayname; private TextView displayplayname;
private int tickets;
private Database database; private Database database;
private TextView displayorderedtickets;
private int orderedtickets = 0;
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.seating); setContentView(R.layout.seating);
displayorderedtickets = findViewById(R.id.orderedtickets);
fullName = (EditText) findViewById(R.id.fullname); fullName = (EditText) findViewById(R.id.fullname);
displayplayname = findViewById(R.id.displayplayname); displayplayname = findViewById(R.id.displayplayname);
orderedtickets = (EditText) findViewById(R.id.noticketsseating); String playName = getIntent().getStringExtra("playName");
Button seatingback = (Button) findViewById(R.id.seatingback);
Spinner seatingtype = (Spinner) findViewById(R.id.seatingtype); Spinner seatingtype = (Spinner) findViewById(R.id.seatingtype);
seatingtype.setOnItemSelectedListener(this); seatingtype.setOnItemSelectedListener(this);
ArrayAdapter aa = new ArrayAdapter(this, android.R.layout.simple_spinner_item, seatings); ArrayAdapter aa = new ArrayAdapter(this, android.R.layout.simple_spinner_item, seatings);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
seatingtype.setAdapter(aa); seatingtype.setAdapter(aa);
Button confirm = (Button) findViewById(R.id.confirm); Button confirm = (Button) findViewById(R.id.confirm);
String playName = getIntent().getStringExtra("name"); Button seatingback = (Button) findViewById(R.id.seatingback);
displayorderedtickets.setText(String.valueOf(orderedtickets));
Intent intent = getIntent(); Intent intent = getIntent();
database = new Database(this); database = new Database(this);
TextView displaytickets = findViewById(R.id.venicetickets); TextView displaytickets = findViewById(R.id.venicetickets);
// displaytickets.setText(String.valueOf(notickets)); // int ticketsavail = database.gettickets(playnameforthis);
int ticketsavail = 17;
displaytickets.setText(String.valueOf(ticketsavail));
confirm.setOnClickListener(v -> { confirm.setOnClickListener(v -> {
String playname = "The Merchant of Venice"; TextView displayorderedtickets = findViewById(R.id.orderedtickets);
int tickets = Integer.parseInt(orderedtickets.getText().toString()); int orderedtickets = Integer.parseInt(displayorderedtickets.getText().toString());
if (tickets > 0) { if (orderedtickets > 0) {
int notickets = database.tickets(playname); String playnameforthis = "The Merchant of Venice";
int ticketsthere = database.gettickets(playnameforthis);
if (tickets <= notickets) { if (orderedtickets <= ticketsthere) {
int currentickets = notickets - tickets; int currentickets = ticketsthere - orderedtickets;
boolean bookedupdate = database.ticketsupdate(playname, currentickets); boolean bookedupdate = database.ticketsupdate(playnameforthis, currentickets);
if (bookedupdate) { if (bookedupdate) {
Intent screenchange = new Intent(seating.this, booked.class); Intent screenchange = new Intent(seating.this, booked.class);
startActivity(screenchange); startActivity(screenchange);
;
} else { } else {
Toast.makeText(seating.this, "Please try again.", Toast.LENGTH_SHORT).show(); Toast.makeText(seating.this, "Please try again.", Toast.LENGTH_SHORT).show();
} }
} else { } else {
Toast.makeText(seating.this, "Please try again.", Toast.LENGTH_SHORT).show(); Toast.makeText(seating.this, "Please order less tickets.", Toast.LENGTH_SHORT).show();
} }
}else {
Toast.makeText(seating.this, "Please order some tickets.", Toast.LENGTH_SHORT).show();
} }
}); });
seatingback.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(seating.this, MainActivity.class);
startActivity(intent);
}
});
Button minusone = findViewById(R.id.minusone);
Button plusone = findViewById(R.id.plusone);
plusone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
orderedtickets++;
displayorderedtickets.setText(String.valueOf(orderedtickets));
}
});
minusone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (orderedtickets > 0) {
orderedtickets--;
displayorderedtickets.setText(String.valueOf(orderedtickets));
}
}
});
} }
private boolean bookingdone(String playName, String fullName, int tickets, String seatingtype) {
boolean storebooking = database.booking(playName, fullName, Integer.parseInt(String.valueOf(tickets)), seatingtype);
private boolean bookingdone(String playName, int noticket) {
boolean storebooking = database.bookinginput(playName, Integer.parseInt(String.valueOf(noticket)));
return storebooking; return storebooking;
} }
......
...@@ -37,20 +37,34 @@ ...@@ -37,20 +37,34 @@
<TextView <TextView
android:id="@+id/textView17" android:id="@+id/textView17"
android:layout_width="wrap_content" android:layout_width="173dp"
android:layout_height="wrap_content" android:layout_height="39dp"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:text="How many" android:text="How many tickets?"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="20sp" android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.066" app:layout_constraintHorizontal_bias="0.432"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.494" app:layout_constraintVertical_bias="0.523"
tools:text="How many tickets?" /> tools:text="How many tickets?" />
<TextView
android:id="@+id/orderedtickets"
android:layout_width="54dp"
android:layout_height="38dp"
android:layout_marginTop="8dp"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.616" />
<TextView <TextView
android:id="@+id/textView18" android:id="@+id/textView18"
android:layout_width="wrap_content" android:layout_width="wrap_content"
...@@ -61,10 +75,10 @@ ...@@ -61,10 +75,10 @@
android:textSize="20sp" android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.075" app:layout_constraintHorizontal_bias="0.124"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.6" app:layout_constraintVertical_bias="0.752"
tools:text="Fullname" /> tools:text="Fullname" />
<TextView <TextView
...@@ -89,10 +103,10 @@ ...@@ -89,10 +103,10 @@
android:text="Confirm" android:text="Confirm"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.694" app:layout_constraintHorizontal_bias="0.764"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.732" /> app:layout_constraintVertical_bias="0.909" />
<Button <Button
android:id="@+id/seatingback" android:id="@+id/seatingback"
...@@ -101,10 +115,10 @@ ...@@ -101,10 +115,10 @@
android:text="Back" android:text="Back"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.059" app:layout_constraintHorizontal_bias="0.152"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.732" /> app:layout_constraintVertical_bias="0.909" />
<EditText <EditText
android:id="@+id/fullname" android:id="@+id/fullname"
...@@ -115,24 +129,10 @@ ...@@ -115,24 +129,10 @@
android:text="Input fullname" android:text="Input fullname"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.833" app:layout_constraintHorizontal_bias="0.9"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.615" />
<EditText
android:id="@+id/noticketsseating"
android:layout_width="209dp"
android:layout_height="48dp"
android:ems="10"
android:inputType="number"
android:text="How many tickets?"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.965"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.499" /> app:layout_constraintVertical_bias="0.766" />
<Spinner <Spinner
android:id="@+id/seatingtype" android:id="@+id/seatingtype"
...@@ -154,23 +154,50 @@ ...@@ -154,23 +154,50 @@
android:textSize="24sp" android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.698" app:layout_constraintHorizontal_bias="0.712"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.424" /> app:layout_constraintVertical_bias="0.414" />
<TextView <TextView
android:id="@+id/venicetickets2" android:id="@+id/venicetickets2"
android:layout_width="wrap_content" android:layout_width="260dp"
android:layout_height="wrap_content" android:layout_height="38dp"
android:text="Available Seating Tickets -"
android:textColor="#000000" android:textColor="#000000"
android:textSize="20sp" android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.067" app:layout_constraintHorizontal_bias="0.105"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.423" app:layout_constraintVertical_bias="0.418"
tools:text="Available Seating Tickets -" /> tools:text="Available Seating Tickets -" />
<Button
android:id="@+id/minusone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="- 1"
android:textSize="34sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.145"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.624" />
<Button
android:id="@+id/plusone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+ 1"
android:textSize="34sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.804"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.624" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment