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

try6

parent d3f5f464
......@@ -19,8 +19,8 @@ public class Database extends SQLiteOpenHelper {
@Override
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 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 play (playName TEXT PRIMARY KEY, tickets INTEGER)");
data.execSQL("CREATE TABLE IF NOT EXISTS booking (bookingid INTEGER PRIMARY KEY AUTOINCREMENT, playName TEXT, noticket INTEGER)");
}
@Override
public void onUpgrade(SQLiteDatabase data, int i, int i1) {
......@@ -37,7 +37,8 @@ public class Database extends SQLiteOpenHelper {
long conclusion = MyDatabase.insert("user", null, cv);
if (conclusion == -1) {
return false;
} else {
} else
{
return true;
}
}
......@@ -61,13 +62,11 @@ public class Database extends SQLiteOpenHelper {
return false;
}
}
public Boolean booking(String playName, String fullname, int notickets, String seatingtype) {
public Boolean bookinginput(String playName, int noticket) {
SQLiteDatabase MyDatabase = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put("playname", playName);
cv.put("noticket", notickets);
cv.put("fullname", fullname);
cv.put("seatingtype", seatingtype);
cv.put("playName", playName);
cv.put("noticket", noticket);
long conclusion = MyDatabase.insert("booking", null, cv);
if (conclusion == -1) {
return false;
......@@ -76,28 +75,28 @@ public class Database extends SQLiteOpenHelper {
return true;
}
}
public boolean play(String playName,int tickets){
public boolean playinput(String playName, int ticketsavail){
SQLiteDatabase data = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put("playname", playName);
cv.put("tickets", tickets);
cv.put("playName", playName);
cv.put("tickets", ticketsavail);
long conclusion = data.insert("play", null, cv);
return conclusion != -1;
}
public boolean ticketsupdate(String playName,int newtickets){
public boolean ticketsupdate(String playName, int newtickets){
SQLiteDatabase data = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put("noticket", newtickets);
int rows = data.update("play", cv, "playname=?", new String[]{playName});
cv.put("tickets", newtickets);
int rows = data.update("play", cv, "playName=?", new String[]{playName});
return rows > 0;
}
public int tickets(String playName) {
public int gettickets(String playName) {
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()) {
int notickets = record.getInt(record.getColumnIndexOrThrow("tickets"));
int ticketsavail = record.getInt(record.getColumnIndexOrThrow("tickets"));
record.close();
return notickets;
return ticketsavail;
}
record.close();
return 0;
......@@ -105,10 +104,10 @@ public class Database extends SQLiteOpenHelper {
public List<String> currentbookings() {
List<String> findbookings = new ArrayList<>();
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()) {
do {
String playName = record.getString(record.getColumnIndexOrThrow("playname"));
String playName = record.getString(record.getColumnIndexOrThrow("playName"));
findbookings.add(playName);
}
while (record.moveToNext());
......
......@@ -20,6 +20,8 @@ public class MainActivity extends AppCompatActivity {
plays = new ArrayList<>();
plays.add(new performancetickets("The Merchant of Venice", 17));
Button performance1 = (Button) findViewById(R.id.Performance1);
Button wheelchair = (Button) findViewById(R.id.filtered);
Button view = (Button) findViewById(R.id.viewall);
......@@ -53,8 +55,6 @@ public class MainActivity extends AppCompatActivity {
startActivity(intent);
}
});
}
}
......@@ -2,24 +2,22 @@ package com.example.playsrus;
public class performancetickets {
private int notickets;
private String playname;
private String playName;
private int ticketsavail;
public performancetickets(String playname, int notickets) {
this.notickets = notickets;
this.playname = playname;
}
public String findplayname() {
return playname;
public performancetickets(String playName, int ticketsavail) {
this.playName = playName;
this.ticketsavail = ticketsavail;
}
public int findtickets() {
return notickets;
}
public void applytickets(int notickets) {
this.notickets = notickets;
public String getPlayName() {
return playName;
}
public int getTicketsavail() {
return ticketsavail;
}
public void setTicketsavail(int ticketsavail) {
this.ticketsavail = ticketsavail;
}
}
......@@ -12,65 +12,100 @@ import android.widget.TextView;
import android.widget.ArrayAdapter;
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{
String[] seatings = { "Seated" };
private EditText fullName;
private EditText orderedtickets;
private TextView displayplayname;
private int tickets;
private Database database;
private TextView displayorderedtickets;
private int orderedtickets = 0;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.seating);
displayorderedtickets = findViewById(R.id.orderedtickets);
fullName = (EditText) findViewById(R.id.fullname);
displayplayname = findViewById(R.id.displayplayname);
orderedtickets = (EditText) findViewById(R.id.noticketsseating);
Button seatingback = (Button) findViewById(R.id.seatingback);
String playName = getIntent().getStringExtra("playName");
Spinner seatingtype = (Spinner) findViewById(R.id.seatingtype);
seatingtype.setOnItemSelectedListener(this);
ArrayAdapter aa = new ArrayAdapter(this, android.R.layout.simple_spinner_item, seatings);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
seatingtype.setAdapter(aa);
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();
database = new Database(this);
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 -> {
String playname = "The Merchant of Venice";
int tickets = Integer.parseInt(orderedtickets.getText().toString());
TextView displayorderedtickets = findViewById(R.id.orderedtickets);
int orderedtickets = Integer.parseInt(displayorderedtickets.getText().toString());
if (tickets > 0) {
int notickets = database.tickets(playname);
if (tickets <= notickets) {
int currentickets = notickets - tickets;
boolean bookedupdate = database.ticketsupdate(playname, currentickets);
if (orderedtickets > 0) {
String playnameforthis = "The Merchant of Venice";
int ticketsthere = database.gettickets(playnameforthis);
if (orderedtickets <= ticketsthere) {
int currentickets = ticketsthere - orderedtickets;
boolean bookedupdate = database.ticketsupdate(playnameforthis, currentickets);
if (bookedupdate) {
Intent screenchange = new Intent(seating.this, booked.class);
startActivity(screenchange);
;
} else {
Toast.makeText(seating.this, "Please try again.", Toast.LENGTH_SHORT).show();
}
} 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;
}
......
......@@ -37,20 +37,34 @@
<TextView
android:id="@+id/textView17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="173dp"
android:layout_height="39dp"
android:layout_marginTop="8dp"
android:text="How many"
android:text="How many tickets?"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="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_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.494"
app:layout_constraintVertical_bias="0.523"
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
android:id="@+id/textView18"
android:layout_width="wrap_content"
......@@ -61,10 +75,10 @@
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="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_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.6"
app:layout_constraintVertical_bias="0.752"
tools:text="Fullname" />
<TextView
......@@ -89,10 +103,10 @@
android:text="Confirm"
app:layout_constraintBottom_toBottomOf="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_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.732" />
app:layout_constraintVertical_bias="0.909" />
<Button
android:id="@+id/seatingback"
......@@ -101,10 +115,10 @@
android:text="Back"
app:layout_constraintBottom_toBottomOf="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_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.732" />
app:layout_constraintVertical_bias="0.909" />
<EditText
android:id="@+id/fullname"
......@@ -115,24 +129,10 @@
android:text="Input fullname"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.833"
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_constraintHorizontal_bias="0.9"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.499" />
app:layout_constraintVertical_bias="0.766" />
<Spinner
android:id="@+id/seatingtype"
......@@ -154,23 +154,50 @@
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="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_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.424" />
app:layout_constraintVertical_bias="0.414" />
<TextView
android:id="@+id/venicetickets2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="260dp"
android:layout_height="38dp"
android:text="Available Seating Tickets -"
android:textColor="#000000"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="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_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.423"
app:layout_constraintVertical_bias="0.418"
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>
\ 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