Commit 16f8e758 authored by chris.crook's avatar chris.crook

> checkout screen works

parent 6fe99650
...@@ -118,6 +118,19 @@ public class AdminMenu extends AppCompatActivity { ...@@ -118,6 +118,19 @@ public class AdminMenu extends AppCompatActivity {
} }
public void goback (View view){ public void goback (View view){
String filename6 = "Booking";
File file6;
file6 = new File(getApplicationContext().getFilesDir(), filename6 + ".txt");
try{
FileWriter stream = new FileWriter(file6, false);
stream.append("");
stream.close();
Toast.makeText(getApplicationContext(), "Logged out, cart contents wiped", Toast.LENGTH_LONG).show();
} catch(Exception e){
Toast.makeText(getApplicationContext(), "Internal File Error", Toast.LENGTH_LONG).show();
}
Intent intent = new Intent(this,MainActivity.class); Intent intent = new Intent(this,MainActivity.class);
startActivity(intent); startActivity(intent);
} }
......
...@@ -152,7 +152,7 @@ public class BookingDetails extends AppCompatActivity { ...@@ -152,7 +152,7 @@ public class BookingDetails extends AppCompatActivity {
public void timeslot1 (View view){ public void timeslot1 (View view){
// time slot 1 // time slot 1
String tempwrite = ((EditText) findViewById(R.id.YEET2)).getText().toString(); String tempwrite = ((EditText) findViewById(R.id.YEET2)).getText().toString();
tempwrite += "&1"; tempwrite += "&9:00-11:00";
String [] temploadarray = tempwrite.split("&"); // id,museum_name,city,country,price,name,password,adminflag,currency,language,id,slot String [] temploadarray = tempwrite.split("&"); // id,museum_name,city,country,price,name,password,adminflag,currency,language,id,slot
String filename6 = "Booking";// + temploadarray[5] + temploadarray [10]; // file will be named: Booking_NameID String filename6 = "Booking";// + temploadarray[5] + temploadarray [10]; // file will be named: Booking_NameID
File file6; File file6;
...@@ -186,9 +186,9 @@ public class BookingDetails extends AppCompatActivity { ...@@ -186,9 +186,9 @@ public class BookingDetails extends AppCompatActivity {
public void timeslot2 (View view){ public void timeslot2 (View view){
// time slot 2 // time slot 2
String tempwrite = ((EditText) findViewById(R.id.YEET2)).getText().toString(); String tempwrite = ((EditText) findViewById(R.id.YEET2)).getText().toString();
tempwrite += "&2"; tempwrite += "&11:00-13:00";
String [] temploadarray = tempwrite.split("&"); // id,museum_name,city,country,price,name,password,adminflag,currency,language,id String [] temploadarray = tempwrite.split("&"); // id,museum_name,city,country,price,name,password,adminflag,currency,language,id
String filename6 = "Booking_" + temploadarray[5] + temploadarray [10]; // file will be named: Booking_NameID String filename6 = "Booking";// + temploadarray[5] + temploadarray [10]; // file will be named: Booking_NameID
File file6; File file6;
file6 = new File(getApplicationContext().getFilesDir(), filename6 + ".txt"); file6 = new File(getApplicationContext().getFilesDir(), filename6 + ".txt");
String temp = ""; String temp = "";
...@@ -203,7 +203,7 @@ public class BookingDetails extends AppCompatActivity { ...@@ -203,7 +203,7 @@ public class BookingDetails extends AppCompatActivity {
// //
} }
else{ else{
tempwrite = "%" + tempwrite; tempwrite = "&" + tempwrite;
} }
try{ try{
FileWriter stream = new FileWriter(file6, true); FileWriter stream = new FileWriter(file6, true);
...@@ -221,9 +221,9 @@ public class BookingDetails extends AppCompatActivity { ...@@ -221,9 +221,9 @@ public class BookingDetails extends AppCompatActivity {
public void timeslot3 (View view){ public void timeslot3 (View view){
// time slot 3 // time slot 3
String tempwrite = ((EditText) findViewById(R.id.YEET2)).getText().toString(); String tempwrite = ((EditText) findViewById(R.id.YEET2)).getText().toString();
tempwrite += "&3"; tempwrite += "&13:00-15:00";
String [] temploadarray = tempwrite.split("&"); // id,museum_name,city,country,price,name,password,adminflag,currency,language,id String [] temploadarray = tempwrite.split("&"); // id,museum_name,city,country,price,name,password,adminflag,currency,language,id
String filename6 = "Booking_" + temploadarray[5] + temploadarray [10]; // file will be named: Booking_NameID String filename6 = "Booking";// + temploadarray[5] + temploadarray [10]; // file will be named: Booking_NameID
File file6; File file6;
file6 = new File(getApplicationContext().getFilesDir(), filename6 + ".txt"); file6 = new File(getApplicationContext().getFilesDir(), filename6 + ".txt");
String temp = ""; String temp = "";
...@@ -238,7 +238,7 @@ public class BookingDetails extends AppCompatActivity { ...@@ -238,7 +238,7 @@ public class BookingDetails extends AppCompatActivity {
// //
} }
else{ else{
tempwrite = "%" + tempwrite; tempwrite = "&" + tempwrite;
} }
try{ try{
FileWriter stream = new FileWriter(file6, true); FileWriter stream = new FileWriter(file6, true);
...@@ -255,9 +255,9 @@ public class BookingDetails extends AppCompatActivity { ...@@ -255,9 +255,9 @@ public class BookingDetails extends AppCompatActivity {
public void timeslot4 (View view){ public void timeslot4 (View view){
// time slot 4 // time slot 4
String tempwrite = ((EditText) findViewById(R.id.YEET2)).getText().toString(); String tempwrite = ((EditText) findViewById(R.id.YEET2)).getText().toString();
tempwrite += "&4"; tempwrite += "&15:00-17:00";
String [] temploadarray = tempwrite.split("&"); // id,museum_name,city,country,price,name,password,adminflag,currency,language,id String [] temploadarray = tempwrite.split("&"); // id,museum_name,city,country,price,name,password,adminflag,currency,language,id
String filename6 = "Booking_" + temploadarray[5] + temploadarray [10]; // file will be named: Booking_NameID String filename6 = "Booking";// + temploadarray[5] + temploadarray [10]; // file will be named: Booking_NameID
File file6; File file6;
file6 = new File(getApplicationContext().getFilesDir(), filename6 + ".txt"); file6 = new File(getApplicationContext().getFilesDir(), filename6 + ".txt");
String temp = ""; String temp = "";
...@@ -272,7 +272,7 @@ public class BookingDetails extends AppCompatActivity { ...@@ -272,7 +272,7 @@ public class BookingDetails extends AppCompatActivity {
// //
} }
else{ else{
tempwrite = "%" + tempwrite; tempwrite = "&" + tempwrite;
} }
try{ try{
FileWriter stream = new FileWriter(file6, true); FileWriter stream = new FileWriter(file6, true);
......
...@@ -8,8 +8,10 @@ import android.view.View; ...@@ -8,8 +8,10 @@ import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import java.io.File; import java.io.File;
import java.io.FileWriter;
import java.util.Scanner; import java.util.Scanner;
public class CheckoutScreen extends AppCompatActivity { public class CheckoutScreen extends AppCompatActivity {
...@@ -19,6 +21,10 @@ public class CheckoutScreen extends AppCompatActivity { ...@@ -19,6 +21,10 @@ public class CheckoutScreen extends AppCompatActivity {
File file1; File file1;
File file2; File file2;
Double Euro = 1.16;
Double USD = 1.40;
Double HKD = 10.85;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -69,15 +75,21 @@ public class CheckoutScreen extends AppCompatActivity { ...@@ -69,15 +75,21 @@ public class CheckoutScreen extends AppCompatActivity {
} }
} catch (Exception e) { } } catch (Exception e) { }
// id,museum_name,city,country,price,name,password,adminflag,currency,language,id,slot // id,museum_name,city,country,price,name,password,adminflag,currency,language,id,slot
int idint = read.hashCode();
if (idint < 0){
idint *=-1;
}
int totalprice = 0;
int idint2 = (int) Math.round(Math.random() * (999999 - 100000 + 1) + 100000);
String [] loadbooking = read.split("&"); String [] loadbooking = read.split("&");
String bookingoutput = "Bookings made:"; String bookingoutput = "Cart ID: " + idint2 + "\nBookings made:\n>";
for (int i = 0; i < loadbooking.length; i++){ for (int i = 0; i < loadbooking.length; i++){
if (i%12 == 2){ if (i%12 == 1){
//museum name //museum name
bookingoutput += loadbooking [i]; bookingoutput += loadbooking [i];
bookingoutput += ", "; bookingoutput += ", ";
} }
if (i%12 == 3){ if (i%12 == 2){
//city //city
bookingoutput += "("; bookingoutput += "(";
bookingoutput += loadbooking [i]; bookingoutput += loadbooking [i];
...@@ -86,26 +98,96 @@ public class CheckoutScreen extends AppCompatActivity { ...@@ -86,26 +98,96 @@ public class CheckoutScreen extends AppCompatActivity {
if (i%12 == 9){ if (i%12 == 9){
//currency mode to select //currency mode to select
} }
if (i%12 == 5){ if (i%12 == 4){
//price //price
totalprice += Integer.parseInt(loadbooking[i]);
bookingoutput += " "; bookingoutput += " ";
String pricetest = loadbooking [i+4]; String pricetest = loadbooking [i+4];
int price = 0; if (temploadarray[3].equals("£")){
bookingoutput += loadbooking [i]; bookingoutput += "£";
bookingoutput += loadbooking[i];
}
if (temploadarray[3].equals("€")){
bookingoutput += "€";
double price = Double.parseDouble(loadbooking[i]);
price *= Euro;
bookingoutput += price;
bookingoutput += "(£";
bookingoutput += loadbooking[i];
bookingoutput += ")";
}
if (temploadarray[3].equals("US$")){
bookingoutput += "$";
double price = Double.parseDouble(loadbooking[i]);
price *= USD;
bookingoutput += price;
bookingoutput += "(£";
bookingoutput += loadbooking[i];
bookingoutput += ")";
}
if (temploadarray[3].equals("HK$")){
bookingoutput += "$";
double price = Double.parseDouble(loadbooking[i]);
price *= HKD;
bookingoutput += price;
bookingoutput += "(£";
bookingoutput += loadbooking[i];
bookingoutput += ")";
}
double price = 0;
//bookingoutput += loadbooking [i];
bookingoutput += ", "; bookingoutput += ", ";
} }
if (i%12 == 10){ if (i%12 == 11){
// //time slot
bookingoutput += loadbooking [i]; bookingoutput += loadbooking [i];
bookingoutput += ", "; bookingoutput += ", ";
} }
if (i%12 == 0){ if (i%12 == 0){
//end of each booking entry //end of each booking entry
bookingoutput += loadbooking [i]; //bookingoutput += loadbooking [i];
bookingoutput += "\n"; bookingoutput += "\n";
bookingoutput += "> "; bookingoutput += "> ";
} }
} }
bookingoutput += "\n\nOther Items:\n>";
bookingoutput += "\n\nTotal: ";
if (temploadarray[3].equals("£")){
bookingoutput += "£";
}
if (temploadarray[3].equals("€")){
bookingoutput += "€";
double price = Double.parseDouble(String.valueOf(totalprice));
price *= Euro;
price = Math.round(price * 100.0) / 100.0;
bookingoutput += price;
bookingoutput += "(£";
bookingoutput += totalprice;
bookingoutput += ")";
}
if (temploadarray[3].equals("US$")){
bookingoutput += "$";
double price = Double.parseDouble(String.valueOf(totalprice));
price *= USD;
price = Math.round(price * 100.0) / 100.0;
bookingoutput += price;
bookingoutput += "(£";
bookingoutput += totalprice;
bookingoutput += ")";
}
if (temploadarray[3].equals("HK$")){
bookingoutput += "$";
double price = Double.parseDouble(String.valueOf(totalprice));
price *= HKD;
price = Math.round(price * 100.0) / 100.0;
bookingoutput += price;
bookingoutput += "(£";
bookingoutput += totalprice;
bookingoutput += ")";
}
bookingoutput += " All Prices Billed in GBP (£)";
((EditText)findViewById(R.id.outputcheckout)).setText(bookingoutput); ((EditText)findViewById(R.id.outputcheckout)).setText(bookingoutput);
} }
...@@ -149,4 +231,27 @@ public class CheckoutScreen extends AppCompatActivity { ...@@ -149,4 +231,27 @@ public class CheckoutScreen extends AppCompatActivity {
Intent intent = new Intent(this,MainBookingPage.class); Intent intent = new Intent(this,MainBookingPage.class);
startActivity(intent); startActivity(intent);
} }
public void IThrewItOnTheGround (View view){
//empty basket
String filename6 = "Booking";
File file6;
file6 = new File(getApplicationContext().getFilesDir(), filename6 + ".txt");
try{
FileWriter stream = new FileWriter(file6, false);
stream.append("");
stream.close();
Toast.makeText(getApplicationContext(), "Cart contents wiped", Toast.LENGTH_LONG).show();
} catch(Exception e){
Toast.makeText(getApplicationContext(), "Internal File Error", Toast.LENGTH_LONG).show();
}
Intent intent = new Intent(this,CheckoutScreen.class);
startActivity(intent);
}
public void ChaChing (View view){
//buy
}
} }
\ No newline at end of file
...@@ -10,6 +10,7 @@ import android.widget.TextView; ...@@ -10,6 +10,7 @@ import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import java.io.File; import java.io.File;
import java.io.FileWriter;
import java.util.Scanner; import java.util.Scanner;
public class UserMenu extends AppCompatActivity { public class UserMenu extends AppCompatActivity {
...@@ -90,6 +91,19 @@ public class UserMenu extends AppCompatActivity { ...@@ -90,6 +91,19 @@ public class UserMenu extends AppCompatActivity {
} }
public void goback (View view){ public void goback (View view){
String filename6 = "Booking";
File file6;
file6 = new File(getApplicationContext().getFilesDir(), filename6 + ".txt");
try{
FileWriter stream = new FileWriter(file6, false);
stream.append("");
stream.close();
Toast.makeText(getApplicationContext(), "Logged out, cart contents wiped", Toast.LENGTH_LONG).show();
} catch(Exception e){
Toast.makeText(getApplicationContext(), "Internal File Error", Toast.LENGTH_LONG).show();
}
Intent intent = new Intent(this,MainActivity.class); Intent intent = new Intent(this,MainActivity.class);
startActivity(intent); startActivity(intent);
} }
......
...@@ -41,11 +41,25 @@ ...@@ -41,11 +41,25 @@
android:onClick="toshop" android:onClick="toshop"
android:text="Shop" /> android:text="Shop" />
<Button
android:id="@+id/button81"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="IThrewItOnTheGround"
android:text="Clear Basket" />
<Button
android:id="@+id/button82"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="ChaChing"
android:text="Buy" />
<EditText <EditText
android:id="@+id/outputcheckout" android:id="@+id/outputcheckout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="523dp" android:layout_height="429dp"
android:ems="10" android:ems="10"
android:inputType="textPersonName" /> android:inputType="textLongMessage|textMultiLine" />
</LinearLayout> </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
...@@ -124,7 +124,7 @@ ...@@ -124,7 +124,7 @@
android:id="@+id/textView26" android:id="@+id/textView26"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Default Currency" /> android:text="Default Currency (display only, transactions are in £)" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
......
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