Commit 4afc5f2e authored by austin.blanke's avatar austin.blanke

Database Updated, Working on Add Booking Method

parent 67e195a8
...@@ -8,7 +8,10 @@ import android.database.sqlite.SQLiteOpenHelper; ...@@ -8,7 +8,10 @@ import android.database.sqlite.SQLiteOpenHelper;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Random;
public class DatabaseConnector extends SQLiteOpenHelper { public class DatabaseConnector extends SQLiteOpenHelper {
...@@ -20,7 +23,6 @@ public class DatabaseConnector extends SQLiteOpenHelper { ...@@ -20,7 +23,6 @@ public class DatabaseConnector extends SQLiteOpenHelper {
private static final String COLUMN_USERNAME = "username"; private static final String COLUMN_USERNAME = "username";
private static final String COLUMN_PASSWORD = "password"; private static final String COLUMN_PASSWORD = "password";
private static final String TABLE_PERFORMANCES = "performances"; private static final String TABLE_PERFORMANCES = "performances";
private static final String COLUMN_PERFORMANCEID = "performanceID"; private static final String COLUMN_PERFORMANCEID = "performanceID";
private static final String COLUMN_NAME = "name"; private static final String COLUMN_NAME = "name";
...@@ -30,24 +32,23 @@ public class DatabaseConnector extends SQLiteOpenHelper { ...@@ -30,24 +32,23 @@ public class DatabaseConnector extends SQLiteOpenHelper {
private static final String COLUMN_FLASH = "flash"; private static final String COLUMN_FLASH = "flash";
private static final String COLUMN_WHEELCHAIR = "wheelchair"; private static final String COLUMN_WHEELCHAIR = "wheelchair";
private static final String COLUMN_STEPS = "steps"; private static final String COLUMN_STEPS = "steps";
private static final String COLUMN_TICSEAT = "ticSeat"; private static final String COLUMN_TICKET1 = "performanceTicket1";
private static final String COLUMN_TICSEATCOST = "ticSeatCost"; private static final String COLUMN_TICKET1TYPE = "performanceTicketType1";
private static final String COLUMN_TICSTAND = "ticStand"; private static final String COLUMN_TICKET1CNT = "performanceTicketCount1";
private static final String COLUMN_TICSTANDCOST = "ticStandCost"; private static final String COLUMN_TICKET2 = "performanceTicket2";
private static final String COLUMN_TICSTAGE = "ticStage"; private static final String COLUMN_TICKET2TYPE = "performanceTicketType2";
private static final String COLUMN_TICSTAGECOST = "ticStageCost"; private static final String COLUMN_TICKET2CNT = "performanceTicketCount2";
private static final String COLUMN_TICGRASS = "ticGrass"; private static final String COLUMN_TICKET3 = "performanceTicket3";
private static final String COLUMN_TICGRASSCOST = "ticGrassCost"; private static final String COLUMN_TICKET3TYPE = "performanceTicketType3";
private static final String COLUMN_TICBOATA = "ticBoatA"; private static final String COLUMN_TICKET3CNT = "performanceTicketCount3";
private static final String COLUMN_TICBOATACOST = "ticBoatACost";
private static final String COLUMN_TICBOATB = "ticBoatB";
private static final String COLUMN_TICBOATBCOST = "ticBoatBCost"; private static final String TABLE_BOOKINGS = "bookings";
private static final String COLUMN_TICRIVERBANK = "ticRiverBank"; private static final String COLUMN_BID = "BID";
private static final String COLUMN_TICRIVERBANKCOST = "ticRiverBankCost"; private static final String COLUMN_PID = "PID";
private static final String COLUMN_TICINNERCIRCLE = "ticInnerCircle"; private static final String COLUMN_TIC1CNT = "ticket1count";
private static final String COLUMN_TICINNERCIRCLECOST = "ticInnerCircleCost"; private static final String COLUMN_TIC2CNT = "ticket2count";
private static final String COLUMN_TICOUTTERCIRCLE = "ticOutterCircle"; private static final String COLUMN_TIC3CNT = "ticket3count";
private static final String COLUMN_TICOUTTERCIRCLECOST = "ticOutterCircleCost";
public DatabaseConnector(Context context, SQLiteDatabase.CursorFactory factory) { public DatabaseConnector(Context context, SQLiteDatabase.CursorFactory factory) {
...@@ -73,26 +74,25 @@ public class DatabaseConnector extends SQLiteOpenHelper { ...@@ -73,26 +74,25 @@ public class DatabaseConnector extends SQLiteOpenHelper {
COLUMN_FLASH + " TEXT, " + COLUMN_FLASH + " TEXT, " +
COLUMN_WHEELCHAIR + " TEXT, " + COLUMN_WHEELCHAIR + " TEXT, " +
COLUMN_STEPS + " TEXT, " + COLUMN_STEPS + " TEXT, " +
COLUMN_TICSEAT + " Int, " + COLUMN_TICKET1 + " INT, " +
COLUMN_TICSEATCOST + " Int, " + COLUMN_TICKET1TYPE + " TEXT, " +
COLUMN_TICSTAND + " INT, " + COLUMN_TICKET1CNT + " INT, " +
COLUMN_TICSTANDCOST + " INT, " + COLUMN_TICKET2 + " INT, " +
COLUMN_TICSTAGE + " INT, " + COLUMN_TICKET2TYPE + " TEXT, " +
COLUMN_TICSTAGECOST + " INT, " + COLUMN_TICKET2CNT + " INT, " +
COLUMN_TICGRASS + " INT, " + COLUMN_TICKET3 + " INT, " +
COLUMN_TICGRASSCOST + " INT, " + COLUMN_TICKET3TYPE + " TEXT, " +
COLUMN_TICBOATA + " INT, " + COLUMN_TICKET3CNT + " INT)";
COLUMN_TICBOATACOST + " INT, " +
COLUMN_TICBOATB + " INT, " +
COLUMN_TICBOATBCOST + " INT, " +
COLUMN_TICRIVERBANK + " INT, " +
COLUMN_TICRIVERBANKCOST + " INT, " +
COLUMN_TICINNERCIRCLE + " INT, " +
COLUMN_TICINNERCIRCLECOST + " INT, " +
COLUMN_TICOUTTERCIRCLE + " INT, " +
COLUMN_TICOUTTERCIRCLECOST + " INT)";
db.execSQL(CREATE_table2); db.execSQL(CREATE_table2);
String CREATE_table3 = "CREATE TABLE " + TABLE_BOOKINGS + "(" +
COLUMN_BID + " INTEGER PRIMARY KEY, " +
COLUMN_PID + " TEXT, " +
COLUMN_TIC1CNT + " INT, " +
COLUMN_TIC2CNT + " INT, " +
COLUMN_TIC3CNT + " INT)";
db.execSQL(CREATE_table3);
ContentValues play1 = new ContentValues(); ContentValues play1 = new ContentValues();
play1.put(COLUMN_PERFORMANCEID, "1"); play1.put(COLUMN_PERFORMANCEID, "1");
play1.put(COLUMN_NAME, "The Merchant of Venice by William Shakespeare"); play1.put(COLUMN_NAME, "The Merchant of Venice by William Shakespeare");
...@@ -102,8 +102,9 @@ public class DatabaseConnector extends SQLiteOpenHelper { ...@@ -102,8 +102,9 @@ public class DatabaseConnector extends SQLiteOpenHelper {
play1.put(COLUMN_FLASH, "false"); play1.put(COLUMN_FLASH, "false");
play1.put(COLUMN_WHEELCHAIR, "true"); play1.put(COLUMN_WHEELCHAIR, "true");
play1.put(COLUMN_STEPS, "false"); play1.put(COLUMN_STEPS, "false");
play1.put(COLUMN_TICSEAT, 17); play1.put(COLUMN_TICKET1CNT, 17);
play1.put(COLUMN_TICSEATCOST, 8); play1.put(COLUMN_TICKET1, 8);
play1.put(COLUMN_TICKET1TYPE, "Seated");
db.insert(TABLE_PERFORMANCES, null, play1); db.insert(TABLE_PERFORMANCES, null, play1);
ContentValues play2 = new ContentValues(); ContentValues play2 = new ContentValues();
...@@ -115,10 +116,12 @@ public class DatabaseConnector extends SQLiteOpenHelper { ...@@ -115,10 +116,12 @@ public class DatabaseConnector extends SQLiteOpenHelper {
play2.put(COLUMN_FLASH, "true"); play2.put(COLUMN_FLASH, "true");
play2.put(COLUMN_WHEELCHAIR, "false"); play2.put(COLUMN_WHEELCHAIR, "false");
play2.put(COLUMN_STEPS, "true"); play2.put(COLUMN_STEPS, "true");
play2.put(COLUMN_TICSEAT, 8); play2.put(COLUMN_TICKET1CNT, 8);
play2.put(COLUMN_TICSEATCOST, 8); play2.put(COLUMN_TICKET1, 8);
play2.put(COLUMN_TICSTAND, 12); play2.put(COLUMN_TICKET1TYPE, "Seated");
play2.put(COLUMN_TICSTANDCOST, 7); play2.put(COLUMN_TICKET2CNT, 12);
play2.put(COLUMN_TICKET2, 7);
play2.put(COLUMN_TICKET2TYPE, "Standing");
db.insert(TABLE_PERFORMANCES, null, play2); db.insert(TABLE_PERFORMANCES, null, play2);
ContentValues play3 = new ContentValues(); ContentValues play3 = new ContentValues();
...@@ -130,10 +133,12 @@ public class DatabaseConnector extends SQLiteOpenHelper { ...@@ -130,10 +133,12 @@ public class DatabaseConnector extends SQLiteOpenHelper {
play3.put(COLUMN_FLASH, "true"); play3.put(COLUMN_FLASH, "true");
play3.put(COLUMN_WHEELCHAIR, "true"); play3.put(COLUMN_WHEELCHAIR, "true");
play3.put(COLUMN_STEPS, "false"); play3.put(COLUMN_STEPS, "false");
play3.put(COLUMN_TICSTAGE, 11); play3.put(COLUMN_TICKET1TYPE, "Stage");
play3.put(COLUMN_TICSTAGECOST, 4); play3.put(COLUMN_TICKET1CNT, 11);
play3.put(COLUMN_TICGRASS, 29); play3.put(COLUMN_TICKET1, 4);
play3.put(COLUMN_TICGRASSCOST, 4); play3.put(COLUMN_TICKET1TYPE, "Grass");
play3.put(COLUMN_TICKET2CNT, 29);
play3.put(COLUMN_TICKET2, 4);
db.insert(TABLE_PERFORMANCES, null, play3); db.insert(TABLE_PERFORMANCES, null, play3);
ContentValues play4 = new ContentValues(); ContentValues play4 = new ContentValues();
...@@ -145,10 +150,12 @@ public class DatabaseConnector extends SQLiteOpenHelper { ...@@ -145,10 +150,12 @@ public class DatabaseConnector extends SQLiteOpenHelper {
play4.put(COLUMN_FLASH, "false"); play4.put(COLUMN_FLASH, "false");
play4.put(COLUMN_WHEELCHAIR, "true"); play4.put(COLUMN_WHEELCHAIR, "true");
play4.put(COLUMN_STEPS, "false"); play4.put(COLUMN_STEPS, "false");
play4.put(COLUMN_TICSEAT, 5); play4.put(COLUMN_TICKET1TYPE, "Seated");
play4.put(COLUMN_TICSEATCOST, 9); play4.put(COLUMN_TICKET1CNT, 5);
play4.put(COLUMN_TICSTAND, 12); play4.put(COLUMN_TICKET1, 9);
play4.put(COLUMN_TICSTANDCOST, 7); play4.put(COLUMN_TICKET1TYPE, "Standing");
play4.put(COLUMN_TICKET2CNT, 12);
play4.put(COLUMN_TICKET2, 7);
db.insert(TABLE_PERFORMANCES, null, play4); db.insert(TABLE_PERFORMANCES, null, play4);
ContentValues play5 = new ContentValues(); ContentValues play5 = new ContentValues();
...@@ -160,10 +167,12 @@ public class DatabaseConnector extends SQLiteOpenHelper { ...@@ -160,10 +167,12 @@ public class DatabaseConnector extends SQLiteOpenHelper {
play5.put(COLUMN_FLASH, "false"); play5.put(COLUMN_FLASH, "false");
play5.put(COLUMN_WHEELCHAIR, "true"); play5.put(COLUMN_WHEELCHAIR, "true");
play5.put(COLUMN_STEPS, "false"); play5.put(COLUMN_STEPS, "false");
play5.put(COLUMN_TICBOATA, 6); play5.put(COLUMN_TICKET1TYPE, "Boat A");
play5.put(COLUMN_TICBOATACOST, 9); play5.put(COLUMN_TICKET1CNT, 6);
play5.put(COLUMN_TICRIVERBANK, 10); play5.put(COLUMN_TICKET1, 9);
play5.put(COLUMN_TICRIVERBANKCOST, 7); play5.put(COLUMN_TICKET1TYPE, "Boat B");
play5.put(COLUMN_TICKET2CNT, 10);
play5.put(COLUMN_TICKET2, 7);
db.insert(TABLE_PERFORMANCES, null, play5); db.insert(TABLE_PERFORMANCES, null, play5);
ContentValues play6 = new ContentValues(); ContentValues play6 = new ContentValues();
...@@ -175,12 +184,15 @@ public class DatabaseConnector extends SQLiteOpenHelper { ...@@ -175,12 +184,15 @@ public class DatabaseConnector extends SQLiteOpenHelper {
play6.put(COLUMN_FLASH, "false"); play6.put(COLUMN_FLASH, "false");
play6.put(COLUMN_WHEELCHAIR, "false"); play6.put(COLUMN_WHEELCHAIR, "false");
play6.put(COLUMN_STEPS, "true"); play6.put(COLUMN_STEPS, "true");
play6.put(COLUMN_TICINNERCIRCLE, 5); play6.put(COLUMN_TICKET1TYPE, "Inner Circle");
play6.put(COLUMN_TICINNERCIRCLECOST, 16); play6.put(COLUMN_TICKET1CNT, 5);
play6.put(COLUMN_TICOUTTERCIRCLE, 8); play6.put(COLUMN_TICKET1, 16);
play6.put(COLUMN_TICOUTTERCIRCLECOST, 13); play6.put(COLUMN_TICKET1TYPE, "Outer Circle");
play6.put(COLUMN_TICSTAND, 10); play6.put(COLUMN_TICKET2CNT, 8);
play6.put(COLUMN_TICSTANDCOST, 10); play6.put(COLUMN_TICKET2, 13);
play6.put(COLUMN_TICKET1TYPE, "Standing");
play6.put(COLUMN_TICKET3CNT, 10);
play6.put(COLUMN_TICKET3, 10);
db.insert(TABLE_PERFORMANCES, null, play6); db.insert(TABLE_PERFORMANCES, null, play6);
} }
...@@ -194,6 +206,31 @@ public class DatabaseConnector extends SQLiteOpenHelper { ...@@ -194,6 +206,31 @@ public class DatabaseConnector extends SQLiteOpenHelper {
db.close(); db.close();
} }
public void addBooking(String PID, int TIC1CNT, int TIC2CNT, int TIC3CNT) {
int CurrentPTicCount1 = 0;
int CurrentPTicCount2 = 0;
int CurrentPTicCount3 = 0;
String query = "SELECT * FROM " + TABLE_PERFORMANCES + " WHERE " + COLUMN_PERFORMANCEID + " = \"" + PID + "\"";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(query, null);
cursor.moveToFirst();
Random rand = new Random();
int BID = rand.nextInt(10000);
ContentValues values = new ContentValues();
values.put(COLUMN_BID, BID);
values.put(COLUMN_PID, PID);
values.put(COLUMN_TIC1CNT, TIC1CNT);
values.put(COLUMN_TIC1CNT, TIC2CNT);
values.put(COLUMN_TIC1CNT, TIC3CNT);
SQLiteDatabase db = this.getWritableDatabase();
db.insert(TABLE_BOOKINGS, null, values);
db.close();
}
@Override @Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) { public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
...@@ -217,48 +254,43 @@ public class DatabaseConnector extends SQLiteOpenHelper { ...@@ -217,48 +254,43 @@ public class DatabaseConnector extends SQLiteOpenHelper {
} }
public String getTicketCount(String PID, int t) { public String getTicketCount(String PID, int t) {
int count = 0;
String result = null; String result = null;
String query = "SELECT * FROM " + TABLE_PERFORMANCES + " WHERE " + COLUMN_PERFORMANCEID + " = \"" + PID + "\""; String query = "SELECT * FROM " + TABLE_PERFORMANCES + " WHERE " + COLUMN_PERFORMANCEID + " = \"" + PID + "\"";
SQLiteDatabase db = this.getWritableDatabase(); SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(query, null); Cursor cursor = db.rawQuery(query, null);
cursor.moveToFirst(); cursor.moveToFirst();
for(int i=8;i<26;i = i+2){ if(t==1){result=cursor.getString(10);}
if(cursor.getString(i) != null){ else if(t==2){result=cursor.getString(13);}
count = count + 1; else if(t==3){result=cursor.getString(16);}
if(count==t){
result = cursor.getString(i+1);
}
}
}
if (result == null) {result = "";}
cursor.close();
db.close();
return result; return result;
} }
public String getTicketPrice(String PID, int t) { public String getTicketPrice(String PID, int t) {
int count = 0;
String result = null; String result = null;
String query = "SELECT * FROM " + TABLE_PERFORMANCES + " WHERE " + COLUMN_PERFORMANCEID + " = \"" + PID + "\""; String query = "SELECT * FROM " + TABLE_PERFORMANCES + " WHERE " + COLUMN_PERFORMANCEID + " = \"" + PID + "\"";
SQLiteDatabase db = this.getWritableDatabase(); SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(query, null); Cursor cursor = db.rawQuery(query, null);
cursor.moveToFirst(); cursor.moveToFirst();
for(int i=8;i<26;i = i + 2){ if(t==1){result=cursor.getString(8);}
if(cursor.getString(i) != null){ else if(t==2){result=cursor.getString(11);}
count = count + 1; else if(t==3){result=cursor.getString(14);}
if(count==t){ return result;
result = cursor.getString(i+1);
}
}
} }
if (result == null || result == "0") {result = "";}
cursor.close(); public String getTicketType(String PID, int t) {
db.close(); String result = null;
String query = "SELECT * FROM " + TABLE_PERFORMANCES + " WHERE " + COLUMN_PERFORMANCEID + " = \"" + PID + "\"";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(query, null);
cursor.moveToFirst();
if(t==1){result=cursor.getString(9);}
else if(t==2){result=cursor.getString(12);}
else if(t==3){result=cursor.getString(15);}
return result; return result;
} }
public String getInfo(String PID, int column) { public String getInfo(String PID, int column) {
String result; String result;
String query = "SELECT * FROM " + TABLE_PERFORMANCES + " WHERE " + COLUMN_PERFORMANCEID + " = \"" + PID + "\""; String query = "SELECT * FROM " + TABLE_PERFORMANCES + " WHERE " + COLUMN_PERFORMANCEID + " = \"" + PID + "\"";
......
...@@ -3,6 +3,7 @@ package com.example.bookingapp_austinblanke; ...@@ -3,6 +3,7 @@ package com.example.bookingapp_austinblanke;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
...@@ -31,6 +32,9 @@ public class MoreInfoActivity extends AppCompatActivity { ...@@ -31,6 +32,9 @@ public class MoreInfoActivity extends AppCompatActivity {
String Flashdis = null; String Flashdis = null;
String Wheelchairdis = null; String Wheelchairdis = null;
String Stairsdis = null; String Stairsdis = null;
String Tickets1Type = null;
String Tickets2Type = null;
String Tickets3Type = null;
String Tickets1 = null; String Tickets1 = null;
String Tickets2 = null; String Tickets2 = null;
String Tickets3 = null; String Tickets3 = null;
...@@ -57,12 +61,15 @@ public class MoreInfoActivity extends AppCompatActivity { ...@@ -57,12 +61,15 @@ public class MoreInfoActivity extends AppCompatActivity {
if(Stairs == "true"){Stairsdis = "There are less than 20 steps";} if(Stairs == "true"){Stairsdis = "There are less than 20 steps";}
else{Stairsdis = "There are more than 20 steps";} else{Stairsdis = "There are more than 20 steps";}
Tickets1 = connector.getInfo(PID, 8); Tickets1 = connector.getTicketCount(PID, 1);
Tickets2 = connector.getTicketCount(PID, 2); Tickets2 = connector.getTicketCount(PID, 2);
Tickets3 = connector.getTicketCount(PID, 3); Tickets3 = connector.getTicketCount(PID, 3);
Tickets1Price = connector.getTicketPrice(PID, 1); Tickets1Price = connector.getTicketPrice(PID, 1);
Tickets2Price = connector.getTicketPrice(PID, 2); Tickets2Price = connector.getTicketPrice(PID, 2);
Tickets3Price = connector.getTicketPrice(PID, 3); Tickets3Price = connector.getTicketPrice(PID, 3);
Tickets1Type = connector.getTicketType(PID, 1);
Tickets2Type = connector.getTicketType(PID, 2);
Tickets3Type = connector.getTicketType(PID, 3);
...@@ -81,13 +88,42 @@ public class MoreInfoActivity extends AppCompatActivity { ...@@ -81,13 +88,42 @@ public class MoreInfoActivity extends AppCompatActivity {
TextView stairs = (TextView) findViewById(R.id.stairs); TextView stairs = (TextView) findViewById(R.id.stairs);
stairs.setText(Stairsdis); stairs.setText(Stairsdis);
TextView ticket1 = (TextView) findViewById(R.id.tickets1); TextView ticket1 = (TextView) findViewById(R.id.tickets1);
ticket1.setText(Tickets1 + ", £" + Tickets1Price);
TextView ticket2 = (TextView) findViewById(R.id.tickets2); TextView ticket2 = (TextView) findViewById(R.id.tickets2);
ticket2.setText(Tickets2 + ", £" + Tickets2Price);
TextView ticket3 = (TextView) findViewById(R.id.tickets3); TextView ticket3 = (TextView) findViewById(R.id.tickets3);
ticket3.setText(Tickets3 + ", £" + Tickets3Price);
if(Tickets1 != null){ticket1.setText(Tickets1Type + ": " + Tickets1 + " (£" + Tickets1Price + ")");}
else{ticket1.setText("");}
if(Tickets2 != null){ticket2.setText(Tickets2Type + ": " + Tickets2 + " (£" + Tickets2Price + ")");}
else{ticket2.setText("");}
if(Tickets3 != null){ticket3.setText(Tickets3Type + ": " + Tickets3 + " (£" + Tickets3Price + ")");}
else{ticket3.setText("");}
}
public void bookNow(View view){bookNow();}
public void bookNow(){
DatabaseConnector connector = new DatabaseConnector(this, null);
int TIC1 = 0;
int TIC2 = 0;
int TIC3 = 0;
EditText Tic1Cnt = findViewById(R.id.bookTicket1Cnt);
EditText Tic2Cnt = findViewById(R.id.bookTicket2Cnt);
EditText Tic3Cnt = findViewById(R.id.bookTicket3Cnt);
if (Tic1Cnt != null){TIC1 = Integer.parseInt(Tic1Cnt.getText().toString());}
if (Tic2Cnt != null){TIC2 = Integer.parseInt(Tic2Cnt.getText().toString());}
if (Tic3Cnt != null){TIC3 = Integer.parseInt(Tic3Cnt.getText().toString());}
connector.addBooking(PID, TIC1, TIC2, TIC3);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
} }
} }
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