Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package project_netbeans;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import javafx.collections.FXCollections;
- import javafx.collections.ObservableList;
- import javafx.geometry.Insets;
- import javafx.geometry.Pos;
- import javafx.scene.Node;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.ComboBox;
- import javafx.scene.control.Label;
- import javafx.scene.control.TextField;
- import javafx.scene.image.Image;
- import javafx.scene.image.ImageView;
- import javafx.scene.layout.BorderPane;
- import javafx.scene.layout.GridPane;
- import javafx.scene.layout.HBox;
- import javafx.scene.layout.StackPane;
- import javafx.scene.layout.VBox;
- import javafx.scene.text.Font;
- import javafx.stage.Modality;
- import javafx.stage.Stage;
- public class PaymentForm {
- static String paymentMethod;
- static long loyaltyNumber;
- static Database database = new Database();
- static Customer cust;
- static Order order;
- static PreOrder preOrder;
- public static void Payment(){
- Stage primaryStage = new Stage();
- primaryStage.setTitle("Payment");
- BorderPane pane = new BorderPane();
- pane.setStyle("-fx-padding: 10; -fx-background-color: #28ABE3" );
- //here we are creating a new image which will be our create new logo
- Image image = new Image("Image/Payment.png");
- StackPane LogoBackGround = new StackPane(); //create a new stack pane to hold this image and allow us
- //to center it within the border top pane
- LogoBackGround.setPrefSize(75,75);//setting the size we want
- ImageView Logo = new ImageView(image); //creating a new image view that will be used
- Logo.setFitHeight(75); //fitting the image to the image view
- Logo.setFitWidth(75);
- LogoBackGround.setPadding(new Insets(30,0,0,0));
- LogoBackGround.getChildren().add(Logo); //adding the logo to the stack pane
- pane.setTop(LogoBackGround); //adding the stack pane to the top region of the borderpane
- pane.setCenter(CenterLayout());
- Scene scene = new Scene(pane, 500, 600);
- primaryStage.setResizable(false);
- primaryStage.setScene(scene);
- primaryStage.initModality(Modality.APPLICATION_MODAL);
- primaryStage.show();
- }
- private static StackPane CenterLayout(){
- StackPane CenterPane = new StackPane();
- VBox CenterLayout = new VBox();
- CenterLayout.setSpacing(10);
- CenterLayout.setPadding(new Insets(10,10,10,10));
- StackPane CustLoyaltyBackGround = new StackPane();
- CustLoyaltyBackGround.setStyle("-fx-background-color: White; -fx-border-color: Black;");
- VBox CustLoyaltyLayout = new VBox();//creating a new VBox for the overall structure
- CustLoyaltyLayout.setSpacing(10);
- CustLoyaltyLayout.setPadding(new Insets(10,10,10,10));
- HBox LoyaltyNum = new HBox(); //creating a new hBox as i want a lable and text box in line with each other
- Label lblLoyaltyNum = new Label("Loyalty Number: ");//adding the label
- lblLoyaltyNum.setFont(new Font("Arial",20));//seeting the font for the lable
- TextField txtLoyaltyNum = new TextField();//creating a new textbox for the user to enter the value
- txtLoyaltyNum.setPrefWidth(150);//setting the height and width of the text box
- txtLoyaltyNum.setPrefHeight(15);
- txtLoyaltyNum.textProperty().addListener((observable, oldValue, newValue) -> {
- loyaltyNumber = Long.valueOf(txtLoyaltyNum.getText()); //setting the action to assign the value of the text box
- //after every change to the textfield text property
- });
- LoyaltyNum.getChildren().addAll(lblLoyaltyNum, txtLoyaltyNum);//adding the label adn the textbox to the HBox
- CustLoyaltyLayout.getChildren().add(LoyaltyNum);//adding the HBox to the VBox
- CustLoyaltyBackGround.getChildren().add(CustLoyaltyLayout); //adding the VBox to the background
- Button btnRegisterNewCustomer = new Button("Register new customer"); //creating a new Button to register a new customer
- btnRegisterNewCustomer.setPrefHeight(15);//setting the size of the button
- btnRegisterNewCustomer.setPrefWidth(200);
- btnRegisterNewCustomer.setOnAction(e -> {
- ((Node)e.getSource()).getScene().getWindow().hide();
- RegisterNewLoyaltyCustomer.display();
- ((Stage)((Node)e.getSource()).getScene().getWindow()).show();
- });
- CustLoyaltyLayout.getChildren().add(btnRegisterNewCustomer); //adding them to the VBox
- Label lblPointsEarned = new Label("Loyalty points earned from this transaction: "); //creating a new Label to display text
- lblPointsEarned.setFont(new Font("Arial",20)); //setting the font
- CustLoyaltyLayout.getChildren().add(lblPointsEarned); //adding the label to the VBox
- Label lblActualPointsEarned = new Label("_____"); //creating a new label to display the points they will earn
- lblActualPointsEarned.setFont(new Font("Arial",20)); //setting the font of the label
- CustLoyaltyLayout.getChildren().add(lblActualPointsEarned); //adding it to the vbox
- StackPane SP_PaymentBackGround = new StackPane(); //new stack pane for the Payment details background
- SP_PaymentBackGround.setStyle("-fx-background-color: White; -fx-border-color: Black;"); ////settting the style of the stackpane
- VBox VX_PaymentLayout = new VBox(); //creating a new VBox for the overall layout of the payment details
- VX_PaymentLayout.setPadding(new Insets(10,10,10,10)); //spacing out the elements
- VX_PaymentLayout.setSpacing(10);
- HBox HB_PaymentOptions = new HBox(); //creating a HBox as i want the buttons to be inline
- HB_PaymentOptions.setSpacing(20); //spacing out the buttons
- HB_PaymentOptions.setAlignment(Pos.CENTER);
- Button btnCash = new Button("Cash");//creating the buttons for cash, credit and loyalty points
- btnCash.setPrefSize(110, 125);
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //moved all button actions to the bottom of the method
- Button btnCredit = new Button("Credit");
- btnCredit.setPrefSize(110,125);
- Button btnLoyalty = new Button("Loyalty Points");
- btnLoyalty.setPrefSize(110,125);
- HB_PaymentOptions.getChildren().addAll(btnCash,btnCredit,btnLoyalty); //adding the buttons to the HBOx
- VX_PaymentLayout.getChildren().add(HB_PaymentOptions); //adding the HBox to the VBox
- SP_PaymentBackGround.getChildren().add(VX_PaymentLayout); //adding the VBox to the stackpane
- GridPane GP_PaymentDetails = new GridPane();
- GP_PaymentDetails.setPadding(new Insets(10,10,10,10));
- //stackpane for card details
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- StackPane SP_CardDetails = new StackPane();
- SP_CardDetails.setVisible(false); //setting these to hidden by defualt because depenind on which option they hit it will show relevant pane
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //vbox for the details \
- VBox VB_CardDetails = new VBox();
- VB_CardDetails.setSpacing(10);
- HBox HB_CardDetails = new HBox();
- HB_CardDetails.setSpacing(10);
- Label lblCardType = new Label("Card type: ");
- lblCardType.setFont(new Font("Arial",20));
- ObservableList<String> options = FXCollections.observableArrayList( //creating an array list to hold the values of the combo box
- "Visa",
- "MasterCard",
- "American Express"
- );
- final ComboBox cboCardType = new ComboBox(options); //then creating the combo box
- cboCardType.setPrefWidth(200);
- HBox HB_CardNum = new HBox(); //creating a hbox for the card number so the label and textbox will be next to each other
- HB_CardNum.setSpacing(10); //setting the spacing
- Label lblCardNum = new Label("Card number: "); //creating the label
- lblCardNum.setFont(new Font("Arial",20));//setting the font
- TextField txtCardNum = new TextField(); //creating the textbox for the card number
- txtCardNum.setPrefWidth(200); //setting the size
- //adding the elements first to the HBox so they will be aligned
- HB_CardDetails.getChildren().addAll(lblCardType, cboCardType);
- HB_CardNum.getChildren().addAll(lblCardNum,txtCardNum); //adding the label and textbox to the hbox for the card number
- VB_CardDetails.getChildren().addAll(HB_CardDetails,HB_CardNum); //then adding them to the VBox as there will be other elements added
- SP_CardDetails.getChildren().add(VB_CardDetails); //adding the vbOX to the stackpane
- StackPane SP_Loyalty = new StackPane();
- //vbox for the details \
- VBox VB_LoyaltyDetails = new VBox();
- VB_LoyaltyDetails.setSpacing(10);
- HBox HB_LoyaltyDetails = new HBox();
- HB_LoyaltyDetails.setSpacing(10);
- Label lblLoyaltyPointsAvailable = new Label("Loyalty points available: ");
- lblLoyaltyPointsAvailable.setFont(new Font("Arial",20));
- TextField txtPointsAvailable = new TextField();
- txtPointsAvailable.setPrefWidth(100);
- HBox HB_LoyaltyRequired = new HBox(); //creating a hbox for the card number so the label and textbox will be next to each other
- HB_LoyaltyRequired.setSpacing(10); //setting the spacing
- Label lblLoyaltyRequired = new Label("Loyalty points required: "); //creating the label
- lblLoyaltyRequired.setFont(new Font("Arial",20));//setting the font
- TextField txtLoyaltyPointsRequired = new TextField(); //creating the textbox for the card number
- txtLoyaltyPointsRequired.setPrefWidth(100); //setting the size
- //adding the elements first to the HBox so they will be aligned
- HB_LoyaltyDetails.getChildren().addAll(lblLoyaltyPointsAvailable, txtPointsAvailable);
- HB_LoyaltyRequired.getChildren().addAll(lblLoyaltyRequired,txtLoyaltyPointsRequired); //adding the label and textbox to the hbox for the card number
- VB_LoyaltyDetails.getChildren().addAll(HB_LoyaltyDetails,HB_LoyaltyRequired); //then adding them to the VBox as there will be other elements added
- SP_Loyalty.getChildren().add(VB_LoyaltyDetails); //adding the vbOX to the stackpane
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //If they click the cash button we dont need anything else to display
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- btnCash.setOnAction(e -> {
- paymentMethod = "Cash"; //valued needed for order construtor and will be recorded in database
- SP_CardDetails.setVisible(false);
- SP_Loyalty.setVisible(false);
- txtCardNum.clear();
- txtPointsAvailable.clear();
- txtLoyaltyPointsRequired.clear();
- });
- ////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////
- //if they click the credit card button it will display the stacl pane for the card details
- ////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- btnCredit.setOnAction(e -> {
- paymentMethod = "Card";
- SP_CardDetails.setVisible(true);
- SP_Loyalty.setVisible(false);
- txtCardNum.clear();
- txtPointsAvailable.clear();
- txtLoyaltyPointsRequired.clear();
- });
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////
- //if they click the credit card button it will display the stacl pane for the card details
- ////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- btnLoyalty.setOnAction(e ->{
- paymentMethod = "Loyalty";
- SP_CardDetails.setVisible(false);
- SP_Loyalty.setVisible(true);
- txtCardNum.clear();
- txtPointsAvailable.clear();
- txtLoyaltyPointsRequired.clear();
- });
- SP_Loyalty.setVisible(false);
- GP_PaymentDetails.add(SP_CardDetails, 0, 0);
- GP_PaymentDetails.add(SP_Loyalty, 0, 0);
- HBox HB_AmountDue = new HBox();
- HB_AmountDue.setSpacing(10);
- Label lblAmountDue = new Label("Amount due: ");
- lblAmountDue.setFont(new Font("Arial",20));
- TextField txtAmountDue = new TextField();
- txtAmountDue.setText("€ " + String.valueOf(OrderingScreen.iTotal));
- txtAmountDue.setPrefSize(200,30);
- HB_AmountDue.getChildren().addAll(lblAmountDue,txtAmountDue);
- HBox HB_ConfirmCancel = new HBox();
- HB_ConfirmCancel.setSpacing(10);
- Button btnConfirm = new Button("Confirm payment");
- btnConfirm.setFont(new Font("Arial",20));
- btnConfirm.setPrefSize(200, 40);
- btnConfirm.setOnAction(e -> {//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ((Node)e.getSource()).getScene().getWindow().hide();//this allows us to hide the current window
- //so the new window can be displayed on its own
- generateOrder(loyaltyNumber);
- SandwichShopSystem.refresh.fire();
- });///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- Button btnCancel = new Button("Cancel");
- btnCancel.setFont(new Font("Arial",20));
- btnCancel.setPrefSize(150,25);
- btnCancel.setOnAction(e -> {//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ((Node)e.getSource()).getScene().getWindow().hide();//this allows us to hide the current window
- //so the new window can be displayed on its own
- });/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- HB_ConfirmCancel.getChildren().addAll(btnConfirm,btnCancel);
- CenterLayout.getChildren().addAll(CustLoyaltyBackGround,SP_PaymentBackGround,GP_PaymentDetails,HB_AmountDue,HB_ConfirmCancel);
- CenterPane.getChildren().add(CenterLayout);
- return CenterPane;
- }
- public static void generateOrder(long iLoyalty)
- {
- if (String.valueOf(iLoyalty).trim() == "")
- {
- loyaltyNumber = 0;
- }
- else
- {
- loyaltyNumber = Long.valueOf(iLoyalty);
- }
- ResultSet customers = database.getTable("LOYALTYCUSTOMER");
- if (String.valueOf(loyaltyNumber).trim() != "") //Check to see if the loyalty field is empty
- {
- try
- {
- while(customers.next()) //cycle through the values
- {
- if (customers.getLong("LOYALTYID") == loyaltyNumber) //Check to see if the customer loyalty number exists
- {
- cust = new Customer(customers.getString("NAME"), customers.getString("EMAIL"), customers.getLong("LOYALTYID"), customers.getInt("LOYALTYBALANCE"));
- //if the loyalty number is matched load that customer into a customer object - required to write to database
- }
- }
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- }
- else
- {
- cust = new Customer();
- }
- if (NewOrderPopUp.preOrder == false)
- {
- order = new Order(paymentMethod, cust.getLoyaltyNumber()); //Create the order Object
- }
- else
- {
- preOrder = new PreOrder(paymentMethod, cust.getLoyaltyNumber(), NewOrderPopUp.preName, NewOrderPopUp.preCollection, NewOrderPopUp.preNumber);
- }
- //Add the quantities of each product selected in the ordering screen
- ArrayList<OrderDetail> details = new ArrayList(); //Create an array for the orderDetails
- if (NewOrderPopUp.preOrder == false)
- {
- for(int x = 1; x <= OrderingScreen.quantities.size();x++)
- {
- if (OrderingScreen.quantities.get(x - 1) != 0)//if the quantity selected is not equal to zero add to the array of order details
- {
- details.add(new OrderDetail(order.getOrderNumber(),x ,OrderingScreen.quantities.get(x-1)));
- }
- }
- order.calculateTotal(details);
- database.write(order,cust);
- database.write(details);
- }
- else
- {
- for(int x = 1; x <= OrderingScreen.quantities.size();x++)
- {
- if (OrderingScreen.quantities.get(x-1) != 0)//if the quantity selected is not equal to zero add to the array of order details
- {
- details.add(new OrderDetail(preOrder.getOrderNumber(),x ,OrderingScreen.quantities.get(x-1)));
- }
- }
- preOrder.calculateTotal(details);
- database.write(preOrder,cust);
- database.write(details);
- System.out.println("PreOrder Sucess");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement