Commit 90fff506 authored by austin.blanke's avatar austin.blanke

Bookings Working

parent 4afc5f2e
......@@ -44,6 +44,14 @@
android:name=".MoreInfoActivity"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<activity
android:name=".MyBookingsActivity"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
......
......@@ -49,6 +49,7 @@ public class DatabaseConnector extends SQLiteOpenHelper {
private static final String COLUMN_TIC1CNT = "ticket1count";
private static final String COLUMN_TIC2CNT = "ticket2count";
private static final String COLUMN_TIC3CNT = "ticket3count";
private static final String COLUMN_BOOKINGTITLE = "booking title";
public DatabaseConnector(Context context, SQLiteDatabase.CursorFactory factory) {
......@@ -90,7 +91,8 @@ public class DatabaseConnector extends SQLiteOpenHelper {
COLUMN_PID + " TEXT, " +
COLUMN_TIC1CNT + " INT, " +
COLUMN_TIC2CNT + " INT, " +
COLUMN_TIC3CNT + " INT)";
COLUMN_TIC3CNT + " INT, " +
COLUMN_BOOKINGTITLE + "TEXT)";
db.execSQL(CREATE_table3);
ContentValues play1 = new ContentValues();
......@@ -208,14 +210,36 @@ public class DatabaseConnector extends SQLiteOpenHelper {
public void addBooking(String PID, int TIC1CNT, int TIC2CNT, int TIC3CNT) {
int CurrentPTicCount1 = 0;
int CurrentPTicCount2 = 0;
int CurrentPTicCount3 = 0;
String CurrentPTicCount1 = null;
String CurrentPTicCount2 = null;
String CurrentPTicCount3 = null;
String query = "SELECT * FROM " + TABLE_PERFORMANCES + " WHERE " + COLUMN_PERFORMANCEID + " = \"" + PID + "\"";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(query, null);
cursor.moveToFirst();
String title = cursor.getString(1);
CurrentPTicCount1 = cursor.getString(10);
CurrentPTicCount2 = cursor.getString(13);
CurrentPTicCount3 = cursor.getString(16);
cursor.close();
if(CurrentPTicCount1 == null){CurrentPTicCount1 = "0";}
if(CurrentPTicCount2 == null){CurrentPTicCount2 = "0";}
if(CurrentPTicCount3 == null){CurrentPTicCount3 = "0";}
if(CurrentPTicCount1 != "0"){CurrentPTicCount1 = String.valueOf(Integer.parseInt(CurrentPTicCount1) - TIC1CNT);}
if(CurrentPTicCount2 != "0"){CurrentPTicCount2 = String.valueOf(Integer.parseInt(CurrentPTicCount2) - TIC2CNT);}
if(CurrentPTicCount3 != "0"){CurrentPTicCount3 = String.valueOf(Integer.parseInt(CurrentPTicCount3) - TIC3CNT);}
System.out.println(CurrentPTicCount1);
System.out.println(CurrentPTicCount2);
System.out.println(CurrentPTicCount3);
ContentValues values2 = new ContentValues();
values2.put(COLUMN_TICKET1CNT, CurrentPTicCount1);
String whereClause = COLUMN_PERFORMANCEID + " = " + "\"" + PID + "\"";
db.update(TABLE_PERFORMANCES, values2, whereClause, null);
Random rand = new Random();
int BID = rand.nextInt(10000);
......@@ -226,7 +250,7 @@ public class DatabaseConnector extends SQLiteOpenHelper {
values.put(COLUMN_TIC1CNT, TIC1CNT);
values.put(COLUMN_TIC1CNT, TIC2CNT);
values.put(COLUMN_TIC1CNT, TIC3CNT);
SQLiteDatabase db = this.getWritableDatabase();
values.put(COLUMN_BOOKINGTITLE, title);
db.insert(TABLE_BOOKINGS, null, values);
db.close();
}
......@@ -322,6 +346,20 @@ public class DatabaseConnector extends SQLiteOpenHelper {
return result;
}
public ArrayList bookings(){
ArrayList<String> bookings = new ArrayList<>();
String booking = null;
String query = "SELECT * FROM " + TABLE_BOOKINGS;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(query, null);
cursor.moveToFirst();
for(int i=0;i< cursor.getCount();i++){
bookings.add(cursor.getString(1) + "id: " + cursor.getString(0));
cursor.moveToNext();
cursor.moveToNext();
}
return bookings;
}
public ArrayList performanceTitles(boolean filter1, boolean filter2, boolean filter3) {
ArrayList<String> performances = new ArrayList<>();
......
......@@ -51,6 +51,13 @@ public class MainActivity extends AppCompatActivity {
}
public void myBookings(View view){myBookings();}
public void myBookings(){
Intent intent = new Intent(this, MyBookingsActivity.class);
startActivity(intent);
}
public void moreInfoClick(View view){moreInfo();}
private void moreInfo(){
......
......@@ -108,20 +108,25 @@ public class MoreInfoActivity extends AppCompatActivity {
DatabaseConnector connector = new DatabaseConnector(this, null);
int TIC1 = 0;
int TIC2 = 0;
int TIC3 = 0;
String TIC1 = null;
String TIC2 = null;
String TIC3 = null;
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());}
TIC1 = Tic1Cnt.getText().toString();
TIC2 = Tic2Cnt.getText().toString();
TIC3 = Tic3Cnt.getText().toString();
connector.addBooking(PID, TIC1, TIC2, TIC3);
if(TIC1 == ""){TIC1="0";}
if(TIC2 == ""){TIC2="0";}
if(TIC3 == ""){TIC3="0";}
connector.addBooking(PID, Integer.parseInt(TIC1), Integer.parseInt(TIC2), Integer.parseInt(TIC3));
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
......
package com.example.bookingapp_austinblanke;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
public class MyBookingsActivity extends AppCompatActivity {
adapter2 adapterObj;
ArrayList<String> bookingList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mybookings_activity);
DatabaseConnector connector = new DatabaseConnector(this, null);
bookingList = new ArrayList<>();
bookingList = connector.bookings();
RecyclerView recyclerObj = findViewById(R.id.myBookingsPage);
recyclerObj.setLayoutManager(new LinearLayoutManager(this));
adapterObj = new adapter2(this, bookingList);
recyclerObj.setAdapter(adapterObj);
}
}
package com.example.bookingapp_austinblanke;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
public class adapter2 extends RecyclerView.Adapter<adapter2.ViewHolder>{
private List<String> mData;
private LayoutInflater mInflater;
Context context;
adapter2(Context context, List<String> data){
this.mInflater = LayoutInflater.from(context);
this.mData = data;
}
@Override
public adapter2.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
View view = mInflater.inflate(R.layout.performance,parent, false);
return new adapter2.ViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull adapter2.ViewHolder holder, int position) {
String name = mData.get(position);
holder.myTextView.setText(name);
}
@Override
public int getItemCount() {
return mData.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
TextView myTextView;
ViewHolder(View v){
super(v);
myTextView = itemView.findViewById(R.id.performance);
}
}
}
......@@ -95,5 +95,18 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.112" />
<Button
android:id="@+id/myBookingsPage"
android:layout_width="131dp"
android:layout_height="58dp"
android:onClick="myBookings"
android:text="My Bookings"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.892"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.023" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="5dp"
android:layout_marginTop="5dp"
android:orientation="vertical">
<TextView
android:id="@+id/booking"
android:layout_width="fill_parent"
android:layout_height="66dp"
android:layout_alignWithParentIfMissing="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:gravity="center_vertical"
android:text="Line 1"
android:textSize="24sp" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#CCCCCC"
/>
</LinearLayout>
\ No newline at end of file
......@@ -12,6 +12,7 @@
android:ems="10"
android:hint="Input Ticket Count"
android:inputType="textPersonName"
android:text="0"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.883"
......@@ -26,6 +27,7 @@
android:ems="10"
android:hint="Input Ticket Count"
android:inputType="textPersonName"
android:text="0"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.876"
......@@ -40,6 +42,7 @@
android:ems="10"
android:hint="Input Ticket Count"
android:inputType="textPersonName"
android:text="0"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.884"
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F2F1E8"
tools:context=".MyBookingsActivity">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/myBookingsPage"
android:layout_width="410dp"
android:layout_height="409dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.993"
tools:ignore="MissingConstraints" />
<Button
android:id="@+id/singleBooking"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Look at Booking"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.995"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.253" />
<EditText
android:id="@+id/bookingID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Booking ID"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.079"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.256" />
<Button
android:id="@+id/performanceBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Performances"
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.136" />
</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